incyclist-devices 1.5.10 → 1.5.12

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 (136) hide show
  1. package/LICENSE +0 -0
  2. package/lib/DeviceSupport.d.ts +36 -36
  3. package/lib/DeviceSupport.js +82 -82
  4. package/lib/ant/AntAdapter.d.ts +50 -50
  5. package/lib/ant/AntAdapter.js +109 -109
  6. package/lib/ant/AntScanner.d.ts +60 -60
  7. package/lib/ant/AntScanner.js +651 -651
  8. package/lib/ant/antfe/AntFEAdapter.d.ts +83 -83
  9. package/lib/ant/antfe/AntFEAdapter.js +652 -652
  10. package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +9 -9
  11. package/lib/ant/antfe/ant-fe-adv-st-mode.js +51 -51
  12. package/lib/ant/antfe/ant-fe-erg-mode.d.ts +6 -6
  13. package/lib/ant/antfe/ant-fe-erg-mode.js +14 -14
  14. package/lib/ant/antfe/ant-fe-st-mode.d.ts +5 -5
  15. package/lib/ant/antfe/ant-fe-st-mode.js +13 -13
  16. package/lib/ant/anthrm/AntHrmAdapter.d.ts +16 -16
  17. package/lib/ant/anthrm/AntHrmAdapter.js +130 -130
  18. package/lib/ant/antpwr/pwr-adapter.d.ts +49 -49
  19. package/lib/ant/antpwr/pwr-adapter.js +251 -251
  20. package/lib/ant/utils.d.ts +1 -1
  21. package/lib/ant/utils.js +23 -23
  22. package/lib/antv2/AntAdapter.d.ts +48 -0
  23. package/lib/antv2/AntAdapter.js +104 -0
  24. package/lib/antv2/adapter-factory.d.ts +11 -11
  25. package/lib/antv2/adapter-factory.js +40 -40
  26. package/lib/antv2/ant-binding.d.ts +13 -13
  27. package/lib/antv2/ant-binding.js +27 -27
  28. package/lib/antv2/ant-device.d.ts +51 -51
  29. package/lib/antv2/ant-device.js +115 -115
  30. package/lib/antv2/ant-interface.d.ts +37 -37
  31. package/lib/antv2/ant-interface.js +255 -255
  32. package/lib/antv2/fe.d.ts +29 -29
  33. package/lib/antv2/fe.js +262 -262
  34. package/lib/antv2/hr.d.ts +18 -18
  35. package/lib/antv2/hr.js +93 -93
  36. package/lib/antv2/incyclist-protocol.d.ts +37 -37
  37. package/lib/antv2/incyclist-protocol.js +126 -126
  38. package/lib/antv2/pwr.d.ts +28 -28
  39. package/lib/antv2/pwr.js +163 -163
  40. package/lib/antv2/sensor-factory.d.ts +5 -5
  41. package/lib/antv2/sensor-factory.js +20 -20
  42. package/lib/ble/ble-device.d.ts +63 -63
  43. package/lib/ble/ble-device.js +444 -444
  44. package/lib/ble/ble-erg-mode.d.ts +18 -18
  45. package/lib/ble/ble-erg-mode.js +132 -132
  46. package/lib/ble/ble-interface.d.ts +100 -100
  47. package/lib/ble/ble-interface.js +721 -721
  48. package/lib/ble/ble-peripheral.d.ts +36 -36
  49. package/lib/ble/ble-peripheral.js +200 -200
  50. package/lib/ble/ble-st-mode.d.ts +15 -15
  51. package/lib/ble/ble-st-mode.js +95 -95
  52. package/lib/ble/ble.d.ts +129 -129
  53. package/lib/ble/ble.js +86 -86
  54. package/lib/ble/consts.d.ts +14 -14
  55. package/lib/ble/consts.js +17 -17
  56. package/lib/ble/elite.d.ts +90 -90
  57. package/lib/ble/elite.js +322 -322
  58. package/lib/ble/fm.d.ts +125 -125
  59. package/lib/ble/fm.js +745 -745
  60. package/lib/ble/hrm.d.ts +48 -48
  61. package/lib/ble/hrm.js +134 -134
  62. package/lib/ble/incyclist-protocol.d.ts +31 -31
  63. package/lib/ble/incyclist-protocol.js +153 -153
  64. package/lib/ble/pwr.d.ts +89 -89
  65. package/lib/ble/pwr.js +321 -321
  66. package/lib/ble/tacx.d.ts +92 -90
  67. package/lib/ble/tacx.js +763 -731
  68. package/lib/ble/wahoo-kickr.d.ts +98 -98
  69. package/lib/ble/wahoo-kickr.js +496 -496
  70. package/lib/calculations.d.ts +13 -13
  71. package/lib/calculations.js +150 -150
  72. package/lib/cycling-mode.d.ts +76 -76
  73. package/lib/cycling-mode.js +79 -79
  74. package/lib/daum/DaumAdapter.d.ts +66 -66
  75. package/lib/daum/DaumAdapter.js +396 -396
  76. package/lib/daum/DaumPowerMeterCyclingMode.d.ts +8 -8
  77. package/lib/daum/DaumPowerMeterCyclingMode.js +21 -21
  78. package/lib/daum/ERGCyclingMode.d.ts +26 -26
  79. package/lib/daum/ERGCyclingMode.js +201 -201
  80. package/lib/daum/SmartTrainerCyclingMode.d.ts +41 -41
  81. package/lib/daum/SmartTrainerCyclingMode.js +344 -344
  82. package/lib/daum/classic/DaumClassicAdapter.d.ts +22 -18
  83. package/lib/daum/classic/DaumClassicAdapter.js +183 -146
  84. package/lib/daum/classic/DaumClassicCyclingMode.d.ts +13 -13
  85. package/lib/daum/classic/DaumClassicCyclingMode.js +97 -97
  86. package/lib/daum/classic/DaumClassicProtocol.d.ts +27 -27
  87. package/lib/daum/classic/DaumClassicProtocol.js +185 -185
  88. package/lib/daum/classic/bike.d.ts +68 -64
  89. package/lib/daum/classic/bike.js +467 -456
  90. package/lib/daum/classic/utils.d.ts +13 -13
  91. package/lib/daum/classic/utils.js +143 -143
  92. package/lib/daum/constants.d.ts +19 -19
  93. package/lib/daum/constants.js +22 -22
  94. package/lib/daum/premium/DaumClassicCyclingMode.d.ts +14 -14
  95. package/lib/daum/premium/DaumClassicCyclingMode.js +86 -86
  96. package/lib/daum/premium/DaumPremiumAdapter.d.ts +16 -14
  97. package/lib/daum/premium/DaumPremiumAdapter.js +163 -139
  98. package/lib/daum/premium/DaumPremiumProtocol.d.ts +32 -32
  99. package/lib/daum/premium/DaumPremiumProtocol.js +207 -207
  100. package/lib/daum/premium/bike.d.ts +127 -123
  101. package/lib/daum/premium/bike.js +904 -894
  102. package/lib/daum/premium/tcpserial.d.ts +33 -33
  103. package/lib/daum/premium/tcpserial.js +123 -123
  104. package/lib/daum/premium/utils.d.ts +62 -62
  105. package/lib/daum/premium/utils.js +376 -376
  106. package/lib/device.d.ts +92 -92
  107. package/lib/device.js +71 -71
  108. package/lib/kettler/comms.d.ts +59 -59
  109. package/lib/kettler/comms.js +242 -242
  110. package/lib/kettler/ergo-racer/ERGCyclingMode.d.ts +25 -25
  111. package/lib/kettler/ergo-racer/ERGCyclingMode.js +144 -144
  112. package/lib/kettler/ergo-racer/adapter.d.ts +101 -101
  113. package/lib/kettler/ergo-racer/adapter.js +639 -639
  114. package/lib/kettler/ergo-racer/protocol.d.ts +41 -41
  115. package/lib/kettler/ergo-racer/protocol.js +203 -203
  116. package/lib/modes/power-base.d.ts +20 -20
  117. package/lib/modes/power-base.js +70 -70
  118. package/lib/modes/power-meter.d.ts +20 -20
  119. package/lib/modes/power-meter.js +78 -78
  120. package/lib/modes/simulator.d.ts +29 -29
  121. package/lib/modes/simulator.js +140 -140
  122. package/lib/protocol.d.ts +74 -74
  123. package/lib/protocol.js +41 -41
  124. package/lib/registry.d.ts +8 -8
  125. package/lib/registry.js +33 -33
  126. package/lib/simulator/Simulator.d.ts +69 -69
  127. package/lib/simulator/Simulator.js +288 -288
  128. package/lib/types/command.d.ts +8 -8
  129. package/lib/types/command.js +2 -2
  130. package/lib/types/route.d.ts +24 -24
  131. package/lib/types/route.js +9 -9
  132. package/lib/types/user.d.ts +11 -11
  133. package/lib/types/user.js +9 -9
  134. package/lib/utils.d.ts +14 -14
  135. package/lib/utils.js +114 -114
  136. package/package.json +47 -47
