incyclist-devices 2.3.0-beta.10 → 2.3.0-beta.11
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/base/sensor.js +16 -2
- package/lib/ble/fm/sensor.js +6 -5
- package/lib/ble/tacx/sensor.js +8 -2
- package/lib/direct-connect/base/peripheral.d.ts +3 -3
- package/lib/direct-connect/base/peripheral.js +11 -7
- package/lib/modes/ant-fe-adv-st-mode.d.ts +1 -1
- package/lib/modes/ant-fe-adv-st-mode.js +5 -3
- package/package.json +1 -1
package/lib/ble/base/sensor.js
CHANGED
|
@@ -101,11 +101,19 @@ class TBleSensor extends events_1.default {
|
|
|
101
101
|
}
|
|
102
102
|
reconnectSensor() {
|
|
103
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
let connected = false;
|
|
105
|
+
let subscribed = false;
|
|
104
106
|
let success = false;
|
|
105
107
|
do {
|
|
106
|
-
|
|
108
|
+
if (!connected) {
|
|
109
|
+
connected = yield this.startSensor(true);
|
|
110
|
+
}
|
|
111
|
+
if (connected && !subscribed) {
|
|
112
|
+
subscribed = yield this.subscribe();
|
|
113
|
+
}
|
|
114
|
+
success = connected && subscribed;
|
|
107
115
|
if (!success) {
|
|
108
|
-
yield (0, utils_1.sleep)(
|
|
116
|
+
yield (0, utils_1.sleep)(1000);
|
|
109
117
|
}
|
|
110
118
|
} while (!success || this.stopRequested);
|
|
111
119
|
});
|
|
@@ -119,10 +127,16 @@ class TBleSensor extends events_1.default {
|
|
|
119
127
|
}
|
|
120
128
|
read(characteristicUUID) {
|
|
121
129
|
var _a;
|
|
130
|
+
if (!this.isConnected()) {
|
|
131
|
+
return Promise.reject(new Error('not connected'));
|
|
132
|
+
}
|
|
122
133
|
return (_a = this.peripheral) === null || _a === void 0 ? void 0 : _a.read(characteristicUUID);
|
|
123
134
|
}
|
|
124
135
|
write(characteristicUUID, data, options) {
|
|
125
136
|
var _a;
|
|
137
|
+
if (!this.isConnected()) {
|
|
138
|
+
return Promise.reject(new Error('not connected'));
|
|
139
|
+
}
|
|
126
140
|
return (_a = this.peripheral) === null || _a === void 0 ? void 0 : _a.write(characteristicUUID, data, options);
|
|
127
141
|
}
|
|
128
142
|
onData(characteristic, data) {
|
package/lib/ble/fm/sensor.js
CHANGED
|
@@ -100,8 +100,6 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
|
|
|
100
100
|
this.logEvent({ message: 'setTargetPower', power, skip: (this.data.targetPower !== undefined && this.data.targetPower === power) });
|
|
101
101
|
if (this.data.targetPower !== undefined && this.data.targetPower === power)
|
|
102
102
|
return true;
|
|
103
|
-
if (!this.hasControl)
|
|
104
|
-
return;
|
|
105
103
|
const hasControl = yield this.requestControl();
|
|
106
104
|
if (!hasControl) {
|
|
107
105
|
this.logEvent({ message: 'setTargetPower failed', reason: 'control is disabled' });
|
|
@@ -111,15 +109,15 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
|
|
|
111
109
|
data.writeUInt8(5, 0);
|
|
112
110
|
data.writeInt16LE(Math.round(power), 1);
|
|
113
111
|
const res = yield this.writeFtmsMessage(5, data);
|
|
112
|
+
if (res === 5) {
|
|
113
|
+
this.hasControl = false;
|
|
114
|
+
}
|
|
114
115
|
return (res === 1);
|
|
115
116
|
});
|
|
116
117
|
}
|
|
117
118
|
setSlope(slope) {
|
|
118
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
120
|
this.logEvent({ message: 'setSlope', slope });
|
|
120
|
-
const hasControl = yield this.requestControl();
|
|
121
|
-
if (!hasControl)
|
|
122
|
-
return;
|
|
123
121
|
const { windSpeed, crr, cw } = this;
|
|
124
122
|
return yield this.setIndoorBikeSimulation(windSpeed, slope, crr, cw);
|
|
125
123
|
});
|
|
@@ -331,6 +329,9 @@ class BleFitnessMachineDevice extends sensor_1.TBleSensor {
|
|
|
331
329
|
data.writeUInt8(Math.round(crr * 10000), 5);
|
|
332
330
|
data.writeUInt8(Math.round(cw * 100), 6);
|
|
333
331
|
const res = yield this.writeFtmsMessage(17, data);
|
|
332
|
+
if (res === 5) {
|
|
333
|
+
this.hasControl = false;
|
|
334
|
+
}
|
|
334
335
|
return (res === 1);
|
|
335
336
|
});
|
|
336
337
|
}
|
package/lib/ble/tacx/sensor.js
CHANGED
|
@@ -452,8 +452,14 @@ class TacxAdvancedFitnessMachineDevice extends sensor_1.default {
|
|
|
452
452
|
sendMessage(message) {
|
|
453
453
|
return __awaiter(this, void 0, void 0, function* () {
|
|
454
454
|
this.logEvent({ message: 'write', characteristic: this.tacxTx, data: message.toString('hex') });
|
|
455
|
-
|
|
456
|
-
|
|
455
|
+
try {
|
|
456
|
+
yield this.write(this.tacxTx, message, { withoutResponse: true });
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
catch (err) {
|
|
460
|
+
this.logEvent({ message: 'write failed', characteristic: this.tacxTx, reason: err.message });
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
457
463
|
});
|
|
458
464
|
}
|
|
459
465
|
sendUserConfiguration(userWeight, bikeWeight, wheelDiameter, gearRatio) {
|
|
@@ -21,7 +21,7 @@ export declare class DirectConnectPeripheral implements IBlePeripheral {
|
|
|
21
21
|
constructor(announcement: MulticastDnsAnnouncement);
|
|
22
22
|
get services(): BleService[];
|
|
23
23
|
connect(): Promise<boolean>;
|
|
24
|
-
disconnect(): Promise<boolean>;
|
|
24
|
+
disconnect(connectionLost?: boolean): Promise<boolean>;
|
|
25
25
|
isConnected(): boolean;
|
|
26
26
|
isConnecting(): boolean;
|
|
27
27
|
onDisconnect(callback: () => void): void;
|
|
@@ -31,14 +31,14 @@ export declare class DirectConnectPeripheral implements IBlePeripheral {
|
|
|
31
31
|
unsubscribe(characteristicUUID: string): Promise<boolean>;
|
|
32
32
|
subscribeAll(callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
|
|
33
33
|
subscribeSelected(characteristics: string[], callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
|
|
34
|
-
unsubscribeAll(): Promise<
|
|
34
|
+
unsubscribeAll(connectionLost?: boolean): Promise<void>;
|
|
35
35
|
read(characteristicUUID: string): Promise<Buffer>;
|
|
36
36
|
write(characteristicUUID: string, data: Buffer, options?: BleWriteProps): Promise<Buffer>;
|
|
37
37
|
protected startConnection(): Promise<boolean>;
|
|
38
38
|
protected onPortError(err: Error): void;
|
|
39
39
|
protected onPortClose(): Promise<void>;
|
|
40
40
|
protected getPath(): string;
|
|
41
|
-
protected stopConnection(): Promise<boolean>;
|
|
41
|
+
protected stopConnection(connectionLost?: boolean): Promise<boolean>;
|
|
42
42
|
protected getNextSeqNo(): number;
|
|
43
43
|
protected send(seqNo: number, data: Buffer): Promise<Buffer>;
|
|
44
44
|
protected getNextMessage(data: Buffer): Buffer;
|
|
@@ -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) {
|
|
@@ -285,13 +285,16 @@ class DirectConnectPeripheral {
|
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
287
|
unsubscribeAll() {
|
|
288
|
-
return __awaiter(this,
|
|
288
|
+
return __awaiter(this, arguments, void 0, function* (connectionLost = false) {
|
|
289
|
+
if (connectionLost) {
|
|
290
|
+
this.subscribed = [];
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
289
293
|
const promises = [];
|
|
290
294
|
this.subscribed.forEach(characteristicUUID => {
|
|
291
295
|
promises.push(this.unsubscribe((0, utils_1.parseUUID)(characteristicUUID)));
|
|
292
296
|
});
|
|
293
297
|
yield Promise.allSettled(promises);
|
|
294
|
-
return true;
|
|
295
298
|
});
|
|
296
299
|
}
|
|
297
300
|
read(characteristicUUID) {
|
|
@@ -397,9 +400,10 @@ class DirectConnectPeripheral {
|
|
|
397
400
|
onPortClose() {
|
|
398
401
|
return __awaiter(this, void 0, void 0, function* () {
|
|
399
402
|
this.socket.removeAllListeners();
|
|
403
|
+
this.socket.on('error', () => { });
|
|
400
404
|
this.logEvent({ message: 'port closed', path: this.getPath() });
|
|
401
405
|
try {
|
|
402
|
-
yield this.disconnect();
|
|
406
|
+
yield this.disconnect(true);
|
|
403
407
|
}
|
|
404
408
|
catch (_a) { }
|
|
405
409
|
if (this.onDisconnectHandler)
|
|
@@ -412,11 +416,11 @@ class DirectConnectPeripheral {
|
|
|
412
416
|
return path;
|
|
413
417
|
}
|
|
414
418
|
stopConnection() {
|
|
415
|
-
return __awaiter(this,
|
|
419
|
+
return __awaiter(this, arguments, void 0, function* (connectionLost = false) {
|
|
416
420
|
this.eventEmitter.removeAllListeners();
|
|
417
421
|
if (!this.isConnected())
|
|
418
422
|
return true;
|
|
419
|
-
yield this.unsubscribeAll();
|
|
423
|
+
yield this.unsubscribeAll(connectionLost);
|
|
420
424
|
this.socket.removeAllListeners();
|
|
421
425
|
return new Promise(done => {
|
|
422
426
|
const onClosed = () => {
|
|
@@ -3,8 +3,8 @@ 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(): import("./types").CyclingModeConfig;
|
|
8
8
|
checkForResetOrEmpty(request: UpdateRequest): UpdateRequest | undefined;
|
|
9
9
|
protected checkForTempPowerAdjustments(request: UpdateRequest, newRequest?: UpdateRequest): void;
|
|
10
10
|
protected checkEmptyRequest(newRequest: UpdateRequest): void;
|
|
@@ -10,12 +10,14 @@ 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
|
+
config.name = 'Advanced Smart Trainer';
|
|
19
|
+
return config;
|
|
20
|
+
}
|
|
19
21
|
checkForResetOrEmpty(request) {
|
|
20
22
|
if (!request || request.reset) {
|
|
21
23
|
this.prevRequest = {};
|