libdrmconf  0.10.4
A library to program DMR radios.
hid_macos.hh
1 #ifndef HID_MACOS_HH
2 #define HID_MACOS_HH
3 
4 #include <QObject>
5 #include <IOKit/hid/IOHIDManager.h>
6 #include "errorstack.hh"
7 #include "radiointerface.hh"
8 
11 class HIDevice: public QObject
12 {
13  Q_OBJECT
14 
15 public:
17  class Descriptor: public USBDeviceDescriptor
18  {
19  public:
21  Descriptor(const USBDeviceInfo &info, uint32_t locationId, uint16_t device);
22  };
23 
24 public:
26  HIDevice(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
28  virtual ~HIDevice();
29 
31  bool isOpen() const;
32 
39  bool hid_send_recv(const unsigned char *data, unsigned nbytes,
40  unsigned char *rdata, unsigned rlength,
41  const ErrorStack &err=ErrorStack());
42 
44  void close();
45 
46 public:
48  static QList<USBDeviceDescriptor> detect(uint16_t vid, uint16_t pid);
49 
50 protected:
52  static void callback_input(void *context, IOReturn result, void *sender, IOHIDReportType type,
53  uint32_t reportID, uint8_t *data, CFIndex nbytes);
55  static void callback_open(void *context, IOReturn result, void *sender, IOHIDDeviceRef deviceRef);
57  static void callback_close(void *ontext, IOReturn result, void *sender, IOHIDDeviceRef deviceRef);
58 
59 protected:
61  IOHIDManagerRef _HIDManager;
63  volatile IOHIDDeviceRef _dev;
65  unsigned char _transfer_buf[42];
67  unsigned char _receive_buf[42];
69  volatile int _nbytes_received = 0;
70 };
71 
72 #endif // HID_MACOS_HH
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
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
volatile IOHIDDeviceRef _dev
Device handle.
Definition: hid_macos.hh:63
unsigned char _receive_buf[42]
Receive buffer.
Definition: hid_libusb.hh:64
static void callback_open(void *context, IOReturn result, void *sender, IOHIDDeviceRef deviceRef)
Internal callback for device opend.
Definition: hid_macos.cc:266
static void callback_input(void *context, IOReturn result, void *sender, IOHIDReportType type, uint32_t reportID, uint8_t *data, CFIndex nbytes)
Internal callback for response data.
Definition: hid_macos.cc:236
IOHIDManagerRef _HIDManager
Device manager.
Definition: hid_macos.hh:61
HIDevice(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Opens a connection to the device with given vendor and product ID.
virtual ~HIDevice()
Destructor.
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.
static void callback_close(void *ontext, IOReturn result, void *sender, IOHIDDeviceRef deviceRef)
Internal callback for device closed.
Definition: hid_macos.cc:289
static QList< USBDeviceDescriptor > detect(uint16_t vid, uint16_t pid)
Finds all HID interfaces with the specified VID/PID combination.
bool isOpen() const
Returns true if the connection was established.
void close()
Close connection to device.
unsigned char _transfer_buf[42]
Device buffer.
Definition: hid_macos.hh:65
volatile int _nbytes_received
Receive result.
Definition: hid_libusb.hh:66
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