X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=main.c;h=17076724388c7808bc9fa21d16fac1e7a8e46390;hp=95b4258f477f4dc304ebf11fe7e7f52432316ddc;hb=f553109693c34861f14884b917139bef19d79000;hpb=cd62e027c0a3a8d97a6689d042b92699d8b619f3 diff --git a/main.c b/main.c index 95b4258..1707672 100644 --- a/main.c +++ b/main.c @@ -71,6 +71,49 @@ int select_channels(struct sr_dev_inst *sdi) return SR_OK; } +static void get_option(void) +{ + struct sr_dev_inst *sdi; + struct sr_channel_group *cg; + const struct sr_config_info *ci; + GSList *devices; + GVariant *gvar; + GHashTable *devargs; + int ret; + char *s; + + if (!(devices = device_scan())) { + g_critical("No devices found."); + return; + } + sdi = devices->data; + g_slist_free(devices); + + if (sr_dev_open(sdi) != SR_OK) { + g_critical("Failed to open device."); + return; + } + + cg = select_channel_group(sdi); + if (!(ci = sr_config_info_name_get(opt_get))) + g_critical("Unknown option '%s'", opt_get); + + if ((devargs = parse_generic_arg(opt_config, FALSE))) + set_dev_options(sdi, devargs); + else devargs = NULL; + + if ((ret = sr_config_get(sdi->driver, sdi, cg, ci->key, &gvar)) != SR_OK) + g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret)); + s = g_variant_print(gvar, FALSE); + printf("%s\n", s); + g_free(s); + + g_variant_unref(gvar); + sr_dev_close(sdi); + if (devargs) + g_hash_table_destroy(devargs); +} + static void set_options(void) { struct sr_dev_inst *sdi; @@ -90,6 +133,7 @@ static void set_options(void) return; } sdi = devices->data; + g_slist_free(devices); if (sr_dev_open(sdi) != SR_OK) { g_critical("Failed to open device."); @@ -99,7 +143,6 @@ static void set_options(void) set_dev_options(sdi, devargs); sr_dev_close(sdi); - g_slist_free(devices); g_hash_table_destroy(devargs); } @@ -162,6 +205,10 @@ int main(int argc, char **argv) if (opt_version) show_version(); + else if (opt_input_format && opt_show) + show_input(); + else if (opt_output_format && opt_show) + show_output(); else if (opt_scan_devs) show_dev_list(); #ifdef HAVE_SRD @@ -172,6 +219,8 @@ int main(int argc, char **argv) show_dev_detail(); else if (opt_input_file) load_input_file(); + else if (opt_get) + get_option(); else if (opt_set) set_options(); else if (opt_samples || opt_time || opt_frames || opt_continuous)