incyclist-devices 2.1.11 → 2.1.13

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 (281) hide show
  1. package/LICENSE +0 -0
  2. package/README.MD +238 -238
  3. package/lib/antv2/base/adapter.d.ts +0 -0
  4. package/lib/antv2/base/adapter.js +0 -0
  5. package/lib/antv2/base/binding.d.ts +0 -0
  6. package/lib/antv2/base/binding.js +0 -0
  7. package/lib/antv2/base/interface.d.ts +0 -0
  8. package/lib/antv2/base/interface.js +0 -0
  9. package/lib/antv2/cad/adapter.d.ts +0 -0
  10. package/lib/antv2/cad/adapter.js +0 -0
  11. package/lib/antv2/cad/index.d.ts +0 -0
  12. package/lib/antv2/cad/index.js +0 -0
  13. package/lib/antv2/consts.d.ts +0 -0
  14. package/lib/antv2/consts.js +0 -0
  15. package/lib/antv2/factories/adapter-factory.d.ts +0 -0
  16. package/lib/antv2/factories/adapter-factory.js +0 -0
  17. package/lib/antv2/factories/sensor-factory.d.ts +0 -0
  18. package/lib/antv2/factories/sensor-factory.js +0 -0
  19. package/lib/antv2/fe/adapter.d.ts +0 -0
  20. package/lib/antv2/fe/adapter.js +0 -0
  21. package/lib/antv2/fe/index.d.ts +0 -0
  22. package/lib/antv2/fe/index.js +0 -0
  23. package/lib/antv2/hr/adapter.d.ts +0 -0
  24. package/lib/antv2/hr/adapter.js +0 -0
  25. package/lib/antv2/hr/index.d.ts +0 -0
  26. package/lib/antv2/hr/index.js +0 -0
  27. package/lib/antv2/index.d.ts +0 -0
  28. package/lib/antv2/index.js +0 -0
  29. package/lib/antv2/pwr/adapter.d.ts +0 -0
  30. package/lib/antv2/pwr/adapter.js +0 -0
  31. package/lib/antv2/pwr/index.d.ts +0 -0
  32. package/lib/antv2/pwr/index.js +0 -0
  33. package/lib/antv2/types.d.ts +0 -0
  34. package/lib/antv2/types.js +0 -0
  35. package/lib/antv2/utils.d.ts +0 -0
  36. package/lib/antv2/utils.js +0 -0
  37. package/lib/base/adpater.d.ts +0 -0
  38. package/lib/base/adpater.js +0 -0
  39. package/lib/base/consts.d.ts +0 -0
  40. package/lib/base/consts.js +0 -0
  41. package/lib/ble/adapter-factory.d.ts +0 -0
  42. package/lib/ble/adapter-factory.js +0 -0
  43. package/lib/ble/base/adapter.d.ts +0 -0
  44. package/lib/ble/base/adapter.js +0 -0
  45. package/lib/ble/base/comms-utils.d.ts +0 -0
  46. package/lib/ble/base/comms-utils.js +0 -0
  47. package/lib/ble/base/comms.d.ts +0 -0
  48. package/lib/ble/base/comms.js +0 -0
  49. package/lib/ble/base/types.d.ts +0 -0
  50. package/lib/ble/base/types.js +0 -0
  51. package/lib/ble/bindings/index.d.ts +0 -0
  52. package/lib/ble/bindings/index.js +0 -0
  53. package/lib/ble/bindings/linux.d.ts +0 -0
  54. package/lib/ble/bindings/linux.js +0 -0
  55. package/lib/ble/bindings/mock.d.ts +0 -0
  56. package/lib/ble/bindings/mock.js +0 -0
  57. package/lib/ble/bindings/types.d.ts +0 -0
  58. package/lib/ble/bindings/types.js +0 -0
  59. package/lib/ble/ble-interface.d.ts +0 -0
  60. package/lib/ble/ble-interface.js +0 -0
  61. package/lib/ble/ble-peripheral.d.ts +0 -0
  62. package/lib/ble/ble-peripheral.js +0 -0
  63. package/lib/ble/consts.d.ts +0 -0
  64. package/lib/ble/consts.js +0 -0
  65. package/lib/ble/cp/adapter.d.ts +0 -0
  66. package/lib/ble/cp/adapter.js +0 -0
  67. package/lib/ble/cp/comm.d.ts +0 -0
  68. package/lib/ble/cp/comm.js +0 -0
  69. package/lib/ble/cp/index.d.ts +0 -0
  70. package/lib/ble/cp/index.js +0 -0
  71. package/lib/ble/cp/types.d.ts +0 -0
  72. package/lib/ble/cp/types.js +0 -0
  73. package/lib/ble/elite/adapter.d.ts +0 -0
  74. package/lib/ble/elite/adapter.js +0 -0
  75. package/lib/ble/elite/comms.d.ts +0 -0
  76. package/lib/ble/elite/comms.js +0 -0
  77. package/lib/ble/elite/index.d.ts +0 -0
  78. package/lib/ble/elite/index.js +0 -0
  79. package/lib/ble/fm/adapter.d.ts +0 -0
  80. package/lib/ble/fm/adapter.js +0 -0
  81. package/lib/ble/fm/comms.d.ts +0 -0
  82. package/lib/ble/fm/comms.js +0 -0
  83. package/lib/ble/fm/consts.d.ts +0 -0
  84. package/lib/ble/fm/consts.js +0 -0
  85. package/lib/ble/fm/index.d.ts +0 -0
  86. package/lib/ble/fm/index.js +0 -0
  87. package/lib/ble/fm/types.d.ts +0 -0
  88. package/lib/ble/fm/types.js +0 -0
  89. package/lib/ble/hr/adapter.d.ts +0 -0
  90. package/lib/ble/hr/adapter.js +0 -0
  91. package/lib/ble/hr/comm.d.ts +0 -0
  92. package/lib/ble/hr/comm.js +0 -0
  93. package/lib/ble/hr/index.d.ts +0 -0
  94. package/lib/ble/hr/index.js +0 -0
  95. package/lib/ble/hr/mock.d.ts +0 -0
  96. package/lib/ble/hr/mock.js +0 -0
  97. package/lib/ble/hr/types.d.ts +0 -0
  98. package/lib/ble/hr/types.js +0 -0
  99. package/lib/ble/index.d.ts +0 -0
  100. package/lib/ble/index.js +0 -0
  101. package/lib/ble/peripheral-cache.d.ts +0 -0
  102. package/lib/ble/peripheral-cache.js +0 -0
  103. package/lib/ble/tacx/adapter.d.ts +0 -0
  104. package/lib/ble/tacx/adapter.js +0 -0
  105. package/lib/ble/tacx/comms.d.ts +0 -0
  106. package/lib/ble/tacx/comms.js +0 -0
  107. package/lib/ble/tacx/index.d.ts +0 -0
  108. package/lib/ble/tacx/index.js +0 -0
  109. package/lib/ble/tacx/types.d.ts +0 -0
  110. package/lib/ble/tacx/types.js +0 -0
  111. package/lib/ble/types.d.ts +0 -0
  112. package/lib/ble/types.js +0 -0
  113. package/lib/ble/utils.d.ts +0 -0
  114. package/lib/ble/utils.js +0 -0
  115. package/lib/ble/wahoo/adapter.d.ts +0 -0
  116. package/lib/ble/wahoo/adapter.js +0 -0
  117. package/lib/ble/wahoo/comms.d.ts +0 -0
  118. package/lib/ble/wahoo/comms.js +0 -0
  119. package/lib/ble/wahoo/index.d.ts +0 -0
  120. package/lib/ble/wahoo/index.js +0 -0
  121. package/lib/ble/wahoo/types.d.ts +0 -0
  122. package/lib/ble/wahoo/types.js +0 -0
  123. package/lib/factories/adapters.d.ts +0 -0
  124. package/lib/factories/adapters.js +0 -0
  125. package/lib/factories/index.d.ts +0 -0
  126. package/lib/factories/index.js +0 -0
  127. package/lib/factories/interfaces.d.ts +0 -0
  128. package/lib/factories/interfaces.js +0 -0
  129. package/lib/index.d.ts +0 -0
  130. package/lib/index.js +0 -0
  131. package/lib/modes/ant-fe-adv-st-mode.d.ts +0 -0
  132. package/lib/modes/ant-fe-adv-st-mode.js +0 -0
  133. package/lib/modes/antble-erg.d.ts +0 -0
  134. package/lib/modes/antble-erg.js +0 -0
  135. package/lib/modes/antble-smarttrainer.d.ts +0 -0
  136. package/lib/modes/antble-smarttrainer.js +0 -0
  137. package/lib/modes/base.d.ts +0 -0
  138. package/lib/modes/base.js +0 -0
  139. package/lib/modes/daum-classic-standard.d.ts +0 -0
  140. package/lib/modes/daum-classic-standard.js +0 -0
  141. package/lib/modes/daum-erg.d.ts +0 -0
  142. package/lib/modes/daum-erg.js +0 -0
  143. package/lib/modes/daum-power.d.ts +0 -0
  144. package/lib/modes/daum-power.js +0 -0
  145. package/lib/modes/daum-premium-standard.d.ts +0 -0
  146. package/lib/modes/daum-premium-standard.js +0 -0
  147. package/lib/modes/daum-smarttrainer.d.ts +0 -0
  148. package/lib/modes/daum-smarttrainer.js +0 -0
  149. package/lib/modes/kettler-erg.d.ts +0 -0
  150. package/lib/modes/kettler-erg.js +0 -0
  151. package/lib/modes/power-base.d.ts +0 -0
  152. package/lib/modes/power-base.js +0 -0
  153. package/lib/modes/power-meter.d.ts +0 -0
  154. package/lib/modes/power-meter.js +0 -0
  155. package/lib/modes/simulator.d.ts +0 -0
  156. package/lib/modes/simulator.js +0 -0
  157. package/lib/modes/types.d.ts +0 -0
  158. package/lib/modes/types.js +0 -0
  159. package/lib/serial/base/adapter.d.ts +0 -0
  160. package/lib/serial/base/adapter.js +0 -0
  161. package/lib/serial/base/comms.d.ts +2 -0
  162. package/lib/serial/base/comms.js +6 -0
  163. package/lib/serial/base/serial-interface.d.ts +0 -0
  164. package/lib/serial/base/serial-interface.js +0 -0
  165. package/lib/serial/base/serial-scanner.d.ts +0 -0
  166. package/lib/serial/base/serial-scanner.js +0 -0
  167. package/lib/serial/base/serialport.d.ts +0 -0
  168. package/lib/serial/base/serialport.js +0 -0
  169. package/lib/serial/bindings/tcp.d.ts +6 -0
  170. package/lib/serial/bindings/tcp.js +23 -5
  171. package/lib/serial/daum/DaumAdapter.d.ts +0 -0
  172. package/lib/serial/daum/DaumAdapter.js +10 -5
  173. package/lib/serial/daum/classic/adapter.d.ts +0 -0
  174. package/lib/serial/daum/classic/adapter.js +0 -0
  175. package/lib/serial/daum/classic/comms.d.ts +0 -0
  176. package/lib/serial/daum/classic/comms.js +0 -0
  177. package/lib/serial/daum/classic/consts.d.ts +0 -0
  178. package/lib/serial/daum/classic/consts.js +0 -0
  179. package/lib/serial/daum/classic/mock.d.ts +0 -0
  180. package/lib/serial/daum/classic/mock.js +0 -0
  181. package/lib/serial/daum/classic/types.d.ts +0 -0
  182. package/lib/serial/daum/classic/types.js +0 -0
  183. package/lib/serial/daum/classic/utils.d.ts +0 -0
  184. package/lib/serial/daum/classic/utils.js +0 -0
  185. package/lib/serial/daum/premium/adapter.d.ts +0 -0
  186. package/lib/serial/daum/premium/adapter.js +0 -0
  187. package/lib/serial/daum/premium/comms.d.ts +3 -0
  188. package/lib/serial/daum/premium/comms.js +11 -1
  189. package/lib/serial/daum/premium/consts.d.ts +0 -0
  190. package/lib/serial/daum/premium/consts.js +0 -0
  191. package/lib/serial/daum/premium/mock.d.ts +0 -0
  192. package/lib/serial/daum/premium/mock.js +0 -0
  193. package/lib/serial/daum/premium/types.d.ts +0 -0
  194. package/lib/serial/daum/premium/types.js +0 -0
  195. package/lib/serial/daum/premium/utils.d.ts +0 -0
  196. package/lib/serial/daum/premium/utils.js +0 -0
  197. package/lib/serial/daum/types.d.ts +2 -2
  198. package/lib/serial/daum/types.js +0 -0
  199. package/lib/serial/factories/adapter-factory.d.ts +0 -0
  200. package/lib/serial/factories/adapter-factory.js +0 -0
  201. package/lib/serial/index.d.ts +0 -0
  202. package/lib/serial/index.js +0 -0
  203. package/lib/serial/kettler/comms.d.ts +0 -0
  204. package/lib/serial/kettler/comms.js +0 -0
  205. package/lib/serial/kettler/ergo-racer/adapter.d.ts +1 -1
  206. package/lib/serial/kettler/ergo-racer/adapter.js +3 -2
  207. package/lib/serial/kettler/ergo-racer/mock.d.ts +0 -0
  208. package/lib/serial/kettler/ergo-racer/mock.js +0 -0
  209. package/lib/serial/kettler/types.d.ts +0 -0
  210. package/lib/serial/kettler/types.js +0 -0
  211. package/lib/serial/types.d.ts +0 -0
  212. package/lib/serial/types.js +0 -0
  213. package/lib/simulator/Simulator.d.ts +0 -0
  214. package/lib/simulator/Simulator.js +0 -0
  215. package/lib/types/adapter.d.ts +0 -0
  216. package/lib/types/adapter.js +0 -0
  217. package/lib/types/capabilities.d.ts +0 -0
  218. package/lib/types/capabilities.js +0 -0
  219. package/lib/types/data.d.ts +0 -0
  220. package/lib/types/data.js +0 -0
  221. package/lib/types/device.d.ts +0 -0
  222. package/lib/types/device.js +0 -0
  223. package/lib/types/index.d.ts +0 -0
  224. package/lib/types/index.js +0 -0
  225. package/lib/types/interface.d.ts +0 -0
  226. package/lib/types/interface.js +0 -0
  227. package/lib/types/user.d.ts +0 -0
  228. package/lib/types/user.js +0 -0
  229. package/lib/utils/calculations.d.ts +0 -0
  230. package/lib/utils/calculations.js +0 -0
  231. package/lib/utils/utils.d.ts +0 -0
  232. package/lib/utils/utils.js +0 -0
  233. package/package.json +51 -51
  234. package/lib/adapters.d.ts +0 -7
  235. package/lib/adapters.js +0 -49
  236. package/lib/antv2/adapter-factory.d.ts +0 -14
  237. package/lib/antv2/adapter-factory.js +0 -65
  238. package/lib/antv2/adapter.d.ts +0 -54
  239. package/lib/antv2/adapter.js +0 -291
  240. package/lib/antv2/ant-interface.d.ts +0 -35
  241. package/lib/antv2/ant-interface.js +0 -285
  242. package/lib/antv2/base/ant-interface.d.ts +0 -35
  243. package/lib/antv2/base/ant-interface.js +0 -285
  244. package/lib/antv2/binding.d.ts +0 -13
  245. package/lib/antv2/binding.js +0 -27
  246. package/lib/antv2/hr copy/adapter.d.ts +0 -11
  247. package/lib/antv2/hr copy/adapter.js +0 -30
  248. package/lib/antv2/hr copy/index.d.ts +0 -2
  249. package/lib/antv2/hr copy/index.js +0 -7
  250. package/lib/antv2/sensor-factory.d.ts +0 -5
  251. package/lib/antv2/sensor-factory.js +0 -20
  252. package/lib/interfaces.d.ts +0 -7
  253. package/lib/interfaces.js +0 -27
  254. package/lib/serial/SinglePathScanner.d.ts +0 -17
  255. package/lib/serial/SinglePathScanner.js +0 -87
  256. package/lib/serial/adapter-factory.d.ts +0 -14
  257. package/lib/serial/adapter-factory.js +0 -30
  258. package/lib/serial/adapter.d.ts +0 -17
  259. package/lib/serial/adapter.js +0 -67
  260. package/lib/serial/comm.d.ts +0 -7
  261. package/lib/serial/comm.js +0 -2
  262. package/lib/serial/comms.d.ts +0 -62
  263. package/lib/serial/comms.js +0 -280
  264. package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +0 -2
  265. package/lib/serial/daum/classic/PROTOCOL_NAME.js +0 -5
  266. package/lib/serial/daum/consts.d.ts +0 -0
  267. package/lib/serial/daum/consts.js +0 -0
  268. package/lib/serial/serial-interface.d.ts +0 -36
  269. package/lib/serial/serial-interface.js +0 -288
  270. package/lib/serial/serial-scanner.d.ts +0 -16
  271. package/lib/serial/serial-scanner.js +0 -87
  272. package/lib/serial/serialport.d.ts +0 -17
  273. package/lib/serial/serialport.js +0 -87
  274. package/lib/types/Command.d.ts +0 -8
  275. package/lib/types/Command.js +0 -2
  276. package/lib/types/command.d.ts +0 -0
  277. package/lib/types/command.js +0 -0
  278. package/lib/types/route.d.ts +0 -0
  279. package/lib/types/route.js +0 -0
  280. package/lib/types/types.d.ts +0 -8
  281. package/lib/types/types.js +0 -2
