incyclist-devices 2.4.10 → 2.4.12

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.
@@ -50,6 +50,7 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
50
50
  initHubService(setSimulation?: boolean): Promise<boolean>;
51
51
  sendHubRequest(request: HubRequest): Promise<Buffer<ArrayBufferLike>>;
52
52
  sendHubCommand(command: HubCommand): Promise<Buffer<ArrayBufferLike>>;
53
+ protected onTrainerResponse(m: Buffer): void;
53
54
  protected onRidingData(m: Buffer): void;
54
55
  protected onDeviceInformation(m: Buffer): void;
55
56
  onClickButtonMessage(d: Buffer): void;
@@ -146,6 +146,9 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
146
146
  else if (type === 0x03) {
147
147
  this.onRidingData(message);
148
148
  }
149
+ else if (type === 0x2A) {
150
+ this.onTrainerResponse(message);
151
+ }
149
152
  else if (type === 0x3c) {
150
153
  this.onDeviceInformation(message);
151
154
  }
@@ -157,31 +160,38 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
157
160
  }
158
161
  initHubService() {
159
162
  return __awaiter(this, arguments, void 0, function* (setSimulation = true) {
160
- var _a;
161
163
  if (!this.isHubServiceActive && this.initHubServicePromise !== undefined) {
162
164
  yield this.initHubServicePromise;
163
165
  }
166
+ const subscribe = () => __awaiter(this, void 0, void 0, function* () {
167
+ var _a;
168
+ if (!this.isHubServiceSubscribed) {
169
+ this.logEvent({ message: 'subscribe to hub service characteristics' });
170
+ this.subscribePromise = (_a = this.subscribePromise) !== null && _a !== void 0 ? _a : this.subscribe();
171
+ const subscribed = yield this.subscribePromise;
172
+ this.subscribePromise = undefined;
173
+ this.isHubServiceSubscribed = subscribed;
174
+ if (!subscribed)
175
+ return false;
176
+ this.logEvent({ message: 'subscribed to hub service characteristics' });
177
+ }
178
+ });
179
+ const pair = () => __awaiter(this, void 0, void 0, function* () {
180
+ if (!this.isHubServicePaired) {
181
+ this.logEvent({ message: 'pair hub service' });
182
+ this.pairPromise = this.pair();
183
+ const paired = yield this.pairPromise;
184
+ this.pairPromise = undefined;
185
+ if (!paired)
186
+ return false;
187
+ }
188
+ });
164
189
  if (this.isHubServiceActive)
165
190
  return true;
166
191
  this.logEvent({ message: 'init hub service', paired: this.isHubPairConfirmed, subscribed: this.isHubServiceSubscribed });
167
- if (!this.isHubServicePaired) {
168
- this.logEvent({ message: 'pair hub service' });
169
- this.pairPromise = this.pair();
170
- const paired = yield this.pairPromise;
171
- this.pairPromise = undefined;
172
- if (!paired)
173
- return false;
174
- }
175
- if (!this.isHubServiceSubscribed) {
176
- this.logEvent({ message: 'subscribe to hub service characteristics' });
177
- this.subscribePromise = (_a = this.subscribePromise) !== null && _a !== void 0 ? _a : this.subscribe();
178
- const subscribed = yield this.subscribePromise;
179
- this.subscribePromise = undefined;
180
- this.isHubServiceSubscribed = subscribed;
181
- if (!subscribed)
182
- return false;
183
- this.logEvent({ message: 'subscribed to hub service characteristics' });
184
- }
192
+ yield subscribe();
193
+ yield pair();
194
+ yield subscribe();
185
195
  this.initHubServicePromise = new Promise((done) => {
186
196
  this.logEvent({ message: 'send hub init message' });
187
197
  let timeout = setTimeout(() => {
@@ -235,6 +245,16 @@ class BleZwiftPlaySensor extends sensor_1.TBleSensor {
235
245
  return yield this.sendPlayCommand(0x04, message);
236
246
  });
237
247
  }
248
+ onTrainerResponse(m) {
249
+ try {
250
+ const data = zwift_hub_1.TrainerResponse.fromBinary(m);
251
+ this.emit('hub-trainer-response', data);
252
+ this.logEvent({ message: 'trainer response received', data });
253
+ }
254
+ catch (err) {
255
+ this.logEvent({ message: 'Error', fn: 'onTrainerResponse', error: err.message, stack: err.stack });
256
+ }
257
+ }
238
258
  onRidingData(m) {
239
259
  try {
240
260
  this.tsLastRidingData = Date.now();
@@ -67,6 +67,13 @@ export interface RideKeyPadStatus {
67
67
  buttonMap?: number;
68
68
  analogButtons?: RideAnalogKeyGroup;
69
69
  }
70
+ export interface TrainerResponse {
71
+ unknown?: number;
72
+ content?: TrainerResponseContent;
73
+ }
74
+ export interface TrainerResponseContent {
75
+ text?: string;
76
+ }
70
77
  export interface ClickKeyPadStatus {
71
78
  buttonPlus?: PlayButtonStatus;
72
79
  buttonMinus?: PlayButtonStatus;
@@ -230,6 +237,20 @@ declare class RideKeyPadStatus$Type extends MessageType<RideKeyPadStatus> {
230
237
  internalBinaryWrite(message: RideKeyPadStatus, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
231
238
  }
232
239
  export declare const RideKeyPadStatus: RideKeyPadStatus$Type;
240
+ declare class TrainerResponse$Type extends MessageType<TrainerResponse> {
241
+ constructor();
242
+ create(value?: PartialMessage<TrainerResponse>): TrainerResponse;
243
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: TrainerResponse): TrainerResponse;
244
+ internalBinaryWrite(message: TrainerResponse, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
245
+ }
246
+ export declare const TrainerResponse: TrainerResponse$Type;
247
+ declare class TrainerResponseContent$Type extends MessageType<TrainerResponseContent> {
248
+ constructor();
249
+ create(value?: PartialMessage<TrainerResponseContent>): TrainerResponseContent;
250
+ internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: TrainerResponseContent): TrainerResponseContent;
251
+ internalBinaryWrite(message: TrainerResponseContent, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
252
+ }
253
+ export declare const TrainerResponseContent: TrainerResponseContent$Type;
233
254
  declare class ClickKeyPadStatus$Type extends MessageType<ClickKeyPadStatus> {
234
255
  constructor();
235
256
  create(value?: PartialMessage<ClickKeyPadStatus>): ClickKeyPadStatus;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeviceDataEnvelope = exports.DeviceSettingsSubContent = exports.DeviceSettings = exports.DeviceInformation = exports.SubContent = exports.DeviceInformationContent = exports.ClickKeyPadStatus = exports.RideKeyPadStatus = exports.RideAnalogKeyGroup = exports.RideAnalogKeyPress = exports.Idle = exports.PlayCommand = exports.PlayCommandContents = exports.PlayCommandParameters = exports.PlayKeyPadStatus = exports.HubCommand = exports.PhysicalParam = exports.SimulationParam = exports.HubRidingData = exports.HubRequest = exports.RideAnalogLocation = exports.RideButtonMask = exports.PlayButtonStatus = void 0;
3
+ exports.DeviceDataEnvelope = exports.DeviceSettingsSubContent = exports.DeviceSettings = exports.DeviceInformation = exports.SubContent = exports.DeviceInformationContent = exports.ClickKeyPadStatus = exports.TrainerResponseContent = exports.TrainerResponse = exports.RideKeyPadStatus = exports.RideAnalogKeyGroup = exports.RideAnalogKeyPress = exports.Idle = exports.PlayCommand = exports.PlayCommandContents = exports.PlayCommandParameters = exports.PlayKeyPadStatus = exports.HubCommand = exports.PhysicalParam = exports.SimulationParam = exports.HubRidingData = exports.HubRequest = exports.RideAnalogLocation = exports.RideButtonMask = exports.PlayButtonStatus = void 0;
4
4
  const runtime_1 = require("@protobuf-ts/runtime");
5
5
  const runtime_2 = require("@protobuf-ts/runtime");
6
6
  const runtime_3 = require("@protobuf-ts/runtime");
@@ -715,6 +715,94 @@ class RideKeyPadStatus$Type extends runtime_4.MessageType {
715
715
  }
716
716
  }
717
717
  exports.RideKeyPadStatus = new RideKeyPadStatus$Type();
718
+ class TrainerResponse$Type extends runtime_4.MessageType {
719
+ constructor() {
720
+ super("org.cagnulen.qdomyoszwift.TrainerResponse", [
721
+ { no: 1, name: "Unknown", kind: "scalar", jsonName: "Unknown", opt: true, T: 13 },
722
+ { no: 2, name: "Content", kind: "message", jsonName: "Content", T: () => exports.TrainerResponseContent }
723
+ ]);
724
+ }
725
+ create(value) {
726
+ const message = globalThis.Object.create((this.messagePrototype));
727
+ if (value !== undefined)
728
+ (0, runtime_3.reflectionMergePartial)(this, message, value);
729
+ return message;
730
+ }
731
+ internalBinaryRead(reader, length, options, target) {
732
+ let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length;
733
+ while (reader.pos < end) {
734
+ let [fieldNo, wireType] = reader.tag();
735
+ switch (fieldNo) {
736
+ case 1:
737
+ message.unknown = reader.uint32();
738
+ break;
739
+ case 2:
740
+ message.content = exports.TrainerResponseContent.internalBinaryRead(reader, reader.uint32(), options, message.content);
741
+ break;
742
+ default:
743
+ let u = options.readUnknownField;
744
+ if (u === "throw")
745
+ throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
746
+ let d = reader.skip(wireType);
747
+ if (u !== false)
748
+ (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
749
+ }
750
+ }
751
+ return message;
752
+ }
753
+ internalBinaryWrite(message, writer, options) {
754
+ if (message.unknown !== undefined)
755
+ writer.tag(1, runtime_1.WireType.Varint).uint32(message.unknown);
756
+ if (message.content)
757
+ exports.TrainerResponseContent.internalBinaryWrite(message.content, writer.tag(2, runtime_1.WireType.LengthDelimited).fork(), options).join();
758
+ let u = options.writeUnknownFields;
759
+ if (u !== false)
760
+ (u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
761
+ return writer;
762
+ }
763
+ }
764
+ exports.TrainerResponse = new TrainerResponse$Type();
765
+ class TrainerResponseContent$Type extends runtime_4.MessageType {
766
+ constructor() {
767
+ super("org.cagnulen.qdomyoszwift.TrainerResponseContent", [
768
+ { no: 4, name: "Text", kind: "scalar", jsonName: "Text", opt: true, T: 9 }
769
+ ]);
770
+ }
771
+ create(value) {
772
+ const message = globalThis.Object.create((this.messagePrototype));
773
+ if (value !== undefined)
774
+ (0, runtime_3.reflectionMergePartial)(this, message, value);
775
+ return message;
776
+ }
777
+ internalBinaryRead(reader, length, options, target) {
778
+ let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length;
779
+ while (reader.pos < end) {
780
+ let [fieldNo, wireType] = reader.tag();
781
+ switch (fieldNo) {
782
+ case 4:
783
+ message.text = reader.string();
784
+ break;
785
+ default:
786
+ let u = options.readUnknownField;
787
+ if (u === "throw")
788
+ throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
789
+ let d = reader.skip(wireType);
790
+ if (u !== false)
791
+ (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
792
+ }
793
+ }
794
+ return message;
795
+ }
796
+ internalBinaryWrite(message, writer, options) {
797
+ if (message.text !== undefined)
798
+ writer.tag(4, runtime_1.WireType.LengthDelimited).string(message.text);
799
+ let u = options.writeUnknownFields;
800
+ if (u !== false)
801
+ (u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
802
+ return writer;
803
+ }
804
+ }
805
+ exports.TrainerResponseContent = new TrainerResponseContent$Type();
718
806
  class ClickKeyPadStatus$Type extends runtime_4.MessageType {
719
807
  constructor() {
720
808
  super("org.cagnulen.qdomyoszwift.ClickKeyPadStatus", [
@@ -2,7 +2,7 @@ import { DeviceType, IncyclistBikeData } from '../../../types';
2
2
  export declare const DEFAULT_AGE = 30;
3
3
  export declare const DEFAULT_USER_WEIGHT = 75;
4
4
  export declare const DEFAULT_BIKE_WEIGHT = 10;
5
- export declare function getCockpit(c: number): "Cardio" | "Fitness" | "Vita De Luxe" | "8008" | "8008 TRS" | "8080" | "Therapie" | "8008 TRS Pro" | "8008 TRS3" | "ergo_lyps Cardio Pro" | "Unknown";
5
+ export declare function getCockpit(c: number): "Unknown" | "Cardio" | "Fitness" | "Vita De Luxe" | "8008" | "8008 TRS" | "8080" | "Therapie" | "8008 TRS Pro" | "8008 TRS3" | "ergo_lyps Cardio Pro";
6
6
  export declare function getSerialNo(arr: Uint8Array, start: number, length: number): string;
7
7
  export declare function getBikeType(type?: DeviceType): number;
8
8
  export declare function getGender(sex: any): 0 | 1 | 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "2.4.10",
3
+ "version": "2.4.12",
4
4
  "dependencies": {
5
5
  "@protobuf-ts/runtime": "^2.11.1",
6
6
  "@serialport/bindings-interface": "^1.2.2",