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

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

@@ -62,7 +62,7 @@
62
         </el-table-column>
62
         </el-table-column>
63
       </el-table>
63
       </el-table>
64
 
64
 
65
-    <el-dialog title="添加小程序模板" width="80%"
65
+    <el-dialog title="发送蓝牙数据" width="80%"
66
                :close-on-click-modal="false"
66
                :close-on-click-modal="false"
67
                :visible.sync="validate"
67
                :visible.sync="validate"
68
                :modal-append-to-body="false"
68
                :modal-append-to-body="false"
@@ -81,7 +81,23 @@
81
           <el-button @click="stopCollection">停止采集</el-button>
81
           <el-button @click="stopCollection">停止采集</el-button>
82
           <el-button @click="resetDevice">复位</el-button>
82
           <el-button @click="resetDevice">复位</el-button>
83
         </div>
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
         <div style="padding-bottom: 20px">
101
         <div style="padding-bottom: 20px">
86
           <div style="width:140px;height:140px;position:relative;margin-top:30px" >
102
           <div style="width:140px;height:140px;position:relative;margin-top:30px" >
87
             <div ref="heatsample" style="width:540px;height:540px;position:absolute;top:0;left:0" />
103
             <div ref="heatsample" style="width:540px;height:540px;position:absolute;top:0;left:0" />
@@ -109,6 +125,7 @@
109
           localName:typeof (this.$route.query.localName) =='undefined' ?'N/A':this.$route.query.localName,
125
           localName:typeof (this.$route.query.localName) =='undefined' ?'N/A':this.$route.query.localName,
110
           validate:false,
126
           validate:false,
111
           sendData:'',
127
           sendData:'',
128
+          inputData:'04 00 02 00'
112
       }
129
       }
113
     },
130
     },
114
     created() {
131
     created() {
@@ -168,9 +185,11 @@
168
             for(let j of properties) {
185
             for(let j of properties) {
169
                 if (j=='write'||j=='read') {
186
                 if (j=='write'||j=='read') {
170
                     flag ++
187
                     flag ++
188
+                } else if(j == 'notify') {
189
+                    flag += 2
171
                 }
190
                 }
172
             }
191
             }
173
-            if(flag == 1) {
192
+            if(flag >= 1) {
174
                 bRes = true
193
                 bRes = true
175
             }
194
             }
176
             return bRes
195
             return bRes
@@ -215,9 +234,21 @@
215
         },
234
         },
216
         resetDevice() {
235
         resetDevice() {
217
             this.$socket.emit('sendBleData', {type: 'resetDevice'})
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
     computed: {
253
     computed: {
223
       ...mapGetters([
254
       ...mapGetters([

+ 3 - 1
static/server/app.js

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

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

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

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

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