incyclist-devices 1.5.37 → 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} +214 -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,84 +8,60 @@ 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))
36
22
  };
23
+ const validateHost = (host) => {
24
+ const ipParts = host.split('.');
25
+ if (ipParts.length > 1)
26
+ return ipParts.map(p => Number(p)).join('.');
27
+ return host;
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); });
37
38
  class Daum8i {
38
39
  constructor(props) {
39
40
  this.props = props || {};
40
- this.logger = process.env.DEBUG ? DEBUG_LOGGER : new gd_eventlog_1.EventLogger('DaumPremium');
41
- if (this.props.interface === 'tcpip') {
42
- const port = this.props.port || DAUM_PREMIUM_DEFAULT_PORT;
43
- const host = this.props.host || DAUM_PREMIUM_DEFAULT_HOST;
44
- this.portName = `${host}:51955`;
45
- this.tcpip = true;
46
- this.serial = false;
47
- this.tcpipConnection = { host, port };
48
- }
49
- else {
50
- this.portName = this.props.port || process.env.COM_PORT;
51
- this.tcpip = false;
52
- this.serial = true;
53
- this.port = this.portName;
54
- }
55
- this.settings = this.props.settings || {};
56
- 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');
57
45
  this.isLoggingPaused = false;
58
- this.sendRetryDelay = DEFAULT_SEND_DELAY;
59
- this.sp = undefined;
60
46
  this.connected = false;
61
47
  this.blocked = false;
62
48
  this.state = {
63
49
  ack: { wait: false, startWait: undefined },
64
50
  commandsInQueue: {},
65
51
  };
52
+ this.settings = {};
66
53
  this.bikeData = {
67
54
  userWeight: 75,
68
55
  bikeWeight: 10,
69
56
  maxPower: 800
70
57
  };
71
58
  }
72
- static getClassName() {
73
- return "Daum8i";
74
- }
75
- getType() {
76
- return "Daum8i";
77
- }
78
- static setSerialPort(spClass) {
79
- __SerialPort = spClass;
80
- }
81
- static setNetImpl(netClass) {
82
- net = netClass;
83
- }
84
- static getSupportedInterfaces() {
85
- 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;
86
62
  }
87
63
  getPort() {
88
- return this.portName;
64
+ return this.path;
89
65
  }
90
66
  isConnected() {
91
67
  return this.connected;
@@ -93,141 +69,71 @@ class Daum8i {
93
69
  pauseLogging() {
94
70
  this.isLoggingPaused = true;
95
71
  }
96
- resumLogging() {
72
+ resumeLogging() {
97
73
  this.isLoggingPaused = false;
98
74
  }
99
75
  logEvent(e) {
100
76
  if (!this.isLoggingPaused)
101
77
  this.logger.logEvent(e);
102
78
  }
103
- setUser(user, callback) {
104
- this.logEvent({ message: "setUser()", user, port: this.portName });
105
- this.settings.user = user || {};
106
- var cb = callback || nop;
107
- cb(200, user);
108
- }
109
- getUserWeight() {
110
- if (!this.settings || !this.settings.user || !this.settings.user.weight)
111
- return 75;
112
- return this.settings.user.weight;
113
- }
114
- getBikeWeight() {
115
- return 10;
116
- }
117
- unblock() {
118
- this.blocked = false;
119
- }
120
79
  connect() {
121
80
  return __awaiter(this, void 0, void 0, function* () {
122
- this.logEvent({ message: "connect()", sp: (this.sp !== undefined), connected: this.connected, blocked: this.blocked, port: this.portName, settings: this.settings });
123
- if (this.connected || this.blocked) {
124
- return;
81
+ if (this.isConnected() && this.sp) {
82
+ return true;
125
83
  }
126
- this.state.busy = true;
127
- this.state.commandsInQueue = {};
128
84
  try {
129
- if (this.sp !== undefined) {
130
- yield this.forceClose();
131
- this.sp = undefined;
132
- }
133
- if (this.sp === undefined) {
134
- if (this.tcpip) {
135
- const { host, port } = this.tcpipConnection;
136
- const { logger } = this.props;
137
- this.logEvent({ message: "creating TCPSocketPort", host, port });
138
- this.sp = new tcpserial_1.default({ host, port, net, timeout: OPEN_TIMEOUT, logger });
139
- }
140
- else {
141
- const settings = this.settings.port || {};
142
- settings.autoOpen = false;
143
- this.logEvent({ message: "creating SerialPort", port: this.port, settings });
144
- this.sp = new __SerialPort(this.port, settings);
145
- }
146
- 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;
147
89
  this.sp.on('close', this.onPortClose.bind(this));
148
90
  this.sp.on('error', (error) => { this.onPortError(error); });
149
91
  this.sp.on('data', (data) => { this.onData(data); });
92
+ return true;
93
+ }
94
+ else {
95
+ return false;
150
96
  }
151
- const start = Date.now();
152
- this.state.connecting = true;
153
- this.state.opening = { start, timeout: start + this.getTimeoutValue() };
154
- this.logEvent({ message: "opening port ..." });
155
- yield this.sp.open();
156
97
  }
157
- catch (err) {
158
- this.logEvent({ message: "connect:error:", error: err.message, stack: err.stack });
159
- this.state.busy = false;
98
+ catch (_a) {
99
+ return false;
160
100
  }
161
101
  });
162
102
  }
163
- reconnect() {
103
+ close() {
164
104
  return __awaiter(this, void 0, void 0, function* () {
165
- try {
166
- yield this.saveClose();
167
- 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
+ }
168
114
  }
169
- catch (_a) { }
115
+ this.connected = false;
116
+ if (this.sp) {
117
+ this.sp.removeAllListeners();
118
+ this.sp = null;
119
+ }
120
+ return true;
170
121
  });
171
122
  }
172
- saveConnect() {
173
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
174
- if (this.isConnected()) {
175
- this.state.connecting = false;
176
- return resolve(true);
177
- }
178
- try {
179
- yield this.connect();
180
- }
181
- catch (_a) { }
182
- const tTimeout = Date.now() + TIMEOUT_START;
183
- const iv = setInterval(() => __awaiter(this, void 0, void 0, function* () {
184
- try {
185
- if (this.state.error !== undefined) {
186
- clearInterval(iv);
187
- yield this.forceClose();
188
- reject(this.state.error);
189
- }
190
- else if (this.isConnected()) {
191
- this.state.connecting = false;
192
- 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) {
193
130
  clearInterval(iv);
131
+ this.writeDone();
132
+ done();
194
133
  }
195
- else {
196
- if (Date.now() > tTimeout) {
197
- this.state.connecting = false;
198
- yield this.forceClose();
199
- clearInterval(iv);
200
- reject(new Error('timeout'));
201
- }
202
- }
203
- }
204
- catch (_b) { }
205
- }), 100);
206
- }));
207
- }
208
- onPortOpen() {
209
- this.error = undefined;
210
- this.connected = true;
211
- this.state.opening = undefined;
212
- this.state.opened = true;
213
- this.state.busy = false;
214
- this.logEvent({ message: "port opened", port: this.portName });
215
- }
216
- onPortClose() {
217
- this.logEvent({ message: "port closed", port: this.portName });
218
- this.error = undefined;
219
- this.connected = false;
220
- if (this.state.opening) {
221
- this.state.opened = false;
222
- this.state.closed = true;
223
- }
224
- else {
225
- this.state = { opened: false, closed: true, busy: false };
226
- }
227
- this.sp.removeAllListeners();
228
- this.sp = undefined;
229
- if (this.queue !== undefined)
230
- this.queue.clear();
134
+ }, 100);
135
+ });
136
+ });
231
137
  }
