incyclist-devices 1.3.0 → 1.4.1

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.
Files changed (71) hide show
  1. package/lib/CyclingMode.d.ts +72 -0
  2. package/lib/CyclingMode.js +66 -0
  3. package/lib/Device.d.ts +48 -10
  4. package/lib/Device.js +9 -8
  5. package/lib/DeviceProtocol.d.ts +40 -12
  6. package/lib/DeviceProtocol.js +16 -16
  7. package/lib/DeviceRegistry.d.ts +4 -4
  8. package/lib/DeviceRegistry.js +10 -10
  9. package/lib/DeviceSupport.d.ts +4 -3
  10. package/lib/DeviceSupport.js +32 -8
  11. package/lib/ant/AntAdapter.d.ts +7 -3
  12. package/lib/ant/AntAdapter.js +23 -3
  13. package/lib/ant/AntScanner.d.ts +15 -6
  14. package/lib/ant/AntScanner.js +372 -128
  15. package/lib/ant/antfe/AntFEAdapter.d.ts +1 -1
  16. package/lib/ant/antfe/AntFEAdapter.js +191 -92
  17. package/lib/ant/anthrm/AntHrmAdapter.d.ts +3 -1
  18. package/lib/ant/anthrm/AntHrmAdapter.js +70 -19
  19. package/lib/ant/utils.js +2 -1
  20. package/lib/calculations.d.ts +12 -13
  21. package/lib/calculations.js +88 -125
  22. package/lib/daum/DaumAdapter.d.ts +29 -6
  23. package/lib/daum/DaumAdapter.js +219 -96
  24. package/lib/daum/ERGCyclingMode.d.ts +28 -0
  25. package/lib/daum/ERGCyclingMode.js +207 -0
  26. package/lib/daum/PowerMeterCyclingMode.d.ts +18 -0
  27. package/lib/daum/PowerMeterCyclingMode.js +79 -0
  28. package/lib/daum/SmartTrainerCyclingMode.d.ts +41 -0
  29. package/lib/daum/SmartTrainerCyclingMode.js +344 -0
  30. package/lib/daum/classic/DaumClassicAdapter.d.ts +3 -1
  31. package/lib/daum/classic/DaumClassicAdapter.js +46 -32
  32. package/lib/daum/classic/DaumClassicCyclingMode.d.ts +13 -0
  33. package/lib/daum/classic/DaumClassicCyclingMode.js +98 -0
  34. package/lib/daum/classic/DaumClassicProtocol.d.ts +5 -3
  35. package/lib/daum/classic/DaumClassicProtocol.js +47 -8
  36. package/lib/daum/classic/ERGCyclingMode.d.ts +23 -0
  37. package/lib/daum/classic/ERGCyclingMode.js +171 -0
  38. package/lib/daum/classic/bike.d.ts +41 -37
  39. package/lib/daum/classic/bike.js +86 -53
  40. package/lib/daum/classic/utils.d.ts +3 -3
  41. package/lib/daum/classic/utils.js +18 -10
  42. package/lib/daum/indoorbike.d.ts +2 -1
  43. package/lib/daum/indoorbike.js +23 -21
  44. package/lib/daum/premium/DaumPremiumAdapter.d.ts +2 -2
  45. package/lib/daum/premium/DaumPremiumAdapter.js +30 -20
  46. package/lib/daum/premium/DaumPremiumProtocol.d.ts +11 -2
  47. package/lib/daum/premium/DaumPremiumProtocol.js +57 -10
  48. package/lib/daum/premium/bike.d.ts +63 -52
  49. package/lib/daum/premium/bike.js +254 -207
  50. package/lib/daum/premium/tcpserial.d.ts +18 -14
  51. package/lib/daum/premium/tcpserial.js +44 -20
  52. package/lib/daum/premium/utils.d.ts +2 -2
  53. package/lib/simulator/Simulator.d.ts +13 -7
  54. package/lib/simulator/Simulator.js +62 -21
  55. package/lib/utils.d.ts +3 -1
  56. package/lib/utils.js +39 -18
  57. package/package.json +12 -11
  58. package/lib/ant/AntScanner.unit.tests.d.ts +0 -1
  59. package/lib/ant/AntScanner.unit.tests.js +0 -25
  60. package/lib/ant/antfe/AntFEProcessor.d.ts +0 -40
  61. package/lib/ant/antfe/AntFEProcessor.js +0 -238
  62. package/lib/ant/antfe/AntHrmProtocol.d.ts +0 -9
  63. package/lib/ant/antfe/AntHrmProtocol.js +0 -30
  64. package/lib/ant/antfe/FEDevice.d.ts +0 -1
  65. package/lib/ant/antfe/FEDevice.js +0 -7
  66. package/lib/ant/antfe/bike.d.ts +0 -47
  67. package/lib/ant/antfe/bike.js +0 -602
  68. package/lib/ant/anthrm/anthrm.d.ts +0 -33
  69. package/lib/ant/anthrm/anthrm.js +0 -523
  70. package/lib/simulator/Simulator.unit.tests.d.ts +0 -1
  71. package/lib/simulator/Simulator.unit.tests.js +0 -79
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,11 +27,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
27
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
28
  });
