aboutsummaryrefslogtreecommitdiff
path: root/src/modules/systemlib
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2015-03-22 23:15:59 -0700
committerLorenz Meier <lm@inf.ethz.ch>2015-03-28 13:07:01 -0700
commitd6f7c9b8b4a9531aa77c65e106093380e3300d07 (patch)
treee93ad6132d395c382005ef8f43992a0fbfb821fb /src/modules/systemlib
parentfe12bffefaf1731464cb4e0be1892c3f300abb6b (diff)
downloadpx4-firmware-d6f7c9b8b4a9531aa77c65e106093380e3300d07.tar.gz
px4-firmware-d6f7c9b8b4a9531aa77c65e106093380e3300d07.tar.bz2
px4-firmware-d6f7c9b8b4a9531aa77c65e106093380e3300d07.zip
systemlib: Implement active param list fully
Diffstat (limited to 'src/modules/systemlib')
-rw-r--r--src/modules/systemlib/param/param.c42
-rw-r--r--src/modules/systemlib/param/param.h22
2 files changed, 60 insertions, 4 deletions
diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c
index ae680eeb0..8dea6e6cc 100644
--- a/src/modules/systemlib/param/param.c
+++ b/src/modules/systemlib/param/param.c
@@ -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;
}
diff --git a/src/modules/systemlib/param/param.h b/src/modules/systemlib/param/param.h
index e3e1b50eb..b29a7e51d 100644
--- a/src/modules/systemlib/param/param.h
+++ b/src/modules/systemlib/param/param.h
@@ -108,6 +108,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.
*
* @param index An index from 0 to n, where n is param_count()-1.
@@ -124,6 +138,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.
*
* @param param A handle returned by param_find or passed by param_foreach.