232
138
  getLogState() {
233
139
  let s = undefined;
@@ -239,137 +145,49 @@ class Daum8i {
239
145
  }
240
146
  return { sending: s, busy, writeBusy, opening, connecting, waitingForStart, waitingForEnd, waitingForAck, retry };
241
147
  }
148
+ onPortClose() {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ yield this.close();
151
+ });
152
+ }
242
153
  onPortError(error) {
243
154
  return __awaiter(this, void 0, void 0, function* () {
244
- 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() });
245
156
  this.error = error;
246
157
  if (this.blocked) {
247
158
  if (!this.state.closed) {
248
- yield this.forceClose();
159
+ yield this.close();
249
160
  }
250
161
  return;
251
162
  }
252
- if (this.state.closing) {
253
- if (error.message === 'Port is not open') {
254
- this.state = { opened: false, closed: true, busy: false };
255
- return;
256
- }
257
- else {
258
- yield this.forceClose();
259
- }
260
- }
261
- else if (this.state.opening) {
262
- if (this.state.connecting) {
263
- this.state.error = error;
264
- }
265
- else {
266
- this.onPortOpen();
267
- }
268
- }
269
- else if (this.state.sending) {
163
+ if (this.state.sending) {
270
164
  if (this.state.sending.reject)
271
165
  this.state.sending.reject(error);
272
166
  this.writeDone();
273
- yield this.forceClose(false);
167
+ yield this.close();
274
168
  return;
275
169
  }
276
170
  this.state.busy = false;
277
171
  });
