tirecheck-device-sdk 0.2.70 → 0.2.71

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
@@ -134,6 +134,19 @@ function normalizeError(error) {
134
134
  return error;
135
135
  }
136
136
 
137
+ const emptyBluetoothClassicSerialImplementation = {
138
+ list: async () => [],
139
+ discoverUnpaired: async () => [],
140
+ setDeviceDiscoveredListener: () => {
141
+ },
142
+ clearDeviceDiscoveredListener: () => {
143
+ }
144
+ };
145
+ let bluetoothClassicSerial = emptyBluetoothClassicSerialImplementation;
146
+ function setBluetoothClassicSerialImplementation(bluetoothClassicSerialImplementation) {
147
+ bluetoothClassicSerial = bluetoothClassicSerialImplementation ?? emptyBluetoothClassicSerialImplementation;
148
+ }
149
+
137
150
  const tyreLabels = getDefaultTyreLabels();
138
151
  const bridgeTools = {
139
152
  getBridgeFromStore,
@@ -657,6 +670,17 @@ const deviceMeta = {
657
670
  };
658
671
  return bleDevice;
659
672
  }
673
+ },
674
+ unitechRfid: {
675
+ nameRegex: /^RP902/i,
676
+ transport: "serial",
677
+ getDeviceInfoFromAdvertising: (device) => {
678
+ const bleDevice = {
679
+ ...device,
680
+ type: "unitechRfid"
681
+ };
682
+ return bleDevice;
683
+ }
660
684
  }
661
685
  };
662
686
 
@@ -693,6 +717,8 @@ const bluetooth = {
693
717
  deviceStateChangeCallback = callback;
694
718
  },
695
719
  scanDevices,
720
+ scanSerialDevicesPaired,
721
+ scanSerialDevicesUnpaired,
696
722
  stopScan() {
697
723
  ble.stopScan();
698
724
  },
@@ -723,6 +749,47 @@ async function scanDevices(services = [], duration) {
723
749
  (e) => console.error("ble.startScanWithOptions error:", e)
724
750
  );
725
751
  }
752
+ async function scanSerialDevicesPaired() {
753
+ try {
754
+ const pairedDevices = await bluetoothClassicSerial.list();
755
+ for (const device of pairedDevices ?? []) handleSerialDevice(device);
756
+ } catch (e) {
757
+ console.error("scanPairedSerialDevices error:", e);
758
+ }
759
+ }
760
+ async function scanSerialDevicesUnpaired() {
761
+ bluetoothClassicSerial.setDeviceDiscoveredListener?.((device) => handleSerialDevice(device));
762
+ try {
763
+ const unpairedDevices = await bluetoothClassicSerial.discoverUnpaired();
764
+ for (const device of unpairedDevices ?? []) handleSerialDevice(device);
765
+ } catch (e) {
766
+ const message = (typeof e === "string" ? e : e?.message ?? "").toLowerCase();
767
+ const pickerDismissed = store.platform === "ios" && ["cancel", "alreadyconnected", "already connected", "notfound", "not found"].some((m) => message.includes(m));
768
+ if (pickerDismissed) {
769
+ console.log("discoverSerialDevices: accessory picker returned no unpaired device -", message);
770
+ } else {
771
+ console.error("discoverSerialDevices error:", e);
772
+ }
773
+ } finally {
774
+ bluetoothClassicSerial.clearDeviceDiscoveredListener?.();
775
+ }
776
+ }
777
+ function handleSerialDevice(device) {
778
+ const rawId = device.id ?? device.address;
779
+ const id = rawId != null ? String(rawId) : void 0;
780
+ if (!id) {
781
+ console.warn("handleSerialDevice: skipped, no id/address", device);
782
+ return;
783
+ }
784
+ const peripheral = { id, name: device.name, rssi: device.rssi ?? 0, advertising: {} };
785
+ const processedDevice = processDevice(peripheral);
786
+ if (!processedDevice) {
787
+ console.warn("handleSerialDevice: processDevice returned null (filtered out)", id, device.name);
788
+ return;
789
+ }
790
+ store.devices[processedDevice.id] = processedDevice;
791
+ deviceAdvertisingCallback?.(processedDevice);
792
+ }
726
793
  async function connect$1(deviceId, disconnectCallback) {
727
794
  if (toolsSvc.canCommunicateWith(deviceId)) return console.warn("Connect Warn: Already connected to device");
728
795
  store.setState(deviceId, "connecting");
@@ -811,7 +878,8 @@ function processDevice(device) {
811
878
  console.warn("Error processing advertising", e);
812
879
  return;
813
880
  }
814
- unreachableSvc.refresh(processedDevice.id, deviceUnreachableCallback);
881
+ const isSerial = deviceMeta[deviceType].transport === "serial";
882
+ if (!isSerial) unreachableSvc.refresh(processedDevice.id, deviceUnreachableCallback);
815
883
  return processedDevice;
816
884
  }
