incyclist-devices 2.0.35 → 2.0.36

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 (54) hide show
  1. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +2 -2
  2. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +2 -2
  3. package/lib/antv2/modes/ant-fe-st-mode.d.ts +2 -2
  4. package/lib/base/adpater.d.ts +2 -1
  5. package/lib/base/adpater.js +7 -6
  6. package/lib/interfaces.d.ts +1 -1
  7. package/lib/modes/ble-erg-mode.d.ts +2 -2
  8. package/lib/modes/ble-st-mode.d.ts +2 -2
  9. package/lib/modes/cycling-mode.d.ts +7 -7
  10. package/lib/modes/power-base.d.ts +3 -3
  11. package/lib/modes/power-base.js +3 -2
  12. package/lib/modes/power-meter.d.ts +2 -2
  13. package/lib/serial/comms.d.ts +62 -0
  14. package/lib/serial/comms.js +280 -0
  15. package/lib/serial/daum/DaumAdapter.d.ts +13 -8
  16. package/lib/serial/daum/DaumAdapter.js +49 -12
  17. package/lib/serial/daum/ERGCyclingMode.d.ts +2 -2
  18. package/lib/serial/daum/ERGCyclingMode.js +1 -1
  19. package/lib/serial/daum/SmartTrainerCyclingMode.d.ts +3 -2
  20. package/lib/serial/daum/SmartTrainerCyclingMode.js +10 -5
  21. package/lib/serial/daum/classic/adapter.d.ts +4 -6
  22. package/lib/serial/daum/classic/adapter.js +5 -23
  23. package/lib/serial/daum/classic/comms.d.ts +33 -65
  24. package/lib/serial/daum/classic/comms.js +148 -332
  25. package/lib/serial/daum/classic/mock.js +5 -3
  26. package/lib/serial/daum/classic/modes/daum-classic.d.ts +2 -2
  27. package/lib/serial/daum/classic/modes/daum-classic.js +1 -1
  28. package/lib/serial/daum/classic/types.d.ts +59 -0
  29. package/lib/serial/daum/classic/types.js +2 -0
  30. package/lib/serial/daum/classic/utils.d.ts +11 -10
  31. package/lib/serial/daum/classic/utils.js +33 -68
  32. package/lib/serial/daum/premium/adapter.d.ts +4 -7
  33. package/lib/serial/daum/premium/adapter.js +7 -30
  34. package/lib/serial/daum/premium/comms.d.ts +28 -105
  35. package/lib/serial/daum/premium/comms.js +262 -466
  36. package/lib/serial/daum/premium/consts.d.ts +6 -0
  37. package/lib/serial/daum/premium/consts.js +9 -0
  38. package/lib/serial/daum/premium/mock.d.ts +32 -1
  39. package/lib/serial/daum/premium/mock.js +131 -8
  40. package/lib/serial/daum/premium/modes/daum-classic.d.ts +2 -2
  41. package/lib/serial/daum/premium/modes/daum-classic.js +1 -1
  42. package/lib/serial/daum/premium/types.d.ts +35 -1
  43. package/lib/serial/daum/premium/types.js +29 -0
  44. package/lib/serial/daum/premium/utils.d.ts +11 -18
  45. package/lib/serial/daum/premium/utils.js +25 -18
  46. package/lib/serial/serial-interface.js +3 -2
  47. package/lib/types/adapter.d.ts +2 -0
  48. package/lib/types/device.d.ts +11 -0
  49. package/lib/types/route.d.ts +0 -5
  50. package/lib/types/route.js +0 -7
  51. package/lib/utils/calculations.js +1 -5
  52. package/lib/utils/utils.d.ts +2 -1
  53. package/lib/utils/utils.js +39 -3
  54. package/package.json +3 -2
@@ -1,13 +1,14 @@
1
+ import { IncyclistBikeData } from '../../..';
2
+ import { DeviceType } from '../../../types/device';
1
3
  export declare const DEFAULT_AGE = 30;
2
4
  export declare const DEFAULT_USER_WEIGHT = 75;
3
5
  export declare const DEFAULT_BIKE_WEIGHT = 10;
