From ab0cda90b6d72e3be99b08459e5a92b6bdce2dd4 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Fri, 2 Apr 2021 21:14:49 +0100 Subject: [PATCH] Add support for choosing metric or imperial units as per #829 --- plugins/feature/aprs/aprsgui.cpp | 115 ++++++++++--- plugins/feature/aprs/aprsgui.h | 7 + plugins/feature/aprs/aprsplugin.cpp | 2 +- plugins/feature/aprs/aprssettings.cpp | 30 ++++ plugins/feature/aprs/aprssettings.h | 16 ++ plugins/feature/aprs/aprssettingsdialog.cpp | 29 ++-- plugins/feature/aprs/aprssettingsdialog.h | 8 +- plugins/feature/aprs/aprssettingsdialog.ui | 177 +++++++++++++++----- plugins/feature/aprs/readme.md | 4 + sdrbase/util/aprs.h | 47 +++++- sdrbase/util/units.h | 10 ++ 11 files changed, 359 insertions(+), 86 deletions(-) diff --git a/plugins/feature/aprs/aprsgui.cpp b/plugins/feature/aprs/aprsgui.cpp index e44153bee..05c3e981f 100644 --- a/plugins/feature/aprs/aprsgui.cpp +++ b/plugins/feature/aprs/aprsgui.cpp @@ -363,7 +363,11 @@ bool APRSGUI::handleMessage(const Message& message) else { swgMapItem->setImage(new QString(QString("qrc:///%1").arg(aprs->m_symbolImage))); - swgMapItem->setText(new QString(aprs->toText())); + swgMapItem->setText(new QString(aprs->toText(true, false, '\n', + m_settings.m_altitudeUnits == APRSSettings::METRES, + (int)m_settings.m_speedUnits, + m_settings.m_temperatureUnits == APRSSettings::CELSIUS, + m_settings.m_rainfallUnits == APRSSettings::MILLIMETRE))); } swgMapItem->setImageMinZoom(11); @@ -609,6 +613,7 @@ void APRSGUI::displaySettings() ui->igate->setChecked(m_settings.m_igateEnabled); ui->stationFilter->setCurrentIndex((int)m_settings.m_stationFilter); ui->filterAddressee->setText(m_settings.m_filterAddressee); + setUnits(); // Order and size columns displayTableSettings(ui->packetsTable, packetsTableMenu, m_settings.m_packetsTableColumnSizes, m_settings.m_packetsTableColumnIndexes, APRS_PACKETS_TABLE_COLUMNS); @@ -693,11 +698,11 @@ void APRSGUI::updateSummary(APRSStation *station) ui->status->setText(station->m_latestStatus); ui->comment->setText(station->m_latestComment); ui->position->setText(station->m_latestPosition); - ui->altitude->setText(station->m_latestAltitude); + ui->altitude->setText(convertAltitude(station->m_latestAltitude)); ui->course->setText(station->m_latestCourse); - ui->speed->setText(station->m_latestSpeed); + ui->speed->setText(convertSpeed(station->m_latestSpeed)); ui->txPower->setText(station->m_powerWatts); - ui->antennaHeight->setText(station->m_antennaHeightFt); + ui->antennaHeight->setText(convertAltitude(station->m_antennaHeightFt)); ui->antennaGain->setText(station->m_antennaGainDB); ui->antennaDirectivity->setText(station->m_antennaDirectivity); ui->radioRange->setText(station->m_radioRange); @@ -779,17 +784,17 @@ void APRSGUI::addPacketToGUI(APRSStation *station, APRSPacket *aprs) if (aprs->m_hasGust) gustsItem->setData(Qt::DisplayRole, aprs->m_gust); if (aprs->m_hasTemp) - temperatureItem->setData(Qt::DisplayRole, aprs->m_temp); + temperatureItem->setData(Qt::DisplayRole, convertTemperature(aprs->m_temp)); if (aprs->m_hasHumidity) humidityItem->setData(Qt::DisplayRole, aprs->m_humidity); if (aprs->m_hasBarometricPressure) pressureItem->setData(Qt::DisplayRole, aprs->m_barometricPressure/10.0f); if (aprs->m_hasRainLastHr) - rainLastHourItem->setData(Qt::DisplayRole, aprs->m_rainLastHr); + rainLastHourItem->setData(Qt::DisplayRole, convertRainfall(aprs->m_rainLastHr)); if (aprs->m_hasRainLast24Hrs) - rainLast24HoursItem->setData(Qt::DisplayRole, aprs->m_rainLast24Hrs); + rainLast24HoursItem->setData(Qt::DisplayRole, convertRainfall(aprs->m_rainLast24Hrs)); if (aprs->m_hasRainSinceMidnight) - rainSinceMidnightItem->setData(Qt::DisplayRole, aprs->m_rainSinceMidnight); + rainSinceMidnightItem->setData(Qt::DisplayRole, convertRainfall(aprs->m_rainSinceMidnight)); if (aprs->m_hasLuminsoity) luminosityItem->setData(Qt::DisplayRole, aprs->m_luminosity); if (aprs->m_hasSnowfallLast24Hrs) @@ -939,11 +944,11 @@ void APRSGUI::addPacketToGUI(APRSStation *station, APRSPacket *aprs) longitudeItem->setData(Qt::DisplayRole, aprs->m_longitude); } if (aprs->m_hasAltitude) - altitudeItem->setData(Qt::DisplayRole, aprs->m_altitudeFt); + altitudeItem->setData(Qt::DisplayRole, convertAltitude(aprs->m_altitudeFt)); if (aprs->m_hasCourseAndSpeed) { courseItem->setData(Qt::DisplayRole, aprs->m_course); - speedItem->setData(Qt::DisplayRole, aprs->m_speed); + speedItem->setData(Qt::DisplayRole, convertSpeed(aprs->m_speed)); } } @@ -1155,17 +1160,17 @@ void APRSGUI::plotWeather() else if (plotSelectIdx == 2 && aprs->m_hasGust) addToSeries(series, dt, aprs->m_gust, minValue, maxValue); else if (plotSelectIdx == 3 && aprs->m_hasTemp) - addToSeries(series, dt, aprs->m_temp, minValue, maxValue); + addToSeries(series, dt, convertTemperature(aprs->m_temp), minValue, maxValue); else if (plotSelectIdx == 4 && aprs->m_hasHumidity) addToSeries(series, dt, aprs->m_humidity, minValue, maxValue); else if (plotSelectIdx == 5 && aprs->m_hasBarometricPressure) addToSeries(series, dt, aprs->m_barometricPressure/10.0, minValue, maxValue); else if (plotSelectIdx == 6 && aprs->m_hasRainLastHr) - addToSeries(series, dt, aprs->m_rainLastHr, minValue, maxValue); + addToSeries(series, dt, convertRainfall(aprs->m_rainLastHr), minValue, maxValue); else if (plotSelectIdx == 7 && aprs->m_hasRainLast24Hrs) - addToSeries(series, dt, aprs->m_rainLast24Hrs, minValue, maxValue); + addToSeries(series, dt, convertRainfall(aprs->m_rainLast24Hrs), minValue, maxValue); else if (plotSelectIdx == 8 && aprs->m_hasRainSinceMidnight) - addToSeries(series, dt, aprs->m_rainSinceMidnight, minValue, maxValue); + addToSeries(series, dt, convertRainfall(aprs->m_rainSinceMidnight), minValue, maxValue); else if (plotSelectIdx == 9 && aprs->m_hasLuminsoity) addToSeries(series, dt, aprs->m_luminosity, minValue, maxValue); else if (plotSelectIdx == 10 && aprs->m_hasSnowfallLast24Hrs) @@ -1383,11 +1388,11 @@ void APRSGUI::plotMotion() else if (plotSelectIdx == 1 && aprs->m_hasPosition) addToSeries(series, dt, aprs->m_longitude, minValue, maxValue); else if (plotSelectIdx == 2 && aprs->m_hasAltitude) - addToSeries(series, dt, aprs->m_altitudeFt, minValue, maxValue); + addToSeries(series, dt, convertAltitude(aprs->m_altitudeFt), minValue, maxValue); else if (plotSelectIdx == 3 && aprs->m_hasCourseAndSpeed) addToSeries(series, dt, aprs->m_course, minValue, maxValue); else if (plotSelectIdx == 4 && aprs->m_hasCourseAndSpeed) - addToSeries(series, dt, aprs->m_speed, minValue, maxValue); + addToSeries(series, dt, convertSpeed(aprs->m_speed), minValue, maxValue); } } } @@ -1606,8 +1611,8 @@ void APRSGUI::resizeTable() ui->motionTable->setItem(row, MOTION_COL_LATITUDE, new QTableWidgetItem("Latitude")); ui->motionTable->setItem(row, MOTION_COL_LONGITUDE, new QTableWidgetItem("Longitude")); ui->motionTable->setItem(row, MOTION_COL_ALTITUDE, new QTableWidgetItem("Message No")); - ui->motionTable->setItem(row, MOTION_COL_ALTITUDE, new QTableWidgetItem("Course")); - ui->motionTable->setItem(row, MOTION_COL_ALTITUDE, new QTableWidgetItem("Speed")); + ui->motionTable->setItem(row, MOTION_COL_COURSE, new QTableWidgetItem("Course")); + ui->motionTable->setItem(row, MOTION_COL_SPEED, new QTableWidgetItem("Speed")); ui->motionTable->resizeColumnsToContents(); ui->motionTable->removeRow(row); @@ -1905,17 +1910,79 @@ QAction *APRSGUI::motionTable_createCheckableItem(QString &text, int idx, bool c return action; } +void APRSGUI::setUnits() +{ + ui->altitudeUnitsLabel->setText(APRSSettings::m_altitudeUnitNames[m_settings.m_altitudeUnits]); + ui->antennaHeightUnitsLabel->setText(APRSSettings::m_altitudeUnitNames[m_settings.m_altitudeUnits]); + ui->speedUnitsLabel->setText(APRSSettings::m_speedUnitNames[m_settings.m_speedUnits]); + + ui->weatherTable->horizontalHeaderItem(WEATHER_COL_TEMPERATURE)->setText(QString("Temp (%1)").arg(APRSSettings::m_temperatureUnitNames[m_settings.m_temperatureUnits])); + + // Display data using new units + int idx = ui->stationSelect->currentIndex(); + if (idx >= 0) + on_stationSelect_currentIndexChanged(idx); +} + +QString APRSGUI::convertAltitude(const QString& altitude) +{ + if ((m_settings.m_altitudeUnits == APRSSettings::FEET) || altitude.isEmpty()) + return altitude; + else + return QString::number((int)std::round(Units::feetToMetres(altitude.toFloat()))); +} + +float APRSGUI::convertAltitude(float altitude) +{ + if (m_settings.m_altitudeUnits == APRSSettings::FEET) + return altitude; + else + return std::round(Units::feetToMetres(altitude)); +} + +QString APRSGUI::convertSpeed(const QString& speed) +{ + if ((m_settings.m_speedUnits == APRSSettings::KNOTS) || speed.isEmpty()) + return speed; + else if (m_settings.m_speedUnits == APRSSettings::MPH) + return QString::number(Units::knotsToIntegerMPH(speed.toFloat())); + else + return QString::number(Units::knotsToIntegerKPH(speed.toFloat())); +} + +int APRSGUI::convertSpeed(int speed) +{ + if (m_settings.m_speedUnits == APRSSettings::KNOTS) + return speed; + else if (m_settings.m_speedUnits == APRSSettings::MPH) + return Units::knotsToIntegerMPH(speed); + else + return Units::knotsToIntegerKPH(speed); +} + +int APRSGUI::convertTemperature(int temperature) +{ + if (m_settings.m_temperatureUnits == APRSSettings::FAHRENHEIT) + return temperature; + else + return (int)std::round(Units::fahrenheitToCelsius(temperature)); +} + +int APRSGUI::convertRainfall(int rainfall) +{ + if (m_settings.m_rainfallUnits == APRSSettings::HUNDREDTHS_OF_AN_INCH) + return rainfall; + else + return (int)std::round(Units::inchesToMilimetres(rainfall/100.0f)); +} + // Show settings dialog void APRSGUI::on_displaySettings_clicked() { - APRSSettingsDialog dialog(m_settings.m_igateServer, m_settings.m_igateCallsign, - m_settings.m_igatePasscode, m_settings.m_igateFilter); + APRSSettingsDialog dialog(&m_settings); if (dialog.exec() == QDialog::Accepted) { - m_settings.m_igateServer = dialog.m_igateServer; - m_settings.m_igateCallsign = dialog.m_igateCallsign; - m_settings.m_igatePasscode = dialog.m_igatePasscode; - m_settings.m_igateFilter = dialog.m_igateFilter; + setUnits(); applySettings(); } } diff --git a/plugins/feature/aprs/aprsgui.h b/plugins/feature/aprs/aprsgui.h index 9523cf4ef..9a6f94bbf 100644 --- a/plugins/feature/aprs/aprsgui.h +++ b/plugins/feature/aprs/aprsgui.h @@ -169,6 +169,13 @@ private: void updateSummary(APRSStation *station); void addPacketToGUI(APRSStation *station, APRSPacket *aprs); + void setUnits(); + QString convertAltitude(const QString& altitude); + float convertAltitude(float altitude); + QString convertSpeed(const QString& speed); + int convertSpeed(int speed); + int convertTemperature(int temperature); + int convertRainfall(int rainfall); private slots: void onMenuDialogCalled(const QPoint &p); diff --git a/plugins/feature/aprs/aprsplugin.cpp b/plugins/feature/aprs/aprsplugin.cpp index 8cd34bdd1..6357a3e82 100644 --- a/plugins/feature/aprs/aprsplugin.cpp +++ b/plugins/feature/aprs/aprsplugin.cpp @@ -30,7 +30,7 @@ const PluginDescriptor APRSPlugin::m_pluginDescriptor = { APRS::m_featureId, QStringLiteral("APRS"), - QStringLiteral("6.5.0"), + QStringLiteral("6.7.1"), QStringLiteral("(c) Jon Beniston, M7RCE"), QStringLiteral("https://github.com/f4exb/sdrangel"), true, diff --git a/plugins/feature/aprs/aprssettings.cpp b/plugins/feature/aprs/aprssettings.cpp index aa4d42654..62987fe58 100644 --- a/plugins/feature/aprs/aprssettings.cpp +++ b/plugins/feature/aprs/aprssettings.cpp @@ -33,6 +33,23 @@ const QStringList APRSSettings::m_pipeURIs = { QStringLiteral("sdrangel.channel.chirpchatdemod") }; +const QStringList APRSSettings::m_altitudeUnitNames = { + QStringLiteral("Feet"), + QStringLiteral("Metres") +}; + +const QStringList APRSSettings::m_speedUnitNames = { + QStringLiteral("Knots"), + QStringLiteral("MPH"), + QStringLiteral("KPH") +}; + +const QStringList APRSSettings::m_temperatureUnitNames = { + QStringLiteral("F"), + QStringLiteral("C") +}; + + APRSSettings::APRSSettings() { resetToDefaults(); @@ -48,6 +65,10 @@ void APRSSettings::resetToDefaults() m_igateEnabled = false; m_stationFilter = ALL; m_filterAddressee = ""; + m_altitudeUnits = FEET; + m_speedUnits = KNOTS; + m_temperatureUnits = FAHRENHEIT; + m_rainfallUnits = HUNDREDTHS_OF_AN_INCH; m_title = "APRS"; m_rgbColor = QColor(225, 25, 99).rgb(); m_useReverseAPI = false; @@ -106,6 +127,10 @@ QByteArray APRSSettings::serialize() const s.writeU32(13, m_reverseAPIPort); s.writeU32(14, m_reverseAPIFeatureSetIndex); s.writeU32(15, m_reverseAPIFeatureIndex); + s.writeS32(16, (int)m_altitudeUnits); + s.writeS32(17, (int)m_speedUnits); + s.writeS32(18, (int)m_temperatureUnits); + s.writeS32(19, (int)m_rainfallUnits); for (int i = 0; i < APRS_PACKETS_TABLE_COLUMNS; i++) s.writeS32(100 + i, m_packetsTableColumnIndexes[i]); @@ -177,6 +202,11 @@ bool APRSSettings::deserialize(const QByteArray& data) d.readU32(15, &utmp, 0); m_reverseAPIFeatureIndex = utmp > 99 ? 99 : utmp; + d.readS32(16, (int *)&m_altitudeUnits, (int)FEET); + d.readS32(17, (int *)&m_speedUnits, (int)KNOTS); + d.readS32(18, (int *)&m_temperatureUnits, (int)FAHRENHEIT); + d.readS32(19, (int *)&m_rainfallUnits, (int)HUNDREDTHS_OF_AN_INCH); + for (int i = 0; i < APRS_PACKETS_TABLE_COLUMNS; i++) d.readS32(100 + i, &m_packetsTableColumnIndexes[i], i); for (int i = 0; i < APRS_PACKETS_TABLE_COLUMNS; i++) diff --git a/plugins/feature/aprs/aprssettings.h b/plugins/feature/aprs/aprssettings.h index 65b4312d5..71a31c4fa 100644 --- a/plugins/feature/aprs/aprssettings.h +++ b/plugins/feature/aprs/aprssettings.h @@ -46,6 +46,18 @@ struct APRSSettings ALL, STATIONS, OBJECTS, WEATHER, TELEMETRY, COURSE_AND_SPEED } m_stationFilter; QString m_filterAddressee; + enum AltitudeUnits { + FEET, METRES + } m_altitudeUnits; + enum SpeedUnits { + KNOTS, MPH, KPH + } m_speedUnits; + enum TemperatureUnits { + FAHRENHEIT, CELSIUS + } m_temperatureUnits; + enum RainfallUnits { + HUNDREDTHS_OF_AN_INCH, MILLIMETRE + } m_rainfallUnits; QString m_title; quint32 m_rgbColor; bool m_useReverseAPI; @@ -74,6 +86,10 @@ struct APRSSettings static const QStringList m_pipeTypes; static const QStringList m_pipeURIs; + + static const QStringList m_altitudeUnitNames; + static const QStringList m_speedUnitNames; + static const QStringList m_temperatureUnitNames; }; #endif // INCLUDE_FEATURE_APRSSETTINGS_H_ diff --git a/plugins/feature/aprs/aprssettingsdialog.cpp b/plugins/feature/aprs/aprssettingsdialog.cpp index 4dc1a8fb7..dc11df79c 100644 --- a/plugins/feature/aprs/aprssettingsdialog.cpp +++ b/plugins/feature/aprs/aprssettingsdialog.cpp @@ -17,15 +17,20 @@ #include "aprssettingsdialog.h" -APRSSettingsDialog::APRSSettingsDialog(QString igateServer, QString igateCallsign, QString igatePasscode, QString igateFilter, QWidget* parent) : +APRSSettingsDialog::APRSSettingsDialog(APRSSettings* settings, QWidget* parent) : QDialog(parent), - ui(new Ui::APRSSettingsDialog) + ui(new Ui::APRSSettingsDialog), + m_settings(settings) { ui->setupUi(this); - ui->igateServer->setCurrentText(igateServer); - ui->igateCallsign->setText(igateCallsign); - ui->igatePasscode->setText(igatePasscode); - ui->igateFilter->setText(igateFilter); + ui->igateServer->setCurrentText(m_settings->m_igateServer); + ui->igateCallsign->setText(m_settings->m_igateCallsign); + ui->igatePasscode->setText(m_settings->m_igatePasscode); + ui->igateFilter->setText(m_settings->m_igateFilter); + ui->altitudeUnits->setCurrentIndex((int)m_settings->m_altitudeUnits); + ui->speedUnits->setCurrentIndex((int)m_settings->m_speedUnits); + ui->temperatureUnits->setCurrentIndex((int)m_settings->m_temperatureUnits); + ui->rainfallUnits->setCurrentIndex((int)m_settings->m_rainfallUnits); } APRSSettingsDialog::~APRSSettingsDialog() @@ -35,9 +40,13 @@ APRSSettingsDialog::~APRSSettingsDialog() void APRSSettingsDialog::accept() { - m_igateServer = ui->igateServer->currentText(); - m_igateCallsign = ui->igateCallsign->text(); - m_igatePasscode = ui->igatePasscode->text(); - m_igateFilter = ui->igateFilter->text(); + m_settings->m_igateServer = ui->igateServer->currentText(); + m_settings->m_igateCallsign = ui->igateCallsign->text(); + m_settings->m_igatePasscode = ui->igatePasscode->text(); + m_settings->m_igateFilter = ui->igateFilter->text(); + m_settings->m_altitudeUnits = (APRSSettings::AltitudeUnits)ui->altitudeUnits->currentIndex(); + m_settings->m_speedUnits = (APRSSettings::SpeedUnits)ui->speedUnits->currentIndex(); + m_settings->m_temperatureUnits = (APRSSettings::TemperatureUnits)ui->temperatureUnits->currentIndex(); + m_settings->m_rainfallUnits = (APRSSettings::RainfallUnits)ui->rainfallUnits->currentIndex(); QDialog::accept(); } diff --git a/plugins/feature/aprs/aprssettingsdialog.h b/plugins/feature/aprs/aprssettingsdialog.h index 76dc892ef..9b2d2420a 100644 --- a/plugins/feature/aprs/aprssettingsdialog.h +++ b/plugins/feature/aprs/aprssettingsdialog.h @@ -25,19 +25,15 @@ class APRSSettingsDialog : public QDialog { Q_OBJECT public: - explicit APRSSettingsDialog(QString igateServer, QString igateCallsign, QString igatePasscode, QString igateFilter, QWidget* parent = 0); + explicit APRSSettingsDialog(APRSSettings* settings, QWidget* parent = 0); ~APRSSettingsDialog(); - QString m_igateServer; - QString m_igateCallsign; - QString m_igatePasscode; - QString m_igateFilter; - private slots: void accept(); private: Ui::APRSSettingsDialog* ui; + APRSSettings *m_settings; }; #endif // INCLUDE_APRSSETTINGSDIALOG_H diff --git a/plugins/feature/aprs/aprssettingsdialog.ui b/plugins/feature/aprs/aprssettingsdialog.ui index d2ee9b07c..076ea121e 100644 --- a/plugins/feature/aprs/aprssettingsdialog.ui +++ b/plugins/feature/aprs/aprssettingsdialog.ui @@ -7,7 +7,7 @@ 0 0 351 - 179 + 275 @@ -23,6 +23,64 @@ + + + + IGate Callsign + + + + + + + Altitude Units + + + + + + + Units used for displaying altitudes + + + + Feet + + + + + Metres + + + + + + + + Speed Units + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + IGate Filter + + + @@ -58,40 +116,6 @@ - - - - IGate Server - - - - - - - IGate Passcode - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - IGate Callsign - - - @@ -99,10 +123,10 @@ - - + + - IGate Filter + IGate Server @@ -120,6 +144,83 @@ + + + + Units used for displaying speeds + + + + Knots + + + + + MPH + + + + + KPH + + + + + + + + IGate Passcode + + + + + + + Units used for displaying temperatures + + + + Fahrenheit + + + + + Celsius + + + + + + + + Temperature Units + + + + + + + Rainfall Units + + + + + + + Units used for displaying rainfall + + + + Hundredths of an inch + + + + + Millimetres + + + + diff --git a/plugins/feature/aprs/readme.md b/plugins/feature/aprs/readme.md index b7920a4e8..324fe7129 100644 --- a/plugins/feature/aprs/readme.md +++ b/plugins/feature/aprs/readme.md @@ -28,6 +28,10 @@ Pressing this button shows the APRS Settings Dialog. This dialog allows you to e * A serverside filter, that specifies which packets should be forwarded from the internet to SDRangel. See http://www.aprs-is.net/javAPRSFilter.aspx m/50 will send you packets within 50 km of the last known position of the station corresponding to the callsign used to log in with. If you do not have a corresponding station, you can specify a location by passing a latitude and longitude. E.g: r/lat/lon/50 +* The units in which altitudes are displyed (Feet or metres). +* The units in which object speeds are displayed (Knots, MPH or KPH). +* The units in which temperature is displayed (Fahrenheit or Celsius). +* The units in which rainfall is displayed (Hundredths of an inch or millimetres).

