incyclist-devices 1.5.38 → 2.0.0

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