X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=main.c;h=8e4ac3a6a5891879c8aec9c946c82b5121b60753;hp=1d3b33df800f1765f6247a7acafe33c603dd94c0;hb=b45ae06ee6eadd9f0ef7154d1d5770f334a11363;hpb=6f7b4c5d7eb49642f8221a85ee6987751fcd81ce;ds=sidebyside
diff --git a/main.c b/main.c
index 1d3b33d..8e4ac3a 100644
--- a/main.c
+++ b/main.c
@@ -17,9 +17,10 @@
* along with this program. If not, see .
*/
-#include "sigrok-cli.h"
+#include
#include
#include
+#include "sigrok-cli.h"
struct sr_context *sr_ctx = NULL;
#ifdef HAVE_SRD
@@ -50,6 +51,7 @@ static void logger(const gchar *log_domain, GLogLevelFlags log_level,
int select_channels(struct sr_dev_inst *sdi)
{
struct sr_channel *ch;
+ gboolean enabled;
GSList *selected_channels, *l, *channels;
channels = sr_dev_inst_channels_get(sdi);
@@ -60,10 +62,9 @@ int select_channels(struct sr_dev_inst *sdi)
for (l = channels; l; l = l->next) {
ch = l->data;
- if (g_slist_find(selected_channels, ch))
- ch->enabled = TRUE;
- else
- ch->enabled = FALSE;
+ enabled = (g_slist_find(selected_channels, ch) != NULL);
+ if (sr_dev_channel_enable(ch, enabled) != SR_OK)
+ return SR_ERR;
}
g_slist_free(selected_channels);
}
@@ -73,36 +74,11 @@ int select_channels(struct sr_dev_inst *sdi)
return SR_OK;
}
-gboolean config_key_has_cap(struct sr_dev_driver *driver,
- const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
- uint32_t key, uint32_t capability)
-{
- GVariant *gvar_opts;
- const uint32_t *opts;
- gsize num_opts, i;
-
- if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS,
- &gvar_opts) != SR_OK)
- return FALSE;
-
- opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t));
- for (i = 0; i < num_opts; i++) {
- if ((opts[i] & SR_CONF_MASK) == key) {
- if ((opts[i] & capability) == capability)
- return TRUE;
- else
- return FALSE;
- }
- }
-
- return FALSE;
-}
-
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 (config_key_has_cap(driver, sdi, cg, key, SR_CONF_GET))
+ if (sr_dev_config_capabilities_list(sdi, cg, key) & SR_CONF_GET)
return sr_config_get(driver, sdi, cg, key, gvar);
return SR_ERR_NA;
@@ -112,7 +88,9 @@ 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)
{
- if (config_key_has_cap(driver, sdi, cg, key, SR_CONF_SET))
+ (void)driver;
+
+ if (sr_dev_config_capabilities_list(sdi, cg, key) & SR_CONF_SET)
return sr_config_set(sdi, cg, key, gvar);
return SR_ERR_NA;
@@ -122,7 +100,7 @@ int maybe_config_list(struct sr_dev_driver *driver,
const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
uint32_t key, GVariant **gvar)
{
- if (config_key_has_cap(driver, sdi, cg, key, SR_CONF_LIST))
+ if (sr_dev_config_capabilities_list(sdi, cg, key) & SR_CONF_LIST)
return sr_config_list(driver, sdi, cg, key, gvar);
return SR_ERR_NA;
@@ -132,13 +110,17 @@ static void get_option(void)
{
struct sr_dev_inst *sdi;
struct sr_channel_group *cg;
- const struct sr_config_info *ci;
+ const struct sr_key_info *ci;
GSList *devices;
GVariant *gvar;
GHashTable *devargs;
int ret;
char *s;
struct sr_dev_driver *driver;
+ const struct sr_key_info *srci, *srmqi, *srmqfi;
+ uint32_t mq;
+ uint64_t mask, mqflags;
+ unsigned int j;
if (!(devices = device_scan())) {
g_critical("No devices found.");
@@ -155,18 +137,37 @@ static void get_option(void)
}
cg = select_channel_group(sdi);
- if (!(ci = sr_config_info_name_get(opt_get)))
+ if (!(ci = sr_key_info_name_get(SR_KEY_CONFIG, 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;
+ else
+ devargs = NULL;
if ((ret = maybe_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);
+ srci = sr_key_info_get(SR_KEY_CONFIG, ci->key);
+ if (srci && srci->datatype == SR_T_MQ) {
+ g_variant_get(gvar, "(ut)", &mq, &mqflags);
+ if ((srmqi = sr_key_info_get(SR_KEY_MQ, mq)))
+ printf("%s", srmqi->id);
+ else
+ printf("%d", mq);
+ for (j = 0, mask = 1; j < 32; j++, mask <<= 1) {
+ if (!(mqflags & mask))
+ continue;
+ if ((srmqfi = sr_key_info_get(SR_KEY_MQFLAGS, mqflags & mask)))
+ printf("/%s", srmqfi->id);
+ else
+ printf("/%" PRIu64, mqflags & mask);
+ }
+ printf("\n");
+ } else {
+ s = g_variant_print(gvar, FALSE);
+ printf("%s\n", s);
+ g_free(s);
+ }
g_variant_unref(gvar);
sr_dev_close(sdi);
@@ -236,8 +237,6 @@ int main(int argc, char **argv)
}
if (register_pds(opt_pds, opt_pd_annotations) != 0)
goto done;
- if (setup_pd_stack(opt_pds, opt_pd_stack, opt_pd_annotations) != 0)
- goto done;
/* Only one output type is ever shown. */
if (opt_pd_binary) {
@@ -265,6 +264,12 @@ int main(int argc, char **argv)
if (opt_version)
show_version();
+ else if (opt_list_supported)
+ show_supported();
+ else if (opt_list_supported_wiki)
+ show_supported_wiki();
+ else if (opt_input_file && opt_show)
+ load_input_file(TRUE);
else if (opt_input_format && opt_show)
show_input();
else if (opt_output_format && opt_show)
@@ -280,7 +285,7 @@ int main(int argc, char **argv)
else if (opt_show)
show_dev_detail();
else if (opt_input_file)
- load_input_file();
+ load_input_file(FALSE);
else if (opt_get)
get_option();
else if (opt_set)