X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=main.c;h=81dc4ad21055a11bfc6f199d1dff732e388eb620;hp=ea4c71846791bd42f20f74aa6d77021fc3475180;hb=783e263e581ed7321ca4bdc1ab7a4fafd2100507;hpb=b4eece7c5f666690fdbe1923cd3bdc7cf9425d98 diff --git a/main.c b/main.c index ea4c718..81dc4ad 100644 --- a/main.c +++ b/main.c @@ -50,13 +50,15 @@ static void logger(const gchar *log_domain, GLogLevelFlags log_level, int select_channels(struct sr_dev_inst *sdi) { struct sr_channel *ch; - GSList *selected_channels, *l; + GSList *selected_channels, *l, *channels; + + channels = sr_dev_inst_channels_get(sdi); if (opt_channels) { if (!(selected_channels = parse_channelstring(sdi, opt_channels))) return SR_ERR; - for (l = sdi->channels; l; l = l->next) { + for (l = channels; l; l = l->next) { ch = l->data; if (g_slist_find(selected_channels, ch)) ch->enabled = TRUE; @@ -71,6 +73,52 @@ 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; + struct sr_dev_driver *driver; + + if (!(devices = device_scan())) { + g_critical("No devices found."); + return; + } + sdi = devices->data; + g_slist_free(devices); + + driver = sr_dev_inst_driver_get(sdi); + + 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(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; @@ -162,6 +210,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 +224,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)