-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.h
267 lines (225 loc) · 8.82 KB
/
defs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*=========================================================================
*
* Filename: main.c
*
* Author: Marcelo Mourier
* Created: Mon Apr 11 11:24:16 MDT 2022
*
* Description: Type definitions
*
*=========================================================================
*
* Copyright (c) 2022 Marcelo Mourier
*
*=========================================================================
*/
#ifndef DEFS_H_
#define DEFS_H_
#include <stdio.h>
#include "tailq.h"
// Program version info
#define PROG_VER_MAJOR 1
#define PROG_VER_MINOR 10
typedef enum Bool {
false = 0,
true = 1
} Bool;
// Activity type
typedef enum ActType {
undef = 0,
ride = 1,
hike = 4,
run = 9,
walk = 10,
vride = 17,
other = 99
} ActType;
// Output file format
typedef enum OutFmt {
nil = 0,
csv = 1, // Comma-Separated-Values format
gpx = 2, // GPS Exchange format
shiz = 3, // FulGaz format
tcx = 4 // Training Center Exchange format
} OutFmt;
// Timestamp format
typedef enum TsFmt {
utc = 0, // YYYY-MM-DD HH:MM:SS
sec = 1, // plain seconds
hms = 2 // hh:mm:ss
} TsFmt;
// Type of units to display
typedef enum Units {
metric = 1, // meters, kph, celsius
imperial = 2, // feet, mph, farenheit
} Units;
// Moving Average method
typedef enum XmaMethod {
simple = 1, // SMA
weighed = 2 // WMA
} XmaMethod;
// Metric used for the SMA/WMA
typedef enum XmaMetric {
elevation = 1, // elevation
grade = 2, // grade
power = 3, // power
speed = 4, // speed
} XmaMetric;
// Sensor data bit masks
#define SD_NONE 0x00 // no metrics
#define SD_ATEMP 0x01 // ambient temperature
#define SD_CADENCE 0x02 // cadence
#define SD_HR 0x04 // heart rate
#define SD_POWER 0x08 // power
#define SD_ALL 0x0f // all metrics
// GPS Track Point
typedef struct TrkPt {
TAILQ_ENTRY(TrkPt) tqEntry; // node in the trkPtList
int index; // TrkPt index (0..N-1)
int lineNum; // line number in the input FIT/GPX/TCX file
const char *inFile; // input FIT/GPX/TCX file this trkpt came from
// Timestamp from FIT/GPX/TCX file
double timestamp; // in seconds+millisec since the Epoch
// GPS data from FIT/GPX/TCX file
double latitude; // in degrees decimal
double longitude; // in degrees decimal
double elevation; // in meters
// Extra data from FIT/GPX/TCX file
int ambTemp; // ambient temperature (in degrees Celsius)
int cadence; // pedaling cadence (in RPM)
int heartRate; // heart rate (in BPM)
int power; // pedaling power (in watts)
double speed; // speed (in m/s)
double distance; // distance from start (in meters)
// Computed metrics
Bool adjGrade; // grade was adjusted
double adjTime; // adjusted timestamp
double deltaG; // grade diff with previous point (in %)
double deltaS; // speed diff with previous point (in m/s)
double deltaT; // time diff with previous point (in seconds)
double dist; // distance traveled from previous point (in meters)
double rise; // elevation diff from previous point (in meters)
double run; // horizontal distance from previous point (in meters)
double bearing; // initial bearing / forward azimuth (in decimal degrees)
double grade; // actual grade (in %)
} TrkPt;
// GPS Track (sequence of Track Points)
typedef struct GpsTrk {
// List of TrkPt's
TAILQ_HEAD(TrkPtList, TrkPt) trkPtList;
// Number of TrkPt's in trkPtList
int numTrkPts;
// Number of TrkPt's that had their elevation values
// adjusted to match the min/max grade levels.
int numElevAdj;
// Number of TrkPt's discarded because they were a
// duplicate of the previous point.
int numDupTrkPts;
// Number of TrkPt's trimmed out (by user request)
int numTrimTrkPts;
// Number of dummy TrkPt's discarded; e.g. because
// of a null deltaT or a null deltaD.
int numDiscTrkPts;
// Activity type / Sport
ActType actType;
// Bitmask of optional metrics present in the input
int inMask;
// Activity's start/end times
double startTime;
double endTime;
// Base distance/time
double baseDistance; // distance reference to generate relative distance values
double baseTime; // time reference to generate relative timestamp values
// Time offset
double timeOffset; // to set/change the activity's start time
// Aggregate values
int heartRate;
int cadence;
int power;
int temp;
double time;
double stoppedTime; // amount of time with speed=0
double distance;
double elevGain;
double elevLoss;
double grade;
// Max values
int maxCadence;
int maxHeartRate;
int maxPower;
int maxTemp;
double maxDeltaD;
double maxDeltaG;
double maxDeltaT;
double maxElev;
double maxGrade;
double maxSpeed;
// Min values
int minCadence;
int minHeartRate;
int minPower;
int minTemp;
double minElev;
double minGrade;
double minSpeed;
const TrkPt *maxCadenceTrkPt; // TrkPt with max cadence value
const TrkPt *maxDeltaDTrkPt; // TrkPt with max dist diff
const TrkPt *maxDeltaGTrkPt; // TrkPt with max grade diff
const TrkPt *maxDeltaTTrkPt; // TrkPt with max time diff
const TrkPt *maxElevTrkPt; // TrkPt with max elevation value
const TrkPt *maxGradeTrkPt; // TrkPt with max grade value
const TrkPt *maxHeartRateTrkPt; // TrkPt with max HR value
const TrkPt *maxPowerTrkPt; // TrkPt with max power value
const TrkPt *maxSpeedTrkPt; // TrkPt with max speed value
const TrkPt *maxTempTrkPt; // TrkPt with max temp value
const TrkPt *minCadenceTrkPt; // TrkPt with min cadence value
const TrkPt *minDeltaDTrkPt; // TrkPt with min dist diff
const TrkPt *minDeltaTTrkPt; // TrkPt with min time diff
const TrkPt *minElevTrkPt; // TrkPt with max elevation value
const TrkPt *minGradeTrkPt; // TrkPt with min grade value
const TrkPt *minHeartRateTrkPt; // TrkPt with min HR value
const TrkPt *minPowerTrkPt; // TrkPt with min power value
const TrkPt *minSpeedTrkPt; // TrkPt with min speed value
const TrkPt *minTempTrkPt; // TrkPt with min temp value
} GpsTrk;
typedef struct CmdArgs {
int argc; // number of arguments
char **argv; // list of arguments
const char *inFile; // input file name
ActType actType; // activity type for the output file
int closeGap; // close the time gap at the specified track point
double maxGrade; // max grade allowed (in %)
double maxGradeChange; // max grade change allowed between points (in %)
double maxSpeedChange; // max speed change allowed between points (in %)
double minGrade; // min grade allowed (in %)
const char *name; // <name> tag
FILE *outFile; // output file
OutFmt outFmt; // format of the output data (csv, gpx)
int outMask; // bitmask of optional metrics to be included in the output
Bool quiet; // don't print any warning messages
int rangeFrom; // start point (inclusive)
int rangeTo; // end point (inclusive)
TsFmt tsFmt; // format of the timestamp value
double setSpeed; // speed to use to generate timestamps (in m/s)
int trimFrom; // start point to trim (inclusive)
int trimTo; // end point to trim (inclusive)
Units units; // type of units to display
XmaMethod xmaMethod; // method to compute the Moving Average
XmaMetric xmaMetric; // metric to use for the SMA/WMA
int xmaWindow; // size of the SMA/WMA window
double startTime; // start time for the activity
Bool noElevAdj; // do not auto-adjust the elevation
Bool summary; // show data summary
Bool verbatim; // no data adjustments
} CmdArgs;
#ifdef __cplusplus
extern "C" {
#endif
static __inline__ double mToKm(double m) { return (m / 1000.0); }
static __inline__ double kmToM(double km) { return (km * 1000.0); }
static __inline__ double mpsToKph(double mps) { return (mps * 3.6); }
static __inline__ double kphToMps(double kph) { return (kph / 3.6); }
#ifdef __cplusplus
};
#endif
#endif /* DEFS_H_ */