4
- export declare function getCockpit(c: any): "Cardio" | "Fitness" | "Vita De Luxe" | "8008" | "8008 TRS" | "8080" | "Therapie" | "8008 TRS Pro" | "8008 TRS3" | "ergo_lyps Cardio Pro" | "Unknown";
5
- export declare function getBikeType(type: any): 0 | 1;
6
- export declare function getGender(sex: any): 1 | 2;
7
- export declare function getLength(length: any): number;
8
- export declare function getWeight(weight?: any): number;
9
- export declare function parseRunData(data: any): any;
10
- export declare function buildError(status: any, err: any): any;
11
- export declare function hexstr(arr: any, start?: any, len?: any): string;
12
- export declare function Float32ToHex(float32: any): any;
13
- export declare function Float32ToIntArray(float32: any): any[];
6
+ 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";
7
+ export declare function getSerialNo(arr: Uint8Array, start: number, length: number): string;
8
+ export declare function getBikeType(type?: DeviceType): number;
9
+ export declare function getGender(sex: any): 0 | 1 | 2;
10
+ export declare function getLength(length?: number): number;
11
+ export declare function getWeight(weight?: number): number;
12
+ export declare function parseRunData(data: any): IncyclistBikeData;
13
+ export declare function between(v: number, min: number, max: number): number;
14
+ export declare function buildSetSlopeCommand(bikeNo: any, slope: any): number[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Float32ToIntArray = exports.Float32ToHex = exports.hexstr = exports.buildError = exports.parseRunData = exports.getWeight = exports.getLength = exports.getGender = exports.getBikeType = exports.getCockpit = exports.DEFAULT_BIKE_WEIGHT = exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_AGE = void 0;
3
+ exports.buildSetSlopeCommand = exports.between = exports.parseRunData = exports.getWeight = exports.getLength = exports.getGender = exports.getBikeType = exports.getSerialNo = exports.getCockpit = exports.DEFAULT_BIKE_WEIGHT = exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_AGE = void 0;
4
4
  exports.DEFAULT_AGE = 30;
5
5
  exports.DEFAULT_USER_WEIGHT = 75;
6
6
  exports.DEFAULT_BIKE_WEIGHT = 10;
@@ -31,18 +31,23 @@ function getCockpit(c) {
31
31
  }
32
32
  }
33
33
  exports.getCockpit = getCockpit;
34
+ function getSerialNo(arr, start, length) {
35
+ const buffer = Buffer.from(arr.subarray(start, start + length));
36
+ return buffer.toString('hex');
37
+ }
38
+ exports.getSerialNo = getSerialNo;
34
39
  function getBikeType(type) {
40
+ const DAUM_CLASSIC_BT_MOUNTAIN = 1;
41
+ const DAUM_CLASSIC_BT_RACE = 0;
35
42
  if (type === undefined)
36
- return 0;
43
+ return DAUM_CLASSIC_BT_RACE;
37
44
  switch (type) {
38
- case "triathlon":
39
- return 0;
40
- case "race":
41
- return 0;
42
- case "mountain":
43
- return 1;
44
- default:
45
- return 1;
45
+ case 'triathlon':
46
+ return DAUM_CLASSIC_BT_RACE;
47
+ case 'race':
48
+ return DAUM_CLASSIC_BT_RACE;
49
+ case 'mountain':
50
+ return DAUM_CLASSIC_BT_MOUNTAIN;
46
51
  }
47
52
  }
48
53
  exports.getBikeType = getBikeType;