278
172
  }
279
- errorHandler() {
280
- throw new Error("Error");
281
- }
282
- saveClose(force) {
283
- return __awaiter(this, void 0, void 0, function* () {
284
- return yield this.close();
285
- });
286
- }
287
173
  forceClose(updateState = false) {
288
174
  return __awaiter(this, void 0, void 0, function* () {
289
- const sp = this.sp;
290
175
  if (!this.sp)
291
176
  return;
292
- this.state.closing = true;
293
- sp.removeAllListeners();
294
- sp.on('error', () => { });
295
177
  try {
296
- sp.unpipe();
297
- sp.flush();
298
- }
299
- catch (_a) { }
300
- try {
301
- yield this.closePort(1000);
178
+ yield this.close();
302
179
  this.writeDone();
303
180
  if (this.queue !== undefined)
304
181
  this.queue.clear();
305
182
  }
306
- catch (_b) { }
183
+ catch (_a) { }
307
184
  this.connected = false;
308
185
  if (updateState)
309
186
  this.state = { opened: false, closed: true, busy: false };
310
187
  });
311
188
  }
312
- closePort(timeout) {
313
- return __awaiter(this, void 0, void 0, function* () {
314
- return new Promise((resolve, reject) => {
315
- let isClosed = false;
316
- const to = setTimeout(() => {
317
- if (!isClosed)
318
- resolve(false);
319
- }, timeout);
320
- try {
321
- this.sp.removeAllListeners('close');
322
- this.sp.removeAllListeners('error');
323
- }
324
- catch (err) {
325
- this.logger.logEvent({ message: 'error', fn: 'closePort()', error: err.message });
326
- }
327
- this.sp.on('error', () => { });
328
- this.sp.on('close', () => {
329
- clearTimeout(to);
330
- isClosed = true;
331
- resolve(true);
332
- });
333
- this.sp.close();
334
- });
335
- });
336
- }
337
- close() {
338
- return __awaiter(this, void 0, void 0, function* () {
339
- this.logEvent({ message: 'close request', port: this.portName });
340
- var sp = this.sp;
341
- if (!sp) {
342
- this.state = { opened: false, closed: true, busy: false };
343
- this.connected = false;
344
- return;
345
- }
346
- let connected = this.connected;
347
- try {
348
- if (connected) {
349
- try {
350
- sp.removeAllListeners();
351
- sp.on('error', () => { });
352
- sp.unpipe();
353
- sp.flush();
354
- }
355
- catch (_a) { }
356
- }
357
- yield this.closePort(this.getTimeoutValue());
358
- this.writeDone();
359
- if (this.queue !== undefined) {
360
- this.queue.clear();
361
- this.queue = undefined;
362
- }
363
- }
364
- catch (err) {
365
- this.logEvent({ message: 'close: Exception', port: this.portName, error: err.message });
366
- }
367
- this.state = { opened: false, closed: true, busy: false };
368
- this.connected = false;
369
- });
370
- }
371
189
  sendTimeout(message) {
372
- 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 });
373
191
  delete this.state.commandsInQueue[this.cmdCurrent.command];
