incyclist-devices 1.5.37 → 2.0.0-beta.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 (251) hide show
  1. package/README.MD +0 -0
  2. package/lib/adapters.d.ts +6 -0
  3. package/lib/adapters.js +30 -0
  4. package/lib/antv2/adapter-factory.d.ts +20 -10
  5. package/lib/antv2/adapter-factory.js +49 -33
  6. package/lib/antv2/adapter.d.ts +64 -0
  7. package/lib/antv2/adapter.js +299 -0
  8. package/lib/antv2/ant-interface.d.ts +11 -9
  9. package/lib/antv2/ant-interface.js +15 -11
  10. package/lib/antv2/fe/adapter.d.ts +25 -0
  11. package/lib/antv2/{fe.js → fe/adapter.js} +48 -72
  12. package/lib/antv2/fe/index.d.ts +2 -0
  13. package/lib/antv2/fe/index.js +7 -0
  14. package/lib/antv2/hr/adapter.d.ts +14 -0
  15. package/lib/antv2/hr/adapter.js +73 -0
  16. package/lib/antv2/hr/index.d.ts +2 -0
  17. package/lib/antv2/hr/index.js +7 -0
  18. package/lib/antv2/index.d.ts +7 -0
  19. package/lib/antv2/index.js +20 -0
  20. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
  21. package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
  22. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
  23. package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
  24. package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
  25. package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
  26. package/lib/antv2/pwr/adapter.d.ts +22 -0
  27. package/lib/antv2/{pwr.js → pwr/adapter.js} +38 -76
  28. package/lib/antv2/pwr/index.d.ts +2 -0
  29. package/lib/antv2/pwr/index.js +7 -0
  30. package/lib/antv2/types.d.ts +19 -0
  31. package/lib/antv2/types.js +2 -0
  32. package/lib/antv2/utils.d.ts +1 -0
  33. package/lib/antv2/utils.js +181 -0
  34. package/lib/base/adpater.d.ts +56 -0
  35. package/lib/base/adpater.js +144 -0
  36. package/lib/ble/adapter-factory.d.ts +31 -0
  37. package/lib/ble/adapter-factory.js +96 -0
  38. package/lib/ble/adapter.d.ts +41 -0
  39. package/lib/ble/adapter.js +188 -0
  40. package/lib/ble/{ble-device.d.ts → ble-comms.d.ts} +9 -4
  41. package/lib/ble/{ble-device.js → ble-comms.js} +23 -11
  42. package/lib/ble/ble-interface.d.ts +15 -24
  43. package/lib/ble/ble-interface.js +32 -137
  44. package/lib/ble/ble-peripheral.d.ts +3 -3
  45. package/lib/ble/ble-peripheral.js +14 -14
  46. package/lib/ble/ble.d.ts +9 -81
  47. package/lib/ble/ble.js +1 -39
  48. package/lib/ble/consts.d.ts +2 -0
  49. package/lib/ble/consts.js +3 -1
  50. package/lib/ble/cp/adapter.d.ts +23 -0
  51. package/lib/ble/cp/adapter.js +124 -0
  52. package/lib/ble/cp/comm.d.ts +28 -0
  53. package/lib/ble/cp/comm.js +140 -0
  54. package/lib/ble/cp/index.d.ts +4 -0
  55. package/lib/ble/cp/index.js +10 -0
  56. package/lib/ble/cp/types.d.ts +13 -0
  57. package/lib/ble/cp/types.js +2 -0
  58. package/lib/ble/elite/adapter.d.ts +20 -0
  59. package/lib/ble/elite/adapter.js +127 -0
  60. package/lib/ble/elite/comms.d.ts +28 -0
  61. package/lib/ble/elite/comms.js +139 -0
  62. package/lib/ble/elite/index.d.ts +3 -0
  63. package/lib/ble/elite/index.js +10 -0
  64. package/lib/ble/fm/adapter.d.ts +21 -0
  65. package/lib/ble/fm/adapter.js +190 -0
  66. package/lib/ble/fm/comms.d.ts +50 -0
  67. package/lib/ble/{fm.js → fm/comms.js} +3 -224
  68. package/lib/ble/fm/consts.d.ts +6 -0
  69. package/lib/ble/fm/consts.js +9 -0
  70. package/lib/ble/fm/index.d.ts +5 -0
  71. package/lib/ble/fm/index.js +13 -0
  72. package/lib/ble/fm/types.d.ts +25 -0
  73. package/lib/ble/fm/types.js +2 -0
  74. package/lib/ble/hr/adapter.d.ts +17 -0
  75. package/lib/ble/hr/adapter.js +62 -0
  76. package/lib/ble/hr/comm.d.ts +15 -0
  77. package/lib/ble/hr/comm.js +52 -0
  78. package/lib/ble/hr/index.d.ts +4 -0
  79. package/lib/ble/hr/index.js +10 -0
  80. package/lib/ble/hr/types.d.ts +5 -0
  81. package/lib/ble/hr/types.js +2 -0
  82. package/lib/ble/index.d.ts +8 -0
  83. package/lib/ble/index.js +26 -0
  84. package/lib/ble/tacx/adapter.d.ts +10 -0
  85. package/lib/ble/tacx/adapter.js +93 -0
  86. package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +6 -38
  87. package/lib/ble/{tacx.js → tacx/comms.js} +13 -112
  88. package/lib/ble/tacx/index.d.ts +4 -0
  89. package/lib/ble/tacx/index.js +10 -0
  90. package/lib/ble/tacx/types.d.ts +25 -0
  91. package/lib/ble/tacx/types.js +2 -0
  92. package/lib/ble/types.d.ts +101 -0
  93. package/lib/ble/types.js +19 -0
  94. package/lib/ble/utils.d.ts +7 -0
  95. package/lib/ble/utils.js +95 -0
  96. package/lib/ble/wahoo/adapter.d.ts +9 -0
  97. package/lib/ble/wahoo/adapter.js +93 -0
  98. package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +5 -39
  99. package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +14 -112
  100. package/lib/ble/wahoo/index.d.ts +4 -0
  101. package/lib/ble/wahoo/index.js +10 -0
  102. package/lib/ble/wahoo/types.d.ts +19 -0
  103. package/lib/ble/wahoo/types.js +2 -0
  104. package/lib/device.d.ts +0 -94
  105. package/lib/device.js +0 -76
  106. package/lib/index.d.ts +12 -0
  107. package/lib/index.js +38 -0
  108. package/lib/interfaces.d.ts +6 -0
  109. package/lib/interfaces.js +23 -0
  110. package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
  111. package/lib/{ble → modes}/ble-erg-mode.js +2 -2
  112. package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
  113. package/lib/{ble → modes}/ble-st-mode.js +1 -1
  114. package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
  115. package/lib/modes/power-base.d.ts +3 -3
  116. package/lib/modes/power-base.js +4 -4
  117. package/lib/modes/power-meter.d.ts +3 -3
  118. package/lib/modes/simulator.d.ts +2 -2
  119. package/lib/modes/simulator.js +1 -1
  120. package/lib/serial/adapter-factory.d.ts +12 -0
  121. package/lib/serial/adapter-factory.js +30 -0
  122. package/lib/serial/adapter.d.ts +16 -0
  123. package/lib/serial/adapter.js +42 -0
  124. package/lib/serial/bindings/tcp.d.ts +44 -0
  125. package/lib/serial/bindings/tcp.js +270 -0
  126. package/lib/serial/comm.d.ts +7 -0
  127. package/lib/serial/comm.js +2 -0
  128. package/lib/{daum → serial/daum}/DaumAdapter.d.ts +13 -22
  129. package/lib/{daum → serial/daum}/DaumAdapter.js +44 -90
  130. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
  131. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
  132. package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
  133. package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
  134. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
  135. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
  136. package/lib/serial/daum/classic/adapter.d.ts +29 -0
  137. package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
  138. package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
  139. package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
  140. package/lib/serial/daum/classic/mock.d.ts +96 -0
  141. package/lib/serial/daum/classic/mock.js +365 -0
  142. package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
  143. package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
  144. package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
  145. package/lib/serial/daum/premium/adapter.d.ts +24 -0
  146. package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +99 -46
  147. package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
  148. package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +214 -420
  149. package/lib/serial/daum/premium/mock.d.ts +75 -0
  150. package/lib/serial/daum/premium/mock.js +290 -0
  151. package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
  152. package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
  153. package/lib/serial/daum/premium/types.d.ts +12 -0
  154. package/lib/serial/daum/premium/types.js +2 -0
  155. package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
  156. package/lib/{daum → serial/daum}/premium/utils.js +22 -63
  157. package/lib/serial/index.d.ts +9 -0
  158. package/lib/serial/index.js +49 -0
  159. package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
  160. package/lib/{kettler → serial/kettler}/comms.js +71 -32
  161. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +13 -24
  162. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +87 -130
  163. package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
  164. package/lib/serial/kettler/ergo-racer/mock.js +216 -0
  165. package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
  166. package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
  167. package/lib/serial/serial-interface.d.ts +58 -0
  168. package/lib/serial/serial-interface.js +283 -0
  169. package/lib/simulator/Simulator.d.ts +10 -25
  170. package/lib/simulator/Simulator.js +19 -83
  171. package/lib/types/adapter.d.ts +32 -0
  172. package/lib/types/adapter.js +2 -0
  173. package/lib/types/capabilities.d.ts +8 -0
  174. package/lib/types/capabilities.js +12 -0
  175. package/lib/types/data.d.ts +12 -0
  176. package/lib/types/data.js +2 -0
  177. package/lib/types/device.d.ts +29 -0
  178. package/lib/types/device.js +11 -0
  179. package/lib/types/interface.d.ts +14 -0
  180. package/lib/types/interface.js +2 -0
  181. package/lib/types/route.d.ts +2 -2
  182. package/lib/types/user.d.ts +1 -1
  183. package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
  184. package/lib/{utils.js → utils/utils.js} +5 -1
  185. package/package.json +15 -11
  186. package/lib/DeviceSupport.d.ts +0 -36
  187. package/lib/DeviceSupport.js +0 -82
  188. package/lib/ant/AntAdapter.d.ts +0 -50
  189. package/lib/ant/AntAdapter.js +0 -109
  190. package/lib/ant/AntScanner.d.ts +0 -60
  191. package/lib/ant/AntScanner.js +0 -651
  192. package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
  193. package/lib/ant/antfe/AntFEAdapter.js +0 -652
  194. package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
  195. package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
  196. package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
  197. package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
  198. package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
  199. package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
  200. package/lib/ant/antpwr/pwr-adapter.js +0 -251
  201. package/lib/ant/utils.d.ts +0 -1
  202. package/lib/ant/utils.js +0 -23
  203. package/lib/antv2/AntAdapter.d.ts +0 -48
  204. package/lib/antv2/AntAdapter.js +0 -104
  205. package/lib/antv2/ant-device.d.ts +0 -59
  206. package/lib/antv2/ant-device.js +0 -161
  207. package/lib/antv2/fe.d.ts +0 -32
  208. package/lib/antv2/hr.d.ts +0 -18
  209. package/lib/antv2/hr.js +0 -102
  210. package/lib/antv2/incyclist-protocol.d.ts +0 -37
  211. package/lib/antv2/incyclist-protocol.js +0 -126
  212. package/lib/antv2/pwr.d.ts +0 -28
  213. package/lib/ble/elite.d.ts +0 -90
  214. package/lib/ble/elite.js +0 -322
  215. package/lib/ble/fm.d.ts +0 -125
  216. package/lib/ble/hrm.d.ts +0 -48
  217. package/lib/ble/hrm.js +0 -134
  218. package/lib/ble/incyclist-protocol.d.ts +0 -31
  219. package/lib/ble/incyclist-protocol.js +0 -153
  220. package/lib/ble/pwr.d.ts +0 -89
  221. package/lib/ble/pwr.js +0 -322
  222. package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
  223. package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
  224. package/lib/daum/classic/DaumClassicProtocol.js +0 -185
  225. package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
  226. package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
  227. package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
  228. package/lib/daum/premium/tcpserial.d.ts +0 -33
  229. package/lib/daum/premium/tcpserial.js +0 -123
  230. package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
  231. package/lib/kettler/ergo-racer/protocol.js +0 -203
  232. package/lib/protocol.d.ts +0 -74
  233. package/lib/protocol.js +0 -41
  234. package/lib/registry.d.ts +0 -8
  235. package/lib/registry.js +0 -33
  236. package/lib/serialport/bindings/tcp.d.ts +0 -20
  237. package/lib/serialport/bindings/tcp.js +0 -33
  238. package/lib/serialport/index.d.ts +0 -2
  239. package/lib/serialport/index.js +0 -29
  240. package/lib/serialport/serialport.d.ts +0 -29
  241. package/lib/serialport/serialport.js +0 -87
  242. /package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +0 -0
  243. /package/lib/antv2/{ant-binding.js → binding.js} +0 -0
  244. /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
  245. /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
  246. /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
  247. /package/lib/{daum → serial/daum}/constants.js +0 -0
  248. /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
  249. /package/lib/{serialport.js → serial/serialport.js} +0 -0
  250. /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
  251. /package/lib/{calculations.js → utils/calculations.js} +0 -0
