AP_Param: add method to find key of top level group variable by pointer

This commit is contained in:
Siddharth Purohit 2019-12-24 15:21:37 +08:00 committed by Randy Mackay
parent 8a7dcafa0f
commit 1d2985e967
2 changed files with 25 additions and 0 deletions

View File

@ -973,6 +973,23 @@ bool AP_Param::find_key_by_pointer(const void *ptr, uint16_t &key)
return false;
}
/*
Find key to top level group parameters by pointer
*/
bool AP_Param::find_top_level_key_by_pointer(const void *ptr, uint16_t &key)
{
for (uint16_t i=0; i<_num_vars; i++) {
if (_var_info[i].type != AP_PARAM_GROUP) {
continue;
}
if (ptr == (void **)_var_info[i].ptr) {
key = _var_info[i].key;
return true;
}
}
return false;
}
// Find a object by name.
//

View File

@ -323,6 +323,14 @@ public:
ptrdiff_t offset, uint16_t &key);
static bool find_key_by_pointer(const void *ptr, uint16_t &key);
/// Find key of top level group variable by pointer
///
///
/// @param p Pointer to variable
/// @return key for variable
static bool find_top_level_key_by_pointer(const void *ptr, uint16_t &key);
/// Find a object in the top level var_info table
///
/// If the variable has no name, it cannot be found by this interface.