diff --git a/index.js b/index.js index e6c6f50..a4bb81f 100644 --- a/index.js +++ b/index.js @@ -285,10 +285,11 @@ function rSequence (req, res, next) { //Ble functions -function bFrame (cb) { +function bFrame (obj, cb) { let dir = intval._state.frame.dir let len = 630 - cb({ dir: dir, len : len }) + console.dir(obj) + setTimeout(cb, 630) } function index (req, res, next) { diff --git a/lib/ble/index.js b/lib/ble/index.js index ee7e4d9..e5406a0 100644 --- a/lib/ble/index.js +++ b/lib/ble/index.js @@ -165,6 +165,7 @@ class BLE { let result = {} let utf8 let obj + let fn if (offset) { log.warn(`Offset scenario`) result = bleno.Characteristic.RESULT_ATTR_NOT_LONG @@ -173,15 +174,15 @@ class BLE { utf8 = data.toString('utf8') obj = JSON.parse(utf8) result = bleno.Characteristic.RESULT_SUCCESS - if (obj.type && this[`_on${capitalize(obj.type)}`]) { - this[`_on${capitalize(obj.type)}`]( obj => { - let str = JSON.stringify(obj) - let data = new Buffer(str) - return callback(result, data.slice(offset, data.length)) + fn = `_on${capitalize(obj.type)}` + if (obj.type && this[fn]) { + return this[fn](obj, () => { + callback(result) }) } else { return callback(result) } + } _onRead (offset, callback) { const result = bleno.Characteristic.RESULT_SUCCESS