libdrmconf  0.12.0
A library to program DMR radios.
usbserial.hh
1 #ifndef USBSERIAL_HH
2 #define USBSERIAL_HH
3 
4 #include <QObject>
5 #include <QSerialPort>
6 #include "radiointerface.hh"
7 #include "errorstack.hh"
8 
15 class USBSerial : public QSerialPort, public RadioInterface
16 {
17  Q_OBJECT
18 
19 public:
22  public:
24  Descriptor(uint16_t vid, uint16_t pid, const QString &device, bool isSave=false);
25  };
26 
27 protected:
34  explicit USBSerial(const USBDeviceDescriptor &descriptor,
35  QSerialPort::BaudRate rate=QSerialPort::Baud115200,
36  const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
37 
38 public:
40  virtual ~USBSerial();
41 
43  bool isOpen() const;
45  void close();
46 
47 public:
49  static QList<USBDeviceDescriptor> detect(uint16_t vid, uint16_t pid, bool isSave=true);
51  static QList<USBDeviceDescriptor> detect();
52 
53 protected slots:
55  void onError(QSerialPort::SerialPortError error_t);
57  void onClose();
59  void signalingChanged();
60 
61 protected:
63  QString formatPinoutSignals();
64 };
65 
66 #endif // USBSERIAL_HH
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
Abstract radio interface.
Definition: radiointerface.hh:21
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
bool isSave() const
Returns true if it is save to send commands to this device without user approval.
Definition: usbdevice.cc:112
Specialization of radio interface info for serial ports.
Definition: usbserial.hh:21
Descriptor(uint16_t vid, uint16_t pid, const QString &device, bool isSave=false)
Constructor from VID, PID and device path.
Definition: usbserial.cc:10
Implements a serial connection to a radio via USB.
Definition: usbserial.hh:16
virtual ~USBSerial()
Destructor.
Definition: usbserial.cc:82
USBSerial(const USBDeviceDescriptor &descriptor, QSerialPort::BaudRate rate=QSerialPort::Baud115200, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Constructs an opens new serial interface to the devices identified by the given vendor and product ID...
Definition: usbserial.cc:19
bool isOpen() const
If true, the device has been found and is open.
Definition: usbserial.cc:88
void signalingChanged()
Signaling callback.
Definition: usbserial.cc:109
void close()
Closes the interface to the device.
Definition: usbserial.cc:93
static QList< USBDeviceDescriptor > detect()
Searches for all USB serial ports.
Definition: usbserial.cc:133
void onError(QSerialPort::SerialPortError error_t)
Callback for serial interface errors.
Definition: usbserial.cc:99
void onClose()
Callback when closing interface.
Definition: usbserial.cc:104
QString formatPinoutSignals()
Serializes the pinout singals.
Definition: usbserial.cc:150