incyclist-devices 1.5.38 → 2.0.0

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 (267) hide show
  1. package/README.MD +238 -0
  2. package/lib/adapters.d.ts +7 -0
  3. package/lib/adapters.js +49 -0
  4. package/lib/antv2/adapter-factory.d.ts +21 -10
  5. package/lib/antv2/adapter-factory.js +51 -33
  6. package/lib/antv2/adapter.d.ts +65 -0
  7. package/lib/antv2/adapter.js +310 -0
  8. package/lib/antv2/ant-interface.d.ts +17 -11
  9. package/lib/antv2/ant-interface.js +41 -31
  10. package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +1 -1
  11. package/lib/antv2/{ant-binding.js → binding.js} +1 -1
  12. package/lib/antv2/fe/adapter.d.ts +28 -0
  13. package/lib/antv2/{fe.js → fe/adapter.js} +106 -90
  14. package/lib/antv2/fe/index.d.ts +2 -0
  15. package/lib/antv2/fe/index.js +7 -0
  16. package/lib/antv2/hr/adapter.d.ts +15 -0
  17. package/lib/antv2/hr/adapter.js +76 -0
  18. package/lib/antv2/hr/index.d.ts +2 -0
  19. package/lib/antv2/hr/index.js +7 -0
  20. package/lib/antv2/index.d.ts +7 -0
  21. package/lib/antv2/index.js +20 -0
  22. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
  23. package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
  24. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
  25. package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
  26. package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
  27. package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
  28. package/lib/antv2/pwr/adapter.d.ts +24 -0
  29. package/lib/antv2/pwr/adapter.js +141 -0
  30. package/lib/antv2/pwr/index.d.ts +2 -0
  31. package/lib/antv2/pwr/index.js +7 -0
  32. package/lib/antv2/sensor-factory.d.ts +2 -2
  33. package/lib/antv2/types.d.ts +22 -0
  34. package/lib/antv2/types.js +5 -0
  35. package/lib/antv2/utils.d.ts +4 -0
  36. package/lib/antv2/utils.js +192 -0
  37. package/lib/base/adpater.d.ts +68 -0
  38. package/lib/base/adpater.js +183 -0
  39. package/lib/ble/adapter-factory.d.ts +33 -0
  40. package/lib/ble/adapter-factory.js +105 -0
  41. package/lib/ble/base/adapter.d.ts +53 -0
  42. package/lib/ble/base/adapter.js +290 -0
  43. package/lib/ble/base/comms-utils.d.ts +7 -0
  44. package/lib/ble/base/comms-utils.js +91 -0
  45. package/lib/ble/{ble-device.d.ts → base/comms.d.ts} +31 -16
  46. package/lib/ble/{ble-device.js → base/comms.js} +193 -55
  47. package/lib/ble/bindings/index.d.ts +2 -0
  48. package/lib/ble/bindings/index.js +8 -0
  49. package/lib/ble/bindings/linux.d.ts +15 -0
  50. package/lib/ble/bindings/linux.js +39 -0
  51. package/lib/ble/bindings/mock.d.ts +9 -0
  52. package/lib/ble/bindings/mock.js +108 -0
  53. package/lib/ble/bindings/types.d.ts +57 -0
  54. package/lib/ble/bindings/types.js +96 -0
  55. package/lib/ble/ble-interface.d.ts +38 -59
  56. package/lib/ble/ble-interface.js +254 -462
  57. package/lib/ble/ble-peripheral.d.ts +7 -5
  58. package/lib/ble/ble-peripheral.js +52 -21
  59. package/lib/ble/consts.d.ts +3 -0
  60. package/lib/ble/consts.js +4 -1
  61. package/lib/ble/cp/adapter.d.ts +22 -0
  62. package/lib/ble/cp/adapter.js +111 -0
  63. package/lib/ble/cp/comm.d.ts +31 -0
  64. package/lib/ble/cp/comm.js +125 -0
  65. package/lib/ble/cp/index.d.ts +4 -0
  66. package/lib/ble/cp/index.js +10 -0
  67. package/lib/ble/cp/types.d.ts +13 -0
  68. package/lib/ble/cp/types.js +2 -0
  69. package/lib/ble/elite/adapter.d.ts +19 -0
  70. package/lib/ble/elite/adapter.js +120 -0
  71. package/lib/ble/elite/comms.d.ts +32 -0
  72. package/lib/ble/elite/comms.js +126 -0
  73. package/lib/ble/elite/index.d.ts +3 -0
  74. package/lib/ble/elite/index.js +10 -0
  75. package/lib/ble/fm/adapter.d.ts +22 -0
  76. package/lib/ble/fm/adapter.js +249 -0
  77. package/lib/ble/fm/comms.d.ts +50 -0
  78. package/lib/ble/{fm.js → fm/comms.js} +34 -277
  79. package/lib/ble/fm/consts.d.ts +6 -0
  80. package/lib/ble/fm/consts.js +9 -0
  81. package/lib/ble/fm/index.d.ts +5 -0
  82. package/lib/ble/fm/index.js +13 -0
  83. package/lib/ble/fm/types.d.ts +30 -0
  84. package/lib/ble/fm/types.js +2 -0
  85. package/lib/ble/hr/adapter.d.ts +14 -0
  86. package/lib/ble/hr/adapter.js +45 -0
  87. package/lib/ble/hr/comm.d.ts +19 -0
  88. package/lib/ble/hr/comm.js +56 -0
  89. package/lib/ble/hr/index.d.ts +4 -0
  90. package/lib/ble/hr/index.js +10 -0
  91. package/lib/ble/hr/mock.d.ts +7 -0
  92. package/lib/ble/hr/mock.js +47 -0
  93. package/lib/ble/hr/types.d.ts +5 -0
  94. package/lib/ble/hr/types.js +2 -0
  95. package/lib/ble/index.d.ts +9 -0
  96. package/lib/ble/index.js +26 -0
  97. package/lib/ble/peripheral-cache.d.ts +43 -0
  98. package/lib/ble/peripheral-cache.js +107 -0
  99. package/lib/ble/tacx/adapter.d.ts +10 -0
  100. package/lib/ble/tacx/adapter.js +99 -0
  101. package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +11 -43
  102. package/lib/ble/{tacx.js → tacx/comms.js} +23 -155
  103. package/lib/ble/tacx/index.d.ts +4 -0
  104. package/lib/ble/tacx/index.js +10 -0
  105. package/lib/ble/tacx/types.d.ts +25 -0
  106. package/lib/ble/tacx/types.js +2 -0
  107. package/lib/ble/types.d.ts +128 -0
  108. package/lib/ble/types.js +2 -0
  109. package/lib/ble/utils.d.ts +17 -0
  110. package/lib/ble/utils.js +54 -0
  111. package/lib/ble/wahoo/adapter.d.ts +9 -0
  112. package/lib/ble/wahoo/adapter.js +95 -0
  113. package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +11 -44
  114. package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +29 -129
  115. package/lib/ble/wahoo/index.d.ts +4 -0
  116. package/lib/ble/wahoo/index.js +10 -0
  117. package/lib/ble/wahoo/types.d.ts +19 -0
  118. package/lib/ble/wahoo/types.js +2 -0
  119. package/lib/index.d.ts +15 -0
  120. package/lib/index.js +34 -0
  121. package/lib/interfaces.d.ts +7 -0
  122. package/lib/interfaces.js +27 -0
  123. package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
  124. package/lib/{ble → modes}/ble-erg-mode.js +2 -2
  125. package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
  126. package/lib/{ble → modes}/ble-st-mode.js +1 -1
  127. package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
  128. package/lib/modes/power-base.d.ts +3 -3
  129. package/lib/modes/power-base.js +8 -4
  130. package/lib/modes/power-meter.d.ts +3 -3
  131. package/lib/modes/simulator.d.ts +2 -2
  132. package/lib/modes/simulator.js +1 -1
  133. package/lib/serial/adapter-factory.d.ts +12 -0
  134. package/lib/serial/adapter-factory.js +30 -0
  135. package/lib/serial/adapter.d.ts +21 -0
  136. package/lib/serial/adapter.js +61 -0
  137. package/lib/serial/bindings/tcp.d.ts +45 -0
  138. package/lib/serial/bindings/tcp.js +284 -0
  139. package/lib/serial/comm.d.ts +7 -0
  140. package/lib/serial/comm.js +2 -0
  141. package/lib/{daum → serial/daum}/DaumAdapter.d.ts +14 -23
  142. package/lib/{daum → serial/daum}/DaumAdapter.js +57 -97
  143. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
  144. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
  145. package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
  146. package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
  147. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
  148. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
  149. package/lib/serial/daum/classic/adapter.d.ts +29 -0
  150. package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
  151. package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
  152. package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
  153. package/lib/serial/daum/classic/mock.d.ts +96 -0
  154. package/lib/serial/daum/classic/mock.js +365 -0
  155. package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
  156. package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
  157. package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
  158. package/lib/serial/daum/premium/adapter.d.ts +25 -0
  159. package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +107 -47
  160. package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
  161. package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +215 -420
  162. package/lib/serial/daum/premium/mock.d.ts +75 -0
  163. package/lib/serial/daum/premium/mock.js +289 -0
  164. package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
  165. package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
  166. package/lib/serial/daum/premium/types.d.ts +12 -0
  167. package/lib/serial/daum/premium/types.js +2 -0
  168. package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
  169. package/lib/{daum → serial/daum}/premium/utils.js +22 -63
  170. package/lib/serial/index.d.ts +9 -0
  171. package/lib/serial/index.js +49 -0
  172. package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
  173. package/lib/{kettler → serial/kettler}/comms.js +71 -32
  174. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +14 -28
  175. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +102 -169
  176. package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
  177. package/lib/serial/kettler/ergo-racer/mock.js +216 -0
  178. package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
  179. package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
  180. package/lib/serial/serial-interface.d.ts +60 -0
  181. package/lib/serial/serial-interface.js +309 -0
  182. package/lib/simulator/Simulator.d.ts +12 -25
  183. package/lib/simulator/Simulator.js +26 -87
  184. package/lib/types/adapter.d.ts +39 -0
  185. package/lib/types/adapter.js +2 -0
  186. package/lib/types/capabilities.d.ts +8 -0
  187. package/lib/types/capabilities.js +12 -0
  188. package/lib/types/data.d.ts +12 -0
  189. package/lib/types/data.js +2 -0
  190. package/lib/types/device.d.ts +32 -0
  191. package/lib/types/device.js +11 -0
  192. package/lib/types/interface.d.ts +18 -0
  193. package/lib/types/interface.js +2 -0
  194. package/lib/types/route.d.ts +2 -2
  195. package/lib/types/user.d.ts +1 -1
  196. package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
  197. package/lib/{utils.js → utils/utils.js} +5 -1
  198. package/package.json +16 -14
  199. package/lib/DeviceSupport.d.ts +0 -36
  200. package/lib/DeviceSupport.js +0 -82
  201. package/lib/ant/AntAdapter.d.ts +0 -50
  202. package/lib/ant/AntAdapter.js +0 -109
  203. package/lib/ant/AntScanner.d.ts +0 -60
  204. package/lib/ant/AntScanner.js +0 -651
  205. package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
  206. package/lib/ant/antfe/AntFEAdapter.js +0 -652
  207. package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
  208. package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
  209. package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
  210. package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
  211. package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
  212. package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
  213. package/lib/ant/antpwr/pwr-adapter.js +0 -251
  214. package/lib/ant/utils.d.ts +0 -1
  215. package/lib/ant/utils.js +0 -23
  216. package/lib/antv2/AntAdapter.d.ts +0 -48
  217. package/lib/antv2/AntAdapter.js +0 -104
  218. package/lib/antv2/ant-device.d.ts +0 -59
  219. package/lib/antv2/ant-device.js +0 -161
  220. package/lib/antv2/fe.d.ts +0 -32
  221. package/lib/antv2/hr.d.ts +0 -18
  222. package/lib/antv2/hr.js +0 -102
  223. package/lib/antv2/incyclist-protocol.d.ts +0 -37
  224. package/lib/antv2/incyclist-protocol.js +0 -126
  225. package/lib/antv2/pwr.d.ts +0 -28
  226. package/lib/antv2/pwr.js +0 -171
  227. package/lib/ble/ble.d.ts +0 -129
  228. package/lib/ble/ble.js +0 -86
  229. package/lib/ble/elite.d.ts +0 -90
  230. package/lib/ble/elite.js +0 -322
  231. package/lib/ble/fm.d.ts +0 -125
  232. package/lib/ble/hrm.d.ts +0 -48
  233. package/lib/ble/hrm.js +0 -134
  234. package/lib/ble/incyclist-protocol.d.ts +0 -31
  235. package/lib/ble/incyclist-protocol.js +0 -153
  236. package/lib/ble/pwr.d.ts +0 -89
  237. package/lib/ble/pwr.js +0 -322
  238. package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
  239. package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
  240. package/lib/daum/classic/DaumClassicProtocol.js +0 -185
  241. package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
  242. package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
  243. package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
  244. package/lib/daum/premium/tcpserial.d.ts +0 -33
  245. package/lib/daum/premium/tcpserial.js +0 -123
  246. package/lib/device.d.ts +0 -94
  247. package/lib/device.js +0 -76
  248. package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
  249. package/lib/kettler/ergo-racer/protocol.js +0 -203
  250. package/lib/protocol.d.ts +0 -74
  251. package/lib/protocol.js +0 -41
  252. package/lib/registry.d.ts +0 -8
  253. package/lib/registry.js +0 -33
  254. package/lib/serialport/bindings/tcp.d.ts +0 -20
  255. package/lib/serialport/bindings/tcp.js +0 -33
  256. package/lib/serialport/index.d.ts +0 -2
  257. package/lib/serialport/index.js +0 -29
  258. package/lib/serialport/serialport.d.ts +0 -29
  259. package/lib/serialport/serialport.js +0 -87
  260. /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
  261. /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
  262. /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
  263. /package/lib/{daum → serial/daum}/constants.js +0 -0
  264. /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
  265. /package/lib/{serialport.js → serial/serialport.js} +0 -0
  266. /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
  267. /package/lib/{calculations.js → utils/calculations.js} +0 -0
