libdrmconf 0.12.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
164 enum class Variant {
165 GD77, UV380
166 };
167
168public:
170 explicit OpenGD77Interface(const USBDeviceDescriptor &descr,
171 const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
173 virtual ~OpenGD77Interface();
174
176 void close();
177
180
181 bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
182 bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
183 bool read_finish(const ErrorStack &err=ErrorStack());
184
185 bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
186 bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
187 bool write_finish(const ErrorStack &err=ErrorStack());
188
189 bool reboot(const ErrorStack &err=ErrorStack());
190
191public:
195 static QList<USBDeviceDescriptor> detect(bool saveOnly=true);
196
197protected:
199 struct __attribute__((packed)) ReadRequest {
201 enum Command {
202 READ_FLASH = 1,
203 READ_EEPROM = 2,
204 READ_MCU_ROM = 5,
205 READ_DISPLAY_BUFFER = 6,
206 READ_WAV_BUFFER = 7,
207 READ_AMBE_BUFFER = 8,
208 READ_FIRMWARE_INFO = 9
209 };
210
212 char type;
214 uint8_t command;
216 uint32_t address;
218 uint16_t length;
219
221 bool initReadFlash(uint32_t address, uint16_t length);
223 bool initReadEEPROM(uint32_t address, uint16_t length);
225 bool initReadFirmwareInfo();
226 };
227
229 struct __attribute__((packed)) FirmwareInfo {
231 enum class RadioType {
232 GD77=0, GD77S=1, DM1801=2, RD5R=3, DM1801A=4, MD9600=5,
233 MDUV380=6, MD380=7, DM1701=8, MD2017=9, DM1701RGB=10
234 };
235
236 uint32_t structVersion;
237 uint32_t radioType;
238 char fw_revision[16];
239 char build_date[16];
241 uint16_t features;
242 };
243
245 struct __attribute__((packed)) ReadResponse {
247 char type;
249 uint16_t length;
251 union {
252 uint8_t data[32];
254 };
255 };
256
258 struct __attribute__((packed)) WriteRequest {
260 enum Command {
261 SET_FLASH_SECTOR = 1,
262 WRITE_SECTOR_BUFFER = 2,
263 WRITE_FLASH_SECTOR = 3,
264 WRITE_EEPROM = 4,
265 WRITE_WAV_BUFFER = 7
266 };
267
269 char type;
271 uint8_t command;
272
273 union {
275 uint8_t sector[3];
277 struct __attribute__((packed)) {
279 uint32_t address;
281 uint16_t length;
283 uint8_t data[32];
284 } payload;
285 };
286
288 bool initWriteEEPROM(Variant variant, uint32_t addr, const uint8_t *data, uint16_t size);
290 bool initSetFlashSector(Variant variant, uint32_t addr);
292 bool initWriteFlash(Variant variant, uint32_t addr, const uint8_t *data, uint16_t size);
294 bool initFinishWriteFlash(Variant variant);
295 };
296
298 struct __attribute__((packed)) WriteResponse {
300 char type;
302 uint8_t command;
303 };
304
306 struct __attribute__((packed)) CommandRequest {
308 enum Command {
309 SHOW_CPS_SCREEN = 0,
310 CLEAR_SCREEN = 1,
311 DISPLAY = 2,
312 RENDER_CPS = 3,
313 CLOSE_CPS_SCREEN = 5,
314 COMMAND = 6
315 };
316
318 enum Option {
319 SAVE_SETTINGS_NOT_VFOS = 0,
320 REBOOT = 1,
321 SAVE_SETTINGS_AND_VFOS = 2,
322 FLASH_GREEN_LED = 3,
323 FLASH_RED_LED = 4
324 };
325
327 char type;
329 uint8_t command;
331 union {
333 uint8_t x;
335 uint8_t option;
336 };
338 uint8_t y;
340 uint8_t font;
342 uint8_t alignment;
344 uint8_t inverted;
346 char message[16];
347
349 void initShowCPSScreen();
351 void initClearScreen();
353 void initDisplay(uint8_t x, uint8_t y, const char *message, unsigned int iSize,
354 uint8_t font, uint8_t alignment, uint8_t inverted);
356 void initRenderCPS();
358 void initCloseScreen();
360 void initCommand(Option option);
361 };
362
363protected:
365 bool readEEPROM(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
367 bool writeEEPROM(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
368
370 bool readFlash(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
373 bool setFlashSector(uint32_t addr, const ErrorStack &err=ErrorStack());
375 bool writeFlash(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
378 bool finishWriteFlash(const ErrorStack &err=ErrorStack());
379
381 bool readFirmwareInfo(FirmwareInfo &radioInfo, const ErrorStack &err=ErrorStack());
382
384 bool sendShowCPSScreen(const ErrorStack &err=ErrorStack());
386 bool sendClearScreen(const ErrorStack &err=ErrorStack());
388 bool sendDisplay(uint8_t x, uint8_t y, const char *message, uint8_t iSize, uint8_t alignment, uint8_t inverted, const ErrorStack &err=ErrorStack());
390 bool sendRenderCPS(const ErrorStack &err=ErrorStack());
392 bool sendCloseScreen(const ErrorStack &err=ErrorStack());
394 bool sendCommand(CommandRequest::Option option, const ErrorStack &err=ErrorStack());
395
396protected:
400 int32_t _sector;
401};
402
403#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:41
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
Implements the interfact to a radio running the Open GD77 firmware.
Definition opengd77_interface.hh:155
bool setFlashSector(uint32_t addr, const ErrorStack &err=ErrorStack())
Select the correct Flash sector for the given address.
Definition opengd77_interface.cc:533
bool sendShowCPSScreen(const ErrorStack &err=ErrorStack())
Send a "show CPS screen" message.
Definition opengd77_interface.cc:678
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:362
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:241
int32_t _sector
The current Flash sector, set to -1 if none is currently selected.
Definition opengd77_interface.hh:400
bool reboot(const ErrorStack &err=ErrorStack())
Some radios need to be rebooted after being read or programmed.
Definition opengd77_interface.cc:395
void close()
Closes the interface to the device.
Definition opengd77_interface.cc:193
OpenGD77Interface(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Constructs a new interface to a specific OpenGD77 device.
Definition opengd77_interface.cc:171
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:283
bool finishWriteFlash(const ErrorStack &err=ErrorStack())
Finalize writing to the Flash memory.
Definition opengd77_interface.cc:606
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:709
static USBDeviceInfo interfaceInfo()
Returns some information about this interface.
Definition opengd77_interface.cc:182
bool read_finish(const ErrorStack &err=ErrorStack())
This function ends a series of read operations.
Definition opengd77_interface.cc:387
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:338
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:483
bool sendCommand(CommandRequest::Option option, const ErrorStack &err=ErrorStack())
Sends some command message with the given options.
Definition opengd77_interface.cc:838
virtual ~OpenGD77Interface()
Destructor.
Definition opengd77_interface.cc:177
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:569
bool sendCloseScreen(const ErrorStack &err=ErrorStack())
Send a "close screen" message.
Definition opengd77_interface.cc:807
bool sendRenderCPS(const ErrorStack &err=ErrorStack())
Send a "render CPS screen" message.
Definition opengd77_interface.cc:775
bool write_finish(const ErrorStack &err=ErrorStack())
This function ends a series of write operations.
Definition opengd77_interface.cc:325
Variant _protocolVariant
The protocol variant determined by the device type obtained by the firmware info.
Definition opengd77_interface.hh:398
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:743
bool readFirmwareInfo(FirmwareInfo &radioInfo, const ErrorStack &err=ErrorStack())
Read radio info struct.
Definition opengd77_interface.cc:641
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:401
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:199
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:448
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
Implements a serial connection to a radio via USB.
Definition usbserial.hh:16
static QList< USBDeviceDescriptor > detect()
Searches for all USB serial ports.
Definition usbserial.cc:133
Represents a command message.
Definition opengd77_interface.hh:306
uint8_t alignment
The text alignment.
Definition opengd77_interface.hh:342
uint8_t option
The command option.
Definition opengd77_interface.hh:335
uint8_t inverted
Is text inverted?
Definition opengd77_interface.hh:344
uint8_t command
The command.
Definition opengd77_interface.hh:329
Command
Possible commands.
Definition opengd77_interface.hh:308
uint8_t y
The y-position on the screen.
Definition opengd77_interface.hh:338
char type
Message type, here 'C' for command.
Definition opengd77_interface.hh:327
uint8_t font
The font size.
Definition opengd77_interface.hh:340
Option
Possible options.
Definition opengd77_interface.hh:318
Radio inforation struct.
Definition opengd77_interface.hh:229
uint16_t features
Some flags, signaling the presence of some features.
Definition opengd77_interface.hh:241
RadioType
Possible radio types, returned by the radio_info struct.
Definition opengd77_interface.hh:231
uint32_t structVersion
Struct version number (currently 3).
Definition opengd77_interface.hh:236
uint32_t flashChipSerial
Serial number of the flash chip.
Definition opengd77_interface.hh:240
uint32_t radioType
Device variant (see RadioType).
Definition opengd77_interface.hh:237
Represents a read message.
Definition opengd77_interface.hh:199
uint32_t address
Memory address to read from in big endian.
Definition opengd77_interface.hh:216
Command
Possible read sources.
Definition opengd77_interface.hh:201
uint8_t command
Memory to read from, FLASH, EEPROM, ROM, etc.
Definition opengd77_interface.hh:214
char type
'R' read block, 'W' write block, 'C' command.
Definition opengd77_interface.hh:212
uint16_t length
Amount of data to read in big endian.
Definition opengd77_interface.hh:218
Represents a read response message.
Definition opengd77_interface.hh:245
uint16_t length
Length of paylod.
Definition opengd77_interface.hh:249
FirmwareInfo info
Firmware information struct.
Definition opengd77_interface.hh:253
char type
Same code as request. That is 'R' read block, 'W' write block, 'C' command.
Definition opengd77_interface.hh:247
Represents a write message.
Definition opengd77_interface.hh:258
Command
Possible write destinations.
Definition opengd77_interface.hh:260
uint16_t length
Payload length.
Definition opengd77_interface.hh:281
char type
'R' read block, 'W' write block or 'C' command.
Definition opengd77_interface.hh:269
uint32_t address
Target address.
Definition opengd77_interface.hh:279
uint8_t command
Command,.
Definition opengd77_interface.hh:271
Represents a write-response message.
Definition opengd77_interface.hh:298
char type
Same code as request. That is 'R' read block, 'W' write block, 'C' command or '-' on Error.
Definition opengd77_interface.hh:300
uint8_t command
Same code as request if OK.
Definition opengd77_interface.hh:302