Przeglądaj źródła

ver:0.0.4
desc:Bluetooth 0.0.4
poster:张晓宇

xiaoyuzhang 4 lat temu
rodzic
commit
cbed73349c

+ 1 - 22
package-lock.json

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "zxy",
3
-  "version": "0.0.2",
3
+  "version": "0.0.3",
4 4
   "lockfileVersion": 1,
5 5
   "requires": true,
6 6
   "dependencies": {
@@ -11363,27 +11363,6 @@
11363 11363
         "semver": "5.7.1"
11364 11364
       }
11365 11365
     },
11366
-    "node-bluetooth": {
11367
-      "version": "1.2.6",
11368
-      "resolved": "https://registry.npm.taobao.org/node-bluetooth/download/node-bluetooth-1.2.6.tgz",
11369
-      "integrity": "sha1-EjzypRmBA4BVSa0Q8Ul4mXH1YKA=",
11370
-      "requires": {
11371
-        "bindings": "1.2.1",
11372
-        "nan": "2.14.1"
11373
-      },
11374
-      "dependencies": {
11375
-        "bindings": {
11376
-          "version": "1.2.1",
11377
-          "resolved": "https://registry.npm.taobao.org/bindings/download/bindings-1.2.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbindings%2Fdownload%2Fbindings-1.2.1.tgz",
11378
-          "integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE="
11379
-        },
11380
-        "nan": {
11381
-          "version": "2.14.1",
11382
-          "resolved": "https://registry.npm.taobao.org/nan/download/nan-2.14.1.tgz?cache=0&sync_timestamp=1587497111086&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnan%2Fdownload%2Fnan-2.14.1.tgz",
11383
-          "integrity": "sha1-174036MQW5FJTDFHCJMV7/iHSwE="
11384
-        }
11385
-      }
11386
-    },
11387 11366
     "node-forge": {
11388 11367
       "version": "0.9.0",
11389 11368
       "resolved": "https://registry.npm.taobao.org/node-forge/download/node-forge-0.9.0.tgz?cache=0&sync_timestamp=1569524876130&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnode-forge%2Fdownload%2Fnode-forge-0.9.0.tgz",

+ 1 - 2
package.json

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "zxy",
3
-  "version": "0.0.2",
3
+  "version": "0.0.4",
4 4
   "author": "xiaoyuzhang <771799477@qq.com>",
5 5
   "description": "An electron-vue project",
6 6
   "license": null,
@@ -60,7 +60,6 @@
60 60
     "echarts": "^4.7.0",
61 61
     "element-ui": "^2.13.1",
62 62
     "koa": "^2.2.0",
63
-    "node-bluetooth": "^1.2.6",
64 63
     "socket.io": "^2.3.0",
65 64
     "vue": "^2.5.16",
66 65
     "vue-echarts": "^5.0.0-beta.0",

+ 277 - 0
src/renderer/components/BlueTooth.vue

@@ -0,0 +1,277 @@
1
+<template>
2
+  <div id="wrapper">
3
+    <div style="padding-bottom: 20px">
4
+      {{showTitleMessage}} <br/>
5
+      <el-button @click="toIndex" >返回首页</el-button>
6
+      <el-button @click="searchModel" :disabled="blueToothDevice == ''" >查询当前模式</el-button>
7
+      <el-button @click="setModel" :disabled="blueToothDevice == ''" >进入配置模式</el-button>
8
+      <el-button @click="InModel" :disabled="blueToothDevice == ''">进入传输模式</el-button>
9
+      <br/>
10
+      <el-row :gutter="20" style="padding-top: 20px" >
11
+        <el-col :span="6">
12
+          <el-select v-model="value" filterable placeholder="请选择">
13
+            <el-option
14
+                    v-for="item in options"
15
+                    :key="item.value"
16
+                    :label="item.label"
17
+                    :value="item.value">
18
+            </el-option>
19
+          </el-select>
20
+        </el-col>
21
+        <el-col :span="6">
22
+          <el-radio v-model="radio" label="1">配置</el-radio>
23
+          <el-radio v-model="radio" label="2">查询</el-radio>
24
+        </el-col>
25
+        <el-col :span="6">
26
+          <span  v-if="value =='wifiAccount'">
27
+                  wifi账号:
28
+                 <el-input
29
+                         placeholder="请输入wifi账号"
30
+                         v-model="wifiAccount"
31
+                         clearable>
32
+                 </el-input>
33
+                 wifi密码:
34
+                  <el-input
35
+                          placeholder="请输入wifi密码"
36
+                          v-model="wifiPassword"
37
+                          clearable>
38
+                 </el-input>
39
+          </span>
40
+          <span  v-if="value =='wifiIp'">
41
+                  wifiIP:
42
+                 <el-input
43
+                         placeholder="请输入wifiIP"
44
+                         v-model="wifiIp"
45
+                         clearable>
46
+                 </el-input>
47
+          </span>
48
+          <span  v-if="value =='serverIp'">
49
+                  服务器ip:
50
+                 <el-input
51
+                         placeholder="请输入服务器ip"
52
+                         v-model="serverIp"
53
+                         clearable>
54
+                 </el-input>
55
+                  服务器端口:
56
+                  <el-input
57
+                          placeholder="请输入服务器端口"
58
+                          v-model="serverPort"
59
+                          clearable>
60
+                 </el-input>
61
+          </span>
62
+
63
+        </el-col>
64
+        <el-col :span="6">
65
+          <el-button @click="sendMessage" :disabled="blueToothDevice == ''">
66
+            发送
67
+          </el-button>
68
+
69
+        </el-col>
70
+      </el-row>
71
+
72
+      <div v-if="blueSendData!=''">收到数据 {{blueSendData}}</div>
73
+    </div>
74
+  </div>
75
+</template>
76
+
77
+<script>
78
+  import {mapState, mapGetters} from "vuex";
79
+  import func from '../utils/FunctionSet'
80
+  export default {
81
+    name: 'blueTooth',
82
+    data(){
83
+        return {
84
+            options: [{
85
+                value: 'wifiAccount',
86
+                label: 'wifi账号密码'
87
+            }, {
88
+                value: 'wifiIp',
89
+                label: 'wifi模块ip'
90
+            }, {
91
+                value: 'serverIp',
92
+                label: '当前服务器Ip与端口'
93
+            }],
94
+            value: 'wifiAccount',
95
+            radio:'1',
96
+            wifiAccount:'semsx',
97
+            wifiPassword:'semsx1024',
98
+            wifiIp:'192.168.1.1',
99
+            serverIp:'192.168.0.0',
100
+            serverPort:'8080'
101
+        }
102
+    },
103
+    methods: {
104
+        toIndex() {
105
+            this.$router.push('/')
106
+        },
107
+        errorNotify(msg) {
108
+            this.$notify({
109
+                title: '提示',
110
+                message: msg,
111
+                duration: 4500
112
+            });
113
+        },
114
+        successNotify() {
115
+            this.$notify({
116
+                title: '提示',
117
+                message: '成功发送指令',
118
+                duration: 1500
119
+            });
120
+        },
121
+        //查询当前模式
122
+        searchModel(){
123
+            this.$socket.emit('searchModel','searchModel')
124
+        },
125
+        //进入配置模式
126
+        setModel() {
127
+            this.$socket.emit('setModel','setModel')
128
+        },
129
+        //进入传输模式
130
+        InModel() {
131
+            this.$socket.emit('InModel','InModel')
132
+        },
133
+        // 发送数据
134
+        sendMessage() {
135
+            let data = ''
136
+            let key = ''
137
+            if(this.value == 'wifiAccount') {
138
+                // wifi账号密码 字符串拼接
139
+                if(this.wifiAccount == '' || this.wifiPassword == '') {
140
+                    this.errorNotify('wifi账户或密码为空')
141
+                    return;
142
+                }
143
+                data = this.wifiAccount + ',' + this.wifiPassword
144
+                key = this.radio == '1'? 'setWifiAccount':'getWifiAccount'
145
+            } else if(this.value == 'wifiIp') {
146
+                //wifi IP
147
+                if(this.wifiIp == '') {
148
+                    this.errorNotify('wifiIp为空')
149
+                    return;
150
+                }
151
+                data = this.wifiIp
152
+                key = this.radio == '1'? 'setWifiIp':'getWifiIp'
153
+            } else if(this.value == 'serverIp') {
154
+                //wifi IP
155
+                if(this.serverIp == '' || this.serverPort == '') {
156
+                    this.errorNotify('服务器ip与端口为空')
157
+                    return;
158
+                }
159
+                data = this.serverIp + ',' + this.serverPort
160
+                key = this.radio == '1'? 'setServerIp':'getServerIp'
161
+            }
162
+            this.$socket.emit(key,func.strToHexCharCode(data))
163
+            this.successNotify()
164
+        }
165
+    },
166
+    created() {
167
+    },
168
+    computed:{
169
+        ...mapGetters([
170
+            'blueToothDevice',
171
+            'blueSendData'
172
+        ]),
173
+        showTitleMessage:{
174
+            get:function () {
175
+                if(this.blueToothDevice !='') {
176
+                    // 当前连接客户端为
177
+                    return '当前连接的蓝牙客户端mac地址为'+this.blueToothDevice
178
+                } else {
179
+                    return '当前未有客户端连接'
180
+                }
181
+            },
182
+            set:function (val) {
183
+
184
+            }
185
+
186
+        }
187
+
188
+    },
189
+    watch:{
190
+
191
+    }
192
+  }
193
+
194
+</script>
195
+
196
+<style>
197
+
198
+  * {
199
+    box-sizing: border-box;
200
+    margin: 0;
201
+    padding: 0;
202
+  }
203
+
204
+  body { font-family: 'Source Sans Pro', sans-serif; }
205
+
206
+  #wrapper {
207
+    background:
208
+      radial-gradient(
209
+        ellipse at top left,
210
+        rgba(255, 255, 255, 1) 40%,
211
+        rgba(229, 229, 229, .9) 100%
212
+      );
213
+    height: 700px;
214
+    padding: 60px 80px;
215
+    width: 100vw;
216
+  }
217
+
218
+  #logo {
219
+    height: auto;
220
+    margin-bottom: 20px;
221
+    width: 420px;
222
+  }
223
+
224
+  main {
225
+    display: flex;
226
+    justify-content: space-between;
227
+  }
228
+
229
+  main > div { flex-basis: 50%; }
230
+
231
+  .left-side {
232
+    display: flex;
233
+    flex-direction: column;
234
+  }
235
+
236
+  .welcome {
237
+    color: #555;
238
+    font-size: 23px;
239
+    margin-bottom: 10px;
240
+  }
241
+
242
+  .title {
243
+    color: #2c3e50;
244
+    font-size: 20px;
245
+    font-weight: bold;
246
+    margin-bottom: 6px;
247
+  }
248
+
249
+  .title.alt {
250
+    font-size: 18px;
251
+    margin-bottom: 10px;
252
+  }
253
+
254
+  .doc p {
255
+    color: black;
256
+    margin-bottom: 10px;
257
+  }
258
+
259
+  .doc button {
260
+    font-size: .8em;
261
+    cursor: pointer;
262
+    outline: none;
263
+    padding: 0.75em 2em;
264
+    border-radius: 2em;
265
+    display: inline-block;
266
+    color: #fff;
267
+    background-color: #4fc08d;
268
+    transition: all 0.15s ease;
269
+    box-sizing: border-box;
270
+    border: 1px solid #4fc08d;
271
+  }
272
+
273
+  .doc button.alt {
274
+    color: #42b983;
275
+    background-color: transparent;
276
+  }
277
+</style>

