incyclist-devices 2.2.9 → 2.3.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 (142) hide show
  1. package/lib/antv2/base/interface.js +2 -2
  2. package/lib/antv2/factories/index.d.ts +1 -0
  3. package/lib/antv2/factories/index.js +17 -0
  4. package/lib/antv2/fe/adapter.js +5 -4
  5. package/lib/antv2/index.d.ts +1 -0
  6. package/lib/antv2/index.js +12 -8
  7. package/lib/base/adpater.js +1 -1
  8. package/lib/ble/adapter-factory.d.ts +20 -24
  9. package/lib/ble/adapter-factory.js +13 -36
  10. package/lib/ble/base/adapter.d.ts +16 -5
  11. package/lib/ble/base/adapter.js +169 -52
  12. package/lib/ble/base/comms.d.ts +2 -74
  13. package/lib/ble/base/comms.js +3 -596
  14. package/lib/ble/base/interface.d.ts +96 -0
  15. package/lib/ble/base/interface.js +544 -0
  16. package/lib/ble/base/peripheral.d.ts +34 -0
  17. package/lib/ble/base/peripheral.js +286 -0
  18. package/lib/ble/base/sensor.d.ts +31 -0
  19. package/lib/ble/base/sensor.js +130 -0
  20. package/lib/ble/base/types.d.ts +7 -0
  21. package/lib/ble/base/types.js +7 -0
  22. package/lib/ble/bindings/mock.js +6 -0
  23. package/lib/ble/bindings/types.d.ts +3 -4
  24. package/lib/ble/ble-interface.d.ts +7 -4
  25. package/lib/ble/ble-interface.js +16 -2
  26. package/lib/ble/ble-peripheral.d.ts +1 -0
  27. package/lib/ble/ble-peripheral.js +7 -11
  28. package/lib/ble/consts.d.ts +0 -6
  29. package/lib/ble/consts.js +1 -7
  30. package/lib/ble/cp/adapter.d.ts +3 -3
  31. package/lib/ble/cp/adapter.js +12 -13
  32. package/lib/ble/cp/comm.d.ts +1 -1
  33. package/lib/ble/cp/comm.js +2 -2
  34. package/lib/ble/cp/index.d.ts +1 -1
  35. package/lib/ble/cp/index.js +2 -2
  36. package/lib/ble/cp/sensor.d.ts +27 -0
  37. package/lib/ble/cp/sensor.js +107 -0
  38. package/lib/ble/elite/comms.d.ts +1 -1
  39. package/lib/ble/elite/comms.js +2 -2
  40. package/lib/ble/factories/adapter-factory.d.ts +32 -0
  41. package/lib/ble/factories/adapter-factory.js +104 -0
  42. package/lib/ble/factories/index.d.ts +2 -0
  43. package/lib/ble/factories/index.js +18 -0
  44. package/lib/ble/factories/interface-factory.d.ts +7 -0
  45. package/lib/ble/factories/interface-factory.js +18 -0
  46. package/lib/ble/fm/adapter.d.ts +9 -4
  47. package/lib/ble/fm/adapter.js +104 -108
  48. package/lib/ble/fm/comms.d.ts +1 -1
  49. package/lib/ble/fm/comms.js +3 -3
  50. package/lib/ble/fm/consts.d.ts +93 -0
  51. package/lib/ble/fm/consts.js +55 -1
  52. package/lib/ble/fm/index.d.ts +1 -1
  53. package/lib/ble/fm/index.js +2 -2
  54. package/lib/ble/fm/sensor.d.ts +44 -0
  55. package/lib/ble/fm/sensor.js +384 -0
  56. package/lib/ble/hr/adapter.d.ts +3 -3
  57. package/lib/ble/hr/adapter.js +5 -8
  58. package/lib/ble/hr/comm.d.ts +1 -1
  59. package/lib/ble/hr/comm.js +2 -2
  60. package/lib/ble/hr/index.d.ts +1 -1
  61. package/lib/ble/hr/index.js +2 -2
  62. package/lib/ble/hr/sensor.d.ts +17 -0
  63. package/lib/ble/hr/sensor.js +52 -0
  64. package/lib/ble/index.d.ts +4 -3
  65. package/lib/ble/index.js +29 -13
  66. package/lib/ble/tacx/adapter.d.ts +4 -2
  67. package/lib/ble/tacx/adapter.js +26 -66
  68. package/lib/ble/tacx/comms.d.ts +1 -1
  69. package/lib/ble/tacx/comms.js +2 -2
  70. package/lib/ble/tacx/consts.d.ts +23 -0
  71. package/lib/ble/tacx/consts.js +27 -0
  72. package/lib/ble/tacx/index.d.ts +1 -1
  73. package/lib/ble/tacx/index.js +2 -2
  74. package/lib/ble/tacx/sensor.d.ts +63 -0
  75. package/lib/ble/tacx/sensor.js +596 -0
  76. package/lib/ble/types.d.ts +81 -52
  77. package/lib/ble/utils.d.ts +7 -2
  78. package/lib/ble/utils.js +84 -9
  79. package/lib/ble/wahoo/adapter.d.ts +2 -2
  80. package/lib/ble/wahoo/adapter.js +4 -72
  81. package/lib/ble/wahoo/comms.d.ts +1 -1
  82. package/lib/ble/wahoo/comms.js +2 -2
  83. package/lib/ble/wahoo/consts.d.ts +16 -0
  84. package/lib/ble/wahoo/consts.js +7 -0
  85. package/lib/ble/wahoo/index.d.ts +1 -1
  86. package/lib/ble/wahoo/index.js +2 -2
  87. package/lib/ble/wahoo/sensor.d.ts +48 -0
  88. package/lib/ble/wahoo/sensor.js +356 -0
  89. package/lib/direct-connect/base/comms.d.ts +3 -0
  90. package/lib/direct-connect/base/comms.js +7 -0
  91. package/lib/direct-connect/base/interface.d.ts +75 -0
  92. package/lib/direct-connect/base/interface.js +306 -0
  93. package/lib/direct-connect/base/peripheral.d.ts +50 -0
  94. package/lib/direct-connect/base/peripheral.js +413 -0
  95. package/lib/direct-connect/base/sensor.d.ts +3 -0
  96. package/lib/direct-connect/base/sensor.js +7 -0
  97. package/lib/direct-connect/bindings/index.d.ts +1 -0
  98. package/lib/direct-connect/bindings/index.js +17 -0
  99. package/lib/direct-connect/bindings/types.d.ts +36 -0
  100. package/lib/direct-connect/bindings/types.js +2 -0
  101. package/lib/direct-connect/consts.d.ts +17 -0
  102. package/lib/direct-connect/consts.js +20 -0
  103. package/lib/direct-connect/index.d.ts +3 -0
  104. package/lib/direct-connect/index.js +22 -0
  105. package/lib/direct-connect/messages/CharacteristicNotification.d.ts +12 -0
  106. package/lib/direct-connect/messages/CharacteristicNotification.js +23 -0
  107. package/lib/direct-connect/messages/DiscoverCharacteristics.d.ts +22 -0
  108. package/lib/direct-connect/messages/DiscoverCharacteristics.js +43 -0
  109. package/lib/direct-connect/messages/DiscoverServices.d.ts +15 -0
  110. package/lib/direct-connect/messages/DiscoverServices.js +33 -0
  111. package/lib/direct-connect/messages/EnableCharacteristicNotifications.d.ts +18 -0
  112. package/lib/direct-connect/messages/EnableCharacteristicNotifications.js +35 -0
  113. package/lib/direct-connect/messages/ReadCharacteristic.d.ts +18 -0
  114. package/lib/direct-connect/messages/ReadCharacteristic.js +34 -0
  115. package/lib/direct-connect/messages/WriteCharacteristic.d.ts +18 -0
  116. package/lib/direct-connect/messages/WriteCharacteristic.js +36 -0
  117. package/lib/direct-connect/messages/error.d.ts +5 -0
  118. package/lib/direct-connect/messages/error.js +18 -0
  119. package/lib/direct-connect/messages/factory.d.ts +6 -0
  120. package/lib/direct-connect/messages/factory.js +44 -0
  121. package/lib/direct-connect/messages/index.d.ts +9 -0
  122. package/lib/direct-connect/messages/index.js +25 -0
  123. package/lib/direct-connect/messages/message.d.ts +20 -0
  124. package/lib/direct-connect/messages/message.js +90 -0
  125. package/lib/direct-connect/types.d.ts +24 -0
  126. package/lib/direct-connect/types.js +9 -0
  127. package/lib/direct-connect/utils.d.ts +5 -0
  128. package/lib/direct-connect/utils.js +73 -0
  129. package/lib/factories/adapters.js +16 -4
  130. package/lib/factories/interfaces.d.ts +2 -1
  131. package/lib/factories/interfaces.js +10 -7
  132. package/lib/index.d.ts +5 -4
  133. package/lib/index.js +6 -2
  134. package/lib/serial/bindings/tcp.d.ts +5 -4
  135. package/lib/serial/bindings/tcp.js +16 -23
  136. package/lib/types/device.d.ts +2 -1
  137. package/lib/types/device.js +1 -0
  138. package/lib/utils/operation.d.ts +17 -0
  139. package/lib/utils/operation.js +20 -0
  140. package/lib/utils/task.d.ts +44 -0
  141. package/lib/utils/task.js +127 -0
  142. package/package.json +3 -1