@@ -51,7 +56,7 @@ function getGender(sex) {
51
56
  return 2;
52
57
  switch (sex) {
53
58
  case "M":
54
- return 1;
59
+ return 0;
55
60
  case "F":
56
61
  return 1;
57
62
  default:
@@ -62,82 +67,42 @@ exports.getGender = getGender;
62
67
  function getLength(length) {
63
68
  if (length === undefined || length === null)
64
69
  return 180;
65
- let l = Math.round(length);
66
- if (l < 100)
67
- return 100;
68
- if (l > 220)
69
- return 220;
70
- return l;
70
+ const l = Math.round(length);
71
+ return between(l, 100, 220);
71
72
  }
72
73
  exports.getLength = getLength;
73
74
  function getWeight(weight) {
74
75
  if (weight === undefined || weight === null)
75
76
  return 80;
76
77
  let m = Math.round(weight);
77
- if (isNaN(m))
78
- return 80;
79
- if (m < 10)
80
- return 10;
81
- if (m > 250)
82
- return 250;
83
- return m;
78
+ return between(m, 10, 250);
84
79
  }
85
80
  exports.getWeight = getWeight;
86
81
  function parseRunData(data) {
87
82
  const bikeData = {};
88
83
  bikeData.isPedalling = (data[4] > 0);
89
84
  bikeData.power = data[5] * 5;
90
- bikeData.cadence = data[6];
85
+ bikeData.pedalRpm = data[6];
91
86
  bikeData.speed = data[7];
92
87
  bikeData.heartrate = data[14];
93
- bikeData.distance = (data[9] * 256 + data[8]) / 10;
94
88
  bikeData.distanceInternal = (data[9] * 256 + data[8]) * 100;
95
89
  bikeData.time = (data[11] * 256 + data[10]);
96
90
  bikeData.gear = data[16];
97
91
  return bikeData;
98
92
  }
99
93
  exports.parseRunData = parseRunData;
100
- function buildError(status, err) {
101
- const message = err && err.message ? err.message : err;
102
- const error = new Error(message);
103
- error.status = status;
104
- return error;
94
+ function between(v, min, max) {
95
+ if (v < min)
96
+ return min;
97
+ if (v > max)
98
+ return max;
99
+ return v;
105
100
  }
106
- exports.buildError = buildError;
107
- function hexstr(arr, start, len) {
108
- var str = "";
109
- if (start === undefined)
110
- start = 0;
111
- if (len === undefined) {
112
- len = arr.length;
113
- }
114
- if (len - start > arr.length) {
115
- len = arr.length - start;
116
- }
117
- var j = start;
118
- for (var i = 0; i < len; i++) {
119
- var hex = Math.abs(arr[j++]).toString(16);
120
- if (i !== 0)
121
- str += " ";
122
- str += hex;
123
- }
124
- return str;
125
- }
126
- exports.hexstr = hexstr;
127
- function Float32ToHex(float32) {
128
- function getHex(i) { return ('00' + i.toString(16)).slice(-2).toUpperCase(); }
129
- var view = new DataView(new ArrayBuffer(4));
130
- view.setFloat32(0, float32);
131
- return Array.apply(null, { length: 4 }).map((_, i) => getHex(view.getUint8(i))).join('');
132
- }
133
- exports.Float32ToHex = Float32ToHex;
134
- function Float32ToIntArray(float32) {
135
- var view = new DataView(new ArrayBuffer(4));
136
- view.setFloat32(0, float32);
137
- var arr = [];
138
- for (let i = 0; i < 4; i++) {
139
- arr.push(view.getUint8(i));
140
- }
141
- return arr;
101
+ exports.between = between;
102
+ function buildSetSlopeCommand(bikeNo, slope) {
103
+ const buffer = Buffer.from([0x55, bikeNo, 0, 0, 0, 0]);
104
+ buffer.writeFloatLE(slope, 2);
105
+ const cmd = Array.from(buffer);
106
+ return cmd;
142
107
  }
143
- exports.Float32ToIntArray = Float32ToIntArray;
108
+ exports.buildSetSlopeCommand = buildSetSlopeCommand;
@@ -1,15 +1,14 @@
1
- import { DeviceProperties } from '../../../types/device';
2
1
  import { SerialInterface } from '../..';
3
2
  import { SerialDeviceSettings } from '../../adapter';
4
3
  import { SerialCommProps } from '../../comm';
5
4
  import DaumAdapter from '../DaumAdapter';
6
5
  import { Daum8iDeviceProperties } from './types';
7
- export default class DaumPremiumAdapter extends DaumAdapter {
6
+ import { IncyclistBikeData } from '../../..';
7
+ export default class DaumPremiumAdapter extends DaumAdapter<SerialDeviceSettings, Daum8iDeviceProperties> {
8
8
  static NAME: string;
9
9
  commProps: SerialCommProps;
10
10
  _startRetryTimeout: number;
11
- constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
12
- logEvent(event: any): void;
11
+ constructor(settings: SerialDeviceSettings, props?: Daum8iDeviceProperties);
13
12
  getName(): string;
14
13
  getUniqueName(): string;
15
14
  getPort(): any;
@@ -19,10 +18,8 @@ export default class DaumPremiumAdapter extends DaumAdapter {
19
18
  isEqual(settings: SerialDeviceSettings): boolean;
20
19
  getSupportedCyclingModes(): Array<any>;
21
20
  check(): Promise<boolean>;
22
- pause(): Promise<boolean>;
23
- resume(): Promise<boolean>;
24
21
  startRide(props?: Daum8iDeviceProperties): Promise<boolean>;
25
22
  start(props?: Daum8iDeviceProperties): Promise<boolean>;
26
23
  launch(props?: Daum8iDeviceProperties, isRelaunch?: boolean): Promise<boolean>;
27
- getCurrentBikeData(): Promise<any>;
24
+ getCurrentBikeData(): Promise<IncyclistBikeData>;
28
25
  }
@@ -60,15 +60,6 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
60
60
  this.distanceInternal = undefined;
61
61
  this.initData();
62
62
  }
63
- logEvent(event) {
64
- if (this.logger) {
65
- this.logger.logEvent(event);
66
- }
67
- const w = global.window;
68
- if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG) {
69
- console.log('~~~ DaumPremium', event);
70
- }
71
- }
72
63
  getName() {
73
64
  return 'Daum8i';
74
65
  }
@@ -136,26 +127,6 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
136
127
  }));
137
128
  });
