-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlm_reader.h
368 lines (298 loc) · 8.8 KB
/
tlm_reader.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
/*
TLM reader library
Copyright (C) 2015 Hannes Diethelm
This file is part of tlm_reader
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TLM_READER_H_
#define TLM_READER_H_
#include <stdint.h>
#define TIMESTAMP_HEADER 0xFFFFFFFF
#define SIZE_HEADER 36
#define SIZE_DATA 20
/* Datatype of Block */
enum _data_type{
HEADER_MAIN = 0x100,
HEADER_AUX = 0x101,
CURRENT = 0x03,
POWERBOX = 0x0A,
AIRSPEED = 0x11,
ATLITUDE = 0x12,
ACCELLERATION = 0x14,
JET_CAT = 0x15,
GPS1 = 0x16,
GPS2 = 0x17,
VARIO = 0x40,
RPM_TEMP_VOLT_TM1000 = 0x7E,
RX_STAT_TM1000 = 0x7F,
RPM_TEMP_VOLT_TM1100 = 0xFE,
RX_STAT_TM1100 = 0xFF
};
typedef enum _data_type DATA_TYPE;
/* Header Blocks ---------------------------------------------------------- */
/* Not really a block, just used to access timestamp and type fields */
struct _block_common {
uint32_t timestamp;
uint8_t type[2];
};
typedef struct _block_common BLOCK_COMMON;
/* Model Type */
enum _model_type{
MODEL_FIXED = 0x00,
MODEL_HELICOPTER = 0x01,
MODEL_GLIDER = 0x02
};
typedef enum _model_type MODEL_TYPE;
/* Bind Info */
enum _bind_info{
BIND_DSM2_6000 = 0x01,
BIND_DSM2_8000 = 0x02,
BIND_DSMX_6000 = 0x03,
BIND_DSMX_8000 = 0x04,
};
typedef enum _bind_info BIND_INFO;
struct _block_header_main {
uint32_t timestamp;
uint8_t model_number;
uint8_t model_type;
uint8_t bind_info;
uint8_t unknown1[5];
uint8_t model_name[16];
uint8_t unknown2[4];
};
typedef struct _block_header_main BLOCK_HEADER_MAIN;
struct _decoded_header_main {
};
typedef struct _decoded_header_main DECODED_HEADER_MAIN;
/* Enabled Info */
enum _ena_info{
ENA_VOLT = 0x01,
ENA_TEMP = 0x02,
ENA_CURRENT = 0x03,
ENA_GPS = 0x16,
ENA_LAST = 0x17,
ENA_ATTITUDE = 0x18,
ENA_ACCELLERATION = 0x20,
ENA_RPM = 0x7E,
};
typedef enum _ena_info ENA_INFO;
struct _block_header_aux {
uint32_t timestamp;
uint8_t ena_info[2];
uint8_t unknown1[16];
uint8_t unknown2[14];
};
typedef struct _block_header_aux BLOCK_HEADER_AUX;
struct _decoded_header_aux {
};
typedef struct _decoded_header_aux DECODED_HEADER_AUX;
/* Data Blocks ---------------------------------------------------------- */
/* current ----------------------------------------------------- */
struct _block_current {
uint32_t timestamp;
uint8_t type;
uint8_t unused1;
int16_t current;
uint8_t unused2[12];
};
typedef struct _block_current BLOCK_CURRENT;
/* See: http://www.rcgroups.com/forums/showpost.php?p=24575795&postcount=53 */
#define DECODE_CURRENT_FACTOR 0.196791
struct _decoded_current {
float current; /* In A */
};
typedef struct _decoded_current DECODED_CURRENT;
/* powerbox ----------------------------------------------------- */
struct _block_powerbox {
uint32_t timestamp;
uint8_t type;
};
typedef struct _block_powerbox BLOCK_POWERBOX;
struct _decoded_powerbox {
};
typedef struct _decoded_powerbox DECODED_POWERBOX;
/* airspeed ----------------------------------------------------- */
struct _block_airspeed {
uint32_t timestamp;
uint8_t type;
};
typedef struct _block_airspeed BLOCK_AIRSPEED;
struct _decoded_airspeed {
};
typedef struct _decoded_airspeed DECODED_AIRSPEED;
/* altitude ----------------------------------------------------- */
struct _block_altitude {
uint32_t timestamp;
uint8_t type;
};
typedef struct _block_altitude BLOCK_ALTITUDE;
struct _decoded_altitude {
};
typedef struct _decoded_altitude DECODED_ALTITUDE;
/* acceleration -------------------------------------------------- */
struct _block_acceleration {
uint32_t timestamp;
uint8_t type;
};
typedef struct _block_acceleration BLOCK_ACCELLERATION;
struct _decoded_acceleration {
};
typedef struct _decoded_acceleration DECODED_ACCELLERATION;
/* jet_cat ------------------------------------------------------- */
struct _block_jet_cat {
uint32_t timestamp;
uint8_t type;
};
typedef struct _block_jet_cat BLOCK_JET_CAT;
struct _decoded_jet_cat {
};
typedef struct _decoded_jet_cat DECODED_JET_CAT;
/* gps ----------------------------------------------------- */
struct _block_gps1 {
uint32_t timestamp;
uint8_t type;
};
typedef struct _block_gps1 BLOCK_GPS1;
struct _decoded_gps1 {
};
typedef struct _decoded_gps1 DECODED_GPS1;
struct _block_gps2 {
uint32_t timestamp;
uint8_t type;
};
typedef struct _block_gps2 BLOCK_GPS2;
struct _decoded_gps2 {
};
typedef struct _decoded_gps2 DECODED_GPS2;
/* vario ----------------------------------------------------- */
struct _block_vario {
uint32_t timestamp;
uint8_t type;
};
typedef struct _block_vario BLOCK_VARIO;
struct _decoded_vario {
};
typedef struct _decoded_vario DECODED_VARIO;
/* rpm_volt_temp ----------------------------------------------------- */
struct _block_rpm_volt_temp {
uint32_t timestamp;
uint8_t type;
uint8_t unused1;
uint16_t rpm;
uint16_t volt;
uint16_t temp;
uint8_t unused2[8];
};
typedef struct _block_rpm_volt_temp BLOCK_RPM_TEMP_VOLT;
struct _decoded_rpm_volt_temp {
uint16_t rpm;
float volt;
float temp;
};
typedef struct _decoded_rpm_volt_temp DECODED_RPM_TEMP_VOLT;
/* rx_stat ----------------------------------------------------- */
struct _block_rx_stat {
uint32_t timestamp;
uint8_t type;
uint8_t unused1;
uint16_t a_fade;
uint16_t b_fade;
uint16_t l_fade;
uint16_t r_fade;
uint16_t frame_loss;
uint16_t hold;
uint16_t rx_volt;
};
typedef struct _block_rx_stat BLOCK_RX_STAT;
struct _decoded_rx_stat {
uint16_t a_fade;
uint16_t b_fade;
uint16_t l_fade;
uint16_t r_fade;
uint16_t frame_loss;
uint16_t hold;
float rx_volt;
};
typedef struct _decoded_rx_stat DECODED_RX_STAT;
/**
* Union for all data block types--------
*/
union _data_block{
BLOCK_COMMON common;
BLOCK_HEADER_MAIN header_main;
BLOCK_HEADER_AUX header_aux;
BLOCK_CURRENT current;
BLOCK_POWERBOX powerbox;
BLOCK_AIRSPEED airspeed;
BLOCK_ALTITUDE altitude;
BLOCK_ACCELLERATION acceleration;
BLOCK_JET_CAT jet_cat;
BLOCK_GPS1 gps1;
BLOCK_GPS2 gps2;
BLOCK_VARIO vario;
BLOCK_RPM_TEMP_VOLT rpm_volt_temp;
BLOCK_RX_STAT rx_stat;
};
typedef union _data_block DATA_BLOCK;
union _decoded_block{
DECODED_HEADER_MAIN header_main;
DECODED_HEADER_AUX header_aux;
DECODED_CURRENT current;
DECODED_POWERBOX powerbox;
DECODED_AIRSPEED airspeed;
DECODED_ALTITUDE altitude;
DECODED_ACCELLERATION acceleration;
DECODED_JET_CAT jet_cat;
DECODED_GPS1 gps1;
DECODED_GPS2 gps2;
DECODED_VARIO vario;
DECODED_RPM_TEMP_VOLT rpm_volt_temp;
DECODED_RX_STAT rx_stat;
};
typedef union _decoded_block DECODED_BLOCK;
/**
* Block structure
*/
struct _generic_block {
DATA_TYPE type;
DATA_BLOCK data;
size_t data_size;
DECODED_BLOCK decoded;
/* Linked list for blocks */
struct _generic_block *prev;
struct _generic_block *next;
};
typedef struct _generic_block GENERIC_BLOCK;
GENERIC_BLOCK *tlm_reader_read(void * log_data, size_t log_size);
void tlm_reader_decode_header(GENERIC_BLOCK * block);
void tlm_reader_decode_data(GENERIC_BLOCK * block);
void tlm_print_raw(GENERIC_BLOCK * block);
/* Byte swap unsigned short */
uint16_t swap_uint16( uint16_t val );
/* Byte swap short */
int16_t swap_int16( int16_t val );
/* Byte swap unsigned int */
uint32_t swap_uint32( uint32_t val );
/* Byte swap int */
int32_t swap_int32( int32_t val );
/* Where to print errors */
#define ERROR_FP stdout
/*#define ERROR_FP stderr*/
/* Type of error */
enum _error_type{
E_ERROR = 0x00,
E_WARNING = 0x01
};
typedef enum _error_type ERROR_TYPE;
#define error_handler(err, ...) _error_handler((err),__LINE__, __FILE__, __VA_ARGS__)
void _error_handler(ERROR_TYPE err, int line, const char *file, char* format, ...);
#endif /* TLM_READER_H_ */