+ 0 - 1
src/renderer/components/Config.vue

@@ -38,7 +38,6 @@
38 38
 </template>
39 39
 
40 40
 <script>
41
-  import h337 from "heatmap.js";
42 41
   import {mapState, mapGetters} from "vuex";
43 42
   export default {
44 43
     name: 'config',

+ 30 - 11
src/renderer/components/LandingPage.vue

@@ -34,7 +34,7 @@
34 34
     <el-button @click="stopCollection" :disabled="hasConnectCount == 0">停止采集</el-button>
35 35
     <el-button @click="resetDevice" :disabled="hasConnectCount == 0">复位</el-button>
36 36
     <el-button @click="toConfig" :disabled="hasConnectCount == 0">跳转至配置</el-button>
37
-    <el-button @click="test">蓝牙发送</el-button>
37
+    <el-button @click="toBlueToothSend" :disabled="deviceStatus != 'deviceSuccess'" >跳转至蓝牙发送</el-button>
38 38
     <br/>
39 39
     <div style="width:540px;height:540px;position:relative;margin-top:30px" >
40 40
       <div ref="heatsample" style="width:540px;height:540px;position:absolute;top:0;left:0" />
@@ -85,15 +85,11 @@
85 85
       toConfig() {
86 86
           this.$router.push('/config')
87 87
       },
88
-      test() {
89
-          this.$socket.emit('sendBlueTouth','sendBlueTouth')
88
+      toBlueToothSend() {
89
+          this.$router.push('/blueTooth')
90 90
       }
91
-
92
-
93
-
94
-
95 91
     },
96
-    created() {
92
+    mounted() {
97 93
         this.$socket.emit('syncConnectCount','resetDevice')
98 94
         setTimeout(()=>{
99 95
             var dst = this.$refs.heatsample;
@@ -267,13 +263,13 @@
267 263
                 }
268 264
             });
269 265
             this.h337 = heatmap;
270
-        },2000)
271
-
266
+        },1000)
272 267
     },