10
29
  };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
11
33
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const DeviceProtocol_1 = require("../../DeviceProtocol");
13
- const DeviceRegistry_1 = require("../../DeviceRegistry");
34
+ const DeviceProtocol_1 = __importStar(require("../../DeviceProtocol"));
35
+ const DeviceRegistry_1 = __importDefault(require("../../DeviceRegistry"));
14
36
  const bike_1 = require("../premium/bike");
15
- const DaumPremiumAdapter_1 = require("./DaumPremiumAdapter");
37
+ const DaumPremiumAdapter_1 = __importDefault(require("./DaumPremiumAdapter"));
16
38
  const gd_eventlog_1 = require("gd-eventlog");
17
39
  const PROTOCOL_NAME = "Daum Premium";
18
40
  const DefaultState = {
@@ -27,6 +49,19 @@ class DaumPremiumProtocol extends DeviceProtocol_1.default {
27
49
  this.logger = new gd_eventlog_1.EventLogger('DaumPremium');
28
50
  this.devices = [];
29
51
  }
52
+ add(settings) {
53
+ if (settings.interface && settings.interface === DeviceProtocol_1.INTERFACE.TCPIP) {
54
+ bike_1.Daum8iTcp.setNetImpl(DeviceProtocol_1.default.getNetImpl());
55
+ const { host } = settings;
56
+ const portName = `${host}:51955`;
57
+ return this.addDevice(bike_1.Daum8iTcp, { host, port: 51955, interface: DeviceProtocol_1.INTERFACE.TCPIP }, portName);
58
+ }
59
+ if (settings.interface && settings.interface === DeviceProtocol_1.INTERFACE.SERIAL) {
60
+ bike_1.Daum8iSerial.setSerialPort(DeviceProtocol_1.default.getSerialPort());
61
+ const { port } = settings;
62
+ return this.addDevice(bike_1.Daum8iSerial, { port, interface: DeviceProtocol_1.INTERFACE.SERIAL }, port);
63
+ }
64
+ }
30
65
  getName() {
31
66
  return PROTOCOL_NAME;
32
67
  }
@@ -45,6 +80,7 @@ class DaumPremiumProtocol extends DeviceProtocol_1.default {
45
80
  scan(props) {
46
81
  const opts = props || {};
47
82
  this.logger.logEvent({ message: 'start scan', opts });
83
+ this.state.scanning = true;
48
84
  if (opts.interface === DeviceProtocol_1.INTERFACE.TCPIP) {
49
85
  this.scanTcpip(opts);
50
86
  }
@@ -60,7 +96,8 @@ class DaumPremiumProtocol extends DeviceProtocol_1.default {
60
96
  this.devices.push(device);
61
97
  }
62
98
  else {
63
- const idx = this.devices.findIndex(d => d.getBike().getPort() === portName);
99
+ const devices = this.devices;
100
+ const idx = devices.findIndex(d => d.getBike().getPort() === portName);
64
101
  if (idx === -1) {
65
102
  const bike = new DeviceClass(opts);
66
103
  device = new DaumPremiumAdapter_1.default(this, bike);
@@ -91,6 +128,9 @@ class DaumPremiumProtocol extends DeviceProtocol_1.default {
91
128
  this.state.activeScans.push({ iv, device });
92
129
  }
93
130
  }
131
+ isScanning() {
132
+ return this.state.scanning;
133
+ }
94
134
  stopScan() {
95
135
  return __awaiter(this, void 0, void 0, function* () {
96
136
  this.logger.logEvent({ message: 'stop scan', activeScans: this.state.activeScans });
@@ -103,8 +143,9 @@ class DaumPremiumProtocol extends DeviceProtocol_1.default {
103
143
  });
104
144
  this.state.activeScans = [];
105
145
  }
106
- for (let i = 0; i < this.devices.length; i++) {
107
- const d = this.devices[i];
146
+ const devices = this.devices;
147
+ for (let i = 0; i < devices.length; i++) {
148
+ const d = devices[i];
108
149
  if (!d.isSelected() && !d.isDetected()) {
109
150
  try {
110
151
  yield d.getBike().saveClose(true);
@@ -114,8 +155,8 @@ class DaumPremiumProtocol extends DeviceProtocol_1.default {
114
155
  }
115
156
  }
116
157
  }
117
- for (let i = 0; i < this.devices.length; i++) {
118
- const d = this.devices[i];
158
+ for (let i = 0; i < devices.length; i++) {
159
+ const d = devices[i];
119
160
  if (!d.isSelected() && !d.isDetected()) {
120
161
  try {
121
162
  yield d.getBike().unblock();
@@ -136,7 +177,7 @@ class DaumPremiumProtocol extends DeviceProtocol_1.default {
136
177
  return;
137
178
  scan.scanning = true;
138
179
  device.check()
139
- .then(() => {
180
+ .then(() => __awaiter(this, void 0, void 0, function* () {
140
181
  if (this.state.stopScanning)
141
182
  return;
142
183
  const { onDeviceFound, onScanFinished, id } = opts;
@@ -146,10 +187,16 @@ class DaumPremiumProtocol extends DeviceProtocol_1.default {
146
187
  if (onScanFinished) {
147
188
  onScanFinished(id);
148
189
  }
190
+ try {
191
+ yield device.getBike().saveClose();
192
+ }
193
+ catch (err) {
194
+ this.logger.logEvent({ message: 'scanCommand warning: Could not close port', error: err.message });
195
+ }
149
196
  clearInterval(scan.iv);
150
197
  scan.iv = undefined;
151
198
  scan.scanning = false;
152
- })
199
+ }))
153
200
  .catch(() => {
154
201
  scan.scanning = false;
155
202
  });
@@ -1,77 +1,74 @@
1
- export class Daum8iTcp extends Daum8i {
2
- constructor(props: any);
3
- }
4
- export class Daum8iSerial extends Daum8i {
5
- constructor(props: any);
6
- }
1
+ import { Queue } from '../../utils';
2
+ import { EventLogger } from 'gd-eventlog';
7
3
  declare class Daum8i {
8
- static getClassName(): string;
9
- static setSerialPort(spClass: any): void;
10
- static setNetImpl(netClass: any): void;
11
- static getSupportedInterfaces(): string[];
12
- constructor(props: any);
13
- LOG: EventLogger;
14
- portName: any;
15
- tcpip: boolean;
4
+ portName: string;
5
+ logger: EventLogger;
16
6
  serial: boolean;
7
+ tcpip: boolean;
17
8
  tcpipConnection: {
18
- host: any;
19
- port: any;
9
+ host: string;
10
+ port: string;
20
11
  };
21
- port: any;
12
+ port: string;
22
13
  settings: any;
23
14
  sendRetryDelay: number;
24
15
  sp: any;
16
+ props: any;
25
17
  connected: boolean;
26
18
  blocked: boolean;
27
- state: {
28
- ack: {
29
- wait: boolean;
30
- startWait: any;
31
- };
32
- commandsInQueue: {};
33
- };
34
- bikeData: {
35
- userWeight: number;
36
- bikeWeight: number;
37
- maxPower: number;
38
- };
39
- processor: IndoorBikeProcessor;
19
+ state: any;
20
+ bikeData: any;
21
+ processor: any;
22
+ error: Error;
23
+ queue: Queue<any>;
24
+ cmdCurrent: any;
25
+ cmdStart: number;
26
+ constructor(props: any);
27
+ static getClassName(): string;
40
28
  getType(): string;
41
- getPort(): any;
29
+ static setSerialPort(spClass: any): void;
30
+ static setNetImpl(netClass: any): void;
31
+ static getSupportedInterfaces(): string[];
32
+ getPort(): string;
42
33
  isConnected(): boolean;
43
34
  setUser(user: any, callback: any): void;
44
35
  getUserWeight(): any;
45
36
  getBikeWeight(): number;
46
37
  unblock(): void;
47
- connect(retry: any): void;
48
- firstOpen: boolean;
38
+ connect(): void;
49
39
  reconnect(): Promise<void>;
50
- saveConnect(): Promise<any>;
40
+ saveConnect(): Promise<unknown>;
51
41
  onPortOpen(): void;
52
- error: any;
53
42
  onPortClose(): void;
54
- onPortError(error: any): NodeJS.Timeout;
43
+ getLogState(): {
44
+ sending: any;
45
+ busy: any;
46
+ writeBusy: any;
47
+ opening: any;
48
+ connecting: any;
49
+ waitingForStart: any;
50
+ waitingForEnd: any;
51
+ waitingForAck: any;
52
+ retry: any;
53
+ };
54
+ onPortError(error: any): void;
55
55
  errorHandler(): void;
56
- saveClose(force: any): Promise<any>;
56
+ saveClose(force?: any): Promise<unknown>;
57
+ forceClose(updateState?: boolean): void;
57
58
  close(): void;
58
- bikeCmdWorker: any;
59
- queue: any;
60
59
  sendTimeout(message: any): void;
61
- cmdCurrent: any;
62
- cmdStart: any;
63
- checkForTimeout(reject: any): void;
64
- getTimeoutValue(cmd: any): number;
65
- onData(data: any): void;
66
- sendDaum8iCommand(command: any, queryType: any, payload: any, cb: any): Promise<any>;
60
+ checkForResponse(): boolean;
61
+ getTimeoutValue(cmd?: any): number;
62
+ onData(data: any): any;
63
+ sendDaum8iCommand(command: any, queryType: any, payload: any): Promise<unknown>;
67
64
  sendACK(): void;
68
65
  sendNAK(): void;
69
- sendReservedDaum8iCommand(command: any, cmdType: any, data: any, onData: any, onError: any): Promise<any[]>;
66
+ sendReservedDaum8iCommand(command: any, cmdType: any, data: any): Promise<any[]>;
70
67
  getProtocolVersion(): Promise<string>;
71
- getDashboardVersion(): Promise<any>;
72
- getDeviceType(): Promise<string>;
73
- getActualBikeType(): Promise<string>;
74
- setActualBikeType(actualBikeType: any): Promise<string>;
68
+ getDashboardVersion(): Promise<unknown>;
69
+ getDeviceType(): Promise<any>;
70
+ getActualBikeType(): Promise<any>;
71
+ setActualBikeType(actualBikeType: any): Promise<any>;
75
72
  getTrainingData(): Promise<{
76
73
  time: number;
77
74
  heartrate: number;
@@ -96,6 +93,20 @@ declare class Daum8i {
96
93
  setGear(gear: any): Promise<number>;
97
94
  getGear(): Promise<number>;
98
95
  }
99
- import { EventLogger } from "gd-eventlog";
100
- import IndoorBikeProcessor from "../indoorbike.js";
96
+ export declare class Daum8iTcp extends Daum8i {
97
+ static getClassName(): string;
98
+ getType(): string;
99
+ static setSerialPort(spClass: any): void;
100
+ getInterface(): string;
101
+ static setNetImpl(netClass: any): void;
102
+ static getSupportedInterfaces(): string[];
103
+ }
104
+ export declare class Daum8iSerial extends Daum8i {
105
+ static getClassName(): string;
106
+ getType(): string;
107
+ getInterface(): string;
108
+ static setSerialPort(spClass: any): void;
109
+ static setNetImpl(netClass: any): void;
110
+ static getSupportedInterfaces(): string[];
111
+ }
101
112
  export {};