Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

firmata

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firmata - npm Package Compare versions

Comparing version
1.0.0
to
2.0.0
+29
test/common/bootstrap.js
process.env.IS_TEST_MODE = true;
// Built-in Dependencies
global.cp = require("child_process");
global.Emitter = require("events");
global.fs = require("fs");
global.path = require("path");
// Third-Party Dependencies
global.assert = require("should");
global.browserify = require("browserify");
global.sinon = require("sinon");
global.webpack = require("webpack");
// Internal Dependencies
global.Encoder7Bit = require("../../../../packages/firmata-io/lib/encoder7bit");
global.OneWire = require("../../../../packages/firmata-io/lib/onewireutils");
global.com = require("../../lib/com");
global.firmata = require("../../lib/firmata");
// Fixtures
global.fixtures = {
unexpected: {
adc: require("../../test/unit/fixtures/unexpected-data-adc"),
i2c: require("../../test/unit/fixtures/unexpected-data-i2c"),
serial: require("../../test/unit/fixtures/unexpected-data-serial"),
}
};
// This test file is primarily for rounding out test coverage
// and gaurding against changes to the "com" stubs.
require("../common/bootstrap");
const sandbox = sinon.sandbox.create();
describe("com.*", () => {
const response = {
error: null,
port: {
comName: null
},
};
it("com.SerialPort", done => {
assert.equal(typeof com.SerialPort, "function");
done();
});
it("com.list", done => {
assert.equal(typeof com.list, "function");
done();
});
});
require("../common/bootstrap");
describe("Encoder7Bit", () => {
it("must encode and decode via in-memory array", done => {
const input = [40, 219, 239, 33, 5, 0, 0, 93, 0, 0, 0, 0, 0, 0, 0, 0];
const encoded = Encoder7Bit.to7BitArray(input);
const decoded = Encoder7Bit.from7BitArray(encoded);
assert.deepEqual(decoded, input);
done();
});
});

Sorry, the diff of this file is too big to display

