]> sigrok.org Git - libsigrok.git/commitdiff
hantek-4032l: Add option to abort acquisition.
authorAndrej Valek <redacted>
Wed, 4 Apr 2018 20:59:52 +0000 (22:59 +0200)
committerUwe Hermann <redacted>
Sun, 22 Apr 2018 09:16:34 +0000 (11:16 +0200)
Signed-off-by: Andrej Valek <redacted>
src/hardware/hantek-4032l/api.c
src/hardware/hantek-4032l/protocol.c
src/hardware/hantek-4032l/protocol.h

index 087cd253afdd5cc220fe0d60fefe283d7974f4b0..cf01e2997ed286085c9c064baaa832086dc36268 100644 (file)
@@ -400,6 +400,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct sr_trigger *trigger = sr_session_trigger_get(sdi->session);
        struct h4032l_cmd_pkt *cmd_pkt = &devc->cmd_pkt;
 
+       devc->acq_aborted = FALSE;
+
        /* Calculate packet ratio. */
        cmd_pkt->pre_trigger_size = (cmd_pkt->sample_size * devc->capture_ratio) / 100;
 
@@ -501,9 +503,13 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
-       (void)sdi;
+       struct dev_context *devc = sdi->priv;
+
+       devc->acq_aborted = TRUE;
+       if (devc->usb_transfer)
+               libusb_cancel_transfer(devc->usb_transfer);
 
-       /* TODO: stop acquisition. */
+       devc->status = H4032L_STATUS_IDLE;
 
        return SR_OK;
 }
index 2c28e173c35874ec47ef7a2d12edf972c463c429..7a2aa56c70f8f4ebeb47c29806e0494436a9e03a 100644 (file)
@@ -37,6 +37,26 @@ struct h4032l_status_packet {
        uint32_t status;
 };
 
+static void finish_acquisition(struct sr_dev_inst *sdi)
+{
+       struct drv_context *drvc = sdi->driver->context;
+
+       std_session_send_df_end(sdi);
+       usb_source_remove(sdi->session, drvc->sr_ctx);
+}
+
+static void free_transfer(struct libusb_transfer *transfer)
+{
+       struct sr_dev_inst *sdi = transfer->user_data;
+       struct dev_context *devc = sdi->priv;
+
+       transfer->buffer = NULL;
+       libusb_free_transfer(transfer);
+       devc->usb_transfer = NULL;
+
+       finish_acquisition(sdi);
+}
+
 SR_PRIV int h4032l_receive_data(int fd, int revents, void *cb_data)
 {
        struct timeval tv;
@@ -68,6 +88,15 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer)
        uint32_t number_samples;
        int ret;
 
+       /*
+        * If acquisition has already ended, just free any queued up
+        * transfers that come in.
+        */
+       if (devc->acq_aborted) {
+               free_transfer(transfer);
+               return;
+       }
+
        if (transfer->status != LIBUSB_TRANSFER_COMPLETED)
                sr_dbg("%s error: %d.", __func__, transfer->status);
 
@@ -175,7 +204,7 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer)
        }
 
        if (devc->status == H4032L_STATUS_IDLE)
-               libusb_free_transfer(transfer);
+               free_transfer(transfer);
 }
 
 uint16_t h4032l_voltage2pwm(double voltage)
index 7328f5cb602b00b1d04dac577cf740221c17abdd..8ebcbaa884b259ba0e143c94666d839fc6034f57 100644 (file)
@@ -121,6 +121,7 @@ struct h4032l_cmd_pkt {
 struct dev_context {
        enum h4032l_status status;
        uint32_t remaining_samples;
+       gboolean acq_aborted;
        struct h4032l_cmd_pkt cmd_pkt;
        struct libusb_transfer *usb_transfer;
        uint8_t buffer[512];