libdrmconf 0.12.3
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
182 bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
183 bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
184 bool read_finish(const ErrorStack &err=ErrorStack());
185
186 bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
187 bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
188 bool write_finish(const ErrorStack &err=ErrorStack());
189
190 bool reboot(const ErrorStack &err=ErrorStack());
191
192public:
196 static QList<USBDeviceDescriptor> detect(bool saveOnly=true);
197
198protected:
200 struct __attribute__((packed)) ReadRequest {
202 enum Command {
203 READ_FLASH = 1,
204 READ_EEPROM = 2,
205 READ_MCU_ROM = 5,
206 READ_DISPLAY_BUFFER = 6,
207 READ_WAV_BUFFER = 7,
208 READ_AMBE_BUFFER = 8,
209 READ_FIRMWARE_INFO = 9
210 };
211
213 char type;
215 uint8_t command;
217 uint32_t address;
219 uint16_t length;
220
222 bool initReadFlash(uint32_t address, uint16_t length);
224 bool initReadEEPROM(uint32_t address, uint16_t length);
227 };
228
230 struct __attribute__((packed)) FirmwareInfo {
232 enum class RadioType {
233 GD77=0, GD77S=1, DM1801=2, RD5R=3, DM1801A=4, MD9600=5,
234 MDUV380=6, MD380=7, DM1701=8, MD2017=9, DM1701RGB=10
235 };
236
237 uint32_t structVersion;
238 uint32_t radioType;
239 char fw_revision[16];
240 char build_date[16];
242 uint16_t features;
243 };
244
246 struct __attribute__((packed)) ReadResponse {
248 char type;
250 uint16_t length;
252 union {
253 uint8_t data[32];
255 };
256 };
257
259 struct __attribute__((packed)) WriteRequest {
261 enum Command {
262 SET_FLASH_SECTOR = 1,
263 WRITE_SECTOR_BUFFER = 2,
264 WRITE_FLASH_SECTOR = 3,
265 WRITE_EEPROM = 4,
266 WRITE_WAV_BUFFER = 7
267 };
268
270 char type;
272 uint8_t command;
273
274 union {
276 uint8_t sector[3];
278 struct __attribute__((packed)) {
280 uint32_t address;
282 uint16_t length;
284 uint8_t data[32];
285 } payload;
286 };
287
289 bool initWriteEEPROM(Variant variant, uint32_t addr, const uint8_t *data, uint16_t size);
291 bool initSetFlashSector(Variant variant, uint32_t addr);
293 bool initWriteFlash(Variant variant, uint32_t addr, const uint8_t *data, uint16_t size);
295 bool initFinishWriteFlash(Variant variant);
296 };
297
299 struct __attribute__((packed)) WriteResponse {
301 char type;
303 uint8_t command;
304 };
305
307 struct __attribute__((packed)) CommandRequest {
309 enum Command {
310 SHOW_CPS_SCREEN = 0,
311 CLEAR_SCREEN = 1,
312 DISPLAY = 2,
313 RENDER_CPS = 3,
314 CLOSE_CPS_SCREEN = 5,
315 COMMAND = 6
316 };
317
319 enum Option {
320 SAVE_SETTINGS_NOT_VFOS = 0,
321 REBOOT = 1,
322 SAVE_SETTINGS_AND_VFOS = 2,
323 FLASH_GREEN_LED = 3,
324 FLASH_RED_LED = 4
325 };
326
328 char type;
332 union {
337 };
347 char message[16];
348
350 void initShowCPSScreen();
352 void initClearScreen();
354 void initDisplay(uint8_t x, uint8_t y, const char *message, unsigned int iSize,
357 void initRenderCPS();
359 void initCloseScreen();
362 };
363
364protected:
366 bool readEEPROM(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
368 bool writeEEPROM(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
369
371 bool readFlash(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
374 bool setFlashSector(uint32_t addr, const ErrorStack &err=ErrorStack());
376 bool writeFlash(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
379 bool finishWriteFlash(const ErrorStack &err=ErrorStack());
380
382 bool readFirmwareInfo(FirmwareInfo &radioInfo, const ErrorStack &err=ErrorStack());
383
385 bool sendShowCPSScreen(const ErrorStack &err=ErrorStack());
387 bool sendClearScreen(const ErrorStack &err=ErrorStack());
389 bool sendDisplay(uint8_t x, uint8_t y, const char *message, uint8_t iSize, uint8_t alignment, uint8_t inverted, const ErrorStack &err=ErrorStack());
391 bool sendRenderCPS(const ErrorStack &err=ErrorStack());
393 bool sendCloseScreen(const ErrorStack &err=ErrorStack());
395 bool sendCommand(CommandRequest::Option option, const ErrorStack &err=ErrorStack());
396
397protected:
401 int32_t _sector;
402};
403
404#endif // OPENGD77INTERFACE_HH
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition errorstack.hh:41
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:401
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
Variant
Specifies the detected model variant.
Definition opengd77_interface.hh:165
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:399
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
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:307
void initClearScreen()
Construct a clear-screen command message.
Definition opengd77_interface.cc:105
void initRenderCPS()
Construct a "render CPS" message.
Definition opengd77_interface.cc:132
void initCloseScreen()
Construct a "close screen" command message.
Definition opengd77_interface.cc:144
char message[16]
Some text message.
Definition opengd77_interface.hh:347
uint8_t alignment
The text alignment.
Definition opengd77_interface.hh:343
uint8_t option
The command option.
Definition opengd77_interface.hh:336
uint8_t inverted
Is text inverted?
Definition opengd77_interface.hh:345
void initCommand(Option option)
Construct a command message with the given option.
Definition opengd77_interface.cc:156
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:117
uint8_t command
The command.
Definition opengd77_interface.hh:330
Command
Possible commands.
Definition opengd77_interface.hh:309
uint8_t y
The y-position on the screen.
Definition opengd77_interface.hh:339
void initShowCPSScreen()
Construct "show CPS screen" command message.
Definition opengd77_interface.cc:93
char type
Message type, here 'C' for command.
Definition opengd77_interface.hh:328
uint8_t font
The font size.
Definition opengd77_interface.hh:341
Option
Possible options.
Definition opengd77_interface.hh:319
uint8_t
The x-position on the screen.
Definition opengd77_interface.hh:334
Radio inforation struct.
Definition opengd77_interface.hh:230
char build_date[16]
Firmware build time, YYYYMMDDhhmmss, 0-padded.
Definition opengd77_interface.hh:240
uint16_t features
Some flags, signaling the presence of some features.
Definition opengd77_interface.hh:242
RadioType
Possible radio types, returned by the radio_info struct.
Definition opengd77_interface.hh:232
uint32_t structVersion
Struct version number (currently 3).
Definition opengd77_interface.hh:237
uint32_t flashChipSerial
Serial number of the flash chip.
Definition opengd77_interface.hh:241
uint32_t radioType
Device variant (see RadioType).
Definition opengd77_interface.hh:238
char fw_revision[16]
Firmware revision ASCII, 0-padded.
Definition opengd77_interface.hh:239
Represents a read message.
Definition opengd77_interface.hh:200
bool initReadEEPROM(uint32_t address, uint16_t length)
Constructs an EEPROM read message.
Definition opengd77_interface.cc:17
bool initReadFlash(uint32_t address, uint16_t length)
Constructs a FLASH read message.
Definition opengd77_interface.cc:26
bool initReadFirmwareInfo()
Constructs a firmware-info read message.
Definition opengd77_interface.cc:35
uint32_t address
Memory address to read from in big endian.
Definition opengd77_interface.hh:217
Command
Possible read sources.
Definition opengd77_interface.hh:202
uint8_t command
Memory to read from, FLASH, EEPROM, ROM, etc.
Definition opengd77_interface.hh:215
char type
'R' read block, 'W' write block, 'C' command.
Definition opengd77_interface.hh:213
uint16_t length
Amount of data to read in big endian.
Definition opengd77_interface.hh:219
Represents a read response message.
Definition opengd77_interface.hh:246
uint16_t length
Length of paylod.
Definition opengd77_interface.hh:250
FirmwareInfo info
Firmware information struct.
Definition opengd77_interface.hh:254
uint8_t data[32]
Data payload.
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:248
Represents a write message.
Definition opengd77_interface.hh:259
Command
Possible write destinations.
Definition opengd77_interface.hh:261
uint8_t sector[3]
24 bit sector number.
Definition opengd77_interface.hh:276
uint16_t length
Payload length.
Definition opengd77_interface.hh:282
char type
'R' read block, 'W' write block or 'C' command.
Definition opengd77_interface.hh:270
uint32_t address
Target address.
Definition opengd77_interface.hh:280
uint8_t data[32]
Payload data.
Definition opengd77_interface.hh:284
uint8_t command
Command,.
Definition opengd77_interface.hh:272
Represents a write-response message.
Definition opengd77_interface.hh:299
char type
Same code as request. That is 'R' read block, 'W' write block, 'C' command or '-' on Error.
Definition opengd77_interface.hh:301
uint8_t command
Same code as request if OK.
Definition opengd77_interface.hh:303