]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-4032l/protocol.c
hantek-4032l: Emit FPGA version log message.
[libsigrok.git] / src / hardware / hantek-4032l / protocol.c
index 2c28e173c35874ec47ef7a2d12edf972c463c429..fb18e8978a47cd0269a21bcda0851261361f762d 100644 (file)
@@ -35,8 +35,30 @@ struct h4032l_status_packet {
        uint32_t magic;
        uint32_t values;
        uint32_t status;
+       uint32_t usbxi_data;
+       uint32_t fpga_version;
 };
 
+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 +90,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);
 
@@ -93,6 +124,7 @@ void LIBUSB_CALL h4032l_usb_callback(struct libusb_transfer *transfer)
                 * First Transfer as next.
                 */
                status = (struct h4032l_status_packet *)transfer->buffer;
+               sr_dbg("FPGA version: 0x%x.", status->fpga_version);
                if (status->magic != H4032L_STATUS_PACKET_MAGIC) {
                        devc->status = H4032L_STATUS_RESPONSE_STATUS;
                } else if (status->status == 2) {
@@ -175,7 +207,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)