param.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson and Daniel Koch, BYU MAGICC Lab
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef ROSFLIGHT_FIRMWARE_PARAM_H
33 #define ROSFLIGHT_FIRMWARE_PARAM_H
34 
35 #include <stdbool.h>
36 #include <stdint.h>
37 #include <functional>
38 
39 #ifndef GIT_VERSION_HASH
40 #define GIT_VERSION_HASH 0x00
41 #pragma message "GIT_VERSION_HASH Undefined, setting to 0x00!"
42 #endif
43 
44 #ifndef GIT_VERSION_STRING
45 #define GIT_VERSION_STRING "empty"
46 #endif
47 
48 namespace rosflight_firmware
49 {
50 
51 enum : uint16_t
52 {
53  /******************************/
54  /*** HARDWARE CONFIGURATION ***/
55  /******************************/
58 
59  /*****************************/
60  /*** MAVLINK CONFIGURATION ***/
61  /*****************************/
65 
74 
77 
78 
79  /********************************/
80  /*** CONTROLLER CONFIGURATION ***/
81  /********************************/
83 
87 
91 
95 
99 
103 
107 
109 
110  /*************************/
111  /*** PWM CONFIGURATION ***/
112  /*************************/
117 
118  /*******************************/
119  /*** ESTIMATOR CONFIGURATION ***/
120  /*******************************/
125 
129 
131 
135 
145 
158 
161 
163 
164  /************************/
165  /*** RC CONFIGURATION ***/
166  /************************/
177 
182 
186 
193 
194  /***************************/
195  /*** FRAME CONFIGURATION ***/
196  /***************************/
198 
203 
207 
208  /********************/
209  /*** ARMING SETUP ***/
210  /********************/
212 
213  /************************/
214  /*** OFFBOARD CONTROL ***/
215  /************************/
217 
218  // keep track of size of params array
220 };
221 
222 typedef enum
223 {
227 } param_type_t;
228 
229 class ROSflight;
230 class Params
231 {
232 
233 public:
234  static constexpr uint8_t PARAMS_NAME_LENGTH = 16;
235 
236 private:
238  {
239  float fvalue;
240  int32_t ivalue;
241  };
242 
243  typedef struct
244  {
245  uint32_t version;
246  uint16_t size;
247  uint8_t magic_be; // magic number, should be 0xBE
248 
251  param_type_t types[PARAMS_COUNT];
252 
253  uint8_t magic_ef; // magic number, should be 0xEF
254  uint8_t chk; // XOR checksum
255  } params_t;
256 
257  std::function<void(int)> callbacks[PARAMS_COUNT]; // Param change callbacks
258 
261 
262  void init_param_int(uint16_t id, const char name[PARAMS_NAME_LENGTH], int32_t value);
263  void init_param_float(uint16_t id, const char name[PARAMS_NAME_LENGTH], float value);
264  uint8_t compute_checksum(void);
265 
266 
267 public:
268  Params(ROSflight &_rf);
269 
270  void add_callback(std::function<void(int)> callback, uint16_t param_id);
271 
272 
273 
274  // function declarations
275 
279  void init();
280 
284  void set_defaults(void);
285 
290  bool read(void);
291 
296  bool write(void);
297 
302  void change_callback(uint16_t id);
303 
309  uint16_t lookup_param_id(const char name[PARAMS_NAME_LENGTH]);
310 
316  inline int get_param_int(uint16_t id) const
317  {
318  return params.values[id].ivalue;
319  }
320 
326  inline float get_param_float(uint16_t id) const
327  {
328  return params.values[id].fvalue;
329  }
330 
336  inline const char *get_param_name(uint16_t id) const
337  {
338  return params.names[id];
339  }
340 
349  inline param_type_t get_param_type(uint16_t id) const
350  {
351  return params.types[id];
352  }
353 
360  bool set_param_int(uint16_t id, int32_t value);
361 
368  bool set_param_float(uint16_t id, float value);
369 
376  bool set_param_by_name_int(const char name[PARAMS_NAME_LENGTH], int32_t value);
377 
384  bool set_param_by_name_float(const char name[PARAMS_NAME_LENGTH], float value);
385 
386 };
387 
388 } // namespace rosflight_firmware
389 
390 #endif // ROSFLIGHT_FIRMWARE_PARAM_H
char names[PARAMS_COUNT][PARAMS_NAME_LENGTH]
Definition: param.h:250
uint16_t lookup_param_id(const char name[PARAMS_NAME_LENGTH])
Gets the id of a parameter from its name.
Definition: param.cpp:351
param_type_t types[PARAMS_COUNT]
Definition: param.h:251
void set_defaults(void)
Set all parameters to default values.
Definition: param.cpp:100
void change_callback(uint16_t id)
Callback for executing actions that need to be taken when a parameter value changes.
Definition: param.cpp:344
bool read(void)
Read parameter values from non-volatile memory.
Definition: param.cpp:314
void init_param_int(uint16_t id, const char name[PARAMS_NAME_LENGTH], int32_t value)
Definition: param.cpp:56
bool set_param_float(uint16_t id, float value)
Sets the value of a floating point parameter by ID and calls the parameter callback.
Definition: param.cpp:389
float get_param_float(uint16_t id) const
Get the value of a floating point parameter by id.
Definition: param.h:326
static constexpr uint8_t PARAMS_NAME_LENGTH
Definition: param.h:234
param_type_t get_param_type(uint16_t id) const
Get the type of a parameter.
Definition: param.h:349
void add_callback(std::function< void(int)> callback, uint16_t param_id)
Definition: param.cpp:308
Params(ROSflight &_rf)
Definition: param.cpp:48
const char * get_param_name(uint16_t id) const
Get the name of a parameter.
Definition: param.h:336
int get_param_int(uint16_t id) const
Get the value of an integer parameter by id.
Definition: param.h:316
bool set_param_by_name_int(const char name[PARAMS_NAME_LENGTH], int32_t value)
Sets the value of a parameter by name and calls the parameter change callback.
Definition: param.cpp:401
void init_param_float(uint16_t id, const char name[PARAMS_NAME_LENGTH], float value)
Definition: param.cpp:63
void init()
Initialize parameter values.
Definition: param.cpp:90
bool set_param_by_name_float(const char name[PARAMS_NAME_LENGTH], float value)
Sets the value of a floating point parameter by name and calls the parameter change callback...
Definition: param.cpp:407
uint8_t compute_checksum(void)
Definition: param.cpp:70
bool write(void)
Write current parameter values to non-volatile memory.
Definition: param.cpp:331
bool set_param_int(uint16_t id, int32_t value)
Sets the value of a parameter by ID and calls the parameter change callback.
Definition: param.cpp:377
std::function< void(int)> callbacks[PARAMS_COUNT]
Definition: param.h:257
param_value_t values[PARAMS_COUNT]
Definition: param.h:249


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:25