Skip to content

Commit

Permalink
Fixed exisiting props of APRSSettings.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek committed Jun 24, 2023
1 parent 6239d4c commit 86d961f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 67 deletions.
131 changes: 73 additions & 58 deletions lib/d878uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2428,21 +2428,21 @@ D878UVCodeplug::APRSSettingsElement::isValid() const {

unsigned
D878UVCodeplug::APRSSettingsElement::fmTXDelay() const {
return ((unsigned)getUInt8(0x0005))*20;
return ((unsigned)getUInt8(Offset::fmTXDelay()))*20;
}
void
D878UVCodeplug::APRSSettingsElement::setFMTXDelay(unsigned ms) {
setUInt8(0x0005, ms/20);
setUInt8(Offset::fmTXDelay(), ms/20);
}

Signaling::Code
D878UVCodeplug::APRSSettingsElement::txTone() const {
if (0 == getUInt8(0x0006)) { // none
if ((uint8_t)SignalingType::Off ==getUInt8(Offset::fmSigType())) { // none
return Signaling::SIGNALING_NONE;
} else if (1 == getUInt8(0x0006)) { // CTCSS
return CTCSS::decode(getUInt8(0x0007));
} else if (2 == getUInt8(0x0006)) { // DCS
uint16_t code = getUInt16_le(0x0008);
} else if ((uint8_t)SignalingType::CTCSS == getUInt8(Offset::fmSigType())) { // CTCSS
return CTCSS::decode(getUInt8(Offset::fmCTCSS()));
} else if ((uint8_t)SignalingType::DCS == getUInt8(Offset::fmSigType())) { // DCS
uint16_t code = getUInt16_le(Offset::fmDCS());
if (512 < code)
return Signaling::fromDCSNumber(dec_to_oct(code), false);
return Signaling::fromDCSNumber(dec_to_oct(code-512), true);
Expand All @@ -2453,56 +2453,63 @@ D878UVCodeplug::APRSSettingsElement::txTone() const {
void
D878UVCodeplug::APRSSettingsElement::setTXTone(Signaling::Code code) {
if (Signaling::SIGNALING_NONE == code) {
setUInt8(0x0006, 0x00);
setUInt8(Offset::fmSigType(), (uint8_t)SignalingType::Off);
} else if (Signaling::isCTCSS(code)) {
setUInt8(0x0006, 0x01);
setUInt8(0x0007, CTCSS::encode(code));
setUInt8(Offset::fmSigType(), (uint8_t)SignalingType::CTCSS);
setUInt8(Offset::fmCTCSS(), CTCSS::encode(code));
} else if (Signaling::isDCSNormal(code)) {
setUInt8(0x0006, 0x02);
setUInt16_le(0x0008, oct_to_dec(Signaling::toDCSNumber(code)));
setUInt8(Offset::fmSigType(), (uint8_t)SignalingType::DCS);
setUInt16_le(Offset::fmDCS(), oct_to_dec(Signaling::toDCSNumber(code)));
} else if (Signaling::isDCSInverted(code)) {
setUInt8(0x0006, 0x02);
setUInt16_le(0x0008, oct_to_dec(Signaling::toDCSNumber(code))+512);
setUInt8(Offset::fmSigType(), (uint8_t)SignalingType::DCS);
setUInt16_le(Offset::fmDCS(), oct_to_dec(Signaling::toDCSNumber(code))+512);
}
}

unsigned
Interval
D878UVCodeplug::APRSSettingsElement::manualTXInterval() const {
return getUInt8(0x000a);
return Interval::fromSeconds(getUInt8(Offset::manualTXInterval()));
}
void
D878UVCodeplug::APRSSettingsElement::setManualTXInterval(unsigned sec) {
setUInt8(0x000a, sec);
D878UVCodeplug::APRSSettingsElement::setManualTXInterval(Interval sec) {
setUInt8(Offset::manualTXInterval(), sec.seconds());
}

bool
D878UVCodeplug::APRSSettingsElement::autoTX() const {
return 0!=autoTXInterval();
return ! autoTXInterval().isNull();
}
unsigned
Interval
D878UVCodeplug::APRSSettingsElement::autoTXInterval() const {
return ((unsigned)getUInt8(0x000b))*30;
return Interval::fromSeconds( ((unsigned)getUInt8(Offset::autoTXInterval()))*30 );
}
void
D878UVCodeplug::APRSSettingsElement::setAutoTXInterval(unsigned sec) {
setUInt8(0x000b, sec/30);
D878UVCodeplug::APRSSettingsElement::setAutoTXInterval(Interval sec) {
setUInt8(Offset::autoTXInterval(), sec.seconds()/30);
}
void
D878UVCodeplug::APRSSettingsElement::disableAutoTX() {
setAutoTXInterval(0);
setAutoTXInterval(Interval::fromMilliseconds(0));
}

bool
D878UVCodeplug::APRSSettingsElement::fixedLocationEnabled() const {
return getUInt8(0x000d);
return getUInt8(Offset::fixedLocation());
}
QGeoCoordinate
D878UVCodeplug::APRSSettingsElement::fixedLocation() const {
double latitude = getUInt8(0x000e) + double(getUInt8(0x000f))/60 + double(getUInt8(0x0010))/3600;
if (getUInt8(0x0011)) latitude *= -1;
double longitude = getUInt8(0x0012) + double(getUInt8(0x0013))/60 + double(getUInt8(0x0014))/3600;
if (getUInt8(0x0015)) longitude *= -1;
return QGeoCoordinate(latitude, longitude);
double latitude = getUInt8(Offset::fixedLatDeg()) + double(getUInt8(Offset::fixedLatMin()))/60
+ double(getUInt8(Offset::fixedLatSec()))/3600;
if (getUInt8(Offset::fixedLatSouth()))
latitude *= -1;

double longitude = getUInt8(Offset::fixedLonDeg()) + double(getUInt8(Offset::fixedLonMin()))/60
+ double(getUInt8(Offset::fixedLonSec()))/3600;
if (getUInt8(Offset::fixedLonWest()))
longitude *= -1;

double height_ft = getUInt16_le(Offset::fixedHeight());
return QGeoCoordinate(latitude, longitude, height_ft/3.281);
}
void
D878UVCodeplug::APRSSettingsElement::setFixedLocation(QGeoCoordinate &loc) {
Expand All @@ -2516,10 +2523,18 @@ D878UVCodeplug::APRSSettingsElement::setFixedLocation(QGeoCoordinate &loc) {
unsigned lon_deg = int(longitude); longitude -= lon_deg; longitude *= 60;
unsigned lon_min = int(longitude); longitude -= lon_min; longitude *= 60;
unsigned lon_sec = int(longitude);
setUInt8(0x000e, lat_deg); setUInt8(0x000f, lat_min); setUInt8(0x0010, lat_sec); setUInt8(0x0011, (south ? 0x01 : 0x00));
setUInt8(0x0012, lon_deg); setUInt8(0x0013, lon_min); setUInt8(0x0014, lon_sec); setUInt8(0x0015, (west ? 0x01 : 0x00));
unsigned height_ft = int(loc.altitude()*3.281);
setUInt8(Offset::fixedLatDeg(), lat_deg);
setUInt8(Offset::fixedLatMin(), lat_min);
setUInt8(Offset::fixedLatSec(), lat_sec);
setUInt8(Offset::fixedLatSouth(), (south ? 0x01 : 0x00));
setUInt8(Offset::fixedLonDeg(), lon_deg);
setUInt8(Offset::fixedLonMin(), lon_min);
setUInt8(Offset::fixedLonSec(), lon_sec);
setUInt8(Offset::fixedLonWest(), (west ? 0x01 : 0x00));
setUInt16_le(Offset::fixedHeight(), height_ft);
// enable fixed location.
setUInt8(0x000d, 0x01);
setUInt8(Offset::fixedLocation(), 0x01);
}
void
D878UVCodeplug::APRSSettingsElement::disableFixedLocation() {
Expand All @@ -2529,56 +2544,56 @@ D878UVCodeplug::APRSSettingsElement::disableFixedLocation() {
QString
D878UVCodeplug::APRSSettingsElement::destination() const {
// Terminated/padded with space
return readASCII(0x0016, 6, ' ');
return readASCII(Offset::destinationCall(), 6, ' ');
}
unsigned
D878UVCodeplug::APRSSettingsElement::destinationSSID() const {
return getUInt8(0x001c);
return getUInt8(Offset::destinationSSID());
}
void
D878UVCodeplug::APRSSettingsElement::setDestination(const QString &call, unsigned ssid) {
// Terminated/padded with space
writeASCII(0x0016, call, 6, ' ');
setUInt8(0x001c, ssid);
writeASCII(Offset::destinationCall(), call, 6, ' ');
setUInt8(Offset::destinationSSID(), ssid);
}
QString
D878UVCodeplug::APRSSettingsElement::source() const {
// Terminated/padded with space
return readASCII(0x001d, 6, ' ');
return readASCII(Offset::sourceCall(), 6, ' ');
}
unsigned
D878UVCodeplug::APRSSettingsElement::sourceSSID() const {
return getUInt8(0x0023);
return getUInt8(Offset::sourceSSID());
}
void
D878UVCodeplug::APRSSettingsElement::setSource(const QString &call, unsigned ssid) {
// Terminated/padded with space
writeASCII(0x001d, call, 6, ' ');
setUInt8(0x0023, ssid);
writeASCII(Offset::sourceCall(), call, 6, ' ');
setUInt8(Offset::sourceSSID(), ssid);
}

QString
D878UVCodeplug::APRSSettingsElement::path() const {
return readASCII(0x0024, 20, 0x00);
return readASCII(Offset::path(), 20, 0x00);
}
void
D878UVCodeplug::APRSSettingsElement::setPath(const QString &path) {
writeASCII(0x0024, path, 20, 0x00);
writeASCII(Offset::path(), path, 20, 0x00);
}

APRSSystem::Icon
D878UVCodeplug::APRSSettingsElement::icon() const {
return code2aprsicon(getUInt8(0x0039), getUInt8(0x003a));
return code2aprsicon(getUInt8(Offset::symbolTable()), getUInt8(Offset::symbol()));
}
void
D878UVCodeplug::APRSSettingsElement::setIcon(APRSSystem::Icon icon) {
setUInt8(0x0039, aprsicon2tablecode(icon));
setUInt8(0x003a, aprsicon2iconcode(icon));
setUInt8(Offset::symbolTable(), aprsicon2tablecode(icon));
setUInt8(Offset::symbol(), aprsicon2iconcode(icon));
}

Channel::Power
D878UVCodeplug::APRSSettingsElement::power() const {
switch (getUInt8(0x003b)) {
switch (getUInt8(Offset::fmPower())) {
case 0: return Channel::Power::Low;
case 1: return Channel::Power::Mid;
case 2: return Channel::Power::High;
Expand All @@ -2590,20 +2605,20 @@ void
D878UVCodeplug::APRSSettingsElement::setPower(Channel::Power power) {
switch (power) {
case Channel::Power::Min:
case Channel::Power::Low: setUInt8(0x003b, 0x00); break;
case Channel::Power::Mid: setUInt8(0x003b, 0x01); break;
case Channel::Power::High: setUInt8(0x003b, 0x02); break;
case Channel::Power::Max: setUInt8(0x003b, 0x03); break;
case Channel::Power::Low: setUInt8(Offset::fmPower(), 0x00); break;
case Channel::Power::Mid: setUInt8(Offset::fmPower(), 0x01); break;
case Channel::Power::High: setUInt8(Offset::fmPower(), 0x02); break;
case Channel::Power::Max: setUInt8(Offset::fmPower(), 0x03); break;
}
}

unsigned
Interval
D878UVCodeplug::APRSSettingsElement::preWaveDelay() const {
return ((unsigned)getUInt8(0x003c))*10;
return Interval::fromMilliseconds(((unsigned)getUInt8(Offset::fmPrewaveDelay()))*10);
}
void
D878UVCodeplug::APRSSettingsElement::setPreWaveDelay(unsigned ms) {
setUInt8(0x003c, ms/10);
D878UVCodeplug::APRSSettingsElement::setPreWaveDelay(Interval ms) {
setUInt8(Offset::fmPrewaveDelay(), ms.milliseconds()/10);
}

bool
Expand All @@ -2618,8 +2633,8 @@ D878UVCodeplug::APRSSettingsElement::fromAPRSSystem(const APRSSystem *sys, Conte
setFrequency(sys->revertChannel()->txFrequency()*1e6);
setTXTone(sys->revertChannel()->txTone());
setPower(sys->revertChannel()->power());
setManualTXInterval(sys->period());
setAutoTXInterval(sys->period());
setManualTXInterval(Interval::fromSeconds(sys->period()));
setAutoTXInterval(Interval::fromSeconds(sys->period()));
setDestination(sys->destination(), sys->destSSID());
setSource(sys->source(), sys->srcSSID());
setPath(sys->path());
Expand Down Expand Up @@ -3491,7 +3506,7 @@ D878UVCodeplug::encodeGPSSystems(const Flags &flags, Context &ctx, const ErrorSt
// This setting might be overridden by any analog APRS system below
APRSSettingsElement aprs(data(Offset::analogAPRSSettings()));
aprs.setAutoTXInterval(ctx.config()->posSystems()->gpsSystem(0)->period());
aprs.setManualTXInterval(ctx.config()->posSystems()->gpsSystem(0)->period());
aprs.setManualTXInterval(Interval::fromSeconds(ctx.config()->posSystems()->gpsSystem(0)->period()));
}
return true;
}
Expand Down
17 changes: 11 additions & 6 deletions lib/d878uv_codeplug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,11 @@ public:
/** Hidden constructor. */
APRSSettingsElement(uint8_t *ptr, unsigned size);

/** Possible settings for the FM APRS subtone type. */
enum class SignalingType {
Off=0, CTCSS=1, DCS=2
};

public:
/** Constructor. */
explicit APRSSettingsElement(uint8_t *ptr);
Expand All @@ -1182,16 +1187,16 @@ public:
virtual void setTXTone(Signaling::Code code);

/** Returns the manual TX interval in seconds. */
virtual unsigned manualTXInterval() const;
virtual Interval manualTXInterval() const;
/** Sets the manual TX interval in seconds. */
virtual void setManualTXInterval(unsigned sec);
virtual void setManualTXInterval(Interval sec);

/** Returns @c true if the auto transmit is enabled. */
virtual bool autoTX() const;
/** Returns the auto TX interval in seconds. */
virtual unsigned autoTXInterval() const;
virtual Interval autoTXInterval() const;
/** Sets the auto TX interval in seconds. */
virtual void setAutoTXInterval(unsigned sec);
virtual void setAutoTXInterval(Interval sec);
/** Disables auto tx. */
virtual void disableAutoTX();

Expand Down Expand Up @@ -1233,9 +1238,9 @@ public:
virtual void setPower(Channel::Power power);

/** Returns the pre-wave delay in ms. */
virtual unsigned preWaveDelay() const;
virtual Interval preWaveDelay() const;
/** Sets the pre-wave delay in ms. */
virtual void setPreWaveDelay(unsigned ms);
virtual void setPreWaveDelay(Interval ms);

/** Configures this APRS system from the given generic config. */
virtual bool fromAPRSSystem(const APRSSystem *sys, Context &ctx,
Expand Down
6 changes: 3 additions & 3 deletions lib/dmr6x2uv_codeplug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1785,8 +1785,8 @@ DMR6X2UVCodeplug::encodeGPSSystems(const Flags &flags, Context &ctx, const Error
// If there is at least one GPS system defined -> set auto TX interval.
// This setting might be overridden by any analog APRS system below
D878UVCodeplug::APRSSettingsElement aprs(data(ADDR_APRS_SETTINGS));
aprs.setAutoTXInterval(ctx.config()->posSystems()->gpsSystem(0)->period());
aprs.setManualTXInterval(ctx.config()->posSystems()->gpsSystem(0)->period());
aprs.setAutoTXInterval(Interval::fromSeconds(ctx.config()->posSystems()->gpsSystem(0)->period()));
aprs.setManualTXInterval(Interval::fromSeconds(ctx.config()->posSystems()->gpsSystem(0)->period()));
}
return true;
}
Expand All @@ -1799,7 +1799,7 @@ DMR6X2UVCodeplug::createGPSSystems(Context &ctx, const ErrorStack &err) {

// Before creating any GPS/APRS systems, get global auto TX interval
D878UVCodeplug::APRSSettingsElement aprs(data(ADDR_APRS_SETTINGS));
unsigned pos_intervall = aprs.autoTXInterval();
unsigned pos_intervall = aprs.autoTXInterval().seconds();

// Create APRS system (if enabled)
uint8_t *aprsmsg = (uint8_t *)data(ADDR_APRS_MESSAGE);
Expand Down

0 comments on commit 86d961f

Please sign in to comment.