Skip to content

Commit

Permalink
Fixed crash of qdmr on failed decoding of codeplug for DR1801UV (fixed
Browse files Browse the repository at this point in the history
…#437) (#460)

* Prevent sending 'downloadFinished' signal twice.
* Fixed DR-1801UV decoder to handle sparse channel encoding.
* Fixed decoding of sparse zones for DR1801UV.
* Fixed decoding of sparse preset messages for DR1801UV.
* Fixed decoding of sparse scan lists for DR1801UV.
* Fixed decoding of sparse group lists for DR1801UV.
* Fixed false warning on decoding encryption keys.
  • Loading branch information
hmatuschek authored Jul 22, 2024
1 parent ddebf12 commit 4dc24f6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 47 deletions.
2 changes: 1 addition & 1 deletion doc/code/dr1801uv_zonebankelement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0000 | Zone count, uint16, little endian | Up current zone index, uint16, little endian |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0004 | Up current zone index, uint16_t, little endian | Unused, set to 0x0000 |
0004 | Down current zone index, uint16_t, little endian | Unused, set to 0x0000 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
0008 | Zone 0 ...
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
Expand Down
13 changes: 8 additions & 5 deletions lib/dr1801uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ DR1801UV::startDownload(bool blocking, const ErrorStack &err) {
// If non-blocking -> move device to this thread
if (_device && _device->isOpen())
_device->moveToThread(this);

start();

return true;
}

Expand Down Expand Up @@ -104,6 +106,8 @@ DR1801UV::run() {
return;
}

emit downloadStarted();

if (! download()) {
_device->read_finish();
_device->reboot();
Expand All @@ -124,6 +128,8 @@ DR1801UV::run() {
return;
}

emit uploadStarted();

if (! upload()) {
_device->write_finish();
_device->reboot();
Expand All @@ -132,10 +138,12 @@ DR1801UV::run() {
emit uploadError(this);
return;
}

_device->write_finish();
_device->reboot();
_device->close();
_task = StatusIdle;

emit uploadComplete(this);
} else if (StatusUploadCallsigns == _task) {
// Not implemented.
Expand All @@ -146,22 +154,17 @@ DR1801UV::run() {

bool
DR1801UV::download() {
emit downloadStarted();

if (! _device->readCodeplug(_codeplug, [this](unsigned int n, unsigned int total){
emit downloadProgress(float(n*100)/total); }, _errorStack)) {
errMsg(_errorStack) << "Cannot read codeplug from device.";
return false;
}

emit downloadFinished(this, &_codeplug);
return true;
}

bool
DR1801UV::upload() {
emit uploadStarted();

// First, read codeplug from the device
if (! _device->readCodeplug(_codeplug, [this](unsigned int n, unsigned int total) {
emit uploadProgress(float(n*50)/total); }, _errorStack))
Expand Down
75 changes: 35 additions & 40 deletions lib/dr1801uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ DR1801UVCodeplug::ChannelBankElement::setChannelName(unsigned int index, const Q

bool
DR1801UVCodeplug::ChannelBankElement::decode(Context &ctx, const ErrorStack &err) const {
for (unsigned int i=0; i<channelCount(); i++) {
for (unsigned int i=0,j=0; i<Limit::channelCount() && j<channelCount(); i++) {
ChannelElement ch = channel(i);
if (! ch.isValid()) {
errMsg(err) << "Cannot decode invalid channel at index " << i
<< ", got promissed " << channelCount() << " valid channels.";
return false;
}
if (! ch.isValid())
continue;
j++;
Channel *obj = ch.toChannelObj(ctx, err);
if (nullptr == obj) {
errMsg(err) << "Cannot decode channel at index " << i << ".";
Expand All @@ -78,8 +76,11 @@ DR1801UVCodeplug::ChannelBankElement::decode(Context &ctx, const ErrorStack &err

bool
DR1801UVCodeplug::ChannelBankElement::link(Context &ctx, const ErrorStack &err) const {
for (unsigned int i=0; i<channelCount(); i++) {
for (unsigned int i=0,j=0; i<Limit::channelCount() && j<channelCount(); i++) {
ChannelElement ch = channel(i);
if (! ch.isValid())
continue;
j++;
if (! ctx.has<Channel>(ch.index())) {
errMsg(err) << "Cannot link channel at index " << i
<< ". Channel not defined.";
Expand Down Expand Up @@ -844,13 +845,11 @@ DR1801UVCodeplug::GroupListBankElement::groupList(unsigned int index) const {

bool
DR1801UVCodeplug::GroupListBankElement::decode(Context &ctx, const ErrorStack &err) const {
for (unsigned int i=0; i<groupListCount(); i++) {
for (unsigned int i=0,j=0; i<Limit::groupListCount() && j<groupListCount(); i++) {
GroupListElement gl = groupList(i);
if (! gl.isValid()) {
errMsg(err) << "Cannot decode invalid group list at index " << i
<< ". Got " << groupListCount() << " valid group lists promissed.";
return false;
}
if (! gl.isValid())
continue;
j++;
RXGroupList *obj = gl.toGroupListObj(ctx, err);
if (nullptr == obj) {
errMsg(err) << "Cannot decode group list at index " << i << ".";
Expand All @@ -866,8 +865,11 @@ DR1801UVCodeplug::GroupListBankElement::decode(Context &ctx, const ErrorStack &e

bool
DR1801UVCodeplug::GroupListBankElement::link(Context &ctx, const ErrorStack &err) const {
for (unsigned int i=0; i<groupListCount(); i++) {
for (unsigned int i=0,j=0; i<Limit::groupListCount() && j<groupListCount(); i++) {
GroupListElement gl = groupList(i);
if (! gl.isValid())
continue;
j++;
if (! ctx.has<RXGroupList>(gl.index())) {
errMsg(err) << "Cannot link group list at index " << i
<< ". Group list not defined.";
Expand Down Expand Up @@ -1052,13 +1054,11 @@ DR1801UVCodeplug::ZoneBankElement::zone(unsigned int index) const {

bool
DR1801UVCodeplug::ZoneBankElement::decode(Context &ctx, const ErrorStack &err) const {
for (unsigned int i=0; i<zoneCount(); i++) {
for (unsigned int i=0,j=0; i<Limit::zoneCount() && j<zoneCount(); i++) {
ZoneElement zone(this->zone(i));
if (! zone.isValid()) {
errMsg(err) << "Unexpected invalid zone at index " << i
<< ", was promissed " << zoneCount() << " zones.";
return false;
}
if (! zone.isValid())
continue;
j++;

Zone *obj = zone.toZoneObj(ctx, err);
if (nullptr == obj) {
Expand All @@ -1077,13 +1077,11 @@ DR1801UVCodeplug::ZoneBankElement::decode(Context &ctx, const ErrorStack &err) c

bool
DR1801UVCodeplug::ZoneBankElement::link(Context &ctx, const ErrorStack &err) const {
for (unsigned int i=0; i<zoneCount(); i++) {
for (unsigned int i=0, j=0; i<Limit::zoneCount() && j<zoneCount(); i++) {
ZoneElement zone(this->zone(i));
if (! zone.isValid()) {
errMsg(err) << "Unexpected invalid zone at index " << i
<< ", was promissed " << zoneCount() << " zones.";
return false;
}
if (! zone.isValid())
continue;
j++;

if (! ctx.has<Zone>(zone.index())) {
errMsg(err) << "Cannot link zone at index " << i << ", not defined.";
Expand Down Expand Up @@ -1672,13 +1670,11 @@ DR1801UVCodeplug::ScanListBankElement::scanList(unsigned int index) const {

bool
DR1801UVCodeplug::ScanListBankElement::decode(Context &ctx, const ErrorStack &err) const {
for (unsigned int i=0; i<scanListCount(); i++) {
for (unsigned int i=0, j=0; i<Limit::scanListCount() && j<scanListCount(); i++) {
ScanListElement sl = scanList(i);
if (! sl.isValid()) {
errMsg(err) << "Cannot decode invalid scan list at index " << i
<< ". Was promissed " << scanListCount() << " scan lists.";
return false;
}
if (! sl.isValid())
continue;
j++;
ScanList *obj = sl.toScanListObj(ctx, err);
if (nullptr == obj) {
errMsg(err) << "Cannot decode scan list at index " << i << ".";
Expand All @@ -1694,13 +1690,11 @@ DR1801UVCodeplug::ScanListBankElement::decode(Context &ctx, const ErrorStack &er

bool
DR1801UVCodeplug::ScanListBankElement::link(Context &ctx, const ErrorStack &err) const {
for (unsigned int i=0; i<scanListCount(); i++) {
for (unsigned int i=0,j=0; i<Limit::scanListCount() && j<scanListCount(); i++) {
ScanListElement sl = scanList(i);
if (! sl.isValid()) {
errMsg(err) << "Cannot link invalid scan list at index " << i
<< ". Was promissed " << scanListCount() << " scan lists.";
return false;
}
if (! sl.isValid())
continue;
j++;
if (! ctx.has<ScanList>(sl.index())) {
errMsg(err) << "Cannot link scan list at index " << i
<< ". Scan list not defined.";
Expand Down Expand Up @@ -1975,10 +1969,11 @@ DR1801UVCodeplug::MessageBankElement::decode(Context &ctx, const ErrorStack &err

ctx.config()->smsExtension()->smsTemplates()->clear();

for (unsigned int i=0; i<messageCount(); i++) {
for (unsigned int i=0,j=0; i<Limit::messageCount() && j<messageCount(); i++) {
MessageElement msg = message(i);
if (! msg.isValid())
continue;
j++;
SMSTemplate *sms = new SMSTemplate();
sms->setName(QString("Message %1").arg(msg.index()));
sms->setMessage(msg.text());
Expand Down Expand Up @@ -2214,7 +2209,7 @@ DR1801UVCodeplug::EncryptionKeyBankElement::decode(Context &ctx, const ErrorStac
ctx.add(obj, key(i).index());
ctx.config()->commercialExtension()->encryptionKeys()->add(obj);
}
return false;
return true;
}

bool
Expand Down
2 changes: 1 addition & 1 deletion src/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ Application::onCodeplugDownloaded(Radio *radio, Codeplug *codeplug) {
_config->clear();
}

if (! radio->codeplug().postprocess(_config, err)) {
if (! codeplug->postprocess(_config, err)) {
ErrorMessageView(err).exec();
_config->clear();
}
Expand Down

0 comments on commit 4dc24f6

Please sign in to comment.