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 <cstddef>
36 #include <cstdint>
37 
39 
40 namespace rosflight_firmware
41 {
42 
43 enum : uint16_t
44 {
45  /******************************/
46  /*** HARDWARE CONFIGURATION ***/
47  /******************************/
50 
51  /*****************************/
52  /*** MAVLINK CONFIGURATION ***/
53  /*****************************/
57 
66 
69 
70 
71  /********************************/
72  /*** CONTROLLER CONFIGURATION ***/
73  /********************************/
75 
79 
83 
87 
91 
95 
99 
101 
102  /*************************/
103  /*** PWM CONFIGURATION ***/
104  /*************************/
109 
110  /*******************************/
111  /*** ESTIMATOR CONFIGURATION ***/
112  /*******************************/
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  // keep track of size of params array
212 };
213 
214 typedef enum
215 {
219 } param_type_t;
220 
221 class ROSflight;
222 class Params
223 {
224 
225 public:
226  static constexpr uint8_t PARAMS_NAME_LENGTH = 16;
227 
228 private:
230  {
231  float fvalue;
232  int32_t ivalue;
233  };
234 
235  typedef struct
236  {
237  uint32_t version;
238  uint16_t size;
239  uint8_t magic_be; // magic number, should be 0xBE
240 
243  param_type_t types[PARAMS_COUNT];
244 
245  uint8_t magic_ef; // magic number, should be 0xEF
246  uint8_t chk; // XOR checksum
247  } params_t;
248 
251 
252  void init_param_int(uint16_t id, const char name[PARAMS_NAME_LENGTH], int32_t value);
253  void init_param_float(uint16_t id, const char name[PARAMS_NAME_LENGTH], float value);
254  uint8_t compute_checksum(void);
255 
258 
259 
260 public:
261  Params(ROSflight &_rf);
262 
263  // function declarations
264 
268  void init();
269 
273  void set_defaults(void);
274 
280  void set_listeners(ParamListenerInterface * const listeners[], size_t num_listeners);
281 
286  bool read(void);
287 
292  bool write(void);
293 
298  void change_callback(uint16_t id);
299 
305  uint16_t lookup_param_id(const char name[PARAMS_NAME_LENGTH]);
306 
312  inline int get_param_int(uint16_t id) const
313  {
314  return params.values[id].ivalue;
315  }
316 
322  inline float get_param_float(uint16_t id) const
323  {
324  return params.values[id].fvalue;
325  }
326 
332  inline const char *get_param_name(uint16_t id) const
333  {
334  return params.names[id];
335  }
336 
345  inline param_type_t get_param_type(uint16_t id) const
346  {
347  return params.types[id];
348  }
349 
356  bool set_param_int(uint16_t id, int32_t value);
357 
364  bool set_param_float(uint16_t id, float value);
365 
372  bool set_param_by_name_int(const char name[PARAMS_NAME_LENGTH], int32_t value);
373 
380  bool set_param_by_name_float(const char name[PARAMS_NAME_LENGTH], float value);
381 
382 };
383 
384 } // namespace rosflight_firmware
385 
386 #endif // ROSFLIGHT_FIRMWARE_PARAM_H
char names[PARAMS_COUNT][PARAMS_NAME_LENGTH]
Definition: param.h:242
uint16_t lookup_param_id(const char name[PARAMS_NAME_LENGTH])
Gets the id of a parameter from its name.
Definition: param.cpp:331
param_type_t types[PARAMS_COUNT]
Definition: param.h:243
void set_defaults(void)
Set all parameters to default values.
Definition: param.cpp:114
void change_callback(uint16_t id)
Callback for executing actions that need to be taken when a parameter value changes.
Definition: param.cpp:319
bool read(void)
Read parameter values from non-volatile memory.
Definition: param.cpp:289
void init_param_int(uint16_t id, const char name[PARAMS_NAME_LENGTH], int32_t value)
Definition: param.cpp:68
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:369
float get_param_float(uint16_t id) const
Get the value of a floating point parameter by id.
Definition: param.h:322
static constexpr uint8_t PARAMS_NAME_LENGTH
Definition: param.h:226
param_type_t get_param_type(uint16_t id) const
Get the type of a parameter.
Definition: param.h:345
void set_listeners(ParamListenerInterface *const listeners[], size_t num_listeners)
Specify listeners for parameter changes.
Definition: param.cpp:283
Params(ROSflight &_rf)
Definition: param.cpp:60
const char * get_param_name(uint16_t id) const
Get the name of a parameter.
Definition: param.h:332
int get_param_int(uint16_t id) const
Get the value of an integer parameter by id.
Definition: param.h:312
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:381
ParamListenerInterface *const * listeners_
Definition: param.h:256
void init_param_float(uint16_t id, const char name[PARAMS_NAME_LENGTH], float value)
Definition: param.cpp:77
void init()
Initialize parameter values.
Definition: param.cpp:103
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:387
uint8_t compute_checksum(void)
Definition: param.cpp:86
bool write(void)
Write current parameter values to non-volatile memory.
Definition: param.cpp:306
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:357
param_value_t values[PARAMS_COUNT]
Definition: param.h:241


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:19