incyclist-devices 2.1.14 → 2.1.16

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 (281) hide show
  1. package/LICENSE +0 -0
  2. package/README.MD +238 -238
  3. package/lib/adapters.d.ts +7 -0
  4. package/lib/adapters.js +49 -0
  5. package/lib/antv2/adapter-factory.d.ts +14 -0
  6. package/lib/antv2/adapter-factory.js +65 -0
  7. package/lib/antv2/adapter.d.ts +54 -0
  8. package/lib/antv2/adapter.js +291 -0
  9. package/lib/antv2/ant-interface.d.ts +35 -0
  10. package/lib/antv2/ant-interface.js +285 -0
  11. package/lib/antv2/base/adapter.d.ts +0 -0
  12. package/lib/antv2/base/adapter.js +0 -0
  13. package/lib/antv2/base/ant-interface.d.ts +35 -0
  14. package/lib/antv2/base/ant-interface.js +285 -0
  15. package/lib/antv2/base/binding.d.ts +0 -0
  16. package/lib/antv2/base/binding.js +0 -0
  17. package/lib/antv2/base/interface.d.ts +0 -0
  18. package/lib/antv2/base/interface.js +0 -0
  19. package/lib/antv2/binding.d.ts +13 -0
  20. package/lib/antv2/binding.js +27 -0
  21. package/lib/antv2/cad/adapter.d.ts +0 -0
  22. package/lib/antv2/cad/adapter.js +0 -0
  23. package/lib/antv2/cad/index.d.ts +0 -0
  24. package/lib/antv2/cad/index.js +0 -0
  25. package/lib/antv2/consts.d.ts +0 -0
  26. package/lib/antv2/consts.js +0 -0
  27. package/lib/antv2/factories/adapter-factory.d.ts +0 -0
  28. package/lib/antv2/factories/adapter-factory.js +0 -0
  29. package/lib/antv2/factories/sensor-factory.d.ts +0 -0
  30. package/lib/antv2/factories/sensor-factory.js +0 -0
  31. package/lib/antv2/fe/adapter.d.ts +0 -0
  32. package/lib/antv2/fe/adapter.js +0 -0
  33. package/lib/antv2/fe/index.d.ts +0 -0
  34. package/lib/antv2/fe/index.js +0 -0
  35. package/lib/antv2/hr/adapter.d.ts +0 -0
  36. package/lib/antv2/hr/adapter.js +0 -0
  37. package/lib/antv2/hr/index.d.ts +0 -0
  38. package/lib/antv2/hr/index.js +0 -0
  39. package/lib/antv2/hr copy/adapter.d.ts +11 -0
  40. package/lib/antv2/hr copy/adapter.js +30 -0
  41. package/lib/antv2/hr copy/index.d.ts +2 -0
  42. package/lib/antv2/hr copy/index.js +7 -0
  43. package/lib/antv2/index.d.ts +0 -0
  44. package/lib/antv2/index.js +0 -0
  45. package/lib/antv2/pwr/adapter.d.ts +0 -0
  46. package/lib/antv2/pwr/adapter.js +0 -0
  47. package/lib/antv2/pwr/index.d.ts +0 -0
  48. package/lib/antv2/pwr/index.js +0 -0
  49. package/lib/antv2/sensor-factory.d.ts +5 -0
  50. package/lib/antv2/sensor-factory.js +20 -0
  51. package/lib/antv2/types.d.ts +0 -0
  52. package/lib/antv2/types.js +0 -0
  53. package/lib/antv2/utils.d.ts +0 -0
  54. package/lib/antv2/utils.js +0 -0
  55. package/lib/base/adpater.d.ts +0 -0
  56. package/lib/base/adpater.js +0 -0
  57. package/lib/base/consts.d.ts +0 -0
  58. package/lib/base/consts.js +0 -0
  59. package/lib/ble/adapter-factory.d.ts +0 -0
  60. package/lib/ble/adapter-factory.js +0 -0
  61. package/lib/ble/base/adapter.d.ts +1 -0
  62. package/lib/ble/base/adapter.js +20 -13
  63. package/lib/ble/base/comms-utils.d.ts +0 -0
  64. package/lib/ble/base/comms-utils.js +0 -0
  65. package/lib/ble/base/comms.d.ts +0 -0
  66. package/lib/ble/base/comms.js +0 -0
  67. package/lib/ble/base/types.d.ts +0 -0
  68. package/lib/ble/base/types.js +0 -0
  69. package/lib/ble/bindings/index.d.ts +0 -0
  70. package/lib/ble/bindings/index.js +0 -0
  71. package/lib/ble/bindings/linux.d.ts +0 -0
  72. package/lib/ble/bindings/linux.js +0 -0
  73. package/lib/ble/bindings/mock.d.ts +0 -0
  74. package/lib/ble/bindings/mock.js +0 -0
  75. package/lib/ble/bindings/types.d.ts +0 -0
  76. package/lib/ble/bindings/types.js +0 -0
  77. package/lib/ble/ble-interface.d.ts +0 -0
  78. package/lib/ble/ble-interface.js +0 -0
  79. package/lib/ble/ble-peripheral.d.ts +0 -0
  80. package/lib/ble/ble-peripheral.js +0 -0
  81. package/lib/ble/consts.d.ts +0 -0
  82. package/lib/ble/consts.js +0 -0
  83. package/lib/ble/cp/adapter.d.ts +1 -0
  84. package/lib/ble/cp/adapter.js +8 -0
  85. package/lib/ble/cp/comm.d.ts +0 -0
  86. package/lib/ble/cp/comm.js +0 -0
  87. package/lib/ble/cp/index.d.ts +0 -0
  88. package/lib/ble/cp/index.js +0 -0
  89. package/lib/ble/cp/types.d.ts +0 -0
  90. package/lib/ble/cp/types.js +0 -0
  91. package/lib/ble/elite/adapter.d.ts +0 -0
  92. package/lib/ble/elite/adapter.js +0 -0
  93. package/lib/ble/elite/comms.d.ts +0 -0
  94. package/lib/ble/elite/comms.js +0 -0
  95. package/lib/ble/elite/index.d.ts +0 -0
  96. package/lib/ble/elite/index.js +0 -0
  97. package/lib/ble/fm/adapter.d.ts +0 -0
  98. package/lib/ble/fm/adapter.js +0 -0
  99. package/lib/ble/fm/comms.d.ts +0 -0
  100. package/lib/ble/fm/comms.js +0 -0
  101. package/lib/ble/fm/consts.d.ts +0 -0
  102. package/lib/ble/fm/consts.js +0 -0
  103. package/lib/ble/fm/index.d.ts +0 -0
  104. package/lib/ble/fm/index.js +0 -0
  105. package/lib/ble/fm/types.d.ts +0 -0
  106. package/lib/ble/fm/types.js +0 -0
  107. package/lib/ble/hr/adapter.d.ts +0 -0
  108. package/lib/ble/hr/adapter.js +0 -0
  109. package/lib/ble/hr/comm.d.ts +0 -0
  110. package/lib/ble/hr/comm.js +0 -0
  111. package/lib/ble/hr/index.d.ts +0 -0
  112. package/lib/ble/hr/index.js +0 -0
  113. package/lib/ble/hr/mock.d.ts +0 -0
  114. package/lib/ble/hr/mock.js +0 -0
  115. package/lib/ble/hr/types.d.ts +0 -0
  116. package/lib/ble/hr/types.js +0 -0
  117. package/lib/ble/index.d.ts +0 -0
  118. package/lib/ble/index.js +0 -0
  119. package/lib/ble/peripheral-cache.d.ts +0 -0
  120. package/lib/ble/peripheral-cache.js +0 -0
  121. package/lib/ble/tacx/adapter.d.ts +0 -0
  122. package/lib/ble/tacx/adapter.js +0 -0
  123. package/lib/ble/tacx/comms.d.ts +0 -0
  124. package/lib/ble/tacx/comms.js +0 -0
  125. package/lib/ble/tacx/index.d.ts +0 -0
  126. package/lib/ble/tacx/index.js +0 -0
  127. package/lib/ble/tacx/types.d.ts +0 -0
  128. package/lib/ble/tacx/types.js +0 -0
  129. package/lib/ble/types.d.ts +0 -0
  130. package/lib/ble/types.js +0 -0
  131. package/lib/ble/utils.d.ts +0 -0
  132. package/lib/ble/utils.js +0 -0
  133. package/lib/ble/wahoo/adapter.d.ts +0 -0
  134. package/lib/ble/wahoo/adapter.js +0 -0
  135. package/lib/ble/wahoo/comms.d.ts +0 -0
  136. package/lib/ble/wahoo/comms.js +0 -0
  137. package/lib/ble/wahoo/index.d.ts +0 -0
  138. package/lib/ble/wahoo/index.js +0 -0
  139. package/lib/ble/wahoo/types.d.ts +0 -0
  140. package/lib/ble/wahoo/types.js +0 -0
  141. package/lib/factories/adapters.d.ts +0 -0
  142. package/lib/factories/adapters.js +0 -0
  143. package/lib/factories/index.d.ts +0 -0
  144. package/lib/factories/index.js +0 -0
  145. package/lib/factories/interfaces.d.ts +0 -0
  146. package/lib/factories/interfaces.js +0 -0
  147. package/lib/index.d.ts +0 -0
  148. package/lib/index.js +0 -0
  149. package/lib/interfaces.d.ts +7 -0
  150. package/lib/interfaces.js +27 -0
  151. package/lib/modes/ant-fe-adv-st-mode.d.ts +0 -0
  152. package/lib/modes/ant-fe-adv-st-mode.js +0 -0
  153. package/lib/modes/antble-erg.d.ts +0 -0
  154. package/lib/modes/antble-erg.js +0 -0
  155. package/lib/modes/antble-smarttrainer.d.ts +0 -0
  156. package/lib/modes/antble-smarttrainer.js +0 -0
  157. package/lib/modes/base.d.ts +0 -0
  158. package/lib/modes/base.js +0 -0
  159. package/lib/modes/daum-classic-standard.d.ts +0 -0
  160. package/lib/modes/daum-classic-standard.js +0 -0
  161. package/lib/modes/daum-erg.d.ts +0 -0
  162. package/lib/modes/daum-erg.js +0 -0
  163. package/lib/modes/daum-power.d.ts +0 -0
  164. package/lib/modes/daum-power.js +0 -0
  165. package/lib/modes/daum-premium-standard.d.ts +0 -0
  166. package/lib/modes/daum-premium-standard.js +0 -0
  167. package/lib/modes/daum-smarttrainer.d.ts +0 -0
  168. package/lib/modes/daum-smarttrainer.js +0 -0
  169. package/lib/modes/kettler-erg.d.ts +0 -0
  170. package/lib/modes/kettler-erg.js +0 -0
  171. package/lib/modes/power-base.d.ts +0 -0
  172. package/lib/modes/power-base.js +0 -0
  173. package/lib/modes/power-meter.d.ts +0 -0
  174. package/lib/modes/power-meter.js +0 -0
  175. package/lib/modes/simulator.d.ts +0 -0
  176. package/lib/modes/simulator.js +0 -0
  177. package/lib/modes/types.d.ts +0 -0
  178. package/lib/modes/types.js +0 -0
  179. package/lib/serial/SinglePathScanner.d.ts +17 -0
  180. package/lib/serial/SinglePathScanner.js +87 -0
  181. package/lib/serial/adapter-factory.d.ts +14 -0
  182. package/lib/serial/adapter-factory.js +30 -0
  183. package/lib/serial/adapter.d.ts +17 -0
  184. package/lib/serial/adapter.js +67 -0
  185. package/lib/serial/base/adapter.d.ts +0 -0
  186. package/lib/serial/base/adapter.js +0 -0
  187. package/lib/serial/base/comms.d.ts +1 -0
  188. package/lib/serial/base/comms.js +9 -0
  189. package/lib/serial/base/serial-interface.d.ts +0 -0
  190. package/lib/serial/base/serial-interface.js +0 -0
  191. package/lib/serial/base/serial-scanner.d.ts +0 -0
  192. package/lib/serial/base/serial-scanner.js +0 -0
  193. package/lib/serial/base/serialport.d.ts +0 -0
  194. package/lib/serial/base/serialport.js +0 -0
  195. package/lib/serial/bindings/tcp.d.ts +0 -0
  196. package/lib/serial/bindings/tcp.js +0 -0
  197. package/lib/serial/comm.d.ts +7 -0
  198. package/lib/serial/comm.js +2 -0
  199. package/lib/serial/comms.d.ts +62 -0
  200. package/lib/serial/comms.js +280 -0
  201. package/lib/serial/daum/DaumAdapter.d.ts +0 -0
  202. package/lib/serial/daum/DaumAdapter.js +0 -0
  203. package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +2 -0
  204. package/lib/serial/daum/classic/PROTOCOL_NAME.js +5 -0
  205. package/lib/serial/daum/classic/adapter.d.ts +0 -0
  206. package/lib/serial/daum/classic/adapter.js +8 -5
  207. package/lib/serial/daum/classic/comms.d.ts +1 -0
  208. package/lib/serial/daum/classic/comms.js +5 -17
  209. package/lib/serial/daum/classic/consts.d.ts +0 -0
  210. package/lib/serial/daum/classic/consts.js +0 -0
  211. package/lib/serial/daum/classic/mock.d.ts +0 -0
  212. package/lib/serial/daum/classic/mock.js +0 -0
  213. package/lib/serial/daum/classic/types.d.ts +0 -0
  214. package/lib/serial/daum/classic/types.js +0 -0
  215. package/lib/serial/daum/classic/utils.d.ts +0 -0
  216. package/lib/serial/daum/classic/utils.js +0 -0
  217. package/lib/serial/daum/consts.d.ts +0 -0
  218. package/lib/serial/daum/consts.js +0 -0
  219. package/lib/serial/daum/premium/adapter.d.ts +0 -0
  220. package/lib/serial/daum/premium/adapter.js +0 -0
  221. package/lib/serial/daum/premium/comms.d.ts +0 -0
  222. package/lib/serial/daum/premium/comms.js +0 -0
  223. package/lib/serial/daum/premium/consts.d.ts +0 -0
  224. package/lib/serial/daum/premium/consts.js +0 -0
  225. package/lib/serial/daum/premium/mock.d.ts +0 -0
  226. package/lib/serial/daum/premium/mock.js +0 -0
  227. package/lib/serial/daum/premium/types.d.ts +0 -0
  228. package/lib/serial/daum/premium/types.js +0 -0
  229. package/lib/serial/daum/premium/utils.d.ts +0 -0
  230. package/lib/serial/daum/premium/utils.js +0 -0
  231. package/lib/serial/daum/types.d.ts +0 -0
  232. package/lib/serial/daum/types.js +0 -0
  233. package/lib/serial/factories/adapter-factory.d.ts +0 -0
  234. package/lib/serial/factories/adapter-factory.js +0 -0
  235. package/lib/serial/index.d.ts +0 -0
  236. package/lib/serial/index.js +0 -0
  237. package/lib/serial/kettler/comms.d.ts +0 -0
  238. package/lib/serial/kettler/comms.js +0 -0
  239. package/lib/serial/kettler/ergo-racer/adapter.d.ts +0 -0
  240. package/lib/serial/kettler/ergo-racer/adapter.js +0 -0
  241. package/lib/serial/kettler/ergo-racer/mock.d.ts +0 -0
  242. package/lib/serial/kettler/ergo-racer/mock.js +0 -0
  243. package/lib/serial/kettler/types.d.ts +0 -0
  244. package/lib/serial/kettler/types.js +0 -0
  245. package/lib/serial/serial-interface.d.ts +36 -0
  246. package/lib/serial/serial-interface.js +288 -0
  247. package/lib/serial/serial-scanner.d.ts +16 -0
  248. package/lib/serial/serial-scanner.js +87 -0
  249. package/lib/serial/serialport.d.ts +17 -0
  250. package/lib/serial/serialport.js +87 -0
  251. package/lib/serial/types.d.ts +0 -0
  252. package/lib/serial/types.js +0 -0
  253. package/lib/simulator/Simulator.d.ts +0 -0
  254. package/lib/simulator/Simulator.js +0 -0
  255. package/lib/types/Command.d.ts +8 -0
  256. package/lib/types/Command.js +2 -0
  257. package/lib/types/adapter.d.ts +0 -0
  258. package/lib/types/adapter.js +0 -0
  259. package/lib/types/capabilities.d.ts +0 -0
  260. package/lib/types/capabilities.js +0 -0
  261. package/lib/types/command.d.ts +0 -0
  262. package/lib/types/command.js +0 -0
  263. package/lib/types/data.d.ts +0 -0
  264. package/lib/types/data.js +0 -0
  265. package/lib/types/device.d.ts +0 -0
  266. package/lib/types/device.js +0 -0
  267. package/lib/types/index.d.ts +0 -0
  268. package/lib/types/index.js +0 -0
  269. package/lib/types/interface.d.ts +0 -0
  270. package/lib/types/interface.js +0 -0
  271. package/lib/types/route.d.ts +0 -0
  272. package/lib/types/route.js +0 -0
  273. package/lib/types/types.d.ts +8 -0
  274. package/lib/types/types.js +2 -0
  275. package/lib/types/user.d.ts +0 -0
  276. package/lib/types/user.js +0 -0
  277. package/lib/utils/calculations.d.ts +0 -0
  278. package/lib/utils/calculations.js +0 -0
  279. package/lib/utils/utils.d.ts +0 -0
  280. package/lib/utils/utils.js +0 -0
  281. package/package.json +51 -51
