Переглянути джерело

feature:修改校验指令的解析

zeng.chen 6 місяців тому
батько
коміт
7dd9056a65
3 змінених файлів з 16 додано та 48 видалено
  1. 1 1
      devices/ble_manager.js
  2. 10 42
      devices/bluetooth/bt_cmd.js
  3. 5 5
      devices/bt_helper.js

+ 1 - 1
devices/ble_manager.js

@@ -472,7 +472,7 @@ class bleManager {
       });
       // }
 
-      // console.log('开始发送数据:', data);
+      console.log('开始发送数据:', buffer);
       wx.writeBLECharacteristicValue({
         deviceId: that.publicDevice.deviceId,
         serviceId: that.publicDevice.serviceId,

+ 10 - 42
devices/bluetooth/bt_cmd.js

@@ -180,13 +180,13 @@ class BtCmd {
         return this._build(CmdRgb.query, [0x00]);
     }
 
-    static stringToUint8Array(str) {
-        // 54 44 44 48 01 11 28 09 73 6d6172745f413246
-        // const encoder = new TextEncoder();
-        // const uint8Array = encoder.encode(str);
-        // return uint8Array;
+    static stringToUint8Array(text) {
         // return [0x73, 0x6d, 0x61, 0x72, 0x74, 0x5f, 0x41, 0x32, 0x46]
-        return [115, 109, 97, 114, 116, 95, 65, 50, 70]
+        // return [115, 109, 97, 114, 116, 95, 65, 50, 70]
+        // 73 6D 61 72 74 5F 41 32 46
+        let code = Array.from(text).map(char => char.charCodeAt(0));
+        console.log("stringToUint8Array", code)
+        return code
     }
 
     // 校验设备
@@ -281,43 +281,13 @@ class BtCmd {
         return this._build(0x36, [0x00]);
     }
 
-    static _buildOther(data) {
-        const cmd = [];
-
-        // 固定头部
-        cmd.push(...this._header);
-
-        // 版本号
-        cmd.push(this._version);
-
-        // 命令类型
-        cmd.push(cmdType);
-
-        if (isWriteChildCmdLength) {
-            // 子命令长度
-            const childLength = this._int2Hex(otherCmd.length);
-            cmd.push(childLength);
-        }
-
-        // 其他命令
-        if (otherCmd.length > 0) {
-            for (const element of otherCmd) {
-                cmd.push(this._int2Hex(element));
-            }
-        }
 
-        // 命令长度(位置在版本号之后)
-        const length = cmd.length + 1;
-        const l = this._int2Hex(length);
-        cmd.splice(5, 0, l);
-        return cmd;
-    }
     // 生成命令(固定头部+版本号+命令总长度+命令类型+)
-    static _build(cmdType, otherCmd = [], isWriteChildCmdLength = true, isChangeOther = true) {
+    static _build(cmdType, otherCmd = [], isWriteChildCmdLength = true, isChangeHex = true) {
         const cmd = [];
 
         // 固定头部
-        cmd.push(...this._header);
+        cmd.concat(this._header);
 
         // 版本号
         cmd.push(this._version);
@@ -333,7 +303,7 @@ class BtCmd {
 
         // 其他命令
         if (otherCmd.length > 0) {
-            if (isChangeOther) {
+            if (isChangeHex) {
                 for (const element of otherCmd) {
                     cmd.push(this._int2Hex(element));
                 }
@@ -359,9 +329,7 @@ class BtCmd {
         }
 
         for (let i = 0; i < cmd.length; i++) {
-            var cmdStr = `${this._int2HexString(cmd[i])}`.padStart(2, "0");
-            cmdStr += ":"
-            result += cmdStr;
+            result += (`${this._int2HexString(cmd[i])}`.padStart(2, "0") + ":");
         }
         if (isSend) {
             mqttAddDebugCmd(`发送蓝牙指令:${cmd} \n ${result}`);

+ 5 - 5
devices/bt_helper.js

@@ -501,8 +501,8 @@ class BtHelper {
     var that = this;
     // console.log("校验设备:", BtCmd); // 输出: EarPhone Info
     that.sendNow(BtCmd.checkDevice());
-    //2.0有发这个,不知道是啥
-    that.send([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x26, 0x01, 0x01]);
+    //低电量提示语
+    // that.send([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x26, 0x01, 0x01]);
   }
 
   async getVersion() {
@@ -526,15 +526,15 @@ class BtHelper {
     // that.send(BtCmd.setDevTime());
 
     // that.send(BtCmd.queryKwh());
-    that.getSleep();
+    // that.getSleep();
     // that.getAlert();
     // that.send(BtCmd.queryRGB());
     // that.getVolume();
     // that.setVolume(8)
-    that.getPauseSleep();
+    // that.getPauseSleep();
 
     // that.send(BtCmd.getClientType());
-    that.send(BtCmd.getIsConnect());
+    // that.send(BtCmd.getIsConnect());
     // that.send(BtCmd.getMac());
 
     // }