incyclist-devices 1.5.10 → 1.5.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/LICENSE +0 -0
- package/lib/DeviceSupport.d.ts +36 -36
- package/lib/DeviceSupport.js +82 -82
- package/lib/ant/AntAdapter.d.ts +50 -50
- package/lib/ant/AntAdapter.js +109 -109
- package/lib/ant/AntScanner.d.ts +60 -60
- package/lib/ant/AntScanner.js +651 -651
- package/lib/ant/antfe/AntFEAdapter.d.ts +83 -83
- package/lib/ant/antfe/AntFEAdapter.js +652 -652
- package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +9 -9
- package/lib/ant/antfe/ant-fe-adv-st-mode.js +51 -51
- package/lib/ant/antfe/ant-fe-erg-mode.d.ts +6 -6
- package/lib/ant/antfe/ant-fe-erg-mode.js +14 -14
- package/lib/ant/antfe/ant-fe-st-mode.d.ts +5 -5
- package/lib/ant/antfe/ant-fe-st-mode.js +13 -13
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +16 -16
- package/lib/ant/anthrm/AntHrmAdapter.js +130 -130
- package/lib/ant/antpwr/pwr-adapter.d.ts +49 -49
- package/lib/ant/antpwr/pwr-adapter.js +251 -251
- package/lib/ant/utils.d.ts +1 -1
- package/lib/ant/utils.js +23 -23
- package/lib/antv2/AntAdapter.d.ts +48 -0
- package/lib/antv2/AntAdapter.js +104 -0
- package/lib/antv2/adapter-factory.d.ts +11 -11
- package/lib/antv2/adapter-factory.js +40 -40
- package/lib/antv2/ant-binding.d.ts +13 -13
- package/lib/antv2/ant-binding.js +27 -27
- package/lib/antv2/ant-device.d.ts +51 -51
- package/lib/antv2/ant-device.js +115 -115
- package/lib/antv2/ant-interface.d.ts +37 -37
- package/lib/antv2/ant-interface.js +255 -255
- package/lib/antv2/fe.d.ts +29 -29
- package/lib/antv2/fe.js +262 -262
- package/lib/antv2/hr.d.ts +18 -18
- package/lib/antv2/hr.js +93 -93
- package/lib/antv2/incyclist-protocol.d.ts +37 -37
- package/lib/antv2/incyclist-protocol.js +126 -126
- package/lib/antv2/pwr.d.ts +28 -28
- package/lib/antv2/pwr.js +163 -163
- package/lib/antv2/sensor-factory.d.ts +5 -5
- package/lib/antv2/sensor-factory.js +20 -20
- package/lib/ble/ble-device.d.ts +63 -63
- package/lib/ble/ble-device.js +444 -444
- package/lib/ble/ble-erg-mode.d.ts +18 -18
- package/lib/ble/ble-erg-mode.js +132 -132
- package/lib/ble/ble-interface.d.ts +100 -100
- package/lib/ble/ble-interface.js +721 -721
- package/lib/ble/ble-peripheral.d.ts +36 -36
- package/lib/ble/ble-peripheral.js +200 -200
- package/lib/ble/ble-st-mode.d.ts +15 -15
- package/lib/ble/ble-st-mode.js +95 -95
- package/lib/ble/ble.d.ts +129 -129
- package/lib/ble/ble.js +86 -86
- package/lib/ble/consts.d.ts +14 -14
- package/lib/ble/consts.js +17 -17
- package/lib/ble/elite.d.ts +90 -90
- package/lib/ble/elite.js +322 -322
- package/lib/ble/fm.d.ts +125 -125
- package/lib/ble/fm.js +745 -745
- package/lib/ble/hrm.d.ts +48 -48
- package/lib/ble/hrm.js +134 -134
- package/lib/ble/incyclist-protocol.d.ts +31 -31
- package/lib/ble/incyclist-protocol.js +153 -153
- package/lib/ble/pwr.d.ts +89 -89
- package/lib/ble/pwr.js +321 -321
- package/lib/ble/tacx.d.ts +92 -90
- package/lib/ble/tacx.js +763 -731
- package/lib/ble/wahoo-kickr.d.ts +98 -98
- package/lib/ble/wahoo-kickr.js +496 -496
- package/lib/calculations.d.ts +13 -13
- package/lib/calculations.js +150 -150
- package/lib/cycling-mode.d.ts +76 -76
- package/lib/cycling-mode.js +79 -79
- package/lib/daum/DaumAdapter.d.ts +66 -66
- package/lib/daum/DaumAdapter.js +396 -396
- package/lib/daum/DaumPowerMeterCyclingMode.d.ts +8 -8
- package/lib/daum/DaumPowerMeterCyclingMode.js +21 -21
- package/lib/daum/ERGCyclingMode.d.ts +26 -26
- package/lib/daum/ERGCyclingMode.js +201 -201
- package/lib/daum/SmartTrainerCyclingMode.d.ts +41 -41
- package/lib/daum/SmartTrainerCyclingMode.js +344 -344
- package/lib/daum/classic/DaumClassicAdapter.d.ts +22 -18
- package/lib/daum/classic/DaumClassicAdapter.js +183 -146
- package/lib/daum/classic/DaumClassicCyclingMode.d.ts +13 -13
- package/lib/daum/classic/DaumClassicCyclingMode.js +97 -97
- package/lib/daum/classic/DaumClassicProtocol.d.ts +27 -27
- package/lib/daum/classic/DaumClassicProtocol.js +185 -185
- package/lib/daum/classic/bike.d.ts +68 -64
- package/lib/daum/classic/bike.js +467 -456
- package/lib/daum/classic/utils.d.ts +13 -13
- package/lib/daum/classic/utils.js +143 -143
- package/lib/daum/constants.d.ts +19 -19
- package/lib/daum/constants.js +22 -22
- package/lib/daum/premium/DaumClassicCyclingMode.d.ts +14 -14
- package/lib/daum/premium/DaumClassicCyclingMode.js +86 -86
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +16 -14
- package/lib/daum/premium/DaumPremiumAdapter.js +163 -139
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +32 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +207 -207
- package/lib/daum/premium/bike.d.ts +127 -123
- package/lib/daum/premium/bike.js +904 -894
- package/lib/daum/premium/tcpserial.d.ts +33 -33
- package/lib/daum/premium/tcpserial.js +123 -123
- package/lib/daum/premium/utils.d.ts +62 -62
- package/lib/daum/premium/utils.js +376 -376
- package/lib/device.d.ts +92 -92
- package/lib/device.js +71 -71
- package/lib/kettler/comms.d.ts +59 -59
- package/lib/kettler/comms.js +242 -242
- package/lib/kettler/ergo-racer/ERGCyclingMode.d.ts +25 -25
- package/lib/kettler/ergo-racer/ERGCyclingMode.js +144 -144
- package/lib/kettler/ergo-racer/adapter.d.ts +101 -101
- package/lib/kettler/ergo-racer/adapter.js +639 -639
- package/lib/kettler/ergo-racer/protocol.d.ts +41 -41
- package/lib/kettler/ergo-racer/protocol.js +203 -203
- package/lib/modes/power-base.d.ts +20 -20
- package/lib/modes/power-base.js +70 -70
- package/lib/modes/power-meter.d.ts +20 -20
- package/lib/modes/power-meter.js +78 -78
- package/lib/modes/simulator.d.ts +29 -29
- package/lib/modes/simulator.js +140 -140
- package/lib/protocol.d.ts +74 -74
- package/lib/protocol.js +41 -41
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +33 -33
- package/lib/simulator/Simulator.d.ts +69 -69
- package/lib/simulator/Simulator.js +288 -288
- package/lib/types/command.d.ts +8 -8
- package/lib/types/command.js +2 -2
- package/lib/types/route.d.ts +24 -24
- package/lib/types/route.js +9 -9
- package/lib/types/user.d.ts +11 -11
- package/lib/types/user.js +9 -9
- package/lib/utils.d.ts +14 -14
- package/lib/utils.js +114 -114
- package/package.json +47 -47
package/lib/daum/premium/bike.js
CHANGED
|
@@ -1,894 +1,904 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Daum8iSerial = exports.Daum8iTcp = void 0;
|
|
16
|
-
const constants_1 = require("../constants");
|
|
17
|
-
const tcpserial_1 = __importDefault(require("./tcpserial"));
|
|
18
|
-
const utils_1 = require("./utils");
|
|
19
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
20
|
-
const nop = () => { };
|
|
21
|
-
const MAX_RETRIES = 5;
|
|
22
|
-
const DEFAULT_TIMEOUT = 10000;
|
|
23
|
-
const DEFAULT_SEND_DELAY = 1000;
|
|
24
|
-
const TIMEOUT_START = 15000;
|
|
25
|
-
const OPEN_TIMEOUT = 1000;
|
|
26
|
-
const DAUM_PREMIUM_DEFAULT_PORT = 51955;
|
|
27
|
-
const DAUM_PREMIUM_DEFAULT_HOST = '127.0.0.1';
|
|
28
|
-
const MAX_DATA_BLOCK_SIZE = 512;
|
|
29
|
-
const DS_BITS_OFF = 0;
|
|
30
|
-
const DS_BITS_ENDLESS_RACE = 2;
|
|
31
|
-
var __SerialPort = undefined;
|
|
32
|
-
var net = undefined;
|
|
33
|
-
const DEBUG_LOGGER = {
|
|
34
|
-
log: (e, ...args) => console.log(e, ...args),
|
|
35
|
-
logEvent: (event) => console.log(JSON.stringify(event))
|
|
36
|
-
};
|
|
37
|
-
class Daum8i {
|
|
38
|
-
constructor(props) {
|
|
39
|
-
this.props = props || {};
|
|
40
|
-
this.logger = process.env.DEBUG ? DEBUG_LOGGER : new gd_eventlog_1.EventLogger('DaumPremium');
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
this.settings = this.
|
|
57
|
-
this.
|
|
58
|
-
this.sendRetryDelay = DEFAULT_SEND_DELAY;
|
|
59
|
-
this.sp = undefined;
|
|
60
|
-
this.connected = false;
|
|
61
|
-
this.blocked = false;
|
|
62
|
-
this.state = {
|
|
63
|
-
ack: { wait: false, startWait: undefined },
|
|
64
|
-
commandsInQueue: {},
|
|
65
|
-
};
|
|
66
|
-
this.bikeData = {
|
|
67
|
-
userWeight: 75,
|
|
68
|
-
bikeWeight: 10,
|
|
69
|
-
maxPower: 800
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
static getClassName() {
|
|
73
|
-
return "Daum8i";
|
|
74
|
-
}
|
|
75
|
-
getType() {
|
|
76
|
-
return "Daum8i";
|
|
77
|
-
}
|
|
78
|
-
static setSerialPort(spClass) {
|
|
79
|
-
__SerialPort = spClass;
|
|
80
|
-
}
|
|
81
|
-
static setNetImpl(netClass) {
|
|
82
|
-
net = netClass;
|
|
83
|
-
}
|
|
84
|
-
static getSupportedInterfaces() {
|
|
85
|
-
return [constants_1.BIKE_INTERFACE.SERIAL, constants_1.BIKE_INTERFACE.TCPIP];
|
|
86
|
-
}
|
|
87
|
-
getPort() {
|
|
88
|
-
return this.portName;
|
|
89
|
-
}
|
|
90
|
-
isConnected() {
|
|
91
|
-
return this.connected;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!this.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
this.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
this.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
sp.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
this.state.
|
|
339
|
-
this.
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return false;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
this.
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
this.
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
this.
|
|
534
|
-
this.state.
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
this.
|
|
544
|
-
this.state.
|
|
545
|
-
this.
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
this.
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
const port = this.portName;
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
.
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
return this.sendDaum8iCommand('
|
|
612
|
-
.then((
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
.
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
return
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
.
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
payload.
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
payload.
|
|
756
|
-
payload.
|
|
757
|
-
payload.
|
|
758
|
-
payload.
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
.
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
});
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
});
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
.
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
})
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
}
|
|
894
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Daum8iSerial = exports.Daum8iTcp = void 0;
|
|
16
|
+
const constants_1 = require("../constants");
|
|
17
|
+
const tcpserial_1 = __importDefault(require("./tcpserial"));
|
|
18
|
+
const utils_1 = require("./utils");
|
|
19
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
20
|
+
const nop = () => { };
|
|
21
|
+
const MAX_RETRIES = 5;
|
|
22
|
+
const DEFAULT_TIMEOUT = 10000;
|
|
23
|
+
const DEFAULT_SEND_DELAY = 1000;
|
|
24
|
+
const TIMEOUT_START = 15000;
|
|
25
|
+
const OPEN_TIMEOUT = 1000;
|
|
26
|
+
const DAUM_PREMIUM_DEFAULT_PORT = 51955;
|
|
27
|
+
const DAUM_PREMIUM_DEFAULT_HOST = '127.0.0.1';
|
|
28
|
+
const MAX_DATA_BLOCK_SIZE = 512;
|
|
29
|
+
const DS_BITS_OFF = 0;
|
|
30
|
+
const DS_BITS_ENDLESS_RACE = 2;
|
|
31
|
+
var __SerialPort = undefined;
|
|
32
|
+
var net = undefined;
|
|
33
|
+
const DEBUG_LOGGER = {
|
|
34
|
+
log: (e, ...args) => console.log(e, ...args),
|
|
35
|
+
logEvent: (event) => console.log(JSON.stringify(event))
|
|
36
|
+
};
|
|
37
|
+
class Daum8i {
|
|
38
|
+
constructor(props) {
|
|
39
|
+
this.props = props || {};
|
|
40
|
+
this.logger = process.env.DEBUG ? DEBUG_LOGGER : new gd_eventlog_1.EventLogger('DaumPremium');
|
|
41
|
+
if (this.props.interface === 'tcpip') {
|
|
42
|
+
const port = this.props.port || DAUM_PREMIUM_DEFAULT_PORT;
|
|
43
|
+
const host = this.props.host || DAUM_PREMIUM_DEFAULT_HOST;
|
|
44
|
+
this.portName = `${host}:51955`;
|
|
45
|
+
this.tcpip = true;
|
|
46
|
+
this.serial = false;
|
|
47
|
+
this.tcpipConnection = { host, port };
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.portName = this.props.port || process.env.COM_PORT;
|
|
51
|
+
this.tcpip = false;
|
|
52
|
+
this.serial = true;
|
|
53
|
+
this.port = this.portName;
|
|
54
|
+
}
|
|
55
|
+
this.settings = this.props.settings || {};
|
|
56
|
+
this.settings.logger = this.logger;
|
|
57
|
+
this.isLoggingPaused = false;
|
|
58
|
+
this.sendRetryDelay = DEFAULT_SEND_DELAY;
|
|
59
|
+
this.sp = undefined;
|
|
60
|
+
this.connected = false;
|
|
61
|
+
this.blocked = false;
|
|
62
|
+
this.state = {
|
|
63
|
+
ack: { wait: false, startWait: undefined },
|
|
64
|
+
commandsInQueue: {},
|
|
65
|
+
};
|
|
66
|
+
this.bikeData = {
|
|
67
|
+
userWeight: 75,
|
|
68
|
+
bikeWeight: 10,
|
|
69
|
+
maxPower: 800
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
static getClassName() {
|
|
73
|
+
return "Daum8i";
|
|
74
|
+
}
|
|
75
|
+
getType() {
|
|
76
|
+
return "Daum8i";
|
|
77
|
+
}
|
|
78
|
+
static setSerialPort(spClass) {
|
|
79
|
+
__SerialPort = spClass;
|
|
80
|
+
}
|
|
81
|
+
static setNetImpl(netClass) {
|
|
82
|
+
net = netClass;
|
|
83
|
+
}
|
|
84
|
+
static getSupportedInterfaces() {
|
|
85
|
+
return [constants_1.BIKE_INTERFACE.SERIAL, constants_1.BIKE_INTERFACE.TCPIP];
|
|
86
|
+
}
|
|
87
|
+
getPort() {
|
|
88
|
+
return this.portName;
|
|
89
|
+
}
|
|
90
|
+
isConnected() {
|
|
91
|
+
return this.connected;
|
|
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
|
+
}
|
|
103
|
+
setUser(user, callback) {
|
|
104
|
+
this.logEvent({ message: "setUser()", user, port: this.portName });
|
|
105
|
+
this.settings.user = user || {};
|
|
106
|
+
var cb = callback || nop;
|
|
107
|
+
cb(200, user);
|
|
108
|
+
}
|
|
109
|
+
getUserWeight() {
|
|
110
|
+
if (!this.settings || !this.settings.user || !this.settings.user.weight)
|
|
111
|
+
return 75;
|
|
112
|
+
return this.settings.user.weight;
|
|
113
|
+
}
|
|
114
|
+
getBikeWeight() {
|
|
115
|
+
return 10;
|
|
116
|
+
}
|
|
117
|
+
unblock() {
|
|
118
|
+
this.blocked = false;
|
|
119
|
+
}
|
|
120
|
+
connect() {
|
|
121
|
+
this.logEvent({ message: "connect()", sp: (this.sp !== undefined), connected: this.connected, blocked: this.blocked, port: this.portName, settings: this.settings });
|
|
122
|
+
if (this.connected || this.blocked) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.state.busy = true;
|
|
126
|
+
this.state.commandsInQueue = {};
|
|
127
|
+
try {
|
|
128
|
+
if (this.sp !== undefined) {
|
|
129
|
+
try {
|
|
130
|
+
this.sp.removeAllListeners();
|
|
131
|
+
this.sp.close();
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
}
|
|
135
|
+
this.sp = undefined;
|
|
136
|
+
}
|
|
137
|
+
if (this.sp === undefined) {
|
|
138
|
+
if (this.tcpip) {
|
|
139
|
+
const { host, port } = this.tcpipConnection;
|
|
140
|
+
const { logger } = this.props;
|
|
141
|
+
this.logEvent({ message: "creating TCPSocketPort", host, port });
|
|
142
|
+
this.sp = new tcpserial_1.default({ host, port, net, timeout: OPEN_TIMEOUT, logger });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const settings = this.settings.port || {};
|
|
146
|
+
settings.autoOpen = false;
|
|
147
|
+
this.logEvent({ message: "creating SerialPort", port: this.port, settings });
|
|
148
|
+
this.sp = new __SerialPort(this.port, settings);
|
|
149
|
+
}
|
|
150
|
+
this.sp.on('open', this.onPortOpen.bind(this));
|
|
151
|
+
this.sp.on('close', this.onPortClose.bind(this));
|
|
152
|
+
this.sp.on('error', (error) => { this.onPortError(error); });
|
|
153
|
+
this.sp.on('data', (data) => { this.onData(data); });
|
|
154
|
+
}
|
|
155
|
+
const start = Date.now();
|
|
156
|
+
this.state.connecting = true;
|
|
157
|
+
this.state.opening = { start, timeout: start + this.getTimeoutValue() };
|
|
158
|
+
this.logEvent({ message: "opening port ..." });
|
|
159
|
+
this.sp.open();
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
this.logEvent({ message: "scan:error:", error: err.message, stack: err.stack });
|
|
163
|
+
this.state.busy = false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
reconnect() {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
yield this.saveClose();
|
|
169
|
+
yield this.saveConnect();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
saveConnect() {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
if (this.isConnected()) {
|
|
175
|
+
this.state.connecting = false;
|
|
176
|
+
return resolve(true);
|
|
177
|
+
}
|
|
178
|
+
this.connect();
|
|
179
|
+
const tTimeout = Date.now() + TIMEOUT_START;
|
|
180
|
+
const iv = setInterval(() => {
|
|
181
|
+
if (this.state.error !== undefined) {
|
|
182
|
+
clearInterval(iv);
|
|
183
|
+
this.forceClose();
|
|
184
|
+
reject(this.state.error);
|
|
185
|
+
this.state = { opened: false, closed: true, busy: false };
|
|
186
|
+
}
|
|
187
|
+
else if (this.isConnected()) {
|
|
188
|
+
this.state.connecting = false;
|
|
189
|
+
resolve(true);
|
|
190
|
+
clearInterval(iv);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
if (Date.now() > tTimeout) {
|
|
194
|
+
this.state.connecting = false;
|
|
195
|
+
this.forceClose();
|
|
196
|
+
clearInterval(iv);
|
|
197
|
+
reject(new Error('timeout'));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}, 100);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
onPortOpen() {
|
|
204
|
+
this.error = undefined;
|
|
205
|
+
this.connected = true;
|
|
206
|
+
this.state.opening = undefined;
|
|
207
|
+
this.state.opened = true;
|
|
208
|
+
this.state.busy = false;
|
|
209
|
+
this.logEvent({ message: "port opened", port: this.portName });
|
|
210
|
+
}
|
|
211
|
+
onPortClose() {
|
|
212
|
+
this.logEvent({ message: "port closed", port: this.portName });
|
|
213
|
+
this.error = undefined;
|
|
214
|
+
this.connected = false;
|
|
215
|
+
if (this.state.opening) {
|
|
216
|
+
this.state.opened = false;
|
|
217
|
+
this.state.closed = true;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
this.state = { opened: false, closed: true, busy: false };
|
|
221
|
+
}
|
|
222
|
+
this.sp.removeAllListeners();
|
|
223
|
+
this.sp = undefined;
|
|
224
|
+
if (this.queue !== undefined)
|
|
225
|
+
this.queue.clear();
|
|
226
|
+
}
|
|
227
|
+
getLogState() {
|
|
228
|
+
let s = undefined;
|
|
229
|
+
const { sending, busy, opening, connecting, writeBusy, waitingForStart, waitingForAck, waitingForEnd, retry } = this.state;
|
|
230
|
+
if (sending) {
|
|
231
|
+
s = {};
|
|
232
|
+
s.command = sending.command;
|
|
233
|
+
s.payload = sending.payload;
|
|
234
|
+
}
|
|
235
|
+
return { sending: s, busy, writeBusy, opening, connecting, waitingForStart, waitingForEnd, waitingForAck, retry };
|
|
236
|
+
}
|
|
237
|
+
onPortError(error) {
|
|
238
|
+
this.logEvent({ message: "port error:", port: this.portName, error: error.message, connected: this.connected, state: this.getLogState() });
|
|
239
|
+
this.error = error;
|
|
240
|
+
if (this.blocked) {
|
|
241
|
+
if (!this.state.closed) {
|
|
242
|
+
if (this.sp) {
|
|
243
|
+
this.sp.removeAllListeners();
|
|
244
|
+
this.sp.close();
|
|
245
|
+
this.sp = undefined;
|
|
246
|
+
}
|
|
247
|
+
this.state = { opened: false, closed: true, busy: false };
|
|
248
|
+
}
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (this.state.closing) {
|
|
252
|
+
if (error.message === 'Port is not open') {
|
|
253
|
+
this.state = { opened: false, closed: true, busy: false };
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
this.forceClose();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
else if (this.state.opening) {
|
|
261
|
+
if (this.state.connecting) {
|
|
262
|
+
this.state.error = error;
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
this.onPortOpen();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
else if (this.state.sending) {
|
|
269
|
+
this.state.error = error;
|
|
270
|
+
this.forceClose(false);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
this.state.busy = false;
|
|
274
|
+
}
|
|
275
|
+
errorHandler() {
|
|
276
|
+
throw new Error("Error");
|
|
277
|
+
}
|
|
278
|
+
saveClose(force) {
|
|
279
|
+
return new Promise((resolve, reject) => {
|
|
280
|
+
if (force)
|
|
281
|
+
this.blocked = true;
|
|
282
|
+
this.close();
|
|
283
|
+
const start = Date.now();
|
|
284
|
+
const iv = setInterval(() => {
|
|
285
|
+
if (this.state.closed || (Date.now() - start > DEFAULT_TIMEOUT)) {
|
|
286
|
+
clearInterval(iv);
|
|
287
|
+
resolve(true);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
}, 50);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
forceClose(updateState = false) {
|
|
294
|
+
const sp = this.sp;
|
|
295
|
+
if (!this.sp)
|
|
296
|
+
return;
|
|
297
|
+
this.sp.removeAllListeners();
|
|
298
|
+
try {
|
|
299
|
+
sp.unpipe();
|
|
300
|
+
sp.flush();
|
|
301
|
+
}
|
|
302
|
+
catch (_a) { }
|
|
303
|
+
sp.close();
|
|
304
|
+
this.connected = false;
|
|
305
|
+
if (updateState)
|
|
306
|
+
this.state = { opened: false, closed: true, busy: false };
|
|
307
|
+
}
|
|
308
|
+
close() {
|
|
309
|
+
this.logEvent({ message: 'close request', port: this.portName });
|
|
310
|
+
var sp = this.sp;
|
|
311
|
+
let connected = this.connected;
|
|
312
|
+
try {
|
|
313
|
+
if (connected) {
|
|
314
|
+
if (sp) {
|
|
315
|
+
sp.unpipe();
|
|
316
|
+
sp.flush();
|
|
317
|
+
sp.close();
|
|
318
|
+
}
|
|
319
|
+
if (this.queue !== undefined) {
|
|
320
|
+
this.queue.clear();
|
|
321
|
+
this.queue = undefined;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
if (sp)
|
|
326
|
+
sp.close();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (err) {
|
|
330
|
+
this.logEvent({ message: 'close: Exception', port: this.portName, error: err.message });
|
|
331
|
+
}
|
|
332
|
+
this.connected = false;
|
|
333
|
+
const start = Date.now();
|
|
334
|
+
if (this.state.closing === undefined)
|
|
335
|
+
this.state.closing = { start, timeout: start + this.getTimeoutValue(), retry: 0, maxRetries: MAX_RETRIES };
|
|
336
|
+
else {
|
|
337
|
+
this.state.closing.start = start;
|
|
338
|
+
this.state.closing.timeout = start + this.getTimeoutValue();
|
|
339
|
+
this.state.retry = this.state.retry + 1;
|
|
340
|
+
}
|
|
341
|
+
this.state.busy = false;
|
|
342
|
+
}
|
|
343
|
+
sendTimeout(message) {
|
|
344
|
+
this.logEvent({ message: `sendCommand:${message || 'timeout'}`, port: this.portName, cmd: this.cmdCurrent });
|
|
345
|
+
delete this.state.commandsInQueue[this.cmdCurrent.command];
|
|
346
|
+
if (this.cmdCurrent.callbackErr !== undefined) {
|
|
347
|
+
let cb = this.cmdCurrent.callbackErr;
|
|
348
|
+
this.state.busy = false;
|
|
349
|
+
this.cmdCurrent = undefined;
|
|
350
|
+
this.cmdStart = undefined;
|
|
351
|
+
cb(408, { message: message || "timeout" });
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
checkForResponse() {
|
|
355
|
+
const d = Date.now();
|
|
356
|
+
const s = this.state.sending;
|
|
357
|
+
if (s === undefined)
|
|
358
|
+
return false;
|
|
359
|
+
const rejectFn = s.reject;
|
|
360
|
+
const reject = (err) => {
|
|
361
|
+
if (rejectFn && typeof rejectFn === 'function') {
|
|
362
|
+
rejectFn(err);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
const error = this.state.error;
|
|
366
|
+
if (error !== undefined) {
|
|
367
|
+
reject(error);
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
try {
|
|
371
|
+
if (this.state.waitingForACK) {
|
|
372
|
+
const timeoutACK = this.state.ack ? this.state.ack.timeout : this.state.sending.timeout;
|
|
373
|
+
if (d < timeoutACK)
|
|
374
|
+
return true;
|
|
375
|
+
reject(new Error('ACK timeout'));
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
if (d < this.state.sending.timeout)
|
|
379
|
+
return true;
|
|
380
|
+
reject(new Error('RESP timeout'));
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
catch (err) {
|
|
384
|
+
this.logEvent({ message: 'checkForResponse: Exception', port: this.portName, error: err.message, stack: err.stack });
|
|
385
|
+
}
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
getTimeoutValue(cmd) {
|
|
389
|
+
let timeout = DEFAULT_TIMEOUT;
|
|
390
|
+
if (this.settings && this.settings.tcpip && this.settings.tcpip.timeout)
|
|
391
|
+
timeout = this.settings.tcpip.timeout;
|
|
392
|
+
if (this.settings && this.settings.serial && this.settings.serial.timeout)
|
|
393
|
+
timeout = this.settings.serial.timeout;
|
|
394
|
+
if (cmd !== undefined && cmd.options !== undefined && cmd.options.timeout !== undefined) {
|
|
395
|
+
timeout = cmd.options.timeout;
|
|
396
|
+
}
|
|
397
|
+
return timeout;
|
|
398
|
+
}
|
|
399
|
+
onData(data) {
|
|
400
|
+
let cmd = '';
|
|
401
|
+
if (this.state.waitingForEnd) {
|
|
402
|
+
cmd = this.state.partialCmd;
|
|
403
|
+
}
|
|
404
|
+
const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data, 'latin1');
|
|
405
|
+
const s = this.state.sending;
|
|
406
|
+
if (s === undefined) {
|
|
407
|
+
if (this.state.input === undefined)
|
|
408
|
+
this.state.input = bufferData;
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const { portName, resolve } = this.state.sending;
|
|
412
|
+
let incoming;
|
|
413
|
+
if (this.state.input !== undefined) {
|
|
414
|
+
const arr = [this.state.input, bufferData];
|
|
415
|
+
incoming = Buffer.concat(arr);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
incoming = bufferData;
|
|
419
|
+
}
|
|
420
|
+
const response = [...incoming];
|
|
421
|
+
this.logEvent({ message: 'sendCommand:RECV', data: (0, utils_1.hexstr)(response) });
|
|
422
|
+
for (let i = 0; i < incoming.length; i++) {
|
|
423
|
+
const getRemaining = () => {
|
|
424
|
+
let remaining = '';
|
|
425
|
+
const done = i === (incoming.length - 1);
|
|
426
|
+
if (!done) {
|
|
427
|
+
for (let j = i + 1; j < incoming.length; j++)
|
|
428
|
+
remaining += String.fromCharCode(incoming.readUInt8(j));
|
|
429
|
+
}
|
|
430
|
+
return remaining;
|
|
431
|
+
};
|
|
432
|
+
const c = incoming.readUInt8(i);
|
|
433
|
+
if (c === 0x06) {
|
|
434
|
+
this.logEvent({ message: "sendCommand:ACK received:", port: portName });
|
|
435
|
+
this.state.waitingForStart = true;
|
|
436
|
+
this.state.waitingForACK = false;
|
|
437
|
+
const remaining = getRemaining();
|
|
438
|
+
if (remaining && remaining !== '')
|
|
439
|
+
return this.onData(remaining);
|
|
440
|
+
}
|
|
441
|
+
else if (c === 0x15) {
|
|
442
|
+
this.state.waitingForStart = true;
|
|
443
|
+
this.state.waitingForACK = false;
|
|
444
|
+
this.logEvent({ message: "sendCommand:NAK received:", port: portName });
|
|
445
|
+
const remaining = getRemaining();
|
|
446
|
+
if (remaining && remaining !== '')
|
|
447
|
+
return this.onData(remaining);
|
|
448
|
+
}
|
|
449
|
+
else if (c === 0x01) {
|
|
450
|
+
this.state.waitingForEnd = true;
|
|
451
|
+
}
|
|
452
|
+
else if (c === 0x17) {
|
|
453
|
+
const remaining = getRemaining();
|
|
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) });
|
|
455
|
+
this.state.waitingForEnd = false;
|
|
456
|
+
const cmdStr = cmd.substring(0, cmd.length - 2);
|
|
457
|
+
const checksumExtracted = cmd.slice(-2);
|
|
458
|
+
const checksumCalculated = (0, utils_1.checkSum)((0, utils_1.getAsciiArrayFromStr)(cmdStr), []);
|
|
459
|
+
if (checksumExtracted === checksumCalculated) {
|
|
460
|
+
this.sendACK();
|
|
461
|
+
if (this.state.sending && this.state.sending.responseCheckIv) {
|
|
462
|
+
clearInterval(this.state.sending.responseCheckIv);
|
|
463
|
+
}
|
|
464
|
+
this.state = {
|
|
465
|
+
sending: undefined,
|
|
466
|
+
busy: false,
|
|
467
|
+
writeBusy: false,
|
|
468
|
+
waitingForStart: false,
|
|
469
|
+
waitingForEnd: false,
|
|
470
|
+
waitingForACK: false,
|
|
471
|
+
};
|
|
472
|
+
const payload = cmd.substring(3, cmd.length - 2);
|
|
473
|
+
resolve(payload);
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
this.sendNAK();
|
|
477
|
+
}
|
|
478
|
+
cmd = '';
|
|
479
|
+
if (remaining)
|
|
480
|
+
return this.onData(remaining);
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
if (this.state.waitingForEnd)
|
|
484
|
+
cmd += String.fromCharCode(c);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (this.state.waitingForEnd) {
|
|
488
|
+
this.state.partialCmd = cmd;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
sendDaum8iCommand(command, queryType, payload) {
|
|
492
|
+
const tsRequest = Date.now();
|
|
493
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
494
|
+
if (this.blocked)
|
|
495
|
+
return reject(new Error('blocked'));
|
|
496
|
+
if (!this.state.busy) {
|
|
497
|
+
this.state.busy = true;
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
const message = (0, utils_1.buildMessage)(command, payload);
|
|
501
|
+
this.logEvent({ message: 'sendCommand:waiting', port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
502
|
+
const busyWait = () => {
|
|
503
|
+
return new Promise((done) => {
|
|
504
|
+
let start = Date.now();
|
|
505
|
+
let timeout = start + 5000;
|
|
506
|
+
const iv = setInterval(() => {
|
|
507
|
+
if (this.state.busy) {
|
|
508
|
+
if (Date.now() > timeout) {
|
|
509
|
+
clearInterval(iv);
|
|
510
|
+
done(false);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
clearInterval(iv);
|
|
515
|
+
done(true);
|
|
516
|
+
}
|
|
517
|
+
}, 10);
|
|
518
|
+
});
|
|
519
|
+
};
|
|
520
|
+
const res = yield busyWait();
|
|
521
|
+
if (!res) {
|
|
522
|
+
this.logEvent({ message: 'sendCommand:busy timeout', port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message), duration: Date.now() - tsRequest });
|
|
523
|
+
return reject(new Error('BUSY timeout'));
|
|
524
|
+
}
|
|
525
|
+
this.state.busy = true;
|
|
526
|
+
}
|
|
527
|
+
const writeDone = () => {
|
|
528
|
+
this.state.sending = undefined;
|
|
529
|
+
this.state.writeBusy = false;
|
|
530
|
+
this.state.busy = false;
|
|
531
|
+
this.state.sending = undefined;
|
|
532
|
+
this.state.waitingForStart = false;
|
|
533
|
+
this.state.waitingForEnd = false;
|
|
534
|
+
this.state.waitingForACK = false;
|
|
535
|
+
};
|
|
536
|
+
const port = this.sp;
|
|
537
|
+
const portName = this.portName;
|
|
538
|
+
this.state.received = [];
|
|
539
|
+
try {
|
|
540
|
+
const message = (0, utils_1.buildMessage)(command, payload);
|
|
541
|
+
const start = Date.now();
|
|
542
|
+
const timeout = start + this.getTimeoutValue();
|
|
543
|
+
this.logEvent({ message: "sendCommand:sending:", port: this.portName, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
544
|
+
this.state.writeBusy = true;
|
|
545
|
+
if (!this.connected || port === undefined) {
|
|
546
|
+
this.logEvent({ message: "sendCommand:error: not connected", port: this.portName });
|
|
547
|
+
writeDone();
|
|
548
|
+
return reject(new Error('not connected'));
|
|
549
|
+
}
|
|
550
|
+
port.write(message);
|
|
551
|
+
this.state.waitingForACK = true;
|
|
552
|
+
this.state.writeBusy = false;
|
|
553
|
+
this.state.retry = 0;
|
|
554
|
+
this.state.ack = { start, timeout };
|
|
555
|
+
this.state.sending = { command, payload, start, timeout, port, portName, tsRequest, resolve, reject };
|
|
556
|
+
const iv = this.state.sending.responseCheckIv = setInterval(() => {
|
|
557
|
+
const stillWaiting = this.checkForResponse();
|
|
558
|
+
if (!stillWaiting) {
|
|
559
|
+
clearInterval(iv);
|
|
560
|
+
writeDone();
|
|
561
|
+
}
|
|
562
|
+
}, 10);
|
|
563
|
+
}
|
|
564
|
+
catch (err) {
|
|
565
|
+
this.logEvent({ message: "sendCommand:error:", port: portName, error: err.message, stack: err.stack });
|
|
566
|
+
writeDone();
|
|
567
|
+
reject(err);
|
|
568
|
+
}
|
|
569
|
+
}));
|
|
570
|
+
}
|
|
571
|
+
sendACK() {
|
|
572
|
+
const port = this.portName;
|
|
573
|
+
this.state.writeBusy = true;
|
|
574
|
+
try {
|
|
575
|
+
this.sp.write([0x06]);
|
|
576
|
+
}
|
|
577
|
+
catch (err) { }
|
|
578
|
+
this.state.writeBusy = false;
|
|
579
|
+
this.logEvent({ message: "sendCommand:sending ACK", port, queue: this.state.commandsInQueue });
|
|
580
|
+
}
|
|
581
|
+
sendNAK() {
|
|
582
|
+
const port = this.portName;
|
|
583
|
+
try {
|
|
584
|
+
this.sp.write([0x15]);
|
|
585
|
+
}
|
|
586
|
+
catch (err) { }
|
|
587
|
+
this.logEvent({ message: "sendCommand:sending NAK", port });
|
|
588
|
+
}
|
|
589
|
+
sendReservedDaum8iCommand(command, cmdType, data) {
|
|
590
|
+
let buffer;
|
|
591
|
+
if (data !== undefined && data.length > 0) {
|
|
592
|
+
buffer = Buffer.alloc(data.length + 4);
|
|
593
|
+
buffer.writeInt16LE(command, 0);
|
|
594
|
+
buffer.writeUInt16LE(data.length, 2);
|
|
595
|
+
data.copy(buffer, 4);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
buffer = Buffer.alloc(4);
|
|
599
|
+
buffer.writeInt16LE(command, 0);
|
|
600
|
+
buffer.writeUInt16LE(0, 2);
|
|
601
|
+
}
|
|
602
|
+
const cmdData = Uint8Array.from(buffer);
|
|
603
|
+
return this.sendDaum8iCommand('M70', cmdType, (0, utils_1.bin2esc)(cmdData))
|
|
604
|
+
.then((res) => {
|
|
605
|
+
const resData = Uint8Array.from(res, x => x.charCodeAt(0));
|
|
606
|
+
const cmd = (0, utils_1.esc2bin)(resData);
|
|
607
|
+
return cmd;
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
getProtocolVersion() {
|
|
611
|
+
return this.sendDaum8iCommand('V00', 'AF', [])
|
|
612
|
+
.then((data) => {
|
|
613
|
+
const version = data.substring(0, 1) + '.' + data.substring(1);
|
|
614
|
+
return (version);
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
getDashboardVersion() {
|
|
618
|
+
return this.sendDaum8iCommand('V70', 'AF', []);
|
|
619
|
+
}
|
|
620
|
+
getDeviceType() {
|
|
621
|
+
return this.sendDaum8iCommand('Y00', 'AF', [])
|
|
622
|
+
.then((str) => {
|
|
623
|
+
let deviceType;
|
|
624
|
+
if (str === '0')
|
|
625
|
+
deviceType = 'run';
|
|
626
|
+
else if (str === '2')
|
|
627
|
+
deviceType = 'bike';
|
|
628
|
+
else if (str === '7')
|
|
629
|
+
deviceType = 'lyps';
|
|
630
|
+
else
|
|
631
|
+
throw (new Error(`unknown device type ${typeof str === 'string' ? (0, utils_1.ascii)(str.charAt(0)) : str}`));
|
|
632
|
+
return deviceType;
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
getActualBikeType() {
|
|
636
|
+
return this.sendDaum8iCommand('M72', 'AF', [])
|
|
637
|
+
.then((str) => {
|
|
638
|
+
let deviceType;
|
|
639
|
+
if (str === '0')
|
|
640
|
+
deviceType = constants_1.ACTUAL_BIKE_TYPE.ALLROUND;
|
|
641
|
+
else if (str === '1')
|
|
642
|
+
deviceType = constants_1.ACTUAL_BIKE_TYPE.RACE;
|
|
643
|
+
else if (str === '2')
|
|
644
|
+
deviceType = constants_1.ACTUAL_BIKE_TYPE.MOUNTAIN;
|
|
645
|
+
else {
|
|
646
|
+
throw (new Error(`unknown actual device type ${typeof str === 'string' ? (0, utils_1.ascii)(str.charAt(0)) : str}`));
|
|
647
|
+
}
|
|
648
|
+
this.state.actualBikeType = deviceType;
|
|
649
|
+
return deviceType;
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
setActualBikeType(actualBikeType) {
|
|
653
|
+
let bikeType;
|
|
654
|
+
switch (actualBikeType) {
|
|
655
|
+
case constants_1.ACTUAL_BIKE_TYPE.ALLROUND:
|
|
656
|
+
bikeType = '0';
|
|
657
|
+
break;
|
|
658
|
+
case constants_1.ACTUAL_BIKE_TYPE.RACE:
|
|
659
|
+
bikeType = '1';
|
|
660
|
+
break;
|
|
661
|
+
case constants_1.ACTUAL_BIKE_TYPE.TRIATHLON:
|
|
662
|
+
bikeType = '1';
|
|
663
|
+
break;
|
|
664
|
+
case constants_1.ACTUAL_BIKE_TYPE.MOUNTAIN:
|
|
665
|
+
bikeType = '2';
|
|
666
|
+
break;
|
|
667
|
+
default:
|
|
668
|
+
bikeType = undefined;
|
|
669
|
+
}
|
|
670
|
+
return this.sendDaum8iCommand(`M72${bikeType}`, 'BF', [])
|
|
671
|
+
.then((str) => {
|
|
672
|
+
let deviceType;
|
|
673
|
+
if (str === '0')
|
|
674
|
+
deviceType = constants_1.ACTUAL_BIKE_TYPE.ALLROUND;
|
|
675
|
+
else if (str === '1')
|
|
676
|
+
deviceType = constants_1.ACTUAL_BIKE_TYPE.RACE;
|
|
677
|
+
else if (str === '2')
|
|
678
|
+
deviceType = constants_1.ACTUAL_BIKE_TYPE.MOUNTAIN;
|
|
679
|
+
else
|
|
680
|
+
throw (new Error('unknown actual device type'));
|
|
681
|
+
this.state.actualBikeType = deviceType;
|
|
682
|
+
return deviceType;
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
getTrainingData() {
|
|
686
|
+
return this.sendDaum8iCommand('X70', 'AF', [])
|
|
687
|
+
.then((data) => {
|
|
688
|
+
const td = (0, utils_1.parseTrainingData)(data);
|
|
689
|
+
return td;
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
setLoadControl(enabled) {
|
|
693
|
+
const val = enabled ? (0, utils_1.ascii)('1') : (0, utils_1.ascii)('0');
|
|
694
|
+
return this.sendDaum8iCommand('S20', 'BF', [val])
|
|
695
|
+
.then((data) => {
|
|
696
|
+
const res = data === '1';
|
|
697
|
+
return res;
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
getLoadControl() {
|
|
701
|
+
return this.sendDaum8iCommand('S20', 'AF', [])
|
|
702
|
+
.then((data) => {
|
|
703
|
+
const res = data === '1';
|
|
704
|
+
return res;
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
setSlope(slope) {
|
|
708
|
+
this.logEvent({ message: 'setSlope not implemted' });
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
setPower(power) {
|
|
712
|
+
const powerStr = Number.parseFloat(power).toFixed(2);
|
|
713
|
+
return this.sendDaum8iCommand(`S23${powerStr}`, 'BF', [])
|
|
714
|
+
.then((str) => {
|
|
715
|
+
return parseInt(str);
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
getPower(power) {
|
|
719
|
+
return this.sendDaum8iCommand('S23', 'AF', [])
|
|
720
|
+
.then((str) => {
|
|
721
|
+
return parseInt(str);
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
setPerson(person) {
|
|
725
|
+
const { sex, age, length, weight } = person;
|
|
726
|
+
this.logEvent({ message: 'setPerson() request', sex, age, length, weight });
|
|
727
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, 'BF', (0, utils_1.getPersonData)(person))
|
|
728
|
+
.then((res) => {
|
|
729
|
+
const buffer = Buffer.from(res);
|
|
730
|
+
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PERSON_SET;
|
|
731
|
+
this.logEvent({ message: 'setPerson() response', success, buffer });
|
|
732
|
+
if (!success)
|
|
733
|
+
throw new Error('Illegal Response');
|
|
734
|
+
return true;
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
programUploadInit() {
|
|
738
|
+
this.logEvent({ message: 'programUploadInit() request' });
|
|
739
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN, 'BF')
|
|
740
|
+
.then((res) => {
|
|
741
|
+
const buffer = Buffer.from(res);
|
|
742
|
+
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_BEGIN;
|
|
743
|
+
this.logEvent({ message: 'programUploadInit() response', success, buffer });
|
|
744
|
+
if (!success)
|
|
745
|
+
throw new Error('Illegal Response');
|
|
746
|
+
return true;
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
programUploadStart(bikeType, route) {
|
|
750
|
+
const payload = Buffer.alloc(40);
|
|
751
|
+
const epp = route ? (0, utils_1.routeToEpp)(route) : undefined;
|
|
752
|
+
const eppLength = epp ? epp.length : 0;
|
|
753
|
+
const bikeTypeVal = (0, utils_1.getBikeType)(bikeType);
|
|
754
|
+
const wBits = route.lapMode ? DS_BITS_ENDLESS_RACE : DS_BITS_OFF;
|
|
755
|
+
payload.writeInt32LE(0, 0);
|
|
756
|
+
payload.writeInt8(bikeTypeVal, 4);
|
|
757
|
+
payload.writeInt8(0, 5);
|
|
758
|
+
payload.writeInt16LE(0, 6);
|
|
759
|
+
payload.writeInt32LE(0, 8);
|
|
760
|
+
payload.writeInt32LE(0, 12);
|
|
761
|
+
payload.writeFloatLE(0, 16);
|
|
762
|
+
payload.writeFloatLE(0, 20);
|
|
763
|
+
payload.writeInt16LE(0, 24);
|
|
764
|
+
payload.writeInt16LE(0, 26);
|
|
765
|
+
payload.writeInt16LE(0, 28);
|
|
766
|
+
payload.writeInt16LE(wBits, 30);
|
|
767
|
+
payload.writeInt32LE(7, 32);
|
|
768
|
+
payload.writeInt32LE(eppLength, 36);
|
|
769
|
+
this.logEvent({ message: 'programUploadStart() request', bikeType, length: eppLength });
|
|
770
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, 'BF', payload)
|
|
771
|
+
.then((res) => {
|
|
772
|
+
const buffer = Buffer.from(res);
|
|
773
|
+
if (buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM) {
|
|
774
|
+
this.logEvent({ message: 'programUploadStart() response', success: true });
|
|
775
|
+
return epp;
|
|
776
|
+
}
|
|
777
|
+
this.logEvent({ message: 'programUploadStart() response', success: false });
|
|
778
|
+
throw new Error('Illegal Response');
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
programUploadSendBlock(epp, offset) {
|
|
782
|
+
const remaining = epp.length - offset;
|
|
783
|
+
if (remaining <= 0)
|
|
784
|
+
return Promise.resolve(true);
|
|
785
|
+
const size = remaining > MAX_DATA_BLOCK_SIZE ? MAX_DATA_BLOCK_SIZE : remaining;
|
|
786
|
+
const payload = Buffer.alloc(size + 8);
|
|
787
|
+
payload.writeInt32LE(size, 0);
|
|
788
|
+
payload.writeInt32LE(offset, 4);
|
|
789
|
+
const chunk = Buffer.from(epp.slice(offset, offset + size));
|
|
790
|
+
chunk.copy(payload, 8);
|
|
791
|
+
this.logEvent({ message: 'programUploadSendBlock() request', offset, size });
|
|
792
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM, 'BF', payload)
|
|
793
|
+
.then((res) => {
|
|
794
|
+
const buffer = Buffer.from(res);
|
|
795
|
+
let success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM;
|
|
796
|
+
success = success && (buffer.readInt16LE(2) === 1);
|
|
797
|
+
success = success && (buffer.readInt8(4) === 1);
|
|
798
|
+
this.logEvent({ message: 'programUploadSendBlock() response' });
|
|
799
|
+
if (!success)
|
|
800
|
+
throw new Error('Illegal Response');
|
|
801
|
+
return true;
|
|
802
|
+
;
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
programUploadDone() {
|
|
806
|
+
this.logEvent({ message: 'programUploadDone() request' });
|
|
807
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END, 'BF')
|
|
808
|
+
.then((res) => {
|
|
809
|
+
const buffer = Buffer.from(res);
|
|
810
|
+
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_END;
|
|
811
|
+
this.logEvent({ message: 'programUploadDone() response', success });
|
|
812
|
+
if (!success)
|
|
813
|
+
throw new Error('Illegal Response');
|
|
814
|
+
return true;
|
|
815
|
+
;
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
programUpload(bikeType, route, onStatusUpdate) {
|
|
819
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
820
|
+
try {
|
|
821
|
+
yield this.programUploadInit();
|
|
822
|
+
const epp = yield this.programUploadStart(bikeType, route);
|
|
823
|
+
if (epp) {
|
|
824
|
+
let success = true;
|
|
825
|
+
let done = false;
|
|
826
|
+
let offset = 0;
|
|
827
|
+
if (onStatusUpdate)
|
|
828
|
+
onStatusUpdate(0, epp.length);
|
|
829
|
+
while (success && !done) {
|
|
830
|
+
success = yield this.programUploadSendBlock(epp, offset);
|
|
831
|
+
offset += MAX_DATA_BLOCK_SIZE;
|
|
832
|
+
done = offset >= epp.length;
|
|
833
|
+
if (onStatusUpdate)
|
|
834
|
+
onStatusUpdate(done ? epp.length : offset, epp.length);
|
|
835
|
+
}
|
|
836
|
+
if (done) {
|
|
837
|
+
return yield this.programUploadDone();
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
else {
|
|
841
|
+
return yield this.programUploadDone();
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
catch (err) {
|
|
845
|
+
console.log('~~~ err', err);
|
|
846
|
+
}
|
|
847
|
+
return false;
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
startProgram(programId = 1) {
|
|
851
|
+
const payload = Buffer.alloc(2);
|
|
852
|
+
payload.writeInt16LE(programId, 0);
|
|
853
|
+
this.logEvent({ message: 'startProgram() request', programId });
|
|
854
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START, 'BF', payload)
|
|
855
|
+
.then((res) => {
|
|
856
|
+
const buffer = Buffer.from(res);
|
|
857
|
+
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_START;
|
|
858
|
+
this.logEvent({ message: 'startProgram() request', programId, success });
|
|
859
|
+
if (!success)
|
|
860
|
+
throw new Error('Illegal Response');
|
|
861
|
+
return true;
|
|
862
|
+
;
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
setGear(gear) {
|
|
866
|
+
return this.sendDaum8iCommand('M71', 'BF', `${gear}`)
|
|
867
|
+
.then((str) => {
|
|
868
|
+
const gearVal = parseInt(str);
|
|
869
|
+
return gearVal > 0 ? gearVal - 1 : undefined;
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
getGear() {
|
|
873
|
+
return this.sendDaum8iCommand('M71', 'AF', '')
|
|
874
|
+
.then((str) => {
|
|
875
|
+
return parseInt(str);
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
class Daum8iTcp extends Daum8i {
|
|
880
|
+
static getClassName() { return "Daum8i"; }
|
|
881
|
+
getType() { return "Daum8iTcp"; }
|
|
882
|
+
static setSerialPort(spClass) { }
|
|
883
|
+
getInterface() { return constants_1.BIKE_INTERFACE.TCPIP; }
|
|
884
|
+
static setNetImpl(netClass) {
|
|
885
|
+
net = netClass;
|
|
886
|
+
}
|
|
887
|
+
static getSupportedInterfaces() {
|
|
888
|
+
return [constants_1.BIKE_INTERFACE.TCPIP];
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
exports.Daum8iTcp = Daum8iTcp;
|
|
892
|
+
class Daum8iSerial extends Daum8i {
|
|
893
|
+
static getClassName() { return "Daum8i"; }
|
|
894
|
+
getType() { return "Daum8iSerial"; }
|
|
895
|
+
getInterface() { return constants_1.BIKE_INTERFACE.SERIAL; }
|
|
896
|
+
static setSerialPort(spClass) {
|
|
897
|
+
__SerialPort = spClass;
|
|
898
|
+
}
|
|
899
|
+
static setNetImpl(netClass) { }
|
|
900
|
+
static getSupportedInterfaces() {
|
|
901
|
+
return [constants_1.BIKE_INTERFACE.SERIAL];
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
exports.Daum8iSerial = Daum8iSerial;
|