Browse Source

添加了测试支付

智方网络_吖荣 4 năm trước cách đây
mục cha
commit
212ec93289

+ 7 - 28
src/components/device/device.vue

@@ -315,15 +315,9 @@ export default {
     open_choose_toy() {
       // $this.choose_toy_window.show = false;
       $this.choose_toy_window.show = true;
-      let $serviceId = game_store.getters.getServiceId();
-      let $charateristic = game_store.getters.getCharacterId();
-
-      bluetooth.shutdownSendControl(
-        $this._deviceId,
-        $serviceId,
-        $charateristic
-      );
-      bluetooth.sendEnd($this._deviceId, $serviceId, $charateristic);
+
+      bluetooth.sendEnd();
+
     },
     // 选好玩具
     choose_ok() {
@@ -339,21 +333,9 @@ export default {
       });
       $this.toy_id = $toy.id;
       let $hex = $toy["hex"].substr($toy["hex"].length - 2, 2);
-      let toy_hex = "0x" + $hex;
-      // game_store.setters.setToyHex(toy_hex)
       //连接玩具
-      // 打开数据帧
-      let $serviceId = game_store.getters.getServiceId();
-      let $charateristic = game_store.getters.getCharacterId();
-
-      bluetooth.sendConnect(
-        toy_hex,
-        $this._deviceId,
-        $serviceId,
-        $charateristic,
-        Toast,
-        $this
-      );
+
+      bluetooth.sendConnect($hex);
     },
     //修改玩具连接状态
     change_toy_connect_status($status = 0) {
@@ -371,10 +353,7 @@ export default {
       //当脑环断开
       if ($status == 0) {
         game_store.setters.setGameStatus(0);
-        let $deviceId = game_store.getters.getDeviceId();
-        let $serviceId = game_store.getters.getServiceId();
-        let $cid = game_store.getters.getCharacterId();
-        bluetooth.shutdownSendControl($deviceId, $serviceId, $cid);
+        bluetooth.shutdownSendControl();
         // 清空链接得设备 三值
         game_store.setters.clearDeviceToy();
         $this.connect_toy = $status;
@@ -549,7 +528,7 @@ export default {
         let $deviceId = game_store.getters.getDeviceId();
         let $serviceId = game_store.getters.getServiceId();
         let $cid = game_store.getters.getCharacterId();
-        bluetooth.shutdownSendControl($deviceId, $serviceId, $cid);
+        bluetooth.shutdownSendControl();
         // 清空链接的设备
         game_store.setters.clearDeviceToy();
 

+ 8 - 48
src/pages/start/index.vue

@@ -148,7 +148,7 @@
     <van-dialog id="van-dialog" />
     <van-toast id="van-toast" />
     <van-notify id="van-notify" />
-    
+
   </div>
 </template>
 
@@ -253,11 +253,7 @@ export default {
   methods: {
     //游戏结束方法
     game_finished() {
-      bluetooth.sendEnd(
-        $this._deviceId,
-        $this._serviceId,
-        $this._characteristicId
-      );
+      bluetooth.sendEnd();
       $this.$emit("closePop", true);
       //取消监听低功耗蓝牙设备
       wx.offBLECharacteristicValueChange();
@@ -285,19 +281,9 @@ export default {
         message: "正在生成报告...",
         duration: 0,
         onClose() {
-          for (var i = 0; i < 2; i++) {
-              bluetooth.shutdownSendControl(
-                $this._deviceId,
-                $this._serviceId,
-                $this._characteristicId
-              );
-              bluetooth.sendEnd(
-                $this._deviceId,
-                $this._serviceId,
-                $this._characteristicId
-              );
+          for (var i = 0; i < 3; i++) {
+              bluetooth.sendEnd();
           }
-          
         },
       });
     },
@@ -316,32 +302,10 @@ export default {
       wx.setKeepScreenOn({
         keepScreenOn: true,
       });
-      //打开内存警告
-      // wx.onMemoryWarning(() => {
-      //   console.log('内存告急警告')
-      //   game_store.setGameAttMedDatas({
-      //     att: $this.attList,
-      //     med: $this.medList
-      //   })
-      // })
-
-      // //初始化数据
-      // $this.played_time = null
-      // //设置未结束游戏
-      // $this.is_end = false
-      // $this.att_list = []
-      // $this.med_list = []
-      // $this.delta_list = []
-      // $this.alpha_list = []
-      // $this.theta_list = []
-      // $this.beta_list = []
+
 
       bluetooth.watchingDevice($this);
-      bluetooth.sendControl(
-        $this._deviceId,
-        $this._serviceId,
-        $this._characteristicId
-      );
+      bluetooth.sendControl();
     },
 
     // ArrayBuffer转16进度字符串示例
@@ -542,7 +506,7 @@ export default {
     //         message: '智脑环已断开连接,请重新扫码智脑环',
     //         duration: 0,
     //       });
-    
+
   },
   created() {
     $this = this;
@@ -614,11 +578,7 @@ export default {
     console.log("小程序被销毁");
     if (!$this.is_end) {
       //停止传输数据
-      bluetooth.sendEnd(
-        $this._deviceId,
-        $this._serviceId,
-        $this._characteristicId
-      );
+      bluetooth.sendEnd();
       wx.offBLECharacteristicValueChange();
       //存储时间
       game_store.setters.setPlayedTime($this.played_time);

+ 65 - 4
src/pages/test/index.vue

@@ -1,5 +1,66 @@
 <template>
-	<div>
-		<h1>Hello WOrld</h1>
-	</div>
-</template>
+  <div>
+    <h1>Hello WOrld</h1>
+  </div>
+</template>
+<script type="text/javascript">
+export default {
+  name: "TestContainer",
+  data() {
+    return {}
+  },
+  methods: {
+    test() {
+      // let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0xff) ^ 0xffffffff) & 0xff;
+      // let $CheckSum = "0x" + CheckSum.toString(16);
+
+      // let buffer = new ArrayBuffer(8);
+      // let dataView = new DataView(buffer);
+      // dataView.setUint8(0, "0xaa");
+      // dataView.setUint8(1, "0xcc");
+      // dataView.setUint8(2, "0x03");
+      // dataView.setUint8(3, "0x00");
+      // dataView.setUint8(4, "0x00");
+      // dataView.setUint8(5, "0x00");
+      // dataView.setUint8(6, "0xff");
+      // dataView.setUint8(7, $CheckSum);
+      let $ff = "ff";
+      let $5f = "ffffffff"
+      let $hex_header = "aa cc ";
+      let $hex = "03 00 01 00 0a";
+
+      let $hex_sum = 0;
+      let $hex_ary = $hex.split(" ");
+      $hex_ary.forEach(($val, $index) => {
+        $hex_sum += parseInt($val, 16);
+      })
+
+      let $checksum = ($hex_sum ^ parseInt($5f,16)) & parseInt($ff,16);
+
+      $hex = $hex_header + $hex + " "+$checksum.toString(16);
+      let buffer = new ArrayBuffer(8);
+      let dataView = new DataView(buffer);
+      $hex_ary = $hex.split(" ");
+      $hex_ary.forEach(($val,$index)=>{
+        dataView.setUint8($index,$val)
+      })
+
+      // dataView.setUint8(0, "0xaa");
+      // dataView.setUint8(1, "0xcc");
+      // dataView.setUint8(2, "0x03");
+      // dataView.setUint8(3, "0x00");
+      // dataView.setUint8(4, "0x00");
+      // dataView.setUint8(5, "0x00");
+      // dataView.setUint8(6, "0xff");
+      // dataView.setUint8(7, $CheckSum);
+
+
+
+
+    }
+  },
+  mounted() {
+    this.test();
+  }
+}
+</script>

+ 3 - 2
src/pages/user_center/recharge/index.vue

@@ -216,12 +216,12 @@
         </view>
 
         <view v-if="selection_card.goods_id < 4">
-          <text class="text-sm text-gray">折扣&emsp;{{ selection_card.discount }}</text>
+          <text class="text-lg text-red" style="font-weight: bold;">折扣&emsp;{{ selection_card.discount * 10 }}折</text>
           <br>
         </view>
         <view class="order_price_container">
           <text class="text-sm text-gray">实付(元)&emsp;</text>
-          <text class="mine_min">{{ selection_card.price * selection_card.discount }}</text>
+          <text class="mine_min">{{ selection_card.total_price }}</text>
         </view>
         <button
           class="cu-btn bg-primary lg text-white recharge_button"
@@ -337,6 +337,7 @@ export default {
     //弹出确认订单
     open_order_confirm($item) {
       $this.order_confirm = true;
+      $item['total_price'] = ($item.price * $item.discount).toFixed(2); 
       $this.selection_card = $item;
     },
     //关闭确认订单

+ 93 - 439
src/utils/bluetooth.js

@@ -1,335 +1,27 @@
 import game_store from "../store/game";
 import ble_store from "../store/bluetooth";
-import bluetooth from "../store/bluetooth";
 import Notify from "../../static/vant/notify/notify";
 
+var $ff = "ff";
+var $8f = "ffffffff"
 export default {
-  // 发送开启脑电数据包指令
-  sendOpen(deviceId, serviceId, Cid) {
-    // 向蓝牙设备发送一个0x00的16进制数据
-
-    // 玩具对应指令数组
-    let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0xff) ^ 0xffffffff) & 0xff;
-    let $CheckSum = "0x" + CheckSum.toString(16);
-
-    let buffer = new ArrayBuffer(8);
-    let dataView = new DataView(buffer);
-    dataView.setUint8(0, "0xaa");
-    dataView.setUint8(1, "0xcc");
-    dataView.setUint8(2, "0x03");
-    dataView.setUint8(3, "0x00");
-    dataView.setUint8(4, "0x00");
-    dataView.setUint8(5, "0x00");
-    dataView.setUint8(6, "0xff");
-    dataView.setUint8(7, $CheckSum);
-    // 向低功耗蓝牙设备特征值中写入二进制数据
 
-    wx.writeBLECharacteristicValue({
-      deviceId: deviceId,
-      serviceId: serviceId,
-      characteristicId: Cid,
-      value: buffer,
-      success: function (res) {
-        // console.log('开启脑电数据包成功')
-        // console.log(res)
-      },
-      fail: function (err) {
-        console.log("开启脑电数据包失败");
-        console.log(err);
-      },
-    });
+  // 发送开启脑电数据包指令
+  sendOpen() {
+    this.WriteBufferInBle("03 00 00 00 ff");
   },
   // 发送开启教具脑控指令
-  sendControl(deviceId, serviceId, Cid) {
-    const that = this;
-
-    // 玩具对应指令数组
-    let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x07) ^ 0xffffffff) & 0xff;
-    let $CheckSum = "0x" + CheckSum.toString(16);
-    // 向蓝牙设备发送一个0x00的16进制数据
-    let buffer = new ArrayBuffer(8);
-    let dataView = new DataView(buffer);
-    dataView.setUint8(0, "0xaa");
-    dataView.setUint8(1, "0xcc");
-    dataView.setUint8(2, "0x03");
-    dataView.setUint8(3, "0x00");
-    dataView.setUint8(4, "0x00");
-    dataView.setUint8(5, "0x00");
-    dataView.setUint8(6, "0x07");
-    dataView.setUint8(7, $CheckSum);
-    // 向低功耗蓝牙设备特征值中写入二进制数据
-
-    wx.writeBLECharacteristicValue({
-      deviceId: deviceId,
-      serviceId: serviceId,
-      characteristicId: Cid,
-      value: buffer,
-      success: function (res) {
-        // console.log('开启教具脑控成功')
-        // that.sendOpen()
-        // console.log(res)
-      },
-      fail: function (err) {
-        console.log("开启教具脑控失败");
-        console.log(err);
-      },
-    });
-  },
-  // 发送连接玩具指令
-  sendConnect($hex, deviceId, serviceId, Cid, Toast, $this) {
-    //获取最后两个字节
-    const that = this;
-    // 玩具对应指令数组
-    let arr = [
-      "0x01",
-      "0x02",
-      "0x03",
-      "0x04",
-      "0x05",
-      "0x06",
-      "0x07",
-      "0x08",
-      "0x09",
-      "0x0a",
-      "0x0b",
-    ];
-    let arr1 = [
-      0x01,
-      0x02,
-      0x03,
-      0x04,
-      0x05,
-      0x06,
-      0x07,
-      0x08,
-      0x09,
-      0x0a,
-      0x0b,
-    ];
-    let $index = arr.indexOf($hex);
-    let CheckSum =
-      ((0x03 + 0x00 + arr1[$index] + 0x00 + 0x0a) ^ 0xffffffff) & 0xff;
-    let $CheckSum = "0x" + CheckSum.toString(16);
-
-    // 向蓝牙设备发送指令
-    let buffer = new ArrayBuffer(8);
-    let dataView = new DataView(buffer);
-    dataView.setUint8(0, "0xaa");
-    dataView.setUint8(1, "0xcc");
-    dataView.setUint8(2, "0x03");
-    dataView.setUint8(3, "0x00");
-    dataView.setUint8(4, arr[$index]);
-    dataView.setUint8(5, "0x00");
-    dataView.setUint8(6, "0x0a");
-    dataView.setUint8(7, $CheckSum);
-    // 向低功耗蓝牙设备特征值中写入二进制数据
-    console.log(buffer);
-    console.log(dataView);
-
-    wx.writeBLECharacteristicValue({
-      deviceId: deviceId,
-      serviceId: serviceId,
-      characteristicId: Cid,
-      value: buffer,
-      success: function (res) {
-        console.log("发送连接玩具指令成功");
-        // wx.showLoading({
-        //   title: '正在创建连接',
-        // })
-        that.watching_toy($this, deviceId, serviceId, Cid, Toast);
-
-        let $game_status = game_store.getters.getGameStatus();
-        if ($game_status == 1) {
-          Toast.loading({
-            duration: 0,
-            message: "正在创建连接",
-            forbidClick: true,
-          });
-        }
-      },
-      fail: function (err) {
-        console.log("发送连接玩具指令失败");
-        Toast.fail({
-          message: "玩具连接失败",
-        });
-        console.log(err);
-      },
-    });
+  sendControl() {
+    this.WriteBufferInBle("03 00 00 00 07");
   },
   //发送断开玩具的指令
-  sendEnd(deviceId, serviceId, Cid) {
+  sendEnd() {
     //AA CC 03 00 00 00 09 F3
-
-    // 玩具对应指令数组
-    let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x09) ^ 0xffffffff) & 0xff;
-    let $CheckSum = "0x" + CheckSum.toString(16);
-
-    let buffer = new ArrayBuffer(8);
-    let dataView = new DataView(buffer);
-    dataView.setUint8(0, "0xaa");
-    dataView.setUint8(1, "0xcc");
-    dataView.setUint8(2, "0x03");
-    dataView.setUint8(3, "0x00");
-    dataView.setUint8(4, "0x00");
-    dataView.setUint8(5, "0x00");
-    dataView.setUint8(6, "0x09");
-    dataView.setUint8(7, $CheckSum);
-    // 向低功耗蓝牙设备特征值中写入二进制数据
-
-    wx.writeBLECharacteristicValue({
-      deviceId: deviceId,
-      serviceId: serviceId,
-      characteristicId: Cid,
-      value: buffer,
-      success: function (res) {
-        console.log("断开玩具成功");
-        // that.sendOpen()
-        console.log(res);
-      },
-      fail: function (err) {
-        console.log("断开玩具失败");
-        console.log(err);
-      },
-    });
+    this.WriteBufferInBle("03 00 00 00 09");
   },
   // 发送停止发送脑电数据包指令
-  sendPause(deviceId, serviceId, Cid) {
-    let that = this;
-    // 玩具对应指令数组
-    let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x08) ^ 0xffffffff) & 0xff;
-    let $CheckSum = "0x" + CheckSum.toString(16);
-    // 向蓝牙设备发送一个0x00的16进制数据
-    let buffer = new ArrayBuffer(8);
-    let dataView = new DataView(buffer);
-    dataView.setUint8(0, "0xaa");
-    dataView.setUint8(1, "0xcc");
-    dataView.setUint8(2, "0x03");
-    dataView.setUint8(3, "0x00");
-    dataView.setUint8(4, "0x00");
-    dataView.setUint8(5, "0x00");
-    dataView.setUint8(6, "0x08");
-    dataView.setUint8(7, $CheckSum);
-    // 向低功耗蓝牙设备特征值中写入二进制数据
-
-    wx.writeBLECharacteristicValue({
-      deviceId: deviceId,
-      serviceId: serviceId,
-      characteristicId: Cid,
-      value: buffer,
-      success: function (res) {
-        console.log("停止数据发送成功");
-        console.log(res);
-      },
-      fail: function (err) {
-        console.log("停止数据发送失败");
-        console.log(err);
-      },
-    });
-  },
-  // 通过字节码获取玩具
-  connect_toy(hexStr, deviceId, serviceId, Cid, Toast) {
-    console.log("开始连接玩具");
-    let $flag = "";
-    let $toys = [{
-        id: 1,
-        hex: "aadd0a0000",
-        msg: "无连接设备",
-        flag: false,
-      },
-      {
-        id: 1,
-        hex: "aadd0a0001",
-        msg: "已连接到智脑水舞",
-        flag: true,
-      },
-      {
-        id: 2,
-        hex: "aadd0a0002",
-        msg: "已连接到智脑恐龙",
-        flag: true,
-      },
-      {
-        id: 3,
-        hex: "aadd0a0003",
-        msg: "已连接到喷雾恐龙(小)",
-        flag: true,
-      },
-      {
-        id: 4,
-        hex: "aadd0a0004",
-        msg: "已连接到智脑赛车",
-        flag: true,
-      },
-      {
-        id: 5,
-        hex: "aadd0a0005",
-        msg: "已连接到智脑碰碰车",
-        flag: true,
-      },
-      {
-        id: 6,
-        hex: "aadd0a0006",
-        msg: "已连接到智脑SUV赛车",
-        flag: true,
-      },
-      {
-        id: 7,
-        hex: "aadd0a0007",
-        msg: "已连接到小车(中)",
-        flag: true,
-      },
-      {
-        id: 8,
-        hex: "aadd0a0008",
-        msg: "已连接到小车(小)",
-        flag: true,
-      },
-      {
-        id: 9,
-        hex: "aadd0a0009",
-        msg: "已连接到智脑无人机",
-        flag: true,
-      },
-      {
-        id: 10,
-        hex: "aadd0a000a",
-        msg: "已连接到飞行器(小)",
-        flag: true,
-      },
-      {
-        id: 11,
-        hex: "aadd0a000b",
-        msg: "已连接到水母灯",
-        flag: true,
-      },
-      {
-        id: 12,
-        hex: "aadd070000",
-        msg: "无连接设备",
-        flag: false,
-      },
-    ];
-
-    $toys.forEach(($val, $index) => {
-      if (hexStr.substring(0, 10) == $val["hex"]) {
-        Toast.clear();
-        if ($val["flag"]) {
-          Toast.success($val["msg"]);
-          let $game_status = game_store.getters.getGameStatus();
-          if ($game_status == 1) {
-            this.sendControl(deviceId, serviceId, Cid);
-          }
-        } else {
-          if ($val["hex"] == "aadd070000") {
-            this.sendOpen(deviceId, serviceId, Cid);
-          } else {
-            Toast.fail($val["msg"]);
-          }
-        }
-        $flag = $val["flag"];
-      }
-    });
-    return $flag;
+  sendPause() {
+    this.WriteBufferInBle("03 00 00 00 08");
   },
 
   //  获取大包数据 进行绘制图表
@@ -447,9 +139,7 @@ export default {
             duration: 0,
             message: '智脑环已断开连接,请重新扫码智脑环'
           });
-          //   game_store.setters.setGameStatus(0);
-          game_store.setters.setGameCloseStatus(1);
-
+          game_store.setters.setGameStatus(0);
 
 
         }
@@ -502,7 +192,7 @@ export default {
             game_store.setters.setServiceId(serviceId);
             game_store.setters.setCid(item.uuid);
             //打开数据帧
-            $this.sendOpen(deviceId, serviceId, item.uuid);
+            $this.sendOpen();
             // $this.sendPause(deviceId, serviceId, item.uuid)
             //获取玩具的值
             // bluetooth.sendConnect($this.toy_hex, deviceId, serviceId, item.uuid)
@@ -523,81 +213,16 @@ export default {
       },
     });
   },
-  //监听玩具得状态
-  watching_toy($this, deviceId, serviceId, Cid, Toast) {
-    Toast.loading({
-      forbidClick: false,
-      message: "正在创建连接",
-    });
-    let that = this;
-    let $count = 0;
-    //关闭核销选项窗口
-    // $this.pay_window = false
-    wx.onBLECharacteristicValueChange((characteristic) => {
-      try {
-        let hexStr = that.ab2hex(characteristic.value);
-        //连接玩具
-        let $flag = that.connect_toy(hexStr, deviceId, serviceId, Cid, Toast);
-        //连接不上设备
-        if ($flag) {
-          //连接成功 打开核销窗口
-          // $this.pay_window = true
-          $this.change_toy_connect_status(2);
-          let $game_status = game_store.getters.getGameStatus();
-          if ($game_status == 1) {
-            $this.change_toy_connect_status(4);
-          }
-          wx.offBLECharacteristicValueChange();
-          that.watchingDevice($this);
-        } else {
-          $count++;
-          if ($count == 10) {
-            $this.change_toy_connect_status(3);
-            wx.offBLECharacteristicValueChange();
-            that.watchingDevice($this);
-          }
-        }
-        // 取消监听低功耗蓝牙设备
-      } catch (e) {
-        wx.offBLECharacteristicValueChange();
-        that.watchingDevice($this);
-      }
-    });
-  },
 
-  //  获取当前连接得玩具
-  getConnectedToy(deviceId, serviceId, Cid) {
-    let that = this;
-    // 玩具对应指令数组
-    let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x06) ^ 0xffffffff) & 0xff;
-    let $CheckSum = "0x" + CheckSum.toString(16);
-    // 向蓝牙设备发送一个0x00的16进制数据
-    let buffer = new ArrayBuffer(8);
-    let dataView = new DataView(buffer);
-    dataView.setUint8(0, "0xaa");
-    dataView.setUint8(1, "0xcc");
-    dataView.setUint8(2, "0x03");
-    dataView.setUint8(3, "0x00");
-    dataView.setUint8(4, "0x00");
-    dataView.setUint8(5, "0x00");
-    dataView.setUint8(6, "0x06");
-    dataView.setUint8(7, $CheckSum);
-    // 向低功耗蓝牙设备特征值中写入二进制数据
 
-    wx.writeBLECharacteristicValue({
-      deviceId: deviceId,
-      serviceId: serviceId,
-      characteristicId: Cid,
-      value: buffer,
-      success: function (res) {
-        console.log("获取当前连接的玩具类型");
-        console.log(res);
-      },
-      fail: function (err) {
-        console.log("获取当前连接的玩具类型失败");
-        console.log(err);
-      },
-    });
+  // 发送连接玩具指令
+  sendConnect($hex) {
+    //获取最后两个字节
+    this.WriteBufferInBle("03 00 " + $hex + " 00 0a");
+  },
+  //  获取当前连接得玩具
+  getConnectedToy() {
+    this.WriteBufferInBle("03 00 00 00 06");
   },
   // ArrayBuffer转16进度字符串示例
   ab2hex(buffer) {
@@ -610,37 +235,8 @@ export default {
     return hexArr.join("");
   },
   //断开发送数据
-  shutdownSendControl(deviceId, serviceId, Cid) {
-    let that = this;
-    let CheckSum = ((0x03 + 0x00 + 0x00 + 0x00 + 0x0a) ^ 0xffffffff) & 0xff;
-    let $CheckSum = "0x" + CheckSum.toString(16);
-
-    // 向蓝牙设备发送指令
-    let buffer = new ArrayBuffer(8);
-    let dataView = new DataView(buffer);
-    dataView.setUint8(0, "0xaa");
-    dataView.setUint8(1, "0xcc");
-    dataView.setUint8(2, "0x03");
-    dataView.setUint8(3, "0x00");
-    dataView.setUint8(4, "0x00");
-    dataView.setUint8(5, "0x00");
-    dataView.setUint8(6, "0x0a");
-    dataView.setUint8(7, $CheckSum);
-    // 向低功耗蓝牙设备特征值中写入二进制数据
-
-    wx.writeBLECharacteristicValue({
-      deviceId: deviceId,
-      serviceId: serviceId,
-      characteristicId: Cid,
-      value: buffer,
-      success: function (res) {
-        console.log("断开连接玩具指令成功");
-      },
-      fail: function (err) {
-        console.log("发送连接玩具指令失败");
-        console.log(err);
-      },
-    });
+  shutdownSendControl() {
+    this.WriteBufferInBle("03 00 00 00 0a");
   },
 
   // 监听脑环是否带正
@@ -650,12 +246,33 @@ export default {
       let hexStr = that.ab2hex(characteristic.value);
       console.log(hexStr);
       let $data = that.get_big_data(hexStr);
-      wx.getBLEDeviceRSSI({
-        deviceId: characteristic.deviceId,
-        success(res) {
-          $this.rssi = Math.abs(res["RSSI"]);
-        },
-      });
+      // wx.getBLEDeviceRSSI({
+      //   deviceId: characteristic.deviceId,
+      //   success(res) {
+      //     $this.rssi = Math.abs(res["RSSI"]);
+      //   },
+      // });
+
+      //监听连接教具
+      if (hexStr.substr(0, 8).toLowerCase() == "aadd0a00") {
+        if ($this.toy_item["hex"]) {
+          let $hex = $this.toy_item["hex"].substr($this.toy_item["hex"].length - 2, 2);
+          if (hexStr.substr(8, 2) == $hex) {
+            console.log("已连接到"+$this.toy_item.name);
+            $this.change_toy_connect_status(2);
+          }else if(hexStr.substr(8, 2) == "00"){
+                    $this.change_toy_connect_status(3);
+          }
+        }
+      }
+
+      //暂停脑控,切断教具连接
+      if(hexStr.substr(0, 8).toLowerCase() == "aadd0900"){
+        this.shutdownSendControl();
+      }
+
+
+      //监听佩戴正确
       if (hexStr.substr(0, 6) == "555520") {
         //当s1为 00时 数据有效
         let $s1 = hexStr.substr(8, 2);
@@ -680,6 +297,7 @@ export default {
         });
       }
 
+      //游戏中模块
       let $game_status = game_store.getters.getGameStatus();
       if ($game_status == 1 && $data) {
         try {
@@ -693,11 +311,7 @@ export default {
           }
           if ($this.played_time == 0) {
             //判断是否隐藏 隐藏则不绘画
-            that.shutdownSendControl(
-              characteristic.deviceId,
-              $this._serviceId,
-              $this._characteristicId
-            );
+            that.shutdownSendControl();
             let $hide_status = game_store.getters.getHideStatus();
             if (!$hide_status) {
               $this.game_finished();
@@ -709,7 +323,7 @@ export default {
       }
     });
   },
-  // 游玩时间倒计时 
+  // 游玩时间倒计时
   formatPlaySeconds(value) {
     console.log('剩余可游玩时间', value)
     // 字符串转数字
@@ -765,4 +379,44 @@ export default {
 
     return $errmsg;
   }
+
+  ,
+  //写入buffer
+  WriteBufferInBle($hex) {
+    let $device_id = game_store.getters.getDeviceId();
+    let $service_id = game_store.getters.getServiceId()
+    let $charateristic = game_store.getters.getCharacterId();
+    let $hex_header = "aa cc ";
+    // let $hex = "03 00 01 00 0a";
+
+    let $hex_sum = 0;
+    let $hex_ary = $hex.split(" ");
+    $hex_ary.forEach(($val, $index) => {
+      $hex_sum += parseInt($val, 16);
+    })
+
+    let $checksum = ($hex_sum ^ parseInt($8f, 16)) & parseInt($ff, 16);
+
+    $hex = $hex_header + $hex + " " + $checksum.toString(16);
+    let buffer = new ArrayBuffer(8);
+    let dataView = new DataView(buffer);
+    $hex_ary = $hex.split(" ");
+    $hex_ary.forEach(($val, $index) => {
+      dataView.setUint8($index, parseInt($val, 16))
+    })
+
+    wx.writeBLECharacteristicValue({
+      deviceId: $device_id,
+      serviceId: $service_id,
+      characteristicId: $charateristic,
+      value: buffer,
+      success: function (res) {
+        console.log($hex + ',写入成功')
+      },
+      fail: function (err) {
+        console.log("开启脑电数据包失败");
+        console.log(err);
+      },
+    });
+  }
 };