|
@@ -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}`);
|