package/lib/antv2/hr.js CHANGED
@@ -1,93 +1,93 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const ant_device_1 = __importDefault(require("./ant-device"));
16
- const utils_1 = require("../ant/utils");
17
- const gd_eventlog_1 = require("gd-eventlog");
18
- class AntHrAdapter extends ant_device_1.default {
19
- constructor(sensor, protocol) {
20
- super(sensor, protocol);
21
- this.started = false;
22
- this.deviceData = {
23
- DeviceID: sensor.getDeviceID()
24
- };
25
- this.logger = new gd_eventlog_1.EventLogger('Ant+Hrm');
26
- }
27
- isBike() { return false; }
28
- isHrm() { return true; }
29
- isPower() { return false; }
30
- getName() {
31
- const deviceID = this.sensor.getDeviceID();
32
- return `Ant+Hrm ${deviceID}`;
33
- }
34
- getDisplayName() {
35
- const { DeviceID, manID, ComputedHeartRate } = this.deviceData;
36
- const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
37
- return `${(0, utils_1.getBrand)(manID)} Hrm ${DeviceID}${hrmStr}`;
38
- }
39
- onDeviceData(deviceData) {
40
- if (!this.started)
41
- return;
42
- this.deviceData = deviceData;
43
- try {
44
- if (this.onDataFn && !this.ignoreHrm && !this.paused) {
45
- if (this.lastUpdate === undefined || (Date.now() - this.lastUpdate) > this.updateFrequency) {
46
- this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
47
- const data = this.updateData(this.data, deviceData);
48
- this.onDataFn(data);
49
- this.lastUpdate = Date.now();
50
- }
51
- }
52
- }
53
- catch (err) {
54
- }
55
- }
56
- updateData(data, deviceData) {
57
- data.heartrate = deviceData.ComputedHeartRate;
58
- return data;
59
- }
60
- start(props) {
61
- const _super = Object.create(null, {
62
- start: { get: () => super.start }
63
- });
64
- return __awaiter(this, void 0, void 0, function* () {
65
- _super.start.call(this, props);
66
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
67
- const { timeout } = props || {};
68
- let to;
69
- if (timeout) {
70
- to = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
71
- yield this.stop();
72
- reject(new Error(`could not start device, reason:timeout`));
73
- }), timeout);
74
- }
75
- this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
76
- if (to)
77
- clearTimeout(to);
78
- resolve(this.started);
79
- }));
80
- });
81
- }
82
- stop() {
83
- const _super = Object.create(null, {
84
- stop: { get: () => super.stop }
85
- });
86
- return __awaiter(this, void 0, void 0, function* () {
87
- const stopped = yield this.ant.stopSensor(this.sensor);
88
- _super.stop.call(this);
89
- return stopped;
90
- });
91
- }
92
- }
93
- exports.default = AntHrAdapter;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const ant_device_1 = __importDefault(require("./ant-device"));
16
+ const utils_1 = require("../ant/utils");
17
+ const gd_eventlog_1 = require("gd-eventlog");
18
+ class AntHrAdapter extends ant_device_1.default {
19
+ constructor(sensor, protocol) {
20
+ super(sensor, protocol);
21
+ this.started = false;
22
+ this.deviceData = {
23
+ DeviceID: sensor.getDeviceID()
24
+ };
25
+ this.logger = new gd_eventlog_1.EventLogger('Ant+Hrm');
26
+ }
27
+ isBike() { return false; }
28
+ isHrm() { return true; }
29
+ isPower() { return false; }
30
+ getName() {
31
+ const deviceID = this.sensor.getDeviceID();
32
+ return `Ant+Hrm ${deviceID}`;
33
+ }
34
+ getDisplayName() {
35
+ const { DeviceID, manID, ComputedHeartRate } = this.deviceData;
36
+ const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
37
+ return `${(0, utils_1.getBrand)(manID)} Hrm ${DeviceID}${hrmStr}`;
38
+ }
39
+ onDeviceData(deviceData) {
40
+ if (!this.started)
41
+ return;
42
+ this.deviceData = deviceData;
43
+ try {
44
+ if (this.onDataFn && !this.ignoreHrm && !this.paused) {
45
+ if (this.lastUpdate === undefined || (Date.now() - this.lastUpdate) > this.updateFrequency) {
46
+ this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
47
+ const data = this.updateData(this.data, deviceData);
48
+ this.onDataFn(data);
49
+ this.lastUpdate = Date.now();
50
+ }
51
+ }
52
+ }
53
+ catch (err) {
54
+ }
55
+ }
56
+ updateData(data, deviceData) {
57
+ data.heartrate = deviceData.ComputedHeartRate;
58
+ return data;
59
+ }
60
+ start(props) {
61
+ const _super = Object.create(null, {
62
+ start: { get: () => super.start }
63
+ });
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ _super.start.call(this, props);
66
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
67
+ const { timeout } = props || {};
68
+ let to;
69
+ if (timeout) {
70
+ to = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
71
+ yield this.stop();
72
+ reject(new Error(`could not start device, reason:timeout`));
73
+ }), timeout);
74
+ }
75
+ this.started = yield this.ant.startSensor(this.sensor, this.onDeviceData.bind(this));
76
+ if (to)
77
+ clearTimeout(to);
78
+ resolve(this.started);
79
+ }));
80
+ });
81
+ }
82
+ stop() {
83
+ const _super = Object.create(null, {
84
+ stop: { get: () => super.stop }
85
+ });
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const stopped = yield this.ant.stopSensor(this.sensor);
88
+ _super.stop.call(this);
89
+ return stopped;
90
+ });
91
+ }
92
+ }
93
+ exports.default = AntHrAdapter;
@@ -1,37 +1,37 @@
1
- import { EventLogger } from "gd-eventlog";
2
- import DeviceProtocolBase, { DeviceProtocol, DeviceSettings, ScanProps } from "../protocol";
3
- import AntDeviceBinding from './ant-binding';
4
- import AntAdapter from "./ant-device";
5
- import AntInterface from "./ant-interface";
6
- export declare const mapAntProfile: (antProfile: any) => "Heartrate Monitor" | "Power Meter" | "Smart Trainer";
7
- export declare const mapIncyclistProfile: (incyclistProfile: any) => "PWR" | "HR" | "FE";
8
- export interface AntDeviceSettings extends DeviceSettings {
9
- deviceID?: string;
10
- profile: string;
11
- }
12
- export interface AntScanProps extends ScanProps {
13
- timeout?: number;
14
- profiles?: string[];
15
- }
16
- export interface AntScannerProps {
17
- timeout?: number;
18
- profiles?: string[];
19
- }
20
- export default class AntProtocol extends DeviceProtocolBase implements DeviceProtocol {
21
- logger: EventLogger;
22
- ant: AntInterface;
23
- binding: typeof AntDeviceBinding;
24
- getAnt(): AntInterface;
25
- constructor();
26
- logEvent(event: any): void;
27
- scan(props: AntScanProps): Promise<void>;
28
- stopScan(): Promise<void>;
29
- isScanning(): boolean;
30
- createDevice(request: AntDeviceSettings | AntAdapter): AntAdapter;
31
- add(settings: AntDeviceSettings): AntAdapter;
32
- getName(): string;
33
- getInterfaces(): Array<string>;
34
- isBike(): boolean;
35
- isHrm(): boolean;
36
- isPower(): boolean;
37
- }
1
+ import { EventLogger } from "gd-eventlog";
2
+ import DeviceProtocolBase, { DeviceProtocol, DeviceSettings, ScanProps } from "../protocol";
3
+ import AntDeviceBinding from './ant-binding';
4
+ import AntAdapter from "./ant-device";
5
+ import AntInterface from "./ant-interface";
6
+ export declare const mapAntProfile: (antProfile: any) => "Heartrate Monitor" | "Power Meter" | "Smart Trainer";
7
+ export declare const mapIncyclistProfile: (incyclistProfile: any) => "PWR" | "HR" | "FE";
8
+ export interface AntDeviceSettings extends DeviceSettings {
9
+ deviceID?: string;
10
+ profile: string;
11
+ }
12
+ export interface AntScanProps extends ScanProps {
13
+ timeout?: number;
14
+ profiles?: string[];
15
+ }
16
+ export interface AntScannerProps {
17
+ timeout?: number;
18
+ profiles?: string[];
19
+ }
20
+ export default class AntProtocol extends DeviceProtocolBase implements DeviceProtocol {
21
+ logger: EventLogger;
22
+ ant: AntInterface;
23
+ binding: typeof AntDeviceBinding;
24
+ getAnt(): AntInterface;
25
+ constructor();
26
+ logEvent(event: any): void;
27
+ scan(props: AntScanProps): Promise<void>;
28
+ stopScan(): Promise<void>;
29
+ isScanning(): boolean;
30
+ createDevice(request: AntDeviceSettings | AntAdapter): AntAdapter;
31
+ add(settings: AntDeviceSettings): AntAdapter;
32
+ getName(): string;
33
+ getInterfaces(): Array<string>;
34
+ isBike(): boolean;
35
+ isHrm(): boolean;
36
+ isPower(): boolean;
37
+ }
@@ -1,126 +1,126 @@
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
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.mapIncyclistProfile = exports.mapAntProfile = void 0;
35
- const gd_eventlog_1 = require("gd-eventlog");
36
- const protocol_1 = __importStar(require("../protocol"));
37
- const registry_1 = __importDefault(require("../registry"));
38
- const adapter_factory_1 = __importDefault(require("./adapter-factory"));
39
- const ant_device_1 = __importDefault(require("./ant-device"));
40
- const ant_interface_1 = __importDefault(require("./ant-interface"));
41
- const mapAntProfile = (antProfile) => {
42
- switch (antProfile) {
43
- case 'HR': return 'Heartrate Monitor';
44
- case 'PWR': return 'Power Meter';
45
- case 'FE': return 'Smart Trainer';
46
- }
47
- };
48
- exports.mapAntProfile = mapAntProfile;
49
- const mapIncyclistProfile = (incyclistProfile) => {
50
- switch (incyclistProfile) {
51
- case 'Heartrate Monitor': return 'HR';
52
- case 'Power Meter': return 'PWR';
53
- case 'Smart Trainer': return 'FE';
54
- }
55
- };
56
- exports.mapIncyclistProfile = mapIncyclistProfile;
57
- class AntProtocol extends protocol_1.default {
58
- constructor() {
59
- super();
60
- }
61
- getAnt() {
62
- if (this.ant)
63
- return this.ant;
64
- this.ant = ant_interface_1.default.getInstance();
65
- this.logger = new gd_eventlog_1.EventLogger('Ant+');
66
- return this.ant;
67
- }
68
- logEvent(event) {
69
- if (!this.logger)
70
- this.logger = new gd_eventlog_1.EventLogger('Ant+');
71
- if (this.logger)
72
- this.logger.logEvent(event);
73
- }
74
- scan(props) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const { id, onDeviceFound, onScanFinished } = props || {};
77
- const ant = this.getAnt();
78
- ant.on('detected', (profile, deviceID) => {
79
- console.log('detected', profile, deviceID);
80
- if (onDeviceFound) {
81
- const detected = { profile, deviceID };
82
- const device = adapter_factory_1.default.create({ detected }, this);
83
- onDeviceFound(device, this);
84
- }
85
- });
86
- this.logEvent({ message: 'scan' });
87
- yield ant.scan(props);
88
- if (onScanFinished) {
89
- onScanFinished(id);
90
- }
91
- });
92
- }
93
- stopScan() {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- const ant = this.getAnt();
96
- yield ant.stopScan();
97
- });
98
- }
99
- isScanning() {
100
- const ant = this.getAnt();
101
- return ant.isScanning();
102
- }
103
- createDevice(request) {
104
- const fromAdapter = request instanceof ant_device_1.default;
105
- let device = undefined;
106
- if (fromAdapter)
107
- device = request;
108
- else {
109
- device = adapter_factory_1.default.create({ configuration: request }, this);
110
- }
111
- return device;
112
- }
113
- add(settings) {
114
- this.logEvent({ message: 'adding device', settings });
115
- const device = this.createDevice(settings);
116
- this.devices.push(device);
117
- return device;
118
- }
119
- getName() { return 'Ant'; }
120
- getInterfaces() { return [protocol_1.INTERFACE.ANT]; }
121
- isBike() { return true; }
122
- isHrm() { return true; }
123
- isPower() { return true; }
124
- }
125
- exports.default = AntProtocol;
126
- registry_1.default.register(new AntProtocol());
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
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.mapIncyclistProfile = exports.mapAntProfile = void 0;
35
+ const gd_eventlog_1 = require("gd-eventlog");
36
+ const protocol_1 = __importStar(require("../protocol"));
37
+ const registry_1 = __importDefault(require("../registry"));
38
+ const adapter_factory_1 = __importDefault(require("./adapter-factory"));
39
+ const ant_device_1 = __importDefault(require("./ant-device"));
40
+ const ant_interface_1 = __importDefault(require("./ant-interface"));
41
+ const mapAntProfile = (antProfile) => {
42
+ switch (antProfile) {
43
+ case 'HR': return 'Heartrate Monitor';
44
+ case 'PWR': return 'Power Meter';
45
+ case 'FE': return 'Smart Trainer';
46
+ }
47
+ };
48
+ exports.mapAntProfile = mapAntProfile;
49
+ const mapIncyclistProfile = (incyclistProfile) => {
50
+ switch (incyclistProfile) {
51
+ case 'Heartrate Monitor': return 'HR';
52
+ case 'Power Meter': return 'PWR';
53
+ case 'Smart Trainer': return 'FE';
54
+ }
55
+ };
56
+ exports.mapIncyclistProfile = mapIncyclistProfile;
57
+ class AntProtocol extends protocol_1.default {
58
+ constructor() {
59
+ super();
60
+ }
61
+ getAnt() {
62
+ if (this.ant)
63
+ return this.ant;
64
+ this.ant = ant_interface_1.default.getInstance();
65
+ this.logger = new gd_eventlog_1.EventLogger('Ant+');
66
+ return this.ant;
67
+ }
68
+ logEvent(event) {
69
+ if (!this.logger)
70
+ this.logger = new gd_eventlog_1.EventLogger('Ant+');
71
+ if (this.logger)
72
+ this.logger.logEvent(event);
73
+ }
74
+ scan(props) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const { id, onDeviceFound, onScanFinished } = props || {};
77
+ const ant = this.getAnt();
78
+ ant.on('detected', (profile, deviceID) => {
79
+ console.log('detected', profile, deviceID);
80
+ if (onDeviceFound) {
81
+ const detected = { profile, deviceID };
82
+ const device = adapter_factory_1.default.create({ detected }, this);
83
+ onDeviceFound(device, this);
84
+ }
85
+ });
86
+ this.logEvent({ message: 'scan' });
87
+ yield ant.scan(props);
88
+ if (onScanFinished) {
89
+ onScanFinished(id);
90
+ }
91
+ });
92
+ }
93
+ stopScan() {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const ant = this.getAnt();
96
+ yield ant.stopScan();
97
+ });
98
+ }
99
+ isScanning() {
100
+ const ant = this.getAnt();
101
+ return ant.isScanning();
102
+ }
103
+ createDevice(request) {
104
+ const fromAdapter = request instanceof ant_device_1.default;
105
+ let device = undefined;
106
+ if (fromAdapter)
107
+ device = request;
108
+ else {
109
+ device = adapter_factory_1.default.create({ configuration: request }, this);
110
+ }
111
+ return device;
112
+ }
113
+ add(settings) {
114
+ this.logEvent({ message: 'adding device', settings });
115
+ const device = this.createDevice(settings);
116
+ this.devices.push(device);
117
+ return device;
118
+ }
119
+ getName() { return 'Ant'; }
120
+ getInterfaces() { return [protocol_1.INTERFACE.ANT]; }
121
+ isBike() { return true; }
122
+ isHrm() { return true; }
123
+ isPower() { return true; }
124
+ }
125
+ exports.default = AntProtocol;
126
+ registry_1.default.register(new AntProtocol());
@@ -1,28 +1,28 @@
1
- import { ISensor } from "incyclist-ant-plus";
2
- import AntAdapter from "./ant-device";
3
- import AntProtocol from "./incyclist-protocol";
4
- import { EventLogger } from "gd-eventlog";
5
- import CyclingMode, { IncyclistBikeData } from '../cycling-mode';
6
- import { DeviceData } from "../device";
7
- export default class AntPwrAdapter extends AntAdapter {
8
- protected started: boolean;
9
- protected logger: EventLogger;
10
- protected mode: CyclingMode;
11
- protected distanceInternal?: number;
12
- constructor(sensor: ISensor, protocol: AntProtocol);
13
- isBike(): boolean;
14
- isHrm(): boolean;
15
- isPower(): boolean;
16
- getName(): string;
17
- getDisplayName(): string;
18
- getCyclingMode(): CyclingMode;
19
- getDefaultCyclingMode(): CyclingMode;
20
- getSupportedCyclingModes(): any[];
21
- getLogData(data: any, excludeList: any): any;
22
- onDeviceData(deviceData: any): void;
23
- sendUpdate(request: any): void;
24
- mapData(deviceData: any): IncyclistBikeData;
25
- transformData(bikeData: IncyclistBikeData): DeviceData;
26
- start(props?: any): Promise<any>;
27
- stop(): Promise<boolean>;
28
- }
1
+ import { ISensor } from "incyclist-ant-plus";
2
+ import AntAdapter from "./ant-device";
3
+ import AntProtocol from "./incyclist-protocol";
4
+ import { EventLogger } from "gd-eventlog";
5
+ import CyclingMode, { IncyclistBikeData } from '../cycling-mode';
6
+ import { DeviceData } from "../device";
7
+ export default class AntPwrAdapter extends AntAdapter {
8
+ protected started: boolean;
9
+ protected logger: EventLogger;
10
+ protected mode: CyclingMode;
11
+ protected distanceInternal?: number;
12
+ constructor(sensor: ISensor, protocol: AntProtocol);
13
+ isBike(): boolean;
14
+ isHrm(): boolean;
15
+ isPower(): boolean;
16
+ getName(): string;
17
+ getDisplayName(): string;
18
+ getCyclingMode(): CyclingMode;
19
+ getDefaultCyclingMode(): CyclingMode;
20
+ getSupportedCyclingModes(): any[];
21
+ getLogData(data: any, excludeList: any): any;
22
+ onDeviceData(deviceData: any): void;
23
+ sendUpdate(request: any): void;
24
+ mapData(deviceData: any): IncyclistBikeData;
25
+ transformData(bikeData: IncyclistBikeData): DeviceData;
26
+ start(props?: any): Promise<any>;
27
+ stop(): Promise<boolean>;
28
+ }