incyclist-devices 2.1.0 → 2.1.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 (159) hide show
  1. package/lib/adapters.d.ts +1 -1
  2. package/lib/antv2/adapter-factory.d.ts +4 -15
  3. package/lib/antv2/adapter.d.ts +15 -15
  4. package/lib/antv2/adapter.js +67 -21
  5. package/lib/antv2/ant-interface.d.ts +3 -11
  6. package/lib/antv2/ant-interface.js +1 -1
  7. package/lib/antv2/base/adapter.d.ts +62 -0
  8. package/lib/antv2/base/adapter.js +360 -0
  9. package/lib/antv2/base/ant-interface.d.ts +35 -0
  10. package/lib/antv2/base/ant-interface.js +285 -0
  11. package/lib/antv2/base/binding.d.ts +13 -0
  12. package/lib/antv2/base/binding.js +27 -0
  13. package/lib/antv2/cad/adapter.d.ts +10 -0
  14. package/lib/antv2/cad/adapter.js +25 -0
  15. package/lib/antv2/cad/index.d.ts +2 -0
  16. package/lib/antv2/cad/index.js +7 -0
  17. package/lib/antv2/consts.d.ts +2 -0
  18. package/lib/antv2/consts.js +5 -0
  19. package/lib/antv2/factories/adapter-factory.d.ts +14 -0
  20. package/lib/antv2/factories/adapter-factory.js +65 -0
  21. package/lib/antv2/factories/sensor-factory.d.ts +5 -0
  22. package/lib/antv2/factories/sensor-factory.js +22 -0
  23. package/lib/antv2/fe/adapter.d.ts +24 -29
  24. package/lib/antv2/fe/adapter.js +208 -225
  25. package/lib/antv2/hr/adapter.d.ts +6 -15
  26. package/lib/antv2/hr/adapter.js +7 -55
  27. package/lib/antv2/hr copy/adapter.d.ts +11 -0
  28. package/lib/antv2/hr copy/adapter.js +30 -0
  29. package/lib/antv2/hr copy/index.d.ts +2 -0
  30. package/lib/antv2/hr copy/index.js +7 -0
  31. package/lib/antv2/index.d.ts +5 -4
  32. package/lib/antv2/index.js +4 -2
  33. package/lib/antv2/pwr/adapter.d.ts +9 -33
  34. package/lib/antv2/pwr/adapter.js +19 -140
  35. package/lib/antv2/types.d.ts +23 -4
  36. package/lib/base/adpater.d.ts +39 -60
  37. package/lib/base/adpater.js +139 -161
  38. package/lib/base/consts.d.ts +4 -0
  39. package/lib/base/consts.js +9 -0
  40. package/lib/ble/adapter-factory.d.ts +10 -11
  41. package/lib/ble/base/adapter.d.ts +7 -14
  42. package/lib/ble/base/adapter.js +2 -36
  43. package/lib/ble/ble-interface.d.ts +5 -7
  44. package/lib/ble/cp/adapter.d.ts +6 -8
  45. package/lib/ble/cp/adapter.js +8 -27
  46. package/lib/ble/elite/adapter.d.ts +7 -8
  47. package/lib/ble/elite/adapter.js +5 -25
  48. package/lib/ble/fm/adapter.d.ts +6 -7
  49. package/lib/ble/fm/adapter.js +13 -34
  50. package/lib/ble/hr/adapter.d.ts +5 -8
  51. package/lib/ble/hr/adapter.js +2 -2
  52. package/lib/ble/peripheral-cache.d.ts +2 -3
  53. package/lib/ble/tacx/adapter.d.ts +2 -3
  54. package/lib/ble/tacx/adapter.js +8 -8
  55. package/lib/ble/types.d.ts +1 -2
  56. package/lib/ble/wahoo/adapter.d.ts +2 -2
  57. package/lib/ble/wahoo/adapter.js +6 -6
  58. package/lib/ble/wahoo/comms.js +16 -16
  59. package/lib/factories/adapters.d.ts +7 -0
  60. package/lib/factories/adapters.js +49 -0
  61. package/lib/factories/index.d.ts +3 -0
  62. package/lib/factories/index.js +10 -0
  63. package/lib/factories/interfaces.d.ts +7 -0
  64. package/lib/factories/interfaces.js +27 -0
  65. package/lib/index.d.ts +5 -6
  66. package/lib/index.js +4 -9
  67. package/lib/interfaces.d.ts +1 -1
  68. package/lib/modes/ant-fe-adv-st-mode.d.ts +1 -1
  69. package/lib/modes/antble-erg.d.ts +1 -1
  70. package/lib/modes/antble-smarttrainer.d.ts +2 -2
  71. package/lib/modes/base.d.ts +5 -5
  72. package/lib/modes/daum-classic-standard.d.ts +3 -2
  73. package/lib/modes/daum-erg.d.ts +3 -3
  74. package/lib/modes/daum-premium-standard.d.ts +3 -2
  75. package/lib/modes/daum-smarttrainer.d.ts +3 -2
  76. package/lib/modes/kettler-erg.d.ts +3 -3
  77. package/lib/modes/power-base.d.ts +3 -3
  78. package/lib/modes/power-base.js +2 -2
  79. package/lib/modes/power-meter.d.ts +3 -2
  80. package/lib/modes/simulator.d.ts +2 -1
  81. package/lib/modes/types.d.ts +2 -13
  82. package/lib/serial/SinglePathScanner.d.ts +17 -0
  83. package/lib/serial/SinglePathScanner.js +87 -0
  84. package/lib/serial/adapter-factory.d.ts +6 -6
  85. package/lib/serial/adapter.d.ts +6 -11
  86. package/lib/serial/base/adapter.d.ts +17 -0
  87. package/lib/serial/base/adapter.js +67 -0
  88. package/lib/serial/base/comms.d.ts +62 -0
  89. package/lib/serial/base/comms.js +280 -0
  90. package/lib/serial/base/serial-interface.d.ts +36 -0
  91. package/lib/serial/base/serial-interface.js +288 -0
  92. package/lib/serial/base/serial-scanner.d.ts +16 -0
  93. package/lib/serial/base/serial-scanner.js +87 -0
  94. package/lib/serial/base/serialport.d.ts +17 -0
  95. package/lib/serial/base/serialport.js +87 -0
  96. package/lib/serial/comms.d.ts +2 -2
  97. package/lib/serial/daum/DaumAdapter.d.ts +12 -24
  98. package/lib/serial/daum/DaumAdapter.js +40 -59
  99. package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +2 -0
  100. package/lib/serial/daum/classic/PROTOCOL_NAME.js +5 -0
  101. package/lib/serial/daum/classic/adapter.d.ts +8 -20
  102. package/lib/serial/daum/classic/adapter.js +28 -58
  103. package/lib/serial/daum/classic/comms.d.ts +4 -6
  104. package/lib/serial/daum/classic/comms.js +2 -2
  105. package/lib/serial/daum/classic/consts.d.ts +2 -0
  106. package/lib/serial/daum/classic/consts.js +5 -0
  107. package/lib/serial/daum/classic/mock.js +4 -3
  108. package/lib/serial/daum/classic/types.d.ts +8 -10
  109. package/lib/serial/daum/classic/utils.d.ts +1 -2
  110. package/lib/serial/daum/consts.d.ts +0 -19
  111. package/lib/serial/daum/consts.js +0 -22
  112. package/lib/serial/daum/premium/adapter.d.ts +8 -11
  113. package/lib/serial/daum/premium/adapter.js +27 -53
  114. package/lib/serial/daum/premium/comms.d.ts +4 -7
  115. package/lib/serial/daum/premium/comms.js +23 -22
  116. package/lib/serial/daum/premium/mock.d.ts +1 -1
  117. package/lib/serial/daum/premium/mock.js +2 -2
  118. package/lib/serial/daum/premium/types.d.ts +32 -17
  119. package/lib/serial/daum/premium/types.js +8 -8
  120. package/lib/serial/daum/premium/utils.d.ts +2 -3
  121. package/lib/serial/daum/premium/utils.js +3 -3
  122. package/lib/serial/daum/types.d.ts +4 -1
  123. package/lib/serial/daum/types.js +9 -1
  124. package/lib/serial/factories/adapter-factory.d.ts +14 -0
  125. package/lib/serial/factories/adapter-factory.js +30 -0
  126. package/lib/serial/index.d.ts +8 -5
  127. package/lib/serial/index.js +15 -15
  128. package/lib/serial/kettler/comms.d.ts +1 -1
  129. package/lib/serial/kettler/ergo-racer/adapter.d.ts +11 -18
  130. package/lib/serial/kettler/ergo-racer/adapter.js +9 -21
  131. package/lib/serial/kettler/types.d.ts +8 -0
  132. package/lib/serial/kettler/types.js +2 -0
  133. package/lib/serial/serial-interface.d.ts +2 -32
  134. package/lib/serial/serial-interface.js +3 -76
  135. package/lib/serial/serial-scanner.d.ts +16 -0
  136. package/lib/serial/serial-scanner.js +87 -0
  137. package/lib/serial/serialport.d.ts +1 -13
  138. package/lib/serial/types.d.ts +45 -0
  139. package/lib/serial/types.js +9 -0
  140. package/lib/simulator/Simulator.d.ts +10 -13
  141. package/lib/simulator/Simulator.js +11 -23
  142. package/lib/types/Command.d.ts +8 -0
  143. package/lib/types/Command.js +2 -0
  144. package/lib/types/adapter.d.ts +22 -33
  145. package/lib/types/adapter.js +0 -68
  146. package/lib/types/command.d.ts +0 -8
  147. package/lib/types/command.js +0 -2
  148. package/lib/types/data.d.ts +12 -1
  149. package/lib/types/device.d.ts +8 -23
  150. package/lib/types/device.js +9 -8
  151. package/lib/types/index.d.ts +6 -0
  152. package/lib/types/index.js +22 -0
  153. package/lib/types/route.d.ts +0 -19
  154. package/lib/types/route.js +0 -2
  155. package/lib/types/types.d.ts +8 -0
  156. package/lib/types/types.js +2 -0
  157. package/lib/utils/utils.d.ts +1 -0
  158. package/lib/utils/utils.js +22 -4
  159. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { IncyclistDeviceAdapter } from "..";
