incyclist-devices 2.3.0-beta.2 → 2.3.0-beta.20
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.
- package/README.MD +55 -0
- package/lib/antv2/base/adapter.d.ts +2 -2
- package/lib/base/adpater.d.ts +4 -0
- package/lib/base/adpater.js +16 -2
- package/lib/ble/adapter-factory.d.ts +24 -20
- package/lib/ble/adapter-factory.js +36 -13
- package/lib/ble/base/adapter.d.ts +6 -3
- package/lib/ble/base/adapter.js +72 -38
- package/lib/ble/base/comms.d.ts +74 -2
- package/lib/ble/base/comms.js +596 -3
- package/lib/ble/base/interface.d.ts +14 -5
- package/lib/ble/base/interface.js +125 -66
- package/lib/ble/base/peripheral.d.ts +7 -3
- package/lib/ble/base/peripheral.js +76 -22
- package/lib/ble/base/sensor.d.ts +1 -1
- package/lib/ble/base/sensor.js +17 -3
- package/lib/ble/ble-interface.d.ts +4 -7
- package/lib/ble/ble-interface.js +2 -16
- package/lib/ble/ble-peripheral.d.ts +0 -1
- package/lib/ble/ble-peripheral.js +11 -7
- package/lib/ble/characteristics/csc/features.d.ts +10 -0
- package/lib/ble/characteristics/csc/features.js +19 -0
- package/lib/ble/characteristics/csc/measurement.d.ts +33 -0
- package/lib/ble/characteristics/csc/measurement.js +109 -0
- package/lib/ble/characteristics/types.d.ts +6 -0
- package/lib/ble/characteristics/types.js +2 -0
- package/lib/ble/consts.d.ts +1 -0
- package/lib/ble/consts.js +2 -1
- package/lib/ble/cp/comm.d.ts +1 -1
- package/lib/ble/cp/comm.js +2 -2
- package/lib/ble/csc/adapter.d.ts +17 -0
- package/lib/ble/csc/adapter.js +66 -0
- package/lib/ble/csc/index.d.ts +3 -0
- package/lib/ble/csc/index.js +19 -0
- package/lib/ble/csc/sensor.d.ts +21 -0
- package/lib/ble/csc/sensor.js +64 -0
- package/lib/ble/csc/types.d.ts +6 -0
- package/lib/ble/csc/types.js +2 -0
- package/lib/ble/elite/comms.d.ts +1 -1
- package/lib/ble/elite/comms.js +2 -2
- package/lib/ble/fm/adapter.d.ts +4 -3
- package/lib/ble/fm/adapter.js +53 -49
- package/lib/ble/fm/comms.d.ts +1 -1
- package/lib/ble/fm/comms.js +3 -3
- package/lib/ble/fm/sensor.d.ts +1 -1
- package/lib/ble/fm/sensor.js +6 -5
- package/lib/ble/hr/comm.d.ts +1 -1
- package/lib/ble/hr/comm.js +2 -2
- package/lib/ble/index.js +2 -0
- package/lib/ble/tacx/adapter.d.ts +1 -1
- package/lib/ble/tacx/adapter.js +12 -10
- package/lib/ble/tacx/comms.d.ts +1 -1
- package/lib/ble/tacx/comms.js +2 -2
- package/lib/ble/tacx/sensor.js +9 -3
- package/lib/ble/types.d.ts +8 -2
- package/lib/ble/utils.d.ts +1 -0
- package/lib/ble/utils.js +5 -1
- package/lib/ble/wahoo/adapter.d.ts +1 -0
- package/lib/ble/wahoo/adapter.js +14 -0
- package/lib/ble/wahoo/comms.d.ts +1 -1
- package/lib/ble/wahoo/comms.js +2 -2
- package/lib/ble/wahoo/sensor.js +3 -6
- package/lib/direct-connect/base/interface.d.ts +1 -0
- package/lib/direct-connect/base/interface.js +9 -4
- package/lib/direct-connect/base/peripheral.d.ts +4 -4
- package/lib/direct-connect/base/peripheral.js +106 -31
- package/lib/direct-connect/messages/message.d.ts +1 -0
- package/lib/direct-connect/messages/message.js +16 -1
- package/lib/modes/ant-fe-adv-st-mode.d.ts +7 -1
- package/lib/modes/ant-fe-adv-st-mode.js +4 -3
- package/lib/types/adapter.d.ts +3 -0
- package/lib/types/interface.d.ts +1 -0
- package/lib/utils/task.d.ts +3 -0
- package/lib/utils/task.js +12 -0
- package/package.json +1 -1
|
@@ -55,10 +55,10 @@ class DirectConnectPeripheral {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
disconnect() {
|
|
58
|
-
return __awaiter(this,
|
|
58
|
+
return __awaiter(this, arguments, void 0, function* (connectionLost = false) {
|
|
59
59
|
try {
|
|
60
60
|
yield this.connectTask.stop();
|
|
61
|
-
yield this.stopConnection();
|
|
61
|
+
yield this.stopConnection(connectionLost);
|
|
62
62
|
delete this.socket;
|
|
63
63
|
}
|
|
64
64
|
catch (err) {
|
|
@@ -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
|
-
|
|
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:
|
|
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,11 @@ class DirectConnectPeripheral {
|
|
|
120
132
|
}
|
|
121
133
|
subscribe(characteristicUUID, callback) {
|
|
122
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
const uuid = (0, utils_1.parseUUID)(characteristicUUID);
|
|
137
|
+
if (this.subscribed.includes(uuid)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
123
140
|
const seqNo = this.getNextSeqNo();
|
|
124
141
|
const message = new messages_1.EnableCharacteristicNotificationsMessage();
|
|
125
142
|
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), enable: true });
|
|
@@ -128,13 +145,20 @@ class DirectConnectPeripheral {
|
|
|
128
145
|
try {
|
|
129
146
|
response = yield this.send(seqNo, request);
|
|
130
147
|
const res = message.parseResponse(response);
|
|
131
|
-
|
|
148
|
+
const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
|
|
149
|
+
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) {
|
|
150
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), rc, characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: response.toString('hex') });
|
|
132
154
|
const confirmed = res.body.characteristicUUID;
|
|
133
155
|
if ((0, utils_1.parseUUID)(confirmed) === (0, utils_1.parseUUID)(characteristicUUID)) {
|
|
134
|
-
this.subscribed.push(characteristicUUID);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
156
|
+
this.subscribed.push((0, utils_1.parseUUID)(characteristicUUID));
|
|
157
|
+
if (callback) {
|
|
158
|
+
this.eventEmitter.on((0, utils_1.parseUUID)(characteristicUUID), (data) => {
|
|
159
|
+
callback(characteristicUUID, data);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
138
162
|
return true;
|
|
139
163
|
}
|
|
140
164
|
return false;
|
|
@@ -147,6 +171,7 @@ class DirectConnectPeripheral {
|
|
|
147
171
|
}
|
|
148
172
|
unsubscribe(characteristicUUID) {
|
|
149
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
var _a, _b;
|
|
150
175
|
try {
|
|
151
176
|
const seqNo = this.getNextSeqNo();
|
|
152
177
|
const message = new messages_1.EnableCharacteristicNotificationsMessage();
|
|
@@ -156,10 +181,15 @@ class DirectConnectPeripheral {
|
|
|
156
181
|
this.logEvent({ message: 'EnableCharacteristicNotifications request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID), enabled: false, raw: request.toString('hex') });
|
|
157
182
|
response = yield this.send(seqNo, request);
|
|
158
183
|
const res = message.parseResponse(response);
|
|
159
|
-
|
|
184
|
+
const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
|
|
185
|
+
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) {
|
|
186
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
this.logEvent({ message: 'EnableCharacteristicNotifications response', path: this.getPath(), rc, characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID), raw: response.toString('hex') });
|
|
160
190
|
const confirmed = res.body.characteristicUUID;
|
|
161
191
|
if ((0, utils_1.parseUUID)(confirmed) === (0, utils_1.parseUUID)(characteristicUUID)) {
|
|
162
|
-
this.subscribed.splice(this.subscribed.indexOf(characteristicUUID), 1);
|
|
192
|
+
this.subscribed.splice(this.subscribed.indexOf((0, utils_1.parseUUID)(characteristicUUID)), 1);
|
|
163
193
|
this.eventEmitter.removeAllListeners((0, utils_1.parseUUID)(characteristicUUID));
|
|
164
194
|
return true;
|
|
165
195
|
}
|
|
@@ -214,12 +244,38 @@ class DirectConnectPeripheral {
|
|
|
214
244
|
}
|
|
215
245
|
subscribeSelected(characteristics, callback) {
|
|
216
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
let services = [];
|
|
248
|
+
let supported = [];
|
|
249
|
+
try {
|
|
250
|
+
services = yield this.discoverServices();
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
this.logEvent({ message: 'could not discover services', reason: err.message });
|
|
254
|
+
}
|
|
255
|
+
for (const element of services) {
|
|
256
|
+
const service = element;
|
|
257
|
+
try {
|
|
258
|
+
const c = yield this.discoverCharacteristics(service);
|
|
259
|
+
supported = supported.concat(c);
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
this.logEvent({ message: 'could not discover characteristics', service, reason: err.message });
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
217
266
|
const retry = [];
|
|
267
|
+
this.logEvent({ message: 'characteristics supported', requested: characteristics.map(c => (0, utils_1.beautifyUUID)(c)), supported: supported.map(c => (0, utils_1.beautifyUUID)(c.uuid)) });
|
|
218
268
|
for (const element of characteristics) {
|
|
219
269
|
const uuid = element;
|
|
220
|
-
const
|
|
221
|
-
if (!
|
|
222
|
-
|
|
270
|
+
const found = supported.find(c => (0, utils_1.beautifyUUID)(c.uuid) === (0, utils_1.beautifyUUID)(uuid));
|
|
271
|
+
if (!found) {
|
|
272
|
+
this.logEvent({ message: 'characteristic not supported', requested: (0, utils_1.beautifyUUID)(uuid) });
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
const success = yield this.subscribe(uuid, callback);
|
|
276
|
+
if (!success)
|
|
277
|
+
retry.push(uuid);
|
|
278
|
+
}
|
|
223
279
|
}
|
|
224
280
|
for (const element of retry) {
|
|
225
281
|
const c = element;
|
|
@@ -229,17 +285,21 @@ class DirectConnectPeripheral {
|
|
|
229
285
|
});
|
|
230
286
|
}
|
|
231
287
|
unsubscribeAll() {
|
|
232
|
-
return __awaiter(this,
|
|
288
|
+
return __awaiter(this, arguments, void 0, function* (connectionLost = false) {
|
|
289
|
+
if (connectionLost) {
|
|
290
|
+
this.subscribed = [];
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
233
293
|
const promises = [];
|
|
234
294
|
this.subscribed.forEach(characteristicUUID => {
|
|
235
|
-
promises.push(this.unsubscribe(characteristicUUID));
|
|
295
|
+
promises.push(this.unsubscribe((0, utils_1.parseUUID)(characteristicUUID)));
|
|
236
296
|
});
|
|
237
297
|
yield Promise.allSettled(promises);
|
|
238
|
-
return true;
|
|
239
298
|
});
|
|
240
299
|
}
|
|
241
300
|
read(characteristicUUID) {
|
|
242
301
|
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
var _a, _b;
|
|
243
303
|
const seqNo = this.getNextSeqNo();
|
|
244
304
|
const message = new messages_1.ReadCharacteristicMessage();
|
|
245
305
|
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID) });
|
|
@@ -248,9 +308,14 @@ class DirectConnectPeripheral {
|
|
|
248
308
|
this.logEvent({ message: 'ReadCharacteristic request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID), raw: request.toString('hex') });
|
|
249
309
|
response = yield this.send(seqNo, request);
|
|
250
310
|
const res = message.parseResponse(response);
|
|
251
|
-
|
|
311
|
+
const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
|
|
312
|
+
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) {
|
|
313
|
+
this.logEvent({ message: 'ReadCharacteristic failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
|
|
314
|
+
return Buffer.from([]);
|
|
315
|
+
}
|
|
316
|
+
this.logEvent({ message: 'ReadCharacteristic response', path: this.getPath(), rc, characteristic: (0, utils_1.beautifyUUID)(res.body.characteristicUUID),
|
|
252
317
|
data: Buffer.from(res.body.characteristicData).toString('hex'),
|
|
253
|
-
raw:
|
|
318
|
+
raw: response.toString('hex') });
|
|
254
319
|
return Buffer.from(res.body.characteristicData);
|
|
255
320
|
}
|
|
256
321
|
catch (err) {
|
|
@@ -262,32 +327,41 @@ class DirectConnectPeripheral {
|
|
|
262
327
|
write(characteristicUUID, data, options) {
|
|
263
328
|
return __awaiter(this, void 0, void 0, function* () {
|
|
264
329
|
return new Promise(resolve => {
|
|
330
|
+
const seqNo = this.getNextSeqNo();
|
|
331
|
+
const message = new messages_1.WriteCharacteristicMessage();
|
|
332
|
+
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), characteristicData: data });
|
|
333
|
+
let response;
|
|
334
|
+
let characteristic = characteristicUUID;
|
|
265
335
|
if (!(options === null || options === void 0 ? void 0 : options.withoutResponse)) {
|
|
336
|
+
this.subscribe(characteristicUUID);
|
|
266
337
|
const uuid = (0, utils_1.parseUUID)(characteristicUUID);
|
|
267
338
|
this.eventEmitter.once(uuid, (data) => {
|
|
268
339
|
resolve(data);
|
|
269
340
|
});
|
|
270
341
|
}
|
|
271
|
-
const seqNo = this.getNextSeqNo();
|
|
272
|
-
const message = new messages_1.WriteCharacteristicMessage();
|
|
273
|
-
const request = message.createRequest(seqNo, { characteristicUUID: (0, utils_1.parseUUID)(characteristicUUID), characteristicData: data });
|
|
274
|
-
let response;
|
|
275
|
-
let characteristic = characteristicUUID;
|
|
276
342
|
this.logEvent({ message: 'WriteCharacteristic request', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(characteristicUUID),
|
|
277
343
|
data: data.toString('hex'),
|
|
278
344
|
raw: request.toString('hex') });
|
|
279
345
|
this.send(seqNo, request).then((data) => {
|
|
346
|
+
var _a, _b;
|
|
280
347
|
response = data;
|
|
281
348
|
const res = message.parseResponse(response);
|
|
349
|
+
const rc = (0, messages_1.RC)((_a = res === null || res === void 0 ? void 0 : res.header) === null || _a === void 0 ? void 0 : _a.respCode);
|
|
350
|
+
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) {
|
|
351
|
+
this.logEvent({ message: 'WriteCharacteristic failed', path: this.getPath(), raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: rc });
|
|
352
|
+
resolve(Buffer.from([]));
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
282
355
|
characteristic = (0, utils_1.beautifyUUID)(res.body.characteristicUUID);
|
|
283
|
-
this.logEvent({ message: 'WriteCharacteristic response', path: this.getPath(), characteristic,
|
|
284
|
-
raw:
|
|
356
|
+
this.logEvent({ message: 'WriteCharacteristic response', path: this.getPath(), rc, characteristic,
|
|
357
|
+
raw: response.toString('hex') });
|
|
285
358
|
if (options === null || options === void 0 ? void 0 : options.withoutResponse) {
|
|
286
359
|
resolve(Buffer.from([]));
|
|
287
360
|
}
|
|
288
361
|
})
|
|
289
362
|
.catch(err => {
|
|
290
363
|
this.logEvent({ message: 'WriteCharacteristic failed', path: this.getPath(), characteristic, raw: response === null || response === void 0 ? void 0 : response.toString('hex'), reason: err.message });
|
|
364
|
+
resolve(Buffer.from([]));
|
|
291
365
|
});
|
|
292
366
|
});
|
|
293
367
|
});
|
|
@@ -326,9 +400,10 @@ class DirectConnectPeripheral {
|
|
|
326
400
|
onPortClose() {
|
|
327
401
|
return __awaiter(this, void 0, void 0, function* () {
|
|
328
402
|
this.socket.removeAllListeners();
|
|
403
|
+
this.socket.on('error', () => { });
|
|
329
404
|
this.logEvent({ message: 'port closed', path: this.getPath() });
|
|
330
405
|
try {
|
|
331
|
-
yield this.disconnect();
|
|
406
|
+
yield this.disconnect(true);
|
|
332
407
|
}
|
|
333
408
|
catch (_a) { }
|
|
334
409
|
if (this.onDisconnectHandler)
|
|
@@ -341,11 +416,11 @@ class DirectConnectPeripheral {
|
|
|
341
416
|
return path;
|
|
342
417
|
}
|
|
343
418
|
stopConnection() {
|
|
344
|
-
return __awaiter(this,
|
|
419
|
+
return __awaiter(this, arguments, void 0, function* (connectionLost = false) {
|
|
345
420
|
this.eventEmitter.removeAllListeners();
|
|
346
421
|
if (!this.isConnected())
|
|
347
422
|
return true;
|
|
348
|
-
yield this.unsubscribeAll();
|
|
423
|
+
yield this.unsubscribeAll(connectionLost);
|
|
349
424
|
this.socket.removeAllListeners();
|
|
350
425
|
return new Promise(done => {
|
|
351
426
|
const onClosed = () => {
|
|
@@ -400,7 +475,7 @@ class DirectConnectPeripheral {
|
|
|
400
475
|
}
|
|
401
476
|
if (incoming.length > header.length + 6) {
|
|
402
477
|
this.remainingBuffer = Buffer.from(incoming.subarray(header.length + 6));
|
|
403
|
-
incoming = incoming.subarray(0, header.length + 6);
|
|
478
|
+
incoming = Buffer.from(incoming.subarray(0, header.length + 6));
|
|
404
479
|
}
|
|
405
480
|
return incoming;
|
|
406
481
|
}
|
|
@@ -424,7 +499,7 @@ class DirectConnectPeripheral {
|
|
|
424
499
|
this.msgSeqNo = notification.header.seqNum;
|
|
425
500
|
const uuid = (0, utils_1.parseUUID)(notification.body.characteristicUUID);
|
|
426
501
|
this.logEvent({ message: 'Characteristic notification', path: this.getPath(), characteristic: (0, utils_1.beautifyUUID)(notification.body.characteristicUUID),
|
|
427
|
-
data: Buffer.from(notification.body.characteristicData).toString('hex') });
|
|
502
|
+
data: Buffer.from(notification.body.characteristicData).toString('hex'), raw: incoming.toString('hex') });
|
|
428
503
|
this.eventEmitter.emit(uuid, notification.body.characteristicData);
|
|
429
504
|
}
|
|
430
505
|
else {
|
|
@@ -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;
|
|
@@ -3,8 +3,14 @@ import SmartTrainerCyclingMode from "./antble-smarttrainer";
|
|
|
3
3
|
import { UpdateRequest } from "./types";
|
|
4
4
|
export default class AntAdvSimCyclingMode extends SmartTrainerCyclingMode {
|
|
5
5
|
constructor(adapter: IncyclistDeviceAdapter, props?: any);
|
|
6
|
-
getName(): string;
|
|
7
6
|
getDescription(): string;
|
|
7
|
+
getConfig(): {
|
|
8
|
+
name: string;
|
|
9
|
+
isERG?: boolean;
|
|
10
|
+
isSIM?: boolean;
|
|
11
|
+
description: string;
|
|
12
|
+
properties: import("./types").CyclingModeProperty[];
|
|
13
|
+
};
|
|
8
14
|
checkForResetOrEmpty(request: UpdateRequest): UpdateRequest | undefined;
|
|
9
15
|
protected checkForTempPowerAdjustments(request: UpdateRequest, newRequest?: UpdateRequest): void;
|
|
10
16
|
protected checkEmptyRequest(newRequest: UpdateRequest): void;
|
|
@@ -10,12 +10,13 @@ class AntAdvSimCyclingMode extends antble_smarttrainer_1.default {
|
|
|
10
10
|
super(adapter, props);
|
|
11
11
|
this.initLogger('AdvmartTrainerMode');
|
|
12
12
|
}
|
|
13
|
-
getName() {
|
|
14
|
-
return 'Advanced Smart Trainer';
|
|
15
|
-
}
|
|
16
13
|
getDescription() {
|
|
17
14
|
return 'Sends Slope to device. Respects Limits (from workout or settings). Calculates speed based on power and slope. ';
|
|
18
15
|
}
|
|
16
|
+
getConfig() {
|
|
17
|
+
const config = super.getConfig();
|
|
18
|
+
return Object.assign(Object.assign({}, config), { name: 'Advanced Smart Trainer' });
|
|
19
|
+
}
|
|
19
20
|
checkForResetOrEmpty(request) {
|
|
20
21
|
if (!request || request.reset) {
|
|
21
22
|
this.prevRequest = {};
|
package/lib/types/adapter.d.ts
CHANGED
|
@@ -46,5 +46,8 @@ export interface IAdapter extends EventEmitter, IBike, ISensor {
|
|
|
46
46
|
resume(): Promise<boolean>;
|
|
47
47
|
connect(): Promise<boolean>;
|
|
48
48
|
close(): Promise<boolean>;
|
|
49
|
+
resetData(): void;
|
|
50
|
+
onScanStart(): void;
|
|
51
|
+
onScanStop(): void;
|
|
49
52
|
onData(callback: OnDeviceDataCallback): any;
|
|
50
53
|
}
|
package/lib/types/interface.d.ts
CHANGED
package/lib/utils/task.d.ts
CHANGED
|
@@ -30,15 +30,18 @@ export declare class InteruptableTask<T extends TaskState, P> {
|
|
|
30
30
|
protected props?: TaskProps<T, P>;
|
|
31
31
|
protected internalEvents: EventEmitter<[never]>;
|
|
32
32
|
protected promise?: Promise<P>;
|
|
33
|
+
protected onStopNotifiers: Array<() => void>;
|
|
33
34
|
constructor(promise: Promise<any>, props?: TaskProps<T, P>);
|
|
34
35
|
getPromise(): Promise<P>;
|
|
35
36
|
getState(): T;
|
|
36
37
|
run(): Promise<P>;
|
|
38
|
+
notifyOnStop(cb: () => void): void;
|
|
37
39
|
start(): void;
|
|
38
40
|
stop(): Promise<boolean>;
|
|
39
41
|
isRunning(): boolean;
|
|
40
42
|
protected clearTimeout(): void;
|
|
41
43
|
protected onTimeout(): void;
|
|
44
|
+
protected sendStopNotification(): void;
|
|
42
45
|
protected logEvent(event: any): void;
|
|
43
46
|
}
|
|
44
47
|
export {};
|
package/lib/utils/task.js
CHANGED
|
@@ -20,6 +20,7 @@ class InteruptableTask {
|
|
|
20
20
|
var _a;
|
|
21
21
|
this.internalState = { isRunning: false };
|
|
22
22
|
this.internalEvents = new events_1.default();
|
|
23
|
+
this.onStopNotifiers = [];
|
|
23
24
|
this.state = ((_a = props === null || props === void 0 ? void 0 : props.state) !== null && _a !== void 0 ? _a : {});
|
|
24
25
|
this.props = props;
|
|
25
26
|
delete this.props.state;
|
|
@@ -39,6 +40,9 @@ class InteruptableTask {
|
|
|
39
40
|
return this.internalState.promise;
|
|
40
41
|
});
|
|
41
42
|
}
|
|
43
|
+
notifyOnStop(cb) {
|
|
44
|
+
this.onStopNotifiers.push(cb);
|
|
45
|
+
}
|
|
42
46
|
start() {
|
|
43
47
|
this.internalState.promise = new Promise((resolve, reject) => {
|
|
44
48
|
var _a;
|
|
@@ -59,8 +63,10 @@ class InteruptableTask {
|
|
|
59
63
|
isRunning: false,
|
|
60
64
|
};
|
|
61
65
|
this.internalEvents.removeAllListeners();
|
|
66
|
+
this.sendStopNotification();
|
|
62
67
|
if (this.getState().result === 'completed' || this.getState().result === 'error')
|
|
63
68
|
return;
|
|
69
|
+
this.getState().result = 'stopped';
|
|
64
70
|
if (this.props.onDone)
|
|
65
71
|
resolve(this.props.onDone(this.getState()));
|
|
66
72
|
else
|
|
@@ -119,6 +125,12 @@ class InteruptableTask {
|
|
|
119
125
|
else
|
|
120
126
|
resolve(null);
|
|
121
127
|
}
|
|
128
|
+
sendStopNotification() {
|
|
129
|
+
this.onStopNotifiers.forEach((cb) => {
|
|
130
|
+
if (typeof cb === 'function')
|
|
131
|
+
cb();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
122
134
|
logEvent(event) {
|
|
123
135
|
if (this.props.log)
|
|
124
136
|
this.props.log(event);
|