@@ -1,185 +0,0 @@
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
- const protocol_1 = __importStar(require("../../protocol"));
35
- const registry_1 = __importDefault(require("../../registry"));
36
- const bike_1 = __importDefault(require("./bike"));
37
- const DaumClassicAdapter_1 = __importDefault(require("./DaumClassicAdapter"));
38
- const gd_eventlog_1 = require("gd-eventlog");
39
- const DaumClassicAdapter_2 = __importDefault(require("./DaumClassicAdapter"));
40
- const PROTOCOL_NAME = "Daum Classic";
41
- const DefaultState = {
42
- activeScans: [],
43
- scanning: false,
44
- stopScanning: false
45
- };
46
- class DaumClassicProtocol extends protocol_1.default {
47
- constructor() {
48
- super();
49
- this.state = DefaultState;
50
- this.logger = new gd_eventlog_1.EventLogger('DaumClassic');
51
- this.devices = [];
52
- }
53
- add(settings) {
54
- this.logger.logEvent({ message: 'adding device', settings });
55
- const { port } = settings;
56
- bike_1.default.setSerialPort(protocol_1.default.getSerialPort());
57
- const bike = new bike_1.default({ port });
58
- let device = new DaumClassicAdapter_2.default(this, bike);
59
- this.devices.push(device);
60
- return device;
61
- }
62
- getName() {
63
- return PROTOCOL_NAME;
64
- }
65
- getInterfaces() {
66
- return [protocol_1.INTERFACE.SERIAL];
67
- }
68
- isBike() {
69
- return true;
70
- }
71
- isHrm() {
72
- return true;
73
- }
74
- isPower() {
75
- return true;
76
- }
77
- scan(props) {
78
- this.logger.logEvent({ message: 'start scan', id: props.id, port: props.port });
79
- bike_1.default.setSerialPort(protocol_1.default.getSerialPort());
80
- this.state.scanning = true;
81
- let device = this.addDevice(props, props.port);
82
- if (device) {
83
- const iv = setInterval(() => { this.scanCommand(device, props); }, 1000);
84
- this.state.activeScans.push({ iv, device, props });
85
- }
86
- }
87
- addDevice(opts, portName) {
88
- let device;
89
- if (this.devices.length === 0) {
90
- const bike = new bike_1.default(opts);
91
- device = new DaumClassicAdapter_1.default(this, bike);
92
- this.devices.push(device);
93
- }
94
- else {
95
- const devices = this.devices;
96
- const idx = devices.findIndex(d => d.getBike().getPort() === portName);
97
- if (idx === -1) {
98
- const bike = new bike_1.default(opts);
99
- device = new DaumClassicAdapter_1.default(this, bike);
100
- this.devices.push(device);
101
- }
102
- else {
103
- device = this.devices[idx];
104
- if (device.isSelected() || device.isDetected())
105
- device = undefined;
106
- }
107
- }
108
- return device;
109
- }
110
- stopScan() {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- if (this.state.stopScanning)
113
- return;
114
- this.state.stopScanning = true;
115
- this.logger.logEvent({ message: 'stop scan', activeScans: this.state.activeScans });
116
- const stopRequired = [];
117
- if (this.state.activeScans.length > 0) {
118
- this.state.activeScans.forEach(scan => {
119
- stopRequired.push(scan.scanning);
120
- clearInterval(scan.iv);
121
- scan.iv = undefined;
122
- scan.scanning = false;
123
- });
124
- }
125
- for (let i = 0; i < this.state.activeScans.length; i++) {
126
- const as = this.state.activeScans[i];
127
- const toStop = stopRequired[i];
128
- const d = as.device;
129
- if (!d.isSelected() && !d.isDetected()) {
130
- try {
131
- yield d.close();
132
- }
133
- catch (err) {
134
- this.logger.logEvent({ message: 'stop scan error', error: err.message });
135
- }
136
- }
137
- if (toStop) {
138
- const { id, onScanFinished } = as.props;
139
- if (onScanFinished)
140
- onScanFinished(id);
141
- }
142
- }
143
- this.state.activeScans = [];
144
- this.state.scanning = false;
145
- this.state.stopScanning = false;
146
- this.logger.logEvent({ message: 'stop scan completed' });
147
- return true;
148
- });
149
- }
150
- isScanning() {
151
- return this.state.scanning;
152
- }
153
- scanCommand(device, opts) {
154
- const scan = this.state.activeScans.find(actScan => actScan.device.getBike().getPort() === device.getBike().getPort());
155
- if (this.state.stopScanning || (scan && scan.scanning) || device.isDetected())
156
- return;
157
- scan.scanning = true;
158
- return device.check()
159
- .then(() => __awaiter(this, void 0, void 0, function* () {
160
- if (this.state.stopScanning)
161
- return;
162
- const { onDeviceFound, onScanFinished, id } = opts;
163
- device.setDetected();
164
- if (onDeviceFound)
165
- onDeviceFound(device, device.getProtocol());
166
- if (onScanFinished) {
167
- onScanFinished(id);
168
- }
169
- try {
170
- yield device.getBike().saveClose();
171
- }
172
- catch (err) {
173
- this.logger.logEvent({ message: 'scanCommand warning: Could not close port', error: err.message });
174
- }
175
- clearInterval(scan.iv);
176
- scan.iv = undefined;
177
- scan.scanning = false;
178
- }))
179
- .catch(() => {
180
- scan.scanning = false;
181
- });
182
- }
183
- }
184
- exports.default = DaumClassicProtocol;
185
- registry_1.default.register(new DaumClassicProtocol());
@@ -1,16 +0,0 @@
1
- import DaumAdapter from '../DaumAdapter';
2
- export default class DaumPremiumDevice extends DaumAdapter {
3
- static NAME: string;
4
- constructor(protocol: any, bike: any);
5
- getName(): string;
6
- getPort(): any;
7
- getInterface(): any;
8
- getSupportedCyclingModes(): Array<any>;
9
- check(): Promise<unknown>;
10
- pause(): Promise<boolean>;
11
- resume(): Promise<boolean>;
12
- startRide(props: any): Promise<boolean>;
13
- start(props: any): Promise<boolean>;
14
- launch(props: any, isRelaunch?: boolean): Promise<boolean>;
15
- getCurrentBikeData(): Promise<any>;
16
- }
@@ -1,32 +0,0 @@
1
- import DeviceProtocolBase, { DeviceProtocol, DeviceSettings } from '../../protocol';
2
- import { EventLogger } from 'gd-eventlog';
3
- export interface DaumPremiumProtocolState {
4
- activeScans: Array<any>;
5
- scanning: boolean;
6
- stopScanning?: boolean;
7
- }
8
- interface DaumPremiumSettings extends DeviceSettings {
9
- interface: string;
10
- }
11
- interface DaumPremiumTCPSettings extends DaumPremiumSettings {
12
- host: string;
13
- }
14
- export default class DaumPremiumProtocol extends DeviceProtocolBase implements DeviceProtocol {
15
- state: DaumPremiumProtocolState;
16
- logger: EventLogger;
17
- constructor();
18
- add(settings: DaumPremiumSettings | DaumPremiumTCPSettings): any;
19
- getName(): string;
20
- getInterfaces(): string[];
21
- isBike(): boolean;
22
- isHrm(): boolean;
23
- isPower(): boolean;
24
- scan(props: any): void;
25
- addDevice(DeviceClass: any, opts: any, portName: any): any;
26
- scanTcpip(opts: any): void;
27
- scanSerial(opts: any): void;
28
- isScanning(): boolean;
29
- stopScan(): Promise<boolean>;
30
- scanCommand(device: any, opts: any): void;
31
- }
32
- export {};
@@ -1,207 +0,0 @@
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
- const protocol_1 = __importStar(require("../../protocol"));
35
- const registry_1 = __importDefault(require("../../registry"));
36
- const bike_1 = require("../premium/bike");
37
- const DaumPremiumAdapter_1 = __importDefault(require("./DaumPremiumAdapter"));
38
- const gd_eventlog_1 = require("gd-eventlog");
39
- const PROTOCOL_NAME = "Daum Premium";
40
- const DefaultState = {
41
- activeScans: [],
42
- scanning: false,
43
- stopScanning: false
44
- };
45
- class DaumPremiumProtocol extends protocol_1.default {
46
- constructor() {
47
- super();
48
- this.state = DefaultState;
49
- this.logger = new gd_eventlog_1.EventLogger('DaumPremium');
50
- this.devices = [];
51
- }
52
- add(settings) {
53
- if (settings.interface && settings.interface === protocol_1.INTERFACE.TCPIP) {
54
- bike_1.Daum8iTcp.setNetImpl(protocol_1.default.getNetImpl());
55
- const { host } = settings;
56
- const portName = `${host}:51955`;
57
- return this.addDevice(bike_1.Daum8iTcp, { host, port: 51955, interface: protocol_1.INTERFACE.TCPIP }, portName);
58
- }
59
- if (settings.interface && settings.interface === protocol_1.INTERFACE.SERIAL) {
60
- bike_1.Daum8iSerial.setSerialPort(protocol_1.default.getSerialPort());
61
- const { port } = settings;
62
- return this.addDevice(bike_1.Daum8iSerial, { port, interface: protocol_1.INTERFACE.SERIAL }, port);
63
- }
64
- }
65
- getName() {
66
- return PROTOCOL_NAME;
67
- }
68
- getInterfaces() {
69
- return [protocol_1.INTERFACE.SERIAL, protocol_1.INTERFACE.TCPIP];
70
- }
71
- isBike() {
72
- return true;
73
- }
74
- isHrm() {
75
- return true;
76
- }
77
- isPower() {
78
- return true;
79
- }
80
- scan(props) {
81
- const opts = props || {};
82
- this.logger.logEvent({ message: 'start scan', opts });
83
- this.state.scanning = true;
84
- if (opts.interface === protocol_1.INTERFACE.TCPIP) {
85
- this.scanTcpip(opts);
86
- }
87
- else if (opts.interface === protocol_1.INTERFACE.SERIAL) {
88
- this.scanSerial(opts);
89
- }
90
- }
91
- addDevice(DeviceClass, opts, portName) {
92
- let device;
93
- if (this.devices.length === 0) {
94
- const bike = new DeviceClass(opts);
95
- device = new DaumPremiumAdapter_1.default(this, bike);
96
- this.devices.push(device);
97
- }
98
- else {
99
- const devices = this.devices;
100
- const idx = devices.findIndex(d => d.getBike().getPort() === portName);
101
- if (idx === -1) {
102
- const bike = new DeviceClass(opts);
103
- device = new DaumPremiumAdapter_1.default(this, bike);
104
- this.devices.push(device);
105
- }
106
- else {
107
- device = this.devices[idx];
108
- if (device.isSelected() || device.isDetected())
109
- device = undefined;
110
- }
111
- }
112
- return device;
113
- }
114
- scanTcpip(opts) {
115
- bike_1.Daum8iTcp.setNetImpl(protocol_1.default.getNetImpl());
116
- const { host, port } = opts;
117
- let device = this.addDevice(bike_1.Daum8iTcp, opts, `${host}:${port || 51955}`);
118
- if (device) {
119
- const iv = setInterval(() => { this.scanCommand(device, opts); }, 500);
120
- this.state.activeScans.push({ iv, device });
121
- }
122
- }
123
- scanSerial(opts) {
124
- bike_1.Daum8iSerial.setSerialPort(protocol_1.default.getSerialPort());
125
- let device = this.addDevice(bike_1.Daum8iSerial, opts, opts.port);
126
- if (device) {
127
- const iv = setInterval(() => { this.scanCommand(device, opts); }, 500);
128
- this.state.activeScans.push({ iv, device });
129
- }
130
- }
131
- isScanning() {
132
- return this.state.scanning;
133
- }
134
- stopScan() {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- this.logger.logEvent({ message: 'stop scan', activeScans: this.state.activeScans });
137
- this.state.stopScanning = true;
138
- if (this.state.activeScans.length > 0) {
139
- this.state.activeScans.forEach(scan => {
140
- clearInterval(scan.iv);
141
- scan.iv = undefined;
142
- scan.scanning = false;
143
- });
144
- this.state.activeScans = [];
145
- }
146
- const devices = this.devices;
147
- for (let i = 0; i < devices.length; i++) {
148
- const d = devices[i];
149
- if (!d.isSelected() && !d.isDetected()) {
150
- try {
151
- yield d.getBike().saveClose(true);
152
- }
153
- catch (err) {
154
- this.logger.logEvent({ message: 'stop scan error', error: err.message });
155
- }
156
- }
157
- }
158
- for (let i = 0; i < devices.length; i++) {
159
- const d = devices[i];
160
- if (!d.isSelected() && !d.isDetected()) {
161
- try {
162
- yield d.getBike().unblock();
163
- }
164
- catch (err) {
165
- }
166
- }
167
- }
168
- this.state.scanning = false;
169
- this.state.stopScanning = false;
170
- this.logger.logEvent({ message: 'stop scan completed' });
171
- return true;
172
- });
173
- }
174
- scanCommand(device, opts) {
175
- const scan = this.state.activeScans.find(actScan => actScan.device.getBike().getPort() === device.getBike().getPort());
176
- if (this.state.stopScanning || (scan && scan.scanning) || device.isDetected())
177
- return;
178
- scan.scanning = true;
179
- device.check()
180
- .then(() => __awaiter(this, void 0, void 0, function* () {
181
- if (this.state.stopScanning)
182
- return;
183
- const { onDeviceFound, onScanFinished, id } = opts;
184
- device.setDetected();
185
- if (onDeviceFound)
186
- onDeviceFound(device, device.getProtocol());
187
- if (onScanFinished) {
188
- onScanFinished(id);
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
- }
196
- clearInterval(scan.iv);
197
- scan.iv = undefined;
198
- scan.scanning = false;
199
- }))
200
- .catch(() => {
201
- scan.scanning = false;
202
- });
203
- }
204
- }
205
- exports.default = DaumPremiumProtocol;
206
- const premium = new DaumPremiumProtocol();
207
- registry_1.default.register(premium);
@@ -1,33 +0,0 @@
1
- import { EventLogger } from 'gd-eventlog';
2
- export default class TcpSocketPort {
3
- callbacks: any;
4
- enabled: boolean;
5
- host: string;
6
- port: number;
7
- net: any;
8
- props: any;
9
- socket: any;
10
- id: number;
11
- isOpen: boolean;
12
- isClosed: boolean;
13
- path: string;
14
- outputQueue: Array<any>;
15
- iv: any;
16
- logger: EventLogger;
17
- constructor(props: any);
18
- flush(): void;
19
- open(retry?: boolean): void;
20
- close(): void;
21
- onTimeout(): void;
22
- onConnect(): void;
23
- onError(err: any): void;
24
- on(event: any, callback: any): void;
25
- removeAllListeners(): void;
26
- emit(event: any, ...args: any[]): void;
27
- write(message: any): void;
28
- unpipe(): void;
29
- pipe(transformer: any): any;
30
- static setResponse(command: any, fn: any): void;
31
- static getReponseHandler(command: any): any;
32
- static reset(): void;
33
- }
@@ -1,123 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const net_1 = __importDefault(require("net"));
7
- const gd_eventlog_1 = require("gd-eventlog");
8
- var __responses = {};
9
- class TcpSocketPort {
10
- constructor(props) {
11
- this.callbacks = {};
12
- this.isOpen = false;
13
- this.isClosed = false;
14
- this.props = props || {};
15
- this.logger = new gd_eventlog_1.EventLogger('TCPSocket') || props.logger;
16
- this.enabled = this.props.enabled || true;
17
- this.host = this.props.host || '127.0.0.1';
18
- this.port = this.props.port || 10000;
19
- this.net = this.props.net || net_1.default;
20
- this.path = `${this.host}:${this.port}`;
21
- if (this.enabled)
22
- this.socket = new this.net.Socket();
23
- this.outputQueue = [];
24
- this.iv = undefined;
25
- }
26
- flush() {
27
- }
28
- open(retry = false) {
29
- try {
30
- if (!retry) {
31
- this.id = Date.now();
32
- this.socket.on('timeout', () => { this.onTimeout(); });
33
- this.socket.on('connect', () => { this.onConnect(); });
34
- this.socket.on('error', (err) => { this.onError(err); });
35
- this.socket.on('ready', () => {
36
- this.logger.logEvent({ message: 'ready' });
37
- });
38
- }
39
- this.logger.logEvent({ message: 'opening', id: this.id, retry });
40
- this.socket.connect(this.port, this.host);
41
- }
42
- catch (err) {
43
- this.logger.logEvent({ message: 'opening error', id: this.id, error: err.message, stack: err.stack });
44
- this.emit('error', err);
45
- }
46
- }
47
- close() {
48
- this.logger.logEvent({ message: 'closing', id: this.id });
49
- this.isOpen = false;
50
- this.isClosed = true;
51
- try {
52
- this.socket.removeAllListeners();
53
- this.socket.destroy();
54
- this.socket.on('error', () => { });
55
- }
56
- catch (err) {
57
- console.log(err);
58
- }
59
- this.emit('close');
60
- setTimeout(() => { this.removeAllListeners(); }, 100);
61
- }
62
- onTimeout() {
63
- if (this.isOpen)
64
- return;
65
- this.logger.logEvent({ message: 'timeout', id: this.id });
66
- try {
67
- this.socket.end();
68
- }
69
- catch (_a) { }
70
- if (this.isClosed)
71
- return;
72
- this.emit('error', new Error('timeout'));
73
- }
74
- onConnect() {
75
- this.logger.logEvent({ message: 'connected', id: this.id });
76
- this.isOpen = true;
77
- this.isClosed = false;
78
- this.emit('open');
79
- }
80
- onError(err) {
81
- this.logger.logEvent({ message: 'error', error: err.message });
82
- if (this.callbacks['error'])
83
- this.callbacks['error'](err);
84
- }
85
- on(event, callback) {
86
- if (event === 'open' || event === 'close' || event === 'error') {
87
- this.callbacks[event] = callback;
88
- return;
89
- }
90
- this.socket.on(event, callback);
91
- }
92
- removeAllListeners() {
93
- this.callbacks = {};
94
- }
95
- emit(event, ...args) {
96
- if (event === 'open' || event === 'close' || event === 'error') {
97
- if (this.callbacks[event])
98
- this.callbacks[event](...args);
99
- }
100
- }
101
- write(message) {
102
- this.socket.write(new Uint8Array(message));
103
- }
104
- unpipe() {
105
- delete this.callbacks['data'];
106
- this.socket.unpipe();
107
- }
108
- pipe(transformer) {
109
- return this.socket.pipe(transformer);
110
- }
111
- static setResponse(command, fn) {
112
- if (!__responses)
113
- this.reset();
114
- __responses[command] = fn;
115
- }
116
- static getReponseHandler(command) {
117
- return __responses[command];
118
- }
119
- static reset() {
120
- __responses = {};
121
- }
122
- }
123
- exports.default = TcpSocketPort;
@@ -1,41 +0,0 @@
1
- /// <reference types="node" />
2
- import DeviceProtocolBase, { DeviceProtocol, DeviceSettings, ScanProps } from '../../protocol';
3
- import KettlerRacerAdapter from './adapter';
4
- export interface KettlerRacerScanProps extends ScanProps {
5
- port: string;
6
- }
7
- declare enum ScanState {
8
- IDLE = 0,
9
- SCANNING = 1,
10
- STOPPING = 2,
11
- STOPPED = 3
12
- }
13
- export interface ScanDescription {
14
- device: KettlerRacerAdapter;
15
- port: string;
16
- iv: NodeJS.Timeout;
17
- state: ScanState;
18
- props: KettlerRacerScanProps;
19
- }
20
- export default class KettlerRacerProtocol extends DeviceProtocolBase implements DeviceProtocol {
21
- private state;
22
- private logger;
23
- private activeScans;
24
- constructor();
25
- getSerialPort(): any;
26
- getInterfaces(): string[];
27
- getName(): string;
28
- isBike(): boolean;
29
- isHrm(): boolean;
30
- isPower(): boolean;
31
- add(settings: DeviceSettings): any;
32
- scan(props: KettlerRacerScanProps): void;
33
- checkDevice(port: string): boolean;
34
- doScan(port: string): Promise<void>;
35
- doStopScan(job: ScanDescription): Promise<void>;
36
- isJobStopped(job: ScanDescription): boolean;
37
- waitForStop(timeout?: number): Promise<boolean>;
38
- stopScan(): Promise<boolean>;
39
- isScanning(): boolean;
40
- }
41
- export {};