add notify test

This commit is contained in:
Jay 2017-08-16 22:03:35 +08:00
parent 32af5548e6
commit 1041190113

View File

@ -11,18 +11,21 @@ device.open(()=>{
var tmp = [] var tmp = []
const notifyDesciptor = new bleno.Descriptor({
uuid: '8888',
value: 0
})
class DataCharacteristic extends bleno.Characteristic { class DataCharacteristic extends bleno.Characteristic {
constructor() { constructor() {
super({ super({
uuid: config.uuid.service.func.data, uuid: config.uuid.service.func.data,
properties: ['write', 'writeWithoutResponse'], properties: ['write', 'writeWithoutResponse', 'notify'],
descriptors: [ descriptors: [
new bleno.Descriptor({ notifyDesciptor
uuid: '8888',
value: 'Now'
})
] ]
}) })
this._notifyFunc = null
} }
onWriteRequest(data, offset, withoutResponse, callback) { onWriteRequest(data, offset, withoutResponse, callback) {
@ -36,6 +39,9 @@ class DataCharacteristic extends bleno.Characteristic {
//console.log(tmp) //console.log(tmp)
console.log(Buffer.from(tmp).toString()) console.log(Buffer.from(tmp).toString())
printString(Buffer.from(tmp).toString()) printString(Buffer.from(tmp).toString())
if(this._notifyFunc) {
this._notifyFunc(Buffer.from([0x00,0x01]))
}
} else { } else {
tmp = [...tmp, ...data.slice(2, data.length)] tmp = [...tmp, ...data.slice(2, data.length)]
} }
@ -44,6 +50,15 @@ class DataCharacteristic extends bleno.Characteristic {
callback(this.RESULT_SUCCESS) callback(this.RESULT_SUCCESS)
} }
} }
onSubscribe(maxValueSize, cb) {
console.log(maxValueSize)
this._notifyFunc = cb
}
onUnsubscribe () {
this._notifyFunc = null
}
} }