Просмотр исходного кода

feature:增加设备的mac地址

zeng.chen 6 месяцев назад
Родитель
Сommit
c0e9c907de
4 измененных файлов с 40 добавлено и 14 удалено
  1. 21 8
      devices/bluetooth/bt_parse.js
  2. 1 1
      devices/bt_helper.js
  3. 17 4
      pages/index/index.js
  4. 1 1
      pages/piano/wallpaper/wallpaper.js

+ 21 - 8
devices/bluetooth/bt_parse.js

@@ -451,16 +451,20 @@ class BtParse {
                 break;
             case CmdBase.getMac:
                 {
-                    var values = []
-                    for (let i = 8; i < cmd.length; i++) {
-                        values.push(cmd[i]);
+                    var values = ""
+                    // [54:44:44:48:01:0D:35:90:9D:99:CF:34:5B:]
+                    for (let i = 7; i < cmd.length; i++) {
+                        values += cmd[i].toString(16);
+                        if (i != cmd.length - 1) {
+                            values += ":";
+                        }
                     }
-                    let str = this.hexArrayToString(values);
+                    // let str = this.hexArrayToString(values);
                     // getMac===== ?MV-SR1(4G_WIFI)
-                    let device = getApp().globalData.mDeviceList[0] ?? {};
-                    device["trueMac"] = str;
-                    console.log("getMac=====", device)
-                    EventManager.fire(CmdEvent.btMac(str));
+                    // let device = getApp().globalData.mDeviceList[0] ?? {};
+                    // device["mac"] = values;
+                    console.log("getMac=====", values)
+                    EventManager.fire(CmdEvent.btMac({ "btMac": values }));
 
                 }
                 // [84, 68, 68, 72, 1, 23, 53, 16, 77, 86, 45, 83, 82, 49, 40, 52, 71, 95, 87, 73, 70, 73, 41]
@@ -558,6 +562,15 @@ class BtParse {
         }
         return str;
     }
+    static ab2hex(buffer) {
+        var hexArr = Array.prototype.map.call(
+            new Uint8Array(buffer),
+            function (bit) {
+                return ('00' + bit.toString(16)).slice(-2)
+            }
+        )
+        return hexArr.join(':');
+    }
 
 }
 

+ 1 - 1
devices/bt_helper.js

@@ -540,7 +540,7 @@ class BtHelper {
 
     // that.send(BtCmd.getClientType());
     // that.send(BtCmd.getIsConnect());
-    // that.send(BtCmd.getMac());
+    that.send(BtCmd.getMac());
 
     // }
   }

+ 17 - 4
pages/index/index.js

@@ -22,7 +22,7 @@ import lexin_message from '../../utils/lexin/message.js';
 import {
   BtHelper
 } from '../../devices/bt_helper.js';
-import event_bus, { addNotification } from '../../utils/event_bus.js';
+import event_bus from '../../utils/event_bus.js';
 import {
   EnumCmdEvent,
   CmdEvent
@@ -590,11 +590,12 @@ Page({
 
     ///去蓝牙连接处理
     // {"connectType":1,"deviceId":"E4:9F:80:09:40:EC","name":"E4:9F:80:09:40:EC","state":"online","ProdModel":"MW-SR1(4G_WIFI)","devName":"猫王音响x阿基米德 SR1 妙播收音机"}
+    var deviceList = that.getDeviceList();
+    let curDevice = deviceList[index]
     if (index === deviceListSelect && device.state === "online") {
-      route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(device))
+      route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(curDevice))
     } else if (device.state === "offline") {
 
-      var deviceList = that.getDeviceList();
       var deviceListSelect = that.getDeviceListSelect();
       if (deviceListSelect != null && deviceList.length > deviceListSelect) {
         that.setData({
@@ -660,6 +661,7 @@ Page({
           if (deviceList[index].connectType == 3) {
             that.cancelWifi(index, false);
           } else {
+            console.log("确定删除", index)
             that.cancelBlue(index, false);
           }
         }
@@ -729,6 +731,8 @@ Page({
       deviceListSelect: isCurrentIndex ? null : deviceListSelect,
     });
 
+    console.log("最终确定删除", deviceId, JSON.stringify(deviceList), deviceList.length)
+
     BtHelper.getInstance().disconnect({
       "deviceId": deviceId
     });
@@ -790,7 +794,16 @@ Page({
     let that = this;
     event_bus.removeNotification(CmdEvent.eventName, that);
     event_bus.addNotification(CmdEvent.eventName, function (event) {
-      if (event.cmdEvent == EnumCmdEvent.onoffline) {
+      if (event.cmdEvent == EnumCmdEvent.btMac) {
+        let deviceList = that.getDeviceList()
+        let disDevice = deviceList.find(item => {
+          return item.state == "online" && item.connectType === 1
+        })
+        if (disDevice) {
+          disDevice.mac = event.btMac
+          console.log("设备mac:", disDevice.mac)
+        }
+      } else if (event.cmdEvent == EnumCmdEvent.onoffline) {
         let isFirst = false;
         // 有下线就开启监听扫描
         if (event.commonValue == "online") {

+ 1 - 1
pages/piano/wallpaper/wallpaper.js

@@ -110,7 +110,7 @@ Page({
     }
     let myImgList = store.getStore(_this.data._localImgPicKey)
     myImgList = myImgList ?? []
-    console.log("updateTopImg1", imgList, myImgList)
+    console.log("updateTopImg1", myImgList)
 
     // 移除保存的重复图片
     let myIndex = myImgList.findIndex(img => img.pic === topUrl);