From d7f491961a5c634204703321118d684eb231e658 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 24 Aug 2017 13:54:57 +0800 Subject: [PATCH] add ble package check --- gdata-characteristic.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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)