X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=session.c;h=9441f5da1865f86992e783056296f1f116b656dd;hp=12033dcc8316a9b8f362d3c751ea3745b883f513;hb=6df458b71ace93941780153b79b348d4fd99493d;hpb=30364883abef6a52180fc6244d79788298729137 diff --git a/session.c b/session.c index 12033dc..9441f5d 100644 --- a/session.c +++ b/session.c @@ -17,14 +17,12 @@ * along with this program. If not, see . */ +#include "sigrok-cli.h" #include "config.h" #include #include -#include -#ifdef HAVE_SRD -#include /* First, so we avoid a _POSIX_C_SOURCE warning. */ -#endif -#include "sigrok-cli.h" +#include +#include static struct sr_output_format *output_format = NULL; static int default_output_format = FALSE; @@ -177,7 +175,10 @@ void datafeed_in(const struct sr_dev_inst *sdi, GSList *l; GString *out; int sample_size, ret; - uint64_t samplerate, output_len, filter_out_len, end_sample; + uint64_t samplerate, output_len, filter_out_len; +#ifdef HAVE_SRD + uint64_t end_sample; +#endif uint8_t *output_buf, *filter_out; (void) cb_data; @@ -446,83 +447,100 @@ void datafeed_in(const struct sr_dev_inst *sdi, } -int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args) +int opt_to_gvar(char *key, char *value, struct sr_config *src) { const struct sr_config_info *srci; - struct sr_probe_group *pg; - GHashTableIter iter; - gpointer key, value; - int ret; double tmp_double; uint64_t tmp_u64, p, q, low, high; + GVariant *rational[2], *range[2]; gboolean tmp_bool; - GVariant *val, *rational[2], *range[2]; + int ret; - g_hash_table_iter_init(&iter, args); - while (g_hash_table_iter_next(&iter, &key, &value)) { - if (!(srci = sr_config_info_name_get(key))) { - g_critical("Unknown device option '%s'.", (char *) key); - return SR_ERR; - } + if (!(srci = sr_config_info_name_get(key))) { + g_critical("Unknown device option '%s'.", (char *) key); + return -1; + } + src->key = srci->key; - if ((value == NULL) && - (srci->datatype != SR_T_BOOL)) { - g_critical("Option '%s' needs a value.", (char *)key); - return SR_ERR; - } - val = NULL; - switch (srci->datatype) { - case SR_T_UINT64: - ret = sr_parse_sizestring(value, &tmp_u64); - if (ret != SR_OK) - break; - val = g_variant_new_uint64(tmp_u64); - break; - case SR_T_CHAR: - val = g_variant_new_string(value); - break; - case SR_T_BOOL: - if (!value) - tmp_bool = TRUE; - else - tmp_bool = sr_parse_boolstring(value); - val = g_variant_new_boolean(tmp_bool); + if ((value == NULL) && + (srci->datatype != SR_T_BOOL)) { + g_critical("Option '%s' needs a value.", (char *)key); + return -1; + } + + ret = 0; + switch (srci->datatype) { + case SR_T_UINT64: + ret = sr_parse_sizestring(value, &tmp_u64); + if (ret != 0) break; - case SR_T_FLOAT: - tmp_double = strtof(value, NULL); - val = g_variant_new_double(tmp_double); + src->data = g_variant_new_uint64(tmp_u64); + break; + case SR_T_INT32: + ret = sr_parse_sizestring(value, &tmp_u64); + if (ret != 0) break; - case SR_T_RATIONAL_PERIOD: - if ((ret = sr_parse_period(value, &p, &q)) != SR_OK) - break; - rational[0] = g_variant_new_uint64(p); - rational[1] = g_variant_new_uint64(q); - val = g_variant_new_tuple(rational, 2); + src->data = g_variant_new_int32(tmp_u64); + break; + case SR_T_CHAR: + src->data = g_variant_new_string(value); + break; + case SR_T_BOOL: + if (!value) + tmp_bool = TRUE; + else + tmp_bool = sr_parse_boolstring(value); + src->data = g_variant_new_boolean(tmp_bool); + break; + case SR_T_FLOAT: + tmp_double = strtof(value, NULL); + src->data = g_variant_new_double(tmp_double); + break; + case SR_T_RATIONAL_PERIOD: + if ((ret = sr_parse_period(value, &p, &q)) != SR_OK) break; - case SR_T_RATIONAL_VOLT: - if ((ret = sr_parse_voltage(value, &p, &q)) != SR_OK) - break; - rational[0] = g_variant_new_uint64(p); - rational[1] = g_variant_new_uint64(q); - val = g_variant_new_tuple(rational, 2); + rational[0] = g_variant_new_uint64(p); + rational[1] = g_variant_new_uint64(q); + src->data = g_variant_new_tuple(rational, 2); + break; + case SR_T_RATIONAL_VOLT: + if ((ret = sr_parse_voltage(value, &p, &q)) != SR_OK) break; - case SR_T_UINT64_RANGE: - if (sscanf(value, "%"PRIu64"-%"PRIu64, &low, &high) != 2) { - ret = SR_ERR; - break; - } else { - range[0] = g_variant_new_uint64(low); - range[1] = g_variant_new_uint64(high); - val = g_variant_new_tuple(range, 2); - } + rational[0] = g_variant_new_uint64(p); + rational[1] = g_variant_new_uint64(q); + src->data = g_variant_new_tuple(rational, 2); + break; + case SR_T_UINT64_RANGE: + if (sscanf(value, "%"PRIu64"-%"PRIu64, &low, &high) != 2) { + ret = -1; break; - default: - ret = SR_ERR; - } - if (val) { - pg = select_probe_group(sdi); - ret = sr_config_set(sdi, pg, srci->key, val); + } else { + range[0] = g_variant_new_uint64(low); + range[1] = g_variant_new_uint64(high); + src->data = g_variant_new_tuple(range, 2); } + break; + default: + ret = -1; + } + + return ret; +} + +int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args) +{ + struct sr_config src; + struct sr_probe_group *pg; + GHashTableIter iter; + gpointer key, value; + int ret; + + g_hash_table_iter_init(&iter, args); + while (g_hash_table_iter_next(&iter, &key, &value)) { + if ((ret = opt_to_gvar(key, value, &src)) != 0) + return ret; + pg = select_probe_group(sdi); + ret = sr_config_set(sdi, pg, src.key, src.data); if (ret != SR_OK) { g_critical("Failed to set device option '%s'.", (char *)key); return ret; @@ -538,6 +556,7 @@ void run_session(void) GHashTable *devargs; GVariant *gvar; struct sr_dev_inst *sdi; + uint64_t min_samples, max_samples; int max_probes, i; char **triggerlist; @@ -616,6 +635,21 @@ void run_session(void) sr_session_destroy(); return; } + if (sr_config_list(sdi->driver, sdi, NULL, + SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK) { + /* The device has no compression, or compression is turned + * off, and publishes its sample memory size. */ + g_variant_get(gvar, "(tt)", &min_samples, &max_samples); + g_variant_unref(gvar); + if (limit_samples < min_samples) { + g_critical("The device stores at least %"PRIu64 + " samples with the current settings.", min_samples); + } + if (limit_samples > max_samples) { + g_critical("The device can store only %"PRIu64 + " samples with the current settings.", max_samples); + } + } gvar = g_variant_new_uint64(limit_samples); if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) { g_critical("Failed to configure sample limit.");