tirecheck-device-sdk 0.1.92 → 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
@@ -576,8 +576,10 @@ async function connect(deviceId, disconnectCallback) {
576
576
  let connectedDevice;
577
577
  for (let attempt = 0; attempt < 3; attempt++) {
578
578
  try {
579
- connectedDevice = await connectInner(deviceId, disconnectCallback);
580
- 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;
581
583
  } catch (e) {
582
584
  console.warn(`${attempt} connect fail`, e);
583
585
  if (attempt === 3) {
@@ -587,12 +589,6 @@ async function connect(deviceId, disconnectCallback) {
587
589
  }
588
590
  }
589
591
  clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
590
- const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
591
- const isConnected = await ble.isConnected(_deviceId);
592
- if (!isConnected) {
593
- store.setState(deviceId, void 0, "failedConnection");
594
- throw new Error("Connect Error");
595
- }
596
592
  store.setState(deviceId, "connected");
597
593
  return connectedDevice;
598
594
  }
@@ -688,7 +684,6 @@ function getDeviceNameFromAdvertising(advertising) {
688
684
  const length = adv[3];
689
685
  const type = adv[4];
690
686
  if (type !== 9) {
691
- console.warn("Bridge name not found in advertising");
692
687
  return "";
693
688
  }
694
689
  const decoder = new TextDecoder("utf-8");
@@ -1744,7 +1739,9 @@ ___default.invert(subCommandIds);
1744
1739
  let keepAliveTimer;
1745
1740
  const bridgeCommands = {
1746
1741
  getCommandHeader(device) {
1747
- return [securityLevelIds.tirecheck, messageTypeIds.command];
1742
+ const accessLevel = store.deviceAccessLevel[device.id];
1743
+ const securityLevelId = securityLevelIds[accessLevel] ?? securityLevelIds.driver;
1744
+ return [securityLevelId, messageTypeIds.command];
1748
1745
  },
1749
1746
  async setAxlesPressure(deviceId, data) {
1750
1747
  const deviceData = bridgeTools.getBridgeFromStore(deviceId);
@@ -1772,15 +1769,16 @@ const bridgeCommands = {
1772
1769
  );
1773
1770
  return { ...structurized, isFactory: result.isFactory };
1774
1771
  },
1775
- async getBridgeConfiguration(deviceId) {
1776
- const deviceData = bridgeTools.getBridgeFromStore(deviceId);
1777
- const result = await this.readCommand(deviceData, subCommandIds.bridgeConfiguration);
1778
- const structurized = bridgeTools.convertBytesToStructure(
1779
- bridgeCommandStructures.bridgeConfiguration.structure,
1780
- result.data
1781
- );
1782
- return { ...structurized, isFactory: result.isFactory };
1783
- },
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
+ // },
1784
1782
  async getCustomerPressureThresholds(deviceId) {
1785
1783
  const deviceData = bridgeTools.getBridgeFromStore(deviceId);
1786
1784
  const result = await this.readCommand(deviceData, subCommandIds.customerPressureThresholds);
@@ -2038,7 +2036,7 @@ const bridgeCommands = {
2038
2036
  const commandHead = this.getCommandHeader(device);
2039
2037
  const macAddress = [0, 0, 0, 0, 0, 0];
2040
2038
  const timestamp = bridgeTools.decimalToHex(Math.floor(Date.now() / 1e3));
2041
- 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();
2042
2040
  if (parsedTimestamp?.length !== 4) throw new Error("Wrong timestamp format");
2043
2041
  const paddedTimestamp = [...parsedTimestamp, 0, 0, 0, 0];
2044
2042
  const crc = bridgeSecurity.getCrcArray([...macAddress, ...paddedTimestamp, ...payload]);
@@ -2070,7 +2068,8 @@ const bridgeCommands = {
2070
2068
  clearTimeout(keepAliveTimer);
2071
2069
  keepAliveTimer = setTimeout(() => {
2072
2070
  if (store.deviceState[device.id] !== "paired" || store.devices[device.id]?.type !== "bridge") {
2073
- return;
2071
+ console.warn("keep alive timer cleared");
2072
+ return clearTimeout(keepAliveTimer);
2074
2073
  }
2075
2074
  this.sendKeepAliveCommand(device);
2076
2075
  }, 1e4);
@@ -2221,7 +2220,6 @@ async function setVehicleLayout(deviceId, tcVehicle) {
2221
2220
  async function getConfiguration(deviceId) {
2222
2221
  const customerCANSettings = await bridgeCommands.getCustomerCANSettings(deviceId);
2223
2222
  const workshopCANSettings = await bridgeCommands.getWorkshopCANSettings(deviceId);
2224
- const bridgeConfiguration = await bridgeCommands.getBridgeConfiguration(deviceId);
2225
2223
  const customerPressureThresholds = await bridgeCommands.getCustomerPressureThresholds(deviceId);
2226
2224
  const customerTemperatureThresholds = await bridgeCommands.getCustomerTemperatureThresholds(deviceId);
2227
2225
  const customerImbalanceThresholds = await bridgeCommands.getCustomerImbalanceThresholds(deviceId);
@@ -2233,7 +2231,6 @@ async function getConfiguration(deviceId) {
2233
2231
  return {
2234
2232
  customerCANSettings,
2235
2233
  workshopCANSettings,
2236
- bridgeConfiguration,
2237
2234
  customerPressureThresholds,
2238
2235
  customerTemperatureThresholds,
2239
2236
  customerImbalanceThresholds,
@@ -2973,6 +2970,9 @@ const flexiGaugeTpms = {
2973
2970
  };
2974
2971
 
2975
2972
  const bridgeSimulator = {
2973
+ isRebootRequired(deviceId) {
2974
+ return store.bridgeRebootRequired[deviceId];
2975
+ },
2976
2976
  async getVehicle(deviceId) {
2977
2977
  const bridge = getSimulatedBridge(deviceId);
2978
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>;
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>;
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>;
package/dist/index.mjs CHANGED
@@ -569,8 +569,10 @@ async function connect(deviceId, disconnectCallback) {
569
569
  let connectedDevice;
570
570
  for (let attempt = 0; attempt < 3; attempt++) {
571
571
  try {
572
- connectedDevice = await connectInner(deviceId, disconnectCallback);
573
- 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;
574
576
  } catch (e) {
575
577
  console.warn(`${attempt} connect fail`, e);
576
578
  if (attempt === 3) {
@@ -580,12 +582,6 @@ async function connect(deviceId, disconnectCallback) {
580
582
  }
581
583
  }
582
584
  clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
583
- const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
584
- const isConnected = await ble.isConnected(_deviceId);
585
- if (!isConnected) {
586
- store.setState(deviceId, void 0, "failedConnection");
587
- throw new Error("Connect Error");
588
- }
589
585
  store.setState(deviceId, "connected");
590
586
  return connectedDevice;
591
587
  }
@@ -681,7 +677,6 @@ function getDeviceNameFromAdvertising(advertising) {
681
677
  const length = adv[3];
682
678
  const type = adv[4];
683
679
  if (type !== 9) {
684
- console.warn("Bridge name not found in advertising");
685
680
  return "";
686
681
  }
687
682
  const decoder = new TextDecoder("utf-8");
@@ -1737,7 +1732,9 @@ _.invert(subCommandIds);
1737
1732
  let keepAliveTimer;
1738
1733
  const bridgeCommands = {
1739
1734
  getCommandHeader(device) {
1740
- return [securityLevelIds.tirecheck, messageTypeIds.command];
1735
+ const accessLevel = store.deviceAccessLevel[device.id];
1736
+ const securityLevelId = securityLevelIds[accessLevel] ?? securityLevelIds.driver;
1737
+ return [securityLevelId, messageTypeIds.command];
1741
1738
  },
1742
1739
  async setAxlesPressure(deviceId, data) {
1743
1740
  const deviceData = bridgeTools.getBridgeFromStore(deviceId);
@@ -1765,15 +1762,16 @@ const bridgeCommands = {
1765
1762
  );
1766
1763
  return { ...structurized, isFactory: result.isFactory };
1767
1764
  },
1768
- async getBridgeConfiguration(deviceId) {
1769
- const deviceData = bridgeTools.getBridgeFromStore(deviceId);
1770
- const result = await this.readCommand(deviceData, subCommandIds.bridgeConfiguration);
1771
- const structurized = bridgeTools.convertBytesToStructure(
1772
- bridgeCommandStructures.bridgeConfiguration.structure,
1773
- result.data
1774
- );
1775
- return { ...structurized, isFactory: result.isFactory };
1776
- },
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
+ // },
1777
1775
  async getCustomerPressureThresholds(deviceId) {
1778
1776
  const deviceData = bridgeTools.getBridgeFromStore(deviceId);
1779
1777
  const result = await this.readCommand(deviceData, subCommandIds.customerPressureThresholds);
@@ -2031,7 +2029,7 @@ const bridgeCommands = {
2031
2029
  const commandHead = this.getCommandHeader(device);
2032
2030
  const macAddress = [0, 0, 0, 0, 0, 0];
2033
2031
  const timestamp = bridgeTools.decimalToHex(Math.floor(Date.now() / 1e3));
2034
- 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();
2035
2033
  if (parsedTimestamp?.length !== 4) throw new Error("Wrong timestamp format");
2036
2034
  const paddedTimestamp = [...parsedTimestamp, 0, 0, 0, 0];
2037
2035
  const crc = bridgeSecurity.getCrcArray([...macAddress, ...paddedTimestamp, ...payload]);
@@ -2063,7 +2061,8 @@ const bridgeCommands = {
2063
2061
  clearTimeout(keepAliveTimer);
2064
2062
  keepAliveTimer = setTimeout(() => {
2065
2063
  if (store.deviceState[device.id] !== "paired" || store.devices[device.id]?.type !== "bridge") {
2066
- return;
2064
+ console.warn("keep alive timer cleared");
2065
+ return clearTimeout(keepAliveTimer);
2067
2066
  }
2068
2067
  this.sendKeepAliveCommand(device);
2069
2068
  }, 1e4);
@@ -2214,7 +2213,6 @@ async function setVehicleLayout(deviceId, tcVehicle) {
2214
2213
  async function getConfiguration(deviceId) {
2215
2214
  const customerCANSettings = await bridgeCommands.getCustomerCANSettings(deviceId);
2216
2215
  const workshopCANSettings = await bridgeCommands.getWorkshopCANSettings(deviceId);
2217
- const bridgeConfiguration = await bridgeCommands.getBridgeConfiguration(deviceId);
2218
2216
  const customerPressureThresholds = await bridgeCommands.getCustomerPressureThresholds(deviceId);
2219
2217
  const customerTemperatureThresholds = await bridgeCommands.getCustomerTemperatureThresholds(deviceId);
2220
2218
  const customerImbalanceThresholds = await bridgeCommands.getCustomerImbalanceThresholds(deviceId);
@@ -2226,7 +2224,6 @@ async function getConfiguration(deviceId) {
2226
2224
  return {
2227
2225
  customerCANSettings,
2228
2226
  workshopCANSettings,
2229
- bridgeConfiguration,
2230
2227
  customerPressureThresholds,
2231
2228
  customerTemperatureThresholds,
2232
2229
  customerImbalanceThresholds,
@@ -2966,6 +2963,9 @@ const flexiGaugeTpms = {
2966
2963
  };
2967
2964
 
2968
2965
  const bridgeSimulator = {
2966
+ isRebootRequired(deviceId) {
2967
+ return store.bridgeRebootRequired[deviceId];
2968
+ },
2969
2969
  async getVehicle(deviceId) {
2970
2970
  const bridge = getSimulatedBridge(deviceId);
2971
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.92",
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",