UNPKG

advlib-ble-gatt

Version:

Wireless advertising packet decoding library for Bluetooth Low Energy GATT data. We believe in an open Internet of Things.

192 lines (177 loc) 9.24 kB
/** * Copyright reelyActive 2024 * We believe in an open Internet of Things */ const advlib = require('../../lib/advlibblegatt.js'); const assert = require ('assert'); // Input data for the scenario const INPUT_DATA_INVALID_DATA_NULL = null; const INPUT_DATA_INVALID_DATA_STRING = 'I am not protocolSpecificData'; const INPUT_DATA_INVALID_DATA_OBJECT = { unsupportedType: true }; const INPUT_DATA_VALID_DATA_EMPTY = { gatt: [] }; const INPUT_DATA_VALID_BLUVIB = { gatt: [ { serviceUuid: '1c930003d45911e79296b8e856369374', characteristicUuid: '1c930031d45911e79296b8e856369374', value: '02' }, { serviceUuid: '1c930003d45911e79296b8e856369374', characteristicUuid: '1c930032d45911e79296b8e856369374', value: 'e812' }, { serviceUuid: '1c930003d45911e79296b8e856369374', characteristicUuid: '1c930038d45911e79296b8e856369374', value: '940d' }, { serviceUuid: '1c930002d45911e79296b8e856369374', characteristicUuid: '1c930023d45911e79296b8e856369374', value: '01' }, { serviceUuid: '1c930002d45911e79296b8e856369374', characteristicUuid: '1c930024d45911e79296b8e856369374', value: '00' }, { serviceUuid: '1c930002d45911e79296b8e856369374', characteristicUuid: '1c930029d45911e79296b8e856369374', value: '841e' }, { serviceUuid: '1c930002d45911e79296b8e856369374', characteristicUuid: '1c930020d45911e79296b8e856369374', values: [ '00871987fe86ed8609870187ef86dd86db86f186dc86e186eb86b086b986dc86b586ba86cb86b886c086bd86b186be86c286bb86b086ad86c186c086be86d086cc86cc86c686b686d086d586c886d686d386d386d586d286e486db86dd86fc86f686f086fa8603870c87148723870e870a872c871e871987248720873d874787', 'af7fa17fa77fc87fcf7fac7fb57fe77fd17fb97fd17fbd7fbe7fe57fe17fda7fca7fb37fc97fd87fe37ffb7fe77fcd7fdb7fe47fe07ff47f0080f67fe87fcf7fdc7ff97fe17fe27fea7fcd7fe37ff87ff37f0d80fc7fdc7ff67f0280f77ff27ff17ff77f0080f67fe47f078024800780fd7f01800280fd7fe57ff37f07800480', '0280fc7f0b80f77ff37fd97fc97ff77fe57fd57fe87fdd7feb7fd97fd87f0080e87ff27fff7fd07fd67ff67f0d80f47fd17ffd7ff57fea7f0b80f87ffd7fea7fc67ffb7f0d800180fb7fe57ffe7f0380fa7ffa7fd87fe77ffc7fdd7fe77f00800280f87fe47fe87ff97ff17fee7ff07fda7fd87fe57fdd7fed7ff27fd87fd07f' ] } ] }; // Expected outputs for the scenario const EXPECTED_DATA_INVALID_INPUT = null; const EXPECTED_DATA_VALID_DATA_EMPTY = {}; const EXPECTED_DATA_VALID_BLUVIB = { operatingMode: 'Wakeup', temperature: 18.90625, batteryVoltage: 3.476, calibration: 7812, numberOfSamples: 64, accelerationSamplingRate: 25600, accelerationTimeSeries: [ [ 0.8750560035842293, 0.8872638161342326, 0.874079378580229, 0.8657780660462269, 0.8794508161022304, 0.8755443160862294, 0.8667546910502272, 0.8579650660142248, 0.8569884410102245, 0.8677313160542274, 0.8574767535122247, 0.8599183160222253, 0.8648014410422267, 0.8359910034242191, 0.8403858159422202, 0.8574767535122247, 0.8384325659342197, 0.8408741284442204, 0.8491754409782225, 0.8398975034402201, 0.8438040034562211, 0.8423390659502207, 0.8364793159262192, 0.8428273784522209, 0.8447806284602214, 0.8413624409462205, 0.8359910034242191, 0.8345260659182187, 0.8442923159582213, 0.8438040034562211, 0.8428273784522209, 0.8516170034882231, 0.8496637534802226, 0.8496637534802226, 0.8467338784682219, 0.8389208784362199, 0.8516170034882231, 0.8540585659982238, 0.8477105034722221, 0.8545468785002239, 0.8530819409942235, 0.8530819409942235, 0.8540585659982238, 0.8525936284922234, 0.8613832535282258, 0.8569884410102245, 0.8579650660142248, 0.8731027535762288, 0.870172878564228, 0.8672430035522273, 0.8721261285722285, 0.8765209410902297, 0.8809157536082308, 0.8848222536242318, 0.8921469411542338, 0.8818923786122311, 0.8799391286042306, 0.896541753672235, 0.8897053786442332, 0.8872638161342326, 0.8926352536562339, 0.8906820036482334, 0.9048430662062371, 0.9097261912262384 ], [ -0.03955331266201036, -0.04638968769001216, -0.04345981267801139, -0.027345500112007166, -0.02392731259800627, -0.04101825016801075, -0.036623437650009597, -0.0122078125500032, -0.022950687594006015, -0.03467018764200908, -0.022950687594006015, -0.032716937634008576, -0.03222862513200844, -0.013184437554003454, -0.015137687562003966, -0.01855587507600486, -0.02636887510800691, -0.03760006265400985, -0.02685718761000704, -0.01953250008000512, -0.014161062558003711, -0.00244156251000064, -0.0122078125500032, -0.024903937602006525, -0.018067562574004735, -0.013672750056003583, -0.015626000064004095, -0.0058597500240015355, 0, -0.00488312502000128, -0.011719500048003071, -0.02392731259800627, -0.017579250072004608, -0.0034181875140008957, -0.015137687562003966, -0.014649375060003838, -0.010742875044002814, -0.024903937602006525, -0.014161062558003711, -0.003906500016001024, -0.006348062526001664, 0.006348062526001664, -0.001953250008000512, -0.017579250072004608, -0.00488312502000128, 0.000976625004000256, -0.004394812518001152, -0.006836375028001791, -0.007324687530001919, -0.004394812518001152, 0, -0.00488312502000128, -0.013672750056003583, 0.0034181875140008957, 0.017579250072004608, 0.0034181875140008957, -0.0014649375060003839, 0.000488312502000128, 0.000976625004000256, -0.0014649375060003839, -0.013184437554003454, -0.006348062526001664, 0.0034181875140008957, 0.001953250008000512 ], [ 0.000976625004000256, -0.001953250008000512, 0.005371437522001407, -0.004394812518001152, -0.006348062526001664, -0.01904418757800499, -0.02685718761000704, -0.004394812518001152, -0.013184437554003454, -0.020997437586005502, -0.011719500048003071, -0.017090937570004478, -0.010254562542002688, -0.01904418757800499, -0.01953250008000512, 0, -0.011719500048003071, -0.006836375028001791, -0.000488312502000128, -0.023439000096006142, -0.020509125084005375, -0.00488312502000128, 0.006348062526001664, -0.0058597500240015355, -0.022950687594006015, -0.0014649375060003839, -0.005371437522001407, -0.010742875044002814, 0.005371437522001407, -0.003906500016001024, -0.0014649375060003839, -0.010742875044002814, -0.028322125116007422, -0.00244156251000064, 0.006348062526001664, 0.000488312502000128, -0.00244156251000064, -0.013184437554003454, -0.000976625004000256, 0.0014649375060003839, -0.0029298750120007678, -0.0029298750120007678, -0.01953250008000512, -0.0122078125500032, -0.001953250008000512, -0.017090937570004478, -0.0122078125500032, 0, 0.000976625004000256, -0.003906500016001024, -0.013672750056003583, -0.011719500048003071, -0.0034181875140008957, -0.007324687530001919, -0.008789625036002304, -0.007813000032002047, -0.01855587507600486, -0.01953250008000512, -0.013184437554003454, -0.017090937570004478, -0.00927793753800243, -0.006836375028001791, -0.01953250008000512, -0.023439000096006142 ] ], acceleration: [ 0.8613756236453812, -0.013771938532972355, -0.009033781287002367 ] }; // Describe the scenario describe('advlib-ble-gatt', function() { // Test the process function with no input data it('should handle no input data', function() { assert.deepEqual(advlib.processProtocolSpecificData(), EXPECTED_DATA_INVALID_INPUT); }); // Test the process function with null input data it('should handle null as input', function() { assert.deepEqual(advlib.processProtocolSpecificData( INPUT_DATA_INVALID_DATA_NULL), EXPECTED_DATA_INVALID_INPUT); }); // Test the process function with string input data it('should handle a string as input', function() { assert.deepEqual(advlib.processProtocolSpecificData( INPUT_DATA_INVALID_DATA_STRING), EXPECTED_DATA_INVALID_INPUT); }); // Test the process function with invalid object input data it('should handle an invalid object as input', function() { assert.deepEqual(advlib.processProtocolSpecificData( INPUT_DATA_INVALID_DATA_OBJECT), EXPECTED_DATA_INVALID_INPUT); }); // Test the process function with valid empty input data it('should handle valid empty data as input', function() { assert.deepEqual(advlib.processProtocolSpecificData( INPUT_DATA_VALID_DATA_EMPTY), EXPECTED_DATA_VALID_DATA_EMPTY); }); // Test the process function with valid BluVib input data it('should handle valid BluVib data as input', function() { assert.deepEqual(advlib.processProtocolSpecificData( INPUT_DATA_VALID_BLUVIB), EXPECTED_DATA_VALID_BLUVIB); }); });