libdrmconf  0.8.1
A library to program DMR radios.
hid_interface.hh
1 #ifndef HIDINTERFACE_HH
2 #define HIDINTERFACE_HH
3 
4 #include <QtGlobal>
5 #include <QObject>
6 #include "radiointerface.hh"
7 
8 #ifdef Q_OS_MACOS
9 #include "hid_macos.hh"
10 #else
11 #include "hid_libusb.hh"
12 #endif
13 
17 class HID: public HIDevice, public RadioInterface
18 {
19  Q_OBJECT
20 
21 public:
23  enum MemoryBank {
24  MEMBANK_NONE = -1,
29  };
30 
31 public:
33  explicit HID(int vid, int pid, QObject *parent = nullptr);
35  virtual ~HID();
36 
38  bool isOpen() const;
39 
40  void close();
41 
43  QString identifier();
44 
45  bool read_start(uint32_t bank, uint32_t addr);
46 
53  bool read(uint32_t bank, uint32_t addr, unsigned char *data, int nbytes);
54 
55  bool read_finish();
56 
57  bool write_start(uint32_t bank, uint32_t addr);
58 
65  bool write(uint32_t bank, uint32_t addr, unsigned char *data, int nbytes);
66 
67  bool write_finish();
68 
70  inline const QString &errorMessage() const { return _errorMessage; }
71 
72 protected:
74  bool selectMemoryBank(MemoryBank bank);
75 
76 private:
78  MemoryBank _current_bank;
80  QString _identifier;
81 };
82 
83 #endif // HIDINTERFACE_HH
HID::selectMemoryBank
bool selectMemoryBank(MemoryBank bank)
Internal used function to select a memory bank.
Definition: hid_interface.cc:222
HID::close
void close()
Closes the connection to the device.
Definition: hid_interface.cc:39
HIDevice
Implements the HID radio interface using libusb.
Definition: hid_libusb.hh:9
HID::MEMBANK_CODEPLUG_LOWER
@ MEMBANK_CODEPLUG_LOWER
Lower memory bank (EEPROM).
Definition: hid_interface.hh:25
HID::HID
HID(int vid, int pid, QObject *parent=nullptr)
Connects to the radio with given vendor and product ID.
Definition: hid_interface.cc:20
HID::errorMessage
const QString & errorMessage() const
Retruns the last error message.
Definition: hid_interface.hh:70
HID::read
bool read(uint32_t bank, uint32_t addr, unsigned char *data, int nbytes)
Reads a block of data from the device at the given block number.
Definition: hid_interface.cc:113
HID::read_finish
bool read_finish()
This function ends a series of read operations.
Definition: hid_interface.cc:139
HID::write_start
bool write_start(uint32_t bank, uint32_t addr)
Starts the write process into the specified bank and at the given address.
Definition: hid_interface.cc:162
HID::MEMBANK_CALLSIGN_UPPER
@ MEMBANK_CALLSIGN_UPPER
Callsign DB memory upper bank (also FLASH).
Definition: hid_interface.hh:28
HID::MEMBANK_NONE
@ MEMBANK_NONE
No bank selected.
Definition: hid_interface.hh:24
HID::isOpen
bool isOpen() const
Returns true if the connection was established.
Definition: hid_interface.cc:34
HID::MemoryBank
MemoryBank
Possible memory banks to select.
Definition: hid_interface.hh:23
HID::identifier
QString identifier()
Returns radio identifier string.
Definition: hid_interface.cc:46
HID::write_finish
bool write_finish()
This function ends a series of write operations.
Definition: hid_interface.cc:201
RadioInterface
Abstract radio interface.
Definition: radiointerface.hh:18
HID::read_start
bool read_start(uint32_t bank, uint32_t addr)
Starts the read process from the specified bank and at the given address.
Definition: hid_interface.cc:103
HID
Implements a radio interface for radios using the HID USB schema.
Definition: hid_interface.hh:17
HID::MEMBANK_CODEPLUG_UPPER
@ MEMBANK_CODEPLUG_UPPER
Upper memory bank (FLASH).
Definition: hid_interface.hh:26
HIDevice::_errorMessage
QString _errorMessage
Holds the error message.
Definition: hid_libusb.hh:52
HID::write
bool write(uint32_t bank, uint32_t addr, unsigned char *data, int nbytes)
Writes a block of data to the device at the given block number.
Definition: hid_interface.cc:172
HID::MEMBANK_CALLSIGN_LOWER
@ MEMBANK_CALLSIGN_LOWER
Callsign DB memory lower bank (also FLASH).
Definition: hid_interface.hh:27
HID::~HID
virtual ~HID()
Destructor.
Definition: hid_interface.cc:27