MAV'RIC
onboard_parameters.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 onboard_parameters.h
34  *
35  * \author MAV'RIC Team
36  * \author Julien Lecoeur
37  *
38  * \brief Onboard parameters
39  *
40  ******************************************************************************/
41 
42 
43 #ifndef ONBOARD_PARAMETERS_H_
44 #define ONBOARD_PARAMETERS_H_
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include "mavlink_stream.h"
51 #include "mavlink_message_handler.h"
52 #include "scheduler.h"
53 
54 #include <stdbool.h>
55 
56 #define MAX_ONBOARD_PARAM_COUNT 120 // should be < 122 to fit on user page on AT32UC3C1512
57 
58 #define MAVERIC_FLASHC_USER_PAGE_START_ADDRESS (AVR32_FLASHC_USER_PAGE_ADDRESS + 0x04) // +4bytes for unknown reason
59 #define MAVERIC_FLASHC_USER_PAGE_FREE_SPACE 500 // 512bytes user page,
60  // -4bytes at the start,
61  // -8bytes for the protected fuses at the end of the user page
62 
66 typedef struct
67 {
68  float* param;
69  char param_name[MAVLINK_MSG_PARAM_SET_FIELD_PARAM_ID_LEN];
70  mavlink_message_type_t data_type;
72  uint8_t param_id;
75 
76 
83 typedef struct
84 {
85  uint32_t param_count;
86  uint32_t max_param_count;
89 
90 
97 typedef struct
98 {
100  bool debug;
103 
104 
108 typedef struct
109 {
110  uint32_t max_param_count;
111  bool debug;
113 
114 
118 typedef struct
119 {
120  //float values[MAVERIC_FLASHC_USER_PAGE_FREE_SPACE];
121  float values[MAX_ONBOARD_PARAM_COUNT];
122 } nvram_data_t;
123 
124 
135 bool onboard_parameters_init(onboard_parameters_t* onboard_parameters, const onboard_parameters_conf_t* config, scheduler_t* scheduler, mavlink_message_handler_t* message_handler, const mavlink_stream_t* mavlink_stream);
136 
137 
147 bool onboard_parameters_add_parameter_uint32(onboard_parameters_t* onboard_parameters, uint32_t* val, const char* param_name);
148 
149 
159 bool onboard_parameters_add_parameter_int32(onboard_parameters_t* onboard_parameters, int32_t* val, const char* param_name);
160 
161 
171 bool onboard_parameters_add_parameter_float(onboard_parameters_t* onboard_parameters, float* val, const char* param_name);
172 
181 mav_result_t onboard_parameters_preflight_storage(onboard_parameters_t* onboard_parameters, mavlink_command_long_t* msg);
182 
190 bool onboard_parameters_read_parameters_from_flashc(onboard_parameters_t* onboard_parameters);
191 
192 
198 void onboard_parameters_write_parameters_to_flashc(onboard_parameters_t* onboard_parameters);
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif /* ONBOARD_PARAMETERS_H */
TODO: Modify the name of this structure to make it sized as the free flash memory to store these para...
Definition: onboard_parameters.h:118
const mavlink_stream_t * mavlink_stream
Pointer to mavlink_stream.
Definition: onboard_parameters.h:99
float * param
Pointer to the parameter value.
Definition: onboard_parameters.h:68
Structure of onboard parameter.
Definition: onboard_parameters.h:66
uint32_t max_param_count
Maximum number of parameters.
Definition: onboard_parameters.h:110
Scheduler.
Definition: scheduler.h:171
Set of onboard parameters.
Definition: onboard_parameters.h:83
uint8_t param_name_length
Length of the parameter name.
Definition: onboard_parameters.h:71
mavlink_message_type_t data_type
Parameter type.
Definition: onboard_parameters.h:70
uint32_t param_count
Number of onboard parameter effectively in the array.
Definition: onboard_parameters.h:85
onboard_parameters_set_t * param_set
Pointer to a set of parameters, needs memory allocation.
Definition: onboard_parameters.h:101
uint32_t max_param_count
Maximum number of parameters.
Definition: onboard_parameters.h:86
bool debug
Indicates if debug messages should be printed for each param change.
Definition: onboard_parameters.h:111
Main structure of the module onboard parameters.
Definition: onboard_parameters.h:97
bool debug
Indicates if debug messages should be printed for each param change.
Definition: onboard_parameters.h:100
Configuration for the module onboard parameters.
Definition: onboard_parameters.h:108
bool schedule_for_transmission
Boolean to activate the transmission of the parameter.
Definition: onboard_parameters.h:73
uint8_t param_id
Parameter ID.
Definition: onboard_parameters.h:72