incyclist-devices 2.0.7 → 2.0.9
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/daum/DaumAdapter.js +4 -0
- package/lib/serial/daum/classic/adapter.d.ts +2 -2
- package/lib/serial/daum/classic/adapter.js +34 -16
- package/lib/serial/daum/classic/comms.js +9 -1
- package/lib/serial/daum/classic/mock.d.ts +2 -0
- package/lib/serial/daum/classic/mock.js +6 -1
- package/lib/serial/daum/premium/adapter.js +2 -2
- package/package.json +1 -1
|
@@ -188,6 +188,10 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
188
188
|
if (!this.logger)
|
|
189
189
|
return;
|
|
190
190
|
this.logger.logEvent(event);
|
|
191
|
+
const w = global.window;
|
|
192
|
+
if (w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) {
|
|
193
|
+
console.log('~~~ Serial', event);
|
|
194
|
+
}
|
|
191
195
|
}
|
|
192
196
|
stop() {
|
|
193
197
|
if (this.stopped)
|
|
@@ -21,8 +21,8 @@ export default class DaumClassicAdapter extends DaumAdapter {
|
|
|
21
21
|
check(): Promise<boolean>;
|
|
22
22
|
pause(): Promise<boolean>;
|
|
23
23
|
resume(): Promise<boolean>;
|
|
24
|
-
startRide(props
|
|
25
|
-
start(props
|
|
24
|
+
startRide(props?: DaumClassicDeviceProperties): Promise<boolean>;
|
|
25
|
+
start(props?: DaumClassicDeviceProperties): Promise<boolean>;
|
|
26
26
|
launch(props: DaumClassicDeviceProperties, isRelaunch?: boolean): Promise<boolean>;
|
|
27
27
|
performStart(props?: DaumClassicDeviceProperties, isRelaunch?: boolean): Promise<unknown>;
|
|
28
28
|
getCurrentBikeData(): any;
|
|
@@ -82,9 +82,9 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
82
82
|
if (this.isStopped())
|
|
83
83
|
return false;
|
|
84
84
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
this.
|
|
85
|
+
this.logEvent({ message: "checking device", port: this.getPort() });
|
|
86
86
|
const iv = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
this.
|
|
87
|
+
this.logEvent({ message: "checking device failed", port: this.getPort(), reason: 'timeout' });
|
|
88
88
|
resolve(false);
|
|
89
89
|
}), 5000);
|
|
90
90
|
try {
|
|
@@ -92,6 +92,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
92
92
|
if (!connected) {
|
|
93
93
|
clearTimeout(iv);
|
|
94
94
|
resolve(false);
|
|
95
|
+
return;
|
|
95
96
|
}
|
|
96
97
|
const address = (yield this.bike.getAddress()) || {};
|
|
97
98
|
info.bikeNo = address.bike;
|
|
@@ -101,11 +102,11 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
101
102
|
this.setName('Daum ' + info.cockpit);
|
|
102
103
|
this.setID(info.serialNo);
|
|
103
104
|
clearTimeout(iv);
|
|
104
|
-
this.
|
|
105
|
+
this.logEvent({ message: "checking device success", port: this.getPort(), info });
|
|
105
106
|
resolve(true);
|
|
106
107
|
}
|
|
107
108
|
catch (err) {
|
|
108
|
-
this.
|
|
109
|
+
this.logEvent({ message: "checking device failed", port: this.getPort(), reason: err.message || err });
|
|
109
110
|
resolve(false);
|
|
110
111
|
}
|
|
111
112
|
}));
|
|
@@ -131,16 +132,30 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
131
132
|
return resumed;
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
|
-
startRide(props) {
|
|
135
|
+
startRide(props = {}) {
|
|
135
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
this.
|
|
137
|
-
|
|
137
|
+
this.logEvent({ message: 'relaunch of device' });
|
|
138
|
+
try {
|
|
139
|
+
yield this.launch(props, true);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
this.logEvent({ message: 'start result: error', error: err.message });
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
138
146
|
});
|
|
139
147
|
}
|
|
140
|
-
start(props) {
|
|
148
|
+
start(props = {}) {
|
|
141
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
this.
|
|
143
|
-
|
|
150
|
+
this.logEvent({ message: 'initial start of device' });
|
|
151
|
+
try {
|
|
152
|
+
yield this.launch(props, false);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
this.logEvent({ message: 'start result: error', error: err.message });
|
|
157
|
+
throw err;
|
|
158
|
+
}
|
|
144
159
|
});
|
|
145
160
|
}
|
|
146
161
|
launch(props, isRelaunch = false) {
|
|
@@ -158,11 +173,11 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
158
173
|
}
|
|
159
174
|
catch (_a) { }
|
|
160
175
|
}
|
|
161
|
-
this.
|
|
176
|
+
this.logEvent({ message: 'start result: success' });
|
|
162
177
|
return true;
|
|
163
178
|
}
|
|
164
179
|
catch (err) {
|
|
165
|
-
this.
|
|
180
|
+
this.logEvent({ message: 'start result: error', error: err.message });
|
|
166
181
|
throw new Error(`could not start device, reason:${err.message}`);
|
|
167
182
|
}
|
|
168
183
|
});
|
|
@@ -176,9 +191,12 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
176
191
|
let startState = {};
|
|
177
192
|
return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
178
193
|
try {
|
|
179
|
-
this.
|
|
180
|
-
if (!isRelaunch && !this.bike.isConnected())
|
|
181
|
-
yield this.
|
|
194
|
+
this.logEvent({ message: 'start attempt', isRelaunch, isConnected: this.bike.isConnected() });
|
|
195
|
+
if (!isRelaunch && !this.bike.isConnected()) {
|
|
196
|
+
const connected = yield this.connect();
|
|
197
|
+
if (!connected)
|
|
198
|
+
throw new Error('Could not connect');
|
|
199
|
+
}
|
|
182
200
|
yield this.getBike().resetDevice();
|
|
183
201
|
if (!startState.setProg) {
|
|
184
202
|
yield this.getBike().setProg(0);
|
|
@@ -214,7 +232,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
214
232
|
return data;
|
|
215
233
|
}
|
|
216
234
|
catch (err) {
|
|
217
|
-
this.
|
|
235
|
+
this.logEvent({ message: 'start attempt failed', error: err.message });
|
|
218
236
|
if (startState.checkRunData) {
|
|
219
237
|
startState = {};
|
|
220
238
|
}
|
|
@@ -60,6 +60,10 @@ class Daum8008 {
|
|
|
60
60
|
logEvent(e) {
|
|
61
61
|
if (!this.isLoggingPaused)
|
|
62
62
|
this.logger.logEvent(e);
|
|
63
|
+
const w = global.window;
|
|
64
|
+
if (w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) {
|
|
65
|
+
console.log('~~~ DaumClassic', e);
|
|
66
|
+
}
|
|
63
67
|
}
|
|
64
68
|
connect() {
|
|
65
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -67,8 +71,10 @@ class Daum8008 {
|
|
|
67
71
|
return true;
|
|
68
72
|
}
|
|
69
73
|
try {
|
|
74
|
+
this.logEvent({ message: 'connect attempt', port: this.portName });
|
|
70
75
|
const port = yield this.serial.openPort(this.portName);
|
|
71
76
|
if (port !== null) {
|
|
77
|
+
this.logEvent({ message: 'connect success', port: this.portName });
|
|
72
78
|
this.connected = true;
|
|
73
79
|
this.sp = port;
|
|
74
80
|
this.sp.on('close', this.onPortClose.bind(this));
|
|
@@ -76,10 +82,12 @@ class Daum8008 {
|
|
|
76
82
|
return true;
|
|
77
83
|
}
|
|
78
84
|
else {
|
|
85
|
+
this.logEvent({ message: 'connect failure' });
|
|
79
86
|
return false;
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
|
-
catch (
|
|
89
|
+
catch (err) {
|
|
90
|
+
this.logEvent({ message: 'connect failure', reason: err.message });
|
|
83
91
|
return false;
|
|
84
92
|
}
|
|
85
93
|
});
|
|
@@ -77,6 +77,8 @@ class DaumClassicMockImpl {
|
|
|
77
77
|
exports.DaumClassicMockImpl = DaumClassicMockImpl;
|
|
78
78
|
const DEFAULT_BIKE_DATA = {
|
|
79
79
|
cockpitVersion: 3,
|
|
80
|
+
serialNo: '4464:<;8',
|
|
81
|
+
cockpitType: 50,
|
|
80
82
|
isPedalling: false,
|
|
81
83
|
bikeType: 0,
|
|
82
84
|
person: { weight: 75, length: 180, age: 30, sex: 0 }
|
|
@@ -208,7 +210,10 @@ class DaumClassicMockBinding extends binding_mock_1.MockPortBinding {
|
|
|
208
210
|
onGetVersion(payload) {
|
|
209
211
|
const bikeNo = payload.readUInt8(0);
|
|
210
212
|
if (bikeNo >= 0 && bikeNo < 10) {
|
|
211
|
-
const
|
|
213
|
+
const { cockpitType, serialNo } = this.simulator.bikes[bikeNo] || {};
|
|
214
|
+
const response = Buffer.from([0x73, bikeNo, 0, 0, 0, 0, 0, 0, 0, 0, cockpitType]);
|
|
215
|
+
for (let i = 0; i < serialNo.length && i < 8; i++)
|
|
216
|
+
response.writeUInt8(serialNo.charCodeAt(i), i + 2);
|
|
212
217
|
this.emitData(response);
|
|
213
218
|
}
|
|
214
219
|
}
|
|
@@ -158,7 +158,7 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
158
158
|
}
|
|
159
159
|
catch (err) {
|
|
160
160
|
this.logEvent({ message: 'start result: error', error: err.message });
|
|
161
|
-
throw
|
|
161
|
+
throw err;
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
}
|
|
@@ -171,7 +171,7 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
171
171
|
}
|
|
172
172
|
catch (err) {
|
|
173
173
|
this.logEvent({ message: 'start result: error', error: err.message });
|
|
174
|
-
throw
|
|
174
|
+
throw err;
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
177
|
}
|