incyclist-devices 1.1.0 → 1.3.25
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/LICENSE +21 -0
- package/lib/CyclingMode.d.ts +72 -0
- package/lib/CyclingMode.js +66 -0
- package/lib/Device.d.ts +48 -10
- package/lib/Device.js +9 -8
- package/lib/DeviceProtocol.d.ts +40 -12
- package/lib/DeviceProtocol.js +16 -16
- package/lib/DeviceRegistry.d.ts +4 -4
- package/lib/DeviceRegistry.js +10 -10
- package/lib/DeviceSupport.d.ts +4 -3
- package/lib/DeviceSupport.js +32 -8
- package/lib/ant/AntAdapter.d.ts +11 -2
- package/lib/ant/AntAdapter.js +30 -1
- package/lib/ant/AntScanner.d.ts +17 -6
- package/lib/ant/AntScanner.js +406 -135
- package/lib/ant/antfe/AntFEAdapter.d.ts +12 -8
- package/lib/ant/antfe/AntFEAdapter.js +404 -182
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +4 -2
- package/lib/ant/anthrm/AntHrmAdapter.js +72 -25
- package/lib/ant/utils.js +2 -1
- package/lib/calculations.d.ts +12 -13
- package/lib/calculations.js +88 -125
- package/lib/daum/DaumAdapter.d.ts +29 -6
- package/lib/daum/DaumAdapter.js +219 -96
- package/lib/daum/ERGCyclingMode.d.ts +28 -0
- package/lib/daum/ERGCyclingMode.js +207 -0
- package/lib/daum/PowerMeterCyclingMode.d.ts +18 -0
- package/lib/daum/PowerMeterCyclingMode.js +79 -0
- package/lib/daum/SmartTrainerCyclingMode.d.ts +41 -0
- package/lib/daum/SmartTrainerCyclingMode.js +344 -0
- package/lib/daum/classic/DaumClassicAdapter.d.ts +3 -1
- package/lib/daum/classic/DaumClassicAdapter.js +46 -32
- package/lib/daum/classic/DaumClassicCyclingMode.d.ts +13 -0
- package/lib/daum/classic/DaumClassicCyclingMode.js +98 -0
- package/lib/daum/classic/DaumClassicProtocol.d.ts +5 -3
- package/lib/daum/classic/DaumClassicProtocol.js +39 -6
- package/lib/daum/classic/ERGCyclingMode.d.ts +23 -0
- package/lib/daum/classic/ERGCyclingMode.js +171 -0
- package/lib/daum/classic/bike.d.ts +41 -37
- package/lib/daum/classic/bike.js +86 -53
- package/lib/daum/classic/utils.d.ts +3 -3
- package/lib/daum/classic/utils.js +16 -10
- package/lib/daum/indoorbike.d.ts +2 -1
- package/lib/daum/indoorbike.js +23 -21
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +2 -2
- package/lib/daum/premium/DaumPremiumAdapter.js +30 -20
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +11 -2
- package/lib/daum/premium/DaumPremiumProtocol.js +49 -8
- package/lib/daum/premium/bike.d.ts +63 -52
- package/lib/daum/premium/bike.js +258 -207
- package/lib/daum/premium/tcpserial.d.ts +18 -14
- package/lib/daum/premium/tcpserial.js +50 -20
- package/lib/daum/premium/utils.d.ts +2 -2
- package/lib/simulator/Simulator.d.ts +13 -7
- package/lib/simulator/Simulator.js +62 -21
- package/lib/utils.d.ts +3 -1
- package/lib/utils.js +39 -18
- package/package.json +12 -11
- package/lib/ant/AntScanner.unit.tests.d.ts +0 -1
- package/lib/ant/AntScanner.unit.tests.js +0 -25
- package/lib/ant/antfe/AntFEProcessor.d.ts +0 -40
- package/lib/ant/antfe/AntFEProcessor.js +0 -238
- package/lib/ant/antfe/AntHrmProtocol.d.ts +0 -9
- package/lib/ant/antfe/AntHrmProtocol.js +0 -30
- package/lib/ant/antfe/bike.d.ts +0 -47
- package/lib/ant/antfe/bike.js +0 -602
- package/lib/ant/anthrm/anthrm.d.ts +0 -33
- package/lib/ant/anthrm/anthrm.js +0 -523
- package/lib/simulator/Simulator.unit.tests.d.ts +0 -1
- package/lib/simulator/Simulator.unit.tests.js +0 -79
|
@@ -1,29 +1,33 @@
|
|
|
1
|
+
import { EventLogger } from 'gd-eventlog';
|
|
1
2
|
export default class TcpSocketPort {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
callbacks: {};
|
|
7
|
-
isOpen: boolean;
|
|
8
|
-
props: any;
|
|
9
|
-
enabled: any;
|
|
10
|
-
host: any;
|
|
11
|
-
port: any;
|
|
3
|
+
callbacks: any;
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
12
7
|
net: any;
|
|
13
|
-
|
|
8
|
+
props: any;
|
|
14
9
|
socket: any;
|
|
15
|
-
|
|
10
|
+
id: number;
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
isClosed: boolean;
|
|
13
|
+
path: string;
|
|
14
|
+
outputQueue: Array<any>;
|
|
16
15
|
iv: any;
|
|
16
|
+
logger: EventLogger;
|
|
17
|
+
constructor(props: any);
|
|
17
18
|
flush(): void;
|
|
18
|
-
open(): void;
|
|
19
|
+
open(retry?: boolean): void;
|
|
19
20
|
close(): void;
|
|
20
|
-
isClosed: boolean;
|
|
21
21
|
onTimeout(): void;
|
|
22
22
|
onConnect(): void;
|
|
23
23
|
onError(err: any): void;
|
|
24
24
|
on(event: any, callback: any): void;
|
|
25
|
+
removeAllListeners(): void;
|
|
25
26
|
emit(event: any, ...args: any[]): void;
|
|
26
27
|
write(message: any): void;
|
|
27
28
|
unpipe(): void;
|
|
28
29
|
pipe(transformer: any): any;
|
|
30
|
+
static setResponse(command: any, fn: any): void;
|
|
31
|
+
static getReponseHandler(command: any): any;
|
|
32
|
+
static reset(): void;
|
|
29
33
|
}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const net_1 = require("net");
|
|
4
|
-
const
|
|
6
|
+
const net_1 = __importDefault(require("net"));
|
|
7
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
8
|
+
const TIMEOUT_OPEN = 1000;
|
|
9
|
+
var __responses = {};
|
|
5
10
|
class TcpSocketPort {
|
|
6
11
|
constructor(props) {
|
|
7
12
|
this.callbacks = {};
|
|
8
13
|
this.isOpen = false;
|
|
14
|
+
this.isClosed = false;
|
|
9
15
|
this.props = props || {};
|
|
16
|
+
this.logger = new gd_eventlog_1.EventLogger('TCPSocket') || props.logger;
|
|
10
17
|
this.enabled = this.props.enabled || true;
|
|
11
18
|
this.host = this.props.host || '127.0.0.1';
|
|
12
19
|
this.port = this.props.port || 10000;
|
|
@@ -19,46 +26,66 @@ class TcpSocketPort {
|
|
|
19
26
|
}
|
|
20
27
|
flush() {
|
|
21
28
|
}
|
|
22
|
-
open() {
|
|
29
|
+
open(retry = false) {
|
|
23
30
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
if (!retry) {
|
|
32
|
+
this.id = Date.now();
|
|
33
|
+
this.socket.on('timeout', () => { this.onTimeout(); });
|
|
34
|
+
this.socket.on('connect', () => { this.onConnect(); });
|
|
35
|
+
this.socket.on('error', (err) => { this.onError(err); });
|
|
36
|
+
this.socket.on('ready', () => {
|
|
37
|
+
this.logger.logEvent({ message: 'ready' });
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
this.logger.logEvent({ message: 'opening', id: this.id, retry });
|
|
41
|
+
console.log('~~opening socket', this.id);
|
|
32
42
|
this.socket.connect(this.port, this.host);
|
|
33
43
|
}
|
|
34
44
|
catch (err) {
|
|
45
|
+
this.logger.logEvent({ message: 'opening error', id: this.id, error: err.message, stack: err.stack });
|
|
46
|
+
console.log('~~open socket error', this.id, err);
|
|
35
47
|
this.emit('error', err);
|
|
36
48
|
}
|
|
37
49
|
}
|
|
38
50
|
close() {
|
|
51
|
+
this.logger.logEvent({ message: 'closing', id: this.id });
|
|
52
|
+
console.log('~~closing socket', this.id);
|
|
39
53
|
this.isOpen = false;
|
|
40
54
|
this.isClosed = true;
|
|
41
55
|
try {
|
|
42
|
-
this.socket.
|
|
56
|
+
this.socket.removeAllListeners();
|
|
43
57
|
this.socket.destroy();
|
|
44
|
-
this.socket.on('timeout', () => { });
|
|
45
|
-
this.socket.on('connect', () => { });
|
|
46
58
|
this.socket.on('error', () => { });
|
|
47
|
-
this.socket.on('ready', () => { });
|
|
48
59
|
}
|
|
49
60
|
catch (err) {
|
|
61
|
+
console.log(err);
|
|
50
62
|
}
|
|
51
63
|
this.emit('close');
|
|
52
|
-
setTimeout(() => { this.
|
|
64
|
+
setTimeout(() => { this.removeAllListeners(); }, 100);
|
|
53
65
|
}
|
|
54
66
|
onTimeout() {
|
|
67
|
+
if (this.isOpen)
|
|
68
|
+
return;
|
|
69
|
+
this.logger.logEvent({ message: 'timeout', id: this.id });
|
|
70
|
+
console.log('~~socket timeout', this.id);
|
|
71
|
+
try {
|
|
72
|
+
this.socket.end();
|
|
73
|
+
}
|
|
74
|
+
catch (_a) { }
|
|
55
75
|
if (this.isClosed)
|
|
56
76
|
return;
|
|
77
|
+
this.emit('error', new Error('timeout'));
|
|
57
78
|
}
|
|
58
79
|
onConnect() {
|
|
80
|
+
this.logger.logEvent({ message: 'connected', id: this.id });
|
|
81
|
+
console.log('~~socket connected', this.id);
|
|
82
|
+
this.isOpen = true;
|
|
59
83
|
this.isClosed = false;
|
|
84
|
+
this.emit('open');
|
|
60
85
|
}
|
|
61
86
|
onError(err) {
|
|
87
|
+
this.logger.logEvent({ message: 'error', error: err.message });
|
|
88
|
+
console.log('~~socket error', this.id, err);
|
|
62
89
|
if (this.callbacks['error'])
|
|
63
90
|
this.callbacks['error'](err);
|
|
64
91
|
}
|
|
@@ -69,6 +96,9 @@ class TcpSocketPort {
|
|
|
69
96
|
}
|
|
70
97
|
this.socket.on(event, callback);
|
|
71
98
|
}
|
|
99
|
+
removeAllListeners() {
|
|
100
|
+
this.callbacks = {};
|
|
101
|
+
}
|
|
72
102
|
emit(event, ...args) {
|
|
73
103
|
if (event === 'open' || event === 'close' || event === 'error') {
|
|
74
104
|
if (this.callbacks[event])
|
|
@@ -86,15 +116,15 @@ class TcpSocketPort {
|
|
|
86
116
|
return this.socket.pipe(transformer);
|
|
87
117
|
}
|
|
88
118
|
static setResponse(command, fn) {
|
|
89
|
-
if (!
|
|
119
|
+
if (!__responses)
|
|
90
120
|
this.reset();
|
|
91
|
-
|
|
121
|
+
__responses[command] = fn;
|
|
92
122
|
}
|
|
93
123
|
static getReponseHandler(command) {
|
|
94
|
-
return
|
|
124
|
+
return __responses[command];
|
|
95
125
|
}
|
|
96
126
|
static reset() {
|
|
97
|
-
|
|
127
|
+
__responses = {};
|
|
98
128
|
}
|
|
99
129
|
}
|
|
100
130
|
exports.default = TcpSocketPort;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare function bin2esc(arr: any): any[];
|
|
2
2
|
export declare function esc2bin(arr: any): any[];
|
|
3
3
|
export declare function checkSum(cmdArr: any, payload: any): string;
|
|
4
|
-
export declare function buildMessage(command: any, payload
|
|
4
|
+
export declare function buildMessage(command: any, payload?: any): any[];
|
|
5
5
|
export declare function getMessageData(command: any): any[];
|
|
6
|
-
export declare function hexstr(arr: any, start
|
|
6
|
+
export declare function hexstr(arr: any, start?: any, len?: any): string;
|
|
7
7
|
export declare function getHex(i: any): string;
|
|
8
8
|
export declare function append(cmd: any, arr: any): void;
|
|
9
9
|
export declare function ascii(c: any): any;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import DeviceProtocolBase, { DeviceSettings } from '../DeviceProtocol';
|
|
2
|
+
import DeviceAdapter from '../Device';
|
|
3
3
|
import { EventLogger } from 'gd-eventlog';
|
|
4
|
-
export declare class Simulator extends
|
|
4
|
+
export declare class Simulator extends DeviceAdapter {
|
|
5
5
|
static NAME: string;
|
|
6
6
|
logger: EventLogger;
|
|
7
7
|
speed: number;
|
|
@@ -14,26 +14,32 @@ export declare class Simulator extends Device {
|
|
|
14
14
|
slope: number;
|
|
15
15
|
limit: any;
|
|
16
16
|
startProps?: any;
|
|
17
|
-
constructor(protocol
|
|
17
|
+
constructor(protocol?: any);
|
|
18
|
+
isBike(): boolean;
|
|
19
|
+
isHrm(): boolean;
|
|
20
|
+
isPower(): boolean;
|
|
21
|
+
getID(): string;
|
|
18
22
|
getName(): string;
|
|
19
23
|
getPort(): string;
|
|
20
24
|
start(props?: any): Promise<unknown>;
|
|
21
25
|
stop(): Promise<boolean>;
|
|
22
26
|
pause(): Promise<boolean>;
|
|
27
|
+
resume(): Promise<boolean>;
|
|
23
28
|
toggle(): Promise<boolean>;
|
|
24
29
|
faster(): void;
|
|
25
30
|
slower(): void;
|
|
26
31
|
update(): void;
|
|
27
32
|
calculateDistance(speedKps: any, timeS: any): number;
|
|
28
|
-
sendUpdate(request: any):
|
|
33
|
+
sendUpdate(request: any): any;
|
|
29
34
|
}
|
|
30
|
-
export default class SimulatorProtocol extends
|
|
35
|
+
export default class SimulatorProtocol extends DeviceProtocolBase {
|
|
31
36
|
static NAME: string;
|
|
32
37
|
constructor();
|
|
38
|
+
add(settings: DeviceSettings): void;
|
|
33
39
|
getName(): string;
|
|
34
40
|
getInterfaces(): string[];
|
|
35
41
|
isBike(): boolean;
|
|
36
42
|
isHrm(): boolean;
|
|
37
43
|
isPower(): boolean;
|
|
38
|
-
getDevices():
|
|
44
|
+
getDevices(): import("../DeviceProtocol").Device[];
|
|
39
45
|
}
|
|
@@ -1,11 +1,33 @@
|
|
|
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
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
2
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
25
|
exports.Simulator = void 0;
|
|
4
|
-
const DeviceProtocol_1 = require("../DeviceProtocol");
|
|
5
|
-
const DeviceRegistry_1 = require("../DeviceRegistry");
|
|
6
|
-
const Device_1 = require("../Device");
|
|
26
|
+
const DeviceProtocol_1 = __importStar(require("../DeviceProtocol"));
|
|
27
|
+
const DeviceRegistry_1 = __importDefault(require("../DeviceRegistry"));
|
|
28
|
+
const Device_1 = __importDefault(require("../Device"));
|
|
7
29
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
8
|
-
const calculations_1 = require("../calculations");
|
|
30
|
+
const calculations_1 = __importDefault(require("../calculations"));
|
|
9
31
|
class Simulator extends Device_1.default {
|
|
10
32
|
constructor(protocol) {
|
|
11
33
|
const proto = protocol || DeviceRegistry_1.default.findByName('Simulator');
|
|
@@ -21,12 +43,12 @@ class Simulator extends Device_1.default {
|
|
|
21
43
|
this.slope = 0;
|
|
22
44
|
this.limit = {};
|
|
23
45
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
46
|
+
isBike() { return true; }
|
|
47
|
+
isHrm() { return false; }
|
|
48
|
+
isPower() { return true; }
|
|
49
|
+
getID() { return Simulator.NAME; }
|
|
50
|
+
getName() { return Simulator.NAME; }
|
|
51
|
+
getPort() { return 'local'; }
|
|
30
52
|
start(props) {
|
|
31
53
|
this.startProps = props;
|
|
32
54
|
return new Promise((resolve) => {
|
|
@@ -50,24 +72,30 @@ class Simulator extends Device_1.default {
|
|
|
50
72
|
return new Promise((resolve, reject) => {
|
|
51
73
|
this.logger.logEvent({ message: 'stop', iv: this.iv });
|
|
52
74
|
this.started = false;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.iv = undefined;
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
this.logger.logEvent({ message: 'stop Error', error: err.message });
|
|
59
|
-
}
|
|
75
|
+
clearInterval(this.iv);
|
|
76
|
+
this.iv = undefined;
|
|
60
77
|
this.paused = undefined;
|
|
61
78
|
resolve(true);
|
|
62
79
|
});
|
|
63
80
|
}
|
|
64
81
|
pause() {
|
|
65
82
|
return new Promise((resolve, reject) => {
|
|
83
|
+
if (!this.started)
|
|
84
|
+
return reject(new Error('illegal state - pause() has been called before start()'));
|
|
66
85
|
this.logger.logEvent({ message: 'pause', iv: this.iv });
|
|
67
86
|
this.paused = true;
|
|
68
87
|
resolve(true);
|
|
69
88
|
});
|
|
70
89
|
}
|
|
90
|
+
resume() {
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
if (!this.started)
|
|
93
|
+
reject(new Error('illegal state - resume() has been called before start()'));
|
|
94
|
+
this.logger.logEvent({ message: 'resume', iv: this.iv });
|
|
95
|
+
this.paused = false;
|
|
96
|
+
resolve(true);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
71
99
|
toggle() {
|
|
72
100
|
if (this.started) {
|
|
73
101
|
return this.stop();
|
|
@@ -108,18 +136,22 @@ class Simulator extends Device_1.default {
|
|
|
108
136
|
if (this.speed === undefined)
|
|
109
137
|
this.speed = 30;
|
|
110
138
|
this.power = calculations_1.default.calculatePower(75, this.speed / 3.6, this.slope);
|
|
139
|
+
if (this.limit.targetPower) {
|
|
140
|
+
this.power = this.limit.targetPower;
|
|
141
|
+
this.speed = calculations_1.default.calculateSpeed(75, this.power, this.slope);
|
|
142
|
+
}
|
|
111
143
|
if (this.limit.maxPower && this.power > this.limit.maxPower) {
|
|
112
144
|
this.power = this.limit.maxPower;
|
|
113
145
|
this.speed = calculations_1.default.calculateSpeed(75, this.power, this.slope);
|
|
114
146
|
}
|
|
115
|
-
if (this.limit.minPower && this.power < this.limit.minPower) {
|
|
147
|
+
else if (this.limit.minPower && this.power < this.limit.minPower) {
|
|
116
148
|
this.power = this.limit.minPower;
|
|
117
149
|
this.speed = calculations_1.default.calculateSpeed(75, this.power, this.slope);
|
|
118
150
|
}
|
|
119
151
|
let distance = this.calculateDistance(this.speed, timespan / 1000);
|
|
120
152
|
let data = { speed: this.speed, cadence: Math.round(this.cadence), power: Math.round(this.power), timespan, distance };
|
|
121
|
-
if (this.
|
|
122
|
-
this.
|
|
153
|
+
if (this.onDataFn) {
|
|
154
|
+
this.onDataFn(data);
|
|
123
155
|
}
|
|
124
156
|
}
|
|
125
157
|
calculateDistance(speedKps, timeS) {
|
|
@@ -127,7 +159,14 @@ class Simulator extends Device_1.default {
|
|
|
127
159
|
}
|
|
128
160
|
sendUpdate(request) {
|
|
129
161
|
this.logger.logEvent({ message: 'bike update request', request });
|
|
130
|
-
|
|
162
|
+
const r = request || { refresh: true };
|
|
163
|
+
if (r.refresh) {
|
|
164
|
+
if (Object.keys(r).length === 1)
|
|
165
|
+
return this.limit;
|
|
166
|
+
delete r.refresh;
|
|
167
|
+
}
|
|
168
|
+
this.limit = r;
|
|
169
|
+
return this.limit;
|
|
131
170
|
}
|
|
132
171
|
}
|
|
133
172
|
exports.Simulator = Simulator;
|
|
@@ -137,6 +176,8 @@ class SimulatorProtocol extends DeviceProtocol_1.default {
|
|
|
137
176
|
super();
|
|
138
177
|
this.devices.push(new Simulator(this));
|
|
139
178
|
}
|
|
179
|
+
add(settings) {
|
|
180
|
+
}
|
|
140
181
|
getName() {
|
|
141
182
|
return SimulatorProtocol.NAME;
|
|
142
183
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export declare const sleep: (
|
|
1
|
+
export declare const sleep: (ms: any) => Promise<unknown>;
|
|
2
2
|
export declare function runWithRetries(fn: any, maxRetries: any, timeBetween: any): Promise<unknown>;
|
|
3
|
+
export declare function floatVal(d?: number | string): number;
|
|
4
|
+
export declare function intVal(d?: number | string): number;
|
|
3
5
|
export declare function hexstr(arr: any, start?: any, len?: any): string;
|
|
4
6
|
export declare class Queue<T> {
|
|
5
7
|
data: Array<T>;
|
package/lib/utils.js
CHANGED
|
@@ -9,10 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Queue = exports.hexstr = exports.runWithRetries = exports.sleep = void 0;
|
|
13
|
-
|
|
14
|
-
return new Promise(
|
|
12
|
+
exports.Queue = exports.hexstr = exports.intVal = exports.floatVal = exports.runWithRetries = exports.sleep = void 0;
|
|
13
|
+
const sleep = (ms) => {
|
|
14
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
15
15
|
};
|
|
16
|
+
exports.sleep = sleep;
|
|
16
17
|
function runWithRetries(fn, maxRetries, timeBetween) {
|
|
17
18
|
return new Promise((resolve, reject) => {
|
|
18
19
|
let retries = 0;
|
|
@@ -32,34 +33,54 @@ function runWithRetries(fn, maxRetries, timeBetween) {
|
|
|
32
33
|
}
|
|
33
34
|
catch (err) {
|
|
34
35
|
tLastFailure = Date.now();
|
|
35
|
-
busy = false;
|
|
36
36
|
retries++;
|
|
37
|
-
if (retries
|
|
37
|
+
if (retries >= maxRetries) {
|
|
38
38
|
clearInterval(iv);
|
|
39
|
+
busy = false;
|
|
39
40
|
return reject(err);
|
|
40
41
|
}
|
|
42
|
+
else {
|
|
43
|
+
busy = false;
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
}), 50);
|
|
44
48
|
});
|
|
45
49
|
}
|
|
46
50
|
exports.runWithRetries = runWithRetries;
|
|
51
|
+
function floatVal(d) {
|
|
52
|
+
if (d === undefined)
|
|
53
|
+
return;
|
|
54
|
+
if (typeof d === 'number')
|
|
55
|
+
return d;
|
|
56
|
+
const res = parseFloat(d);
|
|
57
|
+
return isNaN(res) ? undefined : res;
|
|
58
|
+
}
|
|
59
|
+
exports.floatVal = floatVal;
|
|
60
|
+
function intVal(d) {
|
|
61
|
+
if (d === undefined)
|
|
62
|
+
return;
|
|
63
|
+
if (typeof d === 'number')
|
|
64
|
+
return Math.floor(d);
|
|
65
|
+
const res = parseInt(d);
|
|
66
|
+
return isNaN(res) ? undefined : res;
|
|
67
|
+
}
|
|
68
|
+
exports.intVal = intVal;
|
|
47
69
|
function hexstr(arr, start, len) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (len - start > arr.length) {
|
|
55
|
-
len = arr.length - start;
|
|
70
|
+
let str = "";
|
|
71
|
+
const startIdx = start || 0;
|
|
72
|
+
const length = len || arr.length;
|
|
73
|
+
let endIdx = startIdx + length;
|
|
74
|
+
if (endIdx >= arr.length) {
|
|
75
|
+
endIdx = arr.length;
|
|
56
76
|
}
|
|
57
|
-
|
|
58
|
-
for (var i =
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
str +=
|
|
77
|
+
let added = 0;
|
|
78
|
+
for (var i = startIdx; i < endIdx; i++) {
|
|
79
|
+
const hex = Math.abs(arr[i]).toString(16).toUpperCase();
|
|
80
|
+
if (added !== 0)
|
|
81
|
+
str += ' ';
|
|
62
82
|
str += hex;
|
|
83
|
+
added++;
|
|
63
84
|
}
|
|
64
85
|
return str;
|
|
65
86
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-devices",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.25",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@serialport/parser-byte-length": "^9.0.1",
|
|
6
6
|
"@serialport/parser-delimiter": "^9.0.1",
|
|
7
|
-
"@types/serialport": "^8.0.1"
|
|
7
|
+
"@types/serialport": "^8.0.1",
|
|
8
|
+
"gd-ant-plus": "^0.0.33"
|
|
8
9
|
},
|
|
9
10
|
"peerDependencies": {
|
|
10
|
-
"gd-eventlog": "^0.1.
|
|
11
|
+
"gd-eventlog": "^0.1.22"
|
|
11
12
|
},
|
|
12
13
|
"devDependencies": {
|
|
13
|
-
"@types/jest": "^
|
|
14
|
-
"@types/node": "^10.
|
|
15
|
-
"eslint": "^
|
|
16
|
-
"eslint-config-react-app": "^
|
|
17
|
-
"eslint-loader": "
|
|
18
|
-
"jest": "^
|
|
19
|
-
"ts-jest": "^
|
|
20
|
-
"typescript": "^
|
|
14
|
+
"@types/jest": "^27.0.3",
|
|
15
|
+
"@types/node": "^10.17.58",
|
|
16
|
+
"eslint": "^7.32.0",
|
|
17
|
+
"eslint-config-react-app": "^6.0.0",
|
|
18
|
+
"eslint-loader": "^4.0.2",
|
|
19
|
+
"jest": "^27.4.3",
|
|
20
|
+
"ts-jest": "^27.1.0",
|
|
21
|
+
"typescript": "^4.5.2"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
24
|
"build": "tsc",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const AntScanner_1 = require("./AntScanner");
|
|
4
|
-
const TestData = [
|
|
5
|
-
{ "busNumber": 2, "deviceAddress": 3, "deviceDescriptor": { "bLength": 18, "bDescriptorType": 1, "bcdUSB": 512, "bDeviceClass": 0, "bDeviceSubClass": 0, "bDeviceProtocol": 0, "bMaxPacketSize0": 32, "idVendor": 4047, "idProduct": 4104, "bcdDevice": 256, "iManufacturer": 1, "iProduct": 2, "iSerialNumber": 3, "bNumConfigurations": 1 }, "portNumbers": [1, 2], "inUse": false },
|
|
6
|
-
{ "busNumber": 1, "deviceAddress": 5, "deviceDescriptor": { "bLength": 18, "bDescriptorType": 1, "bcdUSB": 512, "bDeviceClass": 0, "bDeviceSubClass": 0, "bDeviceProtocol": 0, "bMaxPacketSize0": 8, "idVendor": 1133, "idProduct": 49174, "bcdDevice": 832, "iManufacturer": 1, "iProduct": 2, "iSerialNumber": 0, "bNumConfigurations": 1 }, "portNumbers": [1], "inUse": false },
|
|
7
|
-
{ "busNumber": 2, "deviceAddress": 4, "deviceDescriptor": { "bLength": 18, "bDescriptorType": 1, "bcdUSB": 512, "bDeviceClass": 239, "bDeviceSubClass": 2, "bDeviceProtocol": 1, "bMaxPacketSize0": 64, "idVendor": 1266, "idProduct": 46094, "bcdDevice": 26937, "iManufacturer": 2, "iProduct": 1, "iSerialNumber": 0, "bNumConfigurations": 1 }, "portNumbers": [1, 3], "inUse": false },
|
|
8
|
-
{ "busNumber": 2, "deviceAddress": 5, "deviceDescriptor": { "bLength": 18, "bDescriptorType": 1, "bcdUSB": 528, "bDeviceClass": 224, "bDeviceSubClass": 1, "bDeviceProtocol": 1, "bMaxPacketSize0": 64, "idVendor": 3034, "idProduct": 45057, "bcdDevice": 512, "iManufacturer": 1, "iProduct": 2, "iSerialNumber": 3, "bNumConfigurations": 1 }, "portNumbers": [1, 7], "inUse": false },
|
|
9
|
-
{ "busNumber": 1, "deviceAddress": 9, "deviceDescriptor": { "bLength": 18, "bDescriptorType": 1, "bcdUSB": 512, "bDeviceClass": 0, "bDeviceSubClass": 0, "bDeviceProtocol": 0, "bMaxPacketSize0": 32, "idVendor": 4047, "idProduct": 4104, "bcdDevice": 256, "iManufacturer": 1, "iProduct": 2, "iSerialNumber": 3, "bNumConfigurations": 1 }, "portNumbers": [6], "inUse": false },
|
|
10
|
-
{ "busNumber": 2, "deviceAddress": 2, "deviceDescriptor": { "bLength": 18, "bDescriptorType": 1, "bcdUSB": 512, "bDeviceClass": 9, "bDeviceSubClass": 0, "bDeviceProtocol": 1, "bMaxPacketSize0": 64, "idVendor": 32903, "idProduct": 32768, "bcdDevice": 4, "iManufacturer": 0, "iProduct": 0, "iSerialNumber": 0, "bNumConfigurations": 1 }, "portNumbers": [1], "inUse": false },
|
|
11
|
-
{ "busNumber": 2, "deviceAddress": 1, "deviceDescriptor": { "bLength": 18, "bDescriptorType": 1, "bcdUSB": 0, "bDeviceClass": 9, "bDeviceSubClass": 0, "bDeviceProtocol": 0, "bMaxPacketSize0": 0, "idVendor": 32902, "idProduct": 39974, "bcdDevice": 0, "iManufacturer": 0, "iProduct": 0, "iSerialNumber": 0, "bNumConfigurations": 1 }, "inUse": false },
|
|
12
|
-
{ "busNumber": 1, "deviceAddress": 1, "deviceDescriptor": { "bLength": 18, "bDescriptorType": 1, "bcdUSB": 0, "bDeviceClass": 9, "bDeviceSubClass": 0, "bDeviceProtocol": 0, "bMaxPacketSize0": 0, "idVendor": 32902, "idProduct": 39985, "bcdDevice": 0, "iManufacturer": 0, "iProduct": 0, "iSerialNumber": 0, "bNumConfigurations": 1 }, "inUse": false }
|
|
13
|
-
];
|
|
14
|
-
class MockGarminStick2 {
|
|
15
|
-
}
|
|
16
|
-
class MockGarminStick3 {
|
|
17
|
-
}
|
|
18
|
-
class MockAnt {
|
|
19
|
-
static getSticks() { return TestData; }
|
|
20
|
-
}
|
|
21
|
-
describe('AntScanner', () => {
|
|
22
|
-
const scanner = AntScanner_1.AntScanner(MockAnt);
|
|
23
|
-
test('getSticks', () => {
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export default class AntFEProcessor {
|
|
2
|
-
static NAME: string;
|
|
3
|
-
static STATE: {
|
|
4
|
-
INITIALIZED: string;
|
|
5
|
-
STARTING: string;
|
|
6
|
-
START_OK: string;
|
|
7
|
-
START_FAILED: string;
|
|
8
|
-
ERROR: string;
|
|
9
|
-
FINISHING: string;
|
|
10
|
-
FINISH_OK: string;
|
|
11
|
-
FINISH_FAILED: string;
|
|
12
|
-
};
|
|
13
|
-
static isBike(): boolean;
|
|
14
|
-
static isHrm(): boolean;
|
|
15
|
-
constructor(controller: any, bikeInfo: any);
|
|
16
|
-
bikeInfo: any;
|
|
17
|
-
ignoreHrm: boolean;
|
|
18
|
-
instance: any;
|
|
19
|
-
paused: boolean;
|
|
20
|
-
started: boolean;
|
|
21
|
-
time: number;
|
|
22
|
-
iv: NodeJS.Timeout;
|
|
23
|
-
state: string;
|
|
24
|
-
data: {};
|
|
25
|
-
request: any;
|
|
26
|
-
setState(newState: any): void;
|
|
27
|
-
toggle(): void;
|
|
28
|
-
pause(): void;
|
|
29
|
-
setIgnoreHrm(ignore: any): void;
|
|
30
|
-
checkBikeStatus(): Promise<any>;
|
|
31
|
-
startTraining(): Promise<any>;
|
|
32
|
-
getBikeData(): Promise<any>;
|
|
33
|
-
sendBikeUpdate(request: any): Promise<any>;
|
|
34
|
-
onStarted(): void;
|
|
35
|
-
start(user: any): Promise<void>;
|
|
36
|
-
stop(): void;
|
|
37
|
-
update(): Promise<void>;
|
|
38
|
-
sendUpdate(data: any): Promise<void>;
|
|
39
|
-
onEvent(event: any): void | Promise<void>;
|
|
40
|
-
}
|