]> sigrok.org Git - libsigrok.git/blobdiff - hardware/testo/api.c
Add struct sr_session parameter to all session source backends.
[libsigrok.git] / hardware / testo / api.c
index 8dcdf1cb35d1c57d429510b2495e83a1c3ef289e..2b4c9634c09a75b83019e53a95b1e144bb83b941 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 #include <string.h>
-#include <libserialport.h>
 #include "protocol.h"
 
 #define SERIALCOMM "115200/8n1"
@@ -186,6 +185,16 @@ static int dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
+       if (libusb_has_capability(LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER)) {
+               if (libusb_kernel_driver_active(usb->devhdl, 0) == 1) {
+                       if ((ret = libusb_detach_kernel_driver(usb->devhdl, 0)) < 0) {
+                               sr_err("Failed to detach kernel driver: %s.",
+                                          libusb_error_name(ret));
+                               return SR_ERR;
+                       }
+               }
+       }
+
        if ((ret = libusb_claim_interface(usb->devhdl, 0))) {
                sr_err("Failed to claim interface: %s.", libusb_error_name(ret));
                return SR_ERR;
@@ -345,8 +354,7 @@ static void receive_data(struct sr_dev_inst *sdi, unsigned char *data, int len)
                return;
 
        crc = crc16_mcrf4xx(0xffff, devc->reply, devc->reply_size - 2);
-       if ((crc & 0xff) == devc->reply[devc->reply_size - 2]
-                       && (crc >> 8) == devc->reply[devc->reply_size - 1]) {
+       if (crc == RL16(&devc->reply[devc->reply_size - 2])) {
                testo_receive_packet(sdi);
                devc->num_samples++;
        } else {
@@ -422,7 +430,7 @@ static int handle_events(int fd, int revents, void *cb_data)
        }
 
        if (sdi->status == SR_ST_STOPPING) {
-               usb_source_remove(drvc->sr_ctx);
+               usb_source_remove(sdi->session, drvc->sr_ctx);
 
                dev_close(sdi);
 
@@ -465,7 +473,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
-       usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi);
+       usb_source_add(sdi->session, drvc->sr_ctx, 100,
+                       handle_events, (void *)sdi);
 
        if (testo_set_serial_params(usb) != SR_OK)
                return SR_ERR;