forked from yudi_xiao/expo-ble-app-demo
expo-ble模块测试demo 联调BLE模块 take 9 新增类型检查
This commit is contained in:
parent
675036f07c
commit
f816165779
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in New Issue