incyclist-devices 2.3.0-beta.4 → 2.3.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -312,6 +312,7 @@ class BleInterface extends events_1.default {
312
312
  return;
313
313
  }
314
314
  if (announcement.serviceUUIDs.length === 0) {
315
+ return;
315
316
  if (this.isCompleting(announcement)) {
316
317
  return;
317
318
  }
@@ -79,6 +79,7 @@ class DirectConnectPeripheral {
79
79
  }
80
80
  discoverServices() {
81
81
  return __awaiter(this, void 0, void 0, function* () {
82
+ var _a, _b;
82
83
  const seqNo = this.getNextSeqNo();
83
84
  const message = new messages_1.DiscoverServiceMessage();
84
85
  const request = message.createRequest(seqNo, {});
@@ -88,7 +89,12 @@ class DirectConnectPeripheral {
88
89
  response = yield this.send(seqNo, request);
89
90
  const res = message.parseResponse(response);
90
91
  const uuids = res.body.serviceDefinitions.map(s => (0, utils_1.beautifyUUID)(s.serviceUUID));
91
- this.logEvent({ message: 'DiscoverServices response', path: this.getPath(), uuids, raw: response.toString('hex') });
92
+ const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
93
+ if (((_b = res === null || res === void 0 ? void 0 : res.header) === null || _b === void 0 ? void 0 : _b.respCode) !== consts_1.DC_RC_REQUEST_COMPLETED_SUCCESSFULLY) {
94
+ this.logEvent({ message: 'DiscoverServices failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
95
+ return [];
96
+ }
97
+ this.logEvent({ message: 'DiscoverServices response', path: this.getPath(), rc, uuids, raw: response.toString('hex') });
92
98
  return res.body.serviceDefinitions.map(s => s.serviceUUID);
93
99
  }
94
100
  catch (err) {
@@ -99,6 +105,7 @@ class DirectConnectPeripheral {
99
105
  }
100
106
  discoverCharacteristics(serviceUUID) {
101
107
  return __awaiter(this, void 0, void 0, function* () {
108
+ var _a, _b;
102
109
  const seqNo = this.getNextSeqNo();
103
110
  const message = new messages_1.DiscoverCharacteristicsMessage();
104
111
  const request = message.createRequest(seqNo, { serviceUUID: (0, utils_1.parseUUID)(serviceUUID) });
@@ -107,9 +114,14 @@ class DirectConnectPeripheral {
107
114
  try {
108
115
  response = yield this.send(seqNo, request);
109
116
  const res = message.parseResponse(response);
117
+ const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
118
+ if (((_b = res === null || res === void 0 ? void 0 : res.header) === null || _b === void 0 ? void 0 : _b.respCode) !== consts_1.DC_RC_REQUEST_COMPLETED_SUCCESSFULLY) {
119
+ this.logEvent({ message: 'DiscoverCharacteritics failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
120
+ return [];
121
+ }
110
122
  const service = (0, utils_1.beautifyUUID)(res.body.serviceUUID);
111
123
  const characteristics = res.body.characteristicDefinitions.map(cd => `${(0, utils_1.beautifyUUID)(cd.characteristicUUID)}:${cd.properties.join('/')}`);
112
- this.logEvent({ message: 'DiscoverCharacteritics response', path: this.getPath(), service, characteristics, raw: response.toString('hex') });
124
+ this.logEvent({ message: 'DiscoverCharacteritics response', path: this.getPath(), rc, service, characteristics, raw: response.toString('hex') });
113
125
  return res.body.characteristicDefinitions.map(c => ({ uuid: c.characteristicUUID, properties: c.properties }));
114
126
  }
115
127
  catch (err) {
@@ -120,6 +132,7 @@ class DirectConnectPeripheral {
120
132
  }
121
133
  subscribe(characteristicUUID, callback) {
122
134
  return __awaiter(this, void 0, void 0, function* () {
135
+ var _a, _b;
123
136
  const seqNo = this.getNextSeqNo();
124
137
  const message = new messages_1.EnableCharacteristicNotificationsMessage();
125
138
  const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), enable: true });
@@ -128,7 +141,12 @@ class DirectConnectPeripheral {
128
141
  try {
129
142
  response = yield this.send(seqNo, request);
130
143
  const res = message.parseResponse(response);
131
- this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: response.toString('hex') });
144
+ const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
145
+ if (((_b = res === null || res === void 0 ? void 0 : res.header) === null || _b === void 0 ? void 0 : _b.respCode) !== consts_1.DC_RC_REQUEST_COMPLETED_SUCCESSFULLY) {
146
+ this.logEvent({ message: 'EnableCharacteristicNotifications failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
147
+ return false;
148
+ }
149
+ this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), rc, characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: response.toString('hex') });
132
150
  const confirmed = res.body.characteristicUUID;
133
151
  if ((0, utils_1.parseUUID)(confirmed) === (0, utils_1.parseUUID)(characteristicUUID)) {
134
152
  this.subscribed.push(characteristicUUID);
@@ -147,6 +165,7 @@ class DirectConnectPeripheral {
147
165
  }
148
166
  unsubscribe(characteristicUUID) {
149
167
  return __awaiter(this, void 0, void 0, function* () {
168
+ var _a, _b;
150
169
  try {
151
170
  const seqNo = this.getNextSeqNo();
152
171
  const message = new messages_1.EnableCharacteristicNotificationsMessage();
@@ -156,7 +175,12 @@ class DirectConnectPeripheral {
156
175
  this.logEvent({ message: 'EnableCharacteristicNotifications request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID), enabled: false, raw: request.toString('hex') });
157
176
  response = yield this.send(seqNo, request);
158
177
  const res = message.parseResponse(response);
159
- this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: response.toString('hex') });
178
+ const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
179
+ if (((_b = res === null || res === void 0 ? void 0 : res.header) === null || _b === void 0 ? void 0 : _b.respCode) !== consts_1.DC_RC_REQUEST_COMPLETED_SUCCESSFULLY) {
180
+ this.logEvent({ message: 'EnableCharacteristicNotifications failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
181
+ return false;
182
+ }
183
+ this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), rc, characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: response.toString('hex') });
160
184
  const confirmed = res.body.characteristicUUID;
161
185
  if ((0, utils_1.parseUUID)(confirmed) === (0, utils_1.parseUUID)(characteristicUUID)) {
162
186
  this.subscribed.splice(this.subscribed.indexOf(characteristicUUID), 1);
@@ -234,12 +258,18 @@ class DirectConnectPeripheral {
234
258
  }
235
259
  }
236
260
  const retry = [];
237
- this.logEvent({ message: 'characteristics supported', requested: characteristics.map(c => (0, utils_1.beautifyUUID)(c)), supported: supported.map(c => (0, utils_1.beautifyUUID)(c)) });
261
+ this.logEvent({ message: 'characteristics supported', requested: characteristics.map(c => (0, utils_1.beautifyUUID)(c)), supported: supported.map(c => (0, utils_1.beautifyUUID)(c.uuid)) });
238
262
  for (const element of characteristics) {
239
263
  const uuid = element;
240
- const success = yield this.subscribe(uuid, callback);
241
- if (!success)
242
- retry.push(uuid);
264
+ const found = supported.find(c => (0, utils_1.beautifyUUID)(c.uuid) === (0, utils_1.beautifyUUID)(uuid));
265
+ if (!found) {
266
+ this.logEvent({ message: 'characteristic not supported', requested: (0, utils_1.beautifyUUID)(uuid) });
267
+ }
268
+ else {
269
+ const success = yield this.subscribe(uuid, callback);
270
+ if (!success)
271
+ retry.push(uuid);
272
+ }
243
273
  }
244
274
  for (const element of retry) {
245
275
  const c = element;
@@ -260,6 +290,7 @@ class DirectConnectPeripheral {
260
290
  }
261
291
  read(characteristicUUID) {
262
292
  return __awaiter(this, void 0, void 0, function* () {
293
+ var _a, _b;
263
294
  const seqNo = this.getNextSeqNo();
264
295
  const message = new messages_1.ReadCharacteristicMessage();
265
296
  const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID) });
@@ -268,7 +299,12 @@ class DirectConnectPeripheral {
268
299
  this.logEvent({ message: 'ReadCharacteristic request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID), raw: request.toString('hex') });
269
300
  response = yield this.send(seqNo, request);
270
301
  const res = message.parseResponse(response);
271
- this.logEvent({ message: 'ReadCharacteristic response', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID),
302
+ const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
303
+ if (((_b = res === null || res === void 0 ? void 0 : res.header) === null || _b === void 0 ? void 0 : _b.respCode) !== consts_1.DC_RC_REQUEST_COMPLETED_SUCCESSFULLY) {
304
+ this.logEvent({ message: 'ReadCharacteristic failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
305
+ return Buffer.from([]);
306
+ }
307
+ this.logEvent({ message: 'ReadCharacteristic response', path: this.getPath(), rc, characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID),
272
308
  data: Buffer.from(res.body.characteristicData).toString('hex'),
273
309
  raw: response.toString('hex') });
274
310
  return Buffer.from(res.body.characteristicData);
@@ -297,10 +333,17 @@ class DirectConnectPeripheral {
297
333
  data: data.toString('hex'),
298
334
  raw: request.toString('hex') });
299
335
  this.send(seqNo, request).then((data) => {
336
+ var _a, _b;
300
337
  response = data;
301
338
  const res = message.parseResponse(response);
339
+ const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
340
+ if (((_b = res === null || res === void 0 ? void 0 : res.header) === null || _b === void 0 ? void 0 : _b.respCode) !== consts_1.DC_RC_REQUEST_COMPLETED_SUCCESSFULLY) {
341
+ this.logEvent({ message: 'WriteCharacteristic failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
342
+ resolve(Buffer.from([]));
343
+ return;
344
+ }
302
345
  characteristic = (0, utils_1.beautifyUUID)(res.body.characteristicUUID);
303
- this.logEvent({ message: 'WriteCharacteristic response', path: this.getPath(), characteristic,
346
+ this.logEvent({ message: 'WriteCharacteristic response', path: this.getPath(), rc, characteristic,
304
347
  raw: response.toString('hex') });
305
348
  if (options === null || options === void 0 ? void 0 : options.withoutResponse) {
306
349
  resolve(Buffer.from([]));
@@ -308,6 +351,7 @@ class DirectConnectPeripheral {
308
351
  })
309
352
  .catch(err => {
310
353
  this.logEvent({ message: 'WriteCharacteristic failed', path: this.getPath(), characteristic, raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: err.message });
354
+ resolve(Buffer.from([]));
311
355
  });
312
356
  });
313
357
  });
@@ -444,10 +488,11 @@ class DirectConnectPeripheral {
444
488
  this.msgSeqNo = notification.header.seqNum;
445
489
  const uuid = (0, utils_1.parseUUID)(notification.body.characteristicUUID);
446
490
  this.logEvent({ message: 'Characteristic notification', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(notification.body.characteristicUUID),
447
- data: Buffer.from(notification.body.characteristicData).toString('hex') });
491
+ data: Buffer.from(notification.body.characteristicData).toString('hex'), raw: incoming.toString('hex') });
448
492
  this.eventEmitter.emit(uuid, notification.body.characteristicData);
449
493
  }
450
494
  else {
495
+ this.logEvent({ message: 'incoming message', path: this.getPath(), raw: incoming.toString('hex'), header });
451
496
  this.eventEmitter.emit(`response-${header.seqNum}`, incoming);
452
497
  }
453
498
  }
@@ -18,3 +18,4 @@ export declare class Message<TReq extends TDCBody, TRes extends TDCBody> {
18
18
  parseResponseBody(body: Buffer): TRes;
19
19
  }
20
20
  export declare const parseHeader: (buffer: Buffer) => TDCMessageHeader;
21
+ export declare const RC: (code: any) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseHeader = exports.Message = void 0;
3
+ exports.RC = exports.parseHeader = exports.Message = void 0;
4
4
  const consts_1 = require("../consts");
5
5
  const error_1 = require("./error");
6
6
  class Message {
@@ -88,3 +88,18 @@ const parseHeader = (buffer) => {
88
88
  return { msgVersion, msgId, seqNum, respCode, length };
89
89
  };
90
90
  exports.parseHeader = parseHeader;
91
+ const RC = (code) => {
92
+ switch (code) {
93
+ case consts_1.DC_RC_REQUEST_COMPLETED_SUCCESSFULLY: return 'success';
94
+ case consts_1.DC_RC_UNKNOWN_MESSAGE_TYPE: return 'Unknown Message Type';
95
+ case consts_1.DC_RC_UNEXPECTED_ERROR: return 'Unexpected Error';
96
+ case consts_1.DC_RC_SERVICE_NOT_FOUND: return 'Service Not Found';
97
+ case consts_1.DC_RC_CHARACTERISTIC_NOT_FOUND: return 'Characteristic Not Found';
98
+ case consts_1.DC_RC_CHARACTERISTIC_OPERATION_NOT_SUPPORTED: return 'Characteristic Operation Not Supported';
99
+ case consts_1.DC_RC_CHARACTERISTIC_WRITE_FAILED_INVALID_SIZE: return 'Characteristic Write Failed';
100
+ case consts_1.DC_RC_UNKNOWN_PROTOCOL_VERSION: return 'Unknown Protocol Version';
101
+ default:
102
+ return `Unknown (${code})`;
103
+ }
104
+ };
105
+ exports.RC = RC;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.3.0-beta.4",
3
+ "version": "2.3.0-beta.6",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",