incyclist-devices 1.5.21 → 1.5.22

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/antv2/fe.js CHANGED
@@ -217,7 +217,7 @@ class AntFEAdapter extends ant_device_1.default {
217
217
  }), timeout);
218
218
  this.setFEDefaultTimeout();
219
219
  let success = false;
220
- let status;
220
+ let status = { userSent: false, slopeSent: false };
221
221
  let retry = 0;
222
222
  while (!success && retry < MAX_RETRIES) {
223
223
  retry++;
@@ -239,7 +239,8 @@ class AntFEAdapter extends ant_device_1.default {
239
239
  status.userSent = status.userSent || (yield fe.sendUserConfiguration(userWeight, bikeWeight, args.wheelDiameter, args.gearRatio));
240
240
  status.slopeSent = status.slopeSent || (yield fe.sendTrackResistance(0.0));
241
241
  }
242
- catch (error) {
242
+ catch (err) {
243
+ this.logger.logEvent({ message: 'sending FE message error', error: err.message });
243
244
  try {
244
245
  yield yield this.ant.stopSensor(this.sensor);
245
246
  }
@@ -254,6 +255,7 @@ class AntFEAdapter extends ant_device_1.default {
254
255
  if (success) {
255
256
  this.logger.logEvent({ message: 'start success' });
256
257
  stopTimeoutCheck();
258
+ resolve(true);
257
259
  }
258
260
  else {
259
261
  this.logger.logEvent({ message: 'start failed' });
@@ -44,7 +44,7 @@ declare class Daum8i {
44
44
  getUserWeight(): any;
45
45
  getBikeWeight(): number;
46
46
  unblock(): void;
47
- connect(): void;
47
+ connect(): Promise<void>;
48
48
  reconnect(): Promise<void>;
49
49
  saveConnect(): Promise<unknown>;
50
50
  onPortOpen(): void;
@@ -118,87 +118,98 @@ class Daum8i {
118
118
  this.blocked = false;
119
119
  }
120
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;
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ this.logEvent({ message: "connect()", sp: (this.sp !== undefined), connected: this.connected, blocked: this.blocked, port: this.portName, settings: this.settings });
123
+ if (this.connected || this.blocked) {
124
+ return;
136
125
  }
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 });
126
+ this.state.busy = true;
127
+ this.state.commandsInQueue = {};
128
+ try {
129
+ if (this.sp !== undefined) {
130
+ try {
131
+ this.sp.removeAllListeners();
132
+ yield this.sp.close();
133
+ }
134
+ catch (err) {
135
+ }
136
+ this.sp = undefined;
143
137
  }
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);
138
+ if (this.sp === undefined) {
139
+ if (this.tcpip) {
140
+ const { host, port } = this.tcpipConnection;
141
+ const { logger } = this.props;
142
+ this.logEvent({ message: "creating TCPSocketPort", host, port });
143
+ this.sp = new tcpserial_1.default({ host, port, net, timeout: OPEN_TIMEOUT, logger });
144
+ }
145
+ else {
146
+ const settings = this.settings.port || {};
147
+ settings.autoOpen = false;
148
+ this.logEvent({ message: "creating SerialPort", port: this.port, settings });
149
+ this.sp = new __SerialPort(this.port, settings);
150
+ }
151
+ this.sp.on('open', this.onPortOpen.bind(this));
152
+ this.sp.on('close', this.onPortClose.bind(this));
153
+ this.sp.on('error', (error) => { this.onPortError(error); });
154
+ this.sp.on('data', (data) => { this.onData(data); });
149
155
  }
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); });
156
+ const start = Date.now();
157
+ this.state.connecting = true;
158
+ this.state.opening = { start, timeout: start + this.getTimeoutValue() };
159
+ this.logEvent({ message: "opening port ..." });
160
+ yield this.sp.open();
154
161
  }
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
- }
162
+ catch (err) {
163
+ this.logEvent({ message: "connect:error:", error: err.message, stack: err.stack });
164
+ this.state.busy = false;
165
+ }
166
+ });
165
167
  }
166
168
  reconnect() {
167
169
  return __awaiter(this, void 0, void 0, function* () {
168
- yield this.saveClose();
169
- yield this.saveConnect();
170
+ try {
171
+ yield this.saveClose();
172
+ yield this.saveConnect();
173
+ }
174
+ catch (_a) { }
170
175
  });
171
176
  }
172
177
  saveConnect() {
173
- return new Promise((resolve, reject) => {
178
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
174
179
  if (this.isConnected()) {
175
180
  this.state.connecting = false;
176
181
  return resolve(true);
177
182
  }
178
- this.connect();
183
+ try {
184
+ yield this.connect();
185
+ }
186
+ catch (_a) { }
179
187
  const tTimeout = Date.now() + TIMEOUT_START;
180
188
  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;
189
+ try {
190
+ if (this.state.error !== undefined) {
191
+ clearInterval(iv);
195
192
  this.forceClose();
193
+ reject(this.state.error);
194
+ this.state = { opened: false, closed: true, busy: false };
195
+ }
196
+ else if (this.isConnected()) {
197
+ this.state.connecting = false;
198
+ resolve(true);
196
199
  clearInterval(iv);
197
- reject(new Error('timeout'));
200
+ }
201
+ else {
202
+ if (Date.now() > tTimeout) {
203
+ this.state.connecting = false;
204
+ this.forceClose();
205
+ clearInterval(iv);
206
+ reject(new Error('timeout'));
207
+ }
198
208
  }
199
209
  }
210
+ catch (_a) { }
200
211
  }, 100);
201
- });
212
+ }));
202
213
  }
203
214
  onPortOpen() {
204
215
  this.error = undefined;
@@ -239,11 +250,14 @@ class Daum8i {
239
250
  this.error = error;
240
251
  if (this.blocked) {
241
252
  if (!this.state.closed) {
242
- if (this.sp) {
243
- this.sp.removeAllListeners();
244
- this.sp.close();
245
- this.sp = undefined;
253
+ try {
254
+ if (this.sp) {
255
+ this.sp.removeAllListeners();
256
+ this.sp.close();
257
+ this.sp = undefined;
258
+ }
246
259
  }
260
+ catch (_a) { }
247
261
  this.state = { opened: false, closed: true, busy: false };
248
262
  }
249
263
  return;
@@ -300,7 +314,10 @@ class Daum8i {
300
314
  sp.flush();
301
315
  }
302
316
  catch (_a) { }
303
- sp.close();
317
+ try {
318
+ sp.close();
319
+ }
320
+ catch (_b) { }
304
321
  this.connected = false;
305
322
  if (updateState)
306
323
  this.state = { opened: false, closed: true, busy: false };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.5.21",
3
+ "version": "1.5.22",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",
7
7
  "@types/serialport": "^8.0.1",
8
8
  "gd-ant-plus": "^0.0.33",
9
- "incyclist-ant-plus": "^0.1.13",
9
+ "incyclist-ant-plus": "file:../ant-plus",
10
+ "incyclist-devices": "^1.5.21",
10
11
  "win32filetime": "^1.0.2"
11
12
  },
12
13
  "peerDependencies": {