Browse Source

ver:0.0.5
desc:1. characteristicsServers 有notify 也设置为可连接
2. 用户可自主编辑发送指令
poster:张晓宇

xiaoyuzhang 5 years ago
parent
commit
ebe98ad520

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "zxy",
3
-  "version": "0.0.4",
3
+  "version": "0.0.5",
4 4
   "author": "xiaoyuzhang <771799477@qq.com>",
5 5
   "description": "An electron-vue project",
6 6
   "license": null,

+ 35 - 4
src/renderer/components/ble/characteristicsServers.vue

@@ -62,7 +62,7 @@
62 62
         </el-table-column>
63 63
       </el-table>
64 64
 
65
-    <el-dialog title="添加小程序模板" width="80%"
65
+    <el-dialog title="发送蓝牙数据" width="80%"
66 66
                :close-on-click-modal="false"
67 67
                :visible.sync="validate"
68 68
                :modal-append-to-body="false"
@@ -81,7 +81,23 @@
81 81
           <el-button @click="stopCollection">停止采集</el-button>
82 82
           <el-button @click="resetDevice">复位</el-button>
83 83
         </div>
84
-
84
+        <el-row>
85
+          <el-col :span="8">
86
+            <div class="grid-content bg-purple">
87
+              <span>请输入指令(hex):</span>
88
+            </div>
89
+          </el-col>
90
+          <el-col :span="8">
91
+            <div class="grid-content bg-purple-light">
92
+              <el-input v-model="inputData" placeholder="请输入内容"></el-input>
93
+            </div>
94
+          </el-col>
95
+          <el-col :span="8">
96
+            <div class="grid-content bg-purple">
97
+              <el-button @click="sendInputData">发送</el-button>
98
+            </div>
99
+          </el-col>
100
+        </el-row>
85 101
         <div style="padding-bottom: 20px">
86 102
           <div style="width:140px;height:140px;position:relative;margin-top:30px" >
87 103
             <div ref="heatsample" style="width:540px;height:540px;position:absolute;top:0;left:0" />
@@ -109,6 +125,7 @@
109 125
           localName:typeof (this.$route.query.localName) =='undefined' ?'N/A':this.$route.query.localName,
110 126
           validate:false,
111 127
           sendData:'',
128
+          inputData:'04 00 02 00'
112 129
       }
113 130
     },
114 131
     created() {
@@ -168,9 +185,11 @@
168 185
             for(let j of properties) {
169 186
                 if (j=='write'||j=='read') {
170 187
                     flag ++
188
+                } else if(j == 'notify') {
189
+                    flag += 2
171 190
                 }
172 191
             }
173
-            if(flag == 1) {
192
+            if(flag >= 1) {
174 193
                 bRes = true
175 194
             }
176 195
             return bRes
@@ -215,9 +234,21 @@
215 234
         },
216 235
         resetDevice() {
217 236
             this.$socket.emit('sendBleData', {type: 'resetDevice'})
237
+        },
238
+        sendInputData() {
239
+            if(this.inputData =='') {
240
+                this.errorNotify('输入指令值不能为空')
241
+            } else {
242
+                // 16进制数操作
243
+                let arr = this.inputData.trim().split(" ");
244
+                let data = []
245
+                for(let j of arr) {
246
+                    data.push(parseInt(j,16))
247
+                }
248
+                this.$socket.emit('sendBleData', {type: 'sendOwnData',data:Buffer(data)})
249
+            }
218 250
         }
219 251
 
220
-
221 252
     },
222 253
     computed: {
223 254
       ...mapGetters([

+ 3 - 1
static/server/app.js

@@ -240,7 +240,6 @@ io.sockets.on('connection', function (socket) {
240 240
             }
241 241
         } else if(request.cmd == 'closeSetUp') {
242 242
             // 用户关闭dialog  并把CharacteristicServer 取消订阅 unsubscribe
243
-            console.log('close')
244 243
             nobleWrapper.disSetUp()
245 244
         }
246 245
     });
@@ -263,6 +262,9 @@ io.sockets.on('connection', function (socket) {
263 262
             case 'resetDevice':
264 263
                 sendData = sendProtocal.resetDevice()
265 264
                 break;
265
+            case 'sendOwnData':
266
+                sendData = data.data
267
+                break;
266 268
         }
267 269
         nobleWrapper.write(sendData,function (res) {
268 270
             console.log(res)

+ 0 - 1
static/server/ble/nobleWrapper.js

@@ -130,7 +130,6 @@ module.exports = {
130 130
   disSetUp:function () {
131 131
       if(connectedCharacteristic != null) {
132 132
           connectedCharacteristic.unsubscribe(error =>{
133
-              console.log(error)
134 133
               if(error ==null) {
135 134
                   console.log('unsubscribe,success!')
136 135
                   connectedCharacteristic = null

+ 0 - 1
static/server/protocal/sendProtocal.js

@@ -70,7 +70,6 @@ module.exports = {
70 70
       }
71 71
       let checkSum = (realcmd + id + sum) & 0xff
72 72
       data.push(checkSum)
73
-      console.log(Buffer(data))
74 73
       return Buffer(data);
75 74
   },
76 75
   // 查询当前模式