@@ -0,0 +1,284 @@
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
+ exports.TCPPortBinding = exports.TCPBinding = exports.getSubnets = exports.scanSubNet = exports.scanPort = exports.CanceledError = void 0;
16
+ const gd_eventlog_1 = require("gd-eventlog");
17
+ const os_1 = require("os");
18
+ const net_1 = __importDefault(require("net"));
19
+ function resolveNextTick() {
20
+ return new Promise(resolve => process.nextTick(() => resolve()));
21
+ }
22
+ class CanceledError extends Error {
23
+ constructor(message) {
24
+ super(message);
25
+ this.canceled = true;
26
+ }
27
+ }
28
+ exports.CanceledError = CanceledError;
29
+ function scanPort(host, port) {
30
+ return new Promise((resolve) => {
31
+ try {
32
+ const socket = new net_1.default.Socket();
33
+ const cleanup = () => {
34
+ try {
35
+ socket.destroy();
36
+ }
37
+ catch (err) { }
38
+ socket.removeAllListeners();
39
+ };
40
+ socket.setTimeout(1000);
41
+ socket.on('timeout', () => { resolve(false); ; cleanup(); });
42
+ socket.on('error', (err) => { resolve(false); cleanup(); });
43
+ socket.on('ready', () => { resolve(true); cleanup(); });
44
+ socket.connect(port, host);
45
+ }
46
+ catch (err) {
47
+ resolve(false);
48
+ }
49
+ });
50
+ }
51
+ exports.scanPort = scanPort;
52
+ function scanSubNet(sn, port) {
53
+ const range = [];
54
+ for (let i = 1; i < 255; i++)
55
+ range.push(i);
56
+ return Promise.all(range.map(j => scanPort(`${sn}.${j}`, port).then(success => success ? `${sn}.${j}` : null).catch()))
57
+ .then(hosts => hosts.filter(h => h !== null))
58
+ .catch();
59
+ }
60
+ exports.scanSubNet = scanSubNet;
61
+ function getSubnets() {
62
+ const nets = (0, os_1.networkInterfaces)();
63
+ const results = [];
64
+ const names = Object.keys(nets);
65
+ names.forEach(name => {
66
+ for (const net of nets[name]) {
67
+ if (net.family === 'IPv4' && !net.internal) {
68
+ results.push(net.address);
69
+ }
70
+ }
71
+ });
72
+ const address = Object.keys((0, os_1.networkInterfaces)())
73
+ .reduce((a, key) => [
74
+ ...a,
75
+ ...(0, os_1.networkInterfaces)()[key]
76
+ ], [])
77
+ .filter(iface => iface.family === 'IPv4' && !iface.internal && iface.netmask === '255.255.255.0')
78
+ .map(iface => {
79
+ const parts = iface.address.split('.');
80
+ return `${parts[0]}.${parts[1]}.${parts[2]}`;
81
+ });
82
+ const subnets = address.filter((x, i) => i === address.indexOf(x));
83
+ subnets.push('127.0.0');
84
+ return subnets;
85
+ }
86
+ exports.getSubnets = getSubnets;
87
+ exports.TCPBinding = {
88
+ list(port) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ if (!port)
91
+ return [];
92
+ const subnets = getSubnets();
93
+ const hosts = [];
94
+ yield Promise.all(subnets.map(sn => scanSubNet(sn, port).then(found => { hosts.push(...found); })));
95
+ return hosts.map(host => ({
96
+ path: `${host}:${port}`,
97
+ manufacturer: undefined,
98
+ locationId: undefined,
99
+ pnpId: undefined,
100
+ productId: undefined,
101
+ serialNumber: undefined,
102
+ vendorId: undefined
103
+ }));
104
+ });
105
+ },
106
+ open(options) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const asyncOpen = () => {
109
+ return new Promise((resolve, reject) => {
110
+ let host, port;
111
+ if (!options.path)
112
+ return reject(new TypeError('"path" is not valid'));
113
+ try {
114
+ const res = options.path.split(':');
115
+ if (res.length !== 2)
116
+ return reject(new TypeError('"path" is not valid'));
117
+ host = res[0];
118
+ port = Number(res[1]);
119
+ if (isNaN(port))
120
+ return reject(new TypeError('"path" is not valid'));
121
+ }
122
+ catch (err) {
123
+ return reject(new TypeError('"path" is not valid'));
124
+ }
125
+ const socket = new net_1.default.Socket();
126
+ if (options.timeout)
127
+ socket.setTimeout(options.timeout);
128
+ socket.once('timeout', () => { reject(new Error('timeout')); });
129
+ socket.once('error', (err) => { reject(err); });
130
+ socket.once('connect', () => { resolve(socket); });
131
+ socket.connect(port, host);
132
+ });
133
+ };
134
+ const openOptions = Object.assign({ dataBits: 8, lock: true, stopBits: 1, parity: 'none', rtscts: false, xon: false, xoff: false, xany: false, hupcl: true }, options);
135
+ const socket = yield asyncOpen();
136
+ return new TCPPortBinding(socket, openOptions);
137
+ });
138
+ }
139
+ };
140
+ class TCPPortBinding {
141
+ constructor(socket, options) {
142
+ this.logger = new gd_eventlog_1.EventLogger('TCPPort');
143
+ this.socket = socket;
144
+ this.openOptions = options;
145
+ this.pendingRead = null;
146
+ this.writeOperation = null;
147
+ this.data = null;
148
+ this.socket.on('data', this.onData.bind(this));
149
+ this.socket.on('error', this.onError.bind(this));
150
+ this.socket.on('close', () => { this.close(); });
151
+ this.socket.on('end', () => { this.close(); });
152
+ this.socket.on('timeout', () => { this.onError(new Error('socket timeout')); });
153
+ }
154
+ get isOpen() {
155
+ return this.socket !== null;
156
+ }
157
+ onData(data) {
158
+ if (!this.data)
159
+ this.data = Buffer.alloc(0);
160
+ const buffer = Buffer.from(data);
161
+ this.data = Buffer.concat([this.data, buffer]);
162
+ if (this.pendingRead) {
163
+ process.nextTick(this.pendingRead);
164
+ this.pendingRead = null;
165
+ }
166
+ }
167
+ onError(err) {
168
+ if (this.pendingRead) {
169
+ this.pendingRead(err);
170
+ this.socket = null;
171
+ }
172
+ }
173
+ close() {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ if (!this.isOpen)
176
+ return;
177
+ this.data = Buffer.alloc(0);
178
+ const socket = this.socket;
179
+ socket.removeAllListeners();
180
+ socket.destroy();
181
+ socket.on('error', () => { });
182
+ setTimeout(() => { socket.removeAllListeners(); }, 500);
183
+ this.socket = null;
184
+ if (this.pendingRead) {
185
+ this.pendingRead(new CanceledError('port is closed'));
186
+ }
187
+ });
188
+ }
189
+ read(buffer, offset, length) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ if (!this.isOpen) {
192
+ throw new Error('Port is not open');
193
+ }
194
+ if (!Buffer.isBuffer(buffer)) {
195
+ throw new TypeError('"buffer" is not a Buffer');
196
+ }
197
+ if (typeof offset !== 'number' || isNaN(offset)) {
198
+ throw new TypeError(`"offset" is not an integer got "${isNaN(offset) ? 'NaN' : typeof offset}"`);
199
+ }
200
+ if (typeof length !== 'number' || isNaN(length)) {
201
+ throw new TypeError(`"length" is not an integer got "${isNaN(length) ? 'NaN' : typeof length}"`);
202
+ }
203
+ if (buffer.length < offset + length) {
204
+ throw new Error('buffer is too small');
205
+ }
206
+ yield resolveNextTick();
207
+ if (!this.data || this.data.length === 0) {
208
+ return new Promise((resolve, reject) => {
209
+ this.pendingRead = err => {
210
+ if (err) {
211
+ return reject(err);
212
+ }
213
+ this.read(buffer, offset, length).then(resolve, reject);
214
+ };
215
+ });
216
+ }
217
+ const lengthToRead = length === 65536 ? this.data.length : length;
218
+ const toCopy = this.data.slice(0, lengthToRead);
219
+ const bytesRead = toCopy.copy(buffer, offset);
220
+ this.data = this.data.slice(lengthToRead);
221
+ this.pendingRead = null;
222
+ return ({ buffer, bytesRead });
223
+ });
224
+ }
225
+ write(buffer) {
226
+ if (!this.isOpen) {
227
+ throw new Error('Port is not open');
228
+ }
229
+ this.writeOperation = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
230
+ yield resolveNextTick();
231
+ this.socket.write(buffer, () => {
232
+ resolve();
233
+ });
234
+ }));
235
+ return this.writeOperation;
236
+ }
237
+ update(options) {
238
+ return __awaiter(this, void 0, void 0, function* () {
239
+ yield resolveNextTick();
240
+ });
241
+ }
242
+ set(options) {
243
+ return __awaiter(this, void 0, void 0, function* () {
244
+ yield resolveNextTick();
245
+ });
246
+ }
247
+ get() {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ if (!this.isOpen) {
250
+ throw new Error('Port is not open');
251
+ }
252
+ yield resolveNextTick();
253
+ return {
254
+ cts: true,
255
+ dsr: false,
256
+ dcd: false,
257
+ };
258
+ });
259
+ }
260
+ getBaudRate() {
261
+ return __awaiter(this, void 0, void 0, function* () {
262
+ return { baudRate: 9600 };
263
+ });
264
+ }
265
+ flush() {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ if (!this.isOpen) {
268
+ throw new Error('Port is not open');
269
+ }
270
+ yield resolveNextTick();
271
+ this.data = Buffer.alloc(0);
272
+ });
273
+ }
274
+ drain() {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ if (!this.isOpen) {
277
+ throw new Error('Port is not open');
278
+ }
279
+ yield resolveNextTick();
280
+ yield this.writeOperation;
281
+ });
282
+ }
283
+ }
284
+ exports.TCPPortBinding = TCPPortBinding;
@@ -0,0 +1,7 @@
1
+ import { EventLogger } from "gd-eventlog";
2
+ import SerialInterface from "./serial-interface";
3
+ export type SerialCommProps = {
4
+ serial: SerialInterface;
5
+ path: string;
6
+ logger?: EventLogger;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,13 @@
1
1
  import { EventLogger } from 'gd-eventlog';
2
- import CyclingMode, { IncyclistBikeData } from '../cycling-mode';
3
- import IncyclistDevice, { Bike, DeviceAdapter, DeviceData } from '../device';
4
- import { User } from '../types/user';
2
+ import CyclingMode, { IncyclistBikeData } from '../../modes/cycling-mode';
3
+ import { Bike } from '../../types/adapter';
4
+ import { DeviceProperties } from '../../types/device';
5
+ import { SerialDeviceSettings, SerialIncyclistDevice } from '../adapter';
6
+ import { DeviceData } from '../../types/data';
5
7
  interface DaumAdapter {
6
8
  getCurrentBikeData(): Promise<any>;
7
9
  }
8
- export default class DaumAdapterBase extends IncyclistDevice implements DeviceAdapter, DaumAdapter, Bike {
10
+ export default class DaumAdapterBase extends SerialIncyclistDevice implements DaumAdapter, Bike {
9
11
  bike: any;
10
12
  ignoreHrm: boolean;
11
13
  ignoreBike: boolean;
@@ -19,42 +21,30 @@ export default class DaumAdapterBase extends IncyclistDevice implements DeviceAd
19
21
  requests: Array<any>;
20
22
  iv: any;
21
23
  logger: EventLogger;
22
- cyclingMode: CyclingMode;
23
- userSettings: User;
24
- bikeSettings: any;
25
24
  tsPrevData: number;
26
25
  adapterTime: number;
27
26
  requestBusy: boolean;
28
27
  updateBusy: boolean;
29
- constructor(props: any, bike: any);
28
+ constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
30
29
  setCyclingMode(mode: CyclingMode | string, settings?: any): void;
31
30
  getSupportedCyclingModes(): Array<any>;
32
31
  getCyclingMode(): CyclingMode;
33
32
  getDefaultCyclingMode(): CyclingMode;
34
- setUserSettings(userSettings: User): void;
35
- setBikeSettings(bikeSettings: any): void;
36
- getWeight(): number;
37
33
  getCurrentBikeData(): Promise<any>;
38
34
  getBike(): any;
39
- isBike(): boolean;
40
- isPower(): boolean;
41
- isHrm(): boolean;
42
- isSame(device: DeviceAdapter): boolean;
43
- setIgnoreHrm(ignore: any): void;
44
- setIgnoreBike(ignore: any): void;
35
+ isEqual(settings: SerialDeviceSettings): boolean;
36
+ isSame(device: SerialIncyclistDevice): boolean;
45
37
  isStopped(): boolean;
46
38
  initData(): void;
47
- start(props?: any): Promise<any>;
39
+ start(props?: DeviceProperties): Promise<any>;
48
40
  stopUpdatePull(): void;
49
41
  startUpdatePull(): void;
50
- connect(): void;
51
- close(): any;
42
+ connect(): Promise<boolean>;
43
+ close(): Promise<boolean>;
52
44
  logEvent(event: any): void;
53
45
  stop(): Promise<boolean>;
54
- pause(): Promise<boolean>;
55
- resume(): Promise<boolean>;
46
+ canSendUpdate(): boolean;
56
47
  sendUpdate(request: any): Promise<unknown>;
57
- sendData(): void;
58
48
  update(): Promise<void>;
59
49
  sendRequests(): Promise<void>;
60
50
  bikeSync(): Promise<void>;
@@ -63,5 +53,6 @@ export default class DaumAdapterBase extends IncyclistDevice implements DeviceAd
63
53
  sendRequest(request: any): Promise<any>;
64
54
  refreshRequests(): void;
65
55
  processClientRequest(request: any): Promise<unknown>;
56
+ check(): Promise<boolean>;
66
57
  }
67
58
  export {};
@@ -1,23 +1,4 @@
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
- };
21
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -31,19 +12,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
13
  };