var Firmata = require("../../../packages/firmata.js/lib/firmata");
module.exports = [0x42, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x44, 0x02, 0xe0, 0x44, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x44, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x3f, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x3f, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x40, 0x02, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x44, 0x02, 0xe0, 0x44, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x44, 0x02, 0xe0, 0x44, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x44, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x3f, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x43, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x3f, 0x02, 0xe0, 0x40, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x42, 0x02, 0xe0, 0x41, 0x02, 0xe0, 0x40, 0x02,
/* REPORT_VERSION start */ 0xf9, 0x02, 0x05, /* REPORT_VERSION end */
0xf0, 0x79, 0x02, 0x05, 0x53, 0x00, 0x74, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x61, 0x00, 0x72, 0x00, 0x64, 0x00, 0x46, 0x00, 0x69, 0x00, 0x72, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x74, 0x00, 0x61, 0x00, 0x50, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x73, 0x00, 0x2e, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x6f, 0x00, 0xf7, 0xf0, 0x6c, 0x7f, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x06, 0x01, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x06, 0x01, 0x7f, 0xf7, 0xf0, 0x6a, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0xf7, 0xe0, 0x7f, 0x03];
module.exports = [0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0x00, 0x40, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x66, 0x00, 0x05, 0x00, 0x39, 0x01, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x40, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x40, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0x00, 0x40, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x66, 0x00, 0x05, 0x00, 0x39, 0x01, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x40, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x40, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0x00, 0x40, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x66, 0x00, 0x05, 0x00, 0x39, 0x01, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x40, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x40, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x05, 0x00, 0x48, 0x01, 0x05, 0x00, 0x1b, 0x01, 0x05, 0x00, 0x3f, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x42, 0x01, 0xf7,
/* REPORT_VERSION start */ 0xf9, 0x02, 0x05, /* REPORT_VERSION end */
0xf0, 0x79, 0x02, 0x05, 0x53, 0x00, 0x74, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x61, 0x00, 0x72, 0x00, 0x64, 0x00, 0x46, 0x00, 0x69, 0x00, 0x72, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x74, 0x00, 0x61, 0x00, 0x50, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x73, 0x00, 0x2e, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x6f, 0x00, 0xf7, 0xf0, 0x6c, 0x7f, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x06, 0x01, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x06, 0x01, 0x7f, 0xf7, 0xf0, 0x6a, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0xf7, 0xf0, 0x77, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x5d, 0x00, 0x05, 0x00, 0x40, 0x01, 0x05, 0x00, 0x41, 0x01, 0x05, 0x00, 0x41, 0x01, 0x04, 0x00, 0x16, 0x00, 0x05, 0x00, 0x40, 0x01, 0xf7,
];
module.exports = [0x00, 0x2c, 0x00, 0x30, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x30, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x2a, 0x00, 0x37, 0x00, 0x31, 0x00, 0x0d, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x30, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x2a, 0x00, 0x37, 0x00, 0x31, 0x00, 0x0d, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x30, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x2a, 0x00, 0x37, 0x00, 0x31, 0x00, 0x0d, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x30, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x2a, 0x00, 0x37, 0x00, 0x31, 0x00, 0x0d, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x30, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x2a, 0x00, 0x37, 0x00, 0x31, 0x00, 0x0d, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x30, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x2a, 0x00, 0x37, 0x00, 0x31, 0x00, 0x0d, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x30, 0x00, 0x30, 0x00, 0x2c, 0x00, 0x2a, 0x00, 0x37, 0x00, 0x31, 0x00, 0x0d, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x0a, 0x00, 0x24, 0x00, 0x47, 0x00, 0x50, 0x00, 0x52, 0x00, 0x4d, 0x00, 0x43, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x2c, 0x00, 0x2c, 0x00, 0x56, 0x00, 0x2c, 0x00, 0x2c, 0x00, 0x2c, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x2c, 0x00, 0x2c, 0x00, 0x2c, 0x00, 0x2c, 0x00, 0x2c, 0x00, 0x2c, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x2c, 0x00, 0x4e, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x33, 0x00, 0x0d, 0x00, 0x0a, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x24, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x47, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x50, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x47, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x47, 0x00, 0xf7, 0xf0, 0x60, 0x48, 0x41, 0xfe, 0xf0, 0x79, 0x02, 0x05, 0x53, 0x00, 0x74, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x61, 0x00, 0x72, 0x00, 0x64, 0x00, 0x46, 0x00, 0x69, 0x00, 0x72, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x74, 0x00, 0x61, 0x00, 0x50, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x73, 0x00, 0x2e, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x6f, 0x00, 0xf7,
/* REPORT_VERSION start */ 0xf9, 0x02, 0x05, /* REPORT_VERSION end */
0x05, 0x53, 0x00, 0x74, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x61, 0x00, 0x72, 0x00, 0x64, 0x00, 0x46, 0x00, 0x69, 0x00, 0x72, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x74, 0x00, 0x61, 0x00, 0x50, 0x00, 0x6c, 0x00, 0x75, 0x00, 0x73, 0x00, 0x2e, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x6f, 0x00, 0xf7, 0xf0, 0x6c, 0x7f, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x03, 0x08, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x06, 0x01, 0x7f, 0x00, 0x01, 0x0b, 0x01, 0x01, 0x01, 0x02, 0x0a, 0x04, 0x0e, 0x06, 0x01, 0x7f, 0xf7, 0xf0, 0x6a, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0xf7, 0xf0, 0x60, 0x48, 0x19, 0x01, 0xf7];
require("../common/bootstrap");
const sandbox = sinon.sandbox.create();
describe("OneWire.crc8/OneWire.readDevices", () => {
afterEach(() => {
sandbox.restore();
});
describe("OneWire.crc8", () => {
it("must CRC check data read from firmata", done => {
const input = [0x28, 0xDB, 0xEF, 0x21, 0x05, 0x00, 0x00, 0x5D];
const crcByte = OneWire.crc8(input.slice(0, input.length - 1));
assert.equal(crcByte, input[input.length - 1]);
done();
});
it("must return an invalid CRC check for corrupt data", done => {
const input = [0x28, 0xDB, 0xEF, 0x22, 0x05, 0x00, 0x00, 0x5D];
const crcByte = OneWire.crc8(input.slice(0, input.length - 1));
crcByte.should.not.equal(input[input.length - 1]);
done();
});
});
describe("OneWire.readDevices", () => {
it("must read device identifier", done => {
const input = Encoder7Bit.to7BitArray([0x28, 0xDB, 0xEF, 0x21, 0x05, 0x00, 0x00, 0x5D]);
const devices = OneWire.readDevices(input);
assert.equal(devices.length, 1);
done();
});
it("must read device identifiers", done => {
const input = Encoder7Bit.to7BitArray([0x28, 0xDB, 0xEF, 0x21, 0x05, 0x00, 0x00, 0x5D, 0x28, 0xDB, 0xEF, 0x21, 0x05, 0x00, 0x00, 0x5D]);
const devices = OneWire.readDevices(input);
assert.equal(devices.length, 2);
done();
});
it("must read only complete device identifiers", done => {
const input = Encoder7Bit.to7BitArray([0x28, 0xDB, 0xEF, 0x21, 0x05, 0x00, 0x00, 0x5D, 0x28, 0xDB, 0xEF, 0x21, 0x05, 0x00, 0x00, 0x5D, 0x00, 0x01, 0x02]);
const devices = OneWire.readDevices(input);
assert.equal(devices.length, 2);
done();
});
it("detects and logs invalid ROM", done => {
sandbox.stub(console, "error").callsFake(() => {});
sandbox.stub(OneWire, "crc8").callsFake(() => null);
const input = Encoder7Bit.to7BitArray([0x28, 0xDB, 0xEF, 0x21, 0x05, 0x00, 0x00, 0x5D, 0x28, 0xDB, 0xEF, 0x21, 0x05, 0x00, 0x00, 0x5D, 0x00, 0x01, 0x02]);
const devices = OneWire.readDevices(input);
assert.equal(devices.length, 2);
assert.equal(console.error.lastCall.args[0], "ROM invalid!");
done();
});
});
});
+23
-26