Map

diff --git a/sdrbase/util/aprs.h b/sdrbase/util/aprs.h index 9e2d6d3bb..d3933c539 100644 --- a/sdrbase/util/aprs.h +++ b/sdrbase/util/aprs.h @@ -322,7 +322,8 @@ struct SDRBASE_API APRSPacket { return bytes; } - QString toText(bool includeFrom=true, bool includePosition=false, char separator='\n') + QString toText(bool includeFrom=true, bool includePosition=false, char separator='\n', + bool altitudeMetres=false, int speedUnits=0, bool tempCelsius=false, bool rainfallMM=false) { QStringList text; @@ -351,9 +352,21 @@ struct SDRBASE_API APRSPacket { if (includePosition && m_hasPosition) text.append(QString("Latitude: %1 Longitude: %2").arg(m_latitude).arg(m_longitude)); if (m_hasAltitude) - text.append(QString("Altitude: %1 ft").arg(m_altitudeFt)); + { + if (altitudeMetres) + text.append(QString("Altitude: %1 m").arg((int)std::round(Units::feetToMetres(m_altitudeFt)))); + else + text.append(QString("Altitude: %1 ft").arg(m_altitudeFt)); + } if (m_hasCourseAndSpeed) - text.append(QString("Course: %1%3 Speed: %2 knts").arg(m_course).arg(m_speed).arg(QChar(0xb0))); + { + if (speedUnits == 0) + text.append(QString("Course: %1%3 Speed: %2 knts").arg(m_course).arg(m_speed).arg(QChar(0xb0))); + else if (speedUnits == 1) + text.append(QString("Course: %1%3 Speed: %2 mph").arg(m_course).arg(Units::knotsToIntegerMPH(m_speed)).arg(QChar(0xb0))); + else + text.append(QString("Course: %1%3 Speed: %2 kph").arg(m_course).arg(Units::knotsToIntegerKPH(m_speed)).arg(QChar(0xb0))); + } if (m_hasStationDetails) text.append(QString("TX Power: %1 Watts Antenna Height: %2 m Gain: %3 dB Direction: %4").arg(m_powerWatts).arg(std::round(Units::feetToMetres(m_antennaHeightFt))).arg(m_antennaGainDB).arg(m_antennaDirectivity)); @@ -379,7 +392,12 @@ struct SDRBASE_API APRSPacket { { air.append("Air"); if (m_hasTemp) - air.append(QString("Temperature %1C").arg(Units::fahrenheitToCelsius(m_temp), 0, 'f', 1)); + { + if (tempCelsius) + air.append(QString("Temperature %1C").arg(Units::fahrenheitToCelsius(m_temp), 0, 'f', 1)); + else + air.append(QString("Temperature %1F").arg(m_temp)); + } if (m_hasHumidity) air.append(QString("Humidity %1%").arg(m_humidity)); if (m_hasBarometricPressure) @@ -391,11 +409,26 @@ struct SDRBASE_API APRSPacket { { rain.append("Rain"); if (m_hasRainLastHr) - rain.append(QString("%1 mm last hour").arg(std::round(Units::inchesToMilimetres(m_rainLastHr/100.0)))); + { + if (rainfallMM) + rain.append(QString("%1 mm last hour").arg(std::round(Units::inchesToMilimetres(m_rainLastHr/100.0)))); + else + rain.append(QString("%1 1/100\" last hour").arg(m_rainLastHr)); + } if (m_hasRainLast24Hrs) - rain.append(QString("%1 mm last 24 hours").arg(std::round(Units::inchesToMilimetres(m_rainLast24Hrs/100.0)))); + { + if (rainfallMM) + rain.append(QString("%1 mm last 24 hours").arg(std::round(Units::inchesToMilimetres(m_rainLast24Hrs/100.0)))); + else + rain.append(QString("%1 1/100\" last 24 hours").arg(m_rainLast24Hrs)); + } if (m_hasRainSinceMidnight) - rain.append(QString("%1 mm since midnight").arg(std::round(Units::inchesToMilimetres(m_rainSinceMidnight/100.0)))); + { + if (rainfallMM) + rain.append(QString("%1 mm since midnight").arg(std::round(Units::inchesToMilimetres(m_rainSinceMidnight/100.0)))); + else + rain.append(QString("%1 1/100\" since midnight").arg(m_rainSinceMidnight)); + } weather.append(rain.join(' ')); } diff --git a/sdrbase/util/units.h b/sdrbase/util/units.h index 3f79f2dac..0d6559870 100644 --- a/sdrbase/util/units.h +++ b/sdrbase/util/units.h @@ -61,6 +61,16 @@ public: return (int)std::round(knotsToKPH(knots)); } + static float knotsToMPH(float knots) + { + return knots * 1.15078f; + } + + static int knotsToIntegerMPH(float knots) + { + return (int)std::round(knotsToMPH(knots)); + } + static float kmpsToKPH(float kps) { return kps * (60.0 * 60.0);