incyclist-devices 1.4.66 → 1.4.67
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-device.d.ts +1 -0
- package/lib/ble/ble-device.js +3 -1
- package/lib/ble/ble-interface.d.ts +1 -0
- package/lib/ble/ble-interface.js +32 -15
- package/lib/ble/fm.d.ts +1 -0
- package/lib/ble/fm.js +13 -3
- package/lib/ble/pwr.d.ts +1 -0
- package/lib/ble/pwr.js +11 -2
- package/lib/ble/wahoo-kickr.d.ts +1 -0
- package/lib/ble/wahoo-kickr.js +7 -1
- package/package.json +1 -1
package/lib/ble/ble-device.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare abstract class BleDevice extends BleDeviceClass {
|
|
|
30
30
|
logEvent(event: any): void;
|
|
31
31
|
setLogger(logger: EventLogger): void;
|
|
32
32
|
setInterface(ble: BleInterfaceClass): void;
|
|
33
|
+
isMatching(characteristics: string[]): boolean;
|
|
33
34
|
cleanupListeners(): void;
|
|
34
35
|
onDisconnect(): void;
|
|
35
36
|
waitForConnectFinished(timeout: any): Promise<unknown>;
|
package/lib/ble/ble-device.js
CHANGED
|
@@ -57,6 +57,9 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
57
57
|
setInterface(ble) {
|
|
58
58
|
this.ble = ble;
|
|
59
59
|
}
|
|
60
|
+
isMatching(characteristics) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
60
63
|
cleanupListeners() {
|
|
61
64
|
if (this.characteristics === undefined) {
|
|
62
65
|
this.characteristics = [];
|
|
@@ -283,7 +286,6 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
283
286
|
let messageDeleted = false;
|
|
284
287
|
this.writeQueue.push({ uuid: characteristicUuid.toLocaleLowerCase(), data, resolve, reject });
|
|
285
288
|
const to = setTimeout(() => {
|
|
286
|
-
console.log('~~~ write timeout');
|
|
287
289
|
if (this.writeQueue.length > writeId && !messageDeleted)
|
|
288
290
|
this.writeQueue.splice(writeId, 1);
|
|
289
291
|
this.logEvent({ message: 'writing response', err: 'timeout' });
|
|
@@ -77,6 +77,7 @@ export default class BleInterface extends BleInterfaceClass {
|
|
|
77
77
|
getDeviceClasses(peripheral: any, props?: {
|
|
78
78
|
deviceTypes?: (typeof BleDeviceClass)[];
|
|
79
79
|
profile?: string;
|
|
80
|
+
services?: string[];
|
|
80
81
|
}): (typeof BleDeviceClass)[];
|
|
81
82
|
createDevice(DeviceClass: (typeof BleDeviceClass), peripheral: BlePeripheral, characteristics?: BleCharacteristic[]): any;
|
|
82
83
|
connectDevice(requested: BleDeviceClass | BleDeviceDescription, timeout?: number): Promise<BleDeviceClass>;
|
package/lib/ble/ble-interface.js
CHANGED
|
@@ -55,7 +55,9 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
55
55
|
if (this.logger) {
|
|
56
56
|
this.logger.logEvent(event);
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
if (process.env.BLE_DEBUG) {
|
|
59
|
+
console.log('~~BLE:', event);
|
|
60
|
+
}
|
|
59
61
|
}
|
|
60
62
|
onStateChange(state) {
|
|
61
63
|
if (state !== ble_1.BleState.POWERED_ON) {
|
|
@@ -334,13 +336,13 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
334
336
|
}
|
|
335
337
|
getDeviceClasses(peripheral, props = {}) {
|
|
336
338
|
let DeviceClasses;
|
|
337
|
-
const { deviceTypes, profile } = props;
|
|
339
|
+
const { deviceTypes, profile, services = peripheral.advertisement.serviceUuids } = props;
|
|
338
340
|
if ((!deviceTypes || deviceTypes.length === 0)) {
|
|
339
341
|
const classes = BleInterface.deviceClasses.map(c => c.Class);
|
|
340
|
-
DeviceClasses = this.getDevicesFromServices(classes,
|
|
342
|
+
DeviceClasses = this.getDevicesFromServices(classes, services);
|
|
341
343
|
}
|
|
342
344
|
else {
|
|
343
|
-
DeviceClasses = this.getDevicesFromServices(deviceTypes,
|
|
345
|
+
DeviceClasses = this.getDevicesFromServices(deviceTypes, services);
|
|
344
346
|
}
|
|
345
347
|
if (profile && DeviceClasses && DeviceClasses.length > 0) {
|
|
346
348
|
DeviceClasses = DeviceClasses.filter(C => {
|
|
@@ -353,15 +355,26 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
353
355
|
return DeviceClasses;
|
|
354
356
|
}
|
|
355
357
|
createDevice(DeviceClass, peripheral, characteristics) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
358
|
+
try {
|
|
359
|
+
const C = DeviceClass;
|
|
360
|
+
const device = new C({ peripheral });
|
|
361
|
+
const cids = characteristics ? characteristics.map(c => (0, ble_1.uuid)(c.uuid)) : [];
|
|
362
|
+
this.logEvent({ message: 'trying to create device', peripheral: peripheral.address, characteristics: cids, profile: device.getProfile() });
|
|
363
|
+
const existingDevice = this.devices.find(i => i.device.id === device.id && i.device.getProfile() === device.getProfile());
|
|
364
|
+
if (existingDevice)
|
|
365
|
+
return existingDevice;
|
|
366
|
+
device.setInterface(this);
|
|
367
|
+
if (characteristics && device.isMatching(cids)) {
|
|
368
|
+
device.characteristics = characteristics;
|
|
369
|
+
return device;
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this.logEvent({ message: 'failed to create device', peripheral: peripheral.address, profile: device.getProfile() });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
catch (err) {
|
|
376
|
+
this.logEvent({ message: 'error', fn: '', error: err.message || err, stack: err.stack });
|
|
377
|
+
}
|
|
365
378
|
}
|
|
366
379
|
connectDevice(requested, timeout = DEFAULT_SCAN_TIMEOUT + CONNECT_TIMEOUT) {
|
|
367
380
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -551,10 +564,12 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
551
564
|
peripheralsProcessed.push(peripheral.address);
|
|
552
565
|
const characteristics = yield this.getCharacteristics(peripheral);
|
|
553
566
|
const connector = this.getConnector(peripheral);
|
|
567
|
+
const connectedServices = connector.getServices();
|
|
568
|
+
const services = connectedServices ? connectedServices.map(cs => cs.uuid) : undefined;
|
|
554
569
|
const connectedPeripheral = connector.getPeripheral();
|
|
555
570
|
const { id, name, address, advertisement = {} } = connectedPeripheral;
|
|
556
|
-
const DeviceClasses = this.getDeviceClasses(connectedPeripheral, { profile });
|
|
557
|
-
this.logEvent({ message: 'BLE scan: device connected', peripheral: { id, name, address, services: advertisement.serviceUuids, classes: DeviceClasses.map(c => c.prototype.constructor.name) }
|
|
571
|
+
const DeviceClasses = this.getDeviceClasses(connectedPeripheral, { profile, services });
|
|
572
|
+
this.logEvent({ message: 'BLE scan: device connected', peripheral: { id, name, address, services: advertisement.serviceUuids }, services, classes: DeviceClasses.map(c => c.prototype.constructor.name) });
|
|
558
573
|
let cntFound = 0;
|
|
559
574
|
DeviceClasses.forEach((DeviceClass) => __awaiter(this, void 0, void 0, function* () {
|
|
560
575
|
if (!DeviceClass)
|
|
@@ -562,6 +577,8 @@ class BleInterface extends ble_1.BleInterfaceClass {
|
|
|
562
577
|
if (scanForDevice && cntFound > 0)
|
|
563
578
|
return;
|
|
564
579
|
const d = this.createDevice(DeviceClass, peripheral, characteristics);
|
|
580
|
+
if (!d)
|
|
581
|
+
return;
|
|
565
582
|
yield d.connect();
|
|
566
583
|
if (scanForDevice) {
|
|
567
584
|
if ((id && id !== '' && d.id === id) ||
|
package/lib/ble/fm.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export default class BleFitnessMachineDevice extends BleDevice {
|
|
|
52
52
|
windSpeed: number;
|
|
53
53
|
wheelSize: number;
|
|
54
54
|
constructor(props?: any);
|
|
55
|
+
isMatching(characteristics: string[]): boolean;
|
|
55
56
|
init(): Promise<boolean>;
|
|
56
57
|
onDisconnect(): void;
|
|
57
58
|
getProfile(): string;
|
package/lib/ble/fm.js
CHANGED
|
@@ -21,6 +21,8 @@ const power_meter_1 = __importDefault(require("../modes/power-meter"));
|
|
|
21
21
|
const ble_st_mode_1 = __importDefault(require("./ble-st-mode"));
|
|
22
22
|
const ble_erg_mode_1 = __importDefault(require("./ble-erg-mode"));
|
|
23
23
|
const FTMS_CP = '2ad9';
|
|
24
|
+
const FTMS_STATUS = '2ada';
|
|
25
|
+
const INDOOR_BIKE_DATA = '2ad2';
|
|
24
26
|
const cwABike = {
|
|
25
27
|
race: 0.35,
|
|
26
28
|
triathlon: 0.29,
|
|
@@ -94,6 +96,14 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
|
|
|
94
96
|
this.wheelSize = 2100;
|
|
95
97
|
this.data = {};
|
|
96
98
|
}
|
|
99
|
+
isMatching(characteristics) {
|
|
100
|
+
if (!characteristics)
|
|
101
|
+
return false;
|
|
102
|
+
const hasStatus = characteristics.find(c => c === FTMS_STATUS) !== undefined;
|
|
103
|
+
const hasCP = characteristics.find(c => c === FTMS_CP) !== undefined;
|
|
104
|
+
const hasIndoorBike = characteristics.find(c => c === INDOOR_BIKE_DATA) !== undefined;
|
|
105
|
+
return hasStatus && hasCP && hasIndoorBike;
|
|
106
|
+
}
|
|
97
107
|
init() {
|
|
98
108
|
const _super = Object.create(null, {
|
|
99
109
|
init: { get: () => super.init }
|
|
@@ -295,13 +305,13 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
|
|
|
295
305
|
const uuid = characteristic.toLocaleLowerCase();
|
|
296
306
|
let res = undefined;
|
|
297
307
|
switch (uuid) {
|
|
298
|
-
case
|
|
308
|
+
case INDOOR_BIKE_DATA:
|
|
299
309
|
res = this.parseIndoorBikeData(data);
|
|
300
310
|
break;
|
|
301
311
|
case '2a37':
|
|
302
312
|
res = this.parseHrm(data);
|
|
303
313
|
break;
|
|
304
|
-
case
|
|
314
|
+
case FTMS_STATUS:
|
|
305
315
|
res = this.parseFitnessMachineStatus(data);
|
|
306
316
|
break;
|
|
307
317
|
case '2a63':
|
|
@@ -469,7 +479,7 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
|
|
|
469
479
|
}
|
|
470
480
|
exports.default = BleFitnessMachineDevice;
|
|
471
481
|
BleFitnessMachineDevice.services = ['1826'];
|
|
472
|
-
BleFitnessMachineDevice.characteristics = ['2acc',
|
|
482
|
+
BleFitnessMachineDevice.characteristics = ['2acc', INDOOR_BIKE_DATA, '2ad6', '2ad8', FTMS_CP, FTMS_STATUS];
|
|
473
483
|
ble_interface_1.default.register('BleFitnessMachineDevice', 'fm', BleFitnessMachineDevice, BleFitnessMachineDevice.services);
|
|
474
484
|
class FmAdapter extends Device_1.default {
|
|
475
485
|
constructor(device, protocol) {
|
package/lib/ble/pwr.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export default class BleCyclingPowerDevice extends BleDevice {
|
|
|
33
33
|
currentCrankData: CrankData;
|
|
34
34
|
prevCrankData: CrankData;
|
|
35
35
|
constructor(props?: any);
|
|
36
|
+
isMatching(characteristics: string[]): boolean;
|
|
36
37
|
init(): Promise<boolean>;
|
|
37
38
|
getProfile(): string;
|
|
38
39
|
getServiceUUids(): string[];
|
package/lib/ble/pwr.js
CHANGED
|
@@ -37,6 +37,8 @@ const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
|
37
37
|
const Device_1 = __importStar(require("../Device"));
|
|
38
38
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
39
39
|
const power_meter_1 = __importDefault(require("../modes/power-meter"));
|
|
40
|
+
const CP_MEASUREMENT = '2a63';
|
|
41
|
+
const CP_FEATURE = '2a65';
|
|
40
42
|
class BleCyclingPowerDevice extends ble_device_1.BleDevice {
|
|
41
43
|
constructor(props) {
|
|
42
44
|
super(props);
|
|
@@ -49,6 +51,13 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
|
|
|
49
51
|
this.currentCrankData = undefined;
|
|
50
52
|
this.prevCrankData = undefined;
|
|
51
53
|
}
|
|
54
|
+
isMatching(characteristics) {
|
|
55
|
+
if (!characteristics)
|
|
56
|
+
return false;
|
|
57
|
+
const hasCPMeasurement = characteristics.find(c => c === CP_MEASUREMENT) !== undefined;
|
|
58
|
+
const hasCPFeature = characteristics.find(c => c === CP_FEATURE) !== undefined;
|
|
59
|
+
return hasCPMeasurement && hasCPFeature;
|
|
60
|
+
}
|
|
52
61
|
init() {
|
|
53
62
|
const _super = Object.create(null, {
|
|
54
63
|
init: { get: () => super.init }
|
|
@@ -131,7 +140,7 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
|
|
|
131
140
|
}
|
|
132
141
|
onData(characteristic, data) {
|
|
133
142
|
super.onData(characteristic, data);
|
|
134
|
-
if (characteristic.toLocaleLowerCase() ===
|
|
143
|
+
if (characteristic.toLocaleLowerCase() === CP_MEASUREMENT) {
|
|
135
144
|
const res = this.parsePower(data);
|
|
136
145
|
this.emit('data', res);
|
|
137
146
|
}
|
|
@@ -149,7 +158,7 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
|
|
|
149
158
|
}
|
|
150
159
|
exports.default = BleCyclingPowerDevice;
|
|
151
160
|
BleCyclingPowerDevice.services = ['1818'];
|
|
152
|
-
BleCyclingPowerDevice.characteristics = [
|
|
161
|
+
BleCyclingPowerDevice.characteristics = [CP_MEASUREMENT, CP_FEATURE, '2a5d', '2a3c'];
|
|
153
162
|
ble_interface_1.default.register('BleCyclingPowerDevice', 'cp', BleCyclingPowerDevice, BleCyclingPowerDevice.services);
|
|
154
163
|
class PwrAdapter extends Device_1.default {
|
|
155
164
|
constructor(device, protocol) {
|
package/lib/ble/wahoo-kickr.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export default class WahooAdvancedFitnessMachineDevice extends BleFitnessMachine
|
|
|
35
35
|
timeOffset: number;
|
|
36
36
|
tsPrevWrite: any;
|
|
37
37
|
constructor(props?: any);
|
|
38
|
+
isMatching(characteristics: string[]): boolean;
|
|
38
39
|
init(): Promise<boolean>;
|
|
39
40
|
getProfile(): string;
|
|
40
41
|
getServiceUUids(): string[];
|
package/lib/ble/wahoo-kickr.js
CHANGED
|
@@ -54,6 +54,12 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
54
54
|
this.tsPrevWrite = undefined;
|
|
55
55
|
this.data = {};
|
|
56
56
|
}
|
|
57
|
+
isMatching(characteristics) {
|
|
58
|
+
if (!characteristics)
|
|
59
|
+
return false;
|
|
60
|
+
const hasWahooCP = characteristics.find(c => c === WAHOO_ADVANCED_TRAINER_CP) !== undefined;
|
|
61
|
+
return hasWahooCP;
|
|
62
|
+
}
|
|
57
63
|
init() {
|
|
58
64
|
const _super = Object.create(null, {
|
|
59
65
|
init: { get: () => super.init }
|
|
@@ -315,7 +321,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
|
|
|
315
321
|
}
|
|
316
322
|
exports.default = WahooAdvancedFitnessMachineDevice;
|
|
317
323
|
WahooAdvancedFitnessMachineDevice.services = ['a026ee0b'];
|
|
318
|
-
WahooAdvancedFitnessMachineDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada',
|
|
324
|
+
WahooAdvancedFitnessMachineDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada', WAHOO_ADVANCED_TRAINER_CP];
|
|
319
325
|
ble_interface_1.default.register('WahooAdvancedFitnessMachineDevice', 'wahoo-fm', WahooAdvancedFitnessMachineDevice, WahooAdvancedFitnessMachineDevice.services);
|
|
320
326
|
class WahooAdvancedFmAdapter extends fm_1.FmAdapter {
|
|
321
327
|
constructor(device, protocol) {
|