tirecheck-device-sdk 0.2.58 → 0.2.60

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
@@ -136,12 +136,7 @@ function normalizeError(error) {
136
136
 
137
137
  const tyreLabels = getDefaultTyreLabels();
138
138
  const bridgeTools = {
139
- getBridgeFromStore(deviceId) {
140
- const deviceData = store.devices[deviceId];
141
- if (!deviceData) throw new Error(`No device data found: ${deviceId}`);
142
- if (deviceData.type !== "bridge") throw new Error("Device is not bridge");
143
- return deviceData;
144
- },
139
+ getBridgeFromStore,
145
140
  convertBytesToStructure(objStructure, payload, fwVersion) {
146
141
  let numArray = ___default.clone(payload);
147
142
  const keys = Object.keys(objStructure).filter(
@@ -251,7 +246,7 @@ const bridgeTools = {
251
246
  },
252
247
  convertBarToKpaByte(deviceId, value) {
253
248
  if (!value) return 0;
254
- const deviceData = this.getBridgeFromStore(deviceId);
249
+ const deviceData = getBridgeFromStore(deviceId);
255
250
  if (!deviceData) throw new Error(`Cannot convert bar to kpa byte, no device data found: ${deviceId}`);
256
251
  const bitValue = deviceData.name.includes("030717") ? 6.7 : 5.0625;
257
252
  return ___default.round((value + 1) * 100 / bitValue);
@@ -276,7 +271,7 @@ const bridgeTools = {
276
271
  if (!___default.isNumber(value)) {
277
272
  throw new TypeError("Value has to be a number");
278
273
  }
279
- const deviceData = this.getBridgeFromStore(deviceId);
274
+ const deviceData = getBridgeFromStore(deviceId);
280
275
  if (!deviceData) throw new Error(`Cannot convert kpa byte to bar, no device data found: ${deviceId}`);
281
276
  const bitValue = deviceData.name.includes("030717") ? 6.7 : 5.0625;
282
277
  const rawBar = value * bitValue / 100;
@@ -286,7 +281,7 @@ const bridgeTools = {
286
281
  if (version.length !== 5) {
287
282
  throw new Error("Invalid version format");
288
283
  }
289
- const deviceData = this.getBridgeFromStore(deviceId);
284
+ const deviceData = getBridgeFromStore(deviceId);
290
285
  if (deviceData?.advertisingData?.fwVersion) {
291
286
  return deviceData.advertisingData.fwVersion > version;
292
287
  }
@@ -366,6 +361,12 @@ const bridgeTools = {
366
361
  return bitIndex;
367
362
  }
368
363
  };
364
+ function getBridgeFromStore(deviceId) {
365
+ const deviceData = store.devices[deviceId];
366
+ if (!deviceData) throw new Error(`No device data found: ${deviceId}`);
367
+ if (deviceData.type !== "bridge") throw new Error("Device is not bridge");
368
+ return deviceData;
369
+ }
369
370
  function getDefaultTyreLabels() {
370
371
  const tyreLabelsStr = "_L;_R;_LO;_LI;_RI;_RO;_";
371
372
  const tyreLabelsStrLoc = tyreLabelsStr;
@@ -2475,15 +2476,23 @@ async function setVehicle(deviceId, tcVehicle) {
2475
2476
  }
2476
2477
  async function getSensorReading(deviceId, positionId) {
2477
2478
  const value = await bridgeCommands.getSensorMeasurement(deviceId, positionId);
2479
+ const messageLength = value[2];
2480
+ const payloadStartIndex = 9;
2481
+ const payloadLength = messageLength - 6;
2482
+ const payload = value.slice(payloadStartIndex, payloadStartIndex + payloadLength);
2483
+ if (payload.length < 6) {
2484
+ throw new Error(`Invalid sensor measurement payload length: ${payload.length}`);
2485
+ }
2478
2486
  const sensorId = value.slice(5, 9).reverse().map((s) => decimalToHex(s).toUpperCase()).join("");
2479
2487
  const correctedSensorId = bridgeTools.convertSensorIdFromBridge(sensorId);
2480
2488
  return {
2481
- date: Date.now() - value[14] * 2e3,
2489
+ date: Date.now() - payload[5] * 2e3,
2482
2490
  sensorId: correctedSensorId,
2483
- sensorStatus: value[12],
2484
- eceStatus: value[13],
2485
- pressureIssue: getPressureIssue$1(deviceId, value[13]),
2486
- ...getPressureAndTemperatureReadingObjects(value[9], value[10]),
2491
+ sensorType: payload[6],
2492
+ sensorStatus: payload[3],
2493
+ eceStatus: payload[4],
2494
+ pressureIssue: getPressureIssue$1(deviceId, payload[4]),
2495
+ ...getPressureAndTemperatureReadingObjects(payload[0], payload[1]),
2487
2496
  byteReading: value
2488
2497
  };
2489
2498
  }
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;
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;
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;
package/dist/index.mjs CHANGED
@@ -129,12 +129,7 @@ function normalizeError(error) {
129
129
 
130
130
  const tyreLabels = getDefaultTyreLabels();
131
131
  const bridgeTools = {
132
- getBridgeFromStore(deviceId) {
133
- const deviceData = store.devices[deviceId];
134
- if (!deviceData) throw new Error(`No device data found: ${deviceId}`);
135
- if (deviceData.type !== "bridge") throw new Error("Device is not bridge");
136
- return deviceData;
137
- },
132
+ getBridgeFromStore,
138
133
  convertBytesToStructure(objStructure, payload, fwVersion) {
139
134
  let numArray = _.clone(payload);
140
135
  const keys = Object.keys(objStructure).filter(
@@ -244,7 +239,7 @@ const bridgeTools = {
244
239
  },
245
240
  convertBarToKpaByte(deviceId, value) {
246
241
  if (!value) return 0;
247
- const deviceData = this.getBridgeFromStore(deviceId);
242
+ const deviceData = getBridgeFromStore(deviceId);
248
243
  if (!deviceData) throw new Error(`Cannot convert bar to kpa byte, no device data found: ${deviceId}`);
249
244
  const bitValue = deviceData.name.includes("030717") ? 6.7 : 5.0625;
250
245
  return _.round((value + 1) * 100 / bitValue);
@@ -269,7 +264,7 @@ const bridgeTools = {
269
264
  if (!_.isNumber(value)) {
270
265
  throw new TypeError("Value has to be a number");
271
266
  }
272
- const deviceData = this.getBridgeFromStore(deviceId);
267
+ const deviceData = getBridgeFromStore(deviceId);
273
268
  if (!deviceData) throw new Error(`Cannot convert kpa byte to bar, no device data found: ${deviceId}`);
274
269
  const bitValue = deviceData.name.includes("030717") ? 6.7 : 5.0625;
275
270
  const rawBar = value * bitValue / 100;
@@ -279,7 +274,7 @@ const bridgeTools = {
279
274
  if (version.length !== 5) {
280
275
  throw new Error("Invalid version format");
281
276
  }
282
- const deviceData = this.getBridgeFromStore(deviceId);
277
+ const deviceData = getBridgeFromStore(deviceId);
283
278
  if (deviceData?.advertisingData?.fwVersion) {
284
279
  return deviceData.advertisingData.fwVersion > version;
285
280
  }
@@ -359,6 +354,12 @@ const bridgeTools = {
359
354
  return bitIndex;
360
355
  }
361
356
  };
357
+ function getBridgeFromStore(deviceId) {
358
+ const deviceData = store.devices[deviceId];
359
+ if (!deviceData) throw new Error(`No device data found: ${deviceId}`);
360
+ if (deviceData.type !== "bridge") throw new Error("Device is not bridge");
361
+ return deviceData;
362
+ }
362
363
  function getDefaultTyreLabels() {
363
364
  const tyreLabelsStr = "_L;_R;_LO;_LI;_RI;_RO;_";
364
365
  const tyreLabelsStrLoc = tyreLabelsStr;
@@ -2468,15 +2469,23 @@ async function setVehicle(deviceId, tcVehicle) {
2468
2469
  }
2469
2470
  async function getSensorReading(deviceId, positionId) {
2470
2471
  const value = await bridgeCommands.getSensorMeasurement(deviceId, positionId);
2472
+ const messageLength = value[2];
2473
+ const payloadStartIndex = 9;
2474
+ const payloadLength = messageLength - 6;
2475
+ const payload = value.slice(payloadStartIndex, payloadStartIndex + payloadLength);
2476
+ if (payload.length < 6) {
2477
+ throw new Error(`Invalid sensor measurement payload length: ${payload.length}`);
2478
+ }
2471
2479
  const sensorId = value.slice(5, 9).reverse().map((s) => decimalToHex(s).toUpperCase()).join("");
2472
2480
  const correctedSensorId = bridgeTools.convertSensorIdFromBridge(sensorId);
2473
2481
  return {
2474
- date: Date.now() - value[14] * 2e3,
2482
+ date: Date.now() - payload[5] * 2e3,
2475
2483
  sensorId: correctedSensorId,
2476
- sensorStatus: value[12],
2477
- eceStatus: value[13],
2478
- pressureIssue: getPressureIssue$1(deviceId, value[13]),
2479
- ...getPressureAndTemperatureReadingObjects(value[9], value[10]),
2484
+ sensorType: payload[6],
2485
+ sensorStatus: payload[3],
2486
+ eceStatus: payload[4],
2487
+ pressureIssue: getPressureIssue$1(deviceId, payload[4]),
2488
+ ...getPressureAndTemperatureReadingObjects(payload[0], payload[1]),
2480
2489
  byteReading: value
2481
2490
  };
2482
2491
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.2.58",
3
+ "version": "0.2.60",
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",