374
192
  if (this.cmdCurrent.callbackErr !== undefined) {
375
193
  let cb = this.cmdCurrent.callbackErr;
@@ -409,112 +227,112 @@ class Daum8i {
409
227
  return false;
410
228
  }
411
229
  catch (err) {
412
- 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 });
413
231
  }
414
232
  return true;
415
233
  }
416
234
  getTimeoutValue(cmd) {
417
235
  let timeout = DEFAULT_TIMEOUT;
418
- if (this.settings && this.settings.tcpip && this.settings.tcpip.timeout)
419
- timeout = this.settings.tcpip.timeout;
420
- if (this.settings && this.settings.serial && this.settings.serial.timeout)
421
- timeout = this.settings.serial.timeout;
236
+ if (this.settings && this.settings.timeout)
237
+ timeout = this.settings.timeout;
422
238
  if (cmd !== undefined && cmd.options !== undefined && cmd.options.timeout !== undefined) {
423
239
  timeout = cmd.options.timeout;
424
240
  }
425
241
  return timeout;
426
242
  }
427
243
  onData(data, depth = 0) {
428
- let cmd = '';
429
- const MAX_DEPTH = 5;
430
- if (this.state.waitingForEnd) {
431
- cmd = this.state.partialCmd;
432
- }
433
- const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data, 'latin1');
434
- const s = this.state.sending;
435
- if (s === undefined) {
436
- this.logEvent({ message: 'onData:IGNORED', data: bufferData.toString('hex') });
437
- return;
438
- }
439
- const { portName, resolve } = this.state.sending;
440
- let incoming = bufferData;
441
- this.logEvent({ message: 'sendCommand:RECV', data: (0, utils_1.hexstr)(incoming) });
442
- for (let i = 0; i < incoming.length; i++) {
443
- const getRemaining = () => {
444
- let remaining = '';
445
- const done = i === (incoming.length - 1);
446
- if (!done) {
447
- for (let j = i + 1; j < incoming.length; j++)
448
- remaining += String.fromCharCode(incoming.readUInt8(j));
449
- }
450
- return remaining;
451
- };
452
- const c = incoming.readUInt8(i);
453
- if (c === 0x06) {
454
- this.state.waitingForStart = true;
455
- this.state.waitingForACK = false;
456
- const remaining = getRemaining();
457
- this.logEvent({ message: "sendCommand:ACK received:", port: portName, remaining: (0, utils_1.hexstr)(remaining) });
458
- if (remaining && remaining !== '' && depth < MAX_DEPTH)
459
- return this.onData(remaining, depth + 1);
460
- }
461
- else if (c === 0x15) {
462
- this.state.waitingForStart = true;
463
- this.state.waitingForACK = false;
464
- const remaining = getRemaining();
465
- this.logEvent({ message: "sendCommand:NAK received:", port: portName, remaining: (0, utils_1.hexstr)(remaining) });
466
- if (remaining && remaining !== '' && depth < MAX_DEPTH)
467
- 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;
468
249
  }
469
- else if (c === 0x01) {
470
- 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;
471
255
  }
472
- else if (c === 0x17) {
473
- const remaining = getRemaining();
474
- if (this.state.waitingForACK) {
475
- 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) });
476
- 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);
477
277
  }
478
- else {
479
- 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) });
480
- this.state.waitingForEnd = false;
481
- const cmdStr = cmd.substring(0, cmd.length - 2);
482
- const checksumExtracted = cmd.slice(-2);
483
- const checksumCalculated = (0, utils_1.checkSum)((0, utils_1.getAsciiArrayFromStr)(cmdStr), []);
484
- if (checksumExtracted === checksumCalculated) {
485
- this.sendACK();
486
- if (this.state.sending && this.state.sending.responseCheckIv) {
487
- clearInterval(this.state.sending.responseCheckIv);
488
- }
489
- this.state = {
490
- sending: undefined,
491
- busy: false,
492
- writeBusy: false,
493
- waitingForStart: false,
494
- waitingForEnd: false,
495
- waitingForACK: false,
496
- };
497
- const payload = cmd.substring(3, cmd.length - 2);
498
- 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;
499
294
  }
