tirecheck-device-sdk 0.1.5 → 0.1.6
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 +33 -13
- package/dist/index.d.cts +5 -3
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +33 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -14,13 +14,17 @@ function setBleImplementation(bleImplementation) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const store = {
|
|
17
|
-
platform: "
|
|
17
|
+
platform: "android",
|
|
18
|
+
/** Defines access level for each connection, should be 'driver' as default, Supported roles: ['manufacturer', 'driver'] , Example: F4B4553322: 'manufacturer' */
|
|
19
|
+
deviceAccessLevel: {},
|
|
18
20
|
devices: {},
|
|
19
21
|
simulatedDevices: {},
|
|
20
22
|
/** undefined - no information but since we get advertisings it is most likely disconnected, connecting - trying to connect via bluetooth, connected - connected via bluetooth (can send write and read), paired - all additional connection steps completed (setMtu, sendPin, etc) */
|
|
21
23
|
deviceState: {},
|
|
22
24
|
// undefined => connecting => connected => paired => disconnecting => disconnected
|
|
23
25
|
bridgesReboot: {},
|
|
26
|
+
//** Ios uses generated device Id, bridges send mac address in advertising so internaly we always use mac address but when real device id is needed we check mapping table for it */
|
|
27
|
+
deviceIdMapingTable: {},
|
|
24
28
|
setState(deviceId, state) {
|
|
25
29
|
this.deviceState[deviceId] = state;
|
|
26
30
|
deviceStateChangeCallback?.(deviceId, state);
|
|
@@ -306,9 +310,14 @@ const bridgeAdvertisingParser = {
|
|
|
306
310
|
const adversitingType = getAdvertisingType(device);
|
|
307
311
|
if (adversitingType !== "connectable") return void 0;
|
|
308
312
|
const advertisingData = getAdvertisingData({ advertising: device.advertising, deviceName: device.name });
|
|
309
|
-
const
|
|
313
|
+
const macArray = advertisingData?.macAddress?.map((n) => bridgeTools.decimalToHex(n).toUpperCase()).reverse() || [];
|
|
314
|
+
const bridgeId = macArray.join("");
|
|
310
315
|
const vin = String.fromCharCode(...advertisingData?.vinNum || []).split("\0").join("");
|
|
311
|
-
|
|
316
|
+
const macString = macArray.join(":");
|
|
317
|
+
if (store.platform === "ios") {
|
|
318
|
+
store.deviceIdMapingTable[macString] = device.id;
|
|
319
|
+
}
|
|
320
|
+
return { id: macString, name: device.name, bridgeId, vin, advertisingData, type: "bridge", rssi: device.rssi };
|
|
312
321
|
}
|
|
313
322
|
};
|
|
314
323
|
function getAdvertisingType(device) {
|
|
@@ -528,7 +537,8 @@ async function connect(deviceId, disconnectCallback) {
|
|
|
528
537
|
if (attempt === 3) throw new Error("Connection unsuccessful");
|
|
529
538
|
}
|
|
530
539
|
}
|
|
531
|
-
const
|
|
540
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
541
|
+
const isConnected = await ble.isConnected(_deviceId);
|
|
532
542
|
if (!isConnected) {
|
|
533
543
|
store.setState(deviceId, void 0);
|
|
534
544
|
throw new Error("Connect Error");
|
|
@@ -537,8 +547,9 @@ async function connect(deviceId, disconnectCallback) {
|
|
|
537
547
|
return connectedDevice;
|
|
538
548
|
}
|
|
539
549
|
function connectInner(deviceId, disconnectCallback) {
|
|
550
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
540
551
|
return new Promise(
|
|
541
|
-
(resolve, reject) => ble.connect(
|
|
552
|
+
(resolve, reject) => ble.connect(_deviceId, resolve, (err) => {
|
|
542
553
|
if (toolsSvc.canCommunicateWith(deviceId)) {
|
|
543
554
|
deviceLostConnectionCallback?.(deviceId);
|
|
544
555
|
disconnectCallback(deviceId);
|
|
@@ -549,8 +560,9 @@ function connectInner(deviceId, disconnectCallback) {
|
|
|
549
560
|
}
|
|
550
561
|
async function disconnect(deviceId) {
|
|
551
562
|
for (let attempts = 0; attempts < 3; attempts++) {
|
|
552
|
-
|
|
553
|
-
|
|
563
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
564
|
+
await withTimeout(ble.disconnect(_deviceId), 1e3, "Disconnect timed out");
|
|
565
|
+
const isConnected = await ble.isConnected(_deviceId);
|
|
554
566
|
if (!isConnected) return;
|
|
555
567
|
}
|
|
556
568
|
store.setState(deviceId, void 0);
|
|
@@ -559,7 +571,8 @@ async function disconnect(deviceId) {
|
|
|
559
571
|
async function write(deviceId, serviceUuid, characteristicUuid, value) {
|
|
560
572
|
if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Write Error: Not connected to device");
|
|
561
573
|
try {
|
|
562
|
-
|
|
574
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
575
|
+
await ble.writeWithoutResponse(_deviceId, serviceUuid, characteristicUuid, value);
|
|
563
576
|
} catch (e) {
|
|
564
577
|
throw new Error(`Write Error: ${e}`);
|
|
565
578
|
}
|
|
@@ -567,7 +580,8 @@ async function write(deviceId, serviceUuid, characteristicUuid, value) {
|
|
|
567
580
|
async function read(deviceId, serviceUuid, characteristicUuid) {
|
|
568
581
|
if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Read Error: Not connected to device");
|
|
569
582
|
try {
|
|
570
|
-
const
|
|
583
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
584
|
+
const value = await ble.read(_deviceId, serviceUuid, characteristicUuid);
|
|
571
585
|
return Array.from(new Uint8Array(value));
|
|
572
586
|
} catch (e) {
|
|
573
587
|
throw new Error(`Read Error: ${e}`);
|
|
@@ -1780,6 +1794,7 @@ const bridgeCommands = {
|
|
|
1780
1794
|
);
|
|
1781
1795
|
return { ...structurized, isFactory: result.isFactory };
|
|
1782
1796
|
},
|
|
1797
|
+
// Zdenek - add structure
|
|
1783
1798
|
async getAxleInfo(deviceId, axleIndex) {
|
|
1784
1799
|
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1785
1800
|
if (!___default.inRange(axleIndex, 0, 16)) throw new Error("Error getting an axle");
|
|
@@ -2614,18 +2629,22 @@ function createNewTyre(positionId) {
|
|
|
2614
2629
|
}
|
|
2615
2630
|
|
|
2616
2631
|
const bridge = {
|
|
2617
|
-
async connect(deviceId) {
|
|
2632
|
+
async connect(deviceId, accessLevel) {
|
|
2618
2633
|
await promiseQueue$1.clearQueue("Previous pending commands aborted");
|
|
2619
2634
|
const bridgeMeta = deviceMeta.bridge;
|
|
2620
2635
|
await bluetooth.connect(deviceId, this.disconnect);
|
|
2621
|
-
|
|
2636
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
2637
|
+
if (store.platform !== "ios") {
|
|
2638
|
+
await ble.requestMtu(_deviceId, deviceMeta.bridge.mtu);
|
|
2639
|
+
}
|
|
2622
2640
|
await ble.startNotification(
|
|
2623
|
-
|
|
2641
|
+
_deviceId,
|
|
2624
2642
|
bridgeMeta.communication.serviceId,
|
|
2625
2643
|
bridgeMeta.communication.characteristicId,
|
|
2626
2644
|
(notification) => promiseQueue$1.processMessage(deviceId, notification),
|
|
2627
2645
|
(error) => console.error("startNotification Error", error)
|
|
2628
2646
|
);
|
|
2647
|
+
store.deviceAccessLevel[deviceId] = accessLevel ?? "driver";
|
|
2629
2648
|
await bridgeCommands.sendPinCommand(deviceId);
|
|
2630
2649
|
store.setState(deviceId, "paired");
|
|
2631
2650
|
},
|
|
@@ -3053,7 +3072,8 @@ class BridgeTcVehicleAxle {
|
|
|
3053
3072
|
minTargetPressure;
|
|
3054
3073
|
}
|
|
3055
3074
|
|
|
3056
|
-
function createTirecheckDeviceSdk(bleImplementation) {
|
|
3075
|
+
function createTirecheckDeviceSdk(bleImplementation, platform) {
|
|
3076
|
+
store.platform = platform;
|
|
3057
3077
|
setBleImplementation(bleImplementation);
|
|
3058
3078
|
return {
|
|
3059
3079
|
/** Generic methods common for all devices */
|
package/dist/index.d.cts
CHANGED
|
@@ -705,6 +705,8 @@ interface BridgeTcVehicle {
|
|
|
705
705
|
id: string;
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
|
+
type DevicePlatform = 'ios' | 'android' | 'web';
|
|
709
|
+
type BridgeAccessLevel = 'tirecheck' | 'vehicleManufacturer' | 'vehicleDealership' | 'workshop' | 'driver';
|
|
708
710
|
interface BridgeTcTyre {
|
|
709
711
|
mountedOn?: TcTyreMountedOn;
|
|
710
712
|
serialNumber?: string;
|
|
@@ -866,7 +868,7 @@ type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
|
866
868
|
};
|
|
867
869
|
type ReportStatusFn = (status: string, completionPercentage: number) => void;
|
|
868
870
|
|
|
869
|
-
declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation): {
|
|
871
|
+
declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation, platform: DevicePlatform): {
|
|
870
872
|
/** Generic methods common for all devices */
|
|
871
873
|
bluetooth: {
|
|
872
874
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
|
@@ -882,7 +884,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation):
|
|
|
882
884
|
};
|
|
883
885
|
/** Methods for working with Tirecheck CAN Bridge */
|
|
884
886
|
bridge: {
|
|
885
|
-
connect(deviceId: string): Promise<void>;
|
|
887
|
+
connect(deviceId: string, accessLevel: BridgeAccessLevel): Promise<void>;
|
|
886
888
|
disconnect(deviceId: string): Promise<void>;
|
|
887
889
|
getVehicle: (deviceId: string) => Promise<BridgeTcVehicle>;
|
|
888
890
|
setVehicle: (deviceId: string, tcVehicle: BridgeTcVehicle) => Promise<void>;
|
|
@@ -918,4 +920,4 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation):
|
|
|
918
920
|
};
|
|
919
921
|
};
|
|
920
922
|
|
|
921
|
-
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Wrapper, createTirecheckDeviceSdk };
|
|
923
|
+
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DevicePlatform, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Wrapper, createTirecheckDeviceSdk };
|
package/dist/index.d.mts
CHANGED
|
@@ -705,6 +705,8 @@ interface BridgeTcVehicle {
|
|
|
705
705
|
id: string;
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
|
+
type DevicePlatform = 'ios' | 'android' | 'web';
|
|
709
|
+
type BridgeAccessLevel = 'tirecheck' | 'vehicleManufacturer' | 'vehicleDealership' | 'workshop' | 'driver';
|
|
708
710
|
interface BridgeTcTyre {
|
|
709
711
|
mountedOn?: TcTyreMountedOn;
|
|
710
712
|
serialNumber?: string;
|
|
@@ -866,7 +868,7 @@ type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
|
866
868
|
};
|
|
867
869
|
type ReportStatusFn = (status: string, completionPercentage: number) => void;
|
|
868
870
|
|
|
869
|
-
declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation): {
|
|
871
|
+
declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation, platform: DevicePlatform): {
|
|
870
872
|
/** Generic methods common for all devices */
|
|
871
873
|
bluetooth: {
|
|
872
874
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
|
@@ -882,7 +884,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation):
|
|
|
882
884
|
};
|
|
883
885
|
/** Methods for working with Tirecheck CAN Bridge */
|
|
884
886
|
bridge: {
|
|
885
|
-
connect(deviceId: string): Promise<void>;
|
|
887
|
+
connect(deviceId: string, accessLevel: BridgeAccessLevel): Promise<void>;
|
|
886
888
|
disconnect(deviceId: string): Promise<void>;
|
|
887
889
|
getVehicle: (deviceId: string) => Promise<BridgeTcVehicle>;
|
|
888
890
|
setVehicle: (deviceId: string, tcVehicle: BridgeTcVehicle) => Promise<void>;
|
|
@@ -918,4 +920,4 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation):
|
|
|
918
920
|
};
|
|
919
921
|
};
|
|
920
922
|
|
|
921
|
-
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Wrapper, createTirecheckDeviceSdk };
|
|
923
|
+
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DevicePlatform, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Wrapper, createTirecheckDeviceSdk };
|
package/dist/index.d.ts
CHANGED
|
@@ -705,6 +705,8 @@ interface BridgeTcVehicle {
|
|
|
705
705
|
id: string;
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
|
+
type DevicePlatform = 'ios' | 'android' | 'web';
|
|
709
|
+
type BridgeAccessLevel = 'tirecheck' | 'vehicleManufacturer' | 'vehicleDealership' | 'workshop' | 'driver';
|
|
708
710
|
interface BridgeTcTyre {
|
|
709
711
|
mountedOn?: TcTyreMountedOn;
|
|
710
712
|
serialNumber?: string;
|
|
@@ -866,7 +868,7 @@ type Wrapper<T extends Record<string, (...args: any) => any>> = {
|
|
|
866
868
|
};
|
|
867
869
|
type ReportStatusFn = (status: string, completionPercentage: number) => void;
|
|
868
870
|
|
|
869
|
-
declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation): {
|
|
871
|
+
declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation, platform: DevicePlatform): {
|
|
870
872
|
/** Generic methods common for all devices */
|
|
871
873
|
bluetooth: {
|
|
872
874
|
onDeviceAdvertising(callback: (device: BleDevice) => void): void;
|
|
@@ -882,7 +884,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation):
|
|
|
882
884
|
};
|
|
883
885
|
/** Methods for working with Tirecheck CAN Bridge */
|
|
884
886
|
bridge: {
|
|
885
|
-
connect(deviceId: string): Promise<void>;
|
|
887
|
+
connect(deviceId: string, accessLevel: BridgeAccessLevel): Promise<void>;
|
|
886
888
|
disconnect(deviceId: string): Promise<void>;
|
|
887
889
|
getVehicle: (deviceId: string) => Promise<BridgeTcVehicle>;
|
|
888
890
|
setVehicle: (deviceId: string, tcVehicle: BridgeTcVehicle) => Promise<void>;
|
|
@@ -918,4 +920,4 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation):
|
|
|
918
920
|
};
|
|
919
921
|
};
|
|
920
922
|
|
|
921
|
-
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Wrapper, createTirecheckDeviceSdk };
|
|
923
|
+
export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGaugeTpms, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DevicePlatform, type FgSensorReading, type PositionInfo, type ReportStatusFn, type Wrapper, createTirecheckDeviceSdk };
|
package/dist/index.mjs
CHANGED
|
@@ -7,13 +7,17 @@ function setBleImplementation(bleImplementation) {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const store = {
|
|
10
|
-
platform: "
|
|
10
|
+
platform: "android",
|
|
11
|
+
/** Defines access level for each connection, should be 'driver' as default, Supported roles: ['manufacturer', 'driver'] , Example: F4B4553322: 'manufacturer' */
|
|
12
|
+
deviceAccessLevel: {},
|
|
11
13
|
devices: {},
|
|
12
14
|
simulatedDevices: {},
|
|
13
15
|
/** undefined - no information but since we get advertisings it is most likely disconnected, connecting - trying to connect via bluetooth, connected - connected via bluetooth (can send write and read), paired - all additional connection steps completed (setMtu, sendPin, etc) */
|
|
14
16
|
deviceState: {},
|
|
15
17
|
// undefined => connecting => connected => paired => disconnecting => disconnected
|
|
16
18
|
bridgesReboot: {},
|
|
19
|
+
//** Ios uses generated device Id, bridges send mac address in advertising so internaly we always use mac address but when real device id is needed we check mapping table for it */
|
|
20
|
+
deviceIdMapingTable: {},
|
|
17
21
|
setState(deviceId, state) {
|
|
18
22
|
this.deviceState[deviceId] = state;
|
|
19
23
|
deviceStateChangeCallback?.(deviceId, state);
|
|
@@ -299,9 +303,14 @@ const bridgeAdvertisingParser = {
|
|
|
299
303
|
const adversitingType = getAdvertisingType(device);
|
|
300
304
|
if (adversitingType !== "connectable") return void 0;
|
|
301
305
|
const advertisingData = getAdvertisingData({ advertising: device.advertising, deviceName: device.name });
|
|
302
|
-
const
|
|
306
|
+
const macArray = advertisingData?.macAddress?.map((n) => bridgeTools.decimalToHex(n).toUpperCase()).reverse() || [];
|
|
307
|
+
const bridgeId = macArray.join("");
|
|
303
308
|
const vin = String.fromCharCode(...advertisingData?.vinNum || []).split("\0").join("");
|
|
304
|
-
|
|
309
|
+
const macString = macArray.join(":");
|
|
310
|
+
if (store.platform === "ios") {
|
|
311
|
+
store.deviceIdMapingTable[macString] = device.id;
|
|
312
|
+
}
|
|
313
|
+
return { id: macString, name: device.name, bridgeId, vin, advertisingData, type: "bridge", rssi: device.rssi };
|
|
305
314
|
}
|
|
306
315
|
};
|
|
307
316
|
function getAdvertisingType(device) {
|
|
@@ -521,7 +530,8 @@ async function connect(deviceId, disconnectCallback) {
|
|
|
521
530
|
if (attempt === 3) throw new Error("Connection unsuccessful");
|
|
522
531
|
}
|
|
523
532
|
}
|
|
524
|
-
const
|
|
533
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
534
|
+
const isConnected = await ble.isConnected(_deviceId);
|
|
525
535
|
if (!isConnected) {
|
|
526
536
|
store.setState(deviceId, void 0);
|
|
527
537
|
throw new Error("Connect Error");
|
|
@@ -530,8 +540,9 @@ async function connect(deviceId, disconnectCallback) {
|
|
|
530
540
|
return connectedDevice;
|
|
531
541
|
}
|
|
532
542
|
function connectInner(deviceId, disconnectCallback) {
|
|
543
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
533
544
|
return new Promise(
|
|
534
|
-
(resolve, reject) => ble.connect(
|
|
545
|
+
(resolve, reject) => ble.connect(_deviceId, resolve, (err) => {
|
|
535
546
|
if (toolsSvc.canCommunicateWith(deviceId)) {
|
|
536
547
|
deviceLostConnectionCallback?.(deviceId);
|
|
537
548
|
disconnectCallback(deviceId);
|
|
@@ -542,8 +553,9 @@ function connectInner(deviceId, disconnectCallback) {
|
|
|
542
553
|
}
|
|
543
554
|
async function disconnect(deviceId) {
|
|
544
555
|
for (let attempts = 0; attempts < 3; attempts++) {
|
|
545
|
-
|
|
546
|
-
|
|
556
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
557
|
+
await withTimeout(ble.disconnect(_deviceId), 1e3, "Disconnect timed out");
|
|
558
|
+
const isConnected = await ble.isConnected(_deviceId);
|
|
547
559
|
if (!isConnected) return;
|
|
548
560
|
}
|
|
549
561
|
store.setState(deviceId, void 0);
|
|
@@ -552,7 +564,8 @@ async function disconnect(deviceId) {
|
|
|
552
564
|
async function write(deviceId, serviceUuid, characteristicUuid, value) {
|
|
553
565
|
if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Write Error: Not connected to device");
|
|
554
566
|
try {
|
|
555
|
-
|
|
567
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
568
|
+
await ble.writeWithoutResponse(_deviceId, serviceUuid, characteristicUuid, value);
|
|
556
569
|
} catch (e) {
|
|
557
570
|
throw new Error(`Write Error: ${e}`);
|
|
558
571
|
}
|
|
@@ -560,7 +573,8 @@ async function write(deviceId, serviceUuid, characteristicUuid, value) {
|
|
|
560
573
|
async function read(deviceId, serviceUuid, characteristicUuid) {
|
|
561
574
|
if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Read Error: Not connected to device");
|
|
562
575
|
try {
|
|
563
|
-
const
|
|
576
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
577
|
+
const value = await ble.read(_deviceId, serviceUuid, characteristicUuid);
|
|
564
578
|
return Array.from(new Uint8Array(value));
|
|
565
579
|
} catch (e) {
|
|
566
580
|
throw new Error(`Read Error: ${e}`);
|
|
@@ -1773,6 +1787,7 @@ const bridgeCommands = {
|
|
|
1773
1787
|
);
|
|
1774
1788
|
return { ...structurized, isFactory: result.isFactory };
|
|
1775
1789
|
},
|
|
1790
|
+
// Zdenek - add structure
|
|
1776
1791
|
async getAxleInfo(deviceId, axleIndex) {
|
|
1777
1792
|
const deviceData = bridgeTools.getBridgeFromStore(deviceId);
|
|
1778
1793
|
if (!_.inRange(axleIndex, 0, 16)) throw new Error("Error getting an axle");
|
|
@@ -2607,18 +2622,22 @@ function createNewTyre(positionId) {
|
|
|
2607
2622
|
}
|
|
2608
2623
|
|
|
2609
2624
|
const bridge = {
|
|
2610
|
-
async connect(deviceId) {
|
|
2625
|
+
async connect(deviceId, accessLevel) {
|
|
2611
2626
|
await promiseQueue$1.clearQueue("Previous pending commands aborted");
|
|
2612
2627
|
const bridgeMeta = deviceMeta.bridge;
|
|
2613
2628
|
await bluetooth.connect(deviceId, this.disconnect);
|
|
2614
|
-
|
|
2629
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
2630
|
+
if (store.platform !== "ios") {
|
|
2631
|
+
await ble.requestMtu(_deviceId, deviceMeta.bridge.mtu);
|
|
2632
|
+
}
|
|
2615
2633
|
await ble.startNotification(
|
|
2616
|
-
|
|
2634
|
+
_deviceId,
|
|
2617
2635
|
bridgeMeta.communication.serviceId,
|
|
2618
2636
|
bridgeMeta.communication.characteristicId,
|
|
2619
2637
|
(notification) => promiseQueue$1.processMessage(deviceId, notification),
|
|
2620
2638
|
(error) => console.error("startNotification Error", error)
|
|
2621
2639
|
);
|
|
2640
|
+
store.deviceAccessLevel[deviceId] = accessLevel ?? "driver";
|
|
2622
2641
|
await bridgeCommands.sendPinCommand(deviceId);
|
|
2623
2642
|
store.setState(deviceId, "paired");
|
|
2624
2643
|
},
|
|
@@ -3046,7 +3065,8 @@ class BridgeTcVehicleAxle {
|
|
|
3046
3065
|
minTargetPressure;
|
|
3047
3066
|
}
|
|
3048
3067
|
|
|
3049
|
-
function createTirecheckDeviceSdk(bleImplementation) {
|
|
3068
|
+
function createTirecheckDeviceSdk(bleImplementation, platform) {
|
|
3069
|
+
store.platform = platform;
|
|
3050
3070
|
setBleImplementation(bleImplementation);
|
|
3051
3071
|
return {
|
|
3052
3072
|
/** 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.6",
|
|
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",
|