tirecheck-device-sdk 0.2.54 → 0.2.56

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
@@ -533,9 +533,13 @@ const deviceMeta = {
533
533
  bridgeOta: {
534
534
  nameRegex: /(CAN BLE BRDG OTA.*|0303.{2}_B|030632_B)/,
535
535
  mtu: 180,
536
- characteristic: {
537
- serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
538
- characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d7"
536
+ control: {
537
+ serviceId: "1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0",
538
+ characteristicId: "f7bf3564-fb6d-4e53-88a4-5e37e0326063"
539
+ },
540
+ data: {
541
+ serviceId: "1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0",
542
+ characteristicId: "984227f3-34fc-4045-a5d0-2c581f81a153"
539
543
  },
540
544
  getDeviceInfoFromAdvertising: bridgeOtaAdvertisingParser.getDeviceInfoFromAdvertising
541
545
  },
@@ -666,7 +670,7 @@ const bluetooth = {
666
670
  },
667
671
  connect: connect$1,
668
672
  disconnect: disconnect$1,
669
- write,
673
+ write: write$1,
670
674
  read
671
675
  };
672
676
  async function scanDevices(services = [], duration) {
@@ -742,7 +746,7 @@ async function disconnect$1(deviceId) {
742
746
  store.setState(deviceId, void 0, "failedDisconnection");
743
747
  throw new Error("Disconnect unsuccessful");
744
748
  }
745
- async function write(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
749
+ async function write$1(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
746
750
  if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Write Error: Not connected to device");
747
751
  try {
748
752
  const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
@@ -809,18 +813,51 @@ function getDeviceNameFromAdvertising(advertising) {
809
813
  return deviceName;
810
814
  }
811
815
 
812
- const otaServiceUuid = "1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0";
813
- const otaControlCharacteristicUuid = "f7bf3564-fb6d-4e53-88a4-5e37e0326063";
814
- const otaDataCharacteristicUuid = "984227f3-34fc-4045-a5d0-2c581f81a153";
816
+ const callbacks = {};
817
+ const simulatorSvc = {
818
+ registerEvent(eventName, callback) {
819
+ callbacks[eventName] = callback;
820
+ },
821
+ triggerEvent(eventName, deviceId, payload) {
822
+ if (payload && store.simulatedDevices[deviceId]) {
823
+ const simulatedDevice = store.simulatedDevices[deviceId];
824
+ payload = simulatedDevice.simulatorData?.events?.[eventName];
825
+ if (!payload) throw new Error(`Event not found`);
826
+ }
827
+ const callback = callbacks[eventName];
828
+ if (!callback) {
829
+ console.warn(`Event ${eventName} not registered`);
830
+ } else {
831
+ callback(deviceId, payload);
832
+ }
833
+ },
834
+ merge(deviceTemplate, initialData) {
835
+ return ___default.mergeWith({}, deviceTemplate, initialData, (a, b) => ___default.isArray(b) ? b : void 0);
836
+ }
837
+ };
838
+
839
+ const bridgeOtaMeta = deviceMeta.bridgeOta;
815
840
  const bridgeOtaCommands = {
816
841
  async beginOta(deviceId) {
817
- await bluetooth.write(deviceId, otaServiceUuid, otaControlCharacteristicUuid, new Uint8Array([0]).buffer, true);
842
+ await bluetooth.write(
843
+ deviceId,
844
+ bridgeOtaMeta.control.serviceId,
845
+ bridgeOtaMeta.control.characteristicId,
846
+ new Uint8Array([0]).buffer,
847
+ true
848
+ );
818
849
  },
819
850
  async uploadOtaChunk(deviceId, data) {
820
- await bluetooth.write(deviceId, otaServiceUuid, otaDataCharacteristicUuid, data, true);
851
+ await bluetooth.write(deviceId, bridgeOtaMeta.data.serviceId, bridgeOtaMeta.data.characteristicId, data, true);
821
852
  },
822
853
  async endOta(deviceId) {
823
- await bluetooth.write(deviceId, otaServiceUuid, otaControlCharacteristicUuid, new Uint8Array([3]).buffer, true);
854
+ await bluetooth.write(
855
+ deviceId,
856
+ bridgeOtaMeta.control.serviceId,
857
+ bridgeOtaMeta.control.characteristicId,
858
+ new Uint8Array([3]).buffer,
859
+ true
860
+ );
824
861
  }
825
862
  };
826
863
 
@@ -829,17 +866,39 @@ const bridgeOtaService = {
829
866
  await delay(2e3);
830
867
  progressCallback("Connecting to the bridge...", 0.1);
831
868
  await bridgeOta.connect(deviceId);
832
- progressCallback("Uploading bootloader...", 0.12);
833
- await bridgeOtaCommands.beginOta(deviceId);
834
- await uploadOta(deviceId, bootloader, (str, percents) => progressCallback(str, 0.12 + percents * 0.2));
835
- await bridgeOtaCommands.endOta(deviceId);
836
- progressCallback("Uploading application...", 0.32);
837
- await bridgeOtaCommands.beginOta(deviceId);
838
- await uploadOta(deviceId, firmware, (str, percents) => progressCallback(str, 0.32 + percents * 0.5));
839
- await bridgeOtaCommands.endOta(deviceId);
840
- progressCallback("Upload completed, disconnecting...", 0.81);
841
- await bridgeOta.disconnect(deviceId);
842
- progressCallback("Disconnected...", 1);
869
+ try {
870
+ progressCallback("Uploading bootloader...", 0.12);
871
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "bootloaderUploadBegin");
872
+ await bridgeOtaCommands.beginOta(deviceId);
873
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "bootloaderUpload");
874
+ await uploadOta(deviceId, bootloader, (str, percents) => progressCallback(str, 0.12 + percents * 0.2));
875
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "bootloaderUploadEnd");
876
+ await bridgeOtaCommands.endOta(deviceId);
877
+ progressCallback("Uploading application...", 0.32);
878
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "applicationUploadBegin");
879
+ await bridgeOtaCommands.beginOta(deviceId);
880
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "applicationUpload");
881
+ await uploadOta(deviceId, firmware, (str, percents) => progressCallback(str, 0.32 + percents * 0.5));
882
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "applicationUploadEnd");
883
+ await bridgeOtaCommands.endOta(deviceId);
884
+ simulatorSvc.triggerEvent("bridgeOta:success", deviceId);
885
+ progressCallback("Upload completed, disconnecting...", 0.81);
886
+ } catch (error) {
887
+ simulatorSvc.triggerEvent("bridgeOta:error", deviceId);
888
+ throw error;
889
+ } finally {
890
+ await bridgeOta.disconnect(deviceId);
891
+ progressCallback("Disconnected...", 1);
892
+ }
893
+ },
894
+ async onUpdateFirmwareStatus(callback) {
895
+ simulatorSvc.registerEvent("bridgeOta:status", callback);
896
+ },
897
+ async onUpdateFirmwareSuccess(callback) {
898
+ simulatorSvc.registerEvent("bridgeOta:success", callback);
899
+ },
900
+ async onUpdateFirmwareError(callback) {
901
+ simulatorSvc.registerEvent("bridgeOta:error", callback);
843
902
  }
