incyclist-devices 2.0.0-beta.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.MD +238 -0
  2. package/lib/adapters.d.ts +1 -0
  3. package/lib/adapters.js +19 -0
  4. package/lib/antv2/adapter-factory.d.ts +8 -7
  5. package/lib/antv2/adapter-factory.js +4 -2
  6. package/lib/antv2/adapter.d.ts +3 -2
  7. package/lib/antv2/adapter.js +15 -4
  8. package/lib/antv2/ant-interface.d.ts +6 -2
  9. package/lib/antv2/ant-interface.js +27 -21
  10. package/lib/antv2/binding.d.ts +1 -1
  11. package/lib/antv2/binding.js +1 -1
  12. package/lib/antv2/fe/adapter.d.ts +12 -9
  13. package/lib/antv2/fe/adapter.js +67 -27
  14. package/lib/antv2/hr/adapter.d.ts +6 -5
  15. package/lib/antv2/hr/adapter.js +19 -16
  16. package/lib/antv2/index.d.ts +2 -2
  17. package/lib/antv2/pwr/adapter.d.ts +6 -4
  18. package/lib/antv2/pwr/adapter.js +24 -16
  19. package/lib/antv2/sensor-factory.d.ts +2 -2
  20. package/lib/antv2/types.d.ts +5 -2
  21. package/lib/antv2/types.js +3 -0
  22. package/lib/antv2/utils.d.ts +3 -0
  23. package/lib/antv2/utils.js +12 -1
  24. package/lib/base/adpater.d.ts +14 -2
  25. package/lib/base/adpater.js +43 -4
  26. package/lib/ble/adapter-factory.d.ts +18 -16
  27. package/lib/ble/adapter-factory.js +54 -45
  28. package/lib/ble/base/adapter.d.ts +53 -0
  29. package/lib/ble/{adapter.js → base/adapter.js} +111 -9
  30. package/lib/ble/base/comms-utils.d.ts +7 -0
  31. package/lib/ble/base/comms-utils.js +91 -0
  32. package/lib/ble/{ble-comms.d.ts → base/comms.d.ts} +27 -17
  33. package/lib/ble/{ble-comms.js → base/comms.js} +179 -53
  34. package/lib/ble/bindings/index.d.ts +2 -0
  35. package/lib/ble/bindings/index.js +8 -0
  36. package/lib/ble/bindings/linux.d.ts +15 -0
  37. package/lib/ble/bindings/linux.js +39 -0
  38. package/lib/ble/bindings/mock.d.ts +9 -0
  39. package/lib/ble/bindings/mock.js +108 -0
  40. package/lib/ble/bindings/types.d.ts +57 -0
  41. package/lib/ble/bindings/types.js +96 -0
  42. package/lib/ble/ble-interface.d.ts +34 -46
  43. package/lib/ble/ble-interface.js +242 -345
  44. package/lib/ble/ble-peripheral.d.ts +4 -2
  45. package/lib/ble/ble-peripheral.js +39 -8
  46. package/lib/ble/consts.d.ts +1 -0
  47. package/lib/ble/consts.js +2 -1
  48. package/lib/ble/cp/adapter.d.ts +1 -2
  49. package/lib/ble/cp/adapter.js +2 -15
  50. package/lib/ble/cp/comm.d.ts +8 -5
  51. package/lib/ble/cp/comm.js +12 -27
  52. package/lib/ble/elite/adapter.d.ts +1 -2
  53. package/lib/ble/elite/adapter.js +12 -19
  54. package/lib/ble/elite/comms.d.ts +8 -4
  55. package/lib/ble/elite/comms.js +12 -25
  56. package/lib/ble/fm/adapter.d.ts +3 -2
  57. package/lib/ble/fm/adapter.js +129 -70
  58. package/lib/ble/fm/comms.d.ts +8 -8
  59. package/lib/ble/fm/comms.js +33 -55
  60. package/lib/ble/fm/types.d.ts +5 -0
  61. package/lib/ble/hr/adapter.d.ts +1 -4
  62. package/lib/ble/hr/adapter.js +1 -18
  63. package/lib/ble/hr/comm.d.ts +6 -2
  64. package/lib/ble/hr/comm.js +6 -2
  65. package/lib/ble/hr/mock.d.ts +7 -0
  66. package/lib/ble/hr/mock.js +47 -0
  67. package/lib/ble/index.d.ts +2 -1
  68. package/lib/ble/index.js +5 -5
  69. package/lib/ble/peripheral-cache.d.ts +43 -0
  70. package/lib/ble/peripheral-cache.js +107 -0
  71. package/lib/ble/tacx/adapter.d.ts +1 -1
  72. package/lib/ble/tacx/adapter.js +20 -14
  73. package/lib/ble/tacx/comms.d.ts +6 -6
  74. package/lib/ble/tacx/comms.js +10 -43
  75. package/lib/ble/types.d.ts +54 -27
  76. package/lib/ble/types.js +0 -17
  77. package/lib/ble/utils.d.ts +15 -5
  78. package/lib/ble/utils.js +25 -66
  79. package/lib/ble/wahoo/adapter.d.ts +1 -1
  80. package/lib/ble/wahoo/adapter.js +12 -10
  81. package/lib/ble/wahoo/comms.d.ts +7 -6
  82. package/lib/ble/wahoo/comms.js +15 -17
  83. package/lib/index.d.ts +10 -7
  84. package/lib/index.js +21 -25
  85. package/lib/interfaces.d.ts +2 -1
  86. package/lib/interfaces.js +4 -0
  87. package/lib/modes/power-base.js +4 -0
  88. package/lib/serial/adapter.d.ts +5 -0
  89. package/lib/serial/adapter.js +19 -0
  90. package/lib/serial/bindings/tcp.d.ts +2 -1
  91. package/lib/serial/bindings/tcp.js +19 -5
  92. package/lib/serial/daum/DaumAdapter.d.ts +1 -1
  93. package/lib/serial/daum/DaumAdapter.js +16 -10
  94. package/lib/serial/daum/premium/adapter.d.ts +1 -0
  95. package/lib/serial/daum/premium/adapter.js +9 -2
  96. package/lib/serial/daum/premium/comms.js +10 -3
  97. package/lib/serial/daum/premium/mock.js +0 -1
  98. package/lib/serial/index.d.ts +3 -3
  99. package/lib/serial/index.js +2 -2
  100. package/lib/serial/kettler/ergo-racer/adapter.d.ts +1 -4
  101. package/lib/serial/kettler/ergo-racer/adapter.js +15 -39
  102. package/lib/serial/serial-interface.d.ts +3 -1
  103. package/lib/serial/serial-interface.js +43 -17
  104. package/lib/simulator/Simulator.d.ts +2 -0
  105. package/lib/simulator/Simulator.js +8 -5
  106. package/lib/types/adapter.d.ts +10 -3
  107. package/lib/types/device.d.ts +3 -0
  108. package/lib/types/interface.d.ts +7 -3
  109. package/package.json +3 -5
  110. package/lib/ble/adapter.d.ts +0 -41
  111. package/lib/ble/ble.d.ts +0 -57
  112. package/lib/ble/ble.js +0 -48
  113. package/lib/device.d.ts +0 -0
  114. package/lib/device.js +0 -0
