advlib-ble-manufacturers
Version:
Wireless advertising packet decoding library for Bluetooth Low Energy manufacturer-specific data. We believe in an open Internet of Things.
72 lines (59 loc) • 2.48 kB
JavaScript
/**
* Copyright reelyActive 2022-2026
* We believe in an open Internet of Things
*/
const manufacturer = require('../../lib/efento.js');
const assert = require ('assert');
// Input data for the scenario
const INPUT_DATA_EXAMPLE = '0205090100002c07803c0001020645c1003d0e8000005d5d';
const INPUT_DATA_DECODING_ADVERTISING_FRAME =
'03282c024f00123144116421562400b4000100009e04';
const INPUT_DATA_DECODING_SCAN_RESPONSE_FRAME = '04010001c00200004c2830';
// Expected outputs for the scenario
const EXPECTED_DATA_INVALID_INPUT = null;
const EXPECTED_DATA_EXAMPLE = {
batteryPercentage: 100,
measurementPeriodSeconds: 60,
relativeHumidity: 61,
temperature: 28.569999999999993,
txCount: 11271,
uri: "https://sniffypedia.org/Organization/Efento_Sp_zoo/",
version: "5.9"
};
const EXPECTED_DATA_DECODING_ADVERTISING_FRAME = {
batteryPercentage: 100,
deviceIds: [ "282c024f0012/2" ],
firmwareVersion: "6.10.4",
encrypted: { checksum: "9e04", method: "efento-v6" },
uri: "https://sniffypedia.org/Organization/Efento_Sp_zoo/"
};
const EXPECTED_DATA_DECODING_SCAN_RESPONSE_FRAME = {
encrypted: { checksum: "2830", method: "efento-v6" },
relativeHumidity: 38,
temperature: 22.4,
uri: "https://sniffypedia.org/Organization/Efento_Sp_zoo/"
};
// Describe the scenario
describe('efento', function() {
// Test the process function with no input data
it('should handle no input data', function() {
assert.deepEqual(manufacturer.process(), EXPECTED_DATA_INVALID_INPUT);
});
// Test the process function with the published example data
it('should handle the published example data', function() {
assert.deepEqual(manufacturer.process(INPUT_DATA_EXAMPLE),
EXPECTED_DATA_EXAMPLE);
});
// Test the process function with decoding advertising frame data
it('should handle decoding advertising frame data', function() {
assert.deepEqual(manufacturer.process(
INPUT_DATA_DECODING_ADVERTISING_FRAME),
EXPECTED_DATA_DECODING_ADVERTISING_FRAME);
});
// Test the process function with decoding scan response frame data
it('should handle decoding scan response frame data', function() {
assert.deepEqual(manufacturer.process(
INPUT_DATA_DECODING_SCAN_RESPONSE_FRAME),
EXPECTED_DATA_DECODING_SCAN_RESPONSE_FRAME);
});
});