incyclist-devices 1.5.10 → 1.5.11
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/daum/classic/DaumClassicAdapter.d.ts +4 -0
- package/lib/daum/classic/DaumClassicAdapter.js +38 -1
- package/lib/daum/classic/bike.d.ts +4 -0
- package/lib/daum/classic/bike.js +24 -13
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +2 -0
- package/lib/daum/premium/DaumPremiumAdapter.js +28 -4
- package/lib/daum/premium/bike.d.ts +4 -0
- package/lib/daum/premium/bike.js +49 -39
- package/package.json +1 -1
|
@@ -12,7 +12,11 @@ export default class DaumClassicAdapter extends DaumAdapter {
|
|
|
12
12
|
getPort(): any;
|
|
13
13
|
getSupportedCyclingModes(): Array<any>;
|
|
14
14
|
getDefaultCyclingMode(): CyclingMode;
|
|
15
|
+
pause(): Promise<boolean>;
|
|
16
|
+
resume(): Promise<boolean>;
|
|
15
17
|
check(): Promise<unknown>;
|
|
18
|
+
relaunch(props: any): Promise<unknown>;
|
|
16
19
|
start(props: any): Promise<unknown>;
|
|
20
|
+
launch(props: any, isRelaunch?: boolean): Promise<unknown>;
|
|
17
21
|
getCurrentBikeData(): any;
|
|
18
22
|
}
|
|
@@ -53,6 +53,27 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
53
53
|
getDefaultCyclingMode() {
|
|
54
54
|
return new DaumClassicCyclingMode_1.default(this);
|
|
55
55
|
}
|
|
56
|
+
pause() {
|
|
57
|
+
const _super = Object.create(null, {
|
|
58
|
+
pause: { get: () => super.pause }
|
|
59
|
+
});
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
console.log('~~~~~~~~~~ PAUSE');
|
|
62
|
+
const paused = yield _super.pause.call(this);
|
|
63
|
+
this.bike.pauseLogging();
|
|
64
|
+
return paused;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
resume() {
|
|
68
|
+
const _super = Object.create(null, {
|
|
69
|
+
resume: { get: () => super.resume }
|
|
70
|
+
});
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const resumed = yield _super.resume.call(this);
|
|
73
|
+
this.bike.resumeLogging();
|
|
74
|
+
return resumed;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
56
77
|
check() {
|
|
57
78
|
var info = {};
|
|
58
79
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -79,9 +100,20 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
79
100
|
}
|
|
80
101
|
}));
|
|
81
102
|
}
|
|
103
|
+
relaunch(props) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
this.logger.logEvent({ message: 'relaunch()' });
|
|
106
|
+
return yield this.launch(props, true);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
82
109
|
start(props) {
|
|
83
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
this.logger.logEvent({ message: 'start()'
|
|
111
|
+
this.logger.logEvent({ message: 'start(-)' });
|
|
112
|
+
return yield this.launch(props, false);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
launch(props, isRelaunch = false) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
117
|
const opts = props || {};
|
|
86
118
|
const { user, bikeSettings } = opts;
|
|
87
119
|
if (user && user.weight)
|
|
@@ -89,6 +121,9 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
89
121
|
if (bikeSettings && bikeSettings.weight)
|
|
90
122
|
this.bikeSettings.weight = bikeSettings.weight;
|
|
91
123
|
this.initData();
|
|
124
|
+
if (isRelaunch) {
|
|
125
|
+
yield this.stop();
|
|
126
|
+
}
|
|
92
127
|
let startState = {};
|
|
93
128
|
return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
94
129
|
try {
|
|
@@ -133,6 +168,8 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
133
168
|
}
|
|
134
169
|
}), 5, 1000)
|
|
135
170
|
.then(data => {
|
|
171
|
+
this.stopped = false;
|
|
172
|
+
this.paused = false;
|
|
136
173
|
this.startUpdatePull();
|
|
137
174
|
return data;
|
|
138
175
|
});
|
|
@@ -27,12 +27,16 @@ export default class Daum8008 {
|
|
|
27
27
|
bikeCmdWorker: any;
|
|
28
28
|
cmdStart: number;
|
|
29
29
|
cmdCurrent: any;
|
|
30
|
+
isLoggingPaused: boolean;
|
|
30
31
|
constructor(opts?: any);
|
|
31
32
|
static setSerialPort(spClass: any): void;
|
|
32
33
|
static getClassName(): string;
|
|
33
34
|
getType(): string;
|
|
34
35
|
getPort(): string;
|
|
35
36
|
isConnected(): boolean;
|
|
37
|
+
pauseLogging(): void;
|
|
38
|
+
resumLogging(): void;
|
|
39
|
+
logEvent(e: any): void;
|
|
36
40
|
setUser(user: User, callback: any): void;
|
|
37
41
|
getUserWeight(): number;
|
|
38
42
|
getBikeWeight(): any;
|
package/lib/daum/classic/bike.js
CHANGED
|
@@ -27,6 +27,7 @@ class Daum8008 {
|
|
|
27
27
|
this.closed = undefined;
|
|
28
28
|
this.cmdBusy = false;
|
|
29
29
|
this.queue = new utils_2.Queue();
|
|
30
|
+
this.isLoggingPaused = false;
|
|
30
31
|
}
|
|
31
32
|
static setSerialPort(spClass) {
|
|
32
33
|
__SerialPort = spClass;
|
|
@@ -43,8 +44,18 @@ class Daum8008 {
|
|
|
43
44
|
isConnected() {
|
|
44
45
|
return this.connected;
|
|
45
46
|
}
|
|
47
|
+
pauseLogging() {
|
|
48
|
+
this.isLoggingPaused = true;
|
|
49
|
+
}
|
|
50
|
+
resumLogging() {
|
|
51
|
+
this.isLoggingPaused = false;
|
|
52
|
+
}
|
|
53
|
+
logEvent(e) {
|
|
54
|
+
if (!this.isLoggingPaused)
|
|
55
|
+
this.logger.logEvent(e);
|
|
56
|
+
}
|
|
46
57
|
setUser(user, callback) {
|
|
47
|
-
this.
|
|
58
|
+
this.logEvent({ message: "setUser()", user });
|
|
48
59
|
if (user)
|
|
49
60
|
this.settings.user = user;
|
|
50
61
|
var cb = callback || nop;
|
|
@@ -65,7 +76,7 @@ class Daum8008 {
|
|
|
65
76
|
return 10;
|
|
66
77
|
}
|
|
67
78
|
connect() {
|
|
68
|
-
this.
|
|
79
|
+
this.logEvent({ message: "connect()", port: this.getPort(), sp: (this.sp !== undefined), });
|
|
69
80
|
if (this.closing || this.opening) {
|
|
70
81
|
return;
|
|
71
82
|
}
|
|
@@ -84,7 +95,7 @@ class Daum8008 {
|
|
|
84
95
|
this.sp.open();
|
|
85
96
|
}
|
|
86
97
|
catch (err) {
|
|
87
|
-
this.
|
|
98
|
+
this.logEvent({ message: "startTraining:error:", error: err.message });
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
101
|
saveConnect() {
|
|
@@ -120,7 +131,7 @@ class Daum8008 {
|
|
|
120
131
|
});
|
|
121
132
|
}
|
|
122
133
|
close() {
|
|
123
|
-
this.
|
|
134
|
+
this.logEvent({ message: 'close()', port: this.getPort() });
|
|
124
135
|
if (this.closing) {
|
|
125
136
|
return;
|
|
126
137
|
}
|
|
@@ -174,7 +185,7 @@ class Daum8008 {
|
|
|
174
185
|
});
|
|
175
186
|
}
|
|
176
187
|
onPortOpen() {
|
|
177
|
-
this.
|
|
188
|
+
this.logEvent({ message: "port opened", port: this.getPort() });
|
|
178
189
|
this.error = undefined;
|
|
179
190
|
this.connected = true;
|
|
180
191
|
this.opening = false;
|
|
@@ -185,7 +196,7 @@ class Daum8008 {
|
|
|
185
196
|
this.cmdBusy = false;
|
|
186
197
|
}
|
|
187
198
|
onPortClose() {
|
|
188
|
-
this.
|
|
199
|
+
this.logEvent({ message: "port closed", port: this.getPort() });
|
|
189
200
|
this.error = undefined;
|
|
190
201
|
this.connected = false;
|
|
191
202
|
this.closing = false;
|
|
@@ -202,7 +213,7 @@ class Daum8008 {
|
|
|
202
213
|
if (this.opening && (err.message === 'Port is already open' || err.message === 'Port is opening'))
|
|
203
214
|
return;
|
|
204
215
|
const state = { opening: this.opening, connected: this.connected, closing: this.closing, closed: this.closed, busy: this.cmdBusy };
|
|
205
|
-
this.
|
|
216
|
+
this.logEvent({ message: "port error:", port: this.getPort(), error: err.message, stack: err.stack, state });
|
|
206
217
|
this.error = err;
|
|
207
218
|
this.cmdBusy = false;
|
|
208
219
|
}
|
|
@@ -238,7 +249,7 @@ class Daum8008 {
|
|
|
238
249
|
const timeout = (cmdInfo.options && cmdInfo.options.timeout) ? cmdInfo.options.timeout : (this.settings.timeoutMessage || TIMEOUT_SEND);
|
|
239
250
|
let d = Date.now() - cmdInfo.start;
|
|
240
251
|
if (d > timeout) {
|
|
241
|
-
this.
|
|
252
|
+
this.logEvent({ message: 'sendCommmand:timeout', port: this.getPort() });
|
|
242
253
|
const port = this.sp;
|
|
243
254
|
port.unpipe();
|
|
244
255
|
port.flush();
|
|
@@ -274,7 +285,7 @@ class Daum8008 {
|
|
|
274
285
|
};
|
|
275
286
|
this.queue.enqueue(cmdInfo);
|
|
276
287
|
if (this.queue.size() > 1)
|
|
277
|
-
this.
|
|
288
|
+
this.logEvent({ message: "sendCommand:adding:", cmd: logStr, hex: (0, utils_1.hexstr)(payload), queueSize: this.queue.size() });
|
|
278
289
|
if (this.bikeCmdWorker === undefined) {
|
|
279
290
|
this.startWorker();
|
|
280
291
|
}
|
|
@@ -293,12 +304,12 @@ class Daum8008 {
|
|
|
293
304
|
const parser = serialPort.pipe(new ByteLength({ length: expected }));
|
|
294
305
|
parser.on('data', (data) => {
|
|
295
306
|
let duration = Date.now() - this.cmdStart;
|
|
296
|
-
this.
|
|
307
|
+
this.logEvent({ message: "sendCommand:received:", duration, hex: (0, utils_1.hexstr)(data), port: this.getPort() });
|
|
297
308
|
serialPort.unpipe();
|
|
298
309
|
if (callbackErr !== undefined) {
|
|
299
310
|
if (data[0] !== payload[0]) {
|
|
300
311
|
serialPort.flush();
|
|
301
|
-
this.
|
|
312
|
+
this.logEvent({ message: "sendCommand:illegal response", port: this.getPort() });
|
|
302
313
|
done();
|
|
303
314
|
return callbackErr(512, { message: "illegal response" });
|
|
304
315
|
}
|
|
@@ -306,12 +317,12 @@ class Daum8008 {
|
|
|
306
317
|
callback(data);
|
|
307
318
|
done();
|
|
308
319
|
});
|
|
309
|
-
this.
|
|
320
|
+
this.logEvent({ message: "sendCommand:sending:", cmd: logStr, hex: (0, utils_1.hexstr)(payload), port: this.getPort() });
|
|
310
321
|
this.cmdCurrent.start = this.cmdStart = Date.now();
|
|
311
322
|
serialPort.write(payload);
|
|
312
323
|
}
|
|
313
324
|
catch (err) {
|
|
314
|
-
this.
|
|
325
|
+
this.logEvent({ message: "sendCommand:error:", error: err.message, port: this.getPort() });
|
|
315
326
|
done();
|
|
316
327
|
callbackErr(500, { message: `Exception: ${err.message}` });
|
|
317
328
|
}
|
|
@@ -7,6 +7,8 @@ export default class DaumPremiumDevice extends DaumAdapter {
|
|
|
7
7
|
getInterface(): any;
|
|
8
8
|
getSupportedCyclingModes(): Array<any>;
|
|
9
9
|
check(): Promise<unknown>;
|
|
10
|
+
pause(): Promise<boolean>;
|
|
11
|
+
resume(): Promise<boolean>;
|
|
10
12
|
relaunch(props: any): Promise<unknown>;
|
|
11
13
|
start(props: any): Promise<unknown>;
|
|
12
14
|
launch(props: any, isRelaunch?: boolean): Promise<unknown>;
|
|
@@ -62,6 +62,26 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
62
62
|
}
|
|
63
63
|
}));
|
|
64
64
|
}
|
|
65
|
+
pause() {
|
|
66
|
+
const _super = Object.create(null, {
|
|
67
|
+
pause: { get: () => super.pause }
|
|
68
|
+
});
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const paused = yield _super.pause.call(this);
|
|
71
|
+
this.bike.pauseLogging();
|
|
72
|
+
return paused;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
resume() {
|
|
76
|
+
const _super = Object.create(null, {
|
|
77
|
+
resume: { get: () => super.resume }
|
|
78
|
+
});
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const resumed = yield _super.resume.call(this);
|
|
81
|
+
this.bike.resumeLogging();
|
|
82
|
+
return resumed;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
65
85
|
relaunch(props) {
|
|
66
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
87
|
this.logger.logEvent({ message: 'relaunch()' });
|
|
@@ -85,15 +105,18 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
85
105
|
const route = opts.route;
|
|
86
106
|
var info = {};
|
|
87
107
|
this.initData();
|
|
108
|
+
if (isRelaunch) {
|
|
109
|
+
yield this.stop();
|
|
110
|
+
}
|
|
88
111
|
return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
89
112
|
try {
|
|
90
113
|
if (!isRelaunch && !this.bike.isConnected()) {
|
|
91
114
|
yield this.bike.saveConnect();
|
|
92
115
|
}
|
|
93
|
-
if (!
|
|
116
|
+
if (!info.deviceType) {
|
|
94
117
|
info.deviceType = yield this.bike.getDeviceType();
|
|
95
118
|
}
|
|
96
|
-
if (!
|
|
119
|
+
if (!info.version) {
|
|
97
120
|
info.version = yield this.bike.getProtocolVersion();
|
|
98
121
|
}
|
|
99
122
|
if (this.getCyclingMode().getModeProperty('eppSupport')) {
|
|
@@ -120,8 +143,9 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
120
143
|
}
|
|
121
144
|
}), 5, 1500)
|
|
122
145
|
.then(data => {
|
|
123
|
-
|
|
124
|
-
|
|
146
|
+
this.stopped = false;
|
|
147
|
+
this.paused = false;
|
|
148
|
+
this.startUpdatePull();
|
|
125
149
|
return data;
|
|
126
150
|
});
|
|
127
151
|
});
|
|
@@ -28,6 +28,7 @@ declare class Daum8i {
|
|
|
28
28
|
queue: Queue<any>;
|
|
29
29
|
cmdCurrent: any;
|
|
30
30
|
cmdStart: number;
|
|
31
|
+
isLoggingPaused: boolean;
|
|
31
32
|
constructor(props: any);
|
|
32
33
|
static getClassName(): string;
|
|
33
34
|
getType(): string;
|
|
@@ -36,6 +37,9 @@ declare class Daum8i {
|
|
|
36
37
|
static getSupportedInterfaces(): string[];
|
|
37
38
|
getPort(): string;
|
|
38
39
|
isConnected(): boolean;
|
|
40
|
+
pauseLogging(): void;
|
|
41
|
+
resumLogging(): void;
|
|
42
|
+
logEvent(e: any): void;
|
|
39
43
|
setUser(user: any, callback: any): void;
|
|
40
44
|
getUserWeight(): any;
|
|
41
45
|
getBikeWeight(): number;
|
package/lib/daum/premium/bike.js
CHANGED
|
@@ -38,7 +38,6 @@ class Daum8i {
|
|
|
38
38
|
constructor(props) {
|
|
39
39
|
this.props = props || {};
|
|
40
40
|
this.logger = process.env.DEBUG ? DEBUG_LOGGER : new gd_eventlog_1.EventLogger('DaumPremium');
|
|
41
|
-
this.logger.logEvent({ message: 'new DaumPremium object', props: this.props });
|
|
42
41
|
if (this.props.interface === 'tcpip') {
|
|
43
42
|
const port = this.props.port || DAUM_PREMIUM_DEFAULT_PORT;
|
|
44
43
|
const host = this.props.host || DAUM_PREMIUM_DEFAULT_HOST;
|
|
@@ -55,6 +54,7 @@ class Daum8i {
|
|
|
55
54
|
}
|
|
56
55
|
this.settings = this.props.settings || {};
|
|
57
56
|
this.settings.logger = this.logger;
|
|
57
|
+
this.isLoggingPaused = false;
|
|
58
58
|
this.sendRetryDelay = DEFAULT_SEND_DELAY;
|
|
59
59
|
this.sp = undefined;
|
|
60
60
|
this.connected = false;
|
|
@@ -90,8 +90,18 @@ class Daum8i {
|
|
|
90
90
|
isConnected() {
|
|
91
91
|
return this.connected;
|
|
92
92
|
}
|
|
93
|
+
pauseLogging() {
|
|
94
|
+
this.isLoggingPaused = true;
|
|
95
|
+
}
|
|
96
|
+
resumLogging() {
|
|
97
|
+
this.isLoggingPaused = false;
|
|
98
|
+
}
|
|
99
|
+
logEvent(e) {
|
|
100
|
+
if (!this.isLoggingPaused)
|
|
101
|
+
this.logger.logEvent(e);
|
|
102
|
+
}
|
|
93
103
|
setUser(user, callback) {
|
|
94
|
-
this.
|
|
104
|
+
this.logEvent({ message: "setUser()", user, port: this.portName });
|
|
95
105
|
this.settings.user = user || {};
|
|
96
106
|
var cb = callback || nop;
|
|
97
107
|
cb(200, user);
|
|
@@ -108,7 +118,7 @@ class Daum8i {
|
|
|
108
118
|
this.blocked = false;
|
|
109
119
|
}
|
|
110
120
|
connect() {
|
|
111
|
-
this.
|
|
121
|
+
this.logEvent({ message: "connect()", sp: (this.sp !== undefined), connected: this.connected, blocked: this.blocked, port: this.portName, settings: this.settings });
|
|
112
122
|
if (this.connected || this.blocked) {
|
|
113
123
|
return;
|
|
114
124
|
}
|
|
@@ -128,13 +138,13 @@ class Daum8i {
|
|
|
128
138
|
if (this.tcpip) {
|
|
129
139
|
const { host, port } = this.tcpipConnection;
|
|
130
140
|
const { logger } = this.props;
|
|
131
|
-
this.
|
|
141
|
+
this.logEvent({ message: "creating TCPSocketPort", host, port });
|
|
132
142
|
this.sp = new tcpserial_1.default({ host, port, net, timeout: OPEN_TIMEOUT, logger });
|
|
133
143
|
}
|
|
134
144
|
else {
|
|
135
145
|
const settings = this.settings.port || {};
|
|
136
146
|
settings.autoOpen = false;
|
|
137
|
-
this.
|
|
147
|
+
this.logEvent({ message: "creating SerialPort", port: this.port, settings });
|
|
138
148
|
this.sp = new __SerialPort(this.port, settings);
|
|
139
149
|
}
|
|
140
150
|
this.sp.on('open', this.onPortOpen.bind(this));
|
|
@@ -145,11 +155,11 @@ class Daum8i {
|
|
|
145
155
|
const start = Date.now();
|
|
146
156
|
this.state.connecting = true;
|
|
147
157
|
this.state.opening = { start, timeout: start + this.getTimeoutValue() };
|
|
148
|
-
this.
|
|
158
|
+
this.logEvent({ message: "opening port ..." });
|
|
149
159
|
this.sp.open();
|
|
150
160
|
}
|
|
151
161
|
catch (err) {
|
|
152
|
-
this.
|
|
162
|
+
this.logEvent({ message: "scan:error:", error: err.message, stack: err.stack });
|
|
153
163
|
this.state.busy = false;
|
|
154
164
|
}
|
|
155
165
|
}
|
|
@@ -196,10 +206,10 @@ class Daum8i {
|
|
|
196
206
|
this.state.opening = undefined;
|
|
197
207
|
this.state.opened = true;
|
|
198
208
|
this.state.busy = false;
|
|
199
|
-
this.
|
|
209
|
+
this.logEvent({ message: "port opened", port: this.portName });
|
|
200
210
|
}
|
|
201
211
|
onPortClose() {
|
|
202
|
-
this.
|
|
212
|
+
this.logEvent({ message: "port closed", port: this.portName });
|
|
203
213
|
this.error = undefined;
|
|
204
214
|
this.connected = false;
|
|
205
215
|
if (this.state.opening) {
|
|
@@ -225,7 +235,7 @@ class Daum8i {
|
|
|
225
235
|
return { sending: s, busy, writeBusy, opening, connecting, waitingForStart, waitingForEnd, waitingForAck, retry };
|
|
226
236
|
}
|
|
227
237
|
onPortError(error) {
|
|
228
|
-
this.
|
|
238
|
+
this.logEvent({ message: "port error:", port: this.portName, error: error.message, connected: this.connected, state: this.getLogState() });
|
|
229
239
|
this.error = error;
|
|
230
240
|
if (this.blocked) {
|
|
231
241
|
if (!this.state.closed) {
|
|
@@ -296,7 +306,7 @@ class Daum8i {
|
|
|
296
306
|
this.state = { opened: false, closed: true, busy: false };
|
|
297
307
|
}
|
|
298
308
|
close() {
|
|
299
|
-
this.
|
|
309
|
+
this.logEvent({ message: 'close request', port: this.portName });
|
|
300
310
|
var sp = this.sp;
|
|
301
311
|
let connected = this.connected;
|
|
302
312
|
try {
|
|
@@ -317,7 +327,7 @@ class Daum8i {
|
|
|
317
327
|
}
|
|
318
328
|
}
|
|
319
329
|
catch (err) {
|
|
320
|
-
this.
|
|
330
|
+
this.logEvent({ message: 'close: Exception', port: this.portName, error: err.message });
|
|
321
331
|
}
|
|
322
332
|
this.connected = false;
|
|
323
333
|
const start = Date.now();
|
|
@@ -331,7 +341,7 @@ class Daum8i {
|
|
|
331
341
|
this.state.busy = false;
|
|
332
342
|
}
|
|
333
343
|
sendTimeout(message) {
|
|
334
|
-
this.
|
|
344
|
+
this.logEvent({ message: `sendCommand:${message || 'timeout'}`, port: this.portName, cmd: this.cmdCurrent });
|
|
335
345
|
delete this.state.commandsInQueue[this.cmdCurrent.command];
|
|
336
346
|
if (this.cmdCurrent.callbackErr !== undefined) {
|
|
337
347
|
let cb = this.cmdCurrent.callbackErr;
|
|
@@ -371,7 +381,7 @@ class Daum8i {
|
|
|
371
381
|
return false;
|
|
372
382
|
}
|
|
373
383
|
catch (err) {
|
|
374
|
-
this.
|
|
384
|
+
this.logEvent({ message: 'checkForResponse: Exception', port: this.portName, error: err.message, stack: err.stack });
|
|
375
385
|
}
|
|
376
386
|
return true;
|
|
377
387
|
}
|
|
@@ -408,7 +418,7 @@ class Daum8i {
|
|
|
408
418
|
incoming = bufferData;
|
|
409
419
|
}
|
|
410
420
|
const response = [...incoming];
|
|
411
|
-
this.
|
|
421
|
+
this.logEvent({ message: 'sendCommand:RECV', data: (0, utils_1.hexstr)(response) });
|
|
412
422
|
for (let i = 0; i < incoming.length; i++) {
|
|
413
423
|
const getRemaining = () => {
|
|
414
424
|
let remaining = '';
|
|
@@ -421,7 +431,7 @@ class Daum8i {
|
|
|
421
431
|
};
|
|
422
432
|
const c = incoming.readUInt8(i);
|
|
423
433
|
if (c === 0x06) {
|
|
424
|
-
this.
|
|
434
|
+
this.logEvent({ message: "sendCommand:ACK received:", port: portName });
|
|
425
435
|
this.state.waitingForStart = true;
|
|
426
436
|
this.state.waitingForACK = false;
|
|
427
437
|
const remaining = getRemaining();
|
|
@@ -431,7 +441,7 @@ class Daum8i {
|
|
|
431
441
|
else if (c === 0x15) {
|
|
432
442
|
this.state.waitingForStart = true;
|
|
433
443
|
this.state.waitingForACK = false;
|
|
434
|
-
this.
|
|
444
|
+
this.logEvent({ message: "sendCommand:NAK received:", port: portName });
|
|
435
445
|
const remaining = getRemaining();
|
|
436
446
|
if (remaining && remaining !== '')
|
|
437
447
|
return this.onData(remaining);
|
|
@@ -441,7 +451,7 @@ class Daum8i {
|
|
|
441
451
|
}
|
|
442
452
|
else if (c === 0x17) {
|
|
443
453
|
const remaining = getRemaining();
|
|
444
|
-
this.
|
|
454
|
+
this.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) });
|
|
445
455
|
this.state.waitingForEnd = false;
|
|
446
456
|
const cmdStr = cmd.substring(0, cmd.length - 2);
|
|
447
457
|
const checksumExtracted = cmd.slice(-2);
|
|
@@ -488,7 +498,7 @@ class Daum8i {
|
|
|
488
498
|
}
|
|
489
499
|
else {
|
|
490
500
|
const message = (0, utils_1.buildMessage)(command, payload);
|
|
491
|
-
this.
|
|
501
|
+
this.logEvent({ message: 'sendCommand:waiting', port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
492
502
|
const busyWait = () => {
|
|
493
503
|
return new Promise((done) => {
|
|
494
504
|
let start = Date.now();
|
|
@@ -509,7 +519,7 @@ class Daum8i {
|
|
|
509
519
|
};
|
|
510
520
|
const res = yield busyWait();
|
|
511
521
|
if (!res) {
|
|
512
|
-
this.
|
|
522
|
+
this.logEvent({ message: 'sendCommand:busy timeout', port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message), duration: Date.now() - tsRequest });
|
|
513
523
|
return reject(new Error('BUSY timeout'));
|
|
514
524
|
}
|
|
515
525
|
this.state.busy = true;
|
|
@@ -530,10 +540,10 @@ class Daum8i {
|
|
|
530
540
|
const message = (0, utils_1.buildMessage)(command, payload);
|
|
531
541
|
const start = Date.now();
|
|
532
542
|
const timeout = start + this.getTimeoutValue();
|
|
533
|
-
this.
|
|
543
|
+
this.logEvent({ message: "sendCommand:sending:", port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
534
544
|
this.state.writeBusy = true;
|
|
535
545
|
if (!this.connected || port === undefined) {
|
|
536
|
-
this.
|
|
546
|
+
this.logEvent({ message: "sendCommand:error: not connected", port: this.portName });
|
|
537
547
|
writeDone();
|
|
538
548
|
return reject(new Error('not connected'));
|
|
539
549
|
}
|
|
@@ -552,7 +562,7 @@ class Daum8i {
|
|
|
552
562
|
}, 10);
|
|
553
563
|
}
|
|
554
564
|
catch (err) {
|
|
555
|
-
this.
|
|
565
|
+
this.logEvent({ message: "sendCommand:error:", port: portName, error: err.message, stack: err.stack });
|
|
556
566
|
writeDone();
|
|
557
567
|
reject(err);
|
|
558
568
|
}
|
|
@@ -566,7 +576,7 @@ class Daum8i {
|
|
|
566
576
|
}
|
|
567
577
|
catch (err) { }
|
|
568
578
|
this.state.writeBusy = false;
|
|
569
|
-
this.
|
|
579
|
+
this.logEvent({ message: "sendCommand:sending ACK", port, queue: this.state.commandsInQueue });
|
|
570
580
|
}
|
|
571
581
|
sendNAK() {
|
|
572
582
|
const port = this.portName;
|
|
@@ -574,7 +584,7 @@ class Daum8i {
|
|
|
574
584
|
this.sp.write([0x15]);
|
|
575
585
|
}
|
|
576
586
|
catch (err) { }
|
|
577
|
-
this.
|
|
587
|
+
this.logEvent({ message: "sendCommand:sending NAK", port });
|
|
578
588
|
}
|
|
579
589
|
sendReservedDaum8iCommand(command, cmdType, data) {
|
|
580
590
|
let buffer;
|
|
@@ -695,7 +705,7 @@ class Daum8i {
|
|
|
695
705
|
});
|
|
696
706
|
}
|
|
697
707
|
setSlope(slope) {
|
|
698
|
-
this.
|
|
708
|
+
this.logEvent({ message: 'setSlope not implemted' });
|
|
699
709
|
return;
|
|
700
710
|
}
|
|
701
711
|
setPower(power) {
|
|
@@ -713,24 +723,24 @@ class Daum8i {
|
|
|
713
723
|
}
|
|
714
724
|
setPerson(person) {
|
|
715
725
|
const { sex, age, length, weight } = person;
|
|
716
|
-
this.
|
|
726
|
+
this.logEvent({ message: 'setPerson() request', sex, age, length, weight });
|
|
717
727
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, 'BF', (0, utils_1.getPersonData)(person))
|
|
718
728
|
.then((res) => {
|
|
719
729
|
const buffer = Buffer.from(res);
|
|
720
730
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PERSON_SET;
|
|
721
|
-
this.
|
|
731
|
+
this.logEvent({ message: 'setPerson() response', success, buffer });
|
|
722
732
|
if (!success)
|
|
723
733
|
throw new Error('Illegal Response');
|
|
724
734
|
return true;
|
|
725
735
|
});
|
|
726
736
|
}
|
|
727
737
|
programUploadInit() {
|
|
728
|
-
this.
|
|
738
|
+
this.logEvent({ message: 'programUploadInit() request' });
|
|
729
739
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN, 'BF')
|
|
730
740
|
.then((res) => {
|
|
731
741
|
const buffer = Buffer.from(res);
|
|
732
742
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_BEGIN;
|
|
733
|
-
this.
|
|
743
|
+
this.logEvent({ message: 'programUploadInit() response', success, buffer });
|
|
734
744
|
if (!success)
|
|
735
745
|
throw new Error('Illegal Response');
|
|
736
746
|
return true;
|
|
@@ -756,15 +766,15 @@ class Daum8i {
|
|
|
756
766
|
payload.writeInt16LE(wBits, 30);
|
|
757
767
|
payload.writeInt32LE(7, 32);
|
|
758
768
|
payload.writeInt32LE(eppLength, 36);
|
|
759
|
-
this.
|
|
769
|
+
this.logEvent({ message: 'programUploadStart() request', bikeType, length: eppLength });
|
|
760
770
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, 'BF', payload)
|
|
761
771
|
.then((res) => {
|
|
762
772
|
const buffer = Buffer.from(res);
|
|
763
773
|
if (buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM) {
|
|
764
|
-
this.
|
|
774
|
+
this.logEvent({ message: 'programUploadStart() response', success: true });
|
|
765
775
|
return epp;
|
|
766
776
|
}
|
|
767
|
-
this.
|
|
777
|
+
this.logEvent({ message: 'programUploadStart() response', success: false });
|
|
768
778
|
throw new Error('Illegal Response');
|
|
769
779
|
});
|
|
770
780
|
}
|
|
@@ -778,14 +788,14 @@ class Daum8i {
|
|
|
778
788
|
payload.writeInt32LE(offset, 4);
|
|
779
789
|
const chunk = Buffer.from(epp.slice(offset, offset + size));
|
|
780
790
|
chunk.copy(payload, 8);
|
|
781
|
-
this.
|
|
791
|
+
this.logEvent({ message: 'programUploadSendBlock() request', offset, size });
|
|
782
792
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM, 'BF', payload)
|
|
783
793
|
.then((res) => {
|
|
784
794
|
const buffer = Buffer.from(res);
|
|
785
795
|
let success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM;
|
|
786
796
|
success = success && (buffer.readInt16LE(2) === 1);
|
|
787
797
|
success = success && (buffer.readInt8(4) === 1);
|
|
788
|
-
this.
|
|
798
|
+
this.logEvent({ message: 'programUploadSendBlock() response' });
|
|
789
799
|
if (!success)
|
|
790
800
|
throw new Error('Illegal Response');
|
|
791
801
|
return true;
|
|
@@ -793,12 +803,12 @@ class Daum8i {
|
|
|
793
803
|
});
|
|
794
804
|
}
|
|
795
805
|
programUploadDone() {
|
|
796
|
-
this.
|
|
806
|
+
this.logEvent({ message: 'programUploadDone() request' });
|
|
797
807
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END, 'BF')
|
|
798
808
|
.then((res) => {
|
|
799
809
|
const buffer = Buffer.from(res);
|
|
800
810
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_END;
|
|
801
|
-
this.
|
|
811
|
+
this.logEvent({ message: 'programUploadDone() response', success });
|
|
802
812
|
if (!success)
|
|
803
813
|
throw new Error('Illegal Response');
|
|
804
814
|
return true;
|
|
@@ -840,12 +850,12 @@ class Daum8i {
|
|
|
840
850
|
startProgram(programId = 1) {
|
|
841
851
|
const payload = Buffer.alloc(2);
|
|
842
852
|
payload.writeInt16LE(programId, 0);
|
|
843
|
-
this.
|
|
853
|
+
this.logEvent({ message: 'startProgram() request', programId });
|
|
844
854
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START, 'BF', payload)
|
|
845
855
|
.then((res) => {
|
|
846
856
|
const buffer = Buffer.from(res);
|
|
847
857
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_START;
|
|
848
|
-
this.
|
|
858
|
+
this.logEvent({ message: 'startProgram() request', programId, success });
|
|
849
859
|
if (!success)
|
|
850
860
|
throw new Error('Illegal Response');
|
|
851
861
|
return true;
|