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.
- package/lib/antv2/base/interface.js +2 -2
- package/lib/antv2/factories/index.d.ts +1 -0
- package/lib/antv2/factories/index.js +17 -0
- package/lib/antv2/fe/adapter.js +5 -4
- package/lib/antv2/index.d.ts +1 -0
- package/lib/antv2/index.js +12 -8
- package/lib/base/adpater.d.ts +4 -0
- package/lib/base/adpater.js +17 -3
- package/lib/ble/adapter-factory.d.ts +20 -24
- package/lib/ble/adapter-factory.js +13 -36
- package/lib/ble/base/adapter.d.ts +19 -5
- package/lib/ble/base/adapter.js +211 -62
- package/lib/ble/base/comms.d.ts +2 -74
- package/lib/ble/base/comms.js +3 -596
- package/lib/ble/base/interface.d.ts +102 -0
- package/lib/ble/base/interface.js +591 -0
- package/lib/ble/base/peripheral.d.ts +35 -0
- package/lib/ble/base/peripheral.js +311 -0
- package/lib/ble/base/sensor.d.ts +32 -0
- package/lib/ble/base/sensor.js +135 -0
- package/lib/ble/base/types.d.ts +7 -0
- package/lib/ble/base/types.js +7 -0
- package/lib/ble/bindings/mock.js +6 -0
- package/lib/ble/bindings/types.d.ts +3 -4
- package/lib/ble/ble-interface.d.ts +7 -4
- package/lib/ble/ble-interface.js +16 -2
- package/lib/ble/ble-peripheral.d.ts +1 -0
- package/lib/ble/ble-peripheral.js +7 -11
- package/lib/ble/consts.d.ts +0 -6
- package/lib/ble/consts.js +1 -7
- package/lib/ble/cp/adapter.d.ts +3 -3
- package/lib/ble/cp/adapter.js +12 -13
- package/lib/ble/cp/comm.d.ts +1 -1
- package/lib/ble/cp/comm.js +2 -2
- package/lib/ble/cp/index.d.ts +1 -1
- package/lib/ble/cp/index.js +2 -2
- package/lib/ble/cp/sensor.d.ts +27 -0
- package/lib/ble/cp/sensor.js +107 -0
- package/lib/ble/elite/comms.d.ts +1 -1
- package/lib/ble/elite/comms.js +2 -2
- package/lib/ble/factories/adapter-factory.d.ts +34 -0
- package/lib/ble/factories/adapter-factory.js +137 -0
- package/lib/ble/factories/index.d.ts +2 -0
- package/lib/ble/factories/index.js +18 -0
- package/lib/ble/factories/interface-factory.d.ts +7 -0
- package/lib/ble/factories/interface-factory.js +18 -0
- package/lib/ble/factories/types.d.ts +18 -0
- package/lib/ble/factories/types.js +2 -0
- package/lib/ble/fm/adapter.d.ts +12 -6
- package/lib/ble/fm/adapter.js +100 -108
- package/lib/ble/fm/comms.d.ts +1 -1
- package/lib/ble/fm/comms.js +3 -3
- package/lib/ble/fm/consts.d.ts +93 -0
- package/lib/ble/fm/consts.js +55 -1
- package/lib/ble/fm/index.d.ts +1 -1
- package/lib/ble/fm/index.js +2 -2
- package/lib/ble/fm/sensor.d.ts +44 -0
- package/lib/ble/fm/sensor.js +384 -0
- package/lib/ble/hr/adapter.d.ts +3 -3
- package/lib/ble/hr/adapter.js +5 -8
- package/lib/ble/hr/comm.d.ts +1 -1
- package/lib/ble/hr/comm.js +2 -2
- package/lib/ble/hr/index.d.ts +1 -1
- package/lib/ble/hr/index.js +2 -2
- package/lib/ble/hr/sensor.d.ts +17 -0
- package/lib/ble/hr/sensor.js +52 -0
- package/lib/ble/index.d.ts +4 -3
- package/lib/ble/index.js +29 -13
- package/lib/ble/tacx/adapter.d.ts +4 -2
- package/lib/ble/tacx/adapter.js +26 -66
- package/lib/ble/tacx/comms.d.ts +1 -1
- package/lib/ble/tacx/comms.js +2 -2
- package/lib/ble/tacx/consts.d.ts +23 -0
- package/lib/ble/tacx/consts.js +27 -0
- package/lib/ble/tacx/index.d.ts +1 -1
- package/lib/ble/tacx/index.js +2 -2
- package/lib/ble/tacx/sensor.d.ts +63 -0
- package/lib/ble/tacx/sensor.js +596 -0
- package/lib/ble/types.d.ts +87 -52
- package/lib/ble/utils.d.ts +7 -2
- package/lib/ble/utils.js +93 -9
- package/lib/ble/wahoo/adapter.d.ts +2 -2
- package/lib/ble/wahoo/adapter.js +4 -72
- package/lib/ble/wahoo/comms.d.ts +1 -1
- package/lib/ble/wahoo/comms.js +2 -2
- package/lib/ble/wahoo/consts.d.ts +16 -0
- package/lib/ble/wahoo/consts.js +7 -0
- package/lib/ble/wahoo/index.d.ts +1 -1
- package/lib/ble/wahoo/index.js +2 -2
- package/lib/ble/wahoo/sensor.d.ts +48 -0
- package/lib/ble/wahoo/sensor.js +356 -0
- package/lib/direct-connect/base/comms.d.ts +3 -0
- package/lib/direct-connect/base/comms.js +7 -0
- package/lib/direct-connect/base/interface.d.ts +75 -0
- package/lib/direct-connect/base/interface.js +311 -0
- package/lib/direct-connect/base/peripheral.d.ts +50 -0
- package/lib/direct-connect/base/peripheral.js +522 -0
- package/lib/direct-connect/base/sensor.d.ts +3 -0
- package/lib/direct-connect/base/sensor.js +7 -0
- package/lib/direct-connect/bindings/index.d.ts +1 -0
- package/lib/direct-connect/bindings/index.js +17 -0
- package/lib/direct-connect/bindings/types.d.ts +37 -0
- package/lib/direct-connect/bindings/types.js +2 -0
- package/lib/direct-connect/consts.d.ts +17 -0
- package/lib/direct-connect/consts.js +20 -0
- package/lib/direct-connect/index.d.ts +3 -0
- package/lib/direct-connect/index.js +22 -0
- package/lib/direct-connect/messages/CharacteristicNotification.d.ts +12 -0
- package/lib/direct-connect/messages/CharacteristicNotification.js +23 -0
- package/lib/direct-connect/messages/DiscoverCharacteristics.d.ts +22 -0
- package/lib/direct-connect/messages/DiscoverCharacteristics.js +43 -0
- package/lib/direct-connect/messages/DiscoverServices.d.ts +15 -0
- package/lib/direct-connect/messages/DiscoverServices.js +33 -0
- package/lib/direct-connect/messages/EnableCharacteristicNotifications.d.ts +18 -0
- package/lib/direct-connect/messages/EnableCharacteristicNotifications.js +35 -0
- package/lib/direct-connect/messages/ReadCharacteristic.d.ts +18 -0
- package/lib/direct-connect/messages/ReadCharacteristic.js +34 -0
- package/lib/direct-connect/messages/WriteCharacteristic.d.ts +18 -0
- package/lib/direct-connect/messages/WriteCharacteristic.js +36 -0
- package/lib/direct-connect/messages/error.d.ts +5 -0
- package/lib/direct-connect/messages/error.js +18 -0
- package/lib/direct-connect/messages/factory.d.ts +6 -0
- package/lib/direct-connect/messages/factory.js +44 -0
- package/lib/direct-connect/messages/index.d.ts +9 -0
- package/lib/direct-connect/messages/index.js +25 -0
- package/lib/direct-connect/messages/message.d.ts +21 -0
- package/lib/direct-connect/messages/message.js +105 -0
- package/lib/direct-connect/types.d.ts +24 -0
- package/lib/direct-connect/types.js +9 -0
- package/lib/direct-connect/utils.d.ts +5 -0
- package/lib/direct-connect/utils.js +73 -0
- package/lib/factories/adapters.js +14 -4
- package/lib/factories/interfaces.d.ts +2 -1
- package/lib/factories/interfaces.js +10 -7
- package/lib/index.d.ts +5 -4
- package/lib/index.js +6 -2
- package/lib/modes/antble-smarttrainer.d.ts +2 -16
- package/lib/modes/antble-smarttrainer.js +1 -98
- package/lib/modes/types.d.ts +1 -5
- package/lib/serial/bindings/tcp.d.ts +5 -4
- package/lib/serial/bindings/tcp.js +16 -23
- package/lib/types/adapter.d.ts +3 -0
- package/lib/types/device.d.ts +2 -1
- package/lib/types/device.js +1 -0
- package/lib/utils/calculations.d.ts +0 -1
- package/lib/utils/calculations.js +6 -22
- package/lib/utils/operation.d.ts +17 -0
- package/lib/utils/operation.js +20 -0
- package/lib/utils/task.d.ts +47 -0
- package/lib/utils/task.js +139 -0
- 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.
|
|
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",
|