|
@@ -251,96 +251,96 @@ export default {
|
|
|
return $power;
|
|
|
},
|
|
|
|
|
|
- /**
|
|
|
- * todo:监听蓝牙连接状态
|
|
|
- * 监听蓝牙低功耗连接状态改变事件。包括开发者主动连接或断开连接,设备丢失,连接异常断开等
|
|
|
- */
|
|
|
- watchBLEstatus($this) {
|
|
|
- let that = this;
|
|
|
- // 微信自身监听低功耗蓝牙连接状态的改变事件
|
|
|
- wx.onBLEConnectionStateChange((res) => {
|
|
|
- // 该方法回调中可以用于处理连接意外断开等异常情况
|
|
|
- ble_store.setters.setBluetoothLinkStatus(res.connected);
|
|
|
- LogInDb(`${that.getNowTime()} 监听脑机断连`)
|
|
|
- if (res.connected == false) {
|
|
|
- //判断游戏是否游戏中
|
|
|
- let $game_status = game_store.getters.getGameStatus();
|
|
|
- if ($game_status == 1) {
|
|
|
- // $that.game_finished();
|
|
|
- Notify({
|
|
|
- type: 'danger',
|
|
|
- duration: 0,
|
|
|
- message: '智脑机已断开连接,正在尝试重新连接',
|
|
|
- onOpened() {
|
|
|
- that.reconnect(res.deviceId, $this)
|
|
|
- }
|
|
|
- });
|
|
|
- control_close = true
|
|
|
- // connect_toy = false;
|
|
|
- } else {
|
|
|
- //关闭脑控
|
|
|
- connect_toy = false;
|
|
|
- game_store.setters.setGameStatus(0);
|
|
|
- // 清空链接得设备 三值
|
|
|
- game_store.setters.clearDeviceToy();
|
|
|
- $this.connect_toy = 0;
|
|
|
- $this.connect_show = false;
|
|
|
- $this.device_bg = false;
|
|
|
- $this.device_status = 0;
|
|
|
- $this.device = {}
|
|
|
- $this.toy_UUID = "";
|
|
|
- $this.$forceUpdate();
|
|
|
- wx.closeBluetoothAdapter();
|
|
|
- version = "";
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * todo:重新连接蓝牙
|
|
|
- */
|
|
|
- reconnect($deviceId, $this) {
|
|
|
- let that = this;
|
|
|
- let $deviceInfo = getServicesAndCharateristc();
|
|
|
- //重连的次数
|
|
|
- let $connect_count = 0;
|
|
|
- let $rec = setInterval(() => {
|
|
|
- let $game_status = game_store.getters.getGameStatus();
|
|
|
- if ($game_status == 1) {
|
|
|
- wx.createBLEConnection({
|
|
|
- deviceId: $deviceInfo.deviceId,
|
|
|
- success(res) {
|
|
|
- clearInterval($rec)
|
|
|
- Notify({type: 'success', message: `第${$connect_count}次重新连接成功`});
|
|
|
- LogInDb(`${that.getNowTime()} 第${$connect_count}次重新连接成功`)
|
|
|
- let $system = wx.getSystemInfoSync()
|
|
|
- if ($system.platform == 'ios') {
|
|
|
- that.getBLEDeviceServices($deviceInfo.deviceId)
|
|
|
- that.notifyDatas($this)
|
|
|
- } else {
|
|
|
- that.openNotify($this)
|
|
|
- that.watchBLEstatus($this);
|
|
|
- }
|
|
|
- // that.sendToyPower();
|
|
|
-
|
|
|
- },
|
|
|
- fail(res) {
|
|
|
- Notify({type: 'danger', message: `第${$connect_count}次重新连接失败`});
|
|
|
- game_store.setters.setGameCloseStatus(1);
|
|
|
- }
|
|
|
- })
|
|
|
- if ($connect_count >= 3) {
|
|
|
- $this.game_finished();
|
|
|
- clearInterval($rec)
|
|
|
- }
|
|
|
- $connect_count += 1;
|
|
|
- } else {
|
|
|
- clearInterval($rec)
|
|
|
- }
|
|
|
- }, 7000)
|
|
|
-
|
|
|
- },
|
|
|
+ // /**
|
|
|
+ // * todo:监听蓝牙连接状态
|
|
|
+ // * 监听蓝牙低功耗连接状态改变事件。包括开发者主动连接或断开连接,设备丢失,连接异常断开等
|
|
|
+ // */
|
|
|
+ // watchBLEstatus($this) {
|
|
|
+ // let that = this;
|
|
|
+ // // 微信自身监听低功耗蓝牙连接状态的改变事件
|
|
|
+ // wx.onBLEConnectionStateChange((res) => {
|
|
|
+ // // 该方法回调中可以用于处理连接意外断开等异常情况
|
|
|
+ // ble_store.setters.setBluetoothLinkStatus(res.connected);
|
|
|
+ // LogInDb(`${that.getNowTime()} 监听脑机断连`)
|
|
|
+ // if (res.connected == false) {
|
|
|
+ // //判断游戏是否游戏中
|
|
|
+ // let $game_status = game_store.getters.getGameStatus();
|
|
|
+ // if ($game_status == 1) {
|
|
|
+ // // $that.game_finished();
|
|
|
+ // Notify({
|
|
|
+ // type: 'danger',
|
|
|
+ // duration: 0,
|
|
|
+ // message: '智脑机已断开连接,正在尝试重新连接',
|
|
|
+ // onOpened() {
|
|
|
+ // that.reconnect(res.deviceId, $this)
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // control_close = true
|
|
|
+ // // connect_toy = false;
|
|
|
+ // } else {
|
|
|
+ // //关闭脑控
|
|
|
+ // connect_toy = false;
|
|
|
+ // game_store.setters.setGameStatus(0);
|
|
|
+ // // 清空链接得设备 三值
|
|
|
+ // ble_store.setters.clearDeviceToy();
|
|
|
+ // $this.connect_toy = 0;
|
|
|
+ // $this.connect_show = false;
|
|
|
+ // $this.device_bg = false;
|
|
|
+ // $this.device_status = 0;
|
|
|
+ // $this.device = {}
|
|
|
+ // $this.toy_UUID = "";
|
|
|
+ // $this.$forceUpdate();
|
|
|
+ // wx.closeBluetoothAdapter();
|
|
|
+ // version = "";
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ //
|
|
|
+ // /**
|
|
|
+ // * todo:重新连接蓝牙
|
|
|
+ // */
|
|
|
+ // reconnect($deviceId, $this) {
|
|
|
+ // let that = this;
|
|
|
+ // let $deviceInfo = getServicesAndCharateristc();
|
|
|
+ // //重连的次数
|
|
|
+ // let $connect_count = 0;
|
|
|
+ // let $rec = setInterval(() => {
|
|
|
+ // let $game_status = game_store.getters.getGameStatus();
|
|
|
+ // if ($game_status == 1) {
|
|
|
+ // wx.createBLEConnection({
|
|
|
+ // deviceId: $deviceInfo.deviceId,
|
|
|
+ // success(res) {
|
|
|
+ // clearInterval($rec)
|
|
|
+ // Notify({type: 'success', message: `第${$connect_count}次重新连接成功`});
|
|
|
+ // LogInDb(`${that.getNowTime()} 第${$connect_count}次重新连接成功`)
|
|
|
+ // let $system = wx.getSystemInfoSync()
|
|
|
+ // if ($system.platform == 'ios') {
|
|
|
+ // that.getBLEDeviceServices($deviceInfo.deviceId)
|
|
|
+ // that.notifyDatas($this)
|
|
|
+ // } else {
|
|
|
+ // that.openNotify($this)
|
|
|
+ // that.watchBLEstatus($this);
|
|
|
+ // }
|
|
|
+ // // that.sendToyPower();
|
|
|
+ //
|
|
|
+ // },
|
|
|
+ // fail(res) {
|
|
|
+ // Notify({type: 'danger', message: `第${$connect_count}次重新连接失败`});
|
|
|
+ // game_store.setters.setGameCloseStatus(1);
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // if ($connect_count >= 3) {
|
|
|
+ // $this.game_finished();
|
|
|
+ // clearInterval($rec)
|
|
|
+ // }
|
|
|
+ // $connect_count += 1;
|
|
|
+ // } else {
|
|
|
+ // clearInterval($rec)
|
|
|
+ // }
|
|
|
+ // }, 7000)
|
|
|
+ //
|
|
|
+ // },
|
|
|
|
|
|
// /**
|
|
|
// * todo 获取蓝牙设备服务
|
|
@@ -419,21 +419,21 @@ export default {
|
|
|
// },
|
|
|
// });
|
|
|
// },
|
|
|
- // 启用蓝牙低功耗设备特征值变化时的 notify 功能,订阅特征。
|
|
|
- openNotify($this) {
|
|
|
- let that = this;
|
|
|
- let $deviceInfo = getServicesAndCharateristc();
|
|
|
- console.log($deviceInfo)
|
|
|
- wx.notifyBLECharacteristicValueChange({
|
|
|
- deviceId: $deviceInfo.deviceId,
|
|
|
- serviceId: $deviceInfo.service,
|
|
|
- characteristicId: $deviceInfo.charateristic.notify,
|
|
|
- state: true,
|
|
|
- success() {
|
|
|
- that.notifyDatas($this)
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
+ // // 启用蓝牙低功耗设备特征值变化时的 notify 功能,订阅特征。
|
|
|
+ // openNotify($this) {
|
|
|
+ // let that = this;
|
|
|
+ // let $deviceInfo = getServicesAndCharateristc();
|
|
|
+ // console.log($deviceInfo)
|
|
|
+ // wx.notifyBLECharacteristicValueChange({
|
|
|
+ // deviceId: $deviceInfo.deviceId,
|
|
|
+ // serviceId: $deviceInfo.service,
|
|
|
+ // characteristicId: $deviceInfo.charateristic.notify,
|
|
|
+ // state: true,
|
|
|
+ // success() {
|
|
|
+ // that.notifyDatas($this)
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
|
|
|
/**
|
|
|
* todo ArrayBuffer转16进度字符串示例
|
|
@@ -451,268 +451,268 @@ export default {
|
|
|
},
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * todo 监听脑机数据
|
|
|
- * @param $this
|
|
|
- */
|
|
|
- notifyDatas($this) {
|
|
|
- const that = this;
|
|
|
- let DeviceId = ble_store.getters.getDeviceId();
|
|
|
- // 监听蓝牙低功耗设备的特征值变化事件
|
|
|
- wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
- // 获取脑机信号值
|
|
|
- wx.getBLEDeviceRSSI({
|
|
|
- deviceId: DeviceId,
|
|
|
- success(res) {
|
|
|
- if (game_store.getters.getGameStatus() == 1) {
|
|
|
- $this.rssi = res.RSSI;
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- let hexStr = that.ab2hex(characteristic.value);
|
|
|
- console.log("plant监听脑机数据:", hexStr, "当前页面名称:", $this.$options.name);
|
|
|
-
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD") != -1 || hexStr.toUpperCase().indexOf("AAEE") != -1 && update_state == false) {
|
|
|
- let nowTime = Math.round(new Date() / 1000);
|
|
|
- console.log("应答", hexStr, '时间:' + that.getNowTime(), "长度", hexStr.length / 2);
|
|
|
- LogInDb(`${that.getNowTime()} 应答:${hexStr}`)
|
|
|
- }
|
|
|
- let $data = that.get_big_data(hexStr);
|
|
|
- let $game_status = game_store.getters.getGameStatus();
|
|
|
-
|
|
|
- // 教具断链
|
|
|
- if (hexStr.toUpperCase().indexOf("AAEE70") != -1) {
|
|
|
- connect_toy = false
|
|
|
- wx.showModal({
|
|
|
- content: "教具已断开",
|
|
|
- success(res) {
|
|
|
- if (res.confirm) {
|
|
|
- //重连机制
|
|
|
- if ($game_status == 1) {
|
|
|
- $this.game_finished();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (hexStr.toUpperCase().indexOf("AAEE8A0000005A") != -1) {
|
|
|
- that.SendOrder("8a")
|
|
|
- }
|
|
|
-
|
|
|
- //防止在首页 连接的时候重复 选择教具 产生了发送多个教具电量
|
|
|
- // if(hexStr.toUpperCase().indexOf("AAEE8A000000FF76") != -1){
|
|
|
- // that.connect_toy = false;
|
|
|
- // }
|
|
|
-
|
|
|
- if (hexStr.toUpperCase().indexOf("AAEE07") != -1) {
|
|
|
- that.sendControl();
|
|
|
- }
|
|
|
- // 2021年10月20日17:18:13 判断教具 连接
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
|
|
|
- //没连接上教具
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD0A0000") != -1) {
|
|
|
- //if (is_new) {
|
|
|
- $this.connect_toy = 3;
|
|
|
- //}
|
|
|
- return false;
|
|
|
- }
|
|
|
- let $mHexStrIndex = hexStr.toUpperCase().indexOf("AADD0A");
|
|
|
- let $hex_index = hexStr.substr($mHexStrIndex + 28, 2)
|
|
|
- let $toy_id = hexStr.substr($mHexStrIndex + 8, 2)
|
|
|
- console.log("连接", $hex_index)
|
|
|
- console.log("教具", $toy_id)
|
|
|
- // 连接上教具
|
|
|
- if (new RegExp("00").test($hex_index) == true) {
|
|
|
- //if (is_new) {
|
|
|
- that.sendConnectOneToOne($toy_id)
|
|
|
- $this.current_hex = `03 00 ${$toy_id} 01 0A`
|
|
|
- console.log("一对多")
|
|
|
- // } else {
|
|
|
- // $this.current_hex = "";
|
|
|
- // wx.showToast({
|
|
|
- // title: "已连接到" + $this.toy_item.name
|
|
|
- // });
|
|
|
- // $this.toy_connected = true;
|
|
|
- // $this.connect_toy = 2;
|
|
|
- // }
|
|
|
- }
|
|
|
- if (new RegExp("01").test($hex_index) == true) {
|
|
|
- console.log("一对一")
|
|
|
- $this.current_hex = "";
|
|
|
- wx.showToast({
|
|
|
- title: "已连接到" + $this.toy_item.name
|
|
|
- });
|
|
|
- $this.toy_connected = true;
|
|
|
- connect_toy = true;
|
|
|
- $this.connect_toy = 2;
|
|
|
-
|
|
|
- //连接成功后 获取一次教具名称
|
|
|
- //TODO 2022-5-25 08:51:15 延迟发送教具UUID
|
|
|
- //2022年5月25日17:21:57 从2秒更换到3秒
|
|
|
- // 判断冥想模式不发送获取教具名字
|
|
|
- if ($toy_id != 80) {
|
|
|
- setTimeout(() => {
|
|
|
- that.SendOrder('87')
|
|
|
- }, 3000)
|
|
|
-
|
|
|
- // 更改为不断获取教具电量
|
|
|
- setTimeout(() => {
|
|
|
- that.sendToyPower();
|
|
|
- }, 5000)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //2021年11月23日10:39:49
|
|
|
- // 获取教具名称
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD87") != -1) {
|
|
|
- let $mHexStr = hexStr.substr(hexStr.toUpperCase().indexOf("AADD87"))
|
|
|
- let $datas = that.DoAnalysis($mHexStr, 10)
|
|
|
- let $number = $datas.match(/\d+/)
|
|
|
- let toy_list_pre = {'01': "SW", '02': "KL", '04': "SC", '05': "PP", '06': "SU", '09': "UF", '12': "JM", '13': "QM"}
|
|
|
- let $sn = toy_list_pre[current_toy_id] + $number;
|
|
|
- $this.toy_sn = $sn;
|
|
|
- //保存教具sn
|
|
|
- game_store.setters.setToySn($sn);
|
|
|
- console.log("获取教具名称hexStr",hexStr)
|
|
|
- console.log("获取教具名称$sn",$sn)
|
|
|
- }
|
|
|
- if (hexStr.toUpperCase().indexOf("AAEE87") != -1) {
|
|
|
- //获取教具电量
|
|
|
- if (current_toy_id != '80') {
|
|
|
- that.SendOrder('87')
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //2021年10月21日16:30:07
|
|
|
- // 获取教具电量
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD8A") != -1) {//接收教具电量状态
|
|
|
- let $_hexStr = hexStr.substr(hexStr.toUpperCase().indexOf("AADD8A") + 6);
|
|
|
- let $power = parseInt($_hexStr.substr(0, 2), 16)
|
|
|
- let $voltage = parseInt($_hexStr.substr(2, 2), 16)
|
|
|
- connect_toy = true;
|
|
|
- // $this.toy_power = Math.round(that.CalBLEPower($voltage));
|
|
|
- if ($power > 0) {
|
|
|
- $this.toy_power = $power
|
|
|
- $this.toy_voltage = $voltage
|
|
|
- ToyPower = $power;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (current_toy_UUID == "") {
|
|
|
- //获取教具UUID
|
|
|
- that.SendOrder('84')
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //监听佩戴正确
|
|
|
- if (hexStr.substr(0, 6) == "555520") {
|
|
|
- //当s1为 00时 数据有效
|
|
|
- let $s1 = hexStr.substr(8, 2);
|
|
|
- // console.log("监听脑机是否带正:", $s1 == '00')
|
|
|
-
|
|
|
- $this.device_bg = $s1 == "00";
|
|
|
- }
|
|
|
-
|
|
|
- // 2021年10月25日09:15:50
|
|
|
- // 读取教具UUID
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD84") != -1) {//接收UUID 5个字节
|
|
|
- let $hex_index = hexStr.toUpperCase().indexOf("AADD84") + 6;
|
|
|
- let $datas = hexStr.substr($hex_index, 10);
|
|
|
- if ($datas != "0000000000") {
|
|
|
- console.log("以获取UUID:" + $datas)
|
|
|
- current_toy_UUID = $datas;
|
|
|
- $this.toy_UUID = $datas;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD09") != -1) {
|
|
|
- control_close = true;
|
|
|
- connect_toy = false;
|
|
|
- }
|
|
|
-
|
|
|
- //收到发送UUID的应答立马发送连接教具的指令
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD8E") != -1) {
|
|
|
- //发送教具连接
|
|
|
- that.WriteBufferInBle(`03 00 ${current_toy_id} 02 0A`)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 处理打开脑控的应答
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD07") != -1) {
|
|
|
- ble_store.setters.setBluetoothLinkStatus(true)
|
|
|
- FlagOpenControl = true;
|
|
|
- }
|
|
|
-
|
|
|
- //todo 监听脑机电量
|
|
|
- if (hexStr.substr(0, 8) == "55550203") {
|
|
|
- let $power = parseInt(hexStr.substr(8, 2), 16);
|
|
|
- let $voltage = parseInt(hexStr.substr(10, 2), 16);
|
|
|
- //监听是否插入USB
|
|
|
- $this.hasUsb = $voltage.toString().substr(0, 1) == 1
|
|
|
- // 监听脑机电量
|
|
|
- if ($power) {
|
|
|
- // console.log("当前脑机电量:", $power)
|
|
|
- $this.device_power = $power;
|
|
|
- $this.device_voltage = $voltage;
|
|
|
- }
|
|
|
- if ($power < 10 && $power > 0) {
|
|
|
- wx.showToast({
|
|
|
- title: "脑机电量不足",
|
|
|
- icon: "none",
|
|
|
- duration: 2000,
|
|
|
- success() {
|
|
|
- // $this.change_device_status(0);
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //游戏中模块
|
|
|
- if ($game_status == 1 && $data) {
|
|
|
- $this.do_datas($data);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 监听原始数据
|
|
|
- if (hexStr.substr(0, 6) == "5555e2") {
|
|
|
- let _buffer = that.doOriginBufferToData(hexStr)
|
|
|
- if ($game_status == 1) {
|
|
|
- wx.setStorageSync('origin_buffer', wx.getStorageSync('origin_buffer') + _buffer.join(',') + ",")
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //todo 打开原始数据
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD04") != -1) {
|
|
|
- raw_data_open = true;
|
|
|
- that.Send2BOrder(true)
|
|
|
- wx.setStorageSync('origin_buffer', "");
|
|
|
- }
|
|
|
-
|
|
|
- //todo 接收脑机关机指令
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD5A00000000A5") != -1) {
|
|
|
- Notify({
|
|
|
- type: 'danger',
|
|
|
- duration: 0,
|
|
|
- message: '智脑机已关机,训练结束',
|
|
|
- onOpened() {
|
|
|
- setTimeout(() => {
|
|
|
- $this.game_finished();
|
|
|
- clearInterval(control_close_intv)
|
|
|
- }, 2000)
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
+ // /**
|
|
|
+ // * todo 监听脑机数据
|
|
|
+ // * @param $this
|
|
|
+ // */
|
|
|
+ // notifyDatas($this) {
|
|
|
+ // const that = this;
|
|
|
+ // let DeviceId = ble_store.getters.getDeviceId();
|
|
|
+ // // 监听蓝牙低功耗设备的特征值变化事件
|
|
|
+ // wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
+ // // 获取蓝牙低功耗设备(脑机)的信号强度
|
|
|
+ // wx.getBLEDeviceRSSI({
|
|
|
+ // deviceId: DeviceId,
|
|
|
+ // success(res) {
|
|
|
+ // if (game_store.getters.getGameStatus() == 1) {
|
|
|
+ // $this.rssi = res.RSSI;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ //
|
|
|
+ // let hexStr = that.ab2hex(characteristic.value);
|
|
|
+ // console.log("plant监听脑机数据:", hexStr, "当前页面名称:", $this.$options.name);
|
|
|
+ //
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD") != -1 || hexStr.toUpperCase().indexOf("AAEE") != -1 && update_state == false) {
|
|
|
+ // let nowTime = Math.round(new Date() / 1000);
|
|
|
+ // console.log("应答", hexStr, '时间:' + that.getNowTime(), "长度", hexStr.length / 2);
|
|
|
+ // LogInDb(`${that.getNowTime()} 应答:${hexStr}`)
|
|
|
+ // }
|
|
|
+ // let $data = that.get_big_data(hexStr);
|
|
|
+ // let $game_status = game_store.getters.getGameStatus();
|
|
|
+ //
|
|
|
+ // // 教具断链
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AAEE70") != -1) {
|
|
|
+ // connect_toy = false
|
|
|
+ // wx.showModal({
|
|
|
+ // content: "教具已断开",
|
|
|
+ // success(res) {
|
|
|
+ // if (res.confirm) {
|
|
|
+ // //重连机制
|
|
|
+ // if ($game_status == 1) {
|
|
|
+ // $this.game_finished();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AAEE8A0000005A") != -1) {
|
|
|
+ // that.SendOrder("8a")
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //防止在首页 连接的时候重复 选择教具 产生了发送多个教具电量
|
|
|
+ // // if(hexStr.toUpperCase().indexOf("AAEE8A000000FF76") != -1){
|
|
|
+ // // that.connect_toy = false;
|
|
|
+ // // }
|
|
|
+ //
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AAEE07") != -1) {
|
|
|
+ // that.sendControl();
|
|
|
+ // }
|
|
|
+ // // 2021年10月20日17:18:13 判断教具 连接
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
|
|
|
+ // //没连接上教具
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD0A0000") != -1) {
|
|
|
+ // //if (is_new) {
|
|
|
+ // $this.connect_toy = 3;
|
|
|
+ // //}
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // let $mHexStrIndex = hexStr.toUpperCase().indexOf("AADD0A");
|
|
|
+ // let $hex_index = hexStr.substr($mHexStrIndex + 28, 2)
|
|
|
+ // let $toy_id = hexStr.substr($mHexStrIndex + 8, 2)
|
|
|
+ // console.log("连接", $hex_index)
|
|
|
+ // console.log("教具", $toy_id)
|
|
|
+ // // 连接上教具
|
|
|
+ // if (new RegExp("00").test($hex_index) == true) {
|
|
|
+ // //if (is_new) {
|
|
|
+ // that.sendConnectOneToOne($toy_id)
|
|
|
+ // $this.current_hex = `03 00 ${$toy_id} 01 0A`
|
|
|
+ // console.log("一对多")
|
|
|
+ // // } else {
|
|
|
+ // // $this.current_hex = "";
|
|
|
+ // // wx.showToast({
|
|
|
+ // // title: "已连接到" + $this.toy_item.name
|
|
|
+ // // });
|
|
|
+ // // $this.toy_connected = true;
|
|
|
+ // // $this.connect_toy = 2;
|
|
|
+ // // }
|
|
|
+ // }
|
|
|
+ // if (new RegExp("01").test($hex_index) == true) {
|
|
|
+ // console.log("一对一")
|
|
|
+ // $this.current_hex = "";
|
|
|
+ // wx.showToast({
|
|
|
+ // title: "已连接到" + $this.toy_item.name
|
|
|
+ // });
|
|
|
+ // $this.toy_connected = true;
|
|
|
+ // connect_toy = true;
|
|
|
+ // $this.connect_toy = 2;
|
|
|
+ //
|
|
|
+ // //连接成功后 获取一次教具名称
|
|
|
+ // //TODO 2022-5-25 08:51:15 延迟发送教具UUID
|
|
|
+ // //2022年5月25日17:21:57 从2秒更换到3秒
|
|
|
+ // // 判断冥想模式不发送获取教具名字
|
|
|
+ // if ($toy_id != 80) {
|
|
|
+ // setTimeout(() => {
|
|
|
+ // that.SendOrder('87')
|
|
|
+ // }, 3000)
|
|
|
+ //
|
|
|
+ // // 更改为不断获取教具电量
|
|
|
+ // setTimeout(() => {
|
|
|
+ // that.sendToyPower();
|
|
|
+ // }, 5000)
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //2021年11月23日10:39:49
|
|
|
+ // // 获取教具名称
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD87") != -1) {
|
|
|
+ // let $mHexStr = hexStr.substr(hexStr.toUpperCase().indexOf("AADD87"))
|
|
|
+ // let $datas = that.DoAnalysis($mHexStr, 10)
|
|
|
+ // let $number = $datas.match(/\d+/)
|
|
|
+ // let toy_list_pre = {'01': "SW", '02': "KL", '04': "SC", '05': "PP", '06': "SU", '09': "UF", '12': "JM", '13': "QM"}
|
|
|
+ // let $sn = toy_list_pre[current_toy_id] + $number;
|
|
|
+ // $this.toy_sn = $sn;
|
|
|
+ // //保存教具sn
|
|
|
+ // game_store.setters.setToySn($sn);
|
|
|
+ // console.log("获取教具名称hexStr",hexStr)
|
|
|
+ // console.log("获取教具名称$sn",$sn)
|
|
|
+ // }
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AAEE87") != -1) {
|
|
|
+ // //获取教具电量
|
|
|
+ // if (current_toy_id != '80') {
|
|
|
+ // that.SendOrder('87')
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //2021年10月21日16:30:07
|
|
|
+ // // 获取教具电量
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD8A") != -1) {//接收教具电量状态
|
|
|
+ // let $_hexStr = hexStr.substr(hexStr.toUpperCase().indexOf("AADD8A") + 6);
|
|
|
+ // let $power = parseInt($_hexStr.substr(0, 2), 16)
|
|
|
+ // let $voltage = parseInt($_hexStr.substr(2, 2), 16)
|
|
|
+ // connect_toy = true;
|
|
|
+ // // $this.toy_power = Math.round(that.CalBLEPower($voltage));
|
|
|
+ // if ($power > 0) {
|
|
|
+ // $this.toy_power = $power
|
|
|
+ // $this.toy_voltage = $voltage
|
|
|
+ // ToyPower = $power;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // if (current_toy_UUID == "") {
|
|
|
+ // //获取教具UUID
|
|
|
+ // that.SendOrder('84')
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //监听佩戴正确
|
|
|
+ // if (hexStr.substr(0, 6) == "555520") {
|
|
|
+ // //当s1为 00时 数据有效
|
|
|
+ // let $s1 = hexStr.substr(8, 2);
|
|
|
+ // // console.log("监听脑机是否带正:", $s1 == '00')
|
|
|
+ //
|
|
|
+ // $this.device_bg = $s1 == "00";
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 2021年10月25日09:15:50
|
|
|
+ // // 读取教具UUID
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD84") != -1) {//接收UUID 5个字节
|
|
|
+ // let $hex_index = hexStr.toUpperCase().indexOf("AADD84") + 6;
|
|
|
+ // let $datas = hexStr.substr($hex_index, 10);
|
|
|
+ // if ($datas != "0000000000") {
|
|
|
+ // console.log("以获取UUID:" + $datas)
|
|
|
+ // current_toy_UUID = $datas;
|
|
|
+ // $this.toy_UUID = $datas;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD09") != -1) {
|
|
|
+ // control_close = true;
|
|
|
+ // connect_toy = false;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //收到发送UUID的应答立马发送连接教具的指令
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD8E") != -1) {
|
|
|
+ // //发送教具连接
|
|
|
+ // that.WriteBufferInBle(`03 00 ${current_toy_id} 02 0A`)
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // // 处理打开脑控的应答
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD07") != -1) {
|
|
|
+ // ble_store.setters.setBluetoothLinkStatus(true)
|
|
|
+ // FlagOpenControl = true;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //todo 监听脑机电量
|
|
|
+ // if (hexStr.substr(0, 8) == "55550203") {
|
|
|
+ // let $power = parseInt(hexStr.substr(8, 2), 16);
|
|
|
+ // let $voltage = parseInt(hexStr.substr(10, 2), 16);
|
|
|
+ // //监听是否插入USB
|
|
|
+ // $this.hasUsb = $voltage.toString().substr(0, 1) == 1
|
|
|
+ // // 监听脑机电量
|
|
|
+ // if ($power) {
|
|
|
+ // // console.log("当前脑机电量:", $power)
|
|
|
+ // $this.device_power = $power;
|
|
|
+ // $this.device_voltage = $voltage;
|
|
|
+ // }
|
|
|
+ // if ($power < 10 && $power > 0) {
|
|
|
+ // wx.showToast({
|
|
|
+ // title: "脑机电量不足",
|
|
|
+ // icon: "none",
|
|
|
+ // duration: 2000,
|
|
|
+ // success() {
|
|
|
+ // // $this.change_device_status(0);
|
|
|
+ // },
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //游戏中模块
|
|
|
+ // if ($game_status == 1 && $data) {
|
|
|
+ // $this.do_datas($data);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // // 监听原始数据
|
|
|
+ // if (hexStr.substr(0, 6) == "5555e2") {
|
|
|
+ // let _buffer = that.doOriginBufferToData(hexStr)
|
|
|
+ // if ($game_status == 1) {
|
|
|
+ // wx.setStorageSync('origin_buffer', wx.getStorageSync('origin_buffer') + _buffer.join(',') + ",")
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //todo 打开原始数据
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD04") != -1) {
|
|
|
+ // raw_data_open = true;
|
|
|
+ // that.Send2BOrder(true)
|
|
|
+ // wx.setStorageSync('origin_buffer', "");
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //todo 接收脑机关机指令
|
|
|
+ // if (hexStr.toUpperCase().indexOf("AADD5A00000000A5") != -1) {
|
|
|
+ // Notify({
|
|
|
+ // type: 'danger',
|
|
|
+ // duration: 0,
|
|
|
+ // message: '智脑机已关机,训练结束',
|
|
|
+ // onOpened() {
|
|
|
+ // setTimeout(() => {
|
|
|
+ // $this.game_finished();
|
|
|
+ // clearInterval(control_close_intv)
|
|
|
+ // }, 2000)
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
|
|
|
/**
|
|
|
* todo 游玩时间倒计时
|
|
@@ -929,7 +929,7 @@ export default {
|
|
|
|
|
|
|
|
|
getNowTime() {
|
|
|
- var date = new Date();
|
|
|
+ const date = new Date();
|
|
|
const year = date.getFullYear();
|
|
|
const month = date.getMonth() + 1;
|
|
|
const day = date.getDate();
|