RC Pilot
log_manager.h
Go to the documentation of this file.
1 /**
2  * @file log_manager.h
3  *
4  * @brief Functions to start, stop, and interact with the log manager
5  * thread.
6  */
7 
8 #ifndef LOG_MANAGER_H
9 #define LOG_MANAGER_H
10 
11 
12 // to allow printf macros for multi-architecture portability
13 #define __STDC_FORMAT_MACROS
14 #include <inttypes.h>
15 
16 /**
17  * table of values to go into each log entry. It is structured this way so that
18  * it can be transformed into a struct or fprintf statement with macros.
19  */
20 #define LOG_TABLE \
21  X(uint64_t, "%" PRIu64, loop_index ) \
22  X(uint64_t, "%" PRIu64, last_step_ns ) \
23  \
24  X(double, "%f", altitude_kf ) \
25  X(double, "%f", altitude_bmp) \
26  X(double, "%f", roll ) \
27  X(double, "%f", pitch ) \
28  X(double, "%f", yaw ) \
29  \
30  X(double, "%f", Z_throttle_sp ) \
31  X(double, "%f", altitude_sp ) \
32  X(double, "%f", roll_sp ) \
33  X(double, "%f", pitch_sp ) \
34  X(double, "%f", yaw_sp ) \
35  \
36  X(double, "%f", u_X ) \
37  X(double, "%f", u_Y ) \
38  X(double, "%f", u_Z ) \
39  X(double, "%f", u_roll ) \
40  X(double, "%f", u_pitch ) \
41  X(double, "%f", u_yaw ) \
42  \
43  X(double, "%f", mot_1 ) \
44  X(double, "%f", mot_2 ) \
45  X(double, "%f", mot_3 ) \
46  X(double, "%f", mot_4 ) \
47  X(double, "%f", mot_5 ) \
48  X(double, "%f", mot_6 ) \
49  X(double, "%f", v_batt )
50 
51 
52 #define X(type, fmt, name) type name ;
53 /**
54  * Struct definition to contain a single line of the log. For each log entry you
55  * wish to create. Fill in an instance of this and pass to add_log_entry()
56  */
57 typedef struct log_entry_t { LOG_TABLE } log_entry_t;
58 #undef X
59 
60 
61 /**
62  * @brief creates a new csv log file and starts the background thread.
63  *
64  * Used in log_manager.c
65  *
66  * @return 0 on success, -1 on failure
67  */
68 int log_manager_init();
69 
70 /**
71  * @brief Write the contents of one entry to the console.
72  *
73  * Used in log_manager.c
74  *
75  * @param[in] entry The log_entry_t holding the LOG_TABLE to be printed.
76  *
77  * @return 0 on success, -1 on failure
78  */
79 int print_entry(log_entry_t entry);
80 
81 /**
82  * @brief quickly add new data to local buffer
83  *
84  * Used in log_manager.c
85  *
86  * @param[in] new_entry the log_entry_t to be written to the buffer
87  *
88  * @return 0 on success, -1 on failure
89  */
90 int add_log_entry(log_entry_t new_entry);
91 
92 /**
93  * @brief Finish writing remaining data to log and close thread.
94  *
95  * Used in log_manager.c
96  *
97  * @return 0 on sucess and clean exit, -1 on exit timeout/force close.
98  */
100 
101 #endif // LOG_MANAGER_H
int print_entry(log_entry_t entry)
Write the contents of one entry to the console.
Definition: log_manager.c:40
Definition: log_manager.h:57
int log_manager_init()
creates a new csv log file and starts the background thread.
Definition: log_manager.c:124
int add_log_entry(log_entry_t new_entry)
quickly add new data to local buffer
Definition: log_manager.c:50
#define LOG_TABLE
Definition: log_manager.h:20
struct log_entry_t log_entry_t
int log_manager_cleanup()
Finish writing remaining data to log and close thread.
Definition: log_manager.c:186