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