libdrmconf  0.10.4
A library to program DMR radios.
hid_libusb.hh
1 #ifndef HID_MACOS_HH
2 #define HID_MACOS_HH
3 
4 #include <QObject>
5 #include <libusb.h>
6 #include "errorstack.hh"
7 #include "radiointerface.hh"
8 
11 class HIDevice: public QObject
12 {
13  Q_OBJECT
14 
15 public:
18  {
19  public:
21  Descriptor(const USBDeviceInfo &info, uint8_t bus, uint8_t device);
22  };
23 
24 
25 public:
27  HIDevice(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
29  virtual ~HIDevice();
30 
32  bool isOpen() const;
39  bool hid_send_recv(const unsigned char *data, unsigned nbytes,
40  unsigned char *rdata, unsigned rlength, const ErrorStack &err=ErrorStack());
41 
43  void close();
44 
45 public:
47  static QList<USBDeviceDescriptor> detect(uint16_t vid, uint16_t pid);
48 
49 protected:
51  int write_read(const unsigned char *data, unsigned length,
52  unsigned char *reply, unsigned rlength, const ErrorStack &err=ErrorStack());
54  static void read_callback(struct libusb_transfer *t);
55 
56 protected:
58  libusb_context *_ctx;
60  libusb_device_handle *_dev;
62  struct libusb_transfer *_transfer;
64  unsigned char _receive_buf[42];
66  volatile int _nbytes_received;
69 };
70 
71 #endif // HID_MACOS_HH
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
Specialization to address a HI device uniquely.
Definition: hid_libusb.hh:18
Descriptor(const USBDeviceInfo &info, uint8_t bus, uint8_t device)
Constructor from interface info, bus number and device address.
Definition: hid_libusb.cc:11
Implements the HID radio interface using libusb.
Definition: hid_libusb.hh:12
int write_read(const unsigned char *data, unsigned length, unsigned char *reply, unsigned rlength, const ErrorStack &err=ErrorStack())
Internal used implementation of send_recv().
Definition: hid_libusb.cc:219
libusb_context * _ctx
libusb context.
Definition: hid_libusb.hh:58
unsigned char _receive_buf[42]
Receive buffer.
Definition: hid_libusb.hh:64
ErrorStack _cbError
Internal used error stack for the static callback function.
Definition: hid_libusb.hh:68
libusb_device_handle * _dev
libusb device.
Definition: hid_libusb.hh:60
HIDevice(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Connects to the device with given vendor and product ID.
Definition: hid_libusb.cc:21
bool hid_send_recv(const unsigned char *data, unsigned nbytes, unsigned char *rdata, unsigned rlength, const ErrorStack &err=ErrorStack())
Send command/data to the device and store response in rdata.
Definition: hid_libusb.cc:177
static void read_callback(struct libusb_transfer *t)
Callback for response data.
Definition: hid_libusb.cc:282
struct libusb_transfer * _transfer
libusb async transfer descriptor.
Definition: hid_libusb.hh:62
bool isOpen() const
Returns true if the connection is established.
Definition: hid_libusb.cc:150
void close()
Close connection to device.
Definition: hid_libusb.cc:155
virtual ~HIDevice()
Destructor.
Definition: hid_libusb.cc:104
volatile int _nbytes_received
Receive result.
Definition: hid_libusb.hh:66
static QList< USBDeviceDescriptor > detect(uint16_t vid, uint16_t pid)
Finds all HID interfaces with the specified VID/PID combination.
Definition: hid_libusb.cc:109
Base class for all radio interface descriptors representing a unique interface to a connected radio.
Definition: usbdevice.hh:197
const QVariant & device() const
Returns the device information identifying the interface uniquely.
Definition: usbdevice.cc:276
Generic information about a possible radio interface.
Definition: usbdevice.hh:121