@bota-dev/react-native-sdk 0.0.10 → 0.0.12
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/README.md +12 -0
- package/lib/commonjs/ble/BleManager.js +15 -8
- package/lib/commonjs/ble/BleManager.js.map +1 -1
- package/lib/commonjs/ble/constants.js +3 -2
- package/lib/commonjs/ble/constants.js.map +1 -1
- package/lib/commonjs/ble/parsers.js +4 -1
- package/lib/commonjs/ble/parsers.js.map +1 -1
- package/lib/commonjs/managers/DeviceManager.js +25 -0
- package/lib/commonjs/managers/DeviceManager.js.map +1 -1
- package/lib/module/ble/BleManager.js +15 -8
- package/lib/module/ble/BleManager.js.map +1 -1
- package/lib/module/ble/constants.js +1 -0
- package/lib/module/ble/constants.js.map +1 -1
- package/lib/module/ble/parsers.js +4 -1
- package/lib/module/ble/parsers.js.map +1 -1
- package/lib/module/managers/DeviceManager.js +26 -1
- package/lib/module/managers/DeviceManager.js.map +1 -1
- package/lib/typescript/src/ble/BleManager.d.ts.map +1 -1
- package/lib/typescript/src/ble/constants.d.ts +1 -0
- package/lib/typescript/src/ble/constants.d.ts.map +1 -1
- package/lib/typescript/src/ble/parsers.d.ts +2 -1
- package/lib/typescript/src/ble/parsers.d.ts.map +1 -1
- package/lib/typescript/src/managers/DeviceManager.d.ts +6 -0
- package/lib/typescript/src/managers/DeviceManager.d.ts.map +1 -1
- package/lib/typescript/src/models/Device.d.ts +2 -0
- package/lib/typescript/src/models/Device.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ble/BleManager.ts +15 -10
- package/src/ble/constants.ts +1 -0
- package/src/ble/parsers.ts +4 -1
- package/src/managers/DeviceManager.ts +33 -0
- package/src/models/Device.ts +2 -0
package/src/ble/BleManager.ts
CHANGED
|
@@ -341,7 +341,7 @@ export class BleManager extends EventEmitter<BleManagerEvents> {
|
|
|
341
341
|
this.emit(
|
|
342
342
|
'deviceDisconnected',
|
|
343
343
|
disconnectedDevice.id,
|
|
344
|
-
error ? new Error(error.message) : undefined
|
|
344
|
+
error ? new Error(error.message || 'Device disconnected') : undefined
|
|
345
345
|
);
|
|
346
346
|
});
|
|
347
347
|
this.disconnectSubscriptions.set(deviceId, disconnectSub);
|
|
@@ -350,8 +350,9 @@ export class BleManager extends EventEmitter<BleManagerEvents> {
|
|
|
350
350
|
return device;
|
|
351
351
|
} catch (error) {
|
|
352
352
|
const bleError = error as BleError;
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
const msg = bleError.message || 'Connection failed';
|
|
354
|
+
log.error('Connection failed', new Error(msg), { deviceId });
|
|
355
|
+
throw DeviceError.connectionFailed(deviceId, new Error(msg));
|
|
355
356
|
}
|
|
356
357
|
}
|
|
357
358
|
|
|
@@ -436,16 +437,17 @@ export class BleManager extends EventEmitter<BleManagerEvents> {
|
|
|
436
437
|
return Buffer.from(characteristic.value, 'base64');
|
|
437
438
|
} catch (error) {
|
|
438
439
|
const bleError = error as BleError;
|
|
439
|
-
|
|
440
|
+
const msg = bleError.message || 'Unknown BLE error';
|
|
441
|
+
log.error('Read characteristic failed', new Error(msg), {
|
|
440
442
|
deviceId,
|
|
441
443
|
serviceUuid,
|
|
442
444
|
characteristicUuid,
|
|
443
445
|
});
|
|
444
446
|
throw new DeviceError(
|
|
445
|
-
`Failed to read characteristic: ${
|
|
447
|
+
`Failed to read characteristic: ${msg}`,
|
|
446
448
|
'READ_FAILED',
|
|
447
449
|
deviceId,
|
|
448
|
-
new Error(
|
|
450
|
+
new Error(msg)
|
|
449
451
|
);
|
|
450
452
|
}
|
|
451
453
|
}
|
|
@@ -483,16 +485,17 @@ export class BleManager extends EventEmitter<BleManagerEvents> {
|
|
|
483
485
|
}
|
|
484
486
|
} catch (error) {
|
|
485
487
|
const bleError = error as BleError;
|
|
486
|
-
|
|
488
|
+
const msg = bleError.message || 'Unknown BLE error';
|
|
489
|
+
log.error('Write characteristic failed', new Error(msg), {
|
|
487
490
|
deviceId,
|
|
488
491
|
serviceUuid,
|
|
489
492
|
characteristicUuid,
|
|
490
493
|
});
|
|
491
494
|
throw new DeviceError(
|
|
492
|
-
`Failed to write characteristic: ${
|
|
495
|
+
`Failed to write characteristic: ${msg}`,
|
|
493
496
|
'WRITE_FAILED',
|
|
494
497
|
deviceId,
|
|
495
|
-
new Error(
|
|
498
|
+
new Error(msg)
|
|
496
499
|
);
|
|
497
500
|
}
|
|
498
501
|
}
|
|
@@ -521,7 +524,9 @@ export class BleManager extends EventEmitter<BleManagerEvents> {
|
|
|
521
524
|
const errorMessage = error.message || 'Unknown BLE error';
|
|
522
525
|
const isCancelled = errorMessage.includes('cancelled') ||
|
|
523
526
|
errorMessage.includes('disconnected') ||
|
|
524
|
-
error.errorCode === 2
|
|
527
|
+
error.errorCode === 2 || // BleErrorCode.OperationCancelled
|
|
528
|
+
error.errorCode === 201 || // BleErrorCode.DeviceDisconnected
|
|
529
|
+
!this.connectedDevices.has(deviceId); // Device already removed
|
|
525
530
|
|
|
526
531
|
if (!isCancelled) {
|
|
527
532
|
log.error('Notification error', new Error(errorMessage), {
|
package/src/ble/constants.ts
CHANGED
|
@@ -126,6 +126,7 @@ export const ACK_TYPE_NACK = 0x11;
|
|
|
126
126
|
export const ACK_TYPE_ABORT = 0x12;
|
|
127
127
|
|
|
128
128
|
// Device command values
|
|
129
|
+
export const DEVICE_CMD_FACTORY_RESET = 0x01;
|
|
129
130
|
export const DEVICE_CMD_ENTER_DFU = 0x03;
|
|
130
131
|
|
|
131
132
|
// Recording control opcodes (for remote start/stop)
|
package/src/ble/parsers.ts
CHANGED
|
@@ -154,7 +154,8 @@ export function parseDeviceFlags(value: number): DeviceFlags {
|
|
|
154
154
|
* Byte 3: Pending recordings count
|
|
155
155
|
* Bytes 4-7: Last sync timestamp (Unix seconds)
|
|
156
156
|
* Byte 8: Flags (1-byte bitmask)
|
|
157
|
-
* Bytes 9-
|
|
157
|
+
* Bytes 9-10: Storage total MB (uint16LE)
|
|
158
|
+
* Byte 11: Reserved
|
|
158
159
|
*/
|
|
159
160
|
export function parseDeviceStatus(data: Buffer): DeviceStatus {
|
|
160
161
|
if (data.length < 12) {
|
|
@@ -168,10 +169,12 @@ export function parseDeviceStatus(data: Buffer): DeviceStatus {
|
|
|
168
169
|
const lastSyncTimestamp = data.readUInt32LE(4);
|
|
169
170
|
const flagsValue = data.readUInt8(8);
|
|
170
171
|
const flags = parseDeviceFlags(flagsValue);
|
|
172
|
+
const storageTotalMb = data.readUInt16LE(9);
|
|
171
173
|
|
|
172
174
|
return {
|
|
173
175
|
batteryLevel,
|
|
174
176
|
storageUsedPercent,
|
|
177
|
+
storageTotalMb,
|
|
175
178
|
state,
|
|
176
179
|
pendingRecordings,
|
|
177
180
|
lastSyncAt: lastSyncTimestamp > 0 ? new Date(lastSyncTimestamp * 1000) : null,
|
|
@@ -40,6 +40,8 @@ import {
|
|
|
40
40
|
RECORDING_RESULT_NOT_RECORDING,
|
|
41
41
|
RECORDING_RESULT_INVALID_GRANT,
|
|
42
42
|
RECORDING_RESULT_GRANT_EXPIRED,
|
|
43
|
+
CHAR_DEVICE_COMMAND,
|
|
44
|
+
DEVICE_CMD_FACTORY_RESET,
|
|
43
45
|
} from '../ble/constants';
|
|
44
46
|
import {
|
|
45
47
|
parsePairingState,
|
|
@@ -247,6 +249,37 @@ export class DeviceManager extends EventEmitter<DeviceManagerEvents> {
|
|
|
247
249
|
this.emit('connectionStateChanged', device.id, 'disconnected');
|
|
248
250
|
}
|
|
249
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Send factory reset command to a device.
|
|
254
|
+
* Clears stored token and recordings on the device.
|
|
255
|
+
* Device returns to unpaired state after this.
|
|
256
|
+
*/
|
|
257
|
+
async factoryReset(device: ConnectedDevice): Promise<void> {
|
|
258
|
+
log.info('Sending factory reset to device', { deviceId: device.id });
|
|
259
|
+
|
|
260
|
+
if (!this.isConnected(device.id)) {
|
|
261
|
+
throw DeviceError.notConnected(device.id);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const resultPromise = this.waitForProvisioningResult(device.id);
|
|
265
|
+
|
|
266
|
+
await this.bleManager.writeCharacteristic(
|
|
267
|
+
device.id,
|
|
268
|
+
SERVICE_BOTA_CONTROL,
|
|
269
|
+
CHAR_DEVICE_COMMAND,
|
|
270
|
+
Buffer.from([DEVICE_CMD_FACTORY_RESET])
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
try {
|
|
274
|
+
await resultPromise;
|
|
275
|
+
} catch {
|
|
276
|
+
// Timeout is acceptable — device may disconnect before responding
|
|
277
|
+
log.warn('Factory reset result not received (device may have disconnected)');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
log.info('Factory reset sent', { deviceId: device.id });
|
|
281
|
+
}
|
|
282
|
+
|
|
250
283
|
/**
|
|
251
284
|
* Check if a device is connected
|
|
252
285
|
*/
|
package/src/models/Device.ts
CHANGED
|
@@ -117,6 +117,8 @@ export interface DeviceStatus {
|
|
|
117
117
|
batteryLevel: number;
|
|
118
118
|
/** Storage used percentage (0-100) */
|
|
119
119
|
storageUsedPercent: number;
|
|
120
|
+
/** Total storage capacity in MB (from firmware, uint16LE, max 65535) */
|
|
121
|
+
storageTotalMb: number;
|
|
120
122
|
/** Current operational state */
|
|
121
123
|
state: DeviceState;
|
|
122
124
|
/** Number of pending recordings to sync */
|