tirecheck-device-sdk 0.1.91 → 0.1.93

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 CHANGED
@@ -22,7 +22,8 @@ const store = {
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
24
  // undefined => connecting => connected => paired => disconnecting => undefined
25
- bridgesReboot: {},
25
+ /** some bridge commands require bridge reboot to be completed */
26
+ bridgeRebootRequired: {},
26
27
  //** 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
28
  deviceIdMapingTable: {},
28
29
  /** 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 */
@@ -471,7 +472,7 @@ const deviceMeta = {
471
472
  },
472
473
  bridgeOta: {
473
474
  nameRegex: /(CAN BLE BRDG OTA.*|0303.{2}_B)/,
474
- mtu: store.platform === "android" ? 512 : 180,
475
+ mtu: 180,
475
476
  characteristic: {
476
477
  serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
477
478
  characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d7"
@@ -575,8 +576,10 @@ async function connect(deviceId, disconnectCallback) {
575
576
  let connectedDevice;
576
577
  for (let attempt = 0; attempt < 3; attempt++) {
577
578
  try {
578
- connectedDevice = await connectInner(deviceId, disconnectCallback);
579
- if (connectedDevice) break;
579
+ connectedDevice = await withTimeout(connectInner(deviceId, disconnectCallback), 2e4);
580
+ const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
581
+ const isConnected = await ble.isConnected(_deviceId);
582
+ if (connectedDevice && isConnected) break;
580
583
  } catch (e) {
581
584
  console.warn(`${attempt} connect fail`, e);
582
585
  if (attempt === 3) {
@@ -586,12 +589,6 @@ async function connect(deviceId, disconnectCallback) {
586
589
  }
587
590
  }
588
591
  clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
589
- const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
590
- const isConnected = await ble.isConnected(_deviceId);
591
- if (!isConnected) {
592
- store.setState(deviceId, void 0, "failedConnection");
593
- throw new Error("Connect Error");
594
- }
595
592
  store.setState(deviceId, "connected");
596
593
  return connectedDevice;
597
594
  }
@@ -687,7 +684,6 @@ function getDeviceNameFromAdvertising(advertising) {
687
684
  const length = adv[3];
688
685
  const type = adv[4];
689
686
  if (type !== 9) {
690
- console.warn("Bridge name not found in advertising");
691
687
  return "";
692
688
  }
693
689
  const decoder = new TextDecoder("utf-8");
@@ -1669,7 +1665,7 @@ const promiseQueue$1 = {
1669
1665
  return currentReject(new Error(`Command not succesful: ${numberArray[4]}`));
1670
1666
  }
1671
1667
  if ([226, 81].includes(numberArray[3]) && numberArray[4] && toolsSvc.canCommunicateWith(deviceId)) {
1672
- store.bridgesReboot[deviceId] = true;
1668
+ store.bridgeRebootRequired[deviceId] = true;
1673
1669
  }
1674
1670
  if ((!responseIdentifier[0] || numberArray[3] === responseIdentifier[0]) && (!responseIdentifier[1] || numberArray[4] === responseIdentifier[1])) {
1675
1671
  return currentResolve(numberArray);
@@ -1743,7 +1739,9 @@ ___default.invert(subCommandIds);
1743
1739
  let keepAliveTimer;
1744
1740
  const bridgeCommands = {
1745
1741
  getCommandHeader(device) {
1746
- return [securityLevelIds.tirecheck, messageTypeIds.command];
1742
+ const accessLevel = store.deviceAccessLevel[device.id];
1743
+ const securityLevelId = securityLevelIds[accessLevel] ?? securityLevelIds.driver;
1744
+ return [securityLevelId, messageTypeIds.command];
1747
1745
  },
1748
1746
  async setAxlesPressure(deviceId, data) {
1749
1747
  const deviceData = bridgeTools.getBridgeFromStore(deviceId);
@@ -1771,15 +1769,16 @@ const bridgeCommands = {
1771
1769
  );
1772
1770
  return { ...structurized, isFactory: result.isFactory };
1773
1771
  },
1774
- async getBridgeConfiguration(deviceId) {
1775
- const deviceData = bridgeTools.getBridgeFromStore(deviceId);
1776
- const result = await this.readCommand(deviceData, subCommandIds.bridgeConfiguration);
1777
- const structurized = bridgeTools.convertBytesToStructure(
1778
- bridgeCommandStructures.bridgeConfiguration.structure,
1779
- result.data
1780
- );
1781
- return { ...structurized, isFactory: result.isFactory };
1782
- },
1772
+ // only accessible by tirecheck level, which should not be used in production
1773
+ // async getBridgeConfiguration(deviceId: string) {
1774
+ // const deviceData = bridgeTools.getBridgeFromStore(deviceId)
1775
+ // const result = await this.readCommand(deviceData, subCommandIds.bridgeConfiguration)
1776
+ // const structurized = bridgeTools.convertBytesToStructure(
1777
+ // bridgeCommandStructures.bridgeConfiguration.structure,
1778
+ // result.data,
1779
+ // )
1780
+ // return { ...structurized, isFactory: result.isFactory }
1781
+ // },
1783
1782
  async getCustomerPressureThresholds(deviceId) {
1784
1783
  const deviceData = bridgeTools.getBridgeFromStore(deviceId);
1785
1784
  const result = await this.readCommand(deviceData, subCommandIds.customerPressureThresholds);
@@ -2037,7 +2036,7 @@ const bridgeCommands = {
2037
2036
  const commandHead = this.getCommandHeader(device);
2038
2037
  const macAddress = [0, 0, 0, 0, 0, 0];
2039
2038
  const timestamp = bridgeTools.decimalToHex(Math.floor(Date.now() / 1e3));
2040
- const parsedTimestamp = timestamp.match(/.{2}/g)?.map((x) => Number.parseInt(x, 16));
2039
+ const parsedTimestamp = timestamp.match(/.{2}/g)?.map((x) => Number.parseInt(x, 16)).reverse();
2041
2040
  if (parsedTimestamp?.length !== 4) throw new Error("Wrong timestamp format");
2042
2041
  const paddedTimestamp = [...parsedTimestamp, 0, 0, 0, 0];
2043
2042
  const crc = bridgeSecurity.getCrcArray([...macAddress, ...paddedTimestamp, ...payload]);
@@ -2069,7 +2068,8 @@ const bridgeCommands = {
2069
2068
  clearTimeout(keepAliveTimer);
2070
2069
  keepAliveTimer = setTimeout(() => {
2071
2070
  if (store.deviceState[device.id] !== "paired" || store.devices[device.id]?.type !== "bridge") {
2072
- return;
2071
+ console.warn("keep alive timer cleared");
2072
+ return clearTimeout(keepAliveTimer);
2073
2073
  }
2074
2074
  this.sendKeepAliveCommand(device);
2075
2075
  }, 1e4);
@@ -2113,6 +2113,7 @@ const bridgeOtaService = {
2113
2113
  async function uploadOta(deviceId, firmwareBinary, reportStatus) {
2114
2114
  let uploadedBytes = 0;
2115
2115
  let chunkIndex = 0;
2116
+ const mtu = store.platform === "android" ? 512 : deviceMeta.bridgeOta.mtu;
2116
2117
  while (uploadedBytes < firmwareBinary.byteLength) {
2117
2118
  if (chunkIndex % 100 === 0)
2118
2119
  reportStatus(
@@ -2121,7 +2122,7 @@ async function uploadOta(deviceId, firmwareBinary, reportStatus) {
2121
2122
  )} KB)`,
2122
2123
  uploadedBytes / firmwareBinary.byteLength
2123
2124
  );
2124
- const chunkSize = Math.min(deviceMeta.bridgeOta.mtu - 3, firmwareBinary.byteLength - uploadedBytes);
2125
+ const chunkSize = Math.min(mtu - 3, firmwareBinary.byteLength - uploadedBytes);
2125
2126
  const chunk = firmwareBinary.slice(uploadedBytes, uploadedBytes + chunkSize);
2126
2127
  await bridgeOtaCommands.uploadOtaChunk(deviceId, chunk);
2127
2128
  uploadedBytes += chunkSize;
@@ -2133,7 +2134,9 @@ const bridgeOta = {
2133
2134
  async connect(deviceId) {
2134
2135
  await bluetooth.connect(deviceId, this.disconnect);
2135
2136
  const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
2136
- await ble.requestMtu(_deviceId, deviceMeta.bridgeOta.mtu);
2137
+ if (store.platform !== "ios") {
2138
+ await ble.requestMtu(_deviceId, 512);
2139
+ }
2137
2140
  store.setState(deviceId, "paired");
2138
2141
  },
2139
2142
  async disconnect(deviceId, reason) {
@@ -2163,7 +2166,8 @@ const bridgeService = {
2163
2166
  getSensorReading,
2164
2167
  getVehicleReadings,
2165
2168
  resetAutolearnStatuses,
2166
- getAutolearnStatuses
2169
+ getAutolearnStatuses,
2170
+ isRebootRequired
2167
2171
  };
2168
2172
  async function updateFirmware(deviceId, bootloader, firmware, reportStatus) {
2169
2173
  reportStatus("Sending OTA Request...", 0.02);
@@ -2216,7 +2220,6 @@ async function setVehicleLayout(deviceId, tcVehicle) {
2216
2220
  async function getConfiguration(deviceId) {
2217
2221
  const customerCANSettings = await bridgeCommands.getCustomerCANSettings(deviceId);
2218
2222
  const workshopCANSettings = await bridgeCommands.getWorkshopCANSettings(deviceId);
2219
- const bridgeConfiguration = await bridgeCommands.getBridgeConfiguration(deviceId);
2220
2223
  const customerPressureThresholds = await bridgeCommands.getCustomerPressureThresholds(deviceId);
2221
2224
  const customerTemperatureThresholds = await bridgeCommands.getCustomerTemperatureThresholds(deviceId);
2222
2225
  const customerImbalanceThresholds = await bridgeCommands.getCustomerImbalanceThresholds(deviceId);
@@ -2228,7 +2231,6 @@ async function getConfiguration(deviceId) {
2228
2231
  return {
2229
2232
  customerCANSettings,
2230
2233
  workshopCANSettings,
2231
- bridgeConfiguration,
2232
2234
  customerPressureThresholds,
2233
2235
  customerTemperatureThresholds,
2234
2236
  customerImbalanceThresholds,
@@ -2761,15 +2763,15 @@ async function assignTyres(deviceId, tcVehicle) {
2761
2763
  async function assignAxlePressureLimits(deviceId, tcVehicle, tcVehicleAxle, axleIndex, bridgeAxlesPressureData) {
2762
2764
  const axlesPressureData = bridgeAxlesPressureData ?? (await bridgeCommands.getAxlesPressure(deviceId)).data;
2763
2765
  if (axlesPressureData[axleIndex * 3]) {
2764
- tcVehicleAxle.maxTargetPressure = bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]);
2766
+ tcVehicleAxle.maxTargetPressure = ___default.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2765
2767
  }
2766
2768
  if (axlesPressureData[axleIndex * 3 + 1]) {
2767
- tcVehicleAxle.minTargetPressure = bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]);
2769
+ tcVehicleAxle.minTargetPressure = ___default.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2768
2770
  }
2769
2771
  if (axlesPressureData[axleIndex * 3 + 2]) {
2770
- tcVehicleAxle.targetPressure = bridgeTools.kpaByteToBar(
2771
- axlesPressureData[axleIndex * 3 + 2],
2772
- void 0
2772
+ tcVehicleAxle.targetPressure = ___default.round(
2773
+ bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 2], void 0),
2774
+ 1
2773
2775
  );
2774
2776
  }
2775
2777
  return tcVehicleAxle;
@@ -2780,6 +2782,9 @@ function createNewTyre(positionId) {
2780
2782
  serialNumber: `TYRE-${positionId}`
2781
2783
  };
2782
2784
  }
2785
+ function isRebootRequired(deviceId) {
2786
+ return store.bridgeRebootRequired[deviceId];
2787
+ }
2783
2788
 
2784
2789
  const bridge = {
2785
2790
  async connect(deviceId, accessLevel) {
@@ -2799,6 +2804,7 @@ const bridge = {
2799
2804
  (error) => console.error("startNotification Error", error)
2800
2805
  );
2801
2806
  store.deviceAccessLevel[deviceId] = accessLevel ?? "driver";
2807
+ store.bridgeRebootRequired[deviceId] = false;
2802
2808
  await bridgeCommands.sendPinCommand(deviceId);
2803
2809
  store.setState(deviceId, "paired");
2804
2810
  },
@@ -2818,7 +2824,8 @@ const bridge = {
2818
2824
  getVehicleReadings: bridgeService.getVehicleReadings,
2819
2825
  getAutolearnStatuses: bridgeService.getAutolearnStatuses,
2820
2826
  resetAutolearnStatuses: bridgeService.resetAutolearnStatuses,
2821
- updateFirmware: bridgeService.updateFirmware
2827
+ updateFirmware: bridgeService.updateFirmware,
2828
+ isRebootRequired: bridgeService.isRebootRequired
2822
2829
  };
2823
2830
 
2824
2831
  const flexiGaugeTpmsMeta = deviceMeta.flexiGaugeTpms;
@@ -2963,6 +2970,9 @@ const flexiGaugeTpms = {
2963
2970
  };
2964
2971
 
2965
2972
  const bridgeSimulator = {
2973
+ isRebootRequired(deviceId) {
2974
+ return store.bridgeRebootRequired[deviceId];
2975
+ },
2966
2976
  async getVehicle(deviceId) {
2967
2977
  const bridge = getSimulatedBridge(deviceId);
2968
2978
  return { ...bridge.simulatorData.vehicle, tcBridge: { id: deviceId } };
package/dist/index.d.cts CHANGED
@@ -761,7 +761,6 @@ declare class BridgeTcVehicleAxle {
761
761
  interface BridgeConfiguration {
762
762
  customerCANSettings: BridgeCommandStructurized<typeof _default.customerCanSettings.structure>;
763
763
  workshopCANSettings: BridgeCommandStructurized<typeof _default.workshopCanSettings.structure>;
764
- bridgeConfiguration: BridgeCommandStructurized<typeof _default.bridgeConfiguration.structure>;
765
764
  customerPressureThresholds: BridgeCommandStructurized<typeof _default.axlePressureThresholds.structure>;
766
765
  customerTemperatureThresholds: BridgeCommandStructurized<typeof _default.axleTemperatureThresholds.structure>;
767
766
  customerImbalanceThresholds: BridgeCommandStructurized<typeof _default.axleImbalanceThresholds.structure>;
@@ -919,6 +918,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation,
919
918
  getAutolearnStatuses: (deviceId: string, tcVehicle: BridgeTcVehicle) => Promise<BridgeAutolearnStatus[]>;
920
919
  resetAutolearnStatuses: (deviceId: string, positionIds: number[]) => Promise<void>;
921
920
  updateFirmware: (deviceId: string, bootloader: ArrayBuffer, firmware: ArrayBuffer, reportStatus: ReportStatusFn) => Promise<void>;
921
+ isRebootRequired: (deviceId: string) => boolean;
922
922
  };
923
923
  /** Methods for working with Tirecheck CAN Bridge in OTA mode */
924
924
  bridgeOta: {
package/dist/index.d.mts CHANGED
@@ -761,7 +761,6 @@ declare class BridgeTcVehicleAxle {
761
761
  interface BridgeConfiguration {
762
762
  customerCANSettings: BridgeCommandStructurized<typeof _default.customerCanSettings.structure>;
763
763
  workshopCANSettings: BridgeCommandStructurized<typeof _default.workshopCanSettings.structure>;
764
- bridgeConfiguration: BridgeCommandStructurized<typeof _default.bridgeConfiguration.structure>;
765
764
  customerPressureThresholds: BridgeCommandStructurized<typeof _default.axlePressureThresholds.structure>;
766
765
  customerTemperatureThresholds: BridgeCommandStructurized<typeof _default.axleTemperatureThresholds.structure>;
767
766
  customerImbalanceThresholds: BridgeCommandStructurized<typeof _default.axleImbalanceThresholds.structure>;
@@ -919,6 +918,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation,
919
918
  getAutolearnStatuses: (deviceId: string, tcVehicle: BridgeTcVehicle) => Promise<BridgeAutolearnStatus[]>;
920
919
  resetAutolearnStatuses: (deviceId: string, positionIds: number[]) => Promise<void>;
921
920
  updateFirmware: (deviceId: string, bootloader: ArrayBuffer, firmware: ArrayBuffer, reportStatus: ReportStatusFn) => Promise<void>;
921
+ isRebootRequired: (deviceId: string) => boolean;
922
922
  };
923
923
  /** Methods for working with Tirecheck CAN Bridge in OTA mode */
924
924
  bridgeOta: {
package/dist/index.d.ts CHANGED
@@ -761,7 +761,6 @@ declare class BridgeTcVehicleAxle {
761
761
  interface BridgeConfiguration {
762
762
  customerCANSettings: BridgeCommandStructurized<typeof _default.customerCanSettings.structure>;
763
763
  workshopCANSettings: BridgeCommandStructurized<typeof _default.workshopCanSettings.structure>;
764
- bridgeConfiguration: BridgeCommandStructurized<typeof _default.bridgeConfiguration.structure>;
765
764
  customerPressureThresholds: BridgeCommandStructurized<typeof _default.axlePressureThresholds.structure>;
766
765
  customerTemperatureThresholds: BridgeCommandStructurized<typeof _default.axleTemperatureThresholds.structure>;
767
766
  customerImbalanceThresholds: BridgeCommandStructurized<typeof _default.axleImbalanceThresholds.structure>;
@@ -919,6 +918,7 @@ declare function createTirecheckDeviceSdk(bleImplementation: BleImplementation,
919
918
  getAutolearnStatuses: (deviceId: string, tcVehicle: BridgeTcVehicle) => Promise<BridgeAutolearnStatus[]>;
920
919
  resetAutolearnStatuses: (deviceId: string, positionIds: number[]) => Promise<void>;
921
920
  updateFirmware: (deviceId: string, bootloader: ArrayBuffer, firmware: ArrayBuffer, reportStatus: ReportStatusFn) => Promise<void>;
921
+ isRebootRequired: (deviceId: string) => boolean;
922
922
  };
923
923
  /** Methods for working with Tirecheck CAN Bridge in OTA mode */
924
924
  bridgeOta: {
package/dist/index.mjs CHANGED
@@ -15,7 +15,8 @@ const store = {
15
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) */
16
16
  deviceState: {},
17
17
  // undefined => connecting => connected => paired => disconnecting => undefined
18
- bridgesReboot: {},
18
+ /** some bridge commands require bridge reboot to be completed */
19
+ bridgeRebootRequired: {},
19
20
  //** 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
21
  deviceIdMapingTable: {},
21
22
  /** 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 */
@@ -464,7 +465,7 @@ const deviceMeta = {
464
465
  },
465
466
  bridgeOta: {
466
467
  nameRegex: /(CAN BLE BRDG OTA.*|0303.{2}_B)/,
467
- mtu: store.platform === "android" ? 512 : 180,
468
+ mtu: 180,
468
469
  characteristic: {
469
470
  serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
470
471
  characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d7"
@@ -568,8 +569,10 @@ async function connect(deviceId, disconnectCallback) {
568
569
  let connectedDevice;
569
570
  for (let attempt = 0; attempt < 3; attempt++) {
570
571
  try {
571
- connectedDevice = await connectInner(deviceId, disconnectCallback);
572
- if (connectedDevice) break;
572
+ connectedDevice = await withTimeout(connectInner(deviceId, disconnectCallback), 2e4);
573
+ const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
574
+ const isConnected = await ble.isConnected(_deviceId);
575
+ if (connectedDevice && isConnected) break;
573
576
  } catch (e) {
574
577
  console.warn(`${attempt} connect fail`, e);
575
578
  if (attempt === 3) {
@@ -579,12 +582,6 @@ async function connect(deviceId, disconnectCallback) {
579
582
  }
580
583
  }
581
584
  clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
582
- const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
583
- const isConnected = await ble.isConnected(_deviceId);
584
- if (!isConnected) {
585
- store.setState(deviceId, void 0, "failedConnection");
586
- throw new Error("Connect Error");
587
- }
588
585
  store.setState(deviceId, "connected");
589
586
  return connectedDevice;
590
587
  }
@@ -680,7 +677,6 @@ function getDeviceNameFromAdvertising(advertising) {
680
677
  const length = adv[3];
681
678
  const type = adv[4];
682
679
  if (type !== 9) {
683
- console.warn("Bridge name not found in advertising");
684
680
  return "";
685
681
  }
686
682
  const decoder = new TextDecoder("utf-8");
@@ -1662,7 +1658,7 @@ const promiseQueue$1 = {
1662
1658
  return currentReject(new Error(`Command not succesful: ${numberArray[4]}`));
1663
1659
  }
1664
1660
  if ([226, 81].includes(numberArray[3]) && numberArray[4] && toolsSvc.canCommunicateWith(deviceId)) {
1665
- store.bridgesReboot[deviceId] = true;
1661
+ store.bridgeRebootRequired[deviceId] = true;
1666
1662
  }
1667
1663
  if ((!responseIdentifier[0] || numberArray[3] === responseIdentifier[0]) && (!responseIdentifier[1] || numberArray[4] === responseIdentifier[1])) {
1668
1664
  return currentResolve(numberArray);
@@ -1736,7 +1732,9 @@ _.invert(subCommandIds);
1736
1732
  let keepAliveTimer;
1737
1733
  const bridgeCommands = {
1738
1734
  getCommandHeader(device) {
1739
- return [securityLevelIds.tirecheck, messageTypeIds.command];
1735
+ const accessLevel = store.deviceAccessLevel[device.id];
1736
+ const securityLevelId = securityLevelIds[accessLevel] ?? securityLevelIds.driver;
1737
+ return [securityLevelId, messageTypeIds.command];
1740
1738
  },
1741
1739
  async setAxlesPressure(deviceId, data) {
1742
1740
  const deviceData = bridgeTools.getBridgeFromStore(deviceId);
@@ -1764,15 +1762,16 @@ const bridgeCommands = {
1764
1762
  );
1765
1763
  return { ...structurized, isFactory: result.isFactory };
1766
1764
  },
1767
- async getBridgeConfiguration(deviceId) {
1768
- const deviceData = bridgeTools.getBridgeFromStore(deviceId);
1769
- const result = await this.readCommand(deviceData, subCommandIds.bridgeConfiguration);
1770
- const structurized = bridgeTools.convertBytesToStructure(
1771
- bridgeCommandStructures.bridgeConfiguration.structure,
1772
- result.data
1773
- );
1774
- return { ...structurized, isFactory: result.isFactory };
1775
- },
1765
+ // only accessible by tirecheck level, which should not be used in production
1766
+ // async getBridgeConfiguration(deviceId: string) {
1767
+ // const deviceData = bridgeTools.getBridgeFromStore(deviceId)
1768
+ // const result = await this.readCommand(deviceData, subCommandIds.bridgeConfiguration)
1769
+ // const structurized = bridgeTools.convertBytesToStructure(
1770
+ // bridgeCommandStructures.bridgeConfiguration.structure,
1771
+ // result.data,
1772
+ // )
1773
+ // return { ...structurized, isFactory: result.isFactory }
1774
+ // },
1776
1775
  async getCustomerPressureThresholds(deviceId) {
1777
1776
  const deviceData = bridgeTools.getBridgeFromStore(deviceId);
1778
1777
  const result = await this.readCommand(deviceData, subCommandIds.customerPressureThresholds);
@@ -2030,7 +2029,7 @@ const bridgeCommands = {
2030
2029
  const commandHead = this.getCommandHeader(device);
2031
2030
  const macAddress = [0, 0, 0, 0, 0, 0];
2032
2031
  const timestamp = bridgeTools.decimalToHex(Math.floor(Date.now() / 1e3));
2033
- const parsedTimestamp = timestamp.match(/.{2}/g)?.map((x) => Number.parseInt(x, 16));
2032
+ const parsedTimestamp = timestamp.match(/.{2}/g)?.map((x) => Number.parseInt(x, 16)).reverse();
2034
2033
  if (parsedTimestamp?.length !== 4) throw new Error("Wrong timestamp format");
2035
2034
  const paddedTimestamp = [...parsedTimestamp, 0, 0, 0, 0];
2036
2035
  const crc = bridgeSecurity.getCrcArray([...macAddress, ...paddedTimestamp, ...payload]);
@@ -2062,7 +2061,8 @@ const bridgeCommands = {
2062
2061
  clearTimeout(keepAliveTimer);
2063
2062
  keepAliveTimer = setTimeout(() => {
2064
2063
  if (store.deviceState[device.id] !== "paired" || store.devices[device.id]?.type !== "bridge") {
2065
- return;
2064
+ console.warn("keep alive timer cleared");
2065
+ return clearTimeout(keepAliveTimer);
2066
2066
  }
2067
2067
  this.sendKeepAliveCommand(device);
2068
2068
  }, 1e4);
@@ -2106,6 +2106,7 @@ const bridgeOtaService = {
2106
2106
  async function uploadOta(deviceId, firmwareBinary, reportStatus) {
2107
2107
  let uploadedBytes = 0;
2108
2108
  let chunkIndex = 0;
2109
+ const mtu = store.platform === "android" ? 512 : deviceMeta.bridgeOta.mtu;
2109
2110
  while (uploadedBytes < firmwareBinary.byteLength) {
2110
2111
  if (chunkIndex % 100 === 0)
2111
2112
  reportStatus(
@@ -2114,7 +2115,7 @@ async function uploadOta(deviceId, firmwareBinary, reportStatus) {
2114
2115
  )} KB)`,
2115
2116
  uploadedBytes / firmwareBinary.byteLength
2116
2117
  );
2117
- const chunkSize = Math.min(deviceMeta.bridgeOta.mtu - 3, firmwareBinary.byteLength - uploadedBytes);
2118
+ const chunkSize = Math.min(mtu - 3, firmwareBinary.byteLength - uploadedBytes);
2118
2119
  const chunk = firmwareBinary.slice(uploadedBytes, uploadedBytes + chunkSize);
2119
2120
  await bridgeOtaCommands.uploadOtaChunk(deviceId, chunk);
2120
2121
  uploadedBytes += chunkSize;
@@ -2126,7 +2127,9 @@ const bridgeOta = {
2126
2127
  async connect(deviceId) {
2127
2128
  await bluetooth.connect(deviceId, this.disconnect);
2128
2129
  const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
2129
- await ble.requestMtu(_deviceId, deviceMeta.bridgeOta.mtu);
2130
+ if (store.platform !== "ios") {
2131
+ await ble.requestMtu(_deviceId, 512);
2132
+ }
2130
2133
  store.setState(deviceId, "paired");
2131
2134
  },
2132
2135
  async disconnect(deviceId, reason) {
@@ -2156,7 +2159,8 @@ const bridgeService = {
2156
2159
  getSensorReading,
2157
2160
  getVehicleReadings,
2158
2161
  resetAutolearnStatuses,
2159
- getAutolearnStatuses
2162
+ getAutolearnStatuses,
2163
+ isRebootRequired
2160
2164
  };
2161
2165
  async function updateFirmware(deviceId, bootloader, firmware, reportStatus) {
2162
2166
  reportStatus("Sending OTA Request...", 0.02);
@@ -2209,7 +2213,6 @@ async function setVehicleLayout(deviceId, tcVehicle) {
2209
2213
  async function getConfiguration(deviceId) {
2210
2214
  const customerCANSettings = await bridgeCommands.getCustomerCANSettings(deviceId);
2211
2215
  const workshopCANSettings = await bridgeCommands.getWorkshopCANSettings(deviceId);
2212
- const bridgeConfiguration = await bridgeCommands.getBridgeConfiguration(deviceId);
2213
2216
  const customerPressureThresholds = await bridgeCommands.getCustomerPressureThresholds(deviceId);
2214
2217
  const customerTemperatureThresholds = await bridgeCommands.getCustomerTemperatureThresholds(deviceId);
2215
2218
  const customerImbalanceThresholds = await bridgeCommands.getCustomerImbalanceThresholds(deviceId);
@@ -2221,7 +2224,6 @@ async function getConfiguration(deviceId) {
2221
2224
  return {
2222
2225
  customerCANSettings,
2223
2226
  workshopCANSettings,
2224
- bridgeConfiguration,
2225
2227
  customerPressureThresholds,
2226
2228
  customerTemperatureThresholds,
2227
2229
  customerImbalanceThresholds,
@@ -2754,15 +2756,15 @@ async function assignTyres(deviceId, tcVehicle) {
2754
2756
  async function assignAxlePressureLimits(deviceId, tcVehicle, tcVehicleAxle, axleIndex, bridgeAxlesPressureData) {
2755
2757
  const axlesPressureData = bridgeAxlesPressureData ?? (await bridgeCommands.getAxlesPressure(deviceId)).data;
2756
2758
  if (axlesPressureData[axleIndex * 3]) {
2757
- tcVehicleAxle.maxTargetPressure = bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]);
2759
+ tcVehicleAxle.maxTargetPressure = _.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2758
2760
  }
2759
2761
  if (axlesPressureData[axleIndex * 3 + 1]) {
2760
- tcVehicleAxle.minTargetPressure = bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]);
2762
+ tcVehicleAxle.minTargetPressure = _.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2761
2763
  }
2762
2764
  if (axlesPressureData[axleIndex * 3 + 2]) {
2763
- tcVehicleAxle.targetPressure = bridgeTools.kpaByteToBar(
2764
- axlesPressureData[axleIndex * 3 + 2],
2765
- void 0
2765
+ tcVehicleAxle.targetPressure = _.round(
2766
+ bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 2], void 0),
2767
+ 1
2766
2768
  );
2767
2769
  }
2768
2770
  return tcVehicleAxle;
@@ -2773,6 +2775,9 @@ function createNewTyre(positionId) {
2773
2775
  serialNumber: `TYRE-${positionId}`
2774
2776
  };
2775
2777
  }
2778
+ function isRebootRequired(deviceId) {
2779
+ return store.bridgeRebootRequired[deviceId];
2780
+ }
2776
2781
 
2777
2782
  const bridge = {
2778
2783
  async connect(deviceId, accessLevel) {
@@ -2792,6 +2797,7 @@ const bridge = {
2792
2797
  (error) => console.error("startNotification Error", error)
2793
2798
  );
2794
2799
  store.deviceAccessLevel[deviceId] = accessLevel ?? "driver";
2800
+ store.bridgeRebootRequired[deviceId] = false;
2795
2801
  await bridgeCommands.sendPinCommand(deviceId);
2796
2802
  store.setState(deviceId, "paired");
2797
2803
  },
@@ -2811,7 +2817,8 @@ const bridge = {
2811
2817
  getVehicleReadings: bridgeService.getVehicleReadings,
2812
2818
  getAutolearnStatuses: bridgeService.getAutolearnStatuses,
2813
2819
  resetAutolearnStatuses: bridgeService.resetAutolearnStatuses,
2814
- updateFirmware: bridgeService.updateFirmware
2820
+ updateFirmware: bridgeService.updateFirmware,
2821
+ isRebootRequired: bridgeService.isRebootRequired
2815
2822
  };
2816
2823
 
2817
2824
  const flexiGaugeTpmsMeta = deviceMeta.flexiGaugeTpms;
@@ -2956,6 +2963,9 @@ const flexiGaugeTpms = {
2956
2963
  };
2957
2964
 
2958
2965
  const bridgeSimulator = {
2966
+ isRebootRequired(deviceId) {
2967
+ return store.bridgeRebootRequired[deviceId];
2968
+ },
2959
2969
  async getVehicle(deviceId) {
2960
2970
  const bridge = getSimulatedBridge(deviceId);
2961
2971
  return { ...bridge.simulatorData.vehicle, tcBridge: { id: deviceId } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.1.91",
3
+ "version": "0.1.93",
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",