From 65f56a6b1445c03923d838902415afc57ca01a17 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 10 Aug 2017 20:18:43 +0800 Subject: [PATCH] update data getter --- app.js | 5 +++-- config.json | 1 + gdata-characteristic.js | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 4d5d49a..d195fa7 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ const bleno = require('bleno') +const config = require('./config.json') const adapterName = 'BLE_Printer' -const serverUUID = 'ff9987' +const serverUUID = config.uuid.main const MainService = require('./main-service') @@ -24,4 +25,4 @@ bleno.on('advertisingStart', function (error) { console.log('set service', error) }) } -}) \ No newline at end of file +}) diff --git a/config.json b/config.json index fa93475..a540f7d 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,6 @@ { "uuid":{ + "main": "930da73d-1b80-4d3e-a8b6-d9b4e7e771bd", "service":{ "id":"dd535b71-8f05-4e30-beb0-6fa7ea3dfc3e", "func":{ diff --git a/gdata-characteristic.js b/gdata-characteristic.js index 44b82ff..4be0314 100644 --- a/gdata-characteristic.js +++ b/gdata-characteristic.js @@ -1,6 +1,8 @@ const bleno = require('bleno') const config = require('./config.json') +var tmp = [] + class DataCharacteristic extends bleno.Characteristic { constructor() { super({ @@ -18,7 +20,18 @@ class DataCharacteristic extends bleno.Characteristic { onWriteRequest(data, offset, withoutResponse, callback) { console.log(`offset :: ${offset} , withoutRes :: ${withoutResponse}`) console.log(`get data`, data) - if (withoutResponse) { + + if(data.length == 1 && data[0] == 0x00){ + tmp = [] + console.log(data[0]) + }else if(data.length == 1 && data[0] == 0xff){ + //console.log(tmp) + console.log(new Buffer(tmp).toString()) + }else{ + tmp = [...tmp, ...data.slice(2, data.length)] + } + if (!withoutResponse) { + console.log('send response') callback(this.RESULT_SUCCESS) } }