libdrmconf  0.10.4
A library to program DMR radios.
tyt_interface.hh
1 #ifndef TYTINTERFACE_HH
2 #define TYTINTERFACE_HH
3 
4 #include "dfu_libusb.hh"
5 #include "radiointerface.hh"
6 
63 class TyTInterface : public DFUSEDevice, public RadioInterface
64 {
65  Q_OBJECT
66 
67 public:
69  TyTInterface(const USBDeviceDescriptor &descr,
70  const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
72  ~TyTInterface();
73 
74  bool isOpen() const;
76  void close();
77 
78  bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
79  bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
80  bool read_finish(const ErrorStack &err=ErrorStack());
81  bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
82  bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
83  bool write_finish(const ErrorStack &err=ErrorStack());
84  bool reboot(const ErrorStack &err=ErrorStack());
85 
87  bool erase(unsigned start, unsigned size, void (*progress)(unsigned, void *)=nullptr, void *ctx=nullptr, const ErrorStack &err=ErrorStack());
88 
89 public:
93  static QList<USBDeviceDescriptor> detect();
94 
95 protected:
97  int md380_command(uint8_t a, uint8_t b, const ErrorStack &err=ErrorStack());
99  int set_address(uint32_t address, const ErrorStack &err=ErrorStack());
101  int erase_block(uint32_t address, const ErrorStack &err=ErrorStack());
103  const char *identify(const ErrorStack &err=ErrorStack());
104 
105 protected:
108 };
109 
110 #endif // TYTINTERFACE_HH
Implements the ST MCU extensions for the DFU protocol, aka DfuSe.
Definition: dfu_libusb.hh:88
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
Provides some information about a radio model.
Definition: radioinfo.hh:16
Abstract radio interface.
Definition: radiointerface.hh:21
Interface to TyT (and Retevis) devices.
Definition: tyt_interface.hh:64
bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack())
Reads a chunk of data from the block-address bno (block number).
Definition: tyt_interface.cc:193
int md380_command(uint8_t a, uint8_t b, const ErrorStack &err=ErrorStack())
Internal used function to send a control command to the device.
Definition: tyt_interface.cc:95
bool write_finish(const ErrorStack &err=ErrorStack())
This function ends a series of write operations.
Definition: tyt_interface.cc:235
bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack())
Writes a chunk of data at the address addr.
Definition: tyt_interface.cc:219
bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack())
Starts the write process into the specified bank and at the given address.
Definition: tyt_interface.cc:213
const char * identify(const ErrorStack &err=ErrorStack())
Internal used function to read the device identifier.
Definition: tyt_interface.cc:143
bool reboot(const ErrorStack &err=ErrorStack())
Some radios need to be rebooted after being read or programmed.
Definition: tyt_interface.cc:242
bool erase(unsigned start, unsigned size, void(*progress)(unsigned, void *)=nullptr, void *ctx=nullptr, const ErrorStack &err=ErrorStack())
Erases a memory section at start of size size.
Definition: tyt_interface.cc:157
RadioInfo _ident
Read identifier.
Definition: tyt_interface.hh:107
~TyTInterface()
Destructor.
Definition: tyt_interface.cc:60
static QList< USBDeviceDescriptor > detect()
Tries to find all interfaces connected TyT radios.
Definition: tyt_interface.cc:71
void close()
Closes the connection to the device.
Definition: tyt_interface.cc:76
int set_address(uint32_t address, const ErrorStack &err=ErrorStack())
Internal used function to set the current I/O address.
Definition: tyt_interface.cc:108
bool read_finish(const ErrorStack &err=ErrorStack())
This function ends a series of read operations.
Definition: tyt_interface.cc:206
bool isOpen() const
Return true if a connection to the device has been established.
Definition: tyt_interface.cc:84
static USBDeviceInfo interfaceInfo()
Returns some information about the interface.
Definition: tyt_interface.cc:66
RadioInfo identifier(const ErrorStack &err=ErrorStack())
Returns a device identifier.
Definition: tyt_interface.cc:89
int erase_block(uint32_t address, const ErrorStack &err=ErrorStack())
Internal used function to erase a specific block.
Definition: tyt_interface.cc:125
TyTInterface(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Constructor.
Definition: tyt_interface.cc:11
bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack())
Starts the read process from the specified bank and at the given address.
Definition: tyt_interface.cc:184
Base class for all radio interface descriptors representing a unique interface to a connected radio.
Definition: usbdevice.hh:197
Generic information about a possible radio interface.
Definition: usbdevice.hh:121