138
129
  }
139
- pause() {
140
- const _super = Object.create(null, {
141
- pause: { get: () => super.pause }
142
- });
143
- return __awaiter(this, void 0, void 0, function* () {
144
- const paused = yield _super.pause.call(this);
145
- this.bike.pauseLogging();
146
- return paused;
147
- });
148
- }
149
- resume() {
150
- const _super = Object.create(null, {
151
- resume: { get: () => super.resume }
152
- });
153
- return __awaiter(this, void 0, void 0, function* () {
154
- const resumed = yield _super.resume.call(this);
155
- this.bike.resumeLogging();
156
- return resumed;
157
- });
158
- }
159
130
  startRide(props = {}) {
160
131
  return __awaiter(this, void 0, void 0, function* () {
161
132
  this.logEvent({ message: 'relaunch of device' });
@@ -193,7 +164,9 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
193
164
  yield this.stop();
194
165
  return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
195
166
  try {
196
- yield this.connect();
167
+ const connected = yield this.connect();
168
+ if (!connected)
169
+ throw new Error('not connected');
197
170
  if (!info.deviceType) {
198
171
  info.deviceType = yield this.bike.getDeviceType();
199
172
  }
@@ -224,6 +197,10 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
224
197
  return;
225
198
  }
226
199
  catch (err) {
200
+ if (!info.deviceType) {
201
+ yield (0, utils_1.sleep)(500);
202
+ yield this.reconnect();
203
+ }
227
204
  throw (new Error(`could not start device, reason:${err.message}`));
228
205
  }
229
206
  }), 5, this._startRetryTimeout)
@@ -1,123 +1,46 @@
1
1
  /// <reference types="node" />
2
2
  import { ReservedCommands } from './utils';
3
- import { SerialInterface, SerialPortProvider } from '../..';
4
- import { EventLogger } from 'gd-eventlog';
5
3
  import { User } from "../../../types/user";
6
4
  import { Route } from "../../../types/route";
7
- import { SerialCommProps } from "../../comm";
8
- import { SerialPortStream } from "@serialport/stream";
9
5
  import { OnDeviceStartCallback } from "./types";