817
885
  function getDeviceTypeFromName(name) {
@@ -4160,6 +4228,95 @@ const torqueWrench = {
4160
4228
  onReading: torqueWrenchService.onReading
4161
4229
  };
4162
4230
 
4231
+ let unitech;
4232
+ function setUnitechRfidImplementation(unitechRfidImplementation) {
4233
+ if (!unitechRfidImplementation)
4234
+ return console.warn("Unitech RFID implementation is not provided, Unitech RFID functionality will not work");
4235
+ unitech = unitechRfidImplementation;
4236
+ }
4237
+
4238
+ const unitechRfidService = {
4239
+ subscribeListeners(deviceId) {
4240
+ unitech.addListener("readerState", (event) => {
4241
+ simulatorSvc.triggerEvent("unitech:readerState", deviceId, event);
4242
+ simulatorSvc.triggerEvent("unitech:readerStateConnect", deviceId, event);
4243
+ });
4244
+ unitech.addListener("actionState", (event) => simulatorSvc.triggerEvent("unitech:actionState", deviceId, event));
4245
+ unitech.addListener("trigger", (event) => simulatorSvc.triggerEvent("unitech:trigger", deviceId, event));
4246
+ unitech.addListener("tagRead", (event) => simulatorSvc.triggerEvent("unitech:tag", deviceId, event));
4247
+ unitech.addListener("battery", (event) => simulatorSvc.triggerEvent("unitech:battery", deviceId, event));
4248
+ unitech.addListener("temperature", (event) => simulatorSvc.triggerEvent("unitech:temperature", deviceId, event));
4249
+ },
4250
+ onReaderState(callback) {
4251
+ simulatorSvc.registerEvent("unitech:readerState", callback);
4252
+ },
4253
+ onActionState(callback) {
4254
+ simulatorSvc.registerEvent("unitech:actionState", callback);
4255
+ },
4256
+ onTrigger(callback) {
4257
+ simulatorSvc.registerEvent("unitech:trigger", callback);
4258
+ },
4259
+ onTagRead(callback) {
4260
+ simulatorSvc.registerEvent("unitech:tag", callback);
4261
+ },
4262
+ onBattery(callback) {
4263
+ simulatorSvc.registerEvent("unitech:battery", callback);
4264
+ },
4265
+ onTemperature(callback) {
4266
+ simulatorSvc.registerEvent("unitech:temperature", callback);
4267
+ }
4268
+ };
4269
+
4270
+ const unitechRfid = {
4271
+ async connect(deviceId) {
4272
+ const unitechDevices = Object.values(store.devices).filter((d) => d.type === "unitechRfid");
4273
+ for (const device2 of unitechDevices) {
4274
+ if (device2.id !== deviceId && store.deviceState[device2.id] === "paired") {
4275
+ await this.disconnect(device2.id, "manualDisconnection");
4276
+ }
4277
+ }
4278
+ store.setState(deviceId, "connecting");
4279
+ await unitech.removeAllListeners();
4280
+ const device = store.devices[deviceId];
4281
+ if (store.platform === "ios") {
4282
+ await unitech.startDetect({ deviceName: device.name });
4283
+ await toolsSvc.delay(500);
4284
+ await unitech.stopDetect();
4285
+ }
4286
+ const { connected } = await unitech.connect({ bluetoothAddress: device.id });
4287
+ if (!connected) throw new Error("UnitechRfid Error: Unable to connect to the device.");
4288
+ await unitechRfidService.subscribeListeners(deviceId);
4289
+ await withTimeout(
4290
+ new Promise((resolve) => {
4291
+ simulatorSvc.registerEvent("unitech:readerStateConnect", (_deviceId, event) => {
4292
+ if (event.state?.toLowerCase() === "connected") resolve();
4293
+ });
4294
+ }),
4295
+ 15e3
4296
+ );
4297
+ await unitech.initDeviceSettings();
4298
+ store.setState(deviceId, "paired");
4299
+ },
4300
+ async disconnect(deviceId, reason) {
4301
+ store.setState(deviceId, "disconnecting");
4302
+ await unitech.removeAllListeners();
4303
+ await unitech.disconnect();
4304
+ store.setState(deviceId, void 0, reason ?? "manualDisconnection");
4305
+ },
4306
+ async startReading() {
4307
+ await unitech.startInventory();
4308
+ },
4309
+ async stopReading() {
4310
+ await unitech.stopInventory();
4311
+ },
4312
+ onReaderState: unitechRfidService.onReaderState,
4313
+ onActionState: unitechRfidService.onActionState,
4314
+ onTrigger: unitechRfidService.onTrigger,
4315
+ onTagRead: unitechRfidService.onTagRead,
4316
+ onBattery: unitechRfidService.onBattery,
4317
+ onTemperature: unitechRfidService.onTemperature
4318
+ };
4319
+
4163
4320
  const bridgeSimulator = {
4164
4321
  isRebootRequired(deviceId) {
4165
4322
  return store.bridgeRebootRequired[deviceId];
@@ -4801,11 +4958,13 @@ class BridgeTcVehicleAxle {
4801
4958
  minTargetPressure;
4802
4959
  }
4803
4960
 
4804
- function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
4961
+ function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys, unitechRfidImplementation, bluetoothClassicSerialImplementation) {
4805
4962
  store.platform = platform;
4806
4963
  bleImplementation = bleImplementation || emptyBleImplementation;
4807
4964
  store.securityKeys = securityKeys || {};
4808
4965
  setBleImplementation(bleImplementation);
4966
+ setUnitechRfidImplementation(unitechRfidImplementation);
4967
+ setBluetoothClassicSerialImplementation(bluetoothClassicSerialImplementation);
4809
4968
  return {
4810
4969
  /** Generic methods common for all devices */
4811
4970
  bluetooth,
@@ -4823,6 +4982,8 @@ function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
4823
4982
  simulator,
4824
4983
  /** Methods for working with Tirecheck Torque Wrench */
4825
4984
  torqueWrench,
4985
+ /** Methods for working with Unitech RFID reader */
4986
+ unitechRfid,
4826
4987
  utils: {
4827
4988
  bridge: {
4828
4989
  convertBarToKpaByte: bridgeTools.convertBarToKpaByte,
package/dist/index.d.cts CHANGED
@@ -1,3 +1,44 @@
1
+ interface UnitechListenerHandle {
2
+ remove: () => Promise<void>;
3
+ }
4
+ interface ReaderStateEvent {
5
+ state: string;
6
+ }
7
+ interface ActionStateEvent {
8
+ state: string;
9
+ }
10
+ interface TriggerEvent {
11
+ pressed: boolean;
12
+ }
13
+ interface TagReadEvent {
14
+ epc: string;
15
+ rssi: number;
16
+ [key: string]: unknown;
17
+ }
18
+ interface BatteryEvent {
19
+ percent: number;
20
+ }
21
+ interface TemperatureEvent {
22
+ celsius: number;
23
+ }
24
+ interface UnitechRfidImplementation {
25
+ removeAllListeners: () => Promise<void>;
26
+ addListener: ((eventName: 'readerState', listener: (event: ReaderStateEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'actionState', listener: (event: ActionStateEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'trigger', listener: (event: TriggerEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'tagRead', listener: (event: TagReadEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'battery', listener: (event: BatteryEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'temperature', listener: (event: TemperatureEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>);
27
+ startDetect: (options: {
28
+ deviceName: string;
29
+ }) => Promise<void>;
30
+ stopDetect: () => Promise<void>;
31
+ connect: (options: {
32
+ bluetoothAddress?: string;
33
+ }) => Promise<{
34
+ connected: boolean;
35
+ }>;
36
+ disconnect: () => Promise<void>;
37
+ initDeviceSettings: () => Promise<void>;
38
+ startInventory: () => Promise<void>;
39
+ stopInventory: () => Promise<void>;
40
+ }
41
+
1
42
  interface BleImplementation {
2
43
  startScanWithOptions: (services: string[], options: StartScanOptions, success: (data: PeripheralData) => any, failure?: (error: string) => any) => void;
3
44
  stopScan: () => Promise<void>;
@@ -118,6 +159,11 @@ declare const _default$1: {
118
159
  };
119
160
  getDeviceInfoFromAdvertising: (device: PeripheralData) => BleTorqueWrench;
120
161
  };
162
+ unitechRfid: {
163
+ nameRegex: RegExp;
164
+ transport: "serial";
165
+ getDeviceInfoFromAdvertising: (device: PeripheralData) => BleUnitechRfid;
166
+ };
121
167
  };
122
168
 
123
169
  declare const _default: {
@@ -1095,7 +1141,7 @@ type BridgeCommandStructurized<T extends BridgeCommandStructureProperties> = {
1095
1141
  };
1096
1142
  type BleDeviceType = keyof typeof _default$1;
1097
1143
  /** distinguish by type, e.g. `if (device.type === 'bridge')`, to access furhter fields */
1098
- type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick | BleFlexiGauge | BleTorqueWrench;
1144
+ type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick | BleFlexiGauge | BleTorqueWrench | BleUnitechRfid;
1099
1145
  type BleDeviceSimulated = BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
1100
1146
  type BleDeviceStatus = 'connected' | 'connecting' | 'disconnecting' | undefined;
1101
1147
  interface BleDeviceBase {
@@ -1125,6 +1171,9 @@ interface BleFlexiGauge extends BleDeviceBase {
1125
1171
  interface BleTorqueWrench extends BleDeviceBase {
1126
1172
  type: 'torqueWrench';
1127
1173
  }
1174
+ interface BleUnitechRfid extends BleDeviceBase {
1175
+ type: 'unitechRfid';
1176
+ }
1128
1177
  interface BleBridgeOta extends BleDeviceBase {
1129
1178
  advertisingData: {
1130
1179
  bridgeId: string;
@@ -1200,12 +1249,25 @@ type Wrapper<T extends Record<string, (...args: any) => any>> = {
1200
1249
  type ReportStatusFn = (status: string, completionPercentage: number) => void;
1201
1250
  type DeviceState = 'connected' | 'connecting' | 'disconnecting' | 'paired' | undefined;
1202
1251
  type StateReason = 'lostConnection' | 'manualDisconnection' | 'failedConnection' | 'failedDisconnection' | 'firmwareUpdate' | string;
1252
+ /** A unique RFID tag aggregated across many tagRead events, keeping the strongest signal seen. */
1253
+ interface RfidTag {
1254
+ epc: string;
1255
+ rssi: number;
1256
+ }
1203
1257
  interface EventHandlers {
1204
1258
  'fg:treadDepth'?: (deviceId: string, value: number) => void;
1205
1259
  'fg:button'?: (deviceId: string, value: string) => void;
1206
1260
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
1207
1261
  'ps:pressure'?: (deviceId: string, value: number) => void;
1208
1262
  'tw:reading'?: (deviceId: string, value: TorqueWrenchReading) => void;
1263
+ 'unitech:readerState'?: (deviceId: string, event: ReaderStateEvent) => void;
1264
+ 'unitech:readerStateConnect'?: (deviceId: string, event: ReaderStateEvent) => void;
1265
+ 'unitech:actionState'?: (deviceId: string, event: ActionStateEvent) => void;
1266
+ 'unitech:trigger'?: (deviceId: string, event: TriggerEvent) => void;
1267
+ 'unitech:tag'?: (deviceId: string, event: TagReadEvent) => void;
1268
+ 'unitech:tagReadMultiple'?: (deviceId: string, tags: RfidTag[]) => void;
1269
+ 'unitech:battery'?: (deviceId: string, event: BatteryEvent) => void;
1270
+ 'unitech:temperature'?: (deviceId: string, event: TemperatureEvent) => void;
1209
1271
  'bridgeOta:status'?: (deviceId: string, status: string) => void;
1210
1272
  'bridgeOta:success'?: (deviceId: string) => void;
1211
1273
  'bridgeOta:error'?: (deviceId: string, error: string) => void;
@@ -1236,16 +1298,42 @@ interface TorqueWrenchReading {
1236
1298
  }
1237
1299
  type EventName = keyof EventHandlers;
1238
1300
 
1301
+ interface BluetoothClassicSerialDevice {
1302
+ /** Device identifier.
1303
+ * Android: device's MAC address (same value as `address`).
1304
+ * iOS: device UUID. */
1305
+ id: string;
1306
+ /** Device's MAC address (Android only). */
1307
+ address?: string;
1308
+ name: string;
1309
+ /** Bluetooth device class (Android only). */
1310
+ class?: number;
1311
+ rssi?: number;
1312
+ }
1313
+ interface BluetoothClassicSerialImplementation {
1314
+ /** Lists already paired/bonded serial devices. */
1315
+ list: () => Promise<BluetoothClassicSerialDevice[]>;
1316
+ /** Discovers nearby unpaired serial devices. Resolves with all devices found once discovery finishes.
1317
+ * For incremental results during discovery, also register `setDeviceDiscoveredListener`. */
1318
+ discoverUnpaired: () => Promise<BluetoothClassicSerialDevice[]>;
1319
+ /** Registers a listener fired for each device discovered during `discoverUnpaired`. */
1320
+ setDeviceDiscoveredListener?: (notify: (device: BluetoothClassicSerialDevice) => void) => void;
1321
+ /** Removes the listener registered via `setDeviceDiscoveredListener`. */
1322
+ clearDeviceDiscoveredListener?: () => void;
1323
+ }
1324
+
1239
1325
  /** Creates instance of SDK.
1240
1326
  * For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
1241
1327
  * If `bleImplementation` is not provided, SDK will work only with the simulator. */
1242
- declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
1328
+ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys, unitechRfidImplementation?: UnitechRfidImplementation, bluetoothClassicSerialImplementation?: BluetoothClassicSerialImplementation): {
1243
1329
  /** Generic methods common for all devices */
1244
1330
  bluetooth: {
1245
1331
  onDeviceAdvertising(callback: (device: BleDevice) => void): void;
1246
1332
  onDeviceUnreachable(callback: (deviceId: string) => void): void;
1247
1333
  onDeviceStateChange(callback: (deviceId: string, state?: DeviceState, reason?: StateReason) => void): void;
1248
1334
  scanDevices: (services?: string[], duration?: number) => Promise<void>;
1335
+ scanSerialDevicesPaired: () => Promise<void>;
1336
+ scanSerialDevicesUnpaired: () => Promise<void>;
1249
1337
  stopScan(): void;
1250
1338
  connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<void | PeripheralDataExtended>;
1251
1339
  disconnect: (deviceId: string) => Promise<void>;
@@ -1333,6 +1421,19 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1333
1421
  getTime: (deviceId: string) => Promise<Date>;
1334
1422
  onReading: (callback: (deviceId: string, value: TorqueWrenchReading) => void) => void;
1335
1423
  };
1424
+ /** Methods for working with Unitech RFID reader */
1425
+ unitechRfid: {
1426
+ connect(deviceId: string): Promise<void>;
1427
+ disconnect(deviceId: string, reason?: StateReason): Promise<void>;
1428
+ startReading(): Promise<void>;
1429
+ stopReading(): Promise<void>;
1430
+ onReaderState: (callback: (deviceId: string, event: ReaderStateEvent) => void) => void;
1431
+ onActionState: (callback: (deviceId: string, event: ActionStateEvent) => void) => void;
1432
+ onTrigger: (callback: (deviceId: string, event: TriggerEvent) => void) => void;
1433
+ onTagRead: (callback: (deviceId: string, event: TagReadEvent) => void) => void;
1434
+ onBattery: (callback: (deviceId: string, event: BatteryEvent) => void) => void;
1435
+ onTemperature: (callback: (deviceId: string, event: TemperatureEvent) => void) => void;
1436
+ };
1336
1437
  utils: {
1337
1438
  bridge: {
1338
1439
  convertBarToKpaByte: (deviceId: string, value?: number) => number;
@@ -1342,4 +1443,4 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1342
1443
  };
1343
1444
  };
1344
1445
 
1345
- export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
1446
+ export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BleUnitechRfid, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type RfidTag, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,44 @@
1
+ interface UnitechListenerHandle {
2
+ remove: () => Promise<void>;
3
+ }
4
+ interface ReaderStateEvent {
5
+ state: string;
6
+ }
7
+ interface ActionStateEvent {
8
+ state: string;
9
+ }
10
+ interface TriggerEvent {
11
+ pressed: boolean;
12
+ }
13
+ interface TagReadEvent {
14
+ epc: string;
15
+ rssi: number;
16
+ [key: string]: unknown;
17
+ }
18
+ interface BatteryEvent {
19
+ percent: number;
20
+ }
21
+ interface TemperatureEvent {
22
+ celsius: number;
23
+ }
24
+ interface UnitechRfidImplementation {
25
+ removeAllListeners: () => Promise<void>;
26
+ addListener: ((eventName: 'readerState', listener: (event: ReaderStateEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'actionState', listener: (event: ActionStateEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'trigger', listener: (event: TriggerEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'tagRead', listener: (event: TagReadEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'battery', listener: (event: BatteryEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'temperature', listener: (event: TemperatureEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>);
27
+ startDetect: (options: {
28
+ deviceName: string;
29
+ }) => Promise<void>;
30
+ stopDetect: () => Promise<void>;
31
+ connect: (options: {
32
+ bluetoothAddress?: string;
33
+ }) => Promise<{
34
+ connected: boolean;
35
+ }>;
36
+ disconnect: () => Promise<void>;
37
+ initDeviceSettings: () => Promise<void>;
38
+ startInventory: () => Promise<void>;
39
+ stopInventory: () => Promise<void>;
40
+ }
41
+
1
42
  interface BleImplementation {
2
43
  startScanWithOptions: (services: string[], options: StartScanOptions, success: (data: PeripheralData) => any, failure?: (error: string) => any) => void;
3
44
  stopScan: () => Promise<void>;
@@ -118,6 +159,11 @@ declare const _default$1: {
118
159
  };
119
160
  getDeviceInfoFromAdvertising: (device: PeripheralData) => BleTorqueWrench;
120
161
  };
162
+ unitechRfid: {
163
+ nameRegex: RegExp;
164
+ transport: "serial";
165
+ getDeviceInfoFromAdvertising: (device: PeripheralData) => BleUnitechRfid;
166
+ };
121
167
  };
122
168
 
123
169
  declare const _default: {
@@ -1095,7 +1141,7 @@ type BridgeCommandStructurized<T extends BridgeCommandStructureProperties> = {
1095
1141
  };
1096
1142
  type BleDeviceType = keyof typeof _default$1;
1097
1143
  /** distinguish by type, e.g. `if (device.type === 'bridge')`, to access furhter fields */
1098
- type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick | BleFlexiGauge | BleTorqueWrench;
1144
+ type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick | BleFlexiGauge | BleTorqueWrench | BleUnitechRfid;
1099
1145
  type BleDeviceSimulated = BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
1100
1146
  type BleDeviceStatus = 'connected' | 'connecting' | 'disconnecting' | undefined;
1101
1147
  interface BleDeviceBase {
@@ -1125,6 +1171,9 @@ interface BleFlexiGauge extends BleDeviceBase {
1125
1171
  interface BleTorqueWrench extends BleDeviceBase {
1126
1172
  type: 'torqueWrench';
1127
1173
  }
1174
+ interface BleUnitechRfid extends BleDeviceBase {
1175
+ type: 'unitechRfid';
1176
+ }
1128
1177
  interface BleBridgeOta extends BleDeviceBase {
1129
1178
  advertisingData: {
1130
1179
  bridgeId: string;
@@ -1200,12 +1249,25 @@ type Wrapper<T extends Record<string, (...args: any) => any>> = {
1200
1249
  type ReportStatusFn = (status: string, completionPercentage: number) => void;
1201
1250
  type DeviceState = 'connected' | 'connecting' | 'disconnecting' | 'paired' | undefined;
1202
1251
  type StateReason = 'lostConnection' | 'manualDisconnection' | 'failedConnection' | 'failedDisconnection' | 'firmwareUpdate' | string;
1252
+ /** A unique RFID tag aggregated across many tagRead events, keeping the strongest signal seen. */
1253
+ interface RfidTag {
1254
+ epc: string;
1255
+ rssi: number;
1256
+ }
1203
1257
  interface EventHandlers {
1204
1258
  'fg:treadDepth'?: (deviceId: string, value: number) => void;
1205
1259
  'fg:button'?: (deviceId: string, value: string) => void;
1206
1260
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
1207
1261
  'ps:pressure'?: (deviceId: string, value: number) => void;
1208
1262
  'tw:reading'?: (deviceId: string, value: TorqueWrenchReading) => void;
1263
+ 'unitech:readerState'?: (deviceId: string, event: ReaderStateEvent) => void;
1264
+ 'unitech:readerStateConnect'?: (deviceId: string, event: ReaderStateEvent) => void;
1265
+ 'unitech:actionState'?: (deviceId: string, event: ActionStateEvent) => void;
1266
+ 'unitech:trigger'?: (deviceId: string, event: TriggerEvent) => void;
1267
+ 'unitech:tag'?: (deviceId: string, event: TagReadEvent) => void;
1268
+ 'unitech:tagReadMultiple'?: (deviceId: string, tags: RfidTag[]) => void;
1269
+ 'unitech:battery'?: (deviceId: string, event: BatteryEvent) => void;
1270
+ 'unitech:temperature'?: (deviceId: string, event: TemperatureEvent) => void;
1209
1271
  'bridgeOta:status'?: (deviceId: string, status: string) => void;
1210
1272
  'bridgeOta:success'?: (deviceId: string) => void;
1211
1273
  'bridgeOta:error'?: (deviceId: string, error: string) => void;
@@ -1236,16 +1298,42 @@ interface TorqueWrenchReading {
1236
1298
  }
1237
1299
  type EventName = keyof EventHandlers;
1238
1300
 
1301
+ interface BluetoothClassicSerialDevice {
1302
+ /** Device identifier.
1303
+ * Android: device's MAC address (same value as `address`).
1304
+ * iOS: device UUID. */
1305
+ id: string;
1306
+ /** Device's MAC address (Android only). */
1307
+ address?: string;
1308
+ name: string;
1309
+ /** Bluetooth device class (Android only). */
1310
+ class?: number;
1311
+ rssi?: number;
1312
+ }
1313
+ interface BluetoothClassicSerialImplementation {
1314
+ /** Lists already paired/bonded serial devices. */
1315
+ list: () => Promise<BluetoothClassicSerialDevice[]>;
1316
+ /** Discovers nearby unpaired serial devices. Resolves with all devices found once discovery finishes.
1317
+ * For incremental results during discovery, also register `setDeviceDiscoveredListener`. */
1318
+ discoverUnpaired: () => Promise<BluetoothClassicSerialDevice[]>;
1319
+ /** Registers a listener fired for each device discovered during `discoverUnpaired`. */
1320
+ setDeviceDiscoveredListener?: (notify: (device: BluetoothClassicSerialDevice) => void) => void;
1321
+ /** Removes the listener registered via `setDeviceDiscoveredListener`. */
1322
+ clearDeviceDiscoveredListener?: () => void;
1323
+ }
1324
+
1239
1325
  /** Creates instance of SDK.
1240
1326
  * For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
1241
1327
  * If `bleImplementation` is not provided, SDK will work only with the simulator. */
1242
- declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
1328
+ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys, unitechRfidImplementation?: UnitechRfidImplementation, bluetoothClassicSerialImplementation?: BluetoothClassicSerialImplementation): {
1243
1329
  /** Generic methods common for all devices */
1244
1330
  bluetooth: {
1245
1331
  onDeviceAdvertising(callback: (device: BleDevice) => void): void;
1246
1332
  onDeviceUnreachable(callback: (deviceId: string) => void): void;
1247
1333
  onDeviceStateChange(callback: (deviceId: string, state?: DeviceState, reason?: StateReason) => void): void;
1248
1334
  scanDevices: (services?: string[], duration?: number) => Promise<void>;
1335
+ scanSerialDevicesPaired: () => Promise<void>;
1336
+ scanSerialDevicesUnpaired: () => Promise<void>;
1249
1337
  stopScan(): void;
1250
1338
  connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<void | PeripheralDataExtended>;
1251
1339
  disconnect: (deviceId: string) => Promise<void>;
@@ -1333,6 +1421,19 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1333
1421
  getTime: (deviceId: string) => Promise<Date>;
1334
1422
  onReading: (callback: (deviceId: string, value: TorqueWrenchReading) => void) => void;
1335
1423
  };
1424
+ /** Methods for working with Unitech RFID reader */
1425
+ unitechRfid: {
1426
+ connect(deviceId: string): Promise<void>;
1427
+ disconnect(deviceId: string, reason?: StateReason): Promise<void>;
1428
+ startReading(): Promise<void>;
1429
+ stopReading(): Promise<void>;
1430
+ onReaderState: (callback: (deviceId: string, event: ReaderStateEvent) => void) => void;
1431
+ onActionState: (callback: (deviceId: string, event: ActionStateEvent) => void) => void;
1432
+ onTrigger: (callback: (deviceId: string, event: TriggerEvent) => void) => void;
1433
+ onTagRead: (callback: (deviceId: string, event: TagReadEvent) => void) => void;
1434
+ onBattery: (callback: (deviceId: string, event: BatteryEvent) => void) => void;
1435
+ onTemperature: (callback: (deviceId: string, event: TemperatureEvent) => void) => void;
1436
+ };
1336
1437
  utils: {
1337
1438
  bridge: {
1338
1439
  convertBarToKpaByte: (deviceId: string, value?: number) => number;
@@ -1342,4 +1443,4 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1342
1443
  };
1343
1444
  };
1344
1445
 
1345
- export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
1446
+ export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BleUnitechRfid, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type RfidTag, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,44 @@
1
+ interface UnitechListenerHandle {
2
+ remove: () => Promise<void>;
3
+ }
4
+ interface ReaderStateEvent {
5
+ state: string;
6
+ }
7
+ interface ActionStateEvent {
8
+ state: string;
9
+ }
10
+ interface TriggerEvent {
11
+ pressed: boolean;
12
+ }
13
+ interface TagReadEvent {
14
+ epc: string;
15
+ rssi: number;
16
+ [key: string]: unknown;
17
+ }
18
+ interface BatteryEvent {
19
+ percent: number;
20
+ }
21
+ interface TemperatureEvent {
22
+ celsius: number;
23
+ }
24
+ interface UnitechRfidImplementation {
25
+ removeAllListeners: () => Promise<void>;
26
+ addListener: ((eventName: 'readerState', listener: (event: ReaderStateEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'actionState', listener: (event: ActionStateEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'trigger', listener: (event: TriggerEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'tagRead', listener: (event: TagReadEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'battery', listener: (event: BatteryEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>) & ((eventName: 'temperature', listener: (event: TemperatureEvent) => void | Promise<void>) => Promise<UnitechListenerHandle>);
27
+ startDetect: (options: {
28
+ deviceName: string;
29
+ }) => Promise<void>;
30
+ stopDetect: () => Promise<void>;
31
+ connect: (options: {
32
+ bluetoothAddress?: string;
33
+ }) => Promise<{
34
+ connected: boolean;
35
+ }>;
36
+ disconnect: () => Promise<void>;
37
+ initDeviceSettings: () => Promise<void>;
38
+ startInventory: () => Promise<void>;
39
+ stopInventory: () => Promise<void>;
40
+ }
41
+
1
42
  interface BleImplementation {
2
43
  startScanWithOptions: (services: string[], options: StartScanOptions, success: (data: PeripheralData) => any, failure?: (error: string) => any) => void;
3
44
  stopScan: () => Promise<void>;
@@ -118,6 +159,11 @@ declare const _default$1: {
118
159
  };
119
160
  getDeviceInfoFromAdvertising: (device: PeripheralData) => BleTorqueWrench;
120
161
  };
162
+ unitechRfid: {
163
+ nameRegex: RegExp;
164
+ transport: "serial";
165
+ getDeviceInfoFromAdvertising: (device: PeripheralData) => BleUnitechRfid;
166
+ };
121
167
  };
122
168
 
123
169
  declare const _default: {
@@ -1095,7 +1141,7 @@ type BridgeCommandStructurized<T extends BridgeCommandStructureProperties> = {
1095
1141
  };
1096
1142
  type BleDeviceType = keyof typeof _default$1;
1097
1143
  /** distinguish by type, e.g. `if (device.type === 'bridge')`, to access furhter fields */
1098
- type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick | BleFlexiGauge | BleTorqueWrench;
1144
+ type BleDevice = BleBridge | BleBridgeOta | BleFlexiGaugeTpms | BlePressureStick | BleFlexiGauge | BleTorqueWrench | BleUnitechRfid;
1099
1145
  type BleDeviceSimulated = BleBridgeSimulated | BleFlexiGaugeTpmsSimulated;
1100
1146
  type BleDeviceStatus = 'connected' | 'connecting' | 'disconnecting' | undefined;
1101
1147
  interface BleDeviceBase {
@@ -1125,6 +1171,9 @@ interface BleFlexiGauge extends BleDeviceBase {
1125
1171
  interface BleTorqueWrench extends BleDeviceBase {
1126
1172
  type: 'torqueWrench';
1127
1173
  }
1174
+ interface BleUnitechRfid extends BleDeviceBase {
1175
+ type: 'unitechRfid';
1176
+ }
1128
1177
  interface BleBridgeOta extends BleDeviceBase {
1129
1178
  advertisingData: {
1130
1179
  bridgeId: string;
@@ -1200,12 +1249,25 @@ type Wrapper<T extends Record<string, (...args: any) => any>> = {
1200
1249
  type ReportStatusFn = (status: string, completionPercentage: number) => void;
1201
1250
  type DeviceState = 'connected' | 'connecting' | 'disconnecting' | 'paired' | undefined;
1202
1251
  type StateReason = 'lostConnection' | 'manualDisconnection' | 'failedConnection' | 'failedDisconnection' | 'firmwareUpdate' | string;
1252
+ /** A unique RFID tag aggregated across many tagRead events, keeping the strongest signal seen. */
1253
+ interface RfidTag {
1254
+ epc: string;
1255
+ rssi: number;
1256
+ }
1203
1257
  interface EventHandlers {
1204
1258
  'fg:treadDepth'?: (deviceId: string, value: number) => void;
1205
1259
  'fg:button'?: (deviceId: string, value: string) => void;
1206
1260
  'fg:tpms'?: (deviceId: string, value: FgSensorReading | undefined) => void;
1207
1261
  'ps:pressure'?: (deviceId: string, value: number) => void;
1208
1262
  'tw:reading'?: (deviceId: string, value: TorqueWrenchReading) => void;
1263
+ 'unitech:readerState'?: (deviceId: string, event: ReaderStateEvent) => void;
1264
+ 'unitech:readerStateConnect'?: (deviceId: string, event: ReaderStateEvent) => void;
1265
+ 'unitech:actionState'?: (deviceId: string, event: ActionStateEvent) => void;
1266
+ 'unitech:trigger'?: (deviceId: string, event: TriggerEvent) => void;
1267
+ 'unitech:tag'?: (deviceId: string, event: TagReadEvent) => void;
1268
+ 'unitech:tagReadMultiple'?: (deviceId: string, tags: RfidTag[]) => void;
1269
+ 'unitech:battery'?: (deviceId: string, event: BatteryEvent) => void;
1270
+ 'unitech:temperature'?: (deviceId: string, event: TemperatureEvent) => void;
1209
1271
  'bridgeOta:status'?: (deviceId: string, status: string) => void;
1210
1272
  'bridgeOta:success'?: (deviceId: string) => void;
1211
1273
  'bridgeOta:error'?: (deviceId: string, error: string) => void;
@@ -1236,16 +1298,42 @@ interface TorqueWrenchReading {
1236
1298
  }
1237
1299
  type EventName = keyof EventHandlers;
1238
1300
 
1301
+ interface BluetoothClassicSerialDevice {
1302
+ /** Device identifier.
1303
+ * Android: device's MAC address (same value as `address`).
1304
+ * iOS: device UUID. */
1305
+ id: string;
1306
+ /** Device's MAC address (Android only). */
1307
+ address?: string;
1308
+ name: string;
1309
+ /** Bluetooth device class (Android only). */
1310
+ class?: number;
1311
+ rssi?: number;
1312
+ }
1313
+ interface BluetoothClassicSerialImplementation {
1314
+ /** Lists already paired/bonded serial devices. */
1315
+ list: () => Promise<BluetoothClassicSerialDevice[]>;
1316
+ /** Discovers nearby unpaired serial devices. Resolves with all devices found once discovery finishes.
1317
+ * For incremental results during discovery, also register `setDeviceDiscoveredListener`. */
1318
+ discoverUnpaired: () => Promise<BluetoothClassicSerialDevice[]>;
1319
+ /** Registers a listener fired for each device discovered during `discoverUnpaired`. */
1320
+ setDeviceDiscoveredListener?: (notify: (device: BluetoothClassicSerialDevice) => void) => void;
1321
+ /** Removes the listener registered via `setDeviceDiscoveredListener`. */
1322
+ clearDeviceDiscoveredListener?: () => void;
1323
+ }
1324
+
1239
1325
  /** Creates instance of SDK.
1240
1326
  * For real usage, `bleImplementation` argument must be provided - it's an object that follows method definitions from `cordova-plugin-bluetooth-central`.
1241
1327
  * If `bleImplementation` is not provided, SDK will work only with the simulator. */
1242
- declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys): {
1328
+ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplementation?: BleImplementation, securityKeys?: BleSecurityKeys, unitechRfidImplementation?: UnitechRfidImplementation, bluetoothClassicSerialImplementation?: BluetoothClassicSerialImplementation): {
1243
1329
  /** Generic methods common for all devices */
1244
1330
  bluetooth: {
1245
1331
  onDeviceAdvertising(callback: (device: BleDevice) => void): void;
1246
1332
  onDeviceUnreachable(callback: (deviceId: string) => void): void;
1247
1333
  onDeviceStateChange(callback: (deviceId: string, state?: DeviceState, reason?: StateReason) => void): void;
1248
1334
  scanDevices: (services?: string[], duration?: number) => Promise<void>;
1335
+ scanSerialDevicesPaired: () => Promise<void>;
1336
+ scanSerialDevicesUnpaired: () => Promise<void>;
1249
1337
  stopScan(): void;
1250
1338
  connect: (deviceId: string, disconnectCallback: (deviceId: string) => void) => Promise<void | PeripheralDataExtended>;
1251
1339
  disconnect: (deviceId: string) => Promise<void>;
@@ -1333,6 +1421,19 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1333
1421
  getTime: (deviceId: string) => Promise<Date>;
1334
1422
  onReading: (callback: (deviceId: string, value: TorqueWrenchReading) => void) => void;
1335
1423
  };
1424
+ /** Methods for working with Unitech RFID reader */
1425
+ unitechRfid: {
1426
+ connect(deviceId: string): Promise<void>;
1427
+ disconnect(deviceId: string, reason?: StateReason): Promise<void>;
1428
+ startReading(): Promise<void>;
1429
+ stopReading(): Promise<void>;
1430
+ onReaderState: (callback: (deviceId: string, event: ReaderStateEvent) => void) => void;
1431
+ onActionState: (callback: (deviceId: string, event: ActionStateEvent) => void) => void;
1432
+ onTrigger: (callback: (deviceId: string, event: TriggerEvent) => void) => void;
1433
+ onTagRead: (callback: (deviceId: string, event: TagReadEvent) => void) => void;
1434
+ onBattery: (callback: (deviceId: string, event: BatteryEvent) => void) => void;
1435
+ onTemperature: (callback: (deviceId: string, event: TemperatureEvent) => void) => void;
1436
+ };
1336
1437
  utils: {
1337
1438
  bridge: {
1338
1439
  convertBarToKpaByte: (deviceId: string, value?: number) => number;
@@ -1342,4 +1443,4 @@ declare function createTirecheckDeviceSdk(platform: DevicePlatform, bleImplement
1342
1443
  };
1343
1444
  };
1344
1445
 
1345
- export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
1446
+ export { type BleBridge, type BleBridgeAdvertisingData, type BleBridgeOta, type BleBridgeSimulated, type BleDevice, type BleDeviceBase, type BleDeviceSimulated, type BleDeviceStatus, type BleDeviceType, type BleFlexiGauge, type BleFlexiGaugeTpms, type BleFlexiGaugeTpmsSimulated, type BlePressureStick, type BleSecurityKeys, type BleTorqueWrench, type BleUnitechRfid, type BridgeAccessLevel, type BridgeAutolearnStatus, type BridgeCommandStructure, type BridgeCommandStructureProperties, type BridgeCommandStructurized, type BridgeConfiguration, type BridgeReading, type BridgeTcIssue, type BridgeTcTyre, type BridgeTcVehicle, BridgeTcVehicleAxle, type DeepPartial, type DevicePlatform, type DeviceState, type EventHandlers, type EventName, type FgConfig, type FgConfigNeedleLength, type FgConfigPressureDisplay, type FgConfigPressureUnit, type FgConfigRegion, type FgConfigTdUnit, type FgConfigTemperatureUnit, type FgSensorReading, type FgTpmsConfig, type FgTpmsConfigProtocol, type FgTpmsConfigProtocolSetting, type PositionInfo, type ReportStatusFn, type RfidTag, type Simulator, type StateReason, type TorqueWrenchProperties, type TorqueWrenchReading, type TorqueWrenchStartJobParams, type Wrapper, createTirecheckDeviceSdk };
package/dist/index.mjs CHANGED
@@ -127,6 +127,19 @@ function normalizeError(error) {
127
127
  return error;
128
128
  }
129
129
 
130
+ const emptyBluetoothClassicSerialImplementation = {
131
+ list: async () => [],
132
+ discoverUnpaired: async () => [],
133
+ setDeviceDiscoveredListener: () => {
134
+ },
135
+ clearDeviceDiscoveredListener: () => {
136
+ }
137
+ };
138
+ let bluetoothClassicSerial = emptyBluetoothClassicSerialImplementation;
139
+ function setBluetoothClassicSerialImplementation(bluetoothClassicSerialImplementation) {
140
+ bluetoothClassicSerial = bluetoothClassicSerialImplementation ?? emptyBluetoothClassicSerialImplementation;
141
+ }
142
+
130
143
  const tyreLabels = getDefaultTyreLabels();
131
144
  const bridgeTools = {
132
145
  getBridgeFromStore,
@@ -650,6 +663,17 @@ const deviceMeta = {
650
663
  };
651
664
  return bleDevice;
652
665
  }
666
+ },
667
+ unitechRfid: {
668
+ nameRegex: /^RP902/i,
669
+ transport: "serial",
670
+ getDeviceInfoFromAdvertising: (device) => {
671
+ const bleDevice = {
672
+ ...device,
673
+ type: "unitechRfid"
674
+ };
675
+ return bleDevice;
676
+ }
653
677
  }
654
678
  };
655
679
 
@@ -686,6 +710,8 @@ const bluetooth = {
686
710
  deviceStateChangeCallback = callback;
687
711
  },
688
712
  scanDevices,
713
+ scanSerialDevicesPaired,
714
+ scanSerialDevicesUnpaired,
689
715
  stopScan() {
690
716
  ble.stopScan();
691
717
  },
@@ -716,6 +742,47 @@ async function scanDevices(services = [], duration) {
716
742
  (e) => console.error("ble.startScanWithOptions error:", e)
717
743
  );
718
744
  }
745
+ async function scanSerialDevicesPaired() {
746
+ try {
747
+ const pairedDevices = await bluetoothClassicSerial.list();
748
+ for (const device of pairedDevices ?? []) handleSerialDevice(device);
749
+ } catch (e) {
750
+ console.error("scanPairedSerialDevices error:", e);
751
+ }
752
+ }
753
+ async function scanSerialDevicesUnpaired() {
754
+ bluetoothClassicSerial.setDeviceDiscoveredListener?.((device) => handleSerialDevice(device));
755
+ try {
756
+ const unpairedDevices = await bluetoothClassicSerial.discoverUnpaired();
757
+ for (const device of unpairedDevices ?? []) handleSerialDevice(device);
758
+ } catch (e) {
759
+ const message = (typeof e === "string" ? e : e?.message ?? "").toLowerCase();
760
+ const pickerDismissed = store.platform === "ios" && ["cancel", "alreadyconnected", "already connected", "notfound", "not found"].some((m) => message.includes(m));
761
+ if (pickerDismissed) {
762
+ console.log("discoverSerialDevices: accessory picker returned no unpaired device -", message);
763
+ } else {
764
+ console.error("discoverSerialDevices error:", e);
765
+ }
766
+ } finally {
767
+ bluetoothClassicSerial.clearDeviceDiscoveredListener?.();
768
+ }
769
+ }
770
+ function handleSerialDevice(device) {
771
+ const rawId = device.id ?? device.address;
772
+ const id = rawId != null ? String(rawId) : void 0;
773
+ if (!id) {
774
+ console.warn("handleSerialDevice: skipped, no id/address", device);
775
+ return;
776
+ }
777
+ const peripheral = { id, name: device.name, rssi: device.rssi ?? 0, advertising: {} };
778
+ const processedDevice = processDevice(peripheral);
779
+ if (!processedDevice) {
780
+ console.warn("handleSerialDevice: processDevice returned null (filtered out)", id, device.name);
781
+ return;
782
+ }
783
+ store.devices[processedDevice.id] = processedDevice;
784
+ deviceAdvertisingCallback?.(processedDevice);
785
+ }
719
786
  async function connect$1(deviceId, disconnectCallback) {
720
787
  if (toolsSvc.canCommunicateWith(deviceId)) return console.warn("Connect Warn: Already connected to device");
721
788
  store.setState(deviceId, "connecting");
@@ -804,7 +871,8 @@ function processDevice(device) {
804
871
  console.warn("Error processing advertising", e);
805
872
  return;
806
873
  }
807
- unreachableSvc.refresh(processedDevice.id, deviceUnreachableCallback);
874
+ const isSerial = deviceMeta[deviceType].transport === "serial";
875
+ if (!isSerial) unreachableSvc.refresh(processedDevice.id, deviceUnreachableCallback);
808
876
  return processedDevice;
809
877
  }
810
878
  function getDeviceTypeFromName(name) {
@@ -4153,6 +4221,95 @@ const torqueWrench = {
4153
4221
  onReading: torqueWrenchService.onReading
4154
4222
  };
4155
4223
 
4224
+ let unitech;
4225
+ function setUnitechRfidImplementation(unitechRfidImplementation) {
4226
+ if (!unitechRfidImplementation)
4227
+ return console.warn("Unitech RFID implementation is not provided, Unitech RFID functionality will not work");
4228
+ unitech = unitechRfidImplementation;
4229
+ }
4230
+
4231
+ const unitechRfidService = {
4232
+ subscribeListeners(deviceId) {
4233
+ unitech.addListener("readerState", (event) => {
4234
+ simulatorSvc.triggerEvent("unitech:readerState", deviceId, event);
4235
+ simulatorSvc.triggerEvent("unitech:readerStateConnect", deviceId, event);
4236
+ });
4237
+ unitech.addListener("actionState", (event) => simulatorSvc.triggerEvent("unitech:actionState", deviceId, event));
4238
+ unitech.addListener("trigger", (event) => simulatorSvc.triggerEvent("unitech:trigger", deviceId, event));
4239
+ unitech.addListener("tagRead", (event) => simulatorSvc.triggerEvent("unitech:tag", deviceId, event));
4240
+ unitech.addListener("battery", (event) => simulatorSvc.triggerEvent("unitech:battery", deviceId, event));
4241
+ unitech.addListener("temperature", (event) => simulatorSvc.triggerEvent("unitech:temperature", deviceId, event));
4242
+ },
4243
+ onReaderState(callback) {
4244
+ simulatorSvc.registerEvent("unitech:readerState", callback);
4245
+ },
4246
+ onActionState(callback) {
4247
+ simulatorSvc.registerEvent("unitech:actionState", callback);
4248
+ },
4249
+ onTrigger(callback) {
4250
+ simulatorSvc.registerEvent("unitech:trigger", callback);
4251
+ },
4252
+ onTagRead(callback) {
4253
+ simulatorSvc.registerEvent("unitech:tag", callback);
4254
+ },
4255
+ onBattery(callback) {
4256
+ simulatorSvc.registerEvent("unitech:battery", callback);
4257
+ },
4258
+ onTemperature(callback) {
4259
+ simulatorSvc.registerEvent("unitech:temperature", callback);
4260
+ }
4261
+ };
4262
+
4263
+ const unitechRfid = {
4264
+ async connect(deviceId) {
4265
+ const unitechDevices = Object.values(store.devices).filter((d) => d.type === "unitechRfid");
4266
+ for (const device2 of unitechDevices) {
4267
+ if (device2.id !== deviceId && store.deviceState[device2.id] === "paired") {
4268
+ await this.disconnect(device2.id, "manualDisconnection");
4269
+ }
4270
+ }
4271
+ store.setState(deviceId, "connecting");
4272
+ await unitech.removeAllListeners();
4273
+ const device = store.devices[deviceId];
4274
+ if (store.platform === "ios") {
4275
+ await unitech.startDetect({ deviceName: device.name });
4276
+ await toolsSvc.delay(500);
4277
+ await unitech.stopDetect();
4278
+ }
4279
+ const { connected } = await unitech.connect({ bluetoothAddress: device.id });
4280
+ if (!connected) throw new Error("UnitechRfid Error: Unable to connect to the device.");
4281
+ await unitechRfidService.subscribeListeners(deviceId);
4282
+ await withTimeout(
4283
+ new Promise((resolve) => {
4284
+ simulatorSvc.registerEvent("unitech:readerStateConnect", (_deviceId, event) => {
4285
+ if (event.state?.toLowerCase() === "connected") resolve();
4286
+ });
4287
+ }),
4288
+ 15e3
4289
+ );
4290
+ await unitech.initDeviceSettings();
4291
+ store.setState(deviceId, "paired");
4292
+ },
4293
+ async disconnect(deviceId, reason) {
4294
+ store.setState(deviceId, "disconnecting");
4295
+ await unitech.removeAllListeners();
4296
+ await unitech.disconnect();
4297
+ store.setState(deviceId, void 0, reason ?? "manualDisconnection");
4298
+ },
4299
+ async startReading() {
4300
+ await unitech.startInventory();
4301
+ },
4302
+ async stopReading() {
4303
+ await unitech.stopInventory();
4304
+ },
4305
+ onReaderState: unitechRfidService.onReaderState,
4306
+ onActionState: unitechRfidService.onActionState,
4307
+ onTrigger: unitechRfidService.onTrigger,
4308
+ onTagRead: unitechRfidService.onTagRead,
4309
+ onBattery: unitechRfidService.onBattery,
4310
+ onTemperature: unitechRfidService.onTemperature
4311
+ };
4312
+
4156
4313
  const bridgeSimulator = {
4157
4314
  isRebootRequired(deviceId) {
4158
4315
  return store.bridgeRebootRequired[deviceId];
@@ -4794,11 +4951,13 @@ class BridgeTcVehicleAxle {
4794
4951
  minTargetPressure;
4795
4952
  }
4796
4953
 
4797
- function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
4954
+ function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys, unitechRfidImplementation, bluetoothClassicSerialImplementation) {
4798
4955
  store.platform = platform;
4799
4956
  bleImplementation = bleImplementation || emptyBleImplementation;
4800
4957
  store.securityKeys = securityKeys || {};
4801
4958
  setBleImplementation(bleImplementation);
4959
+ setUnitechRfidImplementation(unitechRfidImplementation);
4960
+ setBluetoothClassicSerialImplementation(bluetoothClassicSerialImplementation);
4802
4961
  return {
4803
4962
  /** Generic methods common for all devices */
4804
4963
  bluetooth,
@@ -4816,6 +4975,8 @@ function createTirecheckDeviceSdk(platform, bleImplementation, securityKeys) {
4816
4975
  simulator,
4817
4976
  /** Methods for working with Tirecheck Torque Wrench */
4818
4977
  torqueWrench,
4978
+ /** Methods for working with Unitech RFID reader */
4979
+ unitechRfid,
4819
4980
  utils: {
4820
4981
  bridge: {
4821
4982
  convertBarToKpaByte: bridgeTools.convertBarToKpaByte,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirecheck-device-sdk",
3
- "version": "0.2.70",
3
+ "version": "0.2.71",
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",