libdrmconf  0.12.0
A library to program DMR radios.
c7000device.hh
1 #ifndef C7000DEVICE_HH
2 #define C7000DEVICE_HH
3 
4 #include <QObject>
5 #include <libusb.h>
6 #include "errorstack.hh"
7 #include "radiointerface.hh"
8 
12 class C7000Device : public QObject
13 {
14  Q_OBJECT
15 
16 public:
18  struct Packet {
19  public:
21  Packet();
23  Packet(const Packet &other) = default ;
25  Packet(uint8_t command, uint8_t sub, uint8_t flags=0x0f, const QByteArray &payload=QByteArray());
27  Packet(const QByteArray &buffer);
28 
30  Packet &operator =(const Packet &other) = default;
31 
33  bool isValid() const;
34 
35  uint8_t flags() const;
36  uint8_t command() const;
37  uint8_t subcommand() const;
38  uint16_t payloadSize() const;
39  QByteArray payload() const;
40  const QByteArray &encoded() const;
41 
42  protected:
44  QByteArray _encoded;
45  };
46 
47 public:
50  {
51  public:
53  Descriptor(const USBDeviceInfo &info, uint8_t bus, uint8_t device);
54  };
55 
56 public:
58  C7000Device(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
60  virtual ~C7000Device();
61 
63  bool isOpen() const;
65  void close();
66 
67 public:
71  static QList<USBDeviceDescriptor> detect(bool saveOnly=true);
72 
73 protected:
75  bool sendRecv(const Packet &request, Packet &response, const ErrorStack &err=ErrorStack());
76 
77 protected:
79  libusb_context *_ctx;
81  libusb_device_handle *_dev;
82 };
83 
84 #endif // C7000DEVICE_HH
Specialization to address a DFU device uniquely.
Definition: c7000device.hh:50
Descriptor(const USBDeviceInfo &info, uint8_t bus, uint8_t device)
Constructor from interface info, bus number and device address.
Definition: c7000device.cc:111
Base class for all C7000 based radios.
Definition: c7000device.hh:13
libusb_context * _ctx
USB context.
Definition: c7000device.hh:79
virtual ~C7000Device()
Destructor.
Definition: c7000device.cc:204
bool isOpen() const
Returns true if the C7000 interface is open.
Definition: c7000device.cc:257
void close()
Closes the C7000 interface.
Definition: c7000device.cc:262
static USBDeviceInfo interfaceInfo()
Returns some information about the interface.
Definition: c7000device.cc:209
bool sendRecv(const Packet &request, Packet &response, const ErrorStack &err=ErrorStack())
Sends the given request to the device and receives the response.
Definition: c7000device.cc:275
static QList< USBDeviceDescriptor > detect(bool saveOnly=true)
Finds all C7000 interfaces.
Definition: c7000device.cc:215
libusb_device_handle * _dev
USB device object.
Definition: c7000device.hh:81
C7000Device(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Opens a connection to the C7000 device.
Definition: c7000device.cc:121
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
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:290
Generic information about a possible radio interface.
Definition: usbdevice.hh:121
Request/response packet.
Definition: c7000device.hh:18
bool isValid() const
Returns true, if the packet is valid.
Definition: c7000device.cc:54
Packet & operator=(const Packet &other)=default
Assignment.
Packet()
Default constructor.
Definition: c7000device.cc:13
QByteArray _encoded
Holds the encoded packet.
Definition: c7000device.hh:44
Packet(const Packet &other)=default
Copy constructor.