tirecheck-device-sdk 0.1.98 → 0.1.99

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
@@ -406,7 +406,8 @@ function processAndroidAdvertising(adv, isKrone) {
406
406
  }
407
407
  if (messageType === 3 && identificator === 255) {
408
408
  advertisingData.macAddress = packet.slice(5, 11);
409
- advertisingData.vinNum = packet.slice(-17);
409
+ advertisingData.vinNum = packet.slice(11, 28);
410
+ advertisingData.vinExtension = packet[28];
410
411
  }
411
412
  if (messageType === 1 && identificator === 255) {
412
413
  advertisingData.randomAdvNumber = packet.slice(-8);
@@ -443,6 +444,15 @@ function processIosAdvertising(adv, isKrone) {
443
444
  advertisingData.macAddress = adv.slice(17, 23);
444
445
  advertisingData.vinNum = adv.slice(23, 40);
445
446
  }
447
+ if (adv.length === 43) {
448
+ advertisingData.randomAdvNumber = adv.slice(3, 11);
449
+ advertisingData.fwVersion = bridgeTools.getFwVersion(adv.slice(11, 14));
450
+ advertisingData.configVersion = adv[14];
451
+ advertisingData.timeFromStart = adv[15];
452
+ advertisingData.macAddress = adv.slice(17, 23);
453
+ advertisingData.vinNum = adv.slice(23, 40);
454
+ advertisingData.vinExtension = adv[40];
455
+ }
446
456
  return advertisingData;
447
457
  }
448
458
 
@@ -542,7 +552,22 @@ const deviceMeta = {
542
552
  }
543
553
  };
544
554
 
545
- const checkUnreachableDevicesTimeouts = {};
555
+ const timeouts = {};
556
+ const unreachableSvc = {
557
+ clear,
558
+ refresh
559
+ };
560
+ function clear(deviceId) {
561
+ if (timeouts[deviceId]) clearTimeout(timeouts[deviceId]);
562
+ }
563
+ function refresh(deviceId, deviceUnreachableCallback) {
564
+ clear(deviceId);
565
+ timeouts[deviceId] = setTimeout(() => {
566
+ delete store.devices[deviceId];
567
+ deviceUnreachableCallback?.(deviceId);
568
+ }, 6e4);
569
+ }
570
+
546
571
  let deviceAdvertisingCallback;
547
572
  let deviceUnreachableCallback;
548
573
  let deviceStateChangeCallback;
@@ -612,7 +637,7 @@ async function connect$1(deviceId, disconnectCallback) {
612
637
  }
613
638
  }
614
639
  }
615
- clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
640
+ unreachableSvc.clear(deviceId);
616
641
  store.setState(deviceId, "connected");
617
642
  return connectedDevice;
618
643
  }
@@ -674,7 +699,7 @@ function processDevice(device) {
674
699
  console.warn("Error processing advertising", e);
675
700
  return;
676
701
  }
677
- refreshUnreachableTimeouts(processedDevice.id);
702
+ unreachableSvc.refresh(processedDevice.id, deviceUnreachableCallback);
678
703
  return processedDevice;
679
704
  }
680
705
  function getDeviceTypeFromName(name) {
@@ -687,15 +712,6 @@ function getDeviceTypeFromName(name) {
687
712
  }
688
713
  return deviceType;
689
714
  }
