add ble package check
This commit is contained in:
parent
2462c92c9b
commit
d7f491961a
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user