فهرست منبع

feature: 对数据报错异常修复处理

332777428@qq.com 4 ماه پیش
والد
کامیت
4218776df7
4فایلهای تغییر یافته به همراه36 افزوده شده و 37 حذف شده
  1. 23 23
      utils/blue_ble/manager.js
  2. 0 12
      utils/routePath.js
  3. 11 0
      utils/routeRoot.js
  4. 2 2
      utils/routeUtil.js

+ 23 - 23
utils/blue_ble/manager.js

@@ -69,13 +69,13 @@ class Manager {
   ///监听搜索设备列表
   listenBlueDevices() {
     var that = this;
-    const hex_util = require('./../../utils/hex_util');
+    const hexUtil = require('../hexUtil');
     wx.onBluetoothDeviceFound(function (res) {
       ///第一种情况
       if (res.deviceId) {
         if (that.callBackConnect != null) {
           if (that.connectWillDevice != null && res.name == that.connectWillDevice.clientType) {
-            res.mac = res.advertisData ? hex_util.buf2hex(res.advertisData) : '';
+            res.mac = res.advertisData ? hexUtil.buf2hex(res.advertisData) : '';
             if (that.callBackConnect != null) {
               that.callBackConnect(res);
             }
@@ -105,7 +105,7 @@ class Manager {
           for (var i = 0; i < res.devices.length; i++) {
             var temp = res.devices[i];
             if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
-              temp.mac = temp.advertisData ? hex_util.buf2hex(temp.advertisData) : '';
+              temp.mac = temp.advertisData ? hexUtil.buf2hex(temp.advertisData) : '';
               temp.mac2 = that.ab2hex(temp.advertisData ?? "")
               if (that.callBackConnect != null) {
                 that.callBackConnect(temp);
@@ -138,7 +138,7 @@ class Manager {
       else if (res[0]) {
         if (that.callBackConnect != null) {
           if (that.connectWillDevice != null && res[0].name == that.connectWillDevice.clientType) {
-            res[0].mac = res[0].advertisData ? hex_util.buf2hex(res[0].advertisData) : '';
+            res[0].mac = res[0].advertisData ? hexUtil.buf2hex(res[0].advertisData) : '';
             if (that.callBackConnect != null) {
               that.callBackConnect(res[0]);
             }
@@ -199,8 +199,8 @@ class Manager {
       }
 
       ///做搜索蓝牙适配器权限
-      const permission_util = require('../utils/permission_util');
-      var available = await permission_util.openBluetoothAdapter();
+      const permissionUtil = require('../../utils/permissionUtil');
+      var available = await permissionUtil.openBluetoothAdapter();
       that.isAvailable = available;
       if (!available) {
         that.doStartScaning = false;
@@ -212,11 +212,11 @@ class Manager {
       }
     }
 
-    const route_util = require('../utils/route_util');
-    const route_constant = require('../utils/route_constant');
-    const indexRoot = route_constant.indexRoot;
-    const connectBleRoot = route_constant.connectBleRoot;
-    var lastPageRoute = route_util.getLastPageRoute();
+    const routeUtil = require('../../utils/routeUtil');
+    const routeRoot = require('../../utils/routeRoot');
+    const indexRoot = routeRoot.indexRoot;
+    const connectBleRoot = routeRoot.connectBleRoot;
+    var lastPageRoute = routeUtil.getLastPageRoute();
     if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
       return;
     }
@@ -228,9 +228,9 @@ class Manager {
       }
     }
 
-    const time_util = require('./../../utils/time_util');
+    const timeUtil = require('../../utils/timeUtil');
     that.doStartScaning = true;
-    var currentMill = time_util.getCurrentMills();
+    var currentMill = timeUtil.getCurrentMills();
     var waitMills = 0;
     var reduce = currentMill - that.requestBlueTime;
     const dMills = 6 * 1000;
@@ -239,7 +239,7 @@ class Manager {
     }
 
     if (waitMills > 0) {
-      await time_util.delayMills(waitMills);
+      await timeUtil.delayMills(waitMills);
     }
 
     if (callBackConnect == null && lastPageRoute == connectBleRoot) {
@@ -253,7 +253,7 @@ class Manager {
       },
       fail: (err) => {
         that.doStartScaning = false;
-        that.requestBlueTime = time_util.getCurrentMills();
+        that.requestBlueTime = timeUtil.getCurrentMills();
         if (boolean != null) {
           boolean(false);
         }
@@ -264,13 +264,13 @@ class Manager {
   ///搜索设备
   search(connectWillDevice, boolean, callBackConnect) {
     var that = this;
-    const time_util = require('./../../utils/time_util');
+    const timeUtil = require('../../utils/timeUtil');
     wx.startBluetoothDevicesDiscovery({
       allowDuplicatesKey: true,
       success: function (res) {
         // that.getConnectedDevices();
         that.doStartScaning = false;
-        that.requestBlueTime = time_util.getCurrentMills();
+        that.requestBlueTime = timeUtil.getCurrentMills();
         if (boolean != null) {
           boolean(true);
         }
@@ -280,7 +280,7 @@ class Manager {
       },
       fail(err) {
         that.doStartScaning = false;
-        that.requestBlueTime = time_util.getCurrentMills();
+        that.requestBlueTime = timeUtil.getCurrentMills();
         if (boolean != null) {
           boolean(false);
         }
@@ -422,7 +422,7 @@ class Manager {
 
   async _forProcessDeal(res, failed, readSucceed) {
     var that = this;
-    const time_util = require('./../../utils/time_util');
+    const timeUtil = require('../../utils/timeUtil');
     var characteristics = res.characteristics;
     if (characteristics.length <= 0) {
       failed();
@@ -500,14 +500,14 @@ class Manager {
   onBLECharacteristicValueChange(device, callback) {
     wx.onBLECharacteristicValueChange(function (characteristic) {
       //characteristic: {"value":{},"deviceId":"22:10:14:95:F0:1E","serviceId":"0000FFE5-0000-1000-8000-00805F9B34FB","characteristicId":"0000FFE5-0001-1000-8000-00805F9B34FB"}
-      const hex_util = require('../hex_util');
+      const hexUtil = require('../hexUtil');
       var buffer = characteristic.value
       var dataView = new DataView(buffer)
       var dataResult = []
       for (let i = 0; i < dataView.byteLength; i++) {
         dataResult.push(dataView.getUint8(i))
       }
-      var value = hex_util.buf2string(dataResult);
+      var value = hexUtil.buf2string(dataResult);
       ///109,113,116,116
       ///114,101,99,118,95,102,105,110,105,115,104
       callback(value);
@@ -618,14 +618,14 @@ module.exports = Manager;
 ///获取 所有搜索过的蓝牙设备
 // getConnectedDevices() {
 //   var that = this;
-//   const hex_util = require('./../../utils/hex_util');
+//   const hexUtil = require('../hexUtil');
 //   wx.getBluetoothDevices({
 //     success: (res) => {
 //       if (that.callBackConnect != null) {
 //         for (var i = 0; i < res.devices.length; i++) {
 //           var temp = res.devices[i];
 //           if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
-//             temp.mac = temp.advertisData ? hex_util.buf2hex(temp.advertisData) : '';
+//             temp.mac = temp.advertisData ? hexUtil.buf2hex(temp.advertisData) : '';
 //             if (that.callBackConnect != null) {
 //               that.callBackConnect(temp);
 //             }

+ 0 - 12
utils/routePath.js

@@ -1,8 +1,3 @@
-///路由
-const indexRoot = "pages/index/index";
-const loginRoot = "pages/login/login";
-const connectBleRoot = "pages/connectBle/connectBle";
-
 ///跳转路径
 const index = "../index/index";
 const login = "../login/login";
@@ -18,16 +13,9 @@ const deviceList = "../deviceList/deviceList";
 const connectMode = "../deviceConMode/index";
 const connectBle = "../connectBle/connectBle";
 
-
 const webview = "../webview/webview";
 
 module.exports = {
-  ///路由
-  indexRoot: indexRoot,
-  loginRoot: loginRoot,
-  connectBleRoot: connectBleRoot,
-
-  ///跳转路径
   index: index,
   login: login,
   about: about,

+ 11 - 0
utils/routeRoot.js

@@ -0,0 +1,11 @@
+///路由
+const indexRoot = "pages/index/index";
+const loginRoot = "pages/login/login";
+const connectBleRoot = "pages/connectBle/connectBle";
+
+module.exports = {
+  ///路由
+  indexRoot: indexRoot,
+  loginRoot: loginRoot,
+  connectBleRoot: connectBleRoot,
+}

+ 2 - 2
utils/routeUtil.js

@@ -76,8 +76,8 @@ async function goBack(pages) {
 
 ///返回到首页,不关闭当前界面
 async function goBackHomePage() {
-  const route_constant = require('./routePath.js');
-  await goBackRoute(route_constant.indexRoot);
+  const routePath = require('./routePath.js');
+  await goBackRoute(routePath.indexRoot);
 };
 
 ///返回到某个界面,不替换当前界面