@@ -1,2 +0,0 @@
1
- import AntHrAdapter from './adapter';
2
- export default AntHrAdapter;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const adapter_1 = __importDefault(require("./adapter"));
7
- exports.default = adapter_1.default;
@@ -1,5 +0,0 @@
1
- import { ISensor, Profile } from "incyclist-ant-plus";
2
- export default class SensorFactory {
3
- static create(profile: Profile, deviceID?: number): ISensor;
4
- static createAll(): ISensor[];
5
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const incyclist_ant_plus_1 = require("incyclist-ant-plus");
4
- const profiles = [
5
- { profile: 'PWR', Class: incyclist_ant_plus_1.BicyclePowerSensor },
6
- { profile: 'HR', Class: incyclist_ant_plus_1.HeartRateSensor },
7
- { profile: 'FE', Class: incyclist_ant_plus_1.FitnessEquipmentSensor },
8
- ];
9
- class SensorFactory {
10
- static create(profile, deviceID) {
11
- const info = profiles.find(i => i.profile === profile);
12
- if (!info)
13
- return;
14
- return new info.Class(deviceID);
15
- }
16
- static createAll() {
17
- return profiles.map(info => new info.Class());
18
- }
19
- }
20
- exports.default = SensorFactory;
@@ -1,7 +0,0 @@
1
- import { InterfaceProps } from "./types/interface";
2
- import { SerialInterface } from "./serial";
3
- import AntInterface from "./antv2/ant-interface";
4
- import { BleInterface } from "./ble";
5
- export default class InterfaceFactory {
6
- static create(ifaceName: string, props?: InterfaceProps): AntInterface | BleInterface | SerialInterface;
7
- }
package/lib/interfaces.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const serial_1 = require("./serial");
7
- const ant_interface_1 = __importDefault(require("./antv2/ant-interface"));
8
- const device_1 = require("./types/device");
9
- const ble_1 = require("./ble");
10
- class InterfaceFactory {
11
- static create(ifaceName, props) {
12
- switch (ifaceName) {
13
- case device_1.INTERFACE.SERIAL:
14
- case device_1.INTERFACE.TCPIP:
15
- const serialProps = props;
16
- serialProps.ifaceName = ifaceName;
17
- return serial_1.SerialInterface.getInstance(serialProps);
18
- case device_1.INTERFACE.ANT:
19
- const antProps = props;
20
- return ant_interface_1.default.getInstance(antProps);
21
- case device_1.INTERFACE.BLE:
22
- const bleProps = props;
23
- return ble_1.BleInterface.getInstance(bleProps);
24
- }
25
- }
26
- }
27
- exports.default = InterfaceFactory;
@@ -1,17 +0,0 @@
1
- import { SerialDeviceSettings } from './adapter';
2
- import { EventLogger } from "gd-eventlog";
3
- import { SerialScannerProps } from "./types";
4
- import SerialInterface from "./serial-interface";
5
- export declare class SinglePathScanner {
6
- path: string;
7
- serial: SerialInterface;
8
- result: SerialDeviceSettings;
9
- isScanning: boolean;
10
- props: SerialScannerProps;
11
- logger: EventLogger;
12
- isFound: boolean;
13
- constructor(path: string, serial: SerialInterface, props: SerialScannerProps);
14
- logEvent(event: any): void;
15
- onStopRequest(resolve: any): Promise<void>;
16
- scan(): Promise<SerialDeviceSettings | undefined>;
17
- }
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.SinglePathScanner = void 0;
16
- const gd_eventlog_1 = require("gd-eventlog");
17
- const utils_1 = require("../utils/utils");
18
- const adapter_factory_1 = __importDefault(require("./adapter-factory"));
19
- const types_1 = require("./types");
20
- class SinglePathScanner {
21
- constructor(path, serial, props) {
22
- this.path = path;
23
- this.serial = serial;
24
- this.result = undefined;
25
- this.isScanning = false;
26
- this.isFound = false;
27
- this.props = props;
28
- this.logger = props.logger || new gd_eventlog_1.EventLogger('SerialScanner');
29
- }
30
- logEvent(event) {
31
- if (this.logger) {
32
- this.logger.logEvent(event);
33
- }
34
- const w = global.window;
35
- if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG) {
36
- console.log('~~~ SerialScanner', event);
37
- }
38
- }
39
- onStopRequest(resolve) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- this.logEvent({ message: 'stopping scan', path: this.path });
42
- if (!this.isFound)
43
- yield this.serial.closePort(this.path);
44
- this.isScanning = false;
45
- resolve(this.result);
46
- });
47
- }
48
- scan() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- if (this.isScanning)
51
- return;
52
- this.isScanning = true;
53
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
54
- this.logEvent({ message: 'starting scan', path: this.path, interface: this.serial.getName() });
55
- this.serial.scanEvents.on('timeout', () => this.onStopRequest(resolve));
56
- this.serial.scanEvents.on('stop', () => this.onStopRequest(resolve));
57
- let found = false;
58
- while (!found && this.isScanning) {
59
- try {
60
- const { protocol } = this.props;
61
- let host, port;
62
- if (this.serial.getName() === types_1.SerialInterfaceType.TCPIP) {
63
- [host, port] = this.path.split(':');
64
- }
65
- else {
66
- port = this.path;
67
- }
68
- const adapterSettings = { interface: this.serial.getName(), host, port, protocol };
69
- const adapter = adapter_factory_1.default.getInstance().createInstance(adapterSettings);
70
- found = yield adapter.check();
71
- if (found) {
72
- this.isFound = true;
73
- const name = adapter.getName();
74
- resolve(Object.assign(Object.assign({}, adapterSettings), { name }));
75
- }
76
- yield (0, utils_1.sleep)(100);
77
- }
78
- catch (err) {
79
- this.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
80
- yield (0, utils_1.sleep)(100);
81
- }
82
- }
83
- }));
84
- });
85
- }
86
- }
87
- exports.SinglePathScanner = SinglePathScanner;
@@ -1,14 +0,0 @@
1
- import { DeviceProperties } from '../types';
2
- import { SerialIncyclistDevice } from './adapter';
3
- import { SerialDeviceSettings } from "./types";
4
- export default class SerialAdapterFactory {
5
- static _instance: SerialAdapterFactory;
6
- adapters: Array<{
7
- protocol: string;
8
- AdapterClass: typeof SerialIncyclistDevice<DeviceProperties>;
9
- }>;
10
- static getInstance(): SerialAdapterFactory;
11
- constructor();
12
- registerAdapter(protocol: string, AdapterClass: typeof SerialIncyclistDevice<DeviceProperties>): void;
13
- createInstance(props: SerialDeviceSettings, settings?: any): SerialIncyclistDevice<DeviceProperties>;
14
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class SerialAdapterFactory {
4
- static getInstance() {
5
- if (!SerialAdapterFactory._instance)
6
- SerialAdapterFactory._instance = new SerialAdapterFactory();
7
- return SerialAdapterFactory._instance;
8
- }
9
- constructor() {
10
- this.adapters = [];
11
- }
12
- registerAdapter(protocol, AdapterClass) {
13
- const existing = this.adapters.findIndex(a => a.protocol === protocol);
14
- if (existing !== -1)
15
- this.adapters[existing].AdapterClass = AdapterClass;
16
- else
17
- this.adapters.push({ protocol, AdapterClass });
18
- }
19
- createInstance(props, settings) {
20
- const { protocol } = props;
21
- if (!protocol)
22
- return null;
23
- const adapter = this.adapters.find(a => a.protocol === protocol);
24
- if (!adapter)
25
- return null;
26
- const { AdapterClass } = adapter;
27
- return new AdapterClass(props, settings);
28
- }
29
- }
30
- exports.default = SerialAdapterFactory;
@@ -1,17 +0,0 @@
1
- import IncyclistDevice from "../base/adpater";
2
- import { DeviceProperties } from "../types";
3
- import SerialInterface from "./base/serial-interface";
4
- import { SerialDeviceSettings } from "./types";
5
- export declare class SerialIncyclistDevice<P extends DeviceProperties> extends IncyclistDevice<P> {
6
- pullFrequency: number;
7
- check(): Promise<boolean>;
8
- constructor(settings: SerialDeviceSettings, props?: P);
9
- isEqual(settings: SerialDeviceSettings): boolean;
10
- getPort(): string;
11
- getUniqueName(): string;
12
- getSerialInterface(): SerialInterface;
13
- getInterface(): string;
14
- setMaxUpdateFrequency(ms: number): void;
15
- setPullFrequency(ms: number): void;
16
- getPullFrequency(): number;
17
- }
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.SerialIncyclistDevice = void 0;
16
- const adpater_1 = __importDefault(require("../base/adpater"));
17
- const DEFAULT_PULL_FREQUENCY = 1000;
18
- class SerialIncyclistDevice extends adpater_1.default {
19
- check() {
20
- return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemnted'); });
21
- }
22
- ;
23
- constructor(settings, props) {
24
- super(settings, props);
25
- this.pullFrequency = DEFAULT_PULL_FREQUENCY;
26
- }
27
- isEqual(settings) {
28
- if (settings.interface !== this.getInterface())
29
- return false;
30
- const s = this.settings;
31
- if (settings.protocol !== s.protocol)
32
- return false;
33
- if (settings.port !== s.port)
34
- return false;
35
- if (settings.host && (!s.host || s.host !== settings.host))
36
- return false;
37
- return true;
38
- }
39
- getPort() {
40
- const settings = this.settings;
41
- return settings.port;
42
- }
43
- getUniqueName() {
44
- return `${this.getName()} (${this.getPort()})`;
45
- }
46
- getSerialInterface() {
47
- throw new Error('not implemented');
48
- }
49
- getInterface() {
50
- return 'serial';
51
- }
52
- setMaxUpdateFrequency(ms) {
53
- if (ms <= this.pullFrequency)
54
- this.updateFrequency = -1;
55
- else
56
- this.updateFrequency = ms;
57
- }
58
- setPullFrequency(ms) {
59
- this.pullFrequency = ms;
60
- if (this.updateFrequency <= this.pullFrequency)
61
- this.updateFrequency = -1;
62
- }
63
- getPullFrequency() {
64
- return this.pullFrequency;
65
- }
66
- }
67
- exports.SerialIncyclistDevice = SerialIncyclistDevice;
@@ -1,7 +0,0 @@
1
- import { EventLogger } from "gd-eventlog";
2
- import SerialInterface from "./serial-interface";
3
- export type SerialCommProps = {
4
- serial: SerialInterface;
5
- path: string;
6
- logger?: EventLogger;
7
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,62 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventLogger } from "gd-eventlog";
3
- import SerialInterface from "./base/serial-interface";
4
- import { SerialCommProps } from "./types";
5
- import { SerialPortStream } from "@serialport/stream";
6
- import { Queue } from "../utils/utils";
7
- export type ConnectionState = 'Connecting' | 'Connected' | 'Disconnected' | 'Disconnecting';
8
- export type Request = {
9
- logString?: string;
10
- isBinary?: boolean;
11
- };
12
- export type Response = {};
13
- export interface CommsState {
14
- data?: Queue<Response>;
15
- }
16
- export default class SerialPortComms<T extends CommsState, C extends Request, R extends Response> {
17
- logger: EventLogger;
18
- serial: SerialInterface;
19
- protected path: string;
20
- protected props: SerialCommProps;
21
- protected sp: SerialPortStream;
22
- protected connectState: ConnectionState;
23
- protected connectPromise: Promise<SerialPortStream>;
24
- protected disconnectPromise: Promise<boolean>;
25
- protected writePromise: Promise<void>;
26
- protected sendCmdPromise: Promise<R>;
27
- protected actualBikeType?: string;
28
- protected recvState: T;
29
- protected isLoggingPaused: boolean;
30
- constructor(props: SerialCommProps);
31
- getBusyTimeout(): number;
32
- getDefaultLoggerName(): string;
33
- getInitialCommsState(): T;
34
- validatePath(path: string): string;
35
- getInterface(): string;
36
- getPort(): string;
37
- isConnected(): boolean;
38
- pauseLogging(): void;
39
- resumeLogging(): void;
40
- logEvent(e: any): void;
41
- connect(): Promise<boolean>;
42
- onConnected(): void;
43
- portFlush(): void;
44
- portPipe(destination: any, options?: any): any;
45
- portUnpipe(destination?: any): void;
46
- closePort(): Promise<boolean>;
47
- resetState(isDisconnected?: boolean): void;
48
- cleanupPort(isDisconnected?: boolean): void;
49
- close(): Promise<boolean>;
50
- flush(): Promise<void>;
51
- onPortClose(): Promise<void>;
52
- onPortError(error: Error): Promise<void>;
53
- isSending(): boolean;
54
- rejectCurrent(error: Error): void;
55
- getTimeoutValue(): number;
56
- onData(data: any, depth?: number): Promise<void>;
57
- send(command: C): Promise<R>;
58
- portWrite(buffer: Buffer): Promise<void>;
59
- write(buffer: Buffer): Promise<void>;
60
- ensurePrevCmdFinish(logPayload: any): Promise<void>;
61
- ensureConnection(): Promise<void>;
62
- }
@@ -1,280 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const gd_eventlog_1 = require("gd-eventlog");
13
- const utils_1 = require("./daum/premium/utils");
14
- const utils_2 = require("../utils/utils");
15
- const DEFAULT_BUSY_TIMEOUT = 5000;
16
- class SerialPortComms {
17
- constructor(props) {
18
- this.props = props;
19
- const { logger, serial, path } = props;
20
- this.serial = serial;
21
- this.path = this.validatePath(path);
22
- const w = global.window;
23
- this.logger = logger || ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.DEBUG ? utils_1.DEBUG_LOGGER : new gd_eventlog_1.EventLogger(this.getDefaultLoggerName()));
24
- this.resetState();
25
- }
26
- getBusyTimeout() {
27
- return DEFAULT_BUSY_TIMEOUT;
28
- }
29
- getDefaultLoggerName() {
30
- return 'Serial';
31
- }
32
- getInitialCommsState() {
33
- return { data: new utils_2.Queue() };
34
- }
35
- validatePath(path) {
36
- return path;
37
- }
38
- getInterface() {
39
- var _a;
40
- return (_a = this.serial) === null || _a === void 0 ? void 0 : _a.ifaceName;
41
- }
42
- getPort() {
43
- return this.path;
44
- }
45
- isConnected() {
46
- return this.connectState === 'Connected' || this.connectState === 'Disconnecting';
47
- }
48
- pauseLogging() {
49
- this.isLoggingPaused = true;
50
- }
51
- resumeLogging() {
52
- this.isLoggingPaused = false;
53
- }
54
- logEvent(e) {
55
- if (this.isLoggingPaused)
56
- return;
57
- this.logger.logEvent(e);
58
- const w = global.window;
59
- if (w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) {
60
- console.log(`~~~ ${this.getDefaultLoggerName()}`, e);
61
- }
62
- }
63
- connect() {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- if (this.isConnected() && this.sp) {
66
- return true;
67
- }
68
- if (this.connectState === 'Connecting') {
69
- if (this.connectPromise) {
70
- try {
71
- yield this.connectPromise;
72
- }
73
- catch (_a) {
74
- }
75
- }
76
- return this.isConnected();
77
- }
78
- try {
79
- this.connectState = 'Connecting';
80
- this.connectPromise = this.serial.openPort(this.path);
81
- const port = yield this.connectPromise;
82
- this.connectPromise = null;
83
- if (port !== null) {
84
- this.connectState = 'Connected';
85
- this.sp = port;
86
- this.sp.on('close', this.onPortClose.bind(this));
87
- this.sp.on('error', this.onPortError.bind(this));
88
- this.onConnected();
89
- return true;
90
- }
91
- else {
92
- this.connectState = 'Disconnected';
93
- return false;
94
- }
95
- }
96
- catch (_b) {
97
- this.connectState = 'Disconnected';
98
- return false;
99
- }
100
- });
101
- }
102
- onConnected() {
103
- }
104
- portFlush() {
105
- if (this.sp)
106
- this.sp.flush();
107
- }
108
- portPipe(destination, options) {
109
- if (this.sp)
110
- return this.sp.pipe(destination, options);
111
- }
112
- portUnpipe(destination) {
113
- if (this.sp)
114
- this.sp.unpipe(destination);
115
- }
116
- closePort() {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- if (!this.sp)
119
- return true;
120
- try {
121
- yield this.flush();
122
- yield this.serial.closePort(this.path);
123
- return true;
124
- }
125
- catch (err) {
126
- this.logEvent({ message: 'could not close ', reason: err.message });
127
- return false;
128
- }
129
- });
130
- }
131
- resetState(isDisconnected = true) {
132
- this.isLoggingPaused = false;
133
- this.recvState = this.getInitialCommsState();
134
- this.connectPromise = null;
135
- this.disconnectPromise = null;
136
- this.writePromise = null;
137
- this.sendCmdPromise = null;
138
- if (isDisconnected)
139
- this.connectState = 'Disconnected';
140
- }
141
- cleanupPort(isDisconnected = true) {
142
- if (this.sp) {
143
- this.sp.removeAllListeners();
144
- }
145
- this.sp = null;
146
- this.resetState(isDisconnected);
147
- }
148
- close() {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- let isDisconnected = false;
151
- if (this.disconnectPromise) {
152
- try {
153
- isDisconnected = yield this.disconnectPromise;
154
- }
155
- catch (_a) {
156
- }
157
- return isDisconnected;
158
- }
159
- if (this.connectState === 'Disconnected') {
160
- this.cleanupPort();
161
- return true;
162
- }
163
- else if (this.connectState === 'Disconnecting' || this.connectState === 'Connected' || this.connectState === 'Connecting') {
164
- this.connectState = 'Disconnecting';
165
- this.disconnectPromise = this.closePort();
166
- isDisconnected = yield this.disconnectPromise;
167
- if (isDisconnected) {
168
- this.connectState = 'Disconnected';
169
- this.logEvent({ message: "port closed:", port: this.path });
170
- }
171
- this.cleanupPort(isDisconnected);
172
- }
173
- return isDisconnected;
174
- });
175
- }
176
- flush() {
177
- return __awaiter(this, void 0, void 0, function* () {
178
- if (this.writePromise) {
179
- yield (0, utils_2.waitWithTimeout)(this.writePromise, 1000);
180
- this.writePromise = null;
181
- }
182
- });
183
- }
184
- onPortClose() {
185
- return __awaiter(this, void 0, void 0, function* () {
186
- if (this.connectState !== 'Disconnected' && this.connectState !== 'Disconnecting')
187
- this.logEvent({ message: "port closed:", port: this.path });
188
- this.connectState = 'Disconnected';
189
- this.cleanupPort();
190
- });
191
- }
192
- onPortError(error) {
193
- return __awaiter(this, void 0, void 0, function* () {
194
- if (this.connectState === 'Disconnecting' || this.connectState === 'Disconnected') {
195
- return;
196
- }
197
- this.logEvent({ message: "port error:", port: this.path, error: error.message, connected: this.isConnected(), state: this.connectState });
198
- if (this.isSending()) {
199
- this.rejectCurrent(error);
200
- }
201
- if (this.connectState === 'Connected')
202
- this.close();
203
- });
204
- }
205
- isSending() {
206
- return (this.writePromise !== undefined && this.writePromise !== null) || (this.sendCmdPromise !== null && this.sendCmdPromise !== undefined);
207
- }
208
- rejectCurrent(error) {
209
- this.recvState.data.enqueue({ type: 'Error', error });
210
- }
211
- getTimeoutValue() {
212
- throw new Error('method not implemented');
213
- }
214
- onData(data, depth = 0) {
215
- return __awaiter(this, void 0, void 0, function* () {
216
- });
217
- }
218
- send(command) {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- throw new Error('method not implemented');
221
- });
222
- }
223
- portWrite(buffer) {
224
- return __awaiter(this, void 0, void 0, function* () {
225
- if (!this.sp) {
226
- this.logEvent({ message: 'write failed', error: 'port is not opened' });
227
- return;
228
- }
229
- try {
230
- yield this.sp.write(buffer);
231
- }
232
- catch (err) {
233
- this.logEvent({ message: 'write failed', error: err.message });
234
- }
235
- });
236
- }
237
- write(buffer) {
238
- return __awaiter(this, void 0, void 0, function* () {
239
- if (this.writePromise) {
240
- try {
241
- yield this.writePromise;
242
- }
243
- catch (_a) {
244
- }
245
- this.writePromise = null;
246
- }
247
- this.writePromise = this.portWrite(buffer);
248
- yield this.writePromise;
249
- this.writePromise = null;
250
- });
251
- }
252
- ensurePrevCmdFinish(logPayload) {
253
- return __awaiter(this, void 0, void 0, function* () {
254
- if (this.sendCmdPromise) {
255
- const tsRequest = Date.now();
256
- this.logEvent(Object.assign({ message: 'sendCommand:waiting:' }, logPayload));
257
- let busyTimedOut = false;
258
- const onTimeout = () => {
259
- this.logEvent(Object.assign(Object.assign({ message: 'sendCommand:error:' }, logPayload), { error: 'BUSY timeout', duration: Date.now() - tsRequest }));
260
- busyTimedOut = true;
261
- };
262
- yield (0, utils_2.waitWithTimeout)(this.sendCmdPromise, this.getBusyTimeout(), onTimeout);
263
- this.sendCmdPromise = null;
264
- if (busyTimedOut)
265
- throw new Error('BUSY timeout');
266
- }
267
- });
268
- }
269
- ensureConnection() {
270
- return __awaiter(this, void 0, void 0, function* () {
271
- if (!this.isConnected()) {
272
- const connected = yield this.connect();
273
- if (!connected) {
274
- throw new Error('not connected');
275
- }
276
- }
277
- });
278
- }
279
- }
280
- exports.default = SerialPortComms;
@@ -1,2 +0,0 @@
1
- export declare const PROTOCOL_NAME = "Daum Classic";
2
- export declare const DEFAULT_GEAR = 10;