Explorar o código

读取crypto加密软件

Fury %!s(int64=2) %!d(string=hai) anos
pai
achega
edaddd72e5

+ 111 - 17
src/components/device/device.vue

@@ -86,7 +86,7 @@
                   : 'toy_item_normal_bg'
               "
             >
-              <img :src="toy.img" alt="" class="toy_img" />
+              <img :src="toy.img" alt="" class="toy_img"/>
               <text class="toy_text padding-top">{{ toy.name }}</text>
             </div>
           </van-col>
@@ -95,7 +95,7 @@
       <!-- 结尾 -->
       <div class="toy_actions padding text-center">
         <view class="text-gray toy_action_text padding"
-          >选择你最感兴趣的项目,点击“选好了”以后将会自动连接
+        >选择你最感兴趣的项目,点击“选好了”以后将会自动连接
         </view>
         <button
           class="cu-btn lg cu-btn-primary text-white text-center padding"
@@ -105,8 +105,19 @@
         </button>
       </div>
     </van-popup>
-    <van-toast id="van-toast" />
-    <van-dialog id="van-dialog" />
+    <van-toast id="van-toast"/>
+    <van-dialog id="van-dialog"/>
+    <van-overlay :show="update_show" :z-index="4">
+      <div class="update_show_container">
+        <p class="update_version_label">{{ remote_version }}</p>
+        <p class="update_desc">当前版本过低,为能使用更多专注力
+          服务功能,建议您更新至最新版本</p>
+        <button class="update_button" @click="toBleUpate">立即升级</button>
+        <div class="skip_update_coontainer"  @click="update_show=false" v-if="force_update == false">
+          <p class="skip_update_label">稍后再说</p>
+        </div>
+      </div>
+    </van-overlay>
   </div>
 </template>
 
@@ -123,10 +134,10 @@ import toy_connecting from "@/components/device/toy/connecting";
 import gameIng from "@/pages/start/index";
 //获取个人信息
 import Toast from "../../../static/vant/toast/toast";
-import { game_devices, getDeviceBySn } from "../../requests/game";
+import {game_devices, getDeviceBySn,getFirmwareVersion} from "../../requests/game";
 import game_store from "@/store/game";
-import { getNowDate } from "../../utils";
-import { LogInDb } from "@/requests/log";
+import {getNowDate} from "../../utils";
+import {LogInDb} from "@/requests/log";
 
 
 let $this;
@@ -214,6 +225,10 @@ export default {
         //UUID
         UUID: "",
       },
