diff --git a/plugins/feature/CMakeLists.txt b/plugins/feature/CMakeLists.txt index e6cf4b815..e2ac16f86 100644 --- a/plugins/feature/CMakeLists.txt +++ b/plugins/feature/CMakeLists.txt @@ -3,6 +3,11 @@ project(feature) if (Qt5SerialPort_FOUND) add_subdirectory(gs232controller) endif() + +if (Qt5Quick_FOUND AND Qt5QuickWidgets_FOUND AND Qt5Positioning_FOUND) + add_subdirectory(vorlocalizer) +endif() + add_subdirectory(afc) add_subdirectory(rigctlserver) add_subdirectory(simpleptt) diff --git a/plugins/feature/vorlocalizer/CMakeLists.txt b/plugins/feature/vorlocalizer/CMakeLists.txt new file mode 100644 index 000000000..d5bc45bbc --- /dev/null +++ b/plugins/feature/vorlocalizer/CMakeLists.txt @@ -0,0 +1,62 @@ +project(vorlocalizer) + +set(vor_SOURCES + vorlocalizer.cpp + vorlocalizersettings.cpp + vorlocalizerworker.cpp + vorlocalizerplugin.cpp + vorlocalizerwebapiadapter.cpp + vorlocalizerreport.cpp +) + +set(vor_HEADERS + vorlocalizer.h + vorlocalizersettings.h + vorlocalizerworker.h + vorlocalizerplugin.h + vorlocalizerwebapiadapter.h + vorlocalizerreport.h +) + + +include_directories( + ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client +) + +if(NOT SERVER_MODE) + set(vor_SOURCES + ${vor_SOURCES} + vorlocalizergui.cpp + vorlocalizergui.ui + map.qrc + icons.qrc + ) + set(vor_HEADERS + ${vor_HEADERS} + vorlocalizergui.h + navaid.h + ) + + set(TARGET_NAME vorlocalizer) + set(TARGET_LIB "Qt5::Widgets" Qt5::Quick Qt5::QuickWidgets Qt5::Positioning) + set(TARGET_LIB_GUI "sdrgui") + set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR}) +else() + set(TARGET_NAME vorlocalizersrv) + set(TARGET_LIB "") + set(TARGET_LIB_GUI "") + set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR}) +endif() + +add_library(${TARGET_NAME} SHARED + ${vor_SOURCES} +) + +target_link_libraries(${TARGET_NAME} + Qt5::Core + ${TARGET_LIB} + sdrbase + ${TARGET_LIB_GUI} +) + +install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER}) diff --git a/plugins/feature/vorlocalizer/icons.qrc b/plugins/feature/vorlocalizer/icons.qrc new file mode 100644 index 000000000..ca8be748f --- /dev/null +++ b/plugins/feature/vorlocalizer/icons.qrc @@ -0,0 +1,6 @@ + + + icons/compass.png + icons/vor.png + + diff --git a/plugins/feature/vorlocalizer/icons/compass.png b/plugins/feature/vorlocalizer/icons/compass.png new file mode 100644 index 000000000..1415a50f0 Binary files /dev/null and b/plugins/feature/vorlocalizer/icons/compass.png differ diff --git a/plugins/feature/vorlocalizer/icons/vor.png b/plugins/feature/vorlocalizer/icons/vor.png new file mode 100644 index 000000000..ac66aad04 Binary files /dev/null and b/plugins/feature/vorlocalizer/icons/vor.png differ diff --git a/plugins/feature/vorlocalizer/map.qrc b/plugins/feature/vorlocalizer/map.qrc new file mode 100644 index 000000000..b0018f5b9 --- /dev/null +++ b/plugins/feature/vorlocalizer/map.qrc @@ -0,0 +1,10 @@ + + + map/map.qml + map/MapStation.qml + map/antenna.png + map/VOR.png + map/VOR-DME.png + map/VORTAC.png + + diff --git a/plugins/feature/vorlocalizer/map/MapStation.qml b/plugins/feature/vorlocalizer/map/MapStation.qml new file mode 100644 index 000000000..a69346e46 --- /dev/null +++ b/plugins/feature/vorlocalizer/map/MapStation.qml @@ -0,0 +1,40 @@ +import QtQuick 2.12 +import QtLocation 5.12 +import QtPositioning 5.12 + +MapQuickItem { + id: station + property string stationName // Name of the station, E.g. Home + + coordinate: QtPositioning.coordinate(51.5, 0.125) // Location of the antenna (QTH) - London + zoomLevel: 11 + + anchorPoint.x: image.width/2 + anchorPoint.y: image.height/2 + + sourceItem: Grid { + columns: 1 + Grid { + horizontalItemAlignment: Grid.AlignHCenter + layer.enabled: true + layer.smooth: true + Image { + id: image + source: "antenna.png" + } + Rectangle { + id: bubble + color: "lightblue" + border.width: 1 + width: text.width * 1.3 + height: text.height * 1.3 + radius: 5 + Text { + id: text + anchors.centerIn: parent + text: stationName + } + } + } + } +} diff --git a/plugins/feature/vorlocalizer/map/VOR-DME.png b/plugins/feature/vorlocalizer/map/VOR-DME.png new file mode 100644 index 000000000..c2e2c412d Binary files /dev/null and b/plugins/feature/vorlocalizer/map/VOR-DME.png differ diff --git a/plugins/feature/vorlocalizer/map/VOR.png b/plugins/feature/vorlocalizer/map/VOR.png new file mode 100644 index 000000000..0d6949fde Binary files /dev/null and b/plugins/feature/vorlocalizer/map/VOR.png differ diff --git a/plugins/feature/vorlocalizer/map/VORTAC.png b/plugins/feature/vorlocalizer/map/VORTAC.png new file mode 100644 index 000000000..f7df0a0b3 Binary files /dev/null and b/plugins/feature/vorlocalizer/map/VORTAC.png differ diff --git a/plugins/feature/vorlocalizer/map/antenna.png b/plugins/feature/vorlocalizer/map/antenna.png new file mode 100644 index 000000000..f13c91881 Binary files /dev/null and b/plugins/feature/vorlocalizer/map/antenna.png differ diff --git a/plugins/feature/vorlocalizer/map/map.qml b/plugins/feature/vorlocalizer/map/map.qml new file mode 100644 index 000000000..0d6eb0508 --- /dev/null +++ b/plugins/feature/vorlocalizer/map/map.qml @@ -0,0 +1,115 @@ +import QtQuick 2.12 +import QtQuick.Window 2.12 +import QtLocation 5.12 +import QtPositioning 5.12 + +Item { + id: qmlMap + property int vorZoomLevel: 11 + + Plugin { + id: mapPlugin + name: "osm" + } + + Map { + id: map + objectName: "map" + anchors.fill: parent + plugin: mapPlugin + center: QtPositioning.coordinate(51.5, 0.125) // London + zoomLevel: 10 + + + MapItemView { + model: vorModel + delegate: vorRadialComponent + } + + MapStation { + id: station + objectName: "station" + stationName: "Home" + coordinate: QtPositioning.coordinate(51.5, 0.125) + } + + MapItemView { + model: vorModel + delegate: vorComponent + } + + onZoomLevelChanged: { + if (zoomLevel > 11) { + station.zoomLevel = zoomLevel + vorZoomLevel = zoomLevel + } else { + station.zoomLevel = 11 + vorZoomLevel = 11 + } + } + + } + + Component { + id: vorRadialComponent + MapPolyline { + line.width: 2 + line.color: 'gray' + path: vorRadial + } + } + + Component { + id: vorComponent + MapQuickItem { + id: vor + anchorPoint.x: image.width/2 + anchorPoint.y: bubble.height/2 + coordinate: position + zoomLevel: vorZoomLevel + + sourceItem: Grid { + columns: 1 + Grid { + horizontalItemAlignment: Grid.AlignHCenter + verticalItemAlignment: Grid.AlignVCenter + columnSpacing: 5 + layer.enabled: true + layer.smooth: true + Image { + id: image + source: vorImage + MouseArea { + anchors.fill: parent + hoverEnabled: true + onDoubleClicked: (mouse) => { + selected = !selected + } + } + } + Rectangle { + id: bubble + color: bubbleColour + border.width: 1 + width: text.width + 5 + height: text.height + 5 + radius: 5 + Text { + id: text + anchors.centerIn: parent + text: vorData + } + MouseArea { + anchors.fill: parent + hoverEnabled: true + onDoubleClicked: (mouse) => { + selected = !selected + } + } + } + } + } + } + } + +} diff --git a/plugins/feature/vorlocalizer/navaid.h b/plugins/feature/vorlocalizer/navaid.h new file mode 100644 index 000000000..0dc8bbf35 --- /dev/null +++ b/plugins/feature/vorlocalizer/navaid.h @@ -0,0 +1,367 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_NAVAID_H +#define INCLUDE_NAVAID_H + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "util/units.h" +#include "util/csv.h" + +#define OURAIRPORTS_NAVAIDS_URL "https://ourairports.com/data/navaids.csv" +#define OPENAIP_NAVAIDS_URL "https://www.openaip.net/customer_export_akfshb9237tgwiuvb4tgiwbf/%1_nav.aip" + +struct NavAid { + + int m_id; + QString m_ident; // 2 or 3 character ident + QString m_type; // VOR, VOR-DME or VORTAC + QString m_name; + float m_latitude; + float m_longitude; + float m_elevation; + int m_frequencykHz; + QString m_channel; + int m_range; // Nautical miles + float m_magneticDeclination; + bool m_alignedTrueNorth; // Is the VOR aligned to true North, rather than magnetic (may be the case at high latitudes) + + static QString trimQuotes(const QString s) + { + if (s.startsWith('\"') && s.endsWith('\"')) + return s.mid(1, s.size() - 2); + else + return s; + } + + int getRangeMetres() + { + return Units::nauticalMilesToIntegerMetres((float)m_range); + } + + // OpenAIP XML file + static void readNavAidsXML(QHash *navAidInfo, const QString &filename) + { + QFile file(filename); + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QXmlStreamReader xmlReader(&file); + + while(!xmlReader.atEnd() && !xmlReader.hasError()) + { + if (xmlReader.readNextStartElement()) + { + if (xmlReader.name() == "NAVAID") + { + QStringRef typeRef = xmlReader.attributes().value("TYPE"); + if ((typeRef == QLatin1String("VOR")) + || (typeRef== QLatin1String("VOR-DME")) + || (typeRef == QLatin1String("VORTAC"))) + { + QString type = typeRef.toString(); + int identifier = 0; + QString name; + QString id; + float lat = 0.0f; + float lon = 0.0f; + float elevation = 0.0f; + int frequency = 0; + QString channel; + int range = 25; + float declination = 0.0f; + bool alignedTrueNorth = false; + while(xmlReader.readNextStartElement()) + { + if (xmlReader.name() == QLatin1String("IDENTIFIER")) + identifier = xmlReader.readElementText().toInt(); + else if (xmlReader.name() == QLatin1String("NAME")) + name = xmlReader.readElementText(); + else if (xmlReader.name() == QLatin1String("ID")) + id = xmlReader.readElementText(); + else if (xmlReader.name() == QLatin1String("GEOLOCATION")) + { + while(xmlReader.readNextStartElement()) + { + if (xmlReader.name() == QLatin1String("LAT")) + lat = xmlReader.readElementText().toFloat(); + else if (xmlReader.name() == QLatin1String("LON")) + lon = xmlReader.readElementText().toFloat(); + else if (xmlReader.name() == QLatin1String("ELEV")) + elevation = xmlReader.readElementText().toFloat(); + else + xmlReader.skipCurrentElement(); + } + } + else if (xmlReader.name() == QLatin1String("RADIO")) + { + while(xmlReader.readNextStartElement()) + { + if (xmlReader.name() == QLatin1String("FREQUENCY")) + frequency = (int)(xmlReader.readElementText().toFloat() * 1000); + else if (xmlReader.name() == QLatin1String("CHANNEL")) + channel = xmlReader.readElementText(); + else + xmlReader.skipCurrentElement(); + } + } + else if (xmlReader.name() == QLatin1String("PARAMS")) + { + while(xmlReader.readNextStartElement()) + { + if (xmlReader.name() == QLatin1String("RANGE")) + range = xmlReader.readElementText().toInt(); + else if (xmlReader.name() == QLatin1String("DECLINATION")) + declination = xmlReader.readElementText().toFloat(); + else if (xmlReader.name() == QLatin1String("ALIGNEDTOTRUENORTH")) + alignedTrueNorth = xmlReader.readElementText() == "TRUE"; + else + xmlReader.skipCurrentElement(); + } + } + else + xmlReader.skipCurrentElement(); + } + NavAid *vor = new NavAid(); + vor->m_id = identifier; + vor->m_ident = id; + // Check idents conform to our filtering rules + if (vor->m_ident.size() < 2) + qDebug() << "Warning: VOR Ident less than 2 characters: " << vor->m_ident; + else if (vor->m_ident.size() > 3) + qDebug() << "Warning: VOR Ident greater than 3 characters: " << vor->m_ident; + vor->m_type = type; + vor->m_name = name; + vor->m_frequencykHz = frequency; + vor->m_channel = channel; + vor->m_latitude = lat; + vor->m_longitude = lon; + vor->m_elevation = elevation; + vor->m_range = range; + vor->m_magneticDeclination = declination; + vor->m_alignedTrueNorth = alignedTrueNorth; + navAidInfo->insert(identifier, vor); + } + } + } + } + + file.close(); + } + else + qDebug() << "NavAid::readNavAidsXML: Could not open " << filename << " for reading."; + } + + // Read OurAirport's NavAids CSV file + // See comments for readOSNDB + static QHash *readNavAidsDB(const QString &filename) + { + int cnt = 0; + QHash *navAidInfo = nullptr; + + // Column numbers used for the data as of 2020/10/28 + int idCol = 0; + int identCol = 2; + int typeCol = 4; + int nameCol = 3; + int frequencyCol = 5; + int latitudeCol = 6; + int longitudeCol = 7; + int elevationCol = 8; + int powerCol = 18; + + qDebug() << "NavAid::readNavAidsDB: " << filename; + + FILE *file; + QByteArray utfFilename = filename.toUtf8(); + if ((file = fopen(utfFilename.constData(), "r")) != NULL) + { + char row[2048]; + + if (fgets(row, sizeof(row), file)) + { + navAidInfo = new QHash(); + navAidInfo->reserve(15000); + + // Read header + int idx = 0; + char *p = strtok(row, ","); + while (p != NULL) + { + if (!strcmp(p, "id")) + idCol = idx; + else if (!strcmp(p, "ident")) + identCol = idx; + else if (!strcmp(p, "type")) + typeCol = idx; + else if (!strcmp(p, "name")) + nameCol = idx; + else if (!strcmp(p, "frequency_khz")) + frequencyCol = idx; + else if (!strcmp(p, "latitude_deg")) + latitudeCol = idx; + else if (!strcmp(p, "longitude_deg")) + longitudeCol = idx; + else if (!strcmp(p, "elevation_ft")) + elevationCol = idx; + else if (!strcmp(p, "power")) + powerCol = idx; + p = strtok(NULL, ","); + idx++; + } + // Read data + while (fgets(row, sizeof(row), file)) + { + int id = 0; + char *idString = NULL; + char *ident = NULL; + size_t identLen = 0; + char *type = NULL; + size_t typeLen = 0; + char *name = NULL; + size_t nameLen = 0; + char *frequencyString = NULL; + int frequency; + float latitude = 0.0f; + char *latitudeString = NULL; + size_t latitudeLen = 0; + float longitude = 0.0f; + char *longitudeString = NULL; + size_t longitudeLen = 0; + float elevation = 0.0f; + char *elevationString = NULL; + size_t elevationLen = 0; + char *power = NULL; + size_t powerLen = 0; + + char *q = row; + idx = 0; + while ((p = csvNext(&q)) != nullptr) + { + // Read strings, stripping quotes + if (idx == idCol) + { + idString = p; + idString[strlen(idString)] = '\0'; + id = strtol(idString, NULL, 10); + } + else if ((idx == identCol) && (p[0] == '\"')) + { + ident = p+1; + identLen = strlen(ident)-1; + ident[identLen] = '\0'; + } + else if ((idx == typeCol) && (p[0] == '\"')) + { + type = p+1; + typeLen = strlen(type)-1; + type[typeLen] = '\0'; + } + else if ((idx == nameCol) && (p[0] == '\"')) + { + name = p+1; + nameLen = strlen(name)-1; + name[nameLen] = '\0'; + } + if (idx == frequencyCol) + { + frequencyString = p; + frequencyString[strlen(frequencyString)] = '\0'; + frequency = strtol(frequencyString, NULL, 10); + } + else if (idx == latitudeCol) + { + latitudeString = p; + latitudeLen = strlen(latitudeString)-1; + latitudeString[latitudeLen] = '\0'; + latitude = atof(latitudeString); + } + else if (idx == longitudeCol) + { + longitudeString = p; + longitudeLen = strlen(longitudeString)-1; + longitudeString[longitudeLen] = '\0'; + longitude = atof(longitudeString); + } + else if (idx == elevationCol) + { + elevationString = p; + elevationLen = strlen(elevationString)-1; + elevationString[elevationLen] = '\0'; + elevation = atof(elevationString); + } + else if ((idx == powerCol) && (p[0] == '\"')) + { + power = p+1; + powerLen = strlen(power)-1; + power[powerLen] = '\0'; + } + idx++; + } + + // For now, we only want VORs + if (type && !strncmp(type, "VOR", 3)) + { + NavAid *vor = new NavAid(); + vor->m_id = id; + vor->m_ident = QString(ident); + // Check idents conform to our filtering rules + if (vor->m_ident.size() < 2) + qDebug() << "Warning: VOR Ident less than 2 characters: " << vor->m_ident; + else if (vor->m_ident.size() > 3) + qDebug() << "Warning: VOR Ident greater than 3 characters: " << vor->m_ident; + vor->m_type = QString(type); + vor->m_name = QString(name); + vor->m_frequencykHz = frequency; + vor->m_latitude = latitude; + vor->m_longitude = longitude; + vor->m_elevation = elevation; + if (power && !strcmp(power, "HIGH")) + vor->m_range = 100; + else if (power && !strcmp(power, "MEDIUM")) + vor->m_range = 40; + else + vor->m_range = 25; + vor->m_magneticDeclination = 0.0f; + vor->m_alignedTrueNorth = false; + navAidInfo->insert(id, vor); + cnt++; + } + } + } + fclose(file); + } + else + qDebug() << "NavAid::readNavAidsDB: Failed to open " << filename; + + qDebug() << "NavAid::readNavAidsDB: Read " << cnt << " VORs"; + + return navAidInfo; + } + +}; + +#endif // INCLUDE_NAVAID_H diff --git a/plugins/feature/vorlocalizer/vorlocalizer.cpp b/plugins/feature/vorlocalizer/vorlocalizer.cpp new file mode 100644 index 000000000..56e2033df --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizer.cpp @@ -0,0 +1,345 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +#include "SWGFeatureSettings.h" +#include "SWGFeatureReport.h" +#include "SWGFeatureActions.h" +#include "SWGSimplePTTReport.h" +#include "SWGDeviceState.h" + +#include "dsp/dspengine.h" + +#include "vorlocalizerworker.h" +#include "vorlocalizer.h" + +MESSAGE_CLASS_DEFINITION(VORLocalizer::MsgConfigureVORLocalizer, Message) +MESSAGE_CLASS_DEFINITION(VORLocalizer::MsgStartStop, Message) +MESSAGE_CLASS_DEFINITION(VORLocalizer::MsgAddVORChannel, Message) +MESSAGE_CLASS_DEFINITION(VORLocalizer::MsgRemoveVORChannel, Message) +MESSAGE_CLASS_DEFINITION(VORLocalizer::MsgRefreshChannels, Message) + +const char* const VORLocalizer::m_featureIdURI = "sdrangel.feature.vorlocalizer"; +const char* const VORLocalizer::m_featureId = "VORLocalizer"; + +VORLocalizer::VORLocalizer(WebAPIAdapterInterface *webAPIAdapterInterface) : + Feature(m_featureIdURI, webAPIAdapterInterface), + m_ptt(false) +{ + setObjectName(m_featureId); + m_worker = new VorLocalizerWorker(webAPIAdapterInterface); + m_state = StIdle; + m_errorMessage = "VORLocalizer error"; +} + +VORLocalizer::~VORLocalizer() +{ + if (m_worker->isRunning()) { + stop(); + } + + delete m_worker; +} + +void VORLocalizer::start() +{ + qDebug("VORLocalizer::start"); + + m_worker->reset(); + m_worker->setMessageQueueToGUI(getMessageQueueToGUI()); + bool ok = m_worker->startWork(); + m_state = ok ? StRunning : StError; + m_thread.start(); + + VorLocalizerWorker::MsgConfigureVORLocalizerWorker *msg = VorLocalizerWorker::MsgConfigureVORLocalizerWorker::create(m_settings, true); + m_worker->getInputMessageQueue()->push(msg); +} + +void VORLocalizer::stop() +{ + qDebug("VORLocalizer::stop"); + m_worker->stopWork(); + m_state = StIdle; + m_thread.quit(); + m_thread.wait(); +} + +bool VORLocalizer::handleMessage(const Message& cmd) +{ + if (MsgConfigureVORLocalizer::match(cmd)) + { + MsgConfigureVORLocalizer& cfg = (MsgConfigureVORLocalizer&) cmd; + qDebug() << "VORLocalizer::handleMessage: MsgConfigureVORLocalizer"; + applySettings(cfg.getSettings(), cfg.getForce()); + + return true; + } + else if (MsgStartStop::match(cmd)) + { + MsgStartStop& cfg = (MsgStartStop&) cmd; + qDebug() << "VORLocalizer::handleMessage: MsgStartStop: start:" << cfg.getStartStop(); + + if (cfg.getStartStop()) { + start(); + } else { + stop(); + } + + return true; + } + else if (MsgRefreshChannels::match(cmd)) + { + qDebug() << "VORLocalizer::handleMessage: MsgRefreshChannels"; + VorLocalizerWorker::MsgRefreshChannels *msg = VorLocalizerWorker::MsgRefreshChannels::create(); + m_worker->getInputMessageQueue()->push(msg); + return true; + } + else + { + return false; + } +} + +QByteArray VORLocalizer::serialize() const +{ + return m_settings.serialize(); +} + +bool VORLocalizer::deserialize(const QByteArray& data) +{ + if (m_settings.deserialize(data)) + { + MsgConfigureVORLocalizer *msg = MsgConfigureVORLocalizer::create(m_settings, true); + m_inputMessageQueue.push(msg); + return true; + } + else + { + m_settings.resetToDefaults(); + MsgConfigureVORLocalizer *msg = MsgConfigureVORLocalizer::create(m_settings, true); + m_inputMessageQueue.push(msg); + return false; + } +} + +void VORLocalizer::applySettings(const VORLocalizerSettings& settings, bool force) +{ + qDebug() << "VORLocalizer::applySettings:" + << " m_title: " << settings.m_title + << " m_rgbColor: " << settings.m_rgbColor + << " m_magDecAdjust: " << settings.m_magDecAdjust + << " force: " << force; + + QList reverseAPIKeys; + + if ((m_settings.m_title != settings.m_title) || force) { + reverseAPIKeys.append("title"); + } + if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) { + reverseAPIKeys.append("rgbColor"); + } + if ((m_settings.m_magDecAdjust != settings.m_magDecAdjust) || force) { + reverseAPIKeys.append("magDecAdjust"); + } + + VorLocalizerWorker::MsgConfigureVORLocalizerWorker *msg = VorLocalizerWorker::MsgConfigureVORLocalizerWorker::create( + settings, force + ); + m_worker->getInputMessageQueue()->push(msg); + + if (settings.m_useReverseAPI) + { + bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) || + (m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) || + (m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) || + (m_settings.m_reverseAPIFeatureSetIndex != settings.m_reverseAPIFeatureSetIndex) || + (m_settings.m_reverseAPIFeatureIndex != settings.m_reverseAPIFeatureIndex); + webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force); + } + + m_settings = settings; +} + +int VORLocalizer::webapiRun(bool run, + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage) +{ + (void) errorMessage; + getFeatureStateStr(*response.getState()); + MsgStartStop *msg = MsgStartStop::create(run); + getInputMessageQueue()->push(msg); + return 202; +} + +int VORLocalizer::webapiSettingsGet( + SWGSDRangel::SWGFeatureSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setSimplePttSettings(new SWGSDRangel::SWGSimplePTTSettings()); + response.getSimplePttSettings()->init(); + webapiFormatFeatureSettings(response, m_settings); + return 200; +} + +int VORLocalizer::webapiSettingsPutPatch( + bool force, + const QStringList& featureSettingsKeys, + SWGSDRangel::SWGFeatureSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + VORLocalizerSettings settings = m_settings; + webapiUpdateFeatureSettings(settings, featureSettingsKeys, response); + + MsgConfigureVORLocalizer *msg = MsgConfigureVORLocalizer::create(settings, force); + m_inputMessageQueue.push(msg); + + qDebug("VORLocalizer::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue); + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigureVORLocalizer *msgToGUI = MsgConfigureVORLocalizer::create(settings, force); + m_guiMessageQueue->push(msgToGUI); + } + + webapiFormatFeatureSettings(response, settings); + + return 200; +} + +void VORLocalizer::webapiFormatFeatureSettings( + SWGSDRangel::SWGFeatureSettings& response, + const VORLocalizerSettings& settings) +{ + if (response.getVorLocalizerSettings()->getTitle()) { + *response.getVorLocalizerSettings()->getTitle() = settings.m_title; + } else { + response.getVorLocalizerSettings()->setTitle(new QString(settings.m_title)); + } + + response.getVorLocalizerSettings()->setRgbColor(settings.m_rgbColor); + response.getVorLocalizerSettings()->setMagDecAdjust(settings.m_magDecAdjust); + + response.getVorLocalizerSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); + + if (response.getVorLocalizerSettings()->getReverseApiAddress()) { + *response.getVorLocalizerSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; + } else { + response.getVorLocalizerSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); + } + + response.getVorLocalizerSettings()->setReverseApiPort(settings.m_reverseAPIPort); + response.getVorLocalizerSettings()->setReverseApiFeatureSetIndex(settings.m_reverseAPIFeatureSetIndex); + response.getVorLocalizerSettings()->setReverseApiFeatureIndex(settings.m_reverseAPIFeatureIndex); +} + +void VORLocalizer::webapiUpdateFeatureSettings( + VORLocalizerSettings& settings, + const QStringList& featureSettingsKeys, + SWGSDRangel::SWGFeatureSettings& response) +{ + if (featureSettingsKeys.contains("title")) { + settings.m_title = *response.getVorLocalizerSettings()->getTitle(); + } + if (featureSettingsKeys.contains("rgbColor")) { + settings.m_rgbColor = response.getVorLocalizerSettings()->getRgbColor(); + } + if (featureSettingsKeys.contains("magDecAdjust")) { + settings.m_magDecAdjust = response.getVorLocalizerSettings()->getMagDecAdjust(); + } + if (featureSettingsKeys.contains("useReverseAPI")) { + settings.m_useReverseAPI = response.getVorLocalizerSettings()->getUseReverseApi() != 0; + } + if (featureSettingsKeys.contains("reverseAPIAddress")) { + settings.m_reverseAPIAddress = *response.getVorLocalizerSettings()->getReverseApiAddress(); + } + if (featureSettingsKeys.contains("reverseAPIPort")) { + settings.m_reverseAPIPort = response.getVorLocalizerSettings()->getReverseApiPort(); + } + if (featureSettingsKeys.contains("reverseAPIFeatureSetIndex")) { + settings.m_reverseAPIFeatureSetIndex = response.getVorLocalizerSettings()->getReverseApiFeatureSetIndex(); + } + if (featureSettingsKeys.contains("reverseAPIFeatureIndex")) { + settings.m_reverseAPIFeatureIndex = response.getVorLocalizerSettings()->getReverseApiFeatureIndex(); + } +} + +void VORLocalizer::webapiReverseSendSettings(QList& channelSettingsKeys, const VORLocalizerSettings& settings, bool force) +{ + SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings(); + // swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet()); + // swgFeatureSettings->setOriginatorFeatureSetIndex(getDeviceSetIndex()); + swgFeatureSettings->setFeatureType(new QString("VORLocalizer")); + swgFeatureSettings->setVorLocalizerSettings(new SWGSDRangel::SWGVORLocalizerSettings()); + SWGSDRangel::SWGVORLocalizerSettings *swgVORLocalizerSettings = swgFeatureSettings->getVorLocalizerSettings(); + + // transfer data that has been modified. When force is on transfer all data except reverse API data + + if (channelSettingsKeys.contains("title") || force) { + swgVORLocalizerSettings->setTitle(new QString(settings.m_title)); + } + if (channelSettingsKeys.contains("rgbColor") || force) { + swgVORLocalizerSettings->setRgbColor(settings.m_rgbColor); + } + if (channelSettingsKeys.contains("magDecAdjust") || force) { + swgVORLocalizerSettings->setMagDecAdjust(settings.m_magDecAdjust); + } + + QString channelSettingsURL = QString("http://%1:%2/sdrangel/featureset/%3/feature/%4/settings") + .arg(settings.m_reverseAPIAddress) + .arg(settings.m_reverseAPIPort) + .arg(settings.m_reverseAPIFeatureSetIndex) + .arg(settings.m_reverseAPIFeatureIndex); + m_networkRequest.setUrl(QUrl(channelSettingsURL)); + m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + + QBuffer *buffer = new QBuffer(); + buffer->open((QBuffer::ReadWrite)); + buffer->write(swgFeatureSettings->asJson().toUtf8()); + buffer->seek(0); + + // Always use PATCH to avoid passing reverse API settings + QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer); + buffer->setParent(reply); + + delete swgFeatureSettings; +} + +void VORLocalizer::networkManagerFinished(QNetworkReply *reply) +{ + QNetworkReply::NetworkError replyError = reply->error(); + + if (replyError) + { + qWarning() << "VORLocalizer::networkManagerFinished:" + << " error(" << (int) replyError + << "): " << replyError + << ": " << reply->errorString(); + } + else + { + QString answer = reply->readAll(); + answer.chop(1); // remove last \n + qDebug("VORLocalizer::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); + } + + reply->deleteLater(); +} diff --git a/plugins/feature/vorlocalizer/vorlocalizer.h b/plugins/feature/vorlocalizer/vorlocalizer.h new file mode 100644 index 000000000..f3abb1809 --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizer.h @@ -0,0 +1,190 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_FEATURE_VORLOCALIZER_H_ +#define INCLUDE_FEATURE_VORLOCALIZER_H_ + +#include +#include + +#include "feature/feature.h" +#include "util/message.h" + +#include "vorlocalizersettings.h" + +class WebAPIAdapterInterface; +class VorLocalizerWorker; +class QNetworkAccessManager; +class QNetworkReply; + +namespace SWGSDRangel { + class SWGDeviceState; +} + +class VORLocalizer : public Feature +{ + Q_OBJECT +public: + class MsgConfigureVORLocalizer : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const VORLocalizerSettings& getSettings() const { return m_settings; } + bool getForce() const { return m_force; } + + static MsgConfigureVORLocalizer* create(const VORLocalizerSettings& settings, bool force) { + return new MsgConfigureVORLocalizer(settings, force); + } + + private: + VORLocalizerSettings m_settings; + bool m_force; + + MsgConfigureVORLocalizer(const VORLocalizerSettings& settings, bool force) : + Message(), + m_settings(settings), + m_force(force) + { } + }; + + class MsgStartStop : public Message { + MESSAGE_CLASS_DECLARATION + + public: + bool getStartStop() const { return m_startStop; } + + static MsgStartStop* create(bool startStop) { + return new MsgStartStop(startStop); + } + + protected: + bool m_startStop; + + MsgStartStop(bool startStop) : + Message(), + m_startStop(startStop) + { } + }; + + class MsgAddVORChannel : public Message { + MESSAGE_CLASS_DECLARATION + + public: + bool getNavId() const { return m_navId; } + + static MsgAddVORChannel* create(int navId) { + return new MsgAddVORChannel(navId); + } + + protected: + int m_navId; + + MsgAddVORChannel(int navId) : + Message(), + m_navId(navId) + { } + }; + + class MsgRemoveVORChannel : public Message { + MESSAGE_CLASS_DECLARATION + + public: + bool getNavId() const { return m_navId; } + + static MsgRemoveVORChannel* create(int navId) { + return new MsgRemoveVORChannel(navId); + } + + protected: + int m_navId; + + MsgRemoveVORChannel(int navId) : + Message(), + m_navId(navId) + { } + }; + + class MsgRefreshChannels : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgRefreshChannels* create() { + return new MsgRefreshChannels(); + } + + protected: + MsgRefreshChannels() : + Message() + { } + }; + + VORLocalizer(WebAPIAdapterInterface *webAPIAdapterInterface); + virtual ~VORLocalizer(); + virtual void destroy() { delete this; } + virtual bool handleMessage(const Message& cmd); + + virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual void getTitle(QString& title) const { title = m_settings.m_title; } + + virtual QByteArray serialize() const; + virtual bool deserialize(const QByteArray& data); + + virtual int webapiRun(bool run, + SWGSDRangel::SWGDeviceState& response, + QString& errorMessage); + + virtual int webapiSettingsGet( + SWGSDRangel::SWGFeatureSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& featureSettingsKeys, + SWGSDRangel::SWGFeatureSettings& response, + QString& errorMessage); + + static void webapiFormatFeatureSettings( + SWGSDRangel::SWGFeatureSettings& response, + const VORLocalizerSettings& settings); + + static void webapiUpdateFeatureSettings( + VORLocalizerSettings& settings, + const QStringList& featureSettingsKeys, + SWGSDRangel::SWGFeatureSettings& response); + + static const char* const m_featureIdURI; + static const char* const m_featureId; + +private: + QThread m_thread; + VorLocalizerWorker *m_worker; + VORLocalizerSettings m_settings; + bool m_ptt; + + QNetworkAccessManager *m_networkManager; + QNetworkRequest m_networkRequest; + + void start(); + void stop(); + void applySettings(const VORLocalizerSettings& settings, bool force = false); + void webapiReverseSendSettings(QList& featureSettingsKeys, const VORLocalizerSettings& settings, bool force); + +private slots: + void networkManagerFinished(QNetworkReply *reply); +}; + +#endif // INCLUDE_FEATURE_VORLOCALIZER_H_ diff --git a/plugins/feature/vorlocalizer/vorlocalizergui.cpp b/plugins/feature/vorlocalizer/vorlocalizergui.cpp new file mode 100644 index 000000000..d0bfebd4a --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizergui.cpp @@ -0,0 +1,1340 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 Edouard Griffiths, F4EXB // +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "feature/featureuiset.h" +#include "dsp/dspengine.h" +#include "dsp/dspcommands.h" +#include "dsp/dspengine.h" +#include "ui_vorlocalizergui.h" +#include "plugin/pluginapi.h" +#include "util/simpleserializer.h" +#include "util/db.h" +#include "util/morse.h" +#include "util/units.h" +#include "gui/basicfeaturesettingsdialog.h" +#include "gui/crightclickenabler.h" +#include "maincore.h" + +#include "vorlocalizer.h" +#include "vorlocalizerreport.h" +#include "vorlocalizersettings.h" +#include "vorlocalizergui.h" + +static const char *countryCodes[] = { + "ad", + "ae", + "af", + "ag", + "ai", + "al", + "am", + "an", + "ao", + "aq", + "ar", + "as", + "at", + "au", + "aw", + "ax", + "az", + "ba", + "bb", + "bd", + "be", + "bf", + "bg", + "bh", + "bi", + "bj", + "bl", + "bm", + "bn", + "bo", + "bq", + "br", + "bs", + "bt", + "bv", + "bw", + "by", + "bz", + "ca", + "cc", + "cd", + "cf", + "cg", + "ch", + "ci", + "ck", + "cl", + "cm", + "cn", + "co", + "cr", + "cu", + "cv", + "cw", + "cx", + "cy", + "cz", + "de", + "dj", + "dk", + "dm", + "do", + "dz", + "ec", + "ee", + "eg", + "eh", + "er", + "es", + "et", + "fi", + "fj", + "fk", + "fm", + "fo", + "fr", + "ga", + "gb", + "ge", + "gf", + "gg", + "gh", + "gi", + "gl", + "gm", + "gn", + "gp", + "gq", + "gr", + "gs", + "gt", + "gu", + "gw", + "gy", + "hk", + "hm", + "hn", + "hr", + "hu", + "id", + "ie", + "il", + "im", + "in", + "io", + "iq", + "ir", + "is", + "it", + "je", + "jm", + "jo", + "jp", + "ke", + "kg", + "kh", + "ki", + "km", + "kn", + "kp", + "kr", + "kw", + "ky", + "kz", + "la", + "lb", + "lc", + "li", + "lk", + "lr", + "ls", + "lt", + "lu", + "lv", + "ly", + "ma", + "mc", + "md", + "me", + "mf", + "mg", + "mh", + "mk", + "ml", + "mm", + "mn", + "mo", + "mp", + "mq", + "mr", + "ms", + "mt", + "mu", + "mv", + "mw", + "mx", + "my", + "mz", + "na", + "nc", + "ne", + "nf", + "ng", + "ni", + "nl", + "no", + "np", + "nr", + "nu", + "nz", + "om", + "pa", + "pe", + "pf", + "pg", + "ph", + "pk", + "pl", + "pm", + "pn", + "pr", + "ps", + "pt", + "pw", + "py", + "qa", + "re", + "ro", + "rs", + "ru", + "rw", + "sa", + "sb", + "sc", + "sd", + "se", + "sg", + "sh", + "si", + "sj", + "sk", + "sl", + "sm", + "sn", + "so", + "sr", + "ss", + "st", + "sv", + "sx", + "sy", + "sz", + "tc", + "td", + "tf", + "tg", + "th", + "tj", + "tk", + "tl", + "tm", + "tn", + "to", + "tr", + "tt", + "tv", + "tw", + "tz", + "ua", + "ug", + "um", + "us", + "uy", + "uz", + "va", + "vc", + "ve", + "vg", + "vi", + "vn", + "vu", + "wf", + "ws", + "ye", + "yt", + "za", + "zm", + "zw", + nullptr +}; + +// Lats and longs in decimal degrees. Distance in metres. Bearing in degrees. +// https://www.movable-type.co.uk/scripts/latlong.html +static void calcRadialEndPoint(float startLatitude, float startLongitude, float distance, float bearing, float &endLatitude, float &endLongitude) +{ + double startLatRad = startLatitude*M_PI/180.0; + double startLongRad = startLongitude*M_PI/180.0; + double theta = bearing*M_PI/180.0; + double earthRadius = 6378137.0; // At equator + double delta = distance/earthRadius; + double endLatRad = std::asin(sin(startLatRad)*cos(delta) + cos(startLatRad)*sin(delta)*cos(theta)); + double endLongRad = startLongRad + std::atan2(sin(theta)*sin(delta)*cos(startLatRad), cos(delta) - sin(startLatRad)*sin(endLatRad)); + endLatitude = endLatRad*180.0/M_PI; + endLongitude = endLongRad*180.0/M_PI; +} + +// Calculate intersection point along two radials +// https://www.movable-type.co.uk/scripts/latlong.html +static bool calcIntersectionPoint(float lat1, float lon1, float bearing1, float lat2, float lon2, float bearing2, float &intersectLat, float &intersectLon) +{ + + double lat1Rad = Units::degreesToRadians(lat1); + double lon1Rad = Units::degreesToRadians(lon1); + double lat2Rad = Units::degreesToRadians(lat2); + double lon2Rad = Units::degreesToRadians(lon2); + double theta13 = Units::degreesToRadians(bearing1); + double theta23 = Units::degreesToRadians(bearing2); + + double deltaLat = lat1Rad - lat2Rad; + double deltaLon = lon1Rad - lon2Rad; + double sindlat = sin(deltaLat/2.0); + double sindlon = sin(deltaLon/2.0); + double cosLat1 = cos(lat1Rad); + double cosLat2 = cos(lat2Rad); + double delta12 = 2.0 * asin(sqrt(sindlat*sindlat+cosLat1*cosLat2*sindlon*sindlon)); + if (abs(delta12) < std::numeric_limits::epsilon()) + return false; + + double sinLat1 = sin(lat1Rad); + double sinLat2 = sin(lat2Rad); + double sinDelta12 = sin(delta12); + double cosDelta12 = cos(delta12); + double thetaA = acos((sinLat2-sinLat1*cosDelta12)/(sinDelta12*cosLat1)); + double thetaB = acos((sinLat1-sinLat2*cosDelta12)/(sinDelta12*cosLat2)); + + double theta12, theta21; + if (sin(lon2Rad-lon1Rad) > 0.0) + { + theta12 = thetaA; + theta21 = 2.0*M_PI-thetaB; + } + else + { + theta12 = 2.0*M_PI-thetaA; + theta21 = thetaB; + } + double alpha1 = theta13 - theta12; + double alpha2 = theta21 - theta23; + double sinAlpha1 = sin(alpha1); + double sinAlpha2 = sin(alpha2); + if ((sinAlpha1 == 0.0) && (sinAlpha2 == 0.0)) + return false; + if (sinAlpha1*sinAlpha2 < 0.0) + return false; + double cosAlpha1 = cos(alpha1); + double cosAlpha2 = cos(alpha2); + double cosAlpha3 = -cosAlpha1*cosAlpha2+sinAlpha1*sinAlpha2*cos(delta12); + double delta13 = atan2(sin(delta12)*sinAlpha1*sinAlpha2, cosAlpha2+cosAlpha1*cosAlpha3); + double lat3Rad = asin(sinLat1*cos(delta13)+cosLat1*sin(delta13)*cos(theta13)); + double lon3Rad = lon1Rad + atan2(sin(theta13)*sin(delta13)*cosLat1, cos(delta13)-sinLat1*sin(lat3Rad)); + + intersectLat = Units::radiansToDegress(lat3Rad); + intersectLon = Units::radiansToDegress(lon3Rad); + + return true; +} + +VORGUI::VORGUI(NavAid *navAid, VORLocalizerGUI *gui) : + m_navAid(navAid), + m_gui(gui) +{ + // These are deleted by QTableWidget + m_nameItem = new QTableWidgetItem(); + m_frequencyItem = new QTableWidgetItem(); + m_offsetItem = new QTableWidgetItem(); + m_radialItem = new QTableWidgetItem(); + m_identItem = new QTableWidgetItem(); + m_morseItem = new QTableWidgetItem(); + m_rxIdentItem = new QTableWidgetItem(); + m_rxMorseItem = new QTableWidgetItem(); + m_varMagItem = new QTableWidgetItem(); + m_refMagItem = new QTableWidgetItem(); + + m_muteItem = new QWidget(); + + m_muteButton = new QToolButton(); + m_muteButton->setCheckable(true); + m_muteButton->setChecked(false); + m_muteButton->setToolTip("Mute/unmute audio from this VOR"); + m_muteButton->setIcon(m_gui->m_muteIcon); + + QHBoxLayout* pLayout = new QHBoxLayout(m_muteItem); + pLayout->addWidget(m_muteButton); + pLayout->setAlignment(Qt::AlignCenter); + pLayout->setContentsMargins(0, 0, 0, 0); + m_muteItem->setLayout(pLayout); + + connect(m_muteButton, &QPushButton::toggled, this, &VORGUI::on_audioMute_toggled); + + m_coordinates.push_back(QVariant::fromValue(*new QGeoCoordinate(m_navAid->m_latitude, m_navAid->m_longitude, Units::feetToMetres(m_navAid->m_elevation)))); +} + +void VORGUI::on_audioMute_toggled(bool checked) +{ + m_gui->m_settings.m_subChannelSettings.value(m_navAid->m_id)->m_audioMute = checked; + m_gui->applySettings(); +} + +QVariant VORModel::data(const QModelIndex &index, int role) const +{ + int row = index.row(); + if ((row < 0) || (row >= m_vors.count())) + return QVariant(); + if (role == VORModel::positionRole) + { + // Coordinates to display the VOR icon at + QGeoCoordinate coords; + coords.setLatitude(m_vors[row]->m_latitude); + coords.setLongitude(m_vors[row]->m_longitude); + coords.setAltitude(Units::feetToMetres(m_vors[row]->m_elevation)); + return QVariant::fromValue(coords); + } + else if (role == VORModel::vorDataRole) + { + // Create the text to go in the bubble next to the VOR + QStringList list; + list.append(QString("Name: %1").arg(m_vors[row]->m_name)); + list.append(QString("Frequency: %1 MHz").arg(m_vors[row]->m_frequencykHz / 1000.0f, 0, 'f', 1)); + if (m_vors[row]->m_channel != "") + list.append(QString("Channel: %1").arg(m_vors[row]->m_channel)); + list.append(QString("Ident: %1 %2").arg(m_vors[row]->m_ident).arg(Morse::toSpacedUnicodeMorse(m_vors[row]->m_ident))); + list.append(QString("Range: %1 nm").arg(m_vors[row]->m_range)); + if (m_vors[row]->m_alignedTrueNorth) + list.append(QString("Magnetic declination: Aligned to true North")); + else if (m_vors[row]->m_magneticDeclination != 0.0f) + list.append(QString("Magnetic declination: %1%2").arg(std::round(m_vors[row]->m_magneticDeclination)).arg(QChar(0x00b0))); + QString data = list.join("\n"); + return QVariant::fromValue(data); + } + else if (role == VORModel::vorImageRole) + { + // Select an image to use for the VOR + return QVariant::fromValue(QString("/demodvor/map/%1.png").arg(m_vors[row]->m_type)); + } + else if (role == VORModel::bubbleColourRole) + { + // Select a background colour for the text bubble next to the VOR + if (m_selected[row]) + return QVariant::fromValue(QColor("lightgreen")); + else + return QVariant::fromValue(QColor("lightblue")); + } + else if (role == VORModel::vorRadialRole) + { + // Draw a radial line from centre of VOR outwards at the demodulated angle + if (m_radialsVisible && m_selected[row] && (m_vorGUIs[row] != nullptr) && (m_radials[row] != -1.0f)) + { + QVariantList list; + + list.push_back(m_vorGUIs[row]->m_coordinates[0]); // Centre of VOR + + float endLat, endLong; + float bearing; + if (m_gui->m_settings.m_magDecAdjust && !m_vors[row]->m_alignedTrueNorth) + bearing = m_radials[row] - m_vors[row]->m_magneticDeclination; + else + bearing = m_radials[row]; + calcRadialEndPoint(m_vors[row]->m_latitude, m_vors[row]->m_longitude, m_vors[row]->getRangeMetres(), bearing, endLat, endLong); + list.push_back(QVariant::fromValue(*new QGeoCoordinate(endLat, endLong, Units::feetToMetres(m_vors[row]->m_elevation)))); + + return list; + } + else + return QVariantList(); + } + else if (role == VORModel::selectedRole) + return QVariant::fromValue(m_selected[row]); + return QVariant(); +} + +bool VORModel::setData(const QModelIndex &index, const QVariant& value, int role) +{ + int row = index.row(); + if ((row < 0) || (row >= m_vors.count())) + return false; + if (role == VORModel::selectedRole) + { + bool selected = value.toBool(); + VORGUI *vorGUI; + if (selected == true) + { + vorGUI = new VORGUI(m_vors[row], m_gui); + m_vorGUIs[row] = vorGUI; + } + else + vorGUI = m_vorGUIs[row]; + m_gui->selectVOR(vorGUI, selected); + m_selected[row] = selected; + emit dataChanged(index, index); + if (!selected) + { + delete vorGUI; + m_vorGUIs[row] = nullptr; + } + return true; + } + return true; +} + +// Find intersection between first two selected radials +bool VORModel::findIntersection(float &lat, float &lon) +{ + if (m_vors.count() > 2) + { + float lat1, lon1, bearing1, valid1 = false; + float lat2, lon2, bearing2, valid2 = false; + + for (int i = 0; i < m_vors.count(); i++) + { + if (m_selected[i] && (m_radials[i] >= 0.0)) + { + if (!valid1) + { + lat1 = m_vors[i]->m_latitude; + lon1 = m_vors[i]->m_longitude; + if (m_gui->m_settings.m_magDecAdjust && !m_vors[i]->m_alignedTrueNorth) + bearing1 = m_radials[i] - m_vors[i]->m_magneticDeclination; + else + bearing1 = m_radials[i]; + valid1 = true; + } + else + { + lat2 = m_vors[i]->m_latitude; + lon2 = m_vors[i]->m_longitude; + if (m_gui->m_settings.m_magDecAdjust && !m_vors[i]->m_alignedTrueNorth) + bearing2 = m_radials[i] - m_vors[i]->m_magneticDeclination; + else + bearing2 = m_radials[i]; + valid2 = true; + break; + } + } + } + + if (valid1 && valid2) + { + return calcIntersectionPoint(lat1, lon1, bearing1, lat2, lon2, bearing2, lat, lon); + } + } + + return false; +} + +void VORLocalizerGUI::resizeTable() +{ + // Fill table with a row of dummy data that will size the columns nicely + // Trailing spaces are for sort arrow + QString morse("---- ---- ----"); + int row = ui->vorData->rowCount(); + ui->vorData->setRowCount(row + 1); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_NAME, new QTableWidgetItem("White Sulphur Springs")); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_FREQUENCY, new QTableWidgetItem("Freq (MHz) ")); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_OFFSET, new QTableWidgetItem("Offset (kHz) ")); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_IDENT, new QTableWidgetItem("Ident ")); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_MORSE, new QTableWidgetItem(Morse::toSpacedUnicode(morse))); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_RADIAL, new QTableWidgetItem("Radial (o) ")); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_RX_IDENT, new QTableWidgetItem("RX Ident ")); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_RX_MORSE, new QTableWidgetItem(Morse::toSpacedUnicode(morse))); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_VAR_MAG, new QTableWidgetItem("Var (dB) ")); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_REF_MAG, new QTableWidgetItem("Ref (dB) ")); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_MUTE, new QTableWidgetItem("Mute")); + ui->vorData->resizeColumnsToContents(); + ui->vorData->removeRow(row); +} + +// Columns in table reordered +void VORLocalizerGUI::vorData_sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex) +{ + (void) oldVisualIndex; + + m_settings.m_columnIndexes[logicalIndex] = newVisualIndex; +} + +// Column in table resized (when hidden size is 0) +void VORLocalizerGUI::vorData_sectionResized(int logicalIndex, int oldSize, int newSize) +{ + (void) oldSize; + + m_settings.m_columnSizes[logicalIndex] = newSize; +} + +// Right click in table header - show column select menu +void VORLocalizerGUI::columnSelectMenu(QPoint pos) +{ + menu->popup(ui->vorData->horizontalHeader()->viewport()->mapToGlobal(pos)); +} + +// Hide/show column when menu selected +void VORLocalizerGUI::columnSelectMenuChecked(bool checked) +{ + (void) checked; + + QAction* action = qobject_cast(sender()); + if (action != nullptr) + { + int idx = action->data().toInt(nullptr); + ui->vorData->setColumnHidden(idx, !action->isChecked()); + } +} + +// Create column select menu item +QAction *VORLocalizerGUI::createCheckableItem(QString &text, int idx, bool checked) +{ + QAction *action = new QAction(text, this); + action->setCheckable(true); + action->setChecked(checked); + action->setData(QVariant(idx)); + connect(action, SIGNAL(triggered()), this, SLOT(columnSelectMenuChecked())); + return action; +} + +// Called when a VOR is selected on the map +void VORLocalizerGUI::selectVOR(VORGUI *vorGUI, bool selected) +{ + int navId = vorGUI->m_navAid->m_id; + + if (selected) + { + VORLocalizer::MsgAddVORChannel *msg = VORLocalizer::MsgAddVORChannel::create(navId); + m_vorLocalizer->getInputMessageQueue()->push(msg); + + m_selectedVORs.insert(navId, vorGUI); + ui->vorData->setSortingEnabled(false); + int row = ui->vorData->rowCount(); + ui->vorData->setRowCount(row + 1); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_NAME, vorGUI->m_nameItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_FREQUENCY, vorGUI->m_frequencyItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_OFFSET, vorGUI->m_offsetItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_IDENT, vorGUI->m_identItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_MORSE, vorGUI->m_morseItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_RADIAL, vorGUI->m_radialItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_RX_IDENT, vorGUI->m_rxIdentItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_RX_MORSE, vorGUI->m_rxMorseItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_VAR_MAG, vorGUI->m_varMagItem); + ui->vorData->setItem(row, VORLocalizerSettings::VOR_COL_REF_MAG, vorGUI->m_refMagItem); + ui->vorData->setCellWidget(row, VORLocalizerSettings::VOR_COL_MUTE, vorGUI->m_muteItem); + vorGUI->m_nameItem->setText(vorGUI->m_navAid->m_name); + vorGUI->m_identItem->setText(vorGUI->m_navAid->m_ident); + vorGUI->m_morseItem->setText(Morse::toSpacedUnicodeMorse(vorGUI->m_navAid->m_ident)); + vorGUI->m_frequencyItem->setData(Qt::DisplayRole, vorGUI->m_navAid->m_frequencykHz / 1000.0); + ui->vorData->setSortingEnabled(true); + + // Add to settings to create corresponding demodulator + VORLocalizerSubChannelSettings *subChannelSettings = new VORLocalizerSubChannelSettings(); + subChannelSettings->m_id = navId; + subChannelSettings->m_frequency = vorGUI->m_navAid->m_frequencykHz * 1000; + subChannelSettings->m_audioMute = false; + m_settings.m_subChannelSettings.insert(navId, subChannelSettings); + + applySettings(); + } + else + { + VORLocalizer::MsgRemoveVORChannel *msg = VORLocalizer::MsgRemoveVORChannel::create(navId); + m_vorLocalizer->getInputMessageQueue()->push(msg); + + m_selectedVORs.remove(navId); + ui->vorData->removeRow(vorGUI->m_nameItem->row()); + // Remove from settings to remove corresponding demodulator + VORLocalizerSubChannelSettings *subChannelSettings = m_settings.m_subChannelSettings.value(navId); + m_settings.m_subChannelSettings.remove(navId); + delete subChannelSettings; + + applySettings(); + } +} + +void VORLocalizerGUI::updateVORs() +{ + m_vorModel.removeAllVORs(); + QHash::iterator i = m_vors->begin(); + AzEl azEl = m_azEl; + + while (i != m_vors->end()) + { + NavAid *vor = i.value(); + + // Calculate distance to VOR from My Position + azEl.setTarget(vor->m_latitude, vor->m_longitude, Units::feetToMetres(vor->m_elevation)); + azEl.calculate(); + + // Only display VOR if in range + if (azEl.getDistance() <= 200000) + { + m_vorModel.addVOR(vor); + } + ++i; + } +} + +VORLocalizerGUI* VORLocalizerGUI::create(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature) +{ + VORLocalizerGUI* gui = new VORLocalizerGUI(pluginAPI, featureUISet, feature); + return gui; +} + +void VORLocalizerGUI::destroy() +{ + delete this; +} + +void VORLocalizerGUI::resetToDefaults() +{ + m_settings.resetToDefaults(); + displaySettings(); + applySettings(true); +} + +QByteArray VORLocalizerGUI::serialize() const +{ + return m_settings.serialize(); +} + +bool VORLocalizerGUI::deserialize(const QByteArray& data) +{ + if(m_settings.deserialize(data)) { + displaySettings(); + applySettings(true); + return true; + } else { + resetToDefaults(); + return false; + } +} + +bool VORLocalizerGUI::handleMessage(const Message& message) +{ + if (VORLocalizer::MsgConfigureVORLocalizer::match(message)) + { + qDebug("VORLocalizerGUI::handleMessage: VORLocalizer::MsgConfigureVORLocalizer"); + const VORLocalizer::MsgConfigureVORLocalizer& cfg = (VORLocalizer::MsgConfigureVORLocalizer&) message; + m_settings = cfg.getSettings(); + blockApplySettings(true); + displaySettings(); + blockApplySettings(false); + return true; + } + else if (DSPSignalNotification::match(message)) + { + DSPSignalNotification& notif = (DSPSignalNotification&) message; + m_basebandSampleRate = notif.getSampleRate(); + return true; + } + else if (VORLocalizerReport::MsgReportRadial::match(message)) + { + VORLocalizerReport::MsgReportRadial& report = (VORLocalizerReport::MsgReportRadial&) message; + int subChannelId = report.getSubChannelId(); + + VORGUI *vorGUI = m_selectedVORs.value(subChannelId); + + // Display radial and signal magnitudes in table + + Real varMagDB = std::round(20.0*std::log10(report.getVarMag())); + Real refMagDB = std::round(20.0*std::log10(report.getRefMag())); + + bool validRadial = report.getValidRadial(); + + vorGUI->m_radialItem->setData(Qt::DisplayRole, std::round(report.getRadial())); + if (validRadial) + vorGUI->m_radialItem->setForeground(QBrush(Qt::white)); + else + vorGUI->m_radialItem->setForeground(QBrush(Qt::red)); + + vorGUI->m_refMagItem->setData(Qt::DisplayRole, refMagDB); + if (report.getValidRefMag()) + vorGUI->m_refMagItem->setForeground(QBrush(Qt::white)); + else + vorGUI->m_refMagItem->setForeground(QBrush(Qt::red)); + + vorGUI->m_varMagItem->setData(Qt::DisplayRole, varMagDB); + if (report.getValidVarMag()) + vorGUI->m_varMagItem->setForeground(QBrush(Qt::white)); + else + vorGUI->m_varMagItem->setForeground(QBrush(Qt::red)); + + // Update radial on map + m_vorModel.setRadial(subChannelId, validRadial, report.getRadial()); + + return true; + } + else if (VORLocalizerReport::MsgReportFreqOffset::match(message)) + { + VORLocalizerReport::MsgReportFreqOffset& report = (VORLocalizerReport::MsgReportFreqOffset&) message; + int subChannelId = report.getSubChannelId(); + + VORGUI *vorGUI = m_selectedVORs.value(subChannelId); + + vorGUI->m_offsetItem->setData(Qt::DisplayRole, report.getFreqOffset() / 1000.0); + if (report.getOutOfBand()) + { + vorGUI->m_offsetItem->setForeground(QBrush(Qt::red)); + // Clear other fields as data is now invalid + vorGUI->m_radialItem->setText(""); + vorGUI->m_refMagItem->setText(""); + vorGUI->m_varMagItem->setText(""); + m_vorModel.setRadial(subChannelId, false, -1.0f); + } + else + vorGUI->m_offsetItem->setForeground(QBrush(Qt::white)); + } + else if (VORLocalizerReport::MsgReportIdent::match(message)) + { + VORLocalizerReport::MsgReportIdent& report = (VORLocalizerReport::MsgReportIdent&) message; + int subChannelId = report.getSubChannelId(); + + VORGUI *vorGUI = m_selectedVORs.value(subChannelId); + + QString ident = report.getIdent(); + // Convert Morse to a string + QString identString = Morse::toString(ident); + // Idents should only be two or three characters, so filter anything else + // other than TEST which indicates a VOR is under maintainance (may also be TST) + if (((identString.size() >= 2) && (identString.size() <= 3)) || (identString == "TEST")) + { + vorGUI->m_rxIdentItem->setText(identString); + vorGUI->m_rxMorseItem->setText(Morse::toSpacedUnicode(ident)); + if (vorGUI->m_navAid->m_ident == identString) + { + // Set colour to green if matching expected ident + vorGUI->m_rxIdentItem->setForeground(QBrush(Qt::green)); + vorGUI->m_rxMorseItem->setForeground(QBrush(Qt::green)); + } + else + { + // Set colour to green if not matching expected ident + vorGUI->m_rxIdentItem->setForeground(QBrush(Qt::red)); + vorGUI->m_rxMorseItem->setForeground(QBrush(Qt::red)); + } + } + else + { + // Set yellow to indicate we've filtered something (unless red) + if (vorGUI->m_rxIdentItem->foreground().color() != Qt::red) + { + vorGUI->m_rxIdentItem->setForeground(QBrush(Qt::yellow)); + vorGUI->m_rxMorseItem->setForeground(QBrush(Qt::yellow)); + } + } + + return true; + } + else if (VORLocalizerReport::MsgReportChannels::match(message)) + { + VORLocalizerReport::MsgReportChannels& report = (VORLocalizerReport::MsgReportChannels&) message; + const std::vector& channels = report.getChannels(); + std::vector::const_iterator it = channels.begin(); + ui->channels->clear(); + + for (; it != channels.end(); ++it) { + ui->channels->addItem(tr("%1:%2").arg(it->m_deviceSetIndex).arg(it->m_channelIndex)); + } + + return true; + } + + return false; +} + +void VORLocalizerGUI::handleInputMessages() +{ + Message* message; + + while ((message = getInputMessageQueue()->pop()) != 0) + { + if (handleMessage(*message)) + { + delete message; + } + } +} + +qint64 VORLocalizerGUI::fileAgeInDays(QString filename) +{ + QFile file(filename); + if (file.exists()) + { + QDateTime modified = file.fileTime(QFileDevice::FileModificationTime); + if (modified.isValid()) + return modified.daysTo(QDateTime::currentDateTime()); + else + return -1; + } + return -1; +} + +bool VORLocalizerGUI::confirmDownload(QString filename) +{ + qint64 age = fileAgeInDays(filename); + if ((age == -1) || (age > 100)) + return true; + else + { + QMessageBox::StandardButton reply; + if (age == 0) + reply = QMessageBox::question(this, "Confirm download", "This file was last downloaded today. Are you sure you wish to redownload it?", QMessageBox::Yes|QMessageBox::No); + else if (age == 1) + reply = QMessageBox::question(this, "Confirm download", "This file was last downloaded yesterday. Are you sure you wish to redownload it?", QMessageBox::Yes|QMessageBox::No); + else + reply = QMessageBox::question(this, "Confirm download", QString("This file was last downloaded %1 days ago. Are you sure you wish to redownload this file?").arg(age), QMessageBox::Yes|QMessageBox::No); + return reply == QMessageBox::Yes; + } +} + +QString VORLocalizerGUI::getDataDir() +{ + // Get directory to store app data in + QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); + // First dir is writable + return locations[0]; +} + +QString VORLocalizerGUI::getOpenAIPVORDBFilename(int i) +{ + if (countryCodes[i] != nullptr) + return getDataDir() + "/" + countryCodes[i] + "_nav.aip"; + else + return ""; +} + +QString VORLocalizerGUI::getOpenAIPVORDBURL(int i) +{ + if (countryCodes[i] != nullptr) + return QString(OPENAIP_NAVAIDS_URL).arg(countryCodes[i]); + else + return ""; +} + +QString VORLocalizerGUI::getVORDBFilename() +{ + return getDataDir() + "/vorDatabase.csv"; +} + +void VORLocalizerGUI::updateDownloadProgress(qint64 bytesRead, qint64 totalBytes) +{ + m_progressDialog->setMaximum(totalBytes); + m_progressDialog->setValue(bytesRead); +} + +void VORLocalizerGUI::downloadFinished(const QString& filename, bool success) +{ + if (success) + { + if (filename == getVORDBFilename()) + { + m_vors = NavAid::readNavAidsDB(filename); + if (m_vors != nullptr) + updateVORs(); + m_progressDialog->close(); + m_progressDialog = nullptr; + } + else if (filename == getOpenAIPVORDBFilename(m_countryIndex)) + { + m_countryIndex++; + if (countryCodes[m_countryIndex] != nullptr) + { + QString vorDBFile = getOpenAIPVORDBFilename(m_countryIndex); + QString urlString = getOpenAIPVORDBURL(m_countryIndex); + QUrl dbURL(urlString); + m_progressDialog->setLabelText(QString("Downloading %1.").arg(urlString)); + m_progressDialog->setValue(m_countryIndex); + m_dlm.download(dbURL, vorDBFile); + } + else + { + readNavAids(); + if (m_vors != nullptr) + updateVORs(); + m_progressDialog->close(); + m_progressDialog = nullptr; + } + } + else + { + qDebug() << "VORLocalizerGUI::downloadFinished: Unexpected filename: " << filename; + m_progressDialog->close(); + m_progressDialog = nullptr; + } + } + else + { + qDebug() << "VORLocalizerGUI::downloadFinished: Failed: " << filename; + m_progressDialog->close(); + m_progressDialog = nullptr; + QMessageBox::warning(this, "Download failed", QString("Failed to download %1").arg(filename)); + } +} + +void VORLocalizerGUI::on_startStop_toggled(bool checked) +{ + if (m_doApplySettings) + { + VORLocalizer::MsgStartStop *message = VORLocalizer::MsgStartStop::create(checked); + m_vorLocalizer->getInputMessageQueue()->push(message); + } +} + +void VORLocalizerGUI::on_getOurAirportsVORDB_clicked() +{ + // Don't try to download while already in progress + if (m_progressDialog == nullptr) + { + QString vorDBFile = getVORDBFilename(); + if (confirmDownload(vorDBFile)) + { + // Download OurAirports navaid database to disk + QUrl dbURL(QString(OURAIRPORTS_NAVAIDS_URL)); + m_progressDialog = new QProgressDialog(this); + m_progressDialog->setAttribute(Qt::WA_DeleteOnClose); + m_progressDialog->setCancelButton(nullptr); + m_progressDialog->setMinimumDuration(500); + m_progressDialog->setLabelText(QString("Downloading %1.").arg(OURAIRPORTS_NAVAIDS_URL)); + QNetworkReply *reply = m_dlm.download(dbURL, vorDBFile); + connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateDownloadProgress(qint64,qint64))); + } + } +} + +void VORLocalizerGUI::on_getOpenAIPVORDB_clicked() +{ + // Don't try to download while already in progress + if (m_progressDialog == nullptr) + { + m_countryIndex = 0; + QString vorDBFile = getOpenAIPVORDBFilename(m_countryIndex); + if (confirmDownload(vorDBFile)) + { + // Download OpenAIP XML to disk + QString urlString = getOpenAIPVORDBURL(m_countryIndex); + QUrl dbURL(urlString); + m_progressDialog = new QProgressDialog(this); + m_progressDialog->setAttribute(Qt::WA_DeleteOnClose); + m_progressDialog->setCancelButton(nullptr); + m_progressDialog->setMinimumDuration(500); + m_progressDialog->setMaximum(sizeof(countryCodes)/sizeof(countryCodes[0])); + m_progressDialog->setValue(0); + m_progressDialog->setLabelText(QString("Downloading %1.").arg(urlString)); + m_dlm.download(dbURL, vorDBFile); + } + } +} + +void VORLocalizerGUI::readNavAids() +{ + m_vors = new QHash(); + + for (int countryIndex = 0; countryCodes[countryIndex] != nullptr; countryIndex++) + { + QString vorDBFile = getOpenAIPVORDBFilename(countryIndex); + NavAid::readNavAidsXML(m_vors, vorDBFile); + } +} + +void VORLocalizerGUI::on_magDecAdjust_clicked(bool checked) +{ + m_settings.m_magDecAdjust = checked; + m_vorModel.allVORUpdated(); + applySettings(); +} + +void VORLocalizerGUI::on_channelsRefresh_clicked() +{ + if (m_doApplySettings) + { + VORLocalizer::MsgRefreshChannels* message = VORLocalizer::MsgRefreshChannels::create(); + m_vorLocalizer->getInputMessageQueue()->push(message); + } +} + +void VORLocalizerGUI::onWidgetRolled(QWidget* widget, bool rollDown) +{ + (void) widget; + (void) rollDown; +} + +void VORLocalizerGUI::onMenuDialogCalled(const QPoint &p) +{ + if (m_contextMenuType == ContextMenuChannelSettings) + { + BasicFeatureSettingsDialog dialog(this); + dialog.setTitle(m_settings.m_title); + dialog.setColor(m_settings.m_rgbColor); + dialog.setUseReverseAPI(m_settings.m_useReverseAPI); + dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress); + dialog.setReverseAPIPort(m_settings.m_reverseAPIPort); + dialog.setReverseAPIFeatureSetIndex(m_settings.m_reverseAPIFeatureSetIndex); + dialog.setReverseAPIFeatureIndex(m_settings.m_reverseAPIFeatureIndex); + + dialog.move(p); + dialog.exec(); + + m_settings.m_rgbColor = dialog.getColor().rgb(); + m_settings.m_title = dialog.getTitle(); + m_settings.m_useReverseAPI = dialog.useReverseAPI(); + m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress(); + m_settings.m_reverseAPIPort = dialog.getReverseAPIPort(); + m_settings.m_reverseAPIFeatureSetIndex = dialog.getReverseAPIFeatureSetIndex(); + m_settings.m_reverseAPIFeatureIndex = dialog.getReverseAPIFeatureIndex(); + + setWindowTitle(m_settings.m_title); + setTitleColor(m_settings.m_rgbColor); + + applySettings(); + } + + resetContextMenuType(); +} + +VORLocalizerGUI::VORLocalizerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent) : + FeatureGUI(parent), + ui(new Ui::VORLocalizerGUI), + m_pluginAPI(pluginAPI), + m_featureUISet(featureUISet), + m_doApplySettings(true), + m_squelchOpen(false), + m_tickCount(0), + m_progressDialog(nullptr), + m_vorModel(this), + m_vors(nullptr), + m_lastFeatureState(0) +{ + ui->setupUi(this); + + ui->map->rootContext()->setContextProperty("vorModel", &m_vorModel); + ui->map->setSource(QUrl(QStringLiteral("qrc:/demodvor/map/map.qml"))); + + m_muteIcon.addPixmap(QPixmap("://sound_off.png"), QIcon::Normal, QIcon::On); + m_muteIcon.addPixmap(QPixmap("://sound_on.png"), QIcon::Normal, QIcon::Off); + + setAttribute(Qt::WA_DeleteOnClose, true); + connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); + connect(&m_dlm, &HttpDownloadManager::downloadComplete, this, &VORLocalizerGUI::downloadFinished); + + m_vorLocalizer = reinterpret_cast(feature); + m_vorLocalizer->setMessageQueueToGUI(getInputMessageQueue()); + + connect(&MainCore::instance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); // 50 ms + + m_featureUISet->addRollupWidget(this); + + connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + + // Get station position + Real stationLatitude = MainCore::instance()->getSettings().getLatitude(); + Real stationLongitude = MainCore::instance()->getSettings().getLongitude(); + Real stationAltitude = MainCore::instance()->getSettings().getAltitude(); + m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude); + + // Centre map at My Position + QQuickItem *item = ui->map->rootObject(); + QObject *object = item->findChild("map"); + if (object) + { + QGeoCoordinate coords = object->property("center").value(); + coords.setLatitude(stationLatitude); + coords.setLongitude(stationLongitude); + object->setProperty("center", QVariant::fromValue(coords)); + } + // Move antenna icon to My Position to start with + QObject *stationObject = item->findChild("station"); + if (stationObject) + { + QGeoCoordinate coords = stationObject->property("coordinate").value(); + coords.setLatitude(stationLatitude); + coords.setLongitude(stationLongitude); + coords.setAltitude(stationAltitude); + stationObject->setProperty("coordinate", QVariant::fromValue(coords)); + stationObject->setProperty("stationName", QVariant::fromValue(MainCore::instance()->getSettings().getStationName())); + } + + // Read in VOR information if it exists + bool useOurAirports = false; + if (useOurAirports) + { + m_vors = NavAid::readNavAidsDB(getVORDBFilename()); + ui->getOpenAIPVORDB->setVisible(false); + } + else + { + readNavAids(); + ui->getOurAirportsVORDB->setVisible(false); + } + if (m_vors != nullptr) { + updateVORs(); + } + + // Resize the table using dummy data + resizeTable(); + // Allow user to reorder columns + ui->vorData->horizontalHeader()->setSectionsMovable(true); + // Allow user to sort table by clicking on headers + ui->vorData->setSortingEnabled(true); + // Add context menu to allow hiding/showing of columns + menu = new QMenu(ui->vorData); + for (int i = 0; i < ui->vorData->horizontalHeader()->count(); i++) + { + QString text = ui->vorData->horizontalHeaderItem(i)->text(); + menu->addAction(createCheckableItem(text, i, true)); + } + ui->vorData->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->vorData->horizontalHeader(), SIGNAL(customContextMenuRequested(QPoint)), SLOT(columnSelectMenu(QPoint))); + // Get signals when columns change + connect(ui->vorData->horizontalHeader(), SIGNAL(sectionMoved(int, int, int)), SLOT(vorData_sectionMoved(int, int, int))); + connect(ui->vorData->horizontalHeader(), SIGNAL(sectionResized(int, int, int)), SLOT(vorData_sectionResized(int, int, int))); + + connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); + m_statusTimer.start(1000); + + displaySettings(); + applySettings(true); +} + +VORLocalizerGUI::~VORLocalizerGUI() +{ + delete ui; +} + +void VORLocalizerGUI::blockApplySettings(bool block) +{ + m_doApplySettings = !block; +} + +void VORLocalizerGUI::applySettings(bool force) +{ + if (m_doApplySettings) + { + VORLocalizer::MsgConfigureVORLocalizer* message = VORLocalizer::MsgConfigureVORLocalizer::create( m_settings, force); + m_vorLocalizer->getInputMessageQueue()->push(message); + } +} + +void VORLocalizerGUI::displaySettings() +{ + setTitleColor(m_settings.m_rgbColor); + setWindowTitle(m_settings.m_title); + + blockApplySettings(true); + + // Order and size columns + QHeaderView *header = ui->vorData->horizontalHeader(); + + for (int i = 0; i < VORLocalizerSettings::VORDEMOD_COLUMNS; i++) + { + bool hidden = m_settings.m_columnSizes[i] == 0; + header->setSectionHidden(i, hidden); + menu->actions().at(i)->setChecked(!hidden); + + if (m_settings.m_columnSizes[i] > 0) { + ui->vorData->setColumnWidth(i, m_settings.m_columnSizes[i]); + } + + header->moveSection(header->visualIndex(i), m_settings.m_columnIndexes[i]); + } + + blockApplySettings(false); +} + +void VORLocalizerGUI::leaveEvent(QEvent*) +{ +} + +void VORLocalizerGUI::enterEvent(QEvent*) +{ +} + +void VORLocalizerGUI::updateStatus() +{ + int state = m_vorLocalizer->getState(); + + if (m_lastFeatureState != state) + { + switch (state) + { + case Feature::StNotStarted: + ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); + break; + case Feature::StIdle: + ui->startStop->setStyleSheet("QToolButton { background-color : blue; }"); + break; + case Feature::StRunning: + ui->startStop->setStyleSheet("QToolButton { background-color : green; }"); + break; + case Feature::StError: + ui->startStop->setStyleSheet("QToolButton { background-color : red; }"); + QMessageBox::information(this, tr("Message"), m_vorLocalizer->getErrorMessage()); + break; + default: + break; + } + + m_lastFeatureState = state; + } +} + +void VORLocalizerGUI::tick() +{ + // Try to determine position, based on intersection of two radials + if (m_tickCount % 50) + { + float lat, lon; + + if (m_vorModel.findIntersection(lat, lon)) + { + // Move antenna icon to estimated position + QQuickItem *item = ui->map->rootObject(); + QObject *stationObject = item->findChild("station"); + if(stationObject != NULL) + { + QGeoCoordinate coords = stationObject->property("coordinate").value(); + coords.setLatitude(lat); + coords.setLongitude(lon); + stationObject->setProperty("coordinate", QVariant::fromValue(coords)); + stationObject->setProperty("stationName", QVariant::fromValue(MainCore::instance()->getSettings().getStationName())); + } + } + } + + m_tickCount++; +} diff --git a/plugins/feature/vorlocalizer/vorlocalizergui.h b/plugins/feature/vorlocalizer/vorlocalizergui.h new file mode 100644 index 000000000..68af9396c --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizergui.h @@ -0,0 +1,287 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 Edouard Griffiths, F4EXB // +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_VORLOCALIZERGUI_H +#define INCLUDE_VORLOCALIZERGUI_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "feature/featuregui.h" +#include "dsp/movingaverage.h" +#include "util/messagequeue.h" +#include "util/httpdownloadmanager.h" +#include "util/azel.h" +#include "vorlocalizersettings.h" +#include "navaid.h" + +class PluginAPI; +class FeatureUISet; +class Feature; +class BasebandSampleSink; +class VORLocalizer; +class VORLocalizerGUI; + +namespace Ui { + class VORLocalizerGUI; +} +class VORLocalizerGUI; + +// Table items for each VOR +class VORGUI : public QObject { + Q_OBJECT +public: + NavAid *m_navAid; + QVariantList m_coordinates; + VORLocalizerGUI *m_gui; + + QTableWidgetItem *m_nameItem; + QTableWidgetItem *m_frequencyItem; + QTableWidgetItem *m_offsetItem; + QTableWidgetItem *m_identItem; + QTableWidgetItem *m_morseItem; + QTableWidgetItem *m_radialItem; + QTableWidgetItem *m_rxIdentItem; + QTableWidgetItem *m_rxMorseItem; + QTableWidgetItem *m_varMagItem; + QTableWidgetItem *m_refMagItem; + QWidget *m_muteItem; + QToolButton *m_muteButton; + + VORGUI(NavAid *navAid, VORLocalizerGUI *gui); +private slots: + void on_audioMute_toggled(bool checked); +}; + +// VOR model used for each VOR on the map +class VORModel : public QAbstractListModel { + Q_OBJECT + +public: + using QAbstractListModel::QAbstractListModel; + enum MarkerRoles{ + positionRole = Qt::UserRole + 1, + vorDataRole = Qt::UserRole + 2, + vorImageRole = Qt::UserRole + 3, + vorRadialRole = Qt::UserRole + 4, + bubbleColourRole = Qt::UserRole + 5, + selectedRole = Qt::UserRole + 6 + }; + + VORModel(VORLocalizerGUI *gui) : + m_gui(gui), + m_radialsVisible(true) + { + } + + Q_INVOKABLE void addVOR(NavAid *vor) { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_vors.append(vor); + m_selected.append(false); + m_radials.append(-1.0f); + m_vorGUIs.append(nullptr); + endInsertRows(); + } + + int rowCount(const QModelIndex &parent = QModelIndex()) const override { + Q_UNUSED(parent) + return m_vors.count(); + } + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + bool setData(const QModelIndex &index, const QVariant& value, int role = Qt::EditRole) override; + + Qt::ItemFlags flags(const QModelIndex &index) const override { + (void) index; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; + } + + void allVORUpdated() { + for (int i = 0; i < m_vors.count(); i++) + { + QModelIndex idx = index(i); + emit dataChanged(idx, idx); + } + } + + void removeVOR(NavAid *vor) { + int row = m_vors.indexOf(vor); + if (row >= 0) + { + beginRemoveRows(QModelIndex(), row, row); + m_vors.removeAt(row); + m_selected.removeAt(row); + m_radials.removeAt(row); + m_vorGUIs.removeAt(row); + endRemoveRows(); + } + } + + void removeAllVORs() { + beginRemoveRows(QModelIndex(), 0, m_vors.count()); + m_vors.clear(); + m_selected.clear(); + m_radials.clear(); + m_vorGUIs.clear(); + endRemoveRows(); + } + + QHash roleNames() const { + QHash roles; + roles[positionRole] = "position"; + roles[vorDataRole] = "vorData"; + roles[vorImageRole] = "vorImage"; + roles[vorRadialRole] = "vorRadial"; + roles[bubbleColourRole] = "bubbleColour"; + roles[selectedRole] = "selected"; + return roles; + } + + void setRadialsVisible(bool radialsVisible) + { + m_radialsVisible = radialsVisible; + allVORUpdated(); + } + + void setRadial(int id, bool valid, Real radial) + { + for (int i = 0; i < m_vors.count(); i++) + { + if (m_vors[i]->m_id == id) + { + if (valid) + m_radials[i] = radial; + else + m_radials[i] = -1; // -1 to indicate invalid + QModelIndex idx = index(i); + emit dataChanged(idx, idx); + break; + } + } + } + + bool findIntersection(float &lat, float &lon); + +private: + VORLocalizerGUI *m_gui; + bool m_radialsVisible; + QList m_vors; + QList m_selected; + QList m_radials; + QList m_vorGUIs; +}; + +class VORLocalizerGUI : public FeatureGUI { + Q_OBJECT + +public: + static VORLocalizerGUI* create(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature); + virtual void destroy(); + + void resetToDefaults(); + QByteArray serialize() const; + bool deserialize(const QByteArray& data); + virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } + void selectVOR(VORGUI *vorGUI, bool selected); + +private: + friend class VORGUI; + friend class VORModel; + + Ui::VORLocalizerGUI* ui; + PluginAPI* m_pluginAPI; + FeatureUISet* m_featureUISet; + VORLocalizerSettings m_settings; + bool m_doApplySettings; + + VORLocalizer* m_vorLocalizer; + bool m_squelchOpen; + int m_basebandSampleRate; + uint32_t m_tickCount; + MessageQueue m_inputMessageQueue; + + QMenu *menu; // Column select context menu + HttpDownloadManager m_dlm; + QProgressDialog *m_progressDialog; + int m_countryIndex; + VORModel m_vorModel; + QHash *m_vors; + QHash m_selectedVORs; + AzEl m_azEl; // Position of station + QIcon m_muteIcon; + QTimer m_statusTimer; + int m_lastFeatureState; + + explicit VORLocalizerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr); + virtual ~VORLocalizerGUI(); + + void blockApplySettings(bool block); + void applySettings(bool force = false); + void displaySettings(); + bool handleMessage(const Message& message); + + void leaveEvent(QEvent*); + void enterEvent(QEvent*); + + void resizeTable(); + QAction *createCheckableItem(QString& text, int idx, bool checked); + + void calculateFreqOffset(VORGUI *vorGUI); + void calculateFreqOffsets(); + void updateVORs(); + QString getOpenAIPVORDBURL(int i); + QString getOpenAIPVORDBFilename(int i); + QString getVORDBFilename(); + void readNavAids(); + // Move to util + QString getDataDir(); + qint64 fileAgeInDays(QString filename); + bool confirmDownload(QString filename); + void updateChannelList(); + +private slots: + void on_startStop_toggled(bool checked); + void on_getOurAirportsVORDB_clicked(); + void on_getOpenAIPVORDB_clicked(); + void on_magDecAdjust_clicked(bool checked); + void on_channelsRefresh_clicked(); + void vorData_sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex); + void vorData_sectionResized(int logicalIndex, int oldSize, int newSize); + void columnSelectMenu(QPoint pos); + void columnSelectMenuChecked(bool checked = false); + void onWidgetRolled(QWidget* widget, bool rollDown); + void onMenuDialogCalled(const QPoint& p); + void updateDownloadProgress(qint64 bytesRead, qint64 totalBytes); + void downloadFinished(const QString& filename, bool success); + void handleInputMessages(); + void updateStatus(); + void tick(); +}; + +#endif // INCLUDE_VORLOCALIZERGUI_H diff --git a/plugins/feature/vorlocalizer/vorlocalizergui.ui b/plugins/feature/vorlocalizer/vorlocalizergui.ui new file mode 100644 index 000000000..978e91a6a --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizergui.ui @@ -0,0 +1,434 @@ + + + VORLocalizerGUI + + + + 0 + 0 + 398 + 893 + + + + + 0 + 0 + + + + + 352 + 0 + + + + + Liberation Sans + 9 + + + + Qt::StrongFocus + + + VOR Localizer + + + VOR Localizer + + + + + 0 + 0 + 390 + 61 + + + + + 350 + 0 + + + + Settings + + + + 3 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + + start/stop acquisition + + + + + + + :/play.png + :/stop.png:/play.png + + + + + + + true + + + Download OurAirports VOR database + + + + + + + :/demodvor/icons/vor.png:/demodvor/icons/vor.png + + + + + + + Download OpenAIP VOR database + + + + + + + :/demodvor/icons/vor.png:/demodvor/icons/vor.png + + + + + + + Draw radials adjusted for magnetic declination + + + + + + + :/demodvor/icons/compass.png:/demodvor/icons/compass.png + + + true + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + VORs + + + + + + + Select VOR channel + + + + + + + + 24 + 16777215 + + + + Refresh VOR channels available + + + + + + + :/recycle.png:/recycle.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + 110 + 391 + 140 + + + + + 0 + 0 + + + + VORs + + + + 2 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + QAbstractItemView::NoEditTriggers + + + + Name + + + Name of the VOR + + + + + Freq (MHz) + + + Frequency of the VOR in MHz + + + + + Offset (kHz) + + + Offset of the VOR's frequency from the current center frequency. Red indicates out of range. + + + + + Ident + + + Ident for the VOR + + + + + Morse + + + Morse code ident for the VOR + + + + + RX Ident + + + Received ident + + + + + RX Morse + + + Received Morse code ident + + + + + Radial (°) + + + Calculated radial from the VOR + + + + + Ref (dB) + + + Magnitude of received reference signal in dB + + + + + Var (dB) + + + Magnitude of received variable signal in dB + + + + + Mute + + + Mute/unmute audio from selected VORs + + + + + + + + + + 0 + 260 + 391 + 581 + + + + + 0 + 0 + + + + Map + + + + 2 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 0 + 0 + + + + + 100 + 500 + + + + VOR map + + + QQuickWidget::SizeRootObjectToView + + + + + + + + + + + + + + QQuickWidget + QWidget +
QtQuickWidgets/QQuickWidget
+
+ + RollupWidget + QWidget +
gui/rollupwidget.h
+ 1 +
+ + ButtonSwitch + QToolButton +
gui/buttonswitch.h
+
+
+ + getOurAirportsVORDB + vorData + map + + + + + + + +
diff --git a/plugins/feature/vorlocalizer/vorlocalizerplugin.cpp b/plugins/feature/vorlocalizer/vorlocalizerplugin.cpp new file mode 100644 index 000000000..b1e9e1971 --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizerplugin.cpp @@ -0,0 +1,80 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + + +#include +#include "plugin/pluginapi.h" + +#ifndef SERVER_MODE +#include "vorlocalizergui.h" +#endif +#include "vorlocalizer.h" +#include "vorlocalizerplugin.h" +#include "vorlocalizerwebapiadapter.h" + +const PluginDescriptor VORLocalizerPlugin::m_pluginDescriptor = { + VORLocalizer::m_featureId, + QStringLiteral("VOR Localizer"), + QStringLiteral("6.3.0"), + QStringLiteral("(c) Jon Beniston, M7RCE"), + QStringLiteral("https://github.com/f4exb/sdrangel"), + true, + QStringLiteral("https://github.com/f4exb/sdrangel") +}; + +VORLocalizerPlugin::VORLocalizerPlugin(QObject* parent) : + QObject(parent), + m_pluginAPI(nullptr) +{ +} + +const PluginDescriptor& VORLocalizerPlugin::getPluginDescriptor() const +{ + return m_pluginDescriptor; +} + +void VORLocalizerPlugin::initPlugin(PluginAPI* pluginAPI) +{ + m_pluginAPI = pluginAPI; + + // register Simple PTT feature + m_pluginAPI->registerFeature(VORLocalizer::m_featureIdURI, VORLocalizer::m_featureId, this); +} + +#ifdef SERVER_MODE +FeatureGUI* VORLocalizerPlugin::createFeatureGUI(FeatureUISet *featureUISet, Feature *feature) const +{ + (void) featureUISet; + (void) feature; + return nullptr; +} +#else +FeatureGUI* VORLocalizerPlugin::createFeatureGUI(FeatureUISet *featureUISet, Feature *feature) const +{ + return VORLocalizerGUI::create(m_pluginAPI, featureUISet, feature); +} +#endif + +Feature* VORLocalizerPlugin::createFeature(WebAPIAdapterInterface* webAPIAdapterInterface) const +{ + return new VORLocalizer(webAPIAdapterInterface); +} + +FeatureWebAPIAdapter* VORLocalizerPlugin::createFeatureWebAPIAdapter() const +{ + return new VORLocalizerWebAPIAdapter(); +} diff --git a/plugins/feature/vorlocalizer/vorlocalizerplugin.h b/plugins/feature/vorlocalizer/vorlocalizerplugin.h new file mode 100644 index 000000000..0d551d896 --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizerplugin.h @@ -0,0 +1,48 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_FEATURE_SIMPLEPTTPLUGIN_H +#define INCLUDE_FEATURE_SIMPLEPTTPLUGIN_H + +#include +#include "plugin/plugininterface.h" + +class FeatureGUI; +class WebAPIAdapterInterface; + +class VORLocalizerPlugin : public QObject, PluginInterface { + Q_OBJECT + Q_INTERFACES(PluginInterface) + Q_PLUGIN_METADATA(IID "sdrangel.feature.vorlocalizer") + +public: + explicit VORLocalizerPlugin(QObject* parent = nullptr); + + const PluginDescriptor& getPluginDescriptor() const; + void initPlugin(PluginAPI* pluginAPI); + + virtual FeatureGUI* createFeatureGUI(FeatureUISet *featureUISet, Feature *feature) const; + virtual Feature* createFeature(WebAPIAdapterInterface *webAPIAdapterInterface) const; + virtual FeatureWebAPIAdapter* createFeatureWebAPIAdapter() const; + +private: + static const PluginDescriptor m_pluginDescriptor; + + PluginAPI* m_pluginAPI; +}; + +#endif // INCLUDE_FEATURE_SIMPLEPTTPLUGIN_H diff --git a/plugins/feature/vorlocalizer/vorlocalizerreport.cpp b/plugins/feature/vorlocalizer/vorlocalizerreport.cpp new file mode 100644 index 000000000..d2fd7572e --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizerreport.cpp @@ -0,0 +1,23 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "vorlocalizerreport.h" + +MESSAGE_CLASS_DEFINITION(VORLocalizerReport::MsgReportFreqOffset, Message) +MESSAGE_CLASS_DEFINITION(VORLocalizerReport::MsgReportRadial, Message) +MESSAGE_CLASS_DEFINITION(VORLocalizerReport::MsgReportIdent, Message) +MESSAGE_CLASS_DEFINITION(VORLocalizerReport::MsgReportChannels, Message) diff --git a/plugins/feature/vorlocalizer/vorlocalizerreport.h b/plugins/feature/vorlocalizer/vorlocalizerreport.h new file mode 100644 index 000000000..d9abe4d5e --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizerreport.h @@ -0,0 +1,172 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB // +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_VORLOCALIZERREPORT_H +#define INCLUDE_VORLOCALIZERREPORT_H + +#include + +#include "util/message.h" + +class VORLocalizerReport : public QObject +{ + Q_OBJECT +public: + class MsgReportRadial : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getSubChannelId() const { return m_subChannelId; } + float getRadial() const { return m_radial; } + float getRefMag() const { return m_refMag; } + float getVarMag() const { return m_varMag; } + bool getValidRadial() const { return m_validRadial; } + bool getValidRefMag() const { return m_validRefMag; } + bool getValidVarMag() const { return m_validVarMag; } + + static MsgReportRadial* create( + int subChannelId, + float radial, + float refMag, + float varMag, + bool validRadial, + bool validRefMag, + bool validVarMag + ) + { + return new MsgReportRadial( + subChannelId, + radial, + refMag, + varMag, + validRadial, + validRefMag, + validVarMag + ); + } + + private: + int m_subChannelId; + float m_radial; + float m_refMag; + float m_varMag; + bool m_validRadial; + bool m_validRefMag; + bool m_validVarMag; + + MsgReportRadial( + int subChannelId, + float radial, + float refMag, + float varMag, + bool validRadial, + bool validRefMag, + bool validVarMag + ) : + Message(), + m_subChannelId(subChannelId), + m_radial(radial), + m_refMag(refMag), + m_varMag(varMag), + m_validRadial(validRadial), + m_validRefMag(validRefMag), + m_validVarMag(validVarMag) + { + } + }; + + class MsgReportFreqOffset : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getSubChannelId() const { return m_subChannelId; } + int getFreqOffset() const { return m_freqOffset; } + bool getOutOfBand() const { return m_outOfBand; } + + static MsgReportFreqOffset* create(int subChannelId, int freqOffset, bool outOfBand) + { + return new MsgReportFreqOffset(subChannelId, freqOffset, outOfBand); + } + + private: + int m_subChannelId; + int m_freqOffset; + bool m_outOfBand; + + MsgReportFreqOffset(int subChannelId, int freqOffset, bool outOfBand) : + Message(), + m_subChannelId(subChannelId), + m_freqOffset(freqOffset), + m_outOfBand(outOfBand) + { + } + }; + + class MsgReportIdent : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getSubChannelId() const { return m_subChannelId; } + QString getIdent() const { return m_ident; } + + static MsgReportIdent* create(int subChannelId, QString ident) + { + return new MsgReportIdent(subChannelId, ident); + } + + private: + int m_subChannelId; + QString m_ident; + + MsgReportIdent(int subChannelId, QString ident) : + Message(), + m_subChannelId(subChannelId), + m_ident(ident) + { + } + }; + + class MsgReportChannels : public Message { + MESSAGE_CLASS_DECLARATION + + public: + struct Channel { + int m_deviceSetIndex; + int m_channelIndex; + }; + + std::vector& getChannels() { return m_channels; } + + static MsgReportChannels* create() { + return new MsgReportChannels(); + } + + private: + std::vector m_channels; + + MsgReportChannels() : + Message() + {} + }; + +public: + VORLocalizerReport() {} + ~VORLocalizerReport() {} +}; + +#endif // INCLUDE_VORLOCALIZERREPORT_H diff --git a/plugins/feature/vorlocalizer/vorlocalizersettings.cpp b/plugins/feature/vorlocalizer/vorlocalizersettings.cpp new file mode 100644 index 000000000..5664a4f04 --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizersettings.cpp @@ -0,0 +1,126 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2015 Edouard Griffiths, F4EXB. // +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "dsp/dspengine.h" +#include "util/simpleserializer.h" +#include "settings/serializable.h" +#include "vorlocalizersettings.h" + +VORLocalizerSettings::VORLocalizerSettings() +{ + resetToDefaults(); +} + +void VORLocalizerSettings::resetToDefaults() +{ + m_rgbColor = QColor(255, 255, 0).rgb(); + m_title = "VOR Localizer"; + m_magDecAdjust = true; + m_useReverseAPI = false; + m_reverseAPIAddress = "127.0.0.1"; + m_reverseAPIPort = 8888; + m_reverseAPIFeatureSetIndex = 0; + m_reverseAPIFeatureIndex = 0; + + + for (int i = 0; i < VORDEMOD_COLUMNS; i++) + { + m_columnIndexes[i] = i; + m_columnSizes[i] = -1; // Autosize + } +} + +QByteArray VORLocalizerSettings::serialize() const +{ + SimpleSerializer s(1); + + s.writeU32(7, m_rgbColor); + s.writeString(9, m_title); + s.writeBool(10, m_magDecAdjust); + s.writeBool(14, m_useReverseAPI); + s.writeString(15, m_reverseAPIAddress); + s.writeU32(16, m_reverseAPIPort); + s.writeU32(17, m_reverseAPIFeatureSetIndex); + s.writeU32(18, m_reverseAPIFeatureIndex); + + for (int i = 0; i < VORDEMOD_COLUMNS; i++) { + s.writeS32(100 + i, m_columnIndexes[i]); + } + + for (int i = 0; i < VORDEMOD_COLUMNS; i++) { + s.writeS32(200 + i, m_columnSizes[i]); + } + + return s.final(); +} + +bool VORLocalizerSettings::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if(!d.isValid()) + { + resetToDefaults(); + return false; + } + + if(d.getVersion() == 1) + { + QByteArray bytetmp; + uint32_t utmp; + QString strtmp; + + d.readBlob(6, &bytetmp); + d.readU32(7, &m_rgbColor); + d.readString(9, &m_title, "VOR Localizer"); + d.readBool(10, &m_magDecAdjust, true); + d.readBool(14, &m_useReverseAPI, false); + d.readString(15, &m_reverseAPIAddress, "127.0.0.1"); + d.readU32(16, &utmp, 0); + + if ((utmp > 1023) && (utmp < 65535)) { + m_reverseAPIPort = utmp; + } else { + m_reverseAPIPort = 8888; + } + + d.readU32(17, &utmp, 0); + m_reverseAPIFeatureSetIndex = utmp > 99 ? 99 : utmp; + d.readU32(18, &utmp, 0); + m_reverseAPIFeatureIndex = utmp > 99 ? 99 : utmp; + + for (int i = 0; i < VORDEMOD_COLUMNS; i++) { + d.readS32(100 + i, &m_columnIndexes[i], i); + } + + for (int i = 0; i < VORDEMOD_COLUMNS; i++) { + d.readS32(200 + i, &m_columnSizes[i], -1); + } + + return true; + } + else + { + resetToDefaults(); + return false; + } +} + + diff --git a/plugins/feature/vorlocalizer/vorlocalizersettings.h b/plugins/feature/vorlocalizer/vorlocalizersettings.h new file mode 100644 index 000000000..f08f6bf2a --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizersettings.h @@ -0,0 +1,77 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB. // +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_VORLOCALIZERSETTINGS_H +#define INCLUDE_VORLOCALIZERSETTINGS_H + +#include +#include + +class Serializable; + +// Number of columns in the table + +struct VORLocalizerSubChannelSettings { + int m_id; //!< Unique VOR identifier (from database) + int m_frequency; //!< Frequency the VOR is on + bool m_audioMute; //!< Mute the audio from this VOR +}; + +struct VORLocalizerSettings +{ + struct VORDemodChannels + { + int m_deviceSetIndex; + int m_channelIndex; + }; + + quint32 m_rgbColor; + QString m_title; + bool m_magDecAdjust; //!< Adjust for magnetic declination when drawing radials on the map + bool m_useReverseAPI; + QString m_reverseAPIAddress; + uint16_t m_reverseAPIPort; + uint16_t m_reverseAPIFeatureSetIndex; + uint16_t m_reverseAPIFeatureIndex; + + + static const int VORDEMOD_COLUMNS = 11; + static const int VOR_COL_NAME = 0; + static const int VOR_COL_FREQUENCY = 1; + static const int VOR_COL_OFFSET = 2; + static const int VOR_COL_IDENT = 3; + static const int VOR_COL_MORSE = 4; + static const int VOR_COL_RX_IDENT = 5; + static const int VOR_COL_RX_MORSE = 6; + static const int VOR_COL_RADIAL = 7; + static const int VOR_COL_REF_MAG = 8; + static const int VOR_COL_VAR_MAG = 9; + static const int VOR_COL_MUTE = 10; + + int m_columnIndexes[VORDEMOD_COLUMNS];//!< How the columns are ordered in the table + int m_columnSizes[VORDEMOD_COLUMNS]; //!< Size of the coumns in the table + + QHash m_subChannelSettings; + + VORLocalizerSettings(); + void resetToDefaults(); + QByteArray serialize() const; + bool deserialize(const QByteArray& data); +}; + +#endif /* INCLUDE_VORLOCALIZERSETTINGS_H */ diff --git a/plugins/feature/vorlocalizer/vorlocalizerwebapiadapter.cpp b/plugins/feature/vorlocalizer/vorlocalizerwebapiadapter.cpp new file mode 100644 index 000000000..0e38ddc93 --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizerwebapiadapter.cpp @@ -0,0 +1,52 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "SWGFeatureSettings.h" +#include "vorlocalizer.h" +#include "vorlocalizerwebapiadapter.h" + +VORLocalizerWebAPIAdapter::VORLocalizerWebAPIAdapter() +{} + +VORLocalizerWebAPIAdapter::~VORLocalizerWebAPIAdapter() +{} + +int VORLocalizerWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGFeatureSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setVorLocalizerSettings(new SWGSDRangel::SWGVORLocalizerSettings()); + response.getVorLocalizerSettings()->init(); + VORLocalizer::webapiFormatFeatureSettings(response, m_settings); + + return 200; +} + +int VORLocalizerWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& featureSettingsKeys, + SWGSDRangel::SWGFeatureSettings& response, + QString& errorMessage) +{ + (void) force; + (void) errorMessage; + VORLocalizer::webapiUpdateFeatureSettings(m_settings, featureSettingsKeys, response); + + return 200; +} diff --git a/plugins/feature/vorlocalizer/vorlocalizerwebapiadapter.h b/plugins/feature/vorlocalizer/vorlocalizerwebapiadapter.h new file mode 100644 index 000000000..6a6d30af3 --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizerwebapiadapter.h @@ -0,0 +1,50 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_VORLOCALIZER_WEBAPIADAPTER_H +#define INCLUDE_VORLOCALIZER_WEBAPIADAPTER_H + +#include "feature/featurewebapiadapter.h" +#include "vorlocalizersettings.h" + +/** + * Standalone API adapter only for the settings + */ +class VORLocalizerWebAPIAdapter : public FeatureWebAPIAdapter { +public: + VORLocalizerWebAPIAdapter(); + virtual ~VORLocalizerWebAPIAdapter(); + + virtual QByteArray serialize() const { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data) { return m_settings.deserialize(data); } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGFeatureSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& featureSettingsKeys, + SWGSDRangel::SWGFeatureSettings& response, + QString& errorMessage); + +private: + VORLocalizerSettings m_settings; +}; + +#endif // INCLUDE_VORDEMOD_WEBAPIADAPTER_H diff --git a/plugins/feature/vorlocalizer/vorlocalizerworker.cpp b/plugins/feature/vorlocalizer/vorlocalizerworker.cpp new file mode 100644 index 000000000..adc2bf9e0 --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizerworker.cpp @@ -0,0 +1,223 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "SWGDeviceState.h" +#include "SWGSuccessResponse.h" +#include "SWGErrorResponse.h" + +#include "webapi/webapiadapterinterface.h" +#include "device/deviceset.h" +#include "channel/channelapi.h" +#include "maincore.h" + +#include "vorlocalizerreport.h" +#include "vorlocalizerworker.h" + +MESSAGE_CLASS_DEFINITION(VorLocalizerWorker::MsgConfigureVORLocalizerWorker, Message) +MESSAGE_CLASS_DEFINITION(VorLocalizerWorker::MsgRefreshChannels, Message) + +class DSPDeviceSourceEngine; + +VorLocalizerWorker::VorLocalizerWorker(WebAPIAdapterInterface *webAPIAdapterInterface) : + m_webAPIAdapterInterface(webAPIAdapterInterface), + m_msgQueueToGUI(nullptr), + m_running(false), + m_mutex(QMutex::Recursive) +{ + qDebug("VorLocalizerWorker::VorLocalizerWorker"); + connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); +} + +VorLocalizerWorker::~VorLocalizerWorker() +{ + m_inputMessageQueue.clear(); +} + +void VorLocalizerWorker::reset() +{ + QMutexLocker mutexLocker(&m_mutex); + m_inputMessageQueue.clear(); +} + +bool VorLocalizerWorker::startWork() +{ + QMutexLocker mutexLocker(&m_mutex); + connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + m_running = true; + return m_running; +} + +void VorLocalizerWorker::stopWork() +{ + QMutexLocker mutexLocker(&m_mutex); + disconnect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + m_running = false; +} + +void VorLocalizerWorker::handleInputMessages() +{ + Message* message; + + while ((message = m_inputMessageQueue.pop()) != nullptr) + { + if (handleMessage(*message)) { + delete message; + } + } +} + +bool VorLocalizerWorker::handleMessage(const Message& cmd) +{ + if (MsgConfigureVORLocalizerWorker::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + MsgConfigureVORLocalizerWorker& cfg = (MsgConfigureVORLocalizerWorker&) cmd; + qDebug() << "VorLocalizerWorker::handleMessage: MsgConfigureVORLocalizerWorker"; + + applySettings(cfg.getSettings(), cfg.getForce()); + + return true; + } + else if (MsgRefreshChannels::match(cmd)) + { + qDebug() << "VorLocalizerWorker::handleMessage: MsgRefreshChannels"; + updateChannels(); + return true; + } + else + { + return false; + } +} + +void VorLocalizerWorker::applySettings(const VORLocalizerSettings& settings, bool force) +{ + qDebug() << "VorLocalizerWorker::applySettings:" + << " m_title: " << settings.m_title + << " m_rgbColor: " << settings.m_rgbColor + << " force: " << force; + + // Remove sub-channels no longer needed + for (int i = 0; i < m_vorChannels.size(); i++) + { + if (!settings.m_subChannelSettings.contains(m_vorChannels[i].m_subChannelId)) + { + qDebug() << "VorLocalizerWorker::applySettings: Removing sink " << m_vorChannels[i].m_subChannelId; + removeVORChannel(m_vorChannels[i].m_subChannelId); + } + } + + // Add new sub channels + QHash::const_iterator itr = settings.m_subChannelSettings.begin(); + while (itr != settings.m_subChannelSettings.end()) + { + VORLocalizerSubChannelSettings *subChannelSettings = itr.value(); + int j = 0; + + for (; j < m_vorChannels.size(); j++) + { + if (subChannelSettings->m_id == m_vorChannels[j].m_subChannelId) + break; + } + + if (j == m_vorChannels.size()) + { + // Add a sub-channel sink + qDebug() << "VorLocalizerWorker::applySettings: Adding sink " << subChannelSettings->m_id; + addVORChannel(subChannelSettings); + } + + ++itr; + } + + m_settings = settings; +} + +void VorLocalizerWorker::updateHardware() +{ + SWGSDRangel::SWGSuccessResponse response; + SWGSDRangel::SWGErrorResponse error; + m_updateTimer.stop(); + m_mutex.unlock(); +} + +void VorLocalizerWorker::removeVORChannel(int navId) +{ + for (int i = 0; i < m_vorChannels.size(); i++) + { + if (m_vorChannels[i].m_subChannelId == navId) + { + m_vorChannels.removeAt(i); + break; + } + } +} + +void VorLocalizerWorker::addVORChannel(const VORLocalizerSubChannelSettings *subChannelSettings) +{ + VORChannel vorChannel = VORChannel{subChannelSettings->m_id, subChannelSettings->m_frequency, subChannelSettings->m_audioMute}; + m_vorChannels.push_back(vorChannel); +} + +void VorLocalizerWorker::updateChannels() +{ + MainCore *mainCore = MainCore::instance(); + std::vector& deviceSets = mainCore->getDeviceSets(); + std::vector::const_iterator it = deviceSets.begin(); + m_availableChannels.clear(); + + int deviceIndex = 0; + + for (; it != deviceSets.end(); ++it, deviceIndex++) + { + DSPDeviceSourceEngine *deviceSourceEngine = (*it)->m_deviceSourceEngine; + + if (deviceSourceEngine) + { + for (int chi = 0; chi < (*it)->getNumberOfChannels(); chi++) + { + ChannelAPI *channel = (*it)->getChannelAt(chi); + + if (channel->getURI() == "sdrangel.channel.vordemodsc") + { + AvailableChannel availableChannel = AvailableChannel{deviceIndex, chi, channel}; + m_availableChannels.push_back(availableChannel); + } + } + } + } + + if (m_msgQueueToGUI) + { + VORLocalizerReport::MsgReportChannels *msg = VORLocalizerReport::MsgReportChannels::create(); + std::vector& msgChannels = msg->getChannels(); + + for (int i = 0; i < m_availableChannels.size(); i++) + { + VORLocalizerReport::MsgReportChannels::Channel msgChannel = + VORLocalizerReport::MsgReportChannels::Channel{ + m_availableChannels[i].m_deviceSetIndex, + m_availableChannels[i].m_channelIndex + }; + msgChannels.push_back(msgChannel); + } + + m_msgQueueToGUI->push(msg); + } +} diff --git a/plugins/feature/vorlocalizer/vorlocalizerworker.h b/plugins/feature/vorlocalizer/vorlocalizerworker.h new file mode 100644 index 000000000..f898cd346 --- /dev/null +++ b/plugins/feature/vorlocalizer/vorlocalizerworker.h @@ -0,0 +1,118 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_FEATURE_VORLOCALIZERWORKER_H_ +#define INCLUDE_FEATURE_VORLOCALIZERWORKER_H_ + +#include +#include + +#include "util/message.h" +#include "util/messagequeue.h" + +#include "vorlocalizersettings.h" + +class WebAPIAdapterInterface; +class ChannelAPI; + +class VorLocalizerWorker : public QObject +{ + Q_OBJECT +public: + class MsgConfigureVORLocalizerWorker : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const VORLocalizerSettings& getSettings() const { return m_settings; } + bool getForce() const { return m_force; } + + static MsgConfigureVORLocalizerWorker* create(const VORLocalizerSettings& settings, bool force) + { + return new MsgConfigureVORLocalizerWorker(settings, force); + } + + private: + VORLocalizerSettings m_settings; + bool m_force; + + MsgConfigureVORLocalizerWorker(const VORLocalizerSettings& settings, bool force) : + Message(), + m_settings(settings), + m_force(force) + { } + }; + + class MsgRefreshChannels : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgRefreshChannels* create() { + return new MsgRefreshChannels(); + } + + protected: + MsgRefreshChannels() : + Message() + { } + }; + + VorLocalizerWorker(WebAPIAdapterInterface *webAPIAdapterInterface); + ~VorLocalizerWorker(); + void reset(); + bool startWork(); + void stopWork(); + bool isRunning() const { return m_running; } + MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } + void setMessageQueueToGUI(MessageQueue *messageQueue) { m_msgQueueToGUI = messageQueue; } + +private: + struct VORChannel + { + int m_subChannelId; //!< Unique VOR identifier (from database) + int m_frequency; //!< Frequency the VOR is on + bool m_audioMute; //!< Mute the audio from this VOR + }; + + struct AvailableChannel + { + int m_deviceSetIndex; + int m_channelIndex; + ChannelAPI *m_channelAPI; + }; + + WebAPIAdapterInterface *m_webAPIAdapterInterface; + MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication + MessageQueue *m_msgQueueToGUI; //!< Queue to report state to GUI + VORLocalizerSettings m_settings; + QList m_vorChannels; + QList m_availableChannels; + bool m_running; + QTimer m_updateTimer; + QMutex m_mutex; + + bool handleMessage(const Message& cmd); + void applySettings(const VORLocalizerSettings& settings, bool force = false); + void updateChannels(); + void removeVORChannel(int navId); + void addVORChannel(const VORLocalizerSubChannelSettings *subChannelSettings); + +private slots: + void handleInputMessages(); + void updateHardware(); +}; + +#endif // INCLUDE_FEATURE_VORLOCALIZERWORKER_H_ diff --git a/sdrbase/CMakeLists.txt b/sdrbase/CMakeLists.txt index 5f2502dd4..f14df3460 100644 --- a/sdrbase/CMakeLists.txt +++ b/sdrbase/CMakeLists.txt @@ -170,6 +170,7 @@ set(sdrbase_SOURCES util/azel.cpp util/crc.cpp util/CRC64.cpp + util/csv.cpp util/db.cpp util/fixedtraits.cpp util/httpdownloadmanager.cpp @@ -346,6 +347,7 @@ set(sdrbase_HEADERS util/azel.h util/CRC64.h + util/csv.h util/db.h util/doublebuffer.h util/doublebufferfifo.h diff --git a/sdrbase/resources/webapi.qrc b/sdrbase/resources/webapi.qrc index e9a0e8a2d..51a36ca67 100644 --- a/sdrbase/resources/webapi.qrc +++ b/sdrbase/resources/webapi.qrc @@ -84,6 +84,7 @@ webapi/doc/swagger/include/User.yaml webapi/doc/swagger/include/USRP.yaml webapi/doc/swagger/include/VORDemod.yaml + webapi/doc/swagger/include/VORLocalizer.yaml webapi/doc/swagger/include/VORDemodSC.yaml webapi/doc/swagger/include/WFMDemod.yaml webapi/doc/swagger/include/WFMMod.yaml diff --git a/sdrbase/resources/webapi/doc/html2/index.html b/sdrbase/resources/webapi/doc/html2/index.html index 2283eb3fb..f9373dbff 100644 --- a/sdrbase/resources/webapi/doc/html2/index.html +++ b/sdrbase/resources/webapi/doc/html2/index.html @@ -4094,6 +4094,9 @@ margin-bottom: 20px; }, "RigCtlServerSettings" : { "$ref" : "#/definitions/RigCtlServerSettings" + }, + "VORLocalizerSettings" : { + "$ref" : "#/definitions/VORLocalizerSettings" } }, "description" : "Base feature settings. Only the feature settings corresponding to the feature specified in the featureType field is or should be present." @@ -9614,6 +9617,37 @@ margin-bottom: 20px; } }, "description" : "VORDemod" +}; + defs.VORLocalizerSettings = { + "properties" : { + "rgbColor" : { + "type" : "integer" + }, + "title" : { + "type" : "string" + }, + "useReverseAPI" : { + "type" : "integer", + "description" : "Synchronize with reverse API (1 for yes, 0 for no)" + }, + "reverseAPIAddress" : { + "type" : "string" + }, + "reverseAPIPort" : { + "type" : "integer" + }, + "reverseAPIFeatureSetIndex" : { + "type" : "integer" + }, + "reverseAPIFeatureIndex" : { + "type" : "integer" + }, + "magDecAdjust" : { + "type" : "integer", + "description" : "Adjust radial lines on map for magnetic declination of VOR" + } + }, + "description" : "VORLocalizer" }; defs.WFMDemodReport = { "properties" : { @@ -44816,7 +44850,7 @@ except ApiException as e:
- Generated 2020-11-29T08:58:14.732+01:00 + Generated 2020-11-29T21:00:18.945+01:00
diff --git a/sdrbase/resources/webapi/doc/swagger/include/FeatureSettings.yaml b/sdrbase/resources/webapi/doc/swagger/include/FeatureSettings.yaml index 36ba21d2f..675596ffb 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/FeatureSettings.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/FeatureSettings.yaml @@ -21,3 +21,5 @@ FeatureSettings: $ref: "/doc/swagger/include/SimplePTT.yaml#/SimplePTTSettings" RigCtlServerSettings: $ref: "/doc/swagger/include/RigCtlServer.yaml#/RigCtlServerSettings" + VORLocalizerSettings: + $ref: "/doc/swagger/include/VORLocalizer.yaml#/VORLocalizerSettings" diff --git a/sdrbase/resources/webapi/doc/swagger/include/VORLocalizer.yaml b/sdrbase/resources/webapi/doc/swagger/include/VORLocalizer.yaml new file mode 100644 index 000000000..5b101cf60 --- /dev/null +++ b/sdrbase/resources/webapi/doc/swagger/include/VORLocalizer.yaml @@ -0,0 +1,21 @@ +VORLocalizerSettings: + description: VORLocalizer + properties: + rgbColor: + type: integer + title: + type: string + useReverseAPI: + description: Synchronize with reverse API (1 for yes, 0 for no) + type: integer + reverseAPIAddress: + type: string + reverseAPIPort: + type: integer + reverseAPIFeatureSetIndex: + type: integer + reverseAPIFeatureIndex: + type: integer + magDecAdjust: + description: Adjust radial lines on map for magnetic declination of VOR + type: integer diff --git a/sdrbase/util/csv.cpp b/sdrbase/util/csv.cpp new file mode 100644 index 000000000..a21ef2b29 --- /dev/null +++ b/sdrbase/util/csv.cpp @@ -0,0 +1,69 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "csv.h" + +#include +#include +#include +#include +#include +#include + +// Create a hash map from a CSV file with two columns +QHash *csvHash(const QString& filename, int reserve) +{ + int cnt = 0; + QHash *map = nullptr; + + qDebug() << "csvHash: " << filename; + + QFile file(filename); + if (file.open(QIODevice::ReadOnly)) + { + // Read header + if (!file.atEnd()) + { + QByteArray row = file.readLine().trimmed(); + if (row.split(',').size() == 2) + { + map = new QHash(); + if (reserve > 0) + map->reserve(reserve); + // Read data + while (!file.atEnd()) + { + row = file.readLine().trimmed(); + QList cols = row.split(','); + map->insert(QString(cols[0]), QString(cols[1])); + cnt++; + } + } + else + qDebug() << "csvHash: Unexpected header"; + } + else + qDebug() << "csvHash: Empty file"; + file.close(); + } + else + qDebug() << "csvHash: Failed to open " << filename; + + qDebug() << "csvHash: " << filename << ": read " << cnt << " entries"; + + return map; +} diff --git a/sdrbase/util/csv.h b/sdrbase/util/csv.h new file mode 100644 index 000000000..0a3716dc7 --- /dev/null +++ b/sdrbase/util/csv.h @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2020 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_CSV_H +#define INCLUDE_CSV_H + +#include +#include + +// Extract string from CSV line, updating pp to next column +static inline char *csvNext(char **pp) +{ + char *p = *pp; + + if (p[0] == '\0') + return nullptr; + + char *start = p; + + while ((*p != ',') && (*p != '\n')) + p++; + *p++ = '\0'; + *pp = p; + + return start; +} + +QHash *csvHash(const QString& filename, int reserve=0); + +#endif /* INCLUDE_CSV_H */ diff --git a/swagger/sdrangel/api/swagger/include/FeatureSettings.yaml b/swagger/sdrangel/api/swagger/include/FeatureSettings.yaml index 6efff8584..ecdc645b7 100644 --- a/swagger/sdrangel/api/swagger/include/FeatureSettings.yaml +++ b/swagger/sdrangel/api/swagger/include/FeatureSettings.yaml @@ -21,3 +21,5 @@ FeatureSettings: $ref: "http://swgserver:8081/api/swagger/include/SimplePTT.yaml#/SimplePTTSettings" RigCtlServerSettings: $ref: "http://swgserver:8081/api/swagger/include/RigCtlServer.yaml#/RigCtlServerSettings" + VORLocalizerSettings: + $ref: "http://swgserver:8081/api/swagger/include/VORLocalizer.yaml#/VORLocalizerSettings" diff --git a/swagger/sdrangel/api/swagger/include/VORLocalizer.yaml b/swagger/sdrangel/api/swagger/include/VORLocalizer.yaml new file mode 100644 index 000000000..5b101cf60 --- /dev/null +++ b/swagger/sdrangel/api/swagger/include/VORLocalizer.yaml @@ -0,0 +1,21 @@ +VORLocalizerSettings: + description: VORLocalizer + properties: + rgbColor: + type: integer + title: + type: string + useReverseAPI: + description: Synchronize with reverse API (1 for yes, 0 for no) + type: integer + reverseAPIAddress: + type: string + reverseAPIPort: + type: integer + reverseAPIFeatureSetIndex: + type: integer + reverseAPIFeatureIndex: + type: integer + magDecAdjust: + description: Adjust radial lines on map for magnetic declination of VOR + type: integer diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 2283eb3fb..f9373dbff 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -4094,6 +4094,9 @@ margin-bottom: 20px; }, "RigCtlServerSettings" : { "$ref" : "#/definitions/RigCtlServerSettings" + }, + "VORLocalizerSettings" : { + "$ref" : "#/definitions/VORLocalizerSettings" } }, "description" : "Base feature settings. Only the feature settings corresponding to the feature specified in the featureType field is or should be present." @@ -9614,6 +9617,37 @@ margin-bottom: 20px; } }, "description" : "VORDemod" +}; + defs.VORLocalizerSettings = { + "properties" : { + "rgbColor" : { + "type" : "integer" + }, + "title" : { + "type" : "string" + }, + "useReverseAPI" : { + "type" : "integer", + "description" : "Synchronize with reverse API (1 for yes, 0 for no)" + }, + "reverseAPIAddress" : { + "type" : "string" + }, + "reverseAPIPort" : { + "type" : "integer" + }, + "reverseAPIFeatureSetIndex" : { + "type" : "integer" + }, + "reverseAPIFeatureIndex" : { + "type" : "integer" + }, + "magDecAdjust" : { + "type" : "integer", + "description" : "Adjust radial lines on map for magnetic declination of VOR" + } + }, + "description" : "VORLocalizer" }; defs.WFMDemodReport = { "properties" : { @@ -44816,7 +44850,7 @@ except ApiException as e:
- Generated 2020-11-29T08:58:14.732+01:00 + Generated 2020-11-29T21:00:18.945+01:00
diff --git a/swagger/sdrangel/code/qt5/client/SWGFeatureSettings.cpp b/swagger/sdrangel/code/qt5/client/SWGFeatureSettings.cpp index c2a0e3588..45c6899c6 100644 --- a/swagger/sdrangel/code/qt5/client/SWGFeatureSettings.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGFeatureSettings.cpp @@ -42,6 +42,8 @@ SWGFeatureSettings::SWGFeatureSettings() { m_simple_ptt_settings_isSet = false; rig_ctl_server_settings = nullptr; m_rig_ctl_server_settings_isSet = false; + vor_localizer_settings = nullptr; + m_vor_localizer_settings_isSet = false; } SWGFeatureSettings::~SWGFeatureSettings() { @@ -64,6 +66,8 @@ SWGFeatureSettings::init() { m_simple_ptt_settings_isSet = false; rig_ctl_server_settings = new SWGRigCtlServerSettings(); m_rig_ctl_server_settings_isSet = false; + vor_localizer_settings = new SWGVORLocalizerSettings(); + m_vor_localizer_settings_isSet = false; } void @@ -85,6 +89,9 @@ SWGFeatureSettings::cleanup() { if(rig_ctl_server_settings != nullptr) { delete rig_ctl_server_settings; } + if(vor_localizer_settings != nullptr) { + delete vor_localizer_settings; + } } SWGFeatureSettings* @@ -112,6 +119,8 @@ SWGFeatureSettings::fromJsonObject(QJsonObject &pJson) { ::SWGSDRangel::setValue(&rig_ctl_server_settings, pJson["RigCtlServerSettings"], "SWGRigCtlServerSettings", "SWGRigCtlServerSettings"); + ::SWGSDRangel::setValue(&vor_localizer_settings, pJson["VORLocalizerSettings"], "SWGVORLocalizerSettings", "SWGVORLocalizerSettings"); + } QString @@ -149,6 +158,9 @@ SWGFeatureSettings::asJsonObject() { if((rig_ctl_server_settings != nullptr) && (rig_ctl_server_settings->isSet())){ toJsonValue(QString("RigCtlServerSettings"), rig_ctl_server_settings, obj, QString("SWGRigCtlServerSettings")); } + if((vor_localizer_settings != nullptr) && (vor_localizer_settings->isSet())){ + toJsonValue(QString("VORLocalizerSettings"), vor_localizer_settings, obj, QString("SWGVORLocalizerSettings")); + } return obj; } @@ -223,6 +235,16 @@ SWGFeatureSettings::setRigCtlServerSettings(SWGRigCtlServerSettings* rig_ctl_ser this->m_rig_ctl_server_settings_isSet = true; } +SWGVORLocalizerSettings* +SWGFeatureSettings::getVorLocalizerSettings() { + return vor_localizer_settings; +} +void +SWGFeatureSettings::setVorLocalizerSettings(SWGVORLocalizerSettings* vor_localizer_settings) { + this->vor_localizer_settings = vor_localizer_settings; + this->m_vor_localizer_settings_isSet = true; +} + bool SWGFeatureSettings::isSet(){ @@ -249,6 +271,9 @@ SWGFeatureSettings::isSet(){ if(rig_ctl_server_settings && rig_ctl_server_settings->isSet()){ isObjectUpdated = true; break; } + if(vor_localizer_settings && vor_localizer_settings->isSet()){ + isObjectUpdated = true; break; + } }while(false); return isObjectUpdated; } diff --git a/swagger/sdrangel/code/qt5/client/SWGFeatureSettings.h b/swagger/sdrangel/code/qt5/client/SWGFeatureSettings.h index 2b3828eec..de48ba254 100644 --- a/swagger/sdrangel/code/qt5/client/SWGFeatureSettings.h +++ b/swagger/sdrangel/code/qt5/client/SWGFeatureSettings.h @@ -26,6 +26,7 @@ #include "SWGGS232ControllerSettings.h" #include "SWGRigCtlServerSettings.h" #include "SWGSimplePTTSettings.h" +#include "SWGVORLocalizerSettings.h" #include #include "SWGObject.h" @@ -67,6 +68,9 @@ public: SWGRigCtlServerSettings* getRigCtlServerSettings(); void setRigCtlServerSettings(SWGRigCtlServerSettings* rig_ctl_server_settings); + SWGVORLocalizerSettings* getVorLocalizerSettings(); + void setVorLocalizerSettings(SWGVORLocalizerSettings* vor_localizer_settings); + virtual bool isSet() override; @@ -92,6 +96,9 @@ private: SWGRigCtlServerSettings* rig_ctl_server_settings; bool m_rig_ctl_server_settings_isSet; + SWGVORLocalizerSettings* vor_localizer_settings; + bool m_vor_localizer_settings_isSet; + }; } diff --git a/swagger/sdrangel/code/qt5/client/SWGModelFactory.h b/swagger/sdrangel/code/qt5/client/SWGModelFactory.h index 80ffe13ff..a58dd73ee 100644 --- a/swagger/sdrangel/code/qt5/client/SWGModelFactory.h +++ b/swagger/sdrangel/code/qt5/client/SWGModelFactory.h @@ -225,6 +225,7 @@ #include "SWGVORDemodSCReport.h" #include "SWGVORDemodSCSettings.h" #include "SWGVORDemodSettings.h" +#include "SWGVORLocalizerSettings.h" #include "SWGWFMDemodReport.h" #include "SWGWFMDemodSettings.h" #include "SWGWFMModReport.h" @@ -872,6 +873,9 @@ namespace SWGSDRangel { if(QString("SWGVORDemodSettings").compare(type) == 0) { return new SWGVORDemodSettings(); } + if(QString("SWGVORLocalizerSettings").compare(type) == 0) { + return new SWGVORLocalizerSettings(); + } if(QString("SWGWFMDemodReport").compare(type) == 0) { return new SWGWFMDemodReport(); } diff --git a/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings.cpp b/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings.cpp new file mode 100644 index 000000000..19e992b06 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings.cpp @@ -0,0 +1,273 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time --- + * + * OpenAPI spec version: 6.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +#include "SWGVORLocalizerSettings.h" + +#include "SWGHelpers.h" + +#include +#include +#include +#include + +namespace SWGSDRangel { + +SWGVORLocalizerSettings::SWGVORLocalizerSettings(QString* json) { + init(); + this->fromJson(*json); +} + +SWGVORLocalizerSettings::SWGVORLocalizerSettings() { + rgb_color = 0; + m_rgb_color_isSet = false; + title = nullptr; + m_title_isSet = false; + use_reverse_api = 0; + m_use_reverse_api_isSet = false; + reverse_api_address = nullptr; + m_reverse_api_address_isSet = false; + reverse_api_port = 0; + m_reverse_api_port_isSet = false; + reverse_api_feature_set_index = 0; + m_reverse_api_feature_set_index_isSet = false; + reverse_api_feature_index = 0; + m_reverse_api_feature_index_isSet = false; + mag_dec_adjust = 0; + m_mag_dec_adjust_isSet = false; +} + +SWGVORLocalizerSettings::~SWGVORLocalizerSettings() { + this->cleanup(); +} + +void +SWGVORLocalizerSettings::init() { + rgb_color = 0; + m_rgb_color_isSet = false; + title = new QString(""); + m_title_isSet = false; + use_reverse_api = 0; + m_use_reverse_api_isSet = false; + reverse_api_address = new QString(""); + m_reverse_api_address_isSet = false; + reverse_api_port = 0; + m_reverse_api_port_isSet = false; + reverse_api_feature_set_index = 0; + m_reverse_api_feature_set_index_isSet = false; + reverse_api_feature_index = 0; + m_reverse_api_feature_index_isSet = false; + mag_dec_adjust = 0; + m_mag_dec_adjust_isSet = false; +} + +void +SWGVORLocalizerSettings::cleanup() { + + if(title != nullptr) { + delete title; + } + + if(reverse_api_address != nullptr) { + delete reverse_api_address; + } + + + + +} + +SWGVORLocalizerSettings* +SWGVORLocalizerSettings::fromJson(QString &json) { + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject jsonObject = doc.object(); + this->fromJsonObject(jsonObject); + return this; +} + +void +SWGVORLocalizerSettings::fromJsonObject(QJsonObject &pJson) { + ::SWGSDRangel::setValue(&rgb_color, pJson["rgbColor"], "qint32", ""); + + ::SWGSDRangel::setValue(&title, pJson["title"], "QString", "QString"); + + ::SWGSDRangel::setValue(&use_reverse_api, pJson["useReverseAPI"], "qint32", ""); + + ::SWGSDRangel::setValue(&reverse_api_address, pJson["reverseAPIAddress"], "QString", "QString"); + + ::SWGSDRangel::setValue(&reverse_api_port, pJson["reverseAPIPort"], "qint32", ""); + + ::SWGSDRangel::setValue(&reverse_api_feature_set_index, pJson["reverseAPIFeatureSetIndex"], "qint32", ""); + + ::SWGSDRangel::setValue(&reverse_api_feature_index, pJson["reverseAPIFeatureIndex"], "qint32", ""); + + ::SWGSDRangel::setValue(&mag_dec_adjust, pJson["magDecAdjust"], "qint32", ""); + +} + +QString +SWGVORLocalizerSettings::asJson () +{ + QJsonObject* obj = this->asJsonObject(); + + QJsonDocument doc(*obj); + QByteArray bytes = doc.toJson(); + delete obj; + return QString(bytes); +} + +QJsonObject* +SWGVORLocalizerSettings::asJsonObject() { + QJsonObject* obj = new QJsonObject(); + if(m_rgb_color_isSet){ + obj->insert("rgbColor", QJsonValue(rgb_color)); + } + if(title != nullptr && *title != QString("")){ + toJsonValue(QString("title"), title, obj, QString("QString")); + } + if(m_use_reverse_api_isSet){ + obj->insert("useReverseAPI", QJsonValue(use_reverse_api)); + } + if(reverse_api_address != nullptr && *reverse_api_address != QString("")){ + toJsonValue(QString("reverseAPIAddress"), reverse_api_address, obj, QString("QString")); + } + if(m_reverse_api_port_isSet){ + obj->insert("reverseAPIPort", QJsonValue(reverse_api_port)); + } + if(m_reverse_api_feature_set_index_isSet){ + obj->insert("reverseAPIFeatureSetIndex", QJsonValue(reverse_api_feature_set_index)); + } + if(m_reverse_api_feature_index_isSet){ + obj->insert("reverseAPIFeatureIndex", QJsonValue(reverse_api_feature_index)); + } + if(m_mag_dec_adjust_isSet){ + obj->insert("magDecAdjust", QJsonValue(mag_dec_adjust)); + } + + return obj; +} + +qint32 +SWGVORLocalizerSettings::getRgbColor() { + return rgb_color; +} +void +SWGVORLocalizerSettings::setRgbColor(qint32 rgb_color) { + this->rgb_color = rgb_color; + this->m_rgb_color_isSet = true; +} + +QString* +SWGVORLocalizerSettings::getTitle() { + return title; +} +void +SWGVORLocalizerSettings::setTitle(QString* title) { + this->title = title; + this->m_title_isSet = true; +} + +qint32 +SWGVORLocalizerSettings::getUseReverseApi() { + return use_reverse_api; +} +void +SWGVORLocalizerSettings::setUseReverseApi(qint32 use_reverse_api) { + this->use_reverse_api = use_reverse_api; + this->m_use_reverse_api_isSet = true; +} + +QString* +SWGVORLocalizerSettings::getReverseApiAddress() { + return reverse_api_address; +} +void +SWGVORLocalizerSettings::setReverseApiAddress(QString* reverse_api_address) { + this->reverse_api_address = reverse_api_address; + this->m_reverse_api_address_isSet = true; +} + +qint32 +SWGVORLocalizerSettings::getReverseApiPort() { + return reverse_api_port; +} +void +SWGVORLocalizerSettings::setReverseApiPort(qint32 reverse_api_port) { + this->reverse_api_port = reverse_api_port; + this->m_reverse_api_port_isSet = true; +} + +qint32 +SWGVORLocalizerSettings::getReverseApiFeatureSetIndex() { + return reverse_api_feature_set_index; +} +void +SWGVORLocalizerSettings::setReverseApiFeatureSetIndex(qint32 reverse_api_feature_set_index) { + this->reverse_api_feature_set_index = reverse_api_feature_set_index; + this->m_reverse_api_feature_set_index_isSet = true; +} + +qint32 +SWGVORLocalizerSettings::getReverseApiFeatureIndex() { + return reverse_api_feature_index; +} +void +SWGVORLocalizerSettings::setReverseApiFeatureIndex(qint32 reverse_api_feature_index) { + this->reverse_api_feature_index = reverse_api_feature_index; + this->m_reverse_api_feature_index_isSet = true; +} + +qint32 +SWGVORLocalizerSettings::getMagDecAdjust() { + return mag_dec_adjust; +} +void +SWGVORLocalizerSettings::setMagDecAdjust(qint32 mag_dec_adjust) { + this->mag_dec_adjust = mag_dec_adjust; + this->m_mag_dec_adjust_isSet = true; +} + + +bool +SWGVORLocalizerSettings::isSet(){ + bool isObjectUpdated = false; + do{ + if(m_rgb_color_isSet){ + isObjectUpdated = true; break; + } + if(title && *title != QString("")){ + isObjectUpdated = true; break; + } + if(m_use_reverse_api_isSet){ + isObjectUpdated = true; break; + } + if(reverse_api_address && *reverse_api_address != QString("")){ + isObjectUpdated = true; break; + } + if(m_reverse_api_port_isSet){ + isObjectUpdated = true; break; + } + if(m_reverse_api_feature_set_index_isSet){ + isObjectUpdated = true; break; + } + if(m_reverse_api_feature_index_isSet){ + isObjectUpdated = true; break; + } + if(m_mag_dec_adjust_isSet){ + isObjectUpdated = true; break; + } + }while(false); + return isObjectUpdated; +} +} + diff --git a/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings.h b/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings.h new file mode 100644 index 000000000..9ddd7f205 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings.h @@ -0,0 +1,101 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time --- + * + * OpenAPI spec version: 6.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * SWGVORLocalizerSettings.h + * + * VORLocalizer + */ + +#ifndef SWGVORLocalizerSettings_H_ +#define SWGVORLocalizerSettings_H_ + +#include + + +#include + +#include "SWGObject.h" +#include "export.h" + +namespace SWGSDRangel { + +class SWG_API SWGVORLocalizerSettings: public SWGObject { +public: + SWGVORLocalizerSettings(); + SWGVORLocalizerSettings(QString* json); + virtual ~SWGVORLocalizerSettings(); + void init(); + void cleanup(); + + virtual QString asJson () override; + virtual QJsonObject* asJsonObject() override; + virtual void fromJsonObject(QJsonObject &json) override; + virtual SWGVORLocalizerSettings* fromJson(QString &jsonString) override; + + qint32 getRgbColor(); + void setRgbColor(qint32 rgb_color); + + QString* getTitle(); + void setTitle(QString* title); + + qint32 getUseReverseApi(); + void setUseReverseApi(qint32 use_reverse_api); + + QString* getReverseApiAddress(); + void setReverseApiAddress(QString* reverse_api_address); + + qint32 getReverseApiPort(); + void setReverseApiPort(qint32 reverse_api_port); + + qint32 getReverseApiFeatureSetIndex(); + void setReverseApiFeatureSetIndex(qint32 reverse_api_feature_set_index); + + qint32 getReverseApiFeatureIndex(); + void setReverseApiFeatureIndex(qint32 reverse_api_feature_index); + + qint32 getMagDecAdjust(); + void setMagDecAdjust(qint32 mag_dec_adjust); + + + virtual bool isSet() override; + +private: + qint32 rgb_color; + bool m_rgb_color_isSet; + + QString* title; + bool m_title_isSet; + + qint32 use_reverse_api; + bool m_use_reverse_api_isSet; + + QString* reverse_api_address; + bool m_reverse_api_address_isSet; + + qint32 reverse_api_port; + bool m_reverse_api_port_isSet; + + qint32 reverse_api_feature_set_index; + bool m_reverse_api_feature_set_index_isSet; + + qint32 reverse_api_feature_index; + bool m_reverse_api_feature_index_isSet; + + qint32 mag_dec_adjust; + bool m_mag_dec_adjust_isSet; + +}; + +} + +#endif /* SWGVORLocalizerSettings_H_ */ diff --git a/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings_vorDemodChannels.cpp b/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings_vorDemodChannels.cpp new file mode 100644 index 000000000..4004d5ecb --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings_vorDemodChannels.cpp @@ -0,0 +1,131 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time --- + * + * OpenAPI spec version: 6.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + +#include "SWGVORLocalizerSettings_vorDemodChannels.h" + +#include "SWGHelpers.h" + +#include +#include +#include +#include + +namespace SWGSDRangel { + +SWGVORLocalizerSettings_vorDemodChannels::SWGVORLocalizerSettings_vorDemodChannels(QString* json) { + init(); + this->fromJson(*json); +} + +SWGVORLocalizerSettings_vorDemodChannels::SWGVORLocalizerSettings_vorDemodChannels() { + device_set_index = 0; + m_device_set_index_isSet = false; + channel_index = 0; + m_channel_index_isSet = false; +} + +SWGVORLocalizerSettings_vorDemodChannels::~SWGVORLocalizerSettings_vorDemodChannels() { + this->cleanup(); +} + +void +SWGVORLocalizerSettings_vorDemodChannels::init() { + device_set_index = 0; + m_device_set_index_isSet = false; + channel_index = 0; + m_channel_index_isSet = false; +} + +void +SWGVORLocalizerSettings_vorDemodChannels::cleanup() { + + +} + +SWGVORLocalizerSettings_vorDemodChannels* +SWGVORLocalizerSettings_vorDemodChannels::fromJson(QString &json) { + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject jsonObject = doc.object(); + this->fromJsonObject(jsonObject); + return this; +} + +void +SWGVORLocalizerSettings_vorDemodChannels::fromJsonObject(QJsonObject &pJson) { + ::SWGSDRangel::setValue(&device_set_index, pJson["deviceSetIndex"], "qint32", ""); + + ::SWGSDRangel::setValue(&channel_index, pJson["channelIndex"], "qint32", ""); + +} + +QString +SWGVORLocalizerSettings_vorDemodChannels::asJson () +{ + QJsonObject* obj = this->asJsonObject(); + + QJsonDocument doc(*obj); + QByteArray bytes = doc.toJson(); + delete obj; + return QString(bytes); +} + +QJsonObject* +SWGVORLocalizerSettings_vorDemodChannels::asJsonObject() { + QJsonObject* obj = new QJsonObject(); + if(m_device_set_index_isSet){ + obj->insert("deviceSetIndex", QJsonValue(device_set_index)); + } + if(m_channel_index_isSet){ + obj->insert("channelIndex", QJsonValue(channel_index)); + } + + return obj; +} + +qint32 +SWGVORLocalizerSettings_vorDemodChannels::getDeviceSetIndex() { + return device_set_index; +} +void +SWGVORLocalizerSettings_vorDemodChannels::setDeviceSetIndex(qint32 device_set_index) { + this->device_set_index = device_set_index; + this->m_device_set_index_isSet = true; +} + +qint32 +SWGVORLocalizerSettings_vorDemodChannels::getChannelIndex() { + return channel_index; +} +void +SWGVORLocalizerSettings_vorDemodChannels::setChannelIndex(qint32 channel_index) { + this->channel_index = channel_index; + this->m_channel_index_isSet = true; +} + + +bool +SWGVORLocalizerSettings_vorDemodChannels::isSet(){ + bool isObjectUpdated = false; + do{ + if(m_device_set_index_isSet){ + isObjectUpdated = true; break; + } + if(m_channel_index_isSet){ + isObjectUpdated = true; break; + } + }while(false); + return isObjectUpdated; +} +} + diff --git a/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings_vorDemodChannels.h b/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings_vorDemodChannels.h new file mode 100644 index 000000000..3416ee3a4 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGVORLocalizerSettings_vorDemodChannels.h @@ -0,0 +1,64 @@ +/** + * SDRangel + * This is the web REST/JSON API of SDRangel SDR software. SDRangel is an Open Source Qt5/OpenGL 3.0+ (4.3+ in Windows) GUI and server Software Defined Radio and signal analyzer in software. It supports Airspy, BladeRF, HackRF, LimeSDR, PlutoSDR, RTL-SDR, SDRplay RSP1 and FunCube --- Limitations and specifcities: * In SDRangel GUI the first Rx device set cannot be deleted. Conversely the server starts with no device sets and its number of device sets can be reduced to zero by as many calls as necessary to /sdrangel/deviceset with DELETE method. * Preset import and export from/to file is a server only feature. * Device set focus is a GUI only feature. * The following channels are not implemented (status 501 is returned): ATV and DATV demodulators, Channel Analyzer NG, LoRa demodulator * The device settings and report structures contains only the sub-structure corresponding to the device type. The DeviceSettings and DeviceReport structures documented here shows all of them but only one will be or should be present at a time * The channel settings and report structures contains only the sub-structure corresponding to the channel type. The ChannelSettings and ChannelReport structures documented here shows all of them but only one will be or should be present at a time --- + * + * OpenAPI spec version: 6.0.0 + * Contact: f4exb06@gmail.com + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +/* + * SWGVORLocalizerSettings_vorDemodChannels.h + * + * + */ + +#ifndef SWGVORLocalizerSettings_vorDemodChannels_H_ +#define SWGVORLocalizerSettings_vorDemodChannels_H_ + +#include + + + +#include "SWGObject.h" +#include "export.h" + +namespace SWGSDRangel { + +class SWG_API SWGVORLocalizerSettings_vorDemodChannels: public SWGObject { +public: + SWGVORLocalizerSettings_vorDemodChannels(); + SWGVORLocalizerSettings_vorDemodChannels(QString* json); + virtual ~SWGVORLocalizerSettings_vorDemodChannels(); + void init(); + void cleanup(); + + virtual QString asJson () override; + virtual QJsonObject* asJsonObject() override; + virtual void fromJsonObject(QJsonObject &json) override; + virtual SWGVORLocalizerSettings_vorDemodChannels* fromJson(QString &jsonString) override; + + qint32 getDeviceSetIndex(); + void setDeviceSetIndex(qint32 device_set_index); + + qint32 getChannelIndex(); + void setChannelIndex(qint32 channel_index); + + + virtual bool isSet() override; + +private: + qint32 device_set_index; + bool m_device_set_index_isSet; + + qint32 channel_index; + bool m_channel_index_isSet; + +}; + +} + +#endif /* SWGVORLocalizerSettings_vorDemodChannels_H_ */