690
- function refreshUnreachableTimeouts(deviceId) {
691
- if (checkUnreachableDevicesTimeouts[deviceId]) {
692
- clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
693
- }
694
- checkUnreachableDevicesTimeouts[deviceId] = setTimeout(() => {
695
- delete store.devices[deviceId];
696
- deviceUnreachableCallback?.(deviceId);
697
- }, 6e4);
698
- }
699
715
  function getDeviceName(device) {
700
716
  const isBridge = deviceMeta.bridge.nameRegex.test(device.name) || deviceMeta.bridgeOta.nameRegex.test(device.name);
701
717
  if (isBridge && !device.advertising.kCBAdvDataLocalName) {
@@ -2184,7 +2200,7 @@ async function getConfiguration(deviceId) {
2184
2200
  }
2185
2201
  function bridgeVehiclesDifference(original, change) {
2186
2202
  const differences = [];
2187
- if (original.vin !== change.vin) differences.push("vin");
2203
+ if (original.vin !== change.vin || original.vinExtension !== change.vinExtension) differences.push("vin");
2188
2204
  const originalTyres = original.tcTyres.map((t) => {
2189
2205
  return { positionId: t.mountedOn?.positionId, sensorId: t.tcTpmsSensor?.id || null };
2190
2206
  });
@@ -3037,6 +3053,7 @@ const bridgeSimulator = {
3037
3053
  bridge.advertisingData.fwVersion = "1.9.9";
3038
3054
  },
3039
3055
  async connect(deviceId) {
3056
+ if (store.simulatedDevices[deviceId].isDisabled) throw new Error(`Simulated bridge is disabled: ${deviceId}`);
3040
3057
  store.setState(deviceId, "connecting");
3041
3058
  await toolsSvc.delay(100);
3042
3059
  store.setState(deviceId, "connected");
@@ -3304,12 +3321,19 @@ function ensureSimulatorMethodsAreInjected() {
3304
3321
  clearInterval(advertisingInterval);
3305
3322
  advertisingInterval = void 0;
3306
3323
  }
3324
+ let previousDevices = store.simulatedDevices;
3307
3325
  advertisingInterval = toolsSvc.setIntervalImmediate(() => {
3308
3326
  for (const key in store.simulatedDevices) {
3309
3327
  const d = store.simulatedDevices[key];
3310
3328
  if (d.isDisabled) continue;
3329
+ unreachableSvc.refresh(d.id, deviceUnreachableCallback);
3311
3330
  deviceAdvertisingCallback?.(store.simulatedDevices[key]);
3312
3331
  }
3332
+ const missingDevices = ___default.omit(previousDevices, Object.keys(store.simulatedDevices));
3333
+ for (const key in missingDevices) {
3334
+ deviceUnreachableCallback?.(key);
3335
+ }
3336
+ previousDevices = ___default.cloneDeep(store.simulatedDevices);
3313
3337
  }, 2e3);
3314
3338
  };
3315
3339
  for (const [svc, sim] of deviceServicesAndSimulators) {
package/dist/index.d.cts CHANGED
@@ -800,6 +800,7 @@ type Simulator<Service extends Record<string, any>, SimulatedDeviceType extends
800
800
  interface BleBridgeAdvertisingData {
801
801
  randomAdvNumber: number[];
802
802
  vinNum: number[];
803
+ vinExtension?: number;
803
804
  macAddress: number[];
804
805
  fwVersion?: string;
805
806
  /**
package/dist/index.d.mts CHANGED
@@ -800,6 +800,7 @@ type Simulator<Service extends Record<string, any>, SimulatedDeviceType extends
800
800
  interface BleBridgeAdvertisingData {
801
801
  randomAdvNumber: number[];
802
802
  vinNum: number[];
803
+ vinExtension?: number;
803
804
  macAddress: number[];
804
805
  fwVersion?: string;
805
806
  /**
package/dist/index.d.ts CHANGED
@@ -800,6 +800,7 @@ type Simulator<Service extends Record<string, any>, SimulatedDeviceType extends
800
800
  interface BleBridgeAdvertisingData {
801
801
  randomAdvNumber: number[];
802
802
  vinNum: number[];
803
+ vinExtension?: number;
803
804
  macAddress: number[];
804
805
  fwVersion?: string;
805
806
  /**
package/dist/index.mjs CHANGED
@@ -399,7 +399,8 @@ function processAndroidAdvertising(adv, isKrone) {
399
399
  }
400
400
  if (messageType === 3 && identificator === 255) {
401
401
  advertisingData.macAddress = packet.slice(5, 11);
402
- advertisingData.vinNum = packet.slice(-17);
402
+ advertisingData.vinNum = packet.slice(11, 28);
403
+ advertisingData.vinExtension = packet[28];
403
404
  }
404
405
  if (messageType === 1 && identificator === 255) {
405
406
  advertisingData.randomAdvNumber = packet.slice(-8);
@@ -436,6 +437,15 @@ function processIosAdvertising(adv, isKrone) {
436
437
  advertisingData.macAddress = adv.slice(17, 23);
437
438
  advertisingData.vinNum = adv.slice(23, 40);
438
439
  }
440
+ if (adv.length === 43) {
441
+ advertisingData.randomAdvNumber = adv.slice(3, 11);
442
+ advertisingData.fwVersion = bridgeTools.getFwVersion(adv.slice(11, 14));
443
+ advertisingData.configVersion = adv[14];
444
+ advertisingData.timeFromStart = adv[15];
445
+ advertisingData.macAddress = adv.slice(17, 23);
446
+ advertisingData.vinNum = adv.slice(23, 40);
447
+ advertisingData.vinExtension = adv[40];
448
+ }
439
449
  return advertisingData;
440
450
  }
441
451
 
@@ -535,7 +545,22 @@ const deviceMeta = {
535
545
  }
536
546
  };
537
547
 
538
- const checkUnreachableDevicesTimeouts = {};
548
+ const timeouts = {};
549
+ const unreachableSvc = {
550
+ clear,
551
+ refresh
552
+ };
553
+ function clear(deviceId) {
554
+ if (timeouts[deviceId]) clearTimeout(timeouts[deviceId]);
555
+ }
556
+ function refresh(deviceId, deviceUnreachableCallback) {
557
+ clear(deviceId);
558
+ timeouts[deviceId] = setTimeout(() => {
559
+ delete store.devices[deviceId];
560
+ deviceUnreachableCallback?.(deviceId);
561
+ }, 6e4);
562
+ }
563
+
539
564
  let deviceAdvertisingCallback;
540
565
  let deviceUnreachableCallback;
541
566
  let deviceStateChangeCallback;
@@ -605,7 +630,7 @@ async function connect$1(deviceId, disconnectCallback) {
605
630
  }
606
631
  }
607
632
  }
608
- clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
633
+ unreachableSvc.clear(deviceId);
609
634
  store.setState(deviceId, "connected");
610
635
  return connectedDevice;
611
636
  }
@@ -667,7 +692,7 @@ function processDevice(device) {
667
692
  console.warn("Error processing advertising", e);
668
693
  return;
669
694
  }
670
- refreshUnreachableTimeouts(processedDevice.id);
695
+ unreachableSvc.refresh(processedDevice.id, deviceUnreachableCallback);
671
696
  return processedDevice;
672
697
  }
673
698
  function getDeviceTypeFromName(name) {
@@ -680,15 +705,6 @@ function getDeviceTypeFromName(name) {
680
705
  }
681
706
  return deviceType;
682
707
  }
683
- function refreshUnreachableTimeouts(deviceId) {
684
- if (checkUnreachableDevicesTimeouts[deviceId]) {
685
- clearTimeout(checkUnreachableDevicesTimeouts[deviceId]);
686
- }
687
- checkUnreachableDevicesTimeouts[deviceId] = setTimeout(() => {
688
- delete store.devices[deviceId];
689
- deviceUnreachableCallback?.(deviceId);
690
- }, 6e4);
691
- }
692
708
  function getDeviceName(device) {
693
709
  const isBridge = deviceMeta.bridge.nameRegex.test(device.name) || deviceMeta.bridgeOta.nameRegex.test(device.name);
694
710
  if (isBridge && !device.advertising.kCBAdvDataLocalName) {
@@ -2177,7 +2193,7 @@ async function getConfiguration(deviceId) {
2177
2193
  }
2178
2194
  function bridgeVehiclesDifference(original, change) {
2179
2195
  const differences = [];
2180
- if (original.vin !== change.vin) differences.push("vin");
2196
+ if (original.vin !== change.vin || original.vinExtension !== change.vinExtension) differences.push("vin");
2181
2197
  const originalTyres = original.tcTyres.map((t) => {
2182
2198
  return { positionId: t.mountedOn?.positionId, sensorId: t.tcTpmsSensor?.id || null };
2183
2199
  });
@@ -3030,6 +3046,7 @@ const bridgeSimulator = {
3030
3046
  bridge.advertisingData.fwVersion = "1.9.9";
3031
3047
  },
3032
3048
  async connect(deviceId) {
3049
+ if (store.simulatedDevices[deviceId].isDisabled) throw new Error(`Simulated bridge is disabled: ${deviceId}`);
3033
3050
  store.setState(deviceId, "connecting");
3034
3051
  await toolsSvc.delay(100);
3035
3052
  store.setState(deviceId, "connected");
@@ -3297,12 +3314,19 @@ function ensureSimulatorMethodsAreInjected() {
3297
3314
  clearInterval(advertisingInterval);
3298
3315
  advertisingInterval = void 0;
3299
3316
  }
3317
+ let previousDevices = store.simulatedDevices;
3300
3318
  advertisingInterval = toolsSvc.setIntervalImmediate(() => {
3301
3319
  for (const key in store.simulatedDevices) {
3302
3320
  const d = store.simulatedDevices[key];
3303
3321
  if (d.isDisabled) continue;
3322
+ unreachableSvc.refresh(d.id, deviceUnreachableCallback);
3304
3323
  deviceAdvertisingCallback?.(store.simulatedDevices[key]);
3305
3324
  }
3325
+ const missingDevices = _.omit(previousDevices, Object.keys(store.simulatedDevices));
3326
+ for (const key in missingDevices) {
3327
+ deviceUnreachableCallback?.(key);
3328
+ }
3329
+ previousDevices = _.cloneDeep(store.simulatedDevices);
3306
3330
  }, 2e3);
3307
3331
  };
3308
3332
  for (const [svc, sim] of deviceServicesAndSimulators) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.1.98",
3
+ "version": "0.1.99",
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",