diff --git a/gdata-characteristic.js b/gdata-characteristic.js index 2fcd438..c75a73e 100644 --- a/gdata-characteristic.js +++ b/gdata-characteristic.js @@ -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)