@@ -5,3 +5,3 @@ "use strict";

class SerialPort extends Emitter {
class TransportStub extends Emitter {
constructor(path/*, options, openCallback*/) {

@@ -26,40 +26,37 @@ super();

}
}
let com;
let sp;
let stub = {
SerialPort,
list() {
static list() {
/* istanbul ignore next */
return Promise.resolve([]);
},
};
}
}
// This trash is necessary for stubbing with sinon.
TransportStub.SerialPort = TransportStub;
let com;
let error;
let SerialPort;
try {
/* istanbul ignore if */
if (process.browser || parseFloat(process.versions.nw) >= 0.13) {
com = require("browser-serialport");
/* istanbul ignore else */
if (process.env.IS_TEST_MODE) {
com = TransportStub;
} else {
/* istanbul ignore else */
if (process.env.IS_TEST_MODE) {
com = stub;
} else {
sp = require("serialport");
com = {
SerialPort: sp,
list: sp.list,
};
}
SerialPort = require("serialport");
com = SerialPort;
}
} catch (err) {}
} catch (err) {
/* istanbul ignore next */
error = err;
}
/* istanbul ignore if */
if (com == null) {
if (process.env.IS_TEST_MODE) {
com = stub;
com = TransportStub;
} else {
console.log("It looks like serialport didn't compile properly. This is a common problem and its fix is well documented here https://github.com/voodootikigod/node-serialport#to-install");
console.log("The result of requiring the package is: ", sp);
console.log(`The result of requiring the package is: ${SerialPort}`);
console.log(error);
throw "Missing serialport dependency";

@@ -66,0 +63,0 @@ }

{
"name": "firmata",
"description": "Firmata protocol implementation for programmatic interaction with Arduino and Arduino compatible development boards.",
"version": "1.0.0",
"description": "Firmata protocol implementation for programmatic interaction with Arduino and Arduino compatible development boards. Includes Serialport",
"version": "2.0.0",
"author": "Julian Gautier",

@@ -12,32 +12,21 @@ "license": "MIT",

},
"main": "lib/firmata",
"bin": {
"firmata": "./repl.js"
},
"devDependencies": {
"browserify": "^13.0.0",
"common-tags": "^1.4.0",
"coveralls": "^2.11.15",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-eslint": "^21.0.0",
"grunt-jsbeautifier": "^0.2.13",
"grunt-jscs": "^3.0.1",
"grunt-mocha-test": "^0.13.3",
"mocha": "^2.3.x",
"nyc": "^10.0.0",
"should": "^7.1.x",
"sinon": "^4.1.3",
"webpack": "^1.12.14"
},
"main": "./lib/firmata",
"dependencies": {
"browser-serialport": "latest",
"serialport": "~6.0.4"
"firmata-io": "^2.0.0",
"serialport": "^7.1.3"
},
"scripts": {
"test": "grunt",
"attempt-timeout": "node examples/test-i2c-read.js && node examples/test-i2c-read.js && node examples/test-analog-read.js && node examples/test-analog-read.js && node examples/test-serial-read.js && node examples/test-serial-read.js",
"test-cover": "nyc grunt test",
"coveralls": "nyc --reporter=lcov grunt test && cat ./coverage/lcov.info | coveralls"
}
},
"bugs": {
"url": "https://github.com/firmata/firmata.js/issues"
},
"directories": {
"example": "examples",
"lib": "lib"
},
"keywords": [],
"gitHead": "7ddbf3e14e360706fa3f64c61926abc11c4f0116"
}
+83
-81

