From: Uwe Hermann Date: Wed, 5 Jul 2017 17:33:38 +0000 (+0200) Subject: Add sr_dev_acquisition_stop(), factor out SR_ERR_DEV_CLOSED check. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d2f7c417fdd96a13d8fd86350d2fc13db16f626c;p=libsigrok.git Add sr_dev_acquisition_stop(), factor out SR_ERR_DEV_CLOSED check. This ensures consistent checks and log messages across all drivers and reduces the per-driver boilerplate. --- diff --git a/src/hardware/agilent-dmm/protocol.c b/src/hardware/agilent-dmm/protocol.c index 439cbd00..8778c711 100644 --- a/src/hardware/agilent-dmm/protocol.c +++ b/src/hardware/agilent-dmm/protocol.c @@ -200,7 +200,7 @@ SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits) || stop) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); else dispatch(sdi); diff --git a/src/hardware/appa-55ii/protocol.c b/src/hardware/appa-55ii/protocol.c index c22ede50..f31b08b8 100644 --- a/src/hardware/appa-55ii/protocol.c +++ b/src/hardware/appa-55ii/protocol.c @@ -224,7 +224,7 @@ static void appa_55ii_log_end(struct sr_dev_inst *sdi) if (devc->data_source != DATA_SOURCE_MEMORY) return; - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } static const uint8_t *appa_55ii_parse_data(struct sr_dev_inst *sdi, @@ -309,7 +309,7 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/arachnid-labs-re-load-pro/protocol.c b/src/hardware/arachnid-labs-re-load-pro/protocol.c index dd0ad409..47cc8af1 100644 --- a/src/hardware/arachnid-labs-re-load-pro/protocol.c +++ b/src/hardware/arachnid-labs-re-load-pro/protocol.c @@ -263,7 +263,7 @@ SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data) handle_new_data(sdi); if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index 4d1b1cce..cc742d10 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -1114,7 +1114,7 @@ static int download_capture(struct sr_dev_inst *sdi) std_session_send_df_end(sdi); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); g_free(dram_line); diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 01c0d369..1768f842 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -466,9 +466,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->acquisition_running = FALSE; diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index a1b860e3..8e0af46d 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -360,9 +360,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - dev_acquisition_close(sdi); sr_session_source_remove_channel(sdi->session, devc->channel); g_io_channel_shutdown(devc->channel, FALSE, NULL); diff --git a/src/hardware/baylibre-acme/protocol.c b/src/hardware/baylibre-acme/protocol.c index 4f62a9e9..0311f68e 100644 --- a/src/hardware/baylibre-acme/protocol.c +++ b/src/hardware/baylibre-acme/protocol.c @@ -793,7 +793,7 @@ SR_PRIV int bl_acme_receive_data(int fd, int revents, void *cb_data) sr_sw_limits_update_samples_read(&devc->limits, 1); if (sr_sw_limits_check(&devc->limits)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 34b09f21..c8e43730 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -332,9 +332,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - /* Execute a stop on BeagleLogic */ beaglelogic_stop(devc); diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index fb9f2807..484e1476 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -227,9 +227,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - std_session_send_df_end(sdi); sr_session_source_remove(sdi->session, -1); diff --git a/src/hardware/brymen-bm86x/protocol.c b/src/hardware/brymen-bm86x/protocol.c index 3181fef0..f9b2bde1 100644 --- a/src/hardware/brymen-bm86x/protocol.c +++ b/src/hardware/brymen-bm86x/protocol.c @@ -344,7 +344,7 @@ SR_PRIV int brymen_bm86x_receive_data(int fd, int revents, void *cb_data) return FALSE; if (sr_sw_limits_check(&devc->sw_limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/brymen-dmm/protocol.c b/src/hardware/brymen-dmm/protocol.c index 5a7f2252..3dd8dd31 100644 --- a/src/hardware/brymen-dmm/protocol.c +++ b/src/hardware/brymen-dmm/protocol.c @@ -143,7 +143,7 @@ SR_PRIV int brymen_dmm_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->sw_limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/cem-dt-885x/protocol.c b/src/hardware/cem-dt-885x/protocol.c index 88fa8b7f..092d1654 100644 --- a/src/hardware/cem-dt-885x/protocol.c +++ b/src/hardware/cem-dt-885x/protocol.c @@ -147,7 +147,7 @@ static void process_mset(const struct sr_dev_inst *sdi) devc->num_samples++; if (devc->limit_samples && devc->num_samples >= devc->limit_samples) - sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi); + sr_dev_acquisition_stop((struct sr_dev_inst *)sdi); break; case TOKEN_RECORDING_ON: devc->recording = TRUE; @@ -208,7 +208,7 @@ static void send_data(const struct sr_dev_inst *sdi, unsigned char *data, devc->num_samples += analog.num_samples; if (devc->limit_samples && devc->num_samples >= devc->limit_samples) - sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi); + sr_dev_acquisition_stop((struct sr_dev_inst *)sdi); return; } @@ -321,7 +321,7 @@ static void process_byte(const struct sr_dev_inst *sdi, const unsigned char c, * records. Otherwise the frontend would have no * way to tell where stored data ends and live * measurements begin. */ - sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi); + sr_dev_acquisition_stop((struct sr_dev_inst *)sdi); } else if (c == RECORD_DATA) { devc->buf_len = 0; devc->state = ST_GET_LOG_RECORD_DATA; diff --git a/src/hardware/center-3xx/protocol.c b/src/hardware/center-3xx/protocol.c index ca1ae3b5..2a02b68e 100644 --- a/src/hardware/center-3xx/protocol.c +++ b/src/hardware/center-3xx/protocol.c @@ -243,7 +243,7 @@ static int receive_data(int fd, int revents, int idx, void *cb_data) } if (sr_sw_limits_check(&devc->sw_limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 11721ebe..3ccac06b 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -43,8 +43,6 @@ static const int32_t trigger_matches[] = { SR_TRIGGER_FALLING, }; -static int dev_acquisition_stop(struct sr_dev_inst *sdi); - static void clear_helper(void *priv) { struct dev_context *devc; @@ -452,7 +450,7 @@ static int receive_data(int fd, int revents, void *cb_data) /* Get one block of data. */ if ((ret = cv_read_block(devc)) < 0) { sr_err("Failed to read data block: %d.", ret); - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return FALSE; } @@ -475,7 +473,7 @@ static int receive_data(int fd, int revents, void *cb_data) for (i = 0; i < NUM_BLOCKS; i++) cv_send_block_to_session_bus(sdi, i); - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } @@ -552,7 +550,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - sr_dbg("Stopping acquisition."); sr_session_source_remove(sdi->session, -1); std_session_send_df_end(sdi); diff --git a/src/hardware/colead-slm/protocol.c b/src/hardware/colead-slm/protocol.c index 2f6957ab..b577f236 100644 --- a/src/hardware/colead-slm/protocol.c +++ b/src/hardware/colead-slm/protocol.c @@ -177,7 +177,7 @@ static void process_packet(const struct sr_dev_inst *sdi) sr_sw_limits_update_samples_read(&devc->limits, 1); if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi); + sr_dev_acquisition_stop((struct sr_dev_inst *)sdi); } SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data) diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index cfa503d5..022e5330 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -171,8 +171,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; + (void)sdi; return SR_OK; } diff --git a/src/hardware/demo/api.c b/src/hardware/demo/api.c index f1a97eb4..5ab1f4af 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -532,7 +532,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - sr_dbg("Stopping acquisition."); sr_session_source_remove(sdi->session, -1); std_session_send_df_end(sdi); diff --git a/src/hardware/demo/protocol.c b/src/hardware/demo/protocol.c index 47000302..38943e43 100644 --- a/src/hardware/demo/protocol.c +++ b/src/hardware/demo/protocol.c @@ -446,7 +446,7 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data) if (devc->cur_samplerate <= 0 || (devc->num_logic_channels <= 0 && devc->num_analog_channels <= 0)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return G_SOURCE_CONTINUE; } @@ -539,7 +539,7 @@ SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data) } } sr_dbg("Requested number of samples reached."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } return G_SOURCE_CONTINUE; diff --git a/src/hardware/fluke-dmm/protocol.c b/src/hardware/fluke-dmm/protocol.c index 7500ab31..af4fd56c 100644 --- a/src/hardware/fluke-dmm/protocol.c +++ b/src/hardware/fluke-dmm/protocol.c @@ -526,7 +526,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 0927d3a2..240aa7ad 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -462,10 +462,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - - sr_dbg("Stopping acquisition."); sr_session_source_remove(sdi->session, -1); std_session_send_df_end(sdi); diff --git a/src/hardware/ftdi-la/protocol.c b/src/hardware/ftdi-la/protocol.c index 8d81d877..264b4f22 100644 --- a/src/hardware/ftdi-la/protocol.c +++ b/src/hardware/ftdi-la/protocol.c @@ -79,7 +79,7 @@ SR_PRIV int ftdi_la_receive_data(int fd, int revents, void *cb_data) if (bytes_read < 0) { sr_err("Failed to read FTDI data (%d): %s.", bytes_read, ftdi_get_error_string(devc->ftdic)); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return FALSE; } if (bytes_read == 0) { @@ -94,7 +94,7 @@ SR_PRIV int ftdi_la_receive_data(int fd, int revents, void *cb_data) if (devc->limit_samples && (n >= devc->limit_samples)) { send_samples(sdi, devc->limit_samples - devc->samples_sent); sr_info("Requested number of samples reached."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } else { send_samples(sdi, devc->bytes_received); diff --git a/src/hardware/gmc-mh-1x-2x/protocol.c b/src/hardware/gmc-mh-1x-2x/protocol.c index 10fe9c09..2911b82f 100644 --- a/src/hardware/gmc-mh-1x-2x/protocol.c +++ b/src/hardware/gmc-mh-1x-2x/protocol.c @@ -1175,7 +1175,7 @@ SR_PRIV int gmc_mh_1x_2x_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } @@ -1218,7 +1218,7 @@ SR_PRIV int gmc_mh_2x_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); /* Request next data set, if required */ if (sdi->status == SR_ST_ACTIVE) { diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index 99c29a3e..7e947466 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -220,11 +220,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) scpi = sdi->conn; devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) { - sr_err("Device inactive, can't stop acquisition."); - return SR_ERR; - } - if (devc->df_started) { packet.type = SR_DF_FRAME_END; sr_session_send(sdi, &packet); diff --git a/src/hardware/gwinstek-gds-800/protocol.c b/src/hardware/gwinstek-gds-800/protocol.c index 604ec54f..962bfe05 100644 --- a/src/hardware/gwinstek-gds-800/protocol.c +++ b/src/hardware/gwinstek-gds-800/protocol.c @@ -35,7 +35,7 @@ static int read_data(struct sr_dev_inst *sdi, data_size - devc->cur_rcv_buffer_position); if (len < 0) { sr_err("Read data error."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); devc->cur_rcv_buffer_position = 0; return SR_ERR; } @@ -55,7 +55,7 @@ static int read_data(struct sr_dev_inst *sdi, return SR_OK; } else { sr_err("Too many bytes read."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); devc->cur_rcv_buffer_position = 0; return SR_ERR; } @@ -96,17 +96,17 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) case START_ACQUISITION: if (sr_scpi_send(scpi, ":TRIG:MOD 3") != SR_OK) { sr_err("Failed to set trigger mode to SINGLE."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } if (sr_scpi_send(scpi, ":STOP") != SR_OK) { sr_err("Failed to put the trigger system into STOP state."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } if (sr_scpi_send(scpi, ":RUN") != SR_OK) { sr_err("Failed to put the trigger system into RUN state."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } @@ -117,12 +117,12 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) if (((struct sr_channel *)g_slist_nth_data(sdi->channels, devc->cur_acq_channel))->enabled) { if (sr_scpi_send(scpi, ":ACQ%d:MEM?", devc->cur_acq_channel+1) != SR_OK) { sr_err("Failed to acquire memory."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } if (sr_scpi_read_begin(scpi) != SR_OK) { sr_err("Could not begin reading SCPI response."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } devc->state = WAIT_FOR_TRANSFER_OF_BEGIN_TRANSMISSION_COMPLETE; @@ -136,7 +136,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) /* All frames accquired. */ sr_spew("All frames acquired."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } else { /* Start acquiring next frame. */ @@ -170,7 +170,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) devc->rcv_buffer[0] != '6') { sr_err("Data size digits is not 4, 5 or 6 but " "'%c'.", devc->rcv_buffer[0]); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } else { devc->data_size_digits = devc->rcv_buffer[0] - '0'; @@ -183,7 +183,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) devc->rcv_buffer[devc->data_size_digits] = 0; if (sr_atoi(devc->rcv_buffer, &devc->data_size) != SR_OK) { sr_err("Could not parse data size '%s'", devc->rcv_buffer); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } else devc->state = WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE; @@ -224,7 +224,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) devc->cur_acq_channel + 1); if (sr_scpi_get_string(scpi, command, &response) != SR_OK) { sr_err("Failed to get volts per division."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } volts_per_division = g_ascii_strtod(response, &end_ptr); @@ -264,7 +264,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) if (devc->cur_acq_frame == devc->frame_limit - 1) { /* All frames acquired. */ sr_spew("All frames acquired."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } else { /* Start acquiring next frame. */ diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 89042da7..8a4212af 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -811,9 +811,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) std_session_send_df_end(sdi); - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->num_frames = 0; diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index f44db1a2..12e79c47 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -1018,7 +1018,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) * the first enabled channel. */ if (++devc->num_frames == devc->frame_limit) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); hmo_cleanup_logic_data(devc); } else { devc->current_channel = devc->enabled_channels; diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index a6aa6854..025695e1 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -88,8 +88,6 @@ static const uint64_t vdivs[][2] = { static int read_channel(const struct sr_dev_inst *sdi, uint32_t amount); -static int dev_acquisition_stop(struct sr_dev_inst *sdi); - static struct sr_dev_inst *hantek_6xxx_dev_new(const struct hantek_6xxx_profile *prof) { struct sr_dev_inst *sdi; @@ -709,7 +707,7 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) PRIu64 " <= %" PRIu64, devc->limit_samples, devc->samp_received); send_data(sdi, devc->sample_buf, devc->limit_samples); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else if (devc->limit_msec && (g_get_monotonic_time() - devc->aq_started) / 1000 >= devc->limit_msec) { sr_info("Requested time limit reached, stopping. %d <= %d", @@ -718,7 +716,7 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) send_data(sdi, devc->sample_buf, devc->samp_received); g_free(devc->sample_buf); devc->sample_buf = NULL; - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else { read_channel(sdi, data_amount(sdi)); } @@ -818,9 +816,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; - devc = sdi->priv; devc->dev_state = STOPPING; diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index 6a6aa09d..f5e7383d 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -161,8 +161,6 @@ static const char *coupling[] = { "GND", }; -static int dev_acquisition_stop(struct sr_dev_inst *sdi); - static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof) { struct sr_dev_inst *sdi; @@ -984,9 +982,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR; - devc = sdi->priv; devc->dev_state = STOPPING; diff --git a/src/hardware/hp-3457a/protocol.c b/src/hardware/hp-3457a/protocol.c index dd8d6f8f..aa8ab528 100644 --- a/src/hardware/hp-3457a/protocol.c +++ b/src/hardware/hp-3457a/protocol.c @@ -435,7 +435,7 @@ SR_PRIV int hp_3457a_receive_data(int fd, int revents, void *cb_data) ret = sr_scpi_get_double(scpi, NULL, &devc->last_channel_sync); if (ret != SR_OK) { sr_err("Cannot check channel synchronization."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return FALSE; } devc->acq_state = ACQ_GOT_CHANNEL_SYNC; @@ -456,7 +456,7 @@ SR_PRIV int hp_3457a_receive_data(int fd, int revents, void *cb_data) sr_err("Expected channel %u, but device says %u", chanc->index, (unsigned int)devc->last_channel_sync); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return FALSE; } /* All is good. Back to business. */ @@ -464,7 +464,7 @@ SR_PRIV int hp_3457a_receive_data(int fd, int revents, void *cb_data) } if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return FALSE; } diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index bad92c00..0ed79959 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -692,11 +692,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return SR_OK; } -SR_PRIV int hung_chang_dso_2100_dev_acquisition_stop(const struct sr_dev_inst *sdi) +static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - std_session_send_df_end(sdi); sr_session_source_remove(sdi->session, -1); hung_chang_dso_2100_move_to(sdi, 1); @@ -704,11 +701,6 @@ SR_PRIV int hung_chang_dso_2100_dev_acquisition_stop(const struct sr_dev_inst *s return SR_OK; } -static int dev_acquisition_stop(struct sr_dev_inst *sdi) -{ - return hung_chang_dso_2100_dev_acquisition_stop(sdi); -} - static struct sr_dev_driver hung_chang_dso_2100_driver_info = { .name = "hung-chang-dso-2100", .longname = "Hung-Chang DSO-2100", diff --git a/src/hardware/hung-chang-dso-2100/protocol.c b/src/hardware/hung-chang-dso-2100/protocol.c index 160e5a0c..69efb14d 100644 --- a/src/hardware/hung-chang-dso-2100/protocol.c +++ b/src/hardware/hung-chang-dso-2100/protocol.c @@ -420,7 +420,7 @@ static int read_subframe(const struct sr_dev_inst *sdi, uint8_t *buf) SR_PRIV int hung_chang_dso_2100_poll(int fd, int revents, void *cb_data) { struct sr_datafeed_packet packet = { .type = SR_DF_FRAME_BEGIN }; - const struct sr_dev_inst *sdi; + struct sr_dev_inst *sdi; struct dev_context *devc; uint8_t state, buf[1000]; @@ -464,7 +464,7 @@ SR_PRIV int hung_chang_dso_2100_poll(int fd, int revents, void *cb_data) sr_session_send(sdi, &packet); if (++devc->frame >= devc->frame_limit) - hung_chang_dso_2100_dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); else hung_chang_dso_2100_move_to(sdi, 0x21); diff --git a/src/hardware/hung-chang-dso-2100/protocol.h b/src/hardware/hung-chang-dso-2100/protocol.h index f210b650..7168bd69 100644 --- a/src/hardware/hung-chang-dso-2100/protocol.h +++ b/src/hardware/hung-chang-dso-2100/protocol.h @@ -63,6 +63,5 @@ SR_PRIV void hung_chang_dso_2100_write_mbox(struct parport *port, uint8_t val); SR_PRIV uint8_t hung_chang_dso_2100_read_mbox(struct parport *port, float timeout); SR_PRIV int hung_chang_dso_2100_move_to(const struct sr_dev_inst *sdi, uint8_t target); SR_PRIV int hung_chang_dso_2100_poll(int fd, int revents, void *cb_data); -SR_PRIV int hung_chang_dso_2100_dev_acquisition_stop(const struct sr_dev_inst *sdi); #endif diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index c82422a5..9ffd60da 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -443,11 +443,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - - sr_dbg("Stopping acquisition."); - sdi->status = SR_ST_STOPPING; return SR_OK; diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 4a9491b8..439116cc 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -43,8 +43,6 @@ static const char *channel_names[] = { /* Note: The IKALOGIC ScanaPLUS always samples at 100MHz. */ static const uint64_t samplerates[1] = { SR_MHZ(100) }; -static int dev_acquisition_stop(struct sr_dev_inst *sdi); - static void clear_helper(void *priv) { struct dev_context *devc; @@ -358,7 +356,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - sr_dbg("Stopping acquisition."); sr_session_source_remove(sdi->session, -1); std_session_send_df_end(sdi); diff --git a/src/hardware/ikalogic-scanaplus/protocol.c b/src/hardware/ikalogic-scanaplus/protocol.c index 39dcfa2c..c0e25362 100644 --- a/src/hardware/ikalogic-scanaplus/protocol.c +++ b/src/hardware/ikalogic-scanaplus/protocol.c @@ -319,7 +319,7 @@ SR_PRIV int scanaplus_receive_data(int fd, int revents, void *cb_data) if (bytes_read < 0) { sr_err("Failed to read FTDI data (%d): %s.", bytes_read, ftdi_get_error_string(devc->ftdic)); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return FALSE; } if (bytes_read == 0) { @@ -358,12 +358,12 @@ SR_PRIV int scanaplus_receive_data(int fd, int revents, void *cb_data) if (devc->limit_samples && (n >= devc->limit_samples)) { send_samples(sdi, devc->limit_samples - devc->samples_sent); sr_info("Requested number of samples reached."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } else if (devc->limit_msec && (n >= max)) { send_samples(sdi, max - devc->samples_sent); sr_info("Requested time limit reached."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } else { send_samples(sdi, devc->bytes_received / 2); diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 30bb1b2a..2d1f97df 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -478,9 +478,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - /* Signal USB transfer handler to clean up and stop. */ sdi->status = SR_ST_STOPPING; diff --git a/src/hardware/kecheng-kc-330b/protocol.c b/src/hardware/kecheng-kc-330b/protocol.c index 886be6f7..1ee5c5e2 100644 --- a/src/hardware/kecheng-kc-330b/protocol.c +++ b/src/hardware/kecheng-kc-330b/protocol.c @@ -67,7 +67,7 @@ SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data) if (ret != 0 || len != 1) { sr_dbg("Failed to request new acquisition: %s", libusb_error_name(ret)); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } libusb_submit_transfer(devc->xfer); @@ -88,7 +88,7 @@ SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data) if (ret != 0 || len != 4) { sr_dbg("Failed to request next chunk: %s", libusb_error_name(ret)); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } libusb_submit_transfer(devc->xfer); @@ -135,7 +135,7 @@ SR_PRIV void LIBUSB_CALL kecheng_kc_330b_receive_transfer(struct libusb_transfer switch (transfer->status) { case LIBUSB_TRANSFER_NO_DEVICE: /* USB device was unplugged. */ - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return; case LIBUSB_TRANSFER_COMPLETED: case LIBUSB_TRANSFER_TIMED_OUT: /* We may have received some data though */ @@ -156,7 +156,7 @@ SR_PRIV void LIBUSB_CALL kecheng_kc_330b_receive_transfer(struct libusb_transfer send_data(sdi, fvalue, 1); devc->num_samples++; if (devc->limit_samples && devc->num_samples >= devc->limit_samples) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else { /* let USB event handler fire off another * request when the time is right. */ @@ -176,7 +176,7 @@ SR_PRIV void LIBUSB_CALL kecheng_kc_330b_receive_transfer(struct libusb_transfer send_data(sdi, fvalue, 1); devc->num_samples += num_samples; if (devc->num_samples >= devc->stored_samples) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else { /* let USB event handler fire off another * request when the time is right. */ diff --git a/src/hardware/kern-scale/protocol.c b/src/hardware/kern-scale/protocol.c index 97b557f9..5d3541df 100644 --- a/src/hardware/kern-scale/protocol.c +++ b/src/hardware/kern-scale/protocol.c @@ -125,7 +125,7 @@ SR_PRIV int kern_scale_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/korad-kaxxxxp/protocol.c b/src/hardware/korad-kaxxxxp/protocol.c index 4705403f..4aacd7cd 100644 --- a/src/hardware/korad-kaxxxxp/protocol.c +++ b/src/hardware/korad-kaxxxxp/protocol.c @@ -387,7 +387,7 @@ SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 96ed3616..5ee1d22a 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -395,13 +395,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) return SR_OK; } -SR_PRIV int dev_acquisition_stop(struct sr_dev_inst *sdi) +static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) { - sr_err("Device inactive, can't stop acquisition."); - return SR_ERR; - } - sdi->status = SR_ST_STOPPING; /* TODO: free ongoing transfers? */ diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c index fc24fbe7..03fbf252 100644 --- a/src/hardware/lascar-el-usb/protocol.c +++ b/src/hardware/lascar-el-usb/protocol.c @@ -528,7 +528,7 @@ SR_PRIV void LIBUSB_CALL lascar_el_usb_receive_transfer(struct libusb_transfer * switch (transfer->status) { case LIBUSB_TRANSFER_NO_DEVICE: /* USB device was unplugged. */ - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return; case LIBUSB_TRANSFER_COMPLETED: case LIBUSB_TRANSFER_TIMED_OUT: /* We may have received some data though */ @@ -547,7 +547,7 @@ SR_PRIV void LIBUSB_CALL lascar_el_usb_receive_transfer(struct libusb_transfer * devc->rcvd_bytes, devc->log_size, devc->rcvd_samples, devc->logged_samples); if (devc->rcvd_bytes >= devc->log_size) - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } if (sdi->status == SR_ST_ACTIVE) { @@ -557,7 +557,7 @@ SR_PRIV void LIBUSB_CALL lascar_el_usb_receive_transfer(struct libusb_transfer * libusb_error_name(ret)); g_free(transfer->buffer); libusb_free_transfer(transfer); - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } } else { /* This was the last transfer we're going to receive, so diff --git a/src/hardware/lascar-el-usb/protocol.h b/src/hardware/lascar-el-usb/protocol.h index c4eec74b..9e7b7167 100644 --- a/src/hardware/lascar-el-usb/protocol.h +++ b/src/hardware/lascar-el-usb/protocol.h @@ -79,6 +79,5 @@ SR_PRIV void LIBUSB_CALL lascar_el_usb_receive_transfer(struct libusb_transfer * SR_PRIV int lascar_start_logging(const struct sr_dev_inst *sdi); SR_PRIV int lascar_stop_logging(const struct sr_dev_inst *sdi); SR_PRIV int lascar_is_logging(const struct sr_dev_inst *sdi); -SR_PRIV int dev_acquisition_stop(struct sr_dev_inst *sdi); #endif diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index db423e4b..95c044f1 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -488,9 +488,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - return lls_stop_acquisition(sdi); } diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 9dfb0b64..2d4acf97 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -616,9 +616,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) std_session_send_df_end(sdi); - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->num_frames = 0; diff --git a/src/hardware/lecroy-xstream/protocol.c b/src/hardware/lecroy-xstream/protocol.c index ec7e958c..18c02061 100644 --- a/src/hardware/lecroy-xstream/protocol.c +++ b/src/hardware/lecroy-xstream/protocol.c @@ -662,7 +662,7 @@ SR_PRIV int lecroy_xstream_receive_data(int fd, int revents, void *cb_data) * the first enabled channel. */ if (++devc->num_frames == devc->frame_limit) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else { devc->current_channel = devc->enabled_channels; lecroy_xstream_request_data(sdi); diff --git a/src/hardware/link-mso19/protocol.c b/src/hardware/link-mso19/protocol.c index 29aacbda..b0cb2d8a 100644 --- a/src/hardware/link-mso19/protocol.c +++ b/src/hardware/link-mso19/protocol.c @@ -405,7 +405,7 @@ SR_PRIV int mso_receive_data(int fd, int revents, void *cb_data) if (devc->limit_samples && devc->num_samples >= devc->limit_samples) { sr_info("Requested number of samples reached."); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } return TRUE; diff --git a/src/hardware/manson-hcs-3xxx/protocol.c b/src/hardware/manson-hcs-3xxx/protocol.c index d36e2504..19d58180 100644 --- a/src/hardware/manson-hcs-3xxx/protocol.c +++ b/src/hardware/manson-hcs-3xxx/protocol.c @@ -236,7 +236,7 @@ SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index 3ded72e9..127830cd 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -455,9 +455,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { struct sr_modbus_dev_inst *modbus; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - std_session_send_df_end(sdi); modbus = sdi->conn; diff --git a/src/hardware/maynuo-m97/protocol.c b/src/hardware/maynuo-m97/protocol.c index 04fa2948..c369fa6c 100644 --- a/src/hardware/maynuo-m97/protocol.c +++ b/src/hardware/maynuo-m97/protocol.c @@ -196,7 +196,7 @@ SR_PRIV int maynuo_m97_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/mic-985xx/protocol.c b/src/hardware/mic-985xx/protocol.c index 65490537..af567ebd 100644 --- a/src/hardware/mic-985xx/protocol.c +++ b/src/hardware/mic-985xx/protocol.c @@ -210,7 +210,7 @@ static int receive_data(int fd, int revents, int idx, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/motech-lps-30x/protocol.c b/src/hardware/motech-lps-30x/protocol.c index 4de6f0e9..867cbb45 100644 --- a/src/hardware/motech-lps-30x/protocol.c +++ b/src/hardware/motech-lps-30x/protocol.c @@ -193,7 +193,7 @@ SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); /* Only request the next packet if required. */ if (!((sdi->status == SR_ST_ACTIVE) && (devc->acq_running))) diff --git a/src/hardware/norma-dmm/protocol.c b/src/hardware/norma-dmm/protocol.c index de31828a..804fc36e 100644 --- a/src/hardware/norma-dmm/protocol.c +++ b/src/hardware/norma-dmm/protocol.c @@ -417,7 +417,7 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) { - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else { /* Request next package. */ if (devc->last_req_pending) { diff --git a/src/hardware/pce-322a/protocol.c b/src/hardware/pce-322a/protocol.c index 6dc9deeb..90c1986b 100644 --- a/src/hardware/pce-322a/protocol.c +++ b/src/hardware/pce-322a/protocol.c @@ -82,7 +82,7 @@ static void send_data(const struct sr_dev_inst *sdi, float sample) devc->num_samples++; /* Limiting number of samples is only supported for live data. */ if (devc->cur_data_source == DATA_SOURCE_LIVE && devc->limit_samples && devc->num_samples >= devc->limit_samples) - sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi); + sr_dev_acquisition_stop((struct sr_dev_inst *)sdi); } static void process_measurement(const struct sr_dev_inst *sdi) diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 269b99f7..bf743606 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -682,7 +682,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) devc = sdi->priv; - sr_dbg("Stopping acquisition."); write_shortcommand(devc, CMD_RESET); write_shortcommand(devc, CMD_RESET); write_shortcommand(devc, CMD_RESET); diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c index 9948944d..8276a9ed 100644 --- a/src/hardware/pipistrello-ols/protocol.c +++ b/src/hardware/pipistrello-ols/protocol.c @@ -424,7 +424,7 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data) if (bytes_read < 0) { sr_err("Failed to read FTDI data (%d): %s.", bytes_read, ftdi_get_error_string(devc->ftdic)); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return FALSE; } if (bytes_read == 0) { @@ -672,7 +672,7 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data) } g_free(devc->raw_sample_buf); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } return TRUE; diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index f58d150d..296d8677 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -1119,11 +1119,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) { - sr_err("Device inactive, can't stop acquisition."); - return SR_ERR; - } - std_session_send_df_end(sdi); g_slist_free(devc->enabled_channels); diff --git a/src/hardware/rigol-ds/protocol.c b/src/hardware/rigol-ds/protocol.c index 39462c28..833104e8 100644 --- a/src/hardware/rigol-ds/protocol.c +++ b/src/hardware/rigol-ds/protocol.c @@ -634,7 +634,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) sr_err("Read error, aborting capture."); packet.type = SR_DF_FRAME_END; sr_session_send(sdi, &packet); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } /* At slow timebases in live capture the DS2072 @@ -667,7 +667,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) sr_err("Read error, aborting capture."); packet.type = SR_DF_FRAME_END; sr_session_send(sdi, &packet); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } @@ -727,7 +727,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) sr_err("Read should have been completed"); packet.type = SR_DF_FRAME_END; sr_session_send(sdi, &packet); - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } devc->num_block_read = 0; @@ -765,7 +765,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) if (++devc->num_frames == devc->limit_frames) { /* Last frame, stop capture. */ - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else { /* Get the next frame, starting with the first channel. */ devc->channel_entry = devc->enabled_channels; diff --git a/src/hardware/saleae-logic-pro/api.c b/src/hardware/saleae-logic-pro/api.c index 8be8fb50..1648c952 100644 --- a/src/hardware/saleae-logic-pro/api.c +++ b/src/hardware/saleae-logic-pro/api.c @@ -399,9 +399,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) struct dev_context *devc = sdi->priv; struct drv_context *drvc = sdi->driver->context; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - saleae_logic_pro_stop(sdi); std_session_send_df_end(sdi); diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index e6b752d1..f7430c21 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -775,9 +775,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) { int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - ret = logic16_abort_acquisition(sdi); abort_acquisition(sdi->priv); diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index 57bdcb81..c6bd3e59 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -678,9 +678,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) struct sr_scpi_dev_inst *scpi; float f; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - scpi = sdi->conn; /* diff --git a/src/hardware/serial-dmm/protocol.c b/src/hardware/serial-dmm/protocol.c index 1d1ca482..39bd965b 100644 --- a/src/hardware/serial-dmm/protocol.c +++ b/src/hardware/serial-dmm/protocol.c @@ -188,7 +188,7 @@ int receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 2b20db83..1da4b00e 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -759,12 +759,9 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - if (devc->state != STATE_IDLE && !devc->cancel_requested) { devc->cancel_requested = TRUE; - sr_dbg("Stopping acquisition."); + sr_dbg("Requesting cancel."); } return SR_OK; diff --git a/src/hardware/teleinfo/protocol.c b/src/hardware/teleinfo/protocol.c index 88fbfac3..d42da22b 100644 --- a/src/hardware/teleinfo/protocol.c +++ b/src/hardware/teleinfo/protocol.c @@ -221,7 +221,7 @@ SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->sw_limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 90f589d7..d04cce6f 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -22,7 +22,6 @@ #include "protocol.h" #define SERIALCOMM "115200/8n1" -static int dev_acquisition_stop(struct sr_dev_inst *sdi); static const uint32_t scanopts[] = { SR_CONF_CONN, @@ -285,7 +284,7 @@ static void receive_data(struct sr_dev_inst *sdi, unsigned char *data, int len) devc->reply_size = 0; if (sr_sw_limits_check(&devc->sw_limits)) - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); else testo_request_packet(sdi); @@ -305,7 +304,7 @@ SR_PRIV void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE) { /* USB device was unplugged. */ - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { /* First two bytes in any transfer are FTDI status bytes. */ if (transfer->actual_length > 2) @@ -320,7 +319,7 @@ SR_PRIV void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) libusb_error_name(ret)); g_free(transfer->buffer); libusb_free_transfer(transfer); - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } } else { /* This was the last transfer we're going to receive, so @@ -347,7 +346,7 @@ static int handle_events(int fd, int revents, void *cb_data) drvc = di->context; if (sr_sw_limits_check(&devc->sw_limits)) - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); if (sdi->status == SR_ST_STOPPING) { usb_source_remove(sdi->session, drvc->sr_ctx); @@ -412,9 +411,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - sdi->status = SR_ST_STOPPING; return SR_OK; diff --git a/src/hardware/testo/protocol.c b/src/hardware/testo/protocol.c index 92bb286e..3fc7806f 100644 --- a/src/hardware/testo/protocol.c +++ b/src/hardware/testo/protocol.c @@ -158,7 +158,7 @@ SR_PRIV int testo_request_packet(const struct sr_dev_inst *sdi) receive_transfer, (void *)sdi, 100); if ((ret = libusb_submit_transfer(devc->out_transfer) != 0)) { sr_err("Failed to request packet: %s.", libusb_error_name(ret)); - sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi); + sr_dev_acquisition_stop((struct sr_dev_inst *)sdi); return SR_ERR; } sr_dbg("Requested new packet."); diff --git a/src/hardware/tondaj-sl-814/protocol.c b/src/hardware/tondaj-sl-814/protocol.c index 58916165..13f04305 100644 --- a/src/hardware/tondaj-sl-814/protocol.c +++ b/src/hardware/tondaj-sl-814/protocol.c @@ -205,7 +205,7 @@ SR_PRIV int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data) } if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index 2a2fc663..c6e0dd9a 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -171,7 +171,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - sr_dbg("Stopping acquisition."); std_session_send_df_end(sdi); sr_session_source_remove(sdi->session, -1); diff --git a/src/hardware/uni-t-dmm/protocol.c b/src/hardware/uni-t-dmm/protocol.c index c0ed21f3..6dc8980e 100644 --- a/src/hardware/uni-t-dmm/protocol.c +++ b/src/hardware/uni-t-dmm/protocol.c @@ -290,7 +290,7 @@ SR_PRIV int uni_t_dmm_receive_data(int fd, int revents, void *cb_data) /* Abort acquisition if we acquired enough samples. */ if (sr_sw_limits_check(&devc->limits)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index 25f142b4..2df113c3 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -296,9 +296,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - /* Signal USB transfer handler to clean up and stop. */ sdi->status = SR_ST_STOPPING; diff --git a/src/hardware/uni-t-ut32x/protocol.c b/src/hardware/uni-t-ut32x/protocol.c index a5d6f62b..6e04dd9b 100644 --- a/src/hardware/uni-t-ut32x/protocol.c +++ b/src/hardware/uni-t-ut32x/protocol.c @@ -140,10 +140,8 @@ static void process_packet(struct sr_dev_inst *sdi) * a sample limit on "Memory" data source still works: unused * memory slots come through as "----" measurements. */ devc->num_samples++; - if (devc->limit_samples && devc->num_samples >= devc->limit_samples) { - sdi->driver->dev_acquisition_stop(sdi); - } - + if (devc->limit_samples && devc->num_samples >= devc->limit_samples) + sr_dev_acquisition_stop(sdi); } SR_PRIV void LIBUSB_CALL uni_t_ut32x_receive_transfer(struct libusb_transfer *transfer) diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index ff0302d9..1ea102ce 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -32,8 +32,6 @@ #define VICTOR_INTERFACE 0 #define VICTOR_ENDPOINT (LIBUSB_ENDPOINT_IN | 1) -static int dev_acquisition_stop(struct sr_dev_inst *sdi); - static const uint32_t drvopts[] = { SR_CONF_MULTIMETER, }; @@ -223,13 +221,13 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) devc = sdi->priv; if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE) { /* USB device was unplugged. */ - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } else if (transfer->status == LIBUSB_TRANSFER_COMPLETED) { sr_dbg("Got %d-byte packet.", transfer->actual_length); if (transfer->actual_length == DMM_DATA_SIZE) { victor_dmm_receive_data(sdi, transfer->buffer); if (sr_sw_limits_check(&devc->limits)) - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } } /* Anything else is either an error or a timeout, which is fine: @@ -242,7 +240,7 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) libusb_error_name(ret)); g_free(transfer->buffer); libusb_free_transfer(transfer); - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } } else { /* This was the last transfer we're going to receive, so @@ -269,7 +267,7 @@ static int handle_events(int fd, int revents, void *cb_data) drvc = di->context; if (sr_sw_limits_check(&devc->limits)) - dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); if (sdi->status == SR_ST_STOPPING) { usb_source_remove(sdi->session, drvc->sr_ctx); @@ -324,11 +322,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) static int dev_acquisition_stop(struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) { - sr_err("Device not active, can't stop acquisition."); - return SR_ERR; - } - sdi->status = SR_ST_STOPPING; return SR_OK; diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index c58906f8..e11587e6 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -660,9 +660,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi) std_session_send_df_end(sdi); - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->num_frames = 0; diff --git a/src/hardware/yokogawa-dlm/protocol.c b/src/hardware/yokogawa-dlm/protocol.c index cf885f7a..6955baae 100644 --- a/src/hardware/yokogawa-dlm/protocol.c +++ b/src/hardware/yokogawa-dlm/protocol.c @@ -1171,7 +1171,7 @@ SR_PRIV int dlm_data_receive(int fd, int revents, void *cb_data) * As of now we only support importing the current acquisition * data so we're going to stop at this point. */ - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } else devc->current_channel = devc->current_channel->next; diff --git a/src/hwdriver.c b/src/hwdriver.c index deff5a7b..6f467edb 100644 --- a/src/hwdriver.c +++ b/src/hwdriver.c @@ -592,6 +592,25 @@ SR_PRIV void sr_config_free(struct sr_config *src) } +/** @private */ +SR_PRIV int sr_dev_acquisition_stop(struct sr_dev_inst *sdi) +{ + if (!sdi || !sdi->driver) { + sr_err("%s: Invalid arguments.", __func__); + return SR_ERR_ARG; + } + + if (sdi->status != SR_ST_ACTIVE) { + sr_err("%s: Device instance not active, can't stop.", + sdi->driver->name); + return SR_ERR_DEV_CLOSED; + } + + sr_dbg("%s: Stopping acquisition.", sdi->driver->name); + + return sdi->driver->dev_acquisition_stop(sdi); +} + static void log_key(const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, uint32_t key, int op, GVariant *data) { diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index 3a987c62..9cd1c2da 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -731,7 +731,7 @@ static int receive_data(int fd, int revents, void *cb_data) if (dev_limit_counter_limit_reached(&devc->frame_count) || dev_time_limit_reached(&devc->time_count)) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); return TRUE; } diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 73e49ef4..d8610f82 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -834,6 +834,7 @@ SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *data); SR_PRIV void sr_hw_cleanup_all(const struct sr_context *ctx); SR_PRIV struct sr_config *sr_config_new(uint32_t key, GVariant *data); SR_PRIV void sr_config_free(struct sr_config *src); +SR_PRIV int sr_dev_acquisition_stop(struct sr_dev_inst *sdi); /*--- session.c -------------------------------------------------------------*/ diff --git a/src/session.c b/src/session.c index c88e48c7..1843fd17 100644 --- a/src/session.c +++ b/src/session.c @@ -830,7 +830,7 @@ SR_API int sr_session_start(struct sr_session *session) lend = l->next; for (l = session->devs; l != lend; l = l->next) { sdi = l->data; - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } /* TODO: Handle delayed stops. Need to iterate the event * sources... */ @@ -913,8 +913,7 @@ static gboolean session_stop_sync(void *user_data) for (node = session->devs; node; node = node->next) { sdi = node->data; - if (sdi->driver && sdi->driver->dev_acquisition_stop) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } return G_SOURCE_REMOVE; diff --git a/src/std.c b/src/std.c index 87b3f1f1..bd748914 100644 --- a/src/std.c +++ b/src/std.c @@ -217,13 +217,6 @@ SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi) const char *prefix = sdi->driver->name; int ret; - if (sdi->status != SR_ST_ACTIVE) { - sr_err("%s: Device inactive, can't stop acquisition.", prefix); - return SR_ERR_DEV_CLOSED; - } - - sr_dbg("%s: Stopping acquisition.", prefix); - if ((ret = serial_source_remove(sdi->session, serial)) < 0) { sr_err("%s: Failed to remove source: %d.", prefix, ret); return ret;