tirecheck-device-sdk 0.2.28 → 0.2.29

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
@@ -2885,7 +2885,8 @@ const flexiGaugeTpmsCommands = {
2885
2885
  vdaSendConfiguration,
2886
2886
  vdaRequestCommandsAccess,
2887
2887
  vdaRequestWriteAccess,
2888
- processMessage
2888
+ processMessage,
2889
+ getFirmwareVersion: getFirmwareVersion$1
2889
2890
  };
2890
2891
  async function startTpmsScan(deviceId) {
2891
2892
  if (!canCommunicateWith(deviceId)) throw new Error("Flexi Gauge not connected");
@@ -2906,24 +2907,28 @@ async function getBattery(deviceId) {
2906
2907
  const battery = Array.from(new Uint8Array(batteryValue))[0];
2907
2908
  return battery;
2908
2909
  }
2910
+ async function getFirmwareVersion$1(deviceId) {
2911
+ const msg = "*FWVER?";
2912
+ return sendCommand(deviceId, msg, "FWV");
2913
+ }
2909
2914
  async function vdaRequestSensor(deviceId) {
2910
2915
  const scanMsg = "*VDA_LF_SEND SID=A0 LID=1A";
2911
- return await sendCommand(deviceId, scanMsg);
2916
+ return sendCommand(deviceId, scanMsg);
2912
2917
  }
2913
2918
  async function vdaRequestSeed(deviceId, sensorId) {
2914
2919
  const sensorIdReversed = getReversedSensorId(sensorId);
2915
2920
  const scanMsg = `*VDA_LF_SEND SID=A0 LID=AA PAR=04 DATA=${sensorIdReversed}CE9A5713`;
2916
- return await sendCommand(deviceId, scanMsg);
2921
+ return sendCommand(deviceId, scanMsg);
2917
2922
  }
2918
2923
  async function vdaRequestCommandsAccess(deviceId, sensorId, signature) {
2919
2924
  const sensorIdReversed = getReversedSensorId(sensorId);
2920
2925
  const scanMsg = `*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=${sensorIdReversed}${signature}`;
2921
- return await sendCommand(deviceId, scanMsg);
2926
+ return sendCommand(deviceId, scanMsg);
2922
2927
  }
2923
2928
  async function vdaRequestWriteAccess(deviceId, sensorId, signature) {
2924
2929
  const sensorIdReversed = getReversedSensorId(sensorId);
2925
2930
  const scanMsg = `*VDA_LF_SEND SID=A0 LID=AA PAR=02 DATA=${sensorIdReversed}${signature}`;
2926
- return await sendCommand(deviceId, scanMsg);
2931
+ return sendCommand(deviceId, scanMsg);
2927
2932
  }
2928
2933
  async function vdaSendWriteModePin(deviceId) {
2929
2934
  const scanMsg = stringToArrayBuffer("*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6\r\n");
@@ -2936,21 +2941,21 @@ async function vdaSendWriteModePin(deviceId) {
2936
2941
  }
2937
2942
  async function vdaReadConfiguration(deviceId) {
2938
2943
  const scanMsg = "*VDA_LF_SEND SID=A0 LID=DA PAR=17";
2939
- return await sendCommand(deviceId, scanMsg);
2944
+ return sendCommand(deviceId, scanMsg);
2940
2945
  }
2941
2946
  async function vdaSendConfiguration(deviceId, configuration) {
2942
2947
  if (configuration.length !== 60) throw new Error("Invalid sensor configuration");
2943
2948
  const crc = flexiGaugeTpmsSecurity.getCrc(configuration);
2944
2949
  const scanMsg = `*VDA_LF_SEND SID=A0 LID=EA PAR=17 DATA=${configuration}${crc}`;
2945
- return await sendCommand(deviceId, scanMsg);
2950
+ return sendCommand(deviceId, scanMsg);
2946
2951
  }
2947
- async function sendCommand(deviceId, command) {
2952
+ async function sendCommand(deviceId, command, identifier = "VDA") {
2948
2953
  const message = `${command}\r
2949
2954
  `;
2950
2955
  const decimalArray = stringToDecimalArray(message);
2951
2956
  let result;
2952
2957
  try {
2953
- result = await promiseQueue.enqueue(deviceId, flexiGaugeTpmsMeta.communication, decimalArray, "VDA");
2958
+ result = await promiseQueue.enqueue(deviceId, flexiGaugeTpmsMeta.communication, decimalArray, identifier);
2954
2959
  } catch (error) {
2955
2960
  flexiGaugeTpms.disconnect(deviceId, "lostConnection");
2956
2961
  throw error;
@@ -3021,7 +3026,8 @@ const flexiGaugeTpmsService = {
3021
3026
  }
3022
3027
  flexiGaugeTpmsCommands.processMessage(deviceId, message);
3023
3028
  },
3024
- programSensor
3029
+ programSensor,
3030
+ getFirmwareVersion
3025
3031
  };
3026
3032
  function processTreadDepth(deviceId, value) {
3027
3033
  const treadDepth = value.match(/\d+/)?.[0];
@@ -3061,6 +3067,8 @@ function processTpms(deviceId, value) {
3061
3067
  }
3062
3068
  }
3063
3069
  async function programSensor(deviceId, oldSensorId, newSensorId) {
3070
+ const fw = await getFirmwareVersion(deviceId);
3071
+ if (fw < "1.4.4") throw new Error("Programming sensors is not supported on this firmware version");
3064
3072
  await findSensor(deviceId, oldSensorId);
3065
3073
  const seed = await getSeed(deviceId, oldSensorId);
3066
3074
  const commandsSignature = await flexiGaugeTpmsSecurity.getCommandsSignature(seed);
@@ -3073,31 +3081,47 @@ async function programSensor(deviceId, oldSensorId, newSensorId) {
3073
3081
  await findSensor(deviceId, newSensorId);
3074
3082
  }
3075
3083
  async function getSeed(deviceId, sensorId) {
3076
- const response = await vdaRepeat(flexiGaugeTpmsCommands.vdaRequestSeed(deviceId, sensorId));
3077
- return response[3];
3084
+ try {
3085
+ const response = await vdaRepeat(() => flexiGaugeTpmsCommands.vdaRequestSeed(deviceId, sensorId));
3086
+ return response[3];
3087
+ } catch {
3088
+ throw new Error("Failed to get signature seed");
3089
+ }
3078
3090
  }
3079
3091
  async function findSensor(deviceId, sensorId) {
3080
3092
  let seen = 0;
3081
- for (let i = 0; i < 13; i++) {
3082
- const response = await vdaRepeat(flexiGaugeTpmsCommands.vdaRequestSensor(deviceId));
3083
- if (response[2] === sensorId) seen++;
3084
- if (seen === 3) return;
3093
+ for (let i = 0; i < 6; i++) {
3094
+ try {
3095
+ const response = await vdaRepeat(() => flexiGaugeTpmsCommands.vdaRequestSensor(deviceId));
3096
+ if (response[2] === sensorId) seen++;
3097
+ if (seen === 3) return;
3098
+ } catch {
3099
+ }
3085
3100
  }
3086
3101
  throw new Error(`Sensor ${sensorId} not found`);
3087
3102
  }
3088
3103
  async function getSensorConfiguration(deviceId) {
3089
- const response = await vdaRepeat(flexiGaugeTpmsCommands.vdaReadConfiguration(deviceId));
3090
- return response[3].slice(2, -4);
3104
+ try {
3105
+ const response = await vdaRepeat(() => flexiGaugeTpmsCommands.vdaReadConfiguration(deviceId));
3106
+ return response[3].slice(2, -4);
3107
+ } catch {
3108
+ throw new Error("Failed to get sensor configuration");
3109
+ }
3091
3110
  }
3092
3111
  async function vdaRepeat(fn) {
3093
3112
  for (let i = 0; i < 5; i++) {
3094
- const response = await fn;
3113
+ const response = await fn();
3095
3114
  const groupedValue = response.split(" ");
3096
3115
  if (groupedValue[1].includes("TIMEOUT")) continue;
3097
3116
  if (response) return groupedValue;
3098
3117
  }
3099
3118
  throw new Error("VDA Timeout");
3100
3119
  }
3120
+ async function getFirmwareVersion(deviceId) {
3121
+ const response = await flexiGaugeTpmsCommands.getFirmwareVersion(deviceId);
3122
+ const groupedValue = response.split(" ");
3123
+ return groupedValue[1];
3124
+ }
3101
3125
 
3102
3126
  const flexiGaugeTpms = {
3103
3127
  async connect(deviceId) {
@@ -3121,6 +3145,7 @@ const flexiGaugeTpms = {
3121
3145
  onButtonPress: flexiGaugeTpmsService.onButton,
3122
3146
  onTpms: flexiGaugeTpmsService.onTpms,
3123
3147
  getBattery: flexiGaugeTpmsService.getBattery,
3148
+ getFirmwareVersion: flexiGaugeTpmsService.getFirmwareVersion,
3124
3149
  startTpmsScan: flexiGaugeTpmsService.startTpmsScan,
3125
3150
  programSensor: flexiGaugeTpmsService.programSensor
3126
3151
  };
@@ -3796,6 +3821,10 @@ const flexiGaugeTpmsSimulator = {
3796
3821
  await toolsSvc.delay(200);
3797
3822
  return fg.simulatorData.battery;
3798
3823
  },
3824
+ async getFirmwareVersion(deviceId) {
3825
+ await toolsSvc.delay(100);
3826
+ return "9.9.9";
3827
+ },
3799
3828
  programSensor(deviceId, oldSensorId, newSensorId) {
3800
3829
  return new Promise((resolve) => resolve());
3801
3830
  },
package/dist/index.d.cts CHANGED
@@ -927,6 +927,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
927
927
  onButtonPress: (callback: (deviceId: string, value: string) => void) => void;
928
928
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
929
929
  getBattery: (deviceId: string) => Promise<number>;
930
+ getFirmwareVersion: (deviceId: string) => Promise<string>;
930
931
  startTpmsScan: (deviceId: string) => void;
931
932
  programSensor: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
932
933
  };
package/dist/index.d.mts CHANGED
@@ -927,6 +927,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
927
927
  onButtonPress: (callback: (deviceId: string, value: string) => void) => void;
928
928
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
929
929
  getBattery: (deviceId: string) => Promise<number>;
930
+ getFirmwareVersion: (deviceId: string) => Promise<string>;
930
931
  startTpmsScan: (deviceId: string) => void;
931
932
  programSensor: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
932
933
  };
package/dist/index.d.ts CHANGED
@@ -927,6 +927,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
927
927
  onButtonPress: (callback: (deviceId: string, value: string) => void) => void;
928
928
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
929
929
  getBattery: (deviceId: string) => Promise<number>;
930
+ getFirmwareVersion: (deviceId: string) => Promise<string>;
930
931
  startTpmsScan: (deviceId: string) => void;
931
932
  programSensor: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
932
933
  };
package/dist/index.mjs CHANGED
@@ -2878,7 +2878,8 @@ const flexiGaugeTpmsCommands = {
2878
2878
  vdaSendConfiguration,
2879
2879
  vdaRequestCommandsAccess,
2880
2880
  vdaRequestWriteAccess,
2881
- processMessage
2881
+ processMessage,
2882
+ getFirmwareVersion: getFirmwareVersion$1
2882
2883
  };
2883
2884
  async function startTpmsScan(deviceId) {
2884
2885
  if (!canCommunicateWith(deviceId)) throw new Error("Flexi Gauge not connected");
@@ -2899,24 +2900,28 @@ async function getBattery(deviceId) {
2899
2900
  const battery = Array.from(new Uint8Array(batteryValue))[0];
2900
2901
  return battery;
2901
2902
  }
2903
+ async function getFirmwareVersion$1(deviceId) {
2904
+ const msg = "*FWVER?";
2905
+ return sendCommand(deviceId, msg, "FWV");
2906
+ }
2902
2907
  async function vdaRequestSensor(deviceId) {
2903
2908
  const scanMsg = "*VDA_LF_SEND SID=A0 LID=1A";
2904
- return await sendCommand(deviceId, scanMsg);
2909
+ return sendCommand(deviceId, scanMsg);
2905
2910
  }
2906
2911
  async function vdaRequestSeed(deviceId, sensorId) {
2907
2912
  const sensorIdReversed = getReversedSensorId(sensorId);
2908
2913
  const scanMsg = `*VDA_LF_SEND SID=A0 LID=AA PAR=04 DATA=${sensorIdReversed}CE9A5713`;
2909
- return await sendCommand(deviceId, scanMsg);
2914
+ return sendCommand(deviceId, scanMsg);
2910
2915
  }
2911
2916
  async function vdaRequestCommandsAccess(deviceId, sensorId, signature) {
2912
2917
  const sensorIdReversed = getReversedSensorId(sensorId);
2913
2918
  const scanMsg = `*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=${sensorIdReversed}${signature}`;
2914
- return await sendCommand(deviceId, scanMsg);
2919
+ return sendCommand(deviceId, scanMsg);
2915
2920
  }
2916
2921
  async function vdaRequestWriteAccess(deviceId, sensorId, signature) {
2917
2922
  const sensorIdReversed = getReversedSensorId(sensorId);
2918
2923
  const scanMsg = `*VDA_LF_SEND SID=A0 LID=AA PAR=02 DATA=${sensorIdReversed}${signature}`;
2919
- return await sendCommand(deviceId, scanMsg);
2924
+ return sendCommand(deviceId, scanMsg);
2920
2925
  }
2921
2926
  async function vdaSendWriteModePin(deviceId) {
2922
2927
  const scanMsg = stringToArrayBuffer("*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6\r\n");
@@ -2929,21 +2934,21 @@ async function vdaSendWriteModePin(deviceId) {
2929
2934
  }
2930
2935
  async function vdaReadConfiguration(deviceId) {
2931
2936
  const scanMsg = "*VDA_LF_SEND SID=A0 LID=DA PAR=17";
2932
- return await sendCommand(deviceId, scanMsg);
2937
+ return sendCommand(deviceId, scanMsg);
2933
2938
  }
2934
2939
  async function vdaSendConfiguration(deviceId, configuration) {
2935
2940
  if (configuration.length !== 60) throw new Error("Invalid sensor configuration");
2936
2941
  const crc = flexiGaugeTpmsSecurity.getCrc(configuration);
2937
2942
  const scanMsg = `*VDA_LF_SEND SID=A0 LID=EA PAR=17 DATA=${configuration}${crc}`;
2938
- return await sendCommand(deviceId, scanMsg);
2943
+ return sendCommand(deviceId, scanMsg);
2939
2944
  }
2940
- async function sendCommand(deviceId, command) {
2945
+ async function sendCommand(deviceId, command, identifier = "VDA") {
2941
2946
  const message = `${command}\r
2942
2947
  `;
2943
2948
  const decimalArray = stringToDecimalArray(message);
2944
2949
  let result;
2945
2950
  try {
2946
- result = await promiseQueue.enqueue(deviceId, flexiGaugeTpmsMeta.communication, decimalArray, "VDA");
2951
+ result = await promiseQueue.enqueue(deviceId, flexiGaugeTpmsMeta.communication, decimalArray, identifier);
2947
2952
  } catch (error) {
2948
2953
  flexiGaugeTpms.disconnect(deviceId, "lostConnection");
2949
2954
  throw error;
@@ -3014,7 +3019,8 @@ const flexiGaugeTpmsService = {
3014
3019
  }
3015
3020
  flexiGaugeTpmsCommands.processMessage(deviceId, message);
3016
3021
  },
3017
- programSensor
3022
+ programSensor,
3023
+ getFirmwareVersion
3018
3024
  };
3019
3025
  function processTreadDepth(deviceId, value) {
3020
3026
  const treadDepth = value.match(/\d+/)?.[0];
@@ -3054,6 +3060,8 @@ function processTpms(deviceId, value) {
3054
3060
  }
3055
3061
  }
3056
3062
  async function programSensor(deviceId, oldSensorId, newSensorId) {
3063
+ const fw = await getFirmwareVersion(deviceId);
3064
+ if (fw < "1.4.4") throw new Error("Programming sensors is not supported on this firmware version");
3057
3065
  await findSensor(deviceId, oldSensorId);
3058
3066
  const seed = await getSeed(deviceId, oldSensorId);
3059
3067
  const commandsSignature = await flexiGaugeTpmsSecurity.getCommandsSignature(seed);
@@ -3066,31 +3074,47 @@ async function programSensor(deviceId, oldSensorId, newSensorId) {
3066
3074
  await findSensor(deviceId, newSensorId);
3067
3075
  }
3068
3076
  async function getSeed(deviceId, sensorId) {
3069
- const response = await vdaRepeat(flexiGaugeTpmsCommands.vdaRequestSeed(deviceId, sensorId));
3070
- return response[3];
3077
+ try {
3078
+ const response = await vdaRepeat(() => flexiGaugeTpmsCommands.vdaRequestSeed(deviceId, sensorId));
3079
+ return response[3];
3080
+ } catch {
3081
+ throw new Error("Failed to get signature seed");
3082
+ }
3071
3083
  }
3072
3084
  async function findSensor(deviceId, sensorId) {
3073
3085
  let seen = 0;
3074
- for (let i = 0; i < 13; i++) {
3075
- const response = await vdaRepeat(flexiGaugeTpmsCommands.vdaRequestSensor(deviceId));
3076
- if (response[2] === sensorId) seen++;
3077
- if (seen === 3) return;
3086
+ for (let i = 0; i < 6; i++) {
3087
+ try {
3088
+ const response = await vdaRepeat(() => flexiGaugeTpmsCommands.vdaRequestSensor(deviceId));
3089
+ if (response[2] === sensorId) seen++;
3090
+ if (seen === 3) return;
3091
+ } catch {
3092
+ }
3078
3093
  }
3079
3094
  throw new Error(`Sensor ${sensorId} not found`);
3080
3095
  }
3081
3096
  async function getSensorConfiguration(deviceId) {
3082
- const response = await vdaRepeat(flexiGaugeTpmsCommands.vdaReadConfiguration(deviceId));
3083
- return response[3].slice(2, -4);
3097
+ try {
3098
+ const response = await vdaRepeat(() => flexiGaugeTpmsCommands.vdaReadConfiguration(deviceId));
3099
+ return response[3].slice(2, -4);
3100
+ } catch {
3101
+ throw new Error("Failed to get sensor configuration");
3102
+ }
3084
3103
  }
3085
3104
  async function vdaRepeat(fn) {
3086
3105
  for (let i = 0; i < 5; i++) {
3087
- const response = await fn;
3106
+ const response = await fn();
3088
3107
  const groupedValue = response.split(" ");
3089
3108
  if (groupedValue[1].includes("TIMEOUT")) continue;
3090
3109
  if (response) return groupedValue;
3091
3110
  }
3092
3111
  throw new Error("VDA Timeout");
3093
3112
  }
3113
+ async function getFirmwareVersion(deviceId) {
3114
+ const response = await flexiGaugeTpmsCommands.getFirmwareVersion(deviceId);
3115
+ const groupedValue = response.split(" ");
3116
+ return groupedValue[1];
3117
+ }
3094
3118
 
3095
3119
  const flexiGaugeTpms = {
3096
3120
  async connect(deviceId) {
@@ -3114,6 +3138,7 @@ const flexiGaugeTpms = {
3114
3138
  onButtonPress: flexiGaugeTpmsService.onButton,
3115
3139
  onTpms: flexiGaugeTpmsService.onTpms,
3116
3140
  getBattery: flexiGaugeTpmsService.getBattery,
3141
+ getFirmwareVersion: flexiGaugeTpmsService.getFirmwareVersion,
3117
3142
  startTpmsScan: flexiGaugeTpmsService.startTpmsScan,
3118
3143
  programSensor: flexiGaugeTpmsService.programSensor
3119
3144
  };
@@ -3789,6 +3814,10 @@ const flexiGaugeTpmsSimulator = {
3789
3814
  await toolsSvc.delay(200);
3790
3815
  return fg.simulatorData.battery;
3791
3816
  },
3817
+ async getFirmwareVersion(deviceId) {
3818
+ await toolsSvc.delay(100);
3819
+ return "9.9.9";
3820
+ },
3792
3821
  programSensor(deviceId, oldSensorId, newSensorId) {
3793
3822
  return new Promise((resolve) => resolve());
3794
3823
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
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",