package/LICENSE CHANGED
File without changes
package/README.MD CHANGED
@@ -1,238 +1,238 @@
1
- # incyclist-devices
2
-
3
- Library used by the [Incyclist](https://incyclist.com) Indoor Cycling App to communicate with devices (Smart Trainers, Sensors)
4
-
5
- It currently support the following Interfaces/Devices
6
-
7
- __ANT__
8
- - Smart Trainers (ANT+ FE)
9
- - Power Meters (ANT+PWR)
10
- - Heartrate Monitors (ANT+HR)
11
-
12
- __BLE__
13
- - Smart Trainers (BLE FTMS)
14
- - Power Meters (BLE CP)
15
- - Heartrate Monitors (BLE HR)
16
- - Wahoo Smart Trainers (Wahoo specific service)
17
- - Tacx FE-C over BLE
18
-
19
- __Serial__
20
- - Daum Classic Ergo Bikes
21
- - Daum Premium Ergo Bikes (also over TCP/IP)
22
- - Kettler Ergo Racer Ergo Bikes
23
-
24
-
25
- ## Install
26
-
27
- ```sh
28
- npm install incyclist-devices
29
- ```
30
-
31
- ## Usage
32
-
33
- ### Setup Interfaces and Bindings
34
-
35
- `Interface` classes are used to enable basic communication (transport layer).
36
-
37
- As this library supports various OS( Linux, Windows, Mac) and Incyclist is based on Electron, which requires to clearly separate between rendering and main process, Bindings need to be provided for each of the Interfaces. The specifications of these bindings are specific to the interface:
38
- - Ant: specified by the [incyclist-ant-plus](https://github.com/incyclist/ant-plus) library
39
- - Serial: specified by the [serialport](https://serialport.io/) library
40
- - BLE: specified by the [noble](https://github.com/noble/noble) library
41
-
42
- __Ant Example__
43
-
44
- ```
45
- const {EventLogger,ConsoleAdapter} = require( 'gd-eventlog');
46
- const {AntDevice} = require('incyclist-ant-plus/lib/bindings');
47
-
48
- const logger = new EventLogger('AntSample')
49
- const ant = InterfaceFactory.create('ant',{logger, log:true, binding:AntDevice})
50
- ```
51
-
52
- __Serial Example__
53
-
54
- ```
55
- const {EventLogger,ConsoleAdapter} = require( 'gd-eventlog');
56
- const { autoDetect } = require('@serialport/bindings-cpp')
57
-
58
-
59
- const logger = new EventLogger('SerialSample')
60
- const serial = InterfaceFactory.create('serial',{logger, log:true, binding:autodetect()})
61
- ```
62
-
63
- __BLE Example__
64
-
65
- ```
66
- const {EventLogger,ConsoleAdapter} = require( 'gd-eventlog');
67
- const {WinrtBindings} = require('./bindings')
68
- const Noble = require('noble/lib/noble');
69
-
70
-
71
- const noble = new Noble(new WinrtBindings())
72
- const logger = new EventLogger('BLESample')
73
- const ble = InterfaceFactory.create('ble',{logger, log:true, binding:noble})
74
- ```
75
-
76
- ### Check availability of interface
77
-
78
- For some interfaces (ANT and BLE) it cannot be guaranteed that the underlying hardware supports the interface ( e.g. a USB stick might be required). Therefore this library offers a `connect` method, that allows to check if the interface is availabe
79
-
80
- __Ant Example__
81
- ```
82
- const connected = await ant.connect() // tries to establish communication and blocks USB stick for usage with other apps
83
- if (connect) {
84
- ....
85
- await ant.disconnect() // closes communication and unblocks USB stick
86
- }
87
- else {
88
- ...
89
- }
90
- ```
91
-
92
- ### Scan for devices
93
-
94
- Every interface offers a method `scan` that allows to scan for devices. The timeout for the scan can be specified in the properties. If those are not provided, a default will apply.
95
-
96
- The scan method returns a `Promise<DeviceSettings[]>` containing the settings of all detected devices.
97
-
98
- In addition to that, all devices that are detected, will be emitted as `device` event during the scan.
99
-
100
- The method `stopScan`can be used to stop an ongoing scan.
101
-
102
- __Examples__
103
-
104
- - Example 1: wait for teh result of the scan
105
-
106
- ```
107
- _interface.on('device',(deviceSettings:DeviceSettings)=>{console.log('Device found', DeviceSettings)})
108
- const devices = await _interface_.scan({timeout:20000})
109
- console.log(devices)
110
- ```
111
- - Example 2: stop scan as soon as one device was found
112
-
113
- ```
114
- _interface.on('device',async (deviceSettings:DeviceSettings)=>{
115
- console.log('Device found', DeviceSettings)
116
- await _interface.stopScan()
117
- })
118
- _interface_.scan({timeout:20000})
119
- ```
120
-
121
-
122
-
123
- ### Create a device
124
-
125
- The Devices library provides and `AdapterFactory`, which allows you to create a device adapters, based on the specifications provided in a `DeviceSettings` object.
126
-
127
- The exact content if this object varies between the interfaces:
128
-
129
- - __Ant__: interface ('ant'), profile( one of 'HR','PWR', 'FE'), deviceID
130
-
131
- - __BLE__: interface ('ble'), protocol( one of 'fm','cp,'hr', 'tacx', 'wahoo'), name, id or address
132
-
133
- - __Serial__: interface('serial' or 'tcpip'), protocol( one of 'Daum Premium', 'Daum Classic', 'Kettler Racer'), name, port, host (only for TCP/IP)
134
-
135
- These device adapters are used by Incyclist to communicate with the devices. The AdapterFactory will ensure that for a given device only one instance of a device adapter will be provided, to avoid that two classes will concurrently communicate with the same physical device.
136
-
137
- At the point where a device adapter is created, the constructor will _not_ try to communicate with the device. I.e. the adapter can be created even if no such device is available/connected.
138
-
139
- __Example__
140
-
141
- ```
142
- const {AdapterFactory} = require('incyclist-devices')
143
-
144
- const device = AdapterFactory.create({interface:'ble, protocol:'fm', name:'KICKR BIKE 1234'})
145
- ```
146
-
147
-
148
-
149
- ### Communicate with a device
150
-
151
- In order to commuicate with the device, the device firstly has to be started
152
-
153
-
154
- #### __start( props?: DeviceProperties):Promise\<boolean\>__
155
-
156
-
157
- you then should register for events:
158
-
159
- - __data__ (device:DeviceSettings, data: DeviceData): is emitted whenever a device/sensor has sent data
160
- - device: describes the device that has sent data
161
- - data: provides the data that the device/sensor has provided (power, speed, cadence,slope, heartrate, timestamp,... )
162
-
163
- - __disconnected__ (device:DeviceSettings): is emitted when the library has not recieved any udate for a configurable time or the underlying interface has recognized a connection loss
164
- - device: describes the device that has sent data
165
-
166
- - __device-info__- (device:DeviceSettings, info:): signals that additional information about the device was received ( e.g. manufacturer, additional features/capabilities)
167
- - device: describes the device that has sent data
168
-
169
-
170
- ```
171
- try {
172
- await device.start({timeout:5000, userWeight:90,bikeWeight:10})
173
- device.on('data',(deviceInfo,data)=> { console.log('device data', deviceInfo,data) })
174
- device.on('disconnected',(deviceInfo)=> {
175
- console.log('device disconnected', deviceInfo)
176
- // check if reconnect makes sense
177
- device.disconnect()
178
- })
179
- }
180
- catch(err) {
181
- console.log('device could not be started, reason', err.message)
182
- }
183
- ```
184
-
185
- #### __setMaxUpdateFrequency(ms:number):void__
186
- #### __getMaxUpdateFrequency():number__
187
-
188
- BLE and ANT devices might send data more frequently than you mihgt want to process in your app. Therefore you can control how often you want to receive updates from a device.
189
-
190
- Default value is 1s
191
-
192
- A value of -1 indicates that the app wants to receive any data without delays
193
-
194
- ```
195
- device.setMaxUpdateFrequency(1000) // send update every 1000ms
196
- const updateFrequency = device.getMaxUpdateFrequency()
197
- ```
198
-
199
-
200
- #### __setPullFrequency(ms:number):void__
201
- #### __getPullFrequency():number__
202
-
203
- Serial Devices are typically not automatically sending data, but the app has to actively pull. Therefore the Serial device adapters also offer the capability to control how often the library will pull data from the device
204
-
205
- Default value is 1s
206
-
207
- _Warning_: Setting this value to low might overload the serial port and you might not receive any data
208
-
209
- #### __stop():Promise\<boolean\>__
210
-
211
- Once the commeunication is not required anymore, you can call stop() to close the connection. This will also automatically unregister the event listeners.
212
-
213
-
214
- #### __pause():Promise\<boolean\>__
215
- #### __resume():Promise\<boolean\>__
216
-
217
- In some cases it might sense to not further receive any update from the device, but still keep the communication open. In thise case, pause() and resume() can be called.
218
-
219
- During a paused state, no event will be emitted
220
-
221
- #### __sendUpdate(request:UpdateRequest):Promise\<boolean\>__
222
-
223
- Allows to send data to the device, typically one of the following data will be sent
224
-
225
- __slope__: (SIM Mode) sets the slope/incline. The smart trainer then will adjust power accordingly
226
-
227
- __targetPower__: (ERG Mode) sets the power that the smart trainer should
228
-
229
- __reset__: returns to the default settings at the start of the training
230
-
231
- __resfresh__: repeats the previous update
232
-
233
- This method should only be called for SmartTrainers or PowerMeters
234
-
235
-
236
- ## Examples
237
-
238
- Please have a look at the [example code](./samples)
1
+ # incyclist-devices
2
+
3
+ Library used by the [Incyclist](https://incyclist.com) Indoor Cycling App to communicate with devices (Smart Trainers, Sensors)
4
+
5
+ It currently support the following Interfaces/Devices
6
+
7
+ __ANT__
8
+ - Smart Trainers (ANT+ FE)
9
+ - Power Meters (ANT+PWR)
10
+ - Heartrate Monitors (ANT+HR)
11
+
12
+ __BLE__
13
+ - Smart Trainers (BLE FTMS)
14
+ - Power Meters (BLE CP)
15
+ - Heartrate Monitors (BLE HR)
16
+ - Wahoo Smart Trainers (Wahoo specific service)
17
+ - Tacx FE-C over BLE
18
+
19
+ __Serial__
20
+ - Daum Classic Ergo Bikes
21
+ - Daum Premium Ergo Bikes (also over TCP/IP)
22
+ - Kettler Ergo Racer Ergo Bikes
23
+
24
+
25
+ ## Install
26
+
27
+ ```sh
28
+ npm install incyclist-devices
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Setup Interfaces and Bindings
34
+
35
+ `Interface` classes are used to enable basic communication (transport layer).
36
+
37
+ As this library supports various OS( Linux, Windows, Mac) and Incyclist is based on Electron, which requires to clearly separate between rendering and main process, Bindings need to be provided for each of the Interfaces. The specifications of these bindings are specific to the interface:
38
+ - Ant: specified by the [incyclist-ant-plus](https://github.com/incyclist/ant-plus) library
39
+ - Serial: specified by the [serialport](https://serialport.io/) library
40
+ - BLE: specified by the [noble](https://github.com/noble/noble) library
41
+
42
+ __Ant Example__
43
+
44
+ ```
45
+ const {EventLogger,ConsoleAdapter} = require( 'gd-eventlog');
46
+ const {AntDevice} = require('incyclist-ant-plus/lib/bindings');
47
+
48
+ const logger = new EventLogger('AntSample')
49
+ const ant = InterfaceFactory.create('ant',{logger, log:true, binding:AntDevice})
50
+ ```
51
+
52
+ __Serial Example__
53
+
54
+ ```
55
+ const {EventLogger,ConsoleAdapter} = require( 'gd-eventlog');
56
+ const { autoDetect } = require('@serialport/bindings-cpp')
57
+
58
+
59
+ const logger = new EventLogger('SerialSample')
60
+ const serial = InterfaceFactory.create('serial',{logger, log:true, binding:autodetect()})
61
+ ```
62
+
63
+ __BLE Example__
64
+
65
+ ```
66
+ const {EventLogger,ConsoleAdapter} = require( 'gd-eventlog');
67
+ const {WinrtBindings} = require('./bindings')
68
+ const Noble = require('noble/lib/noble');
69
+
70
+
71
+ const noble = new Noble(new WinrtBindings())
72
+ const logger = new EventLogger('BLESample')
73
+ const ble = InterfaceFactory.create('ble',{logger, log:true, binding:noble})
74
+ ```
75
+
76
+ ### Check availability of interface
77
+
78
+ For some interfaces (ANT and BLE) it cannot be guaranteed that the underlying hardware supports the interface ( e.g. a USB stick might be required). Therefore this library offers a `connect` method, that allows to check if the interface is availabe
79
+
80
+ __Ant Example__
81
+ ```
82
+ const connected = await ant.connect() // tries to establish communication and blocks USB stick for usage with other apps
83
+ if (connect) {
84
+ ....
85
+ await ant.disconnect() // closes communication and unblocks USB stick
86
+ }
87
+ else {
88
+ ...
89
+ }
90
+ ```
91
+
92
+ ### Scan for devices
93
+
94
+ Every interface offers a method `scan` that allows to scan for devices. The timeout for the scan can be specified in the properties. If those are not provided, a default will apply.
95
+
96
+ The scan method returns a `Promise<DeviceSettings[]>` containing the settings of all detected devices.
97
+
98
+ In addition to that, all devices that are detected, will be emitted as `device` event during the scan.
99
+
100
+ The method `stopScan`can be used to stop an ongoing scan.
101
+
102
+ __Examples__
103
+
104
+ - Example 1: wait for teh result of the scan
105
+
106
+ ```
107
+ _interface.on('device',(deviceSettings:DeviceSettings)=>{console.log('Device found', DeviceSettings)})
108
+ const devices = await _interface_.scan({timeout:20000})
109
+ console.log(devices)
110
+ ```
111
+ - Example 2: stop scan as soon as one device was found
112
+
113
+ ```
114
+ _interface.on('device',async (deviceSettings:DeviceSettings)=>{
115
+ console.log('Device found', DeviceSettings)
116
+ await _interface.stopScan()
117
+ })
118
+ _interface_.scan({timeout:20000})
119
+ ```
120
+
121
+
122
+
123
+ ### Create a device
124
+
125
+ The Devices library provides and `AdapterFactory`, which allows you to create a device adapters, based on the specifications provided in a `DeviceSettings` object.
126
+
127
+ The exact content if this object varies between the interfaces:
128
+
129
+ - __Ant__: interface ('ant'), profile( one of 'HR','PWR', 'FE'), deviceID
130
+
131
+ - __BLE__: interface ('ble'), protocol( one of 'fm','cp,'hr', 'tacx', 'wahoo'), name, id or address
132
+
133
+ - __Serial__: interface('serial' or 'tcpip'), protocol( one of 'Daum Premium', 'Daum Classic', 'Kettler Racer'), name, port, host (only for TCP/IP)
134
+
135
+ These device adapters are used by Incyclist to communicate with the devices. The AdapterFactory will ensure that for a given device only one instance of a device adapter will be provided, to avoid that two classes will concurrently communicate with the same physical device.
136
+
137
+ At the point where a device adapter is created, the constructor will _not_ try to communicate with the device. I.e. the adapter can be created even if no such device is available/connected.
138
+
139
+ __Example__
140
+
141
+ ```
142
+ const {AdapterFactory} = require('incyclist-devices')
143
+
144
+ const device = AdapterFactory.create({interface:'ble, protocol:'fm', name:'KICKR BIKE 1234'})
145
+ ```
146
+
147
+
148
+
149
+ ### Communicate with a device
150
+
151
+ In order to commuicate with the device, the device firstly has to be started
152
+
153
+
154
+ #### __start( props?: DeviceProperties):Promise\<boolean\>__
155
+
156
+
157
+ you then should register for events:
158
+
159
+ - __data__ (device:DeviceSettings, data: DeviceData): is emitted whenever a device/sensor has sent data
160
+ - device: describes the device that has sent data
161
+ - data: provides the data that the device/sensor has provided (power, speed, cadence,slope, heartrate, timestamp,... )
162
+
163
+ - __disconnected__ (device:DeviceSettings): is emitted when the library has not recieved any udate for a configurable time or the underlying interface has recognized a connection loss
164
+ - device: describes the device that has sent data
165
+
166
+ - __device-info__- (device:DeviceSettings, info:): signals that additional information about the device was received ( e.g. manufacturer, additional features/capabilities)
167
+ - device: describes the device that has sent data
168
+
169
+
170
+ ```
171
+ try {
172
+ await device.start({timeout:5000, userWeight:90,bikeWeight:10})
173
+ device.on('data',(deviceInfo,data)=> { console.log('device data', deviceInfo,data) })
174
+ device.on('disconnected',(deviceInfo)=> {
175
+ console.log('device disconnected', deviceInfo)
176
+ // check if reconnect makes sense
177
+ device.disconnect()
178
+ })
179
+ }
180
+ catch(err) {
181
+ console.log('device could not be started, reason', err.message)
182
+ }
183
+ ```
184
+
185
+ #### __setMaxUpdateFrequency(ms:number):void__
186
+ #### __getMaxUpdateFrequency():number__
187
+
188
+ BLE and ANT devices might send data more frequently than you mihgt want to process in your app. Therefore you can control how often you want to receive updates from a device.
189
+
190
+ Default value is 1s
191
+
192
+ A value of -1 indicates that the app wants to receive any data without delays
193
+
194
+ ```
195
+ device.setMaxUpdateFrequency(1000) // send update every 1000ms
196
+ const updateFrequency = device.getMaxUpdateFrequency()
197
+ ```
198
+
199
+
200
+ #### __setPullFrequency(ms:number):void__
201
+ #### __getPullFrequency():number__
202
+
203
+ Serial Devices are typically not automatically sending data, but the app has to actively pull. Therefore the Serial device adapters also offer the capability to control how often the library will pull data from the device
204
+
205
+ Default value is 1s
206
+
207
+ _Warning_: Setting this value to low might overload the serial port and you might not receive any data
208
+
209
+ #### __stop():Promise\<boolean\>__
210
+
211
+ Once the commeunication is not required anymore, you can call stop() to close the connection. This will also automatically unregister the event listeners.
212
+
213
+
214
+ #### __pause():Promise\<boolean\>__
215
+ #### __resume():Promise\<boolean\>__
216
+
217
+ In some cases it might sense to not further receive any update from the device, but still keep the communication open. In thise case, pause() and resume() can be called.
218
+
219
+ During a paused state, no event will be emitted
220
+
221
+ #### __sendUpdate(request:UpdateRequest):Promise\<boolean\>__
222
+
223
+ Allows to send data to the device, typically one of the following data will be sent
224
+
225
+ __slope__: (SIM Mode) sets the slope/incline. The smart trainer then will adjust power accordingly
226
+
227
+ __targetPower__: (ERG Mode) sets the power that the smart trainer should
228
+
229
+ __reset__: returns to the default settings at the start of the training
230
+
231
+ __resfresh__: repeats the previous update
232
+
233
+ This method should only be called for SmartTrainers or PowerMeters
234
+
235
+
236
+ ## Examples
237
+
238
+ Please have a look at the [example code](./samples)
@@ -0,0 +1,7 @@
1
+ import { IncyclistDeviceAdapter } from "./base/adpater";
2
+ import { DeviceProperties, DeviceSettings } from "./types/device";
3
+ export default class AdapterFactory {
4
+ static adapters: IncyclistDeviceAdapter[];
5
+ static reset(): void;
6
+ static create(settings: DeviceSettings, props?: DeviceProperties): any;
7
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const antv2_1 = require("./antv2");
4
+ const ble_1 = require("./ble");
5
+ const serial_1 = require("./serial");
6
+ const Simulator_1 = require("./simulator/Simulator");
7
+ const device_1 = require("./types/device");
8
+ class AdapterFactory {
9
+ static reset() {
10
+ AdapterFactory.adapters = [];
11
+ ble_1.BleAdapterFactory.getInstance().instances = [];
12
+ }
13
+ static create(settings, props) {
14
+ const adapters = AdapterFactory.adapters;
15
+ if (!settings.interface && settings.protocol === 'Simulator') {
16
+ const adapter = new Simulator_1.Simulator(settings);
17
+ if (adapter) {
18
+ adapters.push(adapter);
19
+ }
20
+ return adapter;
21
+ }
22
+ const existing = adapters.find(a => a.isEqual(settings));
23
+ if (existing)
24
+ return existing;
25
+ const ifaceName = typeof settings.interface === 'string' ? settings.interface : settings.interface.getName();
26
+ let adapter;
27
+ switch (ifaceName) {
28
+ case device_1.INTERFACE.SERIAL:
29
+ case device_1.INTERFACE.TCPIP:
30
+ adapter = serial_1.SerialAdapterFactory.getInstance().createInstance(settings, props);
31
+ break;
32
+ case device_1.INTERFACE.ANT:
33
+ adapter = antv2_1.AntAdapterFactory.getInstance().createInstance(settings, props);
34
+ break;
35
+ case device_1.INTERFACE.BLE:
36
+ adapter = ble_1.BleAdapterFactory.getInstance().createInstance(settings, props);
37
+ break;
38
+ case device_1.INTERFACE.SIMULATOR:
39
+ adapter = new Simulator_1.Simulator(settings, props);
40
+ break;
41
+ }
42
+ if (adapter) {
43
+ adapters.push(adapter);
44
+ }
45
+ return adapter;
46
+ }
47
+ }
48
+ AdapterFactory.adapters = [];
49
+ exports.default = AdapterFactory;
@@ -0,0 +1,14 @@
1
+ import { Profile } from "incyclist-ant-plus";
2
+ import AntAdapter from "./base/adapter";
3
+ import { AntDeviceProperties, AntDeviceSettings, LegacyProfile, BaseDeviceData } from "./types";
4
+ import { AntAdapterInfo, AdapterQuery } from "./types";
5
+ export default class AntAdapterFactory {
6
+ static _instance: AntAdapterFactory;
7
+ adapters: AntAdapterInfo[];
8
+ static getInstance(): AntAdapterFactory;
9
+ constructor();
10
+ register<TDeviceData extends BaseDeviceData>(antProfile: Profile, incyclistProfile: LegacyProfile, Adapter: typeof AntAdapter<TDeviceData>): void;
11
+ getAdapter(query?: AdapterQuery): any;
12
+ createInstance(settings: AntDeviceSettings, props?: AntDeviceProperties): any;
13
+ createFromDetected(profile: Profile, deviceID: number, props?: AntDeviceProperties): any;
14
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class AntAdapterFactory {
4
+ static getInstance() {
5
+ if (!AntAdapterFactory._instance)
6
+ AntAdapterFactory._instance = new AntAdapterFactory();
7
+ return AntAdapterFactory._instance;
8
+ }
9
+ constructor() {
10
+ this.adapters = [];
11
+ }
12
+ register(antProfile, incyclistProfile, Adapter) {
13
+ const info = Object.assign({}, { antProfile, incyclistProfile, Adapter });
14
+ const existing = this.adapters.findIndex(a => a.antProfile === antProfile);
15
+ if (existing !== -1)
16
+ this.adapters[existing] = info;
17
+ else
18
+ this.adapters.push(info);
19
+ }
20
+ getAdapter(query) {
21
+ const { antProfile, incyclistProfile } = query;
22
+ if (!antProfile && !incyclistProfile)
23
+ throw new Error('Illegal arguments: either "antProfile" or "incyclistProfile" must be set');
24
+ let found;
25
+ if (antProfile)
26
+ found = this.adapters.find(a => a.antProfile === antProfile);
27
+ if (incyclistProfile)
28
+ found = this.adapters.find(a => a.incyclistProfile === incyclistProfile);
29
+ return found;
30
+ }
31
+ createInstance(settings, props) {
32
+ let info;
33
+ const { profile, protocol } = settings;
34
+ let isLegacy = false;
35
+ if (protocol) {
36
+ try {
37
+ const incyclistProfile = profile;
38
+ info = this.getAdapter({ incyclistProfile });
39
+ isLegacy = true;
40
+ }
41
+ catch (_a) {
42
+ isLegacy = false;
43
+ }
44
+ }
45
+ if (!isLegacy) {
46
+ const antProfile = profile;
47
+ info = this.getAdapter({ antProfile });
48
+ }
49
+ if (info && info.Adapter)
50
+ return new info.Adapter(settings, props);
51
+ }
52
+ createFromDetected(profile, deviceID, props) {
53
+ const info = this.getAdapter({ antProfile: profile });
54
+ if (!info || !info.Adapter)
55
+ return;
56
+ const settings = Object.assign({}, {
57
+ profile: info.incyclistProfile,
58
+ deviceID: deviceID.toString(),
59
+ interface: 'ant',
60
+ protocol: 'Ant'
61
+ });
62
+ return new info.Adapter(settings, props);
63
+ }
64
+ }
65
+ exports.default = AntAdapterFactory;
@@ -0,0 +1,54 @@
1
+ /// <reference types="node" />
2
+ import { IChannel, ISensor, Profile } from 'incyclist-ant-plus';
3
+ import AntInterface from './ant-interface';
4
+ import IncyclistDevice from '../base/adpater';
5
+ import { AntDeviceProperties, AntDeviceSettings, BaseDeviceData } from './types';
6
+ import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../types';
7
+ export default class AntAdapter<TDeviceData extends BaseDeviceData> extends IncyclistDevice<AntDeviceProperties> {
8
+ sensor: ISensor;
9
+ data: IncyclistAdapterData;
10
+ deviceData: TDeviceData;
11
+ updateFrequency: number;
12
+ channel: IChannel;
13
+ ant: AntInterface;
14
+ userSettings: {
15
+ weight?: number;
16
+ };
17
+ bikeSettings: {
18
+ weight?: number;
19
+ };
20
+ onDataFn: (data: IncyclistAdapterData) => void;
21
+ startupRetryPause: number;
22
+ protected ivDataTimeout: NodeJS.Timeout;
23
+ protected lastDataTS: number;
24
+ protected dataMsgCount: number;
25
+ protected ivWaitForData: NodeJS.Timeout;
26
+ constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
27
+ createSensor(settings: AntDeviceSettings): ISensor;
28
+ isEqual(settings: AntDeviceSettings): boolean;
29
+ connect(): Promise<boolean>;
30
+ close(): Promise<boolean>;
31
+ resetData(): void;
32
+ isSame(device: IAdapter): boolean;
33
+ hasData(): boolean;
34
+ mapData(deviceData: TDeviceData): IncyclistBikeData;
35
+ transformData(data: IncyclistBikeData): void;
36
+ mapToAdapterData(deviceData: any): void;
37
+ onDeviceData(deviceData: TDeviceData): void;
38
+ isWaitingForData(): boolean;
39
+ waitForData(timeout: number): Promise<boolean>;
40
+ getID(): string;
41
+ getName(): string;
42
+ getInterface(): string;
43
+ getProfile(): Profile;
44
+ getLogData(data: any, excludeList: any): any;
45
+ triggerTimeoutCheck(): void;
46
+ startDataTimeoutCheck(): void;
47
+ stopDataTimeoutCheck(): void;
48
+ check(): Promise<boolean>;
49
+ checkCapabilities(): Promise<void>;
50
+ initControl(): Promise<void>;
51
+ sendUpdate(request: any): void;
52
+ start(props?: AntDeviceProperties): Promise<boolean>;
53
+ stop(): Promise<boolean>;
54
+ }