LibDMRConf  0.6.0
A library to program DMR radios.
Classes | Public Member Functions | List of all members
D878UVCodeplug Class Reference

Represents the device specific binary codeplug for Anytone AT-D878UV radios. More...

#include <d878uv_codeplug.hh>

Inheritance diagram for D878UVCodeplug:
CodePlug DFUFile

Classes

struct  analog_alarm_setting_t
 Binary representation of the analog alarm settings. More...
 
struct  analog_contact_t
 Represents an ananlog contact within the binary codeplug. More...
 
struct  analog_quick_call_t
 Represents analog quick-call settings within the binary code-plug. More...
 
struct  aprs_setting_t
 Represents the APRS settings within the binary codeplug. More...
 
struct  channel_t
 Represents the actual channel encoded within the binary code-plug. More...
 
struct  contact_map_t
 Represents an entry in the DMR ID -> contact map within the binary code-plug. More...
 
struct  contact_t
 Represents a digital contact within the binary codeplug. More...
 
struct  encryption_key_t
 Represents an encryption key. More...
 
struct  general_settings_base_t
 Represents the general config of the radio within the binary codeplug. More...
 
struct  general_settings_ext1_t
 General settings extension 1. More...
 
struct  general_settings_ext2_t
 General settings extension 2. More...
 
struct  gps_systems_t
 Represents the 8 GPS systems within the binary codeplug. More...
 
struct  grouplist_t
 Represents the actual RX group list encoded within the binary code-plug. More...
 
struct  hotkey_t
 Represents hot-key settings. More...
 
struct  message_list_t
 Some weird linked list of valid message indices. More...
 
struct  message_t
 Represents a prefabricated SMS message within the binary codeplug. More...
 
struct  radioid_t
 Represents an entry of the radio ID table within the binary codeplug. More...
 
struct  roaming_channel_t
 Implements the binary representation of a roaming channel within the codeplug. More...
 
struct  roaming_zone_t
 Represents a roaming zone within the binary codeplug. More...
 
struct  scanlist_t
 Represents a scan list within the binary codeplug. More...
 

Public Member Functions

 D878UVCodeplug (QObject *parent=nullptr)
 Empty constructor.
 
void clear ()
 Clears and resets the complete codeplug to some default values.
 
void setBitmaps (Config *config)
 Sets all bitmaps for the given config.
 
void allocateForDecoding ()
 Allocate all code-plug elements that must be downloaded for decoding. More...
 
void allocateUntouched ()
 Allocate all code-plug elements that must be written back to the device to maintain a working codeplug. More...
 
void allocateForEncoding ()
 Allocate all code-plug elements that are defined through the common Config.
 
bool decode (Config *config)
 Decodes the binary codeplug and stores its content in the given generic configuration.
 
bool encode (Config *config, bool update=true)
 Encodes the given generic configuration as a binary codeplug.
 
- Public Member Functions inherited from CodePlug
virtual ~CodePlug ()
 Destructor.
 
- Public Member Functions inherited from DFUFile
 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.
 

Additional Inherited Members

- Protected Member Functions inherited from CodePlug
 CodePlug (QObject *parent=nullptr)
 Hidden default constructor.
 
- Protected Attributes inherited from DFUFile
QString _errorMessage
 Holds the error string.
 
QVector< Image > _images
 The list of images.
 

Detailed Description

Represents the device specific binary codeplug for Anytone AT-D878UV radios.

In contrast to many other code-plugs, the code-plug for Anytone radios are spread over a large memory area. In principle, this is a good idea, as it allows to upload only the portion of the codeplug that is actually configured. For example, if only a small portion of the available contacts and channels are used, the amount of data that is written to the device can be reduced.

However, the implementation of this idea in this device is utter shit. The amount of fragmentation of the codeplug is overwhelming. For example, while channels are organized more or less nicely in continous banks, zones are distributed throughout the entire code-plug. That is, the names of zones are located in a different memory section that the channel lists. Some lists are defined though bit-masks others by byte-masks. All bit-masks are positive, that is 1 indicates an enabled item while the bit-mask for contacts is inverted.

In general the code-plug is huge and complex. Moreover, the radio provides a huge amount of options and features. To this end, reverse-engeneering this code-plug was a nightmare.

More over, the binary code-plug file generate by the windows CPS does not directly relate to the data being written to the radio. To this end the code-plug has been reverse-engineered using wireshark to monitor the USB communication between the windows CPS (running in a vritual box) and the device. The latter makes the reverse-engineering particularily cumbersome.

Codeplug structure within radio

Channels
Start Size Content
024C1500 000200 Bitmap of 4000 channels, default 0x00, 0x00 padded.
00800000 max. 002000 Channel bank 0 of upto 128 channels, see channel_t 64 b each.
00802000 max, 002000 Unknown data, Maybe extended channel information for channel bank 0? It is of exactly the same size as the channel bank 0. Mostly 0x00, a few 0xff.
00840000 max. 002000 Channel bank 1 of upto 128 channels.
00842000 max. 002000 Unknown data, related to CH bank 1?
... ... ...
00FC0000 max. 000800 Channel bank 32, upto 32 channels.
00FC2000 max. 000800 Unknown data, realted to CH bank 32.
00FC0800 000040 VFO A settings, see channel_t.
00FC0840 000040 VFO B settings, see channel_t.
00FC2800 000080

Unknonw data, related to VFO A+B? It is of exactly the same size as the two VFO channels. Mostly 0x00, a few 0xff. Same pattern as the unknown data associated with channel banks.

