|
@@ -3,13 +3,6 @@ import game_store from "../store/game";
|
|
|
import Toast from "../../static/vant/toast/toast";
|
|
|
import Notify from "../../static/vant/notify/notify";
|
|
|
|
|
|
-
|
|
|
-let current_toy_id = "00";
|
|
|
-
|
|
|
-let connect_toy = true;
|
|
|
-
|
|
|
-let FlagOpenControl = false;
|
|
|
-
|
|
|
function getDeviceWriteInfo() {
|
|
|
let deviceId = ble_store.getters.getDeviceId();
|
|
|
let serviceId = ble_store.getters.getServiceId();
|
|
@@ -17,26 +10,6 @@ function getDeviceWriteInfo() {
|
|
|
let characteristicNotifyId = ble_store.getters.getCharacteristicNotifyId();
|
|
|
return { deviceId, serviceId, characteristicWriteId, characteristicNotifyId};
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
* ArrayBuffer转16进度字符串示例
|
|
@@ -55,21 +28,20 @@ function ab2hex(buffer) {
|
|
|
|
|
|
* todo 解析hex
|
|
|
* @param hexStr
|
|
|
- * @param byte_count
|
|
|
- * @param sublen
|
|
|
+ * @param count
|
|
|
+ * @param len
|
|
|
* @returns {string}
|
|
|
- * @constructor
|
|
|
*/
|
|
|
-function doAnalysis(hexStr, byte_count, sublen = 6) {
|
|
|
+function doAnalysis(hexStr, count, len = 6) {
|
|
|
+ let $result = "";
|
|
|
|
|
|
- let $_str5 = hexStr.substring(sublen);
|
|
|
- let $datas = $_str5.substring(0, byte_count * 2);
|
|
|
- let $_data = "";
|
|
|
- for (let $i = 0; $i < $datas.length; $i += 2) {
|
|
|
- let $code = parseInt($datas.substring($i, $i+2), 16)
|
|
|
- $_data += String.fromCharCode($code)
|
|
|
+ let $str = hexStr.substring(len);
|
|
|
+ let $data = $str.substring(0, count * 2);
|
|
|
+ for (let $i = 0; $i < $data.length; $i += 2) {
|
|
|
+ let $code = parseInt($data.substring($i, $i+2), 16)
|
|
|
+ $result += String.fromCharCode($code)
|
|
|
}
|
|
|
- return $_data;
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
export default {
|
|
@@ -146,7 +118,7 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- fail(res) {
|
|
|
+ fail() {
|
|
|
let deviceId = wx.getStorageSync('deviceId');
|
|
|
|
|
|
wx.closeBLEConnection({
|
|
@@ -185,13 +157,14 @@ export default {
|
|
|
* 连接教具(使用获取的ID)
|
|
|
*/
|
|
|
sendConnectOneToOne(id) {
|
|
|
- current_toy_id = id;
|
|
|
+ ble_store.setters.setCurrentToyId(id);
|
|
|
this.WriteBufferInBle(`03 00 ${id} 01 0A`)
|
|
|
},
|
|
|
|
|
|
* 连接教具(使用下发的ID)
|
|
|
*/
|
|
|
sendConnectOneToToy(id) {
|
|
|
+ ble_store.setters.setCurrentToyId(id);
|
|
|
this.WriteBufferInBle(`03 00 ${id} 02 0A`)
|
|
|
},
|
|
|
|
|
@@ -203,16 +176,6 @@ export default {
|
|
|
let $hexStr = `03 00 00 00 ${id}`;
|
|
|
this.WriteBufferInBle($hexStr)
|
|
|
},
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
* 打开或关闭LED灯 AA CC 03 00 00 ctrl EC CKS
|
|
|
* 00/01
|
|
@@ -230,23 +193,21 @@ export default {
|
|
|
let $hexStr = `03 00 00 ${id} 34`;
|
|
|
this.WriteBufferInBle($hexStr)
|
|
|
},
|
|
|
+
|
|
|
|
|
|
* 自动发送RF重连
|
|
|
* @param {Boolean} isOn 是否打开重连功能
|
|
|
- * @param {[type]} timeOut 有效时间
|
|
|
- * @return {[type]} [description]
|
|
|
+ * @param timeOut 有效时间
|
|
|
* AA CC 03 00 01 0a d0 21
|
|
|
*/
|
|
|
sendAutoConnectRf(isOn, timeOut) {
|
|
|
let onVal = isOn ? '01' : '00';
|
|
|
let mTimeOut = timeOut.toString(16);
|
|
|
-
|
|
|
if (mTimeOut.length === 1) {
|
|
|
- mTimeOut = `0${mTimeOut}`
|
|
|
+ mTimeOut = `0${mTimeOut}`;
|
|
|
}
|
|
|
-
|
|
|
let $hexStr = `03 00 ${onVal} ${mTimeOut} d0`;
|
|
|
- this.WriteBufferInBle($hexStr)
|
|
|
+ this.WriteBufferInBle($hexStr);
|
|
|
},
|
|
|
|
|
|
* todo:开启脑控
|
|
@@ -259,16 +220,6 @@ export default {
|
|
|
setTimeout(()=>{
|
|
|
that.SendOrder('07');
|
|
|
},500)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
},
|
|
|
|
|
|
* 关闭脑控
|
|
@@ -282,13 +233,7 @@ export default {
|
|
|
setTimeout(()=>{
|
|
|
|
|
|
that.SendOrder('09');
|
|
|
-
|
|
|
- FlagOpenControl = false;
|
|
|
-
|
|
|
-
|
|
|
- connect_toy = false;
|
|
|
- current_toy_id = "00";
|
|
|
-
|
|
|
+ ble_store.setters.setCurrentToyId("00");
|
|
|
},1000);
|
|
|
},
|
|
|
|
|
@@ -329,23 +274,7 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
|
|
|
* 监听脑机数据
|
|
|
* @param $this
|
|
@@ -357,7 +286,25 @@ export default {
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
let hexStr = ab2hex(characteristic.value);
|
|
|
console.log("监听脑机数据:", hexStr);
|
|
|
- let $game_status = game_store.getters.getGameStatus();
|
|
|
+
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD07") >= 0) {
|
|
|
+ ble_store.setters.setBluetoothLinkStatus(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD8E") >= 0) {
|
|
|
+ let $currentToyId = ble_store.getters.getCurrentToyId();
|
|
|
+
|
|
|
+ that.sendConnectOneToToy($currentToyId)
|
|
|
+ }
|
|
|
+ if (hexStr.toUpperCase().indexOf("AAEE87") >= 0) {
|
|
|
+ let $currentToyId = ble_store.getters.getCurrentToyId();
|
|
|
+
|
|
|
+ if ($currentToyId !== '80') {
|
|
|
+ that.SendOrder('87')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
if($this && $this.$options.name){
|
|
|
console.log("当前页面名称:", $this?$this.$options.name:"");
|
|
@@ -391,17 +338,17 @@ export default {
|
|
|
console.log("一对多")
|
|
|
|
|
|
that.sendConnectOneToOne($toy_id);
|
|
|
- current_toy_id = $toy_id;
|
|
|
+ ble_store.setters.setCurrentToyId($toy_id);
|
|
|
+
|
|
|
}
|
|
|
if (new RegExp("01").test($hex_index) === true) {
|
|
|
console.log("一对一")
|
|
|
wx.showToast({title: "已连接到" + $this.toy_item.name });
|
|
|
-
|
|
|
- connect_toy = true;
|
|
|
+
|
|
|
$this.connect_toy = 2;
|
|
|
-
|
|
|
|
|
|
if ($toy_id !== "80") {
|
|
|
+
|
|
|
setTimeout(() => {
|
|
|
that.SendOrder('87')
|
|
|
}, 3000)
|
|
@@ -419,45 +366,28 @@ export default {
|
|
|
}
|
|
|
|
|
|
if (hexStr.toUpperCase().indexOf("AADD87") >= 0) {
|
|
|
+ let $currentToyId = ble_store.getters.getCurrentToyId();
|
|
|
let $mHexStr = hexStr.substring(hexStr.toUpperCase().indexOf("AADD87"))
|
|
|
let $datas = 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;
|
|
|
+ let toy_list_pre = {'00': "", '01': "SW", '02': "KL", '04': "SC", '05': "PP", '06': "SU", '09': "UF", '12': "JM", '13': "QM"}
|
|
|
+ let $sn = toy_list_pre[$currentToyId] + $number;
|
|
|
$this.toy_sn = $sn;
|
|
|
|
|
|
- game_store.setters.setToySn($sn);
|
|
|
+ ble_store.setters.setToySn($sn);
|
|
|
console.log("获取教具名称hexStr:",hexStr,",获取教具名称$sn",$sn);
|
|
|
}
|
|
|
|
|
|
if (hexStr.toUpperCase().indexOf("AADD8A") >= 0) {
|
|
|
let $_hexStr = hexStr.substring(hexStr.toUpperCase().indexOf("AADD8A") + 6);
|
|
|
let $power = parseInt($_hexStr.substring(0, 2), 16)
|
|
|
-
|
|
|
- connect_toy = true;
|
|
|
-
|
|
|
if ($power > 0) {
|
|
|
$this.toy_power = $power
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
if (hexStr.toUpperCase().indexOf("AAEE70") >= 0) {
|
|
|
- connect_toy = false
|
|
|
+
|
|
|
wx.showModal({
|
|
|
content: "教具已断开",
|
|
|
success(res) {
|
|
@@ -487,9 +417,6 @@ export default {
|
|
|
if($this.$options.name === "StartGames" && $this.device_bg){
|
|
|
$this.analysisGameData(hexStr);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -511,63 +438,6 @@ export default {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD8E") >= 0) {
|
|
|
-
|
|
|
- that.sendConnectOneToToy(current_toy_id)
|
|
|
- }
|
|
|
- if (hexStr.toUpperCase().indexOf("AAEE87") >= 0) {
|
|
|
-
|
|
|
- if (current_toy_id !== '80') {
|
|
|
- that.SendOrder('87')
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD09") >= 0) {
|
|
|
-
|
|
|
- connect_toy = false;
|
|
|
- }
|
|
|
-
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD07") >= 0) {
|
|
|
- ble_store.setters.setBluetoothLinkStatus(true)
|
|
|
- FlagOpenControl = true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -599,7 +469,7 @@ export default {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- connect_toy = false;
|
|
|
+
|
|
|
game_store.setters.setGameStatus(0);
|
|
|
|
|
|
ble_store.setters.clearDeviceToy();
|
|
@@ -627,15 +497,15 @@ export default {
|
|
|
let $connect_count = 0;
|
|
|
let $rec = setInterval(() => {
|
|
|
let $game_status = game_store.getters.getGameStatus();
|
|
|
- if ($game_status == 1) {
|
|
|
+ if ($game_status === 1) {
|
|
|
wx.createBLEConnection({
|
|
|
deviceId: $deviceInfo.deviceId,
|
|
|
- success(res) {
|
|
|
+ success() {
|
|
|
clearInterval($rec)
|
|
|
Notify({type: 'success', message: `第${$connect_count}次重新连接成功`});
|
|
|
LogInDb(`${that.getNowTime()} 第${$connect_count}次重新连接成功`)
|
|
|
let $system = wx.getSystemInfoSync()
|
|
|
- if ($system.platform == 'ios') {
|
|
|
+ if ($system.platform === 'ios') {
|
|
|
that.getBLEDeviceServices($deviceInfo.deviceId)
|
|
|
that.notifyDatas($this)
|
|
|
} else {
|
|
@@ -643,7 +513,6 @@ export default {
|
|
|
that.watchBLEstatus($this);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
},
|
|
|
fail(res) {
|
|
|
Notify({type: 'danger', message: `第${$connect_count}次重新连接失败`});
|
|
@@ -676,7 +545,6 @@ export default {
|
|
|
$this.device_bg = false;
|
|
|
$this.connect_status = false;
|
|
|
|
|
|
-
|
|
|
|
|
|
that.SendOrder("31");
|
|
|
setTimeout(()=>{
|