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.
Files changed (251) hide show
  1. package/README.MD +0 -0
  2. package/lib/adapters.d.ts +6 -0
  3. package/lib/adapters.js +30 -0
  4. package/lib/antv2/adapter-factory.d.ts +20 -10
  5. package/lib/antv2/adapter-factory.js +49 -33
  6. package/lib/antv2/adapter.d.ts +64 -0
  7. package/lib/antv2/adapter.js +299 -0
  8. package/lib/antv2/ant-interface.d.ts +11 -9
  9. package/lib/antv2/ant-interface.js +15 -11
  10. package/lib/antv2/fe/adapter.d.ts +25 -0
  11. package/lib/antv2/{fe.js → fe/adapter.js} +48 -72
  12. package/lib/antv2/fe/index.d.ts +2 -0
  13. package/lib/antv2/fe/index.js +7 -0
  14. package/lib/antv2/hr/adapter.d.ts +14 -0
  15. package/lib/antv2/hr/adapter.js +73 -0
  16. package/lib/antv2/hr/index.d.ts +2 -0
  17. package/lib/antv2/hr/index.js +7 -0
  18. package/lib/antv2/index.d.ts +7 -0
  19. package/lib/antv2/index.js +20 -0
  20. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
  21. package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
  22. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
  23. package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
  24. package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
  25. package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
  26. package/lib/antv2/pwr/adapter.d.ts +22 -0
  27. package/lib/antv2/{pwr.js → pwr/adapter.js} +38 -76
  28. package/lib/antv2/pwr/index.d.ts +2 -0
  29. package/lib/antv2/pwr/index.js +7 -0
  30. package/lib/antv2/types.d.ts +19 -0
  31. package/lib/antv2/types.js +2 -0
  32. package/lib/antv2/utils.d.ts +1 -0
  33. package/lib/antv2/utils.js +181 -0
  34. package/lib/base/adpater.d.ts +56 -0
  35. package/lib/base/adpater.js +144 -0
  36. package/lib/ble/adapter-factory.d.ts +31 -0
  37. package/lib/ble/adapter-factory.js +96 -0
  38. package/lib/ble/adapter.d.ts +41 -0
  39. package/lib/ble/adapter.js +188 -0
  40. package/lib/ble/{ble-device.d.ts → ble-comms.d.ts} +9 -4
  41. package/lib/ble/{ble-device.js → ble-comms.js} +23 -11
  42. package/lib/ble/ble-interface.d.ts +15 -24
  43. package/lib/ble/ble-interface.js +32 -137
  44. package/lib/ble/ble-peripheral.d.ts +3 -3
  45. package/lib/ble/ble-peripheral.js +14 -14
  46. package/lib/ble/ble.d.ts +9 -81
  47. package/lib/ble/ble.js +1 -39
  48. package/lib/ble/consts.d.ts +2 -0
  49. package/lib/ble/consts.js +3 -1
  50. package/lib/ble/cp/adapter.d.ts +23 -0
  51. package/lib/ble/cp/adapter.js +124 -0
  52. package/lib/ble/cp/comm.d.ts +28 -0
  53. package/lib/ble/cp/comm.js +140 -0
  54. package/lib/ble/cp/index.d.ts +4 -0
  55. package/lib/ble/cp/index.js +10 -0
  56. package/lib/ble/cp/types.d.ts +13 -0
  57. package/lib/ble/cp/types.js +2 -0
  58. package/lib/ble/elite/adapter.d.ts +20 -0
  59. package/lib/ble/elite/adapter.js +127 -0
  60. package/lib/ble/elite/comms.d.ts +28 -0
  61. package/lib/ble/elite/comms.js +139 -0
  62. package/lib/ble/elite/index.d.ts +3 -0
  63. package/lib/ble/elite/index.js +10 -0
  64. package/lib/ble/fm/adapter.d.ts +21 -0
  65. package/lib/ble/fm/adapter.js +190 -0
  66. package/lib/ble/fm/comms.d.ts +50 -0
  67. package/lib/ble/{fm.js → fm/comms.js} +3 -224
  68. package/lib/ble/fm/consts.d.ts +6 -0
  69. package/lib/ble/fm/consts.js +9 -0
  70. package/lib/ble/fm/index.d.ts +5 -0
  71. package/lib/ble/fm/index.js +13 -0
  72. package/lib/ble/fm/types.d.ts +25 -0
  73. package/lib/ble/fm/types.js +2 -0
  74. package/lib/ble/hr/adapter.d.ts +17 -0
  75. package/lib/ble/hr/adapter.js +62 -0
  76. package/lib/ble/hr/comm.d.ts +15 -0
  77. package/lib/ble/hr/comm.js +52 -0
  78. package/lib/ble/hr/index.d.ts +4 -0
  79. package/lib/ble/hr/index.js +10 -0
  80. package/lib/ble/hr/types.d.ts +5 -0
  81. package/lib/ble/hr/types.js +2 -0
  82. package/lib/ble/index.d.ts +8 -0
  83. package/lib/ble/index.js +26 -0
  84. package/lib/ble/tacx/adapter.d.ts +10 -0
  85. package/lib/ble/tacx/adapter.js +93 -0
  86. package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +6 -38
  87. package/lib/ble/{tacx.js → tacx/comms.js} +13 -112
  88. package/lib/ble/tacx/index.d.ts +4 -0
  89. package/lib/ble/tacx/index.js +10 -0
  90. package/lib/ble/tacx/types.d.ts +25 -0
  91. package/lib/ble/tacx/types.js +2 -0
  92. package/lib/ble/types.d.ts +101 -0
  93. package/lib/ble/types.js +19 -0
  94. package/lib/ble/utils.d.ts +7 -0
  95. package/lib/ble/utils.js +95 -0
  96. package/lib/ble/wahoo/adapter.d.ts +9 -0
  97. package/lib/ble/wahoo/adapter.js +93 -0
  98. package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +5 -39
  99. package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +14 -112
  100. package/lib/ble/wahoo/index.d.ts +4 -0
  101. package/lib/ble/wahoo/index.js +10 -0
  102. package/lib/ble/wahoo/types.d.ts +19 -0
  103. package/lib/ble/wahoo/types.js +2 -0
  104. package/lib/device.d.ts +0 -94
  105. package/lib/device.js +0 -76
  106. package/lib/index.d.ts +12 -0
  107. package/lib/index.js +38 -0
  108. package/lib/interfaces.d.ts +6 -0
  109. package/lib/interfaces.js +23 -0
  110. package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
  111. package/lib/{ble → modes}/ble-erg-mode.js +2 -2
  112. package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
  113. package/lib/{ble → modes}/ble-st-mode.js +1 -1
  114. package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
  115. package/lib/modes/power-base.d.ts +3 -3
  116. package/lib/modes/power-base.js +4 -4
  117. package/lib/modes/power-meter.d.ts +3 -3
  118. package/lib/modes/simulator.d.ts +2 -2
  119. package/lib/modes/simulator.js +1 -1
  120. package/lib/serial/adapter-factory.d.ts +12 -0
  121. package/lib/serial/adapter-factory.js +30 -0
  122. package/lib/serial/adapter.d.ts +16 -0
  123. package/lib/serial/adapter.js +42 -0
  124. package/lib/serial/bindings/tcp.d.ts +44 -0
  125. package/lib/serial/bindings/tcp.js +270 -0
  126. package/lib/serial/comm.d.ts +7 -0
  127. package/lib/serial/comm.js +2 -0
  128. package/lib/{daum → serial/daum}/DaumAdapter.d.ts +13 -22
  129. package/lib/{daum → serial/daum}/DaumAdapter.js +44 -90
  130. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
  131. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
  132. package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
  133. package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
  134. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
  135. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
  136. package/lib/serial/daum/classic/adapter.d.ts +29 -0
  137. package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
  138. package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
  139. package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
  140. package/lib/serial/daum/classic/mock.d.ts +96 -0
  141. package/lib/serial/daum/classic/mock.js +365 -0
  142. package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
  143. package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
  144. package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
  145. package/lib/serial/daum/premium/adapter.d.ts +24 -0
  146. package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +99 -46
  147. package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
  148. package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +208 -420
  149. package/lib/serial/daum/premium/mock.d.ts +75 -0
  150. package/lib/serial/daum/premium/mock.js +290 -0
  151. package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
  152. package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
  153. package/lib/serial/daum/premium/types.d.ts +12 -0
  154. package/lib/serial/daum/premium/types.js +2 -0
  155. package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
  156. package/lib/{daum → serial/daum}/premium/utils.js +22 -63
  157. package/lib/serial/index.d.ts +9 -0
  158. package/lib/serial/index.js +49 -0
  159. package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
  160. package/lib/{kettler → serial/kettler}/comms.js +71 -32
  161. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +13 -24
  162. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +87 -130
  163. package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
  164. package/lib/serial/kettler/ergo-racer/mock.js +216 -0
  165. package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
  166. package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
  167. package/lib/serial/serial-interface.d.ts +58 -0
  168. package/lib/serial/serial-interface.js +283 -0
  169. package/lib/simulator/Simulator.d.ts +10 -25
  170. package/lib/simulator/Simulator.js +19 -83
  171. package/lib/types/adapter.d.ts +32 -0
  172. package/lib/types/adapter.js +2 -0
  173. package/lib/types/capabilities.d.ts +8 -0
  174. package/lib/types/capabilities.js +12 -0
  175. package/lib/types/data.d.ts +12 -0
  176. package/lib/types/data.js +2 -0
  177. package/lib/types/device.d.ts +29 -0
  178. package/lib/types/device.js +11 -0
  179. package/lib/types/interface.d.ts +14 -0
  180. package/lib/types/interface.js +2 -0
  181. package/lib/types/route.d.ts +2 -2
  182. package/lib/types/user.d.ts +1 -1
  183. package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
  184. package/lib/{utils.js → utils/utils.js} +5 -1
  185. package/package.json +15 -11
  186. package/lib/DeviceSupport.d.ts +0 -36
  187. package/lib/DeviceSupport.js +0 -82
  188. package/lib/ant/AntAdapter.d.ts +0 -50
  189. package/lib/ant/AntAdapter.js +0 -109
  190. package/lib/ant/AntScanner.d.ts +0 -60
  191. package/lib/ant/AntScanner.js +0 -651
  192. package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
  193. package/lib/ant/antfe/AntFEAdapter.js +0 -652
  194. package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
  195. package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
  196. package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
  197. package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
  198. package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
  199. package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
  200. package/lib/ant/antpwr/pwr-adapter.js +0 -251
  201. package/lib/ant/utils.d.ts +0 -1
  202. package/lib/ant/utils.js +0 -23
  203. package/lib/antv2/AntAdapter.d.ts +0 -48
  204. package/lib/antv2/AntAdapter.js +0 -104
  205. package/lib/antv2/ant-device.d.ts +0 -59
  206. package/lib/antv2/ant-device.js +0 -161
  207. package/lib/antv2/fe.d.ts +0 -32
  208. package/lib/antv2/hr.d.ts +0 -18
  209. package/lib/antv2/hr.js +0 -102
  210. package/lib/antv2/incyclist-protocol.d.ts +0 -37
  211. package/lib/antv2/incyclist-protocol.js +0 -126
  212. package/lib/antv2/pwr.d.ts +0 -28
  213. package/lib/ble/elite.d.ts +0 -90
  214. package/lib/ble/elite.js +0 -322
  215. package/lib/ble/fm.d.ts +0 -125
  216. package/lib/ble/hrm.d.ts +0 -48
  217. package/lib/ble/hrm.js +0 -134
  218. package/lib/ble/incyclist-protocol.d.ts +0 -31
  219. package/lib/ble/incyclist-protocol.js +0 -153
  220. package/lib/ble/pwr.d.ts +0 -89
  221. package/lib/ble/pwr.js +0 -322
  222. package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
  223. package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
  224. package/lib/daum/classic/DaumClassicProtocol.js +0 -185
  225. package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
  226. package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
  227. package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
  228. package/lib/daum/premium/tcpserial.d.ts +0 -33
  229. package/lib/daum/premium/tcpserial.js +0 -123
  230. package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
  231. package/lib/kettler/ergo-racer/protocol.js +0 -203
  232. package/lib/protocol.d.ts +0 -74
  233. package/lib/protocol.js +0 -41
  234. package/lib/registry.d.ts +0 -8
  235. package/lib/registry.js +0 -33
  236. package/lib/serialport/bindings/tcp.d.ts +0 -20
  237. package/lib/serialport/bindings/tcp.js +0 -33
  238. package/lib/serialport/index.d.ts +0 -2
  239. package/lib/serialport/index.js +0 -29
  240. package/lib/serialport/serialport.d.ts +0 -29
  241. package/lib/serialport/serialport.js +0 -87
  242. /package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +0 -0
  243. /package/lib/antv2/{ant-binding.js → binding.js} +0 -0
  244. /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
  245. /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
  246. /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
  247. /package/lib/{daum → serial/daum}/constants.js +0 -0
  248. /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
  249. /package/lib/{serialport.js → serial/serialport.js} +0 -0
  250. /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
  251. /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
