Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lessondesk/marker-protocol

Package Overview
Dependencies
Maintainers
3
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lessondesk/marker-protocol - npm Package Compare versions

Comparing version 3.5.1 to 3.6.0

263

dist/index.js

@@ -7,26 +7,24 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var ref = require("stream");
var Transform = ref.Transform;
const {
Transform
} = require("stream");
var Framer = /*@__PURE__*/(function (Transform) {
function Framer(options) {
if ( options === void 0 ) options = {};
Transform.call(this, options);
class Framer extends Transform {
/**
* Simple default constructor that takes no options. The protocol is not
* configurable.
*/
constructor(options = {}) {
super(options);
this.buffer = Buffer.alloc(0);
}
if ( Transform ) Framer.__proto__ = Transform;
Framer.prototype = Object.create( Transform && Transform.prototype );
Framer.prototype.constructor = Framer;
_transform(chunk, encoding, cb) {
const data = Buffer.concat([this.buffer, chunk]); // We need to have atleast 6 bytes in order to determine the message type.
Framer.prototype._transform = function _transform (chunk, encoding, cb) {
// console.log(chunk);
var data = Buffer.concat([this.buffer, chunk]); // We need to have atleast 8 bytes in order to determine the message type.
if (data.length < 6) {
console.debug(("Packet received with length: " + (data.length) + " require at least 6 bytes, buffering..."));
console.debug(`Packet received with length: ${data.length} require at least 6 bytes, buffering...`);
this.buffer = data;
} else {
var packet_length = data[4] << 8 | data[5];
const packet_length = data[4] << 8 | data[5];

@@ -45,13 +43,13 @@ if (data.length < packet_length) {

return cb();
};
}
return Framer;
}(Transform));
}
var obj;
var ref$1 = require("binary-parser");
var Parser = ref$1.Parser;
const {
Parser
} = require("binary-parser");
var ref$1$1 = require("stream");
var Transform$1 = ref$1$1.Transform;
const {
Transform: Transform$1
} = require("stream");
/**

@@ -63,3 +61,3 @@ * This object contains flags for the different message types that can be sent by the Access Point to the

var Packets = Object.freeze({
const Packets = Object.freeze({
AP_DUMP: 0x09,

@@ -119,7 +117,7 @@ AP_ERROR: 0x03,

function parseSerialNumber(arr) {
var type = arr[0];
var serial = arr.slice(1).reduce(function (acc, byte, index) { return index === 2 ? acc | byte : (acc | byte) << 8; });
const type = arr[0];
const serial = arr.slice(1).reduce((acc, byte, index) => index === 2 ? acc | byte : (acc | byte) << 8);
return {
type: type,
serial: serial
type,
serial
};

@@ -134,3 +132,3 @@ }

var PR_AP_DUMP = new Parser().array("markers", {
const PR_AP_DUMP = new Parser().array("markers", {
type: new Parser().array("marker", {

@@ -154,3 +152,3 @@ type: "uint8",

var PR_AP_UPDATE = new Parser().uint8("count").uint8("amp").uint8("channel");
const PR_AP_UPDATE = new Parser().uint8("count").uint8("amp").uint8("channel");
/**

@@ -163,3 +161,3 @@ * This Parser parses all packets with the 'PT_AP_ERROR' flag, these are messages sent by the Access Point

var PR_AP_ERROR = new Parser().uint8("code");
const PR_AP_ERROR = new Parser().uint8("code");
/**

@@ -175,3 +173,3 @@ * This Parser parses all packets with the 'PT_AP_VERSION' flag, this messages is received as a response the to

var PR_AP_VERSION = new Parser().uint8("hardwareMajor").uint8("hardwareMinor").uint8("firmwareMajor").uint8("firmwareMinor");
const PR_AP_VERSION = new Parser().uint8("hardwareMajor").uint8("hardwareMinor").uint8("firmwareMajor").uint8("firmwareMinor");
/**

@@ -183,3 +181,3 @@ * This parser extracts detail about the marker that has just joined the AP, namely the GTIN.

var PR_MARKER_INFO = new Parser().string("gtin", {
const PR_MARKER_INFO = new Parser().string("gtin", {
encoding: "hex",

@@ -198,3 +196,3 @@ length: 7

var PR_MARKER_JOIN = new Parser().array("marker", {
const PR_MARKER_JOIN = new Parser().array("marker", {
type: "uint8",

@@ -212,3 +210,3 @@ length: 4,

var PR_MARKER_ADDED = new Parser().array("marker", {
const PR_MARKER_ADDED = new Parser().array("marker", {
type: "uint8",

@@ -225,4 +223,4 @@ length: 4,

var PR_MARKER_BUTTON = new Parser().uint8("button", {
formatter: function (data) {
const PR_MARKER_BUTTON = new Parser().uint8("button", {
formatter: data => {
switch (data) {

@@ -252,6 +250,6 @@ case 1:

var PR_MARKER_BATTERY = new Parser().uint16("battery", {
formatter: function (data) {
var voltage = data * 10;
var replace = voltage < 2200 ? true : false;
const PR_MARKER_BATTERY = new Parser().uint16("battery", {
formatter: data => {
const voltage = data * 10;
const replace = voltage < 2200 ? true : false;
return {

@@ -271,3 +269,3 @@ voltage: voltage,

var PR_MARKER_REMOVED = new Parser().array("marker", {
const PR_MARKER_REMOVED = new Parser().array("marker", {
type: "uint8",

@@ -277,3 +275,3 @@ length: 4,

}).uint8("count").uint8("index");
var PARSER = new Parser().skip(3).uint8("version").uint16("bytes").uint8("type").array("source", {
const PARSER = new Parser().skip(3).uint8("version").uint16("bytes").uint8("type").array("source", {
type: "uint8",

@@ -284,3 +282,14 @@ length: 4,

tag: "type",
choices: ( obj = {}, obj[Packets.AP_DUMP] = PR_AP_DUMP, obj[Packets.AP_ERROR] = PR_AP_ERROR, obj[Packets.AP_UPDATE] = PR_AP_UPDATE, obj[Packets.AP_VERSION] = PR_AP_VERSION, obj[Packets.MARKER_INFO] = PR_MARKER_INFO, obj[Packets.MARKER_JOIN] = PR_MARKER_JOIN, obj[Packets.MARKER_ADDED] = PR_MARKER_ADDED, obj[Packets.MARKER_BUTTON] = PR_MARKER_BUTTON, obj[Packets.MARKER_BATTERY] = PR_MARKER_BATTERY, obj[Packets.MARKER_REMOVED] = PR_MARKER_REMOVED, obj )
choices: {
[Packets.AP_DUMP]: PR_AP_DUMP,
[Packets.AP_ERROR]: PR_AP_ERROR,
[Packets.AP_UPDATE]: PR_AP_UPDATE,
[Packets.AP_VERSION]: PR_AP_VERSION,
[Packets.MARKER_INFO]: PR_MARKER_INFO,
[Packets.MARKER_JOIN]: PR_MARKER_JOIN,
[Packets.MARKER_ADDED]: PR_MARKER_ADDED,
[Packets.MARKER_BUTTON]: PR_MARKER_BUTTON,
[Packets.MARKER_BATTERY]: PR_MARKER_BATTERY,
[Packets.MARKER_REMOVED]: PR_MARKER_REMOVED
}
});

@@ -308,5 +317,11 @@ /**

var Protocol = /*@__PURE__*/(function (Transform) {
function Protocol() {
Transform.call(this, {
class Protocol extends Transform$1 {
/**
* Simple default constructor that takes zero args.
*
* Here we set the stream to be in object mode allowing us to write the parsed binary objects to the Writeable Stream which
* will be consumed by anyone listening to the 'data' event.
*/
constructor() {
super({
objectMode: true,

@@ -316,6 +331,2 @@ writableObjectMode: true

}
if ( Transform ) Protocol.__proto__ = Transform;
Protocol.prototype = Object.create( Transform && Transform.prototype );
Protocol.prototype.constructor = Protocol;
/**

@@ -330,6 +341,6 @@ * Transforms the incoming byte chunks into one of the defined message types.

Protocol.prototype._transform = function _transform (chunk, encoding, cb) {
_transform(chunk, encoding, cb) {
// console.log(chunk);
try {
var data = PARSER.parse(chunk);
const data = PARSER.parse(chunk);
return cb(null, data);

@@ -340,27 +351,25 @@ } catch (ex) {

}
};
}
return Protocol;
}(Transform$1));
}
/**
* Accepts a marker join requests, linking the marker to the connected Access Point.
*
* [0xfd], [0xfd], [0xfd], [0x02], [mk_serial_1], [mk_serial_2],[mk_serial_3],[mk_serial_4]
* |____________________| |____| |______________________________________________________|
* Preamble Flag The 4-Byte Marker Serial Number
*
* @param {*} port the serial port interface.
* @param {*} serial the 4-byte marker serial number.
*/
const defaultConfig = {
debug: false,
serialport: {
baudRate: 115200,
databits: 8,
stopBits: 1,
parity: "none"
}
};
var MarkerProtocol = /*@__PURE__*/(function (EventEmitter$$1) {
function MarkerProtocol() {
var this$1 = this;
class MarkerProtocol extends EventEmitter {
constructor(config = defaultConfig) {
super();
EventEmitter$$1.call(this);
this.initialize = () => SerialPort.list().then(this.openAccessPoint).catch(console.error);
this.acceptMarker = function (port, serial) {
var header = Buffer.from([0xfd, 0xfd, 0xfd, 0x03, 0x02]);
var payload = Buffer.alloc(4);
this.acceptMarker = (port, serial) => {
const header = Buffer.from([0xfd, 0xfd, 0xfd, 0x03, 0x02]);
const payload = Buffer.alloc(4);
payload.writeUInt8(121, 0);

@@ -370,12 +379,9 @@ payload.writeUInt8((0x00ff0000 & serial) >> 16, 1);

payload.writeUInt8(0x000000ff & serial, 3);
var packet = Buffer.concat([header, payload]);
const packet = Buffer.concat([header, payload]);
port.write(packet);
};
this.removeMarker = function (port, serial) {
// Remove the marker from our list
//this.markers = this.markers.filter(marker => marker.serial !== serial)
//Remove marker from the AP list
var header = Buffer.from([0xfd, 0xfd, 0xfd, 0x03, 0x05]);
var payload = Buffer.alloc(4);
this.removeMarker = (port, serial) => {
const header = Buffer.from([0xfd, 0xfd, 0xfd, 0x03, 0x05]);
const payload = Buffer.alloc(4);
payload.writeUInt8(121, 0);

@@ -385,80 +391,62 @@ payload.writeUInt8((0x00ff0000 & serial) >> 16, 1);

payload.writeUInt8(0x000000ff & serial, 3);
var packet = Buffer.concat([header, payload]);
const packet = Buffer.concat([header, payload]);
port.write(packet);
};
this.listMarkers = function (port) {
this.listMarkers = port => {
port.write(Buffer.from([0xfd, 0xfd, 0xfd, 0x03, 0x06]));
};
this.handleApVersionRequest = function (port) {
this.handleApVersionRequest = port => {
port.write(Buffer.from([0xfd, 0xfd, 0xfd, 0x03, 0x04]));
};
this.setAmpStateOn = function (port) {
this.setAmpStateOn = port => {
port.write(Buffer.from([0xfd, 0xfd, 0xfd, 0x03, 0x01, 0x01]));
};
this.setApChannel = function (port, channel) {
this.setApChannel = (port, channel) => {
port.write(Buffer.from([0xfd, 0xfd, 0xfd, 0x03, channel]));
};
this.openAccessPoint = function (info) {
var ref = info.filter(function (device) { return device.manufacturer === "FTDI"; });
var usbDetected = ref[0];
var port;
this.onData = packet => Object.keys(Packets).forEach(key => {
if (Packets[key] === packet.type) {
console.log(key, packet);
this.emit(key, packet);
}
});
this.openAccessPoint = info => {
const [usbDetected] = info.filter(device => device.manufacturer === "FTDI");
let port;
if (usbDetected && usbDetected.path) {
if (fs.existsSync(usbDetected.path)) {
console.log('Receiever detected: ', usbDetected.path);
port = new SerialPort(usbDetected.path, {
baudRate: 115200,
databits: 8,
stopBits: 1,
parity: "none"
});
console.log("Receiever detected: ", usbDetected.path);
port = new SerialPort(usbDetected.path, this.config.serialport);
} else {
console.log('Receiever path detected but failed to open path.');
console.log("Receiever path detected but failed to open path.");
}
} else if (fs.existsSync("/dev/ttyAMA0")) {
console.log('Receiever detected: /dev/ttyAMA0');
port = new SerialPort("/dev/ttyAMA0", {
baudRate: 115200,
databits: 8,
stopBits: 1,
parity: "none"
});
console.log("Receiever detected: /dev/ttyAMA0");
port = new SerialPort("/dev/ttyAMA0", this.config.serialport);
} else {
console.log('Receiver not found... Retrying in 10s...');
setTimeout(function () {
SerialPort.list().then(this$1.openAccessPoint).catch(console.error);
}, 10000);
console.log("Receiver not found... Retrying in 10s...");
setTimeout(this.initialize, 10000);
return;
}
var parser = port.pipe(new Framer()).pipe(new Protocol());
parser.on("data", function (packet) {
Object.keys(Packets).forEach(function (key) {
if (Packets[key] === packet.type) {
this$1.debug && console.log(key, packet);
this$1.emit(key, packet);
}
});
});
this$1.on("ACCEPT", function (serial) { return this$1.acceptMarker(port, serial); });
this$1.on("REMOVE", function (serial) { return this$1.removeMarker(port, serial); });
this$1.on("LIST", function () { return this$1.listMarkers(port); });
this$1.on("VERSION", function () { return this$1.handleApVersionRequest(port); });
this$1.on("CHANNEL", function (channel) { return this$1.setApChannel(port, channel); });
const parser = port.pipe(new Framer()).pipe(new Protocol());
parser.on("data", this.onData);
this.on("ACCEPT", serial => this.acceptMarker(port, serial));
this.on("REMOVE", serial => this.removeMarker(port, serial));
this.on("LIST", () => this.listMarkers(port));
this.on("VERSION", () => this.handleApVersionRequest(port));
this.on("CHANNEL", channel => this.setApChannel(port, channel));
};
this.debug = true;
SerialPort.list().then(this.openAccessPoint).catch(console.error);
this.config = config;
this.initialize();
}
if ( EventEmitter$$1 ) MarkerProtocol.__proto__ = EventEmitter$$1;
MarkerProtocol.prototype = Object.create( EventEmitter$$1 && EventEmitter$$1.prototype );
MarkerProtocol.prototype.constructor = MarkerProtocol; // The function below is the receivers response to a marker join request ie. try to accept
/**

@@ -471,10 +459,17 @@ * [0xFD], [0xFD], [0xFD], [0x01], [0x00]

*/
MarkerProtocol.prototype.setAmpStateOff = function setAmpStateOff (port) {
setAmpStateOff(port) {
port.write(Buffer.from([0xfd, 0xfd, 0xfd, 0x03, 0x01, 0x00]));
};
}
/**
* [0xFD], [0xFD], [0xFD], [0x01], [0x01]
* |____________________| |____| |____|
* Preamble Flag Data
*
* @param {*} port the serial port interface.
*/
return MarkerProtocol;
}(EventEmitter));
}
module.exports = MarkerProtocol;
//# sourceMappingURL=index.js.map
{
"name": "@lessondesk/marker-protocol",
"version": "3.5.1",
"version": "3.6.0",
"description": "Lesson Desk Group marker protocol",

@@ -8,6 +8,9 @@ "source": "src/index.js",

"scripts": {
"prepublish": "npm run build",
"prepare": "npm run build",
"fmt": "prettier-eslint --write \"src/**/*.js\"",
"build": "microbundle --format=cjs --target=node",
"test": "node ./index.js"
"test": "node ./index.js",
"check": "npm-check -u",
"commit": "cz",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
},

@@ -18,11 +21,15 @@ "files": [

"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@lessondesk/eslint-config": "^1.2.0",
"axios": "^0.19.0",
"dotenv": "^8.0.0",
"commitizen": "^4.2.2",
"conventional-changelog-cli": "^2.1.1",
"cz-conventional-changelog": "^3.3.0",
"eslint": "5",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-promise": "^4.2.1",
"jest": "^24.8.0",
"microbundle": "^0.11.0",
"husky": "^4.3.5",
"jest": "^26.6.3",
"microbundle": "^0.12.4",
"prettier": "^1.18.2",

@@ -34,11 +41,20 @@ "prettier-eslint-cli": "^5.0.0"

},
"keywords": [],
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"author": "Full Facing",
"license": "MPL-2.0",
"dependencies": {
"binary-parser": "^1.5.0",
"events": "^3.0.0",
"binary-parser": "^1.7.0",
"events": "^3.2.0",
"serialport": "^8.0.6",
"stream": "0.0.2"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
# @lessondesk/marker-protocol
# lnd-app-marker-protocol
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![make a pull request](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![lessondesk-code-style](https://img.shields.io/badge/code%20style-lessondesk-ffa400.svg?style=flat-square)](https://github.com/lessondesk/eslint-config)
[![make a pull request](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![lessondesk-code-style](https://img.shields.io/badge/code%20style-lessondesk-ffa400.svg?style=flat-square)](https://github.com/lessondesk/eslint-config) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

@@ -6,0 +6,0 @@ > Lesson Desk Marker Protocol

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc