incyclist-devices 3.0.28 → 3.0.30

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.
@@ -169,12 +169,12 @@ class BlePeripheral {
169
169
  return res;
170
170
  }
171
171
  checkAnnouncedServices(discovered) {
172
- const announced = this.getAnnouncedServices().map(x => (0, utils_js_2.beautifyUUID)(x));
172
+ const announced = this.getAnnouncedServices();
173
173
  const toBeChecked = discovered.map(x => (0, utils_js_2.beautifyUUID)(x));
174
174
  const cntAnnounced = announced.length;
175
175
  let cntVerified = 0;
176
176
  for (const s of announced) {
177
- if (toBeChecked.includes(s))
177
+ if (toBeChecked.some(d => (0, utils_js_2.isSameServiceFamily)(s, d)))
178
178
  cntVerified++;
179
179
  }
180
180
  return cntAnnounced === cntVerified;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bit = exports.propertyFromVal = exports.propertyVal = exports.fullUUID = exports.beautifyUUID = exports.parseUUID = void 0;
3
+ exports.bit = exports.propertyFromVal = exports.propertyVal = exports.fullUUID = exports.isSameServiceFamily = exports.beautifyUUID = exports.parseUUID = void 0;
4
4
  exports.mapLegacyProfile = mapLegacyProfile;
5
5
  exports.uuid = uuid;
6
6
  exports.matches = matches;
@@ -106,6 +106,17 @@ const beautifyUUID = (str, withX = false) => {
106
106
  return parts.join('-');
107
107
  };
108
108
  exports.beautifyUUID = beautifyUUID;
109
+ const isSameServiceFamily = (uuid1, uuid2) => {
110
+ const a = (0, exports.beautifyUUID)(uuid1);
111
+ const b = (0, exports.beautifyUUID)(uuid2);
112
+ if (a === b)
113
+ return true;
114
+ const isCustom128 = (u) => u.length === 36;
115
+ if (isCustom128(a) && isCustom128(b))
116
+ return a.substring(9) === b.substring(9);
117
+ return false;
118
+ };
119
+ exports.isSameServiceFamily = isSameServiceFamily;
109
120
  const fullUUID = (str) => {
110
121
  if (!str)
111
122
  return str;
@@ -8,6 +8,8 @@ const consts_js_2 = require("../consts.js");
8
8
  const consts_js_3 = require("./consts.js");
9
9
  const sensor_js_1 = __importDefault(require("../fm/sensor.js"));
10
10
  const utils_js_1 = require("../utils.js");
11
+ const task_js_1 = require("../../utils/task.js");
12
+ const WAHOO_CP_WRITE_TIMEOUT = 800;
11
13
  class BleWahooDevice extends sensor_js_1.default {
12
14
  static profile = 'Smart Trainer';
13
15
  static protocol = 'wahoo';
@@ -234,7 +236,22 @@ class BleWahooDevice extends sensor_js_1.default {
234
236
  opcode.writeUInt8(requestedOpCode, 0);
235
237
  const message = Buffer.concat([opcode, data]);
236
238
  this.logEvent({ message: 'wahoo cp:write', data: message.toString('hex') });
237
- const res = await this.write(this.wahooCP, message, props);
239
+ let res;
240
+ if (props?.timeout) {
241
+ const internalAbort = new AbortController();
242
+ const combined = new AbortController();
243
+ props.signal?.addEventListener('abort', () => combined.abort(), { once: true });
244
+ internalAbort.signal.addEventListener('abort', () => combined.abort(), { once: true });
245
+ const signal = combined.signal;
246
+ res = await new task_js_1.InteruptableTask(this.write(this.wahooCP, message, { ...props, signal }), {
247
+ timeout: props.timeout,
248
+ errorOnTimeout: true,
249
+ onCancel: () => internalAbort.abort()
250
+ }).run();
251
+ }
252
+ else {
253
+ res = await this.write(this.wahooCP, message, props);
254
+ }
238
255
  const responseData = Buffer.from(res);
239
256
  const result = responseData.readUInt8(0);
240
257
  return result === 1;
@@ -263,7 +280,7 @@ class BleWahooDevice extends sensor_js_1.default {
263
280
  return false;
264
281
  const data = Buffer.alloc(2);
265
282
  data.writeInt16LE(Math.round(power), 0);
266
- const res = await this.writeWahooFtmsMessage(66, data);
283
+ const res = await this.writeWahooFtmsMessage(66, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
267
284
  if (res === true) {
268
285
  this.setPowerAdjusting();
269
286
  this.data.targetPower = power;
@@ -298,7 +315,7 @@ class BleWahooDevice extends sensor_js_1.default {
298
315
  data.writeInt16LE(Math.round(weight * 100), 0);
299
316
  data.writeInt16LE(Math.round(crr * 10000), 2);
300
317
  data.writeInt16LE(Math.round(cw * 1000), 4);
301
- const res = await this.writeWahooFtmsMessage(67, data);
318
+ const res = await this.writeWahooFtmsMessage(67, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
302
319
  this.isSimMode = true;
303
320
  this.simModeSettings = { weight, crr, cw };
304
321
  return res;
@@ -313,7 +330,7 @@ class BleWahooDevice extends sensor_js_1.default {
313
330
  try {
314
331
  const data = Buffer.alloc(2);
315
332
  data.writeInt16LE(Math.round(crr * 10000), 0);
316
- const res = await this.writeWahooFtmsMessage(68, data);
333
+ const res = await this.writeWahooFtmsMessage(68, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
317
334
  return res;
318
335
  }
319
336
  catch (err) {
@@ -326,7 +343,7 @@ class BleWahooDevice extends sensor_js_1.default {
326
343
  try {
327
344
  const data = Buffer.alloc(2);
328
345
  data.writeInt16LE(Math.round(cw * 1000), 0);
329
- const res = await this.writeWahooFtmsMessage(69, data);
346
+ const res = await this.writeWahooFtmsMessage(69, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
330
347
  return res;
331
348
  }
332
349
  catch (err) {
@@ -345,7 +362,7 @@ class BleWahooDevice extends sensor_js_1.default {
345
362
  const slopeVal = Math.min(Math.round((1 + s / 100) * 65535 / 2.0), 65535);
346
363
  const data = Buffer.alloc(2);
347
364
  data.writeUInt16LE(slopeVal, 0);
348
- const res = await this.writeWahooFtmsMessage(70, data);
365
+ const res = await this.writeWahooFtmsMessage(70, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
349
366
  return res;
350
367
  }
351
368
  catch (err) {
@@ -359,7 +376,7 @@ class BleWahooDevice extends sensor_js_1.default {
359
376
  const value = (Math.max(-32.767, Math.min(32.767, v)) + 32.767) * 1000;
360
377
  const data = Buffer.alloc(2);
361
378
  data.writeInt16LE(Math.round(value), 0);
362
- const res = await this.writeWahooFtmsMessage(71, data);
379
+ const res = await this.writeWahooFtmsMessage(71, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
363
380
  return res;
364
381
  }
365
382
  catch (err) {
@@ -373,5 +390,20 @@ class BleWahooDevice extends sensor_js_1.default {
373
390
  getWheelCircumference() {
374
391
  return this.wheelCircumference;
375
392
  }
393
+ async startRequest() {
394
+ return true;
395
+ }
396
+ async stopRequest() {
397
+ return true;
398
+ }
399
+ async PauseRequest() {
400
+ return true;
401
+ }
402
+ async setTargetInclination(_inclination) {
403
+ return true;
404
+ }
405
+ async setTargetResistanceLevel(_resistanceLevel) {
406
+ return true;
407
+ }
376
408
  }
377
409
  exports.default = BleWahooDevice;
@@ -1,5 +1,5 @@
1
1
  import { sleep } from "../../utils/utils.js";
2
- import { beautifyUUID, fullUUID, matches } from "../utils.js";
2
+ import { beautifyUUID, fullUUID, isSameServiceFamily, matches } from "../utils.js";
3
3
  import { BleInterface } from "./interface.js";
4
4
  export class BlePeripheral {
5
5
  announcement;
@@ -166,12 +166,12 @@ export class BlePeripheral {
166
166
  return res;
167
167
  }
168
168
  checkAnnouncedServices(discovered) {
169
- const announced = this.getAnnouncedServices().map(x => beautifyUUID(x));
169
+ const announced = this.getAnnouncedServices();
170
170
  const toBeChecked = discovered.map(x => beautifyUUID(x));
171
171
  const cntAnnounced = announced.length;
172
172
  let cntVerified = 0;
173
173
  for (const s of announced) {
174
- if (toBeChecked.includes(s))
174
+ if (toBeChecked.some(d => isSameServiceFamily(s, d)))
175
175
  cntVerified++;
176
176
  }
177
177
  return cntAnnounced === cntVerified;
@@ -96,6 +96,16 @@ export const beautifyUUID = (str, withX = false) => {
96
96
  }
97
97
  return parts.join('-');
98
98
  };
99
+ export const isSameServiceFamily = (uuid1, uuid2) => {
100
+ const a = beautifyUUID(uuid1);
101
+ const b = beautifyUUID(uuid2);
102
+ if (a === b)
103
+ return true;
104
+ const isCustom128 = (u) => u.length === 36;
105
+ if (isCustom128(a) && isCustom128(b))
106
+ return a.substring(9) === b.substring(9);
107
+ return false;
108
+ };
99
109
  export const fullUUID = (str) => {
100
110
  if (!str)
101
111
  return str;
@@ -3,6 +3,8 @@ import { CSP, CSP_MEASUREMENT, FTMS_CP, FTMS_FEATURE, FTMS_STATUS, HR_MEASUREMEN
3
3
  import { WAHOO_ADVANCED_FTMS, WAHOO_ADVANCED_TRAINER_CP, ErgWriteDelay } from './consts.js';
4
4
  import BleFitnessMachineDevice from "../fm/sensor.js";
5
5
  import { beautifyUUID } from "../utils.js";
6
+ import { InteruptableTask } from "../../utils/task.js";
7
+ const WAHOO_CP_WRITE_TIMEOUT = 800;
6
8
  export default class BleWahooDevice extends BleFitnessMachineDevice {
7
9
  static profile = 'Smart Trainer';
8
10
  static protocol = 'wahoo';
@@ -229,7 +231,22 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
229
231
  opcode.writeUInt8(requestedOpCode, 0);
230
232
  const message = Buffer.concat([opcode, data]);
231
233
  this.logEvent({ message: 'wahoo cp:write', data: message.toString('hex') });
232
- const res = await this.write(this.wahooCP, message, props);
234
+ let res;
235
+ if (props?.timeout) {
236
+ const internalAbort = new AbortController();
237
+ const combined = new AbortController();
238
+ props.signal?.addEventListener('abort', () => combined.abort(), { once: true });
239
+ internalAbort.signal.addEventListener('abort', () => combined.abort(), { once: true });
240
+ const signal = combined.signal;
241
+ res = await new InteruptableTask(this.write(this.wahooCP, message, { ...props, signal }), {
242
+ timeout: props.timeout,
243
+ errorOnTimeout: true,
244
+ onCancel: () => internalAbort.abort()
245
+ }).run();
246
+ }
247
+ else {
248
+ res = await this.write(this.wahooCP, message, props);
249
+ }
233
250
  const responseData = Buffer.from(res);
234
251
  const result = responseData.readUInt8(0);
235
252
  return result === 1;
@@ -258,7 +275,7 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
258
275
  return false;
259
276
  const data = Buffer.alloc(2);
260
277
  data.writeInt16LE(Math.round(power), 0);
261
- const res = await this.writeWahooFtmsMessage(66, data);
278
+ const res = await this.writeWahooFtmsMessage(66, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
262
279
  if (res === true) {
263
280
  this.setPowerAdjusting();
264
281
  this.data.targetPower = power;
@@ -293,7 +310,7 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
293
310
  data.writeInt16LE(Math.round(weight * 100), 0);
294
311
  data.writeInt16LE(Math.round(crr * 10000), 2);
295
312
  data.writeInt16LE(Math.round(cw * 1000), 4);
296
- const res = await this.writeWahooFtmsMessage(67, data);
313
+ const res = await this.writeWahooFtmsMessage(67, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
297
314
  this.isSimMode = true;
298
315
  this.simModeSettings = { weight, crr, cw };
299
316
  return res;
@@ -308,7 +325,7 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
308
325
  try {
309
326
  const data = Buffer.alloc(2);
310
327
  data.writeInt16LE(Math.round(crr * 10000), 0);
311
- const res = await this.writeWahooFtmsMessage(68, data);
328
+ const res = await this.writeWahooFtmsMessage(68, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
312
329
  return res;
313
330
  }
314
331
  catch (err) {
@@ -321,7 +338,7 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
321
338
  try {
322
339
  const data = Buffer.alloc(2);
323
340
  data.writeInt16LE(Math.round(cw * 1000), 0);
324
- const res = await this.writeWahooFtmsMessage(69, data);
341
+ const res = await this.writeWahooFtmsMessage(69, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
325
342
  return res;
326
343
  }
327
344
  catch (err) {
@@ -340,7 +357,7 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
340
357
  const slopeVal = Math.min(Math.round((1 + s / 100) * 65535 / 2.0), 65535);
341
358
  const data = Buffer.alloc(2);
342
359
  data.writeUInt16LE(slopeVal, 0);
343
- const res = await this.writeWahooFtmsMessage(70, data);
360
+ const res = await this.writeWahooFtmsMessage(70, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
344
361
  return res;
345
362
  }
346
363
  catch (err) {
@@ -354,7 +371,7 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
354
371
  const value = (Math.max(-32.767, Math.min(32.767, v)) + 32.767) * 1000;
355
372
  const data = Buffer.alloc(2);
356
373
  data.writeInt16LE(Math.round(value), 0);
357
- const res = await this.writeWahooFtmsMessage(71, data);
374
+ const res = await this.writeWahooFtmsMessage(71, data, { timeout: WAHOO_CP_WRITE_TIMEOUT });
358
375
  return res;
359
376
  }
360
377
  catch (err) {
@@ -368,4 +385,19 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
368
385
  getWheelCircumference() {
369
386
  return this.wheelCircumference;
370
387
  }
388
+ async startRequest() {
389
+ return true;
390
+ }
391
+ async stopRequest() {
392
+ return true;
393
+ }
394
+ async PauseRequest() {
395
+ return true;
396
+ }
397
+ async setTargetInclination(_inclination) {
398
+ return true;
399
+ }
400
+ async setTargetResistanceLevel(_resistanceLevel) {
401
+ return true;
402
+ }
371
403
  }
@@ -16,6 +16,7 @@ export declare function getPeripheralInfo(p: BleRawPeripheral): {
16
16
  export declare function getCharachteristicsInfo(c: BleCharacteristic): string;
17
17
  export declare const parseUUID: (str: string) => string;
18
18
  export declare const beautifyUUID: (str: string, withX?: boolean) => string;
19
+ export declare const isSameServiceFamily: (uuid1: string, uuid2: string) => boolean;
19
20
  export declare const fullUUID: (str: string) => string;
20
21
  export declare const propertyVal: (properties: BleProperty[]) => number;
21
22
  export declare const propertyFromVal: (val: number) => BleProperty[];
@@ -51,4 +51,9 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
51
51
  setSimWindSpeed(v: number): Promise<boolean>;
52
52
  setWheelCircumference(wheelCircumference: number): Promise<void>;
53
53
  getWheelCircumference(): number;
54
+ startRequest(): Promise<boolean>;
55
+ stopRequest(): Promise<boolean>;
56
+ PauseRequest(): Promise<boolean>;
57
+ setTargetInclination(_inclination: number): Promise<boolean>;
58
+ setTargetResistanceLevel(_resistanceLevel: number): Promise<boolean>;
54
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "3.0.28",
3
+ "version": "3.0.30",
4
4
  "scripts": {
5
5
  "lint": "eslint . --ext .ts",
6
6
  "build": "npm run build:esm && npm run build:cjs",