- this.logger = process.env.DEBUG ? DEBUG_LOGGER : new gd_eventlog_1.EventLogger('DaumPremium');
47
- if (this.props.interface === 'tcpip') {
48
- const port = this.props.port || DAUM_PREMIUM_DEFAULT_PORT;
49
- const host = validateHost(this.props.host || DAUM_PREMIUM_DEFAULT_HOST);
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
- static getClassName() {
79
- return "Daum8i";
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.portName;
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
- resumLogging() {
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.logEvent({ message: "connect()", sp: (this.sp !== undefined), connected: this.connected, blocked: this.blocked, port: this.portName, settings: this.settings });
129
- if (this.connected || this.blocked) {
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
- if (this.sp !== undefined) {
136
- yield this.forceClose();
137
- this.sp = undefined;
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 (err) {
164
- this.logEvent({ message: "connect:error:", error: err.message, stack: err.stack });
165
- this.state.busy = false;
98
+ catch (_a) {
99
+ return false;
166
100
  }
167
101
  });
168
102
  }
169
- reconnect() {
103
+ close() {
170
104
  return __awaiter(this, void 0, void 0, function* () {
171
- try {
172
- yield this.saveClose();
173
- yield this.saveConnect();
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
- catch (_a) { }
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
- saveConnect() {
179
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
180
- if (this.isConnected()) {
181
- this.state.connecting = false;
182
- return resolve(true);
183
- }
184
- try {
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
- else {
202
- if (Date.now() > tTimeout) {
203
- this.state.connecting = false;
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.portName, error: error.message, connected: this.connected, state: this.getLogState() });
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.forceClose();
159
+ yield this.close();
255
160
  }
256
161
  return;
257
162
  }
258
- if (this.state.closing) {
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.forceClose(false);
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
- sp.unpipe();
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 (_b) { }
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.portName, cmd: this.cmdCurrent });
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.portName, error: err.message, stack: err.stack });
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.tcpip && this.settings.tcpip.timeout)
425
- timeout = this.settings.tcpip.timeout;
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
- let cmd = '';
435
- const MAX_DEPTH = 5;
436
- if (this.state.waitingForEnd) {
437
- cmd = this.state.partialCmd;
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
- else if (c === 0x01) {
476
- this.state.waitingForEnd = true;
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
- else if (c === 0x17) {
479
- const remaining = getRemaining();
480
- if (this.state.waitingForACK) {
481
- 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) });
482
- this.state.waitingForEnd = false;
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.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) });
486
- this.state.waitingForEnd = false;
487
- const cmdStr = cmd.substring(0, cmd.length - 2);
488
- const checksumExtracted = cmd.slice(-2);
489
- const checksumCalculated = (0, utils_1.checkSum)((0, utils_1.getAsciiArrayFromStr)(cmdStr), []);
490
- if (checksumExtracted === checksumCalculated) {
491
- this.sendACK();
492
- if (this.state.sending && this.state.sending.responseCheckIv) {
493
- clearInterval(this.state.sending.responseCheckIv);
494
- }
495
- this.state = {
496
- sending: undefined,
497
- busy: false,
498
- writeBusy: false,
499
- waitingForStart: false,
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.sendNAK();
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
- else {
515
- if (this.state.waitingForEnd)
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, queryType, payload) {
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.portName, cmd: command, hex: (0, utils_1.hexstr)(message) });
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.portName, cmd: command, hex: (0, utils_1.hexstr)(message), duration: Date.now() - tsRequest });
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.portName;
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.portName, cmd: command, hex: (0, utils_1.hexstr)(message) });
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.portName });
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
- port.write(message);
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
- const port = this.portName;
608
- this.state.writeBusy = true;
609
- try {
610
- this.sp.write([0x06]);
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
- const port = this.portName;
618
- try {
619
- this.sp.write([0x15]);
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, cmdType, data) {
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', cmdType, (0, utils_1.bin2esc)(cmdData))
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', 'AF', [])
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', 'AF', []);
473
+ return this.sendDaum8iCommand('V70');
657
474
  }
658
475
  getDeviceType() {
659
- return this.sendDaum8iCommand('Y00', 'AF', [])
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.charAt(0)) : 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', 'AF', [])
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}`, 'BF', [])
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', 'AF', [])
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', 'BF', [val])
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', 'AF', [])
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}`, 'BF', [])
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', 'AF', [])
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, 'BF', (0, utils_1.getPersonData)(person))
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, 'BF')
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, 'BF', payload)
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, 'BF', payload)
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, 'BF')
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, 'BF', payload)
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('M71', 'BF', `${gear}`)
718
+ return this.sendDaum8iCommand(`M71${gear}`)
905
719
  .then((str) => {
906
- const gearVal = parseInt(str);
907
- return gearVal > 0 ? gearVal - 1 : undefined;
720
+ return parseInt(str);
908
721
  });
909
722
  }
910
723
  getGear() {
911
- return this.sendDaum8iCommand('M71', 'AF', '')
724
+ return this.sendDaum8iCommand('M71')
912
725
  .then((str) => {
913
726
  return parseInt(str);
914
727
  });
915
728
  }
916
729
  }
917
- class Daum8iTcp extends Daum8i {
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;