incyclist-devices 2.1.14 → 2.1.15
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.
|
@@ -58,6 +58,7 @@ export default class SerialPortComms<T extends CommsState, C extends Request, R
|
|
|
58
58
|
onData(data: any, depth?: number): Promise<void>;
|
|
59
59
|
send(command: C): Promise<R>;
|
|
60
60
|
portWrite(buffer: Buffer): Promise<void>;
|
|
61
|
+
portRead(size?: number): Promise<any>;
|
|
61
62
|
write(buffer: Buffer): Promise<void>;
|
|
62
63
|
ensurePrevCmdFinish(logPayload: any): Promise<void>;
|
|
63
64
|
ensureConnection(): Promise<void>;
|
package/lib/serial/base/comms.js
CHANGED
|
@@ -240,6 +240,15 @@ class SerialPortComms {
|
|
|
240
240
|
}
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
|
+
portRead(size) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
if (!this.sp) {
|
|
246
|
+
this.logEvent({ message: 'write failed', error: 'port is not opened' });
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
return yield this.sp.read(size);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
243
252
|
write(buffer) {
|
|
244
253
|
return __awaiter(this, void 0, void 0, function* () {
|
|
245
254
|
if (this.writePromise) {
|
|
@@ -105,21 +105,22 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
105
105
|
if (!isRelaunch && !this.getComms().isConnected()) {
|
|
106
106
|
yield this.verifyConnection();
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
if (!wasPaused)
|
|
109
|
+
yield this.getComms().resetDevice();
|
|
110
|
+
if (!wasPaused && !startState.setProg) {
|
|
110
111
|
yield this.getComms().setProg(0);
|
|
111
112
|
startState.setProg = true;
|
|
112
113
|
}
|
|
113
|
-
if (!startState.setPerson) {
|
|
114
|
+
if (!wasPaused && !startState.setPerson) {
|
|
114
115
|
yield this.getComms().setPerson(user);
|
|
115
116
|
startState.setPerson = true;
|
|
116
117
|
}
|
|
117
|
-
if (!startState.setBikeType) {
|
|
118
|
+
if (!wasPaused && !startState.setBikeType) {
|
|
118
119
|
const bikeType = this.getCyclingMode().getSetting('bikeType') || 'race';
|
|
119
120
|
yield this.getComms().setBikeType(bikeType.toLowerCase());
|
|
120
121
|
startState.setBikeType = true;
|
|
121
122
|
}
|
|
122
|
-
if (!startState.startProg) {
|
|
123
|
+
if (!wasPaused && !startState.startProg) {
|
|
123
124
|
yield this.getComms().startProg();
|
|
124
125
|
startState.startProg = true;
|
|
125
126
|
}
|
|
@@ -6,6 +6,7 @@ import { DeviceType, IncyclistBikeData, User } from '../../../types';
|
|
|
6
6
|
export default class Daum8008 extends SerialPortComms<DaumClassicCommsState, DaumClassicRequest, DaumClassicResponse> implements DaumSerialComms {
|
|
7
7
|
protected bikeNo: number;
|
|
8
8
|
protected prevFailedPayload: any;
|
|
9
|
+
protected expected: any;
|
|
9
10
|
constructor(props: SerialCommProps);
|
|
10
11
|
validatePath(path: string): string;
|
|
11
12
|
getDefaultLoggerName(): string;
|
|
@@ -22,6 +22,7 @@ class Daum8008 extends comms_1.default {
|
|
|
22
22
|
constructor(props) {
|
|
23
23
|
super(props);
|
|
24
24
|
this.bikeNo = 0;
|
|
25
|
+
this.expected = undefined;
|
|
25
26
|
}
|
|
26
27
|
validatePath(path) {
|
|
27
28
|
return path;
|
|
@@ -36,19 +37,7 @@ class Daum8008 extends comms_1.default {
|
|
|
36
37
|
}
|
|
37
38
|
initForResponse(expected) {
|
|
38
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
|
|
40
|
-
if (!parser)
|
|
41
|
-
return;
|
|
42
|
-
const onDataHandler = (data) => {
|
|
43
|
-
if (data.length < expected) {
|
|
44
|
-
this.logEvent({ message: 'Partial response', data: Buffer.from(data).toString('hex') });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this.portUnpipe();
|
|
48
|
-
parser.off('data', onDataHandler);
|
|
49
|
-
this.recvState.data.enqueue({ type: 'Response', data });
|
|
50
|
-
};
|
|
51
|
-
parser.on('data', onDataHandler);
|
|
40
|
+
this.expected = expected;
|
|
52
41
|
});
|
|
53
42
|
}
|
|
54
43
|
waitForResponse() {
|
|
@@ -58,10 +47,9 @@ class Daum8008 extends comms_1.default {
|
|
|
58
47
|
let start = Date.now();
|
|
59
48
|
let tsTimeout = start + timeout;
|
|
60
49
|
while (waitingForResponse && Date.now() < tsTimeout) {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
64
|
-
}
|
|
50
|
+
const data = yield this.portRead(this.expected);
|
|
51
|
+
if (data)
|
|
52
|
+
return { type: 'Response', data };
|
|
65
53
|
yield (0, utils_1.sleep)(5);
|
|
66
54
|
}
|
|
67
55
|
throw new types_1.ResponseTimeout();
|