incyclist-devices 1.4.9 → 1.4.12
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/CyclingMode.js +0 -1
- package/lib/Device.d.ts +2 -0
- package/lib/Device.js +2 -0
- package/lib/DeviceProtocol.d.ts +4 -1
- package/lib/DeviceProtocol.js +0 -1
- package/lib/DeviceSupport.d.ts +2 -0
- package/lib/DeviceSupport.js +11 -22
- package/lib/ant/AntAdapter.js +0 -1
- package/lib/ant/AntScanner.js +7 -20
- package/lib/ant/antfe/AntFEAdapter.js +8 -8
- package/lib/ant/anthrm/AntHrmAdapter.js +1 -1
- package/lib/ant/utils.js +1 -3
- package/lib/calculations.js +0 -1
- package/lib/daum/DaumAdapter.js +18 -13
- package/lib/daum/SmartTrainerCyclingMode.js +0 -1
- package/lib/daum/classic/DaumClassicAdapter.js +1 -1
- package/lib/daum/classic/DaumClassicProtocol.js +7 -19
- package/lib/daum/classic/bike.js +26 -26
- package/lib/daum/classic/utils.js +0 -1
- package/lib/daum/constants.js +0 -1
- package/lib/daum/premium/DaumPremiumAdapter.js +1 -1
- package/lib/daum/premium/DaumPremiumProtocol.js +7 -19
- package/lib/daum/premium/bike.js +17 -18
- package/lib/daum/premium/utils.js +0 -1
- package/lib/kettler/comms.d.ts +48 -0
- package/lib/kettler/comms.js +194 -0
- package/lib/kettler/ergo-racer/adapter.d.ts +99 -0
- package/lib/kettler/ergo-racer/adapter.js +659 -0
- package/lib/kettler/ergo-racer/modes/power-meter.d.ts +18 -0
- package/lib/kettler/ergo-racer/modes/power-meter.js +78 -0
- package/lib/kettler/ergo-racer/protocol.d.ts +41 -0
- package/lib/kettler/ergo-racer/protocol.js +191 -0
- package/lib/simulator/Simulator.js +2 -15
- package/lib/types/command.d.ts +8 -0
- package/lib/types/command.js +2 -0
- package/lib/types/route.js +0 -1
- package/lib/types/user.js +0 -1
- package/lib/utils.js +1 -3
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
7
|
+
const CyclingMode_1 = require("../../../CyclingMode");
|
|
8
|
+
const calculations_1 = __importDefault(require("../../../calculations"));
|
|
9
|
+
const config = {
|
|
10
|
+
name: 'PowerMeter',
|
|
11
|
+
description: 'Power and cadence are taken from device. Speed is calculated from power and current slope\nThis mode will not respect maximum power and/or workout limits',
|
|
12
|
+
properties: []
|
|
13
|
+
};
|
|
14
|
+
class PowerMeterCyclingMode extends CyclingMode_1.CyclingModeBase {
|
|
15
|
+
constructor(adapter, props) {
|
|
16
|
+
super(adapter, props);
|
|
17
|
+
this.prevUpdateTS = 0;
|
|
18
|
+
this.hasBikeUpdate = false;
|
|
19
|
+
this.logger = adapter ? adapter.getLogger() : undefined;
|
|
20
|
+
if (!this.logger)
|
|
21
|
+
this.logger = new gd_eventlog_1.EventLogger('PowerMeter');
|
|
22
|
+
}
|
|
23
|
+
getName() {
|
|
24
|
+
return config.name;
|
|
25
|
+
}
|
|
26
|
+
getDescription() {
|
|
27
|
+
return config.description;
|
|
28
|
+
}
|
|
29
|
+
getProperties() {
|
|
30
|
+
return config.properties;
|
|
31
|
+
}
|
|
32
|
+
getProperty(name) {
|
|
33
|
+
return config.properties.find(p => p.name === name);
|
|
34
|
+
}
|
|
35
|
+
getBikeInitRequest() {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
sendBikeUpdate(request) {
|
|
39
|
+
if (request.slope)
|
|
40
|
+
this.data.slope = request.slope;
|
|
41
|
+
this.logger.logEvent({ message: "processing update request", request, prev: this.prevRequest });
|
|
42
|
+
this.prevRequest = {};
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
updateData(data) {
|
|
46
|
+
try {
|
|
47
|
+
const prevData = this.data || {};
|
|
48
|
+
const prevRequest = this.prevRequest || {};
|
|
49
|
+
const bikeData = JSON.parse(JSON.stringify(data));
|
|
50
|
+
let power = data.power || 0;
|
|
51
|
+
let speed = data.speed || 0;
|
|
52
|
+
let slope = (prevData.slope !== undefined ? prevData.slope : prevRequest.slope || 0);
|
|
53
|
+
let distanceInternal = prevData.distanceInternal || 0;
|
|
54
|
+
if (!bikeData.pedalRpm || bikeData.isPedalling === false) {
|
|
55
|
+
speed = 0;
|
|
56
|
+
power = 0;
|
|
57
|
+
}
|
|
58
|
+
let ts = Date.now();
|
|
59
|
+
const m = this.adapter.getWeight();
|
|
60
|
+
speed = calculations_1.default.calculateSpeed(m, power, slope);
|
|
61
|
+
let v = speed / 3.6;
|
|
62
|
+
let duration = this.prevUpdateTS === 0 ? 0 : ((ts - this.prevUpdateTS) / 1000);
|
|
63
|
+
distanceInternal += Math.round(v * duration);
|
|
64
|
+
data.speed = parseFloat(speed.toFixed(1));
|
|
65
|
+
data.power = Math.round(power);
|
|
66
|
+
data.distanceInternal = Math.round(distanceInternal);
|
|
67
|
+
data.slope = slope;
|
|
68
|
+
this.logger.logEvent({ message: "updateData result", data, bikeData, prevRequest: {}, prevSpeed: prevData.speed });
|
|
69
|
+
this.data = JSON.parse(JSON.stringify(data));
|
|
70
|
+
this.prevUpdateTS = ts;
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
this.logger.logEvent({ message: 'error', fn: 'updateData()', error: err.message || err });
|
|
74
|
+
}
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.default = PowerMeterCyclingMode;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import DeviceProtocolBase, { DeviceProtocol, DeviceSettings, ScanProps } from '../../DeviceProtocol';
|
|
3
|
+
import KettlerRacerAdapter from './adapter';
|
|
4
|
+
export interface KettlerRacerScanProps extends ScanProps {
|
|
5
|
+
port: string;
|
|
6
|
+
}
|
|
7
|
+
declare enum ScanState {
|
|
8
|
+
IDLE = 0,
|
|
9
|
+
SCANNING = 1,
|
|
10
|
+
STOPPING = 2,
|
|
11
|
+
STOPPED = 3
|
|
12
|
+
}
|
|
13
|
+
export interface ScanDescription {
|
|
14
|
+
device: KettlerRacerAdapter;
|
|
15
|
+
port: string;
|
|
16
|
+
iv: NodeJS.Timeout;
|
|
17
|
+
state: ScanState;
|
|
18
|
+
props: KettlerRacerScanProps;
|
|
19
|
+
}
|
|
20
|
+
export declare class KettlerRacerProtocol extends DeviceProtocolBase implements DeviceProtocol {
|
|
21
|
+
private state;
|
|
22
|
+
private logger;
|
|
23
|
+
private activeScans;
|
|
24
|
+
constructor();
|
|
25
|
+
getSerialPort(): any;
|
|
26
|
+
getInterfaces(): string[];
|
|
27
|
+
getName(): string;
|
|
28
|
+
isBike(): boolean;
|
|
29
|
+
isHrm(): boolean;
|
|
30
|
+
isPower(): boolean;
|
|
31
|
+
add(settings: DeviceSettings): any;
|
|
32
|
+
scan(props: KettlerRacerScanProps): void;
|
|
33
|
+
checkDevice(port: string): boolean;
|
|
34
|
+
doScan(port: string): Promise<void>;
|
|
35
|
+
doStopScan(job: ScanDescription): Promise<void>;
|
|
36
|
+
isJobStopped(job: ScanDescription): boolean;
|
|
37
|
+
waitForStop(timeout?: number): Promise<boolean>;
|
|
38
|
+
stopScan(): Promise<boolean>;
|
|
39
|
+
isScanning(): boolean;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12
|
+
if (mod && mod.__esModule) return mod;
|
|
13
|
+
var result = {};
|
|
14
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
15
|
+
result["default"] = mod;
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const DeviceProtocol_1 = __importStar(require("../../DeviceProtocol"));
|
|
23
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
24
|
+
const DeviceRegistry_1 = __importDefault(require("../../DeviceRegistry"));
|
|
25
|
+
const adapter_1 = __importDefault(require("./adapter"));
|
|
26
|
+
const PROTOCOL_NAME = 'Kettler Racer';
|
|
27
|
+
var ScanState;
|
|
28
|
+
(function (ScanState) {
|
|
29
|
+
ScanState[ScanState["IDLE"] = 0] = "IDLE";
|
|
30
|
+
ScanState[ScanState["SCANNING"] = 1] = "SCANNING";
|
|
31
|
+
ScanState[ScanState["STOPPING"] = 2] = "STOPPING";
|
|
32
|
+
ScanState[ScanState["STOPPED"] = 3] = "STOPPED";
|
|
33
|
+
})(ScanState || (ScanState = {}));
|
|
34
|
+
class KettlerRacerProtocol extends DeviceProtocol_1.default {
|
|
35
|
+
constructor() {
|
|
36
|
+
super();
|
|
37
|
+
this.state = ScanState.IDLE;
|
|
38
|
+
this.logger = new gd_eventlog_1.EventLogger('KettlerRacer');
|
|
39
|
+
this.activeScans = [];
|
|
40
|
+
this.devices = [];
|
|
41
|
+
}
|
|
42
|
+
getSerialPort() {
|
|
43
|
+
return DeviceProtocol_1.default.getSerialPort();
|
|
44
|
+
}
|
|
45
|
+
getInterfaces() {
|
|
46
|
+
return [DeviceProtocol_1.INTERFACE.SERIAL];
|
|
47
|
+
}
|
|
48
|
+
getName() {
|
|
49
|
+
return PROTOCOL_NAME;
|
|
50
|
+
}
|
|
51
|
+
isBike() {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
isHrm() {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
isPower() {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
add(settings) {
|
|
61
|
+
this.logger.logEvent({ message: 'adding device', settings });
|
|
62
|
+
if (this.devices.length > 0) {
|
|
63
|
+
const found = this.devices.find(d => d.getPort() === settings.port);
|
|
64
|
+
if (found)
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
let device = new adapter_1.default(this, settings);
|
|
68
|
+
this.devices.push(device);
|
|
69
|
+
return device;
|
|
70
|
+
}
|
|
71
|
+
scan(props) {
|
|
72
|
+
this.logger.logEvent({ message: 'start scan', id: props.id, port: props.port });
|
|
73
|
+
this.state = ScanState.SCANNING;
|
|
74
|
+
const isAlreadyKnownOrScanning = this.checkDevice(props.port);
|
|
75
|
+
if (!isAlreadyKnownOrScanning) {
|
|
76
|
+
const port = props.port;
|
|
77
|
+
const name = PROTOCOL_NAME;
|
|
78
|
+
const device = new adapter_1.default(this, { name, port });
|
|
79
|
+
const iv = setInterval(() => { this.doScan(port); }, 1000);
|
|
80
|
+
this.activeScans.push({ iv, device, port, state: ScanState.IDLE, props });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
checkDevice(port) {
|
|
84
|
+
if (this.devices.length > 0 && this.devices.findIndex(d => d.getPort() === port) >= 0)
|
|
85
|
+
return true;
|
|
86
|
+
if (this.activeScans.length > 0 && this.activeScans.findIndex(d => d.port === port) >= 0)
|
|
87
|
+
return true;
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
doScan(port) {
|
|
91
|
+
const job = this.activeScans.find(d => d.port === port);
|
|
92
|
+
if (!job)
|
|
93
|
+
return;
|
|
94
|
+
if (this.state === ScanState.STOPPING || job.state === ScanState.STOPPING)
|
|
95
|
+
return;
|
|
96
|
+
const device = job.device;
|
|
97
|
+
if (device && (device.isDetected() || device.isSelected()))
|
|
98
|
+
return;
|
|
99
|
+
this.state = ScanState.SCANNING;
|
|
100
|
+
job.state = ScanState.SCANNING;
|
|
101
|
+
return device.check()
|
|
102
|
+
.then((found) => __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
if (found) {
|
|
104
|
+
if (this.state === ScanState.STOPPING || this.state === ScanState.STOPPED)
|
|
105
|
+
return;
|
|
106
|
+
const { onDeviceFound, onScanFinished, id } = job.props;
|
|
107
|
+
device.setDetected();
|
|
108
|
+
if (onDeviceFound)
|
|
109
|
+
onDeviceFound(device, device.getProtocol());
|
|
110
|
+
if (onScanFinished) {
|
|
111
|
+
onScanFinished(id);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
job.state = ScanState.STOPPED;
|
|
115
|
+
try {
|
|
116
|
+
yield device.waitForClosed();
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
this.logger.logEvent({ message: 'scanCommand warning: Could not close port', error: err.message });
|
|
120
|
+
}
|
|
121
|
+
clearInterval(job.iv);
|
|
122
|
+
job.iv = null;
|
|
123
|
+
job.state = ScanState.STOPPED;
|
|
124
|
+
const idxActiveScan = this.activeScans.findIndex(d => d.state !== ScanState.STOPPED);
|
|
125
|
+
if (idxActiveScan === -1) {
|
|
126
|
+
this.state = ScanState.STOPPED;
|
|
127
|
+
}
|
|
128
|
+
}))
|
|
129
|
+
.catch(() => {
|
|
130
|
+
job.state = ScanState.STOPPED;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
doStopScan(job) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
if (!job)
|
|
136
|
+
return;
|
|
137
|
+
if (job.state === ScanState.STOPPING || job.state === ScanState.STOPPED)
|
|
138
|
+
return;
|
|
139
|
+
job.state = ScanState.STOPPING;
|
|
140
|
+
clearInterval(job.iv);
|
|
141
|
+
job.iv = null;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
isJobStopped(job) {
|
|
145
|
+
return job.state === ScanState.STOPPED && !job.iv;
|
|
146
|
+
}
|
|
147
|
+
waitForStop(timeout) {
|
|
148
|
+
return new Promise((resolve) => {
|
|
149
|
+
let timedOut = false;
|
|
150
|
+
if (timeout)
|
|
151
|
+
setTimeout(() => { timedOut = true; }, timeout);
|
|
152
|
+
const iv = setInterval(() => {
|
|
153
|
+
const idxActiveScan = this.activeScans.findIndex(d => this.isJobStopped(d) === false);
|
|
154
|
+
if (idxActiveScan === -1) {
|
|
155
|
+
clearInterval(iv);
|
|
156
|
+
resolve(true);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (timedOut) {
|
|
160
|
+
clearInterval(iv);
|
|
161
|
+
resolve(false);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}, 500);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
stopScan() {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
if (this.state === ScanState.STOPPING || this.state === ScanState.STOPPED)
|
|
170
|
+
return;
|
|
171
|
+
this.state = ScanState.STOPPING;
|
|
172
|
+
this.logger.logEvent({ message: 'stop scan', activeScans: this.activeScans.map(j => j.port) });
|
|
173
|
+
this.activeScans.forEach(job => this.doStopScan(job));
|
|
174
|
+
const stopped = yield this.waitForStop();
|
|
175
|
+
if (!stopped) {
|
|
176
|
+
this.logger.logEvent({ message: 'scanCommand warning: stop scan timeout' });
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.logger.logEvent({ message: 'stop scan completed' });
|
|
180
|
+
}
|
|
181
|
+
this.activeScans = [];
|
|
182
|
+
this.state = ScanState.IDLE;
|
|
183
|
+
return true;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
isScanning() {
|
|
187
|
+
return this.state === ScanState.SCANNING;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.KettlerRacerProtocol = KettlerRacerProtocol;
|
|
191
|
+
DeviceRegistry_1.default.register(new KettlerRacerProtocol());
|
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
2
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
3
|
if (mod && mod.__esModule) return mod;
|
|
16
4
|
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (
|
|
18
|
-
|
|
5
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
6
|
+
result["default"] = mod;
|
|
19
7
|
return result;
|
|
20
8
|
};
|
|
21
9
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
11
|
};
|
|
24
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.Simulator = void 0;
|
|
26
13
|
const DeviceProtocol_1 = __importStar(require("../DeviceProtocol"));
|
|
27
14
|
const DeviceRegistry_1 = __importDefault(require("../DeviceRegistry"));
|
|
28
15
|
const Device_1 = __importDefault(require("../Device"));
|
package/lib/types/route.js
CHANGED
package/lib/types/user.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -9,11 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const sleep = (ms) => {
|
|
12
|
+
exports.sleep = (ms) => {
|
|
14
13
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
15
14
|
};
|
|
16
|
-
exports.sleep = sleep;
|
|
17
15
|
function runWithRetries(fn, maxRetries, timeBetween) {
|
|
18
16
|
return new Promise((resolve, reject) => {
|
|
19
17
|
let retries = 0;
|