2017-08-09 10:15:07 +00:00
|
|
|
const bleno = require('bleno')
|
2017-08-10 01:24:14 +00:00
|
|
|
const config = require('./config.json')
|
2017-08-09 10:15:07 +00:00
|
|
|
|
2017-08-10 12:18:43 +00:00
|
|
|
var tmp = []
|
|
|
|
|
2017-08-09 10:15:07 +00:00
|
|
|
class DataCharacteristic extends bleno.Characteristic {
|
|
|
|
constructor() {
|
|
|
|
super({
|
2017-08-10 01:24:14 +00:00
|
|
|
uuid: config.uuid.service.func.data,
|
2017-08-09 10:15:07 +00:00
|
|
|
properties: ['write', 'writeWithoutResponse'],
|
|
|
|
descriptors: [
|
|
|
|
new bleno.Descriptor({
|
|
|
|
uuid: '8888',
|
|
|
|
value: 'Now'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
2017-08-10 14:31:02 +00:00
|
|
|
|
2017-08-09 10:15:07 +00:00
|
|
|
onWriteRequest(data, offset, withoutResponse, callback) {
|
|
|
|
console.log(`offset :: ${offset} , withoutRes :: ${withoutResponse}`)
|
|
|
|
console.log(`get data`, data)
|
2017-08-10 12:18:43 +00:00
|
|
|
|
2017-08-10 14:31:02 +00:00
|
|
|
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)]
|
|
|
|
}
|
2017-08-10 12:18:43 +00:00
|
|
|
if (!withoutResponse) {
|
2017-08-10 14:31:02 +00:00
|
|
|
console.log('send response')
|
2017-08-09 10:15:07 +00:00
|
|
|
callback(this.RESULT_SUCCESS)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 01:24:14 +00:00
|
|
|
module.exports = DataCharacteristic
|