tirecheck-device-sdk 0.2.57 → 0.2.59

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
@@ -245,9 +245,17 @@ const bridgeTools = {
245
245
  }, []).join(".");
246
246
  },
247
247
  barToKpaByte(value) {
248
+ console.warn("barToKpaByte is deprecated, please use convertBarToKpaByte instead");
248
249
  if (!value) return 0;
249
250
  return ___default.round((value + 1) * 100 / 5.0625);
250
251
  },
252
+ convertBarToKpaByte(deviceId, value) {
253
+ if (!value) return 0;
254
+ const deviceData = this.getBridgeFromStore(deviceId);
255
+ if (!deviceData) throw new Error(`Cannot convert bar to kpa byte, no device data found: ${deviceId}`);
256
+ const bitValue = deviceData.name.includes("030717") ? 6.7 : 5.0625;
257
+ return ___default.round((value + 1) * 100 / bitValue);
258
+ },
251
259
  convertSensorIdForBridge(sensorId) {
252
260
  let bridgeSensorId = sensorId;
253
261
  if (/\d{10}/.test(sensorId)) {
@@ -257,12 +265,23 @@ const bridgeTools = {
257
265
  return bridgeSensorId;
258
266
  },
259
267
  kpaByteToBar(value, decrementValue = 1) {
268
+ console.warn("kpaByteToBar is deprecated, please use convertKpaByteToBar instead");
260
269
  if (!___default.isNumber(value)) {
261
270
  throw new TypeError("Value has to be a number");
262
271
  }
263
272
  const rawBar = value * 5.0625 / 100;
264
273
  return ___default.round(Math.max(rawBar - decrementValue, 0), 1);
265
274
  },
275
+ convertKpaByteToBar(deviceId, value, decrementValue = 1) {
276
+ if (!___default.isNumber(value)) {
277
+ throw new TypeError("Value has to be a number");
278
+ }
279
+ const deviceData = this.getBridgeFromStore(deviceId);
280
+ if (!deviceData) throw new Error(`Cannot convert kpa byte to bar, no device data found: ${deviceId}`);
281
+ const bitValue = deviceData.name.includes("030717") ? 6.7 : 5.0625;
282
+ const rawBar = value * bitValue / 100;
283
+ return ___default.round(Math.max(rawBar - decrementValue, 0), 1);
284
+ },
266
285
  isVersionGreaterThan(deviceId, version) {
267
286
  if (version.length !== 5) {
268
287
  throw new Error("Invalid version format");
@@ -2386,12 +2405,12 @@ async function setAxlesPressure(deviceId, axles) {
2386
2405
  let bridgeAxlesPressureData;
2387
2406
  for (let index = 0; index < 15; index++) {
2388
2407
  let { targetPressure, maxTargetPressure, minTargetPressure, isSpare } = axles[index] || {};
2389
- maxTargetPressure = bridgeTools.barToKpaByte(maxTargetPressure);
2390
- minTargetPressure = bridgeTools.barToKpaByte(minTargetPressure);
2408
+ maxTargetPressure = bridgeTools.convertBarToKpaByte(deviceId, maxTargetPressure);
2409
+ minTargetPressure = bridgeTools.convertBarToKpaByte(deviceId, minTargetPressure);
2391
2410
  if (isSpare && axles[0]) {
2392
- targetPressure = bridgeTools.barToKpaByte(axles[0].targetPressure);
2411
+ targetPressure = bridgeTools.convertBarToKpaByte(deviceId, axles[0].targetPressure);
2393
2412
  } else {
2394
- targetPressure = bridgeTools.barToKpaByte(targetPressure);
2413
+ targetPressure = bridgeTools.convertBarToKpaByte(deviceId, targetPressure);
2395
2414
  }
2396
2415
  if (!maxTargetPressure) {
2397
2416
  if (!bridgeAxlesPressureData) {
@@ -2456,15 +2475,23 @@ async function setVehicle(deviceId, tcVehicle) {
2456
2475
  }
2457
2476
  async function getSensorReading(deviceId, positionId) {
2458
2477
  const value = await bridgeCommands.getSensorMeasurement(deviceId, positionId);
2478
+ const messageLength = value[2];
2479
+ const payloadStartIndex = 9;
2480
+ const payloadLength = messageLength - 6;
2481
+ const payload = value.slice(payloadStartIndex, payloadStartIndex + payloadLength);
2482
+ if (payload.length < 6) {
2483
+ throw new Error(`Invalid sensor measurement payload length: ${payload.length}`);
2484
+ }
2459
2485
  const sensorId = value.slice(5, 9).reverse().map((s) => decimalToHex(s).toUpperCase()).join("");
2460
2486
  const correctedSensorId = bridgeTools.convertSensorIdFromBridge(sensorId);
2461
2487
  return {
2462
- date: Date.now() - value[14] * 2e3,
2488
+ date: Date.now() - payload[5] * 2e3,
2463
2489
  sensorId: correctedSensorId,
2464
- sensorStatus: value[12],
2465
- eceStatus: value[13],
2466
- pressureIssue: getPressureIssue$1(deviceId, value[13]),
2467
- ...getPressureAndTemperatureReadingObjects(value[9], value[10]),
2490
+ sensorType: payload[6],
2491
+ sensorStatus: payload[3],
2492
+ eceStatus: payload[4],
2493
+ pressureIssue: getPressureIssue$1(deviceId, payload[4]),
2494
+ ...getPressureAndTemperatureReadingObjects(payload[0], payload[1]),
2468
2495
  byteReading: value
2469
2496
  };
2470
2497
  }
@@ -2743,14 +2770,20 @@ async function assignTyres(deviceId, tcVehicle) {
2743
2770
  async function assignAxlePressureLimits(deviceId, tcVehicle, tcVehicleAxle, axleIndex, bridgeAxlesPressureData) {
2744
2771
  const axlesPressureData = bridgeAxlesPressureData ?? (await bridgeCommands.getAxlesPressure(deviceId)).data;
2745
2772
  if (axlesPressureData[axleIndex * 3]) {
2746
- tcVehicleAxle.maxTargetPressure = ___default.floor(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2773
+ tcVehicleAxle.maxTargetPressure = ___default.floor(
2774
+ bridgeTools.convertKpaByteToBar(deviceId, axlesPressureData[axleIndex * 3]),
2775
+ 1
2776
+ );
2747
2777
  }
2748
2778
  if (axlesPressureData[axleIndex * 3 + 1]) {
2749
- tcVehicleAxle.minTargetPressure = ___default.ceil(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2779
+ tcVehicleAxle.minTargetPressure = ___default.ceil(
2780
+ bridgeTools.convertKpaByteToBar(deviceId, axlesPressureData[axleIndex * 3 + 1]),
2781
+ 1
2782
+ );
2750
2783
  }
2751
2784
  if (axlesPressureData[axleIndex * 3 + 2]) {
2752
2785
  tcVehicleAxle.targetPressure = ___default.round(
2753
- bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 2], void 0),
2786
+ bridgeTools.convertKpaByteToBar(deviceId, axlesPressureData[axleIndex * 3 + 2], void 0),
2754
2787
  1
2755
2788
  );
2756
2789
  }
@@ -4502,7 +4535,13 @@ function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
4502
4535
  /** Allows simulating devices without actually using bluetooth */
4503
4536
  simulator,
4504
4537
  /** Methods for working with Tirecheck Torque Wrench */
4505
- torqueWrench
4538
+ torqueWrench,
4539
+ utils: {
4540
+ bridge: {
4541
+ convertBarToKpaByte: bridgeTools.convertBarToKpaByte,
4542
+ convertKpaByteToBar: bridgeTools.convertKpaByteToBar
4543
+ }
4544
+ }
4506
4545
  };
4507
4546
  }
4508
4547
 
package/dist/index.d.cts CHANGED
@@ -736,6 +736,7 @@ interface BridgeConfiguration {
736
736
  interface BridgeReading {
737
737
  date: number;
738
738
  sensorId: string;
739
+ sensorType?: number;
739
740
  sensorStatus: number;
740
741
  eceStatus: number;
741
742
  pressureIssue?: BridgeTcIssue;
@@ -1037,6 +1038,12 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1037
1038
  getTime: (deviceId: string) => Promise<Date>;
1038
1039
  onReading: (callback: (deviceId: string, value: TorqueWrenchReading) => void) => void;
1039
1040
  };
1041
+ utils: {
1042
+ bridge: {
1043
+ convertBarToKpaByte: (deviceId: string, value?: number) => number;
1044
+ convertKpaByteToBar: (deviceId: string, value?: number, decrementValue?: number) => number;
1045
+ };
1046
+ };
1040
1047
  };
1041
1048
 
1042
1049
  export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.d.mts CHANGED
@@ -736,6 +736,7 @@ interface BridgeConfiguration {
736
736
  interface BridgeReading {
737
737
  date: number;
738
738
  sensorId: string;
739
+ sensorType?: number;
739
740
  sensorStatus: number;
740
741
  eceStatus: number;
741
742
  pressureIssue?: BridgeTcIssue;
@@ -1037,6 +1038,12 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1037
1038
  getTime: (deviceId: string) => Promise<Date>;
1038
1039
  onReading: (callback: (deviceId: string, value: TorqueWrenchReading) => void) => void;
1039
1040
  };
1041
+ utils: {
1042
+ bridge: {
1043
+ convertBarToKpaByte: (deviceId: string, value?: number) => number;
1044
+ convertKpaByteToBar: (deviceId: string, value?: number, decrementValue?: number) => number;
1045
+ };
1046
+ };
1040
1047
  };
1041
1048
 
1042
1049
  export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.d.ts CHANGED
@@ -736,6 +736,7 @@ interface BridgeConfiguration {
736
736
  interface BridgeReading {
737
737
  date: number;
738
738
  sensorId: string;
739
+ sensorType?: number;
739
740
  sensorStatus: number;
740
741
  eceStatus: number;
741
742
  pressureIssue?: BridgeTcIssue;
@@ -1037,6 +1038,12 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1037
1038
  getTime: (deviceId: string) => Promise<Date>;
1038
1039
  onReading: (callback: (deviceId: string, value: TorqueWrenchReading) => void) => void;
1039
1040
  };
1041
+ utils: {
1042
+ bridge: {
1043
+ convertBarToKpaByte: (deviceId: string, value?: number) => number;
1044
+ convertKpaByteToBar: (deviceId: string, value?: number, decrementValue?: number) => number;
1045
+ };
1046
+ };
1040
1047
  };
1041
1048
 
1042
1049
  export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.mjs CHANGED
@@ -238,9 +238,17 @@ const bridgeTools = {
238
238
  }, []).join(".");
239
239
  },
240
240
  barToKpaByte(value) {
241
+ console.warn("barToKpaByte is deprecated, please use convertBarToKpaByte instead");
241
242
  if (!value) return 0;
242
243
  return _.round((value + 1) * 100 / 5.0625);
243
244
  },
245
+ convertBarToKpaByte(deviceId, value) {
246
+ if (!value) return 0;
247
+ const deviceData = this.getBridgeFromStore(deviceId);
248
+ if (!deviceData) throw new Error(`Cannot convert bar to kpa byte, no device data found: ${deviceId}`);
249
+ const bitValue = deviceData.name.includes("030717") ? 6.7 : 5.0625;
250
+ return _.round((value + 1) * 100 / bitValue);
251
+ },
244
252
  convertSensorIdForBridge(sensorId) {
245
253
  let bridgeSensorId = sensorId;
246
254
  if (/\d{10}/.test(sensorId)) {
@@ -250,12 +258,23 @@ const bridgeTools = {
250
258
  return bridgeSensorId;
251
259
  },
252
260
  kpaByteToBar(value, decrementValue = 1) {
261
+ console.warn("kpaByteToBar is deprecated, please use convertKpaByteToBar instead");
253
262
  if (!_.isNumber(value)) {
254
263
  throw new TypeError("Value has to be a number");
255
264
  }
256
265
  const rawBar = value * 5.0625 / 100;
257
266
  return _.round(Math.max(rawBar - decrementValue, 0), 1);
258
267
  },
268
+ convertKpaByteToBar(deviceId, value, decrementValue = 1) {
269
+ if (!_.isNumber(value)) {
270
+ throw new TypeError("Value has to be a number");
271
+ }
272
+ const deviceData = this.getBridgeFromStore(deviceId);
273
+ if (!deviceData) throw new Error(`Cannot convert kpa byte to bar, no device data found: ${deviceId}`);
274
+ const bitValue = deviceData.name.includes("030717") ? 6.7 : 5.0625;
275
+ const rawBar = value * bitValue / 100;
276
+ return _.round(Math.max(rawBar - decrementValue, 0), 1);
277
+ },
259
278
  isVersionGreaterThan(deviceId, version) {
260
279
  if (version.length !== 5) {
261
280
  throw new Error("Invalid version format");
@@ -2379,12 +2398,12 @@ async function setAxlesPressure(deviceId, axles) {
2379
2398
  let bridgeAxlesPressureData;
2380
2399
  for (let index = 0; index < 15; index++) {
2381
2400
  let { targetPressure, maxTargetPressure, minTargetPressure, isSpare } = axles[index] || {};
2382
- maxTargetPressure = bridgeTools.barToKpaByte(maxTargetPressure);
2383
- minTargetPressure = bridgeTools.barToKpaByte(minTargetPressure);
2401
+ maxTargetPressure = bridgeTools.convertBarToKpaByte(deviceId, maxTargetPressure);
2402
+ minTargetPressure = bridgeTools.convertBarToKpaByte(deviceId, minTargetPressure);
2384
2403
  if (isSpare && axles[0]) {
2385
- targetPressure = bridgeTools.barToKpaByte(axles[0].targetPressure);
2404
+ targetPressure = bridgeTools.convertBarToKpaByte(deviceId, axles[0].targetPressure);
2386
2405
  } else {
2387
- targetPressure = bridgeTools.barToKpaByte(targetPressure);
2406
+ targetPressure = bridgeTools.convertBarToKpaByte(deviceId, targetPressure);
2388
2407
  }
2389
2408
  if (!maxTargetPressure) {
2390
2409
  if (!bridgeAxlesPressureData) {
@@ -2449,15 +2468,23 @@ async function setVehicle(deviceId, tcVehicle) {
2449
2468
  }
2450
2469
  async function getSensorReading(deviceId, positionId) {
2451
2470
  const value = await bridgeCommands.getSensorMeasurement(deviceId, positionId);
2471
+ const messageLength = value[2];
2472
+ const payloadStartIndex = 9;
2473
+ const payloadLength = messageLength - 6;
2474
+ const payload = value.slice(payloadStartIndex, payloadStartIndex + payloadLength);
2475
+ if (payload.length < 6) {
2476
+ throw new Error(`Invalid sensor measurement payload length: ${payload.length}`);
2477
+ }
2452
2478
  const sensorId = value.slice(5, 9).reverse().map((s) => decimalToHex(s).toUpperCase()).join("");
2453
2479
  const correctedSensorId = bridgeTools.convertSensorIdFromBridge(sensorId);
2454
2480
  return {
2455
- date: Date.now() - value[14] * 2e3,
2481
+ date: Date.now() - payload[5] * 2e3,
2456
2482
  sensorId: correctedSensorId,
2457
- sensorStatus: value[12],
2458
- eceStatus: value[13],
2459
- pressureIssue: getPressureIssue$1(deviceId, value[13]),
2460
- ...getPressureAndTemperatureReadingObjects(value[9], value[10]),
2483
+ sensorType: payload[6],
2484
+ sensorStatus: payload[3],
2485
+ eceStatus: payload[4],
2486
+ pressureIssue: getPressureIssue$1(deviceId, payload[4]),
2487
+ ...getPressureAndTemperatureReadingObjects(payload[0], payload[1]),
2461
2488
  byteReading: value
2462
2489
  };
2463
2490
  }
@@ -2736,14 +2763,20 @@ async function assignTyres(deviceId, tcVehicle) {
2736
2763
  async function assignAxlePressureLimits(deviceId, tcVehicle, tcVehicleAxle, axleIndex, bridgeAxlesPressureData) {
2737
2764
  const axlesPressureData = bridgeAxlesPressureData ?? (await bridgeCommands.getAxlesPressure(deviceId)).data;
2738
2765
  if (axlesPressureData[axleIndex * 3]) {
2739
- tcVehicleAxle.maxTargetPressure = _.floor(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2766
+ tcVehicleAxle.maxTargetPressure = _.floor(
2767
+ bridgeTools.convertKpaByteToBar(deviceId, axlesPressureData[axleIndex * 3]),
2768
+ 1
2769
+ );
2740
2770
  }
2741
2771
  if (axlesPressureData[axleIndex * 3 + 1]) {
2742
- tcVehicleAxle.minTargetPressure = _.ceil(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2772
+ tcVehicleAxle.minTargetPressure = _.ceil(
2773
+ bridgeTools.convertKpaByteToBar(deviceId, axlesPressureData[axleIndex * 3 + 1]),
2774
+ 1
2775
+ );
2743
2776
  }
2744
2777
  if (axlesPressureData[axleIndex * 3 + 2]) {
2745
2778
  tcVehicleAxle.targetPressure = _.round(
2746
- bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 2], void 0),
2779
+ bridgeTools.convertKpaByteToBar(deviceId, axlesPressureData[axleIndex * 3 + 2], void 0),
2747
2780
  1
2748
2781
  );
2749
2782
  }
@@ -4495,7 +4528,13 @@ function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
4495
4528
  /** Allows simulating devices without actually using bluetooth */
4496
4529
  simulator,
4497
4530
  /** Methods for working with Tirecheck Torque Wrench */
4498
- torqueWrench
4531
+ torqueWrench,
4532
+ utils: {
4533
+ bridge: {
4534
+ convertBarToKpaByte: bridgeTools.convertBarToKpaByte,
4535
+ convertKpaByteToBar: bridgeTools.convertKpaByteToBar
4536
+ }
4537
+ }
4499
4538
  };
4500
4539
  }
4501
4540
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.2.57",
3
+ "version": "0.2.59",
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",