/
srmio.h
433 lines (329 loc) · 12.7 KB
/
srmio.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/*
* Copyright (c) 2008 Rainer Clasen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms described in the file LICENSE included in this
* distribution.
*
*/
#ifndef _SRMIO_H
#define _SRMIO_H
#include <stdio.h>
#include <time.h>
#include "srmio_config.h"
#ifdef __cplusplus
extern "C"
{
#endif
/* please check the actual source for descriptions of the individual
* functions */
/************************************************************
*
* from generated commit.c
*
************************************************************/
extern const char *srmio_commit;
/************************************************************
*
* from common.c
*
************************************************************/
extern const char *srmio_version;
/************************************************************
*
* from err.c
*
************************************************************/
#define SRMIO_ERROR_MSG_SIZE 512
struct _srmio_error_t {
char message[SRMIO_ERROR_MSG_SIZE];
};
typedef struct _srmio_error_t srmio_error_t;
/************************************************************
*
* from chunk.c
*
************************************************************/
typedef uint64_t srmio_time_t; /* seconds since epoch * 10 */
/* actual data tuple as retrieved from PowerControl or file */
struct _srmio_chunk_t {
srmio_time_t time; /* chunk start time */
srmio_time_t dur; /* chunk duration */
double temp; /* temperature °C */
unsigned pwr; /* avg power W */
double speed; /* avg speed km/h */
unsigned cad; /* avg cadence 1/min */
unsigned hr; /* avg hr 1/min */
long ele; /* elevation in meter */
};
typedef struct _srmio_chunk_t *srmio_chunk_t;
srmio_chunk_t srmio_chunk_new( srmio_error_t *err );
srmio_chunk_t srmio_chunk_clone( srmio_chunk_t chunk, srmio_error_t *err );
void srmio_chunk_free( srmio_chunk_t chunk );
/************************************************************
*
* from marker.c
*
************************************************************/
struct _srmio_marker_t {
unsigned first; /* num. of first marked chunk */
unsigned last; /* num. of last marked chunk */
char *notes; /* user's notes for this marker */
};
typedef struct _srmio_marker_t *srmio_marker_t;
srmio_marker_t srmio_marker_new( srmio_error_t *err );
srmio_marker_t srmio_marker_clone( srmio_marker_t marker, srmio_error_t *err );
void srmio_marker_free( srmio_marker_t marker );
/************************************************************
*
* from data.c
*
************************************************************/
/* data structure to hold all information retrieved
* from PowerControl or file */
struct _srmio_data_t {
double slope;
unsigned zeropos;
unsigned circum;
char *notes;
char *athlete; /* athlete name */
/* array of chunks */
srmio_chunk_t *chunks;
unsigned cused;
unsigned cavail;
/* array of marker */
srmio_marker_t *marker;
unsigned mused;
unsigned mavail;
};
typedef struct _srmio_data_t *srmio_data_t;
srmio_data_t srmio_data_new( srmio_error_t *err );
srmio_data_t srmio_data_header( srmio_data_t src, srmio_error_t *err );
void srmio_data_free( srmio_data_t data );
bool srmio_data_add_chunkp( srmio_data_t data, srmio_chunk_t chunk, srmio_error_t *err );
bool srmio_data_add_chunk( srmio_data_t data, srmio_chunk_t chunk, srmio_error_t *err );
bool srmio_data_add_markerp( srmio_data_t data, srmio_marker_t mark, srmio_error_t *err );
bool srmio_data_add_marker( srmio_data_t data, unsigned first, unsigned last, srmio_error_t *err );
bool srmio_data_time_start( srmio_data_t data, srmio_time_t *start, srmio_error_t *err );
bool srmio_data_time_end( srmio_data_t data, srmio_time_t *end, srmio_error_t *err );
bool srmio_data_recint( srmio_data_t data, srmio_time_t *recint, srmio_error_t *err );
srmio_marker_t *srmio_data_blocks( srmio_data_t data, srmio_error_t *err );
/************************************************************
*
* from fixup.c
*
************************************************************/
srmio_data_t srmio_data_fixup( srmio_data_t data, srmio_error_t *err );
/************************************************************
*
* from split.c
*
************************************************************/
srmio_data_t *srmio_data_split( srmio_data_t src,
srmio_time_t gap, srmio_time_t overlap, srmio_error_t *err );
/************************************************************
*
* from file_srm.c
*
************************************************************/
srmio_data_t srmio_file_srm_read( FILE *fh, srmio_error_t *err );
bool srmio_file_srm7_write( srmio_data_t data, FILE *fh, srmio_error_t *err );
/************************************************************
*
* from file_wkt.c
*
************************************************************/
bool srmio_file_wkt_write( srmio_data_t data, FILE *fh, srmio_error_t *err );
/************************************************************
*
* from ftypes.c
*
************************************************************/
typedef enum {
srmio_ftype_unknown,
srmio_ftype_srm5,
srmio_ftype_srm6,
srmio_ftype_srm7,
srmio_ftype_wkt,
srmio_ftype_max,
} srmio_ftype_t;
srmio_ftype_t srmio_ftype_from_string( const char *type );
srmio_data_t srmio_file_ftype_read( srmio_ftype_t ftype, FILE *fh, srmio_error_t *err );
bool srmio_file_ftype_write( srmio_data_t data, srmio_ftype_t ftype, FILE *fh, srmio_error_t *err );
/************************************************************
*
* from store.c
*
************************************************************/
typedef struct _srmio_store_t *srmio_store_t;
srmio_store_t srmio_store_new( const char *path, srmio_error_t *err );
void srmio_store_free( srmio_store_t );
bool srmio_store_have( srmio_store_t store,
const char *athlete, srmio_time_t start,
srmio_time_t fuzz, bool *have, srmio_error_t *err );
bool srmio_store_have_data( srmio_store_t store, srmio_data_t data,
srmio_time_t fuzz, bool *have, srmio_error_t *err );
bool srmio_store_add( srmio_store_t store, srmio_data_t data,
char **fname, srmio_error_t *err );
/************************************************************
*
* from serio.c
*
************************************************************/
typedef enum {
srmio_io_baud_2400,
srmio_io_baud_4800,
srmio_io_baud_9600,
srmio_io_baud_19200,
srmio_io_baud_38400,
srmio_io_baud_max
} srmio_io_baudrate_t;
bool srmio_io_baud2name( srmio_io_baudrate_t rate, unsigned *name );
bool srmio_io_name2baud( unsigned name, srmio_io_baudrate_t *rate );
typedef enum {
srmio_io_parity_none,
srmio_io_parity_even,
srmio_io_parity_odd,
srmio_io_parity_max,
} srmio_io_parity_t;
bool srmio_io_parity2name( srmio_io_parity_t parity, char *name );
bool srmio_io_name2parity( char name, srmio_io_parity_t *parity );
typedef enum {
srmio_io_flow_none,
srmio_io_flow_xonoff,
srmio_io_flow_rtscts,
srmio_io_flow_max,
} srmio_io_flow_t;
bool srmio_io_flow2name( srmio_io_flow_t flow, const char **name );
bool srmio_io_name2flow( const char *name, srmio_io_flow_t *parity );
/* IO handle for serial device abstraction */
typedef struct _srmio_io_t *srmio_io_t;
void srmio_io_free( srmio_io_t h );
bool srmio_io_set_baudrate( srmio_io_t h, srmio_io_baudrate_t, srmio_error_t *err );
bool srmio_io_set_parity( srmio_io_t h, srmio_io_parity_t, srmio_error_t *err );
bool srmio_io_set_flow( srmio_io_t h, srmio_io_flow_t, srmio_error_t *err );
bool srmio_io_open( srmio_io_t h, srmio_error_t *err );
bool srmio_io_close( srmio_io_t h, srmio_error_t *err );
bool srmio_io_update( srmio_io_t h, srmio_error_t *err );
bool srmio_io_is_open( srmio_io_t h );
int srmio_io_write( srmio_io_t h, const unsigned char *buf, size_t len, srmio_error_t *err );
int srmio_io_read( srmio_io_t h, unsigned char *buf, size_t len, srmio_error_t *err );
bool srmio_io_flush( srmio_io_t h, srmio_error_t *err );
bool srmio_io_send_break( srmio_io_t h, srmio_error_t *err );
/************************************************************
*
* from serios.c
*
************************************************************/
#ifdef SRMIO_HAVE_TERMIOS
srmio_io_t srmio_ios_new( const char *fname, srmio_error_t *err );
#endif
/************************************************************
*
* from seriow32.c
*
************************************************************/
#ifdef SRMIO_HAVE_WINCOM
srmio_io_t srmio_iow32_new( const char *fname, srmio_error_t *err );
#endif
/************************************************************
*
* from d2xx.c
*
************************************************************/
#ifdef SRMIO_HAVE_D2XX
srmio_io_t srmio_d2xx_serial_new( const char *serial, srmio_error_t *err );
srmio_io_t srmio_d2xx_description_new( const char *desc, srmio_error_t *err );
#endif
/************************************************************
*
* from pc.c
*
************************************************************/
typedef struct _srmio_pc_t *srmio_pc_t;
typedef enum {
srmio_pc_xfer_state_new,
srmio_pc_xfer_state_running,
srmio_pc_xfer_state_success,
srmio_pc_xfer_state_failed,
srmio_pc_xfer_state_abort,
srmio_pc_xfer_state_max,
} srmio_pc_xfer_state_t;
typedef enum {
srmio_pc_xfer_type_new,
srmio_pc_xfer_type_all, /* xfer deleted data, as well */
srmio_pc_xfer_type_max,
} srmio_pc_xfer_type_t;
struct _srmio_pc_xfer_block_t {
double slope;
unsigned zeropos;
unsigned circum;
char *athlete;
size_t total; /* $items in this block - for progress indication */
/* informational only, chunks may disagree!!!:
* 0 = unset/unknown
*/
srmio_time_t recint;
srmio_time_t start;
srmio_time_t end;
};
typedef struct _srmio_pc_xfer_block_t *srmio_pc_xfer_block_t;
void srmio_pc_free( srmio_pc_t conn );
bool srmio_pc_set_device( srmio_pc_t conn, srmio_io_t h, srmio_error_t *err );
bool srmio_pc_get_device( srmio_pc_t conn, srmio_io_t *h, srmio_error_t *err );
bool srmio_pc_set_baudrate( srmio_pc_t pch, srmio_io_baudrate_t rate, srmio_error_t *err );
bool srmio_pc_set_parity( srmio_pc_t pch, srmio_io_parity_t parity, srmio_error_t *err );
typedef void (*srmio_logfunc_t)( const char *msg,
void *user_data );
bool srmio_pc_set_logfunc( srmio_pc_t pch,
srmio_logfunc_t, void *user_data,
srmio_error_t *err );
bool srmio_pc_set_debugfunc( srmio_pc_t pch,
srmio_logfunc_t, void *user_data,
srmio_error_t *err );
bool srmio_pc_open( srmio_pc_t conn, srmio_error_t *err );
bool srmio_pc_close( srmio_pc_t conn, srmio_error_t *err );
bool srmio_pc_get_baudrate( srmio_pc_t pch, srmio_io_baudrate_t *rate, srmio_error_t *err );
bool srmio_pc_get_parity( srmio_pc_t pch, srmio_io_parity_t *parity, srmio_error_t *err );
bool srmio_pc_get_version( srmio_pc_t conn, unsigned *version, srmio_error_t *err );
bool srmio_pc_cmd_get_athlete( srmio_pc_t conn, char **athlete, srmio_error_t *err );
bool srmio_pc_cmd_set_time( srmio_pc_t conn, struct tm *timep, srmio_error_t *err );
bool srmio_pc_cmd_set_recint( srmio_pc_t conn, srmio_time_t recint, srmio_error_t *err );
bool srmio_pc_cmd_get_time( srmio_pc_t conn, struct tm *timep, srmio_error_t *err );
bool srmio_pc_cmd_get_circum( srmio_pc_t conn, unsigned *circum, srmio_error_t *err );
bool srmio_pc_cmd_get_slope( srmio_pc_t conn, double *slope, srmio_error_t *err );
bool srmio_pc_cmd_get_zeropos( srmio_pc_t conn, unsigned *zeropos, srmio_error_t *err );
bool srmio_pc_cmd_get_recint( srmio_pc_t conn, srmio_time_t *recint, srmio_error_t *err );
bool srmio_pc_cmd_clear( srmio_pc_t conn, srmio_error_t *err );
bool srmio_pc_set_xfer( srmio_pc_t conn, srmio_pc_xfer_type_t type, srmio_error_t *err );
bool srmio_pc_can_preview( srmio_pc_t conn );
typedef void (*srmio_progress_t)( size_t total, size_t done,
void *user_data );
bool srmio_pc_xfer_start( srmio_pc_t conn, srmio_error_t *err );
bool srmio_pc_xfer_get_blocks( srmio_pc_t conn, size_t *blocks, srmio_error_t *err );
bool srmio_pc_xfer_block_next( srmio_pc_t conn, srmio_pc_xfer_block_t block );
bool srmio_pc_xfer_chunk_next( srmio_pc_t conn, srmio_chunk_t chunk,
bool *is_intervall, bool *start_intervall );
bool srmio_pc_xfer_finish( srmio_pc_t conn, srmio_error_t *err );
srmio_pc_xfer_state_t srmio_pc_xfer_status( srmio_pc_t conn, srmio_error_t *err);
bool srmio_pc_xfer_block_progress( srmio_pc_t conn, size_t *block_done );
bool srmio_pc_xfer_all( srmio_pc_t conn,
srmio_data_t data,
srmio_progress_t pfunc, void *prog_data,
srmio_error_t *err );
/************************************************************
*
* from pc5.c
*
************************************************************/
srmio_pc_t srmio_pc5_new( srmio_error_t *err );
/************************************************************
*
* from pc7.c
*
************************************************************/
srmio_pc_t srmio_pc7_new( srmio_error_t *err );
# ifdef __cplusplus
}
# endif
#endif /* _SRMIO_H */