incyclist-devices 1.5.38 → 2.0.0
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/README.MD +238 -0
- package/lib/adapters.d.ts +7 -0
- package/lib/adapters.js +49 -0
- package/lib/antv2/adapter-factory.d.ts +21 -10
- package/lib/antv2/adapter-factory.js +51 -33
- package/lib/antv2/adapter.d.ts +65 -0
- package/lib/antv2/adapter.js +310 -0
- package/lib/antv2/ant-interface.d.ts +17 -11
- package/lib/antv2/ant-interface.js +41 -31
- package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +1 -1
- package/lib/antv2/{ant-binding.js → binding.js} +1 -1
- package/lib/antv2/fe/adapter.d.ts +28 -0
- package/lib/antv2/{fe.js → fe/adapter.js} +106 -90
- package/lib/antv2/fe/index.d.ts +2 -0
- package/lib/antv2/fe/index.js +7 -0
- package/lib/antv2/hr/adapter.d.ts +15 -0
- package/lib/antv2/hr/adapter.js +76 -0
- package/lib/antv2/hr/index.d.ts +2 -0
- package/lib/antv2/hr/index.js +7 -0
- package/lib/antv2/index.d.ts +7 -0
- package/lib/antv2/index.js +20 -0
- package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
- package/lib/antv2/pwr/adapter.d.ts +24 -0
- package/lib/antv2/pwr/adapter.js +141 -0
- package/lib/antv2/pwr/index.d.ts +2 -0
- package/lib/antv2/pwr/index.js +7 -0
- package/lib/antv2/sensor-factory.d.ts +2 -2
- package/lib/antv2/types.d.ts +22 -0
- package/lib/antv2/types.js +5 -0
- package/lib/antv2/utils.d.ts +4 -0
- package/lib/antv2/utils.js +192 -0
- package/lib/base/adpater.d.ts +68 -0
- package/lib/base/adpater.js +183 -0
- package/lib/ble/adapter-factory.d.ts +33 -0
- package/lib/ble/adapter-factory.js +105 -0
- package/lib/ble/base/adapter.d.ts +53 -0
- package/lib/ble/base/adapter.js +290 -0
- package/lib/ble/base/comms-utils.d.ts +7 -0
- package/lib/ble/base/comms-utils.js +91 -0
- package/lib/ble/{ble-device.d.ts → base/comms.d.ts} +31 -16
- package/lib/ble/{ble-device.js → base/comms.js} +193 -55
- package/lib/ble/bindings/index.d.ts +2 -0
- package/lib/ble/bindings/index.js +8 -0
- package/lib/ble/bindings/linux.d.ts +15 -0
- package/lib/ble/bindings/linux.js +39 -0
- package/lib/ble/bindings/mock.d.ts +9 -0
- package/lib/ble/bindings/mock.js +108 -0
- package/lib/ble/bindings/types.d.ts +57 -0
- package/lib/ble/bindings/types.js +96 -0
- package/lib/ble/ble-interface.d.ts +38 -59
- package/lib/ble/ble-interface.js +254 -462
- package/lib/ble/ble-peripheral.d.ts +7 -5
- package/lib/ble/ble-peripheral.js +52 -21
- package/lib/ble/consts.d.ts +3 -0
- package/lib/ble/consts.js +4 -1
- package/lib/ble/cp/adapter.d.ts +22 -0
- package/lib/ble/cp/adapter.js +111 -0
- package/lib/ble/cp/comm.d.ts +31 -0
- package/lib/ble/cp/comm.js +125 -0
- package/lib/ble/cp/index.d.ts +4 -0
- package/lib/ble/cp/index.js +10 -0
- package/lib/ble/cp/types.d.ts +13 -0
- package/lib/ble/cp/types.js +2 -0
- package/lib/ble/elite/adapter.d.ts +19 -0
- package/lib/ble/elite/adapter.js +120 -0
- package/lib/ble/elite/comms.d.ts +32 -0
- package/lib/ble/elite/comms.js +126 -0
- package/lib/ble/elite/index.d.ts +3 -0
- package/lib/ble/elite/index.js +10 -0
- package/lib/ble/fm/adapter.d.ts +22 -0
- package/lib/ble/fm/adapter.js +249 -0
- package/lib/ble/fm/comms.d.ts +50 -0
- package/lib/ble/{fm.js → fm/comms.js} +34 -277
- package/lib/ble/fm/consts.d.ts +6 -0
- package/lib/ble/fm/consts.js +9 -0
- package/lib/ble/fm/index.d.ts +5 -0
- package/lib/ble/fm/index.js +13 -0
- package/lib/ble/fm/types.d.ts +30 -0
- package/lib/ble/fm/types.js +2 -0
- package/lib/ble/hr/adapter.d.ts +14 -0
- package/lib/ble/hr/adapter.js +45 -0
- package/lib/ble/hr/comm.d.ts +19 -0
- package/lib/ble/hr/comm.js +56 -0
- package/lib/ble/hr/index.d.ts +4 -0
- package/lib/ble/hr/index.js +10 -0
- package/lib/ble/hr/mock.d.ts +7 -0
- package/lib/ble/hr/mock.js +47 -0
- package/lib/ble/hr/types.d.ts +5 -0
- package/lib/ble/hr/types.js +2 -0
- package/lib/ble/index.d.ts +9 -0
- package/lib/ble/index.js +26 -0
- package/lib/ble/peripheral-cache.d.ts +43 -0
- package/lib/ble/peripheral-cache.js +107 -0
- package/lib/ble/tacx/adapter.d.ts +10 -0
- package/lib/ble/tacx/adapter.js +99 -0
- package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +11 -43
- package/lib/ble/{tacx.js → tacx/comms.js} +23 -155
- package/lib/ble/tacx/index.d.ts +4 -0
- package/lib/ble/tacx/index.js +10 -0
- package/lib/ble/tacx/types.d.ts +25 -0
- package/lib/ble/tacx/types.js +2 -0
- package/lib/ble/types.d.ts +128 -0
- package/lib/ble/types.js +2 -0
- package/lib/ble/utils.d.ts +17 -0
- package/lib/ble/utils.js +54 -0
- package/lib/ble/wahoo/adapter.d.ts +9 -0
- package/lib/ble/wahoo/adapter.js +95 -0
- package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +11 -44
- package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +29 -129
- package/lib/ble/wahoo/index.d.ts +4 -0
- package/lib/ble/wahoo/index.js +10 -0
- package/lib/ble/wahoo/types.d.ts +19 -0
- package/lib/ble/wahoo/types.js +2 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +34 -0
- package/lib/interfaces.d.ts +7 -0
- package/lib/interfaces.js +27 -0
- package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
- package/lib/{ble → modes}/ble-erg-mode.js +2 -2
- package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
- package/lib/{ble → modes}/ble-st-mode.js +1 -1
- package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +8 -4
- package/lib/modes/power-meter.d.ts +3 -3
- package/lib/modes/simulator.d.ts +2 -2
- package/lib/modes/simulator.js +1 -1
- package/lib/serial/adapter-factory.d.ts +12 -0
- package/lib/serial/adapter-factory.js +30 -0
- package/lib/serial/adapter.d.ts +21 -0
- package/lib/serial/adapter.js +61 -0
- package/lib/serial/bindings/tcp.d.ts +45 -0
- package/lib/serial/bindings/tcp.js +284 -0
- package/lib/serial/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/{daum → serial/daum}/DaumAdapter.d.ts +14 -23
- package/lib/{daum → serial/daum}/DaumAdapter.js +57 -97
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
- package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
- package/lib/serial/daum/classic/adapter.d.ts +29 -0
- package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
- package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
- package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
- package/lib/serial/daum/classic/mock.d.ts +96 -0
- package/lib/serial/daum/classic/mock.js +365 -0
- package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
- package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
- package/lib/serial/daum/premium/adapter.d.ts +25 -0
- package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +107 -47
- package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
- package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +215 -420
- package/lib/serial/daum/premium/mock.d.ts +75 -0
- package/lib/serial/daum/premium/mock.js +289 -0
- package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
- package/lib/serial/daum/premium/types.d.ts +12 -0
- package/lib/serial/daum/premium/types.js +2 -0
- package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
- package/lib/{daum → serial/daum}/premium/utils.js +22 -63
- package/lib/serial/index.d.ts +9 -0
- package/lib/serial/index.js +49 -0
- package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
- package/lib/{kettler → serial/kettler}/comms.js +71 -32
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +14 -28
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +102 -169
- package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
- package/lib/serial/kettler/ergo-racer/mock.js +216 -0
- package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
- package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
- package/lib/serial/serial-interface.d.ts +60 -0
- package/lib/serial/serial-interface.js +309 -0
- package/lib/simulator/Simulator.d.ts +12 -25
- package/lib/simulator/Simulator.js +26 -87
- package/lib/types/adapter.d.ts +39 -0
- package/lib/types/adapter.js +2 -0
- package/lib/types/capabilities.d.ts +8 -0
- package/lib/types/capabilities.js +12 -0
- package/lib/types/data.d.ts +12 -0
- package/lib/types/data.js +2 -0
- package/lib/types/device.d.ts +32 -0
- package/lib/types/device.js +11 -0
- package/lib/types/interface.d.ts +18 -0
- package/lib/types/interface.js +2 -0
- package/lib/types/route.d.ts +2 -2
- package/lib/types/user.d.ts +1 -1
- package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
- package/lib/{utils.js → utils/utils.js} +5 -1
- package/package.json +16 -14
- package/lib/DeviceSupport.d.ts +0 -36
- package/lib/DeviceSupport.js +0 -82
- package/lib/ant/AntAdapter.d.ts +0 -50
- package/lib/ant/AntAdapter.js +0 -109
- package/lib/ant/AntScanner.d.ts +0 -60
- package/lib/ant/AntScanner.js +0 -651
- package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
- package/lib/ant/antfe/AntFEAdapter.js +0 -652
- package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
- package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
- package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
- package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
- package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
- package/lib/ant/antpwr/pwr-adapter.js +0 -251
- package/lib/ant/utils.d.ts +0 -1
- package/lib/ant/utils.js +0 -23
- package/lib/antv2/AntAdapter.d.ts +0 -48
- package/lib/antv2/AntAdapter.js +0 -104
- package/lib/antv2/ant-device.d.ts +0 -59
- package/lib/antv2/ant-device.js +0 -161
- package/lib/antv2/fe.d.ts +0 -32
- package/lib/antv2/hr.d.ts +0 -18
- package/lib/antv2/hr.js +0 -102
- package/lib/antv2/incyclist-protocol.d.ts +0 -37
- package/lib/antv2/incyclist-protocol.js +0 -126
- package/lib/antv2/pwr.d.ts +0 -28
- package/lib/antv2/pwr.js +0 -171
- package/lib/ble/ble.d.ts +0 -129
- package/lib/ble/ble.js +0 -86
- package/lib/ble/elite.d.ts +0 -90
- package/lib/ble/elite.js +0 -322
- package/lib/ble/fm.d.ts +0 -125
- package/lib/ble/hrm.d.ts +0 -48
- package/lib/ble/hrm.js +0 -134
- package/lib/ble/incyclist-protocol.d.ts +0 -31
- package/lib/ble/incyclist-protocol.js +0 -153
- package/lib/ble/pwr.d.ts +0 -89
- package/lib/ble/pwr.js +0 -322
- package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
- package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
- package/lib/daum/classic/DaumClassicProtocol.js +0 -185
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
- package/lib/daum/premium/tcpserial.d.ts +0 -33
- package/lib/daum/premium/tcpserial.js +0 -123
- package/lib/device.d.ts +0 -94
- package/lib/device.js +0 -76
- package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
- package/lib/kettler/ergo-racer/protocol.js +0 -203
- package/lib/protocol.d.ts +0 -74
- package/lib/protocol.js +0 -41
- package/lib/registry.d.ts +0 -8
- package/lib/registry.js +0 -33
- package/lib/serialport/bindings/tcp.d.ts +0 -20
- package/lib/serialport/bindings/tcp.js +0 -33
- package/lib/serialport/index.d.ts +0 -2
- package/lib/serialport/index.js +0 -29
- package/lib/serialport/serialport.d.ts +0 -29
- package/lib/serialport/serialport.js +0 -87
- /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
- /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
- /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
- /package/lib/{daum → serial/daum}/constants.js +0 -0
- /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
- /package/lib/{serialport.js → serial/serialport.js} +0 -0
- /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
- /package/lib/{calculations.js → utils/calculations.js} +0 -0
|
@@ -8,28 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Daum8iSerial = exports.Daum8iTcp = void 0;
|
|
16
12
|
const constants_1 = require("../constants");
|
|
17
|
-
const tcpserial_1 = __importDefault(require("./tcpserial"));
|
|
18
13
|
const utils_1 = require("./utils");
|
|
19
14
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
20
|
-
const nop = () => { };
|
|
21
|
-
const MAX_RETRIES = 5;
|
|
22
15
|
const DEFAULT_TIMEOUT = 10000;
|
|
23
|
-
const DEFAULT_SEND_DELAY = 1000;
|
|
24
|
-
const TIMEOUT_START = 15000;
|
|
25
|
-
const OPEN_TIMEOUT = 1000;
|
|
26
|
-
const DAUM_PREMIUM_DEFAULT_PORT = 51955;
|
|
27
|
-
const DAUM_PREMIUM_DEFAULT_HOST = '127.0.0.1';
|
|
28
16
|
const MAX_DATA_BLOCK_SIZE = 512;
|
|
29
17
|
const DS_BITS_OFF = 0;
|
|
30
18
|
const DS_BITS_ENDLESS_RACE = 2;
|
|
31
|
-
var __SerialPort = undefined;
|
|
32
|
-
var net = undefined;
|
|
33
19
|
const DEBUG_LOGGER = {
|
|
34
20
|
log: (e, ...args) => console.log(e, ...args),
|
|
35
21
|
logEvent: (event) => console.log(JSON.stringify(event))
|
|
@@ -40,58 +26,42 @@ const validateHost = (host) => {
|
|
|
40
26
|
return ipParts.map(p => Number(p)).join('.');
|
|
41
27
|
return host;
|
|
42
28
|
};
|
|
29
|
+
const validatePath = (path) => {
|
|
30
|
+
const parts = path.split(':');
|
|
31
|
+
if (parts.length < 2)
|
|
32
|
+
return path;
|
|
33
|
+
const host = validateHost(parts[0]);
|
|
34
|
+
const port = parts[1];
|
|
35
|
+
return `${host}:${port}`;
|
|
36
|
+
};
|
|
37
|
+
const drain = (sp) => new Promise(resolve => { sp.drain(resolve); });
|
|
43
38
|
class Daum8i {
|
|
44
39
|
constructor(props) {
|
|
45
40
|
this.props = props || {};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.portName = `${host}:51955`;
|
|
51
|
-
this.tcpip = true;
|
|
52
|
-
this.serial = false;
|
|
53
|
-
this.tcpipConnection = { host, port };
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
this.portName = this.props.port || process.env.COM_PORT;
|
|
57
|
-
this.tcpip = false;
|
|
58
|
-
this.serial = true;
|
|
59
|
-
this.port = this.portName;
|
|
60
|
-
}
|
|
61
|
-
this.settings = this.props.settings || {};
|
|
62
|
-
this.settings.logger = this.logger;
|
|
41
|
+
const { logger, serial, path } = props;
|
|
42
|
+
this.serial = serial;
|
|
43
|
+
this.path = validatePath(path);
|
|
44
|
+
this.logger = logger || (process.env.DEBUG ? DEBUG_LOGGER : new gd_eventlog_1.EventLogger('DaumPremium'));
|
|
63
45
|
this.isLoggingPaused = false;
|
|
64
|
-
this.sendRetryDelay = DEFAULT_SEND_DELAY;
|
|
65
|
-
this.sp = undefined;
|
|
66
46
|
this.connected = false;
|
|
67
47
|
this.blocked = false;
|
|
68
48
|
this.state = {
|
|
69
49
|
ack: { wait: false, startWait: undefined },
|
|
70
50
|
commandsInQueue: {},
|
|
71
51
|
};
|
|
52
|
+
this.settings = {};
|
|
72
53
|
this.bikeData = {
|
|
73
54
|
userWeight: 75,
|
|
74
55
|
bikeWeight: 10,
|
|
75
56
|
maxPower: 800
|
|
76
57
|
};
|
|
77
58
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
getType() {
|
|
82
|
-
return "Daum8i";
|
|
83
|
-
}
|
|
84
|
-
static setSerialPort(spClass) {
|
|
85
|
-
__SerialPort = spClass;
|
|
86
|
-
}
|
|
87
|
-
static setNetImpl(netClass) {
|
|
88
|
-
net = netClass;
|
|
89
|
-
}
|
|
90
|
-
static getSupportedInterfaces() {
|
|
91
|
-
return [constants_1.BIKE_INTERFACE.SERIAL, constants_1.BIKE_INTERFACE.TCPIP];
|
|
59
|
+
getInterface() {
|
|
60
|
+
var _a;
|
|
61
|
+
return (_a = this.serial) === null || _a === void 0 ? void 0 : _a.ifaceName;
|
|
92
62
|
}
|
|
93
63
|
getPort() {
|
|
94
|
-
return this.
|
|
64
|
+
return this.path;
|
|
95
65
|
}
|
|
96
66
|
isConnected() {
|
|
97
67
|
return this.connected;
|
|
@@ -99,141 +69,71 @@ class Daum8i {
|
|
|
99
69
|
pauseLogging() {
|
|
100
70
|
this.isLoggingPaused = true;
|
|
101
71
|
}
|
|
102
|
-
|
|
72
|
+
resumeLogging() {
|
|
103
73
|
this.isLoggingPaused = false;
|
|
104
74
|
}
|
|
105
75
|
logEvent(e) {
|
|
106
76
|
if (!this.isLoggingPaused)
|
|
107
77
|
this.logger.logEvent(e);
|
|
108
78
|
}
|
|
109
|
-
setUser(user, callback) {
|
|
110
|
-
this.logEvent({ message: "setUser()", user, port: this.portName });
|
|
111
|
-
this.settings.user = user || {};
|
|
112
|
-
var cb = callback || nop;
|
|
113
|
-
cb(200, user);
|
|
114
|
-
}
|
|
115
|
-
getUserWeight() {
|
|
116
|
-
if (!this.settings || !this.settings.user || !this.settings.user.weight)
|
|
117
|
-
return 75;
|
|
118
|
-
return this.settings.user.weight;
|
|
119
|
-
}
|
|
120
|
-
getBikeWeight() {
|
|
121
|
-
return 10;
|
|
122
|
-
}
|
|
123
|
-
unblock() {
|
|
124
|
-
this.blocked = false;
|
|
125
|
-
}
|
|
126
79
|
connect() {
|
|
127
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
return;
|
|
81
|
+
if (this.isConnected() && this.sp) {
|
|
82
|
+
return true;
|
|
131
83
|
}
|
|
132
|
-
this.state.busy = true;
|
|
133
|
-
this.state.commandsInQueue = {};
|
|
134
84
|
try {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
if (this.sp === undefined) {
|
|
140
|
-
if (this.tcpip) {
|
|
141
|
-
const { host, port } = this.tcpipConnection;
|
|
142
|
-
const { logger } = this.props;
|
|
143
|
-
this.logEvent({ message: "creating TCPSocketPort", host, port });
|
|
144
|
-
this.sp = new tcpserial_1.default({ host, port, net, timeout: OPEN_TIMEOUT, logger });
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
const settings = this.settings.port || {};
|
|
148
|
-
settings.autoOpen = false;
|
|
149
|
-
this.logEvent({ message: "creating SerialPort", port: this.port, settings });
|
|
150
|
-
this.sp = new __SerialPort(this.port, settings);
|
|
151
|
-
}
|
|
152
|
-
this.sp.on('open', this.onPortOpen.bind(this));
|
|
85
|
+
const port = yield this.serial.openPort(this.path);
|
|
86
|
+
if (port !== null) {
|
|
87
|
+
this.connected = true;
|
|
88
|
+
this.sp = port;
|
|
153
89
|
this.sp.on('close', this.onPortClose.bind(this));
|
|
154
90
|
this.sp.on('error', (error) => { this.onPortError(error); });
|
|
155
91
|
this.sp.on('data', (data) => { this.onData(data); });
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return false;
|
|
156
96
|
}
|
|
157
|
-
const start = Date.now();
|
|
158
|
-
this.state.connecting = true;
|
|
159
|
-
this.state.opening = { start, timeout: start + this.getTimeoutValue() };
|
|
160
|
-
this.logEvent({ message: "opening port ..." });
|
|
161
|
-
yield this.sp.open();
|
|
162
97
|
}
|
|
163
|
-
catch (
|
|
164
|
-
|
|
165
|
-
this.state.busy = false;
|
|
98
|
+
catch (_a) {
|
|
99
|
+
return false;
|
|
166
100
|
}
|
|
167
101
|
});
|
|
168
102
|
}
|
|
169
|
-
|
|
103
|
+
close() {
|
|
170
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
105
|
+
if (this.isConnected() && this.serial && this.sp) {
|
|
106
|
+
try {
|
|
107
|
+
yield this.flush();
|
|
108
|
+
yield this.serial.closePort(this.path);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
this.logEvent({ message: 'could not close ', reason: err.message });
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
174
114
|
}
|
|
175
|
-
|
|
115
|
+
this.connected = false;
|
|
116
|
+
if (this.sp) {
|
|
117
|
+
this.sp.removeAllListeners();
|
|
118
|
+
this.sp = null;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
176
121
|
});
|
|
177
122
|
}
|
|
178
|
-
|
|
179
|
-
return
|
|
180
|
-
if (this.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
yield this.connect();
|
|
186
|
-
}
|
|
187
|
-
catch (_a) { }
|
|
188
|
-
const tTimeout = Date.now() + TIMEOUT_START;
|
|
189
|
-
const iv = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
try {
|
|
191
|
-
if (this.state.error !== undefined) {
|
|
192
|
-
clearInterval(iv);
|
|
193
|
-
yield this.forceClose();
|
|
194
|
-
reject(this.state.error);
|
|
195
|
-
}
|
|
196
|
-
else if (this.isConnected()) {
|
|
197
|
-
this.state.connecting = false;
|
|
198
|
-
resolve(true);
|
|
123
|
+
flush() {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
if (!this.state.writeBusy)
|
|
126
|
+
return;
|
|
127
|
+
return new Promise(done => {
|
|
128
|
+
const iv = setInterval(() => {
|
|
129
|
+
if (!this.state.writeBusy) {
|
|
199
130
|
clearInterval(iv);
|
|
131
|
+
this.writeDone();
|
|
132
|
+
done();
|
|
200
133
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
yield this.forceClose();
|
|
205
|
-
clearInterval(iv);
|
|
206
|
-
reject(new Error('timeout'));
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
catch (_b) { }
|
|
211
|
-
}), 100);
|
|
212
|
-
}));
|
|
213
|
-
}
|
|
214
|
-
onPortOpen() {
|
|
215
|
-
this.error = undefined;
|
|
216
|
-
this.connected = true;
|
|
217
|
-
this.state.opening = undefined;
|
|
218
|
-
this.state.opened = true;
|
|
219
|
-
this.state.busy = false;
|
|
220
|
-
this.logEvent({ message: "port opened", port: this.portName });
|
|
221
|
-
}
|
|
222
|
-
onPortClose() {
|
|
223
|
-
this.logEvent({ message: "port closed", port: this.portName });
|
|
224
|
-
this.error = undefined;
|
|
225
|
-
this.connected = false;
|
|
226
|
-
if (this.state.opening) {
|
|
227
|
-
this.state.opened = false;
|
|
228
|
-
this.state.closed = true;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
this.state = { opened: false, closed: true, busy: false };
|
|
232
|
-
}
|
|
233
|
-
this.sp.removeAllListeners();
|
|
234
|
-
this.sp = undefined;
|
|
235
|
-
if (this.queue !== undefined)
|
|
236
|
-
this.queue.clear();
|
|
134
|
+
}, 100);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
237
137
|
}
|
|
238
138
|
getLogState() {
|
|
239
139
|
let s = undefined;
|
|
@@ -245,137 +145,53 @@ class Daum8i {
|
|
|
245
145
|
}
|
|
246
146
|
return { sending: s, busy, writeBusy, opening, connecting, waitingForStart, waitingForEnd, waitingForAck, retry };
|
|
247
147
|
}
|
|
148
|
+
onPortClose() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
this.connected = false;
|
|
151
|
+
if (this.sp) {
|
|
152
|
+
this.sp.removeAllListeners();
|
|
153
|
+
this.sp = null;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
248
157
|
onPortError(error) {
|
|
249
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
this.logEvent({ message: "port error:", port: this.
|
|
159
|
+
this.logEvent({ message: "port error:", port: this.path, error: error.message, connected: this.connected, state: this.getLogState() });
|
|
251
160
|
this.error = error;
|
|
252
161
|
if (this.blocked) {
|
|
253
162
|
if (!this.state.closed) {
|
|
254
|
-
yield this.
|
|
163
|
+
yield this.close();
|
|
255
164
|
}
|
|
256
165
|
return;
|
|
257
166
|
}
|
|
258
|
-
if (this.state.
|
|
259
|
-
if (error.message === 'Port is not open') {
|
|
260
|
-
this.state = { opened: false, closed: true, busy: false };
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
yield this.forceClose();
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else if (this.state.opening) {
|
|
268
|
-
if (this.state.connecting) {
|
|
269
|
-
this.state.error = error;
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
this.onPortOpen();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
else if (this.state.sending) {
|
|
167
|
+
if (this.state.sending) {
|
|
276
168
|
if (this.state.sending.reject)
|
|
277
169
|
this.state.sending.reject(error);
|
|
278
170
|
this.writeDone();
|
|
279
|
-
yield this.
|
|
171
|
+
yield this.close();
|
|
280
172
|
return;
|
|
281
173
|
}
|
|
282
174
|
this.state.busy = false;
|
|
283
175
|
});
|
|
284
176
|
}
|
|
285
|
-
errorHandler() {
|
|
286
|
-
throw new Error("Error");
|
|
287
|
-
}
|
|
288
|
-
saveClose(force) {
|
|
289
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
return yield this.close();
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
177
|
forceClose(updateState = false) {
|
|
294
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
-
const sp = this.sp;
|
|
296
179
|
if (!this.sp)
|
|
297
180
|
return;
|
|
298
|
-
this.state.closing = true;
|
|
299
|
-
sp.removeAllListeners();
|
|
300
|
-
sp.on('error', () => { });
|
|
301
181
|
try {
|
|
302
|
-
|
|
303
|
-
sp.flush();
|
|
304
|
-
}
|
|
305
|
-
catch (_a) { }
|
|
306
|
-
try {
|
|
307
|
-
yield this.closePort(1000);
|
|
182
|
+
yield this.close();
|
|
308
183
|
this.writeDone();
|
|
309
184
|
if (this.queue !== undefined)
|
|
310
185
|
this.queue.clear();
|
|
311
186
|
}
|
|
312
|
-
catch (
|
|
187
|
+
catch (_a) { }
|
|
313
188
|
this.connected = false;
|
|
314
189
|
if (updateState)
|
|
315
190
|
this.state = { opened: false, closed: true, busy: false };
|
|
316
191
|
});
|
|
317
192
|
}
|
|
318
|
-
closePort(timeout) {
|
|
319
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
-
return new Promise((resolve, reject) => {
|
|
321
|
-
let isClosed = false;
|
|
322
|
-
const to = setTimeout(() => {
|
|
323
|
-
if (!isClosed)
|
|
324
|
-
resolve(false);
|
|
325
|
-
}, timeout);
|
|
326
|
-
try {
|
|
327
|
-
this.sp.removeAllListeners('close');
|
|
328
|
-
this.sp.removeAllListeners('error');
|
|
329
|
-
}
|
|
330
|
-
catch (err) {
|
|
331
|
-
this.logger.logEvent({ message: 'error', fn: 'closePort()', error: err.message });
|
|
332
|
-
}
|
|
333
|
-
this.sp.on('error', () => { });
|
|
334
|
-
this.sp.on('close', () => {
|
|
335
|
-
clearTimeout(to);
|
|
336
|
-
isClosed = true;
|
|
337
|
-
resolve(true);
|
|
338
|
-
});
|
|
339
|
-
this.sp.close();
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
close() {
|
|
344
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
345
|
-
this.logEvent({ message: 'close request', port: this.portName });
|
|
346
|
-
var sp = this.sp;
|
|
347
|
-
if (!sp) {
|
|
348
|
-
this.state = { opened: false, closed: true, busy: false };
|
|
349
|
-
this.connected = false;
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
let connected = this.connected;
|
|
353
|
-
try {
|
|
354
|
-
if (connected) {
|
|
355
|
-
try {
|
|
356
|
-
sp.removeAllListeners();
|
|
357
|
-
sp.on('error', () => { });
|
|
358
|
-
sp.unpipe();
|
|
359
|
-
sp.flush();
|
|
360
|
-
}
|
|
361
|
-
catch (_a) { }
|
|
362
|
-
}
|
|
363
|
-
yield this.closePort(this.getTimeoutValue());
|
|
364
|
-
this.writeDone();
|
|
365
|
-
if (this.queue !== undefined) {
|
|
366
|
-
this.queue.clear();
|
|
367
|
-
this.queue = undefined;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
catch (err) {
|
|
371
|
-
this.logEvent({ message: 'close: Exception', port: this.portName, error: err.message });
|
|
372
|
-
}
|
|
373
|
-
this.state = { opened: false, closed: true, busy: false };
|
|
374
|
-
this.connected = false;
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
193
|
sendTimeout(message) {
|
|
378
|
-
this.logEvent({ message: `sendCommand:${message || 'timeout'}`, port: this.
|
|
194
|
+
this.logEvent({ message: `sendCommand:${message || 'timeout'}`, port: this.path, cmd: this.cmdCurrent });
|
|
379
195
|
delete this.state.commandsInQueue[this.cmdCurrent.command];
|
|
380
196
|
if (this.cmdCurrent.callbackErr !== undefined) {
|
|
381
197
|
let cb = this.cmdCurrent.callbackErr;
|
|
@@ -415,112 +231,112 @@ class Daum8i {
|
|
|
415
231
|
return false;
|
|
416
232
|
}
|
|
417
233
|
catch (err) {
|
|
418
|
-
this.logEvent({ message: 'checkForResponse: Exception', port: this.
|
|
234
|
+
this.logEvent({ message: 'checkForResponse: Exception', port: this.path, error: err.message, stack: err.stack });
|
|
419
235
|
}
|
|
420
236
|
return true;
|
|
421
237
|
}
|
|
422
238
|
getTimeoutValue(cmd) {
|
|
423
239
|
let timeout = DEFAULT_TIMEOUT;
|
|
424
|
-
if (this.settings && this.settings.
|
|
425
|
-
timeout = this.settings.
|
|
426
|
-
if (this.settings && this.settings.serial && this.settings.serial.timeout)
|
|
427
|
-
timeout = this.settings.serial.timeout;
|
|
240
|
+
if (this.settings && this.settings.timeout)
|
|
241
|
+
timeout = this.settings.timeout;
|
|
428
242
|
if (cmd !== undefined && cmd.options !== undefined && cmd.options.timeout !== undefined) {
|
|
429
243
|
timeout = cmd.options.timeout;
|
|
430
244
|
}
|
|
431
245
|
return timeout;
|
|
432
246
|
}
|
|
433
247
|
onData(data, depth = 0) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data, 'latin1');
|
|
440
|
-
const s = this.state.sending;
|
|
441
|
-
if (s === undefined) {
|
|
442
|
-
this.logEvent({ message: 'onData:IGNORED', data: bufferData.toString('hex') });
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
const { portName, resolve } = this.state.sending;
|
|
446
|
-
let incoming = bufferData;
|
|
447
|
-
this.logEvent({ message: 'sendCommand:RECV', data: (0, utils_1.hexstr)(incoming) });
|
|
448
|
-
for (let i = 0; i < incoming.length; i++) {
|
|
449
|
-
const getRemaining = () => {
|
|
450
|
-
let remaining = '';
|
|
451
|
-
const done = i === (incoming.length - 1);
|
|
452
|
-
if (!done) {
|
|
453
|
-
for (let j = i + 1; j < incoming.length; j++)
|
|
454
|
-
remaining += String.fromCharCode(incoming.readUInt8(j));
|
|
455
|
-
}
|
|
456
|
-
return remaining;
|
|
457
|
-
};
|
|
458
|
-
const c = incoming.readUInt8(i);
|
|
459
|
-
if (c === 0x06) {
|
|
460
|
-
this.state.waitingForStart = true;
|
|
461
|
-
this.state.waitingForACK = false;
|
|
462
|
-
const remaining = getRemaining();
|
|
463
|
-
this.logEvent({ message: "sendCommand:ACK received:", port: portName, remaining: (0, utils_1.hexstr)(remaining) });
|
|
464
|
-
if (remaining && remaining !== '' && depth < MAX_DEPTH)
|
|
465
|
-
return this.onData(remaining, depth + 1);
|
|
466
|
-
}
|
|
467
|
-
else if (c === 0x15) {
|
|
468
|
-
this.state.waitingForStart = true;
|
|
469
|
-
this.state.waitingForACK = false;
|
|
470
|
-
const remaining = getRemaining();
|
|
471
|
-
this.logEvent({ message: "sendCommand:NAK received:", port: portName, remaining: (0, utils_1.hexstr)(remaining) });
|
|
472
|
-
if (remaining && remaining !== '' && depth < MAX_DEPTH)
|
|
473
|
-
return this.onData(remaining, depth + 1);
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
let cmd = '';
|
|
250
|
+
const MAX_DEPTH = 5;
|
|
251
|
+
if (this.state.waitingForEnd) {
|
|
252
|
+
cmd = this.state.partialCmd;
|
|
474
253
|
}
|
|
475
|
-
|
|
476
|
-
|
|
254
|
+
const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data, 'latin1');
|
|
255
|
+
const s = this.state.sending;
|
|
256
|
+
if (s === undefined) {
|
|
257
|
+
this.logEvent({ message: 'onData:IGNORED', data: bufferData.toString('hex') });
|
|
258
|
+
return;
|
|
477
259
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
260
|
+
const { portName, resolve } = this.state.sending;
|
|
261
|
+
let incoming = bufferData;
|
|
262
|
+
this.logEvent({ message: 'sendCommand:RECV', data: (0, utils_1.hexstr)(incoming) });
|
|
263
|
+
for (let i = 0; i < incoming.length; i++) {
|
|
264
|
+
const getRemaining = () => {
|
|
265
|
+
let remaining = '';
|
|
266
|
+
const done = i === (incoming.length - 1);
|
|
267
|
+
if (!done) {
|
|
268
|
+
for (let j = i + 1; j < incoming.length; j++)
|
|
269
|
+
remaining += String.fromCharCode(incoming.readUInt8(j));
|
|
270
|
+
}
|
|
271
|
+
return remaining;
|
|
272
|
+
};
|
|
273
|
+
const c = incoming.readUInt8(i);
|
|
274
|
+
if (c === 0x06) {
|
|
275
|
+
this.state.waitingForStart = true;
|
|
276
|
+
this.state.waitingForACK = false;
|
|
277
|
+
const remaining = getRemaining();
|
|
278
|
+
this.logEvent({ message: "sendCommand:ACK received:", port: portName, remaining: (0, utils_1.hexstr)(remaining) });
|
|
279
|
+
if (remaining && remaining !== '' && depth < MAX_DEPTH)
|
|
280
|
+
return this.onData(remaining, depth + 1);
|
|
483
281
|
}
|
|
484
|
-
else {
|
|
485
|
-
this.
|
|
486
|
-
this.state.
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
waitingForEnd: false,
|
|
501
|
-
waitingForACK: false,
|
|
502
|
-
};
|
|
503
|
-
const payload = cmd.substring(3, cmd.length - 2);
|
|
504
|
-
resolve(payload);
|
|
282
|
+
else if (c === 0x15) {
|
|
283
|
+
this.state.waitingForStart = true;
|
|
284
|
+
this.state.waitingForACK = false;
|
|
285
|
+
const remaining = getRemaining();
|
|
286
|
+
this.logEvent({ message: "sendCommand:NAK received:", port: portName, remaining: (0, utils_1.hexstr)(remaining) });
|
|
287
|
+
if (remaining && remaining !== '' && depth < MAX_DEPTH)
|
|
288
|
+
return this.onData(remaining, depth + 1);
|
|
289
|
+
}
|
|
290
|
+
else if (c === 0x01) {
|
|
291
|
+
this.state.waitingForEnd = true;
|
|
292
|
+
}
|
|
293
|
+
else if (c === 0x17) {
|
|
294
|
+
const remaining = getRemaining();
|
|
295
|
+
if (this.state.waitingForACK) {
|
|
296
|
+
this.logEvent({ message: "sendCommand:ignored:", duration: Date.now() - this.state.sending.tsRequest, port: portName, cmd: `${cmd} [${(0, utils_1.hexstr)(cmd)}]`, remaining: (0, utils_1.hexstr)(remaining) });
|
|
297
|
+
this.state.waitingForEnd = false;
|
|
505
298
|
}
|
|
506
299
|
else {
|
|
507
|
-
this.
|
|
300
|
+
this.logEvent({ message: "sendCommand:received:", duration: Date.now() - this.state.sending.tsRequest, port: portName, cmd: `${cmd} [${(0, utils_1.hexstr)(cmd)}]`, remaining: (0, utils_1.hexstr)(remaining) });
|
|
301
|
+
this.state.waitingForEnd = false;
|
|
302
|
+
const cmdStr = cmd.substring(0, cmd.length - 2);
|
|
303
|
+
const checksumExtracted = cmd.slice(-2);
|
|
304
|
+
const checksumCalculated = (0, utils_1.checkSum)((0, utils_1.getAsciiArrayFromStr)(cmdStr), []);
|
|
305
|
+
if (checksumExtracted === checksumCalculated) {
|
|
306
|
+
yield this.sendACK();
|
|
307
|
+
if (this.state.sending && this.state.sending.responseCheckIv) {
|
|
308
|
+
clearInterval(this.state.sending.responseCheckIv);
|
|
309
|
+
}
|
|
310
|
+
this.state = {
|
|
311
|
+
sending: undefined,
|
|
312
|
+
busy: false,
|
|
313
|
+
writeBusy: false,
|
|
314
|
+
waitingForStart: false,
|
|
315
|
+
waitingForEnd: false,
|
|
316
|
+
waitingForACK: false,
|
|
317
|
+
};
|
|
318
|
+
const payload = cmd.substring(3, cmd.length - 2);
|
|
319
|
+
resolve(payload);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
yield this.sendNAK();
|
|
323
|
+
}
|
|
508
324
|
}
|
|
325
|
+
cmd = '';
|
|
326
|
+
if (remaining && depth < 5)
|
|
327
|
+
return this.onData(remaining, depth + 1);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
if (this.state.waitingForEnd)
|
|
331
|
+
cmd += String.fromCharCode(c);
|
|
509
332
|
}
|
|
510
|
-
cmd = '';
|
|
511
|
-
if (remaining && depth < 5)
|
|
512
|
-
return this.onData(remaining, depth + 1);
|
|
513
333
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
cmd += String.fromCharCode(c);
|
|
334
|
+
if (this.state.waitingForEnd) {
|
|
335
|
+
this.state.partialCmd = cmd;
|
|
517
336
|
}
|
|
518
|
-
}
|
|
519
|
-
if (this.state.waitingForEnd) {
|
|
520
|
-
this.state.partialCmd = cmd;
|
|
521
|
-
}
|
|
337
|
+
});
|
|
522
338
|
}
|
|
523
|
-
sendDaum8iCommand(command,
|
|
339
|
+
sendDaum8iCommand(command, payload = '') {
|
|
524
340
|
const tsRequest = Date.now();
|
|
525
341
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
526
342
|
if (this.blocked)
|
|
@@ -530,7 +346,7 @@ class Daum8i {
|
|
|
530
346
|
}
|
|
531
347
|
else {
|
|
532
348
|
const message = (0, utils_1.buildMessage)(command, payload);
|
|
533
|
-
this.logEvent({ message: 'sendCommand:waiting', port: this.
|
|
349
|
+
this.logEvent({ message: 'sendCommand:waiting', port: this.path, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
534
350
|
const busyWait = () => {
|
|
535
351
|
return new Promise((done) => {
|
|
536
352
|
let start = Date.now();
|
|
@@ -551,26 +367,26 @@ class Daum8i {
|
|
|
551
367
|
};
|
|
552
368
|
const res = yield busyWait();
|
|
553
369
|
if (!res) {
|
|
554
|
-
this.logEvent({ message: 'sendCommand:busy timeout', port: this.
|
|
370
|
+
this.logEvent({ message: 'sendCommand:busy timeout', port: this.path, cmd: command, hex: (0, utils_1.hexstr)(message), duration: Date.now() - tsRequest });
|
|
555
371
|
return reject(new Error('BUSY timeout'));
|
|
556
372
|
}
|
|
557
373
|
this.state.busy = true;
|
|
558
374
|
}
|
|
559
375
|
const port = this.sp;
|
|
560
|
-
const portName = this.
|
|
376
|
+
const portName = this.path;
|
|
561
377
|
this.state.received = [];
|
|
562
378
|
try {
|
|
563
379
|
const message = (0, utils_1.buildMessage)(command, payload);
|
|
564
380
|
const start = Date.now();
|
|
565
381
|
const timeout = start + this.getTimeoutValue();
|
|
566
|
-
this.logEvent({ message: "sendCommand:sending:", port: this.
|
|
382
|
+
this.logEvent({ message: "sendCommand:sending:", port: this.path, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
567
383
|
this.state.writeBusy = true;
|
|
568
384
|
if (!this.connected || port === undefined) {
|
|
569
|
-
this.logEvent({ message: "sendCommand:error: not connected", port: this.
|
|
385
|
+
this.logEvent({ message: "sendCommand:error: not connected", port: this.path });
|
|
570
386
|
this.writeDone();
|
|
571
387
|
return reject(new Error('not connected'));
|
|
572
388
|
}
|
|
573
|
-
|
|
389
|
+
yield this.write(Buffer.from(message));
|
|
574
390
|
this.state.waitingForACK = true;
|
|
575
391
|
this.state.writeBusy = false;
|
|
576
392
|
this.state.retry = 0;
|
|
@@ -603,25 +419,36 @@ class Daum8i {
|
|
|
603
419
|
this.state.waitingForEnd = false;
|
|
604
420
|
this.state.waitingForACK = false;
|
|
605
421
|
}
|
|
422
|
+
write(buffer) {
|
|
423
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
+
return new Promise(done => {
|
|
425
|
+
this.state.writeBusy = true;
|
|
426
|
+
try {
|
|
427
|
+
this.sp.write(buffer, () => {
|
|
428
|
+
this.state.writeBusy = false;
|
|
429
|
+
done();
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
catch (err) {
|
|
433
|
+
this.state.writeBusy = false;
|
|
434
|
+
done();
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
}
|
|
606
439
|
sendACK() {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
catch (err) { }
|
|
613
|
-
this.state.writeBusy = false;
|
|
614
|
-
this.logEvent({ message: "sendCommand:sending ACK", port, queue: this.state.commandsInQueue });
|
|
440
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
441
|
+
this.logEvent({ message: "sendCommand:sending ACK", port: this.path, queue: this.state.commandsInQueue });
|
|
442
|
+
yield this.write(Buffer.from([0x06]));
|
|
443
|
+
});
|
|
615
444
|
}
|
|
616
445
|
sendNAK() {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
this.
|
|
620
|
-
}
|
|
621
|
-
catch (err) { }
|
|
622
|
-
this.logEvent({ message: "sendCommand:sending NAK", port });
|
|
446
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
447
|
+
this.logEvent({ message: "sendCommand:sending NAK", port: this.path, queue: this.state.commandsInQueue });
|
|
448
|
+
yield this.write(Buffer.from([0x15]));
|
|
449
|
+
});
|
|
623
450
|
}
|
|
624
|
-
sendReservedDaum8iCommand(command,
|
|
451
|
+
sendReservedDaum8iCommand(command, data) {
|
|
625
452
|
let buffer;
|
|
626
453
|
if (data !== undefined && data.length > 0) {
|
|
627
454
|
buffer = Buffer.alloc(data.length + 4);
|
|
@@ -635,28 +462,25 @@ class Daum8i {
|
|
|
635
462
|
buffer.writeUInt16LE(0, 2);
|
|
636
463
|
}
|
|
637
464
|
const cmdData = Uint8Array.from(buffer);
|
|
638
|
-
return this.sendDaum8iCommand('M70',
|
|
465
|
+
return this.sendDaum8iCommand('M70', (0, utils_1.bin2esc)(cmdData))
|
|
639
466
|
.then((res) => {
|
|
640
467
|
const resData = Uint8Array.from(res, x => x.charCodeAt(0));
|
|
641
468
|
const cmd = (0, utils_1.esc2bin)(resData);
|
|
642
469
|
return cmd;
|
|
643
470
|
});
|
|
644
471
|
}
|
|
645
|
-
stopWorker() {
|
|
646
|
-
this.logEvent({ message: "stop worker", port: this.getPort() });
|
|
647
|
-
}
|
|
648
472
|
getProtocolVersion() {
|
|
649
|
-
return this.sendDaum8iCommand('V00'
|
|
473
|
+
return this.sendDaum8iCommand('V00')
|
|
650
474
|
.then((data) => {
|
|
651
475
|
const version = data.substring(0, 1) + '.' + data.substring(1);
|
|
652
476
|
return (version);
|
|
653
477
|
});
|
|
654
478
|
}
|
|
655
479
|
getDashboardVersion() {
|
|
656
|
-
return this.sendDaum8iCommand('V70'
|
|
480
|
+
return this.sendDaum8iCommand('V70');
|
|
657
481
|
}
|
|
658
482
|
getDeviceType() {
|
|
659
|
-
return this.sendDaum8iCommand('Y00'
|
|
483
|
+
return this.sendDaum8iCommand('Y00')
|
|
660
484
|
.then((str) => {
|
|
661
485
|
let deviceType;
|
|
662
486
|
if (str === '0')
|
|
@@ -666,12 +490,12 @@ class Daum8i {
|
|
|
666
490
|
else if (str === '7')
|
|
667
491
|
deviceType = 'lyps';
|
|
668
492
|
else
|
|
669
|
-
throw (new Error(`unknown device type ${typeof str === 'string' ? (0, utils_1.ascii)(str
|
|
493
|
+
throw (new Error(`unknown device type ${typeof str === 'string' ? str : (0, utils_1.ascii)(str)}`));
|
|
670
494
|
return deviceType;
|
|
671
495
|
});
|
|
672
496
|
}
|
|
673
497
|
getActualBikeType() {
|
|
674
|
-
return this.sendDaum8iCommand('M72'
|
|
498
|
+
return this.sendDaum8iCommand('M72')
|
|
675
499
|
.then((str) => {
|
|
676
500
|
let deviceType;
|
|
677
501
|
if (str === '0')
|
|
@@ -705,7 +529,7 @@ class Daum8i {
|
|
|
705
529
|
default:
|
|
706
530
|
bikeType = undefined;
|
|
707
531
|
}
|
|
708
|
-
return this.sendDaum8iCommand(`M72${bikeType}
|
|
532
|
+
return this.sendDaum8iCommand(`M72${bikeType}`)
|
|
709
533
|
.then((str) => {
|
|
710
534
|
let deviceType;
|
|
711
535
|
if (str === '0')
|
|
@@ -721,7 +545,7 @@ class Daum8i {
|
|
|
721
545
|
});
|
|
722
546
|
}
|
|
723
547
|
getTrainingData() {
|
|
724
|
-
return this.sendDaum8iCommand('X70'
|
|
548
|
+
return this.sendDaum8iCommand('X70')
|
|
725
549
|
.then((data) => {
|
|
726
550
|
const td = (0, utils_1.parseTrainingData)(data);
|
|
727
551
|
return td;
|
|
@@ -729,32 +553,28 @@ class Daum8i {
|
|
|
729
553
|
}
|
|
730
554
|
setLoadControl(enabled) {
|
|
731
555
|
const val = enabled ? (0, utils_1.ascii)('1') : (0, utils_1.ascii)('0');
|
|
732
|
-
return this.sendDaum8iCommand('S20',
|
|
556
|
+
return this.sendDaum8iCommand('S20', [val])
|
|
733
557
|
.then((data) => {
|
|
734
558
|
const res = data === '1';
|
|
735
559
|
return res;
|
|
736
560
|
});
|
|
737
561
|
}
|
|
738
562
|
getLoadControl() {
|
|
739
|
-
return this.sendDaum8iCommand('S20'
|
|
563
|
+
return this.sendDaum8iCommand('S20')
|
|
740
564
|
.then((data) => {
|
|
741
565
|
const res = data === '1';
|
|
742
566
|
return res;
|
|
743
567
|
});
|
|
744
568
|
}
|
|
745
|
-
setSlope(slope) {
|
|
746
|
-
this.logEvent({ message: 'setSlope not implemted' });
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
569
|
setPower(power) {
|
|
750
570
|
const powerStr = Number.parseFloat(power).toFixed(2);
|
|
751
|
-
return this.sendDaum8iCommand(`S23${powerStr}
|
|
571
|
+
return this.sendDaum8iCommand(`S23${powerStr}`)
|
|
752
572
|
.then((str) => {
|
|
753
573
|
return parseInt(str);
|
|
754
574
|
});
|
|
755
575
|
}
|
|
756
576
|
getPower(power) {
|
|
757
|
-
return this.sendDaum8iCommand('S23'
|
|
577
|
+
return this.sendDaum8iCommand('S23')
|
|
758
578
|
.then((str) => {
|
|
759
579
|
return parseInt(str);
|
|
760
580
|
});
|
|
@@ -762,7 +582,7 @@ class Daum8i {
|
|
|
762
582
|
setPerson(person) {
|
|
763
583
|
const { sex, age, length, weight } = person;
|
|
764
584
|
this.logEvent({ message: 'setPerson() request', sex, age, length, weight });
|
|
765
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET,
|
|
585
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, (0, utils_1.getPersonData)(person))
|
|
766
586
|
.then((res) => {
|
|
767
587
|
const buffer = Buffer.from(res);
|
|
768
588
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PERSON_SET;
|
|
@@ -774,7 +594,7 @@ class Daum8i {
|
|
|
774
594
|
}
|
|
775
595
|
programUploadInit() {
|
|
776
596
|
this.logEvent({ message: 'programUploadInit() request' });
|
|
777
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN
|
|
597
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN)
|
|
778
598
|
.then((res) => {
|
|
779
599
|
const buffer = Buffer.from(res);
|
|
780
600
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_BEGIN;
|
|
@@ -805,7 +625,7 @@ class Daum8i {
|
|
|
805
625
|
payload.writeInt32LE(7, 32);
|
|
806
626
|
payload.writeInt32LE(eppLength, 36);
|
|
807
627
|
this.logEvent({ message: 'programUploadStart() request', bikeType, length: eppLength });
|
|
808
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM,
|
|
628
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, payload)
|
|
809
629
|
.then((res) => {
|
|
810
630
|
const buffer = Buffer.from(res);
|
|
811
631
|
if (buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM) {
|
|
@@ -827,7 +647,7 @@ class Daum8i {
|
|
|
827
647
|
const chunk = Buffer.from(epp.slice(offset, offset + size));
|
|
828
648
|
chunk.copy(payload, 8);
|
|
829
649
|
this.logEvent({ message: 'programUploadSendBlock() request', offset, size });
|
|
830
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM,
|
|
650
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM, payload)
|
|
831
651
|
.then((res) => {
|
|
832
652
|
const buffer = Buffer.from(res);
|
|
833
653
|
let success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM;
|
|
@@ -842,7 +662,7 @@ class Daum8i {
|
|
|
842
662
|
}
|
|
843
663
|
programUploadDone() {
|
|
844
664
|
this.logEvent({ message: 'programUploadDone() request' });
|
|
845
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END
|
|
665
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END)
|
|
846
666
|
.then((res) => {
|
|
847
667
|
const buffer = Buffer.from(res);
|
|
848
668
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_END;
|
|
@@ -881,6 +701,7 @@ class Daum8i {
|
|
|
881
701
|
}
|
|
882
702
|
catch (err) {
|
|
883
703
|
console.log('~~~ err', err);
|
|
704
|
+
return false;
|
|
884
705
|
}
|
|
885
706
|
return false;
|
|
886
707
|
});
|
|
@@ -889,7 +710,7 @@ class Daum8i {
|
|
|
889
710
|
const payload = Buffer.alloc(2);
|
|
890
711
|
payload.writeInt16LE(programId, 0);
|
|
891
712
|
this.logEvent({ message: 'startProgram() request', programId });
|
|
892
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START,
|
|
713
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START, payload)
|
|
893
714
|
.then((res) => {
|
|
894
715
|
const buffer = Buffer.from(res);
|
|
895
716
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_START;
|
|
@@ -901,42 +722,16 @@ class Daum8i {
|
|
|
901
722
|
});
|
|
902
723
|
}
|
|
903
724
|
setGear(gear) {
|
|
904
|
-
return this.sendDaum8iCommand(
|
|
725
|
+
return this.sendDaum8iCommand(`M71${gear}`)
|
|
905
726
|
.then((str) => {
|
|
906
|
-
|
|
907
|
-
return gearVal > 0 ? gearVal - 1 : undefined;
|
|
727
|
+
return parseInt(str);
|
|
908
728
|
});
|
|
909
729
|
}
|
|
910
730
|
getGear() {
|
|
911
|
-
return this.sendDaum8iCommand('M71'
|
|
731
|
+
return this.sendDaum8iCommand('M71')
|
|
912
732
|
.then((str) => {
|
|
913
733
|
return parseInt(str);
|
|
914
734
|
});
|
|
915
735
|
}
|
|
916
736
|
}
|
|
917
|
-
|
|
918
|
-
static getClassName() { return "Daum8i"; }
|
|
919
|
-
getType() { return "Daum8iTcp"; }
|
|
920
|
-
static setSerialPort(spClass) { }
|
|
921
|
-
getInterface() { return constants_1.BIKE_INTERFACE.TCPIP; }
|
|
922
|
-
static setNetImpl(netClass) {
|
|
923
|
-
net = netClass;
|
|
924
|
-
}
|
|
925
|
-
static getSupportedInterfaces() {
|
|
926
|
-
return [constants_1.BIKE_INTERFACE.TCPIP];
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
exports.Daum8iTcp = Daum8iTcp;
|
|
930
|
-
class Daum8iSerial extends Daum8i {
|
|
931
|
-
static getClassName() { return "Daum8i"; }
|
|
932
|
-
getType() { return "Daum8iSerial"; }
|
|
933
|
-
getInterface() { return constants_1.BIKE_INTERFACE.SERIAL; }
|
|
934
|
-
static setSerialPort(spClass) {
|
|
935
|
-
__SerialPort = spClass;
|
|
936
|
-
}
|
|
937
|
-
static setNetImpl(netClass) { }
|
|
938
|
-
static getSupportedInterfaces() {
|
|
939
|
-
return [constants_1.BIKE_INTERFACE.SERIAL];
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
exports.Daum8iSerial = Daum8iSerial;
|
|
737
|
+
exports.default = Daum8i;
|