Skip to content

Commit

Permalink
Do not show all capabilities that can be read.
Browse files Browse the repository at this point in the history
For example, automatic measurements can be read but should not
be shown in the supported configuration options list (--show).

This change requires the following recent libsigrok change:

commit 7b68fbf0671c9865984333327f215384f7e8b197
Date:   Thu Dec 20 19:51:11 2018 +0100
  • Loading branch information
gtrentalancia committed Jul 15, 2019
1 parent ac9b02c commit 6366add
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
15 changes: 15 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ int select_channels(struct sr_dev_inst *sdi)
int maybe_config_get(struct sr_dev_driver *driver,
const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
uint32_t key, GVariant **gvar)
{
if (sr_dev_config_capabilities_list(sdi, cg, key) & SR_CONF_GET_MASK)
return sr_config_get(driver, sdi, cg, key, gvar);

return SR_ERR_NA;
}

/*
* Same as maybe_config_get(), but strictly for capabilities that can
* be only read. Automatic Measurements for example, should not be
* normally listed, so they are skipped by this function.
*/
int maybe_config_get_and_show(struct sr_dev_driver *driver,
const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
uint32_t key, GVariant **gvar)
{
if (sr_dev_config_capabilities_list(sdi, cg, key) & SR_CONF_GET)
return sr_config_get(driver, sdi, cg, key, gvar);
Expand Down
18 changes: 9 additions & 9 deletions show.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static void print_dev_line(const struct sr_dev_inst *sdi)

s = g_string_sized_new(128);
g_string_assign(s, driver->name);
if (maybe_config_get(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
if (maybe_config_get_and_show(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
g_string_append(s, ":conn=");
g_string_append(s, g_variant_get_string(gvar, NULL));
g_variant_unref(gvar);
Expand Down Expand Up @@ -524,7 +524,7 @@ void show_dev_detail(void)
} else if (srci->datatype == SR_T_UINT64) {
printf(" %s: ", srci->id);
gvar = NULL;
if (maybe_config_get(driver, sdi, channel_group, key,
if (maybe_config_get_and_show(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
tmp_uint64 = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
Expand Down Expand Up @@ -552,7 +552,7 @@ void show_dev_detail(void)

} else if (srci->datatype == SR_T_STRING) {
printf(" %s: ", srci->id);
if (maybe_config_get(driver, sdi, channel_group, key,
if (maybe_config_get_and_show(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
g_variant_unref(gvar);
Expand Down Expand Up @@ -591,7 +591,7 @@ void show_dev_detail(void)
continue;
}

if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
if (maybe_config_get_and_show(driver, sdi, channel_group, key, &gvar) == SR_OK) {
g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
g_variant_unref(gvar);
} else {
Expand All @@ -615,7 +615,7 @@ void show_dev_detail(void)

} else if (srci->datatype == SR_T_BOOL) {
printf(" %s: ", srci->id);
if (maybe_config_get(driver, sdi, channel_group, key,
if (maybe_config_get_and_show(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
if (g_variant_get_boolean(gvar))
printf("on (current), off\n");
Expand All @@ -633,7 +633,7 @@ void show_dev_detail(void)
continue;
}

if (maybe_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
if (maybe_config_get_and_show(driver, sdi, channel_group, key, &gvar) == SR_OK) {
g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
g_variant_unref(gvar);
} else {
Expand All @@ -657,7 +657,7 @@ void show_dev_detail(void)

} else if (srci->datatype == SR_T_FLOAT) {
printf(" %s: ", srci->id);
if (maybe_config_get(driver, sdi, channel_group, key,
if (maybe_config_get_and_show(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
printf("%f\n", g_variant_get_double(gvar));
g_variant_unref(gvar);
Expand All @@ -668,7 +668,7 @@ void show_dev_detail(void)
|| srci->datatype == SR_T_RATIONAL_VOLT
|| srci->datatype == SR_T_RATIONAL_VOLT_PER_DIV) {
printf(" %s", srci->id);
if (maybe_config_get(driver, sdi, channel_group, key,
if (maybe_config_get_and_show(driver, sdi, channel_group, key,
&gvar) == SR_OK) {
g_variant_get(gvar, "(tt)", &cur_p, &cur_q);
g_variant_unref(gvar);
Expand Down Expand Up @@ -704,7 +704,7 @@ void show_dev_detail(void)

} else if (srci->datatype == SR_T_MQ) {
printf(" %s: ", srci->id);
if (maybe_config_get(driver, sdi, channel_group, key,
if (maybe_config_get_and_show(driver, sdi, channel_group, key,
&gvar) == SR_OK
&& g_variant_is_of_type(gvar, G_VARIANT_TYPE_TUPLE)
&& g_variant_n_children(gvar) == 2) {
Expand Down
3 changes: 3 additions & 0 deletions sigrok-cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ int select_channels(struct sr_dev_inst *sdi);
int maybe_config_get(struct sr_dev_driver *driver,
const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
uint32_t key, GVariant **gvar);
int maybe_config_get_and_show(struct sr_dev_driver *driver,
const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
uint32_t key, GVariant **gvar);
int maybe_config_set(struct sr_dev_driver *driver,
const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
uint32_t key, GVariant *gvar);
Expand Down

0 comments on commit 6366add

Please sign in to comment.