-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacteristic.js
More file actions
56 lines (38 loc) · 1.53 KB
/
Copy pathcharacteristic.js
File metadata and controls
56 lines (38 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var util = require('util');
var bleno = require('bleno');
var BlenoCharacteristic = bleno.Characteristic;
var EchoCharacteristic = function () {
EchoCharacteristic.super_.call(this, {
uuid: 'ec0e',
properties: ['read', 'write', 'notify'],
value: null
});
this._value = Buffer.alloc(0);
this._updateValueCallback = null;
};
util.inherits(EchoCharacteristic, BlenoCharacteristic);
EchoCharacteristic.prototype.onReadRequest = function (offset, callback) {
console.log('EchoCharacteristic - onReadRequest: value = ' + this._value.toString('hex'));
callback(this.RESULT_SUCCESS, this._value);
};
EchoCharacteristic.prototype.onWriteRequest = function (data, offset, withoutResponse, callback) {
this._value = data;
console.log('EchoCharacteristic - onWriteRequest: value = ' + this._value.toString('hex'));
console.log('converted: value = ' + this._value.toString('base64'));
console.log("raw value: " + this._value);
console.log("data: " + data);
if (this._updateValueCallback) {
console.log('EchoCharacteristic - onWriteRequest: notifying');
this._updateValueCallback(this._value);
}
callback(this.RESULT_SUCCESS);
};
EchoCharacteristic.prototype.onSubscribe = function (maxValueSize, updateValueCallback) {
console.log('EchoCharacteristic - onSubscribe');
this._updateValueCallback = updateValueCallback;
};
EchoCharacteristic.prototype.onUnsubscribe = function () {
console.log('EchoCharacteristic - onUnsubscribe');
this._updateValueCallback = null;
};
module.exports = EchoCharacteristic;