sportident.js 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/SiCard/BaseSiCard.js +8 -45
- package/SiCard/BaseSiCard.js.map +1 -1
- package/SiCard/BaseSiCard.test.js +64 -66
- package/SiCard/BaseSiCard.test.js.map +1 -1
- package/SiCard/IRaceResultData.js +1 -2
- package/SiCard/ISiCard.js +1 -2
- package/SiCard/ISiCardExamples.js +1 -2
- package/SiCard/index.js +2 -20
- package/SiCard/index.js.map +1 -1
- package/SiCard/raceResultTools.js +10 -52
- package/SiCard/raceResultTools.js.map +1 -1
- package/SiCard/raceResultTools.test.js +49 -51
- package/SiCard/raceResultTools.test.js.map +1 -1
- package/SiCard/types/FCard.js +4 -41
- package/SiCard/types/FCard.js.map +1 -1
- package/SiCard/types/FCard.test.js +11 -13
- package/SiCard/types/FCard.test.js.map +1 -1
- package/SiCard/types/ModernSiCard.js +25 -67
- package/SiCard/types/ModernSiCard.js.map +1 -1
- package/SiCard/types/ModernSiCard.test.js +69 -104
- package/SiCard/types/ModernSiCard.test.js.map +1 -1
- package/SiCard/types/PCard.js +4 -41
- package/SiCard/types/PCard.js.map +1 -1
- package/SiCard/types/PCard.test.js +11 -13
- package/SiCard/types/PCard.test.js.map +1 -1
- package/SiCard/types/SIAC.js +4 -8
- package/SiCard/types/SIAC.js.map +1 -1
- package/SiCard/types/SIAC.test.js +38 -73
- package/SiCard/types/SIAC.test.js.map +1 -1
- package/SiCard/types/SiCard10.js +4 -8
- package/SiCard/types/SiCard10.js.map +1 -1
- package/SiCard/types/SiCard10.test.js +41 -76
- package/SiCard/types/SiCard10.test.js.map +1 -1
- package/SiCard/types/SiCard11.js +4 -8
- package/SiCard/types/SiCard11.js.map +1 -1
- package/SiCard/types/SiCard11.test.js +38 -73
- package/SiCard/types/SiCard11.test.js.map +1 -1
- package/SiCard/types/SiCard5.js +16 -55
- package/SiCard/types/SiCard5.js.map +1 -1
- package/SiCard/types/SiCard5.test.js +81 -116
- package/SiCard/types/SiCard5.test.js.map +1 -1
- package/SiCard/types/SiCard6.js +17 -56
- package/SiCard/types/SiCard6.js.map +1 -1
- package/SiCard/types/SiCard6.test.js +79 -114
- package/SiCard/types/SiCard6.test.js.map +1 -1
- package/SiCard/types/SiCard8.js +16 -54
- package/SiCard/types/SiCard8.js.map +1 -1
- package/SiCard/types/SiCard8.test.js +69 -104
- package/SiCard/types/SiCard8.test.js.map +1 -1
- package/SiCard/types/SiCard9.js +15 -53
- package/SiCard/types/SiCard9.js.map +1 -1
- package/SiCard/types/SiCard9.test.js +65 -100
- package/SiCard/types/SiCard9.test.js.map +1 -1
- package/SiCard/types/TCard.js +4 -41
- package/SiCard/types/TCard.js.map +1 -1
- package/SiCard/types/TCard.test.js +11 -13
- package/SiCard/types/TCard.test.js.map +1 -1
- package/SiCard/types/index.js +15 -33
- package/SiCard/types/index.js.map +1 -1
- package/SiCard/types/index.test.js +13 -48
- package/SiCard/types/index.test.js.map +1 -1
- package/SiCard/types/modernSiCardExamples.js +21 -58
- package/SiCard/types/modernSiCardExamples.js.map +1 -1
- package/SiCard/types/siCard5Examples.js +6 -43
- package/SiCard/types/siCard5Examples.js.map +1 -1
- package/SiCard/types/siCard6Examples.js +10 -47
- package/SiCard/types/siCard6Examples.js.map +1 -1
- package/SiCard/types/siCard8Examples.js +8 -45
- package/SiCard/types/siCard8Examples.js.map +1 -1
- package/SiCard/types/siCard9Examples.js +8 -45
- package/SiCard/types/siCard9Examples.js.map +1 -1
- package/SiDevice/ISiDevice.js +6 -45
- package/SiDevice/ISiDevice.js.map +1 -1
- package/SiDevice/ISiDeviceDriver.js +3 -41
- package/SiDevice/ISiDeviceDriver.js.map +1 -1
- package/SiDevice/SiDevice.js +20 -57
- package/SiDevice/SiDevice.js.map +1 -1
- package/SiDevice/SiDevice.test.js +103 -138
- package/SiDevice/SiDevice.test.js.map +1 -1
- package/SiDevice/WebSerialSiDeviceDriver.d.ts +8 -7
- package/SiDevice/WebSerialSiDeviceDriver.d.ts.map +1 -1
- package/SiDevice/WebSerialSiDeviceDriver.js +117 -77
- package/SiDevice/WebSerialSiDeviceDriver.js.map +1 -1
- package/SiDevice/WebUsbSiDeviceDriver.d.ts +5 -6
- package/SiDevice/WebUsbSiDeviceDriver.d.ts.map +1 -1
- package/SiDevice/WebUsbSiDeviceDriver.js +36 -89
- package/SiDevice/WebUsbSiDeviceDriver.js.map +1 -1
- package/SiDevice/index.js +1 -5
- package/SiDevice/index.js.map +1 -1
- package/SiDevice/testUtils/index.js +2 -7
- package/SiDevice/testUtils/index.js.map +1 -1
- package/SiDevice/testUtils/testISiDeviceDriver.js +10 -47
- package/SiDevice/testUtils/testISiDeviceDriver.js.map +1 -1
- package/SiDevice/testUtils/testISiDeviceDriverWithAutodetection.js +15 -52
- package/SiDevice/testUtils/testISiDeviceDriverWithAutodetection.js.map +1 -1
- package/SiStation/BaseSiStation.js +18 -55
- package/SiStation/BaseSiStation.js.map +1 -1
- package/SiStation/BaseSiStation.test.js +60 -95
- package/SiStation/BaseSiStation.test.js.map +1 -1
- package/SiStation/CoupledSiStation.js +16 -53
- package/SiStation/CoupledSiStation.js.map +1 -1
- package/SiStation/CoupledSiStation.test.js +27 -62
- package/SiStation/CoupledSiStation.test.js.map +1 -1
- package/SiStation/ISiMainStation.js +4 -43
- package/SiStation/ISiMainStation.js.map +1 -1
- package/SiStation/ISiSendTask.js +2 -5
- package/SiStation/ISiSendTask.js.map +1 -1
- package/SiStation/ISiStation.js +5 -8
- package/SiStation/ISiStation.js.map +1 -1
- package/SiStation/ISiTargetMultiplexer.js +6 -45
- package/SiStation/ISiTargetMultiplexer.js.map +1 -1
- package/SiStation/SiMainStation.js +19 -56
- package/SiStation/SiMainStation.js.map +1 -1
- package/SiStation/SiMainStation.test.js +88 -123
- package/SiStation/SiMainStation.test.js.map +1 -1
- package/SiStation/SiSendTask.js +11 -48
- package/SiStation/SiSendTask.js.map +1 -1
- package/SiStation/SiTargetMultiplexer.js +46 -83
- package/SiStation/SiTargetMultiplexer.js.map +1 -1
- package/SiStation/SiTargetMultiplexer.targeting.test.js +42 -77
- package/SiStation/SiTargetMultiplexer.targeting.test.js.map +1 -1
- package/SiStation/SiTargetMultiplexer.test.js +201 -236
- package/SiStation/SiTargetMultiplexer.test.js.map +1 -1
- package/SiStation/index.js +5 -13
- package/SiStation/index.js.map +1 -1
- package/SiStation/siStationExamples.js +6 -43
- package/SiStation/siStationExamples.js.map +1 -1
- package/constants.js +4 -7
- package/constants.js.map +1 -1
- package/constants.test.js +12 -47
- package/constants.test.js.map +1 -1
- package/fakes/FakeSiCard/BaseFakeSiCard.js +1 -5
- package/fakes/FakeSiCard/BaseFakeSiCard.js.map +1 -1
- package/fakes/FakeSiCard/BaseFakeSiCard.test.js +6 -41
- package/fakes/FakeSiCard/BaseFakeSiCard.test.js.map +1 -1
- package/fakes/FakeSiCard/IFakeSiCard.js +1 -2
- package/fakes/FakeSiCard/index.js +2 -20
- package/fakes/FakeSiCard/index.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeModernSiCard.js +12 -49
- package/fakes/FakeSiCard/types/FakeModernSiCard.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeModernSiCard.test.js +25 -60
- package/fakes/FakeSiCard/types/FakeModernSiCard.test.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSIAC.js +8 -12
- package/fakes/FakeSiCard/types/FakeSIAC.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard10.js +8 -12
- package/fakes/FakeSiCard/types/FakeSiCard10.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard11.js +8 -12
- package/fakes/FakeSiCard/types/FakeSiCard11.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard5.js +12 -49
- package/fakes/FakeSiCard/types/FakeSiCard5.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard5.test.js +20 -55
- package/fakes/FakeSiCard/types/FakeSiCard5.test.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard6.js +12 -49
- package/fakes/FakeSiCard/types/FakeSiCard6.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard6.test.js +25 -60
- package/fakes/FakeSiCard/types/FakeSiCard6.test.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard8.js +7 -11
- package/fakes/FakeSiCard/types/FakeSiCard8.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard9.js +7 -11
- package/fakes/FakeSiCard/types/FakeSiCard9.js.map +1 -1
- package/fakes/FakeSiCard/types/index.js +7 -17
- package/fakes/FakeSiCard/types/index.js.map +1 -1
- package/fakes/FakeSiDeviceDriver.js +10 -47
- package/fakes/FakeSiDeviceDriver.js.map +1 -1
- package/fakes/FakeSiMainStation.js +29 -66
- package/fakes/FakeSiMainStation.js.map +1 -1
- package/fakes/FakeSiMainStation.test.js +43 -78
- package/fakes/FakeSiMainStation.test.js.map +1 -1
- package/fakes/IFakeSiMainStation.js +2 -39
- package/fakes/IFakeSiMainStation.js.map +1 -1
- package/fakes/index.js +2 -20
- package/fakes/index.js.map +1 -1
- package/index.js +10 -46
- package/index.js.map +1 -1
- package/package.json +3 -2
- package/siProtocol.js +35 -82
- package/siProtocol.js.map +1 -1
- package/siProtocol.test.js +308 -345
- package/siProtocol.test.js.map +1 -1
- package/storage/SiArray.js +4 -8
- package/storage/SiArray.js.map +1 -1
- package/storage/SiArray.test.js +56 -58
- package/storage/SiArray.test.js.map +1 -1
- package/storage/SiBool.js +5 -9
- package/storage/SiBool.js.map +1 -1
- package/storage/SiBool.test.js +63 -65
- package/storage/SiBool.test.js.map +1 -1
- package/storage/SiDataType.js +9 -14
- package/storage/SiDataType.js.map +1 -1
- package/storage/SiDataType.test.js +23 -25
- package/storage/SiDataType.test.js.map +1 -1
- package/storage/SiDict.js +4 -8
- package/storage/SiDict.js.map +1 -1
- package/storage/SiDict.test.js +52 -54
- package/storage/SiDict.test.js.map +1 -1
- package/storage/SiEnum.js +7 -44
- package/storage/SiEnum.js.map +1 -1
- package/storage/SiEnum.test.js +59 -61
- package/storage/SiEnum.test.js.map +1 -1
- package/storage/SiFieldValue.js +4 -8
- package/storage/SiFieldValue.js.map +1 -1
- package/storage/SiFieldValue.test.js +25 -27
- package/storage/SiFieldValue.test.js.map +1 -1
- package/storage/SiInt.js +5 -9
- package/storage/SiInt.js.map +1 -1
- package/storage/SiInt.test.js +63 -65
- package/storage/SiInt.test.js.map +1 -1
- package/storage/SiModified.js +5 -9
- package/storage/SiModified.js.map +1 -1
- package/storage/SiModified.test.js +75 -77
- package/storage/SiModified.test.js.map +1 -1
- package/storage/SiStorage.js +4 -9
- package/storage/SiStorage.js.map +1 -1
- package/storage/SiStorage.test.js +32 -67
- package/storage/SiStorage.test.js.map +1 -1
- package/storage/index.js +11 -28
- package/storage/index.js.map +1 -1
- package/storage/index.test.js +93 -128
- package/storage/index.test.js.map +1 -1
- package/storage/interfaces.js +3 -41
- package/storage/interfaces.js.map +1 -1
- package/storage/siStringEncoding.js +1 -5
- package/storage/siStringEncoding.js.map +1 -1
- package/testUtils.js +16 -28
- package/testUtils.js.map +1 -1
- package/testUtils.test.js +65 -100
- package/testUtils.test.js.map +1 -1
- package/utils/NumberRange.js +2 -6
- package/utils/NumberRange.js.map +1 -1
- package/utils/NumberRange.test.js +54 -56
- package/utils/NumberRange.test.js.map +1 -1
- package/utils/NumberRangeRegistry.js +5 -42
- package/utils/NumberRangeRegistry.js.map +1 -1
- package/utils/NumberRangeRegistry.test.js +35 -37
- package/utils/NumberRangeRegistry.test.js.map +1 -1
- package/utils/bytes.js +11 -22
- package/utils/bytes.js.map +1 -1
- package/utils/bytes.test.js +98 -133
- package/utils/bytes.test.js.map +1 -1
- package/utils/errors.js +4 -11
- package/utils/errors.js.map +1 -1
- package/utils/errors.test.js +16 -51
- package/utils/errors.test.js.map +1 -1
- package/utils/events.js +3 -41
- package/utils/events.js.map +1 -1
- package/utils/events.test.js +21 -56
- package/utils/events.test.js.map +1 -1
- package/utils/general.js +4 -11
- package/utils/general.js.map +1 -1
- package/utils/general.test.js +77 -112
- package/utils/general.test.js.map +1 -1
- package/utils/index.js +8 -24
- package/utils/index.js.map +1 -1
- package/utils/mixins.js +1 -5
- package/utils/mixins.js.map +1 -1
- package/utils/mixins.test.js +13 -48
- package/utils/mixins.test.js.map +1 -1
- package/utils/typed.js +1 -4
- package/utils/typed.js.map +1 -1
- package/SiDevice/INavigatorWebSerial.d.ts +0 -62
- package/SiDevice/INavigatorWebSerial.d.ts.map +0 -1
- package/SiDevice/INavigatorWebSerial.js +0 -3
- package/SiDevice/INavigatorWebSerial.js.map +0 -1
- package/SiDevice/INavigatorWebUsb.d.ts +0 -55
- package/SiDevice/INavigatorWebUsb.d.ts.map +0 -1
- package/SiDevice/INavigatorWebUsb.js +0 -3
- package/SiDevice/INavigatorWebUsb.js.map +0 -1
package/siProtocol.test.js
CHANGED
|
@@ -1,46 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.getValidButIncompleteMessageBytes = void 0;
|
|
37
|
-
const globals_1 = require("@jest/globals");
|
|
38
|
-
const immutable_1 = require("immutable");
|
|
39
|
-
const constants_1 = require("./constants");
|
|
40
|
-
const utils = __importStar(require("./utils"));
|
|
41
|
-
const storage = __importStar(require("./storage"));
|
|
42
|
-
const testUtils = __importStar(require("./testUtils"));
|
|
43
|
-
const siProtocol = __importStar(require("./siProtocol"));
|
|
1
|
+
import { describe, expect, test } from '@jest/globals';
|
|
2
|
+
import { List } from 'immutable';
|
|
3
|
+
import { proto } from './constants';
|
|
4
|
+
import * as utils from './utils';
|
|
5
|
+
import * as storage from './storage';
|
|
6
|
+
import * as testUtils from './testUtils';
|
|
7
|
+
import * as siProtocol from './siProtocol';
|
|
44
8
|
const json2date = (str) => {
|
|
45
9
|
const res = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})\.([0-9]{3})Z$/.exec(str);
|
|
46
10
|
if (!res) {
|
|
@@ -61,7 +25,7 @@ const date2json = (date) => {
|
|
|
61
25
|
const milliseconds = date.getMilliseconds();
|
|
62
26
|
return new Date(Date.UTC(year, month, day, hours, minutes, seconds, milliseconds)).toJSON();
|
|
63
27
|
};
|
|
64
|
-
const getValidButIncompleteMessageBytes = () => {
|
|
28
|
+
export const getValidButIncompleteMessageBytes = () => {
|
|
65
29
|
const cutOffCommands = [];
|
|
66
30
|
const appendCutOffCommands = (command) => {
|
|
67
31
|
Array.from({ length: command.length }, (_, i) => i).forEach((cutOffLength) => {
|
|
@@ -74,446 +38,445 @@ const getValidButIncompleteMessageBytes = () => {
|
|
|
74
38
|
appendCutOffCommands(getRandomMessageBytes(2));
|
|
75
39
|
return cutOffCommands;
|
|
76
40
|
};
|
|
77
|
-
|
|
78
|
-
(0, globals_1.describe)('siProtocol', () => {
|
|
41
|
+
describe('siProtocol', () => {
|
|
79
42
|
const asOf = new Date('2020-01-01T00:00:00.000Z');
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
43
|
+
test('arr2date works', () => {
|
|
44
|
+
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
45
|
+
expect(date2json(siProtocol.arr2date([0x01, 0x02, 0x03], asOf))).toBe('2001-02-03T00:00:00.000Z');
|
|
46
|
+
expect(date2json(siProtocol.arr2date([0x01, 0x0c, 0x1f], asOf))).toBe('2001-12-31T00:00:00.000Z');
|
|
47
|
+
expect(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f], asOf))).toBe('2020-12-31T00:00:00.000Z');
|
|
48
|
+
expect(date2json(siProtocol.arr2date([0x15, 0x01, 0x01], asOf))).toBe('1921-01-01T00:00:00.000Z');
|
|
49
|
+
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f], asOf))).toBe('1999-12-31T00:00:00.000Z');
|
|
50
|
+
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0x00, 0x00], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
51
|
+
expect(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('2020-12-31T12:00:00.000Z');
|
|
52
|
+
expect(date2json(siProtocol.arr2date([0x15, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('1921-12-31T12:00:00.000Z');
|
|
53
|
+
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('1999-12-31T12:00:00.000Z');
|
|
54
|
+
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0xa8, 0xbf], asOf))).toBe('2000-01-01T11:59:59.000Z');
|
|
55
|
+
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0xa8, 0xbf], asOf))).toBe('1999-12-31T23:59:59.000Z');
|
|
56
|
+
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
57
|
+
expect(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x20], asOf))).toBe('2020-12-31T12:00:00.125Z');
|
|
58
|
+
expect(date2json(siProtocol.arr2date([0x15, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x60], asOf))).toBe('1921-12-31T12:00:00.375Z');
|
|
59
|
+
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x80], asOf))).toBe('1999-12-31T12:00:00.500Z');
|
|
60
|
+
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0xa8, 0xbf, 0x40], asOf))).toBe('2000-01-01T11:59:59.250Z');
|
|
61
|
+
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0xa8, 0xbf, 0xc0], asOf))).toBe('1999-12-31T23:59:59.750Z');
|
|
99
62
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
63
|
+
test('arr2date sanitizes', () => {
|
|
64
|
+
expect(() => siProtocol.arr2date([], asOf)).toThrow();
|
|
65
|
+
expect(() => siProtocol.arr2date([0x100], asOf)).toThrow();
|
|
66
|
+
expect(() => siProtocol.arr2date([0x123, 0x123], asOf)).toThrow();
|
|
67
|
+
expect(() => siProtocol.arr2date([1, 2, 3, 4], asOf)).toThrow();
|
|
68
|
+
expect(() => siProtocol.arr2date([1, 2, 3, 4, 5], asOf)).toThrow();
|
|
69
|
+
expect(() => siProtocol.arr2date([1, 2, 3, 4, 5, 6, 7, 8], asOf)).toThrow();
|
|
70
|
+
expect(siProtocol.arr2date([100, 1, 1], asOf)).toBe(undefined);
|
|
71
|
+
expect(siProtocol.arr2date([0xff, 1, 1], asOf)).toBe(undefined);
|
|
72
|
+
expect(siProtocol.arr2date([12, 0, 1], asOf)).toBe(undefined);
|
|
73
|
+
expect(siProtocol.arr2date([12, 13, 1], asOf)).toBe(undefined);
|
|
74
|
+
expect(siProtocol.arr2date([12, 0xff, 1], asOf)).toBe(undefined);
|
|
112
75
|
});
|
|
113
|
-
|
|
114
|
-
|
|
76
|
+
test('arr2date without asOf', () => {
|
|
77
|
+
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01]))).toBe('2000-01-01T00:00:00.000Z');
|
|
115
78
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
79
|
+
test('date2arr', () => {
|
|
80
|
+
expect(siProtocol.date2arr(json2date('2000-01-01T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x01, 0x0c, 0x00, 0x00, 0x00]);
|
|
81
|
+
expect(siProtocol.date2arr(json2date('2000-01-01T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x01, 0x0d, 0x00, 0x00, 0x00]);
|
|
82
|
+
expect(siProtocol.date2arr(json2date('2000-01-02T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00]);
|
|
83
|
+
expect(siProtocol.date2arr(json2date('2000-01-02T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00]);
|
|
84
|
+
expect(siProtocol.date2arr(json2date('2000-01-03T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x03, 0x02, 0x00, 0x00, 0x00]);
|
|
85
|
+
expect(siProtocol.date2arr(json2date('2000-01-03T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00]);
|
|
86
|
+
expect(siProtocol.date2arr(json2date('2000-01-04T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x04, 0x04, 0x00, 0x00, 0x00]);
|
|
87
|
+
expect(siProtocol.date2arr(json2date('2000-01-04T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x04, 0x05, 0x00, 0x00, 0x00]);
|
|
88
|
+
expect(siProtocol.date2arr(json2date('2000-01-05T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x05, 0x06, 0x00, 0x00, 0x00]);
|
|
89
|
+
expect(siProtocol.date2arr(json2date('2000-01-05T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x05, 0x07, 0x00, 0x00, 0x00]);
|
|
90
|
+
expect(siProtocol.date2arr(json2date('2000-01-06T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x06, 0x08, 0x00, 0x00, 0x00]);
|
|
91
|
+
expect(siProtocol.date2arr(json2date('2000-01-06T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x06, 0x09, 0x00, 0x00, 0x00]);
|
|
92
|
+
expect(siProtocol.date2arr(json2date('2000-01-07T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x07, 0x0a, 0x00, 0x00, 0x00]);
|
|
93
|
+
expect(siProtocol.date2arr(json2date('2000-01-07T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x07, 0x0b, 0x00, 0x00, 0x00]);
|
|
94
|
+
expect(siProtocol.date2arr(json2date('2099-12-31T12:00:00.500Z'))).toEqual([0x63, 0x0c, 0x1f, 0x09, 0x00, 0x00, 0x80]);
|
|
95
|
+
expect(siProtocol.date2arr(json2date('2000-01-01T11:59:59.250Z'))).toEqual([0x00, 0x01, 0x01, 0x0c, 0xa8, 0xbf, 0x40]);
|
|
96
|
+
expect(siProtocol.date2arr(json2date('1999-12-31T23:59:59.750Z'))).toEqual([0x63, 0x0c, 0x1f, 0x0b, 0xa8, 0xbf, 0xc0]);
|
|
134
97
|
});
|
|
135
|
-
|
|
98
|
+
test('date2arr and arr2date do the reverse', () => {
|
|
136
99
|
const forthAndBack = (date) => siProtocol.arr2date(siProtocol.date2arr(date), asOf);
|
|
137
100
|
const forthAndBackAsJson = (str) => date2json(forthAndBack(json2date(str)));
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
101
|
+
expect(forthAndBackAsJson('2000-01-01T00:00:00.000Z')).toBe('2000-01-01T00:00:00.000Z');
|
|
102
|
+
expect(forthAndBackAsJson('2001-02-03T00:00:00.000Z')).toBe('2001-02-03T00:00:00.000Z');
|
|
103
|
+
expect(forthAndBackAsJson('2001-12-31T00:00:00.000Z')).toBe('2001-12-31T00:00:00.000Z');
|
|
104
|
+
expect(forthAndBackAsJson('2020-12-31T00:00:00.000Z')).toBe('2020-12-31T00:00:00.000Z');
|
|
105
|
+
expect(forthAndBackAsJson('1921-01-01T00:00:00.000Z')).toBe('1921-01-01T00:00:00.000Z');
|
|
106
|
+
expect(forthAndBackAsJson('1999-12-31T00:00:00.000Z')).toBe('1999-12-31T00:00:00.000Z');
|
|
107
|
+
expect(forthAndBackAsJson('2000-01-01T06:30:00.000Z')).toBe('2000-01-01T06:30:00.000Z');
|
|
108
|
+
expect(forthAndBackAsJson('2020-12-31T13:27:30.000Z')).toBe('2020-12-31T13:27:30.000Z');
|
|
109
|
+
expect(forthAndBackAsJson('1921-12-31T12:00:00.000Z')).toBe('1921-12-31T12:00:00.000Z');
|
|
110
|
+
expect(forthAndBackAsJson('1999-12-31T12:00:00.000Z')).toBe('1999-12-31T12:00:00.000Z');
|
|
111
|
+
expect(forthAndBackAsJson('2000-01-01T11:59:59.000Z')).toBe('2000-01-01T11:59:59.000Z');
|
|
112
|
+
expect(forthAndBackAsJson('1999-12-31T23:59:59.000Z')).toBe('1999-12-31T23:59:59.000Z');
|
|
113
|
+
expect(forthAndBackAsJson('2000-01-01T00:00:00.000Z')).toBe('2000-01-01T00:00:00.000Z');
|
|
114
|
+
expect(forthAndBackAsJson('2020-12-31T12:00:00.125Z')).toBe('2020-12-31T12:00:00.125Z');
|
|
115
|
+
expect(forthAndBackAsJson('1921-12-31T12:00:00.375Z')).toBe('1921-12-31T12:00:00.375Z');
|
|
116
|
+
expect(forthAndBackAsJson('1999-12-31T12:00:00.500Z')).toBe('1999-12-31T12:00:00.500Z');
|
|
117
|
+
expect(forthAndBackAsJson('2000-01-01T11:59:59.250Z')).toBe('2000-01-01T11:59:59.250Z');
|
|
118
|
+
expect(forthAndBackAsJson('1999-12-31T23:59:59.750Z')).toBe('1999-12-31T23:59:59.750Z');
|
|
156
119
|
});
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
120
|
+
test('arr2cardNumber works', () => {
|
|
121
|
+
expect(siProtocol.arr2cardNumber([0x00, 0x00, 0x00])).toBe(0x000000);
|
|
122
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x00])).toBe(0x003412);
|
|
123
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x01])).toBe(0x003412 + 1 * 100000);
|
|
124
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x02])).toBe(0x003412 + 2 * 100000);
|
|
125
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x03])).toBe(0x003412 + 3 * 100000);
|
|
126
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x04])).toBe(0x003412 + 4 * 100000);
|
|
164
127
|
// the following should actually never appear, as 0x053412 = 341010, which would be represented differently
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
128
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x05])).toBe(0x053412);
|
|
129
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x08])).toBe(0x083412);
|
|
130
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x56])).toBe(0x563412);
|
|
131
|
+
expect(siProtocol.arr2cardNumber([0x00, 0x00, 0x00, 0x00])).toBe(0x00000000);
|
|
132
|
+
expect(siProtocol.arr2cardNumber([0x00, 0x00, 0x00, 0x01])).toBe(0x01000000);
|
|
133
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x56, 0x78])).toBe(0x78563412);
|
|
134
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x56, undefined])).toBe(undefined);
|
|
135
|
+
expect(siProtocol.arr2cardNumber([0x12, 0x34, undefined, 0x78])).toBe(undefined);
|
|
136
|
+
expect(siProtocol.arr2cardNumber([0x12, undefined, 0x56, 0x78])).toBe(undefined);
|
|
137
|
+
expect(siProtocol.arr2cardNumber([undefined, 0x34, 0x56, 0x78])).toBe(undefined);
|
|
175
138
|
});
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
139
|
+
test('arr2cardNumber sanitizes', () => {
|
|
140
|
+
expect(() => siProtocol.arr2cardNumber([])).toThrow();
|
|
141
|
+
expect(() => siProtocol.arr2cardNumber([1])).toThrow();
|
|
142
|
+
expect(() => siProtocol.arr2cardNumber([1, 2])).toThrow();
|
|
143
|
+
expect(() => siProtocol.arr2cardNumber([1, 2, 3, 4, 5])).toThrow();
|
|
144
|
+
expect(() => siProtocol.arr2cardNumber([1, 2, 3, 4, 5, 6, 7, 8])).toThrow();
|
|
182
145
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
146
|
+
test('cardNumber2arr works', () => {
|
|
147
|
+
expect(siProtocol.cardNumber2arr(0x000000)).toEqual([0x00, 0x00, 0x00, 0x00]);
|
|
148
|
+
expect(siProtocol.cardNumber2arr(0x003412)).toEqual([0x12, 0x34, 0x00, 0x00]);
|
|
149
|
+
expect(siProtocol.cardNumber2arr(0x003412 + 1 * 100000)).toEqual([0x12, 0x34, 0x01, 0x00]);
|
|
150
|
+
expect(siProtocol.cardNumber2arr(0x003412 + 2 * 100000)).toEqual([0x12, 0x34, 0x02, 0x00]);
|
|
151
|
+
expect(siProtocol.cardNumber2arr(0x003412 + 3 * 100000)).toEqual([0x12, 0x34, 0x03, 0x00]);
|
|
152
|
+
expect(siProtocol.cardNumber2arr(0x003412 + 4 * 100000)).toEqual([0x12, 0x34, 0x04, 0x00]);
|
|
153
|
+
expect(siProtocol.cardNumber2arr(0x083412)).toEqual([0x12, 0x34, 0x08, 0x00]);
|
|
154
|
+
expect(siProtocol.cardNumber2arr(0x563412)).toEqual([0x12, 0x34, 0x56, 0x00]);
|
|
155
|
+
expect(siProtocol.cardNumber2arr(0x00000000)).toEqual([0x00, 0x00, 0x00, 0x00]);
|
|
156
|
+
expect(siProtocol.cardNumber2arr(0x01000000)).toEqual([0x00, 0x00, 0x00, 0x01]);
|
|
157
|
+
expect(siProtocol.cardNumber2arr(0x78563412)).toEqual([0x12, 0x34, 0x56, 0x78]);
|
|
158
|
+
expect(siProtocol.cardNumber2arr(undefined)).toEqual([undefined, undefined, undefined, undefined]);
|
|
196
159
|
});
|
|
197
|
-
|
|
160
|
+
test('consistent cardNumber <=> arr conversion', () => {
|
|
198
161
|
const cardNumbers = [1000, 10000, 65535, 100000, 165535, 200000, 265535, 300000, 365535, 400000, 465535, 500000, 599999, 999999, 1000000, 1999999, 2000000, 2999999];
|
|
199
162
|
cardNumbers.forEach((cardNumber) => {
|
|
200
163
|
const arr = siProtocol.cardNumber2arr(cardNumber);
|
|
201
164
|
const restoredCardNumber = siProtocol.arr2cardNumber(arr);
|
|
202
|
-
|
|
165
|
+
expect(restoredCardNumber).toEqual(cardNumber);
|
|
203
166
|
});
|
|
204
167
|
});
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
168
|
+
test('prettyMessage', () => {
|
|
169
|
+
expect(siProtocol.prettyMessage({ command: proto.cmd.GET_MS, parameters: [] }).length > 3).toBe(true);
|
|
170
|
+
expect(siProtocol.prettyMessage({ mode: proto.ACK }).length > 3).toBe(true);
|
|
208
171
|
});
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
172
|
+
test('CRC16', () => {
|
|
173
|
+
expect(siProtocol.CRC16([])).toEqual([0x00, 0x00]);
|
|
174
|
+
expect(siProtocol.CRC16([0x01])).toEqual([0x01, 0x00]);
|
|
175
|
+
expect(siProtocol.CRC16([0x12])).toEqual([0x12, 0x00]);
|
|
176
|
+
expect(siProtocol.CRC16([0xff])).toEqual([0xff, 0x00]);
|
|
177
|
+
expect(siProtocol.CRC16([0x01, 0x02])).toEqual([0x01, 0x02]);
|
|
178
|
+
expect(siProtocol.CRC16([0x12, 0x34])).toEqual([0x12, 0x34]);
|
|
179
|
+
expect(siProtocol.CRC16([0x12, 0x34, 0x56])).toEqual([0xba, 0xbb]);
|
|
180
|
+
expect(siProtocol.CRC16([0x12, 0x32, 0x56])).toEqual([0xba, 0xaf]);
|
|
181
|
+
expect(siProtocol.CRC16([0x12, 0x34, 0x56, 0x78])).toEqual([0x1e, 0x83]);
|
|
182
|
+
expect(siProtocol.CRC16([0x12, 0x32, 0x56, 0x78])).toEqual([0x1e, 0xfb]);
|
|
220
183
|
});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
message: { mode:
|
|
184
|
+
test('parse WAKEUP', () => {
|
|
185
|
+
expect(siProtocol.parse([proto.WAKEUP])).toEqual({
|
|
186
|
+
message: { mode: proto.WAKEUP },
|
|
224
187
|
remainder: []
|
|
225
188
|
});
|
|
226
189
|
const randomByte = testUtils.getRandomByte();
|
|
227
|
-
|
|
228
|
-
message: { mode:
|
|
190
|
+
expect(siProtocol.parse([proto.WAKEUP, randomByte])).toEqual({
|
|
191
|
+
message: { mode: proto.WAKEUP },
|
|
229
192
|
remainder: [randomByte]
|
|
230
193
|
});
|
|
231
194
|
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
message: { mode:
|
|
195
|
+
test('parse ACK', () => {
|
|
196
|
+
expect(siProtocol.parse([proto.ACK])).toEqual({
|
|
197
|
+
message: { mode: proto.ACK },
|
|
235
198
|
remainder: []
|
|
236
199
|
});
|
|
237
200
|
const randomByte = testUtils.getRandomByte();
|
|
238
|
-
|
|
239
|
-
message: { mode:
|
|
201
|
+
expect(siProtocol.parse([proto.ACK, randomByte])).toEqual({
|
|
202
|
+
message: { mode: proto.ACK },
|
|
240
203
|
remainder: [randomByte]
|
|
241
204
|
});
|
|
242
205
|
});
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
message: { mode:
|
|
206
|
+
test('parse NAK', () => {
|
|
207
|
+
expect(siProtocol.parse([proto.NAK])).toEqual({
|
|
208
|
+
message: { mode: proto.NAK },
|
|
246
209
|
remainder: []
|
|
247
210
|
});
|
|
248
211
|
const randomByte = testUtils.getRandomByte();
|
|
249
|
-
|
|
250
|
-
message: { mode:
|
|
212
|
+
expect(siProtocol.parse([proto.NAK, randomByte])).toEqual({
|
|
213
|
+
message: { mode: proto.NAK },
|
|
251
214
|
remainder: [randomByte]
|
|
252
215
|
});
|
|
253
216
|
});
|
|
254
|
-
|
|
255
|
-
const invalidStartByte = testUtils.getRandomByteExcept([
|
|
217
|
+
test('parse with invalid start byte', () => {
|
|
218
|
+
const invalidStartByte = testUtils.getRandomByteExcept([proto.STX, proto.WAKEUP, proto.NAK]);
|
|
256
219
|
console.debug(`Chosen invalid start byte: ${utils.prettyHex([invalidStartByte])}`);
|
|
257
|
-
|
|
220
|
+
expect(siProtocol.parse([invalidStartByte])).toEqual({ message: null, remainder: [] });
|
|
258
221
|
const randomByte = testUtils.getRandomByte();
|
|
259
|
-
|
|
222
|
+
expect(siProtocol.parse([invalidStartByte, randomByte])).toEqual({
|
|
260
223
|
message: null,
|
|
261
224
|
remainder: [randomByte]
|
|
262
225
|
});
|
|
263
226
|
});
|
|
264
|
-
|
|
227
|
+
test('parse command without remainder', () => {
|
|
265
228
|
const parseForMessage = (message) => siProtocol.parse(siProtocol.render(message)).message;
|
|
266
|
-
|
|
229
|
+
expect(parseForMessage({ command: 0x00, parameters: [] })).toEqual({
|
|
267
230
|
command: 0x00,
|
|
268
231
|
parameters: []
|
|
269
232
|
});
|
|
270
|
-
|
|
233
|
+
expect(parseForMessage({ command: 0xff, parameters: [0xee] })).toEqual({
|
|
271
234
|
command: 0xff,
|
|
272
235
|
parameters: [0xee]
|
|
273
236
|
});
|
|
274
237
|
});
|
|
275
|
-
|
|
238
|
+
test('parse command with remainder', () => {
|
|
276
239
|
const parseForMessageWithRemainder = (message) => siProtocol.parse([...siProtocol.render(message), 0xdd]);
|
|
277
|
-
|
|
240
|
+
expect(parseForMessageWithRemainder({ command: 0x00, parameters: [] })).toEqual({
|
|
278
241
|
message: { command: 0x00, parameters: [] },
|
|
279
242
|
remainder: [0xdd]
|
|
280
243
|
});
|
|
281
|
-
|
|
244
|
+
expect(parseForMessageWithRemainder({ command: 0xff, parameters: [0xee] })).toEqual({
|
|
282
245
|
message: { command: 0xff, parameters: [0xee] },
|
|
283
246
|
remainder: [0xdd]
|
|
284
247
|
});
|
|
285
248
|
});
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
249
|
+
test('parse incomplete but valid command', () => {
|
|
250
|
+
getValidButIncompleteMessageBytes().forEach((cutOffCommand) => {
|
|
251
|
+
expect(siProtocol.parse(cutOffCommand)).toEqual({ message: null, remainder: cutOffCommand });
|
|
289
252
|
});
|
|
290
253
|
});
|
|
291
|
-
|
|
292
|
-
const invalidETX = testUtils.getRandomByteExcept([
|
|
254
|
+
test('parse command with invalid ETX', () => {
|
|
255
|
+
const invalidETX = testUtils.getRandomByteExcept([proto.ETX]);
|
|
293
256
|
console.debug(`Chosen invalid ETX: ${utils.prettyHex([invalidETX])}`);
|
|
294
|
-
|
|
257
|
+
expect(siProtocol.parse([proto.STX, 0x00, 0x00, 0x00, 0x00, invalidETX])).toEqual({
|
|
295
258
|
message: null,
|
|
296
259
|
remainder: [0x00, 0x00, 0x00, 0x00, invalidETX]
|
|
297
260
|
});
|
|
298
|
-
|
|
261
|
+
expect(siProtocol.parse([proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, invalidETX])).toEqual({
|
|
299
262
|
message: null,
|
|
300
263
|
remainder: [0xff, 0x01, 0xee, 0x00, 0x01, invalidETX]
|
|
301
264
|
});
|
|
302
|
-
|
|
265
|
+
expect(siProtocol.parse([proto.STX, 0x00, 0x00, 0x00, 0x01, invalidETX, 0xdd])).toEqual({
|
|
303
266
|
message: null,
|
|
304
267
|
remainder: [0x00, 0x00, 0x00, 0x01, invalidETX, 0xdd]
|
|
305
268
|
});
|
|
306
|
-
|
|
269
|
+
expect(siProtocol.parse([proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, invalidETX, 0xdd])).toEqual({
|
|
307
270
|
message: null,
|
|
308
271
|
remainder: [0xff, 0x01, 0xee, 0x00, 0x01, invalidETX, 0xdd]
|
|
309
272
|
});
|
|
310
273
|
});
|
|
311
|
-
|
|
312
|
-
|
|
274
|
+
test('parse command with invalid CRC', () => {
|
|
275
|
+
expect(siProtocol.parse([proto.STX, 0x00, 0x00, 0x00, 0x01, proto.ETX])).toEqual({
|
|
313
276
|
message: null,
|
|
314
277
|
remainder: []
|
|
315
278
|
});
|
|
316
|
-
|
|
279
|
+
expect(siProtocol.parse([proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, proto.ETX])).toEqual({
|
|
317
280
|
message: null,
|
|
318
281
|
remainder: []
|
|
319
282
|
});
|
|
320
|
-
|
|
283
|
+
expect(siProtocol.parse([proto.STX, 0x00, 0x00, 0x00, 0x01, proto.ETX, 0xdd])).toEqual({
|
|
321
284
|
message: null,
|
|
322
285
|
remainder: [0xdd]
|
|
323
286
|
});
|
|
324
|
-
|
|
287
|
+
expect(siProtocol.parse([proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, proto.ETX, 0xdd])).toEqual({
|
|
325
288
|
message: null,
|
|
326
289
|
remainder: [0xdd]
|
|
327
290
|
});
|
|
328
291
|
});
|
|
329
|
-
|
|
292
|
+
test('parseAll without remainder', () => {
|
|
330
293
|
const stream0 = [];
|
|
331
|
-
|
|
294
|
+
expect(siProtocol.parseAll(stream0)).toEqual({
|
|
332
295
|
messages: [],
|
|
333
296
|
remainder: []
|
|
334
297
|
});
|
|
335
298
|
const stream1 = siProtocol.render({ command: 0x00, parameters: [] });
|
|
336
|
-
|
|
299
|
+
expect(siProtocol.parseAll(stream1)).toEqual({
|
|
337
300
|
messages: [{ command: 0x00, parameters: [] }],
|
|
338
301
|
remainder: []
|
|
339
302
|
});
|
|
340
|
-
const stream2 = [...siProtocol.render({ command: 0x00, parameters: [] }),
|
|
341
|
-
|
|
342
|
-
messages: [{ command: 0x00, parameters: [] }, { mode:
|
|
303
|
+
const stream2 = [...siProtocol.render({ command: 0x00, parameters: [] }), proto.WAKEUP, ...siProtocol.render({ command: 0xff, parameters: [0xee] })];
|
|
304
|
+
expect(siProtocol.parseAll(stream2)).toEqual({
|
|
305
|
+
messages: [{ command: 0x00, parameters: [] }, { mode: proto.WAKEUP }, { command: 0xff, parameters: [0xee] }],
|
|
343
306
|
remainder: []
|
|
344
307
|
});
|
|
345
308
|
});
|
|
346
|
-
|
|
347
|
-
|
|
309
|
+
test('parseAll with valid remainder', () => {
|
|
310
|
+
getValidButIncompleteMessageBytes().forEach((cutOffCommand) => {
|
|
348
311
|
const stream0 = [...cutOffCommand];
|
|
349
|
-
|
|
312
|
+
expect(siProtocol.parseAll(stream0)).toEqual({
|
|
350
313
|
messages: [],
|
|
351
314
|
remainder: cutOffCommand
|
|
352
315
|
});
|
|
353
|
-
const stream1 = [...siProtocol.render({ command: 0x00, parameters: [] }),
|
|
354
|
-
|
|
355
|
-
messages: [{ command: 0x00, parameters: [] }, { mode:
|
|
316
|
+
const stream1 = [...siProtocol.render({ command: 0x00, parameters: [] }), proto.NAK, ...cutOffCommand];
|
|
317
|
+
expect(siProtocol.parseAll(stream1)).toEqual({
|
|
318
|
+
messages: [{ command: 0x00, parameters: [] }, { mode: proto.NAK }],
|
|
356
319
|
remainder: cutOffCommand
|
|
357
320
|
});
|
|
358
|
-
const stream2 = [
|
|
359
|
-
|
|
360
|
-
messages: [{ mode:
|
|
321
|
+
const stream2 = [proto.WAKEUP, ...siProtocol.render({ command: 0x00, parameters: [] }), ...siProtocol.render({ command: 0xff, parameters: [0xee] }), ...cutOffCommand];
|
|
322
|
+
expect(siProtocol.parseAll(stream2)).toEqual({
|
|
323
|
+
messages: [{ mode: proto.WAKEUP }, { command: 0x00, parameters: [] }, { command: 0xff, parameters: [0xee] }],
|
|
361
324
|
remainder: cutOffCommand
|
|
362
325
|
});
|
|
363
326
|
});
|
|
364
327
|
});
|
|
365
|
-
|
|
366
|
-
|
|
328
|
+
test('render ACK', () => {
|
|
329
|
+
expect(siProtocol.render({ mode: proto.ACK })).toEqual([proto.ACK]);
|
|
367
330
|
});
|
|
368
|
-
|
|
369
|
-
|
|
331
|
+
test('render NAK', () => {
|
|
332
|
+
expect(siProtocol.render({ mode: proto.NAK })).toEqual([proto.NAK]);
|
|
370
333
|
});
|
|
371
|
-
|
|
372
|
-
|
|
334
|
+
test('render WAKEUP', () => {
|
|
335
|
+
expect(siProtocol.render({ mode: proto.WAKEUP })).toEqual([proto.WAKEUP]);
|
|
373
336
|
});
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
337
|
+
test('render command', () => {
|
|
338
|
+
expect(siProtocol.render({ command: 0x00, parameters: [] })).toEqual([proto.STX, 0x00, 0x00, 0x00, 0x00, proto.ETX]);
|
|
339
|
+
expect(siProtocol.render({ command: 0xff, parameters: [0xee] })).toEqual([proto.STX, 0xff, 0x01, 0xee, 0xec, 0x0a, proto.ETX]);
|
|
340
|
+
expect(siProtocol.render({ mode: undefined, command: 0x00, parameters: [] })).toEqual([proto.STX, 0x00, 0x00, 0x00, 0x00, proto.ETX]);
|
|
341
|
+
expect(siProtocol.render({ mode: undefined, command: 0xff, parameters: [0xee] })).toEqual([proto.STX, 0xff, 0x01, 0xee, 0xec, 0x0a, proto.ETX]);
|
|
379
342
|
});
|
|
380
|
-
|
|
381
|
-
const invalidMode = testUtils.getRandomByteExcept([
|
|
382
|
-
|
|
343
|
+
test('render invalid mode', () => {
|
|
344
|
+
const invalidMode = testUtils.getRandomByteExcept([proto.WAKEUP, proto.NAK, proto.ACK]);
|
|
345
|
+
expect(() => siProtocol.render({ mode: invalidMode })).toThrow();
|
|
383
346
|
});
|
|
384
|
-
|
|
347
|
+
test('SiDate SiStorage integration', () => {
|
|
385
348
|
const weirdStorage = storage.defineStorage(0x09, {
|
|
386
349
|
weirdDate: new siProtocol.SiDate(3, (i) => i),
|
|
387
350
|
crazyDate: new siProtocol.SiDate(6, (i) => 0x03 + i)
|
|
388
351
|
});
|
|
389
352
|
const myWeirdStorage = weirdStorage(utils.unPrettyHex('0F 03 07 00 00 00 00 00 00'));
|
|
390
|
-
|
|
353
|
+
expect(myWeirdStorage.get('weirdDate').value).toEqual(new Date(2015, 2, 7));
|
|
391
354
|
myWeirdStorage.set('weirdDate', new Date(2017, 12, 30));
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
355
|
+
expect(myWeirdStorage.data.toJS()).toEqual(utils.unPrettyHex('12 01 1E 00 00 00 00 00 00'));
|
|
356
|
+
expect(myWeirdStorage.get('weirdDate').value).toEqual(new Date(2017, 12, 30));
|
|
357
|
+
expect(myWeirdStorage.get('crazyDate')).toEqual(undefined);
|
|
395
358
|
myWeirdStorage.set('crazyDate', new Date(2003, 1, 30, 3, 7, 5));
|
|
396
|
-
|
|
397
|
-
|
|
359
|
+
expect(myWeirdStorage.data.toJS()).toEqual(utils.unPrettyHex('12 01 1E 03 03 02 00 2B D9'));
|
|
360
|
+
expect(myWeirdStorage.get('crazyDate').value).toEqual(new Date(2003, 1, 30, 3, 7, 5));
|
|
398
361
|
const unknownWeirdStorage = weirdStorage();
|
|
399
362
|
const ModifyUndefinedException = storage.ModifyUndefinedException;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
363
|
+
expect(unknownWeirdStorage.get('weirdDate')).toBe(undefined);
|
|
364
|
+
expect(() => unknownWeirdStorage.set('weirdDate', new Date(2017, 12, 30))).toThrow(ModifyUndefinedException);
|
|
365
|
+
expect(unknownWeirdStorage.get('crazyDate')).toBe(undefined);
|
|
366
|
+
expect(() => unknownWeirdStorage.set('crazyDate', new Date(2003, 1, 30, 3, 7, 5))).toThrow(ModifyUndefinedException);
|
|
404
367
|
});
|
|
405
|
-
|
|
368
|
+
describe('SiDate', () => {
|
|
406
369
|
const mySiDate = new siProtocol.SiDate(3, (i) => i);
|
|
407
370
|
const fieldValueOf = (value) => new storage.SiFieldValue(mySiDate, value);
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
const data =
|
|
371
|
+
test('typeSpecificIsValueValid', () => {
|
|
372
|
+
expect(mySiDate.typeSpecificIsValueValid(new Date())).toBe(true);
|
|
373
|
+
});
|
|
374
|
+
test('valueToString', () => {
|
|
375
|
+
expect(mySiDate.valueToString(json2date('2000-01-01T00:00:00.000Z'))).toBe('2000-01-01T00:00:00.000Z');
|
|
376
|
+
expect(mySiDate.valueToString(json2date('2020-12-31T13:27:30.000Z'))).toBe('2020-12-31T13:27:30.000Z');
|
|
377
|
+
});
|
|
378
|
+
test('valueFromString', () => {
|
|
379
|
+
expect(mySiDate.valueFromString('2000-01-01T00:00:00.000Z')).toEqual(json2date('2000-01-01T00:00:00.000Z'));
|
|
380
|
+
expect(mySiDate.valueFromString('2020-12-31T13:27:30.000Z')).toEqual(json2date('2020-12-31T13:27:30.000Z'));
|
|
381
|
+
expect(mySiDate.valueFromString('2020-12-31T13:27:30.000') instanceof storage.ValueFromStringError).toBe(true);
|
|
382
|
+
expect(mySiDate.valueFromString('2020-12-31T13:27:30Z') instanceof storage.ValueFromStringError).toBe(true);
|
|
383
|
+
expect(mySiDate.valueFromString('2020-12-31Z') instanceof storage.ValueFromStringError).toBe(true);
|
|
384
|
+
expect(mySiDate.valueFromString('2020-12-31') instanceof storage.ValueFromStringError).toBe(true);
|
|
385
|
+
expect(mySiDate.valueFromString('test') instanceof storage.ValueFromStringError).toBe(true);
|
|
386
|
+
});
|
|
387
|
+
test('extractFromData gives field value', () => {
|
|
388
|
+
const data = List([0x00, 0x01, 0x01]);
|
|
426
389
|
const fieldValue = mySiDate.extractFromData(data);
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
const getExtractedFieldValue = (bytes) => mySiDate.extractFromData(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
const initialData =
|
|
390
|
+
expect(fieldValue instanceof storage.SiFieldValue).toBe(true);
|
|
391
|
+
expect(fieldValue.field).toBe(mySiDate);
|
|
392
|
+
expect(fieldValue.value).toEqual(json2date('2000-01-01T00:00:00.000Z'));
|
|
393
|
+
});
|
|
394
|
+
test('extractFromData', () => {
|
|
395
|
+
const getExtractedFieldValue = (bytes) => mySiDate.extractFromData(List(bytes));
|
|
396
|
+
expect(getExtractedFieldValue([0x00, 0x01, 0x01]).value instanceof Date).toBe(true);
|
|
397
|
+
expect(getExtractedFieldValue([0x00, 0x01, undefined])).toBe(undefined);
|
|
398
|
+
expect(getExtractedFieldValue([0x00, undefined, 0x01])).toBe(undefined);
|
|
399
|
+
expect(getExtractedFieldValue([undefined, 0x00, 0x01])).toBe(undefined);
|
|
400
|
+
expect(getExtractedFieldValue([0x00])).toBe(undefined);
|
|
401
|
+
expect(getExtractedFieldValue([])).toBe(undefined);
|
|
402
|
+
});
|
|
403
|
+
test('updateData', () => {
|
|
404
|
+
const initialData = List([0x00, 0x00, 0x00]);
|
|
442
405
|
const updateInitialData = (newValue) => mySiDate.updateData(initialData, newValue).toJS();
|
|
443
|
-
|
|
444
|
-
|
|
406
|
+
expect(updateInitialData(json2date('2000-01-01T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x01]);
|
|
407
|
+
expect(updateInitialData(fieldValueOf(json2date('2000-01-01T00:00:00.000Z')))).toEqual([0x00, 0x01, 0x01]);
|
|
445
408
|
});
|
|
446
|
-
|
|
447
|
-
const updateData = (data, newValue) => mySiDate.updateData(
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
409
|
+
test('updateData modify undefined', () => {
|
|
410
|
+
const updateData = (data, newValue) => mySiDate.updateData(List(data), newValue).toJS();
|
|
411
|
+
expect(() => updateData([], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
412
|
+
expect(() => updateData([], fieldValueOf(json2date('2000-01-01T00:00:00.000Z')))).toThrow(storage.ModifyUndefinedException);
|
|
413
|
+
expect(() => updateData([0x00, 0x00, undefined], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
414
|
+
expect(() => updateData([0x00, undefined, 0x00], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
415
|
+
expect(() => updateData([undefined, 0x00, 0x00], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
453
416
|
});
|
|
454
417
|
});
|
|
455
|
-
|
|
418
|
+
describe('SiTime', () => {
|
|
456
419
|
const mySiTime = new siProtocol.SiTime([[0x01], [0x00]]);
|
|
457
420
|
const myInexistentSiTime = new siProtocol.SiTime(undefined);
|
|
458
421
|
const fieldValueOf = (value) => new storage.SiFieldValue(mySiTime, value);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
const data =
|
|
422
|
+
test('typeSpecificIsValueValid', () => {
|
|
423
|
+
expect(mySiTime.typeSpecificIsValueValid({ time: 0 })).toBe(true);
|
|
424
|
+
expect(mySiTime.typeSpecificIsValueValid({ time: 43199 })).toBe(true);
|
|
425
|
+
expect(mySiTime.typeSpecificIsValueValid({ time: 86400 })).toBe(false);
|
|
426
|
+
expect(mySiTime.typeSpecificIsValueValid(null)).toBe(true);
|
|
427
|
+
});
|
|
428
|
+
test('valueToString', () => {
|
|
429
|
+
expect(mySiTime.valueToString({ time: 0 })).toBe('00:00:00');
|
|
430
|
+
expect(mySiTime.valueToString({ time: 43199 })).toBe('11:59:59');
|
|
431
|
+
expect(mySiTime.valueToString(null)).toBe('NO_TIME');
|
|
432
|
+
});
|
|
433
|
+
test('valueFromString', () => {
|
|
434
|
+
expect(mySiTime.valueFromString('00:00:00')).toEqual({ time: 0 });
|
|
435
|
+
expect(mySiTime.valueFromString('11:59:59')).toEqual({ time: 43199 });
|
|
436
|
+
expect(mySiTime.valueFromString('NO_TIME')).toBe(null);
|
|
437
|
+
expect(mySiTime.valueFromString('06:12') instanceof storage.ValueFromStringError).toBe(true);
|
|
438
|
+
expect(mySiTime.valueFromString('test') instanceof storage.ValueFromStringError).toBe(true);
|
|
439
|
+
});
|
|
440
|
+
test('extractFromData gives field value', () => {
|
|
441
|
+
const data = List([0x01, 0x01]);
|
|
479
442
|
const fieldValue = mySiTime.extractFromData(data);
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
const getExtractedFieldValue = (bytes) => mySiTime.extractFromData(
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
const getExtractedFieldValue = (bytes) => myInexistentSiTime.extractFromData(
|
|
495
|
-
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
const initialData =
|
|
443
|
+
expect(fieldValue instanceof storage.SiFieldValue).toBe(true);
|
|
444
|
+
expect(fieldValue.field).toBe(mySiTime);
|
|
445
|
+
expect(JSON.stringify(fieldValue.value)).toBe(JSON.stringify({ time: 257, weekcounter: undefined, weekday: undefined }));
|
|
446
|
+
});
|
|
447
|
+
test('extractFromData', () => {
|
|
448
|
+
const getExtractedFieldValue = (bytes) => mySiTime.extractFromData(List(bytes));
|
|
449
|
+
expect(JSON.stringify(getExtractedFieldValue([0x00, 0x01]).value)).toBe(JSON.stringify({ time: 1, weekcounter: undefined, weekday: undefined }));
|
|
450
|
+
expect(getExtractedFieldValue([0xee, 0xee]).value).toBe(null);
|
|
451
|
+
expect(getExtractedFieldValue([0x00, undefined])).toBe(undefined);
|
|
452
|
+
expect(getExtractedFieldValue([undefined, 0x01])).toBe(undefined);
|
|
453
|
+
expect(getExtractedFieldValue([0x00])).toBe(undefined);
|
|
454
|
+
expect(getExtractedFieldValue([])).toBe(undefined);
|
|
455
|
+
});
|
|
456
|
+
test('extractFromData for inexistent', () => {
|
|
457
|
+
const getExtractedFieldValue = (bytes) => myInexistentSiTime.extractFromData(List(bytes));
|
|
458
|
+
expect(getExtractedFieldValue([0x00, 0x01]).value).toBe(null);
|
|
459
|
+
});
|
|
460
|
+
test('updateData', () => {
|
|
461
|
+
const initialData = List([0x00, 0x00]);
|
|
499
462
|
const updateInitialData = (newValue) => mySiTime.updateData(initialData, newValue).toJS();
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
463
|
+
expect(updateInitialData({ time: 257 })).toEqual([0x01, 0x01]);
|
|
464
|
+
expect(updateInitialData(fieldValueOf({ time: 257 }))).toEqual([0x01, 0x01]);
|
|
465
|
+
expect(updateInitialData(null)).toEqual([0xee, 0xee]);
|
|
466
|
+
expect(updateInitialData(fieldValueOf(null))).toEqual([0xee, 0xee]);
|
|
504
467
|
});
|
|
505
|
-
|
|
506
|
-
const initialData =
|
|
468
|
+
test('updateData for inexistent', () => {
|
|
469
|
+
const initialData = List([0x00, 0x00]);
|
|
507
470
|
const updateInitialData = (newValue) => myInexistentSiTime.updateData(initialData, newValue).toJS();
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
const updateData = (data, newValue) => mySiTime.updateData(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
471
|
+
expect(updateInitialData({ time: 257 })).toEqual([0x00, 0x00]);
|
|
472
|
+
expect(updateInitialData(fieldValueOf({ time: 257 }))).toEqual([0x00, 0x00]);
|
|
473
|
+
});
|
|
474
|
+
test('updateData modify undefined', () => {
|
|
475
|
+
const updateData = (data, newValue) => mySiTime.updateData(List(data), newValue).toJS();
|
|
476
|
+
expect(() => updateData([], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
477
|
+
expect(() => updateData([], fieldValueOf({ time: 257 }))).toThrow(storage.ModifyUndefinedException);
|
|
478
|
+
expect(() => updateData([0x00, undefined], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
479
|
+
expect(() => updateData([undefined, 0x01], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
517
480
|
});
|
|
518
481
|
});
|
|
519
482
|
});
|