incyclist-devices 1.4.81 → 1.4.84

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.
@@ -20,4 +20,15 @@ declare const Protocols: {
20
20
  KettlerRacerProtocol: typeof KettlerRacerProtocol;
21
21
  BleProtocol: typeof BleProtocol;
22
22
  };
23
+ export interface FeatureList {
24
+ [key: string]: boolean;
25
+ }
26
+ export default class DeviceSupport {
27
+ static _features: FeatureList;
28
+ static init(props?: {
29
+ features?: FeatureList;
30
+ }): void;
31
+ static hasFeature(feature: string): boolean;
32
+ static setFeature(key: string, value: boolean): void;
33
+ }
23
34
  export { DeviceProtocolBase, DeviceProtocol, DeviceRegistry, INTERFACE, DeviceAdapter as Device, Protocols, AntScanner, BleProtocol, CyclingModeProperyType, BleInterface, BleHrmDevice, BleCyclingPowerDevice, BleFitnessMachineDevice, WahooAdvancedFitnessMachineDevice };
@@ -58,3 +58,21 @@ const Protocols = {
58
58
  BleProtocol: incyclist_protocol_1.default
59
59
  };
60
60
  exports.Protocols = Protocols;
61
+ class DeviceSupport {
62
+ static init(props = {}) {
63
+ if (props.features) {
64
+ this._features = props.features;
65
+ }
66
+ }
67
+ static hasFeature(feature) {
68
+ const featureVal = this._features[feature];
69
+ if (featureVal === undefined)
70
+ return false;
71
+ return featureVal;
72
+ }
73
+ static setFeature(key, value) {
74
+ this._features[key] = value;
75
+ }
76
+ }
77
+ exports.default = DeviceSupport;
78
+ DeviceSupport._features = {};
@@ -212,7 +212,7 @@ class BleInterface extends ble_1.BleInterfaceClass {
212
212
  if (Array.isArray(services)) {
213
213
  const sids = services.map(ble_1.uuid);
214
214
  return get(deviceTypes, s => {
215
- const res = sids.find((s) => (0, ble_2.matches)(s, services));
215
+ const res = sids.find((service) => (0, ble_2.matches)(s, service));
216
216
  return res !== undefined;
217
217
  });
218
218
  }
package/lib/ble/ble.js CHANGED
@@ -73,10 +73,10 @@ const uuid = (s) => {
73
73
  };
74
74
  exports.uuid = uuid;
75
75
  const matches = (uuid1, uuid2) => {
76
- if ((0, exports.uuid)(uuid1) === (0, exports.uuid)(uuid2))
77
- return true;
78
76
  const ul1 = uuid1.toLowerCase();
79
77
  const ul2 = uuid2.toLowerCase();
78
+ if ((0, exports.uuid)(ul1) === (0, exports.uuid)(ul2))
79
+ return true;
80
80
  if (ul1.length < ul2.length && ul2.startsWith(ul1))
81
81
  return true;
82
82
  if (ul1.length > ul2.length && ul1.startsWith(ul2))
@@ -5,3 +5,7 @@ export declare const FTMS = "1826";
5
5
  export declare const FTMS_CP = "2ad9";
6
6
  export declare const FTMS_STATUS = "2ada";
7
7
  export declare const INDOOR_BIKE_DATA = "2ad2";
8
+ export declare const CSP = "1818";
9
+ export declare const CSP_MEASUREMENT = "2a63";
10
+ export declare const CSP_FEATURE = "2a65";
11
+ export declare const WAHOO_ADVANCED_TRAINER_CP = "a026e005";
package/lib/ble/consts.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = exports.TACX_FE_C_TX = exports.TACX_FE_C_RX = exports.TACX_FE_C_BLE = void 0;
3
+ exports.WAHOO_ADVANCED_TRAINER_CP = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = exports.TACX_FE_C_TX = exports.TACX_FE_C_RX = exports.TACX_FE_C_BLE = void 0;
4
4
  exports.TACX_FE_C_BLE = '6e40fec1';
5
5
  exports.TACX_FE_C_RX = '6e40fec2';
6
6
  exports.TACX_FE_C_TX = '6e40fec3';
@@ -8,3 +8,7 @@ exports.FTMS = '1826';
8
8
  exports.FTMS_CP = '2ad9';
9
9
  exports.FTMS_STATUS = '2ada';
10
10
  exports.INDOOR_BIKE_DATA = '2ad2';
11
+ exports.CSP = '1818';
12
+ exports.CSP_MEASUREMENT = '2a63';
13
+ exports.CSP_FEATURE = '2a65';
14
+ exports.WAHOO_ADVANCED_TRAINER_CP = 'a026e005';
package/lib/ble/pwr.js CHANGED
@@ -36,9 +36,8 @@ const ble_device_1 = require("./ble-device");
36
36
  const ble_interface_1 = __importDefault(require("./ble-interface"));
37
37
  const Device_1 = __importStar(require("../Device"));
38
38
  const gd_eventlog_1 = require("gd-eventlog");
39
+ const consts_1 = require("./consts");
39
40
  const power_meter_1 = __importDefault(require("../modes/power-meter"));
40
- const CP_MEASUREMENT = '2a63';
41
- const CP_FEATURE = '2a65';
42
41
  class BleCyclingPowerDevice extends ble_device_1.BleDevice {
43
42
  constructor(props) {
44
43
  super(props);
@@ -54,8 +53,8 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
54
53
  isMatching(characteristics) {
55
54
  if (!characteristics)
56
55
  return false;
57
- const hasCPMeasurement = characteristics.find(c => c === CP_MEASUREMENT) !== undefined;
58
- const hasCPFeature = characteristics.find(c => c === CP_FEATURE) !== undefined;
56
+ const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
57
+ const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
59
58
  return hasCPMeasurement && hasCPFeature;
60
59
  }
61
60
  init() {
@@ -143,7 +142,7 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
143
142
  const isDuplicate = this.checkForDuplicate(characteristic, data);
144
143
  if (isDuplicate)
145
144
  return;
146
- if (characteristic.toLocaleLowerCase() === CP_MEASUREMENT) {
145
+ if (characteristic.toLocaleLowerCase() === consts_1.CSP_MEASUREMENT) {
147
146
  const res = this.parsePower(data);
148
147
  this.emit('data', res);
149
148
  }
@@ -160,8 +159,8 @@ class BleCyclingPowerDevice extends ble_device_1.BleDevice {
160
159
  }
161
160
  }
162
161
  exports.default = BleCyclingPowerDevice;
163
- BleCyclingPowerDevice.services = ['1818'];
164
- BleCyclingPowerDevice.characteristics = [CP_MEASUREMENT, CP_FEATURE, '2a5d', '2a3c'];
162
+ BleCyclingPowerDevice.services = [consts_1.CSP];
163
+ BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
165
164
  ble_interface_1.default.register('BleCyclingPowerDevice', 'cp', BleCyclingPowerDevice, BleCyclingPowerDevice.services);
166
165
  class PwrAdapter extends Device_1.default {
167
166
  constructor(device, protocol) {
@@ -39,7 +39,6 @@ const gd_eventlog_1 = require("gd-eventlog");
39
39
  const fm_1 = __importStar(require("./fm"));
40
40
  const consts_1 = require("./consts");
41
41
  const WAHOO_ADVANCED_FTMS = 'a026ee0b';
42
- const WAHOO_ADVANCED_TRAINER_CP = 'a026e005';
43
42
  const cwABike = {
44
43
  race: 0.35,
45
44
  triathlon: 0.29,
@@ -56,12 +55,12 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
56
55
  this.tsPrevWrite = undefined;
57
56
  this.prevSlope = undefined;
58
57
  this.data = {};
59
- this.wahooCP = WAHOO_ADVANCED_TRAINER_CP;
58
+ this.wahooCP = consts_1.WAHOO_ADVANCED_TRAINER_CP;
60
59
  }
61
60
  isMatching(characteristics) {
62
61
  if (!characteristics)
63
62
  return false;
64
- const hasWahooCP = characteristics.find(c => (0, ble_1.matches)(c, WAHOO_ADVANCED_TRAINER_CP)) !== undefined;
63
+ const hasWahooCP = characteristics.find(c => (0, ble_1.matches)(c, consts_1.WAHOO_ADVANCED_TRAINER_CP)) !== undefined;
65
64
  const hasFTMS = characteristics.find(c => (0, ble_1.matches)(c, consts_1.FTMS_CP)) !== undefined;
66
65
  return hasWahooCP && !hasFTMS;
67
66
  }
@@ -83,7 +82,7 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
83
82
  }
84
83
  setCharacteristicUUIDs(uuids) {
85
84
  uuids.forEach(c => {
86
- if ((0, ble_1.matches)(c, WAHOO_ADVANCED_TRAINER_CP))
85
+ if ((0, ble_1.matches)(c, consts_1.WAHOO_ADVANCED_TRAINER_CP))
87
86
  this.wahooCP = c;
88
87
  });
89
88
  }
@@ -190,17 +189,18 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
190
189
  writeWahooFtmsMessage(requestedOpCode, data) {
191
190
  return __awaiter(this, void 0, void 0, function* () {
192
191
  try {
192
+ this.logEvent({ message: 'wahoo cp:write', data: data.toString('hex') });
193
193
  const opcode = Buffer.alloc(1);
194
194
  opcode.writeUInt8(requestedOpCode, 0);
195
195
  const message = Buffer.concat([opcode, data]);
196
196
  const res = yield this.write(this.wahooCP, message);
197
197
  const responseData = Buffer.from(res);
198
198
  const result = responseData.readUInt8(0);
199
- this.logEvent({ message: 'response', opCode: requestedOpCode, response: responseData.toString('hex') });
199
+ this.logEvent({ message: 'wahoo cp:response', opCode: requestedOpCode, response: responseData.toString('hex') });
200
200
  return result === 1;
201
201
  }
202
202
  catch (err) {
203
- this.logEvent({ message: 'writeWahooFtmsMessage failed', opCode: requestedOpCode, reason: err.message });
203
+ this.logEvent({ message: 'wahoo cp:write failed', opCode: requestedOpCode, reason: err.message });
204
204
  return false;
205
205
  }
206
206
  });
@@ -210,8 +210,6 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
210
210
  if (this.hasControl)
211
211
  return true;
212
212
  this.logEvent({ message: 'requestControl' });
213
- this.hasControl = true;
214
- return;
215
213
  const data = Buffer.alloc(2);
216
214
  data.writeUInt8(0xEE, 0);
217
215
  data.writeUInt8(0xFC, 1);
@@ -336,8 +334,8 @@ class WahooAdvancedFitnessMachineDevice extends fm_1.default {
336
334
  }
337
335
  }
338
336
  exports.default = WahooAdvancedFitnessMachineDevice;
339
- WahooAdvancedFitnessMachineDevice.services = ['1818'];
340
- WahooAdvancedFitnessMachineDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada', WAHOO_ADVANCED_TRAINER_CP];
337
+ WahooAdvancedFitnessMachineDevice.services = [consts_1.CSP];
338
+ WahooAdvancedFitnessMachineDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada', consts_1.WAHOO_ADVANCED_TRAINER_CP];
341
339
  ble_interface_1.default.register('WahooAdvancedFitnessMachineDevice', 'wahoo-fm', WahooAdvancedFitnessMachineDevice, WahooAdvancedFitnessMachineDevice.services);
342
340
  class WahooAdvancedFmAdapter extends fm_1.FmAdapter {
343
341
  constructor(device, protocol) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.4.81",
3
+ "version": "1.4.84",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",