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 
36 
37 #include <cstddef>
38 #include <cstdint>
39 
40 namespace rosflight_firmware
41 {
42 enum : uint16_t
43 {
44  /******************************/
45  /*** HARDWARE CONFIGURATION ***/
46  /******************************/
49 
50  /*****************************/
51  /*** MAVLINK CONFIGURATION ***/
52  /*****************************/
56 
66 
69 
70  /********************************/
71  /*** CONTROLLER CONFIGURATION ***/
72  /********************************/
74 
78 
82 
86 
90 
94 
98 
100 
101  /*************************/
102  /*** PWM CONFIGURATION ***/
103  /*************************/
108 
109  /*******************************/
110  /*** ESTIMATOR CONFIGURATION ***/
111  /*******************************/
117 
121 
123 
127 
137 
150 
153 
155 
156  /************************/
157  /*** RC CONFIGURATION ***/
158  /************************/
169 
174 
178 
185 
186  /***************************/
187  /*** FRAME CONFIGURATION ***/
188  /***************************/
190 
195 
199 
200  /********************/
201  /*** ARMING SETUP ***/
202  /********************/
204 
205  /************************/
206  /*** OFFBOARD CONTROL ***/
207  /************************/
209 
210  /***********************/
211  /*** BATTERY MONITOR ***/
212  /***********************/
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 public:
233  static constexpr uint8_t PARAMS_NAME_LENGTH = 16;
234 
235 private:
237  {
238  float fvalue;
239  int32_t ivalue;
240  };
241 
242  typedef struct
243  {
244  uint32_t version;
245  uint16_t size;
246  uint8_t magic_be; // magic number, should be 0xBE
247 
250  param_type_t types[PARAMS_COUNT];
251 
252  uint8_t magic_ef; // magic number, should be 0xEF
253  uint8_t chk; // XOR checksum
254  } params_t;
255 
258 
259  void init_param_int(uint16_t id, const char name[PARAMS_NAME_LENGTH], int32_t value);
260  void init_param_float(uint16_t id, const char name[PARAMS_NAME_LENGTH], float value);
261  uint8_t compute_checksum(void);
262 
265 
266 public:
267  Params(ROSflight &_rf);
268 
269  // function declarations
270 
274  void init();
275 
279  void set_defaults(void);
280 
287  void set_listeners(ParamListenerInterface *const listeners[], size_t num_listeners);
288 
293  bool read(void);
294 
299  bool write(void);
300 
305  void change_callback(uint16_t id);
306 
312  uint16_t lookup_param_id(const char name[PARAMS_NAME_LENGTH]);
313 
319  inline int get_param_int(uint16_t id) const { return params.values[id].ivalue; }
320 
326  inline float get_param_float(uint16_t id) const { return params.values[id].fvalue; }
327 
333  inline const char *get_param_name(uint16_t id) const { return params.names[id]; }
334 
343  inline param_type_t get_param_type(uint16_t id) const { return params.types[id]; }
344 
351  bool set_param_int(uint16_t id, int32_t value);
352 
359  bool set_param_float(uint16_t id, float value);
360 
367  bool set_param_by_name_int(const char name[PARAMS_NAME_LENGTH], int32_t value);
368 
376  bool set_param_by_name_float(const char name[PARAMS_NAME_LENGTH], float value);
377 };
378 
379 } // namespace rosflight_firmware
380 
381 #endif // ROSFLIGHT_FIRMWARE_PARAM_H
char names[PARAMS_COUNT][PARAMS_NAME_LENGTH]
Definition: param.h:249
uint16_t lookup_param_id(const char name[PARAMS_NAME_LENGTH])
Gets the id of a parameter from its name.
Definition: param.cpp:340
param_type_t types[PARAMS_COUNT]
Definition: param.h:250
void set_defaults(void)
Set all parameters to default values.
Definition: param.cpp:112
void change_callback(uint16_t id)
Callback for executing actions that need to be taken when a parameter value changes.
Definition: param.cpp:328
bool read(void)
Read parameter values from non-volatile memory.
Definition: param.cpp:298
void init_param_int(uint16_t id, const char name[PARAMS_NAME_LENGTH], int32_t value)
Definition: param.cpp:62
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:378
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:233
param_type_t get_param_type(uint16_t id) const
Get the type of a parameter.
Definition: param.h:343
void set_listeners(ParamListenerInterface *const listeners[], size_t num_listeners)
Specify listeners for parameter changes.
Definition: param.cpp:292
Params(ROSflight &_rf)
Definition: param.cpp:59
const char * get_param_name(uint16_t id) const
Get the name of a parameter.
Definition: param.h:333
int get_param_int(uint16_t id) const
Get the value of an integer parameter by id.
Definition: param.h:319
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:390
ParamListenerInterface *const * listeners_
Definition: param.h:263
void init_param_float(uint16_t id, const char name[PARAMS_NAME_LENGTH], float value)
Definition: param.cpp:71
void init()
Initialize parameter values.
Definition: param.cpp:99
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:396
uint8_t compute_checksum(void)
Definition: param.cpp:80
bool write(void)
Write current parameter values to non-volatile memory.
Definition: param.cpp:315
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:366
param_value_t values[PARAMS_COUNT]
Definition: param.h:248


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Sat May 9 2020 03:16:53