From bc796855cd150147e2ca90b6400421c8fd377346 Mon Sep 17 00:00:00 2001 From: Hannes Matuschek Date: Sun, 11 Sep 2022 16:02:42 +0200 Subject: [PATCH] Fixed contact storage adresses. Addreses #247. --- lib/d578uv_codeplug.cc | 16 ++++++++++------ lib/d868uv_codeplug.cc | 25 ++++++++++++++++--------- lib/d868uv_codeplug.hh | 4 ++-- lib/d878uv2_codeplug.cc | 20 ++++++++++++-------- src/application.cc | 2 +- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/lib/d578uv_codeplug.cc b/lib/d578uv_codeplug.cc index ad24779a..8a2c7aaf 100644 --- a/lib/d578uv_codeplug.cc +++ b/lib/d578uv_codeplug.cc @@ -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 @@ -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); @@ -215,7 +217,9 @@ D578UVCodeplug::encodeContacts(const Flags &flags, Context &ctx, const ErrorStac QVector contacts; // Encode contacts and also collect id<->index map for (int i=0; icontacts()->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; diff --git a/lib/d868uv_codeplug.cc b/lib/d868uv_codeplug.cc index 8011f43d..92d8407d 100644 --- a/lib/d868uv_codeplug.cc +++ b/lib/d868uv_codeplug.cc @@ -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 @@ -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)); @@ -841,7 +844,9 @@ D868UVCodeplug::encodeContacts(const Flags &flags, Context &ctx, const ErrorStac QVector contacts; // Encode contacts and also collect id<->index map for (int i=0; icontacts()->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; @@ -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); } diff --git a/lib/d868uv_codeplug.hh b/lib/d868uv_codeplug.hh index 634899cf..101546c4 100644 --- a/lib/d868uv_codeplug.hh +++ b/lib/d868uv_codeplug.hh @@ -61,10 +61,10 @@ class GPSSystem; * 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, + * 02680000 max. 0186a0 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". + * of 4 contacts. There are 10 banks, each containing 1000 contacts. The offset between banks is 0x40000. * 04340000 max. 013880 DMR ID to contact index map, * see @c AnytoneCodeplug::ContactMapElement. Sorted by ID, empty entries set to * @c 0xffffffffffffffff. diff --git a/lib/d878uv2_codeplug.cc b/lib/d878uv2_codeplug.cc index c54a5c93..c05c3519 100644 --- a/lib/d878uv2_codeplug.cc +++ b/lib/d878uv2_codeplug.cc @@ -11,10 +11,11 @@ #include #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 @@ -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) { @@ -66,7 +68,9 @@ D878UV2Codeplug::encodeContacts(const Flags &flags, Context &ctx, const ErrorSta QVector contacts; // Encode contacts and also collect id<->index map for (int i=0; icontacts()->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; diff --git a/src/application.cc b/src/application.cc index cebb759f..9c493cc4 100644 --- a/src/application.cc +++ b/src/application.cc @@ -682,7 +682,7 @@ Application::onCodeplugUploaded(Radio *radio) { _mainWindow->findChild("progress")->setVisible(false); _mainWindow->setEnabled(true); - logError() << "Write complete."; + logDebug() << "Write complete."; if (radio->wait(250)) radio->deleteLater();