incyclist-devices 2.1.6 → 2.1.8

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/antv2/base/adapter.d.ts +0 -0
  4. package/lib/antv2/base/adapter.js +2 -3
  5. package/lib/antv2/base/binding.d.ts +0 -0
  6. package/lib/antv2/base/binding.js +0 -0
  7. package/lib/antv2/base/interface.d.ts +0 -0
  8. package/lib/antv2/base/interface.js +9 -5
  9. package/lib/antv2/cad/adapter.d.ts +0 -0
  10. package/lib/antv2/cad/adapter.js +0 -0
  11. package/lib/antv2/cad/index.d.ts +0 -0
  12. package/lib/antv2/cad/index.js +0 -0
  13. package/lib/antv2/consts.d.ts +0 -0
  14. package/lib/antv2/consts.js +0 -0
  15. package/lib/antv2/factories/adapter-factory.d.ts +0 -0
  16. package/lib/antv2/factories/adapter-factory.js +0 -0
  17. package/lib/antv2/factories/sensor-factory.d.ts +0 -0
  18. package/lib/antv2/factories/sensor-factory.js +0 -0
  19. package/lib/antv2/fe/adapter.d.ts +0 -0
  20. package/lib/antv2/fe/adapter.js +0 -0
  21. package/lib/antv2/fe/index.d.ts +0 -0
  22. package/lib/antv2/fe/index.js +0 -0
  23. package/lib/antv2/hr/adapter.d.ts +0 -0
  24. package/lib/antv2/hr/adapter.js +0 -0
  25. package/lib/antv2/hr/index.d.ts +0 -0
  26. package/lib/antv2/hr/index.js +0 -0
  27. package/lib/antv2/index.d.ts +0 -0
  28. package/lib/antv2/index.js +0 -0
  29. package/lib/antv2/pwr/adapter.d.ts +0 -0
  30. package/lib/antv2/pwr/adapter.js +0 -0
  31. package/lib/antv2/pwr/index.d.ts +0 -0
  32. package/lib/antv2/pwr/index.js +0 -0
  33. package/lib/antv2/types.d.ts +0 -0
  34. package/lib/antv2/types.js +0 -0
  35. package/lib/antv2/utils.d.ts +0 -0
  36. package/lib/antv2/utils.js +0 -0
  37. package/lib/base/adpater.d.ts +0 -0
  38. package/lib/base/adpater.js +0 -0
  39. package/lib/base/consts.d.ts +0 -0
  40. package/lib/base/consts.js +0 -0
  41. package/lib/ble/adapter-factory.d.ts +0 -0
  42. package/lib/ble/adapter-factory.js +0 -0
  43. package/lib/ble/base/adapter.d.ts +3 -1
  44. package/lib/ble/base/adapter.js +27 -9
  45. package/lib/ble/base/comms-utils.d.ts +0 -0
  46. package/lib/ble/base/comms-utils.js +0 -0
  47. package/lib/ble/base/comms.d.ts +0 -0
  48. package/lib/ble/base/comms.js +0 -0
  49. package/lib/ble/base/types.d.ts +0 -0
  50. package/lib/ble/base/types.js +0 -0
  51. package/lib/ble/bindings/index.d.ts +0 -0
  52. package/lib/ble/bindings/index.js +0 -0
  53. package/lib/ble/bindings/linux.d.ts +1 -0
  54. package/lib/ble/bindings/linux.js +2 -0
  55. package/lib/ble/bindings/mock.d.ts +0 -0
  56. package/lib/ble/bindings/mock.js +2 -0
  57. package/lib/ble/bindings/types.d.ts +0 -0
  58. package/lib/ble/bindings/types.js +0 -0
  59. package/lib/ble/ble-interface.d.ts +11 -9
  60. package/lib/ble/ble-interface.js +74 -56
  61. package/lib/ble/ble-peripheral.d.ts +0 -0
  62. package/lib/ble/ble-peripheral.js +0 -0
  63. package/lib/ble/consts.d.ts +0 -0
  64. package/lib/ble/consts.js +0 -0
  65. package/lib/ble/cp/adapter.d.ts +0 -0
  66. package/lib/ble/cp/adapter.js +0 -0
  67. package/lib/ble/cp/comm.d.ts +0 -0
  68. package/lib/ble/cp/comm.js +3 -2
  69. package/lib/ble/cp/index.d.ts +0 -0
  70. package/lib/ble/cp/index.js +0 -0
  71. package/lib/ble/cp/types.d.ts +0 -0
  72. package/lib/ble/cp/types.js +0 -0
  73. package/lib/ble/elite/adapter.d.ts +0 -0
  74. package/lib/ble/elite/adapter.js +0 -0
  75. package/lib/ble/elite/comms.d.ts +0 -0
  76. package/lib/ble/elite/comms.js +3 -2
  77. package/lib/ble/elite/index.d.ts +0 -0
  78. package/lib/ble/elite/index.js +0 -0
  79. package/lib/ble/fm/adapter.d.ts +0 -0
  80. package/lib/ble/fm/adapter.js +0 -0
  81. package/lib/ble/fm/comms.d.ts +0 -0
  82. package/lib/ble/fm/comms.js +5 -3
  83. package/lib/ble/fm/consts.d.ts +0 -0
  84. package/lib/ble/fm/consts.js +0 -0
  85. package/lib/ble/fm/index.d.ts +0 -0
  86. package/lib/ble/fm/index.js +0 -0
  87. package/lib/ble/fm/types.d.ts +0 -0
  88. package/lib/ble/fm/types.js +0 -0
  89. package/lib/ble/hr/adapter.d.ts +0 -0
  90. package/lib/ble/hr/adapter.js +0 -0
  91. package/lib/ble/hr/comm.d.ts +1 -0
  92. package/lib/ble/hr/comm.js +10 -1
  93. package/lib/ble/hr/index.d.ts +0 -0
  94. package/lib/ble/hr/index.js +0 -0
  95. package/lib/ble/hr/mock.d.ts +0 -0
  96. package/lib/ble/hr/mock.js +0 -0
  97. package/lib/ble/hr/types.d.ts +0 -0
  98. package/lib/ble/hr/types.js +0 -0
  99. package/lib/ble/index.d.ts +0 -0
  100. package/lib/ble/index.js +0 -0
  101. package/lib/ble/peripheral-cache.d.ts +0 -0
  102. package/lib/ble/peripheral-cache.js +0 -0
  103. package/lib/ble/tacx/adapter.d.ts +1 -1
  104. package/lib/ble/tacx/adapter.js +4 -4
  105. package/lib/ble/tacx/comms.d.ts +0 -0
  106. package/lib/ble/tacx/comms.js +3 -2
  107. package/lib/ble/tacx/index.d.ts +0 -0
  108. package/lib/ble/tacx/index.js +0 -0
  109. package/lib/ble/tacx/types.d.ts +0 -0
  110. package/lib/ble/tacx/types.js +0 -0
  111. package/lib/ble/types.d.ts +1 -0
  112. package/lib/ble/types.js +0 -0
  113. package/lib/ble/utils.d.ts +0 -0
  114. package/lib/ble/utils.js +0 -0
  115. package/lib/ble/wahoo/adapter.d.ts +0 -0
  116. package/lib/ble/wahoo/adapter.js +0 -0
  117. package/lib/ble/wahoo/comms.d.ts +0 -0
  118. package/lib/ble/wahoo/comms.js +3 -2
  119. package/lib/ble/wahoo/index.d.ts +0 -0
  120. package/lib/ble/wahoo/index.js +0 -0
  121. package/lib/ble/wahoo/types.d.ts +0 -0
  122. package/lib/ble/wahoo/types.js +0 -0
  123. package/lib/factories/adapters.d.ts +0 -0
  124. package/lib/factories/adapters.js +0 -0
  125. package/lib/factories/index.d.ts +0 -0
  126. package/lib/factories/index.js +0 -0
  127. package/lib/factories/interfaces.d.ts +0 -0
  128. package/lib/factories/interfaces.js +0 -0
  129. package/lib/index.d.ts +0 -0
  130. package/lib/index.js +0 -0
  131. package/lib/modes/ant-fe-adv-st-mode.d.ts +0 -0
  132. package/lib/modes/ant-fe-adv-st-mode.js +0 -0
  133. package/lib/modes/antble-erg.d.ts +0 -0
  134. package/lib/modes/antble-erg.js +0 -0
  135. package/lib/modes/antble-smarttrainer.d.ts +0 -0
  136. package/lib/modes/antble-smarttrainer.js +0 -0
  137. package/lib/modes/base.d.ts +0 -0
  138. package/lib/modes/base.js +0 -0
  139. package/lib/modes/daum-classic-standard.d.ts +0 -0
  140. package/lib/modes/daum-classic-standard.js +0 -0
  141. package/lib/modes/daum-erg.d.ts +0 -0
  142. package/lib/modes/daum-erg.js +0 -0
  143. package/lib/modes/daum-power.d.ts +0 -0
  144. package/lib/modes/daum-power.js +0 -0
  145. package/lib/modes/daum-premium-standard.d.ts +0 -0
  146. package/lib/modes/daum-premium-standard.js +0 -0
  147. package/lib/modes/daum-smarttrainer.d.ts +0 -0
  148. package/lib/modes/daum-smarttrainer.js +0 -0
  149. package/lib/modes/kettler-erg.d.ts +0 -0
  150. package/lib/modes/kettler-erg.js +0 -0
  151. package/lib/modes/power-base.d.ts +0 -0
  152. package/lib/modes/power-base.js +0 -0
  153. package/lib/modes/power-meter.d.ts +0 -0
  154. package/lib/modes/power-meter.js +0 -0
  155. package/lib/modes/simulator.d.ts +0 -0
  156. package/lib/modes/simulator.js +0 -0
  157. package/lib/modes/types.d.ts +0 -0
  158. package/lib/modes/types.js +0 -0
  159. package/lib/serial/base/adapter.d.ts +0 -0
  160. package/lib/serial/base/adapter.js +0 -0
  161. package/lib/serial/base/comms.d.ts +0 -0
  162. package/lib/serial/base/comms.js +0 -0
  163. package/lib/serial/base/serial-interface.d.ts +0 -0
  164. package/lib/serial/base/serial-interface.js +0 -0
  165. package/lib/serial/base/serial-scanner.d.ts +0 -0
  166. package/lib/serial/base/serial-scanner.js +0 -0
  167. package/lib/serial/base/serialport.d.ts +0 -0
  168. package/lib/serial/base/serialport.js +0 -0
  169. package/lib/serial/bindings/tcp.d.ts +0 -0
  170. package/lib/serial/bindings/tcp.js +0 -0
  171. package/lib/serial/daum/DaumAdapter.d.ts +0 -0
  172. package/lib/serial/daum/DaumAdapter.js +0 -0
  173. package/lib/serial/daum/classic/adapter.d.ts +0 -0
  174. package/lib/serial/daum/classic/adapter.js +0 -0
  175. package/lib/serial/daum/classic/comms.d.ts +0 -0
  176. package/lib/serial/daum/classic/comms.js +0 -0
  177. package/lib/serial/daum/classic/consts.d.ts +0 -0
  178. package/lib/serial/daum/classic/consts.js +0 -0
  179. package/lib/serial/daum/classic/mock.d.ts +0 -0
  180. package/lib/serial/daum/classic/mock.js +0 -0
  181. package/lib/serial/daum/classic/types.d.ts +0 -0
  182. package/lib/serial/daum/classic/types.js +0 -0
  183. package/lib/serial/daum/classic/utils.d.ts +0 -0
  184. package/lib/serial/daum/classic/utils.js +0 -0
  185. package/lib/serial/daum/premium/adapter.d.ts +0 -0
  186. package/lib/serial/daum/premium/adapter.js +0 -0
  187. package/lib/serial/daum/premium/comms.d.ts +0 -0
  188. package/lib/serial/daum/premium/comms.js +0 -0
  189. package/lib/serial/daum/premium/consts.d.ts +0 -0
  190. package/lib/serial/daum/premium/consts.js +0 -0
  191. package/lib/serial/daum/premium/mock.d.ts +0 -0
  192. package/lib/serial/daum/premium/mock.js +0 -0
  193. package/lib/serial/daum/premium/types.d.ts +0 -0
  194. package/lib/serial/daum/premium/types.js +0 -0
  195. package/lib/serial/daum/premium/utils.d.ts +0 -0
  196. package/lib/serial/daum/premium/utils.js +0 -0
  197. package/lib/serial/daum/types.d.ts +0 -0
  198. package/lib/serial/daum/types.js +0 -0
  199. package/lib/serial/factories/adapter-factory.d.ts +0 -0
  200. package/lib/serial/factories/adapter-factory.js +0 -0
  201. package/lib/serial/index.d.ts +0 -0
  202. package/lib/serial/index.js +0 -0
  203. package/lib/serial/kettler/comms.d.ts +0 -0
  204. package/lib/serial/kettler/comms.js +0 -0
  205. package/lib/serial/kettler/ergo-racer/adapter.d.ts +0 -0
  206. package/lib/serial/kettler/ergo-racer/adapter.js +0 -0
  207. package/lib/serial/kettler/ergo-racer/mock.d.ts +0 -0
  208. package/lib/serial/kettler/ergo-racer/mock.js +0 -0
  209. package/lib/serial/kettler/types.d.ts +0 -0
  210. package/lib/serial/kettler/types.js +0 -0
  211. package/lib/serial/types.d.ts +0 -0
  212. package/lib/serial/types.js +0 -0
  213. package/lib/simulator/Simulator.d.ts +0 -0
  214. package/lib/simulator/Simulator.js +0 -0
  215. package/lib/types/adapter.d.ts +0 -0
  216. package/lib/types/adapter.js +0 -0
  217. package/lib/types/capabilities.d.ts +0 -0
  218. package/lib/types/capabilities.js +0 -0
  219. package/lib/types/data.d.ts +0 -0
  220. package/lib/types/data.js +0 -0
  221. package/lib/types/device.d.ts +0 -0
  222. package/lib/types/device.js +0 -0
  223. package/lib/types/index.d.ts +0 -0
  224. package/lib/types/index.js +0 -0
  225. package/lib/types/interface.d.ts +0 -0
  226. package/lib/types/interface.js +0 -0
  227. package/lib/types/user.d.ts +0 -0
  228. package/lib/types/user.js +0 -0
  229. package/lib/utils/calculations.d.ts +0 -0
  230. package/lib/utils/calculations.js +0 -0
  231. package/lib/utils/utils.d.ts +0 -0
  232. package/lib/utils/utils.js +0 -0
  233. package/package.json +51 -51
  234. package/lib/adapters.d.ts +0 -7
  235. package/lib/adapters.js +0 -49
  236. package/lib/antv2/adapter-factory.d.ts +0 -14
  237. package/lib/antv2/adapter-factory.js +0 -65
  238. package/lib/antv2/adapter.d.ts +0 -54
  239. package/lib/antv2/adapter.js +0 -291
  240. package/lib/antv2/ant-interface.d.ts +0 -35
  241. package/lib/antv2/ant-interface.js +0 -285
  242. package/lib/antv2/base/ant-interface.d.ts +0 -35
  243. package/lib/antv2/base/ant-interface.js +0 -285
  244. package/lib/antv2/binding.d.ts +0 -13
  245. package/lib/antv2/binding.js +0 -27
  246. package/lib/antv2/hr copy/adapter.d.ts +0 -11
  247. package/lib/antv2/hr copy/adapter.js +0 -30
  248. package/lib/antv2/hr copy/index.d.ts +0 -2
  249. package/lib/antv2/hr copy/index.js +0 -7
  250. package/lib/antv2/sensor-factory.d.ts +0 -5
  251. package/lib/antv2/sensor-factory.js +0 -20
  252. package/lib/interfaces.d.ts +0 -7
  253. package/lib/interfaces.js +0 -27
  254. package/lib/serial/SinglePathScanner.d.ts +0 -17
  255. package/lib/serial/SinglePathScanner.js +0 -87
  256. package/lib/serial/adapter-factory.d.ts +0 -14
  257. package/lib/serial/adapter-factory.js +0 -30
  258. package/lib/serial/adapter.d.ts +0 -17
  259. package/lib/serial/adapter.js +0 -67
  260. package/lib/serial/comm.d.ts +0 -7
  261. package/lib/serial/comm.js +0 -2
  262. package/lib/serial/comms.d.ts +0 -62
  263. package/lib/serial/comms.js +0 -280
  264. package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +0 -2
  265. package/lib/serial/daum/classic/PROTOCOL_NAME.js +0 -5
  266. package/lib/serial/daum/consts.d.ts +0 -0
  267. package/lib/serial/daum/consts.js +0 -0
  268. package/lib/serial/serial-interface.d.ts +0 -36
  269. package/lib/serial/serial-interface.js +0 -288
  270. package/lib/serial/serial-scanner.d.ts +0 -16
  271. package/lib/serial/serial-scanner.js +0 -87
  272. package/lib/serial/serialport.d.ts +0 -17
  273. package/lib/serial/serialport.js +0 -87
  274. package/lib/types/Command.d.ts +0 -8
  275. package/lib/types/Command.js +0 -2
  276. package/lib/types/command.d.ts +0 -0
  277. package/lib/types/command.js +0 -0
  278. package/lib/types/route.d.ts +0 -0
  279. package/lib/types/route.js +0 -0
  280. package/lib/types/types.d.ts +0 -8
  281. package/lib/types/types.js +0 -2
@@ -18,6 +18,7 @@ const INTERFACE_NAME = 'ble';
18
18
  class BleAdapter extends adpater_1.default {
19
19
  constructor(settings, props) {
20
20
  super(settings, props);
21
+ this.onDeviceDataHandler = this.onDeviceData.bind(this);
21
22
  if (this.settings.interface !== INTERFACE_NAME)
22
23
  throw new Error('Incorrect interface');
23
24
  this.deviceData = {};
@@ -139,23 +140,38 @@ class BleAdapter extends adpater_1.default {
139
140
  check() {
140
141
  return this.start({ scanOnly: true });
141
142
  }
142
- start(props = {}) {
143
+ startPreChecks(props) {
143
144
  return __awaiter(this, void 0, void 0, function* () {
145
+ const wasPaused = this.paused;
144
146
  const wasStopped = this.stopped;
145
- this.resume();
146
- if (this.started && !wasStopped)
147
- return true;
148
147
  this.stopped = false;
148
+ if (wasPaused)
149
+ this.resume();
150
+ if (this.started && !wasPaused && !wasStopped) {
151
+ return 'done';
152
+ }
153
+ if (this.started && wasPaused) {
154
+ return 'done';
155
+ }
149
156
  const connected = yield this.connect();
150
157
  if (!connected)
158
+ return 'connection-failed';
159
+ return 'connected';
160
+ });
161
+ }
162
+ start(props = {}) {
163
+ var _a;
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const preCheckResult = yield this.startPreChecks(props);
166
+ if (preCheckResult === 'done')
167
+ return this.started;
168
+ if (preCheckResult === 'connection-failed')
151
169
  throw new Error(`could not start device, reason:could not connect`);
152
- this.logger.logEvent({ message: 'start requested', protocol: this.getProtocolName(), props });
170
+ this.logEvent({ message: 'starting device', device: this.getName(), props, isStarted: this.started });
153
171
  try {
154
172
  const comms = this.device;
155
173
  if (comms) {
156
- comms.on('data', (data) => {
157
- this.onDeviceData(data);
158
- });
174
+ comms.on('data', this.onDeviceDataHandler);
159
175
  this.resetData();
160
176
  this.stopped = false;
161
177
  this.started = true;
@@ -165,14 +181,16 @@ class BleAdapter extends adpater_1.default {
165
181
  }
166
182
  catch (err) {
167
183
  this.logger.logEvent({ message: 'start result: error', error: err.message, protocol: this.getProtocolName() });
184
+ (_a = this.getComms()) === null || _a === void 0 ? void 0 : _a.pause();
168
185
  throw new Error(`could not start device, reason:${err.message}`);
169
186
  }
170
187
  });
171
188
  }
172
189
  stop() {
173
190
  return __awaiter(this, void 0, void 0, function* () {
174
- this.logger.logEvent({ message: 'stop requested', protocol: this.getProtocolName() });
191
+ this.logger.logEvent({ message: 'stopping device', device: this.getName() });
175
192
  this.device.reset();
193
+ this.device.off('data', this.onDeviceDataHandler);
176
194
  const stopped = this.device.disconnect();
177
195
  if (stopped) {
178
196
  this.stopped = true;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -9,6 +9,7 @@ export declare class BleLinuxBinding extends EventEmitter implements BleBinding
9
9
  static getInstance(): any;
10
10
  startScanning(serviceUUIDs?: string[] | undefined, allowDuplicates?: boolean | undefined, callback?: ((error?: Error | undefined) => void) | undefined): void;
11
11
  stopScanning(callback?: (() => void) | undefined): void;
12
+ setServerDebug(enabled: boolean): void;
12
13
  pauseLogging(): void;
13
14
  resumeLogging(): void;
14
15
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
@@ -23,6 +23,8 @@ class BleLinuxBinding extends events_1.default {
23
23
  stopScanning(callback) {
24
24
  throw new Error('Method not implemented.');
25
25
  }
26
+ setServerDebug(enabled) {
27
+ }
26
28
  pauseLogging() {
27
29
  }
28
30
  resumeLogging() {
File without changes
@@ -29,6 +29,8 @@ class Binding extends events_1.default {
29
29
  return Binding._instance;
30
30
  }
31
31
  init() { }
32
+ setServerDebug(enabled) {
33
+ }
32
34
  pauseLogging() {
33
35
  }
34
36
  resumeLogging() {
File without changes
File without changes
@@ -14,6 +14,7 @@ export interface ScanState {
14
14
  timeout?: NodeJS.Timeout;
15
15
  peripherals?: Map<string, BlePeripheral>;
16
16
  detected?: string[];
17
+ emitter?: EventEmitter;
17
18
  }
18
19
  export interface ConnectState {
19
20
  isConnecting: boolean;
@@ -54,24 +55,25 @@ export default class BleInterface extends EventEmitter implements IncyclistInter
54
55
  getBinding(): BleBinding;
55
56
  setBinding(binding: BleBinding): void;
56
57
  getName(): string;
58
+ protected getReconnectPause(): number;
57
59
  startConnectSensor(): void;
58
60
  stopConnectSensor(): void;
59
61
  waitForSensorConnectionFinish(): Promise<void>;
60
62
  getAdapterFactory(): BleAdapterFactory;
61
- pauseLogging(): void;
63
+ pauseLogging(debugOnly?: boolean): void;
62
64
  resumeLogging(): void;
63
- isDebugEnabled(): boolean;
64
- logEvent(event: any): void;
65
- onStateChange(state: BleInterfaceState): void;
66
- onError(err: any): void;
65
+ protected isDebugEnabled(): boolean;
66
+ protected logEvent(event: any): void;
67
+ protected onStateChange(state: BleInterfaceState): void;
68
+ protected onError(err: any): void;
67
69
  connect(to?: number): Promise<boolean>;
68
70
  disconnect(): Promise<boolean>;
69
71
  isConnected(): boolean;
70
- waitForConnectFinished(timeout: any): Promise<unknown>;
71
72
  onDisconnect(peripheral: any): void;
72
- getCharacteristics(peripheral: BlePeripheral): Promise<BleCharacteristic[]>;
73
- waitForScanFinished(timeout: any): Promise<unknown>;
74
- onPeripheralFound(p: BlePeripheral, callback: any, props?: {
73
+ protected scannerWaitForConnection(tsTimeoutExpired?: number): Promise<void>;
74
+ protected getCharacteristics(peripheral: BlePeripheral): Promise<BleCharacteristic[]>;
75
+ protected waitForScanFinished(timeout: any): Promise<unknown>;
76
+ protected onPeripheralFound(p: BlePeripheral, callback: any, props?: {
75
77
  request?: BleDeviceSettings;
76
78
  comms?: BleComms;
77
79
  protocolFilter?: BleProtocol[] | null;
@@ -59,6 +59,9 @@ class BleInterface extends events_1.default {
59
59
  getName() {
60
60
  return 'ble';
61
61
  }
62
+ getReconnectPause() {
63
+ return 1000;
64
+ }
62
65
  startConnectSensor() {
63
66
  this.sensorIsConnecting = true;
64
67
  }
@@ -76,15 +79,19 @@ class BleInterface extends events_1.default {
76
79
  getAdapterFactory() {
77
80
  return adapter_factory_1.default.getInstance();
78
81
  }
79
- pauseLogging() {
80
- this.logEvent({ message: 'pause logging on BLE Interface' });
81
- this.loggingPaused = true;
82
+ pauseLogging(debugOnly = false) {
83
+ if (this.loggingPaused)
84
+ return;
85
+ this.logEvent({ message: 'pause logging on BLE Interface', debugOnly });
86
+ this.loggingPaused = debugOnly;
82
87
  try {
83
88
  this.getBinding().pauseLogging();
84
89
  }
85
90
  catch (_a) { }
86
91
  }
87
92
  resumeLogging() {
93
+ if (!this.loggingPaused)
94
+ return;
88
95
  const event = { message: 'resume logging on BLE Interface' };
89
96
  this.logger.logEvent(event);
90
97
  if (this.isDebugEnabled()) {
@@ -221,25 +228,23 @@ class BleInterface extends events_1.default {
221
228
  isConnected() {
222
229
  return this.connectState.isConnected;
223
230
  }
224
- waitForConnectFinished(timeout) {
225
- const waitStart = Date.now();
226
- const waitTimeout = waitStart + timeout;
227
- return new Promise((resolve, reject) => {
228
- const waitIv = setInterval(() => {
229
- if (this.scanState.isConnecting && Date.now() > waitTimeout) {
230
- clearInterval(waitIv);
231
- return reject(new Error('Connecting already in progress'));
232
- }
233
- if (!this.scanState.isConnecting) {
234
- clearInterval(waitIv);
235
- return resolve(true);
236
- }
237
- }, 100);
238
- });
239
- }
240
231
  onDisconnect(peripheral) {
241
232
  this.peripheralCache.remove(peripheral);
242
233
  }
234
+ scannerWaitForConnection(tsTimeoutExpired) {
235
+ return __awaiter(this, void 0, void 0, function* () {
236
+ const timeoutExpired = () => {
237
+ if (!tsTimeoutExpired)
238
+ return false;
239
+ return Date.now() >= tsTimeoutExpired;
240
+ };
241
+ while (!this.isConnected() && this.scanState.isScanning && !timeoutExpired()) {
242
+ const connected = yield this.connect();
243
+ if (!connected)
244
+ yield (0, utils_2.sleep)(this.getReconnectPause());
245
+ }
246
+ });
247
+ }
243
248
  getCharacteristics(peripheral) {
244
249
  return __awaiter(this, void 0, void 0, function* () {
245
250
  let characteristics = undefined;
@@ -369,6 +374,10 @@ class BleInterface extends events_1.default {
369
374
  const request = comms.getSettings();
370
375
  const { protocol } = request;
371
376
  const ble = this.getBinding();
377
+ try {
378
+ this.getBinding().setServerDebug(true);
379
+ }
380
+ catch (_a) { }
372
381
  if (!this.isConnected()) {
373
382
  yield this.connect();
374
383
  }
@@ -401,6 +410,10 @@ class BleInterface extends events_1.default {
401
410
  this.logEvent({ message: `${opStr}: stop scanning`, request });
402
411
  ble.stopScanning(() => {
403
412
  this.scanState.isScanning = false;
413
+ try {
414
+ this.getBinding().setServerDebug(false);
415
+ }
416
+ catch (_a) { }
404
417
  reject(new Error('device not found'));
405
418
  return;
406
419
  });
@@ -430,6 +443,10 @@ class BleInterface extends events_1.default {
430
443
  ble.stopScanning(() => {
431
444
  ble.removeAllListeners('discover');
432
445
  this.scanState.isScanning = false;
446
+ try {
447
+ this.getBinding().setServerDebug(false);
448
+ }
449
+ catch (_a) { }
433
450
  resolve(peripheral);
434
451
  });
435
452
  });
@@ -447,13 +464,17 @@ class BleInterface extends events_1.default {
447
464
  }
448
465
  scan(props = {}) {
449
466
  return __awaiter(this, void 0, void 0, function* () {
450
- const { timeout = DEFAULT_SCAN_TIMEOUT, protocol, protocols } = props;
467
+ this.resumeLogging();
468
+ this.logEvent({ message: 'starting scan ..' });
469
+ const { timeout, protocol, protocols } = props;
451
470
  const requestedProtocols = protocols || [];
452
471
  if (protocol && !requestedProtocols.find(p => p === protocol))
453
472
  requestedProtocols.push(protocol);
454
473
  const protocolFilter = requestedProtocols.length > 0 ? requestedProtocols : null;
455
474
  const services = protocolFilter === null ? this.getAdapterFactory().getAllSupportedServices() : (0, comms_utils_1.getServicesFromProtocols)(protocolFilter);
456
475
  const ble = this.getBinding();
476
+ if (!ble)
477
+ throw new Error('no binding defined');
457
478
  const opStr = 'scan';
458
479
  if (this.scanState.isScanning) {
459
480
  try {
@@ -466,49 +487,49 @@ class BleInterface extends events_1.default {
466
487
  }
467
488
  }
468
489
  this.scanState.isScanning = true;
490
+ this.scanState.emitter = new events_1.default();
469
491
  const tsStart = Date.now();
470
- const tsTimeoutExpired = tsStart + timeout;
471
- while (!this.isConnected() && this.scanState.isScanning && Date.now() < tsTimeoutExpired) {
472
- const connected = yield this.connect();
473
- if (!connected)
474
- yield (0, utils_2.sleep)(1000);
475
- }
476
- if (Date.now() > tsTimeoutExpired) {
477
- return [];
478
- }
479
- if (!this.scanState.isScanning) {
492
+ const tsTimeoutExpired = timeout ? tsStart + timeout : undefined;
493
+ yield this.scannerWaitForConnection(tsTimeoutExpired);
494
+ if (Date.now() > tsTimeoutExpired || !this.scanState.isScanning) {
480
495
  return [];
481
496
  }
482
- const adjustedScanTimeout = tsStart - Date.now() + timeout;
497
+ const adjustedScanTimeout = timeout;
483
498
  const supported = adapter_factory_1.default.getInstance().getAll().map(i => i.protocol);
484
499
  this.logEvent({ message: 'scan start', services, supported });
485
500
  return new Promise((resolve, reject) => {
486
501
  this.scanState.peripherals = new Map();
487
502
  const detected = [];
488
503
  const requested = protocolFilter;
489
- const onTimeout = () => {
504
+ const onTimeoutOrStopped = (wasTimeout = false) => __awaiter(this, void 0, void 0, function* () {
490
505
  if (!this.scanState.isScanning || !this.scanState.timeout)
491
506
  return;
492
- this.scanState.timeout = null;
507
+ if (this.scanState.timeout) {
508
+ clearTimeout(this.scanState.timeout);
509
+ this.scanState.timeout = null;
510
+ }
493
511
  const devices = detected.map(d => {
494
512
  const { id, name, address, protocol } = d;
495
513
  return { id, name, address, protocol };
496
514
  });
497
- this.logEvent({ message: `${opStr} result: timeout, devices found`, requested, devices });
515
+ if (wasTimeout)
516
+ this.logEvent({ message: `${opStr} result: timeout, devices found`, requested, devices });
498
517
  ble.removeAllListeners('discover');
499
- this.logEvent({ message: `${opStr}: stop scanning`, requested });
500
- ble.stopScanning(() => {
501
- this.scanState.isScanning = false;
502
- resolve(detected);
503
- });
518
+ yield ble.stopScanning();
519
+ resolve(detected);
504
520
  this.emittingAdapters.forEach(a => {
505
521
  a.comms.off('data', a.cb);
506
522
  a.comms.unsubscribeAll();
507
523
  });
508
524
  this.emittingAdapters = [];
509
- };
510
- this.logEvent({ message: `${opStr}: start scanning`, requested, timeout });
511
- this.scanState.timeout = setTimeout(onTimeout, adjustedScanTimeout);
525
+ this.emit('scan stopped', true);
526
+ });
527
+ if (timeout)
528
+ this.scanState.timeout = setTimeout(onTimeoutOrStopped, adjustedScanTimeout);
529
+ this.scanState.emitter.on('stop', () => {
530
+ this.emit('stop-scan');
531
+ onTimeoutOrStopped();
532
+ });
512
533
  ble.startScanning(protocolFilter ? services : [], false, (err) => {
513
534
  if (err) {
514
535
  this.logEvent({ message: `${opStr} result: error`, requested, error: err.message });
@@ -546,24 +567,21 @@ class BleInterface extends events_1.default {
546
567
  }
547
568
  stopScan() {
548
569
  return __awaiter(this, void 0, void 0, function* () {
549
- this.logEvent({ message: 'scan stop request' });
550
- if (!this.scanState.isScanning) {
551
- this.logEvent({ message: 'scan stop result: not scanning' });
570
+ this.logEvent({ message: 'stopping scan ..' });
571
+ this.pauseLogging(true);
572
+ if (!this.isScanning()) {
573
+ this.logEvent({ message: 'stopping scan done ..' });
552
574
  return true;
553
575
  }
554
- const ble = this.getBinding();
555
- if (!ble)
556
- throw new Error('no binding defined');
557
- ble.removeAllListeners('discover');
558
- this.peripheralCache.handleStopScan();
559
- ble.stopScanning();
560
- this.emittingAdapters.forEach(a => {
561
- a.comms.unsubscribeAll();
562
- a.comms.off('data', a.cb);
576
+ yield new Promise(done => {
577
+ var _a;
578
+ (_a = this.scanState.emitter) === null || _a === void 0 ? void 0 : _a.emit('stop');
579
+ this.once('scan stopped', (res) => {
580
+ done(res);
581
+ });
563
582
  });
564
- this.emittingAdapters = [];
565
583
  this.scanState.isScanning = false;
566
- this.logEvent({ message: 'scan stop result: success' });
584
+ this.logEvent({ message: 'stopping scan done ..' });
567
585
  return true;
568
586
  });
569
587
  }
File without changes
File without changes
File without changes
package/lib/ble/consts.js CHANGED
File without changes
File without changes
File without changes
File without changes
@@ -18,8 +18,9 @@ class BleCyclingPowerDevice extends comms_1.BleComms {
18
18
  static isMatching(characteristics) {
19
19
  if (!characteristics)
20
20
  return false;
21
- const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
22
- const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
21
+ const announced = characteristics.map(c => (0, utils_1.uuid)(c));
22
+ const hasCPMeasurement = announced.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
23
+ const hasCPFeature = announced.find(c => c === consts_1.CSP_FEATURE) !== undefined;
23
24
  return hasCPMeasurement && hasCPFeature;
24
25
  }
25
26
  getProfile() {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -19,8 +19,9 @@ class BleEliteDevice extends comms_1.BleComms {
19
19
  static isMatching(characteristics) {
20
20
  if (!characteristics)
21
21
  return false;
22
- const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
23
- const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
22
+ const announced = characteristics.map(c => (0, utils_1.uuid)(c));
23
+ const hasCPMeasurement = announced.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
24
+ const hasCPFeature = announced.find(c => c === consts_1.CSP_FEATURE) !== undefined;
24
25
  return hasCPMeasurement && hasCPFeature;
25
26
  }
26
27
  getProfile() {
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const consts_1 = require("../consts");
13
13
  const comms_1 = require("../base/comms");
14
+ const utils_1 = require("../utils");
14
15
  const bit = (nr) => (1 << nr);
15
16
  const IndoorBikeDataFlag = {
16
17
  MoreData: bit(0),
@@ -82,9 +83,10 @@ class BleFitnessMachineDevice extends comms_1.BleComms {
82
83
  static isMatching(characteristics) {
83
84
  if (!characteristics)
84
85
  return false;
85
- const hasStatus = characteristics.find(c => c === consts_1.FTMS_STATUS) !== undefined;
86
- const hasCP = characteristics.find(c => c === consts_1.FTMS_CP) !== undefined;
87
- const hasIndoorBike = characteristics.find(c => c === consts_1.INDOOR_BIKE_DATA) !== undefined;
86
+ const announced = characteristics.map(c => (0, utils_1.uuid)(c));
87
+ const hasStatus = announced.find(c => c === consts_1.FTMS_STATUS) !== undefined;
88
+ const hasCP = announced.find(c => c === consts_1.FTMS_CP) !== undefined;
89
+ const hasIndoorBike = announced.find(c => c === consts_1.INDOOR_BIKE_DATA) !== undefined;
88
90
  return hasStatus && hasCP && hasIndoorBike;
89
91
  }
90
92
  subscribeWriteResponse(cuuid) {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -14,6 +14,7 @@ export default class BleHrmDevice extends BleComms {
14
14
  getProfile(): LegacyProfile;
15
15
  getProtocol(): BleProtocol;
16
16
  getServiceUUids(): string[];
17
+ static isMatching(characteristics: string[]): boolean;
17
18
  parseHrm(_data: Uint8Array): HrmData;
18
19
  onData(characteristic: string, data: Buffer): boolean;
19
20
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const comms_1 = require("../base/comms");
4
+ const consts_1 = require("../consts");
5
+ const utils_1 = require("../utils");
4
6
  class BleHrmDevice extends comms_1.BleComms {
5
7
  constructor(props) {
6
8
  super(props);
@@ -16,6 +18,13 @@ class BleHrmDevice extends comms_1.BleComms {
16
18
  getServiceUUids() {
17
19
  return BleHrmDevice.services;
18
20
  }
21
+ static isMatching(characteristics) {
22
+ if (!characteristics)
23
+ return false;
24
+ const announced = characteristics.map(c => (0, utils_1.uuid)(c));
25
+ const hasHRMeasurement = announced.find(c => c === consts_1.HR_MEASUREMENT) !== undefined;
26
+ return hasHRMeasurement;
27
+ }
19
28
  parseHrm(_data) {
20
29
  const data = Buffer.from(_data);
21
30
  try {
@@ -51,6 +60,6 @@ class BleHrmDevice extends comms_1.BleComms {
51
60
  }
52
61
  BleHrmDevice.protocol = 'hr';
53
62
  BleHrmDevice.services = ['180d'];
54
- BleHrmDevice.characteristics = ['2a37', '2a38', '2a39', '2a3c'];
63
+ BleHrmDevice.characteristics = [consts_1.HR_MEASUREMENT, '2a38', '2a39', '2a3c'];
55
64
  BleHrmDevice.detectionPriority = 1;
56
65
  exports.default = BleHrmDevice;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/lib/ble/index.js CHANGED
File without changes
File without changes
File without changes
@@ -2,7 +2,7 @@ import { BleFmAdapter } from '../fm';
2
2
  import { BleDeviceSettings, BleStartProperties } from '../types';
3
3
  import { DeviceProperties, IAdapter } from '../../types';
4
4
  import { LegacyProfile } from '../../antv2/types';
5
- export default class BleTacxFEAdapter extends BleFmAdapter {
5
+ export default class BleTacxAdapter extends BleFmAdapter {
6
6
  protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
7
7
  constructor(settings: BleDeviceSettings, props?: DeviceProperties);
8
8
  isSame(device: IAdapter): boolean;
@@ -17,7 +17,7 @@ const fm_1 = require("../fm");
17
17
  const comms_1 = __importDefault(require("./comms"));
18
18
  const consts_1 = require("../../base/consts");
19
19
  const types_1 = require("../../types");
20
- class BleTacxFEAdapter extends fm_1.BleFmAdapter {
20
+ class BleTacxAdapter extends fm_1.BleFmAdapter {
21
21
  constructor(settings, props) {
22
22
  super(settings, props);
23
23
  this.logger = new gd_eventlog_1.EventLogger('BLE-FEC-Tacx');
@@ -31,7 +31,7 @@ class BleTacxFEAdapter extends fm_1.BleFmAdapter {
31
31
  ];
32
32
  }
33
33
  isSame(device) {
34
- if (!(device instanceof BleTacxFEAdapter))
34
+ if (!(device instanceof BleTacxAdapter))
35
35
  return false;
36
36
  return this.isEqual(device.settings);
37
37
  }
@@ -102,5 +102,5 @@ class BleTacxFEAdapter extends fm_1.BleFmAdapter {
102
102
  });
103
103
  }
104
104
  }
105
- BleTacxFEAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
106
- exports.default = BleTacxFEAdapter;
105
+ BleTacxAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
106
+ exports.default = BleTacxAdapter;
File without changes
@@ -53,8 +53,9 @@ class TacxAdvancedFitnessMachineDevice extends comms_1.default {
53
53
  static isMatching(characteristics) {
54
54
  if (!characteristics)
55
55
  return false;
56
- const hasTacxCP = characteristics.find(c => (0, utils_1.matches)(c, consts_1.TACX_FE_C_RX)) !== undefined &&
57
- characteristics.find(c => (0, utils_1.matches)(c, consts_1.TACX_FE_C_TX)) !== undefined;
56
+ const announced = characteristics.map(c => (0, utils_1.uuid)(c));
57
+ const hasTacxCP = announced.find(c => (0, utils_1.matches)(c, consts_1.TACX_FE_C_RX)) !== undefined &&
58
+ announced.find(c => (0, utils_1.matches)(c, consts_1.TACX_FE_C_TX)) !== undefined;
58
59
  return hasTacxCP;
59
60
  }
60
61
  setCharacteristicUUIDs(uuids) {
File without changes