@@ -0,0 +1,96 @@
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
+ exports.StaticNotifyCharacteristic = exports.StaticWriteCharacteristic = exports.StaticReadCharacteristic = exports.MockCharacteristic = exports.RESULT_UNLIKELY_ERROR = exports.RESULT_INVALID_ATTRIBUTE_LENGTH = exports.RESULT_ATTR_NOT_LONG = exports.RESULT_INVALID_OFFSET = exports.RESULT_SUCCESS = void 0;
7
+ const events_1 = __importDefault(require("events"));
8
+ exports.RESULT_SUCCESS = 0x00;
9
+ exports.RESULT_INVALID_OFFSET = 0x07;
10
+ exports.RESULT_ATTR_NOT_LONG = 0x0b;
11
+ exports.RESULT_INVALID_ATTRIBUTE_LENGTH = 0x0d;
12
+ exports.RESULT_UNLIKELY_ERROR = 0x0e;
13
+ class MockCharacteristic extends events_1.default {
14
+ subscribe(callback) {
15
+ throw new Error("Method not implemented.");
16
+ }
17
+ unsubscribe(callback) {
18
+ throw new Error("Method not implemented.");
19
+ }
20
+ read(callback) {
21
+ throw new Error("Method not implemented.");
22
+ }
23
+ write(data, withoutResponse, callback) {
24
+ throw new Error("Method not implemented.");
25
+ }
26
+ }
27
+ exports.MockCharacteristic = MockCharacteristic;
28
+ class StaticReadCharacteristic extends MockCharacteristic {
29
+ constructor(uuid, description, value) {
30
+ super();
31
+ this.uuid = uuid;
32
+ this.properties = ['read'];
33
+ this.value = Buffer.isBuffer(value) ? value : Buffer.from(value);
34
+ this.descriptors = [{ uuid: '2901', value: description }];
35
+ }
36
+ read(callback) {
37
+ callback(undefined, this.value);
38
+ }
39
+ }
40
+ exports.StaticReadCharacteristic = StaticReadCharacteristic;
41
+ class StaticWriteCharacteristic extends MockCharacteristic {
42
+ constructor(uuid, description, size) {
43
+ super();
44
+ this.uuid = uuid;
45
+ this.properties = ['write'];
46
+ this.value = Buffer.alloc(2);
47
+ this.descriptors = [{ uuid: '2901', value: description }];
48
+ this.size = size;
49
+ }
50
+ write(data, withoutResponse, callback) {
51
+ this.value = data;
52
+ if (!withoutResponse && callback)
53
+ callback();
54
+ }
55
+ }
56
+ exports.StaticWriteCharacteristic = StaticWriteCharacteristic;
57
+ class StaticNotifyCharacteristic extends MockCharacteristic {
58
+ constructor(uuid, description) {
59
+ super();
60
+ this.uuid = uuid;
61
+ this.properties = ['notify'];
62
+ this.descriptors = [{ uuid: '2901', value: description }];
63
+ this.cntSubscriptions = 0;
64
+ this.notifyFrequency = 500;
65
+ }
66
+ subscribe(callback) {
67
+ this.cntSubscriptions++;
68
+ this.startNotify();
69
+ if (callback)
70
+ callback(undefined);
71
+ }
72
+ unsubscribe(callback) {
73
+ if (this.cntSubscriptions === 0) {
74
+ if (callback)
75
+ callback(new Error('not subscribed'));
76
+ return;
77
+ }
78
+ this.cntSubscriptions--;
79
+ if (this.cntSubscriptions === 0) {
80
+ this.stopNotify();
81
+ }
82
+ if (callback)
83
+ callback(undefined);
84
+ }
85
+ startNotify() {
86
+ if (!this.iv)
87
+ this.iv = setInterval(this.notify.bind(this), this.notifyFrequency);
88
+ }
89
+ stopNotify() {
90
+ if (this.iv) {
91
+ clearInterval(this.iv);
92
+ this.iv = null;
93
+ }
94
+ }
95
+ }
96
+ exports.StaticNotifyCharacteristic = StaticNotifyCharacteristic;
@@ -1,14 +1,20 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { EventLogger } from 'gd-eventlog';
3
- import { BleInterfaceClass, BleScanProps, BleBinding } from './ble';
4
- import { BleComms } from './ble-comms';
5
4
  import BleAdapterFactory from './adapter-factory';
