Browse Source

uncrustify libraries/AP_Common/AP_Param.h with fixups by hand

master
Pat Hickey 13 years ago
parent
commit
42e24a869f
  1. 121
      libraries/AP_Common/AP_Param.h

121
libraries/AP_Common/AP_Param.h

@ -28,14 +28,14 @@ @@ -28,14 +28,14 @@
#define AP_VAROFFSET(type, element) (((uintptr_t)(&((const type *)1)->element))-1)
// find the type of a variable given the class and element
#define AP_CLASSTYPE(class, element) (((const class *)1)->element.vtype)
#define AP_CLASSTYPE(class, element) (((const class *) 1)->element.vtype)
// declare a group var_info line
#define AP_GROUPINFO(name, idx, class, element, def) { AP_CLASSTYPE(class, element), idx, name, AP_VAROFFSET(class, element), {def_value:def} }
#define AP_GROUPINFO(name, idx, class, element, def) { AP_CLASSTYPE(class, element), idx, name, AP_VAROFFSET(class, element), {def_value : def} }
// declare a nested group entry in a group var_info
#ifdef AP_NESTED_GROUPS_ENABLED
#define AP_NESTEDGROUPINFO(class, idx) { AP_PARAM_GROUP, idx, "", 0, { group_info: class::var_info } }
#define AP_NESTEDGROUPINFO(class, idx) { AP_PARAM_GROUP, idx, "", 0, { group_info : class::var_info } }
#endif
#define AP_GROUPEND { AP_PARAM_NONE, 0xFF, "", 0, { group_info : NULL } }
@ -96,19 +96,21 @@ public: @@ -96,19 +96,21 @@ public:
}
// empty constructor for child classes
AP_Param() {}
AP_Param() {
}
// a token used for first()/next() state
typedef struct {
uint32_t key:8;
uint32_t idx:6; // offset into array types
uint32_t group_element:18;
uint32_t key : 8;
uint32_t idx : 6; // offset into array types
uint32_t group_element : 18;
} ParamToken;
// return true if AP_Param has been initialised via setup()
static bool initialised(void);
/// Copy the variable's name, prefixed by any containing group name, to a buffer.
/// Copy the variable's name, prefixed by any containing group name, to a
/// buffer.
///
/// If the variable has no name, the buffer will contain an empty string.
///
@ -128,7 +130,7 @@ public: @@ -128,7 +130,7 @@ public:
/// @return A pointer to the variable, or NULL if
/// it does not exist.
///
static AP_Param *find(const char *name, enum ap_var_type *ptype);
static AP_Param * find(const char *name, enum ap_var_type *ptype);
/// Save the current value of the variable to EEPROM.
///
@ -173,15 +175,15 @@ public: @@ -173,15 +175,15 @@ public:
/// @return The first variable in _var_info, or NULL if
/// there are none.
///
static AP_Param *first(ParamToken *token, enum ap_var_type *ptype);
static AP_Param * first(ParamToken *token, enum ap_var_type *ptype);
/// Returns the next variable in _var_info, recursing into groups
/// as needed
static AP_Param *next(ParamToken *token, enum ap_var_type *ptype);
static AP_Param * next(ParamToken *token, enum ap_var_type *ptype);
/// Returns the next scalar variable in _var_info, recursing into groups
/// as needed
static AP_Param *next_scalar(ParamToken *token, enum ap_var_type *ptype);
static AP_Param * next_scalar(ParamToken *token, enum ap_var_type *ptype);
/// cast a variable to a float given its type
float cast_to_float(enum ap_var_type type);
@ -199,21 +201,21 @@ private: @@ -199,21 +201,21 @@ private:
};
/* This header is prepended to a variable stored in EEPROM.
The meaning is as follows:
- key: the k_param enum value from Parameter.h in the sketch
- group_element: This is zero for top level parameters. For
parameters stored within an object this is divided
into 3 lots of 6 bits, allowing for three levels
of object to be stored in the eeprom
- type: the ap_var_type value for the variable
*/
* The meaning is as follows:
*
* - key: the k_param enum value from Parameter.h in the sketch
*
* - group_element: This is zero for top level parameters. For
* parameters stored within an object this is divided
* into 3 lots of 6 bits, allowing for three levels
* of object to be stored in the eeprom
*
* - type: the ap_var_type value for the variable
*/
struct Param_header {
uint32_t key:8;
uint32_t type:6;
uint32_t group_element:18;
uint32_t key : 8;
uint32_t type : 6;
uint32_t group_element : 18;
};
// number of bits in each level of nesting of groups
@ -227,29 +229,48 @@ private: @@ -227,29 +229,48 @@ private:
static bool check_group_info(const struct GroupInfo *group_info, uint16_t *total_size, uint8_t max_bits);
static bool duplicate_key(uint8_t vindex, uint8_t key);
static bool check_var_info(void);
const struct Info *find_var_info_group(const struct GroupInfo *group_info,
const struct Info * find_var_info_group(
const struct GroupInfo * group_info,
uint8_t vindex,
uint8_t group_base,
uint8_t group_shift,
uint8_t *group_element,
const struct GroupInfo **group_ret,
uint8_t *idx);
const struct Info *find_var_info(uint8_t *group_element,
const struct GroupInfo **group_ret,
uint8_t *idx);
static const struct Info *find_by_header_group(struct Param_header phdr, void **ptr,
uint8_t * group_element,
const struct GroupInfo ** group_ret,
uint8_t * idx);
const struct Info * find_var_info(
uint8_t * group_element,
const struct GroupInfo ** group_ret,
uint8_t * idx);
static const struct Info * find_by_header_group(
struct Param_header phdr, void **ptr,
uint8_t vindex,
const struct GroupInfo *group_info,
uint8_t group_base,
uint8_t group_shift);
static const struct Info *find_by_header(struct Param_header phdr, void **ptr);
void add_vector3f_suffix(char *buffer, size_t buffer_size, uint8_t idx);
static AP_Param *find_group(const char *name, uint8_t vindex, const struct GroupInfo *group_info, enum ap_var_type *ptype);
static const struct Info * find_by_header(
struct Param_header phdr,
void **ptr);
void add_vector3f_suffix(
char *buffer,
size_t buffer_size,
uint8_t idx);
static AP_Param * find_group(
const char *name,
uint8_t vindex,
const struct GroupInfo *group_info,
enum ap_var_type *ptype);
static void write_sentinal(uint16_t ofs);
bool scan(const struct Param_header *phdr, uint16_t *pofs);
bool scan(
const struct Param_header *phdr,
uint16_t *pofs);
static const uint8_t type_size(enum ap_var_type type);
static void eeprom_write_check(const void *ptr, uint16_t ofs, uint8_t size);
static AP_Param *next_group(uint8_t vindex, const struct GroupInfo *group_info,
static void eeprom_write_check(
const void *ptr,
uint16_t ofs,
uint8_t size);
static AP_Param * next_group(
uint8_t vindex,
const struct GroupInfo *group_info,
bool *found_current,
uint8_t group_base,
uint8_t group_shift,
@ -258,7 +279,7 @@ private: @@ -258,7 +279,7 @@ private:
static uint16_t _eeprom_size;
static uint8_t _num_vars;
static const struct Info *_var_info;
static const struct Info * _var_info;
// values filled into the EEPROM header
static const uint8_t k_EEPROM_magic0 = 0x50;
@ -322,13 +343,13 @@ public: @@ -322,13 +343,13 @@ public:
/// Copy assignment from self does nothing.
///
AP_ParamT<T,PT>& operator=(AP_ParamT<T,PT>& v) {
AP_ParamT<T,PT>& operator= (AP_ParamT<T,PT>& v) {
return v;
}
/// Copy assignment from T is equivalent to ::set.
///
AP_ParamT<T,PT>& operator=(T v) {
AP_ParamT<T,PT>& operator= (T v) {
_value = v;
return *this;
}
@ -388,13 +409,13 @@ public: @@ -388,13 +409,13 @@ public:
/// Copy assignment from self does nothing.
///
AP_ParamV<T,PT>& operator=(AP_ParamV<T,PT>& v) {
AP_ParamV<T,PT>& operator =(AP_ParamV<T,PT>& v) {
return v;
}
/// Copy assignment from T is equivalent to ::set.
///
AP_ParamV<T,PT>& operator=(T v) {
AP_ParamV<T,PT>& operator =(T v) {
_value = v;
return *this;
}
@ -424,7 +445,7 @@ public: @@ -424,7 +445,7 @@ public:
///
/// @note It would be nice to range-check i here, but then what would we return?
///
T &operator [](uint8_t i) {
T & operator[](uint8_t i) {
return _value[i];
}
@ -452,7 +473,7 @@ public: @@ -452,7 +473,7 @@ public:
/// Copy assignment from self does nothing.
///
AP_ParamA<T,N,PT>& operator=(AP_ParamA<T,N,PT>& v) {
AP_ParamA<T,N,PT>& operator= (AP_ParamA<T,N,PT>& v) {
return v;
}
@ -468,7 +489,7 @@ protected: @@ -468,7 +489,7 @@ protected:
// _t is the base type
// _suffix is the suffix on the AP_* type name
// _pt is the enum ap_var_type type
#define AP_PARAMDEF(_t, _suffix, _pt) typedef AP_ParamT<_t, _pt> AP_##_suffix;
#define AP_PARAMDEF(_t, _suffix, _pt) typedef AP_ParamT<_t, _pt> AP_ ## _suffix;
AP_PARAMDEF(float, Float, AP_PARAM_FLOAT); // defines AP_Float
AP_PARAMDEF(int8_t, Int8, AP_PARAM_INT8); // defines AP_Int8
AP_PARAMDEF(int16_t, Int16, AP_PARAM_INT16); // defines AP_Int16
@ -479,7 +500,7 @@ AP_PARAMDEF(int32_t, Int32, AP_PARAM_INT32); // defines AP_Int32 @@ -479,7 +500,7 @@ AP_PARAMDEF(int32_t, Int32, AP_PARAM_INT32); // defines AP_Int32
// _suffix is the suffix on the AP_* type name
// _size is the size of the array
// _pt is the enum ap_var_type type
#define AP_PARAMDEFA(_t, _suffix, _size, _pt) typedef AP_ParamA<_t, _size, _pt> AP_##_suffix;
#define AP_PARAMDEFA(_t, _suffix, _size, _pt) typedef AP_ParamA<_t, _size, _pt> AP_ ## _suffix;
AP_PARAMDEFA(float, Vector6f, 6, AP_PARAM_VECTOR6F);
// declare a non-scalar type
@ -487,7 +508,7 @@ AP_PARAMDEFA(float, Vector6f, 6, AP_PARAM_VECTOR6F); @@ -487,7 +508,7 @@ AP_PARAMDEFA(float, Vector6f, 6, AP_PARAM_VECTOR6F);
// _t is the base type
// _suffix is the suffix on the AP_* type name
// _pt is the enum ap_var_type type
#define AP_PARAMDEFV(_t, _suffix, _pt) typedef AP_ParamV<_t, _pt> AP_##_suffix;
#define AP_PARAMDEFV(_t, _suffix, _pt) typedef AP_ParamV<_t, _pt> AP_ ## _suffix;
/// Rely on built in casting for other variable types
/// to minimize template creation and save memory

Loading…
Cancel
Save