273 268
     computed:{
274 269
         ...mapGetters([
275 270
             'hasConnectCount',
276
-            'pressureData'
271
+            'pressureData',
272
+            'deviceStatus',
277 273
         ]),
278 274
     },
279 275
     watch:{
@@ -284,7 +280,30 @@
284 280
                     data: val
285 281
                 });
286 282
             }
283
+        },
284
+        // 监听蓝牙服务是否成功开启
285
+        deviceStatus:function (val) {
286
+            if(val == 'deviceSuccess') {
287
+                this.$notify({
288
+                    title: '提示',
289
+                    message: '蓝牙服务开启成功',
290
+                    duration: 3500
291
+                });
292
+            } else if(val == 'noUsb') {
293
+                this.$notify({
294
+                    title: '提示',
295
+                    message: '请插入蓝牙适配器后重启软件',
296
+                    duration: 0
297
+                });
298
+            } else if(val == 'deviceError') {
299
+                this.$notify({
300
+                    title: '提示',
301
+                    message: '请安装插件识别的蓝牙驱动后重启软件',
302
+                    duration: 0
303
+                });
304
+            }
287 305
         }
306
+
288 307
     }
289 308
   }
290 309
 </script>

+ 5 - 0
src/renderer/router/index.js

@@ -19,6 +19,11 @@ export default new Router({
19 19
         name: 'config',
20 20
         component: require('@/components/Config').default
21 21
     },
22
+    {
23
+        path: '/blueTooth',
24
+        name: 'blueTooth',
25
+        component: require('@/components/BlueTooth').default
26
+    },
22 27
 
23 28
   ]
