From ef919c4e36f059fed210bca921bf417334f438ff Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Nov 2012 22:08:43 +1100 Subject: [PATCH] AP_Param: fixed a bug with setting nested parameters This bug meant that setting a parameter in a parent class for a doubly nested parameter group, where the parameter index in the parent class is 4 or greater would actually set the first element in that parent class. At the moment only one parameter fits these narrow constraints - the RCn_DZ element of the RC_Channel_aux class. So if someone set RC5_DZ to 17 in ArduPlane it would actually set RC5_MIN to 17. --- libraries/AP_Common/AP_Param.cpp | 22 +++++++++++----------- libraries/AP_Common/AP_Param.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libraries/AP_Common/AP_Param.cpp b/libraries/AP_Common/AP_Param.cpp index 7e9a0d08276..8ecf67e7968 100644 --- a/libraries/AP_Common/AP_Param.cpp +++ b/libraries/AP_Common/AP_Param.cpp @@ -34,12 +34,12 @@ #define PGM_FLOAT(addr) pgm_read_float((const float *)addr) #define PGM_POINTER(addr) pgm_read_pointer((const void *)addr) -// the 'GROUP_ID' of a element of a group is the 8 bit identifier used -// to distinguish between this element of the group and other elements -// of the same group. It is calculated using a bit shift per level of -// nesting, so the first level of nesting gets 4 bits, and the next -// level gets the next 4 bits. This limits groups to having at most 16 -// elements. +// the 'GROUP_ID' of a element of a group is the 18 bit identifier +// used to distinguish between this element of the group and other +// elements of the same group. It is calculated using a bit shift per +// level of nesting, so the first level of nesting gets 6 bits the 2nd +// level gets the next 6 bits, and the 3rd level gets the last 6 +// bits. This limits groups to having at most 64 elements. #define GROUP_ID(grpinfo, base, i, shift) ((base)+(((uint16_t)PGM_UINT8(&grpinfo[i].idx))<<(shift))) // Note about AP_Vector3f handling. @@ -313,7 +313,7 @@ const struct AP_Param::Info *AP_Param::find_var_info_group(const struct GroupInf uint8_t vindex, uint8_t group_base, uint8_t group_shift, - uint8_t * group_element, + uint32_t * group_element, const struct GroupInfo **group_ret, uint8_t * idx) { @@ -364,7 +364,7 @@ const struct AP_Param::Info *AP_Param::find_var_info_group(const struct GroupInf } // find the info structure for a variable -const struct AP_Param::Info *AP_Param::find_var_info(uint8_t * group_element, +const struct AP_Param::Info *AP_Param::find_var_info(uint32_t * group_element, const struct GroupInfo ** group_ret, uint8_t * idx) { @@ -481,7 +481,7 @@ void AP_Param::add_vector3f_suffix(char *buffer, size_t buffer_size, uint8_t idx // void AP_Param::copy_name(char *buffer, size_t buffer_size, bool force_scalar) { - uint8_t group_element; + uint32_t group_element; const struct GroupInfo *ginfo; uint8_t idx; const struct AP_Param::Info *info = find_var_info(&group_element, &ginfo, &idx); @@ -599,7 +599,7 @@ AP_Param::find_by_index(uint16_t idx, enum ap_var_type *ptype) // bool AP_Param::save(void) { - uint8_t group_element = 0; + uint32_t group_element = 0; const struct GroupInfo *ginfo; uint8_t idx; const struct AP_Param::Info *info = find_var_info(&group_element, &ginfo, &idx); @@ -677,7 +677,7 @@ bool AP_Param::save(void) // bool AP_Param::load(void) { - uint8_t group_element = 0; + uint32_t group_element = 0; const struct GroupInfo *ginfo; uint8_t idx; const struct AP_Param::Info *info = find_var_info(&group_element, &ginfo, &idx); diff --git a/libraries/AP_Common/AP_Param.h b/libraries/AP_Common/AP_Param.h index 9b1379e415b..7e4d19228b1 100644 --- a/libraries/AP_Common/AP_Param.h +++ b/libraries/AP_Common/AP_Param.h @@ -243,11 +243,11 @@ private: uint8_t vindex, uint8_t group_base, uint8_t group_shift, - uint8_t * group_element, + uint32_t * group_element, const struct GroupInfo ** group_ret, uint8_t * idx); const struct Info * find_var_info( - uint8_t * group_element, + uint32_t * group_element, const struct GroupInfo ** group_ret, uint8_t * idx); static const struct Info * find_by_header_group(