Selaa lähdekoodia

feature:修改冲突文件

zeng.chen 8 kuukautta sitten
vanhempi
commit
9a9cf549e9
4 muutettua tiedostoa jossa 1006 lisäystä ja 1009 poistoa
  1. 527 533
      devices/ble_manager.js
  2. 37 14
      devices/bluetooth/bt_cmd.js
  3. 17 11
      devices/bluetooth/bt_parse.js
  4. 425 451
      devices/bt_helper.js

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 527 - 533
devices/ble_manager.js


+ 37 - 14
devices/bluetooth/bt_cmd.js

@@ -23,22 +23,22 @@ class BtCmd {
 
     // 获取版本号
     static queryVersion() {
-        return this._build(CmdBase.queryVersion, [0x0]);
+        return this._build(CmdBase.queryVersion, [0x00]);
     }
 
     // 查询电量  电量值 0-9,0对应10%,9对应100%,10充电
     static queryKwh() {
-        return this._build(CmdKwh.queryKwh, [0x0]);
+        return this._build(CmdKwh.queryKwh, [0x00]);
     }
 
     // 查询耳机电量
     static queryKwhEarPhone() {
-        return this._build(CmdEarPhone.queryEarPhoneKwh, [0x0]);
+        return this._build(CmdEarPhone.queryEarPhoneKwh, [0x00]);
     }
 
     // 查询EQ音效
     static queryEQ() {
-        return this._build(CmdEarPhone.queryEQ, [0x0]);
+        return this._build(CmdEarPhone.queryEQ, [0x00]);
     }
 
     // 设置EQ音效
@@ -48,7 +48,7 @@ class BtCmd {
 
     // B5耳机-低电耗模式
     static queryLowPower() {
-        return this._build(CmdEarPhone.queryLowPower, [0x0]);
+        return this._build(CmdEarPhone.queryLowPower, [0x00]);
     }
 
     static setLowPowerMode(isOpen) {
@@ -57,7 +57,7 @@ class BtCmd {
 
     // B5耳机-自定义操作手势
     static queryCtrlStatus() {
-        return this._build(CmdEarPhone.queryCtrlStatus, [0x0]);
+        return this._build(CmdEarPhone.queryCtrlStatus, [0x00]);
     }
 
     static setCtrlStatus(singleClick, doubleClick, longClick) {
@@ -66,7 +66,7 @@ class BtCmd {
 
     // 查询低延时模式
     static queryLowDelayMode() {
-        return this._build(CmdEarPhone.queryLowDelayMode, [0x0]);
+        return this._build(CmdEarPhone.queryLowDelayMode, [0x00]);
     }
 
     // 低延时模式
@@ -162,7 +162,7 @@ class BtCmd {
 
     // 查询RGB
     static queryRGB() {
-        return this._build(CmdRgb.query, [0x0]);
+        return this._build(CmdRgb.query, [0x00]);
     }
 
     static stringToUint8Array(str) {
@@ -170,7 +170,8 @@ class BtCmd {
         // const encoder = new TextEncoder();
         // const uint8Array = encoder.encode(str);
         // return uint8Array;
-        return [0x73, 0x6d, 0x61, 0x72, 0x74, 0x5f, 0x41, 0x32, 0x46]
+        // return [0x73, 0x6d, 0x61, 0x72, 0x74, 0x5f, 0x41, 0x32, 0x46]
+        return [115, 109, 97, 114, 116, 95, 65, 50, 70]
     }
 
     // 校验设备
@@ -243,7 +244,31 @@ class BtCmd {
         return this._build(CmdBase.heiJiaoOta, [value]);
     } static OtaData(value) {
         return this._build(CmdBase.heiJiaoOtaData, [value]);
+    }  // OTA指令
+    static OTA(value) {
+        return this._build(CmdBase.heiJiaoOta, [value]);
+    }
+    /// 获取设备型号指令
+    static getClientType() {
+        return this._build(0x31, [0x00]);
+    }   ///获取设备mac地址
+    static getMac() {
+        return this._build(0x35, [0x00]);
+    }
+    ///获取手机是否连接了设备
+    static getIsConnect() {
+        return this._build(0x36, [0x00]);
     }
+
+
+    /// 获取设备型号指令
+    //   static const int getClientType = 0x31;
+
+    //   ///获取设备mac地址
+    //   static const int getMac = 0x35;
+
+    //   ///获取手机是否连接了设备
+    //   static const int getIsConnect = 0x36;
     // 生成命令(固定头部+版本号+命令总长度+命令类型+)
     static _build(cmdType, otherCmd = [], isWriteChildCmdLength = true) {
         const cmd = [];
@@ -296,11 +321,9 @@ class BtCmd {
     }
 
     static _int2Hex(num) {
-        let hexStr = num >>> 0; // 将 num 转换为无符号 32 位整数
-        hexStr = hexStr.toString(16); // 转换为 16 进制字符串
-        let i = parseInt(hexStr, 16); // 将 16 进制字符串转换回整数
-        // console.log(`${hexStr}==${i}==${num}`);
-        return i;
+        let value = num ?? 0
+        let hexStr = value.toString(16).toUpperCase(); // 转换为16进制字符串并转为大写
+        return hexStr.padStart(2, '0');
     }
 
     static _int2HexString(value) {

+ 17 - 11
devices/bluetooth/bt_parse.js

@@ -171,6 +171,11 @@ class BtParse {
         const value = cmd[8];
         // mqttAddDebugCmd("收到蓝牙指令:" + cmd);
         console.log("收到控制指令:", cmd, type)
+
+        if (type === 0x31 || type === 0x35 || type === 0x36) {
+            console.log("收到新的控制指令:", cmd, type, value)
+        }
+
         switch (type) {
             // 校验设备
             case CmdBase.checkDeviceSuccess:
@@ -233,11 +238,11 @@ class BtParse {
 
                         // 3 单击下一个专辑 或者下一曲
                         else if (value === CmdKey.changeProgram) {
-                            if (ProviderUtil.device.mDevice?.clientType === BtParse.mateX2) {
-                                BtParse._send(EnumCmdEvent.nextAlbum);
-                            } else {
-                                BtParse._send(EnumCmdEvent.nextSong);
-                            }
+                            // if (ProviderUtil.device.mDevice?.clientType === BtParse.mateX2) {
+                            //     BtParse._send(EnumCmdEvent.nextAlbum);
+                            // } else {
+                            //     BtParse._send(EnumCmdEvent.nextSong);
+                            // }
                         }
                         break;
 
@@ -253,11 +258,12 @@ class BtParse {
                         }
                         // 3 单击上一专辑或者上一曲
                         else if (value === CmdKey.changeProgram) {
-                            if (ProviderUtil.device.mDevice?.clientType === BtParse.mateX2) {
-                                BtParse._send(EnumCmdEvent.previousAlbum);
-                            } else {
-                                BtParse._send(EnumCmdEvent.previousSong);
-                            }
+                            // todo
+                            // if (ProviderUtil.device.mDevice?.clientType === BtParse.mateX2) {
+                            //     BtParse._send(EnumCmdEvent.previousAlbum);
+                            // } else {
+                            //     BtParse._send(EnumCmdEvent.previousSong);
+                            // }
                         }
                         break;
 
@@ -300,7 +306,7 @@ class BtParse {
                 const d = phoneMax / max;
 
                 const result = (d * value).toFixed(2);
-                const trueVolume = parseFloat(result);
+                var trueVolume = parseFloat(result) ?? 0;
 
                 console.log("trueVolume=====", max, "===", d, ",,,,", value, ",,,,", result, ",,,,", trueVolume);
                 if (trueVolume > phoneMax) {

+ 425 - 451
devices/bt_helper.js

@@ -4,10 +4,7 @@
 // const BtIOSHelper = require('./BtIOSHelper');
 // const QueueManager = require('./QueueManager');
 // const DeviceManager = require('./DeviceManager');
-const {
-  CmdBase,
-  BtCmd,
-} = require('./../devices/bluetooth/bt_cmd');
+const { CmdBase, BtCmd, } = require('./../devices/bluetooth/bt_cmd');
 const BtParse = require('./../devices/bluetooth/bt_parse');
 // const VolumeUtil = require('./VolumeUtil');
 // const EventManager = require('./EventManager');
@@ -22,468 +19,445 @@ const QueueManager = require('./QueueManager');
 // const EnumLowDelayMode = require('./EnumLowDelayMode');
 // const EnumPlayStatus = require('./EnumPlayStatus');
 
+
+
+
 class BtHelper {
-  static getInstance() {
-    // if (!BtHelper._instance) {
-    //     BtHelper._instance = new BtHelper();
-    // }
-    return BtHelper._instance;
-  }
-  static _instance = new BtHelper();
-  static _isConnecting = false;
-  static isDisConnectByOTA = false;
-  // _helper;
-
-  constructor() {
-    this.timer = null;
-    this.bleManager = new bleManager();
-    // if (DeviceUtil.isAndroid) {
-    //     this._helper = BtAndroidHelper.instance;
-    // } else {
-    //     this._helper = BtIOSHelper.instance;
-    // }
-
-    // QueueManager.instance.listenTask((task) => {
-    //     if (!DeviceManager.instance.isWatch) {
-    //         this._helper.send({ cmd: task });
-    //     }
-    // });
-    this.queueManager = new QueueManager();
-    let _this = this
-    this.queueManager.clear();
-    this.queueManager.listenTask((task) => {
-      _this.bleManager.sendData(task);
-    });
-  }
-
-
-  resetConnectState(connect) {
-    // BtHelper._isConnecting = connect;
-  }
-
-  async search(stopCall) {
-    let res = await this.bleManager.startScan();
-    this.timer = null;
-    this.timer = setTimeout(() => {
-      this.stopSearch();
-      if (stopCall) {
-        stopCall()
-      }
-    }, 10000);
-    // console.log(res);
-    // return await this._helper.search();
-  }
-
-  async findDevices(callback) {
-    this.bleManager.onBluetoothDeviceFound(callback)
-    // return await this._helper.search();
-  }
-
-  async stopSearch() {
-    clearTimeout(this.timer);
-    this.timer = null;
-    await this.bleManager.stopScan();
-  }
-
-  async _connectSuccess() {
-    this.checkDevice()
-    this.getDeviceInfo()
-
-  }
-
-  async connect(data, onChanged) {
-    // await this._helper.connect({ data, onChanged, isClick });
-
-    clearTimeout(this.timer);
-    this.timer = null;
-    this.bleManager.stopScan()
-    var res = await this.bleManager.connectToDevice(data);
-    console.log(res ? '连接成功' : '连接失败');
-    // this.setData({ connectedDeviceId: deviceId });
-    if (res === false) {
-      console.log("连接失败")
-      this.disconnect(data)
-      if (onChanged) {
-        onChanged(false)
-      }
-      return
-    }
-    const serviceId = await this.bleManager.discoverServices(data.deviceId);
-    if (serviceId == "") {
-      console.log("连接失败")
-      this.disconnect(data)
-      if (onChanged) {
-        onChanged(false)
-      }
-      return
-    }
-    // this.setData({ services });
-    console.log("服务ID:" + serviceId)
-
-    var characteristics = await this.bleManager.discoverCharacteristics(data.deviceId, serviceId)
-    if (characteristics == "") {
-      console.log("连接失败")
-      this.disconnect(data)
-      if (onChanged) {
-        onChanged(false)
-      }
-      return
-    }
-    console.log('device特征值:', characteristics)
-    // let uuids = ["ab00", "ffc0"];
-    for (let i = 0; i < characteristics.length; i++) {
-      let charc = characteristics[i];
-      // if (!uuids.includes(charc.uuid)) {
-      //     if (onChanged) {
-      //         console.log('没有特征值:', charc.uuid);
-      //         onChanged(false)
-      //     }
-      //     return;
-      // }
-      if (charc.properties.notify) {
-        console.log('订阅数据:', charc.uuid);
-        // 订阅的
-        this.bleManager.notifyCharacteristicValueChange(charc.uuid, (res) => {
-          BtParse.parseTLV(res);
-        })
-      }
-      if (charc.properties.write || charc.properties.writeWithoutResponse) {
-        // 写入的
-        this.bleManager.setWrite(charc, charc.uuid)
-        setTimeout(() => {
-          this._connectSuccess()
-        }, 500);
-        if (onChanged) {
-          onChanged(true)
-        }
-      }
-      // if (charc.properties.read) {
-      //     var chara = await this.bleManager.readCharacteristicValue(charc.uuid,)
-      // }
+
+    static getInstance() {
+        // if (!BtHelper._instance) {
+        //     BtHelper._instance = new BtHelper();
+        // }
+        return BtHelper._instance;
+    }
+
+    static _instance = new BtHelper();
+
+    static _isConnecting = false;
+    static isDisConnectByOTA = false;
+
+    // _helper;
+
+    constructor() {
+        this.timer = null;
+        this.bleManager = new bleManager();
+        // if (DeviceUtil.isAndroid) {
+        //     this._helper = BtAndroidHelper.instance;
+        // } else {
+        //     this._helper = BtIOSHelper.instance;
+        // }
+
+        // QueueManager.instance.listenTask((task) => {
+        //     if (!DeviceManager.instance.isWatch) {
+        //         this._helper.send({ cmd: task });
+        //     }
+        // });
+        this.queueManager = new QueueManager();
+        let _this = this
+        this.queueManager.clear();
+        this.queueManager.listenTask((task) => {
+            _this.bleManager.sendData(task);
+        });
     }
 
 
-    // this.setData({ characteristics: { ...this.data.characteristics, [service.uuid]: characteristics } });
+    resetConnectState(connect) {
+        // BtHelper._isConnecting = connect;
+    }
 
-  }
+    async search(stopCall) {
+        let res = await this.bleManager.startScan()
+        this.timer = null;
+        this.timer = setTimeout(() => {
+            this.stopSearch();
+            if (stopCall) {
+                stopCall()
+            }
+        }, 10000);
+        // console.log(res);
+        // return await this._helper.search();
+    }
 
-  async disconnect(data) {
-    this.bleManager.disconnect(data.deviceId)
-  }
+    async findDevices(callback) {
+        this.bleManager.onBluetoothDeviceFound(callback)
+        // return await this._helper.search();
+    }
 
-  async dispose() {
-    // await this._helper.dispose();
-  }
+    async stopSearch() {
+        clearTimeout(this.timer);
+        this.timer = null;
+        await this.bleManager.stopScan();
+    }
+
+    async _connectSuccess() {
+        this.checkDevice()
+        this.getDeviceInfo()
+
+    }
+
+    async connect(data, onChanged) {
+        // await this._helper.connect({ data, onChanged, isClick });
+
+        clearTimeout(this.timer);
+        this.timer = null;
+        this.bleManager.stopScan()
+        var res = await this.bleManager.connectToDevice(data);
+        console.log(res ? '连接成功' : '连接失败');
+        // this.setData({ connectedDeviceId: deviceId });
+        if (res === false) {
+            console.log("连接失败")
+            this.disconnect(data)
+            if (onChanged) {
+                onChanged(false)
+            }
+            return
+        }
+        const serviceId = await this.bleManager.discoverServices(data.deviceId);
+        if (serviceId == "") {
+            console.log("连接失败")
+            this.disconnect(data)
+            if (onChanged) {
+                onChanged(false)
+            }
+            return
+        }
+        // this.setData({ services });
+        console.log("服务ID:" + serviceId)
+
+        var characteristics = await this.bleManager.discoverCharacteristics(data.deviceId, serviceId)
+        if (characteristics == "") {
+            console.log("连接失败")
+            this.disconnect(data)
+            if (onChanged) {
+                onChanged(false)
+            }
+            return
+        }
+        console.log('device特征值:', characteristics)
+        let uuids = ["AB01", "FFC1"];
+        for (let i = 0; i < characteristics.length; i++) {
+            let charc = characteristics[i];
+            if (uuids.includes(charc.uuid.toUpperCase())) {
+                console.log('有特征值:', charc.uuid);
+            }
+
+            if (charc.properties.notify) {
+                console.log('订阅数据:', charc.uuid);
+                // 订阅的
+                this.bleManager.notifyCharacteristicValueChange(charc.uuid, (res) => {
+                    BtParse.parseTLV(res);
+                })
+            }
+            if (charc.properties.write || charc.properties.writeWithoutResponse) {
+                // 写入的
+                this.bleManager.setWrite(charc, charc.uuid)
+                setTimeout(() => {
+                    this._connectSuccess()
+                }, 100);
+                if (onChanged) {
+                    onChanged(true)
+                }
+            }
+
+
+
+            // if (charc.properties.read) {
+            //     var chara = await this.bleManager.readCharacteristicValue(charc.uuid,)
+            // }
+        }
+
+
+        // this.setData({ characteristics: { ...this.data.characteristics, [service.uuid]: characteristics } });
+
+    }
+
+    async disconnect(data) {
+        this.bleManager.disconnect(data.deviceId)
+    }
+
+    async dispose() {
+        // await this._helper.dispose();
+    }
 
-  async sendNow(cmd) {
-    if (cmd) {
-      this.bleManager.sendData(cmd)
+    async sendNow(cmd) {
+        if (cmd) {
+            this.bleManager.sendData(cmd)
+        }
     }
-  }
-  async send(cmd, type) {
-    if (cmd) {
-      this.queueManager.addTask(cmd)
+    async send(cmd, type) {
+        if (cmd) {
+            this.queueManager.addTask(cmd)
+        }
+        // QueueManager.instance.addTask({ task: cmd });
     }
-    // QueueManager.instance.addTask({ task: cmd });
-  }
 
-  // onLoad: function () {
-  //     bleManager = new bleManager();
-  //     this.initBluetooth();
-  //   }
+    // onLoad: function () {
+    //     bleManager = new bleManager();
+    //     this.initBluetooth();
+    //   }
+
+    async initBluetooth(callback) {
+        let adpter = await this.bleManager.initBluetoothAdapter((res) => {
+            if (!res) {
+                wx.showToast({
+                    title: '请开启蓝牙功能',
+                    icon: 'none'
+                })
+                if (callback) {
+                    callback(false, false)
+                }
+                return
+            }
+        });
+        // console.log(res)
+
+
+        this.bleManager.checkBluetoothPermission(function (per) {
+            if (!per) {
+                wx.showToast({
+                    title: '没有蓝牙权限',
+                    icon: 'none'
+                })
+            }
+            if (callback) {
+                callback(adpter, per)
+            }
+        });
+    }
 
-  ///初始化蓝牙
-  async initBluetooth(callback) {
-    var that = this;
-    let adpter = await that.bleManager.initBluetoothAdapter((res) => {
-      if (!res) {
-        wx.showToast({
-          title: '请开启蓝牙功能',
-          icon: 'none'
-        })
-        if (callback) {
-          callback(false, false)
+    closeBle() {
+        this.bleManager.closeBle()
+    }
+
+    async getConnectedDevices() {
+        try {
+            const connectedDevices = await this.bleManager.getConnectedDevices();
+            console.log("全部设备1:", connectedDevices)
+            if (connectedDevices.length) {
+                // todo 已经连接上的设备
+            }
+            const allDevices = await this.bleManager.getAllConnectedDevices()
+            console.log("全部设备2:", allDevices)
+            let newDevices = connectedDevices.concat(allDevices);
+            return newDevices
+        } catch (error) {
+            console.error(error);
+            return []
         }
-        return
-      }
-    });
-    // console.log(res)
-    that.bleManager.checkBluetoothPermission(function (per) {
-      if (!per) {
-        wx.showToast({
-          title: '没有蓝牙权限',
-          icon: 'none'
-        })
-      }
-      if (callback) {
-        callback(adpter, per)
-      }
-    });
-  }
-
-  closeBle() {
-    var that = this;
-    that.bleManager.closeBle()
-  }
-
-  async getConnectedDevices() {
-    try {
-      const connectedDevices = await this.bleManager.getConnectedDevices();
-      console.log("全部设备1:", connectedDevices)
-      if (connectedDevices.length) {
-        // todo 已经连接上的设备
-      }
-      const allDevices = await this.bleManager.getAllConnectedDevices()
-      console.log("全部设备2:", allDevices)
-      let newDevices = connectedDevices.concat(allDevices);
-      return newDevices
-    } catch (error) {
-      console.error(error);
-      return []
-    }
-  }
-
-  async checkDevice() {
-    // console.log("校验设备:", BtCmd); // 输出: EarPhone Info
-    this.sendNow(BtCmd.checkDevice());
-    //2.0有发这个,不知道是啥
-    this.send([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x26, 0x01, 0x01]);
-  }
-
-  async getVersion() {
-    this.send(BtCmd.queryVersion());
-  }
-
-  _time() {
-    return 400;
-  }
-
-  getDeviceInfo() {
-    // if (DeviceManager.instance.isEarphone) {
-    //     this.send(BtCmd.queryKwhEarPhone);
-    //     this.send(BtCmd.queryLowDelayMode);
-    //     this.send(BtCmd.queryEQ);
-    //     this.send(BtCmd.queryLowPower);
-    //     this.send(BtCmd.queryCtrlStatus);
-    // } else {
-    // this.send(BtCmd.setDevTime());
-    this.send(BtCmd.queryKwh());
-    this.getSleep();
-    this.getAlert();
-    this.send(BtCmd.queryRGB());
-    this.getVolume();
-    this.setVolume(8)
-    this.getPauseSleep();
-    // }
-  }
-
-  async getAlert() {
-    this.send(BtCmd.queryAlarm());
-  }
-
-  async getSleep() {
-    this.send(BtCmd.querySleep());
-  }
-
-  async setAlert(open, weekCycle, hour, minutes, channel = 1) {
-    this.send(BtCmd.setAlarm({
-      switchStatus: open,
-      weekCycle,
-      hour,
-      minutes
-    }));
-  }
-
-  async setAutoPlay(open) {
-    this.send(BtCmd.setAutoPlay({
-      switchStatus: open
-    }));
-  }
-
-  async getAutoPlay() {
-    this.send(BtCmd.getAutoPlay);
-  }
-
-  async setLowKwhWarningTone(notify) {
-    this.send(BtCmd.setLowKwhWarningTone({
-      notify
-    }));
-  }
-
-  async setPauseSleep(time) {
-    this.send(BtCmd.setSleepAfterPlayPause({
-      time
-    }));
-  }
-
-  async getPauseSleep() {
-    this.send(BtCmd.querySleepAfterPlayPause());
-  }
-
-  async setRGB(r, g, b) {
-    this.send(BtCmd.setRGB({
-      r,
-      g,
-      b
-    }));
-  }
-
-  async setSleep(open, hour, minutes) {
-    this.send(BtCmd.setSleep({
-      switchStatus: open,
-      hour,
-      minutes
-    }));
-  }
-
-  async setTime() {
-    console.log("setTime========111")
-    // this.send(BtCmd.setTime());
-  }
-
-  async setVolume(volume) {
-    // VolumeUtil.setVolume(volume, { hideVolumeView: true });
-
-    const phoneMax = 15; //await VolumeUtil.getMaxVolume();
-    const result = Math.floor(CmdBase.volumeMax * volume / phoneMax);
-
-    console.log(`phoneMax=${phoneMax}, deviceMax=${CmdBase.volumeMax}, setVolume=${volume}, result=${result}`);
-
-    this.send(BtCmd.setVolume({
-      volume: 8
-    }));
-  }
-
-  async getVolume() {
-    this.send(BtCmd.queryVolume());
-  }
-
-  stop() {
-    // EventManager.fire({ event: 'playStatus', playStatus: EnumPlayStatus.stop.index });
-  }
-
-  next() {
-    // TODO: implement next
-  }
-
-  pause() {
-    // EventManager.fire({ event: 'playStatus', playStatus: EnumPlayStatus.pause.index });
-  }
-
-  play() {
-    // TODO: implement play
-  }
-
-  previous() {
-    // TODO: implement previous
-  }
-
-  startVoiceRecordResponse(supplier) {
-    console.log(`回调开始录音:${supplier}`);
-    // switch (supplier) {
-    //     case EnumSupplier.jieLi:
-    //         this.send(BtCmd.jlStartVoiceResponse);
-    //         break;
-    //     case EnumSupplier.lingXin:
-    //         this.send(BtCmd.lxStartVoiceResponse);
-    //         break;
-    //     case EnumSupplier.qiXinWei:
-    //         this.send(BtCmd.b1StartVoiceResponse);
-    //         break;
-    // }
-  }
-
-  stopVoiceRecordResponse(supplier) {
-    console.log(`回调结束录音:${supplier}`);
-    // switch (supplier) {
-    //     case EnumSupplier.jieLi:
-    //         this.send(BtCmd.jlStopVoiceResponse());
-    //         break;
-    //     case EnumSupplier.lingXin:
-    //         this.send(BtCmd.lxStopVoiceResponse());
-    //         break;
-    //     case EnumSupplier.qiXinWei:
-    //         this.send(BtCmd.b1StopVoiceResponse());
-    //         break;
-    // }
-  }
-
-  async getLowDelayMode() {
-    this.send(BtCmd.queryLowDelayMode());
-  }
-
-  async setLowDelayMode(open, mode) {
-    this.send(BtCmd.setLowDelayMode({
-      open,
-      mode
-    }));
-  }
-
-  async setLowPowerMode(isOpen) {
-    this.send(BtCmd.setLowPowerMode({
-      isOpen: isOpen ? EnumOpen.open : EnumOpen.close
-    }));
-  }
-
-  async queryLowPower() {
-    this.send(BtCmd.queryLowPower());
-  }
-
-  async setCtrlStatus(singleClick, doubleClick, longClick) {
-    this.send(BtCmd.setCtrlStatus({
-      singleClick,
-      doubleClick,
-      longClick
-    }));
-  }
-
-  async getEQ() {
-    this.send(BtCmd.queryEQ());
-  }
-
-  async setEQ(list) {
-    this.send(BtCmd.setEQ({
-      list
-    }));
-  }
-
-  async queryLowKwhWarningTone() {
-    this.send(BtCmd.queryLowKwhWarningTone());
-  }
-
-  async changeChannelCallBack() {
-    this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x0a, 0x29, 0x02, 0x00, 0x01]));
-    this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x39, 0x01, 0x00]));
-  }
-
-  /* 黑胶音箱的指令 */
-  // 壁纸指令 1开始, 0结束
-  static wallPaper(value) {
-    this.send(BtCmd.wallPaper(value));
-  }
-  // 壁纸指令 
-  static wallPaperData(value) {
-    this.send(BtCmd.wallPaperData(value));
-  }
-  // 背景图指令
-  static backgroudImg(value) {
-    this.send(BtCmd.backgroudImg(value));
-  } // 背景图指令
-  static backgroudImgData(value) {
-    this.send(BtCmd.backgroudImgData(value));
-  }
-  // OTA指令
-  static OTA(value) {
-    this.send(BtCmd.OTA(value));
-  }
-  static OtaData(value) {
-    this.send(BtCmd.OtaData(value));
-  }
+    }
+
+    async checkDevice() {
+        // console.log("校验设备:", BtCmd); // 输出: EarPhone Info
+        this.sendNow(BtCmd.checkDevice());
+        //2.0有发这个,不知道是啥
+        this.send([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x26, 0x01, 0x01]);
+    }
+
+    async getVersion() {
+        this.send(BtCmd.queryVersion());
+    }
+
+    _time() {
+        return 400;
+    }
+
+    getDeviceInfo() {
+        // if (DeviceManager.instance.isEarphone) {
+        //     this.send(BtCmd.queryKwhEarPhone);
+        //     this.send(BtCmd.queryLowDelayMode);
+        //     this.send(BtCmd.queryEQ);
+        //     this.send(BtCmd.queryLowPower);
+        //     this.send(BtCmd.queryCtrlStatus);
+        // } else {
+        // this.send(BtCmd.setDevTime());
+
+        this.send(BtCmd.queryKwh());
+        this.getSleep();
+        this.getAlert();
+        this.send(BtCmd.queryRGB());
+        this.getVolume();
+        this.setVolume(8)
+        this.getPauseSleep();
+
+        this.send(BtCmd.getClientType());
+        this.send(BtCmd.getIsConnect());
+        this.send(BtCmd.getMac());
+
+        // }
+    }
+
+    async getAlert() {
+        this.send(BtCmd.queryAlarm());
+    }
+
+    async getSleep() {
+        this.send(BtCmd.querySleep());
+    }
+
+    async setAlert(open, weekCycle, hour, minutes, channel = 1) {
+        this.send(BtCmd.setAlarm({ switchStatus: open, weekCycle, hour, minutes }));
+    }
+
+    async setAutoPlay(open) {
+        this.send(BtCmd.setAutoPlay({ switchStatus: open }));
+    }
+
+    async getAutoPlay() {
+        this.send(BtCmd.getAutoPlay);
+    }
+
+    async setLowKwhWarningTone(notify) {
+        this.send(BtCmd.setLowKwhWarningTone({ notify }));
+    }
+
+    async setPauseSleep(time) {
+        this.send(BtCmd.setSleepAfterPlayPause({ time }));
+    }
+
+    async getPauseSleep() {
+        this.send(BtCmd.querySleepAfterPlayPause());
+    }
+
+    async setRGB(r, g, b) {
+        this.send(BtCmd.setRGB({ r, g, b }));
+    }
+
+    async setSleep(open, hour, minutes) {
+        this.send(BtCmd.setSleep({ switchStatus: open, hour, minutes }));
+    }
+
+    async setTime() {
+        console.log("setTime========111")
+        // this.send(BtCmd.setTime());
+    }
+
+    async setVolume(volume) {
+        // VolumeUtil.setVolume(volume, { hideVolumeView: true });
+
+        const phoneMax = 15;//await VolumeUtil.getMaxVolume();
+        const result = Math.floor(CmdBase.volumeMax * volume / phoneMax);
+
+        console.log(`phoneMax=${phoneMax}, deviceMax=${CmdBase.volumeMax}, setVolume=${volume}, result=${result}`);
+
+        this.send(BtCmd.setVolume(8));
+    }
+
+    async getVolume() {
+        this.send(BtCmd.queryVolume());
+    }
+
+    stop() {
+        // EventManager.fire({ event: 'playStatus', playStatus: EnumPlayStatus.stop.index });
+    }
+
+    next() {
+        // TODO: implement next
+    }
+
+    pause() {
+        // EventManager.fire({ event: 'playStatus', playStatus: EnumPlayStatus.pause.index });
+    }
+
+    play() {
+        // TODO: implement play
+    }
+
+    previous() {
+        // TODO: implement previous
+    }
+
+    startVoiceRecordResponse(supplier) {
+        console.log(`回调开始录音:${supplier}`);
+        // switch (supplier) {
+        //     case EnumSupplier.jieLi:
+        //         this.send(BtCmd.jlStartVoiceResponse);
+        //         break;
+        //     case EnumSupplier.lingXin:
+        //         this.send(BtCmd.lxStartVoiceResponse);
+        //         break;
+        //     case EnumSupplier.qiXinWei:
+        //         this.send(BtCmd.b1StartVoiceResponse);
+        //         break;
+        // }
+    }
+
+    stopVoiceRecordResponse(supplier) {
+        console.log(`回调结束录音:${supplier}`);
+        // switch (supplier) {
+        //     case EnumSupplier.jieLi:
+        //         this.send(BtCmd.jlStopVoiceResponse());
+        //         break;
+        //     case EnumSupplier.lingXin:
+        //         this.send(BtCmd.lxStopVoiceResponse());
+        //         break;
+        //     case EnumSupplier.qiXinWei:
+        //         this.send(BtCmd.b1StopVoiceResponse());
+        //         break;
+        // }
+    }
+
+    async getLowDelayMode() {
+        this.send(BtCmd.queryLowDelayMode());
+    }
+
+    async setLowDelayMode(open, mode) {
+        this.send(BtCmd.setLowDelayMode({ open, mode }));
+    }
+
+    async setLowPowerMode(isOpen) {
+        this.send(BtCmd.setLowPowerMode({ isOpen: isOpen ? EnumOpen.open : EnumOpen.close }));
+    }
+
+    async queryLowPower() {
+        this.send(BtCmd.queryLowPower());
+    }
+
+    async setCtrlStatus(singleClick, doubleClick, longClick) {
+        this.send(BtCmd.setCtrlStatus({ singleClick, doubleClick, longClick }));
+    }
+
+    async getEQ() {
+        this.send(BtCmd.queryEQ());
+    }
+
+    async setEQ(list) {
+        this.send(BtCmd.setEQ({ list }));
+    }
+
+    async queryLowKwhWarningTone() {
+        this.send(BtCmd.queryLowKwhWarningTone());
+    }
+
+    async changeChannelCallBack() {
+        this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x0a, 0x29, 0x02, 0x00, 0x01]));
+        this.send(Uint8Array.from([0x54, 0x44, 0x44, 0x48, 0x01, 0x09, 0x39, 0x01, 0x00]));
+    }
+
+    /* 黑胶音箱的指令 */
+    // 壁纸指令 1开始, 0结束
+    static wallPaper(value) {
+        this.send(BtCmd.wallPaper(value));
+    }
+    // 壁纸指令 
+    static wallPaperData(value) {
+        this.send(BtCmd.wallPaperData(value));
+    }
+    // 背景图指令
+    static backgroudImg(value) {
+        this.send(BtCmd.backgroudImg(value));
+    }   // 背景图指令
+    static backgroudImgData(value) {
+        this.send(BtCmd.backgroudImgData(value));
+    }
+    // OTA指令
+    static OTA(value) {
+        this.send(BtCmd.OTA(value));
+    } static OtaData(value) {
+        this.send(BtCmd.OtaData(value));
+    }
 }
 
 // 导出 BtHelper 类
 // const btHelper = new BtHelper();
 
-module.exports = {
-  BtHelper
-}
+module.exports = { BtHelper }