ble_manager.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. // 引入必要的微信小程序 API
  2. // const wx = require('wx');
  3. class bleManager {
  4. constructor() {
  5. var that = this;
  6. that.isAvailable = false;
  7. that.hasPermission = false;
  8. that.scanDevices = [];
  9. that.publicDevice = null;
  10. that.compareList = [];
  11. that.connectWillDevice = null;
  12. that.callBackConnect = null;
  13. that.requestBlueTime = 0;
  14. ///正在执行扫描中
  15. that.doStartScaning = false;
  16. }
  17. ///获取比较的数据
  18. getCompareList() {
  19. return this.compareList;
  20. }
  21. setConnectWillDevice(connectWillDevice) {
  22. this.connectWillDevice = connectWillDevice;
  23. }
  24. getCallBackConnect() {
  25. return this.callBackConnect;
  26. }
  27. setCallBackConnect(callBackConnect) {
  28. this.callBackConnect = callBackConnect;
  29. }
  30. /// 监控蓝牙打开状态
  31. initBluetoothAdapter() {
  32. var that = this;
  33. wx.openBluetoothAdapter({
  34. success: (res) => {
  35. that.isAvailable = true;
  36. },
  37. fail: (err) => {
  38. that.isAvailable = false;
  39. }
  40. });
  41. wx.onBluetoothAdapterStateChange(function (res) {
  42. that.isAvailable = res.available;
  43. })
  44. }
  45. ///监听搜索设备列表
  46. getBluetoothDevices() {
  47. var that = this;
  48. wx.onBluetoothDeviceFound(function (res) {
  49. ///第一种情况
  50. if (res.deviceId) {
  51. if (that.callBackConnect != null) {
  52. if (that.connectWillDevice != null && res.name == that.connectWillDevice.clientType) {
  53. res.advertisData = res.advertisData ? that.buf2hex(res.advertisData) : '';
  54. that.callBackConnect(res);
  55. }
  56. } else {
  57. if (res.name != "") {
  58. if (that.compareList.length > 0) {
  59. var has = false;
  60. for (var i = 0; i < that.compareList.length; i++) {
  61. if (res.deviceId == that.compareList[i].deviceId) {
  62. has = true;
  63. break;
  64. }
  65. }
  66. if (!has) {
  67. that.compareList.push(res);
  68. }
  69. } else {
  70. that.compareList.push(res);
  71. }
  72. }
  73. }
  74. }
  75. ///第二种情况
  76. else if (res.devices) {
  77. if (that.callBackConnect != null) {
  78. for (var i = 0; i < res.devices.length; i++) {
  79. var temp = res.devices[i];
  80. if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
  81. temp.advertisData = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
  82. that.callBackConnect(temp);
  83. break;
  84. }
  85. }
  86. } else {
  87. for (var i = 0; i < res.devices.length; i++) {
  88. if (that.compareList.length > 0) {
  89. var has = false;
  90. for (var j = 0; j < that.compareList.length; j++) {
  91. if (res.devices[i].name != "") {
  92. if (res.devices[i].deviceId == that.compareList[j].deviceId) {
  93. has = true;
  94. break;
  95. }
  96. }
  97. }
  98. if (!has) {
  99. that.compareList.push(res.devices[i]);
  100. }
  101. } else {
  102. that.compareList.push(res.devices[i]);
  103. }
  104. }
  105. }
  106. }
  107. ///第三种情况
  108. else if (res[0]) {
  109. if (that.callBackConnect != null) {
  110. if (that.connectWillDevice != null && res[0].name == that.connectWillDevice.clientType) {
  111. res[0].advertisData = res[0].advertisData ? that.buf2hex(res[0].advertisData) : '';
  112. that.callBackConnect(res[0]);
  113. }
  114. } else {
  115. if (res[0].name != "") {
  116. if (that.compareList.length > 0) {
  117. var has = false;
  118. for (var i = 0; i < that.compareList.length; i++) {
  119. if (res[0].deviceId == that.compareList[i].deviceId) {
  120. has = true;
  121. break;
  122. }
  123. }
  124. if (!has) {
  125. that.compareList.push(res[0]);
  126. }
  127. } else {
  128. that.compareList.push(res[0]);
  129. }
  130. }
  131. }
  132. }
  133. });
  134. }
  135. ///获取已连接的设备
  136. getConnectedDevices() {
  137. wx.getBluetoothDevices({
  138. success: (res) => {
  139. if (res.devices && res.devices.length > 0) {
  140. for (var i = 0; i < res.devices.length; i++) {
  141. var temp = res.devices[i];
  142. if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
  143. temp.advertisData = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
  144. that.callBackConnect(temp);
  145. break;
  146. }
  147. }
  148. }
  149. },
  150. fail: (err) => {
  151. console.error('获取蓝牙设备列表失败', err);
  152. }
  153. });
  154. }
  155. ///获取数据
  156. buf2hex(buffer) {
  157. return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
  158. }
  159. ///获取毫秒
  160. getCurrentMills() {
  161. var currentDate = new Date();
  162. var currentTimeMillis = currentDate.getTime();
  163. // return Math.floor(currentTimeMillis / 1000);
  164. return currentTimeMillis;
  165. }
  166. // 等待多少秒
  167. delay(ms) {
  168. return new Promise(resolve => setTimeout(resolve, ms));
  169. }
  170. // 开始搜索蓝牙设备
  171. async startScan(connectWillDevice, boolean, callBackConnect) {
  172. var that = this;
  173. if (that.doStartScaning == true) {
  174. if (boolean != null) {
  175. boolean(false);
  176. }
  177. return;
  178. }
  179. that.doStartScaning = true;
  180. // const route_util = require('../utils/route_util');
  181. // const route_constant = require('../utils/route_constant');
  182. // const indexRoot = route_constant.indexRoot;
  183. // const connectBleRoot = route_constant.connectBleRoot;
  184. // var lastPageRoute = route_util.getLastPageRoute();
  185. // if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
  186. // return;
  187. // }
  188. // if (!that.isAvailable) {
  189. // if (lastPageRoute == connectBleRoot) {
  190. // wx.showToast({
  191. // title: '蓝牙未打开',
  192. // icon: "none",
  193. // duration: 2000
  194. // })
  195. // }
  196. // return;
  197. // }
  198. ///蓝牙连接 做限制
  199. // if (lastPageRoute == indexRoot) {
  200. // if (that.doStartScaning == true) {
  201. // return;
  202. // }
  203. // }
  204. // that.doStartScaning = true;
  205. // var currentMill = that.getCurrentMills();
  206. // var waitMills = 0;
  207. // var reduce = currentMill - that.requestBlueTime;
  208. // const delayMiliis = 5 * 1000;
  209. // if (reduce > 0 && reduce < delayMiliis) {
  210. // waitMills = delayMiliis - reduce;
  211. // }
  212. // if (waitMills > 0) {
  213. // await that.delay(waitMills);
  214. // }
  215. // if (callBackConnect == null && lastPageRoute == connectBleRoot) {
  216. // that.doStartScaning = false;
  217. // return;
  218. // }
  219. wx.stopBluetoothDevicesDiscovery({
  220. success: (res) => {
  221. wx.startBluetoothDevicesDiscovery({
  222. allowDuplicatesKey: true,
  223. success: function (res) {
  224. that.getConnectedDevices();
  225. that.doStartScaning = false;
  226. that.requestBlueTime = that.getCurrentMills();
  227. if (boolean != null) {
  228. boolean(true);
  229. }
  230. that.setConnectWillDevice(connectWillDevice);
  231. that.setCallBackConnect(callBackConnect);
  232. that.compareList = [];
  233. },
  234. fail(err) {
  235. that.doStartScaning = false;
  236. that.requestBlueTime = that.getCurrentMills();
  237. if (boolean != null) {
  238. boolean(false);
  239. }
  240. },
  241. })
  242. },
  243. fail: (err) => {
  244. wx.showModal({
  245. title: '提示',
  246. content: '请检查手机蓝牙是否打开',
  247. showCancel: false,
  248. success: function (res) {}
  249. });
  250. that.doStartScaning = false;
  251. if (boolean != null) {
  252. boolean(false);
  253. }
  254. }
  255. });
  256. // wx.startBluetoothDevicesDiscovery({
  257. // allowDuplicatesKey: true,
  258. // success: function (res) {
  259. // that.doStartScaning = false;
  260. // that.requestBlueTime = that.getCurrentMills();
  261. // if (boolean != null) {
  262. // boolean(true);
  263. // }
  264. // that.setConnectWillDevice(connectWillDevice);
  265. // that.setCallBackConnect(callBackConnect);
  266. // that.compareList = [];
  267. // },
  268. // fail(err) {
  269. // that.doStartScaning = false;
  270. // that.requestBlueTime = that.getCurrentMills();
  271. // if (boolean != null) {
  272. // boolean(false);
  273. // }
  274. // },
  275. // })
  276. // wx.closeBluetoothAdapter({
  277. // complete: function (res) {
  278. // wx.openBluetoothAdapter({
  279. // success: function (res) {
  280. // wx.getBluetoothAdapterState({
  281. // success: function (res) {
  282. // that.doStartScaning = false;
  283. // console.log("gadsfasdfqwerqwerqwerqr==xxx==" + JSON.stringify(res));
  284. // },
  285. // fail(err) {
  286. // that.doStartScaning = false;
  287. // console.log("gadsfasdfqwerqwerqwerqr==yyyy==" + JSON.stringify(res));
  288. // if (boolean != null) {
  289. // boolean(false);
  290. // }
  291. // },
  292. // })
  293. // wx.startBluetoothDevicesDiscovery({
  294. // allowDuplicatesKey: false,
  295. // success: function (res) {
  296. // console.log("gadsfasdfqwerqwerqwerqr==mmmm==" + JSON.stringify(res));
  297. // that.doStartScaning = false;
  298. // that.requestBlueTime = that.getCurrentMills();
  299. // if (boolean != null) {
  300. // boolean(true);
  301. // }
  302. // that.setConnectWillDevice(connectWillDevice);
  303. // that.setCallBackConnect(callBackConnect);
  304. // that.compareList = [];
  305. // },
  306. // fail(err) {
  307. // console.log("gadsfasdfqwerqwerqwerqr==nnnn==" + JSON.stringify(err));
  308. // that.doStartScaning = false;
  309. // that.requestBlueTime = that.getCurrentMills();
  310. // if (boolean != null) {
  311. // boolean(false);
  312. // }
  313. // },
  314. // })
  315. // },
  316. // fail: function (res) {
  317. // wx.showModal({
  318. // title: '提示',
  319. // content: '请检查手机蓝牙是否打开',
  320. // showCancel: false,
  321. // success: function (res) {}
  322. // });
  323. // that.doStartScaning = false;
  324. // if (boolean != null) {
  325. // boolean(false);
  326. // }
  327. // }
  328. // })
  329. // }
  330. // })
  331. }
  332. // 停止搜索
  333. stopSearch() {
  334. var that = this;
  335. that.setCallBackConnect(null);
  336. that.setConnectWillDevice(null);
  337. return new Promise((resolve, reject) => {
  338. wx.stopBluetoothDevicesDiscovery({
  339. success: (res) => {
  340. resolve(res);
  341. },
  342. fail: (err) => {
  343. reject(new Error('停止搜索失败'));
  344. }
  345. });
  346. });
  347. }
  348. closeBle() {
  349. console.log('关闭蓝牙了')
  350. closeBluetoothAdapter();
  351. }
  352. // 断开与指定设备的连接
  353. disconnect() {
  354. var that = this;
  355. let device = that.publicDevice ?? {};
  356. let deviceId = device.deviceId ?? ""
  357. if (deviceId.length === 0) {
  358. return;
  359. }
  360. return new Promise((resolve, reject) => {
  361. wx.closeBLEConnection({
  362. deviceId: that.publicDevice.deviceId ?? "",
  363. success: (res) => {
  364. that.publicDevice = null;
  365. console.log('断开连接成功:', res);
  366. resolve(res);
  367. },
  368. fail: (err) => {
  369. console.error('断开连接失败:', err);
  370. reject(new Error('断开连接失败'));
  371. }
  372. });
  373. });
  374. }
  375. // 发送数据到指定设备
  376. async sendData(data) {
  377. var that = this
  378. return new Promise((resolve, reject) => {
  379. var buffer = null;
  380. // todo 判断是否是buffer
  381. // if (Buffer.isBuffer(data)) {
  382. // buffer = data;
  383. // } else {
  384. buffer = new ArrayBuffer(data.length);
  385. // 下面是赋值,不能删
  386. const dataView = new DataView(buffer);
  387. data.forEach((value, index) => {
  388. dataView.setUint8(index, value); // 将每个16进制数值写入到 buffer 中
  389. });
  390. // }
  391. console.log('开始发送数据:', data, buffer);
  392. wx.writeBLECharacteristicValue({
  393. deviceId: that.publicDevice.deviceId,
  394. serviceId: that.publicDevice.serviceId,
  395. characteristicId: that.publicDevice.characteristicId,
  396. value: buffer,
  397. success: (res) => {
  398. // console.log('数据发送成功:');
  399. resolve(res);
  400. },
  401. fail: (err) => {
  402. console.error('数据发送失败:', err);
  403. reject(new Error('数据发送失败'));
  404. }
  405. });
  406. });
  407. }
  408. ab2hex(buffer) {
  409. var hexArr = Array.prototype.map.call(
  410. new Uint8Array(buffer),
  411. function (bit) {
  412. return ('00' + bit.toString(16)).slice(-2)
  413. }
  414. )
  415. return hexArr.join(':');
  416. }
  417. fiterDevice(res) {
  418. var that = this;
  419. var devices = res.devices.filter(device => {
  420. const name = device.name || '';
  421. const localName = device.localName || '';
  422. let isNot = that.isNotEmpty(name) || that.isNotEmpty(localName);
  423. if (isNot) {
  424. // console.log('是猫王设备名称:', device.advertisData, device.serviceData)
  425. let mac = that.ab2hex(device.advertisData)
  426. // console.log(mac)
  427. device.mac = mac
  428. }
  429. return isNot
  430. });
  431. let newDevices = devices.map((device) => {
  432. let uuid = device.advertisServiceUUIDs[0] ?? ""
  433. return {
  434. deviceId: device.deviceId,
  435. name: device.name,
  436. localName: device.localName,
  437. uuid: uuid,
  438. mac: device.mac,
  439. connectable: device.connectable
  440. }
  441. });
  442. return newDevices
  443. }
  444. isNotEmpty(name) {
  445. let isNot = (name !== '' &&
  446. (name.startsWith("MW_") ||
  447. name.startsWith("MW-") ||
  448. // name.startsWith("猫王") ||
  449. // name.startsWith("妙播") ||
  450. // name.startsWith("AirSmart") ||
  451. name === "le")
  452. )
  453. // if (!isNot && name !== '') {
  454. // console.log('不是猫王设备名称:', name)
  455. // }
  456. return isNot;
  457. }
  458. // 连接到指定设备
  459. async connectToDevice(device) {
  460. var that = this;
  461. return new Promise((resolve, reject) => {
  462. console.log("开始连接蓝牙:", device.deviceId)
  463. wx.createBLEConnection({
  464. deviceId: device.deviceId,
  465. success: (res) => {
  466. that.publicDevice = device
  467. console.log('连接成功:', res);
  468. resolve(true);
  469. },
  470. fail: (err) => {
  471. that.publicDevice = null
  472. console.error('连接失败:', err);
  473. resolve(false);
  474. }
  475. });
  476. });
  477. }
  478. // 发现服务
  479. discoverServices(deviceId) {
  480. var that = this;
  481. console.log('发现服务:', deviceId);
  482. return new Promise((resolve, reject) => {
  483. wx.getBLEDeviceServices({
  484. deviceId: deviceId,
  485. success: (res) => {
  486. // that.publicDevice .services = res.services;
  487. let service_id = "";
  488. for (let i = 0; i < res.services.length; i++) {
  489. if (res.services[i].uuid.toUpperCase().indexOf("AB00") != -1 ||
  490. res.services[i].uuid.toUpperCase().indexOf("FFC0") != -1
  491. // res.services[i].uuid.toUpperCase().indexOf("ae800") != -1
  492. ) {
  493. service_id = res.services[i].uuid;
  494. break;
  495. }
  496. console.log('发现服务1:', service_id);
  497. service_id = res.services[i].uuid;
  498. }
  499. that.publicDevice.serviceId = service_id;
  500. console.log('发现服务2:', service_id);
  501. resolve(service_id);
  502. // resolve(res.services);
  503. },
  504. fail: (err) => {
  505. that.publicDevice.serviceId = null;
  506. console.error('发现服务失败:', err);
  507. reject([]);
  508. }
  509. });
  510. });
  511. }
  512. // 发现特征值 read / write
  513. discoverCharacteristics(deviceId, serviceId) {
  514. var that = this;
  515. console.log('发现特征值:' + deviceId + " , " + serviceId);
  516. // if (deviceId !== that.publicDevice .deviceId) {
  517. // console.log('设备id不匹配')
  518. // return false
  519. // }
  520. return new Promise((resolve, reject) => {
  521. wx.getBLEDeviceCharacteristics({
  522. deviceId: deviceId,
  523. serviceId: serviceId,
  524. success: (res) => {
  525. // that.characteristics[serviceId] = res.characteristics;
  526. console.log('发现特征值2:', res);
  527. // that.publicDevice .characteristics = res.characteristics;
  528. resolve(res.characteristics);
  529. },
  530. fail: (err) => {
  531. that.publicDevice.characteristics = null;
  532. console.error('发现特征值失败:', err);
  533. reject("");
  534. }
  535. });
  536. });
  537. }
  538. // 读取特征值
  539. readCharacteristicValue(characteristicId) {
  540. var that = ths;
  541. console.log('开始读取特征值', characteristicId)
  542. return new Promise((resolve, reject) => {
  543. wx.readBLECharacteristicValue({
  544. deviceId: that.publicDevice.deviceId,
  545. serviceId: that.publicDevice.serviceId,
  546. characteristicId: characteristicId,
  547. success: (res) => {
  548. const name = that.parseBLEValue(res.value); // 解析读取到的值
  549. console.log('读取特征值成功:', name, res);
  550. resolve(res);
  551. },
  552. fail: (err) => {
  553. console.error('读取特征值失败:', err);
  554. reject("");
  555. }
  556. });
  557. });
  558. }
  559. // 解析读取到的设备名称
  560. parseBLEValue(buffer) {
  561. return String.fromCharCode.apply(null, new Uint8Array(buffer));
  562. }
  563. // 监听特征值变化
  564. notifyCharacteristicValueChange(characteristicId, callback) {
  565. var that = this;
  566. console.log('监听特征值变化:', characteristicId, that.publicDevice.deviceId, that.publicDevice.serviceId);
  567. wx.notifyBLECharacteristicValueChange({
  568. deviceId: that.publicDevice.deviceId, //设备mac IOS和安卓系统不一样
  569. serviceId: that.publicDevice.serviceId, //服务通道,这里主要是notify
  570. characteristicId: characteristicId, //notify uuid
  571. state: true,
  572. success: function (res) {
  573. console.log("开启notify 成功")
  574. //TODO onBLECharacteristicValueChange 监听特征值 设备的数据在这里获取到
  575. wx.onBLECharacteristicValueChange(function (characteristic) {
  576. let buffer = characteristic.value
  577. let dataView = new DataView(buffer)
  578. let dataResult = []
  579. for (let i = 0; i < dataView.byteLength; i++) {
  580. // console.log("0x" + dataView.getUint8(i).toString(16))
  581. // dataResult.push("0x" + dataView.getUint8(i).toString(16))
  582. dataResult.push(dataView.getUint8(i))
  583. }
  584. const result = dataResult
  585. console.log("拿到的数据:", result)
  586. if (callback) {
  587. callback(result)
  588. }
  589. })
  590. },
  591. fail: function (res) {
  592. console.log("订阅特征失败:", res)
  593. }
  594. })
  595. }
  596. setWrite(wirte, characteristicId) {
  597. var that = this;
  598. console.log('写入特征值:', characteristicId)
  599. // that.publicDevice .wirte = wirte
  600. that.publicDevice.characteristicId = characteristicId;
  601. }
  602. }
  603. // const ble = new bleManager();
  604. // 导出 bleManager 类
  605. module.exports = bleManager;
  606. // wx.getSetting({
  607. // success(res) {
  608. // if (res.authSetting["scope.userFuzzyLocation"]) {
  609. // // 成功
  610. // // that.getBluetoothStatus();
  611. // console.log("有定位权限")
  612. // resolve(true);
  613. // } else if (res.authSetting["scope.userFuzzyLocation"] === undefined) {
  614. // wx.authorize({
  615. // scope: "scope.userFuzzyLocation",
  616. // success() {
  617. // console.log("再次获取定位权限")
  618. // resolve(that.getSetting());
  619. // }
  620. // });
  621. // } else {
  622. // wx.showModal({
  623. // title: '请打开系统位置获取定位权限',
  624. // success(res) {
  625. // if (res.confirm) {
  626. // console.log('用户点击确定')
  627. // wx.openSetting({
  628. // complete() {
  629. // // that.getSetting();
  630. // // resolve(that.getSetting());
  631. // }
  632. // })
  633. // } else if (res.cancel) {
  634. // console.log('用户点击取消');
  635. // }
  636. // }
  637. // })
  638. // console.log("没有有定位权限")
  639. // reject(false);
  640. // }
  641. // }
  642. // })
  643. // // 获取已连接的蓝牙设备
  644. // getConnectedDevices() {
  645. // var that = this;
  646. // if (!that.isAvailable && !that.hasPermission) {
  647. // return [];
  648. // }
  649. // return new Promise((resolve, reject) => {
  650. // wx.getConnectedBluetoothDevices({
  651. // // services: ["FFC0", "ffc0", "FFC1", "FFC2", "ffc1", "ffc2", "AB00", "ab00", "AB01", "AB02", "FFF1", "fff1", "FFE2", "FFE5",],
  652. // // services: ["ab00", "ffe5", "1111", "FFC0", "FFC1", "FFF1", ],
  653. // // services: [],
  654. // // services: [
  655. // // "0000ab00-0000-1000-8000-00805f9b34fb",
  656. // // "0000ffc0-0000-1000-8000-00805f9b34fb",
  657. // // "0000FFF0-0000-1000-8000-00805F9B34FB",
  658. // // "0000FFF1-0000-1000-8000-00805F9B34FB",
  659. // // "0000FFE5-0000-1000-8000-00805F9B34FB",
  660. // // ],
  661. // success: (res) => {
  662. // console.log('已连接的蓝牙设备==11==:', newDevices);
  663. // let newDevices = that.fiterDevice(res)
  664. // console.log('已连接的蓝牙设备==22==:', newDevices);
  665. // resolve(newDevices);
  666. // },
  667. // fail: (err) => {
  668. // console.error('获取已连接的蓝牙设备失败:', err);
  669. // reject([]);
  670. // }
  671. // });
  672. // });
  673. // }