Skip to content

Commit

Permalink
param lib: Fix index used routine
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzMeier committed May 18, 2015
1 parent 4345204 commit c06ba04
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modules/systemlib/param/param.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ param_for_used_index(unsigned index)
* return the param value
*/
if (index == count) {
return (param_t)i;
return (param_t)(i * 8 + j);
}

count++;
Expand Down
63 changes: 63 additions & 0 deletions src/systemcmds/param/param.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static void do_save(const char *param_file_name);
static void do_load(const char *param_file_name);
static void do_import(const char *param_file_name);
static void do_show(const char *search_string);
static void do_show_index(const char *index, bool used_index);
static void do_show_print(void *arg, param_t param);
static void do_set(const char *name, const char *val, bool fail_on_not_found);
static void do_compare(const char *name, char *vals[], unsigned comparisons);
Expand Down Expand Up @@ -168,6 +169,24 @@ param_main(int argc, char *argv[])
do_reset_nostart(NULL, 0);
}
}

if (!strcmp(argv[1], "index_used")) {
if (argc >= 3) {
do_show_index(argv[2], true);
} else {
warnx("no index provided");
return 1;
}
}

if (!strcmp(argv[1], "index")) {
if (argc >= 3) {
do_show_index(argv[2], false);
} else {
warnx("no index provided");
return 1;
}
}
}

errx(1, "expected a command, try 'load', 'import', 'show', 'set', 'compare', 'select' or 'save'");
Expand Down Expand Up @@ -242,6 +261,50 @@ do_show(const char *search_string)
exit(0);
}

static void
do_show_index(const char *index, bool used_index)
{
char *end;
int i = strtol(index, &end, 10);
param_t param;
int32_t ii;
float ff;

if (used_index) {
param = param_for_used_index(i);
} else {
param = param_for_index(i);
}

if (param == PARAM_INVALID) {
return;
}

printf("index %d: %c %c %s [%d,%d] : ", i, (param_used(param) ? 'x' : ' '),
param_value_unsaved(param) ? '*' : (param_value_is_default(param) ? ' ' : '+'),
param_name(param), param_get_used_index(param), param_get_index(param));

switch (param_type(param)) {
case PARAM_TYPE_INT32:
if (!param_get(param, &ii)) {
printf("%d\n", ii);
}

break;

case PARAM_TYPE_FLOAT:
if (!param_get(param, &ff)) {
printf("%4.4f\n", (double)ff);
}

break;
default:
printf("<unknown type %d>\n", 0 + param_type(param));
}

exit(0);
}

static void
do_show_print(void *arg, param_t param)
{
Expand Down

0 comments on commit c06ba04

Please sign in to comment.