libdrmconf
0.12.0
A library to program DMR radios.
|
A collection of images, each consisting of one or more memory sections. More...
#include <dfufile.hh>
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 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 (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. | |
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.
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.
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.
Finally, each element of an image is prefixed by a header containing the target address and size of the element in little endian.
bool DFUFile::read | ( | const QString & | filename, |
const ErrorStack & | err = ErrorStack() |
||
) |
Reads the specified DFU file.
false
on error. bool DFUFile::read | ( | QFile & | file, |
const ErrorStack & | err = ErrorStack() |
||
) |
Reads the specified DFU file.
false
on error. bool DFUFile::write | ( | const QString & | filename, |
const ErrorStack & | err = ErrorStack() |
||
) |
Writes to the specified file.
false
on error. bool DFUFile::write | ( | QFile & | file, |
const ErrorStack & | err = ErrorStack() |
||
) |
Writes to the specified file.
false
on error.