Skip to content

Commit

Permalink
Fixed encoding of SMS templates for AnyTone devices. Addresses #413.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek committed May 22, 2024
1 parent d630070 commit 631e480
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/manual/codeplug/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
<xi:include href="radioddity/extensions.xml"/>
<xi:include href="tyt/extensions.xml"/>
<xi:include href="anytone/extensions.xml"/>

<xi:include href="smsextension.xml"/>
</chapter>
11 changes: 9 additions & 2 deletions lib/d868uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,10 @@ 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++) {
MessageElement message(data(Offset::messageBanks() + (i/Limit::numMessagePerBank())*Offset::betweenMessageBanks()));
unsigned int addr =
Offset::messageBanks() + (i/Limit::numMessagePerBank())*Offset::betweenMessageBanks()
+ i*MessageElement::size();
MessageElement message(data(addr));
message.setMessage(ctx.get<SMSTemplate>(i)->message());
MessageListElement listElement(data(Offset::messageIndex() + i*Size::messageIndex()));
listElement.setIndex(i);
Expand All @@ -2178,9 +2181,13 @@ D868UVCodeplug::createSMSMessages(Context &ctx, const ErrorStack &err) {
for (unsigned int i=0; i<Limit::numMessages(); i++) {
if (! messages_bytemap.isEncoded(i))
continue;
MessageElement message(data(Offset::messageBanks() + (i/Limit::numMessagePerBank())*Offset::betweenMessageBanks()));
unsigned int addr =
Offset::messageBanks() + (i/Limit::numMessagePerBank())*Offset::betweenMessageBanks()
+ i*MessageElement::size();
MessageElement message(data(addr));
SMSTemplate *temp = new SMSTemplate();
temp->setName(QString("SMS %1").arg(i+1));
temp->setMessage(message.message());
ctx.config()->smsExtension()->smsTemplates()->add(temp);
ctx.add(temp, i);
}
Expand Down
32 changes: 32 additions & 0 deletions test/d868uve_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,37 @@ D868UVETest::testDTMFContacts() {
}


void
D868UVETest::testSMSTemplates() {
Config config;
config.radioIDs()->add(new DMRRadioID("ID", 1234567));
SMSTemplate *sms0 = new SMSTemplate(); sms0->setName("SMS0"); sms0->setMessage("ABC");
SMSTemplate *sms1 = new SMSTemplate(); sms1->setName("SMS1"); sms1->setMessage("XYZ");
config.smsExtension()->smsTemplates()->add(sms0);
config.smsExtension()->smsTemplates()->add(sms1);

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(), 2);
//QCOMPARE_NE(decoded.smsExtension()->smsTemplates()->message(0)->name(), "SMS0");
QCOMPARE(decoded.smsExtension()->smsTemplates()->message(0)->message(), "ABC");
//QCOMPARE_NE(decoded.smsExtension()->smsTemplates()->message(1)->name(), "SMS1");
QCOMPARE(decoded.smsExtension()->smsTemplates()->message(1)->message(), "XYZ");
}


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 @@ -17,6 +17,7 @@ private slots:
void testChannelFrequency();
void testAutoRepeaterOffset();
void testDTMFContacts();
void testSMSTemplates();
};

#endif // D878UV2TEST_HH

0 comments on commit 631e480

Please sign in to comment.