mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-11 18:38:28 -04:00
AP_Param: added ParamToken type for variable list traversal
This commit is contained in:
parent
230d2300ae
commit
f30c721886
@ -575,9 +575,10 @@ bool AP_Param::load_all(void)
|
|||||||
|
|
||||||
|
|
||||||
// return the first variable in _var_info
|
// return the first variable in _var_info
|
||||||
AP_Param *AP_Param::first(uint16_t *token, enum ap_var_type *ptype)
|
AP_Param *AP_Param::first(ParamToken *token, enum ap_var_type *ptype)
|
||||||
{
|
{
|
||||||
*token = 0;
|
token->key = 0;
|
||||||
|
token->group_element = 0;
|
||||||
if (_num_vars == 0) {
|
if (_num_vars == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -593,7 +594,7 @@ AP_Param *AP_Param::next_group(uint8_t vindex, const struct GroupInfo *group_inf
|
|||||||
bool *found_current,
|
bool *found_current,
|
||||||
uint8_t group_base,
|
uint8_t group_base,
|
||||||
uint8_t group_shift,
|
uint8_t group_shift,
|
||||||
uint16_t *token,
|
ParamToken *token,
|
||||||
enum ap_var_type *ptype)
|
enum ap_var_type *ptype)
|
||||||
{
|
{
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
@ -612,13 +613,14 @@ AP_Param *AP_Param::next_group(uint8_t vindex, const struct GroupInfo *group_inf
|
|||||||
} else {
|
} else {
|
||||||
if (*found_current) {
|
if (*found_current) {
|
||||||
// got a new one
|
// got a new one
|
||||||
(*token) = ((uint16_t)GROUP_ID(group_info, group_base, i, group_shift)<<8) | vindex;
|
token->key = vindex;
|
||||||
|
token->group_element = GROUP_ID(group_info, group_base, i, group_shift);
|
||||||
if (ptype != NULL) {
|
if (ptype != NULL) {
|
||||||
*ptype = (enum ap_var_type)type;
|
*ptype = (enum ap_var_type)type;
|
||||||
}
|
}
|
||||||
return (AP_Param*)(PGM_POINTER(&_var_info[vindex].ptr) + PGM_UINT16(&group_info[i].offset));
|
return (AP_Param*)(PGM_POINTER(&_var_info[vindex].ptr) + PGM_UINT16(&group_info[i].offset));
|
||||||
}
|
}
|
||||||
if (GROUP_ID(group_info, group_base, i, group_shift) == (uint8_t)((*token)>>8)) {
|
if (GROUP_ID(group_info, group_base, i, group_shift) == token->group_element) {
|
||||||
*found_current = true;
|
*found_current = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -628,9 +630,9 @@ AP_Param *AP_Param::next_group(uint8_t vindex, const struct GroupInfo *group_inf
|
|||||||
|
|
||||||
/// Returns the next variable in _var_info, recursing into groups
|
/// Returns the next variable in _var_info, recursing into groups
|
||||||
/// as needed
|
/// as needed
|
||||||
AP_Param *AP_Param::next(uint16_t *token, enum ap_var_type *ptype)
|
AP_Param *AP_Param::next(ParamToken *token, enum ap_var_type *ptype)
|
||||||
{
|
{
|
||||||
uint8_t i = (*token)&0xFF;
|
uint8_t i = token->key;
|
||||||
bool found_current = false;
|
bool found_current = false;
|
||||||
if (i >= _num_vars) {
|
if (i >= _num_vars) {
|
||||||
// illegal token
|
// illegal token
|
||||||
@ -651,7 +653,8 @@ AP_Param *AP_Param::next(uint16_t *token, enum ap_var_type *ptype)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// found the next one
|
// found the next one
|
||||||
(*token) = i;
|
token->key = i;
|
||||||
|
token->group_element = 0;
|
||||||
if (ptype != NULL) {
|
if (ptype != NULL) {
|
||||||
*ptype = (enum ap_var_type)type;
|
*ptype = (enum ap_var_type)type;
|
||||||
}
|
}
|
||||||
@ -663,7 +666,7 @@ AP_Param *AP_Param::next(uint16_t *token, enum ap_var_type *ptype)
|
|||||||
|
|
||||||
/// Returns the next scalar in _var_info, recursing into groups
|
/// Returns the next scalar in _var_info, recursing into groups
|
||||||
/// as needed
|
/// as needed
|
||||||
AP_Param *AP_Param::next_scalar(uint16_t *token, enum ap_var_type *ptype)
|
AP_Param *AP_Param::next_scalar(ParamToken *token, enum ap_var_type *ptype)
|
||||||
{
|
{
|
||||||
AP_Param *ap;
|
AP_Param *ap;
|
||||||
enum ap_var_type type;
|
enum ap_var_type type;
|
||||||
@ -696,7 +699,7 @@ float AP_Param::cast_to_float(enum ap_var_type type)
|
|||||||
// print the value of all variables
|
// print the value of all variables
|
||||||
void AP_Param::show_all(void)
|
void AP_Param::show_all(void)
|
||||||
{
|
{
|
||||||
uint16_t token;
|
ParamToken token;
|
||||||
AP_Param *ap;
|
AP_Param *ap;
|
||||||
enum ap_var_type type;
|
enum ap_var_type type;
|
||||||
|
|
||||||
|
@ -74,6 +74,12 @@ public:
|
|||||||
const struct GroupInfo *group_info;
|
const struct GroupInfo *group_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// a token used for first()/next() state
|
||||||
|
typedef struct {
|
||||||
|
uint8_t key;
|
||||||
|
uint8_t group_element;
|
||||||
|
} ParamToken;
|
||||||
|
|
||||||
// called once at startup to setup the _var_info[] table. This
|
// called once at startup to setup the _var_info[] table. This
|
||||||
// will also check the EEPROM header and re-initialise it if the
|
// will also check the EEPROM header and re-initialise it if the
|
||||||
// wrong version is found
|
// wrong version is found
|
||||||
@ -138,15 +144,15 @@ public:
|
|||||||
/// @return The first variable in _var_info, or NULL if
|
/// @return The first variable in _var_info, or NULL if
|
||||||
/// there are none.
|
/// there are none.
|
||||||
///
|
///
|
||||||
static AP_Param *first(uint16_t *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
|
/// Returns the next variable in _var_info, recursing into groups
|
||||||
/// as needed
|
/// as needed
|
||||||
static AP_Param *next(uint16_t *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
|
/// Returns the next scalar variable in _var_info, recursing into groups
|
||||||
/// as needed
|
/// as needed
|
||||||
static AP_Param *next_scalar(uint16_t *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
|
/// cast a variable to a float given its type
|
||||||
float cast_to_float(enum ap_var_type type);
|
float cast_to_float(enum ap_var_type type);
|
||||||
@ -203,7 +209,7 @@ private:
|
|||||||
bool *found_current,
|
bool *found_current,
|
||||||
uint8_t group_base,
|
uint8_t group_base,
|
||||||
uint8_t group_shift,
|
uint8_t group_shift,
|
||||||
uint16_t *token,
|
ParamToken *token,
|
||||||
enum ap_var_type *ptype);
|
enum ap_var_type *ptype);
|
||||||
|
|
||||||
static uint16_t _eeprom_size;
|
static uint16_t _eeprom_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user