68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
#ifndef USBHANDLER_H
|
||
#define USBHANDLER_H
|
||
|
||
#include <libusb-1.0/libusb.h>
|
||
#include <QByteArray>
|
||
#include <QString>
|
||
#include <QObject>
|
||
#include <QDebug>
|
||
#include "log.h"
|
||
#include "QMap"
|
||
|
||
class UsbHandler : public QObject
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
explicit UsbHandler(QObject *parent = nullptr);
|
||
~UsbHandler();
|
||
|
||
bool initialize();
|
||
void listDevices();
|
||
bool openDevice(int deviceIndex); // New function to open a device by index
|
||
//控制传输使用的是 endpoint 0(默认控制端点)
|
||
bool sendControlTransfer(
|
||
uint8_t bmRequestType, // 请求类型
|
||
uint8_t bRequest, // 请求编号
|
||
uint16_t wValue, // 请求参数值(根据请求定义而定)
|
||
uint16_t wIndex, // 接口号或端点号
|
||
uint8_t *data, // 数据缓冲区(发送或接收)
|
||
uint16_t length // 数据长度
|
||
);
|
||
|
||
|
||
bool sendBulkTransfer(uint8_t endpoint, uint8_t *data, int length,int interfaceNum);
|
||
bool sendAsyncTransfer(uint8_t endpoint, uint8_t *data, int length,int interfaceNum);
|
||
void listInterfaces(int deviceIndex);
|
||
|
||
// bool sendInterruptTransfer(uint8_t endpoint, uint8_t *data, int length);
|
||
|
||
bool closeDevice();
|
||
|
||
void listInterfaceEndpoints(int deviceIndex, int interfaceNumber);
|
||
|
||
|
||
|
||
signals:
|
||
void errorOccurred(const QString &errorMessage);
|
||
void productListUpdate(QMap<int,QString> *_productList);
|
||
void interfaceListUpdate(QMap<int,QString> *_interfaceList);
|
||
void endPointListUpdate(QMap<int,QString> *_endPointList);
|
||
|
||
|
||
|
||
private:
|
||
libusb_context *context;
|
||
libusb_device **deviceList;
|
||
ssize_t deviceCount;
|
||
libusb_device_handle *handle;
|
||
QMap<int,QString> *productList;
|
||
QMap<int,QString> *interfaceList;
|
||
QMap<int,QString> *endPointList;
|
||
|
||
|
||
QString printDeviceInfo(libusb_device *device);
|
||
};
|
||
|
||
#endif // USBHANDLER_H
|