tirecheck-device-sdk 0.1.993 → 0.1.995
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/dist/index.cjs +27 -131
- package/dist/index.d.cts +12 -2
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.mjs +27 -131
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ function setBleImplementation(bleImplementation) {
|
|
|
37
37
|
|
|
38
38
|
const store = {
|
|
39
39
|
platform: "android",
|
|
40
|
+
securityKeys: {},
|
|
40
41
|
/** Defines access level for each connection, should be 'driver' as default, Supported roles: ['manufacturer', 'driver'] , Example: F4B4553322: 'manufacturer' */
|
|
41
42
|
deviceAccessLevel: {},
|
|
42
43
|
devices: {},
|
|
@@ -84,8 +85,9 @@ function waitUntil(callback, timeout = 5e3) {
|
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
function canCommunicateWith(deviceId) {
|
|
88
|
+
const device = store.devices[deviceId];
|
|
87
89
|
const state = store.deviceState[deviceId];
|
|
88
|
-
if (!state) return false;
|
|
90
|
+
if (!device || !state) return false;
|
|
89
91
|
return ["connected", "paired"].includes(state);
|
|
90
92
|
}
|
|
91
93
|
function getPositionId(axlePosition, tyrePosition, axleTyresCount, isSpare) {
|
|
@@ -619,7 +621,7 @@ async function connect$1(deviceId, disconnectCallback) {
|
|
|
619
621
|
if (toolsSvc.canCommunicateWith(deviceId)) return console.warn("Connect Warn: Already connected to device");
|
|
620
622
|
store.setState(deviceId, "connecting");
|
|
621
623
|
let connectedDevice;
|
|
622
|
-
for (let attempt = 1; attempt <=
|
|
624
|
+
for (let attempt = 1; attempt <= 5; attempt++) {
|
|
623
625
|
try {
|
|
624
626
|
connectedDevice = await withTimeout(connectInner(deviceId, disconnectCallback), 2e4);
|
|
625
627
|
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
@@ -631,7 +633,7 @@ async function connect$1(deviceId, disconnectCallback) {
|
|
|
631
633
|
}
|
|
632
634
|
} catch (e) {
|
|
633
635
|
console.warn(`${attempt} connect fail`, e);
|
|
634
|
-
if (attempt ===
|
|
636
|
+
if (attempt === 5) {
|
|
635
637
|
store.setState(deviceId, void 0, "failedConnection");
|
|
636
638
|
throw new Error("Connection unsuccessful");
|
|
637
639
|
}
|
|
@@ -656,8 +658,12 @@ async function disconnect$1(deviceId) {
|
|
|
656
658
|
for (let attempts = 0; attempts < 3; attempts++) {
|
|
657
659
|
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
658
660
|
await withTimeout(ble.disconnect(_deviceId), 1e3, "Disconnect timed out");
|
|
659
|
-
|
|
660
|
-
|
|
661
|
+
try {
|
|
662
|
+
const isConnected = await withTimeout(ble.isConnected(_deviceId), 1e3, "IsConnected timed out");
|
|
663
|
+
if (!isConnected) return;
|
|
664
|
+
} catch (e) {
|
|
665
|
+
console.warn("IsConnected error: ", e);
|
|
666
|
+
}
|
|
661
667
|
}
|
|
662
668
|
store.setState(deviceId, void 0, "failedDisconnection");
|
|
663
669
|
throw new Error("Disconnect unsuccessful");
|
|
@@ -1405,105 +1411,6 @@ const bridgeCommandStructures = {
|
|
|
1405
1411
|
}
|
|
1406
1412
|
};
|
|
1407
1413
|
|
|
1408
|
-
const signature_keys = {
|
|
1409
|
-
0: [
|
|
1410
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
1411
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 31],
|
|
1412
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 47],
|
|
1413
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 63],
|
|
1414
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 79],
|
|
1415
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 95],
|
|
1416
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 111],
|
|
1417
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 127],
|
|
1418
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 143],
|
|
1419
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 159],
|
|
1420
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 175],
|
|
1421
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 191],
|
|
1422
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 207],
|
|
1423
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 223],
|
|
1424
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 239],
|
|
1425
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 255]
|
|
1426
|
-
],
|
|
1427
|
-
1: [
|
|
1428
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
1429
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 31],
|
|
1430
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 47],
|
|
1431
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 63],
|
|
1432
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 79],
|
|
1433
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 95],
|
|
1434
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 111],
|
|
1435
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 127],
|
|
1436
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 143],
|
|
1437
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 159],
|
|
1438
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 175],
|
|
1439
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 191],
|
|
1440
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 207],
|
|
1441
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 223],
|
|
1442
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 239],
|
|
1443
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 255]
|
|
1444
|
-
],
|
|
1445
|
-
2: [
|
|
1446
|
-
[121, 114, 34, 71, 3, 133, 92, 108, 162, 173, 161, 168, 164, 148, 34, 139],
|
|
1447
|
-
[136, 120, 146, 44, 228, 28, 205, 63, 205, 120, 170, 120, 251, 245, 227, 154],
|
|
1448
|
-
[37, 22, 60, 132, 154, 66, 59, 185, 36, 142, 163, 103, 39, 121, 227, 209],
|
|
1449
|
-
[15, 30, 54, 173, 21, 127, 65, 158, 168, 84, 192, 17, 51, 3, 90, 173],
|
|
1450
|
-
[136, 165, 72, 127, 72, 38, 200, 5, 4, 187, 203, 29, 6, 82, 130, 39],
|
|
1451
|
-
[106, 95, 111, 82, 191, 213, 104, 194, 106, 30, 199, 250, 69, 223, 79, 250],
|
|
1452
|
-
[150, 63, 177, 61, 50, 182, 227, 53, 157, 168, 245, 96, 90, 212, 17, 132],
|
|
1453
|
-
[233, 159, 182, 205, 3, 216, 203, 73, 193, 142, 183, 16, 22, 208, 38, 143],
|
|
1454
|
-
[7, 45, 239, 102, 47, 8, 237, 115, 77, 232, 2, 167, 47, 65, 164, 251],
|
|
1455
|
-
[7, 159, 18, 71, 3, 132, 84, 47, 60, 167, 134, 251, 114, 207, 254, 190],
|
|
1456
|
-
[203, 129, 34, 153, 32, 169, 153, 45, 215, 172, 76, 214, 5, 21, 210, 65],
|
|
1457
|
-
[29, 194, 255, 4, 195, 144, 178, 174, 255, 66, 15, 19, 26, 212, 61, 251],
|
|
1458
|
-
[42, 13, 136, 252, 143, 234, 120, 242, 164, 36, 21, 135, 252, 145, 101, 124],
|
|
1459
|
-
[24, 24, 207, 236, 159, 24, 180, 141, 80, 119, 86, 239, 192, 32, 51, 34],
|
|
1460
|
-
[187, 89, 217, 2, 16, 125, 121, 46, 159, 66, 85, 169, 9, 155, 2, 178],
|
|
1461
|
-
[212, 230, 71, 216, 35, 20, 241, 0, 204, 163, 80, 198, 132, 210, 166, 173]
|
|
1462
|
-
],
|
|
1463
|
-
16: [
|
|
1464
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
1465
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 31],
|
|
1466
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 47],
|
|
1467
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 63],
|
|
1468
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 79],
|
|
1469
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 95],
|
|
1470
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 111],
|
|
1471
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 127],
|
|
1472
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 143],
|
|
1473
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 159],
|
|
1474
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 175],
|
|
1475
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 191],
|
|
1476
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 207],
|
|
1477
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 223],
|
|
1478
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 239],
|
|
1479
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 255]
|
|
1480
|
-
],
|
|
1481
|
-
17: [
|
|
1482
|
-
[75, 40, 61, 20, 254, 102, 105, 160, 44, 236, 79, 39, 84, 27, 235, 100],
|
|
1483
|
-
[185, 139, 202, 38, 158, 109, 211, 6, 38, 73, 28, 120, 208, 168, 159, 108],
|
|
1484
|
-
[252, 100, 192, 127, 135, 127, 228, 125, 190, 210, 248, 146, 45, 229, 218, 159],
|
|
1485
|
-
[217, 39, 58, 200, 22, 212, 105, 55, 15, 45, 82, 96, 216, 134, 69, 123],
|
|
1486
|
-
[192, 34, 199, 199, 200, 112, 61, 98, 174, 62, 7, 200, 149, 168, 175, 110],
|
|
1487
|
-
[60, 41, 125, 116, 134, 191, 241, 188, 171, 127, 209, 10, 114, 52, 120, 164],
|
|
1488
|
-
[255, 19, 220, 184, 141, 224, 242, 117, 230, 143, 20, 75, 44, 50, 70, 113],
|
|
1489
|
-
[55, 112, 171, 176, 239, 50, 111, 3, 175, 145, 123, 38, 12, 44, 18, 79],
|
|
1490
|
-
[211, 119, 219, 6, 27, 41, 170, 199, 206, 66, 89, 89, 154, 128, 110, 70],
|
|
1491
|
-
[187, 184, 42, 154, 108, 182, 238, 223, 192, 10, 144, 139, 130, 22, 220, 66],
|
|
1492
|
-
[91, 248, 195, 246, 212, 104, 246, 252, 231, 120, 153, 211, 39, 250, 221, 133],
|
|
1493
|
-
[184, 148, 72, 207, 106, 143, 21, 239, 133, 206, 1, 234, 1, 75, 92, 43],
|
|
1494
|
-
[46, 35, 117, 127, 103, 37, 155, 16, 177, 106, 195, 129, 168, 235, 159, 162],
|
|
1495
|
-
[0, 7, 114, 77, 77, 66, 224, 223, 92, 193, 241, 44, 242, 104, 67, 163],
|
|
1496
|
-
[116, 194, 13, 179, 75, 181, 245, 211, 19, 38, 45, 21, 36, 163, 252, 235],
|
|
1497
|
-
[6, 211, 31, 66, 81, 221, 137, 33, 23, 18, 160, 147, 159, 34, 121, 125]
|
|
1498
|
-
]
|
|
1499
|
-
};
|
|
1500
|
-
const pinKeys = {
|
|
1501
|
-
0: "00000000000000010000000000000002",
|
|
1502
|
-
1: "00000000000000010000000000000002",
|
|
1503
|
-
2: "B2D24304FC345F1418EB96835B3B7AE8",
|
|
1504
|
-
16: "00000000000000010000000000000002",
|
|
1505
|
-
17: "CB5A6AA23FD565A141C5CE5ABF209000"
|
|
1506
|
-
};
|
|
1507
1414
|
const bridgeSecurity = {
|
|
1508
1415
|
getSignedCommand(device, command) {
|
|
1509
1416
|
const { randomAdvNumber, configVersion } = device?.advertisingData || {};
|
|
@@ -1520,7 +1427,8 @@ const bridgeSecurity = {
|
|
|
1520
1427
|
const r = command.length % 16;
|
|
1521
1428
|
paddedCommand = bridgeTools.pkcs(command, r ? ++t * 16 : t * 16);
|
|
1522
1429
|
}
|
|
1523
|
-
|
|
1430
|
+
if (!store.securityKeys?.bridge?.signatureKeys?.[configVersion]) throw new Error("No signature key found");
|
|
1431
|
+
const key = store.securityKeys.bridge.signatureKeys[configVersion][keyIndex];
|
|
1524
1432
|
const startArray = key.slice(keyShift);
|
|
1525
1433
|
const endArray = key.slice(0, keyShift);
|
|
1526
1434
|
const shiftedKey = startArray.concat(endArray).map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
@@ -1557,13 +1465,14 @@ const bridgeSecurity = {
|
|
|
1557
1465
|
},
|
|
1558
1466
|
async getPin(deviceId) {
|
|
1559
1467
|
const deviceData = store.devices[deviceId];
|
|
1560
|
-
if (deviceData?.type !== "bridge") throw new Error("Device data missing");
|
|
1468
|
+
if (deviceData?.type !== "bridge") throw new Error("Device data missing 1 ");
|
|
1561
1469
|
const { randomAdvNumber, macAddress, configVersion } = deviceData.advertisingData || {};
|
|
1562
1470
|
if (!randomAdvNumber || !macAddress || !___default.isNumber(configVersion)) throw new Error("Cannot compute pin");
|
|
1563
1471
|
const mac = macAddress.map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
1564
1472
|
const rand = randomAdvNumber.map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
1565
1473
|
const message = `${mac}0000${rand}`;
|
|
1566
|
-
|
|
1474
|
+
if (!store.securityKeys?.bridge?.pinKeys?.[configVersion]) throw new Error("No pin key found");
|
|
1475
|
+
const key = store.securityKeys?.bridge?.pinKeys[configVersion];
|
|
1567
1476
|
const res = await this.aesToCrc32(message, key);
|
|
1568
1477
|
return res;
|
|
1569
1478
|
},
|
|
@@ -1827,6 +1736,7 @@ const bridgeCommands = {
|
|
|
1827
1736
|
return this.promisify(deviceData, [...this.getCommandHeader(deviceData), 18, commandIds.pin, 0, ...pin]);
|
|
1828
1737
|
},
|
|
1829
1738
|
async setBridgeToRestart(deviceId) {
|
|
1739
|
+
if (store.bridgeRebootRequired[deviceId]) return;
|
|
1830
1740
|
const deviceData = await bridgeTools.getBridgeFromStore(deviceId);
|
|
1831
1741
|
const useNewCommand = (deviceData.advertisingData.fwVersion || "") > "0.9.7";
|
|
1832
1742
|
await this.promisify(deviceData, [
|
|
@@ -1845,24 +1755,6 @@ const bridgeCommands = {
|
|
|
1845
1755
|
);
|
|
1846
1756
|
return await this.writeCommand(deviceData, commandIds.writeData, subCommandIds.customerCanSettings, payload);
|
|
1847
1757
|
},
|
|
1848
|
-
async getCustomerCrcSettings(deviceId) {
|
|
1849
|
-
const result = await this.readCrcCommand(deviceId, subCommandIds.customerCanSettings);
|
|
1850
|
-
let factorySettings = false;
|
|
1851
|
-
if (!result?.length || result.every((n) => n === 0)) factorySettings = true;
|
|
1852
|
-
return factorySettings;
|
|
1853
|
-
},
|
|
1854
|
-
async readCrcCommand(deviceId, subCommandId) {
|
|
1855
|
-
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1856
|
-
const commandLength = 2;
|
|
1857
|
-
const result = await this.promisify(deviceData, [
|
|
1858
|
-
...this.getCommandHeader(deviceData),
|
|
1859
|
-
commandLength,
|
|
1860
|
-
commandIds.readData,
|
|
1861
|
-
subCommandId
|
|
1862
|
-
]);
|
|
1863
|
-
const crc = result.slice(result.length - 8, result.length - 4);
|
|
1864
|
-
return crc;
|
|
1865
|
-
},
|
|
1866
1758
|
async setWorkshopCANSettings(deviceId, structurizedPayload) {
|
|
1867
1759
|
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1868
1760
|
const payload = bridgeTools.convertStructureToBytes(
|
|
@@ -2132,7 +2024,7 @@ async function updateFirmware(deviceId, bootloader, firmware, reportStatus) {
|
|
|
2132
2024
|
}
|
|
2133
2025
|
async function setVehicleLayout(deviceId, tcVehicle) {
|
|
2134
2026
|
const spareTyres = tcVehicle.tcTyres?.filter((tyre) => String(tyre.mountedOn?.positionId).endsWith("0"));
|
|
2135
|
-
let spareTyresCount = Math.min(spareTyres
|
|
2027
|
+
let spareTyresCount = Math.min(spareTyres?.length || 0, 2);
|
|
2136
2028
|
const result = {
|
|
2137
2029
|
axle01: "0000",
|
|
2138
2030
|
axle02: "0000",
|
|
@@ -2492,7 +2384,7 @@ async function getAutolearnStatuses(deviceId, tcVehicle) {
|
|
|
2492
2384
|
return autolearnedStatuses;
|
|
2493
2385
|
}
|
|
2494
2386
|
function getAutolearnStatusName(statusId) {
|
|
2495
|
-
if (["2", "A"].includes(statusId)) {
|
|
2387
|
+
if (["2", "A"].includes(statusId.toUpperCase())) {
|
|
2496
2388
|
return "error";
|
|
2497
2389
|
}
|
|
2498
2390
|
if (statusId === "4") {
|
|
@@ -2504,7 +2396,7 @@ function getAutolearnStatusName(statusId) {
|
|
|
2504
2396
|
if (statusId === "0") {
|
|
2505
2397
|
return "default";
|
|
2506
2398
|
}
|
|
2507
|
-
throw new Error(
|
|
2399
|
+
throw new Error(`Unknown autolearn status: ${statusId}`);
|
|
2508
2400
|
}
|
|
2509
2401
|
async function resetAutolearnStatuses(deviceId, positionIds) {
|
|
2510
2402
|
if (!bridgeTools.isVersionGreaterThan(deviceId, "0.9.7"))
|
|
@@ -3323,10 +3215,13 @@ function ensureSimulatorMethodsAreInjected() {
|
|
|
3323
3215
|
advertisingInterval = void 0;
|
|
3324
3216
|
}
|
|
3325
3217
|
let previousDevices = store.simulatedDevices;
|
|
3326
|
-
advertisingInterval = toolsSvc.setIntervalImmediate(() => {
|
|
3218
|
+
advertisingInterval = toolsSvc.setIntervalImmediate(async () => {
|
|
3327
3219
|
for (const key in store.simulatedDevices) {
|
|
3328
3220
|
const d = store.simulatedDevices[key];
|
|
3329
|
-
if (d.isDisabled)
|
|
3221
|
+
if (d.isDisabled) {
|
|
3222
|
+
if (store.deviceState[key] === "paired") await bridgeSimulator.disconnect(key);
|
|
3223
|
+
continue;
|
|
3224
|
+
}
|
|
3330
3225
|
unreachableSvc.refresh(d.id, deviceUnreachableCallback);
|
|
3331
3226
|
deviceAdvertisingCallback?.(store.simulatedDevices[key]);
|
|
3332
3227
|
}
|
|
@@ -3372,9 +3267,10 @@ class BridgeTcVehicleAxle {
|
|
|
3372
3267
|
minTargetPressure;
|
|
3373
3268
|
}
|
|
3374
3269
|
|
|
3375
|
-
function createTirecheckDeviceSdk(platform, bleImplementation) {
|
|
3270
|
+
function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
|
|
3376
3271
|
store.platform = platform;
|
|
3377
3272
|
bleImplementation = bleImplementation || emptyBleImplementation;
|
|
3273
|
+
store.securityKeys = securityKeys || {};
|
|
3378
3274
|
setBleImplementation(bleImplementation);
|
|
3379
3275
|
return {
|
|
3380
3276
|
/** Generic methods common for all devices */
|
package/dist/index.d.cts
CHANGED
|
@@ -813,6 +813,16 @@ interface BleBridgeAdvertisingData {
|
|
|
813
813
|
configVersion: number;
|
|
814
814
|
timeFromStart?: number;
|
|
815
815
|
}
|
|
816
|
+
interface BleSecurityKeys {
|
|
817
|
+
bridge?: {
|
|
818
|
+
signatureKeys: {
|
|
819
|
+
[index: number]: number[][];
|
|
820
|
+
};
|
|
821
|
+
pinKeys: {
|
|
822
|
+
[index: number]: string;
|
|
823
|
+
};
|
|
824
|
+
};
|
|
825
|
+
}
|
|
816
826
|
type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
817
827
|
[K in keyof T]: (...args: [next: (...paramsOverride: any[]) => ReturnType<T[K]>, ...Parameters<T[K]>]) => ReturnType<T[K]>;
|
|
818
828
|
};
|
|
@@ -830,7 +840,7 @@ type EventName = keyof EventHandlers;
|
|
|
830
840
|
/** Creates instance of SDK.
|
|
831
841
|
* For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
|
|
832
842
|
* If `bleImplementation` is not provided, SDK will work only with the simulator. */
|
|
833
|
-
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation): {
|
|
843
|
+
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
|
|
834
844
|
/** Generic methods common for all devices */
|
|
835
845
|
bluetooth: {
|
|
836
846
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
|
@@ -890,4 +900,4 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
|
|
|
890
900
|
};
|
|
891
901
|
};
|
|
892
902
|
|
|
893
|
-
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
|
|
903
|
+
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
|
package/dist/index.d.mts
CHANGED
|
@@ -813,6 +813,16 @@ interface BleBridgeAdvertisingData {
|
|
|
813
813
|
configVersion: number;
|
|
814
814
|
timeFromStart?: number;
|
|
815
815
|
}
|
|
816
|
+
interface BleSecurityKeys {
|
|
817
|
+
bridge?: {
|
|
818
|
+
signatureKeys: {
|
|
819
|
+
[index: number]: number[][];
|
|
820
|
+
};
|
|
821
|
+
pinKeys: {
|
|
822
|
+
[index: number]: string;
|
|
823
|
+
};
|
|
824
|
+
};
|
|
825
|
+
}
|
|
816
826
|
type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
817
827
|
[K in keyof T]: (...args: [next: (...paramsOverride: any[]) => ReturnType<T[K]>, ...Parameters<T[K]>]) => ReturnType<T[K]>;
|
|
818
828
|
};
|
|
@@ -830,7 +840,7 @@ type EventName = keyof EventHandlers;
|
|
|
830
840
|
/** Creates instance of SDK.
|
|
831
841
|
* For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
|
|
832
842
|
* If `bleImplementation` is not provided, SDK will work only with the simulator. */
|
|
833
|
-
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation): {
|
|
843
|
+
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
|
|
834
844
|
/** Generic methods common for all devices */
|
|
835
845
|
bluetooth: {
|
|
836
846
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
|
@@ -890,4 +900,4 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
|
|
|
890
900
|
};
|
|
891
901
|
};
|
|
892
902
|
|
|
893
|
-
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
|
|
903
|
+
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
|
package/dist/index.d.ts
CHANGED
|
@@ -813,6 +813,16 @@ interface BleBridgeAdvertisingData {
|
|
|
813
813
|
configVersion: number;
|
|
814
814
|
timeFromStart?: number;
|
|
815
815
|
}
|
|
816
|
+
interface BleSecurityKeys {
|
|
817
|
+
bridge?: {
|
|
818
|
+
signatureKeys: {
|
|
819
|
+
[index: number]: number[][];
|
|
820
|
+
};
|
|
821
|
+
pinKeys: {
|
|
822
|
+
[index: number]: string;
|
|
823
|
+
};
|
|
824
|
+
};
|
|
825
|
+
}
|
|
816
826
|
type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
817
827
|
[K in keyof T]: (...args: [next: (...paramsOverride: any[]) => ReturnType<T[K]>, ...Parameters<T[K]>]) => ReturnType<T[K]>;
|
|
818
828
|
};
|
|
@@ -830,7 +840,7 @@ type EventName = keyof EventHandlers;
|
|
|
830
840
|
/** Creates instance of SDK.
|
|
831
841
|
* For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
|
|
832
842
|
* If `bleImplementation` is not provided, SDK will work only with the simulator. */
|
|
833
|
-
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation): {
|
|
843
|
+
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
|
|
834
844
|
/** Generic methods common for all devices */
|
|
835
845
|
bluetooth: {
|
|
836
846
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
|
@@ -890,4 +900,4 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
|
|
|
890
900
|
};
|
|
891
901
|
};
|
|
892
902
|
|
|
893
|
-
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
|
|
903
|
+
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type Wrapper, createTirecheckDeviceSdk };
|
package/dist/index.mjs
CHANGED
|
@@ -30,6 +30,7 @@ function setBleImplementation(bleImplementation) {
|
|
|
30
30
|
|
|
31
31
|
const store = {
|
|
32
32
|
platform: "android",
|
|
33
|
+
securityKeys: {},
|
|
33
34
|
/** Defines access level for each connection, should be 'driver' as default, Supported roles: ['manufacturer', 'driver'] , Example: F4B4553322: 'manufacturer' */
|
|
34
35
|
deviceAccessLevel: {},
|
|
35
36
|
devices: {},
|
|
@@ -77,8 +78,9 @@ function waitUntil(callback, timeout = 5e3) {
|
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
80
|
function canCommunicateWith(deviceId) {
|
|
81
|
+
const device = store.devices[deviceId];
|
|
80
82
|
const state = store.deviceState[deviceId];
|
|
81
|
-
if (!state) return false;
|
|
83
|
+
if (!device || !state) return false;
|
|
82
84
|
return ["connected", "paired"].includes(state);
|
|
83
85
|
}
|
|
84
86
|
function getPositionId(axlePosition, tyrePosition, axleTyresCount, isSpare) {
|
|
@@ -612,7 +614,7 @@ async function connect$1(deviceId, disconnectCallback) {
|
|
|
612
614
|
if (toolsSvc.canCommunicateWith(deviceId)) return console.warn("Connect Warn: Already connected to device");
|
|
613
615
|
store.setState(deviceId, "connecting");
|
|
614
616
|
let connectedDevice;
|
|
615
|
-
for (let attempt = 1; attempt <=
|
|
617
|
+
for (let attempt = 1; attempt <= 5; attempt++) {
|
|
616
618
|
try {
|
|
617
619
|
connectedDevice = await withTimeout(connectInner(deviceId, disconnectCallback), 2e4);
|
|
618
620
|
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
@@ -624,7 +626,7 @@ async function connect$1(deviceId, disconnectCallback) {
|
|
|
624
626
|
}
|
|
625
627
|
} catch (e) {
|
|
626
628
|
console.warn(`${attempt} connect fail`, e);
|
|
627
|
-
if (attempt ===
|
|
629
|
+
if (attempt === 5) {
|
|
628
630
|
store.setState(deviceId, void 0, "failedConnection");
|
|
629
631
|
throw new Error("Connection unsuccessful");
|
|
630
632
|
}
|
|
@@ -649,8 +651,12 @@ async function disconnect$1(deviceId) {
|
|
|
649
651
|
for (let attempts = 0; attempts < 3; attempts++) {
|
|
650
652
|
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
651
653
|
await withTimeout(ble.disconnect(_deviceId), 1e3, "Disconnect timed out");
|
|
652
|
-
|
|
653
|
-
|
|
654
|
+
try {
|
|
655
|
+
const isConnected = await withTimeout(ble.isConnected(_deviceId), 1e3, "IsConnected timed out");
|
|
656
|
+
if (!isConnected) return;
|
|
657
|
+
} catch (e) {
|
|
658
|
+
console.warn("IsConnected error: ", e);
|
|
659
|
+
}
|
|
654
660
|
}
|
|
655
661
|
store.setState(deviceId, void 0, "failedDisconnection");
|
|
656
662
|
throw new Error("Disconnect unsuccessful");
|
|
@@ -1398,105 +1404,6 @@ const bridgeCommandStructures = {
|
|
|
1398
1404
|
}
|
|
1399
1405
|
};
|
|
1400
1406
|
|
|
1401
|
-
const signature_keys = {
|
|
1402
|
-
0: [
|
|
1403
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
1404
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 31],
|
|
1405
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 47],
|
|
1406
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 63],
|
|
1407
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 79],
|
|
1408
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 95],
|
|
1409
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 111],
|
|
1410
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 127],
|
|
1411
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 143],
|
|
1412
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 159],
|
|
1413
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 175],
|
|
1414
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 191],
|
|
1415
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 207],
|
|
1416
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 223],
|
|
1417
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 239],
|
|
1418
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 255]
|
|
1419
|
-
],
|
|
1420
|
-
1: [
|
|
1421
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
1422
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 31],
|
|
1423
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 47],
|
|
1424
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 63],
|
|
1425
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 79],
|
|
1426
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 95],
|
|
1427
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 111],
|
|
1428
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 127],
|
|
1429
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 143],
|
|
1430
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 159],
|
|
1431
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 175],
|
|
1432
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 191],
|
|
1433
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 207],
|
|
1434
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 223],
|
|
1435
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 239],
|
|
1436
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 255]
|
|
1437
|
-
],
|
|
1438
|
-
2: [
|
|
1439
|
-
[121, 114, 34, 71, 3, 133, 92, 108, 162, 173, 161, 168, 164, 148, 34, 139],
|
|
1440
|
-
[136, 120, 146, 44, 228, 28, 205, 63, 205, 120, 170, 120, 251, 245, 227, 154],
|
|
1441
|
-
[37, 22, 60, 132, 154, 66, 59, 185, 36, 142, 163, 103, 39, 121, 227, 209],
|
|
1442
|
-
[15, 30, 54, 173, 21, 127, 65, 158, 168, 84, 192, 17, 51, 3, 90, 173],
|
|
1443
|
-
[136, 165, 72, 127, 72, 38, 200, 5, 4, 187, 203, 29, 6, 82, 130, 39],
|
|
1444
|
-
[106, 95, 111, 82, 191, 213, 104, 194, 106, 30, 199, 250, 69, 223, 79, 250],
|
|
1445
|
-
[150, 63, 177, 61, 50, 182, 227, 53, 157, 168, 245, 96, 90, 212, 17, 132],
|
|
1446
|
-
[233, 159, 182, 205, 3, 216, 203, 73, 193, 142, 183, 16, 22, 208, 38, 143],
|
|
1447
|
-
[7, 45, 239, 102, 47, 8, 237, 115, 77, 232, 2, 167, 47, 65, 164, 251],
|
|
1448
|
-
[7, 159, 18, 71, 3, 132, 84, 47, 60, 167, 134, 251, 114, 207, 254, 190],
|
|
1449
|
-
[203, 129, 34, 153, 32, 169, 153, 45, 215, 172, 76, 214, 5, 21, 210, 65],
|
|
1450
|
-
[29, 194, 255, 4, 195, 144, 178, 174, 255, 66, 15, 19, 26, 212, 61, 251],
|
|
1451
|
-
[42, 13, 136, 252, 143, 234, 120, 242, 164, 36, 21, 135, 252, 145, 101, 124],
|
|
1452
|
-
[24, 24, 207, 236, 159, 24, 180, 141, 80, 119, 86, 239, 192, 32, 51, 34],
|
|
1453
|
-
[187, 89, 217, 2, 16, 125, 121, 46, 159, 66, 85, 169, 9, 155, 2, 178],
|
|
1454
|
-
[212, 230, 71, 216, 35, 20, 241, 0, 204, 163, 80, 198, 132, 210, 166, 173]
|
|
1455
|
-
],
|
|
1456
|
-
16: [
|
|
1457
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
|
1458
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 31],
|
|
1459
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 47],
|
|
1460
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 63],
|
|
1461
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 79],
|
|
1462
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 95],
|
|
1463
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 111],
|
|
1464
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 127],
|
|
1465
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 143],
|
|
1466
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 159],
|
|
1467
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 175],
|
|
1468
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 191],
|
|
1469
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 207],
|
|
1470
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 223],
|
|
1471
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 239],
|
|
1472
|
-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 255]
|
|
1473
|
-
],
|
|
1474
|
-
17: [
|
|
1475
|
-
[75, 40, 61, 20, 254, 102, 105, 160, 44, 236, 79, 39, 84, 27, 235, 100],
|
|
1476
|
-
[185, 139, 202, 38, 158, 109, 211, 6, 38, 73, 28, 120, 208, 168, 159, 108],
|
|
1477
|
-
[252, 100, 192, 127, 135, 127, 228, 125, 190, 210, 248, 146, 45, 229, 218, 159],
|
|
1478
|
-
[217, 39, 58, 200, 22, 212, 105, 55, 15, 45, 82, 96, 216, 134, 69, 123],
|
|
1479
|
-
[192, 34, 199, 199, 200, 112, 61, 98, 174, 62, 7, 200, 149, 168, 175, 110],
|
|
1480
|
-
[60, 41, 125, 116, 134, 191, 241, 188, 171, 127, 209, 10, 114, 52, 120, 164],
|
|
1481
|
-
[255, 19, 220, 184, 141, 224, 242, 117, 230, 143, 20, 75, 44, 50, 70, 113],
|
|
1482
|
-
[55, 112, 171, 176, 239, 50, 111, 3, 175, 145, 123, 38, 12, 44, 18, 79],
|
|
1483
|
-
[211, 119, 219, 6, 27, 41, 170, 199, 206, 66, 89, 89, 154, 128, 110, 70],
|
|
1484
|
-
[187, 184, 42, 154, 108, 182, 238, 223, 192, 10, 144, 139, 130, 22, 220, 66],
|
|
1485
|
-
[91, 248, 195, 246, 212, 104, 246, 252, 231, 120, 153, 211, 39, 250, 221, 133],
|
|
1486
|
-
[184, 148, 72, 207, 106, 143, 21, 239, 133, 206, 1, 234, 1, 75, 92, 43],
|
|
1487
|
-
[46, 35, 117, 127, 103, 37, 155, 16, 177, 106, 195, 129, 168, 235, 159, 162],
|
|
1488
|
-
[0, 7, 114, 77, 77, 66, 224, 223, 92, 193, 241, 44, 242, 104, 67, 163],
|
|
1489
|
-
[116, 194, 13, 179, 75, 181, 245, 211, 19, 38, 45, 21, 36, 163, 252, 235],
|
|
1490
|
-
[6, 211, 31, 66, 81, 221, 137, 33, 23, 18, 160, 147, 159, 34, 121, 125]
|
|
1491
|
-
]
|
|
1492
|
-
};
|
|
1493
|
-
const pinKeys = {
|
|
1494
|
-
0: "00000000000000010000000000000002",
|
|
1495
|
-
1: "00000000000000010000000000000002",
|
|
1496
|
-
2: "B2D24304FC345F1418EB96835B3B7AE8",
|
|
1497
|
-
16: "00000000000000010000000000000002",
|
|
1498
|
-
17: "CB5A6AA23FD565A141C5CE5ABF209000"
|
|
1499
|
-
};
|
|
1500
1407
|
const bridgeSecurity = {
|
|
1501
1408
|
getSignedCommand(device, command) {
|
|
1502
1409
|
const { randomAdvNumber, configVersion } = device?.advertisingData || {};
|
|
@@ -1513,7 +1420,8 @@ const bridgeSecurity = {
|
|
|
1513
1420
|
const r = command.length % 16;
|
|
1514
1421
|
paddedCommand = bridgeTools.pkcs(command, r ? ++t * 16 : t * 16);
|
|
1515
1422
|
}
|
|
1516
|
-
|
|
1423
|
+
if (!store.securityKeys?.bridge?.signatureKeys?.[configVersion]) throw new Error("No signature key found");
|
|
1424
|
+
const key = store.securityKeys.bridge.signatureKeys[configVersion][keyIndex];
|
|
1517
1425
|
const startArray = key.slice(keyShift);
|
|
1518
1426
|
const endArray = key.slice(0, keyShift);
|
|
1519
1427
|
const shiftedKey = startArray.concat(endArray).map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
@@ -1550,13 +1458,14 @@ const bridgeSecurity = {
|
|
|
1550
1458
|
},
|
|
1551
1459
|
async getPin(deviceId) {
|
|
1552
1460
|
const deviceData = store.devices[deviceId];
|
|
1553
|
-
if (deviceData?.type !== "bridge") throw new Error("Device data missing");
|
|
1461
|
+
if (deviceData?.type !== "bridge") throw new Error("Device data missing 1 ");
|
|
1554
1462
|
const { randomAdvNumber, macAddress, configVersion } = deviceData.advertisingData || {};
|
|
1555
1463
|
if (!randomAdvNumber || !macAddress || !_.isNumber(configVersion)) throw new Error("Cannot compute pin");
|
|
1556
1464
|
const mac = macAddress.map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
1557
1465
|
const rand = randomAdvNumber.map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
1558
1466
|
const message = `${mac}0000${rand}`;
|
|
1559
|
-
|
|
1467
|
+
if (!store.securityKeys?.bridge?.pinKeys?.[configVersion]) throw new Error("No pin key found");
|
|
1468
|
+
const key = store.securityKeys?.bridge?.pinKeys[configVersion];
|
|
1560
1469
|
const res = await this.aesToCrc32(message, key);
|
|
1561
1470
|
return res;
|
|
1562
1471
|
},
|
|
@@ -1820,6 +1729,7 @@ const bridgeCommands = {
|
|
|
1820
1729
|
return this.promisify(deviceData, [...this.getCommandHeader(deviceData), 18, commandIds.pin, 0, ...pin]);
|
|
1821
1730
|
},
|
|
1822
1731
|
async setBridgeToRestart(deviceId) {
|
|
1732
|
+
if (store.bridgeRebootRequired[deviceId]) return;
|
|
1823
1733
|
const deviceData = await bridgeTools.getBridgeFromStore(deviceId);
|
|
1824
1734
|
const useNewCommand = (deviceData.advertisingData.fwVersion || "") > "0.9.7";
|
|
1825
1735
|
await this.promisify(deviceData, [
|
|
@@ -1838,24 +1748,6 @@ const bridgeCommands = {
|
|
|
1838
1748
|
);
|
|
1839
1749
|
return await this.writeCommand(deviceData, commandIds.writeData, subCommandIds.customerCanSettings, payload);
|
|
1840
1750
|
},
|
|
1841
|
-
async getCustomerCrcSettings(deviceId) {
|
|
1842
|
-
const result = await this.readCrcCommand(deviceId, subCommandIds.customerCanSettings);
|
|
1843
|
-
let factorySettings = false;
|
|
1844
|
-
if (!result?.length || result.every((n) => n === 0)) factorySettings = true;
|
|
1845
|
-
return factorySettings;
|
|
1846
|
-
},
|
|
1847
|
-
async readCrcCommand(deviceId, subCommandId) {
|
|
1848
|
-
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1849
|
-
const commandLength = 2;
|
|
1850
|
-
const result = await this.promisify(deviceData, [
|
|
1851
|
-
...this.getCommandHeader(deviceData),
|
|
1852
|
-
commandLength,
|
|
1853
|
-
commandIds.readData,
|
|
1854
|
-
subCommandId
|
|
1855
|
-
]);
|
|
1856
|
-
const crc = result.slice(result.length - 8, result.length - 4);
|
|
1857
|
-
return crc;
|
|
1858
|
-
},
|
|
1859
1751
|
async setWorkshopCANSettings(deviceId, structurizedPayload) {
|
|
1860
1752
|
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1861
1753
|
const payload = bridgeTools.convertStructureToBytes(
|
|
@@ -2125,7 +2017,7 @@ async function updateFirmware(deviceId, bootloader, firmware, reportStatus) {
|
|
|
2125
2017
|
}
|
|
2126
2018
|
async function setVehicleLayout(deviceId, tcVehicle) {
|
|
2127
2019
|
const spareTyres = tcVehicle.tcTyres?.filter((tyre) => String(tyre.mountedOn?.positionId).endsWith("0"));
|
|
2128
|
-
let spareTyresCount = Math.min(spareTyres
|
|
2020
|
+
let spareTyresCount = Math.min(spareTyres?.length || 0, 2);
|
|
2129
2021
|
const result = {
|
|
2130
2022
|
axle01: "0000",
|
|
2131
2023
|
axle02: "0000",
|
|
@@ -2485,7 +2377,7 @@ async function getAutolearnStatuses(deviceId, tcVehicle) {
|
|
|
2485
2377
|
return autolearnedStatuses;
|
|
2486
2378
|
}
|
|
2487
2379
|
function getAutolearnStatusName(statusId) {
|
|
2488
|
-
if (["2", "A"].includes(statusId)) {
|
|
2380
|
+
if (["2", "A"].includes(statusId.toUpperCase())) {
|
|
2489
2381
|
return "error";
|
|
2490
2382
|
}
|
|
2491
2383
|
if (statusId === "4") {
|
|
@@ -2497,7 +2389,7 @@ function getAutolearnStatusName(statusId) {
|
|
|
2497
2389
|
if (statusId === "0") {
|
|
2498
2390
|
return "default";
|
|
2499
2391
|
}
|
|
2500
|
-
throw new Error(
|
|
2392
|
+
throw new Error(`Unknown autolearn status: ${statusId}`);
|
|
2501
2393
|
}
|
|
2502
2394
|
async function resetAutolearnStatuses(deviceId, positionIds) {
|
|
2503
2395
|
if (!bridgeTools.isVersionGreaterThan(deviceId, "0.9.7"))
|
|
@@ -3316,10 +3208,13 @@ function ensureSimulatorMethodsAreInjected() {
|
|
|
3316
3208
|
advertisingInterval = void 0;
|
|
3317
3209
|
}
|
|
3318
3210
|
let previousDevices = store.simulatedDevices;
|
|
3319
|
-
advertisingInterval = toolsSvc.setIntervalImmediate(() => {
|
|
3211
|
+
advertisingInterval = toolsSvc.setIntervalImmediate(async () => {
|
|
3320
3212
|
for (const key in store.simulatedDevices) {
|
|
3321
3213
|
const d = store.simulatedDevices[key];
|
|
3322
|
-
if (d.isDisabled)
|
|
3214
|
+
if (d.isDisabled) {
|
|
3215
|
+
if (store.deviceState[key] === "paired") await bridgeSimulator.disconnect(key);
|
|
3216
|
+
continue;
|
|
3217
|
+
}
|
|
3323
3218
|
unreachableSvc.refresh(d.id, deviceUnreachableCallback);
|
|
3324
3219
|
deviceAdvertisingCallback?.(store.simulatedDevices[key]);
|
|
3325
3220
|
}
|
|
@@ -3365,9 +3260,10 @@ class BridgeTcVehicleAxle {
|
|
|
3365
3260
|
minTargetPressure;
|
|
3366
3261
|
}
|
|
3367
3262
|
|
|
3368
|
-
function createTirecheckDeviceSdk(platform, bleImplementation) {
|
|
3263
|
+
function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
|
|
3369
3264
|
store.platform = platform;
|
|
3370
3265
|
bleImplementation = bleImplementation || emptyBleImplementation;
|
|
3266
|
+
store.securityKeys = securityKeys || {};
|
|
3371
3267
|
setBleImplementation(bleImplementation);
|
|
3372
3268
|
return {
|
|
3373
3269
|
/** Generic methods common for all devices */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tirecheck-device-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.995",
|
|
4
4
|
"description": "SDK for working with various devices produced by Tirecheck via Bluetooth (CAN Bridge, Routers, Sensors, FlexiGauge, PressureStick, etc)",
|
|
5
5
|
"author": "Leonid Buneev <leonid.buneev@tirecheck.com>",
|
|
6
6
|
"license": "ISC",
|