libdrmconf 0.14.1
A library to program DMR radios.
Loading...
Searching...
No Matches
opengd77_interface.hh
1#ifndef OPENGD77INTERFACE_HH
2#define OPENGD77INTERFACE_HH
3
4#include "usbserial.hh"
5#include "errorstack.hh"
6
155{
156 Q_OBJECT
157
158public:
160 static const uint32_t EEPROM = 0;
162 static const uint32_t FLASH = 1;
163
165 enum class Variant {
166 GD77, UV380
167 };
168
169public:
171 explicit OpenGD77Interface(const USBDeviceDescriptor &descr,
172 const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
174 virtual ~OpenGD77Interface();
175
177 void close();
178
181
185 bool extendedCallsignDB() const;
186
187 bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
188 bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
189 bool read_finish(const ErrorStack &err=ErrorStack());
190
191 bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
192 bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
193 bool write_finish(const ErrorStack &err=ErrorStack());
194
195 bool setDateTime(const QDateTime &datetime, const ErrorStack &err);
196
197 bool saveSettingsNotVFOs(const ErrorStack &err=ErrorStack());
198 bool saveSettingsAndVFOs(const ErrorStack &err=ErrorStack());
199 bool reboot(const ErrorStack &err=ErrorStack());
200
201public:
205 static QList<USBDeviceDescriptor> detect(bool saveOnly=true);
206
207protected:
209 struct __attribute__((packed)) ReadRequest {
211 enum Command {
212 READ_FLASH = 1,
213 READ_EEPROM = 2,
214 READ_MCU_ROM = 5,
215 READ_DISPLAY_BUFFER = 6,
216 READ_WAV_BUFFER = 7,
217 READ_AMBE_BUFFER = 8,
218 READ_FIRMWARE_INFO = 9
219 };
220
222 char type;
224 uint8_t command;
226 uint32_t address;
228 uint16_t length;
229
231 bool initReadFlash(uint32_t address, uint16_t length);
233 bool initReadEEPROM(uint32_t address, uint16_t length);
236 };
237
239 struct __attribute__((packed)) FirmwareInfo {
241 enum class RadioType {
242 GD77=0, GD77S=1, DM1801=2, RD5R=3, DM1801A=4, MD9600=5,
243 MDUV380=6, MD380=7, DM1701=8, MD2017=9, DM1701RGB=10
244 };
245
246 uint32_t structVersion;
247 uint32_t radioType;
248 char fw_revision[16];
249 char build_date[16];
251 uint16_t features;
252
254 bool featureInvertedDisplay() const;
256 bool featureExtendedCallsignDB() const;
258 bool featureVoicePromptLoaded() const;
259 };
260
262 struct __attribute__((packed)) ReadResponse {
264 char type;
266 uint16_t length;
268 union {
269 uint8_t data[32];
271 };
272 };
273
275 struct __attribute__((packed)) WriteRequest {
277 enum Command {
278 SET_FLASH_SECTOR = 1,
279 WRITE_SECTOR_BUFFER = 2,
280 WRITE_FLASH_SECTOR = 3,
281 WRITE_EEPROM = 4,
282 WRITE_WAV_BUFFER = 7
283 };
284
286 char type;
288 uint8_t command;
289
290 union {
292 uint8_t sector[3];
294 struct __attribute__((packed)) {
296 uint32_t address;
298 uint16_t length;
300 uint8_t data[32];
301 } payload;
302 };
303
305 bool initWriteEEPROM(Variant variant, uint32_t addr, const uint8_t *data, uint16_t size);
307 bool initSetFlashSector(Variant variant, uint32_t addr);
309 bool initWriteFlash(Variant variant, uint32_t addr, const uint8_t *data, uint16_t size);
311 bool initFinishWriteFlash(Variant variant);
312 };
313
315 struct __attribute__((packed)) WriteResponse {
317 char type;
319 uint8_t command;
320 };
321
323 struct __attribute__((packed)) CommandRequest {
325 enum Command {
326 SHOW_CPS_SCREEN = 0,
327 CLEAR_SCREEN = 1,
328 DISPLAY = 2,
329 RENDER_CPS = 3,
330 CLOSE_CPS_SCREEN = 5,
331 COMMAND = 6
332 };
333
335 enum Option {
336 SAVE_SETTINGS_NOT_VFOS = 0,
337 REBOOT = 1,
338 SAVE_SETTINGS_AND_VFOS = 2,
339 FLASH_GREEN_LED = 3,
340 FLASH_RED_LED = 4,
341 INIT_CODEC = 5,
342 INIT_SOUND = 6,
343 SET_DATETIME = 7,
344 DELAY_10ms = 10
345 };
346
348 char type;
352 union {
357 };
358 // Either some text options or a timestamp.
359 union {
360 struct __attribute__((packed)) {
369 };
370 uint32_t timestamp;
371 };
372
374 char message[16];
375
377 void initShowCPSScreen();
379 void initClearScreen();
381 void initDisplay(uint8_t x, uint8_t y, const char *message, unsigned int iSize,
384 void initRenderCPS();
386 void initCloseScreen();
390 void initSetDateTime(const QDateTime &dt);
391 };
392
393protected:
395 bool readEEPROM(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
397 bool writeEEPROM(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
398
400 bool readFlash(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
403 bool setFlashSector(uint32_t addr, const ErrorStack &err=ErrorStack());
405 bool writeFlash(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
408 bool finishWriteFlash(const ErrorStack &err=ErrorStack());
409
411 bool readFirmwareInfo(FirmwareInfo &radioInfo, const ErrorStack &err=ErrorStack());
412
414 bool sendShowCPSScreen(const ErrorStack &err=ErrorStack());
416 bool sendClearScreen(const ErrorStack &err=ErrorStack());
418 bool sendDisplay(uint8_t x, uint8_t y, const char *message, uint8_t iSize, uint8_t alignment, uint8_t inverted, const ErrorStack &err=ErrorStack());
420 bool sendRenderCPS(const ErrorStack &err=ErrorStack());
422 bool sendCloseScreen(const ErrorStack &err=ErrorStack());
424 bool sendSetDateTime(const QDateTime &dt, const ErrorStack &err=ErrorStack());
426 bool sendCommand(CommandRequest::Option option, const ErrorStack &err=ErrorStack());
427
428protected:
435 int32_t _sector;
436};
437
438#endif // OPENGD77INTERFACE_HH
Implements an USB interface to the Baofeng DM-1701 and Retevis RT84 VHF/UHF 5W DMR (Tier I&II) radios...
Definition dm1701.hh:39
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition errorstack.hh:43
Implements an USB interface to the Radioddity GD-77(S) VHF/UHF 5W DMR (Tier I&II) radios.
Definition gd77.hh:22
Implements an USB interface to the TYT MD-2017 & Retevis RT82 VHF/UHF 5W DMR (Tier I&II) radios.
Definition md2017.hh:36
bool setFlashSector(uint32_t addr, const ErrorStack &err=ErrorStack())
Select the correct Flash sector for the given address.
Definition opengd77_interface.cc:591
bool sendShowCPSScreen(const ErrorStack &err=ErrorStack())
Send a "show CPS screen" message.
Definition opengd77_interface.cc:737
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 opengd77_interface.cc:400
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 opengd77_interface.cc:280
int32_t _sector
The current Flash sector, set to -1 if none is currently selected.
Definition opengd77_interface.hh:435
bool reboot(const ErrorStack &err=ErrorStack())
Some radios need to be rebooted after being read or programmed.
Definition opengd77_interface.cc:452
void close()
Closes the interface to the device.
Definition opengd77_interface.cc:229
Variant
Specifies the detected model variant.
Definition opengd77_interface.hh:165
bool setDateTime(const QDateTime &datetime, const ErrorStack &err)
Some radios allow to set date and time of the internal clock during codeplug upload.
Definition opengd77_interface.cc:435
OpenGD77Interface(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Constructs a new interface to a specific OpenGD77 device.
Definition opengd77_interface.cc:206
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 opengd77_interface.cc:322
bool finishWriteFlash(const ErrorStack &err=ErrorStack())
Finalize writing to the Flash memory.
Definition opengd77_interface.cc:664
static const uint32_t EEPROM
The EEPROM memory bank.
Definition opengd77_interface.hh:160
bool sendClearScreen(const ErrorStack &err=ErrorStack())
Send a "clear screen" message.
Definition opengd77_interface.cc:768
bool sendSetDateTime(const QDateTime &dt, const ErrorStack &err=ErrorStack())
Send a "set date time" message.
Definition opengd77_interface.cc:898
static USBDeviceInfo interfaceInfo()
Returns some information about this interface.
Definition opengd77_interface.cc:218
bool read_finish(const ErrorStack &err=ErrorStack())
This function ends a series of read operations.
Definition opengd77_interface.cc:427
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 opengd77_interface.cc:376
bool readFlash(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack())
Read some data from Flash at the given address.
Definition opengd77_interface.cc:541
bool sendCommand(CommandRequest::Option option, const ErrorStack &err=ErrorStack())
Sends some command message with the given options.
Definition opengd77_interface.cc:930
virtual ~OpenGD77Interface()
Destructor.
Definition opengd77_interface.cc:213
bool writeFlash(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack())
Write some data to the given Flash memory.
Definition opengd77_interface.cc:627
bool sendCloseScreen(const ErrorStack &err=ErrorStack())
Send a "close screen" message.
Definition opengd77_interface.cc:866
bool sendRenderCPS(const ErrorStack &err=ErrorStack())
Send a "render CPS screen" message.
Definition opengd77_interface.cc:834
bool write_finish(const ErrorStack &err=ErrorStack())
This function ends a series of write operations.
Definition opengd77_interface.cc:364
Variant _protocolVariant
The protocol variant determined by the device type obtained by the firmware info.
Definition opengd77_interface.hh:430
bool sendDisplay(uint8_t 1, uint8_t y, const char *message, uint8_t iSize, uint8_t alignment, uint8_t inverted, const ErrorStack &err=ErrorStack())
Send a "display some text" message.
Definition opengd77_interface.cc:802
bool readFirmwareInfo(FirmwareInfo &radioInfo, const ErrorStack &err=ErrorStack())
Read radio info struct.
Definition opengd77_interface.cc:700
bool _extendedCallsignDB
If true, the device allows for storing parts of the call-sign DB inside the voice prompt memory.
Definition opengd77_interface.hh:433
bool extendedCallsignDB() const
Returns true if the device allows for storing part of the call-sign DB inside the voice prompt memory...
Definition opengd77_interface.cc:274
bool readEEPROM(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack())
Read some data from EEPROM at the given address.
Definition opengd77_interface.cc:459
static const uint32_t FLASH
The Flash memory bank.
Definition opengd77_interface.hh:162
RadioInfo identifier(const ErrorStack &err=ErrorStack())
Returns an identifier of the radio.
Definition opengd77_interface.cc:235
bool writeEEPROM(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack())
Write some data to EEPROM at the given address.
Definition opengd77_interface.cc:506
Implements an interface to the Baofeng/Radioddity RD-5R VHF/UHF 5W DMR (Tier I/II) radio.
Definition rd5r.hh:37
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
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
static QList< USBDeviceDescriptor > detect()
Searches for all USB serial ports.
Definition usbserial.cc:133
Represents a command message.
Definition opengd77_interface.hh:323
void initClearScreen()
Construct a clear-screen command message.
Definition opengd77_interface.cc:133
void initRenderCPS()
Construct a "render CPS" message.
Definition opengd77_interface.cc:160
void initCloseScreen()
Construct a "close screen" command message.
Definition opengd77_interface.cc:172
char message[16]
Some text message.
Definition opengd77_interface.hh:374
void initSetDateTime(const QDateTime &dt)
Construct a SET_DATETIME message with the given date time.
Definition opengd77_interface.cc:196
uint8_t alignment
The text alignment.
Definition opengd77_interface.hh:366
uint8_t option
The command option.
Definition opengd77_interface.hh:356
uint8_t inverted
Is text inverted?
Definition opengd77_interface.hh:368
void initCommand(Option option)
Construct a command message with the given option.
Definition opengd77_interface.cc:184
void initDisplay(uint8_t 1, uint8_t y, const char *message, unsigned int iSize, uint8_t font, uint8_t alignment, uint8_t inverted)
Construct a "show text on screen" message.
Definition opengd77_interface.cc:145
uint8_t command
The command.
Definition opengd77_interface.hh:350
Command
Possible commands.
Definition opengd77_interface.hh:325
uint8_t y
The y-position on the screen.
Definition opengd77_interface.hh:362
void initShowCPSScreen()
Construct "show CPS screen" command message.
Definition opengd77_interface.cc:121
char type
Message type, here 'C' for command.
Definition opengd77_interface.hh:348
uint8_t font
The font size.
Definition opengd77_interface.hh:364
Option
Possible options.
Definition opengd77_interface.hh:335
uint8_t
The x-position on the screen.
Definition opengd77_interface.hh:354
Radio information struct.
Definition opengd77_interface.hh:239
char build_date[16]
Firmware build time, YYYYMMDDhhmmss, 0-padded.
Definition opengd77_interface.hh:249
uint16_t features
Some flags, signaling the presence of some features.
Definition opengd77_interface.hh:251
RadioType
Possible radio types, returned by the radio_info struct.
Definition opengd77_interface.hh:241
bool featureVoicePromptLoaded() const
Returns true if the voice prompt data is loaded.
Definition opengd77_interface.cc:33
uint32_t structVersion
Struct version number (currently 3).
Definition opengd77_interface.hh:246
uint32_t flashChipSerial
Serial number of the flash chip.
Definition opengd77_interface.hh:250
bool featureExtendedCallsignDB() const
Returns true if the vocie prompt memory is used for storing callsign db.
Definition opengd77_interface.cc:28
uint32_t radioType
Device variant (see RadioType).
Definition opengd77_interface.hh:247
bool featureInvertedDisplay() const
Returns true if the devices display is inverted.
Definition opengd77_interface.cc:23
char fw_revision[16]
Firmware revision ASCII, 0-padded.
Definition opengd77_interface.hh:248
Represents a read message.
Definition opengd77_interface.hh:209
bool initReadEEPROM(uint32_t address, uint16_t length)
Constructs an EEPROM read message.
Definition opengd77_interface.cc:43
bool initReadFlash(uint32_t address, uint16_t length)
Constructs a FLASH read message.
Definition opengd77_interface.cc:52
bool initReadFirmwareInfo()
Constructs a firmware-info read message.
Definition opengd77_interface.cc:61
uint32_t address
Memory address to read from in big endian.
Definition opengd77_interface.hh:226
Command
Possible read sources.
Definition opengd77_interface.hh:211
uint8_t command
Memory to read from, FLASH, EEPROM, ROM, etc.
Definition opengd77_interface.hh:224
char type
'R' read block, 'W' write block, 'C' command.
Definition opengd77_interface.hh:222
uint16_t length
Amount of data to read in big endian.
Definition opengd77_interface.hh:228
Represents a read response message.
Definition opengd77_interface.hh:262
uint16_t length
Length of paylod.
Definition opengd77_interface.hh:266
FirmwareInfo info
Firmware information struct.
Definition opengd77_interface.hh:270
uint8_t data[32]
Data payload.
Definition opengd77_interface.hh:269
char type
Same code as request. That is 'R' read block, 'W' write block, 'C' command.
Definition opengd77_interface.hh:264
Represents a write message.
Definition opengd77_interface.hh:275
Command
Possible write destinations.
Definition opengd77_interface.hh:277
uint8_t sector[3]
24 bit sector number.
Definition opengd77_interface.hh:292
uint16_t length
Payload length.
Definition opengd77_interface.hh:298
char type
'R' read block, 'W'/'X' write block or 'C' command.
Definition opengd77_interface.hh:286
uint32_t address
Target address.
Definition opengd77_interface.hh:296
uint8_t data[32]
Payload data.
Definition opengd77_interface.hh:300
uint8_t command
Command,.
Definition opengd77_interface.hh:288
Represents a write-response message.
Definition opengd77_interface.hh:315
char type
Same code as request. That is 'R' read block, 'W' write block, 'C' command or '-' on Error.
Definition opengd77_interface.hh:317
uint8_t command
Same code as request if OK.
Definition opengd77_interface.hh:319