incyclist-devices 1.4.11 → 1.4.14

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.
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const gd_eventlog_1 = require("gd-eventlog");
16
16
  const utils_1 = require("../utils");
17
17
  const events_1 = __importDefault(require("events"));
18
- const DEFAULT_RCV_TIMEOUT = 500;
18
+ const DEFAULT_RCV_TIMEOUT = 1500;
19
19
  const DEBUG_LOGGER = {
20
20
  log: (e, ...args) => console.log(e, ...args),
21
21
  logEvent: (event) => console.log(JSON.stringify(event))
@@ -136,16 +136,16 @@ class KettlerSerialComms extends events_1.default {
136
136
  }
137
137
  onData(data) {
138
138
  this.sendState = SendState.Idle;
139
- this.currentCmd = undefined;
140
139
  this.logger.logEvent({ message: "sendCommand:receiving:", data: data });
141
140
  if (typeof data === 'string') {
142
- if (data.length > 2)
143
- data = data.trim();
144
- this.currentCmd.onResponse(data);
141
+ if (this.currentCmd.onResponse)
142
+ this.currentCmd.onResponse(data);
145
143
  }
146
144
  else {
147
- this.currentCmd.onResponse(data);
145
+ if (this.currentCmd.onResponse)
146
+ this.currentCmd.onResponse(data);
148
147
  }
148
+ this.currentCmd = undefined;
149
149
  }
150
150
  write(cmd) {
151
151
  this.sendState = SendState.Sending;
@@ -153,7 +153,8 @@ class KettlerSerialComms extends events_1.default {
153
153
  const msg = typeof message === 'string' ? message : utils_1.hexstr(message);
154
154
  const onError = (err) => {
155
155
  this.logger.logEvent({ message: "sendCommand:error:", cmd: logStr, error: err.message, port: this.getPort() });
156
- cmd.onError(err);
156
+ if (cmd.onError)
157
+ cmd.onError(err);
157
158
  this.sendState = SendState.Idle;
158
159
  this.currentCmd = undefined;
159
160
  };
@@ -167,7 +168,7 @@ class KettlerSerialComms extends events_1.default {
167
168
  if (timeout) {
168
169
  setTimeout(() => {
169
170
  if (this.sendState === SendState.Receiving) {
170
- onError(new Error("timeout"));
171
+ onError(new Error("response timeout"));
171
172
  }
172
173
  }, timeout);
173
174
  }
@@ -79,113 +79,115 @@ class KettlerRacerAdapter extends Device_1.default {
79
79
  return bikeWeight + userWeight;
80
80
  }
81
81
  setComputerMode() {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- return this.send('setComputerMode', 'CP').then(response => {
84
- if (response === 'ACK' || response === 'RUN') {
85
- return true;
86
- }
87
- else {
88
- return false;
89
- }
90
- });
82
+ return this.send('setComputerMode', 'CP').then(response => {
83
+ this.logger.logEvent({ response });
84
+ if (response === 'ACK' || response === 'RUN') {
85
+ return true;
86
+ }
87
+ else {
88
+ return false;
89
+ }
91
90
  });
92
91
  }
93
92
  setClientMode() {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- return this.send('setClientMode', 'CM').then(response => {
96
- if (response === 'ACK' || response === 'RUN') {
97
- return true;
98
- }
99
- else {
100
- return false;
101
- }
102
- });
93
+ return this.send('setClientMode', 'CM').then(response => {
94
+ this.logger.logEvent({ response });
95
+ if (response === 'ACK' || response === 'RUN') {
96
+ this.logger.logEvent({ response });
97
+ return true;
98
+ }
99
+ else {
100
+ return false;
101
+ }
103
102
  });
104
103
  }
105
104
  reset() {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- return this.send('reset', 'RS').then(response => {
108
- if (response === 'ACK' || response === 'RUN') {
109
- return true;
110
- }
111
- else {
112
- return false;
113
- }
114
- });
105
+ return this.send('reset', 'RS').then(response => {
106
+ this.logger.logEvent({ response });
107
+ if (response === 'ACK' || response === 'RUN') {
108
+ return true;
109
+ }
110
+ else {
111
+ return false;
112
+ }
115
113
  });
116
114
  }
117
115
  getIdentifier() {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- return this.send('getIdentifier', 'ID').then(response => {
120
- return response.substring(0, 3);
121
- });
116
+ return this.send('getIdentifier', 'ID').then(response => {
117
+ this.logger.logEvent({ response });
118
+ return response.substring(0, 3);
122
119
  });
123
120
  }
124
121
  getInterface() {
125
122
  return __awaiter(this, void 0, void 0, function* () {
126
- return this.send('getInterface', 'KI');
123
+ const res = yield this.send('getInterface', 'KI');
124
+ this.logger.logEvent({ interface: res });
125
+ return res;
127
126
  });
128
127
  }
129
128
  getVersion() {
130
129
  return __awaiter(this, void 0, void 0, function* () {
131
- return this.send('getVersion', 'VE');
130
+ const res = yield this.send('getVersion', 'VE');
131
+ this.logger.logEvent({ version: res });
132
+ return res;
132
133
  });
133
134
  }
134
135
  getCalibration() {
135
136
  return __awaiter(this, void 0, void 0, function* () {
136
- return this.send('getCalibration', 'CA');
137
+ return yield this.send('getCalibration', 'CA');
137
138
  });
138
139
  }
139
140
  startTraining() {
140
141
  return __awaiter(this, void 0, void 0, function* () {
141
- return this.send('startTraining', 'LB');
142
+ return yield this.send('startTraining', 'LB');
142
143
  });
143
144
  }
144
145
  unknownSN() {
145
146
  return __awaiter(this, void 0, void 0, function* () {
146
- return this.send('SN', 'SN');
147
+ return yield this.send('SN', 'SN');
147
148
  });
148
149
  }
149
150
  setBaudrate(baudrate) {
150
151
  return __awaiter(this, void 0, void 0, function* () {
151
- return this.send('startTraining', `BR${baudrate}`);
152
+ return yield this.send(`setBaudrate(${baudrate})`, `BR${baudrate}`);
152
153
  });
153
154
  }
154
155
  setPower(power) {
155
156
  return __awaiter(this, void 0, void 0, function* () {
156
- return this.send('setPower', `PW${power}`);
157
+ return yield this.send(`setPower(${power})`, `PW${power}`);
157
158
  });
158
159
  }
159
160
  getExtendedStatus() {
160
- return __awaiter(this, void 0, void 0, function* () {
161
- return this.send('getExtendedStatus', 'ES1').then(response => {
162
- const data = this.parseExtendedStatus(response);
163
- return data;
164
- });
161
+ return this.send('getExtendedStatus', 'ES1').then(response => {
162
+ const data = this.parseExtendedStatus(response);
163
+ return data;
165
164
  });
166
165
  }
167
166
  getStatus() {
168
- return __awaiter(this, void 0, void 0, function* () {
169
- return this.send('getExtendedStatus', 'ST').then(response => {
170
- const data = this.parseStatus(response);
171
- return data;
172
- });
167
+ return this.send('getStatus', 'ST').then(response => {
168
+ const data = this.parseStatus(response);
169
+ return data;
173
170
  });
174
171
  }
175
172
  getDB() {
176
173
  return __awaiter(this, void 0, void 0, function* () {
177
- return this.send('getDB', 'DB');
174
+ return yield this.send('getDB', 'DB');
178
175
  });
179
176
  }
180
177
  send(logStr, message, timeout) {
181
178
  return __awaiter(this, void 0, void 0, function* () {
182
- const opened = yield this.waitForOpened();
183
- if (!opened) {
184
- throw new Error('connection error');
185
- }
186
- return new Promise((resolve, reject) => {
187
- this.comms.send({ logStr, message, onError: reject, onResponse: resolve, timeout });
188
- });
179
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
180
+ try {
181
+ const opened = yield this.waitForOpened();
182
+ if (!opened) {
183
+ reject(new Error('connection error'));
184
+ }
185
+ }
186
+ catch (err) {
187
+ reject(err);
188
+ }
189
+ this.comms.send({ logStr, message, onResponse: resolve, onError: reject, timeout });
190
+ }));
189
191
  });
190
192
  }
191
193
  parseExtendedStatus(data) {
@@ -248,13 +250,17 @@ class KettlerRacerAdapter extends Device_1.default {
248
250
  reject(new Error(`timeout`));
249
251
  }), 5000);
250
252
  if (!info.pcMode)
251
- info.pcMode = yield this.setComputerMode();
252
- if (!info.interface)
253
- info.interface = yield this.getInterface();
254
- if (!info.version)
255
- info.version = yield this.getVersion();
253
+ info.pcMode = yield this.setClientMode();
256
254
  if (!info.id)
257
255
  info.id = yield this.getIdentifier();
256
+ if (!info.version)
257
+ info.version = yield this.getVersion();
258
+ try {
259
+ yield this.getInterface();
260
+ }
261
+ catch (e) {
262
+ this.logger.logEvent({ message: 'Error', error: e.message });
263
+ }
258
264
  clearTimeout(iv);
259
265
  resolve(info);
260
266
  }
@@ -268,7 +274,6 @@ class KettlerRacerAdapter extends Device_1.default {
268
274
  }
269
275
  start(props) {
270
276
  this.logger.logEvent({ message: 'start()' });
271
- const opts = props || {};
272
277
  var info = {};
273
278
  return utils_1.runWithRetries(() => __awaiter(this, void 0, void 0, function* () {
274
279
  try {
@@ -278,12 +283,25 @@ class KettlerRacerAdapter extends Device_1.default {
278
283
  if (!info.started) {
279
284
  info.started = yield this.startTraining();
280
285
  }
286
+ try {
287
+ yield this.setPower(100);
288
+ }
289
+ catch (e) {
290
+ this.logger.logEvent({ message: 'Error', error: e.message });
291
+ }
281
292
  if (!info.data) {
282
- info.data = yield this.getStatus();
293
+ yield this.update();
294
+ info.data = this.data;
283
295
  }
284
296
  return info.data;
285
297
  }
286
298
  catch (err) {
299
+ try {
300
+ yield this.reset();
301
+ }
302
+ catch (e) {
303
+ this.logger.logEvent({ message: 'Error', error: e.message });
304
+ }
287
305
  throw (new Error(`could not start device, reason:${err.message}`));
288
306
  }
289
307
  }), 5, 1000)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.4.11",
3
+ "version": "1.4.14",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",