ble_manager.js 22 KB

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