Skip to content

Commit

Permalink
Fixed contact storage adresses. Addreses #247.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek committed Sep 11, 2022
1 parent 30db189 commit bc79685
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
16 changes: 10 additions & 6 deletions lib/d578uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
#define CHANNEL_SIZE 0x00000040

#define NUM_CONTACTS 10000 // Total number of contacts
#define NUM_CONTACT_BANKS 2500 // Number of contact banks
#define CONTACTS_PER_BANK 4
#define CONTACT_BANK_0 0x02680000 // First bank of 4 contacts
#define CONTACT_BANK_SIZE 0x00000190 // Size of 4 contacts
#define CONTACTS_PER_BLOCK 4
#define CONTACT_BLOCK_0 0x02680000 // First bank of 4 contacts
#define CONTACT_BLOCK_SIZE 0x00000190 // Size of 4 contacts
#define CONTACT_BANK_SIZE 0x00040000 // Size of one contact bank
#define CONTACTS_PER_BANK 1000 // Number of contacts per bank
#define CONTACT_INDEX_LIST 0x02600000 // Address of contact index list
#define CONTACTS_BITMAP 0x02640000 // Address of contact bitmap
#define CONTACTS_BITMAP_SIZE 0x00000500 // Size of contact bitmap
Expand Down Expand Up @@ -193,7 +194,8 @@ D578UVCodeplug::allocateContacts() {
if (1 == ((contact_bitmap[i/8]>>(i%8)) & 0x01))
continue;
contactCount++;
uint32_t addr = CONTACT_BANK_0+(i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t bank_addr = CONTACT_BLOCK_0 + (i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t addr = bank_addr + (i%CONTACTS_PER_BANK)*CONTACT_SIZE;
if (nullptr == data(addr, 0)) {
image(0).addElement(addr, CONTACT_BANK_SIZE);
memset(data(addr), 0x00, CONTACT_BANK_SIZE);
Expand All @@ -215,7 +217,9 @@ D578UVCodeplug::encodeContacts(const Flags &flags, Context &ctx, const ErrorStac
QVector<DigitalContact*> contacts;
// Encode contacts and also collect id<->index map
for (int i=0; i<ctx.config()->contacts()->digitalCount(); i++) {
ContactElement con(data(CONTACT_BANK_0+i*CONTACT_SIZE));
uint32_t bank_addr = CONTACT_BLOCK_0 + (i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t addr = bank_addr + (i%CONTACTS_PER_BANK)*CONTACT_SIZE;
ContactElement con(data(addr));
DigitalContact *contact = ctx.config()->contacts()->digitalContact(i);
if(! con.fromContactObj(contact, ctx))
return false;
Expand Down
25 changes: 16 additions & 9 deletions lib/d868uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
#define VFO_SIZE 0x00000040 // Size of each VFO settings.

#define NUM_CONTACTS 10000 // Total number of contacts
#define NUM_CONTACT_BANKS 2500 // Number of contact banks
#define CONTACTS_PER_BANK 4
#define CONTACT_BANK_0 0x02680000 // First bank of 4 contacts
#define CONTACT_BANK_SIZE 0x00000190 // Size of 4 contacts
#define CONTACTS_PER_BLOCK 4
#define CONTACT_BLOCK_0 0x02680000 // First bank of 4 contacts
#define CONTACT_BLOCK_SIZE 0x00000190 // Size of 4 contacts
#define CONTACT_BANK_SIZE 0x00040000 // Size of one contact bank
#define CONTACTS_PER_BANK 1000 // Number of contacts per bank
#define CONTACT_INDEX_LIST 0x02600000 // Address of contact index list
#define CONTACTS_BITMAP 0x02640000 // Address of contact bitmap
#define CONTACTS_BITMAP_SIZE 0x00000500 // Size of contact bitmap
Expand Down Expand Up @@ -820,12 +821,14 @@ D868UVCodeplug::allocateContacts() {
if (1 == ((contact_bitmap[i/8]>>(i%8)) & 0x01))
continue;
contactCount++;
uint32_t addr = CONTACT_BANK_0+(i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t bank_addr = CONTACT_BLOCK_0 + (i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t addr = bank_addr + ((i%CONTACTS_PER_BANK)/CONTACTS_PER_BLOCK)*CONTACT_BLOCK_SIZE;
if (nullptr == data(addr, 0)) {
image(0).addElement(addr, CONTACT_BANK_SIZE);
memset(data(addr), 0x00, CONTACT_BANK_SIZE);
image(0).addElement(addr, CONTACT_BLOCK_SIZE);
memset(data(addr), 0x00, CONTACT_BLOCK_SIZE);
}
}

if (contactCount) {
image(0).addElement(CONTACT_INDEX_LIST, align_size(4*contactCount, 16));
memset(data(CONTACT_INDEX_LIST), 0xff, align_size(4*contactCount, 16));
Expand All @@ -841,7 +844,9 @@ D868UVCodeplug::encodeContacts(const Flags &flags, Context &ctx, const ErrorStac
QVector<DigitalContact*> contacts;
// Encode contacts and also collect id<->index map
for (int i=0; i<ctx.config()->contacts()->digitalCount(); i++) {
ContactElement con(data(CONTACT_BANK_0+i*CONTACT_SIZE));
uint32_t bank_addr = CONTACT_BLOCK_0 + (i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t addr = bank_addr + (i%CONTACTS_PER_BANK)*CONTACT_SIZE;
ContactElement con(data(addr));
DigitalContact *contact = ctx.config()->contacts()->digitalContact(i);
if(! con.fromContactObj(contact, ctx))
return false;
Expand Down Expand Up @@ -872,7 +877,9 @@ D868UVCodeplug::createContacts(Context &ctx, const ErrorStack &err) {
uint16_t bit = i%8, byte = i/8;
if (1 == ((contact_bitmap[byte]>>bit) & 0x01))
continue;
ContactElement con(data(CONTACT_BANK_0+i*CONTACT_SIZE));
uint32_t bank_addr = CONTACT_BLOCK_0 + (i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t addr = bank_addr + (i%CONTACTS_PER_BANK)*CONTACT_SIZE;
ContactElement con(data(addr));
if (DigitalContact *obj = con.toContactObj(ctx)) {
ctx.config()->contacts()->add(obj); ctx.add(obj, i);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/d868uv_codeplug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class GPSSystem;
* <tr><td>02600000</td> <td>max. 009C40</td> <td>Index list of valid contacts.
* 10000 32bit indices, little endian, default 0xffffffff</td></tr>
* <tr><td>02640000</td> <td>000500</td> <td>Contact bitmap, 10000 bit, inverted, default 0xff, 0x00 padded.</td></tr>
* <tr><td>02680000</td> <td>max. 0f4240</td> <td>10000 contacts,
* <tr><td>02680000</td> <td>max. 0186a0</td> <td>Bank 1 of 1000 contacts,
* see @c AnytoneCodeplug::ContactElement. 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". </td></tr>
* of 4 contacts. There are 10 banks, each containing 1000 contacts. The offset between banks is 0x40000. </td></tr>
* <tr><td>04340000</td> <td>max. 013880</td> <td>DMR ID to contact index map,
* see @c AnytoneCodeplug::ContactMapElement. Sorted by ID, empty entries set to
* @c 0xffffffffffffffff.</td>
Expand Down
20 changes: 12 additions & 8 deletions lib/d878uv2_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#include <QtEndian>

#define NUM_CONTACTS 10000 // Total number of contacts
#define NUM_CONTACT_BANKS 2500 // Number of contact banks
#define CONTACTS_PER_BANK 4
#define CONTACT_BANK_0 0x02680000 // First bank of 4 contacts
#define CONTACT_BANK_SIZE 0x00000190 // Size of 4 contacts
#define CONTACTS_PER_BLOCK 4
#define CONTACT_BLOCK_0 0x02680000 // First bank of 4 contacts
#define CONTACT_BLOCK_SIZE 0x00000190 // Size of 4 contacts
#define CONTACT_BANK_SIZE 0x00040000 // Size of one contact bank
#define CONTACTS_PER_BANK 1000 // Number of contacts per bank
#define CONTACT_INDEX_LIST 0x02600000 // Address of contact index list
#define CONTACTS_BITMAP 0x02640000 // Address of contact bitmap
#define CONTACTS_BITMAP_SIZE 0x00000500 // Size of contact bitmap
Expand Down Expand Up @@ -45,10 +46,11 @@ D878UV2Codeplug::allocateContacts() {
if (1 == ((contact_bitmap[i/8]>>(i%8)) & 0x01))
continue;
contactCount++;
uint32_t addr = CONTACT_BANK_0+(i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t bank_addr = CONTACT_BLOCK_0 + (contactCount/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t addr = bank_addr + ((i%CONTACTS_PER_BANK)/CONTACTS_PER_BLOCK)*CONTACT_BLOCK_SIZE;
if (nullptr == data(addr, 0)) {
image(0).addElement(addr, CONTACT_BANK_SIZE);
memset(data(addr), 0x00, CONTACT_BANK_SIZE);
image(0).addElement(addr, CONTACT_BLOCK_SIZE);
memset(data(addr), 0x00, CONTACT_BLOCK_SIZE);
}
}
if (contactCount) {
Expand All @@ -66,7 +68,9 @@ D878UV2Codeplug::encodeContacts(const Flags &flags, Context &ctx, const ErrorSta
QVector<DigitalContact*> contacts;
// Encode contacts and also collect id<->index map
for (int i=0; i<ctx.config()->contacts()->digitalCount(); i++) {
ContactElement con(data(CONTACT_BANK_0+i*CONTACT_SIZE));
uint32_t bank_addr = CONTACT_BLOCK_0 + (i/CONTACTS_PER_BANK)*CONTACT_BANK_SIZE;
uint32_t addr = bank_addr + (i%CONTACTS_PER_BANK)*CONTACT_SIZE;
ContactElement con(data(addr));
DigitalContact *contact = ctx.config()->contacts()->digitalContact(i);
if(! con.fromContactObj(contact, ctx))
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ Application::onCodeplugUploaded(Radio *radio) {
_mainWindow->findChild<QProgressBar *>("progress")->setVisible(false);
_mainWindow->setEnabled(true);

logError() << "Write complete.";
logDebug() << "Write complete.";

if (radio->wait(250))
radio->deleteLater();
Expand Down

0 comments on commit bc79685

Please sign in to comment.