6
- import { ConnectProps, BlePeripheral, BleCharacteristic, BleDeviceSettings } from './types';
5
+ import { BleInterfaceProps, BlePeripheral, BleDeviceSettings, BleProtocol, BleBinding, BleInterfaceState, BleScanProps, BleCharacteristic } from './types';
6
+ import { BleComms } from './base/comms';
7
+ import { IncyclistInterface } from '../types/interface';
8
+ import BleAdapter from './base/adapter';
9
+ import { IncyclistScanProps } from '../types/device';
10
+ import BlePeripheralCache from './peripheral-cache';
11
+ import EventEmitter from 'events';
7
12
  export interface ScanState {
8
13
  isScanning: boolean;
9
14
  isConnecting: boolean;
10
15
  isBackgroundScan: boolean;
11
16
  timeout?: NodeJS.Timeout;
17
+ peripherals?: Map<string, BlePeripheral>;
12
18
  }
13
19
  export interface ConnectState {
14
20
  isConnecting: boolean;
@@ -16,11 +22,6 @@ export interface ConnectState {
16
22
  timeout?: NodeJS.Timeout;
17
23
  isInitSuccess: boolean;
18
24
  }
19
- export interface PeripheralState {
20
- isLoading: boolean;
21
- isConfigured: boolean;
22
- isInterrupted: boolean;
23
- }
24
25
  export interface BleDeviceInfo {
25
26
  device: BleComms;
26
27
  isConnected: boolean;
@@ -31,61 +32,48 @@ export interface BleDeviceClassInfo {
31
32
  services: string[];
32
33
  id: string;
33
34
  }
34
- export interface PeripheralCacheItem {
35
- address: string;
36
- ts: number;
37
- peripheral: BlePeripheral;
38
- state?: PeripheralState;
39
- characteristics?: BleCharacteristic[];
40
- }
41
- export default class BleInterface extends BleInterfaceClass {
35
+ export default class BleInterface extends EventEmitter implements IncyclistInterface {
42
36
  scanState: ScanState;
43
37
  connectState: ConnectState;
44
- devices: BleDeviceInfo[];
45
- peripheralCache: any[];
38
+ peripheralCache: BlePeripheralCache;
46
39
  logger: EventLogger;
40
+ props: BleInterfaceProps;
41
+ binding: BleBinding;
42
+ connectedDevices: BleAdapter[];
43
+ sensorIsConnecting: boolean;
47
44
  static _instance: BleInterface;
48
45
  static getInstance(props?: {
49
46
  binding?: BleBinding;
50
47
  log?: boolean;
51
48
  logger?: EventLogger;
52
49
  }): BleInterface;
53
- constructor(props?: {
54
- binding?: BleBinding;
55
- log?: boolean;
56
- logger?: EventLogger;
57
- });
50
+ constructor(props?: BleInterfaceProps);
51
+ getBinding(): BleBinding;
52
+ setBinding(binding: BleBinding): void;
53
+ getName(): string;
54
+ startConnectSensor(): void;
55
+ stopConnectSensor(): void;
56
+ waitForSensorConnectionFinish(): Promise<void>;
58
57
  getAdapterFactory(): BleAdapterFactory;
59
58
  logEvent(event: any): void;
60
- onStateChange(state: any): void;
59
+ onStateChange(state: BleInterfaceState): void;
61
60
  onError(err: any): void;
62
- connect(props?: ConnectProps): Promise<boolean>;
61
+ connect(to?: number): Promise<boolean>;
63
62
  disconnect(): Promise<boolean>;
64
63
  isConnected(): boolean;
65
64
  waitForConnectFinished(timeout: any): Promise<unknown>;
66
- addPeripheralToCache(peripheral: any, props?: {}): void;
67
65
  onDisconnect(peripheral: any): void;
68
- getConnector(peripheral: BlePeripheral): any;
69
- findPeripheral(peripheral: BlePeripheral | {
70
- id?: string;
71
- address?: string;
72
- name?: string;
73
- }): BlePeripheral;
74
- getCharacteristics(peripheral: any): Promise<any>;
75
- createDeviceComms(DeviceClass: (typeof BleComms), peripheral: BlePeripheral, characteristics?: BleCharacteristic[]): any;
76
- connectDevice(requested: BleComms | BleDeviceSettings, timeout?: number): Promise<BleComms>;
66
+ getCharacteristics(peripheral: BlePeripheral): Promise<BleCharacteristic[]>;
77
67
  waitForScanFinished(timeout: any): Promise<unknown>;
78
- scan(props: BleScanProps): Promise<BleComms[]>;
68
+ onPeripheralFound(p: BlePeripheral, callback: any, props?: {
69
+ request?: BleDeviceSettings;
70
+ comms?: BleComms;
71
+ protocolFilter?: BleProtocol[] | null;
72
+ }): Promise<any>;
73
+ scanForDevice(comms: BleComms, props: IncyclistScanProps): Promise<BlePeripheral>;
74
+ scan(props?: BleScanProps): Promise<BleDeviceSettings[]>;
79
75
  stopScan(): Promise<boolean>;
80
76
  isScanning(): boolean;
81
- addConnectedDevice(device: BleComms): void;
82
- addDeviceToCache(device: BleComms, isConnected: boolean): void;
83
- findConnected(device: BleComms | BlePeripheral): BleComms;
84
- findDeviceInCache(device: {
85
- id?: string;
86
- address?: string;
87
- name?: string;
88
- profile: string;
89
- }): BleComms;
90
- removeConnectedDevice(device: BleComms): void;
77
+ addConnectedDevice(device: BleAdapter): void;
78
+ removeConnectedDevice(device: BleAdapter): void;
91
79
  }