Skip to content

Commit

Permalink
Fixed SMS bank and message offset.
Browse files Browse the repository at this point in the history
Fixes #469. Also added regression tests.
  • Loading branch information
hmatuschek authored Aug 14, 2024
1 parent ebd6b72 commit 3c7a928
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/d868uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2159,9 +2159,8 @@ bool
D868UVCodeplug::encodeSMSMessages(const Flags &flags, Context &ctx, const ErrorStack &err) {
Q_UNUSED(flags); Q_UNUSED(err)
for (unsigned int i=0; i<ctx.count<SMSTemplate>(); i++) {
unsigned int addr =
Offset::messageBanks() + (i/Limit::numMessagePerBank())*Offset::betweenMessageBanks()
+ i*MessageElement::size();
unsigned int bank = i/Limit::numMessagePerBank(), msg_idx = i % Limit::numMessagePerBank();
unsigned int addr = Offset::messageBanks() + bank*Offset::betweenMessageBanks() + msg_idx*MessageElement::size();
MessageElement message(data(addr));
message.setMessage(ctx.get<SMSTemplate>(i)->message());
MessageListElement listElement(data(Offset::messageIndex() + i*Size::messageIndex()));
Expand All @@ -2181,9 +2180,8 @@ D868UVCodeplug::createSMSMessages(Context &ctx, const ErrorStack &err) {
for (unsigned int i=0; i<Limit::numMessages(); i++) {
if (! messages_bytemap.isEncoded(i))
continue;
unsigned int addr =
Offset::messageBanks() + (i/Limit::numMessagePerBank())*Offset::betweenMessageBanks()
+ i*MessageElement::size();
unsigned int bank = i/Limit::numMessagePerBank(), msg_idx = i % Limit::numMessagePerBank();
unsigned int addr = Offset::messageBanks() + bank*Offset::betweenMessageBanks() + msg_idx*MessageElement::size();
MessageElement message(data(addr));
SMSTemplate *temp = new SMSTemplate();
temp->setName(QString("SMS %1").arg(i+1));
Expand Down
30 changes: 30 additions & 0 deletions test/d868uve_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,35 @@ D868UVETest::testSMSTemplates() {
}


void
D868UVETest::testRegressionSMSTemplateOffset() {
// Regression test for issue #469, message index offset error if more than one bank is used
// (i.e., more than 8 SMS).
Config config;
config.radioIDs()->add(new DMRRadioID("ID", 1234567));
for (int i=0; i<9; i++) {
SMSTemplate *sms = new SMSTemplate(); sms->setName(QString("SMS%1").arg(i)); sms->setMessage("ABC");
config.smsExtension()->smsTemplates()->add(sms);
}

ErrorStack err;
D868UVCodeplug codeplug;
Codeplug::Flags flags; flags.updateCodePlug=false;
if (! codeplug.encode(&config, flags, err)) {
QFAIL(QString("Cannot encode codeplug for AnyTone AT-D868UVE: %1")
.arg(err.format()).toStdString().c_str());
}

Config decoded;
if (! codeplug.decode(&decoded, err)) {
QFAIL(QString("Cannot decode codeplug for AnyTone AT-D868UVE: %1")
.arg(err.format()).toStdString().c_str());
}

// For now, messages are not encoded
QCOMPARE(decoded.smsExtension()->smsTemplates()->count(), 9);
}


QTEST_GUILESS_MAIN(D868UVETest)

1 change: 1 addition & 0 deletions test/d868uve_test.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private slots:
void testAutoRepeaterOffset();
void testDTMFContacts();
void testSMSTemplates();
void testRegressionSMSTemplateOffset();
};

#endif // D878UV2TEST_HH

0 comments on commit 3c7a928

Please sign in to comment.