libdrmconf  0.10.4
A library to program DMR radios.
opengd77_interface.hh
1 #ifndef OPENGD77INTERFACE_HH
2 #define OPENGD77INTERFACE_HH
3 
4 #include "usbserial.hh"
5 #include "errorstack.hh"
6 
16 {
17  Q_OBJECT
18 
19 public:
21  static const uint32_t EEPROM = 0;
23  static const uint32_t FLASH = 1;
24 
25 public:
27  explicit OpenGD77Interface(const USBDeviceDescriptor &descr,
28  const ErrorStack &err=ErrorStack(), QObject *parent=nullptr);
30  virtual ~OpenGD77Interface();
31 
33  void close();
34 
37 
38  bool read_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
39  bool read(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
40  bool read_finish(const ErrorStack &err=ErrorStack());
41 
42  bool write_start(uint32_t bank, uint32_t addr, const ErrorStack &err=ErrorStack());
43  bool write(uint32_t bank, uint32_t addr, uint8_t *data, int nbytes, const ErrorStack &err=ErrorStack());
44  bool write_finish(const ErrorStack &err=ErrorStack());
45 
46  bool reboot(const ErrorStack &err=ErrorStack());
47 
48 public:
52  static QList<USBDeviceDescriptor> detect();
53 
54 protected:
56  struct __attribute__((packed)) ReadRequest {
58  enum Command {
59  READ_FLASH = 1,
60  READ_EEPROM = 2,
61  READ_MCU_ROM = 5,
62  READ_DISPLAY_BUFFER = 6,
63  READ_WAV_BUFFER = 7,
64  READ_AMBE_BUFFER = 8,
65  READ_FIRMWARE_INFO = 9
66  };
67 
69  char type;
71  uint8_t command;
73  uint32_t address;
75  uint16_t length;
76 
78  bool initReadFlash(uint32_t address, uint16_t length);
80  bool initReadEEPROM(uint32_t address, uint16_t length);
82  bool initReadFirmwareInfo();
83  };
84 
86  struct __attribute__((packed)) ReadResponse {
88  char type;
90  uint16_t length;
91 
92  union {
94  uint8_t data[32];
96  struct {
97  uint32_t _unknown00;
98  uint32_t _unknown04;
99  char fw_revision[16];
100  char build_date[16];
101  uint32_t _unknown24;
102  } radio_info;
103  };
104  };
105 
107  struct __attribute__((packed)) WriteRequest {
109  enum Command {
110  SET_FLASH_SECTOR = 1,
111  WRITE_SECTOR_BUFFER = 2,
112  WRITE_FLASH_SECTOR = 3,
113  WRITE_EEPROM = 4,
114  WRITE_WAV_BUFFER = 7
115  };
116 
118  char type;
120  uint8_t command;
121 
122  union {
124  uint8_t sector[3];
126  struct __attribute__((packed)) {
128  uint32_t address;
130  uint16_t length;
132  uint8_t data[32];
133  } payload;
134  };
135 
137  bool initWriteEEPROM(uint32_t addr, const uint8_t *data, uint16_t size);
139  bool initSetFlashSector(uint32_t addr);
141  bool initWriteFlash(uint32_t addr, const uint8_t *data, uint16_t size);
143  bool initFinishWriteFlash();
144  };
145 
147  struct __attribute__((packed)) WriteResponse {
149  char type;
151  uint8_t command;
152  };
153 
155  struct __attribute__((packed)) CommandRequest {
157  enum Command {
158  SHOW_CPS_SCREEN = 0,
159  CLEAR_SCREEN = 1,
160  DISPLAY = 2,
161  RENDER_CPS = 3,
162  CLOSE_CPS_SCREEN = 5,
163  COMMAND = 6
164  };
165 
167  enum Option {
168  SAVE_SETTINGS_NOT_VFOS = 0,
169  REBOOT = 1,
170  SAVE_SETTINGS_AND_VFOS = 2,
171  FLASH_GREEN_LED = 3,
172  FLASH_RED_LED = 4
173  };
174 
176  char type;
178  uint8_t command;
180  union {
182  uint8_t x;
184  uint8_t option;
185  };
187  uint8_t y;
189  uint8_t size;
191  uint8_t alignment;
193  uint8_t inverted;
195  char message[16];
196 
198  void initShowCPSScreen();
200  void initClearScreen();
202  void initDisplay(uint8_t x, uint8_t y, const char *message, uint8_t iSize, uint8_t alignment, uint8_t inverted);
204  void initRenderCPS();
206  void initCloseScreen();
208  void initCommand(Option option);
209  };
210 
211 protected:
213  bool readEEPROM(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
215  bool writeEEPROM(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
217  bool readFlash(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
220  bool setFlashSector(uint32_t addr, const ErrorStack &err=ErrorStack());
222  bool writeFlash(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack());
225  bool finishWriteFlash(const ErrorStack &err=ErrorStack());
226 
228  bool sendShowCPSScreen(const ErrorStack &err=ErrorStack());
230  bool sendClearScreen(const ErrorStack &err=ErrorStack());
232  bool sendDisplay(uint8_t x, uint8_t y, const char *message, uint8_t iSize, uint8_t alignment, uint8_t inverted, const ErrorStack &err=ErrorStack());
234  bool sendRenderCPS(const ErrorStack &err=ErrorStack());
236  bool sendCloseScreen(const ErrorStack &err=ErrorStack());
238  bool sendCommand(CommandRequest::Option option, const ErrorStack &err=ErrorStack());
239 
240 protected:
242  int32_t _sector;
243 };
244 
245 #endif // OPENGD77INTERFACE_HH
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41
Implements the interfact to a radio running the Open GD77 firmware.
Definition: opengd77_interface.hh:16
bool setFlashSector(uint32_t addr, const ErrorStack &err=ErrorStack())
Select the correct Flash sector for the given address.
Definition: opengd77_interface.cc:498
bool sendShowCPSScreen(const ErrorStack &err=ErrorStack())
Send a "show CPS screen" message.
Definition: opengd77_interface.cc:606
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:327
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:206
int32_t _sector
The current Flash sector, set to -1 if none is currently selected.
Definition: opengd77_interface.hh:242
bool reboot(const ErrorStack &err=ErrorStack())
Some radios need to be rebooted after being read or programmed.
Definition: opengd77_interface.cc:360
void close()
Closes the interface to the device.
Definition: opengd77_interface.cc:191
OpenGD77Interface(const USBDeviceDescriptor &descr, const ErrorStack &err=ErrorStack(), QObject *parent=nullptr)
Constructs a new interface to a specific OpenGD77 device.
Definition: opengd77_interface.cc:170
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:248
bool finishWriteFlash(const ErrorStack &err=ErrorStack())
Finalize writing to the Flash memory.
Definition: opengd77_interface.cc:571
static const uint32_t EEPROM
The EEPROM memory bank.
Definition: opengd77_interface.hh:21
bool sendClearScreen(const ErrorStack &err=ErrorStack())
Send a "clear screen" message.
Definition: opengd77_interface.cc:637
static USBDeviceInfo interfaceInfo()
Returns some information about this interface.
Definition: opengd77_interface.cc:181
bool read_finish(const ErrorStack &err=ErrorStack())
This function ends a series of read operations.
Definition: opengd77_interface.cc:352
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:303
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:448
bool sendCommand(CommandRequest::Option option, const ErrorStack &err=ErrorStack())
Sends some command message with the given options.
Definition: opengd77_interface.cc:766
virtual ~OpenGD77Interface()
Destructor.
Definition: opengd77_interface.cc:176
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:534
static QList< USBDeviceDescriptor > detect()
Tries to find all interfaces connected AnyTone radios.
Definition: opengd77_interface.cc:186
bool sendCloseScreen(const ErrorStack &err=ErrorStack())
Send a "close screen" message.
Definition: opengd77_interface.cc:735
bool sendRenderCPS(const ErrorStack &err=ErrorStack())
Send a "render CPS screen" message.
Definition: opengd77_interface.cc:703
bool write_finish(const ErrorStack &err=ErrorStack())
This function ends a series of write operations.
Definition: opengd77_interface.cc:290
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:671
bool readEEPROM(uint32_t addr, uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack())
Write some data to EEPROM at the given address.
Definition: opengd77_interface.cc:366
static const uint32_t FLASH
The Flash memory bank.
Definition: opengd77_interface.hh:23
RadioInfo identifier(const ErrorStack &err=ErrorStack())
Returns an identifier of the radio.
Definition: opengd77_interface.cc:197
bool writeEEPROM(uint32_t addr, const uint8_t *data, uint16_t len, const ErrorStack &err=ErrorStack())
Read some data from EEPROM at the given address.
Definition: opengd77_interface.cc:413
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
Represents a command message.
Definition: opengd77_interface.hh:155
uint8_t size
The size.
Definition: opengd77_interface.hh:189
uint8_t alignment
The text alignment.
Definition: opengd77_interface.hh:191
uint8_t option
The command option.
Definition: opengd77_interface.hh:184
uint8_t inverted
Is text inverted?
Definition: opengd77_interface.hh:193
uint8_t command
The command.
Definition: opengd77_interface.hh:178
Command
Possible commands.
Definition: opengd77_interface.hh:157
uint8_t y
The y-position on the screen.
Definition: opengd77_interface.hh:187
char type
Message type, here 'C' for command.
Definition: opengd77_interface.hh:176
Option
Possible options.
Definition: opengd77_interface.hh:167
Represents a read message.
Definition: opengd77_interface.hh:56
uint32_t address
Memory address to read from in big endian.
Definition: opengd77_interface.hh:73
Command
Possible read sources.
Definition: opengd77_interface.hh:58
uint8_t command
Memory to read from, FLASH, EEPROM, ROM, etc.
Definition: opengd77_interface.hh:71
char type
'R' read block, 'W' write block, 'C' command.
Definition: opengd77_interface.hh:69
uint16_t length
Amount of data to read in big endian.
Definition: opengd77_interface.hh:75
Represents a read response message.
Definition: opengd77_interface.hh:86
uint16_t length
Length of paylod.
Definition: opengd77_interface.hh:90
uint32_t _unknown24
Some unknown number in little endian, seen 0x4014.
Definition: opengd77_interface.hh:101
uint32_t _unknown00
Some unknown number in little endian, seen 0x0001.
Definition: opengd77_interface.hh:97
char type
Same code as request. That is 'R' read block, 'W' write block, 'C' command.
Definition: opengd77_interface.hh:88
uint32_t _unknown04
Some unknown number in little endian, seen 0x0003.
Definition: opengd77_interface.hh:98
Represents a write message.
Definition: opengd77_interface.hh:107
Command
Possible write destinations.
Definition: opengd77_interface.hh:109
uint16_t length
Payload length.
Definition: opengd77_interface.hh:130
char type
'R' read block, 'W' write block or 'C' command.
Definition: opengd77_interface.hh:118
uint32_t address
Target address.
Definition: opengd77_interface.hh:128
uint8_t command
Command,.
Definition: opengd77_interface.hh:120
Represents a write-response message.
Definition: opengd77_interface.hh:147
char type
Same code as request. That is 'R' read block, 'W' write block, 'C' command or '-' on Error.
Definition: opengd77_interface.hh:149
uint8_t command
Same code as request if OK.
Definition: opengd77_interface.hh:151