libdrmconf  0.12.0
A library to program DMR radios.
dr1801uv_interface.hh
1 #ifndef DR1801UVINTERFACE_HH
2 #define DR1801UVINTERFACE_HH
3 
4 #include "auctus_a6_interface.hh"
5 #include <functional>
6 
7 
8 // Forward declarations
9 class Codeplug;
10 
15 {
16  Q_OBJECT
17 
18 public:
20  DR1801UVInterface(const USBDeviceDescriptor &descriptor,
21  const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
22 
23  RadioInfo identifier(const ErrorStack &err);
24 
26  bool readCodeplug(Codeplug &codeplug, std::function<void (unsigned int, unsigned int)> progress,
27  const ErrorStack &err=ErrorStack());
28 
30  bool writeCodeplug(const Codeplug &codeplug, std::function<void(unsigned int, unsigned int)> progress,
31  const ErrorStack &err=ErrorStack());
32 
33  bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
34  bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
35  bool read_finish(const ErrorStack &err=ErrorStack());
36 
37  bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
38  bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
39  bool write_finish(const ErrorStack &err=ErrorStack());
40 
41 public:
45  static QList<USBDeviceDescriptor> detect(bool saveOnly=true);
46 
47 protected:
51  DefaultSpeed = QSerialPort::Baud9600,
53  ReadSpeed = QSerialPort::Baud115200,
55  WriteSpeed = QSerialPort::Baud9600
56  };
57 
59  enum Command {
60  REQUEST_INFO = 0x0000,
64  START_READ_DATA = 0x0101,
66  CODEPLUG_WRITTEN = 0x0103
67  };
68 
70  struct Q_PACKED PrepareReadRequest {
72  uint32_t baudrate;
73 
75  PrepareReadRequest(uint32_t baudrate);
77  void setBaudrate(uint32_t baudrate);
78  };
79 
82  struct Q_PACKED PrepareReadResponse {
83  uint8_t success;
84  uint32_t size;
85  uint8_t _unknown[10];
86 
88  bool isSuccessful() const;
90  uint32_t getSize() const;
91  };
92 
95  struct Q_PACKED PrepareWriteRequest {
96  uint16_t _unknown0;
97  uint32_t size;
98  uint16_t checksum;
99  uint32_t baudRate;
100 
102  PrepareWriteRequest(uint32_t size, uint32_t speed, uint16_t crc);
104  void updateCRC(const uint8_t *data, size_t length);
105  };
106 
108  struct Q_PACKED PrepareWriteResponse {
109  uint16_t responseCode;
110 
112  bool isSuccessful() const;
113  };
114 
116  struct Q_PACKED CodeplugWriteResponse {
117  uint8_t success;
118  uint16_t unknown;
119 
121  bool isSuccessful() const;
122  };
123 
125  bool enterProgrammingMode(const ErrorStack &err=ErrorStack());
127  bool getDeviceInfo(QString &info, const ErrorStack &err=ErrorStack());
130 
132  bool prepareReading(uint32_t baudrate, PrepareReadResponse &response, const ErrorStack &err=ErrorStack());
135  bool startReading(const ErrorStack &err=ErrorStack());
136 
138  bool prepareWriting(uint32_t size, uint32_t baudrate, uint16_t crc, const ErrorStack &err=ErrorStack());
140  bool receiveWriteACK(const ErrorStack &err=ErrorStack());
141 
142 protected:
144  QString _identifier;
145 };
146 
147 #endif // DR1801UVINTERFACE_HH
Implements the communication interface to radios using the Auctus A6 chip.
Definition: auctus_a6_interface.hh:20
This class defines the interface all device-specific code-plugs must implement.
Definition: codeplug.hh:19
Implements the actual interface to the DR-1801UV, which builds upon the AuctusA6Interface.
Definition: dr1801uv_interface.hh:15
bool checkProgrammingPassword(const ErrorStack &err=ErrorStack())
Checks the if a programming password is set.
Definition: dr1801uv_interface.cc:368
bool prepareReading(uint32_t baudrate, PrepareReadResponse &response, const ErrorStack &err=ErrorStack())
Prepares reading the codeplug.
Definition: dr1801uv_interface.cc:390
DR1801UVInterface(const USBDeviceDescriptor &descriptor, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Constructs an interface to the BTECH DR-1801UV from the specifeid USB descriptor.
Definition: dr1801uv_interface.cc:80
RadioInfo identifier(const ErrorStack &err)
Returns a device identifier.
Definition: dr1801uv_interface.cc:107
bool getDeviceInfo(QString &info, const ErrorStack &err=ErrorStack())
Reads some information about the device.
Definition: dr1801uv_interface.cc:311
bool write_finish(const ErrorStack &err=ErrorStack())
This function ends a series of write operations.
Definition: dr1801uv_interface.cc:291
static USBDeviceInfo interfaceInfo()
Returns some information about this interface.
Definition: dr1801uv_interface.cc:297
bool read_finish(const ErrorStack &err=ErrorStack())
This function ends a series of read operations.
Definition: dr1801uv_interface.cc:272
bool prepareWriting(uint32_t size, uint32_t baudrate, uint16_t crc, const ErrorStack &err=ErrorStack())
Repares the codeplug write.
Definition: dr1801uv_interface.cc:415
QString _identifier
Holds the device identifier, once read.
Definition: dr1801uv_interface.hh:144
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: dr1801uv_interface.cc:266
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: dr1801uv_interface.cc:260
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: dr1801uv_interface.cc:279
bool readCodeplug(Codeplug &codeplug, std::function< void(unsigned int, unsigned int)> progress, const ErrorStack &err=ErrorStack())
Reads the codeplug from the device blocking.
Definition: dr1801uv_interface.cc:119
bool enterProgrammingMode(const ErrorStack &err=ErrorStack())
Puts the device into programming mode.
Definition: dr1801uv_interface.cc:348
Command
Implemented commands.
Definition: dr1801uv_interface.hh:59
@ PREPARE_CODEPLUG_WRITE
Prepares writing the codeplug.
Definition: dr1801uv_interface.hh:65
@ ENTER_PROGRAMMING_MODE
Puts the device into the programming mode.
Definition: dr1801uv_interface.hh:61
@ CHECK_PROG_PASSWORD
Checks the programming password.
Definition: dr1801uv_interface.hh:62
@ START_READ_DATA
Actually starts reading the codeplug.
Definition: dr1801uv_interface.hh:64
@ PREPARE_CODEPLUG_READ
Sets baud rate and prepares codeplug read.
Definition: dr1801uv_interface.hh:63
@ CODEPLUG_WRITTEN
Send by the device once the codeplug was written.
Definition: dr1801uv_interface.hh:66
@ REQUEST_INFO
Returns some information about the device.
Definition: dr1801uv_interface.hh:60
bool receiveWriteACK(const ErrorStack &err=ErrorStack())
Receives the ACK for writing the codeplug.
Definition: dr1801uv_interface.cc:442
bool writeCodeplug(const Codeplug &codeplug, std::function< void(unsigned int, unsigned int)> progress, const ErrorStack &err=ErrorStack())
Writes the codeplug to the device blocking.
Definition: dr1801uv_interface.cc:186
bool startReading(const ErrorStack &err=ErrorStack())
Starts the read operation.
Definition: dr1801uv_interface.cc:470
DefaultTransferSpeed
Some default speeds.
Definition: dr1801uv_interface.hh:49
@ DefaultSpeed
Initial speed, used to send commands.
Definition: dr1801uv_interface.hh:51
@ WriteSpeed
Speed for writing the codeplug.
Definition: dr1801uv_interface.hh:55
@ ReadSpeed
Speed for reading the codeplug.
Definition: dr1801uv_interface.hh:53
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: dr1801uv_interface.cc:285
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
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
static QList< USBDeviceDescriptor > detect()
Searches for all USB serial ports.
Definition: usbserial.cc:133
Response to a codeplug write.
Definition: dr1801uv_interface.hh:116
uint16_t unknown
Some unkown data.
Definition: dr1801uv_interface.hh:118
uint8_t success
Response code.
Definition: dr1801uv_interface.hh:117
Request to set transfer speed and load codeplug into RAM for transfer.
Definition: dr1801uv_interface.hh:70
uint32_t baudrate
The transfer speed.
Definition: dr1801uv_interface.hh:72
Response to a PREPARE_CODEPLUG_READ command.
Definition: dr1801uv_interface.hh:82
uint8_t success
If successful, set to 0x01.
Definition: dr1801uv_interface.hh:83
uint32_t size
Contains the size of the codeplug in big-endian.
Definition: dr1801uv_interface.hh:84
Request to prepare a codeplug write.
Definition: dr1801uv_interface.hh:95
uint32_t baudRate
The baud rate for the transfer.
Definition: dr1801uv_interface.hh:99
uint32_t size
Contains the size of the codeplug in big-endian.
Definition: dr1801uv_interface.hh:97
uint16_t _unknown0
Just set to 0x0001.
Definition: dr1801uv_interface.hh:96
uint16_t checksum
A checksum over the codeplug to be written.
Definition: dr1801uv_interface.hh:98
Response to a prepare-write request.
Definition: dr1801uv_interface.hh:108
uint16_t responseCode
Response code.
Definition: dr1801uv_interface.hh:109