tirecheck-device-sdk 0.1.6 → 0.1.8
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/README.md +5 -0
- package/dist/index.cjs +48 -9
- package/dist/index.d.cts +5 -2
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +48 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,6 +54,11 @@ await tirecheckDeviceSdk.bridge.readVehicleSchema(deviceId)
|
|
|
54
54
|
|
|
55
55
|
That should open Vitest's UI. Feel free to add new functionality and tests.
|
|
56
56
|
|
|
57
|
+
### Publishing your changes
|
|
58
|
+
|
|
59
|
+
CI is set up in a way that new version of package is published to NPM if change in `package.json`'s `version` field is
|
|
60
|
+
detected. So, if you want to publish your changes, increment version in package.json as part of your merge request.
|
|
61
|
+
|
|
57
62
|
### Test-driven development
|
|
58
63
|
|
|
59
64
|
For this project, we advice to follow TDD for every feature. That means that you first write failing test, and then add
|
package/dist/index.cjs
CHANGED
|
@@ -407,6 +407,49 @@ function processIosAdvertising(adv, isKrone) {
|
|
|
407
407
|
return advertisingData;
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
+
const bridgeOtaAdvertisingParser = {
|
|
411
|
+
getDeviceInfoFromAdvertising: (device) => {
|
|
412
|
+
const adv = Array.from(new Uint8Array(device.advertising));
|
|
413
|
+
let deviceId = "";
|
|
414
|
+
let bridgeId = "";
|
|
415
|
+
let processedByteCount = 0;
|
|
416
|
+
if (store.platform === "ios") {
|
|
417
|
+
if (!device.advertising.kCBAdvDataLeBluetoothDeviceAddress)
|
|
418
|
+
return console.warn("No mac address in advertising data");
|
|
419
|
+
const macAddress = Array.from(new Uint8Array(device.advertising.kCBAdvDataLeBluetoothDeviceAddress)).map(
|
|
420
|
+
(x) => bridgeTools.decimalToHex(x).toUpperCase()
|
|
421
|
+
);
|
|
422
|
+
deviceId = macAddress.join(":");
|
|
423
|
+
bridgeId = macAddress.join("");
|
|
424
|
+
} else {
|
|
425
|
+
do {
|
|
426
|
+
const length = adv[processedByteCount];
|
|
427
|
+
const identificator = adv[processedByteCount + 1];
|
|
428
|
+
const packet = adv.slice(processedByteCount, processedByteCount + length + 1);
|
|
429
|
+
if (!length) {
|
|
430
|
+
processedByteCount = adv.length;
|
|
431
|
+
}
|
|
432
|
+
processedByteCount += length + 1;
|
|
433
|
+
if (identificator === 27) {
|
|
434
|
+
const macAddress = packet.slice(-6).reverse().map((x) => bridgeTools.decimalToHex(x).toUpperCase());
|
|
435
|
+
deviceId = macAddress.join(":");
|
|
436
|
+
bridgeId = macAddress.join("");
|
|
437
|
+
processedByteCount = adv.length;
|
|
438
|
+
}
|
|
439
|
+
} while (processedByteCount < adv.length);
|
|
440
|
+
}
|
|
441
|
+
if (!deviceId) return console.warn("Failed to get device Id");
|
|
442
|
+
store.deviceIdMapingTable[deviceId] = device.id;
|
|
443
|
+
const bleDevice = {
|
|
444
|
+
...device,
|
|
445
|
+
id: deviceId,
|
|
446
|
+
advertisingData: { bridgeId },
|
|
447
|
+
type: "bridgeOta"
|
|
448
|
+
};
|
|
449
|
+
return bleDevice;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
|
|
410
453
|
const deviceMeta = {
|
|
411
454
|
bridge: {
|
|
412
455
|
nameRegex: /(030303|030321)/,
|
|
@@ -424,13 +467,7 @@ const deviceMeta = {
|
|
|
424
467
|
serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
|
|
425
468
|
characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d7"
|
|
426
469
|
},
|
|
427
|
-
getDeviceInfoFromAdvertising:
|
|
428
|
-
const bleDevice = {
|
|
429
|
-
...device,
|
|
430
|
-
type: "bridgeOta"
|
|
431
|
-
};
|
|
432
|
-
return bleDevice;
|
|
433
|
-
}
|
|
470
|
+
getDeviceInfoFromAdvertising: bridgeOtaAdvertisingParser.getDeviceInfoFromAdvertising
|
|
434
471
|
},
|
|
435
472
|
flexiGaugeTpms: {
|
|
436
473
|
nameRegex: /Flexi.*/,
|
|
@@ -526,6 +563,7 @@ async function scanDevices(services = [], duration) {
|
|
|
526
563
|
);
|
|
527
564
|
}
|
|
528
565
|
async function connect(deviceId, disconnectCallback) {
|
|
566
|
+
if (toolsSvc.canCommunicateWith(deviceId)) return console.warn("Connect Warn: Already connected to device");
|
|
529
567
|
store.setState(deviceId, "connecting");
|
|
530
568
|
let connectedDevice;
|
|
531
569
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
@@ -1942,7 +1980,7 @@ const bridgeOtaCommands = {
|
|
|
1942
1980
|
}
|
|
1943
1981
|
};
|
|
1944
1982
|
|
|
1945
|
-
const mtu = 180;
|
|
1983
|
+
const mtu = store.platform === "android" ? 512 : 180;
|
|
1946
1984
|
const bridgeOtaService = {
|
|
1947
1985
|
async updateFirmware(deviceId, bootloader, firmware, progressCallback) {
|
|
1948
1986
|
await delay(2e3);
|
|
@@ -1958,7 +1996,7 @@ const bridgeOtaService = {
|
|
|
1958
1996
|
await bridgeOtaCommands.endOta(deviceId);
|
|
1959
1997
|
progressCallback("Upload completed, disconnecting...", 0.81);
|
|
1960
1998
|
await bridgeOta.disconnect(deviceId);
|
|
1961
|
-
progressCallback("Disconnected...",
|
|
1999
|
+
progressCallback("Disconnected...", 1);
|
|
1962
2000
|
}
|
|
1963
2001
|
};
|
|
1964
2002
|
async function uploadOta(deviceId, firmwareBinary, reportStatus) {
|
|
@@ -2630,6 +2668,7 @@ function createNewTyre(positionId) {
|
|
|
2630
2668
|
|
|
2631
2669
|
const bridge = {
|
|
2632
2670
|
async connect(deviceId, accessLevel) {
|
|
2671
|
+
if (canCommunicateWith(deviceId)) return;
|
|
2633
2672
|
await promiseQueue$1.clearQueue("Previous pending commands aborted");
|
|
2634
2673
|
const bridgeMeta = deviceMeta.bridge;
|
|
2635
2674
|
await bluetooth.connect(deviceId, this.disconnect);
|
package/dist/index.d.cts
CHANGED
|
@@ -66,7 +66,7 @@ declare const _default$1: {
|
|
|
66
66
|
serviceId: string;
|
|
67
67
|
characteristicId: string;
|
|
68
68
|
};
|
|
69
|
-
getDeviceInfoFromAdvertising: (device: PeripheralData) =>
|
|
69
|
+
getDeviceInfoFromAdvertising: (device: PeripheralData) => void | BleDevice;
|
|
70
70
|
};
|
|
71
71
|
flexiGaugeTpms: {
|
|
72
72
|
nameRegex: RegExp;
|
|
@@ -838,6 +838,9 @@ interface BleFlexiGaugeTpms extends BleDeviceBase {
|
|
|
838
838
|
type: 'flexiGaugeTpms';
|
|
839
839
|
}
|
|
840
840
|
interface BleBridgeOta extends BleDeviceBase {
|
|
841
|
+
advertisingData: {
|
|
842
|
+
bridgeId: string;
|
|
843
|
+
};
|
|
841
844
|
type: 'bridgeOta';
|
|
842
845
|
}
|
|
843
846
|
interface BleBridgeSimulated extends BleBridge {
|
|
@@ -877,7 +880,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation,
|
|
|
877
880
|
onDeviceStateChange(callback: (deviceId: string, state: string | undefined) => void): void;
|
|
878
881
|
scanDevices: (services?: string[], duration?: number) => Promise<void>;
|
|
879
882
|
stopScan(): void;
|
|
880
|
-
connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<
|
|
883
|
+
connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<void | PeripheralDataExtended>;
|
|
881
884
|
disconnect: (deviceId: string) => Promise<void>;
|
|
882
885
|
write: (deviceId: string, serviceUuid: string, characteristicUuid: string, value: ArrayBuffer) => Promise<void>;
|
|
883
886
|
read: (deviceId: string, serviceUuid: string, characteristicUuid: string) => Promise<number[]>;
|
package/dist/index.d.mts
CHANGED
|
@@ -66,7 +66,7 @@ declare const _default$1: {
|
|
|
66
66
|
serviceId: string;
|
|
67
67
|
characteristicId: string;
|
|
68
68
|
};
|
|
69
|
-
getDeviceInfoFromAdvertising: (device: PeripheralData) =>
|
|
69
|
+
getDeviceInfoFromAdvertising: (device: PeripheralData) => void | BleDevice;
|
|
70
70
|
};
|
|
71
71
|
flexiGaugeTpms: {
|
|
72
72
|
nameRegex: RegExp;
|
|
@@ -838,6 +838,9 @@ interface BleFlexiGaugeTpms extends BleDeviceBase {
|
|
|
838
838
|
type: 'flexiGaugeTpms';
|
|
839
839
|
}
|
|
840
840
|
interface BleBridgeOta extends BleDeviceBase {
|
|
841
|
+
advertisingData: {
|
|
842
|
+
bridgeId: string;
|
|
843
|
+
};
|
|
841
844
|
type: 'bridgeOta';
|
|
842
845
|
}
|
|
843
846
|
interface BleBridgeSimulated extends BleBridge {
|
|
@@ -877,7 +880,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation,
|
|
|
877
880
|
onDeviceStateChange(callback: (deviceId: string, state: string | undefined) => void): void;
|
|
878
881
|
scanDevices: (services?: string[], duration?: number) => Promise<void>;
|
|
879
882
|
stopScan(): void;
|
|
880
|
-
connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<
|
|
883
|
+
connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<void | PeripheralDataExtended>;
|
|
881
884
|
disconnect: (deviceId: string) => Promise<void>;
|
|
882
885
|
write: (deviceId: string, serviceUuid: string, characteristicUuid: string, value: ArrayBuffer) => Promise<void>;
|
|
883
886
|
read: (deviceId: string, serviceUuid: string, characteristicUuid: string) => Promise<number[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ declare const _default$1: {
|
|
|
66
66
|
serviceId: string;
|
|
67
67
|
characteristicId: string;
|
|
68
68
|
};
|
|
69
|
-
getDeviceInfoFromAdvertising: (device: PeripheralData) =>
|
|
69
|
+
getDeviceInfoFromAdvertising: (device: PeripheralData) => void | BleDevice;
|
|
70
70
|
};
|
|
71
71
|
flexiGaugeTpms: {
|
|
72
72
|
nameRegex: RegExp;
|
|
@@ -838,6 +838,9 @@ interface BleFlexiGaugeTpms extends BleDeviceBase {
|
|
|
838
838
|
type: 'flexiGaugeTpms';
|
|
839
839
|
}
|
|
840
840
|
interface BleBridgeOta extends BleDeviceBase {
|
|
841
|
+
advertisingData: {
|
|
842
|
+
bridgeId: string;
|
|
843
|
+
};
|
|
841
844
|
type: 'bridgeOta';
|
|
842
845
|
}
|
|
843
846
|
interface BleBridgeSimulated extends BleBridge {
|
|
@@ -877,7 +880,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation,
|
|
|
877
880
|
onDeviceStateChange(callback: (deviceId: string, state: string | undefined) => void): void;
|
|
878
881
|
scanDevices: (services?: string[], duration?: number) => Promise<void>;
|
|
879
882
|
stopScan(): void;
|
|
880
|
-
connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<
|
|
883
|
+
connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<void | PeripheralDataExtended>;
|
|
881
884
|
disconnect: (deviceId: string) => Promise<void>;
|
|
882
885
|
write: (deviceId: string, serviceUuid: string, characteristicUuid: string, value: ArrayBuffer) => Promise<void>;
|
|
883
886
|
read: (deviceId: string, serviceUuid: string, characteristicUuid: string) => Promise<number[]>;
|
package/dist/index.mjs
CHANGED
|
@@ -400,6 +400,49 @@ function processIosAdvertising(adv, isKrone) {
|
|
|
400
400
|
return advertisingData;
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
+
const bridgeOtaAdvertisingParser = {
|
|
404
|
+
getDeviceInfoFromAdvertising: (device) => {
|
|
405
|
+
const adv = Array.from(new Uint8Array(device.advertising));
|
|
406
|
+
let deviceId = "";
|
|
407
|
+
let bridgeId = "";
|
|
408
|
+
let processedByteCount = 0;
|
|
409
|
+
if (store.platform === "ios") {
|
|
410
|
+
if (!device.advertising.kCBAdvDataLeBluetoothDeviceAddress)
|
|
411
|
+
return console.warn("No mac address in advertising data");
|
|
412
|
+
const macAddress = Array.from(new Uint8Array(device.advertising.kCBAdvDataLeBluetoothDeviceAddress)).map(
|
|
413
|
+
(x) => bridgeTools.decimalToHex(x).toUpperCase()
|
|
414
|
+
);
|
|
415
|
+
deviceId = macAddress.join(":");
|
|
416
|
+
bridgeId = macAddress.join("");
|
|
417
|
+
} else {
|
|
418
|
+
do {
|
|
419
|
+
const length = adv[processedByteCount];
|
|
420
|
+
const identificator = adv[processedByteCount + 1];
|
|
421
|
+
const packet = adv.slice(processedByteCount, processedByteCount + length + 1);
|
|
422
|
+
if (!length) {
|
|
423
|
+
processedByteCount = adv.length;
|
|
424
|
+
}
|
|
425
|
+
processedByteCount += length + 1;
|
|
426
|
+
if (identificator === 27) {
|
|
427
|
+
const macAddress = packet.slice(-6).reverse().map((x) => bridgeTools.decimalToHex(x).toUpperCase());
|
|
428
|
+
deviceId = macAddress.join(":");
|
|
429
|
+
bridgeId = macAddress.join("");
|
|
430
|
+
processedByteCount = adv.length;
|
|
431
|
+
}
|
|
432
|
+
} while (processedByteCount < adv.length);
|
|
433
|
+
}
|
|
434
|
+
if (!deviceId) return console.warn("Failed to get device Id");
|
|
435
|
+
store.deviceIdMapingTable[deviceId] = device.id;
|
|
436
|
+
const bleDevice = {
|
|
437
|
+
...device,
|
|
438
|
+
id: deviceId,
|
|
439
|
+
advertisingData: { bridgeId },
|
|
440
|
+
type: "bridgeOta"
|
|
441
|
+
};
|
|
442
|
+
return bleDevice;
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
|
|
403
446
|
const deviceMeta = {
|
|
404
447
|
bridge: {
|
|
405
448
|
nameRegex: /(030303|030321)/,
|
|
@@ -417,13 +460,7 @@ const deviceMeta = {
|
|
|
417
460
|
serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
|
|
418
461
|
characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d7"
|
|
419
462
|
},
|
|
420
|
-
getDeviceInfoFromAdvertising:
|
|
421
|
-
const bleDevice = {
|
|
422
|
-
...device,
|
|
423
|
-
type: "bridgeOta"
|
|
424
|
-
};
|
|
425
|
-
return bleDevice;
|
|
426
|
-
}
|
|
463
|
+
getDeviceInfoFromAdvertising: bridgeOtaAdvertisingParser.getDeviceInfoFromAdvertising
|
|
427
464
|
},
|
|
428
465
|
flexiGaugeTpms: {
|
|
429
466
|
nameRegex: /Flexi.*/,
|
|
@@ -519,6 +556,7 @@ async function scanDevices(services = [], duration) {
|
|
|
519
556
|
);
|
|
520
557
|
}
|
|
521
558
|
async function connect(deviceId, disconnectCallback) {
|
|
559
|
+
if (toolsSvc.canCommunicateWith(deviceId)) return console.warn("Connect Warn: Already connected to device");
|
|
522
560
|
store.setState(deviceId, "connecting");
|
|
523
561
|
let connectedDevice;
|
|
524
562
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
@@ -1935,7 +1973,7 @@ const bridgeOtaCommands = {
|
|
|
1935
1973
|
}
|
|
1936
1974
|
};
|
|
1937
1975
|
|
|
1938
|
-
const mtu = 180;
|
|
1976
|
+
const mtu = store.platform === "android" ? 512 : 180;
|
|
1939
1977
|
const bridgeOtaService = {
|
|
1940
1978
|
async updateFirmware(deviceId, bootloader, firmware, progressCallback) {
|
|
1941
1979
|
await delay(2e3);
|
|
@@ -1951,7 +1989,7 @@ const bridgeOtaService = {
|
|
|
1951
1989
|
await bridgeOtaCommands.endOta(deviceId);
|
|
1952
1990
|
progressCallback("Upload completed, disconnecting...", 0.81);
|
|
1953
1991
|
await bridgeOta.disconnect(deviceId);
|
|
1954
|
-
progressCallback("Disconnected...",
|
|
1992
|
+
progressCallback("Disconnected...", 1);
|
|
1955
1993
|
}
|
|
1956
1994
|
};
|
|
1957
1995
|
async function uploadOta(deviceId, firmwareBinary, reportStatus) {
|
|
@@ -2623,6 +2661,7 @@ function createNewTyre(positionId) {
|
|
|
2623
2661
|
|
|
2624
2662
|
const bridge = {
|
|
2625
2663
|
async connect(deviceId, accessLevel) {
|
|
2664
|
+
if (canCommunicateWith(deviceId)) return;
|
|
2626
2665
|
await promiseQueue$1.clearQueue("Previous pending commands aborted");
|
|
2627
2666
|
const bridgeMeta = deviceMeta.bridge;
|
|
2628
2667
|
await bluetooth.connect(deviceId, this.disconnect);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tirecheck-device-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"typecheck": "pnpm tsc --noEmit",
|
|
47
47
|
"lint": "eslint \"{src,test}/**/*.{vue,ts,js}\"",
|
|
48
48
|
"dev": "pnpm install && vitest --ui",
|
|
49
|
-
"dev-server-old": "ts-node ./devServer/devServer.ts",
|
|
50
49
|
"dev-server": "npx --yes listhen -w --ws --open ./devServer/devServer.ts",
|
|
51
50
|
"dev-ngrok": "node --loader ts-node/esm ./devServer/ngrok.mts",
|
|
51
|
+
"npmPublish": "node --loader ts-node/esm ./scripts/npmPublish.mts",
|
|
52
52
|
"build": "unbuild"
|
|
53
53
|
}
|
|
54
54
|
}
|