incyclist-devices 1.5.38 → 2.0.0-beta.1
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 +0 -0
- package/lib/adapters.d.ts +6 -0
- package/lib/adapters.js +30 -0
- package/lib/antv2/adapter-factory.d.ts +20 -10
- package/lib/antv2/adapter-factory.js +49 -33
- package/lib/antv2/adapter.d.ts +64 -0
- package/lib/antv2/adapter.js +299 -0
- package/lib/antv2/ant-interface.d.ts +11 -9
- package/lib/antv2/ant-interface.js +15 -11
- package/lib/antv2/fe/adapter.d.ts +25 -0
- package/lib/antv2/{fe.js → fe/adapter.js} +48 -72
- package/lib/antv2/fe/index.d.ts +2 -0
- package/lib/antv2/fe/index.js +7 -0
- package/lib/antv2/hr/adapter.d.ts +14 -0
- package/lib/antv2/hr/adapter.js +73 -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 +22 -0
- package/lib/antv2/{pwr.js → pwr/adapter.js} +38 -76
- package/lib/antv2/pwr/index.d.ts +2 -0
- package/lib/antv2/pwr/index.js +7 -0
- package/lib/antv2/types.d.ts +19 -0
- package/lib/antv2/types.js +2 -0
- package/lib/antv2/utils.d.ts +1 -0
- package/lib/antv2/utils.js +181 -0
- package/lib/base/adpater.d.ts +56 -0
- package/lib/base/adpater.js +144 -0
- package/lib/ble/adapter-factory.d.ts +31 -0
- package/lib/ble/adapter-factory.js +96 -0
- package/lib/ble/adapter.d.ts +41 -0
- package/lib/ble/adapter.js +188 -0
- package/lib/ble/{ble-device.d.ts → ble-comms.d.ts} +9 -4
- package/lib/ble/{ble-device.js → ble-comms.js} +23 -11
- package/lib/ble/ble-interface.d.ts +15 -24
- package/lib/ble/ble-interface.js +32 -137
- package/lib/ble/ble-peripheral.d.ts +3 -3
- package/lib/ble/ble-peripheral.js +14 -14
- package/lib/ble/ble.d.ts +9 -81
- package/lib/ble/ble.js +1 -39
- package/lib/ble/consts.d.ts +2 -0
- package/lib/ble/consts.js +3 -1
- package/lib/ble/cp/adapter.d.ts +23 -0
- package/lib/ble/cp/adapter.js +124 -0
- package/lib/ble/cp/comm.d.ts +28 -0
- package/lib/ble/cp/comm.js +140 -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 +20 -0
- package/lib/ble/elite/adapter.js +127 -0
- package/lib/ble/elite/comms.d.ts +28 -0
- package/lib/ble/elite/comms.js +139 -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 +21 -0
- package/lib/ble/fm/adapter.js +190 -0
- package/lib/ble/fm/comms.d.ts +50 -0
- package/lib/ble/{fm.js → fm/comms.js} +3 -224
- 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 +25 -0
- package/lib/ble/fm/types.js +2 -0
- package/lib/ble/hr/adapter.d.ts +17 -0
- package/lib/ble/hr/adapter.js +62 -0
- package/lib/ble/hr/comm.d.ts +15 -0
- package/lib/ble/hr/comm.js +52 -0
- package/lib/ble/hr/index.d.ts +4 -0
- package/lib/ble/hr/index.js +10 -0
- package/lib/ble/hr/types.d.ts +5 -0
- package/lib/ble/hr/types.js +2 -0
- package/lib/ble/index.d.ts +8 -0
- package/lib/ble/index.js +26 -0
- package/lib/ble/tacx/adapter.d.ts +10 -0
- package/lib/ble/tacx/adapter.js +93 -0
- package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +6 -38
- package/lib/ble/{tacx.js → tacx/comms.js} +13 -112
- 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 +101 -0
- package/lib/ble/types.js +19 -0
- package/lib/ble/utils.d.ts +7 -0
- package/lib/ble/utils.js +95 -0
- package/lib/ble/wahoo/adapter.d.ts +9 -0
- package/lib/ble/wahoo/adapter.js +93 -0
- package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +5 -39
- package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +14 -112
- 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/device.d.ts +0 -94
- package/lib/device.js +0 -76
- package/lib/index.d.ts +12 -0
- package/lib/index.js +38 -0
- package/lib/interfaces.d.ts +6 -0
- package/lib/interfaces.js +23 -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 +4 -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 +16 -0
- package/lib/serial/adapter.js +42 -0
- package/lib/serial/bindings/tcp.d.ts +44 -0
- package/lib/serial/bindings/tcp.js +270 -0
- package/lib/serial/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/{daum → serial/daum}/DaumAdapter.d.ts +13 -22
- package/lib/{daum → serial/daum}/DaumAdapter.js +44 -90
- 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 +24 -0
- package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +99 -46
- 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} +208 -420
- package/lib/serial/daum/premium/mock.d.ts +75 -0
- package/lib/serial/daum/premium/mock.js +290 -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 +13 -24
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +87 -130
- 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 +58 -0
- package/lib/serial/serial-interface.js +283 -0
- package/lib/simulator/Simulator.d.ts +10 -25
- package/lib/simulator/Simulator.js +19 -83
- package/lib/types/adapter.d.ts +32 -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 +29 -0
- package/lib/types/device.js +11 -0
- package/lib/types/interface.d.ts +14 -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 +15 -11
- 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/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/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/antv2/{ant-binding.d.ts → binding.d.ts} +0 -0
- /package/lib/antv2/{ant-binding.js → binding.js} +0 -0
- /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,49 @@ 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
|
+
yield this.close();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
248
153
|
onPortError(error) {
|
|
249
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
this.logEvent({ message: "port error:", port: this.
|
|
155
|
+
this.logEvent({ message: "port error:", port: this.path, error: error.message, connected: this.connected, state: this.getLogState() });
|
|
251
156
|
this.error = error;
|
|
252
157
|
if (this.blocked) {
|
|
253
158
|
if (!this.state.closed) {
|
|
254
|
-
yield this.
|
|
159
|
+
yield this.close();
|
|
255
160
|
}
|
|
256
161
|
return;
|
|
257
162
|
}
|
|
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) {
|
|
163
|
+
if (this.state.sending) {
|
|
276
164
|
if (this.state.sending.reject)
|
|
277
165
|
this.state.sending.reject(error);
|
|
278
166
|
this.writeDone();
|
|
279
|
-
yield this.
|
|
167
|
+
yield this.close();
|
|
280
168
|
return;
|
|
281
169
|
}
|
|
282
170
|
this.state.busy = false;
|
|
283
171
|
});
|
|
284
172
|
}
|
|
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
173
|
forceClose(updateState = false) {
|
|
294
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
-
const sp = this.sp;
|
|
296
175
|
if (!this.sp)
|
|
297
176
|
return;
|
|
298
|
-
this.state.closing = true;
|
|
299
|
-
sp.removeAllListeners();
|
|
300
|
-
sp.on('error', () => { });
|
|
301
177
|
try {
|
|
302
|
-
|
|
303
|
-
sp.flush();
|
|
304
|
-
}
|
|
305
|
-
catch (_a) { }
|
|
306
|
-
try {
|
|
307
|
-
yield this.closePort(1000);
|
|
178
|
+
yield this.close();
|
|
308
179
|
this.writeDone();
|
|
309
180
|
if (this.queue !== undefined)
|
|
310
181
|
this.queue.clear();
|
|
311
182
|
}
|
|
312
|
-
catch (
|
|
183
|
+
catch (_a) { }
|
|
313
184
|
this.connected = false;
|
|
314
185
|
if (updateState)
|
|
315
186
|
this.state = { opened: false, closed: true, busy: false };
|
|
316
187
|
});
|
|
317
188
|
}
|
|
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
189
|
sendTimeout(message) {
|
|
378
|
-
this.logEvent({ message: `sendCommand:${message || 'timeout'}`, port: this.
|
|
190
|
+
this.logEvent({ message: `sendCommand:${message || 'timeout'}`, port: this.path, cmd: this.cmdCurrent });
|
|
379
191
|
delete this.state.commandsInQueue[this.cmdCurrent.command];
|
|
380
192
|
if (this.cmdCurrent.callbackErr !== undefined) {
|
|
381
193
|
let cb = this.cmdCurrent.callbackErr;
|
|
@@ -415,112 +227,112 @@ class Daum8i {
|
|
|
415
227
|
return false;
|
|
416
228
|
}
|
|
417
229
|
catch (err) {
|
|
418
|
-
this.logEvent({ message: 'checkForResponse: Exception', port: this.
|
|
230
|
+
this.logEvent({ message: 'checkForResponse: Exception', port: this.path, error: err.message, stack: err.stack });
|
|
419
231
|
}
|
|
420
232
|
return true;
|
|
421
233
|
}
|
|
422
234
|
getTimeoutValue(cmd) {
|
|
423
235
|
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;
|
|
236
|
+
if (this.settings && this.settings.timeout)
|
|
237
|
+
timeout = this.settings.timeout;
|
|
428
238
|
if (cmd !== undefined && cmd.options !== undefined && cmd.options.timeout !== undefined) {
|
|
429
239
|
timeout = cmd.options.timeout;
|
|
430
240
|
}
|
|
431
241
|
return timeout;
|
|
432
242
|
}
|
|
433
243
|
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);
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
let cmd = '';
|
|
246
|
+
const MAX_DEPTH = 5;
|
|
247
|
+
if (this.state.waitingForEnd) {
|
|
248
|
+
cmd = this.state.partialCmd;
|
|
474
249
|
}
|
|
475
|
-
|
|
476
|
-
|
|
250
|
+
const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data, 'latin1');
|
|
251
|
+
const s = this.state.sending;
|
|
252
|
+
if (s === undefined) {
|
|
253
|
+
this.logEvent({ message: 'onData:IGNORED', data: bufferData.toString('hex') });
|
|
254
|
+
return;
|
|
477
255
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
256
|
+
const { portName, resolve } = this.state.sending;
|
|
257
|
+
let incoming = bufferData;
|
|
258
|
+
this.logEvent({ message: 'sendCommand:RECV', data: (0, utils_1.hexstr)(incoming) });
|
|
259
|
+
for (let i = 0; i < incoming.length; i++) {
|
|
260
|
+
const getRemaining = () => {
|
|
261
|
+
let remaining = '';
|
|
262
|
+
const done = i === (incoming.length - 1);
|
|
263
|
+
if (!done) {
|
|
264
|
+
for (let j = i + 1; j < incoming.length; j++)
|
|
265
|
+
remaining += String.fromCharCode(incoming.readUInt8(j));
|
|
266
|
+
}
|
|
267
|
+
return remaining;
|
|
268
|
+
};
|
|
269
|
+
const c = incoming.readUInt8(i);
|
|
270
|
+
if (c === 0x06) {
|
|
271
|
+
this.state.waitingForStart = true;
|
|
272
|
+
this.state.waitingForACK = false;
|
|
273
|
+
const remaining = getRemaining();
|
|
274
|
+
this.logEvent({ message: "sendCommand:ACK received:", port: portName, remaining: (0, utils_1.hexstr)(remaining) });
|
|
275
|
+
if (remaining && remaining !== '' && depth < MAX_DEPTH)
|
|
276
|
+
return this.onData(remaining, depth + 1);
|
|
483
277
|
}
|
|
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);
|
|
278
|
+
else if (c === 0x15) {
|
|
279
|
+
this.state.waitingForStart = true;
|
|
280
|
+
this.state.waitingForACK = false;
|
|
281
|
+
const remaining = getRemaining();
|
|
282
|
+
this.logEvent({ message: "sendCommand:NAK received:", port: portName, remaining: (0, utils_1.hexstr)(remaining) });
|
|
283
|
+
if (remaining && remaining !== '' && depth < MAX_DEPTH)
|
|
284
|
+
return this.onData(remaining, depth + 1);
|
|
285
|
+
}
|
|
286
|
+
else if (c === 0x01) {
|
|
287
|
+
this.state.waitingForEnd = true;
|
|
288
|
+
}
|
|
289
|
+
else if (c === 0x17) {
|
|
290
|
+
const remaining = getRemaining();
|
|
291
|
+
if (this.state.waitingForACK) {
|
|
292
|
+
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) });
|
|
293
|
+
this.state.waitingForEnd = false;
|
|
505
294
|
}
|
|
506
295
|
else {
|
|
507
|
-
this.
|
|
296
|
+
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) });
|
|
297
|
+
this.state.waitingForEnd = false;
|
|
298
|
+
const cmdStr = cmd.substring(0, cmd.length - 2);
|
|
299
|
+
const checksumExtracted = cmd.slice(-2);
|
|
300
|
+
const checksumCalculated = (0, utils_1.checkSum)((0, utils_1.getAsciiArrayFromStr)(cmdStr), []);
|
|
301
|
+
if (checksumExtracted === checksumCalculated) {
|
|
302
|
+
yield this.sendACK();
|
|
303
|
+
if (this.state.sending && this.state.sending.responseCheckIv) {
|
|
304
|
+
clearInterval(this.state.sending.responseCheckIv);
|
|
305
|
+
}
|
|
306
|
+
this.state = {
|
|
307
|
+
sending: undefined,
|
|
308
|
+
busy: false,
|
|
309
|
+
writeBusy: false,
|
|
310
|
+
waitingForStart: false,
|
|
311
|
+
waitingForEnd: false,
|
|
312
|
+
waitingForACK: false,
|
|
313
|
+
};
|
|
314
|
+
const payload = cmd.substring(3, cmd.length - 2);
|
|
315
|
+
resolve(payload);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
yield this.sendNAK();
|
|
319
|
+
}
|
|
508
320
|
}
|
|
321
|
+
cmd = '';
|
|
322
|
+
if (remaining && depth < 5)
|
|
323
|
+
return this.onData(remaining, depth + 1);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
if (this.state.waitingForEnd)
|
|
327
|
+
cmd += String.fromCharCode(c);
|
|
509
328
|
}
|
|
510
|
-
cmd = '';
|
|
511
|
-
if (remaining && depth < 5)
|
|
512
|
-
return this.onData(remaining, depth + 1);
|
|
513
329
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
cmd += String.fromCharCode(c);
|
|
330
|
+
if (this.state.waitingForEnd) {
|
|
331
|
+
this.state.partialCmd = cmd;
|
|
517
332
|
}
|
|
518
|
-
}
|
|
519
|
-
if (this.state.waitingForEnd) {
|
|
520
|
-
this.state.partialCmd = cmd;
|
|
521
|
-
}
|
|
333
|
+
});
|
|
522
334
|
}
|
|
523
|
-
sendDaum8iCommand(command,
|
|
335
|
+
sendDaum8iCommand(command, payload = '') {
|
|
524
336
|
const tsRequest = Date.now();
|
|
525
337
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
526
338
|
if (this.blocked)
|
|
@@ -530,7 +342,7 @@ class Daum8i {
|
|
|
530
342
|
}
|
|
531
343
|
else {
|
|
532
344
|
const message = (0, utils_1.buildMessage)(command, payload);
|
|
533
|
-
this.logEvent({ message: 'sendCommand:waiting', port: this.
|
|
345
|
+
this.logEvent({ message: 'sendCommand:waiting', port: this.path, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
534
346
|
const busyWait = () => {
|
|
535
347
|
return new Promise((done) => {
|
|
536
348
|
let start = Date.now();
|
|
@@ -551,26 +363,26 @@ class Daum8i {
|
|
|
551
363
|
};
|
|
552
364
|
const res = yield busyWait();
|
|
553
365
|
if (!res) {
|
|
554
|
-
this.logEvent({ message: 'sendCommand:busy timeout', port: this.
|
|
366
|
+
this.logEvent({ message: 'sendCommand:busy timeout', port: this.path, cmd: command, hex: (0, utils_1.hexstr)(message), duration: Date.now() - tsRequest });
|
|
555
367
|
return reject(new Error('BUSY timeout'));
|
|
556
368
|
}
|
|
557
369
|
this.state.busy = true;
|
|
558
370
|
}
|
|
559
371
|
const port = this.sp;
|
|
560
|
-
const portName = this.
|
|
372
|
+
const portName = this.path;
|
|
561
373
|
this.state.received = [];
|
|
562
374
|
try {
|
|
563
375
|
const message = (0, utils_1.buildMessage)(command, payload);
|
|
564
376
|
const start = Date.now();
|
|
565
377
|
const timeout = start + this.getTimeoutValue();
|
|
566
|
-
this.logEvent({ message: "sendCommand:sending:", port: this.
|
|
378
|
+
this.logEvent({ message: "sendCommand:sending:", port: this.path, cmd: command, hex: (0, utils_1.hexstr)(message) });
|
|
567
379
|
this.state.writeBusy = true;
|
|
568
380
|
if (!this.connected || port === undefined) {
|
|
569
|
-
this.logEvent({ message: "sendCommand:error: not connected", port: this.
|
|
381
|
+
this.logEvent({ message: "sendCommand:error: not connected", port: this.path });
|
|
570
382
|
this.writeDone();
|
|
571
383
|
return reject(new Error('not connected'));
|
|
572
384
|
}
|
|
573
|
-
|
|
385
|
+
yield this.write(Buffer.from(message));
|
|
574
386
|
this.state.waitingForACK = true;
|
|
575
387
|
this.state.writeBusy = false;
|
|
576
388
|
this.state.retry = 0;
|
|
@@ -603,25 +415,33 @@ class Daum8i {
|
|
|
603
415
|
this.state.waitingForEnd = false;
|
|
604
416
|
this.state.waitingForACK = false;
|
|
605
417
|
}
|
|
418
|
+
write(buffer) {
|
|
419
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
return new Promise(done => {
|
|
421
|
+
this.state.writeBusy = true;
|
|
422
|
+
try {
|
|
423
|
+
this.sp.write(buffer, () => {
|
|
424
|
+
this.state.writeBusy = false;
|
|
425
|
+
done();
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
catch (err) { }
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
}
|
|
606
432
|
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 });
|
|
433
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
434
|
+
this.logEvent({ message: "sendCommand:sending ACK", port: this.path, queue: this.state.commandsInQueue });
|
|
435
|
+
yield this.write(Buffer.from([0x06]));
|
|
436
|
+
});
|
|
615
437
|
}
|
|
616
438
|
sendNAK() {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
this.
|
|
620
|
-
}
|
|
621
|
-
catch (err) { }
|
|
622
|
-
this.logEvent({ message: "sendCommand:sending NAK", port });
|
|
439
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
440
|
+
this.logEvent({ message: "sendCommand:sending NAK", port: this.path, queue: this.state.commandsInQueue });
|
|
441
|
+
yield this.write(Buffer.from([0x15]));
|
|
442
|
+
});
|
|
623
443
|
}
|
|
624
|
-
sendReservedDaum8iCommand(command,
|
|
444
|
+
sendReservedDaum8iCommand(command, data) {
|
|
625
445
|
let buffer;
|
|
626
446
|
if (data !== undefined && data.length > 0) {
|
|
627
447
|
buffer = Buffer.alloc(data.length + 4);
|
|
@@ -635,28 +455,25 @@ class Daum8i {
|
|
|
635
455
|
buffer.writeUInt16LE(0, 2);
|
|
636
456
|
}
|
|
637
457
|
const cmdData = Uint8Array.from(buffer);
|
|
638
|
-
return this.sendDaum8iCommand('M70',
|
|
458
|
+
return this.sendDaum8iCommand('M70', (0, utils_1.bin2esc)(cmdData))
|
|
639
459
|
.then((res) => {
|
|
640
460
|
const resData = Uint8Array.from(res, x => x.charCodeAt(0));
|
|
641
461
|
const cmd = (0, utils_1.esc2bin)(resData);
|
|
642
462
|
return cmd;
|
|
643
463
|
});
|
|
644
464
|
}
|
|
645
|
-
stopWorker() {
|
|
646
|
-
this.logEvent({ message: "stop worker", port: this.getPort() });
|
|
647
|
-
}
|
|
648
465
|
getProtocolVersion() {
|
|
649
|
-
return this.sendDaum8iCommand('V00'
|
|
466
|
+
return this.sendDaum8iCommand('V00')
|
|
650
467
|
.then((data) => {
|
|
651
468
|
const version = data.substring(0, 1) + '.' + data.substring(1);
|
|
652
469
|
return (version);
|
|
653
470
|
});
|
|
654
471
|
}
|
|
655
472
|
getDashboardVersion() {
|
|
656
|
-
return this.sendDaum8iCommand('V70'
|
|
473
|
+
return this.sendDaum8iCommand('V70');
|
|
657
474
|
}
|
|
658
475
|
getDeviceType() {
|
|
659
|
-
return this.sendDaum8iCommand('Y00'
|
|
476
|
+
return this.sendDaum8iCommand('Y00')
|
|
660
477
|
.then((str) => {
|
|
661
478
|
let deviceType;
|
|
662
479
|
if (str === '0')
|
|
@@ -666,12 +483,12 @@ class Daum8i {
|
|
|
666
483
|
else if (str === '7')
|
|
667
484
|
deviceType = 'lyps';
|
|
668
485
|
else
|
|
669
|
-
throw (new Error(`unknown device type ${typeof str === 'string' ? (0, utils_1.ascii)(str
|
|
486
|
+
throw (new Error(`unknown device type ${typeof str === 'string' ? str : (0, utils_1.ascii)(str)}`));
|
|
670
487
|
return deviceType;
|
|
671
488
|
});
|
|
672
489
|
}
|
|
673
490
|
getActualBikeType() {
|
|
674
|
-
return this.sendDaum8iCommand('M72'
|
|
491
|
+
return this.sendDaum8iCommand('M72')
|
|
675
492
|
.then((str) => {
|
|
676
493
|
let deviceType;
|
|
677
494
|
if (str === '0')
|
|
@@ -705,7 +522,7 @@ class Daum8i {
|
|
|
705
522
|
default:
|
|
706
523
|
bikeType = undefined;
|
|
707
524
|
}
|
|
708
|
-
return this.sendDaum8iCommand(`M72${bikeType}
|
|
525
|
+
return this.sendDaum8iCommand(`M72${bikeType}`)
|
|
709
526
|
.then((str) => {
|
|
710
527
|
let deviceType;
|
|
711
528
|
if (str === '0')
|
|
@@ -721,7 +538,7 @@ class Daum8i {
|
|
|
721
538
|
});
|
|
722
539
|
}
|
|
723
540
|
getTrainingData() {
|
|
724
|
-
return this.sendDaum8iCommand('X70'
|
|
541
|
+
return this.sendDaum8iCommand('X70')
|
|
725
542
|
.then((data) => {
|
|
726
543
|
const td = (0, utils_1.parseTrainingData)(data);
|
|
727
544
|
return td;
|
|
@@ -729,32 +546,28 @@ class Daum8i {
|
|
|
729
546
|
}
|
|
730
547
|
setLoadControl(enabled) {
|
|
731
548
|
const val = enabled ? (0, utils_1.ascii)('1') : (0, utils_1.ascii)('0');
|
|
732
|
-
return this.sendDaum8iCommand('S20',
|
|
549
|
+
return this.sendDaum8iCommand('S20', [val])
|
|
733
550
|
.then((data) => {
|
|
734
551
|
const res = data === '1';
|
|
735
552
|
return res;
|
|
736
553
|
});
|
|
737
554
|
}
|
|
738
555
|
getLoadControl() {
|
|
739
|
-
return this.sendDaum8iCommand('S20'
|
|
556
|
+
return this.sendDaum8iCommand('S20')
|
|
740
557
|
.then((data) => {
|
|
741
558
|
const res = data === '1';
|
|
742
559
|
return res;
|
|
743
560
|
});
|
|
744
561
|
}
|
|
745
|
-
setSlope(slope) {
|
|
746
|
-
this.logEvent({ message: 'setSlope not implemted' });
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
562
|
setPower(power) {
|
|
750
563
|
const powerStr = Number.parseFloat(power).toFixed(2);
|
|
751
|
-
return this.sendDaum8iCommand(`S23${powerStr}
|
|
564
|
+
return this.sendDaum8iCommand(`S23${powerStr}`)
|
|
752
565
|
.then((str) => {
|
|
753
566
|
return parseInt(str);
|
|
754
567
|
});
|
|
755
568
|
}
|
|
756
569
|
getPower(power) {
|
|
757
|
-
return this.sendDaum8iCommand('S23'
|
|
570
|
+
return this.sendDaum8iCommand('S23')
|
|
758
571
|
.then((str) => {
|
|
759
572
|
return parseInt(str);
|
|
760
573
|
});
|
|
@@ -762,7 +575,7 @@ class Daum8i {
|
|
|
762
575
|
setPerson(person) {
|
|
763
576
|
const { sex, age, length, weight } = person;
|
|
764
577
|
this.logEvent({ message: 'setPerson() request', sex, age, length, weight });
|
|
765
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET,
|
|
578
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, (0, utils_1.getPersonData)(person))
|
|
766
579
|
.then((res) => {
|
|
767
580
|
const buffer = Buffer.from(res);
|
|
768
581
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PERSON_SET;
|
|
@@ -774,7 +587,7 @@ class Daum8i {
|
|
|
774
587
|
}
|
|
775
588
|
programUploadInit() {
|
|
776
589
|
this.logEvent({ message: 'programUploadInit() request' });
|
|
777
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN
|
|
590
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN)
|
|
778
591
|
.then((res) => {
|
|
779
592
|
const buffer = Buffer.from(res);
|
|
780
593
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_BEGIN;
|
|
@@ -805,7 +618,7 @@ class Daum8i {
|
|
|
805
618
|
payload.writeInt32LE(7, 32);
|
|
806
619
|
payload.writeInt32LE(eppLength, 36);
|
|
807
620
|
this.logEvent({ message: 'programUploadStart() request', bikeType, length: eppLength });
|
|
808
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM,
|
|
621
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, payload)
|
|
809
622
|
.then((res) => {
|
|
810
623
|
const buffer = Buffer.from(res);
|
|
811
624
|
if (buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM) {
|
|
@@ -827,7 +640,7 @@ class Daum8i {
|
|
|
827
640
|
const chunk = Buffer.from(epp.slice(offset, offset + size));
|
|
828
641
|
chunk.copy(payload, 8);
|
|
829
642
|
this.logEvent({ message: 'programUploadSendBlock() request', offset, size });
|
|
830
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM,
|
|
643
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM, payload)
|
|
831
644
|
.then((res) => {
|
|
832
645
|
const buffer = Buffer.from(res);
|
|
833
646
|
let success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM;
|
|
@@ -842,7 +655,7 @@ class Daum8i {
|
|
|
842
655
|
}
|
|
843
656
|
programUploadDone() {
|
|
844
657
|
this.logEvent({ message: 'programUploadDone() request' });
|
|
845
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END
|
|
658
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END)
|
|
846
659
|
.then((res) => {
|
|
847
660
|
const buffer = Buffer.from(res);
|
|
848
661
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_END;
|
|
@@ -881,6 +694,7 @@ class Daum8i {
|
|
|
881
694
|
}
|
|
882
695
|
catch (err) {
|
|
883
696
|
console.log('~~~ err', err);
|
|
697
|
+
return false;
|
|
884
698
|
}
|
|
885
699
|
return false;
|
|
886
700
|
});
|
|
@@ -889,7 +703,7 @@ class Daum8i {
|
|
|
889
703
|
const payload = Buffer.alloc(2);
|
|
890
704
|
payload.writeInt16LE(programId, 0);
|
|
891
705
|
this.logEvent({ message: 'startProgram() request', programId });
|
|
892
|
-
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START,
|
|
706
|
+
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START, payload)
|
|
893
707
|
.then((res) => {
|
|
894
708
|
const buffer = Buffer.from(res);
|
|
895
709
|
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_START;
|
|
@@ -901,42 +715,16 @@ class Daum8i {
|
|
|
901
715
|
});
|
|
902
716
|
}
|
|
903
717
|
setGear(gear) {
|
|
904
|
-
return this.sendDaum8iCommand(
|
|
718
|
+
return this.sendDaum8iCommand(`M71${gear}`)
|
|
905
719
|
.then((str) => {
|
|
906
|
-
|
|
907
|
-
return gearVal > 0 ? gearVal - 1 : undefined;
|
|
720
|
+
return parseInt(str);
|
|
908
721
|
});
|
|
909
722
|
}
|
|
910
723
|
getGear() {
|
|
911
|
-
return this.sendDaum8iCommand('M71'
|
|
724
|
+
return this.sendDaum8iCommand('M71')
|
|
912
725
|
.then((str) => {
|
|
913
726
|
return parseInt(str);
|
|
914
727
|
});
|
|
915
728
|
}
|
|
916
729
|
}
|
|
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;
|
|
730
|
+
exports.default = Daum8i;
|