ble_manager.js 22 KB

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