Преглед изворни кода

fix:修改IOS搜索,第一次没有localName的问题

zeng.chen пре 2 месеци
родитељ
комит
eddd1ae6c5
2 измењених фајлова са 48 додато и 12 уклоњено
  1. 17 7
      pages/pageB/deviceConnect2/deviceConnect2.js
  2. 31 5
      utils/blufi/xBlufi-wx-impl.js

+ 17 - 7
pages/pageB/deviceConnect2/deviceConnect2.js

@@ -29,6 +29,7 @@ Page({
   },
 
   onLoad(options) {
+    console.log("开始搜索")
     const that = this;
     var param = options.param;
     if (!strings.isEmpty(param)) {
@@ -91,9 +92,10 @@ Page({
         }
         break;
 
-        // [{"deviceId":"7C:DF:A1:FD:3A:F2","name":"BLUFI_7cdfa1fd3af0","RSSI":-62,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fd3af0","serviceData":{}}]
-        ///发现设备列表回调
+      // [{"deviceId":"7C:DF:A1:FD:3A:F2","name":"BLUFI_7cdfa1fd3af0","RSSI":-62,"connectable":true,"advertisData":"","advertisServiceUUIDs":["0000FFFF-0000-1000-8000-00805F9B34FB"],"localName":"BLUFI_7cdfa1fd3af0","serviceData":{}}]
+      ///发现设备列表回调
       case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
+
         // 搜索到蓝牙
         if (options.result) {
           var devicesList = options.data.filter((v) => {
@@ -101,7 +103,12 @@ Page({
             var isLexin = name.indexOf(lexin_devices.leXin) !== -1;
             var isJungzheng1 = junzhengUtil.isJungzheng1(name);
             var isJungzheng2 = junzhengUtil.isJungzheng2(name);
-            return isLexin || isJungzheng1 || isJungzheng2;
+
+            var localName = v.localName;
+            var isLexin1 = localName.indexOf(lexin_devices.leXin) !== -1;
+            var isJungzheng3 = junzhengUtil.isJungzheng1(localName);
+            var isJungzheng4 = junzhengUtil.isJungzheng2(localName);
+            return isLexin || isJungzheng1 || isJungzheng2 || isLexin1 || isJungzheng3 || isJungzheng4;
             ///2AXD
             // return v.name == "AIrSMArT_d0311004155e";
             ///X4
@@ -109,6 +116,8 @@ Page({
           });
 
           if (!strings.isEmpty(devicesList)) {
+            console.log("打印4", JSON.stringify(devicesList))
+
             ///过滤乐鑫设备
             that.setData({
               islanya: true,
@@ -118,9 +127,9 @@ Page({
         }
         break;
 
-        // {"type":"0","result":true,"data":{"deviceId":"7C:DF:A1:FD:3A:F2","name":"BLUFI_7cdfa1fd3af0"}}
-        // {"type":"0","result":true,"data":{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24"}}
-        ///主动去连接连接
+      // {"type":"0","result":true,"data":{"deviceId":"7C:DF:A1:FD:3A:F2","name":"BLUFI_7cdfa1fd3af0"}}
+      // {"type":"0","result":true,"data":{"deviceId":"7C:DF:A1:FC:BB:26","name":"BLUFI_7cdfa1fcbb24"}}
+      ///主动去连接连接
       case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
         wx.hideLoading();
         if (options.result) {
@@ -141,7 +150,7 @@ Page({
         }
         break;
 
-        ///停止发现设备列表回调
+      ///停止发现设备列表回调
       case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
         if (options.result) {
           //蓝牙停止搜索ok
@@ -181,6 +190,7 @@ Page({
 
     var name = devicesList[0].name;
     var deviceId = devicesList[0].deviceId;
+    console.log("")
     var isJungzheng1 = junzhengUtil.isJungzheng1(name);
     var isJungzheng2 = junzhengUtil.isJungzheng2(name);
 

+ 31 - 5
utils/blufi/xBlufi-wx-impl.js

@@ -162,7 +162,7 @@ function getSecret(deviceId, serviceId, characteristicId, client, kBytes, pBytes
         getSecret(deviceId, serviceId, characteristicId, client, kBytes, pBytes, gBytes, obj.laveData);
       }
     },
-    fail: function (res) {}
+    fail: function (res) { }
   })
 }
 
@@ -192,7 +192,7 @@ function writeDeviceRouterInfoStart(deviceId, serviceId, characteristicId, data)
         writeRouterSsid(deviceId, serviceId, characteristicId, null);
       }
     },
-    fail: function (res) {}
+    fail: function (res) { }
   })
 }
 
@@ -290,7 +290,7 @@ function writeDevicePwd(deviceId, serviceId, characteristicId, data) {
         writeDeviceEnd(deviceId, serviceId, characteristicId, null);
       }
     },
-    fail: function (res) {}
+    fail: function (res) { }
   })
 }
 
@@ -336,7 +336,7 @@ function init() {
     if (options.isStart) {
       //第一步检查蓝牙适配器是否可用
       wx.onBluetoothAdapterStateChange(function (res) {
-        if (!res.available) {}
+        if (!res.available) { }
       });
       if (!itue) {
         return;
@@ -357,6 +357,19 @@ function init() {
                       let countsTimes = 0;
                       wx.onBluetoothDeviceFound(function (devices) {
                         //剔除重复设备,兼容不同设备API的不同返回值
+                        // let newOptions = devices.devices;
+                        // newOptions.forEach((v) => {
+                        //   // let name = v.name ?? ""
+                        //   let deviceId = v.deviceId ?? ""
+                        //   // let localName =v.localName ?? ""
+                        //   // if (name && name.includes("MW") ) {
+                        //   if (deviceId && deviceId.includes("AAA4E8D0")) {
+                        //     // let deviceStr = `${v.name ?? ""}, ${v.localName ?? ""}; `;
+                        //     // deviceInfoStr += deviceStr;
+                        //     console.log("搜索到的MW设备信息2:", mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS, JSON.stringify(v));
+                        //   }
+                        // })
+
                         var isnotexist = true;
                         if (devices.deviceId) {
                           if (devices.advertisData) {
@@ -370,6 +383,8 @@ function init() {
                             }
                           }
                           if (isnotexist) {
+                            console.log("打印1")
+
                             devicesList.push(devices)
                           }
                         } else if (devices.devices) {
@@ -384,7 +399,16 @@ function init() {
                             }
                           }
                           if (isnotexist) {
-                            devicesList.push(devices.devices[0])
+                 
+                            let name = devices.devices[0].name ?? ""
+                            let localName = devices.devices[0].localName ?? ""
+                            // AIrSMArT_d03110c71019
+                            if (name.includes("AIrSMArT") || localName.includes("AIrSMArT")) {
+                              // devices.devices[0].name = name.includes("AIrSMArT") ? name : localName
+                              console.log("打印2", JSON.stringify(devices.devices[0]))
+                              devicesList.push(devices.devices[0])
+                            }
+
                           }
                         } else if (devices[0]) {
                           if (devices[0].advertisData) {
@@ -398,9 +422,11 @@ function init() {
                             }
                           }
                           if (isnotexist) {
+                            console.log("打印3", devices[0].deviceId.inc)
                             devicesList.push(devices[0])
                           }
                         }
+                        // console.log("打印:", newOptions);
 
                         let obj = {
                           'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS,