incyclist-devices 2.2.10-beta.0 → 2.3.0-beta.10

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 (151) hide show
  1. package/lib/antv2/base/interface.js +2 -2
  2. package/lib/antv2/factories/index.d.ts +1 -0
  3. package/lib/antv2/factories/index.js +17 -0
  4. package/lib/antv2/fe/adapter.js +5 -4
  5. package/lib/antv2/index.d.ts +1 -0
  6. package/lib/antv2/index.js +12 -8
  7. package/lib/base/adpater.d.ts +4 -0
  8. package/lib/base/adpater.js +17 -3
  9. package/lib/ble/adapter-factory.d.ts +20 -24
  10. package/lib/ble/adapter-factory.js +13 -36
  11. package/lib/ble/base/adapter.d.ts +19 -5
  12. package/lib/ble/base/adapter.js +211 -62
  13. package/lib/ble/base/comms.d.ts +2 -74
  14. package/lib/ble/base/comms.js +3 -596
  15. package/lib/ble/base/interface.d.ts +102 -0
  16. package/lib/ble/base/interface.js +591 -0
  17. package/lib/ble/base/peripheral.d.ts +35 -0
  18. package/lib/ble/base/peripheral.js +311 -0
  19. package/lib/ble/base/sensor.d.ts +32 -0
  20. package/lib/ble/base/sensor.js +135 -0
  21. package/lib/ble/base/types.d.ts +7 -0
  22. package/lib/ble/base/types.js +7 -0
  23. package/lib/ble/bindings/mock.js +6 -0
  24. package/lib/ble/bindings/types.d.ts +3 -4
  25. package/lib/ble/ble-interface.d.ts +7 -4
  26. package/lib/ble/ble-interface.js +16 -2
  27. package/lib/ble/ble-peripheral.d.ts +1 -0
  28. package/lib/ble/ble-peripheral.js +7 -11
  29. package/lib/ble/consts.d.ts +0 -6
  30. package/lib/ble/consts.js +1 -7
  31. package/lib/ble/cp/adapter.d.ts +3 -3
  32. package/lib/ble/cp/adapter.js +12 -13
  33. package/lib/ble/cp/comm.d.ts +1 -1
  34. package/lib/ble/cp/comm.js +2 -2
  35. package/lib/ble/cp/index.d.ts +1 -1
  36. package/lib/ble/cp/index.js +2 -2
  37. package/lib/ble/cp/sensor.d.ts +27 -0
  38. package/lib/ble/cp/sensor.js +107 -0
  39. package/lib/ble/elite/comms.d.ts +1 -1
  40. package/lib/ble/elite/comms.js +2 -2
  41. package/lib/ble/factories/adapter-factory.d.ts +34 -0
  42. package/lib/ble/factories/adapter-factory.js +137 -0
  43. package/lib/ble/factories/index.d.ts +2 -0
  44. package/lib/ble/factories/index.js +18 -0
  45. package/lib/ble/factories/interface-factory.d.ts +7 -0
  46. package/lib/ble/factories/interface-factory.js +18 -0
  47. package/lib/ble/factories/types.d.ts +18 -0
  48. package/lib/ble/factories/types.js +2 -0
  49. package/lib/ble/fm/adapter.d.ts +12 -6
  50. package/lib/ble/fm/adapter.js +100 -108
  51. package/lib/ble/fm/comms.d.ts +1 -1
  52. package/lib/ble/fm/comms.js +3 -3
  53. package/lib/ble/fm/consts.d.ts +93 -0
  54. package/lib/ble/fm/consts.js +55 -1
  55. package/lib/ble/fm/index.d.ts +1 -1
  56. package/lib/ble/fm/index.js +2 -2
  57. package/lib/ble/fm/sensor.d.ts +44 -0
  58. package/lib/ble/fm/sensor.js +384 -0
  59. package/lib/ble/hr/adapter.d.ts +3 -3
  60. package/lib/ble/hr/adapter.js +5 -8
  61. package/lib/ble/hr/comm.d.ts +1 -1
  62. package/lib/ble/hr/comm.js +2 -2
  63. package/lib/ble/hr/index.d.ts +1 -1
  64. package/lib/ble/hr/index.js +2 -2
  65. package/lib/ble/hr/sensor.d.ts +17 -0
  66. package/lib/ble/hr/sensor.js +52 -0
  67. package/lib/ble/index.d.ts +4 -3
  68. package/lib/ble/index.js +29 -13
  69. package/lib/ble/tacx/adapter.d.ts +4 -2
  70. package/lib/ble/tacx/adapter.js +26 -66
  71. package/lib/ble/tacx/comms.d.ts +1 -1
  72. package/lib/ble/tacx/comms.js +2 -2
  73. package/lib/ble/tacx/consts.d.ts +23 -0
  74. package/lib/ble/tacx/consts.js +27 -0
  75. package/lib/ble/tacx/index.d.ts +1 -1
  76. package/lib/ble/tacx/index.js +2 -2
  77. package/lib/ble/tacx/sensor.d.ts +63 -0
  78. package/lib/ble/tacx/sensor.js +596 -0
  79. package/lib/ble/types.d.ts +87 -52
  80. package/lib/ble/utils.d.ts +7 -2
  81. package/lib/ble/utils.js +93 -9
  82. package/lib/ble/wahoo/adapter.d.ts +2 -2
  83. package/lib/ble/wahoo/adapter.js +4 -72
  84. package/lib/ble/wahoo/comms.d.ts +1 -1
  85. package/lib/ble/wahoo/comms.js +2 -2
  86. package/lib/ble/wahoo/consts.d.ts +16 -0
  87. package/lib/ble/wahoo/consts.js +7 -0
  88. package/lib/ble/wahoo/index.d.ts +1 -1
  89. package/lib/ble/wahoo/index.js +2 -2
  90. package/lib/ble/wahoo/sensor.d.ts +48 -0
  91. package/lib/ble/wahoo/sensor.js +356 -0
  92. package/lib/direct-connect/base/comms.d.ts +3 -0
  93. package/lib/direct-connect/base/comms.js +7 -0
  94. package/lib/direct-connect/base/interface.d.ts +75 -0
  95. package/lib/direct-connect/base/interface.js +311 -0
  96. package/lib/direct-connect/base/peripheral.d.ts +50 -0
  97. package/lib/direct-connect/base/peripheral.js +522 -0
  98. package/lib/direct-connect/base/sensor.d.ts +3 -0
  99. package/lib/direct-connect/base/sensor.js +7 -0
  100. package/lib/direct-connect/bindings/index.d.ts +1 -0
  101. package/lib/direct-connect/bindings/index.js +17 -0
  102. package/lib/direct-connect/bindings/types.d.ts +37 -0
  103. package/lib/direct-connect/bindings/types.js +2 -0
  104. package/lib/direct-connect/consts.d.ts +17 -0
  105. package/lib/direct-connect/consts.js +20 -0
  106. package/lib/direct-connect/index.d.ts +3 -0
  107. package/lib/direct-connect/index.js +22 -0
  108. package/lib/direct-connect/messages/CharacteristicNotification.d.ts +12 -0
  109. package/lib/direct-connect/messages/CharacteristicNotification.js +23 -0
  110. package/lib/direct-connect/messages/DiscoverCharacteristics.d.ts +22 -0
  111. package/lib/direct-connect/messages/DiscoverCharacteristics.js +43 -0
  112. package/lib/direct-connect/messages/DiscoverServices.d.ts +15 -0
  113. package/lib/direct-connect/messages/DiscoverServices.js +33 -0
  114. package/lib/direct-connect/messages/EnableCharacteristicNotifications.d.ts +18 -0
  115. package/lib/direct-connect/messages/EnableCharacteristicNotifications.js +35 -0
  116. package/lib/direct-connect/messages/ReadCharacteristic.d.ts +18 -0
  117. package/lib/direct-connect/messages/ReadCharacteristic.js +34 -0
  118. package/lib/direct-connect/messages/WriteCharacteristic.d.ts +18 -0
  119. package/lib/direct-connect/messages/WriteCharacteristic.js +36 -0
  120. package/lib/direct-connect/messages/error.d.ts +5 -0
  121. package/lib/direct-connect/messages/error.js +18 -0
  122. package/lib/direct-connect/messages/factory.d.ts +6 -0
  123. package/lib/direct-connect/messages/factory.js +44 -0
  124. package/lib/direct-connect/messages/index.d.ts +9 -0
  125. package/lib/direct-connect/messages/index.js +25 -0
  126. package/lib/direct-connect/messages/message.d.ts +21 -0
  127. package/lib/direct-connect/messages/message.js +105 -0
  128. package/lib/direct-connect/types.d.ts +24 -0
  129. package/lib/direct-connect/types.js +9 -0
  130. package/lib/direct-connect/utils.d.ts +5 -0
  131. package/lib/direct-connect/utils.js +73 -0
  132. package/lib/factories/adapters.js +14 -4
  133. package/lib/factories/interfaces.d.ts +2 -1
  134. package/lib/factories/interfaces.js +10 -7
  135. package/lib/index.d.ts +5 -4
  136. package/lib/index.js +6 -2
  137. package/lib/modes/antble-smarttrainer.d.ts +2 -16
  138. package/lib/modes/antble-smarttrainer.js +1 -98
  139. package/lib/modes/types.d.ts +1 -5
  140. package/lib/serial/bindings/tcp.d.ts +5 -4
  141. package/lib/serial/bindings/tcp.js +16 -23
  142. package/lib/types/adapter.d.ts +3 -0
  143. package/lib/types/device.d.ts +2 -1
  144. package/lib/types/device.js +1 -0
  145. package/lib/utils/calculations.d.ts +0 -1
  146. package/lib/utils/calculations.js +6 -22
  147. package/lib/utils/operation.d.ts +17 -0
  148. package/lib/utils/operation.js +20 -0
  149. package/lib/utils/task.d.ts +47 -0
  150. package/lib/utils/task.js +139 -0
  151. package/package.json +3 -1
@@ -0,0 +1,139 @@
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.InteruptableTask = void 0;
16
+ const events_1 = __importDefault(require("events"));
17
+ const utils_1 = require("./utils");
18
+ class InteruptableTask {
19
+ constructor(promise, props) {
20
+ var _a;
21
+ this.internalState = { isRunning: false };
22
+ this.internalEvents = new events_1.default();
23
+ this.onStopNotifiers = [];
24
+ this.state = ((_a = props === null || props === void 0 ? void 0 : props.state) !== null && _a !== void 0 ? _a : {});
25
+ this.props = props;
26
+ delete this.props.state;
27
+ this.promise = promise;
28
+ this.start();
29
+ }
30
+ getPromise() {
31
+ return this.internalState.promise;
32
+ }
33
+ getState() {
34
+ return this.state;
35
+ }
36
+ run() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ if (!this.internalState.isRunning)
39
+ yield (0, utils_1.resolveNextTick)();
40
+ return this.internalState.promise;
41
+ });
42
+ }
43
+ notifyOnStop(cb) {
44
+ this.onStopNotifiers.push(cb);
45
+ }
46
+ start() {
47
+ this.internalState.promise = new Promise((resolve, reject) => {
48
+ var _a;
49
+ this.internalState.isRunning = true;
50
+ this.internalState.onDone = resolve;
51
+ this.internalState.onError = reject;
52
+ this.internalState.tsStart = Date.now();
53
+ const { timeout } = this.props;
54
+ if (timeout) {
55
+ this.internalState.tsTimeout = this.internalState.tsStart + timeout;
56
+ this.internalState.onTimeout = this.onTimeout.bind(this);
57
+ this.internalState.timeout = setTimeout(() => { this.internalEvents.emit('timeout'); }, timeout);
58
+ this.internalEvents.on('timeout', this.internalState.onTimeout);
59
+ }
60
+ this.internalEvents.once('stopped', () => {
61
+ this.clearTimeout();
62
+ this.internalState = {
63
+ isRunning: false,
64
+ };
65
+ this.internalEvents.removeAllListeners();
66
+ this.sendStopNotification();
67
+ if (this.getState().result === 'completed' || this.getState().result === 'error')
68
+ return;
69
+ this.getState().result = 'stopped';
70
+ if (this.props.onDone)
71
+ resolve(this.props.onDone(this.getState()));
72
+ else
73
+ resolve(null);
74
+ });
75
+ (_a = this.promise) === null || _a === void 0 ? void 0 : _a.then((res) => {
76
+ this.clearTimeout();
77
+ this.internalState = {
78
+ isRunning: false,
79
+ };
80
+ this.getState().result = 'completed';
81
+ this.internalEvents.emit('stopped');
82
+ resolve(res);
83
+ }).catch((err) => {
84
+ this.getState().result = 'error';
85
+ this.getState().error = err;
86
+ this.internalEvents.emit('stopped');
87
+ reject(err);
88
+ });
89
+ });
90
+ }
91
+ stop() {
92
+ return new Promise((resolve) => {
93
+ this.internalEvents.emit('stopped');
94
+ (0, utils_1.resolveNextTick)().then(() => {
95
+ resolve(true);
96
+ });
97
+ });
98
+ }
99
+ isRunning() {
100
+ return this.internalState.isRunning === true;
101
+ }
102
+ clearTimeout() {
103
+ if (this.internalState.timeout) {
104
+ clearTimeout(this.internalState.timeout);
105
+ this.internalEvents.off('timeout', this.internalState.onTimeout);
106
+ }
107
+ delete this.internalState.timeout;
108
+ }
109
+ onTimeout() {
110
+ var _a;
111
+ if (!this.internalState.timeout)
112
+ return;
113
+ const message = this.props.name ? `${this.props.name} timeout` : 'timeout';
114
+ this.logEvent({ message, active: this.isRunning() });
115
+ this.clearTimeout();
116
+ this.getState().result = 'timeout';
117
+ const resolve = this.internalState.onDone;
118
+ const reject = this.internalState.onError;
119
+ this.internalState = { isRunning: false };
120
+ if ((_a = this.props.errorOnTimeout) !== null && _a !== void 0 ? _a : true) {
121
+ reject(new Error('timeout'));
122
+ }
123
+ if (this.props.onDone)
124
+ resolve(this.props.onDone(this.getState()));
125
+ else
126
+ resolve(null);
127
+ }
128
+ sendStopNotification() {
129
+ this.onStopNotifiers.forEach((cb) => {
130
+ if (typeof cb === 'function')
131
+ cb();
132
+ });
133
+ }
134
+ logEvent(event) {
135
+ if (this.props.log)
136
+ this.props.log(event);
137
+ }
138
+ }
139
+ exports.InteruptableTask = InteruptableTask;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.2.10-beta.0",
3
+ "version": "2.3.0-beta.10",
4
4
  "dependencies": {
5
5
  "@serialport/bindings-interface": "^1.2.2",
6
6
  "@serialport/parser-byte-length": "^9.0.1",
@@ -16,8 +16,10 @@
16
16
  "devDependencies": {
17
17
  "@serialport/binding-mock": "^10.2.2",
18
18
  "@serialport/bindings-cpp": "^10.8.0",
19
+ "@stoprocent/noble": "^1.15.2",
19
20
  "@types/jest": "^29.5.12",
20
21
  "@types/node": "^22.5.0",
22
+ "bonjour-service": "^1.3.0",
21
23
  "eslint": "^8.47.0",
22
24
  "eslint-config-react-app": "^7.0.1",
23
25
  "jest": "^29.7.0",