+      update_show: false,
+      remote_version: "V1.0.0.4",
+      //强制更新
+      force_update:false
     };
   },
   methods: {
@@ -259,9 +274,9 @@ export default {
 
             //二维码
             if (res.scanType == "QR_CODE") {
-              if (url.indexOf("AI")!=-1) {
+              if (url.indexOf("AI") != -1) {
                 $code = url.substr(url.indexOf("AI"));
-              }else if(url.toUpperCase().indexOf("JELLYFISH")){
+              } else if (url.toUpperCase().indexOf("JELLYFISH")) {
                 $code = url.substr(url.toUpperCase().indexOf("JELLYFISH"));
               }
             } else {
@@ -520,6 +535,8 @@ export default {
     },
     //连接低功耗蓝牙设备。
     createBLEConnection(deviceId) {
+      wx.offBluetoothDeviceFound();
+      wx.stopBluetoothDevicesDiscovery();
       wx.createBLEConnection({
         deviceId: deviceId,
         success: (res) => {
@@ -527,9 +544,9 @@ export default {
           // 设置mtu单位大小
           wx.setBLEMTU({
             deviceId,
-            mtu:250,
-            success(res){
-              console.log("设置mtu成功",JSON.stringify(res));
+            mtu: 250,
+            success(res) {
+              console.log("设置mtu成功", JSON.stringify(res));
             }
           })
 
@@ -550,11 +567,9 @@ export default {
               $this.$bluetooth.watch_bluetooth_status($this);
               //录入库
               //读取信息逐个写入
-              if (!$this.device_finded) {
-                setTimeout(() => {
-                  $this.$bluetooth.SendOrder("02");
-                }, 3000);
-              }
+              setTimeout(() => {
+                $this.$bluetooth.SendOrder("02");
+              }, 2000);
             }
           }, 1500);
         },
@@ -591,9 +606,26 @@ export default {
       $this.game_status = 1;
       $this.connect_toy = 4;
     },
+    //todo 跳转升级界面
+    toBleUpate(){
+      wx.closeBLEConnection({
+        deviceId:game_store.getters.getDeviceId(),
+        success(){
+          wx.navigateTo({
+            url:`/pages/user_center/firmware/main?sn=${$this.code}`,
+            success(){
+              $this.update_show = false;
+            }
+          })
+        }
+      });
+    }
   },
   mounted() {
     $this.get_toy_list();
+    getFirmwareVersion().then((res)=>{
+      wx.setStorageSync("firmware_info",JSON.stringify(res.data.data))
+    })
   },
   created() {
     $this = this;
@@ -876,5 +908,67 @@ export default {
   flex-wrap: wrap;
 }
 
+.update_show_container {
+  width: 325px;
+  height: 425px;
+  background: url("https://img.shuimuai.com/update_show_bg.png") no-repeat;
+  background-size: 100%;
+  margin: 50px auto;
+}
+
+@font-face {
+  font-family: Din;
+  src: url("https://img.shuimuai.com/DIN-Bold.otf");
+}
+
+.update_version_label {
+  font-family: Din;
+  width: 100%;
+  height: 16px;
+  font-size: 21px;
+  font-family: Din;
+  font-weight: bold;
+  font-style: italic;
+  color: #FFFFFF;
+
+  padding: 90px 130px 0px;
+}
+
+.update_desc {
+  width: 268px;
+  height: 41px;
+  font-size: 17px;
+  font-family: PingFang SC;
+  font-weight: 400;
+  color: #151515;
+  margin: 150px 30px 0px;
+}
+
+.update_button {
+  width: 250px;
+  height: 45px;
+  background: #7078FF;
+  border-radius: 23px;
+
+
+  font-size: 17px;
+  font-family: PingFang SC;
+  font-weight: bold;
+  color: #FFFFFF;
+
+  margin-top: 30px;
+}
+.skip_update_coontainer{
+  width: 100%;
+  text-align: center;
+  margin-top: 20px;
+}
+.skip_update_label {
+  font-size: 13px;
+  font-family: PingFang SC;
+  font-weight: bold;
+  color: #999999;
+}
+
 /* padding toy_list */
 </style>

+ 1 - 0
src/pages/index/main.json

@@ -7,6 +7,7 @@
     "van-overlay": "../../../static/vant/overlay/index",
     "van-toast": "../../../static/vant/toast/index",
     "van-field": "../../../static/vant/field/index",
+    "van-button": "../../../static/vant/button/index",
     "van-count-down": "../../../static/vant/count-down/index",
     "van-dialog": "../../static/vant/dialog/index"
   }

+ 253 - 177
src/pages/user_center/firmware/index.vue

@@ -1,22 +1,55 @@
 <template>
   <div id="firmwareContainer">
-    <van-button @click="ConnectBrain">扫码连接</van-button>
-    <p>脑环名称:{{ brain_sn }}</p>
-    <p v-html="result"></p>
-    <p>{{ proccess }}</p>
-    <van-button @click="downloadUpateFile">下载更新文件</van-button>
-    <van-button @click="readUpdateFile">读取文件</van-button>
-    <van-button @click="OpenBleUpdate">开始升级</van-button>
-    <van-button @click="FinishBleUpdate">更新结束</van-button>
+    <div v-if="finished == false">
+      <p class="title">
+        {{ title }}
+      </p>
+      <div class="loading" v-if="update_state">
+        <van-steps :steps="steps" :active="step_active"/>
+        <div class="progress_container">
+          <van-progress :percentage="progress" v-if="step_active == 2"/>
+        </div>
+      </div>
+      <van-divider/>
+      <p class="subtitle">
+        更新相关准备
+      </p>
+      <div class="desc_container">
+        <p class="desc" v-for="(desc,index) in desc_list" :key="index">{{ desc }}</p>
+        <p class="desc" v-if="step_active>0">请将脑环保持供电
+          <van-icon name="checked" color="#07c160" v-if="hasUsb"/>
+          <van-icon name="clear" color="#ff2f4f" v-else/>
+        </p>
+      </div>
 
+      <button class="ready_button" @click="ReadyUpdate" v-if="update_state == false">准备好了</button>
 
-    <van-button @click="TestUdpateData">测试</van-button>
+    </div>
+    <div v-else>
+      <div class="finished_container">
+        <van-icon name="checked" size="60px" color="#46D5A4"/>
+        <p class="finsihed_subtitle">升级完成</p>
+        <van-button
+          class="finished_button"
+          round color="#7078FF"
+          plain
+          custom-style="margin:200px auto 0px;"
+          @click="BackIndex"
+        >&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;返回&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
+        </van-button>
+      </div>
+    </div>
+    <!--    <p class="version_info">-->
+    <!--      当前版本:{{ software_version }}-->
+    <!--    </p>-->
 
+    <van-toast id="van-toast"/>
   </div>
 </template>
 <script>
-import {getDeviceBySn} from "../../../requests/game";
+import {getDeviceBySn, EditFirmwareVersion} from "../../../requests/game";
 import game_store from "@/store/game";
+import Toast from "../../../../static/vant/toast/toast";
 
 var $this;
 var FileSystemManager = wx.getFileSystemManager();
@@ -33,12 +66,52 @@ export default {
       dec_index: 0,
       buffers: [],
       payload_len: 0,
-      update_seq1_index: 0,
-      update_index: 0,
-      update_seq2_index: 0,
-      totalBuffer: [],
-      proccess: "",
-      test_arry: []
+      progress: "",
+      hasUsb: false,
+      title: "固件升级准备",
+      //更新状态
+      update_state: false,
+      desc_list: [
+        "1.保持智脑环开机状态,且电量保证50%,或保持充电;",
+        "2.保持手机电量充足,网络处于WIFI或畅通状态;",
+        "3.手机蓝牙开启状态;",
+        "4.升级固件时避免手机关机或智脑环关机;",
+        "5.固件升级中大概5-10分钟,中途不能退出水母星球,否则会导致升级失败"
+      ],
+      step_active: 0,
+      steps: [
+        {
+          text: "环境检查"
+        },
+        {
+          text: "下载固件"
+        },
+        {
+          text: "固件更新"
+        },
+        {
+          text: "更新完成"
+        },
+      ],
+      finished: false
+    }
+  },
+  watch: {
+    update_state($new, $old) {
+      if ($new == true) {
+        $this.title = "固件更新"
+      } else {
+        $this.title = "固件升级准备"
+      }
+    },
+    step_active($new, $old) {
+      //更新完成
+      if ($new == $this.steps.length - 1) {
+        //提交 脑环和版本到数据库
+        let firmware_info = JSON.parse(wx.getStorageSync("firmware_info"))
+        EditFirmwareVersion($this.brain_sn, firmware_info.version)
+        $this.finished = true;
+      }
     }
   },
   methods: {
@@ -47,89 +120,33 @@ export default {
      * @constructor
      */
     ConnectBrain() {
-      wx.scanCode({
-        onlyFromCamera: true,
-        scanType: ["barCode", "qrCode"],
-        success: (res) => {
-          let $data = res;
-          if ($data.result) {
-            let url = decodeURIComponent($data.result);
-            let $code = "";
-
-            //二维码
-            if (res.scanType == "QR_CODE") {
-              if (url.indexOf("AI") != -1) {
-                $code = url.substr(url.indexOf("AI"));
-              } else if (url.toUpperCase().indexOf("JELLYFISH")) {
-                $code = url.substr(url.toUpperCase().indexOf("JELLYFISH"));
-              }
-            } else {
-              //一维码
-              $code = res.result.toUpperCase();
-            }
-            console.log($code)
-            // 判断新的标识值
-            $this.brain_sn = $code;
-            $this.AddContent(`脑环:${$code}`)
-            //打开蓝牙设备
-            wx.getSystemInfo({
+      // 判断新的标识值
+      // $this.brain_sn = $code;
+      //打开蓝牙设备
+      wx.getSystemInfo({
+        success(res) {
+          // 判断ios 和 安卓
+          if (res.platform == "ios") {
+            wx.openBluetoothAdapter({
+              //判断主机模式蓝牙是否打开
+              mode: "central",
               success(res) {
-                // 判断ios 和 安卓
-                if (res.platform == "ios") {
-                  wx.openBluetoothAdapter({
-                    //判断主机模式蓝牙是否打开
-                    mode: "central",
-                    success(res) {
-                      //判断已经打开连接了
-                      if (res["errMsg"] == "openBluetoothAdapter:ok") {
-                        // $this.startBluetoothDevicesDiscovery();
-                        wx.openBluetoothAdapter({
-                          //判断从机模式蓝牙是否打开
-                          mode: "peripheral",
-                          success(res) {
-                            if (res["errMsg"] == "openBluetoothAdapter:ok") {
-                              $this.startBluetoothDevicesDiscovery();
-                            }
-                          },
-                          fail(err) {
-                            let $msg =
-                              $this.$bluetooth.GetopenBluetoothAdapterError(
-                                err["errCode"]
-                              );
-                            setTimeout(() => {
-                              Toast.fail({
-                                message: $msg,
-                              });
-                            }, 3000);
-                          },
-                        });
-                      }
-                    },
-                    fail(err) {
-                      let $msg = $this.$bluetooth.GetopenBluetoothAdapterError(
-                        err["errCode"]
-                      );
-                      setTimeout(() => {
-                        Toast.fail({
-                          message: $msg,
-                        });
-                      }, 3000);
-                    },
-                  });
-                } else {
-                  // 安卓手机
+                //判断已经打开连接了
+                if (res["errMsg"] == "openBluetoothAdapter:ok") {
+                  // $this.startBluetoothDevicesDiscovery();
                   wx.openBluetoothAdapter({
+                    //判断从机模式蓝牙是否打开
                     mode: "peripheral",
                     success(res) {
-                      //判断已经打开连接了
                       if (res["errMsg"] == "openBluetoothAdapter:ok") {
                         $this.startBluetoothDevicesDiscovery();
                       }
                     },
                     fail(err) {
-                      let $msg = $this.$bluetooth.GetopenBluetoothAdapterError(
-                        err["errCode"]
-                      );
+                      let $msg =
+                        $this.$bluetooth.GetopenBluetoothAdapterError(
+                          err["errCode"]
+                        );
                       setTimeout(() => {
                         Toast.fail({
                           message: $msg,
@@ -139,31 +156,42 @@ export default {
                   });
                 }
               },
+              fail(err) {
+                let $msg = $this.$bluetooth.GetopenBluetoothAdapterError(
+                  err["errCode"]
+                );
+                setTimeout(() => {
+                  Toast.fail({
+                    message: $msg,
+                  });
+                }, 3000);
+              },
+            });
+          } else {
+            // 安卓手机
+            wx.openBluetoothAdapter({
+              mode: "peripheral",
+              success(res) {
+                //判断已经打开连接了
+                if (res["errMsg"] == "openBluetoothAdapter:ok") {
+                  $this.startBluetoothDevicesDiscovery();
+                }
+              },
+              fail(err) {
+                let $msg = $this.$bluetooth.GetopenBluetoothAdapterError(
+                  err["errCode"]
+                );
+                setTimeout(() => {
+                  Toast.fail({
+                    message: $msg,
+                  });
+                }, 3000);
+              },
             });
           }
         },
-        fail(res) {
-          console.log(res);
-        },
       });
 
-      //
-      // wx.openBluetoothAdapter({
-      //   //判断主机模式蓝牙是否打开
-      //   mode: "central",
-      //   success(res) {
-      //     //判断已经打开连接了
-      //     if (res["errMsg"] == "openBluetoothAdapter:ok") {
-      //       wx.startBluetoothDevicesDiscovery({
-      //         allowDuplicatesKey: true,
-      //         success: (res) => {
-      //           $this.createBLEConnection('E4:E1:12:5F:07:9D')
-      //         }
-      //       })
-      //     }
-      //   }
-      // })
-
     },
     /**
      * 开始蓝牙被发现
@@ -254,16 +282,17 @@ export default {
               $this.$bluetooth.openNotify($this);
               $this.$bluetooth.watchingDevice($this);
               $this.$bluetooth.watch_bluetooth_status($this);
-              //读取信息逐个写入
-              if (!$this.device_finded) {
-                setTimeout(() => {
-                  $this.$bluetooth.SendOrder("02");
-                }, 3000);
-              }
             }
+            // setTimeout(() => {
+            //     $this.$bluetooth.SendOrder("02");
+            //   }, 1000);
           }, 1500);
+
+          //步骤加一
+          $this.step_active += 1;
+          $this.downloadUpateFile()
+
           console.log("连接成功")
-          $this.AddContent("连接成功");
         },
         fail(err) {
           console.log(err);
@@ -271,15 +300,17 @@ export default {
       });
     },
     /**
-     * 下载更新文件
+     * todo 下载更新文件
      */
     downloadUpateFile() {
+      let firmware_info = JSON.parse(wx.getStorageSync("firmware_info"))
+
       wx.downloadFile({
-        url: 'https://vs.shuimuai.com/ble/update0714.img', //仅为示例,并非真实的资源
+        url: firmware_info.url, //仅为示例,并非真实的资源
         success(res) {
           // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
           if (res.statusCode === 200) {
-            $this.AddContent("下载成功")
+            // $this.AddContent("下载成功")
             console.log(res)
             //将临时文件保存到用户文件路径下
             FileSystemManager.saveFile({
@@ -287,7 +318,7 @@ export default {
               filePath: `${wx.env.USER_DATA_PATH}/update.img`,
               success(res) {
                 $this.updateImageSavePath = res.savedFilePath
-                $this.AddContent(`保存地址:${res.savedFilePath}`)
+                $this.readUpdateFile()
               }, fail(err) {
                 console.log(err)
               }
@@ -296,9 +327,6 @@ export default {
         }
       })
     },
-    AddContent(content) {
-      $this.result += `<p>${content}</p>`
-    },
     /**
      * todo 读取更新文件
      */
@@ -312,7 +340,7 @@ export default {
       FileSystemManager.readFile({
         filePath: $this.updateImageSavePath,
         success(res) {
-          $this.AddContent("读取文件成功")
+          // $this.AddContent("读取文件成功")
           let buffer_len = new Uint8Array(res.data).length
           // 读取信息
           for (let i = 0; i < buffer_len; i += 16) {
@@ -320,14 +348,13 @@ export default {
             if (i == 0) {
               //读取第一行信息 并返回 文件解密下标
               $this.dec_index = $this.getUpdateHeader0(buffer) / 10
-              $this.AddContent(`解密指定行:${$this.dec_index}`)
               console.log(`解密指定行:${$this.dec_index}`)
             }
             if (i == 1 * 16) {
+              let software_version = "";
               for (let j = 0; j < buffer.length; j++) {
-                $this.software_version += String.fromCharCode(buffer[j])
+                software_version += String.fromCharCode(buffer[j])
               }
-              $this.AddContent(`软件版本:${$this.software_version}`)
               console.log(`软件版本:${$this.software_version}`)
             }
             if (i == 2 * 16) {
@@ -336,11 +363,13 @@ export default {
               }
               $this.model = $this.model.trim()
               console.log(`模型:${$this.model}`)
-              $this.AddContent(`模型:${$this.model}`)
             }
             //发送指定行的数据
             if (i >= $this.dec_index * 16) {
               $this.buffers = res.data
+              $this.step_active += 1;
+              //开始升级
+              $this.OpenBleUpdate();
               break;
             }
           }
@@ -365,7 +394,7 @@ export default {
         if (_buffer == update_tag[i]) {
           update_tag_count -= 1;
           if (update_tag_count == 0) {
-            $this.AddContent("验证升级标志成功")
+            // // $this.AddContent("验证升级标志成功")
           }
         }
       }
@@ -379,7 +408,6 @@ export default {
       }
       payload_len = parseInt(payload_len, 16);
       $this.payload_len = payload_len;
-      $this.AddContent(`payload长度:${payload_len}`)
 
       //获取升级的offset
       let update_offset = 0
@@ -388,11 +416,9 @@ export default {
         //验证升级标志
         update_offset += parseInt(_buffer);
       }
-      $this.AddContent(`offset:${update_offset}`)
 
       //文件总长度
       let file_total_size = payload_len + parseInt(update_offset, 16)
-      $this.AddContent(`文件总长度:${file_total_size}`)
       return update_offset;
     },
     /**
@@ -415,54 +441,104 @@ export default {
       }
       $this.$bluetooth.WriteBufferInBle($hexStr.join(' '), 16)
     },
-    FinishBleUpdate() {
-      let $hexStr = `03 33 00 00 00`;
-      $this.$bluetooth.WriteBufferInBle($hexStr)
-    },
-    TestUdpateData() {
-      let buffer_len = 224;
-      let total_index = Math.round($this.payload_len / buffer_len)
-      let another_buffer_len = $this.payload_len % buffer_len;
-      while ($this.update_index < total_index - 1) {
-        // console.log(`${$this.update_index}/${total_index}`, `余:${another_buffer_len}`)
-        // 6 * 1 * 16 + 0*240 = 96
-        //  6 * 16 + 1 *240  = 336
-        $this.SendUpdateData($this.buffers, $this.dec_index * 16 + $this.update_index * buffer_len, buffer_len)
-      }
-      $this.SendUpdateData($this.buffers, $this.dec_index * 16 + $this.update_index * buffer_len, another_buffer_len)
-      console.log($this.test_arry)
-
-    },
-    SendUpdateData(buffers, start_index, speed = 248) {
-      // console.log("更新下标:" + start_index)
-      let buffer = new Uint8Array(buffers, start_index, speed)
-      let $hexStr = [
-        '03',
-        '31',
-        `00${$this.update_seq1_index.toString(16)}`.substr(-2, 2),
-        `00${$this.update_seq2_index.toString(16)}`.substr(-2, 2),
-        speed.toString(16),
-      ]
-      $this.test_arry.push([`00${$this.update_seq1_index.toString(16)}`.substr(-2, 2),
-        `00${$this.update_seq2_index.toString(16)}`.substr(-2, 2)])
-      for (let j = 0; j < speed; j++) {
-        let $hex = ('00' + buffer[j].toString(16)).substr(-2, 2)
-        $hexStr.push($hex)
-        $this.totalBuffer.push($hex)
-      }
-      // console.log(`总共发送totalBuffer:${$this.totalBuffer.length}`)
-      $this.proccess = `${$this.totalBuffer.length}/${$this.payload_len}`;
-
-      this.update_seq1_index += 1;
-      this.update_index += 1;
-      if ($this.update_seq1_index == 256) {
-        $this.update_seq1_index = 0;
-        $this.update_seq2_index += 1;
-      }
+    // todo 准备升级
+    ReadyUpdate() {
+      $this.update_state = true
+      this.ConnectBrain()
+      // this.downloadUpateFile();
     },
+    BackIndex() {
+      wx.navigateBack();
+    }
+  },
+  mounted() {
   },
   created() {
     $this = this;
+  },
+  onLoad(option) {
+    this.brain_sn = option.sn
   }
 }
 </script>
+<style>
+.title {
+  font-size: 32px;
+  font-family: PingFang SC;
+  font-weight: bold;
+  color: #151515;
+  margin: 25px 0px;
+}
+
+#firmwareContainer {
+  padding: 0px 30px;
+}
+
+.subtitle {
+  font-size: 17px;
+  font-family: PingFang SC;
+  font-weight: 500;
+  color: #151515;
+}
+
+.desc_container {
+  margin: 20px 0px;
+}
+
+.desc {
+  font-size: 14px;
+  font-family: PingFang SC;
+  font-weight: 400;
+  color: #666666;
+  margin: 10px 0px;
+}
+
+.ready_button {
+  width: 250px;
+  height: 45px;
+  background: #7078FF;
+  border-radius: 23px;
+
+  font-size: 17px;
+  font-family: PingFang SC;
+  font-weight: bold;
+  color: #FFFFFF;
+
+  margin: 100px auto;
+}
+
+.progress_container {
+  margin: 10px 0px;
+}
+
+.finsihed_subtitle {
+  font-size: 17px;
+  font-family: PingFang SC;
+  font-weight: bold;
+  color: #151515;
+  text-align: center;
+  margin-top: 20px;
+}
+
+.finished_container {
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+  margin-top: 100px;
+}
+
+.finished_button {
+  text-align: center;
+}
+
+.version_info {
+  font-size: 13px;
+  font-family: PingFang SC;
+  font-weight: 400;
+  color: #B2B2B2;
+  text-align: center;
+  position: absolute;
+  bottom: 100px;
+  margin: 0px auto;
+}
+</style>

+ 4 - 2
src/pages/user_center/firmware/main.json

@@ -7,7 +7,9 @@
     "van-cell-group": "../../../static/vant/cell-group/index",
     "van-icon": "../../../static/vant/icon/index",
     "van-toast": "../../../static/vant/toast/index",
-        "van-button": "../../../static/vant/button/index"
-
+    "van-divider": "../../../static/vant/divider/index",
+    "van-steps": "../../../static/vant/steps/index",
+    "van-progress": "../../../static/vant/progress/index",
+    "van-button": "../../../static/vant/button/index"
   }
 }

+ 12 - 12
src/pages/user_center/index.vue

@@ -89,18 +89,18 @@
           class="icon1"
         >
       </van-cell>
-      <van-cell
-        title="固件升级"
-        is-link
-        url="/pages/user_center/firmware/main"
-      >
-        <img
-          src="https://img.shuimuai.com/web/icon/icon_dingdan.png"
-          alt=""
-          slot="icon"
-          class="icon1"
-        >
-      </van-cell>
+<!--      <van-cell-->
+<!--        title="固件升级"-->
+<!--        is-link-->
+<!--        url="/pages/user_center/firmware/main"-->
+<!--      >-->
+<!--        <img-->
+<!--          src="https://img.shuimuai.com/web/icon/icon_dingdan.png"-->
+<!--          alt=""-->
+<!--          slot="icon"-->
+<!--          class="icon1"-->
+<!--        >-->
+<!--      </van-cell>-->
       <van-cell
         title="代理商中心"
         is-link

+ 2 - 2
src/pages/user_center/main.json

@@ -7,7 +7,7 @@
     "van-cell-group": "../../static/vant/cell-group/index",
     "van-icon": "../../static/vant/icon/index",
     "van-toast": "../../static/vant/toast/index",
-        "van-button": "../../static/vant/button/index"
-
+    "van-overlay": "../../static/vant/overlay/index",
+    "van-button": "../../static/vant/button/index"
   }
 }

+ 15 - 24
src/requests/game.js

@@ -54,29 +54,20 @@ export function getDeviceBySn($sn) {
   return fly.post("equipment/equipment-search", $params)
 }
 
-//2021年10月22日11:11:03
-// 写入设备
-export function setDeviceInDb($this, $deviceId) {
-  let $params = $this.device_data;
-  $params["access_token"] = wx.getStorageSync("token")
-  wx.getSystemInfo({
-    success(res) {
-      switch (res.platform) {
-        case "android":
-        default:
-          $params['is_android'] = 0;
-          break;
-        case "ios":
-          $params['is_android'] = 2;
-          break;
-      }
-      if (res.platform == "ios") {
-        $params['ios_device_id'] = $deviceId
-      } else {
-        $params['device_id'] = $deviceId;
-      }
-    }
-  })
-  return fly.post("https://testadmin.shuimuai.com/equipment/factory", $params)
+//todo 获取最新脑环数据包信息
+export function getFirmwareVersion() {
+  let $params = {
+    "access_token": wx.getStorageSync("token"),
+  }
+  return fly.post("firmware/firmware-info", $params)
+}
+
+//todo 提交 脑环与版本
+export function EditFirmwareVersion(sn,version) {
+  let $params = {
+    "access_token": wx.getStorageSync("token"),
+    sn,version
+  }
+  return fly.post("equipment/edit", $params)
 }
 

+ 82 - 7
src/utils/bluetooth.js

@@ -68,6 +68,11 @@ var update_seq1_index = 0;
 //序列下标2
 var update_seq2_index = 0;
 var totalBuffer = [];
+// 脑环model
+var model = "";
+//脑环固件版本
+var version = "";
+
 
 export default {
   //变量
@@ -464,7 +469,7 @@ export default {
       let hexStr = that.ab2hex(characteristic.value);
       // console.log("数据", hexStr, "长度", hexStr.length / 2);
 
-      if (hexStr.toUpperCase().indexOf("AADD") != -1 || hexStr.toUpperCase().indexOf("AAEE") != -1) {
+      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}`)
@@ -654,10 +659,12 @@ export default {
         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)
@@ -678,30 +685,42 @@ export default {
 
       // todo 监听ota升级
       if (hexStr.toUpperCase().indexOf("AADD30") != -1 || hexStr.toUpperCase().indexOf("AADD31") != -1) {
+        if (hexStr.toUpperCase().indexOf("AADD30") != -1) {
+          update_index = 0;
+          update_seq1_index = 0;
+          update_seq2_index = 0;
+          update_state = true;
+          totalBuffer = [];
+        }
         // 开始升级、
         console.log("升级中")
         let buffer_len = 224
         if (update_state) {
           let total_index = Math.round($this.payload_len / buffer_len)
           let another_buffer_len = $this.payload_len % buffer_len;
-          if (update_index < total_index - 1) {
+          if (update_index < total_index) {
             that.SendUpdateData($this.buffers, $this.dec_index * 16 + update_index * buffer_len, buffer_len)
           } else {
+            console.log(`update_index:${update_index}`,`total_index:${total_index}`)
+            console.log("余:"+another_buffer_len)
             if (another_buffer_len > 0) {
               that.SendUpdateData($this.buffers, $this.dec_index * 16 + update_index * buffer_len, another_buffer_len)
             }
             update_state = false;
           }
+          $this.progress = (update_index / total_index * 100).toFixed(2);
         } else {
+          //更新结束
+          that.FinishBleUpdate()
           console.log(`文件buffer长度:${$this.payload_len},总共发送totalBuffer:${totalBuffer.length}`)
         }
       }
 
 
       if (hexStr.toUpperCase().indexOf("AAEE31") != -1) {
-        console.log("升级停止")
         let $hexStr = `03 32 00 00 00`;
         this.WriteBufferInBle($hexStr)
+        $this.AddContent("更新停止")
       }
 
 
@@ -709,6 +728,50 @@ export default {
       if ($game_status == 1 && $data) {
         $this.do_datas($data);
       }
+
+      //todo 监听收到更新结束
+      if (hexStr.toUpperCase().indexOf("AADD33") != -1) {
+        //发送重启脑环指令
+        let $hexStr = `03 00 00 00 26`;
+        this.WriteBufferInBle($hexStr)
+        $this.step_active += 1;
+      }
+
+      //todo 监听收到脑环型号
+      if (hexStr.toUpperCase().indexOf("AADD02") != -1) {
+        hexStr = hexStr.substr(10, 20)
+        for (let i = 0; i < hexStr.length; i += 2) {
+          model += String.fromCharCode(parseInt(hexStr.substr(i, 2), 16));
+        }
+        console.log(`model:${model}`)
+        this.SendOrder("03");
+      }
+
+      //todo 获取固件信息
+      if (hexStr.toUpperCase().indexOf("AADD03") != -1) {
+        hexStr = hexStr.substr(6, 24)
+        for (let i = 0; i < hexStr.length; i += 2) {
+          version += String.fromCharCode(parseInt(hexStr.substr(i, 2), 16));
+        }
+        $this.software_version = version
+        console.log(`version:${version}`)
+
+        let firmware_info = JSON.parse(wx.getStorageSync("firmware_info"))
+
+        //todo 与数据库匹对固件升级
+        if (model == firmware_info.model) {
+          //版本不一样
+          if (firmware_info.version != version) {
+            //硬更/软更
+            $this.force_update = firmware_info.status == 1;
+            $this.remote_version = `V${firmware_info.version}`;
+            $this.update_show = true
+          }
+        }
+
+      }
+
+
     });
   },
 
@@ -815,9 +878,12 @@ export default {
       characteristicId: $deviceInfo.charateristic.write,
       value: buffer,
       success: function (res) {
-        console.log($hex + ',写入成功,时间:' + that.getNowTime())
-        LogInDb(`${that.getNowTime()} ${$hex}',写入成功`)
-        logTime = Math.round(new Date() / 1000);
+        if ($buffer_len <= 16) {
+          console.log($hex + ',写入成功,时间:' + that.getNowTime())
+        } else {
+          console.log('写入成功,时间:' + that.getNowTime())
+        }
+        // LogInDb(`${that.getNowTime()} ${$hex}',写入成功`)
       },
       fail: function (err) {
         console.log($hex + "写入失败", err);
@@ -1035,4 +1101,13 @@ export default {
       update_seq2_index += 1;
     }
   },
+
+  /**
+   * 更新结束
+   * @constructor
+   */
+  FinishBleUpdate() {
+    let $hexStr = `03 33 00 00 00`;
+    this.WriteBufferInBle($hexStr)
+  },
 };