tirecheck-device-sdk 0.1.8 → 0.1.91
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 +171 -53
- package/dist/index.d.cts +64 -43
- package/dist/index.d.mts +64 -43
- package/dist/index.d.ts +64 -43
- package/dist/index.mjs +171 -53
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,13 +21,15 @@ const store = {
|
|
|
21
21
|
simulatedDevices: {},
|
|
22
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) */
|
|
23
23
|
deviceState: {},
|
|
24
|
-
// undefined => connecting => connected => paired => disconnecting =>
|
|
24
|
+
// undefined => connecting => connected => paired => disconnecting => undefined
|
|
25
25
|
bridgesReboot: {},
|
|
26
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
27
|
deviceIdMapingTable: {},
|
|
28
|
-
|
|
28
|
+
/** Used to change device state in store, also notifies app via calback. Every undefined state should have its reason so that app can handle it accordingly */
|
|
29
|
+
setState(deviceId, state, reason) {
|
|
30
|
+
if (state === void 0 && !reason) console.error("setState called with undefined state and no reason");
|
|
29
31
|
this.deviceState[deviceId] = state;
|
|
30
|
-
deviceStateChangeCallback?.(deviceId, state);
|
|
32
|
+
deviceStateChangeCallback?.(deviceId, state, reason);
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
35
|
|
|
@@ -147,6 +149,9 @@ const bridgeTools = {
|
|
|
147
149
|
if (displayUnits === "decimal") {
|
|
148
150
|
return Number(`0x${_reversedData.map((dec) => this.decimalToHex(dec)).join("")}`.replace(/\r\n/g, ""));
|
|
149
151
|
}
|
|
152
|
+
if (displayUnits === "reverseHex") {
|
|
153
|
+
return _reversedData.map((dec) => this.decimalToHex(dec).split("").reverse().join("")).join("");
|
|
154
|
+
}
|
|
150
155
|
return _reversedData.map((dec) => this.decimalToHex(dec)).join("");
|
|
151
156
|
},
|
|
152
157
|
encodeData(data, displayUnits) {
|
|
@@ -157,6 +162,11 @@ const bridgeTools = {
|
|
|
157
162
|
if (displayUnits === "decimal") {
|
|
158
163
|
return this.hexToDecimalArray(this.decimalToHex(_data)).reverse();
|
|
159
164
|
}
|
|
165
|
+
if (displayUnits === "reverseHex") {
|
|
166
|
+
const byteArray = _data.match(/.{1,2}/g) || [];
|
|
167
|
+
const reversedBytes = byteArray.map((b) => b.split("").reverse().join(""));
|
|
168
|
+
return this.hexToDecimalArray(reversedBytes.join("")).reverse();
|
|
169
|
+
}
|
|
160
170
|
return this.hexToDecimalArray(_data).reverse();
|
|
161
171
|
},
|
|
162
172
|
// getBridgeId(device: BluetoothDeviceBridge) {
|
|
@@ -322,7 +332,8 @@ const bridgeAdvertisingParser = {
|
|
|
322
332
|
};
|
|
323
333
|
function getAdvertisingType(device) {
|
|
324
334
|
if (device.advertising?.kCBAdvDataIsConnectable) {
|
|
325
|
-
|
|
335
|
+
const adv = Array.from(new Uint8Array(device.advertising.kCBAdvDataManufacturerData));
|
|
336
|
+
return adv.length > 34 ? "connectable" : "unknown";
|
|
326
337
|
}
|
|
327
338
|
const numberArray = Array.from(new Uint8Array(device.advertising));
|
|
328
339
|
if (___default.isEqual(numberArray.slice(0, 4), [2, 1, 6, 7])) {
|
|
@@ -414,11 +425,8 @@ const bridgeOtaAdvertisingParser = {
|
|
|
414
425
|
let bridgeId = "";
|
|
415
426
|
let processedByteCount = 0;
|
|
416
427
|
if (store.platform === "ios") {
|
|
417
|
-
if (!device.advertising.kCBAdvDataLeBluetoothDeviceAddress)
|
|
418
|
-
|
|
419
|
-
const macAddress = Array.from(new Uint8Array(device.advertising.kCBAdvDataLeBluetoothDeviceAddress)).map(
|
|
420
|
-
(x) => bridgeTools.decimalToHex(x).toUpperCase()
|
|
421
|
-
);
|
|
428
|
+
if (!device.advertising.kCBAdvDataLeBluetoothDeviceAddress) return void 0;
|
|
429
|
+
const macAddress = Array.from(new Uint8Array(device.advertising.kCBAdvDataLeBluetoothDeviceAddress)).slice(-6).reverse().map((x) => bridgeTools.decimalToHex(x).toUpperCase());
|
|
422
430
|
deviceId = macAddress.join(":");
|
|
423
431
|
bridgeId = macAddress.join("");
|
|
424
432
|
} else {
|
|
@@ -438,7 +446,7 @@ const bridgeOtaAdvertisingParser = {
|
|
|
438
446
|
}
|
|
439
447
|
} while (processedByteCount < adv.length);
|
|
440
448
|
}
|
|
441
|
-
if (!deviceId) return
|
|
449
|
+
if (!deviceId) return void 0;
|
|
442
450
|
store.deviceIdMapingTable[deviceId] = device.id;
|
|
443
451
|
const bleDevice = {
|
|
444
452
|
...device,
|
|
@@ -463,6 +471,7 @@ const deviceMeta = {
|
|
|
463
471
|
},
|
|
464
472
|
bridgeOta: {
|
|
465
473
|
nameRegex: /(CAN BLE BRDG OTA.*|0303.{2}_B)/,
|
|
474
|
+
mtu: store.platform === "android" ? 512 : 180,
|
|
466
475
|
characteristic: {
|
|
467
476
|
serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
|
|
468
477
|
characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d7"
|
|
@@ -515,19 +524,17 @@ const deviceMeta = {
|
|
|
515
524
|
const checkUnreachableDevicesTimeouts = {};
|
|
516
525
|
let deviceAdvertisingCallback;
|
|
517
526
|
let deviceUnreachableCallback;
|
|
518
|
-
let deviceLostConnectionCallback;
|
|
519
527
|
let deviceStateChangeCallback;
|
|
520
528
|
const bluetooth = {
|
|
521
529
|
/** Triggered when "scanDevices" detects device supported by SDK */
|
|
522
530
|
onDeviceAdvertising(callback) {
|
|
523
531
|
deviceAdvertisingCallback = callback;
|
|
524
532
|
},
|
|
533
|
+
/** Triggered when device doesnt send advertisement for 60 seconds */
|
|
525
534
|
onDeviceUnreachable(callback) {
|
|
526
535
|
deviceUnreachableCallback = callback;
|
|
527
536
|
},
|
|
528
|
-
|
|
529
|
-
deviceLostConnectionCallback = callback;
|
|
530
|
-
},
|
|
537
|
+
/** Triggered when device changed state, allows app to react to state changes */
|
|
531
538
|
onDeviceStateChange(callback) {
|
|
532
539
|
deviceStateChangeCallback = callback;
|
|
533
540
|
},
|
|
@@ -572,13 +579,17 @@ async function connect(deviceId, disconnectCallback) {
|
|
|
572
579
|
if (connectedDevice) break;
|
|
573
580
|
} catch (e) {
|
|
574
581
|
console.warn(`${attempt} connect fail`, e);
|
|
575
|
-
if (attempt === 3)
|
|
582
|
+
if (attempt === 3) {
|
|
583
|
+
store.setState(deviceId, void 0, "failedConnection");
|
|
584
|
+
throw new Error("Connection unsuccessful");
|
|
585
|
+
}
|
|
576
586
|
}
|
|
577
587
|
}
|
|
588
|
+
clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
|
|
578
589
|
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
579
590
|
const isConnected = await ble.isConnected(_deviceId);
|
|
580
591
|
if (!isConnected) {
|
|
581
|
-
store.setState(deviceId, void 0);
|
|
592
|
+
store.setState(deviceId, void 0, "failedConnection");
|
|
582
593
|
throw new Error("Connect Error");
|
|
583
594
|
}
|
|
584
595
|
store.setState(deviceId, "connected");
|
|
@@ -589,8 +600,7 @@ function connectInner(deviceId, disconnectCallback) {
|
|
|
589
600
|
return new Promise(
|
|
590
601
|
(resolve, reject) => ble.connect(_deviceId, resolve, (err) => {
|
|
591
602
|
if (toolsSvc.canCommunicateWith(deviceId)) {
|
|
592
|
-
|
|
593
|
-
disconnectCallback(deviceId);
|
|
603
|
+
disconnectCallback(deviceId, "lostConnection");
|
|
594
604
|
}
|
|
595
605
|
reject(err);
|
|
596
606
|
})
|
|
@@ -603,14 +613,18 @@ async function disconnect(deviceId) {
|
|
|
603
613
|
const isConnected = await ble.isConnected(_deviceId);
|
|
604
614
|
if (!isConnected) return;
|
|
605
615
|
}
|
|
606
|
-
store.setState(deviceId, void 0);
|
|
616
|
+
store.setState(deviceId, void 0, "failedDisconnection");
|
|
607
617
|
throw new Error("Disconnect unsuccessful");
|
|
608
618
|
}
|
|
609
|
-
async function write(deviceId, serviceUuid, characteristicUuid, value) {
|
|
619
|
+
async function write(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
|
|
610
620
|
if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Write Error: Not connected to device");
|
|
611
621
|
try {
|
|
612
622
|
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
613
|
-
|
|
623
|
+
if (withResponse) {
|
|
624
|
+
await ble.write(_deviceId, serviceUuid, characteristicUuid, value);
|
|
625
|
+
} else {
|
|
626
|
+
await ble.writeWithoutResponse(_deviceId, serviceUuid, characteristicUuid, value);
|
|
627
|
+
}
|
|
614
628
|
} catch (e) {
|
|
615
629
|
throw new Error(`Write Error: ${e}`);
|
|
616
630
|
}
|
|
@@ -657,7 +671,7 @@ function refreshUnreachableTimeouts(deviceId) {
|
|
|
657
671
|
clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
|
|
658
672
|
}
|
|
659
673
|
checkUnreachableDevicesTimeouts[deviceId] = setTimeout(() => {
|
|
660
|
-
store.
|
|
674
|
+
delete store.devices[deviceId];
|
|
661
675
|
deviceUnreachableCallback?.(deviceId);
|
|
662
676
|
}, 6e4);
|
|
663
677
|
}
|
|
@@ -1165,63 +1179,78 @@ const bridgeCommandStructures = {
|
|
|
1165
1179
|
structure: {
|
|
1166
1180
|
axle01: {
|
|
1167
1181
|
size: 8,
|
|
1168
|
-
description: "Axle 01 autolearn statuses, each nibble signifies a single wheel."
|
|
1182
|
+
description: "Axle 01 autolearn statuses, each nibble signifies a single wheel.",
|
|
1183
|
+
display: "reverseHex"
|
|
1169
1184
|
},
|
|
1170
1185
|
axle02: {
|
|
1171
1186
|
size: 8,
|
|
1172
|
-
description: "Axle 02 autolearn statuses, each nibble signifies a single wheel"
|
|
1187
|
+
description: "Axle 02 autolearn statuses, each nibble signifies a single wheel",
|
|
1188
|
+
display: "reverseHex"
|
|
1173
1189
|
},
|
|
1174
1190
|
axle03: {
|
|
1175
1191
|
size: 8,
|
|
1176
|
-
description: "Axle 03 autolearn statuses, each nibble signifies a single wheel"
|
|
1192
|
+
description: "Axle 03 autolearn statuses, each nibble signifies a single wheel",
|
|
1193
|
+
display: "reverseHex"
|
|
1177
1194
|
},
|
|
1178
1195
|
axle04: {
|
|
1179
1196
|
size: 8,
|
|
1180
|
-
description: "Axle 04 autolearn statuses, each nibble signifies a single wheel"
|
|
1197
|
+
description: "Axle 04 autolearn statuses, each nibble signifies a single wheel",
|
|
1198
|
+
display: "reverseHex"
|
|
1181
1199
|
},
|
|
1182
1200
|
axle05: {
|
|
1183
1201
|
size: 8,
|
|
1184
|
-
description: "Axle 05 autolearn statuses, each nibble signifies a single wheel"
|
|
1202
|
+
description: "Axle 05 autolearn statuses, each nibble signifies a single wheel",
|
|
1203
|
+
display: "reverseHex"
|
|
1185
1204
|
},
|
|
1186
1205
|
axle06: {
|
|
1187
1206
|
size: 8,
|
|
1188
|
-
description: "Axle 06 autolearn statuses, each nibble signifies a single wheel"
|
|
1207
|
+
description: "Axle 06 autolearn statuses, each nibble signifies a single wheel",
|
|
1208
|
+
display: "reverseHex"
|
|
1189
1209
|
},
|
|
1190
1210
|
axle07: {
|
|
1191
1211
|
size: 8,
|
|
1192
|
-
description: "Axle 07 autolearn statuses, each nibble signifies a single wheel"
|
|
1212
|
+
description: "Axle 07 autolearn statuses, each nibble signifies a single wheel",
|
|
1213
|
+
display: "reverseHex"
|
|
1193
1214
|
},
|
|
1194
1215
|
axle08: {
|
|
1195
1216
|
size: 8,
|
|
1196
|
-
description: "Axle 08 autolearn statuses, each nibble signifies a single wheel"
|
|
1217
|
+
description: "Axle 08 autolearn statuses, each nibble signifies a single wheel",
|
|
1218
|
+
display: "reverseHex"
|
|
1197
1219
|
},
|
|
1198
1220
|
axle09: {
|
|
1199
1221
|
size: 8,
|
|
1200
|
-
description: "Axle 09 autolearn statuses, each nibble signifies a single wheel"
|
|
1222
|
+
description: "Axle 09 autolearn statuses, each nibble signifies a single wheel",
|
|
1223
|
+
display: "reverseHex"
|
|
1201
1224
|
},
|
|
1202
1225
|
axle10: {
|
|
1203
1226
|
size: 8,
|
|
1204
|
-
description: "Axle 10 autolearn statuses, each nibble signifies a single wheel"
|
|
1227
|
+
description: "Axle 10 autolearn statuses, each nibble signifies a single wheel",
|
|
1228
|
+
display: "reverseHex"
|
|
1205
1229
|
},
|
|
1206
1230
|
axle11: {
|
|
1207
1231
|
size: 8,
|
|
1208
|
-
description: "Axle 11 autolearn statuses, each nibble signifies a single wheel"
|
|
1232
|
+
description: "Axle 11 autolearn statuses, each nibble signifies a single wheel",
|
|
1233
|
+
display: "reverseHex"
|
|
1209
1234
|
},
|
|
1210
1235
|
axle12: {
|
|
1211
1236
|
size: 8,
|
|
1212
|
-
description: "Axle 12 autolearn statuses, each nibble signifies a single wheel"
|
|
1237
|
+
description: "Axle 12 autolearn statuses, each nibble signifies a single wheel",
|
|
1238
|
+
display: "reverseHex"
|
|
1213
1239
|
},
|
|
1214
1240
|
axle13: {
|
|
1215
1241
|
size: 8,
|
|
1216
|
-
description: "Axle 13 autolearn statuses, each nibble signifies a single wheel"
|
|
1242
|
+
description: "Axle 13 autolearn statuses, each nibble signifies a single wheel",
|
|
1243
|
+
display: "reverseHex"
|
|
1217
1244
|
},
|
|
1218
1245
|
axle14: {
|
|
1219
1246
|
size: 8,
|
|
1220
|
-
description: "Axle 14 autolearn statuses, each nibble signifies a single wheel"
|
|
1247
|
+
description: "Axle 14 autolearn statuses, each nibble signifies a single wheel",
|
|
1248
|
+
display: "reverseHex"
|
|
1221
1249
|
},
|
|
1222
1250
|
axle15: {
|
|
1223
1251
|
size: 8,
|
|
1224
|
-
description: "Axle 15 autolearn statuses, each nibble signifies a single wheel"
|
|
1252
|
+
description: "Axle 15 autolearn statuses, each nibble signifies a single wheel",
|
|
1253
|
+
display: "reverseHex"
|
|
1225
1254
|
}
|
|
1226
1255
|
}
|
|
1227
1256
|
},
|
|
@@ -1290,6 +1319,88 @@ const bridgeCommandStructures = {
|
|
|
1290
1319
|
description: "Unknown sensor data"
|
|
1291
1320
|
}
|
|
1292
1321
|
}
|
|
1322
|
+
},
|
|
1323
|
+
vehicleLayout: {
|
|
1324
|
+
id: [98, 1],
|
|
1325
|
+
name: "vehicleLayout",
|
|
1326
|
+
structure: {
|
|
1327
|
+
axle01: {
|
|
1328
|
+
size: 2,
|
|
1329
|
+
description: "Axle 01 each bit represents present tyre."
|
|
1330
|
+
},
|
|
1331
|
+
axle02: {
|
|
1332
|
+
size: 2,
|
|
1333
|
+
description: "Axle 02 each bit represents present tyre"
|
|
1334
|
+
},
|
|
1335
|
+
axle03: {
|
|
1336
|
+
size: 2,
|
|
1337
|
+
description: "Axle 03 each bit represents present tyre"
|
|
1338
|
+
},
|
|
1339
|
+
axle04: {
|
|
1340
|
+
size: 2,
|
|
1341
|
+
description: "Axle 04 each bit represents present tyre"
|
|
1342
|
+
},
|
|
1343
|
+
axle05: {
|
|
1344
|
+
size: 2,
|
|
1345
|
+
description: "Axle 05 each bit represents present tyre"
|
|
1346
|
+
},
|
|
1347
|
+
axle06: {
|
|
1348
|
+
size: 2,
|
|
1349
|
+
description: "Axle 06 each bit represents present tyre"
|
|
1350
|
+
},
|
|
1351
|
+
axle07: {
|
|
1352
|
+
size: 2,
|
|
1353
|
+
description: "Axle 07 each bit represents present tyre"
|
|
1354
|
+
},
|
|
1355
|
+
axle08: {
|
|
1356
|
+
size: 2,
|
|
1357
|
+
description: "Axle 08 each bit represents present tyre"
|
|
1358
|
+
},
|
|
1359
|
+
axle09: {
|
|
1360
|
+
size: 2,
|
|
1361
|
+
description: "Axle 09 each bit represents present tyre"
|
|
1362
|
+
},
|
|
1363
|
+
axle10: {
|
|
1364
|
+
size: 2,
|
|
1365
|
+
description: "Axle 10 each bit represents present tyre"
|
|
1366
|
+
},
|
|
1367
|
+
axle11: {
|
|
1368
|
+
size: 2,
|
|
1369
|
+
description: "Axle 11 each bit represents present tyre"
|
|
1370
|
+
},
|
|
1371
|
+
axle12: {
|
|
1372
|
+
size: 2,
|
|
1373
|
+
description: "Axle 12 each bit represents present tyre"
|
|
1374
|
+
},
|
|
1375
|
+
axle13: {
|
|
1376
|
+
size: 2,
|
|
1377
|
+
description: "Axle 13 each bit represents present tyre"
|
|
1378
|
+
},
|
|
1379
|
+
axle14: {
|
|
1380
|
+
size: 2,
|
|
1381
|
+
description: "Axle 14 each bit represents present tyre"
|
|
1382
|
+
},
|
|
1383
|
+
axle15: {
|
|
1384
|
+
size: 2,
|
|
1385
|
+
description: "Axle 15 each bit represents present tyre"
|
|
1386
|
+
},
|
|
1387
|
+
vin: {
|
|
1388
|
+
size: 17,
|
|
1389
|
+
description: "Vehicle Identification Number",
|
|
1390
|
+
display: "ascii"
|
|
1391
|
+
},
|
|
1392
|
+
vinExtension: {
|
|
1393
|
+
size: 1,
|
|
1394
|
+
description: "VIN extension",
|
|
1395
|
+
display: "ascii",
|
|
1396
|
+
optional: true
|
|
1397
|
+
},
|
|
1398
|
+
test: {
|
|
1399
|
+
size: 3,
|
|
1400
|
+
description: "Test",
|
|
1401
|
+
optional: true
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1293
1404
|
}
|
|
1294
1405
|
};
|
|
1295
1406
|
|
|
@@ -1547,13 +1658,14 @@ const promiseQueue$1 = {
|
|
|
1547
1658
|
);
|
|
1548
1659
|
}
|
|
1549
1660
|
});
|
|
1550
|
-
return withTimeout(promise, 5e3,
|
|
1661
|
+
return withTimeout(promise, 5e3, `Command timed out ${responseIdentifier}`);
|
|
1551
1662
|
});
|
|
1552
1663
|
return promiseQueue;
|
|
1553
1664
|
},
|
|
1554
1665
|
async processMessage(deviceId, payload) {
|
|
1555
1666
|
const numberArray = Array.from(new Uint8Array(payload));
|
|
1556
1667
|
if (numberArray[3] === 127) {
|
|
1668
|
+
console.error(numberArray);
|
|
1557
1669
|
return currentReject(new Error(`Command not succesful: ${numberArray[4]}`));
|
|
1558
1670
|
}
|
|
1559
1671
|
if ([226, 81].includes(numberArray[3]) && numberArray[4] && toolsSvc.canCommunicateWith(deviceId)) {
|
|
@@ -1956,7 +2068,7 @@ const bridgeCommands = {
|
|
|
1956
2068
|
if (!canCommunicateWith(device.id)) throw new Error("Bridge not connected");
|
|
1957
2069
|
clearTimeout(keepAliveTimer);
|
|
1958
2070
|
keepAliveTimer = setTimeout(() => {
|
|
1959
|
-
if (
|
|
2071
|
+
if (store.deviceState[device.id] !== "paired" || store.devices[device.id]?.type !== "bridge") {
|
|
1960
2072
|
return;
|
|
1961
2073
|
}
|
|
1962
2074
|
this.sendKeepAliveCommand(device);
|
|
@@ -1970,17 +2082,16 @@ const otaControlCharacteristicUuid = "f7bf3564-fb6d-4e53-88a4-5e37e0326063";
|
|
|
1970
2082
|
const otaDataCharacteristicUuid = "984227f3-34fc-4045-a5d0-2c581f81a153";
|
|
1971
2083
|
const bridgeOtaCommands = {
|
|
1972
2084
|
async beginOta(deviceId) {
|
|
1973
|
-
await bluetooth.write(deviceId, otaServiceUuid, otaControlCharacteristicUuid, new Uint8Array([0]).buffer);
|
|
2085
|
+
await bluetooth.write(deviceId, otaServiceUuid, otaControlCharacteristicUuid, new Uint8Array([0]).buffer, true);
|
|
1974
2086
|
},
|
|
1975
2087
|
async uploadOtaChunk(deviceId, data) {
|
|
1976
|
-
await bluetooth.write(deviceId, otaServiceUuid, otaDataCharacteristicUuid, data);
|
|
2088
|
+
await bluetooth.write(deviceId, otaServiceUuid, otaDataCharacteristicUuid, data, true);
|
|
1977
2089
|
},
|
|
1978
2090
|
async endOta(deviceId) {
|
|
1979
|
-
await bluetooth.write(deviceId, otaServiceUuid, otaControlCharacteristicUuid, new Uint8Array([3]).buffer);
|
|
2091
|
+
await bluetooth.write(deviceId, otaServiceUuid, otaControlCharacteristicUuid, new Uint8Array([3]).buffer, true);
|
|
1980
2092
|
}
|
|
1981
2093
|
};
|
|
1982
2094
|
|
|
1983
|
-
const mtu = store.platform === "android" ? 512 : 180;
|
|
1984
2095
|
const bridgeOtaService = {
|
|
1985
2096
|
async updateFirmware(deviceId, bootloader, firmware, progressCallback) {
|
|
1986
2097
|
await delay(2e3);
|
|
@@ -2010,7 +2121,7 @@ async function uploadOta(deviceId, firmwareBinary, reportStatus) {
|
|
|
2010
2121
|
)} KB)`,
|
|
2011
2122
|
uploadedBytes / firmwareBinary.byteLength
|
|
2012
2123
|
);
|
|
2013
|
-
const chunkSize = Math.min(mtu - 3, firmwareBinary.byteLength - uploadedBytes);
|
|
2124
|
+
const chunkSize = Math.min(deviceMeta.bridgeOta.mtu - 3, firmwareBinary.byteLength - uploadedBytes);
|
|
2014
2125
|
const chunk = firmwareBinary.slice(uploadedBytes, uploadedBytes + chunkSize);
|
|
2015
2126
|
await bridgeOtaCommands.uploadOtaChunk(deviceId, chunk);
|
|
2016
2127
|
uploadedBytes += chunkSize;
|
|
@@ -2021,12 +2132,14 @@ async function uploadOta(deviceId, firmwareBinary, reportStatus) {
|
|
|
2021
2132
|
const bridgeOta = {
|
|
2022
2133
|
async connect(deviceId) {
|
|
2023
2134
|
await bluetooth.connect(deviceId, this.disconnect);
|
|
2135
|
+
const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
|
|
2136
|
+
await ble.requestMtu(_deviceId, deviceMeta.bridgeOta.mtu);
|
|
2024
2137
|
store.setState(deviceId, "paired");
|
|
2025
2138
|
},
|
|
2026
|
-
async disconnect(deviceId) {
|
|
2139
|
+
async disconnect(deviceId, reason) {
|
|
2027
2140
|
store.setState(deviceId, "disconnecting");
|
|
2028
2141
|
await bluetooth.disconnect(deviceId);
|
|
2029
|
-
store.setState(deviceId, "
|
|
2142
|
+
store.setState(deviceId, void 0, reason ?? "manualDisconnection");
|
|
2030
2143
|
},
|
|
2031
2144
|
async updateFirmware(deviceId, bootloader, firmware, progressCallback) {
|
|
2032
2145
|
return bridgeOtaService.updateFirmware(deviceId, bootloader, firmware, progressCallback);
|
|
@@ -2055,6 +2168,7 @@ const bridgeService = {
|
|
|
2055
2168
|
async function updateFirmware(deviceId, bootloader, firmware, reportStatus) {
|
|
2056
2169
|
reportStatus("Sending OTA Request...", 0.02);
|
|
2057
2170
|
await bridgeCommands.sendOtaRequest(deviceId);
|
|
2171
|
+
await bridge.disconnect(deviceId, "firmwareUpdate");
|
|
2058
2172
|
await toolsSvc.delay(2e3);
|
|
2059
2173
|
await bluetooth.scanDevices();
|
|
2060
2174
|
reportStatus("Discovering OTA Device...", 0.02);
|
|
@@ -2365,7 +2479,8 @@ async function getSensorReading(deviceId, positionId) {
|
|
|
2365
2479
|
sensorStatus: value[12],
|
|
2366
2480
|
eceStatus: value[13],
|
|
2367
2481
|
pressureIssue: getPressureIssue(deviceId, value[13]),
|
|
2368
|
-
...getPressureAndTemperatureReadingObjects(value[9], value[10])
|
|
2482
|
+
...getPressureAndTemperatureReadingObjects(value[9], value[10]),
|
|
2483
|
+
byteReading: value
|
|
2369
2484
|
};
|
|
2370
2485
|
}
|
|
2371
2486
|
async function getVehicleReadings(deviceId, tcVehicle) {
|
|
@@ -2687,11 +2802,13 @@ const bridge = {
|
|
|
2687
2802
|
await bridgeCommands.sendPinCommand(deviceId);
|
|
2688
2803
|
store.setState(deviceId, "paired");
|
|
2689
2804
|
},
|
|
2690
|
-
async disconnect(deviceId) {
|
|
2805
|
+
async disconnect(deviceId, reason) {
|
|
2691
2806
|
store.setState(deviceId, "disconnecting");
|
|
2692
2807
|
promiseQueue$1.clearQueue("Previous pending commands aborted");
|
|
2693
2808
|
await bluetooth.disconnect(deviceId);
|
|
2694
|
-
store.
|
|
2809
|
+
delete store.devices[deviceId];
|
|
2810
|
+
deviceUnreachableCallback?.(deviceId);
|
|
2811
|
+
store.setState(deviceId, void 0, reason ?? "manualDisconnection");
|
|
2695
2812
|
},
|
|
2696
2813
|
getVehicle: bridgeService.getVehicle,
|
|
2697
2814
|
setVehicle: bridgeService.setVehicle,
|
|
@@ -2827,10 +2944,10 @@ const flexiGaugeTpms = {
|
|
|
2827
2944
|
);
|
|
2828
2945
|
store.setState(deviceId, "paired");
|
|
2829
2946
|
},
|
|
2830
|
-
async disconnect(deviceId) {
|
|
2947
|
+
async disconnect(deviceId, reason) {
|
|
2831
2948
|
store.setState(deviceId, "disconnecting");
|
|
2832
2949
|
await bluetooth.disconnect(deviceId);
|
|
2833
|
-
store.setState(deviceId, "
|
|
2950
|
+
store.setState(deviceId, void 0, reason ?? "manualDisconnection");
|
|
2834
2951
|
},
|
|
2835
2952
|
onTreadDepth(callback) {
|
|
2836
2953
|
flexiGaugeTpmsService.onTreadDepth(callback);
|
|
@@ -2901,7 +3018,7 @@ const bridgeSimulator = {
|
|
|
2901
3018
|
async disconnect(deviceId) {
|
|
2902
3019
|
store.deviceState[deviceId] = "disconnecting";
|
|
2903
3020
|
await toolsSvc.delay(100);
|
|
2904
|
-
store.deviceState[deviceId] =
|
|
3021
|
+
store.deviceState[deviceId] = void 0;
|
|
2905
3022
|
},
|
|
2906
3023
|
createSimulatedBridge(initialData) {
|
|
2907
3024
|
return {
|
|
@@ -2928,7 +3045,8 @@ const bridgeSimulator = {
|
|
|
2928
3045
|
sensorStatus: 0,
|
|
2929
3046
|
pressure: { bar: 0, meas: 0, raw: 0 },
|
|
2930
3047
|
pressureIssue: void 0,
|
|
2931
|
-
temperature: { amb: 0, celsius: 0, raw: 0 }
|
|
3048
|
+
temperature: { amb: 0, celsius: 0, raw: 0 },
|
|
3049
|
+
byteReading: [0, 0, 0, 0, 0, 0, 0, 0]
|
|
2932
3050
|
}
|
|
2933
3051
|
},
|
|
2934
3052
|
vehicle: {
|