24 29
 })

+ 15 - 0
src/renderer/store/modules/socket.js

@@ -3,6 +3,9 @@ import func from '../../utils/FunctionSet'
3 3
 const state = {
4 4
     hasConnectCount:0,
5 5
     pressureData:[],
6
+    blueToothDevice:'',
7
+    deviceStatus:'',
8
+    blueSendData:''
6 9
 }
7 10
 
8 11
 const actions = {
@@ -26,12 +29,24 @@ const mutations = {
26 29
     },
27 30
     SOCKET_connectedClient(state,data) {
28 31
         console.log(data)
32
+    },
33
+    SOCKET_setBlueToothDevice(state,data) {
34
+        state.blueToothDevice = data
35
+    },
36
+    SOCKET_setDeviceStatus(state,data) {
37
+        state.deviceStatus = data
38
+    },
39
+    SOCKET_sendBlueData(state,data) {
40
+        state.blueSendData = func.buf2hex(data)
29 41
     }
30 42
 }
31 43
 
32 44
 const getters = {
33 45
     hasConnectCount:state=>state.hasConnectCount,
34 46
     pressureData:state=>state.pressureData,
47
+    blueToothDevice:state=>state.blueToothDevice,
48
+    deviceStatus:state=>state.deviceStatus,
49
+    blueSendData:state=>state.blueSendData,
35 50
 }
