expo-ble模块测试demo 联调BLE模块 take 9 新增类型检查

This commit is contained in:
Yudi Xiao 2025-12-11 13:56:44 +08:00
parent 675036f07c
commit f816165779
1 changed files with 3 additions and 1 deletions

View File

@ -139,10 +139,12 @@ export class BleProtocolService {
}
}
public async send(deviceId: string, type: COMMAND_TYPES, data: object | ArrayBuffer, onProgress?: (progress: number) => void): Promise<void> {
public async send(deviceId: string, type: COMMAND_TYPES, data: object | ArrayBuffer | Uint8Array, onProgress?: (progress: number) => void): Promise<void> {
let payload: Uint8Array;
if (data instanceof ArrayBuffer) {
payload = new Uint8Array(data);
} else if (data instanceof Uint8Array) {
payload = data;
} else {
const jsonStr = JSON.stringify(data);
payload = new Uint8Array(Buffer.from(jsonStr));