add ble package check

This commit is contained in:
Jay 2017-08-24 13:54:57 +08:00
parent 2462c92c9b
commit d7f491961a
1 changed files with 14 additions and 2 deletions

View File

@ -4,6 +4,7 @@ const localEvent = require('./localEvent')
var tmp = []
var idx = 0
var failFlag = false
const notifyDesciptor = new bleno.Descriptor({
uuid: '8888',
@ -29,12 +30,23 @@ class DataCharacteristic extends bleno.Characteristic {
if (data.length == 1 && data[0] == 0x00) {
tmp = []
idx = 0
failFlag = false
} else if (data.length == 1 && data[0] == 0xff) {
console.log(Buffer.from(tmp).toString())
localEvent.emit('print', Buffer.from(tmp).toString())
} else {
if (!failFlag) {
localEvent.emit('print', Buffer.from(tmp).toString())
}
} else if (!failFlag) {
let pidx = ((data[0] & 0xff) << 8) + (data[1] & 0xff)
if (idx !== pidx) {
// insert fail method
failFlag = true
this.sendNotidy('fail')
}
idx++
tmp = [...tmp, ...data.slice(2, data.length)]
}
if (!withoutResponse) {
console.log('send response')
callback(this.RESULT_SUCCESS)