Commit c5620057 authored by martin hou's avatar martin hou

feat: 增加已配对设备列表的查询和设备回连消息

parent 86838102
......@@ -55,8 +55,8 @@ export type BluetoothStatus = {
export type BluetoothDevice = {
name: string; // 设备名称
mac: string; // 设备MAC地址
rssi: number; // 设备信号强度
cod: number; // 设备类型编码
rssi?: number; // 设备信号强度
cod?: number; // 设备类型编码
};
// 操作系统枚举
......@@ -285,6 +285,12 @@ declare class Jensen {
// 写入蓝牙设备列表
writeBluetoothDeviceList: (mac_list: string[], seconds?: number) => Promise<ReturnStruct['common']>;
// 获取已配对的蓝牙设备列表
getPairedDevices: (seconds?: number) => Promise<BluetoothDevice[]>;
// 设备回连
reconnectDevice: (mac: string, seconds?: number) => Promise<ReturnStruct['common']>;
// 获取实时音频流的设置信息,主要是确定设备端的实时音频的编码信息
getRealtimeSettings: () => Promise<any>;
......
......@@ -38,7 +38,7 @@ const BLUETOOTH_STATUS = 0x1003;
const BT_SCAN = 0x1005;
const BT_DEV_LIST = 0x1006;
const BT_WRITE_DEV_LIST = 0x1007;
const BT_GET_PAIRED_DEV_LIST = 0x1007;
const TEST_SN_WRITE = 0xf007;
const RECORD_TEST_START = 0xf008;
......@@ -728,6 +728,22 @@ Jensen.prototype.getScanResults = async function (seconds) {
return this.send(new Command(BT_DEV_LIST), seconds);
};
// 获取已配对的蓝牙设备列表
Jensen.prototype.getPairedDevices = async function (seconds) {
if (this.model.indexOf('hidock-p1') == -1) return null;
return this.send(new Command(BT_GET_PAIRED_DEV_LIST), seconds);
};
// 设备回连
Jensen.prototype.reconnectDevice = async function (mac, seconds) {
if (this.model.indexOf('hidock-p1') == -1) return null;
let marr = mac.split('-');
if (marr.length != 6) throw new Error('invalid mac');
let addr = [];
for (let i = 0; i < marr.length; i++) addr[i] = parseInt(marr[i], 16);
return this.send(new Command(BLUETOOTH_CMD).body([0x03].concat(addr)), seconds);
}
Jensen.prototype.setWebUSBTimeout = async function (timeout, seconds)
{
let data = [];
......@@ -1502,6 +1518,30 @@ Jensen.registerHandler(BLUETOOTH_SCAN, (msg) => {
return devices;
});
Jensen.registerHandler(BT_GET_PAIRED_DEV_LIST, (msg) => {
if (msg.body.length == 0) return [];
let nums = ((msg.body[0] & 0xff) << 8) | (msg.body[1] & 0xff);
let devices = [];
let decoder = new TextDecoder('UTF-8');
for (let i = 0, k = 2; i < nums; i++) {
let len = ((msg.body[k++] & 0xff) << 8) | (msg.body[k++] & 0xff);
let sname = new Uint8Array(len);
for (let f = 0; f < len; f++) {
sname[f] = msg.body[k++] & 0xff;
}
let mac = [];
for (let f = 0; f < 6; f++) {
let m = (msg.body[k++] & 0xff).toString(16).toUpperCase();
mac.push(m.length == 1 ? '0' + m : m);
}
devices.push({
name: decoder.decode(sname),
mac: mac.join('-')
});
}
return devices;
});
Jensen.registerHandler(BLUETOOTH_STATUS, (msg) => {
if (msg.body.length == 0) return { status: 'disconnected' };
let status = msg.body[0];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment