tirecheck-device-sdk 0.1.994 → 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 +15 -27
- package/dist/index.d.cts +8 -6
- package/dist/index.d.mts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.mjs +15 -27
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -85,8 +85,9 @@ function waitUntil(callback, timeout = 5e3) {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
function canCommunicateWith(deviceId) {
|
|
88
|
+
const device = store.devices[deviceId];
|
|
88
89
|
const state = store.deviceState[deviceId];
|
|
89
|
-
if (!state) return false;
|
|
90
|
+
if (!device || !state) return false;
|
|
90
91
|
return ["connected", "paired"].includes(state);
|
|
91
92
|
}
|
|
92
93
|
function getPositionId(axlePosition, tyrePosition, axleTyresCount, isSpare) {
|
|
@@ -657,8 +658,12 @@ async function disconnect$1(deviceId) {
|
|
|
657
658
|
for (let attempts = 0; attempts < 3; attempts++) {
|
|
658
659
|
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
659
660
|
await withTimeout(ble.disconnect(_deviceId), 1e3, "Disconnect timed out");
|
|
660
|
-
|
|
661
|
-
|
|
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
|
+
}
|
|
662
667
|
}
|
|
663
668
|
store.setState(deviceId, void 0, "failedDisconnection");
|
|
664
669
|
throw new Error("Disconnect unsuccessful");
|
|
@@ -1422,8 +1427,8 @@ const bridgeSecurity = {
|
|
|
1422
1427
|
const r = command.length % 16;
|
|
1423
1428
|
paddedCommand = bridgeTools.pkcs(command, r ? ++t * 16 : t * 16);
|
|
1424
1429
|
}
|
|
1425
|
-
if (!store.securityKeys?.signatureKeys?.[configVersion]) throw new Error("No signature key found");
|
|
1426
|
-
const key = store.securityKeys.signatureKeys[configVersion][keyIndex];
|
|
1430
|
+
if (!store.securityKeys?.bridge?.signatureKeys?.[configVersion]) throw new Error("No signature key found");
|
|
1431
|
+
const key = store.securityKeys.bridge.signatureKeys[configVersion][keyIndex];
|
|
1427
1432
|
const startArray = key.slice(keyShift);
|
|
1428
1433
|
const endArray = key.slice(0, keyShift);
|
|
1429
1434
|
const shiftedKey = startArray.concat(endArray).map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
@@ -1466,8 +1471,8 @@ const bridgeSecurity = {
|
|
|
1466
1471
|
const mac = macAddress.map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
1467
1472
|
const rand = randomAdvNumber.map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
1468
1473
|
const message = `${mac}0000${rand}`;
|
|
1469
|
-
if (!store.securityKeys?.pinKeys?.[configVersion]) throw new Error("No pin key found");
|
|
1470
|
-
const key = store.securityKeys
|
|
1474
|
+
if (!store.securityKeys?.bridge?.pinKeys?.[configVersion]) throw new Error("No pin key found");
|
|
1475
|
+
const key = store.securityKeys?.bridge?.pinKeys[configVersion];
|
|
1471
1476
|
const res = await this.aesToCrc32(message, key);
|
|
1472
1477
|
return res;
|
|
1473
1478
|
},
|
|
@@ -1731,6 +1736,7 @@ const bridgeCommands = {
|
|
|
1731
1736
|
return this.promisify(deviceData, [...this.getCommandHeader(deviceData), 18, commandIds.pin, 0, ...pin]);
|
|
1732
1737
|
},
|
|
1733
1738
|
async setBridgeToRestart(deviceId) {
|
|
1739
|
+
if (store.bridgeRebootRequired[deviceId]) return;
|
|
1734
1740
|
const deviceData = await bridgeTools.getBridgeFromStore(deviceId);
|
|
1735
1741
|
const useNewCommand = (deviceData.advertisingData.fwVersion || "") > "0.9.7";
|
|
1736
1742
|
await this.promisify(deviceData, [
|
|
@@ -1749,24 +1755,6 @@ const bridgeCommands = {
|
|
|
1749
1755
|
);
|
|
1750
1756
|
return await this.writeCommand(deviceData, commandIds.writeData, subCommandIds.customerCanSettings, payload);
|
|
1751
1757
|
},
|
|
1752
|
-
async getCustomerCrcSettings(deviceId) {
|
|
1753
|
-
const result = await this.readCrcCommand(deviceId, subCommandIds.customerCanSettings);
|
|
1754
|
-
let factorySettings = false;
|
|
1755
|
-
if (!result?.length || result.every((n) => n === 0)) factorySettings = true;
|
|
1756
|
-
return factorySettings;
|
|
1757
|
-
},
|
|
1758
|
-
async readCrcCommand(deviceId, subCommandId) {
|
|
1759
|
-
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1760
|
-
const commandLength = 2;
|
|
1761
|
-
const result = await this.promisify(deviceData, [
|
|
1762
|
-
...this.getCommandHeader(deviceData),
|
|
1763
|
-
commandLength,
|
|
1764
|
-
commandIds.readData,
|
|
1765
|
-
subCommandId
|
|
1766
|
-
]);
|
|
1767
|
-
const crc = result.slice(result.length - 8, result.length - 4);
|
|
1768
|
-
return crc;
|
|
1769
|
-
},
|
|
1770
1758
|
async setWorkshopCANSettings(deviceId, structurizedPayload) {
|
|
1771
1759
|
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1772
1760
|
const payload = bridgeTools.convertStructureToBytes(
|
|
@@ -3279,10 +3267,10 @@ class BridgeTcVehicleAxle {
|
|
|
3279
3267
|
minTargetPressure;
|
|
3280
3268
|
}
|
|
3281
3269
|
|
|
3282
|
-
function createTirecheckDeviceSdk(platform,
|
|
3283
|
-
store.securityKeys = securityKeys;
|
|
3270
|
+
function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
|
|
3284
3271
|
store.platform = platform;
|
|
3285
3272
|
bleImplementation = bleImplementation || emptyBleImplementation;
|
|
3273
|
+
store.securityKeys = securityKeys || {};
|
|
3286
3274
|
setBleImplementation(bleImplementation);
|
|
3287
3275
|
return {
|
|
3288
3276
|
/** Generic methods common for all devices */
|
package/dist/index.d.cts
CHANGED
|
@@ -814,11 +814,13 @@ interface BleBridgeAdvertisingData {
|
|
|
814
814
|
timeFromStart?: number;
|
|
815
815
|
}
|
|
816
816
|
interface BleSecurityKeys {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
817
|
+
bridge?: {
|
|
818
|
+
signatureKeys: {
|
|
819
|
+
[index: number]: number[][];
|
|
820
|
+
};
|
|
821
|
+
pinKeys: {
|
|
822
|
+
[index: number]: string;
|
|
823
|
+
};
|
|
822
824
|
};
|
|
823
825
|
}
|
|
824
826
|
type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
@@ -838,7 +840,7 @@ type EventName = keyof EventHandlers;
|
|
|
838
840
|
/** Creates instance of SDK.
|
|
839
841
|
* For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
|
|
840
842
|
* If `bleImplementation` is not provided, SDK will work only with the simulator. */
|
|
841
|
-
declare function createTirecheckDeviceSdk(platform: DevicePlatform,
|
|
843
|
+
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
|
|
842
844
|
/** Generic methods common for all devices */
|
|
843
845
|
bluetooth: {
|
|
844
846
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
package/dist/index.d.mts
CHANGED
|
@@ -814,11 +814,13 @@ interface BleBridgeAdvertisingData {
|
|
|
814
814
|
timeFromStart?: number;
|
|
815
815
|
}
|
|
816
816
|
interface BleSecurityKeys {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
817
|
+
bridge?: {
|
|
818
|
+
signatureKeys: {
|
|
819
|
+
[index: number]: number[][];
|
|
820
|
+
};
|
|
821
|
+
pinKeys: {
|
|
822
|
+
[index: number]: string;
|
|
823
|
+
};
|
|
822
824
|
};
|
|
823
825
|
}
|
|
824
826
|
type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
@@ -838,7 +840,7 @@ type EventName = keyof EventHandlers;
|
|
|
838
840
|
/** Creates instance of SDK.
|
|
839
841
|
* For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
|
|
840
842
|
* If `bleImplementation` is not provided, SDK will work only with the simulator. */
|
|
841
|
-
declare function createTirecheckDeviceSdk(platform: DevicePlatform,
|
|
843
|
+
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
|
|
842
844
|
/** Generic methods common for all devices */
|
|
843
845
|
bluetooth: {
|
|
844
846
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -814,11 +814,13 @@ interface BleBridgeAdvertisingData {
|
|
|
814
814
|
timeFromStart?: number;
|
|
815
815
|
}
|
|
816
816
|
interface BleSecurityKeys {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
817
|
+
bridge?: {
|
|
818
|
+
signatureKeys: {
|
|
819
|
+
[index: number]: number[][];
|
|
820
|
+
};
|
|
821
|
+
pinKeys: {
|
|
822
|
+
[index: number]: string;
|
|
823
|
+
};
|
|
822
824
|
};
|
|
823
825
|
}
|
|
824
826
|
type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
@@ -838,7 +840,7 @@ type EventName = keyof EventHandlers;
|
|
|
838
840
|
/** Creates instance of SDK.
|
|
839
841
|
* For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
|
|
840
842
|
* If `bleImplementation` is not provided, SDK will work only with the simulator. */
|
|
841
|
-
declare function createTirecheckDeviceSdk(platform: DevicePlatform,
|
|
843
|
+
declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
|
|
842
844
|
/** Generic methods common for all devices */
|
|
843
845
|
bluetooth: {
|
|
844
846
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
package/dist/index.mjs
CHANGED
|
@@ -78,8 +78,9 @@ function waitUntil(callback, timeout = 5e3) {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
function canCommunicateWith(deviceId) {
|
|
81
|
+
const device = store.devices[deviceId];
|
|
81
82
|
const state = store.deviceState[deviceId];
|
|
82
|
-
if (!state) return false;
|
|
83
|
+
if (!device || !state) return false;
|
|
83
84
|
return ["connected", "paired"].includes(state);
|
|
84
85
|
}
|
|
85
86
|
function getPositionId(axlePosition, tyrePosition, axleTyresCount, isSpare) {
|
|
@@ -650,8 +651,12 @@ async function disconnect$1(deviceId) {
|
|
|
650
651
|
for (let attempts = 0; attempts < 3; attempts++) {
|
|
651
652
|
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
652
653
|
await withTimeout(ble.disconnect(_deviceId), 1e3, "Disconnect timed out");
|
|
653
|
-
|
|
654
|
-
|
|
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
|
+
}
|
|
655
660
|
}
|
|
656
661
|
store.setState(deviceId, void 0, "failedDisconnection");
|
|
657
662
|
throw new Error("Disconnect unsuccessful");
|
|
@@ -1415,8 +1420,8 @@ const bridgeSecurity = {
|
|
|
1415
1420
|
const r = command.length % 16;
|
|
1416
1421
|
paddedCommand = bridgeTools.pkcs(command, r ? ++t * 16 : t * 16);
|
|
1417
1422
|
}
|
|
1418
|
-
if (!store.securityKeys?.signatureKeys?.[configVersion]) throw new Error("No signature key found");
|
|
1419
|
-
const key = store.securityKeys.signatureKeys[configVersion][keyIndex];
|
|
1423
|
+
if (!store.securityKeys?.bridge?.signatureKeys?.[configVersion]) throw new Error("No signature key found");
|
|
1424
|
+
const key = store.securityKeys.bridge.signatureKeys[configVersion][keyIndex];
|
|
1420
1425
|
const startArray = key.slice(keyShift);
|
|
1421
1426
|
const endArray = key.slice(0, keyShift);
|
|
1422
1427
|
const shiftedKey = startArray.concat(endArray).map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
@@ -1459,8 +1464,8 @@ const bridgeSecurity = {
|
|
|
1459
1464
|
const mac = macAddress.map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
1460
1465
|
const rand = randomAdvNumber.map((n) => bridgeTools.decimalToHex(n)).join("");
|
|
1461
1466
|
const message = `${mac}0000${rand}`;
|
|
1462
|
-
if (!store.securityKeys?.pinKeys?.[configVersion]) throw new Error("No pin key found");
|
|
1463
|
-
const key = store.securityKeys
|
|
1467
|
+
if (!store.securityKeys?.bridge?.pinKeys?.[configVersion]) throw new Error("No pin key found");
|
|
1468
|
+
const key = store.securityKeys?.bridge?.pinKeys[configVersion];
|
|
1464
1469
|
const res = await this.aesToCrc32(message, key);
|
|
1465
1470
|
return res;
|
|
1466
1471
|
},
|
|
@@ -1724,6 +1729,7 @@ const bridgeCommands = {
|
|
|
1724
1729
|
return this.promisify(deviceData, [...this.getCommandHeader(deviceData), 18, commandIds.pin, 0, ...pin]);
|
|
1725
1730
|
},
|
|
1726
1731
|
async setBridgeToRestart(deviceId) {
|
|
1732
|
+
if (store.bridgeRebootRequired[deviceId]) return;
|
|
1727
1733
|
const deviceData = await bridgeTools.getBridgeFromStore(deviceId);
|
|
1728
1734
|
const useNewCommand = (deviceData.advertisingData.fwVersion || "") > "0.9.7";
|
|
1729
1735
|
await this.promisify(deviceData, [
|
|
@@ -1742,24 +1748,6 @@ const bridgeCommands = {
|
|
|
1742
1748
|
);
|
|
1743
1749
|
return await this.writeCommand(deviceData, commandIds.writeData, subCommandIds.customerCanSettings, payload);
|
|
1744
1750
|
},
|
|
1745
|
-
async getCustomerCrcSettings(deviceId) {
|
|
1746
|
-
const result = await this.readCrcCommand(deviceId, subCommandIds.customerCanSettings);
|
|
1747
|
-
let factorySettings = false;
|
|
1748
|
-
if (!result?.length || result.every((n) => n === 0)) factorySettings = true;
|
|
1749
|
-
return factorySettings;
|
|
1750
|
-
},
|
|
1751
|
-
async readCrcCommand(deviceId, subCommandId) {
|
|
1752
|
-
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1753
|
-
const commandLength = 2;
|
|
1754
|
-
const result = await this.promisify(deviceData, [
|
|
1755
|
-
...this.getCommandHeader(deviceData),
|
|
1756
|
-
commandLength,
|
|
1757
|
-
commandIds.readData,
|
|
1758
|
-
subCommandId
|
|
1759
|
-
]);
|
|
1760
|
-
const crc = result.slice(result.length - 8, result.length - 4);
|
|
1761
|
-
return crc;
|
|
1762
|
-
},
|
|
1763
1751
|
async setWorkshopCANSettings(deviceId, structurizedPayload) {
|
|
1764
1752
|
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1765
1753
|
const payload = bridgeTools.convertStructureToBytes(
|
|
@@ -3272,10 +3260,10 @@ class BridgeTcVehicleAxle {
|
|
|
3272
3260
|
minTargetPressure;
|
|
3273
3261
|
}
|
|
3274
3262
|
|
|
3275
|
-
function createTirecheckDeviceSdk(platform,
|
|
3276
|
-
store.securityKeys = securityKeys;
|
|
3263
|
+
function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
|
|
3277
3264
|
store.platform = platform;
|
|
3278
3265
|
bleImplementation = bleImplementation || emptyBleImplementation;
|
|
3266
|
+
store.securityKeys = securityKeys || {};
|
|
3279
3267
|
setBleImplementation(bleImplementation);
|
|
3280
3268
|
return {
|
|
3281
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",
|