incyclist-devices 2.0.29 → 2.0.30

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.
@@ -174,6 +174,7 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
174
174
  return connected;
175
175
  }
176
176
  catch (err) {
177
+ yield this.bike.close();
177
178
  return false;
178
179
  }
179
180
  });
@@ -11,6 +11,7 @@ export default class DaumClassicAdapter extends DaumAdapter {
11
11
  id: string;
12
12
  started: boolean;
13
13
  startPromise: Promise<unknown>;
14
+ checkPromise: Promise<boolean>;
14
15
  constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
15
16
  setID(id: any): void;
16
17
  getID(): string;
@@ -21,6 +22,7 @@ export default class DaumClassicAdapter extends DaumAdapter {
21
22
  getSupportedCyclingModes(): Array<any>;
22
23
  getDefaultCyclingMode(): CyclingMode;
23
24
  check(): Promise<boolean>;
25
+ performCheck(): Promise<boolean>;
24
26
  pause(): Promise<boolean>;
25
27
  resume(): Promise<boolean>;
26
28
  startRide(props?: DaumClassicDeviceProperties): Promise<boolean>;
@@ -51,6 +51,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
51
51
  this.iv = undefined;
52
52
  this.distanceInternal = undefined;
53
53
  this.startPromise = undefined;
54
+ this.checkPromise = undefined;
54
55
  this.initData();
55
56
  }
56
57
  setID(id) {
@@ -81,9 +82,32 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
81
82
  }
82
83
  check() {
83
84
  return __awaiter(this, void 0, void 0, function* () {
84
- var info = {};
85
85
  if (this.isStopped())
86
86
  return false;
87
+ if (this.checkPromise) {
88
+ this.logEvent({ message: "waiting for previous check device", port: this.getPort() });
89
+ try {
90
+ yield this.checkPromise;
91
+ }
92
+ catch (_a) { }
93
+ this.logEvent({ message: "previous check device completed", port: this.getPort() });
94
+ this.checkPromise = undefined;
95
+ }
96
+ this.checkPromise = this.performCheck();
97
+ try {
98
+ const res = yield this.checkPromise;
99
+ this.checkPromise = undefined;
100
+ return res;
101
+ }
102
+ catch (err) {
103
+ this.checkPromise = undefined;
104
+ throw err;
105
+ }
106
+ });
107
+ }
108
+ performCheck() {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ var info = {};
87
111
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
88
112
  this.logEvent({ message: "checking device", port: this.getPort() });
89
113
  const iv = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
@@ -109,6 +133,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
109
133
  resolve(true);
110
134
  }
111
135
  catch (err) {
136
+ clearTimeout(iv);
112
137
  this.logEvent({ message: "checking device failed", port: this.getPort(), reason: err.message || err });
113
138
  resolve(false);
114
139
  }
@@ -94,20 +94,27 @@ class Daum8008 {
94
94
  return __awaiter(this, void 0, void 0, function* () {
95
95
  if (!this.serial)
96
96
  return;
97
+ this.closing = true;
97
98
  this.stopWorker();
98
- yield this.flush();
99
- try {
100
- yield this.serial.closePort(this.portName);
99
+ if (this.isConnected()) {
100
+ try {
101
+ yield this.flush();
102
+ }
103
+ catch (_a) { }
104
+ try {
105
+ yield this.serial.closePort(this.portName);
106
+ }
107
+ catch (_b) { }
101
108
  }
102
- catch (_a) { }
103
109
  this.connected = false;
104
- if (this.sp)
110
+ this.cmdBusy = false;
111
+ if (this.sp) {
105
112
  this.sp.removeAllListeners();
106
- this.sp = null;
113
+ this.sp = null;
114
+ }
107
115
  this.error = undefined;
108
116
  this.closing = false;
109
117
  this.closed = true;
110
- this.cmdBusy = false;
111
118
  return;
112
119
  });
113
120
  }
@@ -116,8 +123,9 @@ class Daum8008 {
116
123
  if (!this.cmdBusy)
117
124
  return;
118
125
  return new Promise(done => {
126
+ const tsStart = Date.now();
119
127
  const iv = setInterval(() => {
120
- if (!this.cmdBusy) {
128
+ if (!this.cmdBusy || (Date.now() - tsStart > TIMEOUT_SEND + 500)) {
121
129
  clearInterval(iv);
122
130
  done();
123
131
  }
@@ -176,7 +184,7 @@ class Daum8008 {
176
184
  }
177
185
  }
178
186
  }
179
- if (this.connected && this.cmdBusy) {
187
+ if (this.connected && this.cmdBusy && !this.closing) {
180
188
  if (this.cmdCurrent !== undefined && this.cmdCurrent.start !== undefined) {
181
189
  const cmdInfo = this.cmdCurrent;
182
190
  const timeout = (cmdInfo.options && cmdInfo.options.timeout) ? cmdInfo.options.timeout : this._timeoutSend;
@@ -205,7 +213,8 @@ class Daum8008 {
205
213
  return;
206
214
  }
207
215
  const cmd = this.queue.dequeue();
208
- this.send(cmd);
216
+ if (this.connected && !this.closing && !this.closed)
217
+ this.send(cmd);
209
218
  }
210
219
  sendDaum8008Command(logStr, payload, expected, callback, callbackErr, options) {
211
220
  let cmdInfo = {
@@ -175,12 +175,12 @@ class SerialInterface extends events_1.default {
175
175
  }
176
176
  openPort(path) {
177
177
  return __awaiter(this, void 0, void 0, function* () {
178
- this.logEvent({ message: 'opening port', path });
178
+ this.logEvent({ message: 'opening port', port: path });
179
179
  const existing = this.ports.findIndex(p => p.path === path);
180
180
  if (existing !== -1) {
181
181
  const port = this.ports[existing].port;
182
182
  if (port.isOpen) {
183
- this.logEvent({ message: 'opening port - port already exists', path });
183
+ this.logEvent({ message: 'opening port - port already exists', port: path });
184
184
  return port;
185
185
  }
186
186
  else {
@@ -189,7 +189,7 @@ class SerialInterface extends events_1.default {
189
189
  }
190
190
  const port = serialport_1.default.getInstance().getSerialPort(this.ifaceName, { path });
191
191
  if (!port) {
192
- this.logEvent({ message: 'opening port - port does not exist', path });
192
+ this.logEvent({ message: 'opening port - port does not exist', port: path });
193
193
  return null;
194
194
  }
195
195
  return new Promise((resolve) => {
@@ -210,7 +210,7 @@ class SerialInterface extends events_1.default {
210
210
  }
211
211
  closePort(path) {
212
212
  return __awaiter(this, void 0, void 0, function* () {
213
- this.logEvent({ message: 'closing port' });
213
+ this.logEvent({ message: 'closing port', port: path });
214
214
  const existing = this.ports.findIndex(p => p.path === path);
215
215
  if (existing === -1)
216
216
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.0.29",
3
+ "version": "2.0.30",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",