incyclist-devices 2.1.13 → 2.1.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.
@@ -208,8 +208,7 @@ class SerialInterface extends events_1.default {
208
208
  if (attemptNo === 0)
209
209
  this.logEvent({ message: 'checking for ports', interface: this.ifaceName, port, excludes: this.inUse });
210
210
  else
211
- this.logEvent({ message: 'checking for ports retry', interface: this.ifaceName, retry: attemptNo });
212
- attemptNo++;
211
+ attemptNo++;
213
212
  try {
214
213
  if (isTcpip) {
215
214
  const _binding = binding;
@@ -223,7 +222,7 @@ class SerialInterface extends events_1.default {
223
222
  this.logEvent({ message: 'error', fn: 'scan#detect ports', error: err.message, interface: this.ifaceName, port, excludes: this.inUse });
224
223
  }
225
224
  paths = paths.filter(p => !this.inUse.includes(p.path));
226
- if (!paths || paths.length === 0) {
225
+ if ((!paths || paths.length === 0) && attemptNo === 1) {
227
226
  this.logEvent({ message: 'scanning: no ports detected', interface: this.ifaceName, paths: paths.map(p => p.path), timeout });
228
227
  yield (0, utils_1.sleep)(1000);
229
228
  }
@@ -39,10 +39,16 @@ class Daum8008 extends comms_1.default {
39
39
  const parser = this.portPipe(new ByteLength({ length: expected }));
40
40
  if (!parser)
41
41
  return;
42
- parser.on('data', (data) => {
42
+ const onDataHandler = (data) => {
43
+ if (data.length < expected) {
44
+ this.logEvent({ message: 'Partial response', data: Buffer.from(data).toString('hex') });
45
+ return;
46
+ }
43
47
  this.portUnpipe();
48
+ parser.off('data', onDataHandler);
44
49
  this.recvState.data.enqueue({ type: 'Response', data });
45
- });
50
+ };
51
+ parser.on('data', onDataHandler);
46
52
  });
47
53
  }
48
54
  waitForResponse() {
@@ -66,12 +66,14 @@ export declare class DaumClassicSimulator {
66
66
  _timeoutResponse: number;
67
67
  _simulateNoReponseCnt: number;
68
68
  _simulateIllegalResponseCnt: number;
69
+ _simulatePartialDelayed: number;
69
70
  openHandles: Array<NodeJS.Timeout>;
70
71
  constructor();
71
72
  reset(): void;
72
73
  simulateTimeout(ms: number): void;
73
74
  simulateNoResponse(cnt?: number): void;
74
75
  simulateIllegalResponse(cnt?: number): void;
76
+ simulatePartialDelayed(cnt?: number): void;
75
77
  addHandle(handle: NodeJS.Timeout): void;
76
78
  cleanup(): void;
77
79
  isPedalling(): 0 | 1;
@@ -84,7 +86,7 @@ export declare class DaumClassicMockBinding extends MockPortBinding {
84
86
  getPath(): string;
85
87
  initHandlers(): void;
86
88
  write(buffer: Buffer): Promise<void>;
87
- emitData(data: string | Buffer): void;
89
+ emitData(data: string | Buffer): Promise<void>;
88
90
  onCheckCockpit(payload: Buffer): void;
89
91
  onGetAddress(_payload: Buffer): void;
90
92
  onGetVersion(payload: Buffer): void;
@@ -91,6 +91,7 @@ class DaumClassicSimulator {
91
91
  this._timeoutResponse = 0;
92
92
  this._simulateNoReponseCnt = 0;
93
93
  this._simulateIllegalResponseCnt = 0;
94
+ this._simulatePartialDelayed = 0;
94
95
  this.openHandles = [];
95
96
  for (let i = 0; i < 10; i++)
96
97
  this.bikes.push(Object.assign({}, DEFAULT_BIKE_DATA));
@@ -119,6 +120,9 @@ class DaumClassicSimulator {
119
120
  simulateIllegalResponse(cnt = 1) {
120
121
  this._simulateIllegalResponseCnt += cnt;
121
122
  }
123
+ simulatePartialDelayed(cnt = 1) {
124
+ this._simulatePartialDelayed += cnt;
125
+ }
122
126
  addHandle(handle) {
123
127
  this.openHandles.push(handle);
124
128
  }
@@ -202,9 +206,29 @@ class DaumClassicMockBinding extends binding_mock_1.MockPortBinding {
202
206
  });
203
207
  }
204
208
  emitData(data) {
205
- if (!this.isOpen || !this.port)
206
- return;
207
- super.emitData(data);
209
+ const _super = Object.create(null, {
210
+ emitData: { get: () => super.emitData }
211
+ });
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ if (!this.isOpen || !this.port)
214
+ return;
215
+ if (this.simulator._simulatePartialDelayed > 0) {
216
+ this.simulator._simulatePartialDelayed--;
217
+ let buffer;
218
+ if (Buffer.isBuffer(data))
219
+ buffer = data;
220
+ else
221
+ buffer = Buffer.from(data);
222
+ const data1 = buffer.subarray(0, buffer.length - 1);
223
+ const data2 = buffer.subarray(buffer.length - 1, buffer.length);
224
+ _super.emitData.call(this, data1);
225
+ yield (0, utils_1.sleep)(10);
226
+ _super.emitData.call(this, data2);
227
+ }
228
+ else {
229
+ _super.emitData.call(this, data);
230
+ }
231
+ });
208
232
  }
209
233
  onCheckCockpit(payload) {
210
234
  const bikeNo = payload.readUInt8(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.1.13",
3
+ "version": "2.1.14",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",