add ble package check
This commit is contained in:
parent
2462c92c9b
commit
d7f491961a
@ -4,6 +4,7 @@ const localEvent = require('./localEvent')
|
|||||||
|
|
||||||
var tmp = []
|
var tmp = []
|
||||||
var idx = 0
|
var idx = 0
|
||||||
|
var failFlag = false
|
||||||
|
|
||||||
const notifyDesciptor = new bleno.Descriptor({
|
const notifyDesciptor = new bleno.Descriptor({
|
||||||
uuid: '8888',
|
uuid: '8888',
|
||||||
@ -29,12 +30,23 @@ class DataCharacteristic extends bleno.Characteristic {
|
|||||||
if (data.length == 1 && data[0] == 0x00) {
|
if (data.length == 1 && data[0] == 0x00) {
|
||||||
tmp = []
|
tmp = []
|
||||||
idx = 0
|
idx = 0
|
||||||
|
failFlag = false
|
||||||
} else if (data.length == 1 && data[0] == 0xff) {
|
} else if (data.length == 1 && data[0] == 0xff) {
|
||||||
console.log(Buffer.from(tmp).toString())
|
console.log(Buffer.from(tmp).toString())
|
||||||
localEvent.emit('print', Buffer.from(tmp).toString())
|
if (!failFlag) {
|
||||||
} else {
|
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)]
|
tmp = [...tmp, ...data.slice(2, data.length)]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!withoutResponse) {
|
if (!withoutResponse) {
|
||||||
console.log('send response')
|
console.log('send response')
|
||||||
callback(this.RESULT_SUCCESS)
|
callback(this.RESULT_SUCCESS)
|
||||||
|
Loading…
Reference in New Issue
Block a user