Zones
Start Size Content
024C1300 000020 Bitmap of 250 zones.
01000000 max. 01f400 250 zones channel lists of 250 16bit indices each. 0-based, little endian, default/padded=0xffff. Offset between channel lists 0x200, size of each list 0x1f4.
02540000 max. 001f40

250 Zone names. Each zone name is upto 16 ASCII chars long and gets 0-padded to 32b.

Roaming
Start Size Content
01042000 000020 Roaming channel bitmask, up to 250 bits, 0-padded, default 0.
01040000 max. 0x1f40 Optional up to 250 roaming channels, of 32b each. See roaming_channel_t for details.
01042080 000010 Roaming zone bitmask, up to 64 bits, 0-padded, default 0.
01043000 max. 0x2000

Optional up to 64 roaming zones, of 128b each. See roaming_zone_t for details.

Contacts
Start Size Content
02600000 max. 009C40 Index list of valid contacts. 10000 32bit indices, little endian, default 0xffffffff
02640000 000500 Contact bitmap, 10000 bit, inverted, default 0xff, 0x00 padded.
02680000 max. 0f4240

10000 contacts, see contact_t. As each contact is 100b, they do not align with the 16b blocks being transferred to the device. Hence contacts are organized internally in groups of 4 contacts forming a "bank".

Analog Contacts
Start Size Content
02900000 000080 Index list of valid ananlog contacts.
02900100 000080 Bytemap for 128 analog contacts.
02940000 max. 000180

128 analog contacts. See analog_contact_t. As each analog contact is 24b, they do not align with the 16b transfer block-size. Hence analog contacts are internally organized in groups of 2.

RX Group Lists
Start Size Content
025C0B10 000020 Bitmap of 250 RX group lists, default/padding 0x00.
02980000 max. 000120 Grouplist 0, see grouplist_t.
02980200 max. 000120 Grouplist 1
... ... ...
0299f200 max. 000120

Grouplist 250

Scan lists
Start Size Content
024C1340 000020 Bitmap of 250 scan lists.
01080000 000090 Bank 0, Scanlist 1, see scanlist_t.
01080200 000090 Bank 0, Scanlist 2
... ... ...
01081E00 000090 Bank 0, Scanlist 16
010C0000 000090 Bank 1, Scanlist 17
... ... ...
01440000 000090 Bank 15, Scanlist 241
... ... ...
01441400 000090

Bank 15, Scanlist 250

Radio IDs
Start Size Content
024C1320 000020 Bitmap of 250 radio IDs.
02580000 max. 001f40

250 Radio IDs. See radioid_t.

GPS/APRS
Start Size Content
02501000 000040 APRS settings, see aprs_setting_t.
02501040 000060 APRS settings, see gps_systems_t.
02501200 000040

APRS Text, upto 60 chars ASCII, 0-padded.

General Settings
Start Size Content
02500000 000630 General settings, see general_settings_base_t.
02501280 000030 General settings extension 1, see general_settings_ext1_t.
02501400 000100 General settings extension 2, see general_settings_ext2_t.
024C2000 0003F0

List of 250 auto-repeater offset frequencies. 32bit little endian frequency in 10Hz. I.e., 600kHz = 60000. Default 0x00000000, 0x00 padded.

Messages
Start Size Content
01640000 max. 000100 Some kind of linked list of messages. See message_list_t. Each entry has a size of 0x10.
01640800 000090 Bytemap of up to 100 valid messages. 0x00=valid, 0xff=invalid, remaining 46b set to 0x00.
02140000 max. 000800 Bank 0, Messages 1-8. Each message consumes 0x100b. See message_t.
02180000 max. 000800 Bank 1, Messages 9-16
... ... ...
02440000 max. 000800

Bank 12, Messages 97-100

Hot Keys
Start Size Content
025C0000 000100 4 analog quick-call settings. See analog_quick_call_t.
025C0B00 000010 Status message bitmap.
025C0100 000400 Upto 32 status messages. Length unknown, offset 0x20. ASCII 0x00 terminated and padded.
025C0500 000360

18 hot-key settings, see hotkey_t

Encryption keys
Start Size Content
024C4000 004000

Upto 256 AES encryption keys. See encryption_key_t.

Misc
Start Size Content
024C1400 000020

Alarm setting, see analog_alarm_setting_t.

FM Broadcast
Start Size Content
02480210 000020 Bitmap of 100 FM broadcast channels.
02480000 max. 000200 100 FM broadcast channels. Encoded as 8-digit BCD little-endian in 100Hz. Filled with 0x00.
02480200 000010

FM broadcast VFO frequency. Encoded as 8-digit BCD little-endian in 100Hz. Filled with 0x00.

ID -> Contact map
Start Size Content
04340000 max. 013880

DMR ID to contact index map, see contact_map_t. Sorted by ID, empty entries set to 0xffffffffffffffff.

Still unknown
Start Size Content
024C0000 000020 Unknown data.
024C0C80 000010 Unknown data, bitmap?, default 0x00.
024C0D00 000200 Empty, set to 0x00?`
024C1000 0000D0 Unknown data.
024C1100 000010 Unknown data.
024C1280 000020 Unknown data.
024C1440 000030 Unknown data.
024C1700 000040 Unknown, 8bit indices.
024C1800 000500 Empty, set to 0x00?
024C2400 000030 Unknown data.
024C2600 000010 Unknown data.

Member Function Documentation

◆ allocateForDecoding()

void D878UVCodeplug::allocateForDecoding ( )

Allocate all code-plug elements that must be downloaded for decoding.

All code-plug elements with the radio that are not represented within the common Config are omitted.

◆ allocateUntouched()

void D878UVCodeplug::allocateUntouched ( )

Allocate all code-plug elements that must be written back to the device to maintain a working codeplug.

These elements might be updated during encoding.


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