tirecheck-device-sdk 0.2.51 → 0.2.52

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
@@ -251,10 +251,12 @@ const bridgeTools = {
251
251
  return ___default.round((value + 1) * 100 / 5.0625);
252
252
  },
253
253
  convertSensorIdForBridge(sensorId) {
254
- if (sensorId.startsWith("2") && sensorId.length === 10) {
255
- return Number.parseInt(sensorId).toString(16);
254
+ let bridgeSensorId = sensorId;
255
+ if (/\d{10}/.test(sensorId)) {
256
+ bridgeSensorId = Number.parseInt(sensorId).toString(16);
256
257
  }
257
- return sensorId;
258
+ if (bridgeSensorId.length !== 8) throw new Error("Sensor ID has to be 8 characters long");
259
+ return bridgeSensorId;
258
260
  },
259
261
  kpaByteToBar(value, decrementValue = 1) {
260
262
  if (!___default.isNumber(value)) {
@@ -274,9 +276,8 @@ const bridgeTools = {
274
276
  return false;
275
277
  },
276
278
  convertSensorIdFromBridge(sensorId) {
277
- const sensorIdDecimal = Number.parseInt(sensorId, 16).toString();
278
- if (sensorId.startsWith("B") && sensorIdDecimal.startsWith("2") && sensorIdDecimal.length === 10) {
279
- return sensorIdDecimal;
279
+ if (sensorId.startsWith("B")) {
280
+ return Number.parseInt(sensorId, 16).toString();
280
281
  }
281
282
  return sensorId;
282
283
  },
@@ -2300,9 +2301,9 @@ async function setAxleInfo(deviceId, tcVehicle) {
2300
2301
  if (!axleTyres.length && !spareTyre && axleIndex >= tcVehicle.axles.length) continue;
2301
2302
  for (const tyre of axleTyres) {
2302
2303
  const bridgeIndex = bridgeTools.getBridgeIndexFromPositionId(tyre.positionId, 7);
2303
- tyres[bridgeIndex] = tyre.tcTpmsSensor.id;
2304
+ tyres[bridgeIndex] = bridgeTools.convertSensorIdForBridge(tyre.tcTpmsSensor.id);
2304
2305
  }
2305
- if (spareTyre && spareTyre.tcTpmsSensor) tyres[7] = spareTyre.tcTpmsSensor.id;
2306
+ if (spareTyre && spareTyre.tcTpmsSensor) tyres[7] = bridgeTools.convertSensorIdForBridge(spareTyre.tcTpmsSensor.id);
2306
2307
  const numberArray = tyres.map((x) => x.match(/.{2}/g)?.reverse()).flat().map((n) => n ? Number.parseInt(n, 16) : 0);
2307
2308
  await bridgeCommands.setAxleInfo(deviceId, axleIndex, numberArray);
2308
2309
  }
package/dist/index.mjs CHANGED
@@ -244,10 +244,12 @@ const bridgeTools = {
244
244
  return _.round((value + 1) * 100 / 5.0625);
245
245
  },
246
246
  convertSensorIdForBridge(sensorId) {
247
- if (sensorId.startsWith("2") && sensorId.length === 10) {
248
- return Number.parseInt(sensorId).toString(16);
247
+ let bridgeSensorId = sensorId;
248
+ if (/\d{10}/.test(sensorId)) {
249
+ bridgeSensorId = Number.parseInt(sensorId).toString(16);
249
250
  }
250
- return sensorId;
251
+ if (bridgeSensorId.length !== 8) throw new Error("Sensor ID has to be 8 characters long");
252
+ return bridgeSensorId;
251
253
  },
252
254
  kpaByteToBar(value, decrementValue = 1) {
253
255
  if (!_.isNumber(value)) {
@@ -267,9 +269,8 @@ const bridgeTools = {
267
269
  return false;
268
270
  },
269
271
  convertSensorIdFromBridge(sensorId) {
270
- const sensorIdDecimal = Number.parseInt(sensorId, 16).toString();
271
- if (sensorId.startsWith("B") && sensorIdDecimal.startsWith("2") && sensorIdDecimal.length === 10) {
272
- return sensorIdDecimal;
272
+ if (sensorId.startsWith("B")) {
273
+ return Number.parseInt(sensorId, 16).toString();
273
274
  }
274
275
  return sensorId;
275
276
  },
@@ -2293,9 +2294,9 @@ async function setAxleInfo(deviceId, tcVehicle) {
2293
2294
  if (!axleTyres.length && !spareTyre && axleIndex >= tcVehicle.axles.length) continue;
2294
2295
  for (const tyre of axleTyres) {
2295
2296
  const bridgeIndex = bridgeTools.getBridgeIndexFromPositionId(tyre.positionId, 7);
2296
- tyres[bridgeIndex] = tyre.tcTpmsSensor.id;
2297
+ tyres[bridgeIndex] = bridgeTools.convertSensorIdForBridge(tyre.tcTpmsSensor.id);
2297
2298
  }
2298
- if (spareTyre && spareTyre.tcTpmsSensor) tyres[7] = spareTyre.tcTpmsSensor.id;
2299
+ if (spareTyre && spareTyre.tcTpmsSensor) tyres[7] = bridgeTools.convertSensorIdForBridge(spareTyre.tcTpmsSensor.id);
2299
2300
  const numberArray = tyres.map((x) => x.match(/.{2}/g)?.reverse()).flat().map((n) => n ? Number.parseInt(n, 16) : 0);
2300
2301
  await bridgeCommands.setAxleInfo(deviceId, axleIndex, numberArray);
2301
2302
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.2.51",
3
+ "version": "0.2.52",
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",