diff --git a/main.c b/main.c index c038b6f..9cc5ba2 100644 --- a/main.c +++ b/main.c @@ -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); diff --git a/parsers.c b/parsers.c index 5ec655f..69f7bde 100644 --- a/parsers.c +++ b/parsers.c @@ -272,6 +272,7 @@ GHashTable *parse_generic_arg(const char *arg, gboolean sep_first) GHashTable *hash; int i; char **elements, *e; + const struct sr_key_info *info; if (!arg || !arg[0]) return NULL; @@ -279,7 +280,14 @@ GHashTable *parse_generic_arg(const char *arg, gboolean sep_first) i = 0; hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - elements = g_strsplit(arg, ":", 0); + + /* In the SCPI command syntax the ":" character is reserved. */ + info = sr_key_info_get(SR_KEY_CONFIG, SR_CONF_CUSTOM_CMD); + if (info && !strncmp(info->id, arg, strlen(info->id))) { + elements = g_strsplit(arg, "\n", 1); + } else { + elements = g_strsplit(arg, ":", 0); + } if (sep_first) g_hash_table_insert(hash, g_strdup("sigrok_key"), g_strdup(elements[i++])); diff --git a/show.c b/show.c index 533ab1e..32de99d 100644 --- a/show.c +++ b/show.c @@ -208,7 +208,26 @@ static gint sort_channels(gconstpointer a, gconstpointer b) { const struct sr_channel *pa = a, *pb = b; - return pa->index - pb->index; + if (pa->type == pb->type) + return pa->index - pb->index; + + /* + * Sort analog channels before digital channels and + * digital channels before special FFT channels. + */ + if (pa->type == SR_CHANNEL_ANALOG) + return -1; + + if (pb->type == SR_CHANNEL_ANALOG) + return 1; + + if (pa->type == SR_CHANNEL_LOGIC) + return -1; + + if (pb->type == SR_CHANNEL_LOGIC) + return 1; + + return 0; } static void print_dev_line(const struct sr_dev_inst *sdi) @@ -228,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); @@ -321,7 +340,8 @@ void show_dev_detail(void) GVariant *gvar_dict, *gvar_list, *gvar; gsize num_elements; double dlow, dhigh, dcur_low, dcur_high; - const uint64_t *uint64, p = 0, q = 0, low = 0, high = 0; + const uint64_t *uint64; + uint64_t p = 0, q = 0, low = 0, high = 0; uint64_t tmp_uint64, mask, cur_low, cur_high, cur_p, cur_q; GArray *opts; const int32_t *int32; @@ -504,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); @@ -532,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); @@ -571,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 { @@ -595,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"); @@ -613,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 { @@ -637,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); @@ -645,9 +665,10 @@ void show_dev_detail(void) printf("\n"); } else if (srci->datatype == SR_T_RATIONAL_PERIOD - || srci->datatype == SR_T_RATIONAL_VOLT) { + || 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); @@ -664,10 +685,15 @@ void show_dev_detail(void) for (i = 0; i < num_elements; i++) { gvar = g_variant_get_child_value(gvar_list, i); g_variant_get(gvar, "(tt)", &p, &q); + g_variant_unref(gvar); if (srci->datatype == SR_T_RATIONAL_PERIOD) s = sr_period_string(p, q); - else + else if (srci->datatype == SR_T_RATIONAL_VOLT) s = sr_voltage_string(p, q); + else if (srci->datatype == SR_T_RATIONAL_VOLT_PER_DIV) + s = sr_voltage_per_div_string(p, q); + else + s = g_strdup("Invalid datatype"); printf(" %s", s); g_free(s); if (p == cur_p && q == cur_q) @@ -678,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) { @@ -698,6 +724,7 @@ void show_dev_detail(void) printf(" "); gvar = g_variant_get_child_value(gvar_list, i); g_variant_get(gvar, "(ut)", &mq, &mqflags); + g_variant_unref(gvar); if ((srmqi = sr_key_info_get(SR_KEY_MQ, mq))) printf("%s", srmqi->id); else diff --git a/sigrok-cli.h b/sigrok-cli.h index f564448..8b0f3df 100644 --- a/sigrok-cli.h +++ b/sigrok-cli.h @@ -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);