tirecheck-device-sdk 0.2.55 → 0.2.57

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
@@ -155,10 +155,8 @@ const bridgeTools = {
155
155
  console.warn("missing bytes filled with empty values");
156
156
  numArray = numArray.concat(Array.from({ length: sumWithInitial - numArray.length }, () => 0));
157
157
  }
158
- if (numArray.length !== sumWithInitial) {
159
- throw new Error(
160
- `Cannot convert bytes to object: bytes received ${numArray.length}, expected ${sumWithInitial}, fw version ${fwVersion}`
161
- );
158
+ if (numArray.length > sumWithInitial) {
159
+ console.warn("extra bytes will be ignored");
162
160
  }
163
161
  const result = {};
164
162
  for (const key of keys) {
@@ -670,7 +668,7 @@ const bluetooth = {
670
668
  },
671
669
  connect: connect$1,
672
670
  disconnect: disconnect$1,
673
- write,
671
+ write: write$1,
674
672
  read
675
673
  };
676
674
  async function scanDevices(services = [], duration) {
@@ -746,7 +744,7 @@ async function disconnect$1(deviceId) {
746
744
  store.setState(deviceId, void 0, "failedDisconnection");
747
745
  throw new Error("Disconnect unsuccessful");
748
746
  }
749
- async function write(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
747
+ async function write$1(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
750
748
  if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Write Error: Not connected to device");
751
749
  try {
752
750
  const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
@@ -3059,15 +3057,12 @@ async function setTpmsConfig(deviceId, config) {
3059
3057
  const msg = `*TPMS CONFIG ${config}`;
3060
3058
  return sendCommand(deviceId, msg);
3061
3059
  }
3062
- async function startTpmsScan(deviceId) {
3060
+ async function startTpmsScan(deviceId, filterBySensorId, time = 10) {
3063
3061
  if (!canCommunicateWith(deviceId)) throw new Error("Flexi Gauge not connected");
3064
- const scanMsg = stringToArrayBuffer("*TPMS ON TIME=10\r\n");
3065
- return bluetooth.write(
3066
- deviceId,
3067
- flexiGaugeTpmsMeta.communication.serviceId,
3068
- flexiGaugeTpmsMeta.communication.characteristicId,
3069
- scanMsg
3070
- );
3062
+ const massageParts = ["*TPMS ON"];
3063
+ if (filterBySensorId) massageParts.push(`FILTER=${filterBySensorId}`);
3064
+ if (time) massageParts.push(`TIME=${time}`);
3065
+ return write(deviceId, massageParts.join(" "));
3071
3066
  }
3072
3067
  async function getBattery(deviceId) {
3073
3068
  const batteryValue = await bluetooth.read(
@@ -3102,13 +3097,8 @@ async function vdaRequestWriteAccess(deviceId, sensorId, signature) {
3102
3097
  return sendCommand(deviceId, scanMsg);
3103
3098
  }
3104
3099
  async function vdaSendWriteModePin(deviceId) {
3105
- const scanMsg = stringToArrayBuffer("*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6\r\n");
3106
- await bluetooth.write(
3107
- deviceId,
3108
- flexiGaugeTpmsMeta.communication.serviceId,
3109
- flexiGaugeTpmsMeta.communication.characteristicId,
3110
- scanMsg
3111
- );
3100
+ const scanMsg = "*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6";
3101
+ return write(deviceId, scanMsg);
3112
3102
  }
3113
3103
  async function vdaReadConfiguration(deviceId) {
3114
3104
  const scanMsg = "*VDA_LF_SEND SID=A0 LID=DA PAR=17";
@@ -3134,6 +3124,23 @@ async function sendCommand(deviceId, command) {
3134
3124
  }
3135
3125
  return String.fromCharCode(...result);
3136
3126
  }
3127
+ async function write(deviceId, message, mtu = 20) {
3128
+ const payload = stringToDecimalArray(`${message}\r
3129
+ `);
3130
+ const chunks = [];
3131
+ for (let i = 0; i < payload.length; i += mtu) {
3132
+ chunks.push(payload.slice(i, i + mtu));
3133
+ }
3134
+ for (const chunk of chunks) {
3135
+ const convertedChunk = new Uint8Array(chunk);
3136
+ await bluetooth.write(
3137
+ deviceId,
3138
+ flexiGaugeTpmsMeta.communication.serviceId,
3139
+ flexiGaugeTpmsMeta.communication.characteristicId,
3140
+ convertedChunk.buffer
3141
+ );
3142
+ }
3143
+ }
3137
3144
  function processMessage(deviceId, payload) {
3138
3145
  promiseQueue.processMessage(deviceId, payload, getIdentifier$1, isComplete$1, isError$1);
3139
3146
  }
@@ -3322,8 +3329,8 @@ const capabilities$1 = [
3322
3329
  }
3323
3330
  ];
3324
3331
  const flexiGaugeTpmsService = {
3325
- startTpmsScan(deviceId) {
3326
- flexiGaugeTpmsCommands.startTpmsScan(deviceId);
3332
+ startTpmsScan(deviceId, filterBySensorId, time = 10) {
3333
+ flexiGaugeTpmsCommands.startTpmsScan(deviceId, filterBySensorId, time);
3327
3334
  },
3328
3335
  getBattery(deviceId) {
3329
3336
  return flexiGaugeTpmsCommands.getBattery(deviceId);
package/dist/index.d.cts CHANGED
@@ -989,7 +989,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
989
989
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
990
990
  getBattery: (deviceId: string) => Promise<number>;
991
991
  getFirmwareVersion: (deviceId: string) => Promise<string>;
992
- startTpmsScan: (deviceId: string) => void;
992
+ startTpmsScan: (deviceId: string, filterBySensorId?: string, time?: number) => void;
993
993
  setSensorDisplayId: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
994
994
  resetSensorDisplayId: (deviceId: string, sensorId: string) => Promise<void>;
995
995
  getConfig: (deviceId: string) => Promise<FgConfig>;
package/dist/index.d.mts CHANGED
@@ -989,7 +989,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
989
989
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
990
990
  getBattery: (deviceId: string) => Promise<number>;
991
991
  getFirmwareVersion: (deviceId: string) => Promise<string>;
992
- startTpmsScan: (deviceId: string) => void;
992
+ startTpmsScan: (deviceId: string, filterBySensorId?: string, time?: number) => void;
993
993
  setSensorDisplayId: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
994
994
  resetSensorDisplayId: (deviceId: string, sensorId: string) => Promise<void>;
995
995
  getConfig: (deviceId: string) => Promise<FgConfig>;
package/dist/index.d.ts CHANGED
@@ -989,7 +989,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
989
989
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
990
990
  getBattery: (deviceId: string) => Promise<number>;
991
991
  getFirmwareVersion: (deviceId: string) => Promise<string>;
992
- startTpmsScan: (deviceId: string) => void;
992
+ startTpmsScan: (deviceId: string, filterBySensorId?: string, time?: number) => void;
993
993
  setSensorDisplayId: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
994
994
  resetSensorDisplayId: (deviceId: string, sensorId: string) => Promise<void>;
995
995
  getConfig: (deviceId: string) => Promise<FgConfig>;
package/dist/index.mjs CHANGED
@@ -148,10 +148,8 @@ const bridgeTools = {
148
148
  console.warn("missing bytes filled with empty values");
149
149
  numArray = numArray.concat(Array.from({ length: sumWithInitial - numArray.length }, () => 0));
150
150
  }
151
- if (numArray.length !== sumWithInitial) {
152
- throw new Error(
153
- `Cannot convert bytes to object: bytes received ${numArray.length}, expected ${sumWithInitial}, fw version ${fwVersion}`
154
- );
151
+ if (numArray.length > sumWithInitial) {
152
+ console.warn("extra bytes will be ignored");
155
153
  }
156
154
  const result = {};
157
155
  for (const key of keys) {
@@ -663,7 +661,7 @@ const bluetooth = {
663
661
  },
664
662
  connect: connect$1,
665
663
  disconnect: disconnect$1,
666
- write,
664
+ write: write$1,
667
665
  read
668
666
  };
669
667
  async function scanDevices(services = [], duration) {
@@ -739,7 +737,7 @@ async function disconnect$1(deviceId) {
739
737
  store.setState(deviceId, void 0, "failedDisconnection");
740
738
  throw new Error("Disconnect unsuccessful");
741
739
  }
742
- async function write(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
740
+ async function write$1(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
743
741
  if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Write Error: Not connected to device");
744
742
  try {
745
743
  const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
@@ -3052,15 +3050,12 @@ async function setTpmsConfig(deviceId, config) {
3052
3050
  const msg = `*TPMS CONFIG ${config}`;
3053
3051
  return sendCommand(deviceId, msg);
3054
3052
  }
3055
- async function startTpmsScan(deviceId) {
3053
+ async function startTpmsScan(deviceId, filterBySensorId, time = 10) {
3056
3054
  if (!canCommunicateWith(deviceId)) throw new Error("Flexi Gauge not connected");
3057
- const scanMsg = stringToArrayBuffer("*TPMS ON TIME=10\r\n");
3058
- return bluetooth.write(
3059
- deviceId,
3060
- flexiGaugeTpmsMeta.communication.serviceId,
3061
- flexiGaugeTpmsMeta.communication.characteristicId,
3062
- scanMsg
3063
- );
3055
+ const massageParts = ["*TPMS ON"];
3056
+ if (filterBySensorId) massageParts.push(`FILTER=${filterBySensorId}`);
3057
+ if (time) massageParts.push(`TIME=${time}`);
3058
+ return write(deviceId, massageParts.join(" "));
3064
3059
  }
3065
3060
  async function getBattery(deviceId) {
3066
3061
  const batteryValue = await bluetooth.read(
@@ -3095,13 +3090,8 @@ async function vdaRequestWriteAccess(deviceId, sensorId, signature) {
3095
3090
  return sendCommand(deviceId, scanMsg);
3096
3091
  }
3097
3092
  async function vdaSendWriteModePin(deviceId) {
3098
- const scanMsg = stringToArrayBuffer("*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6\r\n");
3099
- await bluetooth.write(
3100
- deviceId,
3101
- flexiGaugeTpmsMeta.communication.serviceId,
3102
- flexiGaugeTpmsMeta.communication.characteristicId,
3103
- scanMsg
3104
- );
3093
+ const scanMsg = "*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6";
3094
+ return write(deviceId, scanMsg);
3105
3095
  }
3106
3096
  async function vdaReadConfiguration(deviceId) {
3107
3097
  const scanMsg = "*VDA_LF_SEND SID=A0 LID=DA PAR=17";
@@ -3127,6 +3117,23 @@ async function sendCommand(deviceId, command) {
3127
3117
  }
3128
3118
  return String.fromCharCode(...result);
3129
3119
  }
3120
+ async function write(deviceId, message, mtu = 20) {
3121
+ const payload = stringToDecimalArray(`${message}\r
3122
+ `);
3123
+ const chunks = [];
3124
+ for (let i = 0; i < payload.length; i += mtu) {
3125
+ chunks.push(payload.slice(i, i + mtu));
3126
+ }
3127
+ for (const chunk of chunks) {
3128
+ const convertedChunk = new Uint8Array(chunk);
3129
+ await bluetooth.write(
3130
+ deviceId,
3131
+ flexiGaugeTpmsMeta.communication.serviceId,
3132
+ flexiGaugeTpmsMeta.communication.characteristicId,
3133
+ convertedChunk.buffer
3134
+ );
3135
+ }
3136
+ }
3130
3137
  function processMessage(deviceId, payload) {
3131
3138
  promiseQueue.processMessage(deviceId, payload, getIdentifier$1, isComplete$1, isError$1);
3132
3139
  }
@@ -3315,8 +3322,8 @@ const capabilities$1 = [
3315
3322
  }
3316
3323
  ];
3317
3324
  const flexiGaugeTpmsService = {
3318
- startTpmsScan(deviceId) {
3319
- flexiGaugeTpmsCommands.startTpmsScan(deviceId);
3325
+ startTpmsScan(deviceId, filterBySensorId, time = 10) {
3326
+ flexiGaugeTpmsCommands.startTpmsScan(deviceId, filterBySensorId, time);
3320
3327
  },
3321
3328
  getBattery(deviceId) {
3322
3329
  return flexiGaugeTpmsCommands.getBattery(deviceId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.2.55",
3
+ "version": "0.2.57",
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",