1 | var events = require('events');
|
2 | var util = require('util');
|
3 |
|
4 | var descriptors = require('./descriptors.json');
|
5 |
|
6 | function Descriptor(peripheral, uuid, handle) {
|
7 | this._peripheral = peripheral;
|
8 | this.uuid = uuid;
|
9 | this.handle = handle;
|
10 | this.name = null;
|
11 | this.type = null;
|
12 | this.value;
|
13 |
|
14 | var descriptor = descriptors[uuid];
|
15 | if (descriptor) {
|
16 | this.name = descriptor.name;
|
17 | this.type = descriptor.type;
|
18 | }
|
19 | }
|
20 |
|
21 | util.inherits(Descriptor, events.EventEmitter);
|
22 |
|
23 | Descriptor.isStandardDescriptor = function(uuid) {
|
24 | return (descriptors[uuid] ? true : false);
|
25 | }
|
26 |
|
27 | Descriptor.prototype.toString = function() {
|
28 | return JSON.stringify({
|
29 | uuid: this.uuid,
|
30 | name: this.name,
|
31 | type: this.type,
|
32 | value : this.value,
|
33 | });
|
34 | };
|
35 |
|
36 | Descriptor.prototype.read = function(callback) {
|
37 | this._peripheral._controller.readDescriptor(this, callback);
|
38 | };
|
39 |
|
40 | Descriptor.prototype.write = function(data, callback) {
|
41 | this._peripheral._controller.writeDescriptor(this, data, callback);
|
42 | };
|
43 |
|
44 | module.exports = Descriptor;
|