1
+ import { IncyclistDeviceAdapter } from "../base/adpater";
2
2
  import SmartTrainerCyclingMode from "./antble-smarttrainer";
3
3
  import { UpdateRequest } from "./types";
4
4
  export default class AntAdvSimCyclingMode extends SmartTrainerCyclingMode {
@@ -1,6 +1,6 @@
1
- import { IncyclistDeviceAdapter } from "..";
2
1
  import ICyclingMode, { CyclingModeProperyType, UpdateRequest } from "./types";
3
2
  import PowerBasedCyclingModeBase from "./power-base";
3
+ import { IncyclistDeviceAdapter } from "../base/adpater";
4
4
  export default class ERGCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
5
5
  protected static config: {
6
6
  isERG: boolean;
@@ -1,6 +1,6 @@
1
1
  import ICyclingMode, { CyclingModeProperyType, UpdateRequest } from "./types";
2
2
  import PowerBasedCyclingModeBase from "./power-base";
3
- import { IncyclistDeviceAdapter } from "../types/adapter";
3
+ import { IAdapter } from "../types";
4
4
  export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
5
5
  protected static config: {
6
6
  name: string;
@@ -14,7 +14,7 @@ export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase i
14
14
  default: string;
15
15
  }[];
16
16
  };
17
- constructor(adapter: IncyclistDeviceAdapter, props?: any);
17
+ constructor(adapter: IAdapter, props?: any);
18
18
  getBikeInitRequest(): UpdateRequest;
19
19
  checkForResetOrEmpty(request: UpdateRequest): UpdateRequest | undefined;
20
20
  protected checkSlope(request: UpdateRequest, newRequest?: UpdateRequest): void;
@@ -1,15 +1,15 @@
1
- import { IncyclistDeviceAdapter } from "../types/adapter";
2
- import ICyclingMode, { CyclingMode, CyclingModeConfig, CyclingModeProperty, IncyclistBikeData, Settings, UpdateRequest } from "./types";
1
+ import { IncyclistBikeData, IAdapter } from "../types";
2
+ import ICyclingMode, { CyclingMode, CyclingModeConfig, CyclingModeProperty, Settings, UpdateRequest } from "./types";
3
3
  export declare abstract class CyclingModeBase extends CyclingMode implements ICyclingMode {
4
- adapter: IncyclistDeviceAdapter;
4
+ adapter: IAdapter;
5
5
  settings: Settings;
6
6
  properties: Settings;
7
7
  localConfig: CyclingModeConfig;
8
8
  protected static config: CyclingModeConfig;
9
9
  protected static isERG: boolean;
10
10
  static supportsERGMode(): boolean;
11
- constructor(adapter: IncyclistDeviceAdapter, props?: any);
12
- setAdapter(adapter: IncyclistDeviceAdapter): void;
11
+ constructor(adapter: IAdapter, props?: any);
12
+ setAdapter(adapter: IAdapter): void;
13
13
  setConfig(config: CyclingModeConfig): void;
14
14
  getConfig(): CyclingModeConfig;
15
15
  getName(): string;
@@ -1,6 +1,7 @@
1
- import ICyclingMode, { IncyclistBikeData, Settings, UpdateRequest } from "./types";
2
- import { IncyclistDeviceAdapter } from "../types/adapter";
1
+ import ICyclingMode, { Settings, UpdateRequest } from "./types";
2
+ import { IncyclistBikeData } from "../types";
3
3
  import SmartTrainerCyclingMode from "./antble-smarttrainer";
4
+ import { IncyclistDeviceAdapter } from "../base/adpater";
4
5
  type DaumClassicEvent = {
5
6
  noData?: boolean;
6
7
  slopeUpdate?: boolean;
@@ -1,6 +1,6 @@
1
- import ICyclingMode, { CyclingModeProperyType, IncyclistBikeData, UpdateRequest } from "./types";
1
+ import ICyclingMode, { CyclingModeProperyType, UpdateRequest } from "./types";
2
+ import { IncyclistBikeData, IAdapter } from "../types";
2
3
  import PowerBasedCyclingModeBase from "./power-base";
3
- import { IncyclistDeviceAdapter } from "../types/adapter";
4
4
  export type ERGEvent = {
5
5
  rpmUpdated?: boolean;
6
6
  gearUpdated?: boolean;
@@ -37,7 +37,7 @@ export default class ERGCyclingMode extends PowerBasedCyclingModeBase implements
37
37
  options?: undefined;
38
38
  })[];
39
39
  };
40
- constructor(adapter: IncyclistDeviceAdapter, props?: any);
40
+ constructor(adapter: IAdapter, props?: any);
41
41
  getBikeInitRequest(): UpdateRequest;
42
42
  sendBikeUpdate(request: UpdateRequest): UpdateRequest;
43
43
  copyBikeData(data: IncyclistBikeData, bikeData: IncyclistBikeData): IncyclistBikeData;
@@ -1,6 +1,7 @@
1
- import ICyclingMode, { CyclingModeProperyType, IncyclistBikeData, Settings, UpdateRequest } from "./types";
2
- import { IncyclistDeviceAdapter } from "../types/adapter";
1
+ import ICyclingMode, { CyclingModeProperyType, Settings, UpdateRequest } from "./types";
2
+ import { IncyclistBikeData } from "../types";
3
3
  import PowerMeterCyclingMode from "./power-meter";
4
+ import { IncyclistDeviceAdapter } from "../base/adpater";
4
5
  export default class DaumClassicCyclingMode extends PowerMeterCyclingMode implements ICyclingMode {
5
6
  prevInternalDistance: number;
6
7
  distanceOffset: number;
@@ -1,7 +1,8 @@
1
1
  import { EventLogger } from "gd-eventlog";
2
- import ICyclingMode, { CyclingModeProperyType, IncyclistBikeData, Settings, UpdateRequest } from "./types";
3
- import { IncyclistDeviceAdapter } from "..";
2
+ import ICyclingMode, { CyclingModeProperyType, Settings, UpdateRequest } from "./types";
3
+ import { IncyclistBikeData } from "../types";
4
4
  import { CyclingModeBase } from "./base";
5
+ import { IncyclistDeviceAdapter } from "../base/adpater";
5
6
  interface STUpdateRequest extends UpdateRequest {
6
7
  calculatedPower?: number;
7
8
  delta?: number;
@@ -1,6 +1,6 @@
1
- import ICyclingMode, { CyclingModeProperyType, IncyclistBikeData, UpdateRequest } from './types';
1
+ import ICyclingMode, { CyclingModeProperyType, UpdateRequest } from './types';
2
+ import { IncyclistBikeData, IAdapter } from "../types";
2
3
  import PowerBasedCyclingModeBase from './power-base';
3
- import { IncyclistDeviceAdapter } from '../types/adapter';
4
4
  export type ERGEvent = {
5
5
  rpmUpdated?: boolean;
6
6
  gearUpdated?: boolean;
@@ -37,7 +37,7 @@ export default class ERGCyclingMode extends PowerBasedCyclingModeBase implements
37
37
  chain: number[];
38
38
  cassette: number[];
39
39
  event: ERGEvent;
40
- constructor(adapter: IncyclistDeviceAdapter, props?: any);
40
+ constructor(adapter: IAdapter, props?: any);
41
41
  getBikeInitRequest(): UpdateRequest;
42
42
  sendBikeUpdate(request: UpdateRequest): UpdateRequest;
43
43
  updateData(bikeData: IncyclistBikeData): any;
@@ -1,6 +1,6 @@
1
- import { CyclingModeConfig, IncyclistBikeData, Settings, UpdateRequest } from './types';
1
+ import { CyclingModeConfig, Settings, UpdateRequest } from './types';
2
+ import { IncyclistBikeData, IAdapter } from "../types";
2
3
  import { EventLogger } from 'gd-eventlog';
3
- import { IncyclistDeviceAdapter } from '..';
4
4
  import { CyclingModeBase } from './base';
5
5
  export default class PowerBasedCyclingModeBase extends CyclingModeBase {
6
6
  data: IncyclistBikeData;
@@ -8,7 +8,7 @@ export default class PowerBasedCyclingModeBase extends CyclingModeBase {
8
8
  logger: EventLogger;
9
9
  prevRequest: UpdateRequest | undefined;
10
10
  protected static config: CyclingModeConfig;
11
- constructor(adapter: IncyclistDeviceAdapter, props?: Settings);
11
+ constructor(adapter: IAdapter, props?: Settings);
12
12
  getData(): IncyclistBikeData;
13
13
  getSlope(): number;
14
14
  initLogger(defaultLogName: any): void;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const adpater_1 = require("../base/adpater");
6
+ const consts_1 = require("../base/consts");
7
7
  const calculations_1 = __importDefault(require("../utils/calculations"));
8
8
  const gd_eventlog_1 = require("gd-eventlog");
9
9
  const base_1 = require("./base");
@@ -29,7 +29,7 @@ class PowerBasedCyclingModeBase extends base_1.CyclingModeBase {
29
29
  }
30
30
  getWeight() {
31
31
  const a = this.adapter;
32
- const defaultWeight = adpater_1.DEFAULT_BIKE_WEIGHT + adpater_1.DEFAULT_USER_WEIGHT;
32
+ const defaultWeight = consts_1.DEFAULT_BIKE_WEIGHT + consts_1.DEFAULT_USER_WEIGHT;
33
33
  const m = (a) ? a.getWeight() || defaultWeight : defaultWeight;
34
34
  return m;
35
35
  }
@@ -1,6 +1,7 @@
1
- import ICyclingMode, { IncyclistBikeData, Settings, UpdateRequest } from './types';
1
+ import ICyclingMode, { Settings, UpdateRequest } from './types';
2
+ import { IncyclistBikeData } from "../types";
2
3
  import PowerBasedCyclingModeBase from './power-base';
3
- import { IncyclistDeviceAdapter } from '..';
4
+ import { IncyclistDeviceAdapter } from '../base/adpater';
4
5
  export default class PowerMeterCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
5
6
  protected static config: {
6
7
  name: string;
@@ -1,5 +1,6 @@
1
1
  import { EventLogger } from "gd-eventlog";
2
- import { CyclingModeProperyType, IncyclistBikeData, UpdateRequest } from "./types";
2
+ import { CyclingModeProperyType, UpdateRequest } from "./types";
3
+ import { IncyclistBikeData } from "../types";
3
4
  import { Simulator } from "../simulator/Simulator";
4
5
  import PowerBasedCyclingModeBase from "./power-base";
5
6
  export type ERGEvent = {
@@ -1,4 +1,4 @@
1
- import { IBike } from "../types/adapter";
1
+ import { IAdapter, IncyclistBikeData } from "../types";
2
2
  export type UpdateRequest = {
3
3
  slope?: number;
4
4
  minPower?: number;
@@ -27,17 +27,6 @@ export type CyclingModeProperty = {
27
27
  default?: any;
28
28
  options?: any[];
29
29
  };
30
- export type IncyclistBikeData = {
31
- isPedalling?: boolean;
32
- power: number;
33
- pedalRpm: number;
34
- speed: number;
35
- heartrate?: number;
36
- distanceInternal?: number;
37
- time?: number;
38
- gear?: number;
39
- slope?: number;
40
- };
41
30
  export type Settings = {
42
31
  [key: string]: any;
43
32
  };
@@ -63,7 +52,7 @@ export type CyclingModeConfig = {
63
52
  properties: CyclingModeProperty[];
64
53
  };
65
54
  export declare class CyclingMode implements ICyclingMode {
66
- constructor(_adapter: IBike, _props?: any);
55
+ constructor(_adapter: IAdapter, _props?: any);
67
56
  static supportsERGMode(): boolean;
68
57
  getName(): string;
69
58
  getDescription(): string;
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,87 @@
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 +1,14 @@
1
- import { ControllableDevice } from '../base/adpater';
2
- import { DeviceProperties } from '../types/device';
3
- import { SerialIncyclistDevice, SerialDeviceSettings } from './adapter';
1
+ import { DeviceProperties } from '../types';
2
+ import { SerialIncyclistDevice } from './adapter';
3
+ import { SerialDeviceSettings } from "./types";
4
4
  export default class SerialAdapterFactory {
5
5
  static _instance: SerialAdapterFactory;
6
6
  adapters: Array<{
7
7
  protocol: string;
8
- AdapterClass: typeof SerialIncyclistDevice<ControllableDevice<DeviceProperties>, DeviceProperties>;
8
+ AdapterClass: typeof SerialIncyclistDevice<DeviceProperties>;
9
9
  }>;
10
10
  static getInstance(): SerialAdapterFactory;
11
11
  constructor();
12
- registerAdapter(protocol: string, AdapterClass: typeof SerialIncyclistDevice<ControllableDevice<DeviceProperties>, DeviceProperties>): void;
13
- createInstance(props: SerialDeviceSettings, settings?: any): SerialIncyclistDevice<ControllableDevice<DeviceProperties>, DeviceProperties>;
12
+ registerAdapter(protocol: string, AdapterClass: typeof SerialIncyclistDevice<DeviceProperties>): void;
13
+ createInstance(props: SerialDeviceSettings, settings?: any): SerialIncyclistDevice<DeviceProperties>;
14
14
  }
@@ -1,16 +1,11 @@
1
- import { DeviceProperties, DeviceSettings } from "../types/device";
2
- import IncyclistDevice, { ControllableDevice } from "../base/adpater";
3
- import SerialInterface from "./serial-interface";
4
- export interface SerialDeviceSettings extends DeviceSettings {
5
- protocol: string;
6
- host?: string;
7
- port?: string;
8
- interface: string | SerialInterface;
9
- }
10
- export declare class SerialIncyclistDevice<C extends ControllableDevice<P>, P extends DeviceProperties> extends IncyclistDevice<C, P> {
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> {
11
6
  pullFrequency: number;
12
7
  check(): Promise<boolean>;
13
- constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
8
+ constructor(settings: SerialDeviceSettings, props?: P);
14
9
  isEqual(settings: SerialDeviceSettings): boolean;
15
10
  getPort(): string;
16
11
  getUniqueName(): string;
@@ -0,0 +1,17 @@
1
+ import IncyclistDevice from "../../base/adpater";
2
+ import { DeviceProperties } from "../../types";
3
+ import SerialInterface from "./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
+ }
@@ -0,0 +1,67 @@
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;
@@ -0,0 +1,62 @@
1
+ /// <reference types="node" />
2
+ import { EventLogger } from "gd-eventlog";
3
+ import SerialInterface from "./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
+ }