incyclist-devices 2.1.10 → 2.1.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/serial/base/comms.d.ts +2 -0
- package/lib/serial/base/comms.js +6 -0
- package/lib/serial/bindings/tcp.d.ts +6 -0
- package/lib/serial/bindings/tcp.js +23 -5
- package/lib/serial/daum/DaumAdapter.d.ts +11 -2
- package/lib/serial/daum/DaumAdapter.js +39 -10
- package/lib/serial/daum/premium/comms.d.ts +3 -0
- package/lib/serial/daum/premium/comms.js +11 -1
- package/lib/serial/daum/types.d.ts +2 -2
- package/package.json +1 -1
|
@@ -37,6 +37,8 @@ export default class SerialPortComms<T extends CommsState, C extends Request, R
|
|
|
37
37
|
isConnected(): boolean;
|
|
38
38
|
pauseLogging(): void;
|
|
39
39
|
resumeLogging(): void;
|
|
40
|
+
pause(): void;
|
|
41
|
+
resume(): void;
|
|
40
42
|
logEvent(e: any): void;
|
|
41
43
|
connect(): Promise<boolean>;
|
|
42
44
|
onConnected(): void;
|
package/lib/serial/base/comms.js
CHANGED
|
@@ -24,10 +24,16 @@ export declare class TCPPortBinding implements BindingPortInterface {
|
|
|
24
24
|
writeOperation: null | Promise<any>;
|
|
25
25
|
data: Buffer;
|
|
26
26
|
private pendingRead;
|
|
27
|
+
private onDataHandler;
|
|
28
|
+
private onErrorHandler;
|
|
29
|
+
private onTimeoutHandler;
|
|
30
|
+
private onCloseHandler;
|
|
27
31
|
constructor(socket: net.Socket, options: Required<OpenOptions>);
|
|
28
32
|
get isOpen(): boolean;
|
|
29
33
|
onData(data: Buffer): void;
|
|
30
34
|
onError(err: Error): void;
|
|
35
|
+
onTimeout(): void;
|
|
36
|
+
onClose(): void;
|
|
31
37
|
close(): Promise<void>;
|
|
32
38
|
read(buffer: Buffer, offset: number, length: number): Promise<{
|
|
33
39
|
buffer: Buffer;
|
|
@@ -141,6 +141,10 @@ exports.TCPBinding = {
|
|
|
141
141
|
};
|
|
142
142
|
class TCPPortBinding {
|
|
143
143
|
constructor(socket, options) {
|
|
144
|
+
this.onDataHandler = this.onData.bind(this);
|
|
145
|
+
this.onErrorHandler = this.onError.bind(this);
|
|
146
|
+
this.onTimeoutHandler = this.onTimeout.bind(this);
|
|
147
|
+
this.onCloseHandler = this.onClose.bind(this);
|
|
144
148
|
this.logger = new gd_eventlog_1.EventLogger('TCPPort');
|
|
145
149
|
this.socket = socket;
|
|
146
150
|
this.openOptions = options;
|
|
@@ -148,11 +152,11 @@ class TCPPortBinding {
|
|
|
148
152
|
this.writeOperation = null;
|
|
149
153
|
this.data = null;
|
|
150
154
|
this.socket.removeAllListeners();
|
|
151
|
-
this.socket.on('data', this.
|
|
152
|
-
this.socket.on('error', this.
|
|
153
|
-
this.socket.on('close',
|
|
154
|
-
this.socket.on('end',
|
|
155
|
-
this.socket.on('timeout',
|
|
155
|
+
this.socket.on('data', this.onDataHandler);
|
|
156
|
+
this.socket.on('error', this.onErrorHandler);
|
|
157
|
+
this.socket.on('close', this.onCloseHandler);
|
|
158
|
+
this.socket.on('end', this.onCloseHandler);
|
|
159
|
+
this.socket.on('timeout', this.onTimeoutHandler);
|
|
156
160
|
}
|
|
157
161
|
get isOpen() {
|
|
158
162
|
return this.socket !== null;
|
|
@@ -168,11 +172,21 @@ class TCPPortBinding {
|
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
onError(err) {
|
|
175
|
+
this.logger.logEvent({ message: 'Port Error', error: err.message });
|
|
171
176
|
if (this.pendingRead) {
|
|
172
177
|
this.pendingRead(err);
|
|
173
178
|
this.socket = null;
|
|
174
179
|
}
|
|
175
180
|
}
|
|
181
|
+
onTimeout() {
|
|
182
|
+
this.logger.logEvent({ message: 'Port Timeout' });
|
|
183
|
+
if (this.pendingRead) {
|
|
184
|
+
this.pendingRead(new Error('timeout'));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
onClose() {
|
|
188
|
+
this.close();
|
|
189
|
+
}
|
|
176
190
|
close() {
|
|
177
191
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
192
|
if (!this.isOpen)
|
|
@@ -217,6 +231,10 @@ class TCPPortBinding {
|
|
|
217
231
|
return new Promise((resolve, reject) => {
|
|
218
232
|
this.pendingRead = err => {
|
|
219
233
|
if (err) {
|
|
234
|
+
if (err.message === 'timeout') {
|
|
235
|
+
resolve({ buffer: Buffer.from([]), bytesRead: 0 });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
220
238
|
return reject(err);
|
|
221
239
|
}
|
|
222
240
|
this.read(buffer, offset, length).then(resolve, reject);
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
1
3
|
import { IncyclistAdapterData, ControllerConfig, IAdapter, DeviceProperties, IncyclistBikeData } from '../../types';
|
|
2
4
|
import { SerialDeviceSettings } from "../types";
|
|
3
5
|
import { DaumSerialComms } from './types';
|
|
4
6
|
import { SerialIncyclistDevice } from '../base/adapter';
|
|
5
7
|
import SerialInterface from '../base/serial-interface';
|
|
8
|
+
import EventEmitter from 'events';
|
|
6
9
|
export default class DaumAdapter<S extends SerialDeviceSettings, P extends DeviceProperties, C extends DaumSerialComms> extends SerialIncyclistDevice<P> {
|
|
7
10
|
protected static controllers: ControllerConfig;
|
|
8
11
|
comms: C;
|
|
9
12
|
distanceInternal: number;
|
|
10
13
|
deviceData: IncyclistBikeData;
|
|
11
14
|
requests: Array<any>;
|
|
12
|
-
iv:
|
|
15
|
+
iv: {
|
|
16
|
+
sync: NodeJS.Timeout;
|
|
17
|
+
update: NodeJS.Timeout;
|
|
18
|
+
emitter: EventEmitter;
|
|
19
|
+
stopRequested?: boolean;
|
|
20
|
+
};
|
|
13
21
|
tsPrevData: number;
|
|
14
22
|
adapterTime: number;
|
|
15
23
|
requestBusy: boolean;
|
|
@@ -35,7 +43,8 @@ export default class DaumAdapter<S extends SerialDeviceSettings, P extends Devic
|
|
|
35
43
|
start(props?: P): Promise<boolean>;
|
|
36
44
|
performStart(props?: P, isRelaunch?: boolean, wasPaused?: boolean): Promise<boolean>;
|
|
37
45
|
startUpdatePull(): void;
|
|
38
|
-
|
|
46
|
+
protected cleanupInterval(): void;
|
|
47
|
+
stopUpdatePull(): Promise<void>;
|
|
39
48
|
connect(): Promise<boolean>;
|
|
40
49
|
close(): Promise<boolean>;
|
|
41
50
|
verifyConnection(): Promise<void>;
|
|
@@ -18,6 +18,7 @@ const types_1 = require("../../types");
|
|
|
18
18
|
const adapter_1 = require("../base/adapter");
|
|
19
19
|
const daum_smarttrainer_1 = __importDefault(require("../../modes/daum-smarttrainer"));
|
|
20
20
|
const daum_power_1 = __importDefault(require("../../modes/daum-power"));
|
|
21
|
+
const events_1 = __importDefault(require("events"));
|
|
21
22
|
class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
22
23
|
constructor(settings, props) {
|
|
23
24
|
super(settings, props);
|
|
@@ -116,7 +117,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
116
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
118
|
yield this.stopUpdatePull();
|
|
118
119
|
const paused = yield _super.pause.call(this);
|
|
119
|
-
(_a = this.comms) === null || _a === void 0 ? void 0 : _a.
|
|
120
|
+
(_a = this.comms) === null || _a === void 0 ? void 0 : _a.pause();
|
|
120
121
|
return paused;
|
|
121
122
|
});
|
|
122
123
|
}
|
|
@@ -127,7 +128,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
127
128
|
var _a;
|
|
128
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
130
|
const resumed = yield _super.resume.call(this);
|
|
130
|
-
(_a = this.comms) === null || _a === void 0 ? void 0 : _a.
|
|
131
|
+
(_a = this.comms) === null || _a === void 0 ? void 0 : _a.resume();
|
|
131
132
|
if (startUpdatePull)
|
|
132
133
|
yield this.startUpdatePull();
|
|
133
134
|
return resumed;
|
|
@@ -247,17 +248,39 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
247
248
|
}, this.pullFrequency);
|
|
248
249
|
this.iv = {
|
|
249
250
|
sync: ivSync,
|
|
250
|
-
update: ivUpdate
|
|
251
|
+
update: ivUpdate,
|
|
252
|
+
emitter: new events_1.default()
|
|
251
253
|
};
|
|
254
|
+
this.iv.emitter.once('stop', () => {
|
|
255
|
+
this.iv.stopRequested = true;
|
|
256
|
+
});
|
|
252
257
|
}
|
|
253
|
-
|
|
258
|
+
cleanupInterval() {
|
|
254
259
|
if (!this.iv)
|
|
255
260
|
return;
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
261
|
+
if (this.iv.sync)
|
|
262
|
+
clearInterval(this.iv.sync);
|
|
263
|
+
if (this.iv.sync)
|
|
264
|
+
clearInterval(this.iv.update);
|
|
265
|
+
if (this.iv.emitter)
|
|
266
|
+
this.iv.emitter.removeAllListeners();
|
|
259
267
|
this.iv = undefined;
|
|
260
268
|
}
|
|
269
|
+
stopUpdatePull() {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
if (!this.iv || !this.iv.emitter)
|
|
272
|
+
return;
|
|
273
|
+
return new Promise(done => {
|
|
274
|
+
this.iv.emitter.on('stop-done', () => {
|
|
275
|
+
this.logEvent({ message: 'stop update pull done', port: this.getPort() });
|
|
276
|
+
this.cleanupInterval();
|
|
277
|
+
done();
|
|
278
|
+
});
|
|
279
|
+
this.iv.emitter.emit('stop');
|
|
280
|
+
this.logEvent({ message: 'stop update pull', port: this.getPort() });
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
261
284
|
connect() {
|
|
262
285
|
return __awaiter(this, void 0, void 0, function* () {
|
|
263
286
|
if (!this.comms)
|
|
@@ -321,7 +344,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
321
344
|
if (this.paused)
|
|
322
345
|
this.resume();
|
|
323
346
|
try {
|
|
324
|
-
this.stopUpdatePull();
|
|
347
|
+
yield this.stopUpdatePull();
|
|
325
348
|
yield this.comms.close();
|
|
326
349
|
this.logEvent({ message: 'stop request completed' });
|
|
327
350
|
this.stopped = true;
|
|
@@ -392,9 +415,15 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
392
415
|
});
|
|
393
416
|
}
|
|
394
417
|
bikeSync() {
|
|
418
|
+
var _a, _b, _c;
|
|
395
419
|
return __awaiter(this, void 0, void 0, function* () {
|
|
396
|
-
|
|
397
|
-
|
|
420
|
+
if (!((_a = this.iv) === null || _a === void 0 ? void 0 : _a.stopRequested))
|
|
421
|
+
yield this.sendRequests();
|
|
422
|
+
if (!((_b = this.iv) === null || _b === void 0 ? void 0 : _b.stopRequested))
|
|
423
|
+
yield this.update();
|
|
424
|
+
if ((_c = this.iv) === null || _c === void 0 ? void 0 : _c.stopRequested) {
|
|
425
|
+
this.iv.emitter.emit('stop-done', 'bikeSync');
|
|
426
|
+
}
|
|
398
427
|
});
|
|
399
428
|
}
|
|
400
429
|
updateData(bikeData) {
|
|
@@ -5,6 +5,7 @@ import { DaumSerialComms } from "../types";
|
|
|
5
5
|
import { OnDeviceStartCallback, DaumPremiumCommsState, DaumPremiumRequest, ResponseObject, Route } from "./types";
|
|
6
6
|
import SerialPortComms from "../../base/comms";
|
|
7
7
|
export default class Daum8i extends SerialPortComms<DaumPremiumCommsState, DaumPremiumRequest, ResponseObject> implements DaumSerialComms {
|
|
8
|
+
private onDataHandler;
|
|
8
9
|
validatePath(path: string): string;
|
|
9
10
|
getDefaultLoggerName(): string;
|
|
10
11
|
getAckTimeoutValue(): number;
|
|
@@ -43,4 +44,6 @@ export default class Daum8i extends SerialPortComms<DaumPremiumCommsState, DaumP
|
|
|
43
44
|
programUploadDone(): Promise<boolean>;
|
|
44
45
|
startProgram(programId?: number): Promise<boolean>;
|
|
45
46
|
programUpload(bikeType: string, route: Route, onStatusUpdate?: OnDeviceStartCallback): Promise<boolean>;
|
|
47
|
+
pause(): void;
|
|
48
|
+
resume(): void;
|
|
46
49
|
}
|
|
@@ -20,6 +20,10 @@ const utils_2 = require("../../../utils/utils");
|
|
|
20
20
|
const comms_1 = __importDefault(require("../../base/comms"));
|
|
21
21
|
const consts_1 = require("./consts");
|
|
22
22
|
class Daum8i extends comms_1.default {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.onDataHandler = this.onData.bind(this);
|
|
26
|
+
}
|
|
23
27
|
validatePath(path) {
|
|
24
28
|
return (0, utils_1.validatePath)(path);
|
|
25
29
|
}
|
|
@@ -33,7 +37,7 @@ class Daum8i extends comms_1.default {
|
|
|
33
37
|
return consts_1.DEFAULT_TIMEOUT;
|
|
34
38
|
}
|
|
35
39
|
onConnected() {
|
|
36
|
-
this.sp.on('data', this.
|
|
40
|
+
this.sp.on('data', this.onDataHandler);
|
|
37
41
|
}
|
|
38
42
|
getInitialCommsState() {
|
|
39
43
|
const state = super.getInitialCommsState();
|
|
@@ -574,5 +578,11 @@ class Daum8i extends comms_1.default {
|
|
|
574
578
|
}
|
|
575
579
|
});
|
|
576
580
|
}
|
|
581
|
+
pause() {
|
|
582
|
+
super.pause();
|
|
583
|
+
}
|
|
584
|
+
resume() {
|
|
585
|
+
super.resume();
|
|
586
|
+
}
|
|
577
587
|
}
|
|
578
588
|
exports.default = Daum8i;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare abstract class DaumSerialComms {
|
|
2
2
|
serial: any;
|
|
3
3
|
abstract getPort(): string;
|
|
4
|
-
abstract
|
|
5
|
-
abstract
|
|
4
|
+
abstract pause(): void;
|
|
5
|
+
abstract resume(): void;
|
|
6
6
|
abstract isConnected(): boolean;
|
|
7
7
|
abstract connect(): Promise<boolean>;
|
|
8
8
|
abstract close(): Promise<boolean>;
|