tirecheck-device-sdk 0.1.96 → 0.1.97

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
@@ -341,8 +341,9 @@ function getDefaultTyreLabels() {
341
341
  const bridgeAdvertisingParser = {
342
342
  getDeviceInfoFromAdvertising(device) {
343
343
  const adversitingType = getAdvertisingType(device);
344
- if (adversitingType !== "connectable") return void 0;
344
+ if (adversitingType !== "connectable") return;
345
345
  const advertisingData = getAdvertisingData({ advertising: device.advertising, deviceName: device.name });
346
+ if (!advertisingData) return;
346
347
  const macArray = advertisingData?.macAddress?.map((n) => bridgeTools.decimalToHex(n).toUpperCase()).reverse() || [];
347
348
  const bridgeId = macArray.join("");
348
349
  const vin = String.fromCharCode(...advertisingData?.vinNum || []).split("\0").join("");
@@ -378,7 +379,7 @@ function getAdvertisingData({ advertising, deviceName }) {
378
379
  const adv = Array.from(uint8);
379
380
  const advertisingData = advertising.kCBAdvDataIsConnectable ? processIosAdvertising(adv, isKrone) : processAndroidAdvertising(adv, isKrone);
380
381
  if (!advertisingData || !advertisingData.macAddress.length || !advertisingData.randomAdvNumber.length || !advertisingData.vinNum.length) {
381
- throw new Error("Device not recognized");
382
+ return;
382
383
  }
383
384
  return advertisingData;
384
385
  }
@@ -589,12 +590,16 @@ async function connect$1(deviceId, disconnectCallback) {
589
590
  if (toolsSvc.canCommunicateWith(deviceId)) return console.warn("Connect Warn: Already connected to device");
590
591
  store.setState(deviceId, "connecting");
591
592
  let connectedDevice;
592
- for (let attempt = 0; attempt < 3; attempt++) {
593
+ for (let attempt = 1; attempt <= 3; attempt++) {
593
594
  try {
594
595
  connectedDevice = await withTimeout(connectInner(deviceId, disconnectCallback), 2e4);
595
596
  const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
596
597
  const isConnected = await ble.isConnected(_deviceId);
597
- if (connectedDevice && isConnected) break;
598
+ if (connectedDevice || isConnected) {
599
+ break;
600
+ } else {
601
+ throw new Error("Connection incomplete");
602
+ }
598
603
  } catch (e) {
599
604
  console.warn(`${attempt} connect fail`, e);
600
605
  if (attempt === 3) {
@@ -1722,7 +1727,7 @@ const subCommandIds = {
1722
1727
  };
1723
1728
  ___default.invert(commandIds);
1724
1729
  ___default.invert(subCommandIds);
1725
- let keepAliveTimer;
1730
+ const keepAliveTimer = {};
1726
1731
  const bridgeCommands = {
1727
1732
  getCommandHeader(device) {
1728
1733
  const accessLevel = store.deviceAccessLevel[device.id];
@@ -2033,11 +2038,11 @@ const bridgeCommands = {
2033
2038
  throw new Error("Invalid command");
2034
2039
  }
2035
2040
  if (!canCommunicateWith(device.id)) throw new Error("Bridge not connected");
2036
- clearTimeout(keepAliveTimer);
2037
- keepAliveTimer = setTimeout(() => {
2041
+ clearTimeout(keepAliveTimer[device.id]);
2042
+ keepAliveTimer[device.id] = setTimeout(() => {
2038
2043
  if (store.deviceState[device.id] !== "paired" || store.devices[device.id]?.type !== "bridge") {
2039
2044
  console.warn("keep alive timer cleared");
2040
- return clearTimeout(keepAliveTimer);
2045
+ return clearTimeout(keepAliveTimer[device.id]);
2041
2046
  }
2042
2047
  this.sendKeepAliveCommand(device);
2043
2048
  }, 1e4);
@@ -2664,10 +2669,10 @@ async function assignTyres(deviceId, tcVehicle) {
2664
2669
  async function assignAxlePressureLimits(deviceId, tcVehicle, tcVehicleAxle, axleIndex, bridgeAxlesPressureData) {
2665
2670
  const axlesPressureData = bridgeAxlesPressureData ?? (await bridgeCommands.getAxlesPressure(deviceId)).data;
2666
2671
  if (axlesPressureData[axleIndex * 3]) {
2667
- tcVehicleAxle.maxTargetPressure = ___default.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2672
+ tcVehicleAxle.maxTargetPressure = ___default.floor(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2668
2673
  }
2669
2674
  if (axlesPressureData[axleIndex * 3 + 1]) {
2670
- tcVehicleAxle.minTargetPressure = ___default.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2675
+ tcVehicleAxle.minTargetPressure = ___default.ceil(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2671
2676
  }
2672
2677
  if (axlesPressureData[axleIndex * 3 + 2]) {
2673
2678
  tcVehicleAxle.targetPressure = ___default.round(
@@ -2726,12 +2731,11 @@ async function connect(deviceId, accessLevel) {
2726
2731
  await bridgeService.sendPinCommand(deviceId);
2727
2732
  store.setState(deviceId, "paired");
2728
2733
  } catch (e) {
2729
- disconnect(deviceId);
2734
+ disconnect(deviceId, "failedConnection");
2730
2735
  throw new Error(`Pairing unsuccessful ${e}`);
2731
2736
  }
2732
2737
  }
2733
2738
  async function disconnect(deviceId, reason) {
2734
- await waitUntil(() => store.deviceState[deviceId] === "paired" || store.deviceState[deviceId] === void 0);
2735
2739
  store.setState(deviceId, "disconnecting");
2736
2740
  promiseQueue.clearQueue(deviceId, "Previous pending commands aborted");
2737
2741
  await bluetooth.disconnect(deviceId);
package/dist/index.mjs CHANGED
@@ -334,8 +334,9 @@ function getDefaultTyreLabels() {
334
334
  const bridgeAdvertisingParser = {
335
335
  getDeviceInfoFromAdvertising(device) {
336
336
  const adversitingType = getAdvertisingType(device);
337
- if (adversitingType !== "connectable") return void 0;
337
+ if (adversitingType !== "connectable") return;
338
338
  const advertisingData = getAdvertisingData({ advertising: device.advertising, deviceName: device.name });
339
+ if (!advertisingData) return;
339
340
  const macArray = advertisingData?.macAddress?.map((n) => bridgeTools.decimalToHex(n).toUpperCase()).reverse() || [];
340
341
  const bridgeId = macArray.join("");
341
342
  const vin = String.fromCharCode(...advertisingData?.vinNum || []).split("\0").join("");
@@ -371,7 +372,7 @@ function getAdvertisingData({ advertising, deviceName }) {
371
372
  const adv = Array.from(uint8);
372
373
  const advertisingData = advertising.kCBAdvDataIsConnectable ? processIosAdvertising(adv, isKrone) : processAndroidAdvertising(adv, isKrone);
373
374
  if (!advertisingData || !advertisingData.macAddress.length || !advertisingData.randomAdvNumber.length || !advertisingData.vinNum.length) {
374
- throw new Error("Device not recognized");
375
+ return;
375
376
  }
376
377
  return advertisingData;
377
378
  }
@@ -582,12 +583,16 @@ async function connect$1(deviceId, disconnectCallback) {
582
583
  if (toolsSvc.canCommunicateWith(deviceId)) return console.warn("Connect Warn: Already connected to device");
583
584
  store.setState(deviceId, "connecting");
584
585
  let connectedDevice;
585
- for (let attempt = 0; attempt < 3; attempt++) {
586
+ for (let attempt = 1; attempt <= 3; attempt++) {
586
587
  try {
587
588
  connectedDevice = await withTimeout(connectInner(deviceId, disconnectCallback), 2e4);
588
589
  const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
589
590
  const isConnected = await ble.isConnected(_deviceId);
590
- if (connectedDevice && isConnected) break;
591
+ if (connectedDevice || isConnected) {
592
+ break;
593
+ } else {
594
+ throw new Error("Connection incomplete");
595
+ }
591
596
  } catch (e) {
592
597
  console.warn(`${attempt} connect fail`, e);
593
598
  if (attempt === 3) {
@@ -1715,7 +1720,7 @@ const subCommandIds = {
1715
1720
  };
1716
1721
  _.invert(commandIds);
1717
1722
  _.invert(subCommandIds);
1718
- let keepAliveTimer;
1723
+ const keepAliveTimer = {};
1719
1724
  const bridgeCommands = {
1720
1725
  getCommandHeader(device) {
1721
1726
  const accessLevel = store.deviceAccessLevel[device.id];
@@ -2026,11 +2031,11 @@ const bridgeCommands = {
2026
2031
  throw new Error("Invalid command");
2027
2032
  }
2028
2033
  if (!canCommunicateWith(device.id)) throw new Error("Bridge not connected");
2029
- clearTimeout(keepAliveTimer);
2030
- keepAliveTimer = setTimeout(() => {
2034
+ clearTimeout(keepAliveTimer[device.id]);
2035
+ keepAliveTimer[device.id] = setTimeout(() => {
2031
2036
  if (store.deviceState[device.id] !== "paired" || store.devices[device.id]?.type !== "bridge") {
2032
2037
  console.warn("keep alive timer cleared");
2033
- return clearTimeout(keepAliveTimer);
2038
+ return clearTimeout(keepAliveTimer[device.id]);
2034
2039
  }
2035
2040
  this.sendKeepAliveCommand(device);
2036
2041
  }, 1e4);
@@ -2657,10 +2662,10 @@ async function assignTyres(deviceId, tcVehicle) {
2657
2662
  async function assignAxlePressureLimits(deviceId, tcVehicle, tcVehicleAxle, axleIndex, bridgeAxlesPressureData) {
2658
2663
  const axlesPressureData = bridgeAxlesPressureData ?? (await bridgeCommands.getAxlesPressure(deviceId)).data;
2659
2664
  if (axlesPressureData[axleIndex * 3]) {
2660
- tcVehicleAxle.maxTargetPressure = _.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2665
+ tcVehicleAxle.maxTargetPressure = _.floor(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3]), 1);
2661
2666
  }
2662
2667
  if (axlesPressureData[axleIndex * 3 + 1]) {
2663
- tcVehicleAxle.minTargetPressure = _.round(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2668
+ tcVehicleAxle.minTargetPressure = _.ceil(bridgeTools.kpaByteToBar(axlesPressureData[axleIndex * 3 + 1]), 1);
2664
2669
  }
2665
2670
  if (axlesPressureData[axleIndex * 3 + 2]) {
2666
2671
  tcVehicleAxle.targetPressure = _.round(
@@ -2719,12 +2724,11 @@ async function connect(deviceId, accessLevel) {
2719
2724
  await bridgeService.sendPinCommand(deviceId);
2720
2725
  store.setState(deviceId, "paired");
2721
2726
  } catch (e) {
2722
- disconnect(deviceId);
2727
+ disconnect(deviceId, "failedConnection");
2723
2728
  throw new Error(`Pairing unsuccessful ${e}`);
2724
2729
  }
2725
2730
  }
2726
2731
  async function disconnect(deviceId, reason) {
2727
- await waitUntil(() => store.deviceState[deviceId] === "paired" || store.deviceState[deviceId] === void 0);
2728
2732
  store.setState(deviceId, "disconnecting");
2729
2733
  promiseQueue.clearQueue(deviceId, "Previous pending commands aborted");
2730
2734
  await bluetooth.disconnect(deviceId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.1.96",
3
+ "version": "0.1.97",
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",