33
14
  Object.defineProperty(exports, "__esModule", { value: true });
34
- const device_1 = __importStar(require("../device"));
35
15
  const ERGCyclingMode_1 = __importDefault(require("./ERGCyclingMode"));
36
16
  const SmartTrainerCyclingMode_1 = __importDefault(require("./SmartTrainerCyclingMode"));
37
17
  const DaumPowerMeterCyclingMode_1 = __importDefault(require("./DaumPowerMeterCyclingMode"));
38
- const utils_1 = require("../utils");
39
- class DaumAdapterBase extends device_1.default {
40
- constructor(props, bike) {
41
- super(props);
18
+ const utils_1 = require("../../utils/utils");
19
+ const adapter_1 = require("../adapter");
20
+ const capabilities_1 = require("../../types/capabilities");
21
+ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
22
+ constructor(settings, props) {
23
+ super(settings, props);
42
24
  this.requests = [];
43
25
  this.adapterTime = 0;
44
26
  this.requestBusy = false;
45
27
  this.updateBusy = false;
46
- this.bike = bike;
47
28
  this.stopped = false;
48
29
  this.paused = false;
49
30
  this.cyclingData = {
@@ -56,21 +37,23 @@ class DaumAdapterBase extends device_1.default {
56
37
  heartrate: 0
57
38
  };
58
39
  this.deviceData = {};
59
- const options = props || {};
60
- this.cyclingMode = options.cyclingMode;
61
- this.setUserSettings(options.userSettings);
62
- this.setBikeSettings(options.bikeSettings);
40
+ this.capabilities = [
41
+ capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Speed, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Gear, capabilities_1.IncyclistCapability.HeartRate,
42
+ capabilities_1.IncyclistCapability.Control
43
+ ];
63
44
  }
64
45
  setCyclingMode(mode, settings) {
65
- let selectedMode;
46
+ let selectedMode = this.cyclingMode;
66
47
  if (typeof mode === 'string') {
67
- const supported = this.getSupportedCyclingModes();
68
- const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
69
- if (CyclingModeClass) {
70
- this.cyclingMode = new CyclingModeClass(this, settings);
71
- return;
48
+ if (!this.cyclingMode || this.cyclingMode.getName() !== mode) {
49
+ const supported = this.getSupportedCyclingModes();
50
+ const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
51
+ if (CyclingModeClass) {
52
+ this.cyclingMode = new CyclingModeClass(this, settings);
53
+ return;
54
+ }
55
+ selectedMode = this.getDefaultCyclingMode();
72
56
  }
73
- selectedMode = this.getDefaultCyclingMode();
74
57
  }
75
58
  else {
76
59
  selectedMode = mode;
@@ -89,42 +72,18 @@ class DaumAdapterBase extends device_1.default {
89
72
  getDefaultCyclingMode() {
90
73
  return new ERGCyclingMode_1.default(this);
91
74
  }
92
- setUserSettings(userSettings) {
93
- this.userSettings = userSettings || {};
94
- if (this.bike) {
95
- if (!this.bike.settings)
96
- this.bike.settings = { user: {} };
97
- if (!this.bike.settings.user)
98
- this.bike.settings.user = {};
99
- this.bike.settings.user.weight = this.userSettings.weight || device_1.DEFAULT_USER_WEIGHT;
100
- }
101
- }
102
- setBikeSettings(bikeSettings) {
103
- this.bikeSettings = bikeSettings || {};
104
- if (this.bike) {
105
- if (!this.bike.settings)
106
- this.bike.settings = {};
107
- this.bike.settings.weight = this.userSettings.weight || device_1.DEFAULT_BIKE_WEIGHT;
108
- }
109
- }
110
- getWeight() {
111
- const userWeight = Number(this.userSettings.weight || device_1.DEFAULT_USER_WEIGHT);
112
- const bikeWeight = Number(this.bikeSettings.weight || device_1.DEFAULT_BIKE_WEIGHT);
113
- return bikeWeight + userWeight;
114
- }
115
75
  getCurrentBikeData() {
116
76
  throw new Error('Method not implemented.');
117
77
  }
118
78
  getBike() {
119
79
  return this.bike;
120
80
  }
121
- isBike() {
122
- return true;
123
- }
124
- isPower() {
125
- return true;
126
- }
127
- isHrm() {
81
+ isEqual(settings) {
82
+ const as = this.settings;
83
+ if (settings.interface !== this.getInterface())
84
+ return false;
85
+ if (settings.protocol !== as.protocol || settings.port !== as.port)
86
+ return false;
128
87
  return true;
129
88
  }
130
89
  isSame(device) {
@@ -133,12 +92,6 @@ class DaumAdapterBase extends device_1.default {
133
92
  const adapter = device;
134
93
  return (adapter.getName() === this.getName() && adapter.getPort() === this.getPort());
135
94
  }
136
- setIgnoreHrm(ignore) {
137
- this.ignoreHrm = ignore;
138
- }
139
- setIgnoreBike(ignore) {
140
- this.ignoreBike = ignore;
141
- }
142
95
  isStopped() {
143
96
  return this.stopped;
144
97
  }
@@ -181,22 +134,35 @@ class DaumAdapterBase extends device_1.default {
181
134
  return;
182
135
  const ivSync = setInterval(() => {
183
136
  this.bikeSync();
184
- }, 1000);
137
+ }, this.pullFrequency);
185
138
  const ivUpdate = setInterval(() => {
186
- this.sendData();
139
+ this.emitData(this.deviceData);
187
140
  this.refreshRequests();
188
- }, 1000);
141
+ }, this.pullFrequency);
189
142
  this.iv = {
190
143
  sync: ivSync,
191
144
  update: ivUpdate
192
145
  };
193
146
  }
194
147
  connect() {
195
- if (!this.bike.isConnected())
196
- this.bike.connect();
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ if (this.bike.isConnected())
150
+ return true;
151
+ try {
152
+ const connected = yield this.bike.connect();
153
+ return connected;
154
+ }
155
+ catch (err) {
156
+ return false;
157
+ }
158
+ });
197
159
  }
198
160
  close() {
199
- return this.bike.saveClose();
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ if (!this.bike.isConnected())
163
+ return true;
164
+ return yield this.bike.close();
165
+ });
200
166
  }
201
167
  logEvent(event) {
202
168
  if (!this.logger)
@@ -217,7 +183,8 @@ class DaumAdapterBase extends device_1.default {
217
183
  clearInterval(this.iv.update);
218
184
  this.iv = undefined;
219
185
  }
220
- this.bike.stopWorker();
186
+ if (this.bike.stopWorker && typeof this.bike.stopWorker === 'function')
187
+ this.bike.stopWorker();
221
188
  this.logEvent({ message: 'stop request completed' });
222
189
  this.paused = undefined;
223
190
  resolve(true);
@@ -228,19 +195,10 @@ class DaumAdapterBase extends device_1.default {
228
195
  }
229
196
  });
