incyclist-devices 2.1.4 → 2.1.6

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.
@@ -333,9 +333,12 @@ class AntAdapter extends adpater_1.default {
333
333
  try {
334
334
  this.sensorConnected = yield this.startSensor();
335
335
  if (this.sensorConnected) {
336
- this.logEvent({ message: 'sensor started', props });
336
+ this.logEvent({ message: 'sensor started', device: this.getName(), props });
337
337
  this.startStatus.sensorStarted = true;
338
338
  }
339
+ else {
340
+ this.logEvent({ message: 'start sensor failed', device: this.getName(), reason: 'unknown', props });
341
+ }
339
342
  }
340
343
  catch (err) {
341
344
  this.logEvent({ message: 'start sensor failed', device: this.getName(), reason: err.message, props });
@@ -15,6 +15,7 @@ export default class AntFEAdapter extends AntAdapter<FitnessEquipmentSensorState
15
15
  protected distanceInternal?: number;
16
16
  protected startProps: AntDeviceProperties;
17
17
  protected promiseReconnect: Promise<boolean>;
18
+ protected promiseSendUpdate: Promise<boolean>;
18
19
  constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
19
20
  getDisplayName(): string;
20
21
  isReconnecting(): boolean;
@@ -40,19 +40,26 @@ class AntFEAdapter extends adapter_1.default {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
41
  if ((this.paused || this.isReconnecting()) && !forced)
42
42
  return;
43
+ if (this.promiseSendUpdate) {
44
+ this.logEvent({ message: 'send bike update skipped', device: this.getName(), request, reason: 'busy' });
45
+ return;
46
+ }
43
47
  let isReset = request.reset && Object.keys(request).length === 1;
44
48
  const update = isReset ? this.getCyclingMode().getBikeInitRequest() : this.getCyclingMode().sendBikeUpdate(request);
45
49
  this.logEvent({ message: 'send bike update requested', device: this.getName(), update, request });
46
50
  try {
47
51
  const fe = this.sensor;
48
52
  if (update.slope !== undefined) {
49
- yield fe.sendTrackResistance(update.slope);
53
+ this.promiseSendUpdate = fe.sendTrackResistance(update.slope);
50
54
  }
51
55
  if (update.targetPower !== undefined) {
52
- yield fe.sendTargetPower(update.targetPower);
56
+ this.promiseSendUpdate = fe.sendTargetPower(update.targetPower);
53
57
  }
58
+ yield this.promiseSendUpdate;
59
+ delete this.promiseSendUpdate;
54
60
  }
55
61
  catch (err) {
62
+ delete this.promiseSendUpdate;
56
63
  if (err.message && err.message.toLowerCase() === 'timeout') {
57
64
  this.emit('timeout');
58
65
  if (this.startProps.automaticReconnect) {
@@ -141,10 +141,8 @@ class BleAdapter extends adpater_1.default {
141
141
  }
142
142
  start(props = {}) {
143
143
  return __awaiter(this, void 0, void 0, function* () {
144
- const wasPaused = this.paused;
145
144
  const wasStopped = this.stopped;
146
- if (wasPaused)
147
- this.resume();
145
+ this.resume();
148
146
  if (this.started && !wasStopped)
149
147
  return true;
150
148
  this.stopped = false;
@@ -61,10 +61,12 @@ class BleComms extends events_1.default {
61
61
  return this.connectState.isConnected;
62
62
  }
63
63
  pause() {
64
+ this.ble.pauseLogging();
64
65
  this.paused = true;
65
66
  }
66
67
  resume() {
67
68
  this.paused = false;
69
+ this.ble.resumeLogging();
68
70
  }
69
71
  getServiceUUids() {
70
72
  throw new Error("Method not implemented.");
@@ -174,9 +176,9 @@ class BleComms extends events_1.default {
174
176
  }
175
177
  initDevice() {
176
178
  this.logEvent({ message: 'get device info' });
177
- return this.getDeviceInfo().then(() => {
178
- this.emit('deviceInfo', this.deviceInfo);
179
- this.logEvent(Object.assign({ message: 'device init done' }, this.deviceInfo));
179
+ return this.getDeviceInfo().then((info) => {
180
+ this.emit('deviceInfo', info);
181
+ this.logEvent(Object.assign({ message: 'device init done' }, info));
180
182
  this.isInitialized = true;
181
183
  return true;
182
184
  });
@@ -282,6 +284,7 @@ class BleComms extends events_1.default {
282
284
  }
283
285
  connect(props) {
284
286
  return __awaiter(this, void 0, void 0, function* () {
287
+ this.ble.resumeLogging();
285
288
  if (!this.ble.isConnected()) {
286
289
  try {
287
290
  yield this.ble.connect();
@@ -382,6 +385,7 @@ class BleComms extends events_1.default {
382
385
  return __awaiter(this, void 0, void 0, function* () {
383
386
  const { id, name, address } = this;
384
387
  this.logEvent({ message: 'disconnect requested', device: { id, name, address } });
388
+ this.ble.pauseLogging();
385
389
  this.connectState.isDisconnecting = true;
386
390
  if (this.workerIv) {
387
391
  this.stopWorker();
@@ -9,6 +9,8 @@ export declare class BleLinuxBinding extends EventEmitter implements BleBinding
9
9
  static getInstance(): any;
10
10
  startScanning(serviceUUIDs?: string[] | undefined, allowDuplicates?: boolean | undefined, callback?: ((error?: Error | undefined) => void) | undefined): void;
11
11
  stopScanning(callback?: (() => void) | undefined): void;
12
+ pauseLogging(): void;
13
+ resumeLogging(): void;
12
14
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
13
15
  }
14
16
  declare const Binding: any;
@@ -23,6 +23,10 @@ class BleLinuxBinding extends events_1.default {
23
23
  stopScanning(callback) {
24
24
  throw new Error('Method not implemented.');
25
25
  }
26
+ pauseLogging() {
27
+ }
28
+ resumeLogging() {
29
+ }
26
30
  on(eventName, listener) {
27
31
  super.addListener(eventName, listener);
28
32
  if (eventName === 'stateChange') {
@@ -29,6 +29,10 @@ class Binding extends events_1.default {
29
29
  return Binding._instance;
30
30
  }
31
31
  init() { }
32
+ pauseLogging() {
33
+ }
34
+ resumeLogging() {
35
+ }
32
36
  addMock(peripheral) {
33
37
  this.peripherals.push(peripheral);
34
38
  }
@@ -43,6 +43,7 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
43
43
  comms: BleComms;
44
44
  cb: (data: any) => void;
45
45
  }[];
46
+ loggingPaused: boolean;
46
47
  static _instance: BleInterface;
47
48
  static getInstance(props?: {
48
49
  binding?: BleBinding;
@@ -57,6 +58,9 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
57
58
  stopConnectSensor(): void;
58
59
  waitForSensorConnectionFinish(): Promise<void>;
59
60
  getAdapterFactory(): BleAdapterFactory;
61
+ pauseLogging(): void;
62
+ resumeLogging(): void;
63
+ isDebugEnabled(): boolean;
60
64
  logEvent(event: any): void;
61
65
  onStateChange(state: BleInterfaceState): void;
62
66
  onError(err: any): void;
@@ -51,6 +51,7 @@ class BleInterface extends events_1.default {
51
51
  this.logger = props.logger;
52
52
  else
53
53
  this.logger = new gd_eventlog_1.EventLogger('BLE');
54
+ this.loggingPaused = false;
54
55
  }
55
56
  getBinding() { return this.binding; }
56
57
  setBinding(binding) { if (binding)
@@ -75,12 +76,38 @@ class BleInterface extends events_1.default {
75
76
  getAdapterFactory() {
76
77
  return adapter_factory_1.default.getInstance();
77
78
  }
78
- logEvent(event) {
79
- if (this.logger) {
80
- this.logger.logEvent(event);
79
+ pauseLogging() {
80
+ this.logEvent({ message: 'pause logging on BLE Interface' });
81
+ this.loggingPaused = true;
82
+ try {
83
+ this.getBinding().pauseLogging();
81
84
  }
85
+ catch (_a) { }
86
+ }
87
+ resumeLogging() {
88
+ const event = { message: 'resume logging on BLE Interface' };
89
+ this.logger.logEvent(event);
90
+ if (this.isDebugEnabled()) {
91
+ console.log('~~~ BLE', event);
92
+ }
93
+ this.loggingPaused = false;
94
+ try {
95
+ this.getBinding().resumeLogging();
96
+ }
97
+ catch (_a) { }
98
+ }
99
+ isDebugEnabled() {
82
100
  const w = global.window;
83
101
  if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG) {
102
+ return true;
103
+ }
104
+ return false;
105
+ }
106
+ logEvent(event) {
107
+ if (this.logger && !this.loggingPaused) {
108
+ this.logger.logEvent(event);
109
+ }
110
+ if (this.isDebugEnabled()) {
84
111
  console.log('~~~ BLE', event);
85
112
  }
86
113
  }
@@ -98,6 +125,7 @@ class BleInterface extends events_1.default {
98
125
  this.logEvent({ message: 'error', error: err.message, stack: err.stack });
99
126
  }
100
127
  connect(to) {
128
+ this.resumeLogging();
101
129
  const timeout = this.props.timeout || to || 2000;
102
130
  return new Promise((resolve, reject) => {
103
131
  if (this.connectState.isConnected) {
@@ -186,6 +214,7 @@ class BleInterface extends events_1.default {
186
214
  this.connectState.timeout = null;
187
215
  }
188
216
  this.logEvent({ message: 'disconnect result: success' });
217
+ this.pauseLogging();
189
218
  return true;
190
219
  });
191
220
  }
@@ -35,7 +35,7 @@ export default class BleFitnessMachineDevice extends BleComms {
35
35
  getWindSpeed(): number;
36
36
  parseIndoorBikeData(_data: Uint8Array): IndoorBikeData;
37
37
  parseFitnessMachineStatus(_data: Uint8Array): IndoorBikeData;
38
- getFitnessMachineFeatures(): Promise<IndoorBikeFeatures>;
38
+ getFitnessMachineFeatures(): Promise<IndoorBikeFeatures | undefined>;
39
39
  onData(characteristic: string, data: Buffer): boolean;
40
40
  writeFtmsMessage(requestedOpCode: any, data: any, props?: BleWriteProps): Promise<number>;
41
41
  requestControl(): Promise<boolean>;
@@ -76,7 +76,7 @@ class BleFitnessMachineDevice extends comms_1.BleComms {
76
76
  this.cw = 0.6;
77
77
  this.windSpeed = 0;
78
78
  this.wheelSize = 2100;
79
- this.data = {};
79
+ this.reset();
80
80
  this.services = BleFitnessMachineDevice.services;
81
81
  }
82
82
  static isMatching(characteristics) {
@@ -310,6 +310,7 @@ class BleFitnessMachineDevice extends comms_1.BleComms {
310
310
  }
311
311
  catch (err) {
312
312
  this.logEvent({ message: 'could not read FitnessMachineFeatures', error: err.message, stack: err.stack });
313
+ return undefined;
313
314
  }
314
315
  });
315
316
  }
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const _1 = require(".");
16
15
  const consts_1 = require("../consts");
17
16
  const comms_1 = __importDefault(require("../fm/comms"));
18
17
  const utils_1 = require("../utils");
@@ -88,7 +87,7 @@ class TacxAdvancedFitnessMachineDevice extends comms_1.default {
88
87
  return 'Smart Trainer';
89
88
  }
90
89
  getProtocol() {
91
- return _1.BleTacxComms.protocol;
90
+ return TacxAdvancedFitnessMachineDevice.protocol;
92
91
  }
93
92
  getServiceUUids() {
94
93
  return TacxAdvancedFitnessMachineDevice.services;
@@ -8,6 +8,8 @@ export type BleInterfaceState = 'unknown' | 'resetting' | 'unsupported' | 'unaut
8
8
  export interface BleBinding extends EventEmitter {
9
9
  startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, callback?: (error?: Error) => void): void;
10
10
  stopScanning(callback?: () => void): void;
11
+ pauseLogging(): any;
12
+ resumeLogging(): any;
11
13
  _bindings: any;
12
14
  state: BleInterfaceState;
13
15
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
@@ -5,6 +5,7 @@ import { SerialCommProps } from '../../types';
5
5
  import { DeviceType, IncyclistBikeData, User } from '../../../types';
6
6
  export default class Daum8008 extends SerialPortComms<DaumClassicCommsState, DaumClassicRequest, DaumClassicResponse> implements DaumSerialComms {
7
7
  protected bikeNo: number;
8
+ protected prevFailedPayload: any;
8
9
  constructor(props: SerialCommProps);
9
10
  validatePath(path: string): string;
10
11
  getDefaultLoggerName(): string;
@@ -17,7 +17,7 @@ const comms_1 = __importDefault(require("../../base/comms"));
17
17
  const utils_2 = require("./utils");
18
18
  const types_1 = require("../types");
19
19
  const ByteLength = require('@serialport/parser-byte-length');
20
- const TIMEOUT_SEND = 2000;
20
+ const TIMEOUT_SEND = 5000;
21
21
  class Daum8008 extends comms_1.default {
22
22
  constructor(props) {
23
23
  super(props);
@@ -65,11 +65,12 @@ class Daum8008 extends comms_1.default {
65
65
  return __awaiter(this, void 0, void 0, function* () {
66
66
  this.initForResponse(expected);
67
67
  yield this.write(Buffer.from(payload));
68
- const response = yield this.waitForResponse();
68
+ let response = yield this.waitForResponse();
69
69
  if (response.type === 'Error')
70
70
  throw response.error;
71
71
  if (response.data[0] !== payload[0]) {
72
72
  this.portFlush();
73
+ this.logEvent({ message: "sendCommand:received:", port: this.path, hex: Buffer.from(response.data).toString('hex') });
73
74
  throw new Error('illegal response');
74
75
  }
75
76
  return response;
@@ -91,11 +92,13 @@ class Daum8008 extends comms_1.default {
91
92
  const res = yield this.doSend(expected, payload);
92
93
  this.logEvent(Object.assign(Object.assign({ message: "sendCommand:received:" }, logPayload), { hex: Buffer.from(res.data).toString('hex') }));
93
94
  this.sendCmdPromise = null;
95
+ this.prevFailedPayload = null;
94
96
  resolve(res);
95
97
  }
96
98
  catch (err) {
97
99
  this.logEvent(Object.assign(Object.assign({ message: "sendCommand:error:" }, logPayload), { error: err.message }));
98
100
  this.sendCmdPromise = null;
101
+ this.prevFailedPayload = payload;
99
102
  reject(err);
100
103
  }
101
104
  }));
@@ -569,7 +569,7 @@ class Daum8i extends comms_1.default {
569
569
  }
570
570
  }
571
571
  catch (err) {
572
- this.logEvent({ message: 'error', fn: 'programUpload', error: err.message, stack: err.stack });
572
+ this.logEvent({ message: 'programUpload failed', reason: err.message });
573
573
  return false;
574
574
  }
575
575
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",