UNPKG

1.67 kBJavaScriptView Raw
1var events = require('events');
2var util = require('util');
3
4var services = require('./services.json');
5
6function 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
24util.inherits(Service, events.EventEmitter);
25
26Service.isStandardService = function(uuid) {
27 return (services[uuid] ? true : false);
28}
29Service.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 // includedServiceUuids: this.includedServiceUuids
37 });
38};
39
40// TODO: Implement this
41Service.prototype.discoverIncludedServices = function(serviceUuids, callback) {
42 // if (callback) {
43 // this.once('includedServicesDiscover', function(includedServiceUuids) {
44 // callback(null, includedServiceUuids);
45 // });
46 // }
47
48 // this._noble.discoverIncludedServices(
49 // this._peripheralUuid,
50 // this.uuid,
51 // serviceUuids
52 // );
53};
54Service.prototype.discoverCharacteristics = function(characteristicUuids, callback) {
55 this._peripheral._controller.discoverCharacteristicsOfService(this, characteristicUuids, callback);
56};
57
58Service.prototype.discoverAllCharacteristics = function(callback) {
59 this._peripheral._controller.discoverAllCharacteristicsOfService(this, callback);
60};
61
62module.exports = Service;