tirecheck-device-sdk 0.2.1 → 0.2.2

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
@@ -3290,7 +3290,12 @@ const simulator = {
3290
3290
  const simulatedDevices = {};
3291
3291
  for (const key in devices) {
3292
3292
  const device = devices[key];
3293
- const normalizedDevice = normalizeSimulatedDevice(device);
3293
+ let normalizedDevice = normalizeSimulatedDevice(device);
3294
+ if (normalizedDevice) {
3295
+ if (normalizedDevice?.type === "bridge" && normalizedDevice?.simulatorData?.sensors) {
3296
+ normalizedDevice = processNormalizedBridgeDevice(normalizedDevice);
3297
+ }
3298
+ }
3294
3299
  if (normalizedDevice) simulatedDevices[normalizedDevice.id] = normalizedDevice;
3295
3300
  }
3296
3301
  store.simulatedDevices = simulatedDevices;
@@ -3298,7 +3303,12 @@ const simulator = {
3298
3303
  },
3299
3304
  putSimulatedDevice(device) {
3300
3305
  ensureSimulatorMethodsAreInjected();
3301
- const normalizedDevice = this.createSimulatedDevice(device);
3306
+ let normalizedDevice = this.createSimulatedDevice(device);
3307
+ if (normalizedDevice) {
3308
+ if (normalizedDevice?.type === "bridge" && normalizedDevice?.simulatorData?.sensors) {
3309
+ normalizedDevice = processNormalizedBridgeDevice(normalizedDevice);
3310
+ }
3311
+ }
3302
3312
  store.simulatedDevices[normalizedDevice.id] = normalizedDevice;
3303
3313
  return normalizedDevice;
3304
3314
  },
@@ -3307,40 +3317,10 @@ const simulator = {
3307
3317
  },
3308
3318
  createSimulatedDevice(device) {
3309
3319
  ensureSimulatorMethodsAreInjected();
3310
- const normalizedDevice = normalizeSimulatedDevice(device);
3320
+ let normalizedDevice = normalizeSimulatedDevice(device);
3311
3321
  if (normalizedDevice) {
3312
3322
  if (normalizedDevice?.type === "bridge" && normalizedDevice?.simulatorData?.sensors) {
3313
- const keys = Object.keys(normalizedDevice.simulatorData.sensors);
3314
- for (const key of keys) {
3315
- const sensor = normalizedDevice.simulatorData.sensors[key];
3316
- const sensorIdInBinary = bridgeTools.hexToDecimalArray(sensor.sensorId).reverse();
3317
- const pressureTemperature = getRawPressureandTemperatureValue(
3318
- sensor.pressure.bar,
3319
- sensor.pressure.meas,
3320
- sensor.temperature.celsius
3321
- );
3322
- const responseHeader = [16, 1, 12, 253];
3323
- const rssiByte = 255;
3324
- const sensorStatus = sensor.sensorStatus;
3325
- const eceStatusByte = calculateEceStatusByte(
3326
- key,
3327
- normalizedDevice.simulatorData,
3328
- normalizedDevice.advertisingData
3329
- );
3330
- const signatureBytes = [255, 255, 255, 255];
3331
- sensor.byteReading = [
3332
- ...responseHeader,
3333
- 25,
3334
- ...sensorIdInBinary,
3335
- ...pressureTemperature,
3336
- rssiByte,
3337
- sensorStatus,
3338
- eceStatusByte,
3339
- 40,
3340
- ...signatureBytes
3341
- ];
3342
- sensor.eceStatus = eceStatusByte;
3343
- }
3323
+ normalizedDevice = processNormalizedBridgeDevice(normalizedDevice);
3344
3324
  }
3345
3325
  }
3346
3326
  return normalizedDevice;
@@ -3399,12 +3379,12 @@ function getRawPressureandTemperatureValue(barPressure, measPressure, measuredTe
3399
3379
  const ambientTemperature = 20;
3400
3380
  const rawTemperature = 40 + measuredTemperature;
3401
3381
  if (measPressure !== null) {
3402
- return [Math.round((measPressure + 1) * 19.753086), rawTemperature];
3382
+ return { rawPressure: Math.round((measPressure + 1) * 19.753086), rawTemperature };
3403
3383
  }
3404
3384
  const rawPressure = Math.round(
3405
3385
  (barPressure + 1) * (273 + measuredTemperature) / (273 + ambientTemperature) * 19.753086
3406
3386
  );
3407
- return [rawPressure, rawTemperature];
3387
+ return { rawPressure, rawTemperature };
3408
3388
  }
3409
3389
  function ensureSimulatorMethodsAreInjected() {
3410
3390
  if (areSimulatorMethodsInjected) return;
@@ -3456,6 +3436,39 @@ function ensureSimulatorMethodsAreInjected() {
3456
3436
  }
3457
3437
  }
3458
3438
  }
3439
+ function processNormalizedBridgeDevice(device) {
3440
+ const keys = Object.keys(device.simulatorData.sensors);
3441
+ for (const key of keys) {
3442
+ const sensor = device.simulatorData.sensors[key];
3443
+ const sensorIdInBinary = bridgeTools.hexToDecimalArray(sensor.sensorId).reverse();
3444
+ const { rawPressure, rawTemperature } = getRawPressureandTemperatureValue(
3445
+ sensor.pressure.bar,
3446
+ sensor.pressure.meas,
3447
+ sensor.temperature.celsius
3448
+ );
3449
+ sensor.pressure.raw = rawPressure;
3450
+ sensor.temperature.raw = rawTemperature;
3451
+ const responseHeader = [16, 1, 12, 253];
3452
+ const rssiByte = 255;
3453
+ const sensorStatus = sensor.sensorStatus;
3454
+ const eceStatusByte = calculateEceStatusByte(key, device.simulatorData, device.advertisingData);
3455
+ const signatureBytes = [255, 255, 255, 255];
3456
+ sensor.byteReading = [
3457
+ ...responseHeader,
3458
+ 25,
3459
+ ...sensorIdInBinary,
3460
+ rawPressure,
3461
+ rawTemperature,
3462
+ rssiByte,
3463
+ sensorStatus,
3464
+ eceStatusByte,
3465
+ 40,
3466
+ ...signatureBytes
3467
+ ];
3468
+ sensor.eceStatus = eceStatusByte;
3469
+ }
3470
+ return device;
3471
+ }
3459
3472
 
3460
3473
  class BridgeTcVehicleAxle {
3461
3474
  targetPressure;
package/dist/index.mjs CHANGED
@@ -3283,7 +3283,12 @@ const simulator = {
3283
3283
  const simulatedDevices = {};
3284
3284
  for (const key in devices) {
3285
3285
  const device = devices[key];
3286
- const normalizedDevice = normalizeSimulatedDevice(device);
3286
+ let normalizedDevice = normalizeSimulatedDevice(device);
3287
+ if (normalizedDevice) {
3288
+ if (normalizedDevice?.type === "bridge" && normalizedDevice?.simulatorData?.sensors) {
3289
+ normalizedDevice = processNormalizedBridgeDevice(normalizedDevice);
3290
+ }
3291
+ }
3287
3292
  if (normalizedDevice) simulatedDevices[normalizedDevice.id] = normalizedDevice;
3288
3293
  }
3289
3294
  store.simulatedDevices = simulatedDevices;
@@ -3291,7 +3296,12 @@ const simulator = {
3291
3296
  },
3292
3297
  putSimulatedDevice(device) {
3293
3298
  ensureSimulatorMethodsAreInjected();
3294
- const normalizedDevice = this.createSimulatedDevice(device);
3299
+ let normalizedDevice = this.createSimulatedDevice(device);
3300
+ if (normalizedDevice) {
3301
+ if (normalizedDevice?.type === "bridge" && normalizedDevice?.simulatorData?.sensors) {
3302
+ normalizedDevice = processNormalizedBridgeDevice(normalizedDevice);
3303
+ }
3304
+ }
3295
3305
  store.simulatedDevices[normalizedDevice.id] = normalizedDevice;
3296
3306
  return normalizedDevice;
3297
3307
  },
@@ -3300,40 +3310,10 @@ const simulator = {
3300
3310
  },
3301
3311
  createSimulatedDevice(device) {
3302
3312
  ensureSimulatorMethodsAreInjected();
3303
- const normalizedDevice = normalizeSimulatedDevice(device);
3313
+ let normalizedDevice = normalizeSimulatedDevice(device);
3304
3314
  if (normalizedDevice) {
3305
3315
  if (normalizedDevice?.type === "bridge" && normalizedDevice?.simulatorData?.sensors) {
3306
- const keys = Object.keys(normalizedDevice.simulatorData.sensors);
3307
- for (const key of keys) {
3308
- const sensor = normalizedDevice.simulatorData.sensors[key];
3309
- const sensorIdInBinary = bridgeTools.hexToDecimalArray(sensor.sensorId).reverse();
3310
- const pressureTemperature = getRawPressureandTemperatureValue(
3311
- sensor.pressure.bar,
3312
- sensor.pressure.meas,
3313
- sensor.temperature.celsius
3314
- );
3315
- const responseHeader = [16, 1, 12, 253];
3316
- const rssiByte = 255;
3317
- const sensorStatus = sensor.sensorStatus;
3318
- const eceStatusByte = calculateEceStatusByte(
3319
- key,
3320
- normalizedDevice.simulatorData,
3321
- normalizedDevice.advertisingData
3322
- );
3323
- const signatureBytes = [255, 255, 255, 255];
3324
- sensor.byteReading = [
3325
- ...responseHeader,
3326
- 25,
3327
- ...sensorIdInBinary,
3328
- ...pressureTemperature,
3329
- rssiByte,
3330
- sensorStatus,
3331
- eceStatusByte,
3332
- 40,
3333
- ...signatureBytes
3334
- ];
3335
- sensor.eceStatus = eceStatusByte;
3336
- }
3316
+ normalizedDevice = processNormalizedBridgeDevice(normalizedDevice);
3337
3317
  }
3338
3318
  }
3339
3319
  return normalizedDevice;
@@ -3392,12 +3372,12 @@ function getRawPressureandTemperatureValue(barPressure, measPressure, measuredTe
3392
3372
  const ambientTemperature = 20;
3393
3373
  const rawTemperature = 40 + measuredTemperature;
3394
3374
  if (measPressure !== null) {
3395
- return [Math.round((measPressure + 1) * 19.753086), rawTemperature];
3375
+ return { rawPressure: Math.round((measPressure + 1) * 19.753086), rawTemperature };
3396
3376
  }
3397
3377
  const rawPressure = Math.round(
3398
3378
  (barPressure + 1) * (273 + measuredTemperature) / (273 + ambientTemperature) * 19.753086
3399
3379
  );
3400
- return [rawPressure, rawTemperature];
3380
+ return { rawPressure, rawTemperature };
3401
3381
  }
3402
3382
  function ensureSimulatorMethodsAreInjected() {
3403
3383
  if (areSimulatorMethodsInjected) return;
@@ -3449,6 +3429,39 @@ function ensureSimulatorMethodsAreInjected() {
3449
3429
  }
3450
3430
  }
3451
3431
  }
3432
+ function processNormalizedBridgeDevice(device) {
3433
+ const keys = Object.keys(device.simulatorData.sensors);
3434
+ for (const key of keys) {
3435
+ const sensor = device.simulatorData.sensors[key];
3436
+ const sensorIdInBinary = bridgeTools.hexToDecimalArray(sensor.sensorId).reverse();
3437
+ const { rawPressure, rawTemperature } = getRawPressureandTemperatureValue(
3438
+ sensor.pressure.bar,
3439
+ sensor.pressure.meas,
3440
+ sensor.temperature.celsius
3441
+ );
3442
+ sensor.pressure.raw = rawPressure;
3443
+ sensor.temperature.raw = rawTemperature;
3444
+ const responseHeader = [16, 1, 12, 253];
3445
+ const rssiByte = 255;
3446
+ const sensorStatus = sensor.sensorStatus;
3447
+ const eceStatusByte = calculateEceStatusByte(key, device.simulatorData, device.advertisingData);
3448
+ const signatureBytes = [255, 255, 255, 255];
3449
+ sensor.byteReading = [
3450
+ ...responseHeader,
3451
+ 25,
3452
+ ...sensorIdInBinary,
3453
+ rawPressure,
3454
+ rawTemperature,
3455
+ rssiByte,
3456
+ sensorStatus,
3457
+ eceStatusByte,
3458
+ 40,
3459
+ ...signatureBytes
3460
+ ];
3461
+ sensor.eceStatus = eceStatusByte;
3462
+ }
3463
+ return device;
3464
+ }
3452
3465
 
3453
3466
  class BridgeTcVehicleAxle {
3454
3467
  targetPressure;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.2.01",
3
+ "version": "0.2.02",
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",