36 51
 
37 52
 

+ 10 - 0
src/renderer/utils/FunctionSet.js

@@ -59,6 +59,16 @@ module.exports = {
59 59
 
60 60
         // join all the hex values of the elements into a single string
61 61
         return hexParts.join('');
62
+    },
63
+    // 字符串转16进制数组
64
+    strToHexCharCode(str) {
65
+        if(str === "")
66
+            return "";
67
+        var hexCharCode = [];
68
+        for(var i = 0; i < str.length; i++) {
69
+            hexCharCode.push((str.charCodeAt(i)).toString(16));
70
+        }
71
+        return hexCharCode;
62 72
     }
63 73
 
64 74
 }

+ 53 - 3
static/server/app.js

@@ -9,7 +9,6 @@ var sendProtocal = require('./protocal/sendProtocal')
9 9
 var command = require('./protocal/command')
10 10
 var commonFunction = require('./protocal/commonFunction')
11 11
 var blueTouth = require('./blueTouth')
12
-blueTouth.setIo(io)
13 12
 // socket 服务开启
14 13
 
15 14
 let socketEvent = null;
@@ -57,6 +56,9 @@ io.sockets.on('connection', function (socket) {
57 56
             console.log('已有初始连接' +connectCount +'个')
58 57
         }
59 58
         io.sockets.emit('connectCount', connectCount);
59
+        io.sockets.emit('setDeviceStatus', blueTouth.getBlueServerStatus());
60
+        // 将io对象传递给blueTooth js (发送连接客户端已经断开客户端消息发送)
61
+        blueTouth.setIo(io)
60 62
     })
61 63
     // 发送获取采样频率指令
