incyclist-devices 2.1.15 → 2.1.18
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/adapters.d.ts +7 -0
- package/lib/adapters.js +49 -0
- package/lib/antv2/adapter-factory.d.ts +14 -0
- package/lib/antv2/adapter-factory.js +65 -0
- package/lib/antv2/adapter.d.ts +54 -0
- package/lib/antv2/adapter.js +291 -0
- package/lib/antv2/ant-interface.d.ts +35 -0
- package/lib/antv2/ant-interface.js +285 -0
- package/lib/antv2/base/adapter.d.ts +0 -0
- package/lib/antv2/base/adapter.js +0 -0
- package/lib/antv2/base/ant-interface.d.ts +35 -0
- package/lib/antv2/base/ant-interface.js +285 -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 +0 -0
- package/lib/antv2/binding.d.ts +13 -0
- package/lib/antv2/binding.js +27 -0
- 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/hr copy/adapter.d.ts +11 -0
- package/lib/antv2/hr copy/adapter.js +30 -0
- package/lib/antv2/hr copy/index.d.ts +2 -0
- package/lib/antv2/hr copy/index.js +7 -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/sensor-factory.d.ts +5 -0
- package/lib/antv2/sensor-factory.js +20 -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 +1 -0
- package/lib/ble/base/adapter.js +20 -13
- 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 +0 -0
- package/lib/ble/bindings/linux.js +0 -0
- package/lib/ble/bindings/mock.d.ts +0 -0
- package/lib/ble/bindings/mock.js +0 -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 +0 -0
- package/lib/ble/ble-interface.js +0 -0
- 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 +1 -0
- package/lib/ble/cp/adapter.js +8 -0
- package/lib/ble/cp/comm.d.ts +0 -0
- package/lib/ble/cp/comm.js +0 -0
- 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 +0 -0
- 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 +0 -0
- 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 +0 -0
- package/lib/ble/hr/comm.js +0 -0
- 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 +0 -0
- package/lib/ble/tacx/adapter.js +0 -0
- package/lib/ble/tacx/comms.d.ts +0 -0
- package/lib/ble/tacx/comms.js +0 -0
- 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 +0 -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 +0 -0
- 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/interfaces.d.ts +7 -0
- package/lib/interfaces.js +27 -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/SinglePathScanner.d.ts +17 -0
- package/lib/serial/SinglePathScanner.js +87 -0
- package/lib/serial/adapter-factory.d.ts +14 -0
- package/lib/serial/adapter-factory.js +30 -0
- package/lib/serial/adapter.d.ts +17 -0
- package/lib/serial/adapter.js +67 -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 +1 -2
- 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/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/serial/comms.d.ts +62 -0
- package/lib/serial/comms.js +280 -0
- package/lib/serial/daum/DaumAdapter.d.ts +0 -0
- package/lib/serial/daum/DaumAdapter.js +0 -0
- package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +2 -0
- package/lib/serial/daum/classic/PROTOCOL_NAME.js +5 -0
- package/lib/serial/daum/classic/adapter.d.ts +0 -0
- package/lib/serial/daum/classic/adapter.js +3 -1
- package/lib/serial/daum/classic/comms.d.ts +0 -0
- package/lib/serial/daum/classic/comms.js +1 -1
- 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/consts.d.ts +0 -0
- package/lib/serial/daum/consts.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/serial-interface.d.ts +36 -0
- package/lib/serial/serial-interface.js +288 -0
- package/lib/serial/serial-scanner.d.ts +16 -0
- package/lib/serial/serial-scanner.js +87 -0
- package/lib/serial/serialport.d.ts +17 -0
- package/lib/serial/serialport.js +87 -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/Command.d.ts +8 -0
- package/lib/types/Command.js +2 -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/command.d.ts +0 -0
- package/lib/types/command.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/route.d.ts +0 -0
- package/lib/types/route.js +0 -0
- package/lib/types/types.d.ts +8 -0
- package/lib/types/types.js +2 -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
|
@@ -0,0 +1,285 @@
|
|
|
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
|
+
const events_1 = __importDefault(require("events"));
|
|
16
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
|
+
const sensor_factory_1 = __importDefault(require("../factories/sensor-factory"));
|
|
18
|
+
class AntInterface extends events_1.default {
|
|
19
|
+
static getInstance(props = {}) {
|
|
20
|
+
if (AntInterface._instance === undefined)
|
|
21
|
+
AntInterface._instance = new AntInterface(props);
|
|
22
|
+
return AntInterface._instance;
|
|
23
|
+
}
|
|
24
|
+
static hasInstance() {
|
|
25
|
+
return AntInterface._instance !== undefined;
|
|
26
|
+
}
|
|
27
|
+
constructor(props) {
|
|
28
|
+
super();
|
|
29
|
+
this.props = props;
|
|
30
|
+
this.device = undefined;
|
|
31
|
+
this.connectState = {
|
|
32
|
+
connected: false,
|
|
33
|
+
connecting: false
|
|
34
|
+
};
|
|
35
|
+
const { binding, logger } = props;
|
|
36
|
+
if (logger)
|
|
37
|
+
this.logger = logger;
|
|
38
|
+
else {
|
|
39
|
+
this.logger = new gd_eventlog_1.EventLogger('Ant+');
|
|
40
|
+
}
|
|
41
|
+
if (binding) {
|
|
42
|
+
this.Binding = binding;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
getName() {
|
|
46
|
+
return AntInterface.INTERFACE_NAME;
|
|
47
|
+
}
|
|
48
|
+
getBinding() {
|
|
49
|
+
return this.Binding;
|
|
50
|
+
}
|
|
51
|
+
setBinding(binding) {
|
|
52
|
+
this.Binding = binding;
|
|
53
|
+
}
|
|
54
|
+
setLogger(logger) {
|
|
55
|
+
this.logger = logger;
|
|
56
|
+
}
|
|
57
|
+
logEvent(event) {
|
|
58
|
+
if (this.logger)
|
|
59
|
+
this.logger.logEvent(event);
|
|
60
|
+
const w = global.window;
|
|
61
|
+
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.ANT_DEBUG) {
|
|
62
|
+
console.log('~~~ ANT', event);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
isConnected() {
|
|
66
|
+
return this.connectState.connected;
|
|
67
|
+
}
|
|
68
|
+
connect() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
if (this.isConnected())
|
|
71
|
+
return true;
|
|
72
|
+
if (!this.connectState.connecting) {
|
|
73
|
+
this.connectState.connecting = true;
|
|
74
|
+
this.logEvent({ message: 'ANT+ connecting ...' });
|
|
75
|
+
try {
|
|
76
|
+
const device = new this.Binding(Object.assign(Object.assign({}, this.props), { logger: this.logger }));
|
|
77
|
+
const opened = yield device.open();
|
|
78
|
+
if (!opened) {
|
|
79
|
+
this.logEvent({ message: 'ANT+ not connected' });
|
|
80
|
+
this.connectState.connecting = false;
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
this.device = device;
|
|
84
|
+
this.connectState.connected = true;
|
|
85
|
+
this.connectState.connecting = false;
|
|
86
|
+
this.logEvent({ message: 'ANT+ connected' });
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
this.logEvent({ message: 'error', fn: 'connect', error: err.message, stack: err.stack });
|
|
91
|
+
this.connectState.connected = false;
|
|
92
|
+
this.connectState.connecting = false;
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return new Promise(resolve => {
|
|
98
|
+
setInterval(() => {
|
|
99
|
+
if (!this.connectState.connecting)
|
|
100
|
+
resolve(this.connectState.connected);
|
|
101
|
+
}, 500);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
disconnect() {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
if (!this.device)
|
|
109
|
+
return true;
|
|
110
|
+
this.logEvent({ message: 'ANT+ disconnecting ...' });
|
|
111
|
+
const closed = yield this.device.close();
|
|
112
|
+
this.connectState.connected = !closed;
|
|
113
|
+
this.logEvent({ message: 'ANT+ disconnected' });
|
|
114
|
+
return closed;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
onError(profile, error) {
|
|
118
|
+
this.logEvent({ message: 'ANT+ERROR:', profile, error });
|
|
119
|
+
}
|
|
120
|
+
onData(profile, id, data, tag) {
|
|
121
|
+
this.emit('data', profile, id, data, tag);
|
|
122
|
+
}
|
|
123
|
+
scan(props = {}) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
this.logEvent({ message: 'starting scan ..' });
|
|
126
|
+
const detected = [];
|
|
127
|
+
const onDetected = (profile, deviceID) => {
|
|
128
|
+
if (deviceID && detected.find(s => s.deviceID === deviceID && s.profile === profile) === undefined) {
|
|
129
|
+
try {
|
|
130
|
+
detected.push({ interface: this.getName(), profile, deviceID });
|
|
131
|
+
this.emit('device', { interface: 'ant', profile, deviceID });
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
this.logEvent({ message: 'error', fn: 'onDerected', error: err.message, stack: err.stack });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
let channel;
|
|
139
|
+
if (!this.activeScan) {
|
|
140
|
+
while (!this.isConnected()) {
|
|
141
|
+
const connected = yield this.connect();
|
|
142
|
+
if (!connected)
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
channel = this.device.getChannel();
|
|
146
|
+
channel.setProps({ logger: this.logger });
|
|
147
|
+
if (!channel)
|
|
148
|
+
return [];
|
|
149
|
+
const sensors = sensor_factory_1.default.createAll();
|
|
150
|
+
sensors.forEach((sensor) => {
|
|
151
|
+
channel.attach(sensor);
|
|
152
|
+
});
|
|
153
|
+
channel.on('detected', onDetected);
|
|
154
|
+
channel.on('data', this.onData.bind(this));
|
|
155
|
+
try {
|
|
156
|
+
const success = yield channel.startScanner();
|
|
157
|
+
this.logEvent({ message: 'scan started', success });
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
this.logEvent({ message: 'scan could not be started', error: err.message, stack: err.stack });
|
|
161
|
+
channel.off('detected', onDetected);
|
|
162
|
+
channel.off('data', this.onData.bind(this));
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
let iv;
|
|
166
|
+
return new Promise(resolve => {
|
|
167
|
+
this.activeScan = channel;
|
|
168
|
+
const start = Date.now();
|
|
169
|
+
const timeout = props.timeout ? start + props.timeout : undefined;
|
|
170
|
+
iv = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
if (this.activeScan && (!timeout || Date.now() < timeout))
|
|
172
|
+
return;
|
|
173
|
+
clearInterval(iv);
|
|
174
|
+
if (this.activeScan)
|
|
175
|
+
yield this.stopScan();
|
|
176
|
+
this.emit('stop-scan');
|
|
177
|
+
channel.off('detected', onDetected);
|
|
178
|
+
channel.off('data', this.onData.bind(this));
|
|
179
|
+
resolve(detected);
|
|
180
|
+
}), 100);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
return new Promise(resolve => {
|
|
185
|
+
channel = this.activeScan;
|
|
186
|
+
channel.on('data', this.onData.bind(this));
|
|
187
|
+
channel.on('detected', onDetected);
|
|
188
|
+
this.once('stop-scan', () => {
|
|
189
|
+
channel.off('detected', onDetected);
|
|
190
|
+
channel.off('data', this.onData.bind(this));
|
|
191
|
+
resolve(detected);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
stopScan() {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
this.logEvent({ message: 'stopping scan ..' });
|
|
200
|
+
if (!this.activeScan)
|
|
201
|
+
return false;
|
|
202
|
+
const channel = this.activeScan;
|
|
203
|
+
try {
|
|
204
|
+
const stopped = yield channel.stopScanner();
|
|
205
|
+
this.activeScan = undefined;
|
|
206
|
+
this.logEvent({ message: 'scan stopped' });
|
|
207
|
+
return stopped;
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
this.logEvent({ message: 'error', fn: 'stopScan()', error: err.message, stack: err.stack });
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
startSensor(sensor, onDeviceData) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
if (!this.isConnected()) {
|
|
218
|
+
const connected = yield this.connect();
|
|
219
|
+
if (!connected)
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
let channel;
|
|
223
|
+
channel = this.device.getChannel();
|
|
224
|
+
channel.setProps({ logger: this.logger });
|
|
225
|
+
if (!channel)
|
|
226
|
+
return false;
|
|
227
|
+
channel.on('data', this.onData.bind(this));
|
|
228
|
+
sensor.setChannel(channel);
|
|
229
|
+
this.on('data', (profile, deviceID, data) => {
|
|
230
|
+
if (profile === sensor.getProfile() && deviceID === sensor.getDeviceID())
|
|
231
|
+
onDeviceData(data);
|
|
232
|
+
});
|
|
233
|
+
try {
|
|
234
|
+
return yield channel.startSensor(sensor);
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
this.logEvent({ message: 'could not start sensor', error: err.message || err, stack: err.stack });
|
|
238
|
+
try {
|
|
239
|
+
yield channel.stopSensor(sensor);
|
|
240
|
+
}
|
|
241
|
+
catch (_a) { }
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
stopSensor(sensor) {
|
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
if (!this.isConnected() || !this.device) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
const channel = sensor.getChannel();
|
|
252
|
+
if (channel) {
|
|
253
|
+
try {
|
|
254
|
+
if (!channel.flush) {
|
|
255
|
+
this.logEvent({ message: 'old version of ant-channel detected' });
|
|
256
|
+
channel.flush = () => {
|
|
257
|
+
const c = channel;
|
|
258
|
+
c.messageQueue.forEach(msg => { msg.resolve(false); });
|
|
259
|
+
c.messageQueue = [];
|
|
260
|
+
c.isWriting = false;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
channel.flush();
|
|
264
|
+
channel.removeAllListeners('data');
|
|
265
|
+
const stopped = yield channel.stopSensor(sensor);
|
|
266
|
+
return stopped;
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
this.logEvent({ message: 'could not stop sensor', error: err.message || err, deviceID: sensor.getDeviceID(), stack: err.stack });
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
this.logEvent({ message: 'could not stop sensor', deviceID: sensor.getDeviceID(), error: 'no channel attached' });
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
isScanning() {
|
|
280
|
+
return (this.activeScan === undefined || this.activeScan === null);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
AntInterface._instance = undefined;
|
|
284
|
+
AntInterface.INTERFACE_NAME = 'ant';
|
|
285
|
+
exports.default = AntInterface;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IAntDevice, IChannel } from 'incyclist-ant-plus';
|
|
3
|
+
import { AntInterfaceProps } from './ant-interface';
|
|
4
|
+
export default class AntDeviceBinding implements IAntDevice {
|
|
5
|
+
constructor(_props: AntInterfaceProps);
|
|
6
|
+
open(): Promise<boolean>;
|
|
7
|
+
close(): Promise<boolean>;
|
|
8
|
+
getMaxChannels(): number;
|
|
9
|
+
getChannel(): IChannel;
|
|
10
|
+
freeChannel(channel: IChannel): void;
|
|
11
|
+
getDeviceNumber(): number;
|
|
12
|
+
write(data: Buffer): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class AntDeviceBinding {
|
|
4
|
+
constructor(_props) { }
|
|
5
|
+
open() {
|
|
6
|
+
throw new Error('Method not implemented.');
|
|
7
|
+
}
|
|
8
|
+
close() {
|
|
9
|
+
throw new Error('Method not implemented.');
|
|
10
|
+
}
|
|
11
|
+
getMaxChannels() {
|
|
12
|
+
throw new Error('Method not implemented.');
|
|
13
|
+
}
|
|
14
|
+
getChannel() {
|
|
15
|
+
throw new Error('Method not implemented.');
|
|
16
|
+
}
|
|
17
|
+
freeChannel(channel) {
|
|
18
|
+
throw new Error('Method not implemented.');
|
|
19
|
+
}
|
|
20
|
+
getDeviceNumber() {
|
|
21
|
+
throw new Error('Method not implemented.');
|
|
22
|
+
}
|
|
23
|
+
write(data) {
|
|
24
|
+
throw new Error('Method not implemented.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = AntDeviceBinding;
|
|
File without changes
|
package/lib/antv2/cad/adapter.js
CHANGED
|
File without changes
|
package/lib/antv2/cad/index.d.ts
CHANGED
|
File without changes
|
package/lib/antv2/cad/index.js
CHANGED
|
File without changes
|
package/lib/antv2/consts.d.ts
CHANGED
|
File without changes
|
package/lib/antv2/consts.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/antv2/fe/adapter.js
CHANGED
|
File without changes
|
package/lib/antv2/fe/index.d.ts
CHANGED
|
File without changes
|
package/lib/antv2/fe/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/antv2/hr/adapter.js
CHANGED
|
File without changes
|
package/lib/antv2/hr/index.d.ts
CHANGED
|
File without changes
|
package/lib/antv2/hr/index.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HeartRateSensorState, Profile } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "../base/adapter";
|
|
3
|
+
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile } from "../types";
|
|
4
|
+
export default class AntHrAdapter extends AntAdapter<HeartRateSensorState> {
|
|
5
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
6
|
+
protected static ANT_PROFILE_NAME: Profile;
|
|
7
|
+
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
8
|
+
getDisplayName(): string;
|
|
9
|
+
mapToAdapterData(deviceData: HeartRateSensorState): void;
|
|
10
|
+
hasData(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
7
|
+
const types_1 = require("../../types");
|
|
8
|
+
class AntHrAdapter extends adapter_1.default {
|
|
9
|
+
constructor(settings, props) {
|
|
10
|
+
super(settings, props);
|
|
11
|
+
this.capabilities = [types_1.IncyclistCapability.HeartRate];
|
|
12
|
+
}
|
|
13
|
+
getDisplayName() {
|
|
14
|
+
const { ComputedHeartRate } = this.deviceData;
|
|
15
|
+
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
16
|
+
return `${this.getUniqueName()}${hrmStr}`;
|
|
17
|
+
}
|
|
18
|
+
mapToAdapterData(deviceData) {
|
|
19
|
+
if (deviceData.ComputedHeartRate) {
|
|
20
|
+
this.data.heartrate = deviceData.ComputedHeartRate;
|
|
21
|
+
this.data.timestamp = Date.now();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
hasData() {
|
|
25
|
+
return this.deviceData.ComputedHeartRate !== undefined && this.deviceData.ComputedHeartRate !== null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
AntHrAdapter.INCYCLIST_PROFILE_NAME = 'Heartrate Monitor';
|
|
29
|
+
AntHrAdapter.ANT_PROFILE_NAME = 'HR';
|
|
30
|
+
exports.default = AntHrAdapter;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const adapter_1 = __importDefault(require("./adapter"));
|
|
7
|
+
exports.default = adapter_1.default;
|
package/lib/antv2/index.d.ts
CHANGED
|
File without changes
|
package/lib/antv2/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/antv2/pwr/adapter.js
CHANGED
|
File without changes
|
package/lib/antv2/pwr/index.d.ts
CHANGED
|
File without changes
|
package/lib/antv2/pwr/index.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const incyclist_ant_plus_1 = require("incyclist-ant-plus");
|
|
4
|
+
const profiles = [
|
|
5
|
+
{ profile: 'PWR', Class: incyclist_ant_plus_1.BicyclePowerSensor },
|
|
6
|
+
{ profile: 'HR', Class: incyclist_ant_plus_1.HeartRateSensor },
|
|
7
|
+
{ profile: 'FE', Class: incyclist_ant_plus_1.FitnessEquipmentSensor },
|
|
8
|
+
];
|
|
9
|
+
class SensorFactory {
|
|
10
|
+
static create(profile, deviceID) {
|
|
11
|
+
const info = profiles.find(i => i.profile === profile);
|
|
12
|
+
if (!info)
|
|
13
|
+
return;
|
|
14
|
+
return new info.Class(deviceID);
|
|
15
|
+
}
|
|
16
|
+
static createAll() {
|
|
17
|
+
return profiles.map(info => new info.Class());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = SensorFactory;
|
package/lib/antv2/types.d.ts
CHANGED
|
File without changes
|
package/lib/antv2/types.js
CHANGED
|
File without changes
|
package/lib/antv2/utils.d.ts
CHANGED
|
File without changes
|
package/lib/antv2/utils.js
CHANGED
|
File without changes
|
package/lib/base/adpater.d.ts
CHANGED
|
File without changes
|
package/lib/base/adpater.js
CHANGED
|
File without changes
|
package/lib/base/consts.d.ts
CHANGED
|
File without changes
|
package/lib/base/consts.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/ble/base/adapter.js
CHANGED
|
@@ -109,21 +109,26 @@ class BleAdapter extends adpater_1.default {
|
|
|
109
109
|
return settings.name || settings.id || settings.address;
|
|
110
110
|
}
|
|
111
111
|
onDeviceData(deviceData) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
112
|
+
try {
|
|
113
|
+
this.dataMsgCount++;
|
|
114
|
+
this.lastDataTS = Date.now();
|
|
115
|
+
this.deviceData = Object.assign({}, deviceData);
|
|
116
|
+
if (!this.canEmitData())
|
|
117
|
+
return;
|
|
118
|
+
this.logEvent({ message: 'onDeviceData', data: deviceData, isControllable: this.isControllable() });
|
|
119
|
+
if (this.isControllable()) {
|
|
120
|
+
const mappedData = this.mapData(deviceData);
|
|
121
|
+
const incyclistData = this.getCyclingMode().updateData(mappedData);
|
|
122
|
+
this.data = this.transformData(incyclistData);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.data = this.mapData(this.deviceData);
|
|
126
|
+
}
|
|
127
|
+
this.emitData(this.data);
|
|
122
128
|
}
|
|
123
|
-
|
|
124
|
-
this.
|
|
129
|
+
catch (err) {
|
|
130
|
+
this.logEvent({ message: 'Error', fn: 'onDeviceData', error: err.message });
|
|
125
131
|
}
|
|
126
|
-
this.emitData(this.data);
|
|
127
132
|
}
|
|
128
133
|
mapData(deviceData) {
|
|
129
134
|
throw new Error('message not implemented');
|
|
@@ -223,5 +228,7 @@ class BleAdapter extends adpater_1.default {
|
|
|
223
228
|
return res;
|
|
224
229
|
});
|
|
225
230
|
}
|
|
231
|
+
update() {
|
|
232
|
+
}
|
|
226
233
|
}
|
|
227
234
|
exports.default = BleAdapter;
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/ble/bindings/mock.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/ble/ble-interface.js
CHANGED
|
File without changes
|
|
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
|
@@ -16,4 +16,5 @@ export default class PwrAdapter extends BleAdapter<PowerData, BleCyclingPowerDev
|
|
|
16
16
|
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
17
17
|
transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
|
|
18
18
|
stop(): Promise<boolean>;
|
|
19
|
+
sendUpdate(request: any): void;
|
|
19
20
|
}
|
package/lib/ble/cp/adapter.js
CHANGED
|
@@ -93,6 +93,14 @@ class PwrAdapter extends adapter_1.default {
|
|
|
93
93
|
return stopped;
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
+
sendUpdate(request) {
|
|
97
|
+
try {
|
|
98
|
+
super.sendUpdate(request);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
this.logEvent({ message: 'Error', fn: 'sendUpdate', error: err.message });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
96
104
|
}
|
|
97
105
|
PwrAdapter.INCYCLIST_PROFILE_NAME = 'Power Meter';
|
|
98
106
|
PwrAdapter.controllers = {
|
package/lib/ble/cp/comm.d.ts
CHANGED
|
File without changes
|
package/lib/ble/cp/comm.js
CHANGED
|
File without changes
|
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
|