tirecheck-device-sdk 0.1.996 → 0.1.998

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
@@ -235,7 +235,7 @@ const bridgeTools = {
235
235
  },
236
236
  barToKpaByte(value) {
237
237
  if (!value) return 0;
238
- return ___default.round((value + 1) * 100 / 5.0625);
238
+ return ___default.round(value * 100 / 5.0625);
239
239
  },
240
240
  convertSensorIdForBridge(sensorId) {
241
241
  if (sensorId.startsWith("2") && sensorId.length === 10) {
@@ -243,12 +243,12 @@ const bridgeTools = {
243
243
  }
244
244
  return sensorId;
245
245
  },
246
- kpaByteToBar(value, decrementValue = 1) {
246
+ kpaByteToBar(value) {
247
247
  if (!___default.isNumber(value)) {
248
248
  throw new TypeError("Value has to be a number");
249
249
  }
250
250
  const rawBar = value * 5.0625 / 100;
251
- return ___default.round(Math.max(rawBar - decrementValue, 0), 1);
251
+ return ___default.round(Math.max(rawBar, 0), 1);
252
252
  },
253
253
  isVersionGreaterThan(deviceId, version) {
254
254
  if (version.length !== 5) {
@@ -2333,7 +2333,7 @@ async function getSensorReading(deviceId, positionId) {
2333
2333
  sensorId: correctedSensorId,
2334
2334
  sensorStatus: value[12],
2335
2335
  eceStatus: value[13],
2336
- pressureIssue: getPressureIssue(deviceId, value[13]),
2336
+ pressureIssue: getPressureIssue$1(deviceId, value[13]),
2337
2337
  ...getPressureAndTemperatureReadingObjects(value[9], value[10]),
2338
2338
  byteReading: value
2339
2339
  };
@@ -2436,13 +2436,13 @@ function getPressureAndTemperatureReadingObjects(rawPressure, rawTemperature) {
2436
2436
  return {
2437
2437
  pressure: {
2438
2438
  raw: rawPressure,
2439
- meas: Math.max(0, measuredPressureAbsolute - 1),
2440
- bar: Math.max(0, compensatedPressureAbsolute - 1)
2439
+ meas: Math.max(0, measuredPressureAbsolute),
2440
+ bar: Math.max(0, compensatedPressureAbsolute)
2441
2441
  },
2442
2442
  temperature: { raw: rawTemperature, amb: ambientTemperature, celsius: measuredTemperature }
2443
2443
  };
2444
2444
  }
2445
- function getPressureIssue(deviceId, eceStatus) {
2445
+ function getPressureIssue$1(deviceId, eceStatus) {
2446
2446
  if (eceStatus === 254) {
2447
2447
  return {
2448
2448
  date: Date.now(),
@@ -2615,16 +2615,13 @@ async function assignTyres(deviceId, tcVehicle) {
2615
2615
  async function assignAxlePressureLimits(deviceId, tcVehicle, tcVehicleAxle, axleIndex, bridgeAxlesPressureData) {
2616
2616
  const axlesPressureData = bridgeAxlesPressureData ?? (await bridgeCommands.getAxlesPressure(deviceId)).data;
2617
2617
  if (axlesPressureData[axleIndex * 3]) {
2618
- tcVehicleAxle.maxTargetPressure = ___default.floor(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2618
+ tcVehicleAxle.maxTargetPressure = ___default.floor(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]));
2619
2619
  }
2620
2620
  if (axlesPressureData[axleIndex * 3 + 1]) {
2621
- tcVehicleAxle.minTargetPressure = ___default.ceil(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2621
+ tcVehicleAxle.minTargetPressure = ___default.ceil(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]));
2622
2622
  }
2623
2623
  if (axlesPressureData[axleIndex * 3 + 2]) {
2624
- tcVehicleAxle.targetPressure = ___default.round(
2625
- bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 2], void 0),
2626
- 1
2627
- );
2624
+ tcVehicleAxle.targetPressure = ___default.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 2]), 1);
2628
2625
  }
2629
2626
  return tcVehicleAxle;
2630
2627
  }
@@ -2906,6 +2903,7 @@ const bridgeSimulator = {
2906
2903
  },
2907
2904
  async setVehicle(deviceId, vehicle) {
2908
2905
  const bridge = getSimulatedBridge(deviceId);
2906
+ bridge.vin = vehicle.vin ?? bridge.vin;
2909
2907
  bridge.simulatorData.vehicle = vehicle;
2910
2908
  },
2911
2909
  async getConfiguration(deviceId) {
@@ -2914,7 +2912,7 @@ const bridgeSimulator = {
2914
2912
  },
2915
2913
  async setConfiguration(deviceId, config) {
2916
2914
  const bridge = getSimulatedBridge(deviceId);
2917
- bridge.simulatorData.configuration = config;
2915
+ bridge.simulatorData.configuration = ___default.cloneDeep(config);
2918
2916
  },
2919
2917
  async getSensorReading(deviceId, positionId) {
2920
2918
  const bridge = getSimulatedBridge(deviceId);
@@ -2922,7 +2920,12 @@ const bridgeSimulator = {
2922
2920
  },
2923
2921
  async getVehicleReadings(deviceId, vehicle) {
2924
2922
  const bridge = getSimulatedBridge(deviceId);
2925
- return ___default.values(bridge.simulatorData.sensors);
2923
+ const readings = ___default.values(bridge.simulatorData.sensors);
2924
+ for (const reading of readings) {
2925
+ reading.date = (/* @__PURE__ */ new Date()).getTime();
2926
+ reading.pressureIssue = getPressureIssue(deviceId, reading.eceStatus);
2927
+ }
2928
+ return readings;
2926
2929
  },
2927
2930
  async getAutolearnStatuses(deviceId) {
2928
2931
  const bridge = getSimulatedBridge(deviceId);
@@ -2946,7 +2949,7 @@ const bridgeSimulator = {
2946
2949
  bridge.advertisingData.fwVersion = "1.9.9";
2947
2950
  },
2948
2951
  async connect(deviceId) {
2949
- if (store.simulatedDevices[deviceId].isDisabled) throw new Error(`Simulated bridge is disabled: ${deviceId}`);
2952
+ if (store.simulatedDevices[deviceId].isDisabled) return;
2950
2953
  store.setState(deviceId, "connecting");
2951
2954
  await toolsSvc.delay(100);
2952
2955
  store.setState(deviceId, "connected");
@@ -2959,9 +2962,72 @@ const bridgeSimulator = {
2959
2962
  store.setState(deviceId, void 0, "manualDisconnection");
2960
2963
  },
2961
2964
  createSimulatedDevice(initialData) {
2962
- return simulatorSvc.merge(getSimulatedBridgeTemplate(), initialData);
2965
+ const mergedData = simulatorSvc.merge(getSimulatedBridgeTemplate(), initialData);
2966
+ mergedData.advertisingData.macAddress = initialData.id?.split(":").map((x) => Number.parseInt(x, 16)) ?? [
2967
+ 1,
2968
+ 2,
2969
+ 3,
2970
+ 4,
2971
+ 5,
2972
+ 6
2973
+ ];
2974
+ return mergedData;
2963
2975
  }
2964
2976
  };
2977
+ function getPressureIssue(deviceId, eceStatus) {
2978
+ if (eceStatus === 254) {
2979
+ return {
2980
+ date: Date.now(),
2981
+ tcIssue: {
2982
+ id: "outdatedCritical"
2983
+ },
2984
+ type: "outdated",
2985
+ severity: "critical"
2986
+ };
2987
+ }
2988
+ const bridge = getSimulatedBridge(deviceId);
2989
+ const usesNewValues = (bridge.advertisingData.fwVersion || "") > "0.8.F";
2990
+ if (eceStatus === (usesNewValues ? 3 : 4)) {
2991
+ return {
2992
+ date: Date.now(),
2993
+ tcIssue: {
2994
+ id: "overinflationCritical"
2995
+ },
2996
+ type: "over_inflated",
2997
+ severity: "critical"
2998
+ };
2999
+ }
3000
+ if (eceStatus === (usesNewValues ? 1 : 3)) {
3001
+ return {
3002
+ date: Date.now(),
3003
+ tcIssue: {
3004
+ id: "overinflationWarning"
3005
+ },
3006
+ severity: "warning",
3007
+ type: "over_inflated"
3008
+ };
3009
+ }
3010
+ if (eceStatus === (usesNewValues ? 4 : 2)) {
3011
+ return {
3012
+ date: Date.now(),
3013
+ tcIssue: {
3014
+ id: "underinflationCritical"
3015
+ },
3016
+ severity: "critical",
3017
+ type: "under_inflated"
3018
+ };
3019
+ }
3020
+ if (eceStatus === (usesNewValues ? 2 : 1)) {
3021
+ return {
3022
+ date: Date.now(),
3023
+ tcIssue: {
3024
+ id: "underinflationWarning"
3025
+ },
3026
+ severity: "warning",
3027
+ type: "under_inflated"
3028
+ };
3029
+ }
3030
+ }
2965
3031
  function getSimulatedBridge(deviceId) {
2966
3032
  const simulatedDevice = store.simulatedDevices[deviceId];
2967
3033
  if (!simulatedDevice) throw new Error(`Simulated bridge was not found: ${deviceId}`);
@@ -2973,7 +3039,7 @@ function getSimulatedBridgeTemplate() {
2973
3039
  type: "bridge",
2974
3040
  id: "bridge1",
2975
3041
  rssi: -50,
2976
- bridgeId: "FFFFAABB",
3042
+ bridgeId: "FFFAABB",
2977
3043
  vin: "VIN1",
2978
3044
  name: "Bridge1",
2979
3045
  simulatorData: {
@@ -2982,7 +3048,7 @@ function getSimulatedBridgeTemplate() {
2982
3048
  registrationNumber: "",
2983
3049
  vin: "VIN1",
2984
3050
  tcTyres: [
2985
- { mountedOn: { positionId: 112 }, serialNumber: "TYRE-112", tcTpmsSensor: { id: "FFFFAABB" } },
3051
+ { mountedOn: { positionId: 112 }, serialNumber: "TYRE-112", tcTpmsSensor: { id: "A0FFAABB" } },
2986
3052
  { mountedOn: { positionId: 122 }, serialNumber: "TYRE-122" }
2987
3053
  ]
2988
3054
  },
@@ -2990,18 +3056,18 @@ function getSimulatedBridgeTemplate() {
2990
3056
  112: {
2991
3057
  autolearnedStatus: "default",
2992
3058
  positionId: 112,
2993
- autolearnedSensorId: "FFFFAABB"
3059
+ autolearnedSensorId: "A0FFAABB"
2994
3060
  }
2995
3061
  },
2996
3062
  sensors: {
2997
3063
  112: {
2998
3064
  date: Date.now(),
2999
- eceStatus: 0,
3000
- sensorId: "FFFFAABB",
3065
+ eceStatus: 2,
3066
+ sensorId: "A0FFAABB",
3001
3067
  sensorStatus: 0,
3002
- pressure: { bar: 0, meas: 0, raw: 0 },
3068
+ pressure: { bar: 1, meas: 1, raw: 19 },
3003
3069
  pressureIssue: void 0,
3004
- temperature: { amb: 0, celsius: 0, raw: 0 },
3070
+ temperature: { amb: 20, celsius: 24, raw: 64 },
3005
3071
  byteReading: [0, 0, 0, 0, 0, 0, 0, 0]
3006
3072
  }
3007
3073
  },
@@ -3179,10 +3245,51 @@ const simulator = {
3179
3245
  return simulatedDevices;
3180
3246
  },
3181
3247
  putSimulatedDevice(device) {
3248
+ ensureSimulatorMethodsAreInjected();
3249
+ const normalizedDevice = this.createSimulatedDevice(device);
3250
+ store.simulatedDevices[normalizedDevice.id] = normalizedDevice;
3251
+ return normalizedDevice;
3252
+ },
3253
+ putSimulatedNormalizedDevice(normalizedDevice) {
3254
+ store.simulatedDevices[normalizedDevice.id] = normalizedDevice;
3255
+ },
3256
+ createSimulatedDevice(device) {
3182
3257
  ensureSimulatorMethodsAreInjected();
3183
3258
  const normalizedDevice = normalizeSimulatedDevice(device);
3184
3259
  if (normalizedDevice) {
3185
- store.simulatedDevices[normalizedDevice.id] = normalizedDevice;
3260
+ if (normalizedDevice?.type === "bridge" && normalizedDevice?.simulatorData?.sensors) {
3261
+ const keys = Object.keys(normalizedDevice.simulatorData.sensors);
3262
+ for (const key of keys) {
3263
+ const sensor = normalizedDevice.simulatorData.sensors[key];
3264
+ const sensorIdInBinary = bridgeTools.hexToDecimalArray(sensor.sensorId).reverse();
3265
+ const pressureTemperature = getRawPressureandTemperatureValue(
3266
+ sensor.pressure.bar,
3267
+ sensor.pressure.meas,
3268
+ sensor.temperature.celsius
3269
+ );
3270
+ const responseHeader = [16, 1, 12, 253];
3271
+ const rssiByte = 255;
3272
+ const sensorStatus = sensor.sensorStatus;
3273
+ const eceStatusByte = calculateEceStatusByte(
3274
+ key,
3275
+ normalizedDevice.simulatorData,
3276
+ normalizedDevice.advertisingData
3277
+ );
3278
+ const signatureBytes = [255, 255, 255, 255];
3279
+ sensor.byteReading = [
3280
+ ...responseHeader,
3281
+ 25,
3282
+ ...sensorIdInBinary,
3283
+ ...pressureTemperature,
3284
+ rssiByte,
3285
+ sensorStatus,
3286
+ eceStatusByte,
3287
+ 40,
3288
+ ...signatureBytes
3289
+ ];
3290
+ sensor.eceStatus = eceStatusByte;
3291
+ }
3292
+ }
3186
3293
  }
3187
3294
  return normalizedDevice;
3188
3295
  },
@@ -3204,6 +3311,49 @@ function normalizeSimulatedDevice(device) {
3204
3311
  }
3205
3312
  throw new Error(`Simulator is not supported for device type: ${device.type}`);
3206
3313
  }
3314
+ function calculateEceStatusByte(positionId, simulatorData, advertisingData) {
3315
+ const customerPressureThresholdsDecimal = bridgeTools.hexToDecimalArray(
3316
+ simulatorData.configuration.customerPressureThresholds.axle01
3317
+ );
3318
+ const pressureThresholds = {
3319
+ overinflationCritical: customerPressureThresholdsDecimal[0],
3320
+ overinflationWarning: customerPressureThresholdsDecimal[1],
3321
+ underinflationWarning: customerPressureThresholdsDecimal[2],
3322
+ underinflationCritical: customerPressureThresholdsDecimal[3]
3323
+ };
3324
+ const sensor = simulatorData.sensors[positionId];
3325
+ const axleIndex = Math.floor(positionId / 100) - 1;
3326
+ const axle = simulatorData.vehicle.axles[axleIndex];
3327
+ if (!axle || axle.targetPressure === void 0) return 0;
3328
+ if (!sensor.pressure) return 0;
3329
+ const sensorPressure = sensor.pressure.meas ?? sensor.pressure.bar;
3330
+ const percentageDifference = (sensorPressure - axle.targetPressure) / axle.targetPressure * 100;
3331
+ const usesNewValues = (advertisingData.fwVersion || "") > "0.8.F";
3332
+ if (percentageDifference >= pressureThresholds.overinflationCritical) {
3333
+ return usesNewValues ? 3 : 4;
3334
+ }
3335
+ if (percentageDifference >= pressureThresholds.overinflationWarning) {
3336
+ return usesNewValues ? 1 : 3;
3337
+ }
3338
+ if (percentageDifference <= -pressureThresholds.underinflationCritical) {
3339
+ return usesNewValues ? 4 : 2;
3340
+ }
3341
+ if (percentageDifference <= -pressureThresholds.underinflationWarning) {
3342
+ return usesNewValues ? 2 : 1;
3343
+ }
3344
+ return 0;
3345
+ }
3346
+ function getRawPressureandTemperatureValue(barPressure, measPressure, measuredTemperature) {
3347
+ const ambientTemperature = 20;
3348
+ const rawTemperature = 40 + measuredTemperature;
3349
+ if (measPressure !== null) {
3350
+ return [Math.round((measPressure + 1) * 19.753086), rawTemperature];
3351
+ }
3352
+ const rawPressure = Math.round(
3353
+ (barPressure + 1) * (273 + measuredTemperature) / (273 + ambientTemperature) * 19.753086
3354
+ );
3355
+ return [rawPressure, rawTemperature];
3356
+ }
3207
3357
  function ensureSimulatorMethodsAreInjected() {
3208
3358
  if (areSimulatorMethodsInjected) return;
3209
3359
  areSimulatorMethodsInjected = true;
package/dist/index.d.cts CHANGED
@@ -894,6 +894,8 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
894
894
  simulator: {
895
895
  putSimulatedDevices(devices: Record<string, DeepPartial<BleDeviceSimulated>>): Record<string, BleDeviceSimulated>;
896
896
  putSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
897
+ putSimulatedNormalizedDevice(normalizedDevice: BleBridgeSimulated | BleFlexiGaugeTpmsSimulated): void;
898
+ createSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
897
899
  deleteSimulatedDevice(deviceId: string): void;
898
900
  getSimulatedDevices(): Record<string, BleDeviceSimulated>;
899
901
  triggerEvent: (eventName: EventName, deviceId: string, payload?: any) => void;
package/dist/index.d.mts CHANGED
@@ -894,6 +894,8 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
894
894
  simulator: {
895
895
  putSimulatedDevices(devices: Record<string, DeepPartial<BleDeviceSimulated>>): Record<string, BleDeviceSimulated>;
896
896
  putSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
897
+ putSimulatedNormalizedDevice(normalizedDevice: BleBridgeSimulated | BleFlexiGaugeTpmsSimulated): void;
898
+ createSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
897
899
  deleteSimulatedDevice(deviceId: string): void;
898
900
  getSimulatedDevices(): Record<string, BleDeviceSimulated>;
899
901
  triggerEvent: (eventName: EventName, deviceId: string, payload?: any) => void;
package/dist/index.d.ts CHANGED
@@ -894,6 +894,8 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
894
894
  simulator: {
895
895
  putSimulatedDevices(devices: Record<string, DeepPartial<BleDeviceSimulated>>): Record<string, BleDeviceSimulated>;
896
896
  putSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
897
+ putSimulatedNormalizedDevice(normalizedDevice: BleBridgeSimulated | BleFlexiGaugeTpmsSimulated): void;
898
+ createSimulatedDevice(device: DeepPartial<BleDeviceSimulated>): BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
897
899
  deleteSimulatedDevice(deviceId: string): void;
898
900
  getSimulatedDevices(): Record<string, BleDeviceSimulated>;
899
901
  triggerEvent: (eventName: EventName, deviceId: string, payload?: any) => void;
package/dist/index.mjs CHANGED
@@ -228,7 +228,7 @@ const bridgeTools = {
228
228
  },
229
229
  barToKpaByte(value) {
230
230
  if (!value) return 0;
231
- return _.round((value + 1) * 100 / 5.0625);
231
+ return _.round(value * 100 / 5.0625);
232
232
  },
233
233
  convertSensorIdForBridge(sensorId) {
234
234
  if (sensorId.startsWith("2") && sensorId.length === 10) {
@@ -236,12 +236,12 @@ const bridgeTools = {
236
236
  }
237
237
  return sensorId;
238
238
  },
239
- kpaByteToBar(value, decrementValue = 1) {
239
+ kpaByteToBar(value) {
240
240
  if (!_.isNumber(value)) {
241
241
  throw new TypeError("Value has to be a number");
242
242
  }
243
243
  const rawBar = value * 5.0625 / 100;
244
- return _.round(Math.max(rawBar - decrementValue, 0), 1);
244
+ return _.round(Math.max(rawBar, 0), 1);
245
245
  },
246
246
  isVersionGreaterThan(deviceId, version) {
247
247
  if (version.length !== 5) {
@@ -2326,7 +2326,7 @@ async function getSensorReading(deviceId, positionId) {
2326
2326
  sensorId: correctedSensorId,
2327
2327
  sensorStatus: value[12],
2328
2328
  eceStatus: value[13],
2329
- pressureIssue: getPressureIssue(deviceId, value[13]),
2329
+ pressureIssue: getPressureIssue$1(deviceId, value[13]),
2330
2330
  ...getPressureAndTemperatureReadingObjects(value[9], value[10]),
2331
2331
  byteReading: value
2332
2332
  };
@@ -2429,13 +2429,13 @@ function getPressureAndTemperatureReadingObjects(rawPressure, rawTemperature) {
2429
2429
  return {
2430
2430
  pressure: {
2431
2431
  raw: rawPressure,
2432
- meas: Math.max(0, measuredPressureAbsolute - 1),
2433
- bar: Math.max(0, compensatedPressureAbsolute - 1)
2432
+ meas: Math.max(0, measuredPressureAbsolute),
2433
+ bar: Math.max(0, compensatedPressureAbsolute)
2434
2434
  },
2435
2435
  temperature: { raw: rawTemperature, amb: ambientTemperature, celsius: measuredTemperature }
2436
2436
  };
2437
2437
  }
2438
- function getPressureIssue(deviceId, eceStatus) {
2438
+ function getPressureIssue$1(deviceId, eceStatus) {
2439
2439
  if (eceStatus === 254) {
2440
2440
  return {
2441
2441
  date: Date.now(),
@@ -2608,16 +2608,13 @@ async function assignTyres(deviceId, tcVehicle) {
2608
2608
  async function assignAxlePressureLimits(deviceId, tcVehicle, tcVehicleAxle, axleIndex, bridgeAxlesPressureData) {
2609
2609
  const axlesPressureData = bridgeAxlesPressureData ?? (await bridgeCommands.getAxlesPressure(deviceId)).data;
2610
2610
  if (axlesPressureData[axleIndex * 3]) {
2611
- tcVehicleAxle.maxTargetPressure = _.floor(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2611
+ tcVehicleAxle.maxTargetPressure = _.floor(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]));
2612
2612
  }
2613
2613
  if (axlesPressureData[axleIndex * 3 + 1]) {
2614
- tcVehicleAxle.minTargetPressure = _.ceil(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2614
+ tcVehicleAxle.minTargetPressure = _.ceil(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]));
2615
2615
  }
2616
2616
  if (axlesPressureData[axleIndex * 3 + 2]) {
2617
- tcVehicleAxle.targetPressure = _.round(
2618
- bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 2], void 0),
2619
- 1
2620
- );
2617
+ tcVehicleAxle.targetPressure = _.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 2]), 1);
2621
2618
  }
2622
2619
  return tcVehicleAxle;
2623
2620
  }
@@ -2899,6 +2896,7 @@ const bridgeSimulator = {
2899
2896
  },
2900
2897
  async setVehicle(deviceId, vehicle) {
2901
2898
  const bridge = getSimulatedBridge(deviceId);
2899
+ bridge.vin = vehicle.vin ?? bridge.vin;
2902
2900
  bridge.simulatorData.vehicle = vehicle;
2903
2901
  },
2904
2902
  async getConfiguration(deviceId) {
@@ -2907,7 +2905,7 @@ const bridgeSimulator = {
2907
2905
  },
2908
2906
  async setConfiguration(deviceId, config) {
2909
2907
  const bridge = getSimulatedBridge(deviceId);
2910
- bridge.simulatorData.configuration = config;
2908
+ bridge.simulatorData.configuration = _.cloneDeep(config);
2911
2909
  },
2912
2910
  async getSensorReading(deviceId, positionId) {
2913
2911
  const bridge = getSimulatedBridge(deviceId);
@@ -2915,7 +2913,12 @@ const bridgeSimulator = {
2915
2913
  },
2916
2914
  async getVehicleReadings(deviceId, vehicle) {
2917
2915
  const bridge = getSimulatedBridge(deviceId);
2918
- return _.values(bridge.simulatorData.sensors);
2916
+ const readings = _.values(bridge.simulatorData.sensors);
2917
+ for (const reading of readings) {
2918
+ reading.date = (/* @__PURE__ */ new Date()).getTime();
2919
+ reading.pressureIssue = getPressureIssue(deviceId, reading.eceStatus);
2920
+ }
2921
+ return readings;
2919
2922
  },
2920
2923
  async getAutolearnStatuses(deviceId) {
2921
2924
  const bridge = getSimulatedBridge(deviceId);
@@ -2939,7 +2942,7 @@ const bridgeSimulator = {
2939
2942
  bridge.advertisingData.fwVersion = "1.9.9";
2940
2943
  },
2941
2944
  async connect(deviceId) {
2942
- if (store.simulatedDevices[deviceId].isDisabled) throw new Error(`Simulated bridge is disabled: ${deviceId}`);
2945
+ if (store.simulatedDevices[deviceId].isDisabled) return;
2943
2946
  store.setState(deviceId, "connecting");
2944
2947
  await toolsSvc.delay(100);
2945
2948
  store.setState(deviceId, "connected");
@@ -2952,9 +2955,72 @@ const bridgeSimulator = {
2952
2955
  store.setState(deviceId, void 0, "manualDisconnection");
2953
2956
  },
2954
2957
  createSimulatedDevice(initialData) {
2955
- return simulatorSvc.merge(getSimulatedBridgeTemplate(), initialData);
2958
+ const mergedData = simulatorSvc.merge(getSimulatedBridgeTemplate(), initialData);
2959
+ mergedData.advertisingData.macAddress = initialData.id?.split(":").map((x) => Number.parseInt(x, 16)) ?? [
2960
+ 1,
2961
+ 2,
2962
+ 3,
2963
+ 4,
2964
+ 5,
2965
+ 6
2966
+ ];
2967
+ return mergedData;
2956
2968
  }
2957
2969
  };
2970
+ function getPressureIssue(deviceId, eceStatus) {
2971
+ if (eceStatus === 254) {
2972
+ return {
2973
+ date: Date.now(),
2974
+ tcIssue: {
2975
+ id: "outdatedCritical"
2976
+ },
2977
+ type: "outdated",
2978
+ severity: "critical"
2979
+ };
2980
+ }
2981
+ const bridge = getSimulatedBridge(deviceId);
2982
+ const usesNewValues = (bridge.advertisingData.fwVersion || "") > "0.8.F";
2983
+ if (eceStatus === (usesNewValues ? 3 : 4)) {
2984
+ return {
2985
+ date: Date.now(),
2986
+ tcIssue: {
2987
+ id: "overinflationCritical"
2988
+ },
2989
+ type: "over_inflated",
2990
+ severity: "critical"
2991
+ };
2992
+ }
2993
+ if (eceStatus === (usesNewValues ? 1 : 3)) {
2994
+ return {
2995
+ date: Date.now(),
2996
+ tcIssue: {
2997
+ id: "overinflationWarning"
2998
+ },
2999
+ severity: "warning",
3000
+ type: "over_inflated"
3001
+ };
3002
+ }
3003
+ if (eceStatus === (usesNewValues ? 4 : 2)) {
3004
+ return {
3005
+ date: Date.now(),
3006
+ tcIssue: {
3007
+ id: "underinflationCritical"
3008
+ },
3009
+ severity: "critical",
3010
+ type: "under_inflated"
3011
+ };
3012
+ }
3013
+ if (eceStatus === (usesNewValues ? 2 : 1)) {
3014
+ return {
3015
+ date: Date.now(),
3016
+ tcIssue: {
3017
+ id: "underinflationWarning"
3018
+ },
3019
+ severity: "warning",
3020
+ type: "under_inflated"
3021
+ };
3022
+ }
3023
+ }
2958
3024
  function getSimulatedBridge(deviceId) {
2959
3025
  const simulatedDevice = store.simulatedDevices[deviceId];
2960
3026
  if (!simulatedDevice) throw new Error(`Simulated bridge was not found: ${deviceId}`);
@@ -2966,7 +3032,7 @@ function getSimulatedBridgeTemplate() {
2966
3032
  type: "bridge",
2967
3033
  id: "bridge1",
2968
3034
  rssi: -50,
2969
- bridgeId: "FFFFAABB",
3035
+ bridgeId: "FFFAABB",
2970
3036
  vin: "VIN1",
2971
3037
  name: "Bridge1",
2972
3038
  simulatorData: {
@@ -2975,7 +3041,7 @@ function getSimulatedBridgeTemplate() {
2975
3041
  registrationNumber: "",
2976
3042
  vin: "VIN1",
2977
3043
  tcTyres: [
2978
- { mountedOn: { positionId: 112 }, serialNumber: "TYRE-112", tcTpmsSensor: { id: "FFFFAABB" } },
3044
+ { mountedOn: { positionId: 112 }, serialNumber: "TYRE-112", tcTpmsSensor: { id: "A0FFAABB" } },
2979
3045
  { mountedOn: { positionId: 122 }, serialNumber: "TYRE-122" }
2980
3046
  ]
2981
3047
  },
@@ -2983,18 +3049,18 @@ function getSimulatedBridgeTemplate() {
2983
3049
  112: {
2984
3050
  autolearnedStatus: "default",
2985
3051
  positionId: 112,
2986
- autolearnedSensorId: "FFFFAABB"
3052
+ autolearnedSensorId: "A0FFAABB"
2987
3053
  }
2988
3054
  },
2989
3055
  sensors: {
2990
3056
  112: {
2991
3057
  date: Date.now(),
2992
- eceStatus: 0,
2993
- sensorId: "FFFFAABB",
3058
+ eceStatus: 2,
3059
+ sensorId: "A0FFAABB",
2994
3060
  sensorStatus: 0,
2995
- pressure: { bar: 0, meas: 0, raw: 0 },
3061
+ pressure: { bar: 1, meas: 1, raw: 19 },
2996
3062
  pressureIssue: void 0,
2997
- temperature: { amb: 0, celsius: 0, raw: 0 },
3063
+ temperature: { amb: 20, celsius: 24, raw: 64 },
2998
3064
  byteReading: [0, 0, 0, 0, 0, 0, 0, 0]
2999
3065
  }
3000
3066
  },
@@ -3172,10 +3238,51 @@ const simulator = {
3172
3238
  return simulatedDevices;
3173
3239
  },
3174
3240
  putSimulatedDevice(device) {
3241
+ ensureSimulatorMethodsAreInjected();
3242
+ const normalizedDevice = this.createSimulatedDevice(device);
3243
+ store.simulatedDevices[normalizedDevice.id] = normalizedDevice;
3244
+ return normalizedDevice;
3245
+ },
3246
+ putSimulatedNormalizedDevice(normalizedDevice) {
3247
+ store.simulatedDevices[normalizedDevice.id] = normalizedDevice;
3248
+ },
3249
+ createSimulatedDevice(device) {
3175
3250
  ensureSimulatorMethodsAreInjected();
3176
3251
  const normalizedDevice = normalizeSimulatedDevice(device);
3177
3252
  if (normalizedDevice) {
3178
- store.simulatedDevices[normalizedDevice.id] = normalizedDevice;
3253
+ if (normalizedDevice?.type === "bridge" && normalizedDevice?.simulatorData?.sensors) {
3254
+ const keys = Object.keys(normalizedDevice.simulatorData.sensors);
3255
+ for (const key of keys) {
3256
+ const sensor = normalizedDevice.simulatorData.sensors[key];
3257
+ const sensorIdInBinary = bridgeTools.hexToDecimalArray(sensor.sensorId).reverse();
3258
+ const pressureTemperature = getRawPressureandTemperatureValue(
3259
+ sensor.pressure.bar,
3260
+ sensor.pressure.meas,
3261
+ sensor.temperature.celsius
3262
+ );
3263
+ const responseHeader = [16, 1, 12, 253];
3264
+ const rssiByte = 255;
3265
+ const sensorStatus = sensor.sensorStatus;
3266
+ const eceStatusByte = calculateEceStatusByte(
3267
+ key,
3268
+ normalizedDevice.simulatorData,
3269
+ normalizedDevice.advertisingData
3270
+ );
3271
+ const signatureBytes = [255, 255, 255, 255];
3272
+ sensor.byteReading = [
3273
+ ...responseHeader,
3274
+ 25,
3275
+ ...sensorIdInBinary,
3276
+ ...pressureTemperature,
3277
+ rssiByte,
3278
+ sensorStatus,
3279
+ eceStatusByte,
3280
+ 40,
3281
+ ...signatureBytes
3282
+ ];
3283
+ sensor.eceStatus = eceStatusByte;
3284
+ }
3285
+ }
3179
3286
  }
3180
3287
  return normalizedDevice;
3181
3288
  },
@@ -3197,6 +3304,49 @@ function normalizeSimulatedDevice(device) {
3197
3304
  }
3198
3305
  throw new Error(`Simulator is not supported for device type: ${device.type}`);
3199
3306
  }
3307
+ function calculateEceStatusByte(positionId, simulatorData, advertisingData) {
3308
+ const customerPressureThresholdsDecimal = bridgeTools.hexToDecimalArray(
3309
+ simulatorData.configuration.customerPressureThresholds.axle01
3310
+ );
3311
+ const pressureThresholds = {
3312
+ overinflationCritical: customerPressureThresholdsDecimal[0],
3313
+ overinflationWarning: customerPressureThresholdsDecimal[1],
3314
+ underinflationWarning: customerPressureThresholdsDecimal[2],
3315
+ underinflationCritical: customerPressureThresholdsDecimal[3]
3316
+ };
3317
+ const sensor = simulatorData.sensors[positionId];
3318
+ const axleIndex = Math.floor(positionId / 100) - 1;
3319
+ const axle = simulatorData.vehicle.axles[axleIndex];
3320
+ if (!axle || axle.targetPressure === void 0) return 0;
3321
+ if (!sensor.pressure) return 0;
3322
+ const sensorPressure = sensor.pressure.meas ?? sensor.pressure.bar;
3323
+ const percentageDifference = (sensorPressure - axle.targetPressure) / axle.targetPressure * 100;
3324
+ const usesNewValues = (advertisingData.fwVersion || "") > "0.8.F";
3325
+ if (percentageDifference >= pressureThresholds.overinflationCritical) {
3326
+ return usesNewValues ? 3 : 4;
3327
+ }
3328
+ if (percentageDifference >= pressureThresholds.overinflationWarning) {
3329
+ return usesNewValues ? 1 : 3;
3330
+ }
3331
+ if (percentageDifference <= -pressureThresholds.underinflationCritical) {
3332
+ return usesNewValues ? 4 : 2;
3333
+ }
3334
+ if (percentageDifference <= -pressureThresholds.underinflationWarning) {
3335
+ return usesNewValues ? 2 : 1;
3336
+ }
3337
+ return 0;
3338
+ }
3339
+ function getRawPressureandTemperatureValue(barPressure, measPressure, measuredTemperature) {
3340
+ const ambientTemperature = 20;
3341
+ const rawTemperature = 40 + measuredTemperature;
3342
+ if (measPressure !== null) {
3343
+ return [Math.round((measPressure + 1) * 19.753086), rawTemperature];
3344
+ }
3345
+ const rawPressure = Math.round(
3346
+ (barPressure + 1) * (273 + measuredTemperature) / (273 + ambientTemperature) * 19.753086
3347
+ );
3348
+ return [rawPressure, rawTemperature];
3349
+ }
3200
3350
  function ensureSimulatorMethodsAreInjected() {
3201
3351
  if (areSimulatorMethodsInjected) return;
3202
3352
  areSimulatorMethodsInjected = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.1.996",
3
+ "version": "0.1.998",
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",