incyclist-devices 1.4.76 → 1.4.77
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/lib/ble/ble-interface.js +5 -4
- package/lib/ble/ble-peripheral.js +8 -10
- package/lib/ble/ble.js +1 -1
- package/lib/ble/tacx.d.ts +1 -0
- package/lib/ble/tacx.js +43 -13
- package/package.json +1 -1
package/lib/ble/ble-interface.js
CHANGED
|
@@ -55,9 +55,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
55
55
|
if (this.logger) {
|
|
56
56
|
this.logger.logEvent(event);
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
console.log('~~BLE:', event);
|
|
60
|
-
}
|
|
58
|
+
console.log('~~BLE:', event);
|
|
61
59
|
}
|
|
62
60
|
onStateChange(state) {
|
|
63
61
|
if (state !== ble_1.BleState.POWERED_ON) {
|
|
@@ -583,9 +581,12 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
583
581
|
if (scanForDevice && cntFound > 0)
|
|
584
582
|
return;
|
|
585
583
|
const d = this.createDevice(DeviceClass, peripheral, characteristics);
|
|
586
|
-
if (!d)
|
|
584
|
+
if (!d) {
|
|
585
|
+
this.logEvent({ message: `${opStr}: could not create device `, DeviceClass });
|
|
587
586
|
return;
|
|
587
|
+
}
|
|
588
588
|
try {
|
|
589
|
+
this.logEvent({ message: `${opStr}: connecting `, device: d.name, profile: d.getProfile(), address: d.address });
|
|
589
590
|
yield d.connect();
|
|
590
591
|
}
|
|
591
592
|
catch (err) {
|
|
@@ -31,9 +31,7 @@ class BlePeripheralConnector {
|
|
|
31
31
|
if (this.logger) {
|
|
32
32
|
this.logger.logEvent(event);
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
console.log('~~~BLE:', event);
|
|
36
|
-
}
|
|
34
|
+
console.log('~~~BLE:', event);
|
|
37
35
|
}
|
|
38
36
|
connect() {
|
|
39
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -132,15 +130,15 @@ class BlePeripheralConnector {
|
|
|
132
130
|
this.logEvent({ message: 'subscribe', characteristic: characteristicUuid, characteristics: this.characteristics.map(c => ({ characteristic: c.uuid, uuid: (0, ble_1.uuid)(c.uuid) })) });
|
|
133
131
|
return new Promise((resolve, reject) => {
|
|
134
132
|
try {
|
|
135
|
-
const characteristic = this.characteristics.find(c => c.uuid === characteristicUuid || (0, ble_1.uuid)(c.uuid) === characteristicUuid);
|
|
136
|
-
this.logEvent({ message: 'subscribe', peripheral: this.peripheral.address, characteristic: characteristic.uuid, uuid: (0, ble_1.uuid)(characteristic.uuid) });
|
|
133
|
+
const characteristic = this.characteristics.find(c => (0, ble_1.uuid)(c.uuid) === (0, ble_1.uuid)(characteristicUuid) || (0, ble_1.uuid)(c.uuid) === (0, ble_1.uuid)(characteristicUuid));
|
|
137
134
|
if (!characteristic) {
|
|
138
135
|
reject(new Error('Characteristic not found'));
|
|
139
136
|
return;
|
|
140
137
|
}
|
|
138
|
+
this.logEvent({ message: 'subscribe', peripheral: this.peripheral.address, characteristic: characteristic.uuid, uuid: (0, ble_1.uuid)(characteristic.uuid) });
|
|
141
139
|
characteristic.removeAllListeners('data');
|
|
142
140
|
characteristic.on('data', (data, _isNotification) => {
|
|
143
|
-
this.onData(characteristicUuid, data);
|
|
141
|
+
this.onData((0, ble_1.uuid)(characteristicUuid), data);
|
|
144
142
|
});
|
|
145
143
|
const to = setTimeout(() => {
|
|
146
144
|
this.logEvent({ message: 'subscribe result', characteristic: characteristicUuid, error: 'timeout' });
|
|
@@ -163,18 +161,18 @@ class BlePeripheralConnector {
|
|
|
163
161
|
});
|
|
164
162
|
}
|
|
165
163
|
onData(characteristicUuid, data) {
|
|
166
|
-
this.emitter.emit(characteristicUuid, characteristicUuid, data);
|
|
164
|
+
this.emitter.emit((0, ble_1.uuid)(characteristicUuid), characteristicUuid, data);
|
|
167
165
|
}
|
|
168
166
|
on(characteristicUuid, callback) {
|
|
169
167
|
if (callback)
|
|
170
|
-
this.emitter.on(characteristicUuid, callback);
|
|
168
|
+
this.emitter.on((0, ble_1.uuid)(characteristicUuid), callback);
|
|
171
169
|
}
|
|
172
170
|
off(characteristicUuid, callback) {
|
|
173
171
|
if (callback)
|
|
174
|
-
this.emitter.off(characteristicUuid, callback);
|
|
172
|
+
this.emitter.off((0, ble_1.uuid)(characteristicUuid), callback);
|
|
175
173
|
}
|
|
176
174
|
removeAllListeners(characteristicUuid) {
|
|
177
|
-
this.emitter.removeAllListeners(characteristicUuid);
|
|
175
|
+
this.emitter.removeAllListeners((0, ble_1.uuid)(characteristicUuid));
|
|
178
176
|
}
|
|
179
177
|
getState() {
|
|
180
178
|
return this.peripheral.state;
|
package/lib/ble/ble.js
CHANGED
package/lib/ble/tacx.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export default class TacxAdvancedFitnessMachineDevice extends BleFitnessMachineD
|
|
|
47
47
|
rpm: number;
|
|
48
48
|
time: any;
|
|
49
49
|
};
|
|
50
|
+
parseCSC(_data: Buffer): IndoorBikeData;
|
|
50
51
|
parsePower(_data: Buffer): IndoorBikeData;
|
|
51
52
|
resetState(): void;
|
|
52
53
|
parseFEState(capStateBF: number): void;
|
package/lib/ble/tacx.js
CHANGED
|
@@ -150,7 +150,29 @@ class TacxAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
150
150
|
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
151
151
|
return { rpm, time: this.timeOffset + c.time };
|
|
152
152
|
}
|
|
153
|
+
parseCSC(_data) {
|
|
154
|
+
this.logEvent({ message: 'BLE CSC message', data: _data.toString('hex') });
|
|
155
|
+
const data = Buffer.from(_data);
|
|
156
|
+
let offset = 0;
|
|
157
|
+
const flags = data.readUInt8(offset);
|
|
158
|
+
offset++;
|
|
159
|
+
if (flags & 0x01) {
|
|
160
|
+
offset += 6;
|
|
161
|
+
}
|
|
162
|
+
if (flags & 0x02) {
|
|
163
|
+
const crankData = {
|
|
164
|
+
revolutions: data.readUInt16LE(offset),
|
|
165
|
+
time: data.readUInt16LE(offset + 2)
|
|
166
|
+
};
|
|
167
|
+
const { rpm, time } = this.parseCrankData(crankData);
|
|
168
|
+
this.data.cadence = rpm;
|
|
169
|
+
this.data.time = time;
|
|
170
|
+
offset += 4;
|
|
171
|
+
}
|
|
172
|
+
return this.data;
|
|
173
|
+
}
|
|
153
174
|
parsePower(_data) {
|
|
175
|
+
this.logEvent({ message: 'BLE CSP message', data: _data.toString('hex') });
|
|
154
176
|
const data = Buffer.from(_data);
|
|
155
177
|
try {
|
|
156
178
|
let offset = 4;
|
|
@@ -174,6 +196,7 @@ class TacxAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
174
196
|
}
|
|
175
197
|
}
|
|
176
198
|
catch (err) {
|
|
199
|
+
this.logEvent({ message: 'error', fn: 'parsePower()', error: err.message || err, stack: err.stack });
|
|
177
200
|
}
|
|
178
201
|
const { instantaneousPower, cadence, time } = this.data;
|
|
179
202
|
return { instantaneousPower, cadence, time, raw: data.toString('hex') };
|
|
@@ -374,25 +397,29 @@ class TacxAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
374
397
|
}
|
|
375
398
|
const len = data.readUInt8(1);
|
|
376
399
|
const messageId = data.readUInt8(4);
|
|
377
|
-
this.hasFECData = true;
|
|
378
400
|
let res;
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
401
|
+
try {
|
|
402
|
+
switch (messageId) {
|
|
403
|
+
case ANTMessages.generalFE:
|
|
404
|
+
res = this.parseGeneralFE(data.slice(4, len + 3));
|
|
405
|
+
break;
|
|
406
|
+
case ANTMessages.trainerData:
|
|
407
|
+
res = this.parseTrainerData(data.slice(4, len + 3));
|
|
408
|
+
break;
|
|
409
|
+
case ANTMessages.productInformation:
|
|
410
|
+
res = this.parseProductInformation(data.slice(4, len + 3));
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
if (res)
|
|
414
|
+
res.raw = data.toString('hex');
|
|
415
|
+
}
|
|
416
|
+
catch (err) {
|
|
417
|
+
this.logEvent({ message: 'error', fn: 'parseFECMessage()', error: err.message || err, stack: err.stack });
|
|
389
418
|
}
|
|
390
|
-
res.raw = data.toString('hex');
|
|
391
419
|
return res;
|
|
392
420
|
}
|
|
393
421
|
onData(characteristic, data) {
|
|
394
422
|
try {
|
|
395
|
-
super.onData(characteristic, data);
|
|
396
423
|
const uuid = characteristic.toLocaleLowerCase();
|
|
397
424
|
let res = undefined;
|
|
398
425
|
if (uuid && uuid.startsWith(TACX_FE_C_RX)) {
|
|
@@ -411,6 +438,9 @@ class TacxAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
411
438
|
case '2a37':
|
|
412
439
|
res = this.parseHrm(data);
|
|
413
440
|
break;
|
|
441
|
+
case '2a5b':
|
|
442
|
+
res = this.parseCSC(data);
|
|
443
|
+
break;
|
|
414
444
|
case '2ada':
|
|
415
445
|
if (!this.hasFECData)
|
|
416
446
|
res = this.parseFitnessMachineStatus(data);
|