@@ -1,6 +1,6 @@
1
1
  import EventEmitter from "events";
2
2
  import { EventLogger } from "gd-eventlog";
3
- import { DeviceProperties, DeviceSettings, DeviceStartProperties, IncyclistScanProps, InterfaceProps } from "../types";
3
+ import { DeviceProperties, DeviceSettings, DeviceStartProperties, IncyclistInterface, IncyclistScanProps, InterfaceProps } from "../types";
4
4
  export type BleProtocol = 'hr' | 'fm' | 'cp' | 'tacx' | 'wahoo' | 'elite';
5
5
  export type BleInterfaceState = 'unknown' | 'resetting' | 'unsupported' | 'unauthorized' | 'poweredOff' | 'poweredOn';
6
6
  export interface BleBinding extends EventEmitter {
@@ -13,15 +13,46 @@ export interface BleBinding extends EventEmitter {
13
13
  state: BleInterfaceState;
14
14
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
15
15
  }
16
+ export interface BleRawPeripheral extends EventEmitter {
17
+ id?: string;
18
+ address?: string;
19
+ name?: string;
20
+ services: [];
21
+ advertisement: any;
22
+ state: string;
23
+ connectAsync(): Promise<void>;
24
+ disconnectAsync(): Promise<void>;
25
+ disconnect(cb: (err?: Error) => void): Promise<void>;
26
+ discoverSomeServicesAndCharacteristicsAsync(serviceUUIDs: string[], characteristicUUIDs: string[]): Promise<DiscoverResult>;
27
+ discoverServicesAsync?(serviceUUIDs: string[]): Promise<BleService[]>;
28
+ }
29
+ export interface PeripheralAnnouncement {
30
+ name: string;
31
+ serviceUUIDs: string[];
32
+ transport: string;
33
+ }
34
+ export interface BlePeripheralAnnouncement extends PeripheralAnnouncement {
35
+ advertisement: any;
36
+ peripheral: BleRawPeripheral;
37
+ }
38
+ export interface BlePeripheralInfo {
39
+ id: string;
40
+ uuid: string;
41
+ address: string;
42
+ addressType: string;
43
+ advertisement: any;
44
+ rssi: number;
45
+ serviceUUIDs: string[];
46
+ stats: string;
47
+ }
16
48
  export interface BleScanProps extends IncyclistScanProps {
17
49
  protocol?: BleProtocol;
18
50
  protocols?: BleProtocol[];
19
51
  isBackgroundScan?: boolean;
20
52
  }
21
- export interface BleDeviceConstructProps extends BleDeviceProps {
53
+ export interface BleDeviceConstructProps extends BlePeripheralAnnouncement {
22
54
  log?: boolean;
23
55
  logger?: EventLogger;
24
- peripheral?: BlePeripheral;
25
56
  }
26
57
  export interface BleDeviceSettings extends DeviceSettings {
27
58
  id?: string;
@@ -30,9 +61,6 @@ export interface BleDeviceSettings extends DeviceSettings {
30
61
  address?: string;
31
62
  name?: string;
32
63
  }
33
- export interface BleDetectedDevice extends BleDeviceSettings {
34
- peripheral: BlePeripheral;
35
- }
36
64
  export interface BleDeviceProperties extends DeviceProperties {
37
65
  wheelDiameter?: number;
38
66
  gearRatio?: number;
@@ -48,54 +76,26 @@ export interface BleInterfaceProps extends InterfaceProps {
48
76
  timeout?: number;
49
77
  reconnect?: boolean;
50
78
  }
51
- export type BleService = {
52
- uuid: string;
53
- };
54
79
  export type DiscoverResult = {
55
80
  services: BleService[];
56
- characteristics: BleCharacteristic[];
81
+ characteristics: BleRawCharacteristic[];
57
82
  };
58
- export interface BlePeripheral extends EventEmitter, BlePeripheralIdentifier {
59
- services: [];
60
- advertisement: any;
61
- state: string;
62
- connectAsync(): Promise<void>;
63
- disconnect(cb: (err?: Error) => void): Promise<void>;
64
- discoverSomeServicesAndCharacteristicsAsync(serviceUUIDs: string[], characteristicUUIDs: string[]): Promise<DiscoverResult>;
65
- }
66
- export interface IBlePeripheralConnector {
67
- connect(): Promise<void>;
68
- reconnect(): Promise<void>;
69
- initialize(enforce: boolean): Promise<boolean>;
70
- isSubscribed(characteristicUuid: string): boolean;
71
- subscribeAll(callback: (characteristicUuid: string, data: any) => void): Promise<string[]>;
72
- subscribe(characteristicUuid: string, timeout?: number): Promise<boolean>;
73
- onDisconnect(): void;
74
- onData(characteristicUuid: string, data: any): void;
75
- on(characteristicUuid: string, callback: (characteristicUuid: string, data: any) => void): void;
76
- off(characteristicUuid: string, callback: (characteristicUuid: string, data: any) => void): void;
77
- removeAllListeners(characteristicUuid: string): void;
78
- getState(): string;
79
- getCharachteristics(): BleCharacteristic[];
80
- getServices(): string[];
81
- getPeripheral(): BlePeripheral;
82
- }
83
- export interface BleCharacteristic extends EventEmitter {
83
+ export type BleProperty = 'notify' | 'read' | 'write';
84
+ export interface BleCharacteristic {
84
85
  uuid: string;
85
- properties: string[];
86
- _serviceUuid?: string;
86
+ properties: BleProperty[];
87
87
  name?: string;
88
+ _serviceUuid?: string;
89
+ }
90
+ export interface BleRawCharacteristic extends BleCharacteristic, EventEmitter {
88
91
  subscribe(callback: (err: Error | undefined) => void): void;
89
92
  unsubscribe(callback: (err: Error | undefined) => void): void;
90
93
  read(callback: (err: Error | undefined, data: Buffer) => void): void;
91
94
  write(data: Buffer, withoutResponse: boolean, callback?: (err: Error | undefined) => void): void;
92
95
  }
93
- export type BleDeviceProps = {
94
- id?: string;
95
- address?: string;
96
- name?: string;
97
- services?: string[];
98
- peripheral?: BlePeripheral;
96
+ export type BleService = {
97
+ uuid: string;
98
+ characteristics?: BleCharacteristic[];
99
99
  };
100
100
  export type BleCommsConnectProps = {
101
101
  timeout?: number;
@@ -105,14 +105,6 @@ export interface BleWriteProps {
105
105
  withoutResponse?: boolean;
106
106
  timeout?: number;
107
107
  }
108
- export interface BlePeripheralIdentifier {
109
- id?: string;
110
- address?: string;
111
- name?: string;
112
- }
113
- export interface BlePeripheralDescription extends BlePeripheralIdentifier {
114
- profile: string;
115
- }
116
108
  export interface ConnectState {
117
109
  isConnecting: boolean;
118
110
  isConnected: boolean;
@@ -126,3 +118,40 @@ export type BleDeviceInfo = {
126
118
  model?: string;
127
119
  serialNo?: string;
128
120
  };
121
+ export interface IBleInterface<T extends PeripheralAnnouncement> extends IncyclistInterface {
122
+ pauseLogging(debugOnly?: boolean): void;
123
+ resumeLogging(): any;
124
+ isLoggingPaused(): boolean;
125
+ logEvent(event: any): any;
126
+ logError(err: Error, fn: string, args?: any): any;
127
+ createPeripheral(announcement: T): IBlePeripheral;
128
+ createPeripheralFromSettings(settings: DeviceSettings): IBlePeripheral;
129
+ createDeviceSetting(announcement: T): DeviceSettings;
130
+ waitForPeripheral(settings: DeviceSettings): Promise<IBlePeripheral>;
131
+ pauseDiscovery?(): Promise<void>;
132
+ resumeDiscovery?(): Promise<void>;
133
+ }
134
+ export interface IBlePeripheral {
135
+ services: BleService[];
136
+ connect(): Promise<boolean>;
137
+ disconnect(): Promise<boolean>;
138
+ isConnected(): boolean;
139
+ isConnecting(): boolean;
140
+ onDisconnect(callback: () => void): void;
141
+ discoverServices(): Promise<string[]>;
142
+ discoverCharacteristics(serviceUUID: string): Promise<BleCharacteristic[]>;
143
+ subscribe(characteristicUUID: string, callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
144
+ unsubscribe(characteristicUUID: string): Promise<boolean>;
145
+ subscribeAll?(callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
146
+ subscribeSelected(characteristics: string[], callback: (characteristicUuid: string, data: Buffer) => void): Promise<boolean>;
147
+ read(characteristicUUID: string): Promise<Buffer>;
148
+ write(characteristicUUID: string, data: Buffer, options?: BleWriteProps): Promise<Buffer>;
149
+ }
150
+ export interface IBleSensor extends EventEmitter {
151
+ startSensor(): Promise<boolean>;
152
+ stopSensor(): Promise<boolean>;
153
+ reset(): void;
154
+ isConnected(): boolean;
155
+ read(characteristicUUID: string): Promise<Buffer>;
156
+ write(characteristicUUID: string, data: Buffer, options?: BleWriteProps): Promise<Buffer>;
157
+ }
@@ -1,5 +1,5 @@
1
1
  import { LegacyProfile } from "../antv2/types";
2
- import { BleCharacteristic, BlePeripheral, BleProtocol } from "./types";
2
+ import { BleCharacteristic, BleProperty, BleProtocol, BleRawPeripheral } from "./types";
3
3
  type MappingRecord = {
4
4
  profile: LegacyProfile;
5
5
  protocol: BleProtocol;
@@ -7,11 +7,16 @@ type MappingRecord = {
7
7
  export declare function mapLegacyProfile(profile: string): MappingRecord;
8
8
  export declare function uuid(s: string): string;
9
9
  export declare function matches(uuid1: string, uuid2: string): boolean;
10
- export declare function getPeripheralInfo(p: BlePeripheral): {
10
+ export declare function getPeripheralInfo(p: BleRawPeripheral): {
11
11
  id: string;
12
12
  name: any;
13
13
  address: string;
14
14
  services: any;
15
15
  };
16
16
  export declare function getCharachteristicsInfo(c: BleCharacteristic): string;
17
+ export declare const parseUUID: (str: string) => string;
18
+ export declare const beautifyUUID: (str: string, withX?: boolean) => string;
19
+ export declare const fullUUID: (str: string) => string;
20
+ export declare const propertyVal: (properties: BleProperty[]) => number;
21
+ export declare const propertyFromVal: (val: number) => BleProperty[];
17
22
  export {};
package/lib/ble/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.propertyFromVal = exports.propertyVal = exports.fullUUID = exports.beautifyUUID = exports.parseUUID = void 0;
3
4
  exports.mapLegacyProfile = mapLegacyProfile;
4
5
  exports.uuid = uuid;
5
6
  exports.matches = matches;
@@ -29,15 +30,7 @@ function uuid(s) {
29
30
  }
30
31
  }
31
32
  function matches(uuid1, uuid2) {
32
- const ul1 = uuid1.toLowerCase();
33
- const ul2 = uuid2.toLowerCase();
34
- if (uuid(ul1) === uuid(ul2))
35
- return true;
36
- if (ul1.length < ul2.length && ul2.startsWith(ul1))
37
- return true;
38
- if (ul1.length > ul2.length && ul1.startsWith(ul2))
39
- return true;
40
- return false;
33
+ return (0, exports.parseUUID)(uuid1) === (0, exports.parseUUID)(uuid2);
41
34
  }
42
35
  function getPeripheralInfo(p) {
43
36
  const { id, name, address, advertisement, services } = p;
@@ -54,3 +47,85 @@ function getCharachteristicsInfo(c) {
54
47
  const serviceStr = _serviceUuid ? `${_serviceUuid}:` : '';
55
48
  return `${serviceStr}${uuid}${nameStr} ${properties}`;
56
49
  }
50
+ const parseUUID = (str) => {
51
+ const uuid = str.toUpperCase();
52
+ if (str.startsWith('0x')) {
53
+ const hex = uuid.slice(2);
54
+ if (hex.length === 4) {
55
+ return `0000${hex}00001000800000805F9B34FB`;
56
+ }
57
+ if (hex.length === 8) {
58
+ return `${hex}00001000800000805F9B34FB`;
59
+ }
60
+ }
61
+ else if (uuid.length === 4) {
62
+ return `0000${uuid}00001000800000805F9B34FB`;
63
+ }
64
+ else if (uuid.length === 8) {
65
+ return `${uuid}00001000800000805F9B34FB`;
66
+ }
67
+ else if (uuid.length === 32) {
68
+ return uuid;
69
+ }
70
+ else if (uuid.length === 36) {
71
+ return uuid.replace(/-/g, '');
72
+ }
73
+ throw new Error(`Invalid UUID: ${uuid}`);
74
+ };
75
+ exports.parseUUID = parseUUID;
76
+ const beautifyUUID = (str, withX = false) => {
77
+ const uuid = (0, exports.parseUUID)(str);
78
+ const parts = [
79
+ uuid.substring(0, 8),
80
+ uuid.substring(8, 12),
81
+ uuid.substring(12, 16),
82
+ uuid.substring(16, 20),
83
+ uuid.substring(20),
84
+ ];
85
+ if (uuid.substring(8) === '00001000800000805F9B34FB') {
86
+ let short;
87
+ if (parts[0].startsWith('0000')) {
88
+ short = parts[0].substring(4);
89
+ }
90
+ else {
91
+ short = parts[0];
92
+ }
93
+ return withX ? `0x${short}` : short;
94
+ }
95
+ return parts.join('-');
96
+ };
97
+ exports.beautifyUUID = beautifyUUID;
98
+ const fullUUID = (str) => {
99
+ const uuid = (0, exports.parseUUID)(str);
100
+ const parts = [
101
+ uuid.substring(0, 8),
102
+ uuid.substring(8, 12),
103
+ uuid.substring(12, 16),
104
+ uuid.substring(16, 20),
105
+ uuid.substring(20),
106
+ ];
107
+ return parts.join('-');
108
+ };
109
+ exports.fullUUID = fullUUID;
110
+ const propertyVal = (properties) => {
111
+ let res = 0;
112
+ if (properties.includes('read'))
113
+ res |= 0x01;
114
+ if (properties.includes('write'))
115
+ res |= 0x02;
116
+ if (properties.includes('notify'))
117
+ res |= 0x04;
118
+ return res;
119
+ };
120
+ exports.propertyVal = propertyVal;
121
+ const propertyFromVal = (val) => {
122
+ const res = [];
123
+ if (val & 0x01)
124
+ res.push('read');
125
+ if (val & 0x02)
126
+ res.push('write');
127
+ if (val & 0x04)
128
+ res.push('notify');
129
+ return res;
130
+ };
131
+ exports.propertyFromVal = propertyFromVal;
@@ -1,5 +1,5 @@
1
1
  import { BleFmAdapter } from '../fm';
2
- import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from '../types';
2
+ import { BleDeviceProperties, BleDeviceSettings, IBlePeripheral } from '../types';
3
3
  import { IAdapter } from '../../types';
4
4
  import { LegacyProfile } from '../../antv2/types';
5
5
  export default class BleWahooAdapter extends BleFmAdapter {
@@ -7,5 +7,5 @@ export default class BleWahooAdapter extends BleFmAdapter {
7
7
  constructor(settings: BleDeviceSettings, props?: BleDeviceProperties);
8
8
  isSame(device: IAdapter): boolean;
9
9
  getProfile(): LegacyProfile;
10
- start(props?: BleStartProperties): Promise<any>;
10
+ updateSensor(peripheral: IBlePeripheral): void;
11
11
  }
@@ -1,30 +1,17 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  const gd_eventlog_1 = require("gd-eventlog");
16
7
  const fm_1 = require("../fm");
17
- const comms_1 = __importDefault(require("./comms"));
18
- const consts_1 = require("../../base/consts");
8
+ const sensor_1 = __importDefault(require("./sensor"));
19
9
  const types_1 = require("../../types");
20
10
  class BleWahooAdapter extends fm_1.BleFmAdapter {
21
11
  constructor(settings, props) {
22
12
  super(settings, props);
23
13
  this.logger = new gd_eventlog_1.EventLogger('BLE-WahooFM');
24
- const { id, address, name } = settings;
25
- const logger = this.logger;
26
- const ble = this.ble;
27
- this.device = new comms_1.default({ id, address, name, ble, logger });
14
+ this.device = new sensor_1.default(this.getPeripheral(), { logger: this.logger });
28
15
  this.capabilities = [
29
16
  types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence,
30
17
  types_1.IncyclistCapability.Control
@@ -38,63 +25,8 @@ class BleWahooAdapter extends fm_1.BleFmAdapter {
38
25
  getProfile() {
39
26
  return 'Smart Trainer';
40
27
  }
41
- start() {
42
- return __awaiter(this, arguments, void 0, function* (props = {}) {
43
- const wasPaused = this.paused;
44
- const wasStopped = this.stopped;
45
- if (wasPaused)
46
- this.resume();
47
- if (wasStopped)
48
- this.stopped = false;
49
- if (this.started && !wasPaused && !wasStopped)
50
- return true;
51
- this.logger.logEvent({ message: 'start requested', protocol: this.getProtocolName(), props });
52
- try {
53
- if (this.ble.isScanning()) {
54
- this.logger.logEvent({ message: 'stop previous scan', isScanning: this.ble.isScanning() });
55
- yield this.ble.stopScan();
56
- }
57
- const connected = yield this.connect();
58
- if (!connected)
59
- throw new Error(`could not start device, reason:could not connect`);
60
- const comms = this.device;
61
- if (comms) {
62
- const mode = this.getCyclingMode();
63
- if (mode && mode.getSetting('bikeType')) {
64
- const bikeType = mode.getSetting('bikeType').toLowerCase();
65
- comms.setCrr(fm_1.cRR);
66
- switch (bikeType) {
67
- case 'race':
68
- comms.setCw(fm_1.cwABike.race);
69
- break;
70
- case 'triathlon':
71
- comms.setCw(fm_1.cwABike.triathlon);
72
- break;
73
- case 'mountain':
74
- comms.setCw(fm_1.cwABike.mountain);
75
- break;
76
- }
77
- }
78
- const { user, bikeWeight = consts_1.DEFAULT_BIKE_WEIGHT } = props || {};
79
- const weight = (user && user.weight ? Number(user.weight) : consts_1.DEFAULT_USER_WEIGHT) + bikeWeight;
80
- yield comms.setSimMode(weight, comms.getCrr(), comms.getCw());
81
- const startRequest = this.getCyclingMode().getBikeInitRequest();
82
- yield this.sendUpdate(startRequest);
83
- comms.on('data', (data) => {
84
- this.onDeviceData(data);
85
- });
86
- this.resetData();
87
- this.stopped = false;
88
- this.started = true;
89
- this.paused = false;
90
- return true;
91
- }
92
- }
93
- catch (err) {
94
- this.logger.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
95
- throw new Error(`could not start device, reason:${err.message}`);
96
- }
97
- });
28
+ updateSensor(peripheral) {
29
+ this.device = new sensor_1.default(peripheral, { logger: this.logger });
98
30
  }
99
31
  }
100
32
  BleWahooAdapter.INCYCLIST_PROFILE_NAME = 'Smart Trainer';
@@ -1,7 +1,7 @@
1
1
  import { LegacyProfile } from "../../antv2/types";
2
2
  import { CrankData } from "../cp";
3
3
  import { IndoorBikeData } from "../fm";
4
- import BleFitnessMachineDevice from "../fm/comms";
4
+ import BleFitnessMachineDevice from "../fm/sensor";
5
5
  import { BleProtocol, BleWriteProps, IBlePeripheralConnector } from "../types";
6
6
  export declare const enum OpCode {
7
7
  unlock = 32,
@@ -15,10 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const _1 = require(".");
16
16
  const consts_1 = require("../../base/consts");
17
17
  const consts_2 = require("../consts");
18
- const comms_1 = __importDefault(require("../fm/comms"));
18
+ const sensor_1 = __importDefault(require("../fm/sensor"));
19
19
  const utils_1 = require("../utils");
20
20
  const ErgWriteDelay = 2000;
21
- class BleWahooDevice extends comms_1.default {
21
+ class BleWahooDevice extends sensor_1.default {
22
22
  constructor(props) {
23
23
  super(props);
24
24
  this.prevCrankData = undefined;
@@ -0,0 +1,16 @@
1
+ export declare const enum OpCode {
2
+ unlock = 32,
3
+ setResistanceMode = 64,
4
+ setStandardMode = 65,
5
+ setErgMode = 66,
6
+ setSimMode = 67,
7
+ setSimCRR = 68,
8
+ setSimWindResistance = 69,
9
+ setSimGrade = 70,
10
+ setSimWindSpeed = 71,
11
+ setWheelCircumference = 72
12
+ }
13
+ export declare const ErgWriteDelay = 2000;
14
+ export declare const WAHOO_ADVANCED_TRAINER_CP = "a026e005-0a7d-4ab3-97fa-f1500f9feb8b";
15
+ export declare const WAHOO_ADVANCED_FTMS = "a026ee0b-0a7d-4ab3-97fa-f1500f9feb8b";
16
+ export declare const WAHOO_ADVANCED_TRAINER_CP_FULL = "A026E005-0A7D-4AB3-97FA-F1500F9FEB8B";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WAHOO_ADVANCED_TRAINER_CP_FULL = exports.WAHOO_ADVANCED_FTMS = exports.WAHOO_ADVANCED_TRAINER_CP = exports.ErgWriteDelay = void 0;
4
+ exports.ErgWriteDelay = 2000;
5
+ exports.WAHOO_ADVANCED_TRAINER_CP = 'a026e005-0a7d-4ab3-97fa-f1500f9feb8b';
6
+ exports.WAHOO_ADVANCED_FTMS = 'a026ee0b-0a7d-4ab3-97fa-f1500f9feb8b';
7
+ exports.WAHOO_ADVANCED_TRAINER_CP_FULL = 'A026E005-0A7D-4AB3-97FA-F1500F9FEB8B';
@@ -1,4 +1,4 @@
1
- import BleWahooComms from "./comms";
1
+ import BleWahooComms from "./sensor";
2
2
  import BleWahooAdapter from "./adapter";
3
3
  import { IndoorBikeData as WahooIndoorBikeData } from "./types";
4
4
  export { WahooIndoorBikeData, BleWahooAdapter, BleWahooComms };
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BleWahooComms = exports.BleWahooAdapter = void 0;
7
- const comms_1 = __importDefault(require("./comms"));
8
- exports.BleWahooComms = comms_1.default;
7
+ const sensor_1 = __importDefault(require("./sensor"));
8
+ exports.BleWahooComms = sensor_1.default;
9
9
  const adapter_1 = __importDefault(require("./adapter"));
10
10
  exports.BleWahooAdapter = adapter_1.default;
@@ -0,0 +1,48 @@
1
+ import { LegacyProfile } from "../../antv2/types";
2
+ import { CrankData } from "../cp";
3
+ import { IndoorBikeData } from "../fm";
4
+ import BleFitnessMachineDevice from "../fm/sensor";
5
+ import { BleProtocol, BleWriteProps } from "../types";
6
+ export default class BleWahooDevice extends BleFitnessMachineDevice {
7
+ static readonly profile: LegacyProfile;
8
+ static readonly protocol: BleProtocol;
9
+ static readonly services: string[];
10
+ static readonly characteristics: string[];
11
+ static readonly detectionPriority = 5;
12
+ prevCrankData: CrankData;
13
+ currentCrankData: CrankData;
14
+ timeOffset: number;
15
+ tsPrevWrite: any;
16
+ prevSlope: any;
17
+ wahooCP: string;
18
+ isSimMode: boolean;
19
+ isRequestControlBusy: boolean;
20
+ weight: number;
21
+ simModeSettings: {
22
+ weight: number;
23
+ crr: number;
24
+ cw: number;
25
+ };
26
+ constructor(peripheral: any, props?: any);
27
+ isMatching(serviceUUIDs: string[]): boolean;
28
+ reset(): void;
29
+ protected getRequiredCharacteristics(): Array<string>;
30
+ onData(characteristic: string, data: Buffer): boolean;
31
+ requestControl(): Promise<boolean>;
32
+ setTargetPower(power: number): Promise<boolean>;
33
+ setSlope(slope: any): Promise<boolean>;
34
+ protected parseCrankData(crankData: any): {
35
+ rpm: number;
36
+ time: any;
37
+ };
38
+ protected parsePower(_data: Buffer): IndoorBikeData;
39
+ protected writeWahooFtmsMessage(requestedOpCode: number, data: Buffer, props?: BleWriteProps): Promise<boolean>;
40
+ protected setPowerAdjusting(): void;
41
+ protected isPowerAdjusting(): boolean;
42
+ setErgMode(power: number): Promise<boolean>;
43
+ setSimMode(weight: number, crr: number, cw: number): Promise<boolean>;
44
+ setSimCRR(crr: number): Promise<boolean>;
45
+ setSimWindResistance(cw: number): Promise<boolean>;
46
+ setSimGrade(slope: number): Promise<boolean>;
47
+ setSimWindSpeed(v: number): Promise<boolean>;
48
+ }