1 | var events = require('events');
|
2 | var util = require('util');
|
3 |
|
4 | var services = require('./services.json');
|
5 |
|
6 | function Service(peripheral, uuid, startHandle, endHandle) {
|
7 | this._peripheral = peripheral;
|
8 | this._startHandle = startHandle;
|
9 | this._endHandle = endHandle;
|
10 |
|
11 | this.uuid = uuid;
|
12 | this.name = null;
|
13 | this.type = null;
|
14 | this.includedServiceUuids = null;
|
15 | this.characteristics = {};
|
16 |
|
17 | var service = services[uuid];
|
18 | if (service) {
|
19 | this.name = service.name;
|
20 | this.type = service.type;
|
21 | }
|
22 | }
|
23 |
|
24 | util.inherits(Service, events.EventEmitter);
|
25 |
|
26 | Service.isStandardService = function(uuid) {
|
27 | return (services[uuid] ? true : false);
|
28 | }
|
29 | Service.prototype.toString = function() {
|
30 | return JSON.stringify({
|
31 | uuid: this.uuid,
|
32 | name: this.name,
|
33 | type: this.type,
|
34 | startHandle : this._startHandle,
|
35 | endHandle : this._endHandle,
|
36 |
|
37 | });
|
38 | };
|
39 |
|
40 |
|
41 | Service.prototype.discoverIncludedServices = function(serviceUuids, callback) {
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | };
|
54 | Service.prototype.discoverCharacteristics = function(characteristicUuids, callback) {
|
55 | this._peripheral._controller.discoverCharacteristicsOfService(this, characteristicUuids, callback);
|
56 | };
|
57 |
|
58 | Service.prototype.discoverAllCharacteristics = function(callback) {
|
59 | this._peripheral._controller.discoverAllCharacteristicsOfService(this, callback);
|
60 | };
|
61 |
|
62 | module.exports = Service;
|