10
- import { Queue } from "../../../utils/utils";
11
- export type ResponseObject = {
12
- type: ResponseType;
13
- data?: string;
14
- error?: Error;
15
- };
16
- export type ResponseType = 'ACK' | 'NAK' | 'Response' | 'Error';
17
- export type Daum8iCommsState = {
18
- waitingForStart?: boolean;
19
- waitingForACK?: boolean;
20
- waitingForEnd?: boolean;
21
- partialCmd?: any;
22
- data: Queue<ResponseObject>;
23
- };
24
- export type ConnectionState = 'Connecting' | 'Connected' | 'Disconnected' | 'Disconnecting';
25
- export declare class CheckSumError extends Error {
26
- constructor();
27
- }
28
- export declare class ACKTimeout extends Error {
29
- constructor();
30
- }
31
- export declare class BusyTimeout extends Error {
32
- constructor();
33
- }
34
- export declare class ResponseTimeout extends Error {
35
- constructor();
36
- }
37
- export default class Daum8i {
38
- logger: EventLogger;
39
- serial: SerialInterface;
40
- path: string;
41
- tcpipConnection: {
42
- host: string;
43
- port: string;
44
- };
45
- port: string;
46
- settings: any;
47
- props: any;
48
- protected sp: SerialPortStream;
49
- protected connectState: ConnectionState;
50
- protected connectPromise: Promise<SerialPortStream>;
51
- protected disconnectPromise: Promise<boolean>;
52
- protected writePromise: Promise<void>;
53
- protected sendCmdPromise: Promise<string>;
54
- protected actualBikeType?: string;
55
- protected recvState: Daum8iCommsState;
56
- bikeData: any;
57
- isLoggingPaused: boolean;
58
- spp: SerialPortProvider;
59
- serialportProps: any;
60
- constructor(props: SerialCommProps);
61
- getInterface(): string;
62
- getPort(): string;
63
- isConnected(): boolean;
64
- pauseLogging(): void;
65
- resumeLogging(): void;
66
- logEvent(e: any): void;
67
- connect(): Promise<boolean>;
68
- closePort(): Promise<boolean>;
69
- cleanupPort(): void;
70
- close(): Promise<boolean>;
71
- flush(): Promise<void>;
72
- onPortClose(): Promise<void>;
73
- onPortError(error: Error): Promise<void>;
74
- isSending(): boolean;
75
- rejectCurrent(error: Error): void;
76
- getTimeoutValue(cmd?: any): number;
6
+ import SerialPortComms from "../../comms";
7
+ import { DaumPremiumCommsState, DaumPremiumRequest, ResponseObject } from "./types";
8
+ import { IncyclistBikeData } from "../../..";
9
+ export default class Daum8i extends SerialPortComms<DaumPremiumCommsState, DaumPremiumRequest, ResponseObject> {
10
+ validatePath(path: string): string;
11
+ getDefaultLoggerName(): string;
12
+ getAckTimeoutValue(): number;
13
+ getTimeoutValue(): number;
14
+ onConnected(): void;
15
+ getInitialCommsState(): DaumPremiumCommsState;
16
+ setState(ack: boolean, start: boolean, end: boolean): void;
77
17
  onData(data: any, depth?: number): any;
78
- waitWithTimeout(promise: Promise<any>, timeout: number, onTimeout?: () => void): Promise<any>;
79
- sendDaum8iCommand(command: string, payload?: string | any[]): Promise<string>;
80
- onIgnored(payload: string): void;
81
- onACK(): void;
82
- onNAK: () => void;
18
+ send(request: DaumPremiumRequest): Promise<ResponseObject>;
19
+ sendStrCommand(logString: string, command: string, payload?: string | Uint8Array): Promise<string>;
20
+ sendBinaryCommand(logString: string, command: string, payload?: string | Uint8Array): Promise<string>;
83
21
  waitForACK(): Promise<boolean>;
84
- waitForResponse(): Promise<string>;
85
- portWrite(buffer: Buffer): Promise<void>;
22
+ waitForResponse(): Promise<ResponseObject>;
86
23
  write(buffer: Buffer, ackExpected?: boolean): Promise<void>;
87
- sendACK(): Promise<void>;
88
- sendNAK(): Promise<void>;
89
- sendReservedDaum8iCommand(command: ReservedCommands, data?: Buffer): Promise<any[]>;
24
+ sendACK(logPayload: any): Promise<void>;
25
+ sendNAK(logPayload: any): Promise<void>;
90
26
  getProtocolVersion(): Promise<string>;
91
27
  getDashboardVersion(): Promise<string>;
92
- getDeviceType(): Promise<any>;
93
- getActualBikeType(): Promise<any>;
94
- setActualBikeType(actualBikeType: any): Promise<any>;
95
- getTrainingData(): Promise<{
96
- time: number;
97
- heartrate: number;
98
- speed: number;
99
- slope: number;
100
- distanceInternal: number;
101
- cadence: number;
102
- power: number;
103
- physEnergy: number;
104
- realEnergy: number;
105
- torque: number;
106
- gear: number;
107
- deviceState: number;
108
- speedStatus: string;
109
- }>;
110
- setLoadControl(enabled: any): Promise<boolean>;
28
+ getDeviceType(): Promise<string>;
29
+ getActualBikeType(): Promise<string>;
30
+ setActualBikeType(actualBikeType: any): Promise<string>;
31
+ getTrainingData(): Promise<IncyclistBikeData>;
32
+ setLoadControl(enabled: boolean): Promise<boolean>;
111
33
  getLoadControl(): Promise<boolean>;
112
- setPower(power: any): Promise<number>;
113
- getPower(power: any): Promise<number>;
34
+ setPower(power: number | string): Promise<number>;
35
+ getPower(): Promise<number>;
36
+ setGear(gear: number): Promise<number>;
37
+ getGear(): Promise<number>;
38
+ sendReservedDaum8iCommand(logString: string, command: ReservedCommands, data?: Buffer): Promise<Uint8Array>;
114
39
  setPerson(person: User): Promise<boolean>;
115
40
  programUploadInit(): Promise<boolean>;
116
41
  programUploadStart(bikeType: string, route?: Route): Promise<Uint8Array>;
117
42
  programUploadSendBlock(epp: Uint8Array, offset: number): Promise<boolean>;
118
43
  programUploadDone(): Promise<boolean>;
119
- programUpload(bikeType: string, route: Route, onStatusUpdate?: OnDeviceStartCallback): Promise<boolean>;
120
44
  startProgram(programId?: number): Promise<boolean>;
121
- setGear(gear: any): Promise<number>;
122
- getGear(): Promise<number>;
45
+ programUpload(bikeType: string, route: Route, onStatusUpdate?: OnDeviceStartCallback): Promise<boolean>;
123
46
  }