@@ -299,6 +299,43 @@ int QUsbEndpointPrivate::writeUsb(const char *data, qint64 maxSize)
299
299
return rc;
300
300
}
301
301
302
+ int QUsbEndpointPrivate::writeUsbSynchronous (const char *data, qint64 maxSize)
303
+ {
304
+ Q_Q (QUsbEndpoint);
305
+ DbgPrivPrintFuncName ();
306
+ int rc = -1 ;
307
+ m_buf_mutex.lock ();
308
+ m_buf.resize (static_cast <int >(maxSize));
309
+ memcpy (m_buf.data (), data, static_cast <ulong>(maxSize));
310
+ int transferred = 0 ;
311
+ auto buf = reinterpret_cast <uchar *>(m_buf.data ());
312
+ auto sizeInt = static_cast <int >(maxSize);
313
+ auto handle = q->m_dev ->d_func ()->m_devHandle ;
314
+ auto timeout = q->m_dev ->timeout ();
315
+
316
+ // perform synchronous transfer
317
+ rc = libusb_bulk_transfer (handle, q->m_ep , buf, sizeInt, &transferred, timeout);
318
+
319
+ if (rc == LIBUSB_ERROR_TIMEOUT)
320
+ {
321
+ qDebug () << " timeout (%d)\n " << transferred << " on bulk syncrhonous transfer" ;
322
+ }
323
+ else if (rc < 0 )
324
+ {
325
+ qDebug () << " Error while waiting for char: %d\n " << rc;
326
+ }
327
+ if (rc != LIBUSB_SUCCESS) {
328
+ setStatus (QUsbEndpoint::transferError);
329
+ error (QUsbEndpoint::transferError);
330
+ // TODO: Check if QUsbEndpoint::QUsbDevice must be const...
331
+ QUsbDevice *dev = const_cast <QUsbDevice *>(q->m_dev );
332
+ dev->handleUsbError (rc);
333
+ }
334
+ m_buf_mutex.unlock ();
335
+ return rc;
336
+
337
+ }
338
+
302
339
void QUsbEndpointPrivate::setPolling (bool enable)
303
340
{
304
341
Q_Q (QUsbEndpoint);
@@ -725,3 +762,21 @@ qint64 QUsbEndpoint::writeData(const char *data, qint64 maxSize)
725
762
726
763
return maxSize;
727
764
}
765
+
766
+ qint64 QUsbEndpoint::writeDataSynchronous (const char *data, qint64 maxSize)
767
+ {
768
+ if (this ->openMode () != WriteOnly)
769
+ return -1 ;
770
+
771
+ Q_D (QUsbEndpoint);
772
+ DbgPrintFuncName ();
773
+ Q_CHECK_PTR (data);
774
+
775
+ if (!d->isValid ())
776
+ return -1 ;
777
+
778
+ if (d->writeUsbSynchronous (data, maxSize) != 0 )
779
+ return -1 ;
780
+
781
+ return maxSize;
782
+ }
0 commit comments