@@ -38,4 +38,4 @@ # Firmata.js

```js
const Board = require("firmata");
const board = new Board("system path or name");
const Firmata = require("firmata");
const board = new Firmata("system path or name");

@@ -51,4 +51,4 @@ board.on("ready", () => {

const Serialport = require("serialport");
const Board = require("firmata");
const board = new Board(new Serialport(...));
const Firmata = require("firmata");
const board = new Firmata(new Serialport(...));

@@ -67,4 +67,4 @@ board.on("ready", () => {

const Etherport = require("etherport");
const Board = require("firmata");
const board = new Board(new Etherport(...));
const Firmata = require("firmata");
const board = new Firmata(new Etherport(...));

@@ -79,4 +79,4 @@ board.on("ready", () => {

```js
const Board = require("firmata");
const board = new Board("system path or name", () => {
const Firmata = require("firmata");
const board = new Firmata("system path or name", () => {
// Arduino is ready to communicate

@@ -90,4 +90,4 @@ });

const Serialport = require("serialport");
const Board = require("firmata");
const board = new Board(new Serialport(...), () => {
const Firmata = require("firmata");
const board = new Firmata(new Serialport(...), () => {
// Arduino is ready to communicate

@@ -101,4 +101,4 @@ });

const Etherport = require("etherport");
const Board = require("firmata");
const board = new Board(new Etherport(...), () => {
const Firmata = require("firmata");
const board = new Firmata(new Etherport(...), () => {
// Arduino is ready to communicate

@@ -112,8 +112,8 @@ });

# `Board`
# `Firmata`
The `Board` constructor creates an instance that represents a physical board.
The `Firmata` constructor creates an instance that represents a physical board.
- `new Board(path[, options][, readyCallback])`
- `new Board(port[, options][, readyCallback])`
- `new Firmata(path[, options][, readyCallback])`
- `new Firmata(port[, options][, readyCallback])`

@@ -130,9 +130,9 @@ | Parameter | Type | Description | Default | Required |

- Notes:
- `new Board(path: string)`: instances can be constructed using only a system path of the serial port to open or name, for example:
+ `new Board("/dev/usb.whatever")`
+ `new Board("/dev/ttyACM0")`
+ `new Board("COM1")`
- `new Board(port: Transport)`: instances can be constructed using a "Transport" object, for example:
+ `new Board(new Serialport(...))`
+ `new Board(new Etherport(...))`
- `new Firmata(path: string)`: instances can be constructed using only a system path of the serial port to open or name, for example:
+ `new Firmata("/dev/usb.whatever")`
+ `new Firmata("/dev/ttyACM0")`
+ `new Firmata("COM1")`
- `new Firmata(port: Transport)`: instances can be constructed using a "Transport" object, for example:
+ `new Firmata(new Serialport(...))`
+ `new Firmata(new Etherport(...))`

@@ -154,3 +154,3 @@ - Options<a name="board-options"></a>

## Board Instance
## Firmata Instance

@@ -192,3 +192,3 @@ - `board.MODES`

value: Number, // Current value of the pin. when pin is digital and set to output it will be
// Board.HIGH or Board.LOW. If the pin is an analog pin it will be an numeric
// Firmata.HIGH or Firmata.LOW. If the pin is an analog pin it will be an numeric
// value between 0 and 1023.

@@ -204,3 +204,3 @@ supportedModes: [ ...Number ], // Array of modes from board.MODES that are supported on this pin.

- `analogPins`
- `board.analogPins`

@@ -213,19 +213,19 @@ This is an array of all the array indexes of the analog pins in the `board.pins` array. For example to get the analog pin 5 from the `board.pins` attributes use:

## Board Prototype API
## Firmata Prototype API
### Pin
- `pinMode(pin,mode)`
- `board.pinMode(pin,mode)`
Set a mode for a pin. pin is the number of the pin and the mode is on of the Board.MODES values. All digital pins are set to board.MODES.OUTPUT by default (because this is what the Firmata firmware running on the board defaults to) and all analog pins are set to board.MODES.ANALOG (analog input) by default.
Set a mode for a pin. pin is the number of the pin and the mode is on of the Firmata.MODES values. All digital pins are set to board.MODES.OUTPUT by default (because this is what the Firmata firmware running on the board defaults to) and all analog pins are set to board.MODES.ANALOG (analog input) by default.
- `digitalWrite(pin,value,enqueue)`
- `board.digitalWrite(pin,value,enqueue)`
Write an output to a digital pin. pin is the number of the pin and the value is either board.HIGH or board.LOW. enqueue is optional and when true will update the local pin value but will not write the data until `writeQueuedDigitalPorts()` is called.
Write an output to a digital pin. pin is the number of the pin and the value is either board.HIGH or board.LOW. enqueue is optional and when true will update the local pin value but will not write the data until `flushDigitalPorts()` is called.
- `writeQueuedDigitalPorts()`
- `board.flushDigitalPorts()`
Directs firmata to update all ports whose values have been changed via digitalWrite with the `enqueue` parameter set to true.
- `digitalRead(pin,callback)`
- `board.digitalRead(pin,callback)`

@@ -246,7 +246,7 @@ Register to get the digital value (board.HIGH or board.LOW). The value is reported via the callback whenever it changes. To get the locally stored value at any other time you can use `board.pins[pinNumber].value`.

- `analogWrite(pin,value)`
- `board.analogWrite(pin,value)`
Write an output to an analog pin (PWM). pin is the number of the pin and the value is between 0 and 255.
- `analogRead(pin,callback)`
- `board.analogRead(pin,callback)`

@@ -267,15 +267,15 @@ Register to get the analog value (0 - 1023) of the pin. The value is reported via the callback at the current sampling interval. The sampling interval is 19 milliseconds by default so the analog value is reported every 19 ms unless the sampling interval is changed. See documentation for `board.setSamplingInterval` below. To get the locally stored value at any other time you can use `board.pins[board.analogPins[analogPinNumber]].value`, but the value will only be as fresh as the most recent report via the sampling interval.

- `setSamplingInterval(interval)`
- `board.setSamplingInterval(interval)`
Set the sampling interval in milliseconds. Default is 19 ms. Minimum is 10 ms, max is 65535 ms. The sampling interval controls how often analog values are reported when using `board.analogRead` and how often i2c device values are reported when using `board.i2cRead`. The same sampling interval is used for both analog and i2c value reporting.
You can alternatively set the sampling interval when creating a new Board instance:
You can alternatively set the sampling interval when creating a new Firmata instance:
```js
// set sampling interval to 30 milliseconds
const board = new Board(serialPortName, {samplingInterval: 30});
const board = new Firmata(serialPortName, {samplingInterval: 30});
```
- `getSamplingInterval()`
- `board.getSamplingInterval()`

@@ -286,7 +286,8 @@ Get the current sampling interval value in milliseconds.

- `servoWrite(pin, degree)`
- `board.servoWrite(pin, degree)`
- `board.servoWrite(pin, pulse)`
Write a degree value to a servo pin.
- `servoConfig(pin, min, max)`
- `board.servoConfig(pin, min, max)`

@@ -297,7 +298,7 @@ Setup a servo with a specific min and max pulse (call instead of `pinMode`, which will provide default).

- `i2cConfig(delay)`
- `board.i2cConfig(delay)`
Configure and enable I2C, optionally provide a value in μs to delay between reads (defaults to `0`). Required to enable I2C communication.
- `i2cConfig(options)`
- `board.i2cConfig(options)`

@@ -318,39 +319,39 @@ Configure and enable I2C, optionally provide an object that contains properties to use for whose value is a number in μs to delay between reads. Required to enable I2C communication.

- `i2cWrite(address, [...bytes])`
- `board.i2cWrite(address, [...bytes])`
Write an arbitrary number of bytes. May not exceed 64 Bytes.
- `i2cWrite(address, register, [...bytes])`
- `board.i2cWrite(address, register, [...bytes])`
Write an arbitrary number of bytes to the specified register. May not exceed 64 Bytes.
- `i2cWriteReg(address, register, byte)`
- `board.i2cWriteReg(address, register, byte)`
Write a byte value to a specific register.
- `i2cRead(address, numberOfBytesToRead, handler(data))`
- `board.i2cRead(address, numberOfBytesToRead, handler(data))`
Read a specified number of bytes, continuously. `handler` receives an array of values, with a length corresponding to the number of read bytes.
- `i2cRead(address, register, numberOfBytesToRead, handler(data))`
- `board.i2cRead(address, register, numberOfBytesToRead, handler(data))`
Read a specified number of bytes from a register, continuously. `handler` receives an array of values, with a length corresponding to the number of read bytes.
- `i2cReadOnce(address, numberOfBytesToRead, handler(data))`
- `board.i2cReadOnce(address, numberOfBytesToRead, handler(data))`
Read a specified number of bytes, one time. `handler` receives an array of values, with a length corresponding to the number of read bytes.
- `i2cReadOnce(address, register, numberOfBytesToRead, handler(data))`
- `board.i2cReadOnce(address, register, numberOfBytesToRead, handler(data))`
Read a specified number of bytes from a register, one time. `handler` receives an array of values, with a length corresponding to the number of read bytes.
- `sendI2CConfig(delay)` **Deprecated**
- `board.sendI2CConfig(delay)` **Deprecated**
Set I2C Config on the arduino
- `sendI2CWriteRequest(slaveAddress, [bytes])` **Deprecated**
- `board.sendI2CWriteRequest(slaveAddress, [bytes])` **Deprecated**
Write an array of bytes to a an I2C device.
- `sendI2CReadRequest(slaveAddress, numBytes, function(data))` **Deprecated**
- `board.sendI2CReadRequest(slaveAddress, numBytes, function(data))` **Deprecated**

@@ -361,3 +362,3 @@ Requests a number of bytes from a slave I2C device. When the bytes are received from the I2C device the callback is called with the byte array.

- `sendString("a string")`
- `board.sendString("a string")`

@@ -368,31 +369,31 @@ Send an arbitrary string.

- `sendOneWireConfig(pin, enableParasiticPower)`
- `board.sendOneWireConfig(pin, enableParasiticPower)`
Configure the pin as the controller in a 1-wire bus. Set `enableParasiticPower` to `true` if you want the data pin to power the bus.
- `sendOneWireSearch(pin, callback)`
- `board.sendOneWireSearch(pin, callback)`
Searches for 1-wire devices on the bus. The callback should accept an error argument and an array of device identifiers.
- `sendOneWireAlarmsSearch(pin, callback)`
- `board.sendOneWireAlarmsSearch(pin, callback)`
Searches for 1-wire devices on the bus in an alarmed state. The callback should accept and error argument and an array of device identifiers.
- `sendOneWireRead(pin, device, numBytesToRead, callback)`
- `board.sendOneWireRead(pin, device, numBytesToRead, callback)`
Reads data from a device on the bus and invokes the callback.
- `sendOneWireReset()`
- `board.sendOneWireReset()`
Resets all devices on the bus.
- `sendOneWireWrite(pin, device, data)`
- `board.sendOneWireWrite(pin, device, data)`
Writes data to the bus to be received by the device. The device should be obtained from a previous call to `sendOneWireSearch`.
- `sendOneWireDelay(pin, delay)`
- `board.sendOneWireDelay(pin, delay)`
Tells Firmata to not do anything for the amount of ms. Use when you need to give a device attached to the bus time to do a calculation.
- `sendOneWireWriteAndRead(pin, device, data, numBytesToRead, callback)`
- `board.sendOneWireWriteAndRead(pin, device, data, numBytesToRead, callback)`

@@ -426,3 +427,3 @@ Sends the `data` to the `device` on the bus, reads the specified number of bytes and invokes the `callback`.

```
options = {
{
portId: board.SERIAL_PORT_IDs.HW_SERIAL1, // <number> The serial port to use (HW_SERIAL2, SW_SERIAL0, SW_SERIAL1...)

@@ -507,3 +508,3 @@ baud: 115200, // <number> (optional) The baud rate of the serial port; default is 57600

- `board.accelStepperConfig(opts)`
- `board.accelStepperConfig(options)`

@@ -513,3 +514,3 @@ Configure a stepper motor

```
opts = {
{
deviceNum: 0, // <number> Device number for the stepper (range 0-9)

@@ -544,35 +545,35 @@ type: board.STEPPER.TYPE.DRIVER, // <number> (optional) Type of stepper or controller; default is FOUR_WIRE

- `board.prototype.accelStepperZero(deviceNum)`
- `board.accelStepperZero(deviceNum)`
Set the current stepper position to zero
- `Board.prototype.accelStepperStep(deviceNum, steps, callback)`
- `board.accelStepperStep(deviceNum, steps, callback)`
Move the stepper motor by a number of steps. Optional callback will be called when motor has finished moving or stop is called
- `Board.prototype.accelStepperTo(deviceNum, position, callback)`
- `board.accelStepperTo(deviceNum, position, callback)`
Move the stepper motor to a specified position. Optional callback will be called when motor has finished moving or stop is called
- `Board.prototype.accelStepperEnable(deviceNum, enabled)`
- `board.accelStepperEnable(deviceNum, enabled)`
If enabled param is set to false, stepper will be disabled, otherwise stepper will be enabled
- `Board.prototype.accelStepperStop(deviceNum)`
- `board.accelStepperStop(deviceNum)`
Stop the stepper motor. Triggers a stepper-done event
- `Board.prototype.accelStepperReportPosition(deviceNum)`
- `board.accelStepperReportPosition(deviceNum)`
Request the current position of the stepper. Triggers a `"stepper-position"` event.
- `Board.prototype.accelStepperSpeed(deviceNum, speed)`
- `board.accelStepperSpeed(deviceNum, speed)`
Set the speed of the stepper in steps per second
- `Board.prototype.accelStepperAcceleration(deviceNum, acceleration)`
- `board.accelStepperAcceleration(deviceNum, acceleration)`
Set the acceleration and deceleration for the stepper in steps / sec^2
- `Board.prototype.multiStepperConfig(opts)`
- `board.multiStepperConfig(opts)`

@@ -588,7 +589,7 @@ Configure a multStepper group. multiStepper groups allow you to pass an array of targeted positions and have all the steppers move to their targets and arrive at the same time. Note that acceleration cannot be used when moving a multiStepper group.

- `Board.prototype.multiStepperTo(groupNum, positions, callback)`
- `board.multiStepperTo(groupNum, positions, callback)`
Move a goup of steppers to and array of desired positions. Optional callback will be called when group has finished moving or multiStepperStop is called
- `Board.prototype.multiStepperStop(groupNum)`
- `board.multiStepperStop(groupNum)`

@@ -603,3 +604,3 @@ Stop a group of stepper motors. Triggers a multi-stepper-done event

- Use `Board.decode(data)` to extract useful values from the incoming response data.
- Use `Firmata.decode(data)` to extract useful values from the incoming response data.

@@ -610,3 +611,3 @@ - `board.sysexCommand(message)`

- Use `Board.encode(data)` to encode data values into an array of 7-bit byte pairs.
- Use `Firmata.encode(data)` to encode data values into an array of 7-bit byte pairs.

@@ -620,7 +621,7 @@ - `board.clearSysexResponse(commandByte)`

- `Board.encode(data)`
- `Firmata.encode(data)`
Encode an array of 8-bit data values as an array of two 7-bit byte pairs (each). (LSB first).
- `Board.decode(data)`
- `Firmata.decode(data)`

@@ -634,3 +635,4 @@ Decode an array of 7-bit byte pairs into a an array of 8-bit data values. (LSB first)

Copyright (c) 2011-2015 Julian Gautier <julian.gautier@alumni.neumont.edu>
Copyright (c) 2011-2015 Julian Gautier <julian.gautier@alumni.neumont.edu>\
Copyright (c) 2015-2019 The Firmata.js Authors (see AUTHORS.md)

@@ -637,0 +639,0 @@ Permission is hereby granted, free of charge, to any person obtaining

+11
-11
#!/usr/bin/env node
var firmata = require('./lib/firmata.js'),
repl = require('repl');
console.log('Enter USB Port and press enter:');
const firmata = require("./lib/firmata");
const repl = require("repl");
console.log("Enter USB Port and press enter:");
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.once('data', function(chunk) {
var port = chunk.replace('\n', '');
var board = new firmata.Board(port, function() {
console.log('Successfully Connected to ' + port);
repl.start('firmata>').context.board = board;
});
});
process.stdin.setEncoding("utf8");
process.stdin.once("data", (chunk) => {
const port = chunk.replace("\n", "");
const board = new firmata.Board(port, () => {
console.log(`Successfully Connected to ${port}`);
repl.start("firmata>").context.board = board;
});
});
{
"env": {
"es6": true,
"browser": true,
"mocha": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module"
},
"globals": {
"it": true,
"describe": true,
"beforeEach": true,
"afterEach": true,
"before": true
},
"rules": {
"curly": 2,
"eqeqeq": 0,
"wrap-iife": [
2,
"any"
],
"no-use-before-define": 0,
"no-caller": 2,
"no-console": 0,
"no-empty": 0,
"dot-notation": 0,
"no-undef": 2,
"no-cond-assign": [
2,
"except-parens"
],
"no-eq-null": 0,
"strict": 0
}
}

Sorry, the diff of this file is not supported yet

"use strict";
const com = require("./lib/com");
module.exports = require("firmata-core")(com.SerialPort);
"use strict";
/**
* "Inspired" by Encoder7Bit.h/Encoder7Bit.cpp in the
* Firmata source code.
*/
module.exports = {
to7BitArray(data) {
let shift = 0;
let previous = 0;
const output = [];
data.forEach(byte => {
if (shift === 0) {
output.push(byte & 0x7f);
shift++;
previous = byte >> 7;
} else {
output.push(((byte << shift) & 0x7f) | previous);
if (shift === 6) {
output.push(byte >> 1);
shift = 0;
} else {
shift++;
previous = byte >> (8 - shift);
}
}
});
/* istanbul ignore else */
if (shift > 0) {
output.push(previous);
}
return output;
},
from7BitArray(encoded) {
const expectedBytes = (encoded.length) * 7 >> 3;
const decoded = [];
for (let i = 0; i < expectedBytes; i++) {
const j = i << 3;
const pos = parseInt(j / 7, 10);
const shift = j % 7;
decoded[i] = (encoded[pos] >> shift) | ((encoded[pos + 1] << (7 - shift)) & 0xFF);
}
return decoded;
}
};
"use strict";
const Encoder7Bit = require("./encoder7bit");
const OneWireUtils = {
crc8(data) {
let crc = 0;
for (let inbyte of data) {
for (let n = 8; n; n--) {
const mix = (crc ^ inbyte) & 0x01;
crc >>= 1;
if (mix) {
crc ^= 0x8C;
}
inbyte >>= 1;
}
}
return crc;
},
readDevices(data) {
const deviceBytes = Encoder7Bit.from7BitArray(data);
const devices = [];
for (let i = 0; i < deviceBytes.length; i += 8) {
const device = deviceBytes.slice(i, i + 8);
if (device.length !== 8) {
continue;
}
const check = OneWireUtils.crc8(device.slice(0, 7));
if (check !== device[7]) {
console.error("ROM invalid!");
}
devices.push(device);
}
return devices;
}
};
module.exports = OneWireUtils;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display