OK! Cannot pass data back during a write event, BUUUT can respond asynchronously, and state can be read immediately after? Or should I cache a response? More on this later.

This commit is contained in:
mmcwilliams 2017-12-12 13:37:36 -05:00
parent 601d0cf581
commit d8e6a2206e
2 changed files with 9 additions and 7 deletions

View File

@ -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) {

View File

@ -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