From c388dc5438747e04387a08c89d5369cbd26c0673 Mon Sep 17 00:00:00 2001 From: Guido Trentalancia Date: Sun, 18 Nov 2018 23:43:54 +0100 Subject: [PATCH 1/6] The listing of the following configuration options is currently broken in sigrok-cli (invalid values are displayed): - "timebase" in yokogawa-dlm, rohde-schwarz-hameg, hantek-dso, lecroy-xstream, siglent-sds and rigol-ds drivers; - "vdiv" in hantek-6xxx, yokogawa-dlm, rohde-schwarz-hameg, hantek-dso, lecroy-xstream, hung-chang-dso-2100, siglent-sds and rigol-ds drivers; - "spl_meas_range" in pce-322a and cem-dt-885x drivers. Fixes bug #1331. --- show.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/show.c b/show.c index 533ab1e..73240ee 100644 --- a/show.c +++ b/show.c @@ -321,7 +321,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; From c2fc81f2b661d25d01241977034c7b973ff93c7b Mon Sep 17 00:00:00 2001 From: Guido Trentalancia Date: Sun, 18 Nov 2018 23:44:52 +0100 Subject: [PATCH 2/6] Add missing function calls to free the memory used by the GVariant data structure. --- show.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/show.c b/show.c index 73240ee..672483f 100644 --- a/show.c +++ b/show.c @@ -665,6 +665,7 @@ 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 @@ -699,6 +700,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 From 490c9f447673f18a8b2cbb438fe632597e2b7f03 Mon Sep 17 00:00:00 2001 From: Guido Trentalancia Date: Wed, 21 Nov 2018 17:43:01 +0100 Subject: [PATCH 3/6] Support printing Volts per division (V/div) units (used for the vertical scale). --- show.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/show.c b/show.c index 672483f..26b6320 100644 --- a/show.c +++ b/show.c @@ -646,7 +646,8 @@ 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, &gvar) == SR_OK) { @@ -668,8 +669,12 @@ void show_dev_detail(void) 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) From ac9b02cf5d0ddd39c12700984ce381edd03a30ae Mon Sep 17 00:00:00 2001 From: Guido Trentalancia Date: Thu, 13 Dec 2018 16:56:01 +0100 Subject: [PATCH 4/6] Sort channels by type and not only by index. --- show.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/show.c b/show.c index 26b6320..064ab11 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) From 6366add37ffeb8a55860996838349efbd7ed0a5b Mon Sep 17 00:00:00 2001 From: Guido Trentalancia Date: Sun, 16 Dec 2018 22:34:25 +0100 Subject: [PATCH 5/6] Do not show all capabilities that can be read. 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 --- main.c | 15 +++++++++++++++ show.c | 18 +++++++++--------- sigrok-cli.h | 3 +++ 3 files changed, 27 insertions(+), 9 deletions(-) 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/show.c b/show.c index 064ab11..32de99d 100644 --- a/show.c +++ b/show.c @@ -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); @@ -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); @@ -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); @@ -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 { @@ -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"); @@ -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 { @@ -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); @@ -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); @@ -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) { 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); From e212d5381f5b178fcbb5efa745856b825f29c1fb Mon Sep 17 00:00:00 2001 From: Guido Trentalancia Date: Sat, 22 Dec 2018 14:16:22 +0100 Subject: [PATCH 6/6] Support parsing SCPI commands in sigrok-cli. The support for sending custom SCPI commands to the device has recently been added to libsigrok. Add the corresponding support for parsing such commands in sigrok-cli. --- parsers.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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++]));