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

A collection of images, each consisting of one or more memory sections. More...

#include <dfufile.hh>

Inheritance diagram for DFUFile:
Inheritance graph
[legend]
Collaboration diagram for DFUFile:
Collaboration graph
[legend]

Classes

class  Element
 Represents a single element within a Image. More...
 
class  Image
 Represents a single image within a DFUFile. More...
 

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 Imageimage (int i) const
 Returns a reference to the i-th image of the file.
 
Imageimage (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 (unsigned blocksize) const
 Checks if all image addresses and sizes is aligned with the given block size.
 
bool read (const QString &filename, const ErrorStack &err=ErrorStack())
 Reads the specified DFU file. More...
 
bool read (QFile &file, const ErrorStack &err=ErrorStack())
 Reads the specified DFU file. More...
 
bool write (const QString &filename, const ErrorStack &err=ErrorStack())
 Writes to the specified file. More...
 
bool write (QFile &file, const ErrorStack &err=ErrorStack())
 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 bool isAllocated (uint32_t offset, uint32_t img=0) const
 Returns true if the specified address (and image) is allocated.
 
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

QVector< Image_images
 The list of images.
 

Detailed Description

A collection of images, each consisting of one or more memory sections.

This class forms the base of all binary encoded codeplugs and call-sign DBs. To this end, it represents the codeplug or call-sign DB memory as written and stored inside the radio. It also implements the DFU file format (hence the name) and thus allows to store and load binary codeplugs or call-sign DBs in files. Please note, that binary codeplugs and call-sign DBs are highly vendor and device specific. Consequently, they should be be used to exchange codeplugs.

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 |
+---+---+---+---+---+---+---+---+---+---+---+
uint32_t size() const
Returns the total size of the DFU file.
Definition: dfufile.cc:52

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 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
Implements the CRC32 checksum as used in DFU files.
Definition: crc32.hh:10

Each image section consists of a image prefix followed by several element sections. The image prefix consists of a 6byte signature containing 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 |
+---+---+---+---+---+---+---+---+---+...+---+
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:259

Member Function Documentation

◆ read() [1/2]

bool DFUFile::read ( const QString &  filename,
const ErrorStack err = ErrorStack() 
)

Reads the specified DFU file.

Returns
false on error.

◆ read() [2/2]

bool DFUFile::read ( QFile &  file,
const ErrorStack err = ErrorStack() 
)

Reads the specified DFU file.

Returns
false on error.

◆ write() [1/2]

bool DFUFile::write ( const QString &  filename,
const ErrorStack err = ErrorStack() 
)

Writes to the specified file.

Returns
false on error.

◆ write() [2/2]

bool DFUFile::write ( QFile &  file,
const ErrorStack err = ErrorStack() 
)

Writes to the specified file.

Returns
false on error.

The documentation for this class was generated from the following files: