incyclist-devices 2.1.13 → 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.
- package/lib/serial/base/comms.d.ts +1 -0
- package/lib/serial/base/comms.js +9 -0
- package/lib/serial/base/serial-interface.js +2 -3
- package/lib/serial/daum/classic/adapter.js +6 -5
- package/lib/serial/daum/classic/comms.d.ts +1 -0
- package/lib/serial/daum/classic/comms.js +5 -11
- package/lib/serial/daum/classic/mock.d.ts +3 -1
- package/lib/serial/daum/classic/mock.js +27 -3
- package/package.json +1 -1
|
@@ -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) {
|
|
@@ -208,8 +208,7 @@ class SerialInterface extends events_1.default {
|
|
|
208
208
|
if (attemptNo === 0)
|
|
209
209
|
this.logEvent({ message: 'checking for ports', interface: this.ifaceName, port, excludes: this.inUse });
|
|
210
210
|
else
|
|
211
|
-
|
|
212
|
-
attemptNo++;
|
|
211
|
+
attemptNo++;
|
|
213
212
|
try {
|
|
214
213
|
if (isTcpip) {
|
|
215
214
|
const _binding = binding;
|
|
@@ -223,7 +222,7 @@ class SerialInterface extends events_1.default {
|
|
|
223
222
|
this.logEvent({ message: 'error', fn: 'scan#detect ports', error: err.message, interface: this.ifaceName, port, excludes: this.inUse });
|
|
224
223
|
}
|
|
225
224
|
paths = paths.filter(p => !this.inUse.includes(p.path));
|
|
226
|
-
if (!paths || paths.length === 0) {
|
|
225
|
+
if ((!paths || paths.length === 0) && attemptNo === 1) {
|
|
227
226
|
this.logEvent({ message: 'scanning: no ports detected', interface: this.ifaceName, paths: paths.map(p => p.path), timeout });
|
|
228
227
|
yield (0, utils_1.sleep)(1000);
|
|
229
228
|
}
|
|
@@ -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,13 +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
|
-
parser.on('data', (data) => {
|
|
43
|
-
this.portUnpipe();
|
|
44
|
-
this.recvState.data.enqueue({ type: 'Response', data });
|
|
45
|
-
});
|
|
40
|
+
this.expected = expected;
|
|
46
41
|
});
|
|
47
42
|
}
|
|
48
43
|
waitForResponse() {
|
|
@@ -52,10 +47,9 @@ class Daum8008 extends comms_1.default {
|
|
|
52
47
|
let start = Date.now();
|
|
53
48
|
let tsTimeout = start + timeout;
|
|
54
49
|
while (waitingForResponse && Date.now() < tsTimeout) {
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
return
|
|
58
|
-
}
|
|
50
|
+
const data = yield this.portRead(this.expected);
|
|
51
|
+
if (data)
|
|
52
|
+
return { type: 'Response', data };
|
|
59
53
|
yield (0, utils_1.sleep)(5);
|
|
60
54
|
}
|
|
61
55
|
throw new types_1.ResponseTimeout();
|
|
@@ -66,12 +66,14 @@ export declare class DaumClassicSimulator {
|
|
|
66
66
|
_timeoutResponse: number;
|
|
67
67
|
_simulateNoReponseCnt: number;
|
|
68
68
|
_simulateIllegalResponseCnt: number;
|
|
69
|
+
_simulatePartialDelayed: number;
|
|
69
70
|
openHandles: Array<NodeJS.Timeout>;
|
|
70
71
|
constructor();
|
|
71
72
|
reset(): void;
|
|
72
73
|
simulateTimeout(ms: number): void;
|
|
73
74
|
simulateNoResponse(cnt?: number): void;
|
|
74
75
|
simulateIllegalResponse(cnt?: number): void;
|
|
76
|
+
simulatePartialDelayed(cnt?: number): void;
|
|
75
77
|
addHandle(handle: NodeJS.Timeout): void;
|
|
76
78
|
cleanup(): void;
|
|
77
79
|
isPedalling(): 0 | 1;
|
|
@@ -84,7 +86,7 @@ export declare class DaumClassicMockBinding extends MockPortBinding {
|
|
|
84
86
|
getPath(): string;
|
|
85
87
|
initHandlers(): void;
|
|
86
88
|
write(buffer: Buffer): Promise<void>;
|
|
87
|
-
emitData(data: string | Buffer): void
|
|
89
|
+
emitData(data: string | Buffer): Promise<void>;
|
|
88
90
|
onCheckCockpit(payload: Buffer): void;
|
|
89
91
|
onGetAddress(_payload: Buffer): void;
|
|
90
92
|
onGetVersion(payload: Buffer): void;
|
|
@@ -91,6 +91,7 @@ class DaumClassicSimulator {
|
|
|
91
91
|
this._timeoutResponse = 0;
|
|
92
92
|
this._simulateNoReponseCnt = 0;
|
|
93
93
|
this._simulateIllegalResponseCnt = 0;
|
|
94
|
+
this._simulatePartialDelayed = 0;
|
|
94
95
|
this.openHandles = [];
|
|
95
96
|
for (let i = 0; i < 10; i++)
|
|
96
97
|
this.bikes.push(Object.assign({}, DEFAULT_BIKE_DATA));
|
|
@@ -119,6 +120,9 @@ class DaumClassicSimulator {
|
|
|
119
120
|
simulateIllegalResponse(cnt = 1) {
|
|
120
121
|
this._simulateIllegalResponseCnt += cnt;
|
|
121
122
|
}
|
|
123
|
+
simulatePartialDelayed(cnt = 1) {
|
|
124
|
+
this._simulatePartialDelayed += cnt;
|
|
125
|
+
}
|
|
122
126
|
addHandle(handle) {
|
|
123
127
|
this.openHandles.push(handle);
|
|
124
128
|
}
|
|
@@ -202,9 +206,29 @@ class DaumClassicMockBinding extends binding_mock_1.MockPortBinding {
|
|
|
202
206
|
});
|
|
203
207
|
}
|
|
204
208
|
emitData(data) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
const _super = Object.create(null, {
|
|
210
|
+
emitData: { get: () => super.emitData }
|
|
211
|
+
});
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
if (!this.isOpen || !this.port)
|
|
214
|
+
return;
|
|
215
|
+
if (this.simulator._simulatePartialDelayed > 0) {
|
|
216
|
+
this.simulator._simulatePartialDelayed--;
|
|
217
|
+
let buffer;
|
|
218
|
+
if (Buffer.isBuffer(data))
|
|
219
|
+
buffer = data;
|
|
220
|
+
else
|
|
221
|
+
buffer = Buffer.from(data);
|
|
222
|
+
const data1 = buffer.subarray(0, buffer.length - 1);
|
|
223
|
+
const data2 = buffer.subarray(buffer.length - 1, buffer.length);
|
|
224
|
+
_super.emitData.call(this, data1);
|
|
225
|
+
yield (0, utils_1.sleep)(10);
|
|
226
|
+
_super.emitData.call(this, data2);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
_super.emitData.call(this, data);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
208
232
|
}
|
|
209
233
|
onCheckCockpit(payload) {
|
|
210
234
|
const bikeNo = payload.readUInt8(0);
|