844
903
  };
845
904
  async function uploadOta(deviceId, firmwareBinary, reportStatus) {
@@ -878,6 +937,15 @@ const bridgeOta = {
878
937
  },
879
938
  async updateFirmware(deviceId, bootloader, firmware, progressCallback) {
880
939
  return bridgeOtaService.updateFirmware(deviceId, bootloader, firmware, progressCallback);
940
+ },
941
+ async onUpdateFirmwareStatus(callback) {
942
+ return bridgeOtaService.onUpdateFirmwareStatus(callback);
943
+ },
944
+ async onUpdateFirmwareSuccess(callback) {
945
+ return bridgeOtaService.onUpdateFirmwareSuccess(callback);
946
+ },
947
+ async onUpdateFirmwareError(callback) {
948
+ return bridgeOtaService.onUpdateFirmwareError(callback);
881
949
  }
882
950
  };
883
951
 
@@ -2155,10 +2223,16 @@ function bridgeVehiclesDifference(original, change) {
2155
2223
  const differences = [];
2156
2224
  if (original.vin !== change.vin || original.vinExtension !== change.vinExtension) differences.push("vin");
2157
2225
  const originalTyres = original.tcTyres.map((t) => {
2158
- return { positionId: t.mountedOn?.positionId, sensorId: t.tcTpmsSensor?.id || null };
2226
+ return {
2227
+ positionId: t.mountedOn?.positionId,
2228
+ sensorId: t.tcTpmsSensor?.id || null
2229
+ };
2159
2230
  });
2160
2231
  const changeTyres = change.tcTyres?.map((t) => {
2161
- return { positionId: t.mountedOn?.positionId, sensorId: t.tcTpmsSensor?.id || null };
2232
+ return {
2233
+ positionId: t.mountedOn?.positionId,
2234
+ sensorId: t.tcTpmsSensor?.id || null
2235
+ };
2162
2236
  });
2163
2237
  if (!___default.isEqual(___default.sortBy(changeTyres, "positionId"), ___default.sortBy(originalTyres, "positionId")))
2164
2238
  differences.push("sensorPosition");
@@ -2213,7 +2287,8 @@ async function bridgeConfigurationDifference(original, change) {
2213
2287
  for (const prop of propertiesToCheck) {
2214
2288
  if (!originalAny[prop] || !changeAny[prop]) continue;
2215
2289
  for (const key in changeAny[prop]) {
2216
- if (originalAny[prop][key] !== changeAny[prop][key] || originalAny[prop].isFactory) {
2290
+ if (key === "isFactory") continue;
2291
+ if (originalAny[prop][key] !== changeAny[prop][key]) {
2217
2292
  differentProps.push(prop);
2218
2293
  break;
2219
2294
  }
@@ -2489,7 +2564,11 @@ function getPressureAndTemperatureReadingObjects(rawPressure, rawTemperature) {
2489
2564
  meas: Math.max(0, measuredPressureAbsolute - 1),
2490
2565
  bar: Math.max(0, compensatedPressureAbsolute - 1)
2491
2566
  },
2492
- temperature: { raw: rawTemperature, amb: ambientTemperature, celsius: measuredTemperature }
2567
+ temperature: {
2568
+ raw: rawTemperature,
2569
+ amb: ambientTemperature,
2570
+ celsius: measuredTemperature
2571
+ }
2493
2572
  };
2494
2573
  }
2495
2574
  function getPressureIssue$1(deviceId, eceStatus) {
@@ -2612,7 +2691,12 @@ async function assignAxles(deviceId, tcVehicle) {
2612
2691
  const tyreCount = Number.parseInt(activeAxles[index], 16).toString(2).split("").filter((x) => x === "1").length;
2613
2692
  if (!tyreCount) continue;
2614
2693
  const hasSpareTyre = tyreCount % 2 === 1;
2615
- const axle = { tyresCount: hasSpareTyre ? tyreCount - 1 : tyreCount, isSteer, isDrive, isLift };
2694
+ const axle = {
2695
+ tyresCount: hasSpareTyre ? tyreCount - 1 : tyreCount,
2696
+ isSteer,
2697
+ isDrive,
2698
+ isLift
2699
+ };
2616
2700
  const axleWithLimits = await assignAxlePressureLimits(deviceId, tcVehicle, axle, index, axlesPressureData);
2617
2701
  tcVehicle.axles.push(axleWithLimits);
2618
2702
  if (hasSpareTyre) {
@@ -2736,30 +2820,6 @@ async function disconnect(deviceId, reason) {
2736
2820
  store.setState(deviceId, void 0, reason ?? "manualDisconnection");
2737
2821
  }
2738
2822
 
2739
- const callbacks = {};
2740
- const simulatorSvc = {
2741
- registerEvent(eventName, callback) {
2742
- callbacks[eventName] = callback;
2743
- },
2744
- triggerEvent(eventName, deviceId, payload) {
2745
- if (payload === void 0) {
2746
- const simulatedDevice = store.simulatedDevices[deviceId];
2747
- if (!simulatedDevice) throw new Error(`Device not found`);
2748
- payload = simulatedDevice.simulatorData?.events?.[eventName];
2749
- if (!payload) throw new Error(`Event not found`);
2750
- }
2751
- const callback = callbacks[eventName];
2752
- if (!callback) {
2753
- console.warn(`Event ${eventName} not registered`);
2754
- } else {
2755
- callback(deviceId, payload);
2756
- }
2757
- },
2758
- merge(deviceTemplate, initialData) {
2759
- return ___default.mergeWith({}, deviceTemplate, initialData, (a, b) => ___default.isArray(b) ? b : void 0);
2760
- }
2761
- };
2762
-
2763
2823
  const flexiGaugeTpmsMeta$1 = deviceMeta.flexiGaugeTpms;
2764
2824
  const flexiGaugeCommands = {
2765
2825
  getBattery: getBattery$1,
@@ -2999,15 +3059,12 @@ async function setTpmsConfig(deviceId, config) {
2999
3059
  const msg = `*TPMS CONFIG ${config}`;
3000
3060
  return sendCommand(deviceId, msg);
3001
3061
  }
3002
- async function startTpmsScan(deviceId) {
3062
+ async function startTpmsScan(deviceId, filterBySensorId, time = 10) {
3003
3063
  if (!canCommunicateWith(deviceId)) throw new Error("Flexi Gauge not connected");
3004
- const scanMsg = stringToArrayBuffer("*TPMS ON TIME=10\r\n");
3005
- return bluetooth.write(
3006
- deviceId,
3007
- flexiGaugeTpmsMeta.communication.serviceId,
3008
- flexiGaugeTpmsMeta.communication.characteristicId,
3009
- scanMsg
3010
- );
3064
+ const massageParts = ["*TPMS ON"];
3065
+ if (filterBySensorId) massageParts.push(`FILTER=${filterBySensorId}`);
3066
+ if (time) massageParts.push(`TIME=${time}`);
3067
+ return write(deviceId, massageParts.join(" "));
3011
3068
  }
3012
3069
  async function getBattery(deviceId) {
3013
3070
  const batteryValue = await bluetooth.read(
@@ -3042,13 +3099,8 @@ async function vdaRequestWriteAccess(deviceId, sensorId, signature) {
3042
3099
  return sendCommand(deviceId, scanMsg);
3043
3100
  }
3044
3101
  async function vdaSendWriteModePin(deviceId) {
3045
- const scanMsg = stringToArrayBuffer("*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6\r\n");
3046
- await bluetooth.write(
3047
- deviceId,
3048
- flexiGaugeTpmsMeta.communication.serviceId,
3049
- flexiGaugeTpmsMeta.communication.characteristicId,
3050
- scanMsg
3051
- );
3102
+ const scanMsg = "*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6";
3103
+ return write(deviceId, scanMsg);
3052
3104
  }
3053
3105
  async function vdaReadConfiguration(deviceId) {
3054
3106
  const scanMsg = "*VDA_LF_SEND SID=A0 LID=DA PAR=17";
@@ -3074,6 +3126,23 @@ async function sendCommand(deviceId, command) {
3074
3126
  }
3075
3127
  return String.fromCharCode(...result);
3076
3128
  }
3129
+ async function write(deviceId, message, mtu = 20) {
3130
+ const payload = stringToDecimalArray(`${message}\r
3131
+ `);
3132
+ const chunks = [];
3133
+ for (let i = 0; i < payload.length; i += mtu) {
3134
+ chunks.push(payload.slice(i, i + mtu));
3135
+ }
3136
+ for (const chunk of chunks) {
3137
+ const convertedChunk = new Uint8Array(chunk);
3138
+ await bluetooth.write(
3139
+ deviceId,
3140
+ flexiGaugeTpmsMeta.communication.serviceId,
3141
+ flexiGaugeTpmsMeta.communication.characteristicId,
3142
+ convertedChunk.buffer
3143
+ );
3144
+ }
3145
+ }
3077
3146
  function processMessage(deviceId, payload) {
3078
3147
  promiseQueue.processMessage(deviceId, payload, getIdentifier$1, isComplete$1, isError$1);
3079
3148
  }
@@ -3262,8 +3331,8 @@ const capabilities$1 = [
3262
3331
  }
3263
3332
  ];
3264
3333
  const flexiGaugeTpmsService = {
3265
- startTpmsScan(deviceId) {
3266
- flexiGaugeTpmsCommands.startTpmsScan(deviceId);
3334
+ startTpmsScan(deviceId, filterBySensorId, time = 10) {
3335
+ flexiGaugeTpmsCommands.startTpmsScan(deviceId, filterBySensorId, time);
3267
3336
  },
3268
3337
  getBattery(deviceId) {
3269
3338
  return flexiGaugeTpmsCommands.getBattery(deviceId);
package/dist/index.d.cts CHANGED
@@ -64,7 +64,11 @@ declare const _default$1: {
64
64
  bridgeOta: {
65
65
  nameRegex: RegExp;
66
66
  mtu: number;
67
- characteristic: {
67
+ control: {
68
+ serviceId: string;
69
+ characteristicId: string;
70
+ };
71
+ data: {
68
72
  serviceId: string;
69
73
  characteristicId: string;
70
74
  };
@@ -906,6 +910,9 @@ interface EventHandlers {
906
910
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
907
911
  'ps:pressure'?: (deviceId: string, value: number) => void;
908
912
  'tw:reading'?: (deviceId: string, value: TorqueWrenchReading) => void;
913
+ 'bridgeOta:status'?: (deviceId: string, status: string) => void;
914
+ 'bridgeOta:success'?: (deviceId: string) => void;
915
+ 'bridgeOta:error'?: (deviceId: string, error: string) => void;
909
916
  }
910
917
  interface TorqueWrenchStartJobParams {
911
918
  nuts: number;
@@ -969,6 +976,9 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
969
976
  connect(deviceId: string): Promise<void>;
970
977
  disconnect(deviceId: string, reason?: StateReason): Promise<void>;
971
978
  updateFirmware(deviceId: string, bootloader: ArrayBuffer, firmware: ArrayBuffer, progressCallback: ReportStatusFn): Promise<void>;
979
+ onUpdateFirmwareStatus(callback: (deviceId: string, status: string) => void): Promise<void>;
980
+ onUpdateFirmwareSuccess(callback: (deviceId: string) => void): Promise<void>;
981
+ onUpdateFirmwareError(callback: (deviceId: string) => void): Promise<void>;
972
982
  };
973
983
  /** Methods for working with Tirecheck TPMS FlexiGauge */
974
984
  flexiGaugeTpms: {
@@ -979,7 +989,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
979
989
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
980
990
  getBattery: (deviceId: string) => Promise<number>;
981
991
  getFirmwareVersion: (deviceId: string) => Promise<string>;
982
- startTpmsScan: (deviceId: string) => void;
992
+ startTpmsScan: (deviceId: string, filterBySensorId?: string, time?: number) => void;
983
993
  setSensorDisplayId: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
984
994
  resetSensorDisplayId: (deviceId: string, sensorId: string) => Promise<void>;
985
995
  getConfig: (deviceId: string) => Promise<FgConfig>;
package/dist/index.d.mts CHANGED
@@ -64,7 +64,11 @@ declare const _default$1: {
64
64
  bridgeOta: {
65
65
  nameRegex: RegExp;
66
66
  mtu: number;
67
- characteristic: {
67
+ control: {
68
+ serviceId: string;
69
+ characteristicId: string;
70
+ };
71
+ data: {
68
72
  serviceId: string;
69
73
  characteristicId: string;
70
74
  };
@@ -906,6 +910,9 @@ interface EventHandlers {
906
910
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
907
911
  'ps:pressure'?: (deviceId: string, value: number) => void;
908
912
  'tw:reading'?: (deviceId: string, value: TorqueWrenchReading) => void;
913
+ 'bridgeOta:status'?: (deviceId: string, status: string) => void;
914
+ 'bridgeOta:success'?: (deviceId: string) => void;
915
+ 'bridgeOta:error'?: (deviceId: string, error: string) => void;
909
916
  }
910
917
  interface TorqueWrenchStartJobParams {
911
918
  nuts: number;
@@ -969,6 +976,9 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
969
976
  connect(deviceId: string): Promise<void>;
970
977
  disconnect(deviceId: string, reason?: StateReason): Promise<void>;
971
978
  updateFirmware(deviceId: string, bootloader: ArrayBuffer, firmware: ArrayBuffer, progressCallback: ReportStatusFn): Promise<void>;
979
+ onUpdateFirmwareStatus(callback: (deviceId: string, status: string) => void): Promise<void>;
980
+ onUpdateFirmwareSuccess(callback: (deviceId: string) => void): Promise<void>;
981
+ onUpdateFirmwareError(callback: (deviceId: string) => void): Promise<void>;
972
982
  };
973
983
  /** Methods for working with Tirecheck TPMS FlexiGauge */
974
984
  flexiGaugeTpms: {
@@ -979,7 +989,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
979
989
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
980
990
  getBattery: (deviceId: string) => Promise<number>;
981
991
  getFirmwareVersion: (deviceId: string) => Promise<string>;
982
- startTpmsScan: (deviceId: string) => void;
992
+ startTpmsScan: (deviceId: string, filterBySensorId?: string, time?: number) => void;
983
993
  setSensorDisplayId: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
984
994
  resetSensorDisplayId: (deviceId: string, sensorId: string) => Promise<void>;
985
995
  getConfig: (deviceId: string) => Promise<FgConfig>;
package/dist/index.d.ts CHANGED
@@ -64,7 +64,11 @@ declare const _default$1: {
64
64
  bridgeOta: {
65
65
  nameRegex: RegExp;
66
66
  mtu: number;
67
- characteristic: {
67
+ control: {
68
+ serviceId: string;
69
+ characteristicId: string;
70
+ };
71
+ data: {
68
72
  serviceId: string;
69
73
  characteristicId: string;
70
74
  };
@@ -906,6 +910,9 @@ interface EventHandlers {
906
910
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
907
911
  'ps:pressure'?: (deviceId: string, value: number) => void;
908
912
  'tw:reading'?: (deviceId: string, value: TorqueWrenchReading) => void;
913
+ 'bridgeOta:status'?: (deviceId: string, status: string) => void;
914
+ 'bridgeOta:success'?: (deviceId: string) => void;
915
+ 'bridgeOta:error'?: (deviceId: string, error: string) => void;
909
916
  }
910
917
  interface TorqueWrenchStartJobParams {
911
918
  nuts: number;
@@ -969,6 +976,9 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
969
976
  connect(deviceId: string): Promise<void>;
970
977
  disconnect(deviceId: string, reason?: StateReason): Promise<void>;
971
978
  updateFirmware(deviceId: string, bootloader: ArrayBuffer, firmware: ArrayBuffer, progressCallback: ReportStatusFn): Promise<void>;
979
+ onUpdateFirmwareStatus(callback: (deviceId: string, status: string) => void): Promise<void>;
980
+ onUpdateFirmwareSuccess(callback: (deviceId: string) => void): Promise<void>;
981
+ onUpdateFirmwareError(callback: (deviceId: string) => void): Promise<void>;
972
982
  };
973
983
  /** Methods for working with Tirecheck TPMS FlexiGauge */
974
984
  flexiGaugeTpms: {
@@ -979,7 +989,7 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
979
989
  onTpms: (callback: (deviceId: string, value: FgSensorReading | undefined) => void) => void;
980
990
  getBattery: (deviceId: string) => Promise<number>;
981
991
  getFirmwareVersion: (deviceId: string) => Promise<string>;
982
- startTpmsScan: (deviceId: string) => void;
992
+ startTpmsScan: (deviceId: string, filterBySensorId?: string, time?: number) => void;
983
993
  setSensorDisplayId: (deviceId: string, oldSensorId: string, newSensorId: string) => Promise<void>;
984
994
  resetSensorDisplayId: (deviceId: string, sensorId: string) => Promise<void>;
985
995
  getConfig: (deviceId: string) => Promise<FgConfig>;
package/dist/index.mjs CHANGED
@@ -526,9 +526,13 @@ const deviceMeta = {
526
526
  bridgeOta: {
527
527
  nameRegex: /(CAN BLE BRDG OTA.*|0303.{2}_B|030632_B)/,
528
528
  mtu: 180,
529
- characteristic: {
530
- serviceId: "4880c12c-fdcb-4077-8920-a450d7f9b907",
531
- characteristicId: "fec26ec4-6d71-4442-9f81-55bc21d658d7"
529
+ control: {
530
+ serviceId: "1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0",
531
+ characteristicId: "f7bf3564-fb6d-4e53-88a4-5e37e0326063"
532
+ },
533
+ data: {
534
+ serviceId: "1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0",
535
+ characteristicId: "984227f3-34fc-4045-a5d0-2c581f81a153"
532
536
  },
533
537
  getDeviceInfoFromAdvertising: bridgeOtaAdvertisingParser.getDeviceInfoFromAdvertising
534
538
  },
@@ -659,7 +663,7 @@ const bluetooth = {
659
663
  },
660
664
  connect: connect$1,
661
665
  disconnect: disconnect$1,
662
- write,
666
+ write: write$1,
663
667
  read
664
668
  };
665
669
  async function scanDevices(services = [], duration) {
@@ -735,7 +739,7 @@ async function disconnect$1(deviceId) {
735
739
  store.setState(deviceId, void 0, "failedDisconnection");
736
740
  throw new Error("Disconnect unsuccessful");
737
741
  }
738
- async function write(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
742
+ async function write$1(deviceId, serviceUuid, characteristicUuid, value, withResponse) {
739
743
  if (!toolsSvc.canCommunicateWith(deviceId)) throw new Error("Write Error: Not connected to device");
740
744
  try {
741
745
  const _deviceId = store.deviceIdMapingTable[deviceId] ?? deviceId;
@@ -802,18 +806,51 @@ function getDeviceNameFromAdvertising(advertising) {
802
806
  return deviceName;
803
807
  }
804
808
 
805
- const otaServiceUuid = "1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0";
806
- const otaControlCharacteristicUuid = "f7bf3564-fb6d-4e53-88a4-5e37e0326063";
807
- const otaDataCharacteristicUuid = "984227f3-34fc-4045-a5d0-2c581f81a153";
809
+ const callbacks = {};
810
+ const simulatorSvc = {
811
+ registerEvent(eventName, callback) {
812
+ callbacks[eventName] = callback;
813
+ },
814
+ triggerEvent(eventName, deviceId, payload) {
815
+ if (payload && store.simulatedDevices[deviceId]) {
816
+ const simulatedDevice = store.simulatedDevices[deviceId];
817
+ payload = simulatedDevice.simulatorData?.events?.[eventName];
818
+ if (!payload) throw new Error(`Event not found`);
819
+ }
820
+ const callback = callbacks[eventName];
821
+ if (!callback) {
822
+ console.warn(`Event ${eventName} not registered`);
823
+ } else {
824
+ callback(deviceId, payload);
825
+ }
826
+ },
827
+ merge(deviceTemplate, initialData) {
828
+ return _.mergeWith({}, deviceTemplate, initialData, (a, b) => _.isArray(b) ? b : void 0);
829
+ }
830
+ };
831
+
832
+ const bridgeOtaMeta = deviceMeta.bridgeOta;
808
833
  const bridgeOtaCommands = {
809
834
  async beginOta(deviceId) {
810
- await bluetooth.write(deviceId, otaServiceUuid, otaControlCharacteristicUuid, new Uint8Array([0]).buffer, true);
835
+ await bluetooth.write(
836
+ deviceId,
837
+ bridgeOtaMeta.control.serviceId,
838
+ bridgeOtaMeta.control.characteristicId,
839
+ new Uint8Array([0]).buffer,
840
+ true
841
+ );
811
842
  },
812
843
  async uploadOtaChunk(deviceId, data) {
813
- await bluetooth.write(deviceId, otaServiceUuid, otaDataCharacteristicUuid, data, true);
844
+ await bluetooth.write(deviceId, bridgeOtaMeta.data.serviceId, bridgeOtaMeta.data.characteristicId, data, true);
814
845
  },
815
846
  async endOta(deviceId) {
816
- await bluetooth.write(deviceId, otaServiceUuid, otaControlCharacteristicUuid, new Uint8Array([3]).buffer, true);
847
+ await bluetooth.write(
848
+ deviceId,
849
+ bridgeOtaMeta.control.serviceId,
850
+ bridgeOtaMeta.control.characteristicId,
851
+ new Uint8Array([3]).buffer,
852
+ true
853
+ );
817
854
  }
818
855
  };
819
856
 
@@ -822,17 +859,39 @@ const bridgeOtaService = {
822
859
  await delay(2e3);
823
860
  progressCallback("Connecting to the bridge...", 0.1);
824
861
  await bridgeOta.connect(deviceId);
825
- progressCallback("Uploading bootloader...", 0.12);
826
- await bridgeOtaCommands.beginOta(deviceId);
827
- await uploadOta(deviceId, bootloader, (str, percents) => progressCallback(str, 0.12 + percents * 0.2));
828
- await bridgeOtaCommands.endOta(deviceId);
829
- progressCallback("Uploading application...", 0.32);
830
- await bridgeOtaCommands.beginOta(deviceId);
831
- await uploadOta(deviceId, firmware, (str, percents) => progressCallback(str, 0.32 + percents * 0.5));
832
- await bridgeOtaCommands.endOta(deviceId);
833
- progressCallback("Upload completed, disconnecting...", 0.81);
834
- await bridgeOta.disconnect(deviceId);
835
- progressCallback("Disconnected...", 1);
862
+ try {
863
+ progressCallback("Uploading bootloader...", 0.12);
864
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "bootloaderUploadBegin");
865
+ await bridgeOtaCommands.beginOta(deviceId);
866
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "bootloaderUpload");
867
+ await uploadOta(deviceId, bootloader, (str, percents) => progressCallback(str, 0.12 + percents * 0.2));
868
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "bootloaderUploadEnd");
869
+ await bridgeOtaCommands.endOta(deviceId);
870
+ progressCallback("Uploading application...", 0.32);
871
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "applicationUploadBegin");
872
+ await bridgeOtaCommands.beginOta(deviceId);
873
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "applicationUpload");
874
+ await uploadOta(deviceId, firmware, (str, percents) => progressCallback(str, 0.32 + percents * 0.5));
875
+ simulatorSvc.triggerEvent("bridgeOta:status", deviceId, "applicationUploadEnd");
876
+ await bridgeOtaCommands.endOta(deviceId);
877
+ simulatorSvc.triggerEvent("bridgeOta:success", deviceId);
878
+ progressCallback("Upload completed, disconnecting...", 0.81);
879
+ } catch (error) {
880
+ simulatorSvc.triggerEvent("bridgeOta:error", deviceId);
881
+ throw error;
882
+ } finally {
883
+ await bridgeOta.disconnect(deviceId);
884
+ progressCallback("Disconnected...", 1);
885
+ }
886
+ },
887
+ async onUpdateFirmwareStatus(callback) {
888
+ simulatorSvc.registerEvent("bridgeOta:status", callback);
889
+ },
890
+ async onUpdateFirmwareSuccess(callback) {
891
+ simulatorSvc.registerEvent("bridgeOta:success", callback);
892
+ },
893
+ async onUpdateFirmwareError(callback) {
894
+ simulatorSvc.registerEvent("bridgeOta:error", callback);
836
895
  }
837
896
  };
838
897
  async function uploadOta(deviceId, firmwareBinary, reportStatus) {
@@ -871,6 +930,15 @@ const bridgeOta = {
871
930
  },
872
931
  async updateFirmware(deviceId, bootloader, firmware, progressCallback) {
873
932
  return bridgeOtaService.updateFirmware(deviceId, bootloader, firmware, progressCallback);
933
+ },
934
+ async onUpdateFirmwareStatus(callback) {
935
+ return bridgeOtaService.onUpdateFirmwareStatus(callback);
936
+ },
937
+ async onUpdateFirmwareSuccess(callback) {
938
+ return bridgeOtaService.onUpdateFirmwareSuccess(callback);
939
+ },
940
+ async onUpdateFirmwareError(callback) {
941
+ return bridgeOtaService.onUpdateFirmwareError(callback);
874
942
  }
875
943
  };
876
944
 
@@ -2148,10 +2216,16 @@ function bridgeVehiclesDifference(original, change) {
2148
2216
  const differences = [];
2149
2217
  if (original.vin !== change.vin || original.vinExtension !== change.vinExtension) differences.push("vin");
2150
2218
  const originalTyres = original.tcTyres.map((t) => {
2151
- return { positionId: t.mountedOn?.positionId, sensorId: t.tcTpmsSensor?.id || null };
2219
+ return {
2220
+ positionId: t.mountedOn?.positionId,
2221
+ sensorId: t.tcTpmsSensor?.id || null
2222
+ };
2152
2223
  });
2153
2224
  const changeTyres = change.tcTyres?.map((t) => {
2154
- return { positionId: t.mountedOn?.positionId, sensorId: t.tcTpmsSensor?.id || null };
2225
+ return {
2226
+ positionId: t.mountedOn?.positionId,
2227
+ sensorId: t.tcTpmsSensor?.id || null
2228
+ };
2155
2229
  });
2156
2230
  if (!_.isEqual(_.sortBy(changeTyres, "positionId"), _.sortBy(originalTyres, "positionId")))
2157
2231
  differences.push("sensorPosition");
@@ -2206,7 +2280,8 @@ async function bridgeConfigurationDifference(original, change) {
2206
2280
  for (const prop of propertiesToCheck) {
2207
2281
  if (!originalAny[prop] || !changeAny[prop]) continue;
2208
2282
  for (const key in changeAny[prop]) {
2209
- if (originalAny[prop][key] !== changeAny[prop][key] || originalAny[prop].isFactory) {
2283
+ if (key === "isFactory") continue;
2284
+ if (originalAny[prop][key] !== changeAny[prop][key]) {
2210
2285
  differentProps.push(prop);
2211
2286
  break;
2212
2287
  }
@@ -2482,7 +2557,11 @@ function getPressureAndTemperatureReadingObjects(rawPressure, rawTemperature) {
2482
2557
  meas: Math.max(0, measuredPressureAbsolute - 1),
2483
2558
  bar: Math.max(0, compensatedPressureAbsolute - 1)
2484
2559
  },
2485
- temperature: { raw: rawTemperature, amb: ambientTemperature, celsius: measuredTemperature }
2560
+ temperature: {
2561
+ raw: rawTemperature,
2562
+ amb: ambientTemperature,
2563
+ celsius: measuredTemperature
2564
+ }
2486
2565
  };
2487
2566
  }
2488
2567
  function getPressureIssue$1(deviceId, eceStatus) {
@@ -2605,7 +2684,12 @@ async function assignAxles(deviceId, tcVehicle) {
2605
2684
  const tyreCount = Number.parseInt(activeAxles[index], 16).toString(2).split("").filter((x) => x === "1").length;
2606
2685
  if (!tyreCount) continue;
2607
2686
  const hasSpareTyre = tyreCount % 2 === 1;
2608
- const axle = { tyresCount: hasSpareTyre ? tyreCount - 1 : tyreCount, isSteer, isDrive, isLift };
2687
+ const axle = {
2688
+ tyresCount: hasSpareTyre ? tyreCount - 1 : tyreCount,
2689
+ isSteer,
2690
+ isDrive,
2691
+ isLift
2692
+ };
2609
2693
  const axleWithLimits = await assignAxlePressureLimits(deviceId, tcVehicle, axle, index, axlesPressureData);
2610
2694
  tcVehicle.axles.push(axleWithLimits);
2611
2695
  if (hasSpareTyre) {
@@ -2729,30 +2813,6 @@ async function disconnect(deviceId, reason) {
2729
2813
  store.setState(deviceId, void 0, reason ?? "manualDisconnection");
2730
2814
  }
2731
2815
 
2732
- const callbacks = {};
2733
- const simulatorSvc = {
2734
- registerEvent(eventName, callback) {
2735
- callbacks[eventName] = callback;
2736
- },
2737
- triggerEvent(eventName, deviceId, payload) {
2738
- if (payload === void 0) {
2739
- const simulatedDevice = store.simulatedDevices[deviceId];
2740
- if (!simulatedDevice) throw new Error(`Device not found`);
2741
- payload = simulatedDevice.simulatorData?.events?.[eventName];
2742
- if (!payload) throw new Error(`Event not found`);
2743
- }
2744
- const callback = callbacks[eventName];
2745
- if (!callback) {
2746
- console.warn(`Event ${eventName} not registered`);
2747
- } else {
2748
- callback(deviceId, payload);
2749
- }
2750
- },
2751
- merge(deviceTemplate, initialData) {
2752
- return _.mergeWith({}, deviceTemplate, initialData, (a, b) => _.isArray(b) ? b : void 0);
2753
- }
2754
- };
2755
-
2756
2816
  const flexiGaugeTpmsMeta$1 = deviceMeta.flexiGaugeTpms;
2757
2817
  const flexiGaugeCommands = {
2758
2818
  getBattery: getBattery$1,
@@ -2992,15 +3052,12 @@ async function setTpmsConfig(deviceId, config) {
2992
3052
  const msg = `*TPMS CONFIG ${config}`;
2993
3053
  return sendCommand(deviceId, msg);
2994
3054
  }
2995
- async function startTpmsScan(deviceId) {
3055
+ async function startTpmsScan(deviceId, filterBySensorId, time = 10) {
2996
3056
  if (!canCommunicateWith(deviceId)) throw new Error("Flexi Gauge not connected");
2997
- const scanMsg = stringToArrayBuffer("*TPMS ON TIME=10\r\n");
2998
- return bluetooth.write(
2999
- deviceId,
3000
- flexiGaugeTpmsMeta.communication.serviceId,
3001
- flexiGaugeTpmsMeta.communication.characteristicId,
3002
- scanMsg
3003
- );
3057
+ const massageParts = ["*TPMS ON"];
3058
+ if (filterBySensorId) massageParts.push(`FILTER=${filterBySensorId}`);
3059
+ if (time) massageParts.push(`TIME=${time}`);
3060
+ return write(deviceId, massageParts.join(" "));
3004
3061
  }
3005
3062
  async function getBattery(deviceId) {
3006
3063
  const batteryValue = await bluetooth.read(
@@ -3035,13 +3092,8 @@ async function vdaRequestWriteAccess(deviceId, sensorId, signature) {
3035
3092
  return sendCommand(deviceId, scanMsg);
3036
3093
  }
3037
3094
  async function vdaSendWriteModePin(deviceId) {
3038
- const scanMsg = stringToArrayBuffer("*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6\r\n");
3039
- await bluetooth.write(
3040
- deviceId,
3041
- flexiGaugeTpmsMeta.communication.serviceId,
3042
- flexiGaugeTpmsMeta.communication.characteristicId,
3043
- scanMsg
3044
- );
3095
+ const scanMsg = "*VDA_LF_SEND SID=A0 LID=AA PAR=00 DATA=FCCC71F6";
3096
+ return write(deviceId, scanMsg);
3045
3097
  }
3046
3098
  async function vdaReadConfiguration(deviceId) {
3047
3099
  const scanMsg = "*VDA_LF_SEND SID=A0 LID=DA PAR=17";
@@ -3067,6 +3119,23 @@ async function sendCommand(deviceId, command) {
3067
3119
  }
3068
3120
  return String.fromCharCode(...result);
3069
3121
  }
3122
+ async function write(deviceId, message, mtu = 20) {
3123
+ const payload = stringToDecimalArray(`${message}\r
3124
+ `);
3125
+ const chunks = [];
3126
+ for (let i = 0; i < payload.length; i += mtu) {
3127
+ chunks.push(payload.slice(i, i + mtu));
3128
+ }
3129
+ for (const chunk of chunks) {
3130
+ const convertedChunk = new Uint8Array(chunk);
3131
+ await bluetooth.write(
3132
+ deviceId,
3133
+ flexiGaugeTpmsMeta.communication.serviceId,
3134
+ flexiGaugeTpmsMeta.communication.characteristicId,
3135
+ convertedChunk.buffer
3136
+ );
3137
+ }
3138
+ }
3070
3139
  function processMessage(deviceId, payload) {
3071
3140
  promiseQueue.processMessage(deviceId, payload, getIdentifier$1, isComplete$1, isError$1);
3072
3141
  }
@@ -3255,8 +3324,8 @@ const capabilities$1 = [
3255
3324
  }
3256
3325
  ];
3257
3326
  const flexiGaugeTpmsService = {
3258
- startTpmsScan(deviceId) {
3259
- flexiGaugeTpmsCommands.startTpmsScan(deviceId);
3327
+ startTpmsScan(deviceId, filterBySensorId, time = 10) {
3328
+ flexiGaugeTpmsCommands.startTpmsScan(deviceId, filterBySensorId, time);
3260
3329
  },
3261
3330
  getBattery(deviceId) {
3262
3331
  return flexiGaugeTpmsCommands.getBattery(deviceId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.2.54",
3
+ "version": "0.2.56",
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",