230
197
  }
231
- pause() {
232
- this.logEvent({ message: 'pause' });
233
- return new Promise(resolve => {
234
- this.paused = true;
235
- resolve(true);
236
- });
237
- }
238
- resume() {
239
- this.logEvent({ message: 'resume' });
240
- return new Promise(resolve => {
241
- this.paused = false;
242
- resolve(true);
243
- });
198
+ canSendUpdate() {
199
+ if (this.paused || this.stopped)
200
+ return false;
201
+ return super.canSendUpdate();
244
202
  }
245
203
  sendUpdate(request) {
246
204
  return __awaiter(this, void 0, void 0, function* () {
@@ -250,10 +208,6 @@ class DaumAdapterBase extends device_1.default {
250
208
  return yield this.processClientRequest(request);
251
209
  });
252
210
  }
253
- sendData() {
254
- if (this.onDataFn)
255
- this.onDataFn(this.deviceData);
256
- }
257
211
  update() {
258
212
  return __awaiter(this, void 0, void 0, function* () {
259
213
  if (this.stopped)
@@ -261,9 +215,11 @@ class DaumAdapterBase extends device_1.default {
261
215
  this.updateBusy = true;
262
216
  this.getCurrentBikeData()
263
217
  .then(bikeData => {
218
+ console.log('~~~ bike data', bikeData);
264
219
  this.updateData(this.cyclingData, bikeData);
265
- this.transformData();
220
+ const data = this.transformData();
266
221
  this.updateBusy = false;
222
+ this.emitData(data);
267
223
  })
268
224
  .catch(err => {
269
225
  this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack });
@@ -359,6 +315,7 @@ class DaumAdapterBase extends device_1.default {
359
315
  data = { heartrate: data.heartrate };
360
316
  }
361
317
  this.deviceData = data;
318
+ return data;
362
319
  }
363
320
  sendRequest(request) {
364
321
  return __awaiter(this, void 0, void 0, function* () {
@@ -408,5 +365,8 @@ class DaumAdapterBase extends device_1.default {
408
365
  resolve(bikeRequest);
409
366
  }));
410
367
  }
368
+ check() {
369
+ throw new Error('Method not implemented.');
370
+ }
411
371
  }
412
372
  exports.default = DaumAdapterBase;
@@ -1,5 +1,5 @@
1
- import CyclingMode, { UpdateRequest } from "../cycling-mode";
2
- import PowerMeterCyclingMode from "../modes/power-meter";
1
+ import CyclingMode, { UpdateRequest } from "../../modes/cycling-mode";
2
+ import PowerMeterCyclingMode from "../../modes/power-meter";
3
3
  export default class DaumPowerMeterCyclingMode extends PowerMeterCyclingMode implements CyclingMode {
4
4
  prevRequest: UpdateRequest;
5
5
  hasBikeUpdate: boolean;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const power_meter_1 = __importDefault(require("../modes/power-meter"));
6
+ const power_meter_1 = __importDefault(require("../../modes/power-meter"));
7
7
  class DaumPowerMeterCyclingMode extends power_meter_1.default {
8
8
  constructor() {
9
9
  super(...arguments);
@@ -1,7 +1,7 @@
1
- import CyclingMode, { CyclingModeProperty, IncyclistBikeData, UpdateRequest } from "../cycling-mode";
1
+ import CyclingMode, { CyclingModeProperty, IncyclistBikeData, UpdateRequest } from "../../modes/cycling-mode";
2
2
  import DaumAdapter from "./DaumAdapter";
3
- import PowerBasedCyclingModeBase from "../modes/power-base";
4
- export declare type ERGEvent = {
3
+ import PowerBasedCyclingModeBase from "../../modes/power-base";
4
+ export type ERGEvent = {
5
5
  rpmUpdated?: boolean;
6
6
  gearUpdated?: boolean;
7
7
  starting?: boolean;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cycling_mode_1 = require("../cycling-mode");
7
- const calculations_1 = __importDefault(require("../calculations"));
8
- const power_base_1 = __importDefault(require("../modes/power-base"));
6
+ const cycling_mode_1 = require("../../modes/cycling-mode");
7
+ const calculations_1 = __importDefault(require("../../utils/calculations"));
8
+ const power_base_1 = __importDefault(require("../../modes/power-base"));
9
9
  const MIN_SPEED = 10;
10
10
  const config = {
11
11
  name: "ERG",