500
295
  else {
501
- 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
+ }
502
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);
503
328
  }
504
- cmd = '';
505
- if (remaining && depth < 5)
506
- return this.onData(remaining, depth + 1);
507
329
  }
508
- else {
509
- if (this.state.waitingForEnd)
510
- cmd += String.fromCharCode(c);
330
+ if (this.state.waitingForEnd) {
331
+ this.state.partialCmd = cmd;
511
332
  }
512
- }
513
- if (this.state.waitingForEnd) {
514
- this.state.partialCmd = cmd;
515
- }
333
+ });
516
334
  }
517
- sendDaum8iCommand(command, queryType, payload) {
335
+ sendDaum8iCommand(command, payload = '') {
518
336
  const tsRequest = Date.now();
519
337
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
520
338
  if (this.blocked)
@@ -524,7 +342,7 @@ class Daum8i {
524
342
  }
525
343
  else {
526
344
  const message = (0, utils_1.buildMessage)(command, payload);
527
- 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) });
528
346
  const busyWait = () => {
529
347
  return new Promise((done) => {
530
348
  let start = Date.now();
@@ -545,26 +363,26 @@ class Daum8i {
545
363
  };
546
364
  const res = yield busyWait();
547
365
  if (!res) {
548
- 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 });
549
367
  return reject(new Error('BUSY timeout'));
550
368
  }
551
369
  this.state.busy = true;
552
370
  }
553
371
  const port = this.sp;
554
- const portName = this.portName;
372
+ const portName = this.path;
555
373
  this.state.received = [];
556
374
  try {
557
375
  const message = (0, utils_1.buildMessage)(command, payload);
558
376
  const start = Date.now();
559
377
  const timeout = start + this.getTimeoutValue();
560
- 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) });
561
379
  this.state.writeBusy = true;
562
380
  if (!this.connected || port === undefined) {
563
- this.logEvent({ message: "sendCommand:error: not connected", port: this.portName });
381
+ this.logEvent({ message: "sendCommand:error: not connected", port: this.path });
564
382
  this.writeDone();
565
383
  return reject(new Error('not connected'));
566
384
  }
567
- port.write(message);
385
+ yield this.write(Buffer.from(message));
568
386
  this.state.waitingForACK = true;
569
387
  this.state.writeBusy = false;
570
388
  this.state.retry = 0;
@@ -597,25 +415,33 @@ class Daum8i {
597
415
  this.state.waitingForEnd = false;
598
416
  this.state.waitingForACK = false;
599
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
+ }
600
432
  sendACK() {
601
- const port = this.portName;
602
- this.state.writeBusy = true;
603
- try {
604
- this.sp.write([0x06]);
605
- }
606
- catch (err) { }
607
- this.state.writeBusy = false;
608
- 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
+ });
609
437
  }
610
438
  sendNAK() {
611
- const port = this.portName;
612
- try {
613
- this.sp.write([0x15]);
614
- }
615
- catch (err) { }
616
- 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
+ });
617
443
  }
