From 54deb4cb36d171e8e3c672cdc6204f7b5eed84c6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 May 2020 19:35:20 +1000 Subject: [PATCH] AP_Param: added find_top_level_key_by_pointer --- libraries/AP_Param/AP_Param.cpp | 17 +++++++++++++++++ libraries/AP_Param/AP_Param.h | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/libraries/AP_Param/AP_Param.cpp b/libraries/AP_Param/AP_Param.cpp index 6e8588a739..0e3233ba23 100644 --- a/libraries/AP_Param/AP_Param.cpp +++ b/libraries/AP_Param/AP_Param.cpp @@ -962,6 +962,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. // diff --git a/libraries/AP_Param/AP_Param.h b/libraries/AP_Param/AP_Param.h index 2749f99175..e795da62ea 100644 --- a/libraries/AP_Param/AP_Param.h +++ b/libraries/AP_Param/AP_Param.h @@ -303,6 +303,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.