ble_manager.js 22 KB

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