618
- sendReservedDaum8iCommand(command, cmdType, data) {
444
+ sendReservedDaum8iCommand(command, data) {
619
445
  let buffer;
620
446
  if (data !== undefined && data.length > 0) {
621
447
  buffer = Buffer.alloc(data.length + 4);
@@ -629,28 +455,25 @@ class Daum8i {
629
455
  buffer.writeUInt16LE(0, 2);
630
456
  }
631
457
  const cmdData = Uint8Array.from(buffer);
632
- return this.sendDaum8iCommand('M70', cmdType, (0, utils_1.bin2esc)(cmdData))
458
+ return this.sendDaum8iCommand('M70', (0, utils_1.bin2esc)(cmdData))
633
459
  .then((res) => {
634
460
  const resData = Uint8Array.from(res, x => x.charCodeAt(0));
635
461
  const cmd = (0, utils_1.esc2bin)(resData);
636
462
  return cmd;
637
463
  });
638
464
  }
639
- stopWorker() {
640
- this.logEvent({ message: "stop worker", port: this.getPort() });
641
- }
642
465
  getProtocolVersion() {
643
- return this.sendDaum8iCommand('V00', 'AF', [])
466
+ return this.sendDaum8iCommand('V00')
644
467
  .then((data) => {
645
468
  const version = data.substring(0, 1) + '.' + data.substring(1);
646
469
  return (version);
647
470
  });
648
471
  }
649
472
  getDashboardVersion() {
650
- return this.sendDaum8iCommand('V70', 'AF', []);
473
+ return this.sendDaum8iCommand('V70');
651
474
  }
652
475
  getDeviceType() {
653
- return this.sendDaum8iCommand('Y00', 'AF', [])
476
+ return this.sendDaum8iCommand('Y00')
654
477
  .then((str) => {
655
478
  let deviceType;
656
479
  if (str === '0')
@@ -660,12 +483,12 @@ class Daum8i {
660
483
  else if (str === '7')
661
484
  deviceType = 'lyps';
662
485
  else
663
- 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)}`));
664
487
  return deviceType;
665
488
  });
666
489
  }
667
490
  getActualBikeType() {
668
- return this.sendDaum8iCommand('M72', 'AF', [])
491
+ return this.sendDaum8iCommand('M72')
669
492
  .then((str) => {
670
493
  let deviceType;
671
494
  if (str === '0')
@@ -699,7 +522,7 @@ class Daum8i {
699
522
  default:
700
523
  bikeType = undefined;
701
524
  }
702
- return this.sendDaum8iCommand(`M72${bikeType}`, 'BF', [])
525
+ return this.sendDaum8iCommand(`M72${bikeType}`)
703
526
  .then((str) => {
704
527
  let deviceType;
705
528
  if (str === '0')
@@ -715,7 +538,7 @@ class Daum8i {
715
538
  });
716
539
  }
717
540
  getTrainingData() {
718
- return this.sendDaum8iCommand('X70', 'AF', [])
541
+ return this.sendDaum8iCommand('X70')
719
542
  .then((data) => {
720
543
  const td = (0, utils_1.parseTrainingData)(data);
721
544
  return td;
@@ -723,32 +546,28 @@ class Daum8i {
723
546
  }
724
547
  setLoadControl(enabled) {
725
548
  const val = enabled ? (0, utils_1.ascii)('1') : (0, utils_1.ascii)('0');
726
- return this.sendDaum8iCommand('S20', 'BF', [val])
549
+ return this.sendDaum8iCommand('S20', [val])
727
550
  .then((data) => {
728
551
  const res = data === '1';
729
552
  return res;
730
553
  });
731
554
  }
732
555
  getLoadControl() {
733
- return this.sendDaum8iCommand('S20', 'AF', [])
556
+ return this.sendDaum8iCommand('S20')
734
557
  .then((data) => {
735
558
  const res = data === '1';
736
559
  return res;
737
560
  });
738
561
  }
739
- setSlope(slope) {
740
- this.logEvent({ message: 'setSlope not implemted' });
741
- return;
742
- }
743
562
  setPower(power) {
744
563
  const powerStr = Number.parseFloat(power).toFixed(2);
745
- return this.sendDaum8iCommand(`S23${powerStr}`, 'BF', [])
564
+ return this.sendDaum8iCommand(`S23${powerStr}`)
746
565
  .then((str) => {
747
566
  return parseInt(str);
748
567
  });
749
568
  }
750
569
  getPower(power) {
751
- return this.sendDaum8iCommand('S23', 'AF', [])
570
+ return this.sendDaum8iCommand('S23')
752
571
  .then((str) => {
753
572
  return parseInt(str);
754
573
  });
@@ -756,7 +575,7 @@ class Daum8i {
756
575
  setPerson(person) {
757
576
  const { sex, age, length, weight } = person;
758
577
  this.logEvent({ message: 'setPerson() request', sex, age, length, weight });
759
- 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))
760
579
  .then((res) => {
761
580
  const buffer = Buffer.from(res);
762
581
  const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PERSON_SET;
@@ -768,7 +587,7 @@ class Daum8i {
768
587
  }
769
588
  programUploadInit() {
770
589
  this.logEvent({ message: 'programUploadInit() request' });
771
- return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN, 'BF')
590
+ return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN)
772
591
  .then((res) => {
773
592
  const buffer = Buffer.from(res);
774
593
  const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_BEGIN;
@@ -799,7 +618,7 @@ class Daum8i {
799
618
  payload.writeInt32LE(7, 32);
800
619
  payload.writeInt32LE(eppLength, 36);
801
620
  this.logEvent({ message: 'programUploadStart() request', bikeType, length: eppLength });
802
- return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, 'BF', payload)
621
+ return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, payload)
803
622
  .then((res) => {
804
623
  const buffer = Buffer.from(res);
805
624
  if (buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM) {
@@ -821,7 +640,7 @@ class Daum8i {
821
640
  const chunk = Buffer.from(epp.slice(offset, offset + size));
822
641
  chunk.copy(payload, 8);
823
642
  this.logEvent({ message: 'programUploadSendBlock() request', offset, size });
824
- return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM, 'BF', payload)
643
+ return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM, payload)
825
644
  .then((res) => {
826
645
  const buffer = Buffer.from(res);
827
646
  let success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM;
@@ -836,7 +655,7 @@ class Daum8i {
836
655
  }
837
656
  programUploadDone() {
838
657
  this.logEvent({ message: 'programUploadDone() request' });
839
- return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END, 'BF')
658
+ return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END)
840
659
  .then((res) => {
841
660
  const buffer = Buffer.from(res);
842
661
  const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_END;
@@ -875,6 +694,7 @@ class Daum8i {
875
694
  }
876
695
  catch (err) {
877
696
  console.log('~~~ err', err);
697
+ return false;
878
698
  }
879
699
  return false;
880
700
  });
@@ -883,7 +703,7 @@ class Daum8i {
883
703
  const payload = Buffer.alloc(2);
884
704
  payload.writeInt16LE(programId, 0);
885
705
  this.logEvent({ message: 'startProgram() request', programId });
886
- return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START, 'BF', payload)
706
+ return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START, payload)
887
707
  .then((res) => {
888
708
  const buffer = Buffer.from(res);
889
709
  const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_START;
@@ -895,42 +715,16 @@ class Daum8i {
895
715
  });
896
716
  }
897
717
  setGear(gear) {
898
- return this.sendDaum8iCommand('M71', 'BF', `${gear}`)
718
+ return this.sendDaum8iCommand(`M71${gear}`)
899
719
  .then((str) => {
900
- const gearVal = parseInt(str);
901
- return gearVal > 0 ? gearVal - 1 : undefined;
720
+ return parseInt(str);
902
721
  });
903
722
  }
904
723
  getGear() {
905
- return this.sendDaum8iCommand('M71', 'AF', '')
724
+ return this.sendDaum8iCommand('M71')
906
725
  .then((str) => {
907
726
  return parseInt(str);
908
727
  });
909
728
  }
910
729
  }
911
- class Daum8iTcp extends Daum8i {
912
- static getClassName() { return "Daum8i"; }
913
- getType() { return "Daum8iTcp"; }
914
- static setSerialPort(spClass) { }
915
- getInterface() { return constants_1.BIKE_INTERFACE.TCPIP; }
916
- static setNetImpl(netClass) {
917
- net = netClass;
918
- }
919
- static getSupportedInterfaces() {
920
- return [constants_1.BIKE_INTERFACE.TCPIP];
921
- }
922
- }
923
- exports.Daum8iTcp = Daum8iTcp;
924
- class Daum8iSerial extends Daum8i {
925
- static getClassName() { return "Daum8i"; }
926
- getType() { return "Daum8iSerial"; }
927
- getInterface() { return constants_1.BIKE_INTERFACE.SERIAL; }
928
- static setSerialPort(spClass) {
929
- __SerialPort = spClass;
930
- }
931
- static setNetImpl(netClass) { }
932
- static getSupportedInterfaces() {
933
- return [constants_1.BIKE_INTERFACE.SERIAL];
934
- }
935
- }
936
- exports.Daum8iSerial = Daum8iSerial;
730
+ exports.default = Daum8i;