Skip to content

Commit

Permalink
Fixed location settings for OpenGD77 channels (#557)
Browse files Browse the repository at this point in the history
* Added regression test.
* Fixed locator -> coordinate translation.
  • Loading branch information
hmatuschek authored Jan 23, 2025
1 parent a924fb8 commit 3c85868
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
20 changes: 12 additions & 8 deletions lib/opengd77base_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ OpenGD77BaseCodeplug::encodeAngle(double angle) {
uint32_t sign = (angle < 0) ? 1 : 0;
uint32_t decimals = std::abs(int(angle * 10000));
uint32_t deg = decimals/10000; decimals = decimals % 10000;
return (sign << 23) | (deg <<15) | decimals;
return (sign << 23) | (deg << 15) | decimals;
}

double
OpenGD77BaseCodeplug::decodeAngle(uint32_t code) {
return (((code >> 23) & 1) ? -1 : 1) * (
((code >> 15) & 0xff) + double(code & 0x7ff)/10000
((code >> 15) & 0xff) + double(code & 0x7fff)/10000
);
}

Expand Down Expand Up @@ -211,19 +211,19 @@ OpenGD77BaseCodeplug::ChannelElement::hasFixedPosition() const {

QGeoCoordinate
OpenGD77BaseCodeplug::ChannelElement::fixedPosition() const {
uint32_t latCode = (((uint32_t)getUInt8(Offset::latitude2())) << 24) +
(((uint32_t)getUInt8(Offset::latitude1())) << 16) +
uint32_t latCode = (((uint32_t)getUInt8(Offset::latitude2())) << 16) +
(((uint32_t)getUInt8(Offset::latitude1())) << 8) +
((uint32_t)getUInt8(Offset::latitude0()));
uint32_t lonCode = (((uint32_t)getUInt8(Offset::longitude2())) << 24) +
(((uint32_t)getUInt8(Offset::longitude1())) << 16) +
uint32_t lonCode = (((uint32_t)getUInt8(Offset::longitude2())) << 16) +
(((uint32_t)getUInt8(Offset::longitude1())) << 8) +
((uint32_t)getUInt8(Offset::longitude0()));

return QGeoCoordinate(decodeAngle(latCode), decodeAngle(lonCode));
}

void
OpenGD77BaseCodeplug::ChannelElement::setFixedPosition(const QGeoCoordinate &coordinate) {
if (!coordinate.isValid()) {
if (! coordinate.isValid()) {
clearFixedPosition();
return;
}
Expand Down Expand Up @@ -565,7 +565,10 @@ OpenGD77BaseCodeplug::ChannelElement::decode(Codeplug::Context &ctx, const Error
ch->openGD77ChannelExtension()->enableScanAllSkip(skipScan());
ch->openGD77ChannelExtension()->enableBeep(beep());
ch->openGD77ChannelExtension()->enablePowerSave(powerSave());
ch->openGD77ChannelExtension()->setLocation(fixedPosition());
if (hasFixedPosition())
ch->openGD77ChannelExtension()->setLocation(fixedPosition());
else
ch->openGD77ChannelExtension()->setLocation(QGeoCoordinate());
ch->openGD77ChannelExtension()->setTalkerAliasTS1(aliasTimeSlot1());
ch->openGD77ChannelExtension()->setTalkerAliasTS2(aliasTimeSlot2());

Expand Down Expand Up @@ -953,6 +956,7 @@ void
OpenGD77BaseCodeplug::APRSSettingsElement::clear() {
Element::clear();
setName("");
clearFixedPosition();
}


Expand Down
9 changes: 6 additions & 3 deletions lib/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ loc2deg(const QString &loc) {
if (4 > loc.size()) {
lon = lon - 180;
lat = lat - 90;
return QGeoCoordinate(lat, lon);
// Offset places coordinate in the middle of the square
return QGeoCoordinate(lat+5.0, lon+10.0);
}

l = loc[2].toUpper();
Expand All @@ -501,7 +502,8 @@ loc2deg(const QString &loc) {
if (6 > loc.size()){
lon = lon - 180;
lat = lat - 90;
return QGeoCoordinate(lat, lon);
// Offset places coordinate in the middle of the square
return QGeoCoordinate(lat+0.5, lon+1.0);
}

l = loc[4].toUpper();
Expand All @@ -511,7 +513,8 @@ loc2deg(const QString &loc) {

lon = lon - 180;
lat = lat - 90;
return QGeoCoordinate(lat, lon);
// Offset places coordinate in the middle of the square
return QGeoCoordinate(lat+1./48, lon+1./24);
}

QString
Expand Down
28 changes: 28 additions & 0 deletions test/opengd77_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,33 @@ OpenGD77Test::testChannelSubTones() {
QCOMPARE(rxTone.Hz(), 123.0);
}


void
OpenGD77Test::testChannelFixedLocation() {
ErrorStack err;
Config config, decoded;

if (! config.readYAML(":/data/fm_aprs_test.yaml", err)) {
QFAIL(QString("Cannot open codeplug file: %1")
.arg(err.format()).toLocal8Bit().constData());
}

auto ext = new OpenGD77ChannelExtension();
ext->setLocator("JO62jl");
config.channelList()->channel(0)->setOpenGD77ChannelExtension(ext);

if (! encodeDecode(config, decoded, err))
QFAIL(err.format().toLocal8Bit().constData());

QVERIFY(decoded.channelList()->channel(0)->openGD77ChannelExtension());
QCOMPARE(decoded.channelList()->channel(0)->openGD77ChannelExtension()->locator(), "JO62jl");

ext->setLocator("JO59gw");
if (! encodeDecode(config, decoded, err))
QFAIL(err.format().toLocal8Bit().constData());
QCOMPARE(decoded.channelList()->channel(0)->openGD77ChannelExtension()->locator(), "JO59gw");
}


QTEST_GUILESS_MAIN(OpenGD77Test)

2 changes: 2 additions & 0 deletions test/opengd77_test.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ private slots:
void testOverrideChannelRadioId();
/** Regression test for #549. */
void testChannelSubTones();
/** Regression test for #556. */
void testChannelFixedLocation();

protected:
static bool encodeDecode(Config &config, Config &decoded, const ErrorStack &err=ErrorStack());
Expand Down

0 comments on commit 3c85868

Please sign in to comment.