mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-21 13:57:35 +08:00
systemlib: Implement active param list fully
This commit is contained in:
@@ -106,8 +106,6 @@ ORB_DEFINE(parameter_update, struct parameter_update_s);
|
||||
/** parameter update topic handle */
|
||||
static orb_advert_t param_topic = -1;
|
||||
|
||||
static bool param_used_internal(param_t param);
|
||||
|
||||
static void param_set_used_internal(param_t param);
|
||||
|
||||
static param_t param_find_internal(const char *name, bool notification);
|
||||
@@ -250,6 +248,20 @@ param_count(void)
|
||||
return param_info_count;
|
||||
}
|
||||
|
||||
unsigned
|
||||
param_count_used(void)
|
||||
{
|
||||
unsigned count = 0;
|
||||
for (unsigned i = 0; i < sizeof(param_changed_storage) / sizeof(param_changed_storage[0]); i++) {
|
||||
for (unsigned j = 0; j < 8; j++) {
|
||||
if (param_changed_storage[i] & (1 << j)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
param_t
|
||||
param_for_index(unsigned index)
|
||||
{
|
||||
@@ -268,6 +280,27 @@ param_get_index(param_t param)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
param_get_used_index(param_t param)
|
||||
{
|
||||
if (!handle_in_range(param)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* walk all params and count */
|
||||
int count = 0;
|
||||
|
||||
for (unsigned i = 0; i < (unsigned)param + 1; i++) {
|
||||
for (unsigned j = 0; j < 8; j++) {
|
||||
if (param_changed_storage[i] & (1 << j)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
const char *
|
||||
param_name(param_t param)
|
||||
{
|
||||
@@ -481,7 +514,8 @@ param_set_no_notification(param_t param, const void *val)
|
||||
return param_set_internal(param, val, false, false);
|
||||
}
|
||||
|
||||
bool param_used_internal(param_t param)
|
||||
bool
|
||||
param_used(param_t param)
|
||||
{
|
||||
int param_index = param_get_index(param);
|
||||
if (param_index < 0) {
|
||||
@@ -903,7 +937,7 @@ param_foreach(void (*func)(void *arg, param_t param), void *arg, bool only_chang
|
||||
continue;
|
||||
}
|
||||
|
||||
if (only_used && !param_used_internal(param)) {
|
||||
if (only_used && !param_used(param)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,20 @@ __EXPORT param_t param_find_no_notification(const char *name);
|
||||
*/
|
||||
__EXPORT unsigned param_count(void);
|
||||
|
||||
/**
|
||||
* Return the actually used number of parameters.
|
||||
*
|
||||
* @return The number of parameters.
|
||||
*/
|
||||
__EXPORT unsigned param_count_used(void);
|
||||
|
||||
/**
|
||||
* Wether a parameter is in use in the system.
|
||||
*
|
||||
* @return True if it has been written or read
|
||||
*/
|
||||
__EXPORT bool param_used(param_t param);
|
||||
|
||||
/**
|
||||
* Look up a parameter by index.
|
||||
*
|
||||
@@ -123,6 +137,14 @@ __EXPORT param_t param_for_index(unsigned index);
|
||||
*/
|
||||
__EXPORT int param_get_index(param_t param);
|
||||
|
||||
/**
|
||||
* Look up the index of an used parameter.
|
||||
*
|
||||
* @param param The parameter to obtain the index for.
|
||||
* @return The index of the parameter in use, or -1 if the parameter does not exist.
|
||||
*/
|
||||
__EXPORT int param_get_used_index(param_t param);
|
||||
|
||||
/**
|
||||
* Obtain the name of a parameter.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user