]> cvs.zerfleddert.de Git - hmcfgusb/blobdiff - hmcfgusb.c
make -R default, it doesn't hurt but may improve performance
[hmcfgusb] / hmcfgusb.c
index 1ba9b2412a7b2b5b685faef7beb73f6c71def49e..f35138f6d7bbe22cddb13bf1b55074de818fc161 100644 (file)
@@ -140,6 +140,20 @@ static libusb_device_handle *hmcfgusb_find() {
        return NULL;
 }
 
+int hmcfgusb_send_null_frame(struct hmcfgusb_dev *usbdev)
+{
+       int err;
+       int cnt;
+
+       err = libusb_interrupt_transfer(usbdev->usb_devh, EP_OUT, NULL, 0, &cnt, USB_TIMEOUT);
+       if (err) {
+               fprintf(stderr, "Can't send data: %s\n", usb_strerror(err));
+               return 0;
+       }
+
+       return 1;
+}
+
 int hmcfgusb_send(struct hmcfgusb_dev *usbdev, unsigned char* send_data, int len, int done)
 {
        int err;
@@ -149,9 +163,10 @@ int hmcfgusb_send(struct hmcfgusb_dev *usbdev, unsigned char* send_data, int len
 
        if (debug) {
                hexdump(send_data, len, "USB < ");
-               gettimeofday(&tv_start, NULL);
        }
 
+       gettimeofday(&tv_start, NULL);
+
        err = libusb_interrupt_transfer(usbdev->usb_devh, EP_OUT, send_data, len, &cnt, USB_TIMEOUT);
        if (err) {
                fprintf(stderr, "Can't send data: %s\n", usb_strerror(err));
@@ -159,17 +174,18 @@ int hmcfgusb_send(struct hmcfgusb_dev *usbdev, unsigned char* send_data, int len
        }
 
        if (done) {
-               err = libusb_interrupt_transfer(usbdev->usb_devh, EP_OUT, send_data, 0, &cnt, USB_TIMEOUT);
-               if (err) {
-                       fprintf(stderr, "Can't send data: %s\n", usb_strerror(err));
+               if (!hmcfgusb_send_null_frame(usbdev)) {
                        return 0;
                }
        }
 
-       if (debug) {
-               gettimeofday(&tv_end, NULL);
-               msec = ((tv_end.tv_sec-tv_start.tv_sec)*1000)+((tv_end.tv_usec-tv_start.tv_usec)/1000);
-               fprintf(stderr, "send took %dms!\n", msec);
+       gettimeofday(&tv_end, NULL);
+       msec = ((tv_end.tv_sec-tv_start.tv_sec)*1000)+((tv_end.tv_usec-tv_start.tv_usec)/1000);
+
+       if (msec > 100) {
+               fprintf(stderr, "usb-transfer took more than 100ms (%dms), this may lead to timing problems!\n", msec);
+       } else if (debug) {
+               fprintf(stderr, "usb-transfer took %dms!\n", msec);
        }
 
        return 1;
Impressum, Datenschutz