MAV'RIC
data_logging.h
1 /*******************************************************************************
2  * Copyright (c) 2009-2014, MAV'RIC Development Team
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  ******************************************************************************/
31 
32 /*******************************************************************************
33  * \file data_logging.h
34  *
35  * \author MAV'RIC Team
36  * \author Nicolas Dousse
37  *
38  * \brief Performs the data logging on the SD card
39  *
40  ******************************************************************************/
41 
42 
43 #ifndef DATA_LOGGING_H__
44 #define DATA_LOGGING_H__
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include "fat_fs/ff.h"
51 #include "tasks.h"
52 
53 
57 typedef struct
58 {
59  double* param_double;
60  double* param;
61  char param_name[MAVLINK_MSG_PARAM_SET_FIELD_PARAM_ID_LEN];
62  mavlink_message_type_t data_type;
64 
65 
72 typedef struct
73 {
74  uint32_t data_logging_count;
76  uint16_t max_logs;
77  uint16_t log_interval;
78  data_logging_entry_t data_log[];
80 
81 
85 typedef struct
86 {
88  uint16_t max_logs;
89  uint16_t log_interval;
90  bool debug;
91  uint32_t log_data;
93 
94 
101 typedef struct
102 {
103  bool debug;
105 
106  FRESULT fr;
109 
110  uint32_t time_ms;
111 
114 
115  char *file_name;
117 
118  bool file_init;
119  bool file_opened;
121  bool sys_mounted;
122 
123  uint32_t loop_count;
124 
125  uint32_t logging_time;
126 
127  uint32_t log_data;
128 
129  uint32_t sys_id;
130 
131  const state_t* state;
133 
134 
144 bool data_logging_init(data_logging_t* data_logging, const data_logging_conf_t* config, const state_t* state);
145 
155 bool data_logging_create_new_log_file(data_logging_t* data_logging, const char* file_name, uint32_t sysid);
156 
164 task_return_t data_logging_update(data_logging_t* data_logging);
165 
175 bool data_logging_add_parameter_uint8(data_logging_t* data_logging, uint8_t* val, const char* param_name);
176 
186 bool data_logging_add_parameter_int8(data_logging_t* data_logging, int8_t* val, const char* param_name);
187 
197 bool data_logging_add_parameter_uint16(data_logging_t* data_logging, uint16_t* val, const char* param_name);
198 
208 bool data_logging_add_parameter_int16(data_logging_t* data_logging, int16_t* val, const char* param_name);
209 
219 bool data_logging_add_parameter_uint32(data_logging_t* data_logging, uint32_t* val, const char* param_name);
220 
230 bool data_logging_add_parameter_int32(data_logging_t* data_logging, int32_t* val, const char* param_name);
231 
241 bool data_logging_add_parameter_uint64(data_logging_t* data_logging, uint64_t* val, const char* param_name);
242 
252 bool data_logging_add_parameter_int64(data_logging_t* data_logging, int64_t* val, const char* param_name);
253 
263 bool data_logging_add_parameter_float(data_logging_t* data_logging, float* val, const char* param_name);
264 
274 bool data_logging_add_parameter_double(data_logging_t* data_logging, double* val, const char* param_name);
275 
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif /* DATA_LOGGING_H__ */
int buffer_name_size
The buffer for the size of the file's name.
Definition: data_logging.h:112
uint16_t max_logs
The max number of logged files with the same name on the SD card.
Definition: data_logging.h:76
uint32_t loop_count
Counter to try to mount the SD card many times.
Definition: data_logging.h:123
FATFS fs
The fatfs handler.
Definition: data_logging.h:107
int buffer_add_size
The buffer for the size of the file's extension char*.
Definition: data_logging.h:113
bool file_init
A flag to tell whether a file is init or not.
Definition: data_logging.h:118
uint16_t log_interval
The time interval in sec.
Definition: data_logging.h:77
uint16_t max_logs
The max number of logged files with the same name on the SD card.
Definition: data_logging.h:88
File system object structure (FATFS)
Definition: ff.h:81
uint16_t log_interval
The time interval in sec.
Definition: data_logging.h:89
char * name_n_extension
Stores the name of the file.
Definition: data_logging.h:116
FRESULT fr
The result of the fatfs functions.
Definition: data_logging.h:106
bool debug
Indicates if debug messages should be printed for each param change.
Definition: data_logging.h:103
Set of data logging parameters.
Definition: data_logging.h:72
bool file_name_init
A flag to tell whether a valid name was proposed.
Definition: data_logging.h:120
uint32_t max_data_logging_count
Maximum number of parameters.
Definition: data_logging.h:87
uint32_t data_logging_count
Number of data logging parameter effectively in the array.
Definition: data_logging.h:74
const state_t * state
The pointer to the state structure.
Definition: data_logging.h:131
bool file_opened
A flag to tell whether a file is opened or not.
Definition: data_logging.h:119
bool debug
Indicates if debug messages should be printed for each param change.
Definition: data_logging.h:90
char * file_name
The file name.
Definition: data_logging.h:115
The state structure.
Definition: state.h:79
uint32_t max_data_logging_count
Maximum number of logged parameters.
Definition: data_logging.h:75
uint32_t logging_time
The time that we've passed logging since the last f_close.
Definition: data_logging.h:125
uint32_t log_data
A flag to stop/start writing to file.
Definition: data_logging.h:127
Configuration for the module data logging.
Definition: data_logging.h:85
data_logging_set_t * data_logging_set
Pointer to a set of parameters, needs memory allocation.
Definition: data_logging.h:104
uint32_t log_data
The initial state of writing a file.
Definition: data_logging.h:91
File object structure (FIL)
Definition: ff.h:119
mavlink_message_type_t data_type
Parameter type.
Definition: data_logging.h:62
Structure of data logging parameter.
Definition: data_logging.h:57
bool sys_mounted
A flag to tell whether the file system is mounted.
Definition: data_logging.h:121
uint32_t sys_id
the system ID
Definition: data_logging.h:129
FIL fil
The fatfs file handler.
Definition: data_logging.h:108
The structure to log the data.
Definition: data_logging.h:101
double * param_double
Pointer to the parameter value.
Definition: data_logging.h:59
uint32_t time_ms
The microcontroller time in ms.
Definition: data_logging.h:110