X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=sigrok-cli.c;h=a6db4f5ddc3cba15e47d933dd2964aa10c073497;hp=bc293179b4c8130a32ebbc517bbe6207f5be79de;hb=41d7fb2343dc765fa34ffa661ee19c20c93eff9a;hpb=a172e2a0f496c1b7685d8843ace31ac940f91c21 diff --git a/sigrok-cli.c b/sigrok-cli.c index bc29317..a6db4f5 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -314,22 +314,12 @@ static void show_dev_detail(void) num_devices = g_slist_length(devices); if (num_devices > 1) { - if (!opt_dev) { - g_critical("%d devices found. Use --list-devices to show them, " - "and --device to select one.", num_devices); - return; - } - /* opt_dev is NULL if not specified, which is fine. */ - n = strtol(opt_dev, NULL, 10); - if (n >= num_devices) { - g_critical("%d devices found, numbered starting from 0.", - num_devices); - return; - } - sdi = g_slist_nth_data(devices, n); - } else - sdi = g_slist_nth_data(devices, 0); + g_critical("%d devices found. Use --list-devices to show them, " + "and --device to select one.", num_devices); + return; + } + sdi = devices->data; print_dev_line(sdi); if (sr_config_list(sdi->driver, SR_CONF_TRIGGER_TYPE, (const void **)&charopts, @@ -640,45 +630,6 @@ static void datafeed_in(const struct sr_dev_inst *sdi, } break; - case SR_DF_END: - g_debug("cli: Received SR_DF_END"); - if (!o) { - g_debug("cli: double end!"); - break; - } - if (o->format->event) { - o->format->event(o, SR_DF_END, &output_buf, &output_len); - if (output_buf) { - if (outfile) - fwrite(output_buf, 1, output_len, outfile); - g_free(output_buf); - output_len = 0; - } - } - if (limit_samples && received_samples < limit_samples) - g_warning("Device only sent %" PRIu64 " samples.", - received_samples); - if (opt_continuous) - g_warning("Device stopped after %" PRIu64 " samples.", - received_samples); - - if (outfile && outfile != stdout) - fclose(outfile); - - if (opt_output_file && default_output_format) { - if (sr_session_save(opt_output_file, sdi, savebuf->data, - unitsize, savebuf->len / unitsize) != SR_OK) - g_critical("Failed to save session."); - g_byte_array_free(savebuf, FALSE); - } - - g_array_free(logic_probelist, TRUE); - if (o->format->cleanup) - o->format->cleanup(o); - g_free(o); - o = NULL; - break; - case SR_DF_META: g_debug("cli: received SR_DF_META"); meta = packet->payload; @@ -819,6 +770,47 @@ static void datafeed_in(const struct sr_dev_inst *sdi, } } + /* SR_DF_END needs to be handled after the output module's recv() + * is called, so it can properly clean up that module etc. */ + if (packet->type == SR_DF_END) { + g_debug("cli: Received SR_DF_END"); + + if (o->format->event) { + o->format->event(o, SR_DF_END, &output_buf, &output_len); + if (output_buf) { + if (outfile) + fwrite(output_buf, 1, output_len, outfile); + g_free(output_buf); + output_len = 0; + } + } + + if (limit_samples && received_samples < limit_samples) + g_warning("Device only sent %" PRIu64 " samples.", + received_samples); + + if (opt_continuous) + g_warning("Device stopped after %" PRIu64 " samples.", + received_samples); + + g_array_free(logic_probelist, TRUE); + + if (o->format->cleanup) + o->format->cleanup(o); + g_free(o); + o = NULL; + + if (outfile && outfile != stdout) + fclose(outfile); + + if (opt_output_file && default_output_format) { + if (sr_session_save(opt_output_file, sdi, savebuf->data, + unitsize, savebuf->len / unitsize) != SR_OK) + g_critical("Failed to save session."); + g_byte_array_free(savebuf, FALSE); + } + } + } /* Register the given PDs for this session.