62 64
     socket.on('checkCaiyang',function (sendData) {
@@ -111,13 +113,59 @@ io.sockets.on('connection', function (socket) {
111 113
     socket.on('sendBlueTouth',function (sendData) {
112 114
         blueTouth.sendData('123')
113 115
     })
114
-
116
+    socket.on('searchModel',function (sendData) {
117
+        let data = sendProtocal.searchModel();
118
+        blueTouth.sendData(data)
119
+    })
120
+    socket.on('setModel',function (sendData) {
121
+        let data = sendProtocal.inSetModel();
122
+        blueTouth.sendData(data)
123
+    })
124
+    socket.on('InModel',function (sendData) {
125
+        let data = sendProtocal.inTransModel();
126
+        blueTouth.sendData(data)
127
+    })
128
+    // 蓝牙设置wifi账号密码
129
+    socket.on('setWifiAccount',function (sendData) {
130
+        let data = sendProtocal.blueToothSendCommand(
131
+            sendData,'wifiAccount','set')
132
+        blueTouth.sendData(data)
133
+    })
134
+    // 蓝牙获取wifi账号密码
135
+    socket.on('getWifiAccount',function (sendData) {
136
+        let data = sendProtocal.blueToothSendCommand(
137
+            sendData,'wifiAccount','get')
138
+        blueTouth.sendData(data)
139
+    })
140
+    // 蓝牙设置wifiIP
141
+    socket.on('setWifiIp',function (sendData) {
142
+        let data = sendProtocal.blueToothSendCommand(
143
+            sendData,'wifiIp','set')
144
+        blueTouth.sendData(data)
145
+    })
146
+    // 蓝牙获取wifi账号密码
147
+    socket.on('getWifiIp',function (sendData) {
148
+        let data = sendProtocal.blueToothSendCommand(
149
+            sendData,'wifiIp','get')
150
+        blueTouth.sendData(data)
151
+    })
152
+    // 蓝牙设置 服务端IP与端口
153
+    socket.on('setServerIp',function (sendData) {
154
+        let data = sendProtocal.blueToothSendCommand(
155
+            sendData,'serverIp','set')
156
+        blueTouth.sendData(data)
157
+    })
158
+    // 蓝牙获取wifi账号密码
159
+    socket.on('getServerIp',function (sendData) {
160
+        let data = sendProtocal.blueToothSendCommand(
161
+            sendData,'serverIp','get')
162
+        blueTouth.sendData(data)
163
+    })
115 164
 })
116 165
 
117 166
 const frame_header_and_size_bytes = 1 + 2;
118 167
 
119 168
 socketServer.on('connection',(socket)=>{
120
-    console.log('连接已建立')
121 169
     socketEvent = socket
122 170
     socketServer.getConnections((err, count)=>{
123 171
         if(err){
@@ -126,6 +174,8 @@ socketServer.on('connection',(socket)=>{
126 174
             console.log(`当前有${count}个连接`);
127 175
             connectCount = count
128 176
             io.sockets.emit('connectCount', count);
177
+
178
+
129 179
         }
130 180
     });
131 181
     socket.on('data', (data)=>{

+ 23 - 15
static/server/blueTouth.js

@@ -31,7 +31,7 @@ function Utf8ArrayToStr(array) {
31 31
     }
32 32
     return out;
33 33
 }
34
-var ioNew = null
34
+var blueServerStatus = ''
35 35
 try {
36 36
     bleno.on('stateChange', function(state) {
37 37
         console.log('on -> stateChange: ' + state);
@@ -44,8 +44,8 @@ try {
44 44
     bleno.on('advertisingStart', function(error) {
45 45
         console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
46 46
         if (!error) {
47
-            io.sockets.emit('blueConnect', 'success');
48 47
             console.log('start');
48
+            blueServerStatus = 'deviceSuccess'
49 49
             var Descriptor = bleno.Descriptor;
50 50
             var descriptor = new Descriptor({
51 51
                 uuid: '212112',
@@ -61,13 +61,15 @@ try {
61 61
                     descriptor
62 62
                 ],
63 63
                 onWriteRequest: function (data, offset, withoutResponse,callBack) {
64
-                    var obj = JSON.parse( Utf8ArrayToStr(new Uint8Array(data)))
64
+                    ioNew.sockets.emit('sendBlueData',data);
65
+                    //var obj = JSON.parse( Utf8ArrayToStr(new Uint8Array(data)))
65 66
                     //console.log(withoutResponse)
66 67
                     callBack()
67 68
                 },
68 69
                 onReadRequest: function (offset, callBack) {
69 70
                     var result = characteristic.RESULT_SUCCESS;
70
-                    //var data = new Buffer('321');
71
+                    var data = new Buffer('connectTest');
72
+                    callBack(result,data)
71 73
                     sendMessageHandle = callBack
72 74
                 }
73 75
 
@@ -85,17 +87,17 @@ try {
85 87
                 if (error) {
86 88
                     console.log(error);
87 89
                 }
88
-                console.log('success');
89 90
             });
90 91
         } else {
91 92
         }
92 93
     });
93 94
 
94 95
     bleno.on('disconnect',function (clientAddress) {
95
-        console.log('disconnectAddress')
96
+        ioNew.sockets.emit('setBlueToothDevice','');
97
+        ioNew.sockets.emit('sendBlueData','');
96 98
     })
97 99
     bleno.on('accept',function (clientAddress) {
98
-        console.log('connectAddress')
100
+        ioNew.sockets.emit('setBlueToothDevice',clientAddress);
99 101
     })
100 102
     bleno.on('advertisingStartError', function(error) {
101 103
         console.log(error)
@@ -103,24 +105,30 @@ try {
103 105
 }catch (err){
104 106
     // 判断用户是否开启蓝牙 或者是堵塞
105 107
     if(err.message == 'No compatible USB Bluetooth 4.0 device found!') {
106
-        // 没有插设备
108
+        // 没有插蓝牙适配器
109
+        blueServerStatus = 'noUsb'
110
+    } else {
111
+        // 驱动错误
112
+        blueServerStatus = 'deviceError'
107 113
     }
108
-
109
-    console.log(err.message)
110 114
 }
111 115
 var sendMessageHandle = null
112 116
 var messageObj = null
117
+var ioNew = null
118
+
113 119
 
114 120
 module.exports = {
121
+    // 蓝牙 传输数据
115 122
     sendData:function (buffer) {
116 123
         if(sendMessageHandle) {
117 124
             var result =messageObj.RESULT_SUCCESS;
118
-            var data = new Buffer('woshi zhangxiaoyu');
119
-            sendMessageHandle(result,data)
125
+            sendMessageHandle(result,buffer)
120 126
         }
121 127
     },
122
-    setIo:function (data) {
123
-        ioNew  = data
128
+    getBlueServerStatus:function () {
129
+        return blueServerStatus
130
+    },
131
+    setIo:function(data) {
132
+        ioNew = data
124 133
     }
125
-
126 134
 }

+ 1 - 1
static/server/protocal/commonFunction.js

@@ -35,7 +35,7 @@ module.exports = {
35 35
                 }
36 36
             }
37 37
         }
38
-        return pressureDataProcess(dataAll,1,4)
38
+        return pressureDataProcess(dataAll,2.5,4)
39 39
     },
40 40
 }
41 41
 

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

@@ -58,7 +58,7 @@ module.exports = {
58 58
       let data = [];
59 59
       data.push(head)
60 60
       // 计算长度
61
-      let size = (1+1+arrData.length).toString(16)
61
+      let size = (1+1+arrData.length)
62 62
       data.push(size)
63 63
       data.push(0x00)
64 64
       data.push(realcmd)
@@ -73,6 +73,68 @@ module.exports = {
73 73
       console.log(Buffer(data))
74 74
       return Buffer(data);
75 75
   },
76
+  // 查询当前模式
77
+  searchModel:function () {
78
+      let data = [];
79
+      data.push(0x05);
80
+      data.push(0x00);
81
+      data.push(0x01);
82
+      data.push(0x00);
83
+      return Buffer(data);
84
+  },
85
+  // 进入配置模式
86
+  inSetModel:function () {
87
+      let data = [];
88
+      data.push(0x05);
89
+      data.push(0x00);
90
+      data.push(0x02);
91
+      data.push(0x00);
92
+      return Buffer(data);
93
+  },
94
+  // 进入传输模式
95
+  inTransModel:function () {
96
+      let data = [];
97
+      data.push(0x05);
98
+      data.push(0x00);
99
+      data.push(0x03);
100
+      data.push(0x00);
101
+      return Buffer(data);
102
+  },
103
+  // 蓝牙模块发送 查询配置指令
104
+  blueToothSendCommand:function (arrData,cmd,type) {
105
+      let head  = 0xf7
106
+      let realcmd = 0x00
107
+      if(type == 'get') {
108
+          realcmd = 0x01
109
+      } else {
110
+          realcmd = 0x02
111
+      }
112
+      let id = 0x00
113
+      if(cmd == 'wifiAccount') {
114
+          id = 0xa1
115
+      } else if (cmd == 'wifiIp') {
116
+          id = 0xa2
117
+      } else if(cmd == 'serverIp') {
118
+          id = 0xa3
119
+      }
120
+      let data = [];
121
+      data.push(head)
122
+      // 计算长度
123
+      let size = (1+1+arrData.length)
124
+      data.push(size)
125
+      data.push(0x00)
126
+      data.push(realcmd)
127
+      data.push(id)
128
+      let sum = 0
129
+      for(let i in arrData) {
130
+          data.push(parseInt(arrData[i],16))
131
+          sum += parseInt(arrData[i],16)
132
+      }
133
+      let checkSum = (realcmd + id + sum) & 0xff
134
+      data.push(checkSum)
135
+      console.log(Buffer(data))
136
+      return Buffer(data);
137
+  }  
76 138
 
77 139
 }
78 140