incyclist-devices 2.1.7 → 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.
- package/LICENSE +0 -0
- package/README.MD +238 -238
- package/lib/antv2/base/adapter.d.ts +0 -0
- package/lib/antv2/base/adapter.js +0 -0
- package/lib/antv2/base/binding.d.ts +0 -0
- package/lib/antv2/base/binding.js +0 -0
- package/lib/antv2/base/interface.d.ts +0 -0
- package/lib/antv2/base/interface.js +9 -5
- package/lib/antv2/cad/adapter.d.ts +0 -0
- package/lib/antv2/cad/adapter.js +0 -0
- package/lib/antv2/cad/index.d.ts +0 -0
- package/lib/antv2/cad/index.js +0 -0
- package/lib/antv2/consts.d.ts +0 -0
- package/lib/antv2/consts.js +0 -0
- package/lib/antv2/factories/adapter-factory.d.ts +0 -0
- package/lib/antv2/factories/adapter-factory.js +0 -0
- package/lib/antv2/factories/sensor-factory.d.ts +0 -0
- package/lib/antv2/factories/sensor-factory.js +0 -0
- package/lib/antv2/fe/adapter.d.ts +0 -0
- package/lib/antv2/fe/adapter.js +0 -0
- package/lib/antv2/fe/index.d.ts +0 -0
- package/lib/antv2/fe/index.js +0 -0
- package/lib/antv2/hr/adapter.d.ts +0 -0
- package/lib/antv2/hr/adapter.js +0 -0
- package/lib/antv2/hr/index.d.ts +0 -0
- package/lib/antv2/hr/index.js +0 -0
- package/lib/antv2/index.d.ts +0 -0
- package/lib/antv2/index.js +0 -0
- package/lib/antv2/pwr/adapter.d.ts +0 -0
- package/lib/antv2/pwr/adapter.js +0 -0
- package/lib/antv2/pwr/index.d.ts +0 -0
- package/lib/antv2/pwr/index.js +0 -0
- package/lib/antv2/types.d.ts +0 -0
- package/lib/antv2/types.js +0 -0
- package/lib/antv2/utils.d.ts +0 -0
- package/lib/antv2/utils.js +0 -0
- package/lib/base/adpater.d.ts +0 -0
- package/lib/base/adpater.js +0 -0
- package/lib/base/consts.d.ts +0 -0
- package/lib/base/consts.js +0 -0
- package/lib/ble/adapter-factory.d.ts +0 -0
- package/lib/ble/adapter-factory.js +0 -0
- package/lib/ble/base/adapter.d.ts +3 -1
- package/lib/ble/base/adapter.js +27 -9
- package/lib/ble/base/comms-utils.d.ts +0 -0
- package/lib/ble/base/comms-utils.js +0 -0
- package/lib/ble/base/comms.d.ts +0 -0
- package/lib/ble/base/comms.js +0 -0
- package/lib/ble/base/types.d.ts +0 -0
- package/lib/ble/base/types.js +0 -0
- package/lib/ble/bindings/index.d.ts +0 -0
- package/lib/ble/bindings/index.js +0 -0
- package/lib/ble/bindings/linux.d.ts +1 -0
- package/lib/ble/bindings/linux.js +2 -0
- package/lib/ble/bindings/mock.d.ts +0 -0
- package/lib/ble/bindings/mock.js +2 -0
- package/lib/ble/bindings/types.d.ts +0 -0
- package/lib/ble/bindings/types.js +0 -0
- package/lib/ble/ble-interface.d.ts +11 -9
- package/lib/ble/ble-interface.js +74 -56
- package/lib/ble/ble-peripheral.d.ts +0 -0
- package/lib/ble/ble-peripheral.js +0 -0
- package/lib/ble/consts.d.ts +0 -0
- package/lib/ble/consts.js +0 -0
- package/lib/ble/cp/adapter.d.ts +0 -0
- package/lib/ble/cp/adapter.js +0 -0
- package/lib/ble/cp/comm.d.ts +0 -0
- package/lib/ble/cp/comm.js +3 -2
- package/lib/ble/cp/index.d.ts +0 -0
- package/lib/ble/cp/index.js +0 -0
- package/lib/ble/cp/types.d.ts +0 -0
- package/lib/ble/cp/types.js +0 -0
- package/lib/ble/elite/adapter.d.ts +0 -0
- package/lib/ble/elite/adapter.js +0 -0
- package/lib/ble/elite/comms.d.ts +0 -0
- package/lib/ble/elite/comms.js +3 -2
- package/lib/ble/elite/index.d.ts +0 -0
- package/lib/ble/elite/index.js +0 -0
- package/lib/ble/fm/adapter.d.ts +0 -0
- package/lib/ble/fm/adapter.js +0 -0
- package/lib/ble/fm/comms.d.ts +0 -0
- package/lib/ble/fm/comms.js +5 -3
- package/lib/ble/fm/consts.d.ts +0 -0
- package/lib/ble/fm/consts.js +0 -0
- package/lib/ble/fm/index.d.ts +0 -0
- package/lib/ble/fm/index.js +0 -0
- package/lib/ble/fm/types.d.ts +0 -0
- package/lib/ble/fm/types.js +0 -0
- package/lib/ble/hr/adapter.d.ts +0 -0
- package/lib/ble/hr/adapter.js +0 -0
- package/lib/ble/hr/comm.d.ts +1 -0
- package/lib/ble/hr/comm.js +10 -1
- package/lib/ble/hr/index.d.ts +0 -0
- package/lib/ble/hr/index.js +0 -0
- package/lib/ble/hr/mock.d.ts +0 -0
- package/lib/ble/hr/mock.js +0 -0
- package/lib/ble/hr/types.d.ts +0 -0
- package/lib/ble/hr/types.js +0 -0
- package/lib/ble/index.d.ts +0 -0
- package/lib/ble/index.js +0 -0
- package/lib/ble/peripheral-cache.d.ts +0 -0
- package/lib/ble/peripheral-cache.js +0 -0
- package/lib/ble/tacx/adapter.d.ts +1 -1
- package/lib/ble/tacx/adapter.js +4 -4
- package/lib/ble/tacx/comms.d.ts +0 -0
- package/lib/ble/tacx/comms.js +3 -2
- package/lib/ble/tacx/index.d.ts +0 -0
- package/lib/ble/tacx/index.js +0 -0
- package/lib/ble/tacx/types.d.ts +0 -0
- package/lib/ble/tacx/types.js +0 -0
- package/lib/ble/types.d.ts +1 -0
- package/lib/ble/types.js +0 -0
- package/lib/ble/utils.d.ts +0 -0
- package/lib/ble/utils.js +0 -0
- package/lib/ble/wahoo/adapter.d.ts +0 -0
- package/lib/ble/wahoo/adapter.js +0 -0
- package/lib/ble/wahoo/comms.d.ts +0 -0
- package/lib/ble/wahoo/comms.js +3 -2
- package/lib/ble/wahoo/index.d.ts +0 -0
- package/lib/ble/wahoo/index.js +0 -0
- package/lib/ble/wahoo/types.d.ts +0 -0
- package/lib/ble/wahoo/types.js +0 -0
- package/lib/factories/adapters.d.ts +0 -0
- package/lib/factories/adapters.js +0 -0
- package/lib/factories/index.d.ts +0 -0
- package/lib/factories/index.js +0 -0
- package/lib/factories/interfaces.d.ts +0 -0
- package/lib/factories/interfaces.js +0 -0
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/modes/ant-fe-adv-st-mode.d.ts +0 -0
- package/lib/modes/ant-fe-adv-st-mode.js +0 -0
- package/lib/modes/antble-erg.d.ts +0 -0
- package/lib/modes/antble-erg.js +0 -0
- package/lib/modes/antble-smarttrainer.d.ts +0 -0
- package/lib/modes/antble-smarttrainer.js +0 -0
- package/lib/modes/base.d.ts +0 -0
- package/lib/modes/base.js +0 -0
- package/lib/modes/daum-classic-standard.d.ts +0 -0
- package/lib/modes/daum-classic-standard.js +0 -0
- package/lib/modes/daum-erg.d.ts +0 -0
- package/lib/modes/daum-erg.js +0 -0
- package/lib/modes/daum-power.d.ts +0 -0
- package/lib/modes/daum-power.js +0 -0
- package/lib/modes/daum-premium-standard.d.ts +0 -0
- package/lib/modes/daum-premium-standard.js +0 -0
- package/lib/modes/daum-smarttrainer.d.ts +0 -0
- package/lib/modes/daum-smarttrainer.js +0 -0
- package/lib/modes/kettler-erg.d.ts +0 -0
- package/lib/modes/kettler-erg.js +0 -0
- package/lib/modes/power-base.d.ts +0 -0
- package/lib/modes/power-base.js +0 -0
- package/lib/modes/power-meter.d.ts +0 -0
- package/lib/modes/power-meter.js +0 -0
- package/lib/modes/simulator.d.ts +0 -0
- package/lib/modes/simulator.js +0 -0
- package/lib/modes/types.d.ts +0 -0
- package/lib/modes/types.js +0 -0
- package/lib/serial/base/adapter.d.ts +0 -0
- package/lib/serial/base/adapter.js +0 -0
- package/lib/serial/base/comms.d.ts +0 -0
- package/lib/serial/base/comms.js +0 -0
- package/lib/serial/base/serial-interface.d.ts +0 -0
- package/lib/serial/base/serial-interface.js +0 -0
- package/lib/serial/base/serial-scanner.d.ts +0 -0
- package/lib/serial/base/serial-scanner.js +0 -0
- package/lib/serial/base/serialport.d.ts +0 -0
- package/lib/serial/base/serialport.js +0 -0
- package/lib/serial/bindings/tcp.d.ts +0 -0
- package/lib/serial/bindings/tcp.js +0 -0
- package/lib/serial/daum/DaumAdapter.d.ts +0 -0
- package/lib/serial/daum/DaumAdapter.js +0 -0
- package/lib/serial/daum/classic/adapter.d.ts +0 -0
- package/lib/serial/daum/classic/adapter.js +0 -0
- package/lib/serial/daum/classic/comms.d.ts +0 -0
- package/lib/serial/daum/classic/comms.js +0 -0
- package/lib/serial/daum/classic/consts.d.ts +0 -0
- package/lib/serial/daum/classic/consts.js +0 -0
- package/lib/serial/daum/classic/mock.d.ts +0 -0
- package/lib/serial/daum/classic/mock.js +0 -0
- package/lib/serial/daum/classic/types.d.ts +0 -0
- package/lib/serial/daum/classic/types.js +0 -0
- package/lib/serial/daum/classic/utils.d.ts +0 -0
- package/lib/serial/daum/classic/utils.js +0 -0
- package/lib/serial/daum/premium/adapter.d.ts +0 -0
- package/lib/serial/daum/premium/adapter.js +0 -0
- package/lib/serial/daum/premium/comms.d.ts +0 -0
- package/lib/serial/daum/premium/comms.js +0 -0
- package/lib/serial/daum/premium/consts.d.ts +0 -0
- package/lib/serial/daum/premium/consts.js +0 -0
- package/lib/serial/daum/premium/mock.d.ts +0 -0
- package/lib/serial/daum/premium/mock.js +0 -0
- package/lib/serial/daum/premium/types.d.ts +0 -0
- package/lib/serial/daum/premium/types.js +0 -0
- package/lib/serial/daum/premium/utils.d.ts +0 -0
- package/lib/serial/daum/premium/utils.js +0 -0
- package/lib/serial/daum/types.d.ts +0 -0
- package/lib/serial/daum/types.js +0 -0
- package/lib/serial/factories/adapter-factory.d.ts +0 -0
- package/lib/serial/factories/adapter-factory.js +0 -0
- package/lib/serial/index.d.ts +0 -0
- package/lib/serial/index.js +0 -0
- package/lib/serial/kettler/comms.d.ts +0 -0
- package/lib/serial/kettler/comms.js +0 -0
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +0 -0
- package/lib/serial/kettler/ergo-racer/adapter.js +0 -0
- package/lib/serial/kettler/ergo-racer/mock.d.ts +0 -0
- package/lib/serial/kettler/ergo-racer/mock.js +0 -0
- package/lib/serial/kettler/types.d.ts +0 -0
- package/lib/serial/kettler/types.js +0 -0
- package/lib/serial/types.d.ts +0 -0
- package/lib/serial/types.js +0 -0
- package/lib/simulator/Simulator.d.ts +0 -0
- package/lib/simulator/Simulator.js +0 -0
- package/lib/types/adapter.d.ts +0 -0
- package/lib/types/adapter.js +0 -0
- package/lib/types/capabilities.d.ts +0 -0
- package/lib/types/capabilities.js +0 -0
- package/lib/types/data.d.ts +0 -0
- package/lib/types/data.js +0 -0
- package/lib/types/device.d.ts +0 -0
- package/lib/types/device.js +0 -0
- package/lib/types/index.d.ts +0 -0
- package/lib/types/index.js +0 -0
- package/lib/types/interface.d.ts +0 -0
- package/lib/types/interface.js +0 -0
- package/lib/types/user.d.ts +0 -0
- package/lib/types/user.js +0 -0
- package/lib/utils/calculations.d.ts +0 -0
- package/lib/utils/calculations.js +0 -0
- package/lib/utils/utils.d.ts +0 -0
- package/lib/utils/utils.js +0 -0
- package/package.json +51 -51
- package/lib/adapters.d.ts +0 -7
- package/lib/adapters.js +0 -49
- package/lib/antv2/adapter-factory.d.ts +0 -14
- package/lib/antv2/adapter-factory.js +0 -65
- package/lib/antv2/adapter.d.ts +0 -54
- package/lib/antv2/adapter.js +0 -291
- package/lib/antv2/ant-interface.d.ts +0 -35
- package/lib/antv2/ant-interface.js +0 -285
- package/lib/antv2/base/ant-interface.d.ts +0 -35
- package/lib/antv2/base/ant-interface.js +0 -285
- package/lib/antv2/binding.d.ts +0 -13
- package/lib/antv2/binding.js +0 -27
- package/lib/antv2/hr copy/adapter.d.ts +0 -11
- package/lib/antv2/hr copy/adapter.js +0 -30
- package/lib/antv2/hr copy/index.d.ts +0 -2
- package/lib/antv2/hr copy/index.js +0 -7
- package/lib/antv2/sensor-factory.d.ts +0 -5
- package/lib/antv2/sensor-factory.js +0 -20
- package/lib/interfaces.d.ts +0 -7
- package/lib/interfaces.js +0 -27
- package/lib/serial/SinglePathScanner.d.ts +0 -17
- package/lib/serial/SinglePathScanner.js +0 -87
- package/lib/serial/adapter-factory.d.ts +0 -14
- package/lib/serial/adapter-factory.js +0 -30
- package/lib/serial/adapter.d.ts +0 -17
- package/lib/serial/adapter.js +0 -67
- package/lib/serial/comm.d.ts +0 -7
- package/lib/serial/comm.js +0 -2
- package/lib/serial/comms.d.ts +0 -62
- package/lib/serial/comms.js +0 -280
- package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +0 -2
- package/lib/serial/daum/classic/PROTOCOL_NAME.js +0 -5
- package/lib/serial/daum/consts.d.ts +0 -0
- package/lib/serial/daum/consts.js +0 -0
- package/lib/serial/serial-interface.d.ts +0 -36
- package/lib/serial/serial-interface.js +0 -288
- package/lib/serial/serial-scanner.d.ts +0 -16
- package/lib/serial/serial-scanner.js +0 -87
- package/lib/serial/serialport.d.ts +0 -17
- package/lib/serial/serialport.js +0 -87
- package/lib/types/Command.d.ts +0 -8
- package/lib/types/Command.js +0 -2
- package/lib/types/command.d.ts +0 -0
- package/lib/types/command.js +0 -0
- package/lib/types/route.d.ts +0 -0
- package/lib/types/route.js +0 -0
- package/lib/types/types.d.ts +0 -8
- package/lib/types/types.js +0 -2
package/lib/ble/base/adapter.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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',
|
|
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: '
|
|
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
|
package/lib/ble/base/comms.d.ts
CHANGED
|
File without changes
|
package/lib/ble/base/comms.js
CHANGED
|
File without changes
|
package/lib/ble/base/types.d.ts
CHANGED
|
File without changes
|
package/lib/ble/base/types.js
CHANGED
|
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;
|
|
File without changes
|
package/lib/ble/bindings/mock.js
CHANGED
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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;
|
package/lib/ble/ble-interface.js
CHANGED
|
@@ -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.
|
|
81
|
-
|
|
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
|
-
|
|
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
|
-
|
|
472
|
-
|
|
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 =
|
|
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
|
|
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
|
|
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
|
-
|
|
515
|
+
if (wasTimeout)
|
|
516
|
+
this.logEvent({ message: `${opStr} result: timeout, devices found`, requested, devices });
|
|
498
517
|
ble.removeAllListeners('discover');
|
|
499
|
-
|
|
500
|
-
|
|
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
|
-
|
|
511
|
-
|
|
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
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
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
|
|
584
|
+
this.logEvent({ message: 'stopping scan done ..' });
|
|
567
585
|
return true;
|
|
568
586
|
});
|
|
569
587
|
}
|
|
File without changes
|
|
File without changes
|
package/lib/ble/consts.d.ts
CHANGED
|
File without changes
|
package/lib/ble/consts.js
CHANGED
|
File without changes
|
package/lib/ble/cp/adapter.d.ts
CHANGED
|
File without changes
|
package/lib/ble/cp/adapter.js
CHANGED
|
File without changes
|
package/lib/ble/cp/comm.d.ts
CHANGED
|
File without changes
|
package/lib/ble/cp/comm.js
CHANGED
|
@@ -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
|
|
22
|
-
const
|
|
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() {
|
package/lib/ble/cp/index.d.ts
CHANGED
|
File without changes
|
package/lib/ble/cp/index.js
CHANGED
|
File without changes
|
package/lib/ble/cp/types.d.ts
CHANGED
|
File without changes
|
package/lib/ble/cp/types.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/ble/elite/adapter.js
CHANGED
|
File without changes
|
package/lib/ble/elite/comms.d.ts
CHANGED
|
File without changes
|
package/lib/ble/elite/comms.js
CHANGED
|
@@ -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
|
|
23
|
-
const
|
|
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() {
|
package/lib/ble/elite/index.d.ts
CHANGED
|
File without changes
|
package/lib/ble/elite/index.js
CHANGED
|
File without changes
|
package/lib/ble/fm/adapter.d.ts
CHANGED
|
File without changes
|
package/lib/ble/fm/adapter.js
CHANGED
|
File without changes
|
package/lib/ble/fm/comms.d.ts
CHANGED
|
File without changes
|
package/lib/ble/fm/comms.js
CHANGED
|
@@ -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
|
|
86
|
-
const
|
|
87
|
-
const
|
|
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) {
|
package/lib/ble/fm/consts.d.ts
CHANGED
|
File without changes
|
package/lib/ble/fm/consts.js
CHANGED
|
File without changes
|
package/lib/ble/fm/index.d.ts
CHANGED
|
File without changes
|
package/lib/ble/fm/index.js
CHANGED
|
File without changes
|
package/lib/ble/fm/types.d.ts
CHANGED
|
File without changes
|
package/lib/ble/fm/types.js
CHANGED
|
File without changes
|
package/lib/ble/hr/adapter.d.ts
CHANGED
|
File without changes
|
package/lib/ble/hr/adapter.js
CHANGED
|
File without changes
|
package/lib/ble/hr/comm.d.ts
CHANGED
|
@@ -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
|
}
|
package/lib/ble/hr/comm.js
CHANGED
|
@@ -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 = [
|
|
63
|
+
BleHrmDevice.characteristics = [consts_1.HR_MEASUREMENT, '2a38', '2a39', '2a3c'];
|
|
55
64
|
BleHrmDevice.detectionPriority = 1;
|
|
56
65
|
exports.default = BleHrmDevice;
|
package/lib/ble/hr/index.d.ts
CHANGED
|
File without changes
|
package/lib/ble/hr/index.js
CHANGED
|
File without changes
|
package/lib/ble/hr/mock.d.ts
CHANGED
|
File without changes
|
package/lib/ble/hr/mock.js
CHANGED
|
File without changes
|
package/lib/ble/hr/types.d.ts
CHANGED
|
File without changes
|
package/lib/ble/hr/types.js
CHANGED
|
File without changes
|
package/lib/ble/index.d.ts
CHANGED
|
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
|
|
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;
|
package/lib/ble/tacx/adapter.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
106
|
-
exports.default =
|
|
105
|
+
BleTacxAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
|
|
106
|
+
exports.default = BleTacxAdapter;
|
package/lib/ble/tacx/comms.d.ts
CHANGED
|
File without changes
|
package/lib/ble/tacx/comms.js
CHANGED
|
@@ -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
|
|
57
|
-
|
|
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) {
|
package/lib/ble/tacx/index.d.ts
CHANGED
|
File without changes
|