LibDMRConf  0.5.2
A library to program DMR radios.
Classes | Public Member Functions | Protected Attributes | List of all members
DFUFile Class Reference

Implements reading and writing DFU files. More...

#include <dfufile.hh>

Inheritance diagram for DFUFile:
CodePlug OpenGD77CallsignDB UV390CallsignDB D878UVCodeplug GD77Codeplug RD5RCodeplug UV390Codeplug OpenGD77Codeplug

Public Member Functions

 DFUFile (QObject *parent=nullptr)
 Constructs an empty DFU file object.
 
uint32_t size () const
 Returns the total size of the DFU file.
 
uint32_t memSize () const
 Returns the total memory size stored in the DFU file.
 
int numImages () const
 Returns the number of images within the DFU file.
 
const Image & image (int i) const
 Returns a reference to the i-th image of the file.
 
Image & image (int i)
 Returns a reference to the i-th image of the file.
 
void addImage (const QString &name, uint8_t altSettings=1)
 Adds a new image to the file.
 
void addImage (const Image &img)
 Adds an image to the file.
 
void remImage (int i)
 Deletes the i-th image from the file.
 
bool isAligned (uint blocksize) const
 Checks if all image addresses and sizes is aligned with the given block size.
 
const QString & errorMessage () const
 Returns the error message in case of an error.
 
bool read (const QString &filename)
 Reads the specified DFU file. More...
 
bool read (QFile &file)
 Reads the specified DFU file. More...
 
bool write (const QString &filename)
 Writes to the specified file. More...
 
bool write (QFile &file)
 Writes to the specified file. More...
 
void dump (QTextStream &stream) const
 Dumps a text representation of the DFU file structure to the specified text stream.
 
virtual unsigned char * data (uint32_t offset, uint32_t img=0)
 Returns a pointer to the encoded raw data at the specified offset.
 
virtual const unsigned char * data (uint32_t offset, uint32_t img=0) const
 Returns a const pointer to the encoded raw data at the specified offset.
 

Protected Attributes

QString _errorMessage
 Holds the error string.
 
QVector< Image > _images
 The list of images.
 

Detailed Description

Implements reading and writing DFU files.

DFU File consists of a file prefix followed by several images and a final file suffix. The file prefix consists of a file signature of 5 bytes just consisting of the ASCII string "DfuSe", followed by a single byte indicating the version number (V), here 0x01. The next field is a uint32_t containing the file-size excluding the suffix in little endian. Finally, there is a single byte (N) holding the number of images.

+---+---+---+---+---+---+---+---+---+---+---+
| "DfuSe" | V | file size | N |
+---+---+---+---+---+---+---+---+---+---+---+

The file suffix consists of the device, product and vendor IDs as uint16_t followed by a fixed signature uin16_t 0x011a (little endian) followed by another fixed signature containing the ASCII string "UFD". The next field (S) contains the size of the suffix, that is 16. Finally there is a CRC32 field computed over the entire file excluding the CRC itself and stored in little endian.

+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| dev | prod | vend | Sig | UFD | S | CRC32 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Each image section consists of a image prefix followed by several element sections. The image prefix consists of a 6byte signature containting the ASCII string "Target" followed by a single byte indicating the so-called "alternate settings" field, usually 0x01. The 32bit field "is named" just indicates that the 255 byte name field is set (i.e., 0x01 in little endian). The next field contains the 32 bit size of the image excluding the image prefix in little endian. Finally the last 32bit field contains the number of elements, the image consists of in little endian too.

+---+---+---+---+---+---+---+---+---+---+---+---+...+---+---+---+---+---+---+---+---+---+
| "Target" | A | is named | 255b name | size | N Elements |
+---+---+---+---+---+---+---+---+---+---+---+---+...+---+---+---+---+---+---+---+---+---+

Finally, each element of an image is prefixed by a header containing the target address and size of the element in little endian.

+---+---+---+---+---+---+---+---+---+...+---+
| address | size | el. data |
+---+---+---+---+---+---+---+---+---+...+---+

Member Function Documentation

◆ read() [1/2]

bool DFUFile::read ( const QString &  filename)

Reads the specified DFU file.

Returns
false on error.

◆ read() [2/2]

bool DFUFile::read ( QFile &  file)

Reads the specified DFU file.

Returns
false on error.

◆ write() [1/2]

bool DFUFile::write ( const QString &  filename)

Writes to the specified file.

Returns
false on error.

◆ write() [2/2]

bool DFUFile::write ( QFile &  file)

Writes to the specified file.

Returns
false on error.

The documentation for this class was generated from the following files:
DFUFile::size
uint32_t size() const
Returns the total size of the DFU file.
Definition: dfufile.cc:55
CRC32
Implements the CRC32 checksum.
Definition: crc32.hh:8
DFUFile::data
virtual unsigned char * data(uint32_t offset, uint32_t img=0)
Returns a pointer to the encoded raw data at the specified offset.
Definition: dfufile.cc:244