From: Uwe Hermann Date: Wed, 5 Jul 2017 20:37:10 +0000 (+0200) Subject: Add sr_dev_acquisition_start(), factor out SR_ERR_DEV_CLOSED check. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f670835f1fbc03525e995d6970a5495976ab7c1a;p=libsigrok.git Add sr_dev_acquisition_start(), 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/api.c b/src/hardware/agilent-dmm/api.c index aaba3281..ea67039d 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -311,9 +311,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc = sdi->priv; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc->cur_channel = sr_next_enabled_channel(sdi, NULL); devc->cur_conf = sr_next_enabled_channel(sdi, NULL); devc->cur_sample = 1; diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index 27fb992a..c287134f 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -200,9 +200,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; serial = sdi->conn; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/arachnid-labs-re-load-pro/api.c b/src/hardware/arachnid-labs-re-load-pro/api.c index 1a5281f8..88e8f52e 100644 --- a/src/hardware/arachnid-labs-re-load-pro/api.c +++ b/src/hardware/arachnid-labs-re-load-pro/api.c @@ -308,9 +308,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; serial = sdi->conn; diff --git a/src/hardware/asix-sigma/api.c b/src/hardware/asix-sigma/api.c index 4e3d32be..30d32da4 100644 --- a/src/hardware/asix-sigma/api.c +++ b/src/hardware/asix-sigma/api.c @@ -299,9 +299,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) uint8_t clock_bytes[sizeof(clockselect)]; size_t clock_idx; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; if (sigma_convert_trigger(sdi) != SR_OK) { diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 1768f842..9c43a78c 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -439,9 +439,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_serial_dev_inst *serial; uint8_t packet[PACKET_SIZE]; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; memset(devc->packet, 0x44, PACKET_SIZE); devc->packet_size = 0; diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index 8e0af46d..a1f149fc 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -316,9 +316,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) .it_value = { 0, 0 } }; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - if (dev_acquisition_open(sdi)) return SR_ERR; diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index c8e43730..734f477f 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -294,9 +294,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc = sdi->priv; struct sr_trigger *trigger; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - /* Clear capture state */ devc->bytes_read = 0; devc->offset = 0; diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index 484e1476..2edade93 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -210,9 +210,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) { struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->sw_limits); diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index 00ff6cf1..9c7b273e 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -160,9 +160,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->sw_limits); diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index 5b8bb94c..7ad8e610 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -346,9 +346,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->state = ST_INIT; devc->num_samples = 0; diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c index 44f07f4d..e826c59d 100644 --- a/src/hardware/center-3xx/api.c +++ b/src/hardware/center-3xx/api.c @@ -165,9 +165,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->sw_limits); diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 3ccac06b..e8a4afc3 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -484,9 +484,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) uint8_t buf[8]; int bytes_to_write, bytes_written; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; if (!devc->ftdic) { diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index 762cda19..f7a1c16f 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -123,9 +123,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc = sdi->priv; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - sr_sw_limits_acquisition_start(&devc->limits); std_session_send_df_header(sdi); diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index 022e5330..ec134d30 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -163,8 +163,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * static int dev_acquisition_start(const 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 5ab1f4af..92de2ce1 100644 --- a/src/hardware/demo/api.c +++ b/src/hardware/demo/api.c @@ -464,9 +464,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) GHashTableIter iter; void *value; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->sent_samples = 0; diff --git a/src/hardware/dreamsourcelab-dslogic/protocol.c b/src/hardware/dreamsourcelab-dslogic/protocol.c index b5ca61b7..0818e23f 100644 --- a/src/hardware/dreamsourcelab-dslogic/protocol.c +++ b/src/hardware/dreamsourcelab-dslogic/protocol.c @@ -1056,9 +1056,6 @@ SR_PRIV int dslogic_acquisition_start(const struct sr_dev_inst *sdi) struct libusb_transfer *transfer; int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - di = sdi->driver; drvc = di->context; devc = sdi->priv; diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index 0ee6c7fa..a706675a 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -221,9 +221,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 240aa7ad..7adbb7a3 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -439,9 +439,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - if (!devc->ftdic) return SR_ERR_BUG; diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index 95ce4bd3..a31231fd 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -683,9 +683,6 @@ SR_PRIV int fx2lafw_start_acquisition(const struct sr_dev_inst *sdi) int timeout, ret; size_t size; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - di = sdi->driver; drvc = di->context; devc = sdi->priv; diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 801429ce..71ab57d0 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -427,9 +427,6 @@ static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->settings_ok = FALSE; devc->buflen = 0; @@ -450,9 +447,6 @@ static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->settings_ok = FALSE; devc->buflen = 0; diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index 7e947466..d8b00f9a 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -199,9 +199,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) scpi = sdi->conn; devc = sdi->priv; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc->state = START_ACQUISITION; devc->cur_acq_frame = 0; diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 8a4212af..7b5a71db 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -727,9 +727,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_scpi_dev_inst *scpi; int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - scpi = sdi->conn; devc = sdi->priv; diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index 025695e1..e4e20e0a 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -784,9 +784,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc = di->context; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; if (configure_channels(sdi) != SR_OK) { diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index f5e7383d..119e8274 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -954,9 +954,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_dev_driver *di = sdi->driver; struct drv_context *drvc = di->context; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; if (configure_channels(sdi) != SR_OK) { diff --git a/src/hardware/hp-3457a/api.c b/src/hardware/hp-3457a/api.c index 3bcc723b..b3a91353 100644 --- a/src/hardware/hp-3457a/api.c +++ b/src/hardware/hp-3457a/api.c @@ -367,9 +367,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) GArray *ch_list; GSList *channels; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - scpi = sdi->conn; devc = sdi->priv; diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index 0ed79959..70b094a6 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -664,9 +664,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc = sdi->priv; int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - if (devc->channel) { static const float res_array[] = {0.5, 1, 2, 5}; static const uint8_t relays[] = {100, 10, 10, 1}; diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 9ffd60da..6acf4352 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -361,9 +361,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) unsigned int i, j; int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; drvc = di->context; diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index 439116cc..2105bce1 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -325,9 +325,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int ret; struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; if (!devc->ftdic) diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 2d1f97df..e99e0b19 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -380,9 +380,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int req_len, buf_len, len, ret; unsigned char buf[9]; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - drvc = di->context; devc = sdi->priv; usb = sdi->conn; diff --git a/src/hardware/kern-scale/api.c b/src/hardware/kern-scale/api.c index 167bf1bc..0f7b8709 100644 --- a/src/hardware/kern-scale/api.c +++ b/src/hardware/kern-scale/api.c @@ -152,9 +152,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; serial = sdi->conn; diff --git a/src/hardware/korad-kaxxxxp/api.c b/src/hardware/korad-kaxxxxp/api.c index fc57725c..c9b67766 100644 --- a/src/hardware/korad-kaxxxxp/api.c +++ b/src/hardware/korad-kaxxxxp/api.c @@ -344,9 +344,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 5ee1d22a..4a58f280 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -293,9 +293,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int ret; unsigned char cmd[3], resp[4], *buf; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - drvc = di->context; devc = sdi->priv; usb = sdi->conn; diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index 95c044f1..ebb92e1e 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -472,9 +472,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct drv_context *drvc; int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - drvc = sdi->driver->context; if ((ret = lls_start_acquisition(sdi)) < 0) diff --git a/src/hardware/lecroy-xstream/api.c b/src/hardware/lecroy-xstream/api.c index 2d4acf97..748fbd1e 100644 --- a/src/hardware/lecroy-xstream/api.c +++ b/src/hardware/lecroy-xstream/api.c @@ -553,9 +553,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int ret; struct sr_scpi_dev_inst *scpi; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; scpi = sdi->conn; /* Preset empty results. */ diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 7924b231..cf6514fb 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -330,9 +330,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; int ret = SR_ERR; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; if (mso_configure_channels(sdi) != SR_OK) { diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index ee478033..1808e033 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -353,9 +353,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index 127830cd..5c3a73c7 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -435,9 +435,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_modbus_dev_inst *modbus; int ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - modbus = sdi->conn; devc = sdi->priv; diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index d755bea7..3a924072 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -178,9 +178,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index 4ec35ff5..d5b55a81 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -764,9 +764,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->acq_running = TRUE; diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index eb2ba25c..1d1247e3 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -203,9 +203,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 5e74a523..5cf87c23 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -439,9 +439,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int num_ols_changrp; int ret, i; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; serial = sdi->conn; diff --git a/src/hardware/pce-322a/api.c b/src/hardware/pce-322a/api.c index b0f62505..e6c6fda0 100644 --- a/src/hardware/pce-322a/api.c +++ b/src/hardware/pce-322a/api.c @@ -328,9 +328,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; devc->buffer_len = 0; devc->memory_state = MEM_STATE_REQUEST_MEMORY_USAGE; diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index bf743606..33d965e5 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -523,9 +523,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int num_pols_changrp, samplespercount; int ret, i; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; pols_channel_mask(sdi); diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 296d8677..a2e32297 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -997,9 +997,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) gboolean some_digital; GSList *l; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - scpi = sdi->conn; devc = sdi->priv; diff --git a/src/hardware/rohde-schwarz-sme-0x/api.c b/src/hardware/rohde-schwarz-sme-0x/api.c index 7b971b2b..68c57ea9 100644 --- a/src/hardware/rohde-schwarz-sme-0x/api.c +++ b/src/hardware/rohde-schwarz-sme-0x/api.c @@ -265,8 +265,7 @@ static int config_list(uint32_t key, GVariant **data, static int dev_acquisition_start(const 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/saleae-logic-pro/api.c b/src/hardware/saleae-logic-pro/api.c index 1648c952..f448533e 100644 --- a/src/hardware/saleae-logic-pro/api.c +++ b/src/hardware/saleae-logic-pro/api.c @@ -348,9 +348,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) uint8_t *buf; unsigned int i, ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - ret = saleae_logic_pro_init(sdi); if (ret != SR_OK) return ret; diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index f7430c21..6538b75f 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -674,9 +674,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) unsigned char *buf; size_t size, convsize; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - drvc = di->context; devc = sdi->priv; usb = sdi->conn; diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index c6bd3e59..bdf4bffe 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -642,9 +642,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct pps_channel *pch; int cmd, ret; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; scpi = sdi->conn; diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index 47496465..a11a9b36 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -179,9 +179,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 1da4b00e..439d71f2 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -743,11 +743,6 @@ static int config_list(uint32_t key, GVariant **data, */ static int dev_acquisition_start(const struct sr_dev_inst *sdi) { - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - - sr_info("Starting acquisition."); - return lwla_start_acquisition(sdi); } diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index 4cfadf4b..41537f1b 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -163,9 +163,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct sr_serial_dev_inst *serial = sdi->conn; struct dev_context *devc; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; sr_sw_limits_acquisition_start(&devc->sw_limits); diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index d04cce6f..0ebab5d7 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -372,10 +372,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) unsigned char *buf; drvc = di->context; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - - devc = sdi->priv; usb = sdi->conn; devc->reply_size = 0; diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index 445b4274..804b57b3 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -133,9 +133,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc = sdi->priv; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - std_session_send_df_header(sdi); sr_sw_limits_acquisition_start(&devc->limits); diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index 2df113c3..a4d906d0 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -241,9 +241,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int len, ret; unsigned char cmd[2]; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - drvc = di->context; devc = sdi->priv; usb = sdi->conn; diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 1ea102ce..58a11f84 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -291,9 +291,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) int ret; unsigned char *buf; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - usb = sdi->conn; std_session_send_df_header(sdi); diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index e11587e6..891775cc 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -612,9 +612,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_scpi_dev_inst *scpi; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - scpi = sdi->conn; devc = sdi->priv; digital_added = FALSE; diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 3d0c3a41..c36e06ae 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -490,9 +490,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) unsigned int discard; int trigger_now; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; if (analyzer_add_triggers(sdi) != SR_OK) { diff --git a/src/hwdriver.c b/src/hwdriver.c index 6f467edb..b16dcd34 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_start(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 start.", + sdi->driver->name); + return SR_ERR_DEV_CLOSED; + } + + sr_dbg("%s: Starting acquisition.", sdi->driver->name); + + return sdi->driver->dev_acquisition_start(sdi); +} + /** @private */ SR_PRIV int sr_dev_acquisition_stop(struct sr_dev_inst *sdi) { diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index 9cd1c2da..fd26fd9e 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -909,9 +909,6 @@ SR_PRIV int es51919_serial_acquisition_start(const struct sr_dev_inst *sdi) struct dev_context *devc; struct sr_serial_dev_inst *serial; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - if (!(devc = sdi->priv)) return SR_ERR_BUG; diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index d8610f82..7dc3928a 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_start(struct sr_dev_inst *sdi); 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 1843fd17..ad39ddcf 100644 --- a/src/session.c +++ b/src/session.c @@ -365,7 +365,7 @@ SR_API int sr_session_dev_add(struct sr_session *session, sr_strerror(ret)); return ret; } - if ((ret = sdi->driver->dev_acquisition_start(sdi)) != SR_OK) { + if ((ret = sr_dev_acquisition_start(sdi)) != SR_OK) { sr_err("Failed to start acquisition of device in " "running session (%s)", sr_strerror(ret)); return ret; @@ -816,7 +816,7 @@ SR_API int sr_session_start(struct sr_session *session) ret = SR_ERR; break; } - ret = sdi->driver->dev_acquisition_start(sdi); + ret = sr_dev_acquisition_start(sdi); if (ret != SR_OK) { sr_err("Could not start %s device %s acquisition.", sdi->driver->name, sdi->connection_id); diff --git a/src/std.c b/src/std.c index bd748914..df7a1749 100644 --- a/src/std.c +++ b/src/std.c @@ -98,8 +98,6 @@ SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi) struct sr_datafeed_packet packet; struct sr_datafeed_header header; - sr_dbg("%s: Starting acquisition.", prefix); - /* Send header packet to the session bus. */ sr_dbg("%s: Sending SR_DF_HEADER packet.", prefix); packet.type = SR_DF_HEADER;