incyclist-devices 1.4.21 → 1.4.22
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 +1 -0
- package/lib/Device.js +1 -0
- package/lib/DeviceProtocol.js +1 -0
- package/lib/DeviceSupport.js +21 -8
- package/lib/ant/AntAdapter.js +1 -0
- package/lib/ant/AntScanner.js +20 -7
- package/lib/ant/antfe/AntFEAdapter.d.ts +1 -0
- package/lib/ant/antfe/AntFEAdapter.js +16 -8
- package/lib/ant/anthrm/AntHrmAdapter.js +1 -1
- package/lib/ant/utils.js +3 -1
- package/lib/calculations.js +1 -0
- package/lib/daum/DaumAdapter.js +25 -13
- package/lib/daum/SmartTrainerCyclingMode.js +1 -0
- package/lib/daum/classic/DaumClassicAdapter.js +1 -1
- package/lib/daum/classic/DaumClassicProtocol.js +19 -7
- package/lib/daum/classic/bike.js +26 -26
- package/lib/daum/classic/utils.js +1 -0
- package/lib/daum/constants.js +1 -0
- package/lib/daum/premium/DaumPremiumAdapter.js +1 -1
- package/lib/daum/premium/DaumPremiumProtocol.js +19 -7
- package/lib/daum/premium/bike.js +18 -17
- package/lib/daum/premium/utils.js +1 -0
- package/lib/kettler/comms.js +2 -1
- package/lib/kettler/ergo-racer/adapter.js +21 -9
- package/lib/kettler/ergo-racer/protocol.js +19 -7
- package/lib/simulator/Simulator.d.ts +20 -4
- package/lib/simulator/Simulator.js +121 -56
- package/lib/simulator/simulator-mode.d.ts +28 -0
- package/lib/simulator/simulator-mode.js +120 -0
- package/lib/types/route.js +1 -0
- package/lib/types/user.js +1 -0
- package/lib/utils.js +3 -1
- package/package.json +1 -1
package/lib/daum/premium/bike.js
CHANGED
|
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Daum8iSerial = exports.Daum8iTcp = void 0;
|
|
15
16
|
const constants_1 = require("../constants");
|
|
16
17
|
const tcpserial_1 = __importDefault(require("./tcpserial"));
|
|
17
18
|
const utils_1 = require("./utils");
|
|
@@ -407,7 +408,7 @@ class Daum8i {
|
|
|
407
408
|
incoming = bufferData;
|
|
408
409
|
}
|
|
409
410
|
const response = [...incoming];
|
|
410
|
-
this.logger.logEvent({ message: 'sendCommand:RECV', data: utils_1.hexstr(response) });
|
|
411
|
+
this.logger.logEvent({ message: 'sendCommand:RECV', data: (0, utils_1.hexstr)(response) });
|
|
411
412
|
for (let i = 0; i < incoming.length; i++) {
|
|
412
413
|
const getRemaining = () => {
|
|
413
414
|
let remaining = '';
|
|
@@ -440,11 +441,11 @@ class Daum8i {
|
|
|
440
441
|
}
|
|
441
442
|
else if (c === 0x17) {
|
|
442
443
|
const remaining = getRemaining();
|
|
443
|
-
this.logger.logEvent({ message: "sendCommand:received:", duration: Date.now() - this.state.sending.tsRequest, port: portName, cmd: `${cmd} [${utils_1.hexstr(cmd)}]`, remaining: utils_1.hexstr(remaining) });
|
|
444
|
+
this.logger.logEvent({ message: "sendCommand:received:", duration: Date.now() - this.state.sending.tsRequest, port: portName, cmd: `${cmd} [${(0, utils_1.hexstr)(cmd)}]`, remaining: (0, utils_1.hexstr)(remaining) });
|
|
444
445
|
this.state.waitingForEnd = false;
|
|
445
446
|
const cmdStr = cmd.substring(0, cmd.length - 2);
|
|
446
447
|
const checksumExtracted = cmd.slice(-2);
|
|
447
|
-
const checksumCalculated = utils_1.checkSum(utils_1.getAsciiArrayFromStr(cmdStr), []);
|
|
448
|
+
const checksumCalculated = (0, utils_1.checkSum)((0, utils_1.getAsciiArrayFromStr)(cmdStr), []);
|
|
448
449
|
if (checksumExtracted === checksumCalculated) {
|
|
449
450
|
this.sendACK();
|
|
450
451
|
if (this.state.sending && this.state.sending.responseCheckIv) {
|
|
@@ -486,8 +487,8 @@ class Daum8i {
|
|
|
486
487
|
this.state.busy = true;
|
|
487
488
|
}
|
|
488
489
|
else {
|
|
489
|
-
const message = utils_1.buildMessage(command, payload);
|
|
490
|
-
this.logger.logEvent({ message: 'sendCommand:waiting', port: this.portName, cmd: command, hex: utils_1.hexstr(message) });
|
|
490
|
+
const message = (0, utils_1.buildMessage)(command, payload);
|
|
491
|
+
this.logger.logEvent({ message: 'sendCommand:waiting', port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
491
492
|
const busyWait = () => {
|
|
492
493
|
return new Promise((done) => {
|
|
493
494
|
let start = Date.now();
|
|
@@ -508,7 +509,7 @@ class Daum8i {
|
|
|
508
509
|
};
|
|
509
510
|
const res = yield busyWait();
|
|
510
511
|
if (!res) {
|
|
511
|
-
this.logger.logEvent({ message: 'sendCommand:busy timeout', port: this.portName, cmd: command, hex: utils_1.hexstr(message), duration: Date.now() - tsRequest });
|
|
512
|
+
this.logger.logEvent({ message: 'sendCommand:busy timeout', port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message), duration: Date.now() - tsRequest });
|
|
512
513
|
return reject(new Error('BUSY timeout'));
|
|
513
514
|
}
|
|
514
515
|
this.state.busy = true;
|
|
@@ -526,10 +527,10 @@ class Daum8i {
|
|
|
526
527
|
const portName = this.portName;
|
|
527
528
|
this.state.received = [];
|
|
528
529
|
try {
|
|
529
|
-
const message = utils_1.buildMessage(command, payload);
|
|
530
|
+
const message = (0, utils_1.buildMessage)(command, payload);
|
|
530
531
|
const start = Date.now();
|
|
531
532
|
const timeout = start + this.getTimeoutValue();
|
|
532
|
-
this.logger.logEvent({ message: "sendCommand:sending:", port: this.portName, cmd: command, hex: utils_1.hexstr(message) });
|
|
533
|
+
this.logger.logEvent({ message: "sendCommand:sending:", port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
533
534
|
this.state.writeBusy = true;
|
|
534
535
|
if (!this.connected || port === undefined) {
|
|
535
536
|
this.logger.logEvent({ message: "sendCommand:error: not connected", port: this.portName });
|
|
@@ -589,10 +590,10 @@ class Daum8i {
|
|
|
589
590
|
buffer.writeUInt16LE(0, 2);
|
|
590
591
|
}
|
|
591
592
|
const cmdData = Uint8Array.from(buffer);
|
|
592
|
-
return this.sendDaum8iCommand('M70', cmdType, utils_1.bin2esc(cmdData))
|
|
593
|
+
return this.sendDaum8iCommand('M70', cmdType, (0, utils_1.bin2esc)(cmdData))
|
|
593
594
|
.then((res) => {
|
|
594
595
|
const resData = Uint8Array.from(res, x => x.charCodeAt(0));
|
|
595
|
-
const cmd = utils_1.esc2bin(resData);
|
|
596
|
+
const cmd = (0, utils_1.esc2bin)(resData);
|
|
596
597
|
return cmd;
|
|
597
598
|
});
|
|
598
599
|
}
|
|
@@ -617,7 +618,7 @@ class Daum8i {
|
|
|
617
618
|
else if (str === '7')
|
|
618
619
|
deviceType = 'lyps';
|
|
619
620
|
else
|
|
620
|
-
throw (new Error(`unknown device type ${typeof str === 'string' ? utils_1.ascii(str.charAt(0)) : str}`));
|
|
621
|
+
throw (new Error(`unknown device type ${typeof str === 'string' ? (0, utils_1.ascii)(str.charAt(0)) : str}`));
|
|
621
622
|
return deviceType;
|
|
622
623
|
});
|
|
623
624
|
}
|
|
@@ -632,7 +633,7 @@ class Daum8i {
|
|
|
632
633
|
else if (str === '2')
|
|
633
634
|
deviceType = constants_1.ACTUAL_BIKE_TYPE.MOUNTAIN;
|
|
634
635
|
else {
|
|
635
|
-
throw (new Error(`unknown actual device type ${typeof str === 'string' ? utils_1.ascii(str.charAt(0)) : str}`));
|
|
636
|
+
throw (new Error(`unknown actual device type ${typeof str === 'string' ? (0, utils_1.ascii)(str.charAt(0)) : str}`));
|
|
636
637
|
}
|
|
637
638
|
this.state.actualBikeType = deviceType;
|
|
638
639
|
return deviceType;
|
|
@@ -674,12 +675,12 @@ class Daum8i {
|
|
|
674
675
|
getTrainingData() {
|
|
675
676
|
return this.sendDaum8iCommand('X70', 'AF', [])
|
|
676
677
|
.then((data) => {
|
|
677
|
-
const td = utils_1.parseTrainingData(data);
|
|
678
|
+
const td = (0, utils_1.parseTrainingData)(data);
|
|
678
679
|
return td;
|
|
679
680
|
});
|
|
680
681
|
}
|
|
681
682
|
setLoadControl(enabled) {
|
|
682
|
-
const val = enabled ? utils_1.ascii('1') : utils_1.ascii('0');
|
|
683
|
+
const val = enabled ? (0, utils_1.ascii)('1') : (0, utils_1.ascii)('0');
|
|
683
684
|
return this.sendDaum8iCommand('S20', 'BF', [val])
|
|
684
685
|
.then((data) => {
|
|
685
686
|
const res = data === '1';
|
|
@@ -713,7 +714,7 @@ class Daum8i {
|
|
|
713
714
|
setPerson(person) {
|
|
714
715
|
const { sex, age, length, weight } = person;
|
|
715
716
|
this.logger.logEvent({ message: 'setPerson() request', sex, age, length, weight });
|
|
716
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, 'BF', utils_1.getPersonData(person))
|
|
717
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, 'BF', (0, utils_1.getPersonData)(person))
|
|
717
718
|
.then((res) => {
|
|
718
719
|
const buffer = Buffer.from(res);
|
|
719
720
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PERSON_SET;
|
|
@@ -737,9 +738,9 @@ class Daum8i {
|
|
|
737
738
|
}
|
|
738
739
|
programUploadStart(bikeType, route) {
|
|
739
740
|
const payload = Buffer.alloc(40);
|
|
740
|
-
const epp = route ? utils_1.routeToEpp(route) : undefined;
|
|
741
|
+
const epp = route ? (0, utils_1.routeToEpp)(route) : undefined;
|
|
741
742
|
const eppLength = epp ? epp.length : 0;
|
|
742
|
-
const bikeTypeVal = utils_1.getBikeType(bikeType);
|
|
743
|
+
const bikeTypeVal = (0, utils_1.getBikeType)(bikeType);
|
|
743
744
|
const wBits = route.lapMode ? DS_BITS_ENDLESS_RACE : DS_BITS_OFF;
|
|
744
745
|
payload.writeInt32LE(0, 0);
|
|
745
746
|
payload.writeInt8(bikeTypeVal, 4);
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPersonData = exports.parseTrainingData = exports.routeToEpp = exports.getBikeType = exports.BikeType = exports.ReservedCommands = exports.Int32ToIntArray = exports.Int16ToIntArray = exports.Float32ToIntArray = exports.Float32ToHex = exports.getAsciiArrayFromStr = exports.asciiArrayToString = exports.charArrayToString = exports.ascii = exports.append = exports.getHex = exports.hexstr = exports.getMessageData = exports.buildMessage = exports.checkSum = exports.esc2bin = exports.bin2esc = void 0;
|
|
6
7
|
const win32filetime_1 = __importDefault(require("win32filetime"));
|
|
7
8
|
const sum = (arr) => arr.reduce((a, b) => a + b, 0);
|
|
8
9
|
function bin2esc(arr) {
|
package/lib/kettler/comms.js
CHANGED
|
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SendState = exports.SerialCommsState = void 0;
|
|
15
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
17
|
const utils_1 = require("../utils");
|
|
17
18
|
const events_1 = __importDefault(require("events"));
|
|
@@ -193,7 +194,7 @@ class KettlerSerialComms extends events_1.default {
|
|
|
193
194
|
write(cmd) {
|
|
194
195
|
this.sendState = SendState.Sending;
|
|
195
196
|
const { logStr, message, timeout = (this.settings.timeout || DEFAULT_RCV_TIMEOUT) } = cmd;
|
|
196
|
-
const msg = typeof message === 'string' ? message : utils_1.hexstr(message);
|
|
197
|
+
const msg = typeof message === 'string' ? message : (0, utils_1.hexstr)(message);
|
|
197
198
|
const onError = (err) => {
|
|
198
199
|
this.logger.logEvent({ message: "sendCommand:error:", cmd: logStr, error: err.message, port: this.getPort() });
|
|
199
200
|
if (cmd.onError)
|
|
@@ -1,4 +1,23 @@
|
|
|
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
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,13 +27,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
28
|
});
|
|
10
29
|
};
|
|
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
30
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
32
|
};
|
|
@@ -288,7 +300,7 @@ class KettlerRacerAdapter extends Device_1.default {
|
|
|
288
300
|
this.logger.logEvent({ message: 'start()' });
|
|
289
301
|
var info = {};
|
|
290
302
|
yield this.waitForOpened(true);
|
|
291
|
-
return utils_1.runWithRetries(() => __awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
292
304
|
try {
|
|
293
305
|
if (!info.checkDone) {
|
|
294
306
|
info.checkDone = yield this.check();
|
|
@@ -573,7 +585,7 @@ class KettlerRacerAdapter extends Device_1.default {
|
|
|
573
585
|
if (!retries) {
|
|
574
586
|
return new Promise((resolve, reject) => run(resolve, reject));
|
|
575
587
|
}
|
|
576
|
-
return utils_1.runWithRetries(() => {
|
|
588
|
+
return (0, utils_1.runWithRetries)(() => {
|
|
577
589
|
return new Promise((resolve, reject) => run(resolve, reject));
|
|
578
590
|
}, 3, 1000);
|
|
579
591
|
}
|
|
@@ -1,4 +1,23 @@
|
|
|
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
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,13 +27,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
28
|
});
|
|
10
29
|
};
|
|
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
30
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
32
|
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import DeviceProtocolBase, { DeviceSettings } from '../DeviceProtocol';
|
|
1
|
+
import DeviceProtocolBase, { DeviceSettings, DeviceProtocol } from '../DeviceProtocol';
|
|
2
2
|
import DeviceAdapter from '../Device';
|
|
3
3
|
import { EventLogger } from 'gd-eventlog';
|
|
4
|
+
import CyclingMode, { IncyclistBikeData } from '../CyclingMode';
|
|
5
|
+
interface SimulatorSettings extends DeviceSettings {
|
|
6
|
+
isBot?: boolean;
|
|
7
|
+
settings?: any;
|
|
8
|
+
}
|
|
4
9
|
export declare class Simulator extends DeviceAdapter {
|
|
5
10
|
static NAME: string;
|
|
6
11
|
logger: EventLogger;
|
|
@@ -14,13 +19,23 @@ export declare class Simulator extends DeviceAdapter {
|
|
|
14
19
|
slope: number;
|
|
15
20
|
limit: any;
|
|
16
21
|
startProps?: any;
|
|
17
|
-
|
|
22
|
+
cyclingMode: CyclingMode;
|
|
23
|
+
startTS: number;
|
|
24
|
+
data: IncyclistBikeData;
|
|
25
|
+
isBot: boolean;
|
|
26
|
+
ignoreHrm: boolean;
|
|
27
|
+
constructor(protocol?: DeviceProtocol, props?: SimulatorSettings);
|
|
18
28
|
isBike(): boolean;
|
|
19
29
|
isHrm(): boolean;
|
|
20
30
|
isPower(): boolean;
|
|
21
31
|
getID(): string;
|
|
22
32
|
getName(): string;
|
|
23
33
|
getPort(): string;
|
|
34
|
+
setIgnoreHrm(ignore: any): void;
|
|
35
|
+
getSupportedCyclingModes(): Array<any>;
|
|
36
|
+
getDefaultCyclingMode(): CyclingMode;
|
|
37
|
+
getCyclingMode(): CyclingMode;
|
|
38
|
+
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
24
39
|
start(props?: any): Promise<unknown>;
|
|
25
40
|
stop(): Promise<boolean>;
|
|
26
41
|
pause(): Promise<boolean>;
|
|
@@ -30,12 +45,12 @@ export declare class Simulator extends DeviceAdapter {
|
|
|
30
45
|
slower(): void;
|
|
31
46
|
update(): void;
|
|
32
47
|
calculateDistance(speedKps: any, timeS: any): number;
|
|
33
|
-
sendUpdate(request: any):
|
|
48
|
+
sendUpdate(request: any): import("../CyclingMode").UpdateRequest;
|
|
34
49
|
}
|
|
35
50
|
export default class SimulatorProtocol extends DeviceProtocolBase {
|
|
36
51
|
static NAME: string;
|
|
37
52
|
constructor();
|
|
38
|
-
add(settings:
|
|
53
|
+
add(settings: SimulatorSettings): any;
|
|
39
54
|
getName(): string;
|
|
40
55
|
getInterfaces(): string[];
|
|
41
56
|
isBike(): boolean;
|
|
@@ -43,3 +58,4 @@ export default class SimulatorProtocol extends DeviceProtocolBase {
|
|
|
43
58
|
isPower(): boolean;
|
|
44
59
|
getDevices(): import("../DeviceProtocol").Device[];
|
|
45
60
|
}
|
|
61
|
+
export {};
|
|
@@ -1,22 +1,45 @@
|
|
|
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
|
+
});
|
|
2
14
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
3
15
|
if (mod && mod.__esModule) return mod;
|
|
4
16
|
var result = {};
|
|
5
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result
|
|
6
|
-
result
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
7
19
|
return result;
|
|
8
20
|
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
9
30
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
32
|
};
|
|
12
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.Simulator = void 0;
|
|
13
35
|
const DeviceProtocol_1 = __importStar(require("../DeviceProtocol"));
|
|
14
36
|
const DeviceRegistry_1 = __importDefault(require("../DeviceRegistry"));
|
|
15
37
|
const Device_1 = __importDefault(require("../Device"));
|
|
16
38
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
|
-
const
|
|
39
|
+
const simulator_mode_1 = __importDefault(require("./simulator-mode"));
|
|
40
|
+
const DEFAULT_SETTINGS = { name: 'Simulator', port: '', isBot: false };
|
|
18
41
|
class Simulator extends Device_1.default {
|
|
19
|
-
constructor(protocol) {
|
|
42
|
+
constructor(protocol, props = DEFAULT_SETTINGS) {
|
|
20
43
|
const proto = protocol || DeviceRegistry_1.default.findByName('Simulator');
|
|
21
44
|
super(proto);
|
|
22
45
|
this.logger = new gd_eventlog_1.EventLogger(Simulator.NAME);
|
|
@@ -27,8 +50,16 @@ class Simulator extends Device_1.default {
|
|
|
27
50
|
this.time = undefined;
|
|
28
51
|
this.iv = undefined;
|
|
29
52
|
this.started = false;
|
|
53
|
+
this.paused = false;
|
|
30
54
|
this.slope = 0;
|
|
31
55
|
this.limit = {};
|
|
56
|
+
this.startTS = undefined;
|
|
57
|
+
this.data = { isPedalling: false, power: 0, pedalRpm: 0, speed: 0, heartrate: 0, distanceInternal: 0 };
|
|
58
|
+
this.isBot = props.isBot || false;
|
|
59
|
+
this.ignoreHrm = false;
|
|
60
|
+
const name = this.getCyclingMode().getName();
|
|
61
|
+
const modeSettings = this.isBot ? props.settings || {} : this.getCyclingMode().getSettings();
|
|
62
|
+
this.setCyclingMode(name, modeSettings);
|
|
32
63
|
}
|
|
33
64
|
isBike() { return true; }
|
|
34
65
|
isHrm() { return false; }
|
|
@@ -36,28 +67,66 @@ class Simulator extends Device_1.default {
|
|
|
36
67
|
getID() { return Simulator.NAME; }
|
|
37
68
|
getName() { return Simulator.NAME; }
|
|
38
69
|
getPort() { return 'local'; }
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
70
|
+
setIgnoreHrm(ignore) {
|
|
71
|
+
this.ignoreHrm = ignore;
|
|
72
|
+
}
|
|
73
|
+
getSupportedCyclingModes() {
|
|
74
|
+
const supported = [];
|
|
75
|
+
supported.push(simulator_mode_1.default);
|
|
76
|
+
return supported;
|
|
77
|
+
}
|
|
78
|
+
getDefaultCyclingMode() {
|
|
79
|
+
return new simulator_mode_1.default(this);
|
|
80
|
+
}
|
|
81
|
+
getCyclingMode() {
|
|
82
|
+
if (!this.cyclingMode)
|
|
83
|
+
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
84
|
+
return this.cyclingMode;
|
|
85
|
+
}
|
|
86
|
+
setCyclingMode(mode, settings) {
|
|
87
|
+
let selectedMode;
|
|
88
|
+
if (typeof mode === 'string') {
|
|
89
|
+
const supported = this.getSupportedCyclingModes();
|
|
90
|
+
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
91
|
+
if (CyclingModeClass) {
|
|
92
|
+
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
93
|
+
return;
|
|
45
94
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
95
|
+
selectedMode = this.getDefaultCyclingMode();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
selectedMode = mode;
|
|
99
|
+
}
|
|
100
|
+
this.cyclingMode = selectedMode;
|
|
101
|
+
this.cyclingMode.setSettings(settings);
|
|
102
|
+
}
|
|
103
|
+
start(props) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
this.startProps = props;
|
|
106
|
+
return new Promise((resolve) => {
|
|
107
|
+
if (!this.isBot)
|
|
108
|
+
this.logger.logEvent({ message: 'start', iv: this.iv });
|
|
109
|
+
if (this.started) {
|
|
110
|
+
return resolve({ started: true, error: undefined });
|
|
111
|
+
}
|
|
112
|
+
this.started = true;
|
|
113
|
+
this.time = Date.now();
|
|
114
|
+
this.startTS = this.time;
|
|
115
|
+
if (this.iv !== undefined) {
|
|
116
|
+
clearInterval(this.iv);
|
|
117
|
+
this.iv = undefined;
|
|
118
|
+
}
|
|
119
|
+
this.iv = setInterval(() => this.update(), 1000);
|
|
120
|
+
if (!this.isBot)
|
|
121
|
+
this.logger.logEvent({ message: 'started' });
|
|
122
|
+
resolve({ started: true, error: undefined });
|
|
123
|
+
});
|
|
56
124
|
});
|
|
57
125
|
}
|
|
58
126
|
stop() {
|
|
59
127
|
return new Promise((resolve, reject) => {
|
|
60
|
-
|
|
128
|
+
if (!this.isBot)
|
|
129
|
+
this.logger.logEvent({ message: 'stop', iv: this.iv });
|
|
61
130
|
this.started = false;
|
|
62
131
|
clearInterval(this.iv);
|
|
63
132
|
this.iv = undefined;
|
|
@@ -69,7 +138,8 @@ class Simulator extends Device_1.default {
|
|
|
69
138
|
return new Promise((resolve, reject) => {
|
|
70
139
|
if (!this.started)
|
|
71
140
|
return reject(new Error('illegal state - pause() has been called before start()'));
|
|
72
|
-
|
|
141
|
+
if (!this.isBot)
|
|
142
|
+
this.logger.logEvent({ message: 'pause', iv: this.iv });
|
|
73
143
|
this.paused = true;
|
|
74
144
|
resolve(true);
|
|
75
145
|
});
|
|
@@ -78,7 +148,8 @@ class Simulator extends Device_1.default {
|
|
|
78
148
|
return new Promise((resolve, reject) => {
|
|
79
149
|
if (!this.started)
|
|
80
150
|
reject(new Error('illegal state - resume() has been called before start()'));
|
|
81
|
-
|
|
151
|
+
if (!this.isBot)
|
|
152
|
+
this.logger.logEvent({ message: 'resume', iv: this.iv });
|
|
82
153
|
this.paused = false;
|
|
83
154
|
resolve(true);
|
|
84
155
|
});
|
|
@@ -114,29 +185,26 @@ class Simulator extends Device_1.default {
|
|
|
114
185
|
}
|
|
115
186
|
}
|
|
116
187
|
update() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.speed
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
let distance = this.calculateDistance(this.speed, timespan / 1000);
|
|
139
|
-
let data = { speed: this.speed, cadence: Math.round(this.cadence), power: Math.round(this.power), timespan, distance };
|
|
188
|
+
const startDelay = this.getCyclingMode().getSetting('delay');
|
|
189
|
+
const timeSinceStart = Date.now() - this.startTS;
|
|
190
|
+
if (startDelay && timeSinceStart < startDelay * 1000)
|
|
191
|
+
return;
|
|
192
|
+
const prevDist = this.data.distanceInternal;
|
|
193
|
+
this.data = this.getCyclingMode().updateData(this.data);
|
|
194
|
+
let data = {
|
|
195
|
+
speed: this.data.speed,
|
|
196
|
+
slope: this.data.slope,
|
|
197
|
+
power: this.data.power,
|
|
198
|
+
cadence: this.data.pedalRpm,
|
|
199
|
+
distance: this.data.distanceInternal - prevDist,
|
|
200
|
+
heartrate: Math.round(this.data.power - 10 + Math.random() * 20),
|
|
201
|
+
timestamp: Date.now(),
|
|
202
|
+
deviceTime: Math.round((Date.now() - this.startTS) / 1000),
|
|
203
|
+
deviceDistanceCounter: this.data.distanceInternal
|
|
204
|
+
};
|
|
205
|
+
this.paused = (this.data.speed === 0);
|
|
206
|
+
if (this.ignoreHrm)
|
|
207
|
+
delete data.heartrate;
|
|
140
208
|
if (this.onDataFn) {
|
|
141
209
|
this.onDataFn(data);
|
|
142
210
|
}
|
|
@@ -145,15 +213,9 @@ class Simulator extends Device_1.default {
|
|
|
145
213
|
return timeS * speedKps / 3.6;
|
|
146
214
|
}
|
|
147
215
|
sendUpdate(request) {
|
|
148
|
-
this.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (Object.keys(r).length === 1)
|
|
152
|
-
return this.limit;
|
|
153
|
-
delete r.refresh;
|
|
154
|
-
}
|
|
155
|
-
this.limit = r;
|
|
156
|
-
return this.limit;
|
|
216
|
+
if (this.paused)
|
|
217
|
+
return;
|
|
218
|
+
return this.getCyclingMode().sendBikeUpdate(request);
|
|
157
219
|
}
|
|
158
220
|
}
|
|
159
221
|
exports.Simulator = Simulator;
|
|
@@ -161,9 +223,12 @@ Simulator.NAME = 'Simulator';
|
|
|
161
223
|
class SimulatorProtocol extends DeviceProtocol_1.default {
|
|
162
224
|
constructor() {
|
|
163
225
|
super();
|
|
164
|
-
this.devices
|
|
226
|
+
this.devices = [];
|
|
165
227
|
}
|
|
166
228
|
add(settings) {
|
|
229
|
+
let device = new Simulator(this, settings);
|
|
230
|
+
this.devices.push(device);
|
|
231
|
+
return device;
|
|
167
232
|
}
|
|
168
233
|
getName() {
|
|
169
234
|
return SimulatorProtocol.NAME;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EventLogger } from "gd-eventlog";
|
|
2
|
+
import CyclingMode, { CyclingModeBase, CyclingModeProperty, IncyclistBikeData, UpdateRequest } from "../CyclingMode";
|
|
3
|
+
import { Simulator } from "./Simulator";
|
|
4
|
+
export declare type ERGEvent = {
|
|
5
|
+
rpmUpdated?: boolean;
|
|
6
|
+
gearUpdated?: boolean;
|
|
7
|
+
starting?: boolean;
|
|
8
|
+
tsStart?: number;
|
|
9
|
+
};
|
|
10
|
+
export default class SimulatorCyclingMode extends CyclingModeBase implements CyclingMode {
|
|
11
|
+
logger: EventLogger;
|
|
12
|
+
data: IncyclistBikeData;
|
|
13
|
+
prevRequest: UpdateRequest;
|
|
14
|
+
prevUpdateTS: number;
|
|
15
|
+
hasBikeUpdate: boolean;
|
|
16
|
+
chain: number[];
|
|
17
|
+
cassette: number[];
|
|
18
|
+
event: ERGEvent;
|
|
19
|
+
constructor(adapter: Simulator, props?: any);
|
|
20
|
+
getName(): string;
|
|
21
|
+
getDescription(): string;
|
|
22
|
+
getProperties(): CyclingModeProperty[];
|
|
23
|
+
getProperty(name: string): CyclingModeProperty;
|
|
24
|
+
getBikeInitRequest(): UpdateRequest;
|
|
25
|
+
sendBikeUpdate(request: UpdateRequest): UpdateRequest;
|
|
26
|
+
updateData(bikeData: IncyclistBikeData): IncyclistBikeData;
|
|
27
|
+
calculateTargetPower(request: any, updateMode?: boolean): void;
|
|
28
|
+
}
|