X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=session.c;h=9fa545ec690a35fc5b6f3e742df2eb472ec5ce0c;hp=d3c7e01d3389f0676b47d277836aa109460b6353;hb=c59bf72b694ab1d08b2ea44de4349c277e206414;hpb=84c250a2ee6152ec0d857f7be142f873fa44e640 diff --git a/session.c b/session.c index d3c7e01..9fa545e 100644 --- a/session.c +++ b/session.c @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -#include "sigrok-cli.h" #include #include #include #include +#include "sigrok-cli.h" static uint64_t limit_samples = 0; static uint64_t limit_frames = 0; @@ -53,7 +53,7 @@ static int set_limit_time(const struct sr_dev_inst *sdi) } } else if (config_key_has_cap(driver, sdi, NULL, SR_CONF_SAMPLERATE, SR_CONF_GET | SR_CONF_SET)) { - /* Convert to samples based on the samplerate. */ + /* Convert to samples based on the samplerate. */ sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE, &gvar); samplerate = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -171,7 +171,7 @@ void datafeed_in(const struct sr_dev_inst *sdi, driver = sr_dev_inst_driver_get(sdi); /* If the first packet to come in isn't a header, don't even try. */ - if (packet->type != SR_DF_HEADER && o == NULL) + if (packet->type != SR_DF_HEADER && !o) return; session = cb_data; @@ -308,8 +308,10 @@ void datafeed_in(const struct sr_dev_inst *sdi, if (!out || (out->len == 0 && !opt_output_format && packet->type == SR_DF_ANALOG)) { - /* The user didn't specify an output module, - * but needs to see this analog data. */ + /* + * The user didn't specify an output module, + * but needs to see this analog data. + */ sr_output_send(oa, packet, &out); } if (out && out->len > 0) { @@ -321,15 +323,16 @@ void datafeed_in(const struct sr_dev_inst *sdi, } } - /* SR_DF_END needs to be handled after the output module's receive() - * is called, so it can properly clean up that module. */ + /* + * SR_DF_END needs to be handled after the output module's receive() + * is called, so it can properly clean up that module. + */ if (packet->type == SR_DF_END) { g_debug("cli: Received SR_DF_END."); if (o) { sr_output_free(o); - if (srzip_and_filename) - g_free(srzip_and_filename); + g_free(srzip_and_filename); } o = NULL; @@ -368,7 +371,7 @@ int opt_to_gvar(char *key, char *value, struct sr_config *src) } src->key = srci->key; - if ((value == NULL || strlen(value) == 0) && + if ((!value || strlen(value) == 0) && (srci->datatype != SR_T_BOOL)) { g_critical("Option '%s' needs a value.", (char *)key); return -1; @@ -478,7 +481,8 @@ int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args) cg = select_channel_group(sdi); if ((ret = maybe_config_set(sr_dev_inst_driver_get(sdi), sdi, cg, src.key, src.data)) != SR_OK) { - g_critical("Failed to set device option '%s'.", (char *)key); + g_critical("Failed to set device option '%s': %s.", + (char *)key, sr_strerror(ret)); return ret; } } @@ -548,7 +552,7 @@ void run_session(void) g_slist_free(devices); g_slist_free(real_devices); - sr_session_new(&session); + sr_session_new(sr_ctx, &session); sr_session_datafeed_callback_add(session, datafeed_in, NULL); if (sr_dev_open(sdi) != SR_OK) { @@ -610,8 +614,10 @@ void run_session(void) } if (maybe_config_list(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. */ + /* + * 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) { @@ -666,4 +672,3 @@ void run_session(void) sr_session_destroy(session); } -