diff --git a/CMakeLists.txt b/CMakeLists.txt index 2621e1212..56399cc89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,7 @@ option(ENABLE_CHANNELRX_DEMODDSD "Enable channelrx demoddsd plugin" ON) option(ENABLE_CHANNELRX_DEMODFT8 "Enable channelrx demodft8 plugin" ON) option(ENABLE_CHANNELRX_DEMODNAVTEX "Enable channelrx demodnavtex plugin" ON) option(ENABLE_CHANNELRX_DEMODRTTY "Enable channelrx demodrtty plugin" ON) +option(ENABLE_CHANNELRX_DEMODPSK31 "Enable channelrx demodpsk31 plugin" ON) option(ENABLE_CHANNELRX_DEMODILS "Enable channelrx demodils plugin" ON) option(ENABLE_CHANNELRX_DEMODDSC "Enable channelrx demoddsc plugin" ON) option(ENABLE_CHANNELRX_HEATMAP "Enable channelrx heatmap plugin" ON) diff --git a/doc/img/PSK31Demod_plugin.png b/doc/img/PSK31Demod_plugin.png new file mode 100644 index 000000000..555014903 Binary files /dev/null and b/doc/img/PSK31Demod_plugin.png differ diff --git a/plugins/channelrx/CMakeLists.txt b/plugins/channelrx/CMakeLists.txt index 5df094246..7992c8e13 100644 --- a/plugins/channelrx/CMakeLists.txt +++ b/plugins/channelrx/CMakeLists.txt @@ -211,6 +211,12 @@ else() message(STATUS "Not building demodrtty (ENABLE_CHANNELRX_DEMODRTTY=${ENABLE_CHANNELRX_DEMODRTTY})") endif() +if (ENABLE_CHANNELRX_DEMODPSK31) + add_subdirectory(demodpsk31) +else() + message(STATUS "Not building demodpsk31 (ENABLE_CHANNELRX_DEMODPSK31=${ENABLE_CHANNELRX_DEMODPSK31})") +endif() + if (ENABLE_CHANNELRX_DEMODILS) add_subdirectory(demodils) else() diff --git a/plugins/channelrx/demodpsk31/CMakeLists.txt b/plugins/channelrx/demodpsk31/CMakeLists.txt new file mode 100644 index 000000000..ba56457be --- /dev/null +++ b/plugins/channelrx/demodpsk31/CMakeLists.txt @@ -0,0 +1,71 @@ +project(demodpsk31) + +set(demodpsk31_SOURCES + psk31demod.cpp + psk31demodsettings.cpp + psk31demodbaseband.cpp + psk31demodsink.cpp + psk31demodplugin.cpp + psk31demodwebapiadapter.cpp +) + +set(demodpsk31_HEADERS + psk31demod.h + psk31demodsettings.h + psk31demodbaseband.h + psk31demodsink.h + psk31demodplugin.h + psk31demodwebapiadapter.h +) + +include_directories( + ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client +) + +if(NOT SERVER_MODE) + set(demodpsk31_SOURCES + ${demodpsk31_SOURCES} + psk31demodgui.cpp + psk31demodgui.ui + ) + set(demodpsk31_HEADERS + ${demodpsk31_HEADERS} + psk31demodgui.h + ) + + set(TARGET_NAME ${PLUGINS_PREFIX}demodpsk31) + set(TARGET_LIB "Qt::Widgets") + set(TARGET_LIB_GUI "sdrgui") + set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR}) +else() + set(TARGET_NAME ${PLUGINSSRV_PREFIX}demodpsk31srv) + set(TARGET_LIB "") + set(TARGET_LIB_GUI "") + set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR}) +endif() + +if(NOT Qt6_FOUND) + add_library(${TARGET_NAME} ${demodpsk31_SOURCES}) +else() + qt_add_plugin(${TARGET_NAME} CLASS_NAME PSK31DemodPlugin) + target_sources(${TARGET_NAME} PRIVATE ${demodpsk31_SOURCES}) +endif() + +if(NOT BUILD_SHARED_LIBS) + set_property(GLOBAL APPEND PROPERTY STATIC_PLUGINS_PROPERTY ${TARGET_NAME}) +endif() + +target_link_libraries(${TARGET_NAME} PRIVATE + Qt::Core + ${TARGET_LIB} + sdrbase + ${TARGET_LIB_GUI} +) + +install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER}) + +# Install debug symbols +if (WIN32) + install(FILES $/${TARGET_NAME}stripped.pdb CONFIGURATIONS Release DESTINATION ${INSTALL_FOLDER} RENAME ${TARGET_NAME}.pdb ) + install(FILES $ CONFIGURATIONS Debug RelWithDebInfo DESTINATION ${INSTALL_FOLDER} ) +endif() diff --git a/plugins/channelrx/demodpsk31/psk31demod.cpp b/plugins/channelrx/demodpsk31/psk31demod.cpp new file mode 100644 index 000000000..a918029b6 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demod.cpp @@ -0,0 +1,702 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 "psk31demod.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "SWGChannelSettings.h" +#include "SWGWorkspaceInfo.h" +#include "SWGPSK31DemodSettings.h" +#include "SWGChannelReport.h" + +#include "dsp/dspcommands.h" +#include "device/deviceapi.h" +#include "settings/serializable.h" +#include "util/db.h" +#include "maincore.h" + +MESSAGE_CLASS_DEFINITION(PSK31Demod::MsgConfigurePSK31Demod, Message) +MESSAGE_CLASS_DEFINITION(PSK31Demod::MsgCharacter, Message) +MESSAGE_CLASS_DEFINITION(PSK31Demod::MsgDemodReport, Message) + +const char * const PSK31Demod::m_channelIdURI = "sdrangel.channel.psk31demod"; +const char * const PSK31Demod::m_channelId = "PSK31Demod"; + +PSK31Demod::PSK31Demod(DeviceAPI *deviceAPI) : + ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), + m_deviceAPI(deviceAPI), + m_basebandSampleRate(0), + m_centerFrequency(0) +{ + setObjectName(m_channelId); + m_thread.setObjectName("PSK31DemodBB"); + + m_basebandSink = new PSK31DemodBaseband(); + m_basebandSink->setMessageQueueToChannel(getInputMessageQueue()); + m_basebandSink->moveToThread(&m_thread); + + applySettings(QStringList(), m_settings, true); + + m_deviceAPI->addChannelSink(this); + m_deviceAPI->addChannelSinkAPI(this); + + m_networkManager = new QNetworkAccessManager(); + QObject::connect( + m_networkManager, + &QNetworkAccessManager::finished, + this, + &PSK31Demod::networkManagerFinished + ); + QObject::connect( + this, + &ChannelAPI::indexInDeviceSetChanged, + this, + &PSK31Demod::handleIndexInDeviceSetChanged + ); +} + +PSK31Demod::~PSK31Demod() +{ + qDebug("PSK31Demod::~PSK31Demod"); + QObject::disconnect( + m_networkManager, + &QNetworkAccessManager::finished, + this, + &PSK31Demod::networkManagerFinished + ); + delete m_networkManager; + m_deviceAPI->removeChannelSinkAPI(this); + m_deviceAPI->removeChannelSink(this, true, m_settings.m_streamIndex); + + if (m_basebandSink->isRunning()) { + stop(); + } + + delete m_basebandSink; +} + +void PSK31Demod::setDeviceAPI(DeviceAPI *deviceAPI) +{ + if (deviceAPI != m_deviceAPI) + { + m_deviceAPI->removeChannelSinkAPI(this); + m_deviceAPI->removeChannelSink(this, false, m_settings.m_streamIndex); + m_deviceAPI = deviceAPI; + m_deviceAPI->addChannelSink(this, m_settings.m_streamIndex); + m_deviceAPI->addChannelSinkAPI(this); + } +} + +uint32_t PSK31Demod::getNumberOfDeviceStreams() const +{ + return m_deviceAPI->getNbSourceStreams(); +} + +void PSK31Demod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst) +{ + (void) firstOfBurst; + m_basebandSink->feed(begin, end); +} + +void PSK31Demod::start() +{ + qDebug("PSK31Demod::start"); + + m_basebandSink->reset(); + m_basebandSink->startWork(); + m_thread.start(); + + DSPSignalNotification *dspMsg = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency); + m_basebandSink->getInputMessageQueue()->push(dspMsg); + + PSK31DemodBaseband::MsgConfigurePSK31DemodBaseband *msg = PSK31DemodBaseband::MsgConfigurePSK31DemodBaseband::create(QStringList(), m_settings, true); + m_basebandSink->getInputMessageQueue()->push(msg); +} + +void PSK31Demod::stop() +{ + qDebug("PSK31Demod::stop"); + m_basebandSink->stopWork(); + m_thread.quit(); + m_thread.wait(); +} + +bool PSK31Demod::handleMessage(const Message& cmd) +{ + if (MsgConfigurePSK31Demod::match(cmd)) + { + MsgConfigurePSK31Demod& cfg = (MsgConfigurePSK31Demod&) cmd; + qDebug() << "PSK31Demod::handleMessage: MsgConfigurePSK31Demod"; + applySettings(cfg.getSettingsKeys(), cfg.getSettings(), cfg.getForce()); + return true; + } + else if (DSPSignalNotification::match(cmd)) + { + DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + m_basebandSampleRate = notif.getSampleRate(); + m_centerFrequency = notif.getCenterFrequency(); + // Forward to the sink + DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy + qDebug() << "PSK31Demod::handleMessage: DSPSignalNotification"; + m_basebandSink->getInputMessageQueue()->push(rep); + // Forward to GUI if any + if (m_guiMessageQueue) { + m_guiMessageQueue->push(new DSPSignalNotification(notif)); + } + + return true; + } + else if (PSK31Demod::MsgCharacter::match(cmd)) + { + // Forward to GUI + PSK31Demod::MsgCharacter& report = (PSK31Demod::MsgCharacter&)cmd; + if (getMessageQueueToGUI()) + { + PSK31Demod::MsgCharacter *msg = new PSK31Demod::MsgCharacter(report); + getMessageQueueToGUI()->push(msg); + } + + // Forward via UDP + if (m_settings.m_udpEnabled) + { + QByteArray bytes = report.getCharacter().toUtf8(); + m_udpSocket.writeDatagram(bytes, bytes.size(), + QHostAddress(m_settings.m_udpAddress), m_settings.m_udpPort); + } + + // Write to log file + if (m_logFile.isOpen()) + { + m_logStream << report.getCharacter(); + m_logStream.flush(); + } + + return true; + } + else if (PSK31Demod::MsgDemodReport::match(cmd)) + { + PSK31Demod::MsgDemodReport& report = (PSK31Demod::MsgDemodReport&)cmd; + if (getMessageQueueToGUI()) + { + PSK31Demod::MsgDemodReport *msg = new PSK31Demod::MsgDemodReport(report); + getMessageQueueToGUI()->push(msg); + } + + return true; + } + else if (MainCore::MsgChannelDemodQuery::match(cmd)) + { + qDebug() << "PSK31Demod::handleMessage: MsgChannelDemodQuery"; + sendSampleRateToDemodAnalyzer(); + + return true; + } + else + { + return false; + } +} + +ScopeVis *PSK31Demod::getScopeSink() +{ + return m_basebandSink->getScopeSink(); +} + +void PSK31Demod::setCenterFrequency(qint64 frequency) +{ + PSK31DemodSettings settings = m_settings; + settings.m_inputFrequencyOffset = frequency; + applySettings(QStringList({"inputFrequencyOffset"}), settings, false); + + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigurePSK31Demod *msgToGUI = MsgConfigurePSK31Demod::create(QStringList({"inputFrequencyOffset"}), settings, false); + m_guiMessageQueue->push(msgToGUI); + } +} + +void PSK31Demod::applySettings(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force) +{ + PSK31DemodSettings validatedSettings = settings; + validatedSettings.m_rfBandwidth = PSK31DemodSettings::validateRFBandwidth(settings.m_rfBandwidth); + qDebug() << "PSK31Demod::applySettings:" << validatedSettings.getDebugString(settingsKeys, force); + + if (settingsKeys.contains("streamIndex") && (validatedSettings.m_streamIndex != m_settings.m_streamIndex)) + { + if (m_deviceAPI->getSampleMIMO()) // change of stream is possible for MIMO devices only + { + m_deviceAPI->removeChannelSinkAPI(this); + m_deviceAPI->removeChannelSink(this, false, m_settings.m_streamIndex); + m_deviceAPI->addChannelSink(this, validatedSettings.m_streamIndex); + m_deviceAPI->addChannelSinkAPI(this); + m_settings.m_streamIndex = validatedSettings.m_streamIndex; // make sure ChannelAPI::getStreamIndex() is consistent + emit streamIndexChanged(validatedSettings.m_streamIndex); + } + } + + PSK31DemodBaseband::MsgConfigurePSK31DemodBaseband *msg = PSK31DemodBaseband::MsgConfigurePSK31DemodBaseband::create(settingsKeys, validatedSettings, force); + m_basebandSink->getInputMessageQueue()->push(msg); + + if (validatedSettings.m_useReverseAPI) + { + const bool fullUpdate = settingsKeys.contains("useReverseAPI") || + settingsKeys.contains("reverseAPIAddress") || + settingsKeys.contains("reverseAPIPort") || + settingsKeys.contains("reverseAPIDeviceIndex") || + settingsKeys.contains("reverseAPIChannelIndex"); + webapiReverseSendSettings(settingsKeys, validatedSettings, fullUpdate || force); + } + + if ((settingsKeys.contains("logEnabled") && (validatedSettings.m_logEnabled != m_settings.m_logEnabled)) + || (settingsKeys.contains("logFilename") && (validatedSettings.m_logFilename != m_settings.m_logFilename)) + || force) + { + if (m_logFile.isOpen()) + { + m_logStream.flush(); + m_logFile.close(); + } + if (validatedSettings.m_logEnabled && !validatedSettings.m_logFilename.isEmpty()) + { + m_logFile.setFileName(validatedSettings.m_logFilename); + if (m_logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) + { + qDebug() << "PSK31Demod::applySettings - Logging to: " << validatedSettings.m_logFilename; + m_logStream.setDevice(&m_logFile); + } + else + { + qDebug() << "PSK31Demod::applySettings - Unable to open log file: " << validatedSettings.m_logFilename; + } + } + } + + if (force) { + m_settings = validatedSettings; + } else { + m_settings.applySettings(settingsKeys, validatedSettings); + } +} + +void PSK31Demod::sendSampleRateToDemodAnalyzer() +{ + QList pipes; + MainCore::instance()->getMessagePipes().getMessagePipes(this, "reportdemod", pipes); + + if (pipes.size() > 0) + { + for (const auto& pipe : pipes) + { + MessageQueue *messageQueue = qobject_cast(pipe->m_element); + MainCore::MsgChannelDemodReport *msg = MainCore::MsgChannelDemodReport::create( + this, + PSK31DemodSettings::PSK31DEMOD_CHANNEL_SAMPLE_RATE + ); + messageQueue->push(msg); + } + } +} + +QByteArray PSK31Demod::serialize() const +{ + return m_settings.serialize(); +} + +bool PSK31Demod::deserialize(const QByteArray& data) +{ + PSK31DemodSettings settings = m_settings; + + if (settings.deserialize(data)) + { + MsgConfigurePSK31Demod *msg = MsgConfigurePSK31Demod::create(QStringList({"streamIndex"}), settings, true); + m_inputMessageQueue.push(msg); + return true; + } + else + { + settings.resetToDefaults(); + MsgConfigurePSK31Demod *msg = MsgConfigurePSK31Demod::create(QStringList({"streamIndex"}), settings, true); + m_inputMessageQueue.push(msg); + return false; + } +} + +int PSK31Demod::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setPSK31DemodSettings(new SWGSDRangel::SWGPSK31DemodSettings()); + response.getPSK31DemodSettings()->init(); + webapiFormatChannelSettings(response, m_settings); + return 200; +} + +int PSK31Demod::webapiWorkspaceGet( + SWGSDRangel::SWGWorkspaceInfo& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setIndex(m_settings.m_workspaceIndex); + return 200; +} + +int PSK31Demod::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + PSK31DemodSettings settings = m_settings; + webapiUpdateChannelSettings(settings, channelSettingsKeys, response); + + MsgConfigurePSK31Demod *msg = MsgConfigurePSK31Demod::create(channelSettingsKeys, settings, force); + m_inputMessageQueue.push(msg); + + qDebug("PSK31Demod::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue); + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigurePSK31Demod *msgToGUI = MsgConfigurePSK31Demod::create(channelSettingsKeys, settings, force); + m_guiMessageQueue->push(msgToGUI); + } + + webapiFormatChannelSettings(response, settings); + + return 200; +} + +int PSK31Demod::webapiReportGet( + SWGSDRangel::SWGChannelReport& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setPSK31DemodReport(new SWGSDRangel::SWGPSK31DemodReport()); + response.getPSK31DemodReport()->init(); + webapiFormatChannelReport(response); + return 200; +} + +void PSK31Demod::webapiUpdateChannelSettings( + PSK31DemodSettings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response) +{ + if (channelSettingsKeys.contains("inputFrequencyOffset")) { + settings.m_inputFrequencyOffset = response.getPSK31DemodSettings()->getInputFrequencyOffset(); + } + if (channelSettingsKeys.contains("rfBandwidth")) { + settings.m_rfBandwidth = PSK31DemodSettings::validateRFBandwidth( + response.getPSK31DemodSettings()->getRfBandwidth()); + } + if (channelSettingsKeys.contains("udpEnabled")) { + settings.m_udpEnabled = response.getPSK31DemodSettings()->getUdpEnabled(); + } + if (channelSettingsKeys.contains("udpAddress")) { + settings.m_udpAddress = *response.getPSK31DemodSettings()->getUdpAddress(); + } + if (channelSettingsKeys.contains("udpPort")) { + settings.m_udpPort = response.getPSK31DemodSettings()->getUdpPort(); + } + if (channelSettingsKeys.contains("logFilename")) { + settings.m_logFilename = *response.getPSK31DemodSettings()->getLogFilename(); + } + if (channelSettingsKeys.contains("logEnabled")) { + settings.m_logEnabled = response.getPSK31DemodSettings()->getLogEnabled(); + } + if (channelSettingsKeys.contains("rgbColor")) { + settings.m_rgbColor = response.getPSK31DemodSettings()->getRgbColor(); + } + if (channelSettingsKeys.contains("title")) { + settings.m_title = *response.getPSK31DemodSettings()->getTitle(); + } + if (channelSettingsKeys.contains("streamIndex")) { + settings.m_streamIndex = response.getPSK31DemodSettings()->getStreamIndex(); + } + if (channelSettingsKeys.contains("useReverseAPI")) { + settings.m_useReverseAPI = response.getPSK31DemodSettings()->getUseReverseApi() != 0; + } + if (channelSettingsKeys.contains("reverseAPIAddress")) { + settings.m_reverseAPIAddress = *response.getPSK31DemodSettings()->getReverseApiAddress(); + } + if (channelSettingsKeys.contains("reverseAPIPort")) { + settings.m_reverseAPIPort = response.getPSK31DemodSettings()->getReverseApiPort(); + } + if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { + settings.m_reverseAPIDeviceIndex = response.getPSK31DemodSettings()->getReverseApiDeviceIndex(); + } + if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { + settings.m_reverseAPIChannelIndex = response.getPSK31DemodSettings()->getReverseApiChannelIndex(); + } + if (settings.m_scopeGUI && channelSettingsKeys.contains("scopeConfig")) { + settings.m_scopeGUI->updateFrom(channelSettingsKeys, response.getPSK31DemodSettings()->getScopeConfig()); + } + if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) { + settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getPSK31DemodSettings()->getChannelMarker()); + } + if (settings.m_rollupState && channelSettingsKeys.contains("rollupState")) { + settings.m_rollupState->updateFrom(channelSettingsKeys, response.getPSK31DemodSettings()->getRollupState()); + } +} + +void PSK31Demod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const PSK31DemodSettings& settings) +{ + response.getPSK31DemodSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset); + response.getPSK31DemodSettings()->setRfBandwidth(settings.m_rfBandwidth); + response.getPSK31DemodSettings()->setUdpEnabled(settings.m_udpEnabled); + if (response.getPSK31DemodSettings()->getUdpAddress()) { + *response.getPSK31DemodSettings()->getUdpAddress() = settings.m_udpAddress; + } else { + response.getPSK31DemodSettings()->setUdpAddress(new QString(settings.m_udpAddress)); + } + response.getPSK31DemodSettings()->setUdpPort(settings.m_udpPort); + if (response.getPSK31DemodSettings()->getLogFilename()) { + *response.getPSK31DemodSettings()->getLogFilename() = settings.m_logFilename; + } else { + response.getPSK31DemodSettings()->setLogFilename(new QString(settings.m_logFilename)); + } + response.getPSK31DemodSettings()->setLogEnabled(settings.m_logEnabled); + + response.getPSK31DemodSettings()->setRgbColor(settings.m_rgbColor); + if (response.getPSK31DemodSettings()->getTitle()) { + *response.getPSK31DemodSettings()->getTitle() = settings.m_title; + } else { + response.getPSK31DemodSettings()->setTitle(new QString(settings.m_title)); + } + + response.getPSK31DemodSettings()->setStreamIndex(settings.m_streamIndex); + response.getPSK31DemodSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); + + if (response.getPSK31DemodSettings()->getReverseApiAddress()) { + *response.getPSK31DemodSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; + } else { + response.getPSK31DemodSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); + } + + response.getPSK31DemodSettings()->setReverseApiPort(settings.m_reverseAPIPort); + response.getPSK31DemodSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); + response.getPSK31DemodSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex); + + if (settings.m_scopeGUI) + { + if (response.getPSK31DemodSettings()->getScopeConfig()) + { + settings.m_scopeGUI->formatTo(response.getPSK31DemodSettings()->getScopeConfig()); + } + else + { + SWGSDRangel::SWGGLScope *swgGLScope = new SWGSDRangel::SWGGLScope(); + settings.m_scopeGUI->formatTo(swgGLScope); + response.getPSK31DemodSettings()->setScopeConfig(swgGLScope); + } + } + if (settings.m_channelMarker) + { + if (response.getPSK31DemodSettings()->getChannelMarker()) + { + settings.m_channelMarker->formatTo(response.getPSK31DemodSettings()->getChannelMarker()); + } + else + { + SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + settings.m_channelMarker->formatTo(swgChannelMarker); + response.getPSK31DemodSettings()->setChannelMarker(swgChannelMarker); + } + } + + if (settings.m_rollupState) + { + if (response.getPSK31DemodSettings()->getRollupState()) + { + settings.m_rollupState->formatTo(response.getPSK31DemodSettings()->getRollupState()); + } + else + { + SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + settings.m_rollupState->formatTo(swgRollupState); + response.getPSK31DemodSettings()->setRollupState(swgRollupState); + } + } +} + +void PSK31Demod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) +{ + double magsqAvg, magsqPeak; + int nbMagsqSamples; + getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples); + + response.getPSK31DemodReport()->setChannelPowerDb(CalcDb::dbPower(magsqAvg)); + response.getPSK31DemodReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate()); + response.getPSK31DemodReport()->setFrequencyOffset(getFrequencyOffset()); + response.getPSK31DemodReport()->setSnr(getSNR()); + response.getPSK31DemodReport()->setLocked(isLocked() ? 1 : 0); +} + +void PSK31Demod::webapiReverseSendSettings(const QList& channelSettingsKeys, const PSK31DemodSettings& settings, bool force) +{ + SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); + + QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings") + .arg(settings.m_reverseAPIAddress) + .arg(settings.m_reverseAPIPort) + .arg(settings.m_reverseAPIDeviceIndex) + .arg(settings.m_reverseAPIChannelIndex); + m_networkRequest.setUrl(QUrl(channelSettingsURL)); + m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + + QBuffer *buffer = new QBuffer(); + buffer->open((QBuffer::ReadWrite)); + buffer->write(swgChannelSettings->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 swgChannelSettings; +} + +void PSK31Demod::webapiFormatChannelSettings( + const QList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings *swgChannelSettings, + const PSK31DemodSettings& settings, + bool force +) +{ + swgChannelSettings->setDirection(0); // Single sink (Rx) + swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); + swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex()); + if (swgChannelSettings->getChannelType()) { + *swgChannelSettings->getChannelType() = "PSK31Demod"; + } else { + swgChannelSettings->setChannelType(new QString("PSK31Demod")); + } + swgChannelSettings->setPSK31DemodSettings(new SWGSDRangel::SWGPSK31DemodSettings()); + SWGSDRangel::SWGPSK31DemodSettings *swgPSK31DemodSettings = swgChannelSettings->getPSK31DemodSettings(); + + // transfer data that has been modified. When force is on transfer all data except reverse API data + + if (channelSettingsKeys.contains("inputFrequencyOffset") || force) { + swgPSK31DemodSettings->setInputFrequencyOffset(settings.m_inputFrequencyOffset); + } + if (channelSettingsKeys.contains("rfBandwidth") || force) { + swgPSK31DemodSettings->setRfBandwidth(settings.m_rfBandwidth); + } + if (channelSettingsKeys.contains("udpEnabled") || force) { + swgPSK31DemodSettings->setUdpEnabled(settings.m_udpEnabled); + } + if (channelSettingsKeys.contains("udpAddress") || force) { + if (swgPSK31DemodSettings->getUdpAddress()) { + *swgPSK31DemodSettings->getUdpAddress() = settings.m_udpAddress; + } else { + swgPSK31DemodSettings->setUdpAddress(new QString(settings.m_udpAddress)); + } + } + if (channelSettingsKeys.contains("udpPort") || force) { + swgPSK31DemodSettings->setUdpPort(settings.m_udpPort); + } + if (channelSettingsKeys.contains("logFilename") || force) { + if (swgPSK31DemodSettings->getLogFilename()) { + *swgPSK31DemodSettings->getLogFilename() = settings.m_logFilename; + } else { + swgPSK31DemodSettings->setLogFilename(new QString(settings.m_logFilename)); + } + } + if (channelSettingsKeys.contains("logEnabled") || force) { + swgPSK31DemodSettings->setLogEnabled(settings.m_logEnabled); + } + if (channelSettingsKeys.contains("rgbColor") || force) { + swgPSK31DemodSettings->setRgbColor(settings.m_rgbColor); + } + if (channelSettingsKeys.contains("title") || force) { + if (swgPSK31DemodSettings->getTitle()) { + *swgPSK31DemodSettings->getTitle() = settings.m_title; + } else { + swgPSK31DemodSettings->setTitle(new QString(settings.m_title)); + } + } + if (channelSettingsKeys.contains("streamIndex") || force) { + swgPSK31DemodSettings->setStreamIndex(settings.m_streamIndex); + } + + if (settings.m_scopeGUI && (channelSettingsKeys.contains("scopeConfig") || force)) + { + SWGSDRangel::SWGGLScope *swgGLScope = new SWGSDRangel::SWGGLScope(); + settings.m_scopeGUI->formatTo(swgGLScope); + swgPSK31DemodSettings->setScopeConfig(swgGLScope); + } + + if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) + { + SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + settings.m_channelMarker->formatTo(swgChannelMarker); + swgPSK31DemodSettings->setChannelMarker(swgChannelMarker); + } + + if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) + { + SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + settings.m_rollupState->formatTo(swgRollupState); + swgPSK31DemodSettings->setRollupState(swgRollupState); + } +} + +void PSK31Demod::networkManagerFinished(QNetworkReply *reply) +{ + QNetworkReply::NetworkError replyError = reply->error(); + + if (replyError) + { + qWarning() << "PSK31Demod::networkManagerFinished:" + << " error(" << (int) replyError + << "): " << replyError + << ": " << reply->errorString(); + } + else + { + QString answer = reply->readAll(); + answer.chop(1); // remove last \n + qDebug("PSK31Demod::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); + } + + reply->deleteLater(); +} + +void PSK31Demod::handleIndexInDeviceSetChanged(int index) +{ + if (index < 0) { + return; + } + + QString fifoLabel = QString("%1 [%2:%3]") + .arg(m_channelId) + .arg(m_deviceAPI->getDeviceSetIndex()) + .arg(index); + m_basebandSink->setFifoLabel(fifoLabel); +} diff --git a/plugins/channelrx/demodpsk31/psk31demod.h b/plugins/channelrx/demodpsk31/psk31demod.h new file mode 100644 index 000000000..4675103ce --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demod.h @@ -0,0 +1,223 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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_PSK31DEMOD_H +#define INCLUDE_PSK31DEMOD_H + +#include +#include +#include +#include +#include + +#include "dsp/basebandsamplesink.h" +#include "channel/channelapi.h" +#include "util/message.h" + +#include "psk31demodbaseband.h" +#include "psk31demodsettings.h" + +class QNetworkAccessManager; +class QNetworkReply; +class QThread; +class DeviceAPI; +class ScopeVis; + +class PSK31Demod : public BasebandSampleSink, public ChannelAPI { +public: + class MsgConfigurePSK31Demod : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const PSK31DemodSettings& getSettings() const { return m_settings; } + const QStringList& getSettingsKeys() const { return m_settingsKeys; } + bool getForce() const { return m_force; } + + static MsgConfigurePSK31Demod* create(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force) + { + return new MsgConfigurePSK31Demod(settingsKeys, settings, force); + } + + private: + PSK31DemodSettings m_settings; + QStringList m_settingsKeys; + bool m_force; + + MsgConfigurePSK31Demod(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force) : + Message(), + m_settings(settings), + m_settingsKeys(settingsKeys), + m_force(force) + { } + }; + + // Sent from Sink when character is decoded + class MsgCharacter : public Message { + MESSAGE_CLASS_DECLARATION + + public: + QString getCharacter() const { return m_character; } + + static MsgCharacter* create(const QString& character) + { + return new MsgCharacter(character); + } + + private: + QString m_character; + + MsgCharacter(const QString& character) : + m_character(character) + {} + }; + + class MsgDemodReport : public Message { + MESSAGE_CLASS_DECLARATION + + public: + float getFrequencyOffset() const { return m_frequencyOffset; } + float getSNR() const { return m_snr; } + bool isLocked() const { return m_locked; } + + static MsgDemodReport* create(float frequencyOffset, float snr, bool locked) + { + return new MsgDemodReport(frequencyOffset, snr, locked); + } + + private: + float m_frequencyOffset; + float m_snr; + bool m_locked; + + MsgDemodReport(float frequencyOffset, float snr, bool locked) : + m_frequencyOffset(frequencyOffset), + m_snr(snr), + m_locked(locked) + {} + }; + + PSK31Demod(DeviceAPI *deviceAPI); + virtual ~PSK31Demod(); + virtual void destroy() { delete this; } + virtual void setDeviceAPI(DeviceAPI *deviceAPI); + virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; } + + using BasebandSampleSink::feed; + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po); + virtual void start(); + virtual void stop(); + virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); } + virtual QString getSinkName() { return objectName(); } + + virtual void getIdentifier(QString& id) { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } + virtual const QString& getURI() const { return getName(); } + virtual void getTitle(QString& title) { title = m_settings.m_title; } + virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } + virtual void setCenterFrequency(qint64 frequency); + + virtual QByteArray serialize() const; + virtual bool deserialize(const QByteArray& data); + + virtual int getNbSinkStreams() const { return 1; } + virtual int getNbSourceStreams() const { return 0; } + virtual int getStreamIndex() const { return m_settings.m_streamIndex; } + + virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + { + (void) streamIndex; + (void) sinkElseSource; + return 0; + } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiWorkspaceGet( + SWGSDRangel::SWGWorkspaceInfo& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiReportGet( + SWGSDRangel::SWGChannelReport& response, + QString& errorMessage); + + static void webapiFormatChannelSettings( + SWGSDRangel::SWGChannelSettings& response, + const PSK31DemodSettings& settings); + + static void webapiUpdateChannelSettings( + PSK31DemodSettings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response); + + ScopeVis *getScopeSink(); + double getMagSq() const { return m_basebandSink->getMagSq(); } + float getFrequencyOffset() const { return m_basebandSink->getFrequencyOffset(); } + float getSNR() const { return m_basebandSink->getSNR(); } + bool isLocked() const { return m_basebandSink->isLocked(); } + + void getMagSqLevels(double& avg, double& peak, int& nbSamples) { + m_basebandSink->getMagSqLevels(avg, peak, nbSamples); + } + + uint32_t getNumberOfDeviceStreams() const; + + static const char * const m_channelIdURI; + static const char * const m_channelId; + +private: + DeviceAPI *m_deviceAPI; + QThread m_thread; + PSK31DemodBaseband* m_basebandSink; + PSK31DemodSettings m_settings; + int m_basebandSampleRate; //!< stored from device message used when starting baseband sink + qint64 m_centerFrequency; + QUdpSocket m_udpSocket; + QFile m_logFile; + QTextStream m_logStream; + + QNetworkAccessManager *m_networkManager; + QNetworkRequest m_networkRequest; + + virtual bool handleMessage(const Message& cmd); + void applySettings(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force = false); + void sendSampleRateToDemodAnalyzer(); + void webapiReverseSendSettings(const QList& channelSettingsKeys, const PSK31DemodSettings& settings, bool force); + void webapiFormatChannelSettings( + const QList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings *swgChannelSettings, + const PSK31DemodSettings& settings, + bool force + ); + void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response); + +private slots: + void networkManagerFinished(QNetworkReply *reply); + void handleIndexInDeviceSetChanged(int index); + +}; + +#endif // INCLUDE_PSK31DEMOD_H diff --git a/plugins/channelrx/demodpsk31/psk31demodbaseband.cpp b/plugins/channelrx/demodpsk31/psk31demodbaseband.cpp new file mode 100644 index 000000000..431a82367 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodbaseband.cpp @@ -0,0 +1,180 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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/dspcommands.h" +#include "dsp/downchannelizer.h" + +#include "psk31demodbaseband.h" + +MESSAGE_CLASS_DEFINITION(PSK31DemodBaseband::MsgConfigurePSK31DemodBaseband, Message) + +PSK31DemodBaseband::PSK31DemodBaseband() : + m_running(false) +{ + qDebug("PSK31DemodBaseband::PSK31DemodBaseband"); + + m_sink.setScopeSink(&m_scopeSink); + m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(48000)); + m_channelizer = new DownChannelizer(&m_sink); +} + +PSK31DemodBaseband::~PSK31DemodBaseband() +{ + m_inputMessageQueue.clear(); + + delete m_channelizer; +} + +void PSK31DemodBaseband::reset() +{ + QMutexLocker mutexLocker(&m_mutex); + m_inputMessageQueue.clear(); + m_sampleFifo.reset(); +} + +void PSK31DemodBaseband::startWork() +{ + QMutexLocker mutexLocker(&m_mutex); + QObject::connect( + &m_sampleFifo, + &SampleSinkFifo::dataReady, + this, + &PSK31DemodBaseband::handleData, + Qt::QueuedConnection + ); + connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + m_running = true; +} + +void PSK31DemodBaseband::stopWork() +{ + QMutexLocker mutexLocker(&m_mutex); + disconnect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + QObject::disconnect( + &m_sampleFifo, + &SampleSinkFifo::dataReady, + this, + &PSK31DemodBaseband::handleData + ); + m_running = false; +} + +void PSK31DemodBaseband::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) +{ + m_sampleFifo.write(begin, end); +} + +void PSK31DemodBaseband::handleData() +{ + QMutexLocker mutexLocker(&m_mutex); + + while ((m_sampleFifo.fill() > 0) && (m_inputMessageQueue.size() == 0) && m_channelizer->getBasebandSampleRate()) + { + SampleVector::iterator part1begin; + SampleVector::iterator part1end; + SampleVector::iterator part2begin; + SampleVector::iterator part2end; + + std::size_t count = m_sampleFifo.readBegin(m_sampleFifo.fill(), &part1begin, &part1end, &part2begin, &part2end); + + // first part of FIFO data + if (part1begin != part1end) { + m_channelizer->feed(part1begin, part1end); + } + + // second part of FIFO data (used when block wraps around) + if(part2begin != part2end) { + m_channelizer->feed(part2begin, part2end); + } + + m_sampleFifo.readCommit((unsigned int) count); + } +} + +void PSK31DemodBaseband::handleInputMessages() +{ + Message* message; + + while ((message = m_inputMessageQueue.pop())) + { + if (!handleMessage(*message)) { + qDebug("%s: unhandled message: %s", Q_FUNC_INFO, message->getIdentifier()); + } + delete message; + } +} + +bool PSK31DemodBaseband::handleMessage(const Message& cmd) +{ + if (MsgConfigurePSK31DemodBaseband::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + MsgConfigurePSK31DemodBaseband& cfg = (MsgConfigurePSK31DemodBaseband&) cmd; + qDebug() << "PSK31DemodBaseband::handleMessage: MsgConfigurePSK31DemodBaseband"; + + applySettings(cfg.getSettingsKeys(), cfg.getSettings(), cfg.getForce()); + + return true; + } + else if (DSPSignalNotification::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + qDebug() << "PSK31DemodBaseband::handleMessage: DSPSignalNotification: basebandSampleRate: " << notif.getSampleRate(); + setBasebandSampleRate(notif.getSampleRate()); + // We can run with very slow sample rate (E.g. 4k), but we don't want FIFO getting too small + m_sampleFifo.setSize(SampleSinkFifo::getSizePolicy(std::max(notif.getSampleRate(), 48000))); + + return true; + } + else + { + return false; + } +} + +void PSK31DemodBaseband::applySettings(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force) +{ + if ((settingsKeys.contains("inputFrequencyOffset") && (settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset)) || force) + { + m_channelizer->setChannelization(PSK31DemodSettings::PSK31DEMOD_CHANNEL_SAMPLE_RATE, settings.m_inputFrequencyOffset); + m_sink.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset()); + } + + m_sink.applySettings(settingsKeys, settings, force); + + if (force) { + m_settings = settings; + } else { + m_settings.applySettings(settingsKeys, settings); + } +} + +int PSK31DemodBaseband::getChannelSampleRate() const +{ + return m_channelizer->getChannelSampleRate(); +} + +void PSK31DemodBaseband::setBasebandSampleRate(int sampleRate) +{ + m_channelizer->setBasebandSampleRate(sampleRate); + m_sink.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset()); +} diff --git a/plugins/channelrx/demodpsk31/psk31demodbaseband.h b/plugins/channelrx/demodpsk31/psk31demodbaseband.h new file mode 100644 index 000000000..0b84214e0 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodbaseband.h @@ -0,0 +1,105 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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_PSK31DEMODBASEBAND_H +#define INCLUDE_PSK31DEMODBASEBAND_H + +#include +#include + +#include "dsp/samplesinkfifo.h" +#include "dsp/scopevis.h" +#include "util/message.h" +#include "util/messagequeue.h" + +#include "psk31demodsink.h" + +class DownChannelizer; +class ScopeVis; + +class PSK31DemodBaseband : public QObject +{ + Q_OBJECT +public: + class MsgConfigurePSK31DemodBaseband : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const PSK31DemodSettings& getSettings() const { return m_settings; } + const QStringList& getSettingsKeys() const { return m_settingsKeys; } + bool getForce() const { return m_force; } + + static MsgConfigurePSK31DemodBaseband* create(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force) + { + return new MsgConfigurePSK31DemodBaseband(settingsKeys, settings, force); + } + + private: + PSK31DemodSettings m_settings; + QStringList m_settingsKeys; + bool m_force; + + MsgConfigurePSK31DemodBaseband(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force) : + Message(), + m_settings(settings), + m_settingsKeys(settingsKeys), + m_force(force) + { } + }; + + PSK31DemodBaseband(); + ~PSK31DemodBaseband(); + void reset(); + void startWork(); + void stopWork(); + void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end); + MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication + void getMagSqLevels(double& avg, double& peak, int& nbSamples) { + m_sink.getMagSqLevels(avg, peak, nbSamples); + } + void setMessageQueueToChannel(MessageQueue *messageQueue) { m_sink.setMessageQueueToChannel(messageQueue); } + void setBasebandSampleRate(int sampleRate); + int getChannelSampleRate() const; + ScopeVis *getScopeSink() { return &m_scopeSink; } + double getMagSq() const { return m_sink.getMagSq(); } + float getFrequencyOffset() const { return m_sink.getFrequencyOffset(); } + float getSNR() const { return m_sink.getSNR(); } + bool isLocked() const { return m_sink.isLocked(); } + bool isRunning() const { return m_running; } + void setFifoLabel(const QString& label) { m_sampleFifo.setLabel(label); } + +private: + SampleSinkFifo m_sampleFifo; + DownChannelizer *m_channelizer; + PSK31DemodSink m_sink; + MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication + PSK31DemodSettings m_settings; + ScopeVis m_scopeSink; + bool m_running; + QRecursiveMutex m_mutex; + + bool handleMessage(const Message& cmd); + void applySettings(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force = false); + +private slots: + void handleInputMessages(); + void handleData(); //!< Handle data when samples have to be processed +}; + +#endif // INCLUDE_PSK31DEMODBASEBAND_H diff --git a/plugins/channelrx/demodpsk31/psk31demodgui.cpp b/plugins/channelrx/demodpsk31/psk31demodgui.cpp new file mode 100644 index 000000000..d05e7f403 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodgui.cpp @@ -0,0 +1,521 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 "psk31demodgui.h" + +#include "device/deviceuiset.h" +#include "dsp/dspengine.h" +#include "dsp/dspcommands.h" +#include "ui_psk31demodgui.h" +#include "plugin/pluginapi.h" +#include "util/db.h" +#include "util/rtty.h" +#include "gui/basicchannelsettingsdialog.h" +#include "dsp/dspengine.h" +#include "dsp/glscopesettings.h" +#include "gui/dialogpositioner.h" +#include "maincore.h" + +#include "psk31demod.h" + +PSK31DemodGUI* PSK31DemodGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel) +{ + PSK31DemodGUI* gui = new PSK31DemodGUI(pluginAPI, deviceUISet, rxChannel); + return gui; +} + +void PSK31DemodGUI::destroy() +{ + delete this; +} + +void PSK31DemodGUI::resetToDefaults() +{ + m_settings.resetToDefaults(); + displaySettings(); + applySettings(QStringList({"streamIndex"}), true); +} + +QByteArray PSK31DemodGUI::serialize() const +{ + return m_settings.serialize(); +} + +bool PSK31DemodGUI::deserialize(const QByteArray& data) +{ + if(m_settings.deserialize(data)) { + displaySettings(); + applySettings(QStringList({"streamIndex"}), true); + return true; + } else { + resetToDefaults(); + return false; + } +} + +void PSK31DemodGUI::characterReceived(QString c) +{ + // Is the scroll bar at the bottom? + int scrollPos = ui->text->verticalScrollBar()->value(); + bool atBottom = scrollPos >= ui->text->verticalScrollBar()->maximum(); + + // Move cursor to end where we want to append new text + // (user may have moved it by clicking / highlighting text) + ui->text->moveCursor(QTextCursor::End); + + // Restore scroll position + ui->text->verticalScrollBar()->setValue(scrollPos); + + if (c == '\b') + { + ui->text->textCursor().deletePreviousChar(); + } + else + { + ui->text->insertPlainText(c); + } + + // Scroll to bottom, if we we're previously at the bottom + if (atBottom) { + ui->text->verticalScrollBar()->setValue(ui->text->verticalScrollBar()->maximum()); + } + +} + +bool PSK31DemodGUI::handleMessage(const Message& message) +{ + if (PSK31Demod::MsgConfigurePSK31Demod::match(message)) + { + qDebug("PSK31DemodGUI::handleMessage: PSK31Demod::MsgConfigurePSK31Demod"); + const PSK31Demod::MsgConfigurePSK31Demod& cfg = (PSK31Demod::MsgConfigurePSK31Demod&) message; + m_settings = cfg.getSettings(); + blockApplySettings(true); + ui->scopeGUI->updateSettings(); + m_channelMarker.updateSettings(static_cast(m_settings.m_channelMarker)); + displaySettings(); + blockApplySettings(false); + return true; + } + else if (DSPSignalNotification::match(message)) + { + DSPSignalNotification& notif = (DSPSignalNotification&) message; + m_deviceCenterFrequency = notif.getCenterFrequency(); + m_basebandSampleRate = notif.getSampleRate(); + ui->deltaFrequency->setValueRange(false, 7, -m_basebandSampleRate/2, m_basebandSampleRate/2); + ui->deltaFrequencyLabel->setToolTip(tr("Range %1 %L2 Hz").arg(QChar(0xB1)).arg(m_basebandSampleRate/2)); + updateAbsoluteCenterFrequency(); + return true; + } + else if (PSK31Demod::MsgCharacter::match(message)) + { + PSK31Demod::MsgCharacter& report = (PSK31Demod::MsgCharacter&) message; + QString c = report.getCharacter(); + characterReceived(c); + return true; + } + else if (PSK31Demod::MsgDemodReport::match(message)) + { + PSK31Demod::MsgDemodReport& report = (PSK31Demod::MsgDemodReport&) message; + const QString status = report.isLocked() ? tr("Locked") : tr("Unlocked"); + + if (report.isLocked()) + { + const QString offsetValue = QStringLiteral("%1%2 Hz") + .arg(report.getFrequencyOffset() >= 0.0f ? QStringLiteral("+") : QString()) + .arg(report.getFrequencyOffset(), 0, 'f', 1); + const QString offset = tr("Frequency offset: %1 Hz") + .arg(report.getFrequencyOffset(), 0, 'f', 1); + const QString snrValue = tr("%1 dB SNR").arg(report.getSNR(), 0, 'f', 1); + const QString snr = tr("SNR: %1 dB").arg(report.getSNR(), 0, 'f', 1); + ui->carrierStatus->setText(tr("%1 %2 %3").arg(status, offsetValue, snrValue)); + ui->carrierStatus->setToolTip(tr("%1\n%2").arg(offset, snr)); + ui->channelPower->setToolTip(tr("Carrier: %1\n%2\n%3").arg(status, offset, snr)); + } + else + { + ui->carrierStatus->setText(status); + ui->carrierStatus->setToolTip(status); + ui->channelPower->setToolTip(tr("Carrier: %1").arg(status)); + } + + return true; + } + + return false; +} + +void PSK31DemodGUI::handleInputMessages() +{ + Message* message; + + while ((message = getInputMessageQueue()->pop())) + { + if (!handleMessage(*message)) { + qDebug("%s: unhandled message: %s", Q_FUNC_INFO, message->getIdentifier()); + } + delete message; + } +} + +void PSK31DemodGUI::channelMarkerChangedByCursor() +{ + ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); + m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); + applySettings(QStringList({"inputFrequencyOffset"})); +} + +void PSK31DemodGUI::channelMarkerHighlightedByCursor() +{ + setHighlighted(m_channelMarker.getHighlighted()); +} + +void PSK31DemodGUI::on_deltaFrequency_changed(qint64 value) +{ + m_channelMarker.setCenterFrequency(value); + m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); + updateAbsoluteCenterFrequency(); + applySettings(QStringList({"inputFrequencyOffset"})); +} + +void PSK31DemodGUI::on_rfBW_valueChanged(int value) +{ + float bw = value; + ui->rfBWText->setText(formatFrequency((int)bw)); + m_channelMarker.setBandwidth(bw); + m_settings.m_rfBandwidth = bw; + applySettings(QStringList({"rfBandwidth"})); +} + +void PSK31DemodGUI::on_clearTable_clicked() +{ + ui->text->clear(); +} + +void PSK31DemodGUI::on_udpEnabled_clicked(bool checked) +{ + m_settings.m_udpEnabled = checked; + applySettings(QStringList({"udpEnabled"})); +} + +void PSK31DemodGUI::on_udpAddress_editingFinished() +{ + m_settings.m_udpAddress = ui->udpAddress->text(); + applySettings(QStringList({"udpAddress"})); +} + +void PSK31DemodGUI::on_udpPort_editingFinished() +{ + m_settings.m_udpPort = ui->udpPort->text().toInt(); + applySettings(QStringList({"udpPort"})); +} + +void PSK31DemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) +{ + (void) widget; + (void) rollDown; + + getRollupContents()->saveState(m_rollupState); + applySettings(QStringList()); +} + +void PSK31DemodGUI::onMenuDialogCalled(const QPoint &p) +{ + if (m_contextMenuType == ContextMenuType::ContextMenuChannelSettings) + { + BasicChannelSettingsDialog dialog(&m_channelMarker, this); + dialog.setUseReverseAPI(m_settings.m_useReverseAPI); + dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress); + dialog.setReverseAPIPort(m_settings.m_reverseAPIPort); + dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex); + dialog.setReverseAPIChannelIndex(m_settings.m_reverseAPIChannelIndex); + dialog.setDefaultTitle(m_displayedName); + + if (m_deviceUISet->m_deviceMIMOEngine) + { + dialog.setNumberOfStreams(m_psk31Demod->getNumberOfDeviceStreams()); + dialog.setStreamIndex(m_settings.m_streamIndex); + } + + dialog.move(p); + new DialogPositioner(&dialog, false); + dialog.exec(); + + m_settings.m_rgbColor = m_channelMarker.getColor().rgb(); + m_settings.m_title = m_channelMarker.getTitle(); + m_settings.m_useReverseAPI = dialog.useReverseAPI(); + m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress(); + m_settings.m_reverseAPIPort = dialog.getReverseAPIPort(); + m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex(); + m_settings.m_reverseAPIChannelIndex = dialog.getReverseAPIChannelIndex(); + + setWindowTitle(m_settings.m_title); + setTitle(m_channelMarker.getTitle()); + setTitleColor(m_settings.m_rgbColor); + + if (m_deviceUISet->m_deviceMIMOEngine) + { + m_settings.m_streamIndex = dialog.getSelectedStreamIndex(); + m_channelMarker.clearStreamIndexes(); + m_channelMarker.addStreamIndex(m_settings.m_streamIndex); + updateIndexLabel(); + } + + applySettings(QStringList({ + "rgbColor", + "title", + "useReverseAPI", + "reverseAPIAddress", + "reverseAPIPort", + "reverseAPIDeviceIndex", + "reverseAPIChannelIndex", + "streamIndex" + })); + } + + resetContextMenuType(); +} + +PSK31DemodGUI::PSK31DemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent) : + ChannelGUI(parent), + ui(new Ui::PSK31DemodGUI), + m_pluginAPI(pluginAPI), + m_deviceUISet(deviceUISet), + m_channelMarker(this), + m_deviceCenterFrequency(0), + m_doApplySettings(true), + m_tickCount(0) +{ + setAttribute(Qt::WA_DeleteOnClose, true); + m_helpURL = "plugins/channelrx/demodpsk31/readme.md"; + RollupContents *rollupContents = getRollupContents(); + ui->setupUi(rollupContents); + setSizePolicy(rollupContents->sizePolicy()); + rollupContents->arrangeRollups(); + connect(rollupContents, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); + + m_psk31Demod = reinterpret_cast(rxChannel); + m_psk31Demod->setMessageQueueToGUI(getInputMessageQueue()); + + connect(&MainCore::instance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); // 50 ms + + ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); + ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); + ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999); + ui->channelPowerMeter->setColorTheme(LevelMeterSignalDB::ColorGreenAndBlue); + + m_scopeVis = m_psk31Demod->getScopeSink(); + m_scopeVis->setGLScope(ui->glScope); + ui->glScope->connectTimer(MainCore::instance()->getMasterTimer()); + ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope); + + // Scope settings to display the IQ waveforms + ui->scopeGUI->setPreTrigger(1); + GLScopeSettings::TraceData traceDataI, traceDataQ; + traceDataI.m_projectionType = Projector::ProjectionReal; + traceDataI.m_amp = 1.0; // for -1 to +1 + traceDataI.m_ofs = 0.0; // vertical offset + traceDataQ.m_projectionType = Projector::ProjectionImag; + traceDataQ.m_amp = 1.0; + traceDataQ.m_ofs = 0.0; + ui->scopeGUI->changeTrace(0, traceDataI); + ui->scopeGUI->addTrace(traceDataQ); + ui->scopeGUI->setDisplayMode(GLScopeSettings::DisplayXYV); + ui->scopeGUI->focusOnTrace(0); // re-focus to take changes into account in the GUI + + GLScopeSettings::TriggerData triggerData; + triggerData.m_triggerLevel = 0.1; + triggerData.m_triggerLevelCoarse = 10; + triggerData.m_triggerPositiveEdge = true; + ui->scopeGUI->changeTrigger(0, triggerData); + ui->scopeGUI->focusOnTrigger(0); // re-focus to take changes into account in the GUI + + m_scopeVis->setLiveRate(PSK31DemodSettings::PSK31DEMOD_CHANNEL_SAMPLE_RATE); + m_scopeVis->configure(500, 1, 0, 0, true); + + m_channelMarker.blockSignals(true); + m_channelMarker.setColor(QColor(25, 180, 200)); + m_channelMarker.setBandwidth(m_settings.m_rfBandwidth); + m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); + m_channelMarker.setTitle("PSK31 Demodulator"); + m_channelMarker.blockSignals(false); + m_channelMarker.setVisible(true); // activate signal on the last setting only + + setTitleColor(m_channelMarker.getColor()); + m_settings.setChannelMarker(&m_channelMarker); + m_settings.setScopeGUI(ui->scopeGUI); + m_settings.setRollupState(&m_rollupState); + + m_deviceUISet->addChannelMarker(&m_channelMarker); + + connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor())); + connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor())); + connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + + ui->scopeContainer->setVisible(false); + + ui->carrierStatusLabel->setText(tr("Carrier")); + ui->carrierStatus->setText(tr("Unlocked")); + ui->carrierStatus->setToolTip(tr("Unlocked")); + + ui->text->addAcronyms(Rtty::m_acronyms); + + displaySettings(); + makeUIConnections(); + applySettings(QStringList(), true); + m_resizer.enableChildMouseTracking(); +} + +PSK31DemodGUI::~PSK31DemodGUI() +{ + delete ui; +} + +void PSK31DemodGUI::blockApplySettings(bool block) +{ + m_doApplySettings = !block; +} + +void PSK31DemodGUI::applySettings(const QStringList& settingsKeys, bool force) +{ + if (m_doApplySettings) + { + PSK31Demod::MsgConfigurePSK31Demod* message = PSK31Demod::MsgConfigurePSK31Demod::create(settingsKeys, m_settings, force); + m_psk31Demod->getInputMessageQueue()->push(message); + } +} + +QString PSK31DemodGUI::formatFrequency(int frequency) const +{ + return QString("%1 Hz").arg(frequency); +} + +void PSK31DemodGUI::displaySettings() +{ + m_channelMarker.blockSignals(true); + m_channelMarker.setBandwidth(m_settings.m_rfBandwidth); + m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); + m_channelMarker.setTitle(m_settings.m_title); + m_channelMarker.blockSignals(false); + m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only + + setTitleColor(m_settings.m_rgbColor); + setWindowTitle(m_channelMarker.getTitle()); + setTitle(m_channelMarker.getTitle()); + + blockApplySettings(true); + + ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); + + ui->rfBWText->setText(formatFrequency((int)m_settings.m_rfBandwidth)); + ui->rfBW->setValue(m_settings.m_rfBandwidth); + + updateIndexLabel(); + + ui->udpEnabled->setChecked(m_settings.m_udpEnabled); + ui->udpAddress->setText(m_settings.m_udpAddress); + ui->udpPort->setText(QString::number(m_settings.m_udpPort)); + + ui->logFilename->setToolTip(QString(".txt log filename: %1").arg(m_settings.m_logFilename)); + ui->logEnable->setChecked(m_settings.m_logEnabled); + + getRollupContents()->restoreState(m_rollupState); + updateAbsoluteCenterFrequency(); + blockApplySettings(false); +} + +void PSK31DemodGUI::leaveEvent(QEvent* event) +{ + m_channelMarker.setHighlighted(false); + ChannelGUI::leaveEvent(event); +} + +void PSK31DemodGUI::enterEvent(EnterEventType* event) +{ + m_channelMarker.setHighlighted(true); + ChannelGUI::enterEvent(event); +} + +void PSK31DemodGUI::tick() +{ + double magsqAvg, magsqPeak; + int nbMagsqSamples; + m_psk31Demod->getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples); + double powDbAvg = CalcDb::dbPower(magsqAvg); + double powDbPeak = CalcDb::dbPower(magsqPeak); + ui->channelPowerMeter->levelChanged( + (100.0f + powDbAvg) / 100.0f, + (100.0f + powDbPeak) / 100.0f, + nbMagsqSamples); + + if (m_tickCount % 4 == 0) { + ui->channelPower->setText(QString::number(powDbAvg, 'f', 1)); + } + + m_tickCount++; +} + +void PSK31DemodGUI::on_logEnable_clicked(bool checked) +{ + m_settings.m_logEnabled = checked; + applySettings(QStringList({"logEnabled"})); +} + +void PSK31DemodGUI::on_logFilename_clicked() +{ + // Get filename to save to + QFileDialog fileDialog(nullptr, "Select file to log received text to", "", "*.txt"); + fileDialog.setAcceptMode(QFileDialog::AcceptSave); + if (fileDialog.exec()) + { + QStringList fileNames = fileDialog.selectedFiles(); + if (fileNames.size() > 0) + { + m_settings.m_logFilename = fileNames[0]; + ui->logFilename->setToolTip(QString(".txt log filename: %1").arg(m_settings.m_logFilename)); + applySettings(QStringList({"logFilename"})); + } + } +} + +void PSK31DemodGUI::makeUIConnections() +{ + QObject::connect(ui->deltaFrequency, &ValueDialZ::changed, this, &PSK31DemodGUI::on_deltaFrequency_changed); + QObject::connect(ui->rfBW, &QSlider::valueChanged, this, &PSK31DemodGUI::on_rfBW_valueChanged); + QObject::connect(ui->clearTable, &QPushButton::clicked, this, &PSK31DemodGUI::on_clearTable_clicked); + QObject::connect(ui->udpEnabled, &QCheckBox::clicked, this, &PSK31DemodGUI::on_udpEnabled_clicked); + QObject::connect(ui->udpAddress, &QLineEdit::editingFinished, this, &PSK31DemodGUI::on_udpAddress_editingFinished); + QObject::connect(ui->udpPort, &QLineEdit::editingFinished, this, &PSK31DemodGUI::on_udpPort_editingFinished); + QObject::connect(ui->logEnable, &ButtonSwitch::clicked, this, &PSK31DemodGUI::on_logEnable_clicked); + QObject::connect(ui->logFilename, &QToolButton::clicked, this, &PSK31DemodGUI::on_logFilename_clicked); +} + +void PSK31DemodGUI::updateAbsoluteCenterFrequency() +{ + setStatusFrequency(m_deviceCenterFrequency + m_settings.m_inputFrequencyOffset); +} diff --git a/plugins/channelrx/demodpsk31/psk31demodgui.h b/plugins/channelrx/demodpsk31/psk31demodgui.h new file mode 100644 index 000000000..4bef79fb7 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodgui.h @@ -0,0 +1,115 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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_PSK31DEMODGUI_H +#define INCLUDE_PSK31DEMODGUI_H + +#include "channel/channelgui.h" +#include "dsp/channelmarker.h" +#include "util/messagequeue.h" +#include "settings/rollupstate.h" +#include "psk31demod.h" +#include "psk31demodsettings.h" + +class PluginAPI; +class DeviceUISet; +class BasebandSampleSink; +class ScopeVis; +class PSK31Demod; +class PSK31DemodGUI; + +namespace Ui { + class PSK31DemodGUI; +} +class PSK31DemodGUI; + +class PSK31DemodGUI : public ChannelGUI { + Q_OBJECT + +public: + static PSK31DemodGUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel); + virtual void destroy(); + + void resetToDefaults(); + QByteArray serialize() const; + bool deserialize(const QByteArray& data); + virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } + virtual void setWorkspaceIndex(int index) { m_settings.m_workspaceIndex = index; }; + virtual int getWorkspaceIndex() const { return m_settings.m_workspaceIndex; }; + virtual void setGeometryBytes(const QByteArray& blob) { m_settings.m_geometryBytes = blob; }; + virtual QByteArray getGeometryBytes() const { return m_settings.m_geometryBytes; }; + virtual QString getTitle() const { return m_settings.m_title; }; + virtual QColor getTitleColor() const { return m_settings.m_rgbColor; }; + virtual void zetHidden(bool hidden) { m_settings.m_hidden = hidden; } + virtual bool getHidden() const { return m_settings.m_hidden; } + virtual ChannelMarker& getChannelMarker() { return m_channelMarker; } + virtual int getStreamIndex() const { return m_settings.m_streamIndex; } + virtual void setStreamIndex(int streamIndex) { m_settings.m_streamIndex = streamIndex; } + +public slots: + void channelMarkerChangedByCursor(); + void channelMarkerHighlightedByCursor(); + +private: + Ui::PSK31DemodGUI* ui; + PluginAPI* m_pluginAPI; + DeviceUISet* m_deviceUISet; + ChannelMarker m_channelMarker; + RollupState m_rollupState; + PSK31DemodSettings m_settings; + qint64 m_deviceCenterFrequency; + bool m_doApplySettings; + ScopeVis* m_scopeVis; + + PSK31Demod* m_psk31Demod; + int m_basebandSampleRate; + uint32_t m_tickCount; + MessageQueue m_inputMessageQueue; + + explicit PSK31DemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent = 0); + virtual ~PSK31DemodGUI(); + + void blockApplySettings(bool block); + void applySettings(const QStringList& settingsKeys, bool force = false); + void displaySettings(); + bool handleMessage(const Message& message); + void makeUIConnections(); + void updateAbsoluteCenterFrequency(); + QString formatFrequency(int frequency) const; + void characterReceived(QString c); + + void leaveEvent(QEvent*); + void enterEvent(EnterEventType*); + +private slots: + void on_deltaFrequency_changed(qint64 value); + void on_rfBW_valueChanged(int index); + void on_clearTable_clicked(); + void on_udpEnabled_clicked(bool checked); + void on_udpAddress_editingFinished(); + void on_udpPort_editingFinished(); + void on_logEnable_clicked(bool checked=false); + void on_logFilename_clicked(); + void onWidgetRolled(QWidget* widget, bool rollDown); + void onMenuDialogCalled(const QPoint& p); + void handleInputMessages(); + void tick(); +}; + +#endif // INCLUDE_PSK31DEMODGUI_H diff --git a/plugins/channelrx/demodpsk31/psk31demodgui.ui b/plugins/channelrx/demodpsk31/psk31demodgui.ui new file mode 100644 index 000000000..09b17e505 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodgui.ui @@ -0,0 +1,623 @@ + + + PSK31DemodGUI + + + + 0 + 0 + 411 + 814 + + + + + 0 + 0 + + + + + 352 + 0 + + + + + Liberation Sans + 9 + + + + Qt::FocusPolicy::StrongFocus + + + Packet Demodulator + + + + + 0 + 0 + 390 + 181 + + + + + 350 + 0 + + + + Settings + + + + 3 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + 2 + + + + + + 16 + 0 + + + + Df + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + Liberation Mono + 12 + + + + PointingHandCursor + + + Qt::FocusPolicy::StrongFocus + + + Demod shift frequency from center in Hz + + + + + + + Hz + + + + + + + Qt::Orientation::Vertical + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + Channel power + + + Qt::LayoutDirection::RightToLeft + + + 0.0 + + + + + + + dB + + + + + + + + + + + + + dB + + + + + + + + 0 + 0 + + + + + 0 + 24 + + + + + Liberation Mono + 8 + + + + Level meter (dB) top trace: average, bottom trace: instantaneous peak, tip: peak hold + + + + + + + + + Qt::Orientation::Horizontal + + + + + + + + + BW + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + RF bandwidth + + + 50 + + + 500 + + + 1 + + + 250 + + + Qt::Orientation::Horizontal + + + + + + + + 40 + 0 + + + + 500Hz + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + + + Qt::Orientation::Horizontal + + + + + + + + + Send messages via UDP + + + Qt::LayoutDirection::RightToLeft + + + UDP + + + + + + + + 120 + 0 + + + + Qt::FocusPolicy::ClickFocus + + + Destination UDP address + + + 000.000.000.000 + + + 127.0.0.1 + + + + + + + : + + + Qt::AlignmentFlag::AlignCenter + + + + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + Qt::FocusPolicy::ClickFocus + + + Destination UDP port + + + 00000 + + + 9998 + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Orientation::Horizontal + + + + + + + + + Carrier + + + + + + + Carrier status + + + Unlocked + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + 24 + 16777215 + + + + Start/stop logging of received characters to .txt file + + + + + + + :/record_off.png:/record_off.png + + + + + + + Set log .csv filename + + + ... + + + + :/save.png:/save.png + + + false + + + + + + + Clear messages + + + + + + + :/bin.png:/bin.png + + + + + + + + + + + 0 + 190 + 391 + 251 + + + + + 0 + 0 + + + + Received Messages + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Received text + + + true + + + + + + + + + 0 + 440 + 716 + 341 + + + + + 714 + 0 + + + + Waveforms + + + + 2 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 200 + 250 + + + + + Liberation Mono + 8 + + + + + + + + + + + + + RollupContents + QWidget +
gui/rollupcontents.h
+ 1 +
+ + ValueDialZ + QWidget +
gui/valuedialz.h
+ 1 +
+ + ButtonSwitch + QToolButton +
gui/buttonswitch.h
+
+ + LevelMeterSignalDB + QWidget +
gui/levelmeter.h
+ 1 +
+ + GLScope + QWidget +
gui/glscope.h
+ 1 +
+ + GLScopeGUI + QWidget +
gui/glscopegui.h
+ 1 +
+ + AcronymView + QTextEdit +
gui/acronymview.h
+ 1 +
+
+ + deltaFrequency + rfBW + udpEnabled + logEnable + logFilename + clearTable + text + + + + + +
diff --git a/plugins/channelrx/demodpsk31/psk31demodplugin.cpp b/plugins/channelrx/demodpsk31/psk31demodplugin.cpp new file mode 100644 index 000000000..f4c41f9c5 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodplugin.cpp @@ -0,0 +1,93 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 "psk31demodgui.h" +#endif +#include "psk31demod.h" +#include "psk31demodwebapiadapter.h" +#include "psk31demodplugin.h" + +const PluginDescriptor PSK31DemodPlugin::m_pluginDescriptor = { + PSK31Demod::m_channelId, + QStringLiteral("PSK31 Demodulator"), + QStringLiteral("7.28.0"), + QStringLiteral("(c) Jon Beniston, M7RCE"), + QStringLiteral("https://github.com/f4exb/sdrangel"), + true, + QStringLiteral("https://github.com/f4exb/sdrangel") +}; + +PSK31DemodPlugin::PSK31DemodPlugin(QObject* parent) : + QObject(parent), + m_pluginAPI(0) +{ +} + +const PluginDescriptor& PSK31DemodPlugin::getPluginDescriptor() const +{ + return m_pluginDescriptor; +} + +void PSK31DemodPlugin::initPlugin(PluginAPI* pluginAPI) +{ + m_pluginAPI = pluginAPI; + + m_pluginAPI->registerRxChannel(PSK31Demod::m_channelIdURI, PSK31Demod::m_channelId, this); +} + +void PSK31DemodPlugin::createRxChannel(DeviceAPI *deviceAPI, BasebandSampleSink **bs, ChannelAPI **cs) const +{ + if (bs || cs) + { + PSK31Demod *instance = new PSK31Demod(deviceAPI); + + if (bs) { + *bs = instance; + } + + if (cs) { + *cs = instance; + } + } +} + +#ifdef SERVER_MODE +ChannelGUI* PSK31DemodPlugin::createRxChannelGUI( + DeviceUISet *deviceUISet, + BasebandSampleSink *rxChannel) const +{ + (void) deviceUISet; + (void) rxChannel; + return 0; +} +#else +ChannelGUI* PSK31DemodPlugin::createRxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel) const +{ + return PSK31DemodGUI::create(m_pluginAPI, deviceUISet, rxChannel); +} +#endif + +ChannelWebAPIAdapter* PSK31DemodPlugin::createChannelWebAPIAdapter() const +{ + return new PSK31DemodWebAPIAdapter(); +} diff --git a/plugins/channelrx/demodpsk31/psk31demodplugin.h b/plugins/channelrx/demodpsk31/psk31demodplugin.h new file mode 100644 index 000000000..478b88124 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodplugin.h @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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_PSK31DEMODPLUGIN_H +#define INCLUDE_PSK31DEMODPLUGIN_H + +#include +#include "plugin/plugininterface.h" + +class DeviceUISet; +class BasebandSampleSink; + +class PSK31DemodPlugin : public QObject, PluginInterface { + Q_OBJECT + Q_INTERFACES(PluginInterface) + Q_PLUGIN_METADATA(IID "sdrangel.channel.psk31demod") + +public: + explicit PSK31DemodPlugin(QObject* parent = NULL); + + const PluginDescriptor& getPluginDescriptor() const; + void initPlugin(PluginAPI* pluginAPI); + + virtual void createRxChannel(DeviceAPI *deviceAPI, BasebandSampleSink **bs, ChannelAPI **cs) const; + virtual ChannelGUI* createRxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel) const; + virtual ChannelWebAPIAdapter* createChannelWebAPIAdapter() const; + +private: + static const PluginDescriptor m_pluginDescriptor; + + PluginAPI* m_pluginAPI; +}; + +#endif // INCLUDE_PSK31DEMODPLUGIN_H + diff --git a/plugins/channelrx/demodpsk31/psk31demodsettings.cpp b/plugins/channelrx/demodpsk31/psk31demodsettings.cpp new file mode 100644 index 000000000..59590a2ef --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodsettings.cpp @@ -0,0 +1,311 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 "util/simpleserializer.h" +#include "settings/serializable.h" +#include "psk31demodsettings.h" + +PSK31DemodSettings::PSK31DemodSettings() : + m_channelMarker(nullptr), + m_scopeGUI(nullptr), + m_rollupState(nullptr) +{ + resetToDefaults(); +} + +Real PSK31DemodSettings::validateRFBandwidth(Real rfBandwidth) +{ + if (!std::isfinite(rfBandwidth)) { + return 100.0f; + } + + return std::clamp( + rfBandwidth, + PSK31DEMOD_MIN_RF_BANDWIDTH, + PSK31DEMOD_MAX_RF_BANDWIDTH); +} + +void PSK31DemodSettings::resetToDefaults() +{ + m_inputFrequencyOffset = 0; + m_rfBandwidth = 100.0f; + m_udpEnabled = false; + m_udpAddress = "127.0.0.1"; + m_udpPort = 9999; + m_logFilename = "psk31_log.txt"; + m_logEnabled = false; + m_rgbColor = QColor(25, 180, 200).rgb(); + m_title = "PSK31 Demodulator"; + m_streamIndex = 0; + m_useReverseAPI = false; + m_reverseAPIAddress = "127.0.0.1"; + m_reverseAPIPort = 8888; + m_reverseAPIDeviceIndex = 0; + m_reverseAPIChannelIndex = 0; + m_workspaceIndex = 0; + m_hidden = false; +} + +QByteArray PSK31DemodSettings::serialize() const +{ + SimpleSerializer s(1); + s.writeS32(1, m_inputFrequencyOffset); + s.writeS32(2, m_streamIndex); + + s.writeFloat(3, m_rfBandwidth); + + if (m_channelMarker) { + s.writeBlob(11, m_channelMarker->serialize()); + } + + s.writeU32(12, m_rgbColor); + s.writeString(13, m_title); + s.writeBool(14, m_useReverseAPI); + s.writeString(15, m_reverseAPIAddress); + s.writeU32(16, m_reverseAPIPort); + s.writeU32(17, m_reverseAPIDeviceIndex); + s.writeU32(18, m_reverseAPIChannelIndex); + + s.writeBool(22, m_udpEnabled); + s.writeString(23, m_udpAddress); + s.writeU32(24, m_udpPort); + + if (m_scopeGUI) { + s.writeBlob(33, m_scopeGUI->serialize()); + } + + s.writeString(25, m_logFilename); + s.writeBool(26, m_logEnabled); + + if (m_rollupState) { + s.writeBlob(27, m_rollupState->serialize()); + } + + s.writeS32(28, m_workspaceIndex); + s.writeBlob(29, m_geometryBytes); + s.writeBool(30, m_hidden); + + return s.final(); +} + +bool PSK31DemodSettings::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.readS32(1, &m_inputFrequencyOffset, 0); + d.readS32(2, &m_streamIndex, 0); + + d.readFloat(3, &m_rfBandwidth, 100.0f); + m_rfBandwidth = validateRFBandwidth(m_rfBandwidth); + + if (m_channelMarker) + { + d.readBlob(11, &bytetmp); + m_channelMarker->deserialize(bytetmp); + } + + d.readU32(12, &m_rgbColor, QColor(25, 180, 200).rgb()); + d.readString(13, &m_title, "PSK31 Demodulator"); + d.readBool(14, &m_useReverseAPI, false); + d.readString(15, &m_reverseAPIAddress, "127.0.0.1"); + d.readU32(16, &utmp, 0); + + if ((utmp >= 1) && (utmp <= 65535)) { + m_reverseAPIPort = utmp; + } else { + m_reverseAPIPort = 8888; + } + + d.readU32(17, &utmp, 0); + m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp; + d.readU32(18, &utmp, 0); + m_reverseAPIChannelIndex = utmp > 99 ? 99 : utmp; + + + d.readBool(22, &m_udpEnabled); + d.readString(23, &m_udpAddress); + d.readU32(24, &utmp); + + if ((utmp >= 1) && (utmp <= 65535)) { + m_udpPort = utmp; + } else { + m_udpPort = 9999; + } + + if (m_scopeGUI) + { + d.readBlob(33, &bytetmp); + m_scopeGUI->deserialize(bytetmp); + } + + d.readString(25, &m_logFilename, "psk31_log.txt"); + d.readBool(26, &m_logEnabled, false); + + if (m_rollupState) + { + d.readBlob(27, &bytetmp); + m_rollupState->deserialize(bytetmp); + } + + d.readS32(28, &m_workspaceIndex, 0); + d.readBlob(29, &m_geometryBytes); + d.readBool(30, &m_hidden, false); + + return true; + } + else + { + resetToDefaults(); + return false; + } +} + +void PSK31DemodSettings::applySettings(const QStringList& settingsKeys, const PSK31DemodSettings& settings) +{ + if (settingsKeys.contains("inputFrequencyOffset")) { + m_inputFrequencyOffset = settings.m_inputFrequencyOffset; + } + if (settingsKeys.contains("rfBandwidth")) { + m_rfBandwidth = validateRFBandwidth(settings.m_rfBandwidth); + } + if (settingsKeys.contains("udpEnabled")) { + m_udpEnabled = settings.m_udpEnabled; + } + if (settingsKeys.contains("udpAddress")) { + m_udpAddress = settings.m_udpAddress; + } + if (settingsKeys.contains("udpPort")) { + m_udpPort = settings.m_udpPort; + } + if (settingsKeys.contains("rgbColor")) { + m_rgbColor = settings.m_rgbColor; + } + if (settingsKeys.contains("title")) { + m_title = settings.m_title; + } + if (settingsKeys.contains("streamIndex")) { + m_streamIndex = settings.m_streamIndex; + } + if (settingsKeys.contains("useReverseAPI")) { + m_useReverseAPI = settings.m_useReverseAPI; + } + if (settingsKeys.contains("reverseAPIAddress")) { + m_reverseAPIAddress = settings.m_reverseAPIAddress; + } + if (settingsKeys.contains("reverseAPIPort")) { + m_reverseAPIPort = settings.m_reverseAPIPort; + } + if (settingsKeys.contains("reverseAPIDeviceIndex")) { + m_reverseAPIDeviceIndex = settings.m_reverseAPIDeviceIndex; + } + if (settingsKeys.contains("reverseAPIChannelIndex")) { + m_reverseAPIChannelIndex = settings.m_reverseAPIChannelIndex; + } + if (settingsKeys.contains("logFilename")) { + m_logFilename = settings.m_logFilename; + } + if (settingsKeys.contains("logEnabled")) { + m_logEnabled = settings.m_logEnabled; + } + if (settingsKeys.contains("workspaceIndex")) { + m_workspaceIndex = settings.m_workspaceIndex; + } + if (settingsKeys.contains("geometryBytes")) { + m_geometryBytes = settings.m_geometryBytes; + } + if (settingsKeys.contains("hidden")) { + m_hidden = settings.m_hidden; + } +} + +QString PSK31DemodSettings::getDebugString(const QStringList& settingsKeys, bool force) const +{ + std::ostringstream ostr; + + if (settingsKeys.contains("inputFrequencyOffset") || force) { + ostr << " m_inputFrequencyOffset: " << m_inputFrequencyOffset; + } + if (settingsKeys.contains("rfBandwidth") || force) { + ostr << " m_rfBandwidth: " << m_rfBandwidth; + } + if (settingsKeys.contains("udpEnabled") || force) { + ostr << " m_udpEnabled: " << m_udpEnabled; + } + if (settingsKeys.contains("udpAddress") || force) { + ostr << " m_udpAddress: " << m_udpAddress.toStdString(); + } + if (settingsKeys.contains("udpPort") || force) { + ostr << " m_udpPort: " << m_udpPort; + } + if (settingsKeys.contains("rgbColor") || force) { + ostr << " m_rgbColor: " << m_rgbColor; + } + if (settingsKeys.contains("title") || force) { + ostr << " m_title: " << m_title.toStdString(); + } + if (settingsKeys.contains("streamIndex") || force) { + ostr << " m_streamIndex: " << m_streamIndex; + } + if (settingsKeys.contains("useReverseAPI") || force) { + ostr << " m_useReverseAPI: " << m_useReverseAPI; + } + if (settingsKeys.contains("reverseAPIAddress") || force) { + ostr << " m_reverseAPIAddress: " << m_reverseAPIAddress.toStdString(); + } + if (settingsKeys.contains("reverseAPIPort") || force) { + ostr << " m_reverseAPIPort: " << m_reverseAPIPort; + } + if (settingsKeys.contains("reverseAPIDeviceIndex") || force) { + ostr << " m_reverseAPIDeviceIndex: " << m_reverseAPIDeviceIndex; + } + if (settingsKeys.contains("reverseAPIChannelIndex") || force) { + ostr << " m_reverseAPIChannelIndex: " << m_reverseAPIChannelIndex; + } + if (settingsKeys.contains("logFilename") || force) { + ostr << " m_logFilename: " << m_logFilename.toStdString(); + } + if (settingsKeys.contains("logEnabled") || force) { + ostr << " m_logEnabled: " << m_logEnabled; + } + if (settingsKeys.contains("workspaceIndex") || force) { + ostr << " m_workspaceIndex: " << m_workspaceIndex; + } + if (settingsKeys.contains("hidden") || force) { + ostr << " m_hidden: " << m_hidden; + } + + return QString(ostr.str().c_str()); +} diff --git a/plugins/channelrx/demodpsk31/psk31demodsettings.h b/plugins/channelrx/demodpsk31/psk31demodsettings.h new file mode 100644 index 000000000..e8fe1d4b4 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodsettings.h @@ -0,0 +1,71 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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_PSK31DEMODSETTINGS_H +#define INCLUDE_PSK31DEMODSETTINGS_H + +#include + +#include "dsp/dsptypes.h" + +class Serializable; + +struct PSK31DemodSettings +{ + qint32 m_inputFrequencyOffset; + Real m_rfBandwidth; + bool m_udpEnabled; + QString m_udpAddress; + uint16_t m_udpPort; + + quint32 m_rgbColor; + QString m_title; + Serializable *m_channelMarker; + int m_streamIndex; //!< MIMO channel. Not relevant when connected to SI (single Rx). + bool m_useReverseAPI; + QString m_reverseAPIAddress; + uint16_t m_reverseAPIPort; + uint16_t m_reverseAPIDeviceIndex; + uint16_t m_reverseAPIChannelIndex; + + QString m_logFilename; + bool m_logEnabled; + Serializable *m_scopeGUI; + Serializable *m_rollupState; + int m_workspaceIndex; + QByteArray m_geometryBytes; + bool m_hidden; + + static const int PSK31DEMOD_CHANNEL_SAMPLE_RATE = 1000; + static constexpr Real PSK31DEMOD_MIN_RF_BANDWIDTH = 50.0f; + static constexpr Real PSK31DEMOD_MAX_RF_BANDWIDTH = 500.0f; + + PSK31DemodSettings(); + static Real validateRFBandwidth(Real rfBandwidth); + void resetToDefaults(); + void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; } + void setRollupState(Serializable *rollupState) { m_rollupState = rollupState; } + void setScopeGUI(Serializable *scopeGUI) { m_scopeGUI = scopeGUI; } + QByteArray serialize() const; + bool deserialize(const QByteArray& data); + void applySettings(const QStringList& settingsKeys, const PSK31DemodSettings& settings); + QString getDebugString(const QStringList& settingsKeys, bool force=false) const; +}; + +#endif /* INCLUDE_PSK31DEMODSETTINGS_H */ diff --git a/plugins/channelrx/demodpsk31/psk31demodsink.cpp b/plugins/channelrx/demodpsk31/psk31demodsink.cpp new file mode 100644 index 000000000..dfe0a284b --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodsink.cpp @@ -0,0 +1,326 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 "dsp/scopevis.h" +#ifndef PSK31_DEMOD_SINK_BENCH +#include "psk31demod.h" +#endif +#include "psk31demodsink.h" + +PSK31DemodSink::PSK31DemodSink() : + m_scopeSink(nullptr), + m_messageQueueToChannel(nullptr), + m_channelSampleRate(m_internalSampleRate), + m_channelFrequencyOffset(0), + m_interpolatorDistance(1.0f), + m_interpolatorDistanceRemain(1.0f), + m_costasLoop(2.0f * M_PI / 300.0f, 2), + m_magsq(0.0), + m_magsqSum(0.0), + m_magsqPeak(0.0), + m_magsqCount(0), + m_snrInPhaseSum(0.0), + m_snrQuadratureSum(0.0), + m_snrCount(0), + m_snr(0.0f), + m_clockCount(m_samplesPerSymbol / 2), + m_previousPolarity(false), + m_lockCount(0), + m_unlockCount(0), + m_locked(false), + m_reportSampleCount(0), + m_scopeBufferIndex(0) +{ + m_scopeBuffer.resize(m_scopeBufferSize); + applySettings(QStringList(), m_settings, true); + applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); +} + +void PSK31DemodSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) +{ + Complex output; + + for (SampleVector::const_iterator it = begin; it != end; ++it) + { + Complex sample(it->real(), it->imag()); + sample *= m_nco.nextIQ(); + + if (m_interpolatorDistance < 1.0f) + { + while (!m_interpolator.interpolate(&m_interpolatorDistanceRemain, sample, &output)) + { + processOneSample(output); + m_interpolatorDistanceRemain += m_interpolatorDistance; + } + } + else if (m_interpolator.decimate(&m_interpolatorDistanceRemain, sample, &output)) + { + processOneSample(output); + m_interpolatorDistanceRemain += m_interpolatorDistance; + } + } +} + +void PSK31DemodSink::processOneSample(Complex sample) +{ + const double magsqRaw = sample.real() * sample.real() + sample.imag() * sample.imag(); + const Real magsq = magsqRaw / (SDR_RX_SCALED * SDR_RX_SCALED); + m_movingAverage(magsq); + m_magsq = m_movingAverage.asDouble(); + m_magsqSum += magsq; + m_magsqPeak = std::max(m_magsqPeak, static_cast(magsq)); + ++m_magsqCount; + + if (m_magsqCount >= m_internalSampleRate / 10) + { + m_magSqLevelStore.m_magsq = m_magsqSum / m_magsqCount; + m_magSqLevelStore.m_magsqPeak = m_magsqPeak; + m_magSqLevelStore.m_nbSamples = m_magsqCount; + m_magsqSum = 0.0; + m_magsqPeak = 0.0; + m_magsqCount = 0; + } + + sample /= SDR_RX_SCALEF; + sample = m_lowpass.filter(sample); + + // The Costas detector gain is proportional to input power. Normalize from + // the short-term envelope so acquisition bandwidth does not collapse for + // signals below full scale, while preserving the shaped zero crossings. + // The recovered carrier is applied to the original sample below. + const Real carrierScale = 1.0f / std::max(static_cast(std::sqrt(m_magsq)), 1.0e-4f); + m_costasLoop.feed(sample.real() * carrierScale, sample.imag() * carrierScale); + const Complex carrier = -std::conj(m_costasLoop.getComplex()); + const Complex corrected = sample * carrier; + const Real correctedMagnitude = std::abs(corrected); + + if (correctedMagnitude > 0.0f) { + m_lockAverage((std::abs(corrected.real()) - std::abs(corrected.imag())) / correctedMagnitude); + } else { + m_lockAverage(0.0f); + } + + const bool lockDetected = m_lockAverage.instantAverage() > 0.35f; + + // Use a Schmitt decision for transition timing. A pulse-shaped BPSK phase + // reversal crosses zero, so testing the instantaneous magnitude at the + // sign change suppresses the very transition needed to recenter the clock. + bool polarity = m_previousPolarity; + const Real polarityThreshold = 0.2f * std::sqrt(m_magsq); + if (corrected.real() > polarityThreshold) { + polarity = true; + } else if (corrected.real() < -polarityThreshold) { + polarity = false; + } + + if (polarity != m_previousPolarity) + { + // A phase reversal should occur half a symbol before the next sample. + // Nudge the free-running clock toward that point rather than resetting + // it, so an isolated noise crossing cannot insert or delete a symbol. + const Real timingError = m_samplesPerSymbol / 2.0f - m_clockCount; + const Real correction = std::clamp( + m_timingGain * timingError, + -m_maxTimingCorrection, + m_maxTimingCorrection); + m_clockCount += correction; + } + m_previousPolarity = polarity; + + bool symbolSample = false; + m_clockCount -= 1.0f; + + if (m_clockCount <= 0.0f) + { + const bool wasLocked = m_locked; + + // Qualify lock at symbol rate. Noise can briefly cross the instantaneous + // lock threshold, so require a sustained acquisition before accepting + // bits and use a short dropout hysteresis once a signal is acquired. + if (lockDetected) + { + m_unlockCount = 0; + m_lockCount = std::min(m_lockCount + 1, m_lockConfirmSymbols); + m_locked = m_locked || (m_lockCount >= m_lockConfirmSymbols); + } + else + { + m_lockCount = 0; + m_unlockCount = std::min(m_unlockCount + 1, m_unlockConfirmSymbols); + m_locked = m_locked && (m_unlockCount < m_unlockConfirmSymbols); + } + + if (m_locked) { + receiveSymbol(polarity); + } else { + resetDecoder(); + } + + if (m_locked && !wasLocked) + { + // Start a fresh one-second measurement at acquisition. Otherwise + // the first locked report includes pre-lock samples and reads low. + resetSNR(); + m_reportSampleCount = 0; + } + + m_clockCount += m_samplesPerSymbol; + symbolSample = true; + } + + if (m_locked) + { + m_snrInPhaseSum += corrected.real() * corrected.real(); + m_snrQuadratureSum += corrected.imag() * corrected.imag(); + ++m_snrCount; + } + + if (++m_reportSampleCount >= m_internalSampleRate) + { + if (m_locked && (m_snrCount > 0)) + { + const double inPhasePower = m_snrInPhaseSum / m_snrCount; + const double quadraturePower = m_snrQuadratureSum / m_snrCount; + const double signalPower = std::max(inPhasePower - quadraturePower, 1.0e-20); + const double measuredNoisePower = std::max(2.0 * quadraturePower, 1.0e-20); + const double referenceNoisePower = measuredNoisePower + * m_snrReferenceBandwidth / m_settings.m_rfBandwidth; + m_snr = std::clamp( + static_cast(10.0 * std::log10(signalPower / referenceNoisePower)), + -99.9f, + 99.9f); + resetSNR(); + } + +#ifndef PSK31_DEMOD_SINK_BENCH + if (m_messageQueueToChannel) { + m_messageQueueToChannel->push( + PSK31Demod::MsgDemodReport::create(getFrequencyOffset(), m_snr, m_locked)); + } +#endif + m_reportSampleCount = 0; + } + + sampleToScope(Complex(corrected.real(), symbolSample ? 1.0f : 0.0f)); +} + +void PSK31DemodSink::receiveSymbol(bool symbol) +{ + QChar character; + if (m_decoder.decodeSymbol(symbol, character)) + { +#ifndef PSK31_DEMOD_SINK_BENCH + if (m_messageQueueToChannel) + { + PSK31Demod::MsgCharacter *message = PSK31Demod::MsgCharacter::create(QString(character)); + m_messageQueueToChannel->push(message); + } +#endif + if (m_characterSink) { + m_characterSink(character); + } + } +} + +void PSK31DemodSink::resetDecoder() +{ + m_decoder.reset(); +} + +void PSK31DemodSink::resetSNR() +{ + m_snrInPhaseSum = 0.0; + m_snrQuadratureSum = 0.0; + m_snrCount = 0; +} + +void PSK31DemodSink::sampleToScope(const Complex& sample) +{ + if (!m_scopeSink) { + return; + } + + m_scopeBuffer[m_scopeBufferIndex++] = Sample( + sample.real() * SDR_RX_SCALEF, + sample.imag() * SDR_RX_SCALEF); + + if (m_scopeBufferIndex == m_scopeBufferSize) + { + std::vector begin; + begin.push_back(m_scopeBuffer.begin()); + m_scopeSink->feed(begin, m_scopeBufferSize); + m_scopeBufferIndex = 0; + } +} + +void PSK31DemodSink::applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force) +{ + if ((channelSampleRate != m_channelSampleRate) || + (channelFrequencyOffset != m_channelFrequencyOffset) || force) + { + m_nco.setFreq(-channelFrequencyOffset, channelSampleRate); + m_interpolator.create(32, channelSampleRate, m_settings.m_rfBandwidth / 2.0f); + m_interpolatorDistance = static_cast(channelSampleRate) / m_internalSampleRate; + m_interpolatorDistanceRemain = m_interpolatorDistance; + m_channelSampleRate = channelSampleRate; + m_channelFrequencyOffset = channelFrequencyOffset; + m_costasLoop.reset(); + m_lockAverage.reset(); + m_lockCount = 0; + m_unlockCount = 0; + m_locked = false; + resetSNR(); + m_snr = 0.0f; + m_clockCount = m_samplesPerSymbol / 2; + m_previousPolarity = false; + resetDecoder(); + } +} + +void PSK31DemodSink::applySettings(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force) +{ + PSK31DemodSettings validatedSettings = settings; + validatedSettings.m_rfBandwidth = PSK31DemodSettings::validateRFBandwidth(settings.m_rfBandwidth); + + if (settingsKeys.contains("rfBandwidth") || force) + { + m_interpolator.create(32, m_channelSampleRate, validatedSettings.m_rfBandwidth / 2.0f); + m_lowpass.create(129, m_internalSampleRate, validatedSettings.m_rfBandwidth / 2.0f); + const Real maxFrequency = std::max(5.0f, validatedSettings.m_rfBandwidth / 2.0f - 20.0f); + m_costasLoop.setMaxFreq(maxFrequency * 2.0f * M_PI / m_internalSampleRate); + m_costasLoop.setMinFreq(-maxFrequency * 2.0f * M_PI / m_internalSampleRate); + resetSNR(); + m_snr = 0.0f; + m_reportSampleCount = 0; + } + + if (force) { + m_settings = validatedSettings; + } else { + m_settings.applySettings(settingsKeys, validatedSettings); + } +} + +float PSK31DemodSink::getFrequencyOffset() const +{ + return m_costasLoop.getFreq() * m_internalSampleRate / (2.0f * M_PI); +} diff --git a/plugins/channelrx/demodpsk31/psk31demodsink.h b/plugins/channelrx/demodpsk31/psk31demodsink.h new file mode 100644 index 000000000..208796430 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodsink.h @@ -0,0 +1,128 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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_PSK31DEMODSINK_H +#define INCLUDE_PSK31DEMODSINK_H + +#include + +#include "dsp/channelsamplesink.h" +#include "dsp/costasloop.h" +#include "dsp/interpolator.h" +#include "dsp/firfilter.h" +#include "dsp/nco.h" +#include "dsp/dsptypes.h" +#include "util/messagequeue.h" +#include "util/movingaverage.h" +#include "util/psk31.h" + +#include "psk31demodsettings.h" + +class ScopeVis; + +class PSK31DemodSink : public ChannelSampleSink +{ +public: + PSK31DemodSink(); + + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end); + + void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false); + void applySettings(const QStringList& settingsKeys, const PSK31DemodSettings& settings, bool force = false); + void setScopeSink(ScopeVis *scopeSink) { m_scopeSink = scopeSink; } + void setMessageQueueToChannel(MessageQueue *queue) { m_messageQueueToChannel = queue; } + void setCharacterSink(const std::function& sink) { m_characterSink = sink; } +#ifdef PSK31_DEMOD_SINK_BENCH + void feedTestSample(const Complex& normalizedSample) { processOneSample(normalizedSample * SDR_RX_SCALEF); } +#endif + double getMagSq() const { return m_magsq; } + float getFrequencyOffset() const; + float getSNR() const { return m_snr; } + bool isLocked() const { return m_locked; } + + void getMagSqLevels(double& avg, double& peak, int& nbSamples) + { + avg = m_magSqLevelStore.m_magsq; + peak = m_magSqLevelStore.m_magsqPeak; + nbSamples = m_magSqLevelStore.m_nbSamples; + } + +private: + struct MagSqLevelsStore + { + MagSqLevelsStore() : m_magsq(1e-12), m_magsqPeak(1e-12), m_nbSamples(1) {} + double m_magsq; + double m_magsqPeak; + int m_nbSamples; + }; + + static const int m_internalSampleRate = 1000; + static const int m_samplesPerSymbol = 32; + static const int m_scopeBufferSize = 50; + static const int m_lockConfirmSymbols = 8; + static const int m_unlockConfirmSymbols = 2; + static constexpr Real m_snrReferenceBandwidth = 100.0f; + static constexpr Real m_timingGain = 0.25f; + static constexpr Real m_maxTimingCorrection = 2.0f; + + ScopeVis *m_scopeSink; + MessageQueue *m_messageQueueToChannel; + PSK31DemodSettings m_settings; + + int m_channelSampleRate; + int m_channelFrequencyOffset; + NCO m_nco; + Interpolator m_interpolator; + Real m_interpolatorDistance; + Real m_interpolatorDistanceRemain; + Lowpass m_lowpass; + CostasLoop m_costasLoop; + + MovingAverageUtil m_movingAverage; + MovingAverageUtil m_lockAverage; + double m_magsq; + double m_magsqSum; + double m_magsqPeak; + int m_magsqCount; + MagSqLevelsStore m_magSqLevelStore; + double m_snrInPhaseSum; + double m_snrQuadratureSum; + int m_snrCount; + float m_snr; + + Real m_clockCount; + bool m_previousPolarity; + int m_lockCount; + int m_unlockCount; + bool m_locked; + int m_reportSampleCount; + PSK31Decoder m_decoder; + std::function m_characterSink; + + SampleVector m_scopeBuffer; + int m_scopeBufferIndex; + + void processOneSample(Complex sample); + void receiveSymbol(bool symbol); + void resetDecoder(); + void resetSNR(); + void sampleToScope(const Complex& sample); +}; + +#endif // INCLUDE_PSK31DEMODSINK_H diff --git a/plugins/channelrx/demodpsk31/psk31demodwebapiadapter.cpp b/plugins/channelrx/demodpsk31/psk31demodwebapiadapter.cpp new file mode 100644 index 000000000..6b65d9cce --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodwebapiadapter.cpp @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 "SWGChannelSettings.h" +#include "psk31demod.h" +#include "psk31demodwebapiadapter.h" + +PSK31DemodWebAPIAdapter::PSK31DemodWebAPIAdapter() +{} + +PSK31DemodWebAPIAdapter::~PSK31DemodWebAPIAdapter() +{} + +int PSK31DemodWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setPSK31DemodSettings(new SWGSDRangel::SWGPSK31DemodSettings()); + response.getPSK31DemodSettings()->init(); + PSK31Demod::webapiFormatChannelSettings(response, m_settings); + + return 200; +} + +int PSK31DemodWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) force; + (void) errorMessage; + PSK31Demod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response); + + return 200; +} diff --git a/plugins/channelrx/demodpsk31/psk31demodwebapiadapter.h b/plugins/channelrx/demodpsk31/psk31demodwebapiadapter.h new file mode 100644 index 000000000..77fe7fac4 --- /dev/null +++ b/plugins/channelrx/demodpsk31/psk31demodwebapiadapter.h @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB // +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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_PSK31DEMOD_WEBAPIADAPTER_H +#define INCLUDE_PSK31DEMOD_WEBAPIADAPTER_H + +#include "channel/channelwebapiadapter.h" +#include "psk31demodsettings.h" + +/** + * Standalone API adapter only for the settings + */ +class PSK31DemodWebAPIAdapter : public ChannelWebAPIAdapter { +public: + PSK31DemodWebAPIAdapter(); + virtual ~PSK31DemodWebAPIAdapter(); + + virtual QByteArray serialize() const { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data) { return m_settings.deserialize(data); } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + +private: + PSK31DemodSettings m_settings; +}; + +#endif // INCLUDE_PSK31DEMOD_WEBAPIADAPTER_H diff --git a/plugins/channelrx/demodpsk31/readme.md b/plugins/channelrx/demodpsk31/readme.md new file mode 100644 index 000000000..997ff0e5c --- /dev/null +++ b/plugins/channelrx/demodpsk31/readme.md @@ -0,0 +1,125 @@ +

PSK31 Demodulator Plugin

+ +

Introduction

+ +This channel receives PSK31 text. It performs carrier and symbol-clock recovery, +differential BPSK decoding, and Varicode decoding at the standard 31.25 baud rate. +The decoder supports the same extended Latin-1 Varicode table as the [PSK31 modulator](../../channeltx/modpsk31/readme.md). + +

Interface

+ +The top and bottom bars of the channel window are described [here](../../../sdrgui/channel/readme.md). + +![PSK31 Demodulator plugin GUI](../../../doc/img/PSK31Demod_plugin.png) + +

1: Frequency offset

+ +Tune the channel marker to the center of the PSK31 signal. The carrier-recovery +loop corrects a small remaining frequency and phase error. With the default +100 Hz bandwidth, tune to within about 10 Hz for reliable acquisition. The +carrier status label shows the residual error after the loop has locked. + +

2: Channel power and level meter

+ +Channel power is displayed in dB relative to a full-scale signal. The level meter +shows average power, instantaneous peak power, and peak hold. + +

3: RF bandwidth

+ +This sets the input filter bandwidth. The default 100 Hz bandwidth is appropriate +for most PSK31 signals. A narrower setting rejects more adjacent-channel energy; +a wider setting allows a larger initial tuning error. + +

4: UDP

+ +When checked, received characters are forwarded to the specified UDP address (5) and port (6). + +

5: UDP address

+ +IP address of the host to forward received characters to via UDP. + +

6: UDP port

+ +UDP port number to forward received characters to. + +

7: Carrier status

+ +Shows whether the demodulator is locked to the carrier. Once locked, it also +shows the residual frequency error and the estimated SNR. The SNR is measured +from the carrier-corrected constellation over one second of locked samples. Its +noise power is normalized to a 100 Hz reference bandwidth, so changing the RF +bandwidth does not introduce the usual 3 dB change for each doubling or halving +of bandwidth. The first SNR value is displayed after one complete second of +carrier lock; samples collected before acquisition are excluded. + +

8: Start/stop Logging Messages to .txt File

+ +When checked, writes all received characters to the .txt file specified by (9). + +

9: .txt Log Filename

+ +Click to specify the name of the .txt file which received characters are logged to. + +

10: Clear

+ +Clear the received text view (11) of received characters. + +

11: Received text

+ +Decoded text is appended to the text view. + +

Measured performance

+ +The sample-level benchmark sends a +raised-cosine PSK31 waveform with 256 idle symbols followed by the 30-character +test frame `CQ CQ DE SDRANGEL 0123456789\r\n`. A frame passes only when every +character is correct. Run it with: + +``` +sdrangelbench -t psk31 -a perf +``` + +Measurements on the 1000 sample/s internal receiver with the default 100 Hz RF +bandwidth gave these results: + +| Test | Result | +|---|---| +| AWGN, acquired carrier | 32% exact frames at 7 dB SNR; 62% at 8 dB; 88% at 9 dB; 96% at 10 dB; 100% at every tested point from 11 through 16 dB | +| Residual frequency, random starting phase | 10/10 exact frames at every offset from -14 Hz through +11 Hz; use +/-10 Hz as the tuning target | +| Sample-clock error | 5/5 exact frames with zero character errors at every tested point from -5000 through +5000 ppm | +| Noiseless input level | 8/8 timing phases at every tested level from -10 through -60 dBFS | +| Noise only at -40 dBFS | Zero lock acquisitions and zero decoded characters in one simulated hour | +| CW interferer at 25 Hz separation | 5/5 exact frames at -20 dB relative to the wanted signal; 3/5 at -10 dB; 0/5 at equal power | +| CW interferer at 50 Hz separation | 5/5 exact frames at -10 dB relative to the wanted signal; 0/5 at equal power | +| CW interferer at 75 or 100 Hz separation | 5/5 exact frames with the interferer 10 dB stronger than the wanted signal | +| Core demodulator CPU throughput | 5.60-5.93 million internal samples/s, or 5600-5900 times real time at 1000 samples/s | + +SNR is average wanted-signal power divided by complex AWGN power in a 100 Hz +reference bandwidth, after carrier acquisition. The demodulator estimates signal +and noise from the in-phase and quadrature power of the recovered BPSK carrier, +then scales the measured noise from the selected RF bandwidth to 100 Hz. In the +regression test, a 20 dB input measured 21.25 dB with a 100 Hz RF bandwidth and +20.84 dB with a 200 Hz RF bandwidth. At 31.25 baud, 10 dB in 100 Hz corresponds +to about 15 dB Eb/N0. The frequency result measures acquisition after roughly +8.2 seconds of idle symbols; the loop's configured tracking clamp is wider than +its measured acquisition range. Input level alone is not a sensitivity figure +because the usable floor depends on noise and receiver dynamic range. + +The CPU result is the range from three one-second runs of the RelWithDebInfo +Windows build on an Intel Core i9-14900K. It repeatedly feeds representative +BPSK samples directly to the demodulator sink. At the 1000 sample/s internal +rate, this corresponds to roughly 0.018% of one CPU core. It measures the +channel-specific carrier recovery, symbol timing, and decoding path; device +input, channelization, scope rendering, and other application overhead are not +included. Run this focused measurement with: + +``` +sdrangelbench -t psk31 -a cpu +``` + +The receiver qualifies carrier lock over eight symbols before decoding and drops +lock after two failed symbol checks. Run the standalone noise test with: + +``` +sdrangelbench -t psk31 -a noise +``` diff --git a/sdrbase/resources/webapi.qrc b/sdrbase/resources/webapi.qrc index d3ba86e63..fabfc0479 100644 --- a/sdrbase/resources/webapi.qrc +++ b/sdrbase/resources/webapi.qrc @@ -112,6 +112,7 @@ webapi/doc/swagger/include/RollupState.yaml webapi/doc/swagger/include/RtlSdr.yaml webapi/doc/swagger/include/RTTYDemod.yaml + webapi/doc/swagger/include/PSK31Demod.yaml webapi/doc/swagger/include/RTTYMod.yaml webapi/doc/swagger/include/SatelliteTracker.yaml webapi/doc/swagger/include/SDRPlay.yaml diff --git a/sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml b/sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml index ab58bad6c..9c5b9b3e4 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml @@ -160,6 +160,9 @@ ChannelReport: PSK31ModReport: $ref: "/doc/swagger/include/PSK31Mod.yaml#/PSK31ModReport" description: "Psk31 mod report data for Channel." + PSK31DemodReport: + $ref: "/doc/swagger/include/PSK31Demod.yaml#/PSK31DemodReport" + description: "PSK31 demodulator report data for Channel." SigMFFileSinkReport: $ref: "/doc/swagger/include/SigMFFileSink.yaml#/SigMFFileSinkReport" description: "Sig mf file sink report data for Channel." diff --git a/sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml b/sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml index 401d785c6..b828088ae 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml @@ -166,6 +166,9 @@ ChannelSettings: PSK31ModSettings: $ref: "/doc/swagger/include/PSK31Mod.yaml#/PSK31ModSettings" description: "Psk31 mod settings configuration for Channel." + PSK31DemodSettings: + $ref: "/doc/swagger/include/PSK31Demod.yaml#/PSK31DemodSettings" + description: "PSK31 demodulator settings configuration for Channel." RadioAstronomySettings: $ref: "/doc/swagger/include/RadioAstronomy.yaml#/RadioAstronomySettings" description: "Radio astronomy settings configuration for Channel." diff --git a/sdrbase/resources/webapi/doc/swagger/include/PSK31Demod.yaml b/sdrbase/resources/webapi/doc/swagger/include/PSK31Demod.yaml new file mode 100644 index 000000000..1b5bb5658 --- /dev/null +++ b/sdrbase/resources/webapi/doc/swagger/include/PSK31Demod.yaml @@ -0,0 +1,95 @@ +PSK31DemodSettings: + description: PSK31 demodulator settings + properties: + inputFrequencyOffset: + type: integer + format: int64 + description: "Channel frequency offset from the device center frequency in Hz." + rfBandwidth: + type: number + format: float + description: "RF bandwidth in Hz." + minimum: 50 + maximum: 500 + udpEnabled: + description: "Whether to forward received messages to specified UDP port" + type: integer + minimum: 0 + maximum: 1 + udpAddress: + description: "UDP address to forward received messages to" + type: string + udpPort: + description: "UDP port to forward received messages to" + type: integer + minimum: 1 + maximum: 65535 + logFilename: + type: string + description: "Log file name or path." + logEnabled: + type: integer + description: "Enable logging to the configured file (1 enabled, 0 disabled)." + minimum: 0 + maximum: 1 + rgbColor: + type: integer + description: "Display color encoded as an RGB integer." + title: + type: string + description: "User-visible title." + streamIndex: + description: MIMO channel. Not relevant when connected to SI (single Rx). + type: integer + useReverseAPI: + description: Synchronize with reverse API (1 for yes, 0 for no) + type: integer + minimum: 0 + maximum: 1 + reverseAPIAddress: + type: string + description: "IPv4 address or host name of the reverse API peer." + reverseAPIPort: + type: integer + description: "TCP port of the reverse API peer." + minimum: 1 + maximum: 65535 + reverseAPIDeviceIndex: + type: integer + description: "Device-set index used by the reverse API peer." + reverseAPIChannelIndex: + type: integer + description: "Channel index used by the reverse API peer." + scopeConfig: + $ref: "/doc/swagger/include/GLScope.yaml#/GLScope" + description: "Oscilloscope-display configuration." + channelMarker: + $ref: "/doc/swagger/include/ChannelMarker.yaml#/ChannelMarker" + description: "Channel-marker display configuration." + rollupState: + $ref: "/doc/swagger/include/RollupState.yaml#/RollupState" + description: "Saved expanded or collapsed state of the GUI sections." + +PSK31DemodReport: + description: PSK31 demodulator runtime report + properties: + channelPowerDB: + description: power received in channel (dB) + type: number + format: float + channelSampleRate: + type: integer + description: "Effective sample rate delivered to the channel in samples per second." + frequencyOffset: + type: number + format: float + description: "Fine carrier-frequency estimate in Hz relative to the selected channel frequency." + snr: + type: number + format: float + description: "Signal-to-noise ratio in dB, normalized to a 100 Hz noise bandwidth." + locked: + type: integer + minimum: 0 + maximum: 1 + description: "Whether the BPSK carrier-recovery loop is locked." diff --git a/sdrbase/util/psk31.cpp b/sdrbase/util/psk31.cpp index 6bb89123d..5884be77a 100644 --- a/sdrbase/util/psk31.cpp +++ b/sdrbase/util/psk31.cpp @@ -327,3 +327,78 @@ void PSK31Encoder::addBits(unsigned& bits, unsigned int& bitCount, int data, int bits |= data << bitCount; bitCount += count; } + +PSK31Decoder::PSK31Decoder() +{ + reset(); +} + +void PSK31Decoder::reset() +{ + m_code.clear(); + m_zeroCount = 0; + m_havePreviousSymbol = false; + m_previousSymbol = false; +} + +bool PSK31Decoder::decodeSymbol(bool symbol, QChar& character) +{ + if (!m_havePreviousSymbol) + { + m_previousSymbol = symbol; + m_havePreviousSymbol = true; + return false; + } + + const bool bit = symbol == m_previousSymbol; + m_previousSymbol = symbol; + return decode(bit, character); +} + +bool PSK31Decoder::decode(bool bit, QChar& character) +{ + if (bit) + { + if ((m_zeroCount == 1) && !m_code.isEmpty()) { + m_code.append('0'); + } + + m_zeroCount = 0; + m_code.append('1'); + + if (m_code.size() > 12) + { + m_code.clear(); + m_zeroCount = 0; + } + + return false; + } + + ++m_zeroCount; + + if (m_zeroCount < 2) { + return false; + } + + const bool decoded = decodeCode(character); + m_code.clear(); + m_zeroCount = 0; + return decoded; +} + +bool PSK31Decoder::decodeCode(QChar& character) const +{ + if (m_code.isEmpty()) { + return false; + } + + const int index = PSK31Varicode::m_varicode.indexOf(m_code); + + if (index < 0) { + return false; + } + + character = QChar::fromLatin1(static_cast(index)); + return true; +} diff --git a/sdrbase/util/psk31.h b/sdrbase/util/psk31.h index 2064c3e26..40b527e0b 100644 --- a/sdrbase/util/psk31.h +++ b/sdrbase/util/psk31.h @@ -49,5 +49,22 @@ private: }; -#endif // INCLUDE_UTIL_PSK31_H +class SDRBASE_API PSK31Decoder +{ +public: + PSK31Decoder(); + + void reset(); + bool decode(bool bit, QChar& character); + bool decodeSymbol(bool symbol, QChar& character); + +private: + QString m_code; + int m_zeroCount; + bool m_havePreviousSymbol; + bool m_previousSymbol; + + bool decodeCode(QChar& character) const; +}; +#endif // INCLUDE_UTIL_PSK31_H diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index 20a877ae4..dd0eca698 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -5177,6 +5177,12 @@ bool WebAPIRequestMapper::getChannelSettings( channelSettings->getRttyDemodSettings()->init(); channelSettings->getRttyDemodSettings()->fromJsonObject(settingsJsonObject); } + else if (channelSettingsKey == "PSK31DemodSettings") + { + channelSettings->setPSK31DemodSettings(new SWGSDRangel::SWGPSK31DemodSettings()); + channelSettings->getPSK31DemodSettings()->init(); + channelSettings->getPSK31DemodSettings()->fromJsonObject(settingsJsonObject); + } else if (channelSettingsKey == "RTTYModSettings") { channelSettings->setRttyModSettings(new SWGSDRangel::SWGRTTYModSettings()); diff --git a/sdrbase/webapi/webapiutils.cpp b/sdrbase/webapi/webapiutils.cpp index 775501226..9b8b79838 100644 --- a/sdrbase/webapi/webapiutils.cpp +++ b/sdrbase/webapi/webapiutils.cpp @@ -71,6 +71,7 @@ const QMap WebAPIUtils::m_channelURIToSettingsKey = { {"sdrangel.channel.pagerdemod", "PagerDemodSettings"}, {"sdrangel.channeltx.modpacket", "PacketModSettings"}, {"sdrangel.channel.psk31mod", "PSK31ModSettings"}, + {"sdrangel.channel.psk31demod", "PSK31DemodSettings"}, {"sdrangel.channeltx.mod802.15.4", "IEEE_802_15_4_ModSettings"}, {"sdrangel.channel.radioclock", "RadioClockSettings"}, {"sdrangel.channel.radiosondedemod", "RadiosondeDemodSettings"}, @@ -195,6 +196,7 @@ const QMap WebAPIUtils::m_channelTypeToSettingsKey = { {"PacketMod", "PacketModSettings"}, {"PagerDemod", "PagerDemodSettings"}, {"PSK31Mod", "PSK31ModSettings"}, + {"PSK31Demod", "PSK31DemodSettings"}, {"LocalSink", "LocalSinkSettings"}, {"LocalSource", "LocalSourceSettings"}, {"RadioAstronomy", "RadioAstronomySettings"}, diff --git a/sdrbench/CMakeLists.txt b/sdrbench/CMakeLists.txt index 7e3eadca2..a1f45b4f7 100644 --- a/sdrbench/CMakeLists.txt +++ b/sdrbench/CMakeLists.txt @@ -15,6 +15,9 @@ set(sdrbench_SOURCES test_fftrrc.cpp test_firrrc.cpp test_meshtastic.cpp + test_psk31.cpp + ../plugins/channelrx/demodpsk31/psk31demodsink.cpp + ../plugins/channelrx/demodpsk31/psk31demodsettings.cpp ) set(sdrbench_HEADERS @@ -33,9 +36,12 @@ include_directories( ${CMAKE_SOURCE_DIR}/sdrbase ${CMAKE_SOURCE_DIR}/logging ${CMAKE_SOURCE_DIR}/modemmeshtastic + ${CMAKE_SOURCE_DIR}/plugins/channelrx/demodpsk31 ${CMAKE_SOURCE_DIR} ) +target_compile_definitions(sdrbench PRIVATE PSK31_DEMOD_SINK_BENCH) + if(DEFINED FFTW3F_DEPENDS) add_dependencies(sdrbench "${FFTW3F_DEPENDS}") endif() diff --git a/sdrbench/mainbench.cpp b/sdrbench/mainbench.cpp index d6f05e22a..723916995 100644 --- a/sdrbench/mainbench.cpp +++ b/sdrbench/mainbench.cpp @@ -81,6 +81,8 @@ void MainBench::run() testFIRRRCFilter(); } else if (m_parser.getTestType() == ParserBench::TestMeshtastic) { testMeshtastic(m_parser.getArgsStr()); + } else if (m_parser.getTestType() == ParserBench::TestPSK31) { + testPSK31(m_parser.getArgsStr()); } else { qDebug() << "MainBench::run: unknown test type: " << m_parser.getTestType(); } diff --git a/sdrbench/mainbench.h b/sdrbench/mainbench.h index 23ad5c588..ee867bd81 100644 --- a/sdrbench/mainbench.h +++ b/sdrbench/mainbench.h @@ -60,6 +60,7 @@ private: void testFFTRRCFilter(); void testFIRRRCFilter(); void testMeshtastic(const QString& argsStr); + void testPSK31(const QString& argsStr); void testFT4(const QString& wavFile, const QString& argsStr); //!< use with sdrbench/samples/ft4/20260304_180052.wav in -f option void testFT8(const QString& wavFile, const QString& argsStr); //!< use with sdrbench/samples/ft8/230105_091630.wav in -f option void testFT8Protocols(const QString& argsStr); diff --git a/sdrbench/parserbench.cpp b/sdrbench/parserbench.cpp index fdd1b1fcf..584b4be3f 100644 --- a/sdrbench/parserbench.cpp +++ b/sdrbench/parserbench.cpp @@ -24,7 +24,7 @@ ParserBench::ParserBench() : m_testOption(QStringList() << "t" << "test", - "Test type: decimateii, decimatefi, decimateff, decimateif, decimateinfii, decimatesupii, ambe, golay2312, ft8, ft4, ft8protocols, callsign, fftrrcfilter, firrrcfilter, meshtastic.", + "Test type: decimateii, decimatefi, decimateff, decimateif, decimateinfii, decimatesupii, ambe, golay2312, ft8, ft4, ft8protocols, callsign, fftrrcfilter, firrrcfilter, meshtastic, psk31.", "test", "decimateii"), m_nbSamplesOption(QStringList() << "n" << "nb-samples", @@ -159,6 +159,8 @@ ParserBench::TestType ParserBench::getTestType() const return TestFIRRRCFilter; } else if (m_testStr == "meshtastic") { return TestMeshtastic; + } else if (m_testStr == "psk31") { + return TestPSK31; } else { return TestDecimatorsII; } diff --git a/sdrbench/parserbench.h b/sdrbench/parserbench.h index 5bcc0472f..add106825 100644 --- a/sdrbench/parserbench.h +++ b/sdrbench/parserbench.h @@ -44,7 +44,8 @@ public: TestFT8Protocols, TestFFTRRCFilter, TestFIRRRCFilter, - TestMeshtastic + TestMeshtastic, + TestPSK31 } TestType; ParserBench(); diff --git a/sdrbench/test_psk31.cpp b/sdrbench/test_psk31.cpp new file mode 100644 index 000000000..8843260ee --- /dev/null +++ b/sdrbench/test_psk31.cpp @@ -0,0 +1,556 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2026 Jon Beniston, M7RCE // +// Some code by AI // +// // +// 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 "dsp/raisedcosine.h" +#include "mainbench.h" +#include "psk31demodsink.h" +#include "util/psk31.h" + +namespace { + +constexpr float sampleRate = 1000.0f; +constexpr int samplesPerSymbol = 32; +constexpr float measurementBandwidth = 100.0f; +constexpr int noiseDurationSeconds = 3600; +constexpr float noiseLevelDbFS = -40.0f; + +struct TrialOptions +{ + float snrDb100Hz = std::numeric_limits::infinity(); + float frequencyOffset = 0.0f; + float clockErrorPpm = 0.0f; + int timingOffset = 0; + float amplitude = 0.2f; + float initialPhase = std::numeric_limits::quiet_NaN(); + float interfererOffset = 0.0f; + float interfererRelativeDb = -std::numeric_limits::infinity(); + float rfBandwidth = measurementBandwidth; + int phaseGlitchStart = -1; + int phaseGlitchLength = 0; + quint32 seed = 1; +}; + +struct NoiseResult +{ + int characters = 0; + qint64 lockedSamples = 0; + int lockAcquisitions = 0; +}; + +QVector encodeBits(const QString& text) +{ + PSK31Encoder encoder; + QVector bits; + + // Reversing phase on every idle zero gives the Costas loop and symbol clock + // enough time to acquire before any scored text arrives. + bits.fill(false, 256); + + for (QChar character : text) + { + unsigned encoded; + unsigned int bitCount; + encoder.encode(character, encoded, bitCount); + + for (unsigned int i = 0; i < bitCount; ++i) { + bits.append((encoded >> i) & 1U); + } + } + + for (int i = 0; i < 32; ++i) { + bits.append(false); + } + + return bits; +} + +QVector modulate(const QVector& bits) +{ + QVector waveform; + waveform.reserve((bits.size() + 4) * samplesPerSymbol); + + RaisedCosine pulseShape; + pulseShape.create(1.0, 2, samplesPerSymbol, true); + + bool symbol = false; + + for (bool bit : bits) + { + if (!bit) { + symbol = !symbol; + } + + for (int sample = 0; sample < samplesPerSymbol; ++sample) { + waveform.append(pulseShape.filter(sample == 1 ? (symbol ? 1.0f : -1.0f) : 0.0f)); + } + } + + // Flush the pulse-shaping filter. + for (int i = 0; i < 3 * samplesPerSymbol; ++i) { + waveform.append(pulseShape.filter(0.0f)); + } + + return waveform; +} + +QString runTrial(const QVector& source, const TrialOptions& options, float* measuredSNR = nullptr) +{ + const double clockScale = 1.0 + options.clockErrorPpm * 1.0e-6; + QVector resampled; + resampled.reserve(static_cast(source.size() * clockScale) + 1); + + for (double position = options.timingOffset; position < source.size() - 1; position += 1.0 / clockScale) + { + const int index = static_cast(position); + const float fraction = static_cast(position - index); + resampled.append(source[index] + fraction * (source[index + 1] - source[index])); + } + + double meanSignalPower = 0.0; + for (float sample : resampled) { + meanSignalPower += sample * sample; + } + meanSignalPower = options.amplitude * options.amplitude * meanSignalPower / resampled.size(); + + // SNR is quoted in the demodulator's 100 Hz RF bandwidth. The generated + // complex AWGN spans the 1000 sample/s simulation bandwidth. + double noisePower = 0.0; + if (std::isfinite(options.snrDb100Hz)) + { + const double ratio = std::pow(10.0, options.snrDb100Hz / 10.0); + noisePower = meanSignalPower * (sampleRate / measurementBandwidth) / ratio; + } + + std::mt19937 generator(options.seed); + std::normal_distribution gaussian(0.0f, std::sqrt(noisePower / 2.0)); + std::uniform_real_distribution phaseDistribution(-M_PI, M_PI); + const float initialPhase = std::isfinite(options.initialPhase) + ? options.initialPhase : phaseDistribution(generator); + const float interfererAmplitude = std::isfinite(options.interfererRelativeDb) + ? options.amplitude * std::pow(10.0f, options.interfererRelativeDb / 20.0f) + : 0.0f; + + PSK31DemodSink sink; + PSK31DemodSettings settings; + settings.m_rfBandwidth = options.rfBandwidth; + sink.applySettings(QStringList(), settings, true); + sink.applyChannelSettings(sampleRate, 0, true); + + QString received; + sink.setCharacterSink([&received](QChar character) { received.append(character); }); + + for (int i = 0; i < resampled.size(); ++i) + { + const float carrierPhase = initialPhase + 2.0f * M_PI * options.frequencyOffset * i / sampleRate; + Complex sample = options.amplitude * resampled[i] * Complex(std::cos(carrierPhase), std::sin(carrierPhase)); + + if ((i >= options.phaseGlitchStart) && (i < options.phaseGlitchStart + options.phaseGlitchLength)) { + sample = -sample; + } + + if (interfererAmplitude > 0.0f) + { + const float interfererPhase = 0.37f + 2.0f * M_PI * options.interfererOffset * i / sampleRate; + sample += interfererAmplitude * Complex(std::cos(interfererPhase), std::sin(interfererPhase)); + } + + sample += Complex(gaussian(generator), gaussian(generator)); + sink.feedTestSample(sample); + } + + if (measuredSNR) { + *measuredSNR = sink.getSNR(); + } + + return received; +} + +NoiseResult runNoiseTrial(int durationSeconds, float levelDbFS, quint32 seed) +{ + const float noisePower = std::pow(10.0f, levelDbFS / 10.0f); + std::mt19937 generator(seed); + std::normal_distribution gaussian(0.0f, std::sqrt(noisePower / 2.0f)); + + PSK31DemodSink sink; + PSK31DemodSettings settings; + settings.m_rfBandwidth = measurementBandwidth; + sink.applySettings(QStringList(), settings, true); + sink.applyChannelSettings(sampleRate, 0, true); + + NoiseResult result; + sink.setCharacterSink([&result](QChar) { ++result.characters; }); + bool wasLocked = false; + const int sampleCount = static_cast(durationSeconds * sampleRate); + + for (int i = 0; i < sampleCount; ++i) + { + sink.feedTestSample(Complex(gaussian(generator), gaussian(generator))); + const bool locked = sink.isLocked(); + result.lockedSamples += locked; + result.lockAcquisitions += locked && !wasLocked; + wasLocked = locked; + } + + return result; +} + +void measureNoiseRejection() +{ + const NoiseResult noise = runNoiseTrial(noiseDurationSeconds, noiseLevelDbFS, 6000); + qInfo().noquote() << "Noise_only_duration_s,noise_level_dBFS,locked_samples,lock_acquisitions,false_characters"; + qInfo().noquote() << QString("%1,%2,%3,%4,%5") + .arg(noiseDurationSeconds) + .arg(noiseLevelDbFS, 0, 'f', 0) + .arg(noise.lockedSamples) + .arg(noise.lockAcquisitions) + .arg(noise.characters); +} + +void measureCPUPerformance() +{ + constexpr int blockSize = 4096; + constexpr qint64 minimumElapsedMilliseconds = 1000; + + QVector block(blockSize); + for (int i = 0; i < blockSize; ++i) + { + const Real inPhase = ((i / samplesPerSymbol) & 1) ? 0.2f : -0.2f; + const Real quadrature = 0.002f * std::sin(2.0f * M_PI * i / 97.0f); + block[i] = Complex(inPhase, quadrature); + } + + PSK31DemodSink sink; + PSK31DemodSettings settings; + settings.m_rfBandwidth = measurementBandwidth; + sink.applySettings(QStringList(), settings, true); + sink.applyChannelSettings(sampleRate, 0, true); + + qint64 processedSamples = 0; + QElapsedTimer timer; + timer.start(); + + do + { + for (const Complex& sample : block) { + sink.feedTestSample(sample); + } + processedSamples += blockSize; + } while (timer.elapsed() < minimumElapsedMilliseconds); + + const double elapsedSeconds = timer.nsecsElapsed() * 1.0e-9; + const double samplesPerSecond = processedSamples / elapsedSeconds; + const double realTimeFactor = samplesPerSecond / sampleRate; + + qInfo().noquote() << "CPU_internal_samples_per_second,real_time_factor,elapsed_seconds"; + qInfo().noquote() << QString("%1,%2,%3") + .arg(samplesPerSecond, 0, 'f', 0) + .arg(realTimeFactor, 0, 'f', 0) + .arg(elapsedSeconds, 0, 'f', 3); +} + +bool framePassed(const QVector& waveform, const QString& payload, const TrialOptions& options) +{ + return runTrial(waveform, options).contains(payload); +} + +int trailingCharacterErrors(const QString& received, const QString& payload) +{ + const QString scored = received.right(payload.size()); + int errors = std::abs(scored.size() - payload.size()); + const int compared = std::min(scored.size(), payload.size()); + + for (int i = 0; i < compared; ++i) { + errors += scored[i] != payload[payload.size() - compared + i]; + } + + return errors; +} + +void measurePerformance(const QVector& waveform, const QString& payload) +{ + qInfo().noquote() << "PSK31 RX performance benchmark"; + qInfo().noquote() << "SNR definition: average signal power / AWGN power in 100 Hz; acquired carrier; exact-frame criterion"; + qInfo().noquote() << "SNR_dB,frames_passed,frames_total"; + + for (int snrDb = 0; snrDb <= 16; ++snrDb) + { + int passed = 0; + constexpr int trials = 50; + + for (int trial = 0; trial < trials; ++trial) + { + TrialOptions options; + options.snrDb100Hz = snrDb; + options.initialPhase = 0.0f; // Measure AWGN sensitivity after carrier acquisition. + options.seed = 1000 + trial; + passed += framePassed(waveform, payload, options); + } + + qInfo().noquote() << QString("%1,%2,%3").arg(snrDb).arg(passed).arg(trials); + } + + qInfo().noquote() << "Residual_frequency_Hz,frames_passed,frames_total"; + for (int offset = -28; offset <= 28; ++offset) + { + int passed = 0; + constexpr int trials = 10; + + for (int trial = 0; trial < trials; ++trial) + { + TrialOptions options; + options.frequencyOffset = offset; + options.seed = 2000 + trial; + passed += framePassed(waveform, payload, options); + } + + qInfo().noquote() << QString("%1,%2,%3").arg(offset).arg(passed).arg(trials); + } + + qInfo().noquote() << "Sample_clock_error_ppm,frames_passed,frames_total,total_character_errors"; + for (int ppm = -5000; ppm <= 5000; ppm += 500) + { + int passed = 0; + int characterErrors = 0; + constexpr int trials = 5; + + for (int trial = 0; trial < trials; ++trial) + { + TrialOptions options; + options.clockErrorPpm = ppm; + options.timingOffset = trial * 6; + options.seed = 3000 + trial; + const QString received = runTrial(waveform, options); + passed += received.contains(payload); + characterErrors += trailingCharacterErrors(received, payload); + } + + qInfo().noquote() << QString("%1,%2,%3,%4").arg(ppm).arg(passed).arg(trials).arg(characterErrors); + } + + qInfo().noquote() << "Signal_level_dBFS,timing_phases_passed,timing_phases_total"; + for (int levelDb = -10; levelDb >= -60; levelDb -= 5) + { + int passed = 0; + constexpr int trials = 8; + + for (int trial = 0; trial < trials; ++trial) + { + TrialOptions options; + options.amplitude = std::pow(10.0f, levelDb / 20.0f); + options.timingOffset = trial * 4; + options.seed = 4000 + trial; + passed += framePassed(waveform, payload, options); + } + + qInfo().noquote() << QString("%1,%2,%3").arg(levelDb).arg(passed).arg(trials); + } + + qInfo().noquote() << "Interferer_offset_Hz,interferer_over_signal_dB,frames_passed,frames_total"; + for (int offset : {25, 50, 75, 100}) + { + for (int relativeDb : {-20, -10, 0, 6, 10}) + { + int passed = 0; + constexpr int trials = 5; + + for (int trial = 0; trial < trials; ++trial) + { + TrialOptions options; + options.interfererOffset = offset; + options.interfererRelativeDb = relativeDb; + options.seed = 5000 + trial; + passed += framePassed(waveform, payload, options); + } + + qInfo().noquote() << QString("%1,%2,%3,%4") + .arg(offset).arg(relativeDb).arg(passed).arg(trials); + } + } + + measureNoiseRejection(); + measureCPUPerformance(); +} + +} + +void MainBench::testPSK31(const QString& argsStr) +{ + PSK31Encoder encoder; + PSK31Decoder decoder; + QVector decoded; + PSK31DemodSettings serverSettings; + + // Server builds have no scope GUI. Serializing their settings must remain safe. + bool success = !serverSettings.serialize().isEmpty(); + + PSK31DemodSettings edgeSettings; + edgeSettings.m_rfBandwidth = 0.0f; + edgeSettings.m_reverseAPIPort = 1; + edgeSettings.m_udpPort = 65535; + PSK31DemodSettings restoredEdgeSettings; + const bool edgeSettingsRestored = restoredEdgeSettings.deserialize(edgeSettings.serialize()); + const bool settingsValidationPassed = edgeSettingsRestored + && (restoredEdgeSettings.m_rfBandwidth == PSK31DemodSettings::PSK31DEMOD_MIN_RF_BANDWIDTH) + && (restoredEdgeSettings.m_reverseAPIPort == 1) + && (restoredEdgeSettings.m_udpPort == 65535) + && (PSK31DemodSettings::validateRFBandwidth( + std::numeric_limits::quiet_NaN()) == 100.0f); + success = success && settingsValidationPassed; + + // Exercise every entry in the shared extended-ASCII Varicode table as one + // continuous stream. This also checks character-boundary synchronization. + for (int value = 0; value < 256; ++value) + { + unsigned bits; + unsigned int bitCount; + encoder.encode(QChar::fromLatin1(static_cast(value)), bits, bitCount); + + for (unsigned int bit = 0; bit < bitCount; ++bit) + { + QChar character; + if (decoder.decode((bits >> bit) & 1U, character)) { + decoded.append(character.toLatin1() & 0xff); + } + } + } + + QChar finalCharacter; + if (decoder.decode(false, finalCharacter)) { + decoded.append(finalCharacter.toLatin1() & 0xff); + } + + success = success && (decoded.size() == 256); + for (int i = 0; success && (i < decoded.size()); ++i) { + success = decoded[i] == i; + } + + decoder.reset(); + QChar character; + for (int i = 0; i < 8; ++i) { + success = success && !decoder.decode(false, character); + } + for (int i = 0; i < 13; ++i) { + success = success && !decoder.decode(true, character); + } + success = success && !decoder.decode(false, character); + success = success && !decoder.decode(false, character); + + unsigned bits; + unsigned int bitCount; + encoder.encode('A', bits, bitCount); + bool gotA = false; + for (unsigned int bit = 0; bit < bitCount; ++bit) { + gotA = decoder.decode((bits >> bit) & 1U, character) || gotA; + } + gotA = decoder.decode(false, character) || gotA; + success = success && gotA && (character == 'A'); + + const QString message("CQ TEST\r\n"); + QString received; + bool symbol = false; + decoder.reset(); + decoder.decodeSymbol(symbol, character); + + for (QChar sourceCharacter : message) + { + encoder.encode(sourceCharacter, bits, bitCount); + + for (unsigned int bit = 0; bit < bitCount; ++bit) + { + if (((bits >> bit) & 1U) == 0U) { + symbol = !symbol; + } + + if (decoder.decodeSymbol(symbol, character)) { + received.append(character); + } + } + } + + symbol = !symbol; + if (decoder.decodeSymbol(symbol, character)) { + received.append(character); + } + success = success && (received == message); + + const QString payload("CQ CQ DE SDRANGEL 0123456789\r\n"); + const QVector waveform = modulate(encodeBits(payload)); + TrialOptions nominal; + nominal.snrDb100Hz = 20.0f; + float measuredSNR; + const bool nominalPassed = runTrial(waveform, nominal, &measuredSNR).contains(payload); + const bool snrPassed = std::isfinite(measuredSNR) && (std::abs(measuredSNR - nominal.snrDb100Hz) < 5.0f); + + TrialOptions wideBandwidth = nominal; + wideBandwidth.rfBandwidth = 200.0f; + float wideBandwidthSNR; + const bool wideBandwidthPassed = runTrial(waveform, wideBandwidth, &wideBandwidthSNR).contains(payload); + const bool bandwidthNormalized = std::isfinite(wideBandwidthSNR) + && (std::abs(wideBandwidthSNR - measuredSNR) < 1.0f); + success = success && nominalPassed && snrPassed && wideBandwidthPassed && bandwidthNormalized; + + TrialOptions glitch; + glitch.phaseGlitchStart = 250 * samplesPerSymbol + 2; + glitch.phaseGlitchLength = 12; + const bool glitchPassed = framePassed(waveform, payload, glitch); + success = success && glitchPassed; + qInfo() << "PSK31 regressions: nominal" << nominalPassed + << "reported SNR" << measuredSNR << "valid" << snrPassed + << "200 Hz SNR" << wideBandwidthSNR << "normalized" << bandwidthNormalized + << "phase glitch" << glitchPassed + << "settings validation" << settingsValidationPassed; + + const NoiseResult noise = runNoiseTrial(noiseDurationSeconds, noiseLevelDbFS, 6000); + success = success && (noise.characters == 0); + + if (argsStr.contains("perf", Qt::CaseInsensitive)) { + measurePerformance(waveform, payload); + } + else if (argsStr.contains("noise", Qt::CaseInsensitive)) { + measureNoiseRejection(); + } + else if (argsStr.contains("cpu", Qt::CaseInsensitive)) { + measureCPUPerformance(); + } + + if (argsStr.contains("trace", Qt::CaseInsensitive)) + { + for (int ppm : {-5000, 5000}) + { + TrialOptions options; + options.clockErrorPpm = ppm; + const QString trace = runTrial(waveform, options); + qInfo().noquote() << QString("clock %1 ppm: %2").arg(ppm, 6).arg(QString(trace.toLatin1().toHex())); + } + } + + if (success) { + qInfo() << "MainBench::testPSK31: success"; + } else { + qCritical() << "MainBench::testPSK31: failed"; + } +} diff --git a/sdrgui/gui/acronymview.cpp b/sdrgui/gui/acronymview.cpp index 4935cb16d..83be4c907 100644 --- a/sdrgui/gui/acronymview.cpp +++ b/sdrgui/gui/acronymview.cpp @@ -19,10 +19,18 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include +#include +#include +#include #include +#include #include +#include "feature/featurewebapiutils.h" +#include "util/callsign.h" +#include "util/maidenhead.h" #include "acronymview.h" AcronymView::AcronymView(QWidget* parent) : @@ -37,21 +45,45 @@ bool AcronymView::event(QEvent* event) if (event->type() == QEvent::ToolTip) { QHelpEvent* helpEvent = static_cast(event); - QTextCursor cursor = cursorForPosition(helpEvent->pos()); - cursor.select(QTextCursor::WordUnderCursor); - QString text = cursor.selectedText(); + const QString url = urlAt(helpEvent->pos()); + const QString word = wordAt(helpEvent->pos()); + QString acronym = word.toUpper(); // Remove trailing digits from METAR - while (text.size() > 0 && text.right(1)[0].isDigit()) { - text = text.left(text.size() - 1); + while (!acronym.isEmpty() && acronym.back().isDigit()) { + acronym.chop(1); } - if (!text.isEmpty() && m_acronym.contains(text)) + if (!url.isEmpty()) { - QToolTip::showText(helpEvent->globalPos(), QString("%1 - %2").arg(text).arg(m_acronym.value(text))); + QToolTip::showText( + helpEvent->globalPos(), + tr("%1 - Web link (click to open)").arg(url)); + } + else if (!acronym.isEmpty() && m_acronym.contains(acronym)) + { + QToolTip::showText(helpEvent->globalPos(), QString("%1 - %2").arg(acronym, m_acronym.value(acronym))); + } + else if (Maidenhead::isMaidenhead(word)) + { + QToolTip::showText( + helpEvent->globalPos(), + tr("%1 - Maidenhead locator (click to find on Map)").arg(word.toUpper())); } else { - if (!text.isEmpty()) { - qDebug() << "AcronymView::event: No tooltip for " << text; + QString country; + const QString callsign = callsignAt(helpEvent->pos(), &country); + + if (!callsign.isEmpty()) + { + QToolTip::showText( + helpEvent->globalPos(), + tr("%1 - Amateur radio callsign from %2 (click to look up on QRZ)") + .arg(callsign, country)); + return true; + } + + if (!word.isEmpty()) { + qDebug() << "AcronymView::event: No tooltip for " << word; } QToolTip::hideText(); } @@ -60,6 +92,175 @@ bool AcronymView::event(QEvent* event) return QPlainTextEdit::event(event); } +QString AcronymView::wordAt(const QPoint& position) const +{ + QTextCursor cursor = cursorForPosition(position); + cursor.select(QTextCursor::WordUnderCursor); + return cursor.selectedText(); +} + +QString AcronymView::urlAt(const QPoint& position) const +{ + const QTextCursor cursor = cursorForPosition(position); + const QTextBlock block = cursor.block(); + const QString text = block.text(); + const int positionInBlock = cursor.position() - block.position(); + + if ((positionInBlock < 0) || (positionInBlock >= text.size()) || text[positionInBlock].isSpace()) { + return QString(); + } + + int start = positionInBlock; + int end = positionInBlock + 1; + + while ((start > 0) && !text[start - 1].isSpace()) { + --start; + } + while ((end < text.size()) && !text[end].isSpace()) { + ++end; + } + + QString candidate = text.mid(start, end - start); + const QString leadingPunctuation = QStringLiteral("([{<\"'"); + const QString trailingPunctuation = QStringLiteral(".,;:!?)]}>\"'"); + + while (!candidate.isEmpty() && leadingPunctuation.contains(candidate.front())) { + candidate.remove(0, 1); + } + while (!candidate.isEmpty() && trailingPunctuation.contains(candidate.back())) { + candidate.chop(1); + } + + if ( !candidate.startsWith(QStringLiteral("http://"), Qt::CaseInsensitive) + && !candidate.startsWith(QStringLiteral("https://"), Qt::CaseInsensitive)) { + return QString(); + } + + const QUrl url(candidate, QUrl::StrictMode); + return url.isValid() && !url.host().isEmpty() ? url.toString() : QString(); +} + +QString AcronymView::maidenheadAt(const QPoint& position) const +{ + const QString word = wordAt(position); + QString acronym = word; + + while (!acronym.isEmpty() && acronym.back().isDigit()) { + acronym.chop(1); + } + + return !m_acronym.contains(acronym) && Maidenhead::isMaidenhead(word) ? word.toUpper() : QString(); +} + +QString AcronymView::callsignAt(const QPoint& position, QString* country) const +{ + if (country) { + country->clear(); + } + + const QString word = wordAt(position); + QString acronym = word; + + while (!acronym.isEmpty() && acronym.back().isDigit()) { + acronym.chop(1); + } + + if (m_acronym.contains(acronym) || Maidenhead::isMaidenhead(word)) { + return QString(); + } + + const QString callsign = word.toUpper(); + + // Callsign::is_callsign expects at least two characters and deliberately + // accepts a prefix match. Keep the surrounding check strict so ordinary + // words containing a callsign-like fragment do not become QRZ links. + if ((callsign.size() < 3) || (callsign.size() > 10)) { + return QString(); + } + + static const QRegularExpression amateurCallsign( + R"(^(?:[2-9][A-Z]{1,2}|[A-Z]{1,2})[0-9]{1,4}[A-Z]{1,4}$)"); + + if (!amateurCallsign.match(callsign).hasMatch() || !Callsign::is_callsign(callsign)) { + return QString(); + } + + const CountryDat::CountryInfo countryInfo = Callsign::instance()->getCountryInfo(callsign); + + if (countryInfo.country == CountryDat::nullCountry.country) { + return QString(); + } + + if (country) { + *country = countryInfo.country; + } + + return callsign; +} + +void AcronymView::mouseMoveEvent(QMouseEvent* event) +{ + QPlainTextEdit::mouseMoveEvent(event); + const bool link = !urlAt(event->pos()).isEmpty() + || !maidenheadAt(event->pos()).isEmpty() + || !callsignAt(event->pos()).isEmpty(); + viewport()->setCursor(link ? Qt::PointingHandCursor : Qt::IBeamCursor); +} + +void AcronymView::mousePressEvent(QMouseEvent* event) +{ + m_pressedUrl = event->button() == Qt::LeftButton ? urlAt(event->pos()) : QString(); + m_pressedMaidenhead = m_pressedUrl.isEmpty() && (event->button() == Qt::LeftButton) + ? maidenheadAt(event->pos()) : QString(); + m_pressedCallsign = m_pressedUrl.isEmpty() && (event->button() == Qt::LeftButton) + ? callsignAt(event->pos()) : QString(); + QPlainTextEdit::mousePressEvent(event); +} + +void AcronymView::mouseReleaseEvent(QMouseEvent* event) +{ + const QString url = event->button() == Qt::LeftButton ? urlAt(event->pos()) : QString(); + + if (!url.isEmpty() && (url == m_pressedUrl)) + { + m_pressedUrl.clear(); + m_pressedMaidenhead.clear(); + m_pressedCallsign.clear(); + QDesktopServices::openUrl(QUrl(url)); + event->accept(); + return; + } + + const QString maidenhead = event->button() == Qt::LeftButton ? maidenheadAt(event->pos()) : QString(); + + if (!maidenhead.isEmpty() && (maidenhead == m_pressedMaidenhead)) + { + m_pressedUrl.clear(); + m_pressedMaidenhead.clear(); + m_pressedCallsign.clear(); + FeatureWebAPIUtils::mapFind(maidenhead); + event->accept(); + return; + } + + const QString callsign = event->button() == Qt::LeftButton ? callsignAt(event->pos()) : QString(); + + if (!callsign.isEmpty() && (callsign == m_pressedCallsign)) + { + m_pressedUrl.clear(); + m_pressedMaidenhead.clear(); + m_pressedCallsign.clear(); + QDesktopServices::openUrl(QUrl(QString("https://www.qrz.com/db/%1").arg(callsign))); + event->accept(); + return; + } + + m_pressedUrl.clear(); + m_pressedMaidenhead.clear(); + m_pressedCallsign.clear(); + QPlainTextEdit::mouseReleaseEvent(event); +} + void AcronymView::addAcronym(const QString& acronym, const QString& explanation) { m_acronym.insert(acronym, explanation); diff --git a/sdrgui/gui/acronymview.h b/sdrgui/gui/acronymview.h index 4648b5e9e..a96e809ac 100644 --- a/sdrgui/gui/acronymview.h +++ b/sdrgui/gui/acronymview.h @@ -26,11 +26,27 @@ #include "export.h" -// Displays text like a QPlainTextEdit, but adds tooltips for acronyms in the text +class QMouseEvent; + +// Displays text like a QPlainTextEdit, with acronym tooltips and links for +// Maidenhead locators, amateur radio callsigns, and web URLs. class SDRGUI_API AcronymView : public QPlainTextEdit { Q_OBJECT QHash m_acronym; + QString m_pressedUrl; + QString m_pressedMaidenhead; + QString m_pressedCallsign; + + QString wordAt(const QPoint& position) const; + QString urlAt(const QPoint& position) const; + QString maidenheadAt(const QPoint& position) const; + QString callsignAt(const QPoint& position, QString* country = nullptr) const; + +protected: + void mouseMoveEvent(QMouseEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; public: diff --git a/swagger/sdrangel/api/swagger/include/ChannelReport.yaml b/swagger/sdrangel/api/swagger/include/ChannelReport.yaml index 3a8ec7f27..f536bd7bf 100644 --- a/swagger/sdrangel/api/swagger/include/ChannelReport.yaml +++ b/swagger/sdrangel/api/swagger/include/ChannelReport.yaml @@ -160,6 +160,9 @@ ChannelReport: PSK31ModReport: $ref: "http://swgserver:8081/api/swagger/include/PSK31Mod.yaml#/PSK31ModReport" description: "Psk31 mod report data for Channel." + PSK31DemodReport: + $ref: "http://swgserver:8081/api/swagger/include/PSK31Demod.yaml#/PSK31DemodReport" + description: "PSK31 demodulator report data for Channel." SigMFFileSinkReport: $ref: "http://swgserver:8081/api/swagger/include/SigMFFileSink.yaml#/SigMFFileSinkReport" description: "Sig mf file sink report data for Channel." diff --git a/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml b/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml index 5bf9ffa84..1ad5c856d 100644 --- a/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml +++ b/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml @@ -166,6 +166,9 @@ ChannelSettings: PSK31ModSettings: $ref: "http://swgserver:8081/api/swagger/include/PSK31Mod.yaml#/PSK31ModSettings" description: "Psk31 mod settings configuration for Channel." + PSK31DemodSettings: + $ref: "http://swgserver:8081/api/swagger/include/PSK31Demod.yaml#/PSK31DemodSettings" + description: "PSK31 demodulator settings configuration for Channel." RadioAstronomySettings: $ref: "http://swgserver:8081/api/swagger/include/RadioAstronomy.yaml#/RadioAstronomySettings" description: "Radio astronomy settings configuration for Channel." diff --git a/swagger/sdrangel/api/swagger/include/PSK31Demod.yaml b/swagger/sdrangel/api/swagger/include/PSK31Demod.yaml new file mode 100644 index 000000000..1c0d50e7f --- /dev/null +++ b/swagger/sdrangel/api/swagger/include/PSK31Demod.yaml @@ -0,0 +1,95 @@ +PSK31DemodSettings: + description: PSK31 demodulator settings + properties: + inputFrequencyOffset: + type: integer + format: int64 + description: "Channel frequency offset from the device center frequency in Hz." + rfBandwidth: + type: number + format: float + description: "RF bandwidth in Hz." + minimum: 50 + maximum: 500 + udpEnabled: + description: "Whether to forward received messages to specified UDP port" + type: integer + minimum: 0 + maximum: 1 + udpAddress: + description: "UDP address to forward received messages to" + type: string + udpPort: + description: "UDP port to forward received messages to" + type: integer + minimum: 1 + maximum: 65535 + logFilename: + type: string + description: "Log file name or path." + logEnabled: + type: integer + description: "Enable logging to the configured file (1 enabled, 0 disabled)." + minimum: 0 + maximum: 1 + rgbColor: + type: integer + description: "Display color encoded as an RGB integer." + title: + type: string + description: "User-visible title." + streamIndex: + description: MIMO channel. Not relevant when connected to SI (single Rx). + type: integer + useReverseAPI: + description: Synchronize with reverse API (1 for yes, 0 for no) + type: integer + minimum: 0 + maximum: 1 + reverseAPIAddress: + type: string + description: "IPv4 address or host name of the reverse API peer." + reverseAPIPort: + type: integer + description: "TCP port of the reverse API peer." + minimum: 1 + maximum: 65535 + reverseAPIDeviceIndex: + type: integer + description: "Device-set index used by the reverse API peer." + reverseAPIChannelIndex: + type: integer + description: "Channel index used by the reverse API peer." + scopeConfig: + $ref: "http://swgserver:8081/api/swagger/include/GLScope.yaml#/GLScope" + description: "Oscilloscope-display configuration." + channelMarker: + $ref: "http://swgserver:8081/api/swagger/include/ChannelMarker.yaml#/ChannelMarker" + description: "Channel-marker display configuration." + rollupState: + $ref: "http://swgserver:8081/api/swagger/include/RollupState.yaml#/RollupState" + description: "Saved expanded or collapsed state of the GUI sections." + +PSK31DemodReport: + description: PSK31 demodulator runtime report + properties: + channelPowerDB: + description: power received in channel (dB) + type: number + format: float + channelSampleRate: + type: integer + description: "Effective sample rate delivered to the channel in samples per second." + frequencyOffset: + type: number + format: float + description: "Fine carrier-frequency estimate in Hz relative to the selected channel frequency." + snr: + type: number + format: float + description: "Signal-to-noise ratio in dB, normalized to a 100 Hz noise bandwidth." + locked: + type: integer + minimum: 0 + maximum: 1 + description: "Whether the BPSK carrier-recovery loop is locked." diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp b/swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp index 4284ef13d..353850425 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp @@ -130,6 +130,8 @@ SWGChannelReport::SWGChannelReport() { m_pager_demod_report_isSet = false; psk31_mod_report = nullptr; m_psk31_mod_report_isSet = false; + psk31_demod_report = nullptr; + m_psk31_demod_report_isSet = false; sig_mf_file_sink_report = nullptr; m_sig_mf_file_sink_report_isSet = false; ssb_mod_report = nullptr; @@ -246,6 +248,8 @@ SWGChannelReport::init() { m_remote_source_report_isSet = false; rtty_demod_report = new SWGRTTYDemodReport(); m_rtty_demod_report_isSet = false; + psk31_demod_report = new SWGPSK31DemodReport(); + m_psk31_demod_report_isSet = false; rtty_mod_report = new SWGRTTYModReport(); m_rtty_mod_report_isSet = false; packet_demod_report = new SWGPacketDemodReport(); @@ -412,6 +416,9 @@ SWGChannelReport::cleanup() { if(rtty_demod_report != nullptr) { delete rtty_demod_report; } + if(psk31_demod_report != nullptr) { + delete psk31_demod_report; + } if(rtty_mod_report != nullptr) { delete rtty_mod_report; } @@ -555,6 +562,7 @@ SWGChannelReport::fromJsonObject(QJsonObject &pJson) { ::SWGSDRangel::setValue(&remote_source_report, pJson["RemoteSourceReport"], "SWGRemoteSourceReport", "SWGRemoteSourceReport"); ::SWGSDRangel::setValue(&rtty_demod_report, pJson["RTTYDemodReport"], "SWGRTTYDemodReport", "SWGRTTYDemodReport"); + ::SWGSDRangel::setValue(&psk31_demod_report, pJson["PSK31DemodReport"], "SWGPSK31DemodReport", "SWGPSK31DemodReport"); ::SWGSDRangel::setValue(&rtty_mod_report, pJson["RTTYModReport"], "SWGRTTYModReport", "SWGRTTYModReport"); @@ -736,6 +744,9 @@ SWGChannelReport::asJsonObject() { if((rtty_demod_report != nullptr) && (rtty_demod_report->isSet())){ toJsonValue(QString("RTTYDemodReport"), rtty_demod_report, obj, QString("SWGRTTYDemodReport")); } + if((psk31_demod_report != nullptr) && (psk31_demod_report->isSet())){ + toJsonValue(QString("PSK31DemodReport"), psk31_demod_report, obj, QString("SWGPSK31DemodReport")); + } if((rtty_mod_report != nullptr) && (rtty_mod_report->isSet())){ toJsonValue(QString("RTTYModReport"), rtty_mod_report, obj, QString("SWGRTTYModReport")); } @@ -1239,6 +1250,16 @@ SWGChannelReport::setRttyDemodReport(SWGRTTYDemodReport* rtty_demod_report) { this->m_rtty_demod_report_isSet = true; } +SWGPSK31DemodReport* +SWGChannelReport::getPSK31DemodReport() { + return psk31_demod_report; +} +void +SWGChannelReport::setPSK31DemodReport(SWGPSK31DemodReport* psk31_demod_report) { + this->psk31_demod_report = psk31_demod_report; + this->m_psk31_demod_report_isSet = true; +} + SWGRTTYModReport* SWGChannelReport::getRttyModReport() { return rtty_mod_report; @@ -1527,6 +1548,9 @@ SWGChannelReport::isSet(){ if(psk31_mod_report && psk31_mod_report->isSet()){ isObjectUpdated = true; break; } + if(psk31_demod_report && psk31_demod_report->isSet()){ + isObjectUpdated = true; break; + } if(sig_mf_file_sink_report && sig_mf_file_sink_report->isSet()){ isObjectUpdated = true; break; } @@ -1555,4 +1579,3 @@ SWGChannelReport::isSet(){ return isObjectUpdated; } } - diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelReport.h b/swagger/sdrangel/code/qt5/client/SWGChannelReport.h index 59596bd74..04035ca6d 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelReport.h +++ b/swagger/sdrangel/code/qt5/client/SWGChannelReport.h @@ -65,6 +65,7 @@ #include "SWGPacketModReport.h" #include "SWGPagerDemodReport.h" #include "SWGRTTYDemodReport.h" +#include "SWGPSK31DemodReport.h" #include "SWGRTTYModReport.h" #include "SWGRadioAstronomyReport.h" #include "SWGRadioClockReport.h" @@ -237,6 +238,9 @@ public: SWGRTTYDemodReport* getRttyDemodReport(); void setRttyDemodReport(SWGRTTYDemodReport* rtty_demod_report); + SWGPSK31DemodReport* getPSK31DemodReport(); + void setPSK31DemodReport(SWGPSK31DemodReport* psk31_demod_report); + SWGRTTYModReport* getRttyModReport(); void setRttyModReport(SWGRTTYModReport* rtty_mod_report); @@ -418,6 +422,9 @@ private: SWGRTTYDemodReport* rtty_demod_report; bool m_rtty_demod_report_isSet; + SWGPSK31DemodReport* psk31_demod_report; + bool m_psk31_demod_report_isSet; + SWGRTTYModReport* rtty_mod_report; bool m_rtty_mod_report_isSet; diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp b/swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp index 0247995c2..ee8ad5a28 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp @@ -134,6 +134,8 @@ SWGChannelSettings::SWGChannelSettings() { m_pager_demod_settings_isSet = false; psk31_mod_settings = nullptr; m_psk31_mod_settings_isSet = false; + psk31_demod_settings = nullptr; + m_psk31_demod_settings_isSet = false; radio_astronomy_settings = nullptr; m_radio_astronomy_settings_isSet = false; radio_clock_settings = nullptr; @@ -296,6 +298,8 @@ SWGChannelSettings::init() { m_remote_tcp_sink_settings_isSet = false; rtty_demod_settings = new SWGRTTYDemodSettings(); m_rtty_demod_settings_isSet = false; + psk31_demod_settings = new SWGPSK31DemodSettings(); + m_psk31_demod_settings_isSet = false; rtty_mod_settings = new SWGRTTYModSettings(); m_rtty_mod_settings_isSet = false; sig_mf_file_sink_settings = new SWGSigMFFileSinkSettings(); @@ -494,6 +498,9 @@ SWGChannelSettings::cleanup() { if(rtty_demod_settings != nullptr) { delete rtty_demod_settings; } + if(psk31_demod_settings != nullptr) { + delete psk31_demod_settings; + } if(rtty_mod_settings != nullptr) { delete rtty_mod_settings; } @@ -656,6 +663,7 @@ SWGChannelSettings::fromJsonObject(QJsonObject &pJson) { ::SWGSDRangel::setValue(&remote_tcp_sink_settings, pJson["RemoteTCPSinkSettings"], "SWGRemoteTCPSinkSettings", "SWGRemoteTCPSinkSettings"); ::SWGSDRangel::setValue(&rtty_demod_settings, pJson["RTTYDemodSettings"], "SWGRTTYDemodSettings", "SWGRTTYDemodSettings"); + ::SWGSDRangel::setValue(&psk31_demod_settings, pJson["PSK31DemodSettings"], "SWGPSK31DemodSettings", "SWGPSK31DemodSettings"); ::SWGSDRangel::setValue(&rtty_mod_settings, pJson["RTTYModSettings"], "SWGRTTYModSettings", "SWGRTTYModSettings"); @@ -873,6 +881,9 @@ SWGChannelSettings::asJsonObject() { if((rtty_demod_settings != nullptr) && (rtty_demod_settings->isSet())){ toJsonValue(QString("RTTYDemodSettings"), rtty_demod_settings, obj, QString("SWGRTTYDemodSettings")); } + if((psk31_demod_settings != nullptr) && (psk31_demod_settings->isSet())){ + toJsonValue(QString("PSK31DemodSettings"), psk31_demod_settings, obj, QString("SWGPSK31DemodSettings")); + } if((rtty_mod_settings != nullptr) && (rtty_mod_settings->isSet())){ toJsonValue(QString("RTTYModSettings"), rtty_mod_settings, obj, QString("SWGRTTYModSettings")); } @@ -1507,6 +1518,16 @@ SWGChannelSettings::setRttyDemodSettings(SWGRTTYDemodSettings* rtty_demod_settin this->m_rtty_demod_settings_isSet = true; } +SWGPSK31DemodSettings* +SWGChannelSettings::getPSK31DemodSettings() { + return psk31_demod_settings; +} +void +SWGChannelSettings::setPSK31DemodSettings(SWGPSK31DemodSettings* psk31_demod_settings) { + this->psk31_demod_settings = psk31_demod_settings; + this->m_psk31_demod_settings_isSet = true; +} + SWGRTTYModSettings* SWGChannelSettings::getRttyModSettings() { return rtty_mod_settings; @@ -1771,6 +1792,9 @@ SWGChannelSettings::isSet(){ if(psk31_mod_settings && psk31_mod_settings->isSet()){ isObjectUpdated = true; break; } + if(psk31_demod_settings && psk31_demod_settings->isSet()){ + isObjectUpdated = true; break; + } if(radio_astronomy_settings && radio_astronomy_settings->isSet()){ isObjectUpdated = true; break; } @@ -1826,4 +1850,3 @@ SWGChannelSettings::isSet(){ return isObjectUpdated; } } - diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelSettings.h b/swagger/sdrangel/code/qt5/client/SWGChannelSettings.h index 9cc730aa1..c2b375730 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelSettings.h +++ b/swagger/sdrangel/code/qt5/client/SWGChannelSettings.h @@ -72,6 +72,7 @@ #include "SWGPacketModSettings.h" #include "SWGPagerDemodSettings.h" #include "SWGRTTYDemodSettings.h" +#include "SWGPSK31DemodSettings.h" #include "SWGRTTYModSettings.h" #include "SWGRadioAstronomySettings.h" #include "SWGRadioClockSettings.h" @@ -288,6 +289,9 @@ public: SWGRTTYDemodSettings* getRttyDemodSettings(); void setRttyDemodSettings(SWGRTTYDemodSettings* rtty_demod_settings); + SWGPSK31DemodSettings* getPSK31DemodSettings(); + void setPSK31DemodSettings(SWGPSK31DemodSettings* psk31_demod_settings); + SWGRTTYModSettings* getRttyModSettings(); void setRttyModSettings(SWGRTTYModSettings* rtty_mod_settings); @@ -502,6 +506,9 @@ private: SWGRTTYDemodSettings* rtty_demod_settings; bool m_rtty_demod_settings_isSet; + SWGPSK31DemodSettings* psk31_demod_settings; + bool m_psk31_demod_settings_isSet; + SWGRTTYModSettings* rtty_mod_settings; bool m_rtty_mod_settings_isSet; diff --git a/swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.cpp b/swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.cpp new file mode 100644 index 000000000..7f7b01eab --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.cpp @@ -0,0 +1,193 @@ +/** + * 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: 7.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 "SWGPSK31DemodReport.h" + +#include "SWGHelpers.h" + +#include +#include +#include +#include + +namespace SWGSDRangel { + +SWGPSK31DemodReport::SWGPSK31DemodReport(QString* json) { + init(); + this->fromJson(*json); +} + +SWGPSK31DemodReport::SWGPSK31DemodReport() { + channel_power_db = 0.0f; + m_channel_power_db_isSet = false; + channel_sample_rate = 0; + m_channel_sample_rate_isSet = false; + frequency_offset = 0.0f; + m_frequency_offset_isSet = false; + snr = 0.0f; + m_snr_isSet = false; + locked = 0; + m_locked_isSet = false; +} + +SWGPSK31DemodReport::~SWGPSK31DemodReport() { + this->cleanup(); +} + +void +SWGPSK31DemodReport::init() { + channel_power_db = 0.0f; + m_channel_power_db_isSet = false; + channel_sample_rate = 0; + m_channel_sample_rate_isSet = false; + frequency_offset = 0.0f; + m_frequency_offset_isSet = false; + snr = 0.0f; + m_snr_isSet = false; + locked = 0; + m_locked_isSet = false; +} + +void +SWGPSK31DemodReport::cleanup() { + + +} + +SWGPSK31DemodReport* +SWGPSK31DemodReport::fromJson(QString &json) { + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject jsonObject = doc.object(); + this->fromJsonObject(jsonObject); + return this; +} + +void +SWGPSK31DemodReport::fromJsonObject(QJsonObject &pJson) { + ::SWGSDRangel::setValue(&channel_power_db, pJson["channelPowerDB"], "float", ""); + + ::SWGSDRangel::setValue(&channel_sample_rate, pJson["channelSampleRate"], "qint32", ""); + ::SWGSDRangel::setValue(&frequency_offset, pJson["frequencyOffset"], "float", ""); + ::SWGSDRangel::setValue(&snr, pJson["snr"], "float", ""); + ::SWGSDRangel::setValue(&locked, pJson["locked"], "qint32", ""); + +} + +QString +SWGPSK31DemodReport::asJson () +{ + QJsonObject* obj = this->asJsonObject(); + + QJsonDocument doc(*obj); + QByteArray bytes = doc.toJson(); + delete obj; + return QString(bytes); +} + +QJsonObject* +SWGPSK31DemodReport::asJsonObject() { + QJsonObject* obj = new QJsonObject(); + if(m_channel_power_db_isSet){ + obj->insert("channelPowerDB", QJsonValue(channel_power_db)); + } + if(m_channel_sample_rate_isSet){ + obj->insert("channelSampleRate", QJsonValue(channel_sample_rate)); + } + if(m_frequency_offset_isSet){ + obj->insert("frequencyOffset", QJsonValue(frequency_offset)); + } + if(m_snr_isSet){ + obj->insert("snr", QJsonValue(snr)); + } + if(m_locked_isSet){ + obj->insert("locked", QJsonValue(locked)); + } + + return obj; +} + +float +SWGPSK31DemodReport::getChannelPowerDb() { + return channel_power_db; +} +void +SWGPSK31DemodReport::setChannelPowerDb(float channel_power_db) { + this->channel_power_db = channel_power_db; + this->m_channel_power_db_isSet = true; +} + +qint32 +SWGPSK31DemodReport::getChannelSampleRate() { + return channel_sample_rate; +} +void +SWGPSK31DemodReport::setChannelSampleRate(qint32 channel_sample_rate) { + this->channel_sample_rate = channel_sample_rate; + this->m_channel_sample_rate_isSet = true; +} + +float +SWGPSK31DemodReport::getFrequencyOffset() { + return frequency_offset; +} +void +SWGPSK31DemodReport::setFrequencyOffset(float frequency_offset) { + this->frequency_offset = frequency_offset; + this->m_frequency_offset_isSet = true; +} + +float +SWGPSK31DemodReport::getSnr() { + return snr; +} +void +SWGPSK31DemodReport::setSnr(float snr) { + this->snr = snr; + this->m_snr_isSet = true; +} + +qint32 +SWGPSK31DemodReport::getLocked() { + return locked; +} +void +SWGPSK31DemodReport::setLocked(qint32 locked) { + this->locked = locked; + this->m_locked_isSet = true; +} + + +bool +SWGPSK31DemodReport::isSet(){ + bool isObjectUpdated = false; + do{ + if(m_channel_power_db_isSet){ + isObjectUpdated = true; break; + } + if(m_channel_sample_rate_isSet){ + isObjectUpdated = true; break; + } + if(m_frequency_offset_isSet){ + isObjectUpdated = true; break; + } + if(m_snr_isSet){ + isObjectUpdated = true; break; + } + if(m_locked_isSet){ + isObjectUpdated = true; break; + } + }while(false); + return isObjectUpdated; +} +} diff --git a/swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.h b/swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.h new file mode 100644 index 000000000..5800e1566 --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.h @@ -0,0 +1,82 @@ +/** + * 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: 7.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. + */ + +/* + * SWGPSK31DemodReport.h + * + * PSK31Demod + */ + +#ifndef SWGPSK31DemodReport_H_ +#define SWGPSK31DemodReport_H_ + +#include + + + +#include "SWGObject.h" +#include "export.h" + +namespace SWGSDRangel { + +class SWG_API SWGPSK31DemodReport: public SWGObject { +public: + SWGPSK31DemodReport(); + SWGPSK31DemodReport(QString* json); + virtual ~SWGPSK31DemodReport(); + void init(); + void cleanup(); + + virtual QString asJson () override; + virtual QJsonObject* asJsonObject() override; + virtual void fromJsonObject(QJsonObject &json) override; + virtual SWGPSK31DemodReport* fromJson(QString &jsonString) override; + + float getChannelPowerDb(); + void setChannelPowerDb(float channel_power_db); + + qint32 getChannelSampleRate(); + void setChannelSampleRate(qint32 channel_sample_rate); + + float getFrequencyOffset(); + void setFrequencyOffset(float frequency_offset); + + float getSnr(); + void setSnr(float snr); + + qint32 getLocked(); + void setLocked(qint32 locked); + + + virtual bool isSet() override; + +private: + float channel_power_db; + bool m_channel_power_db_isSet; + + qint32 channel_sample_rate; + bool m_channel_sample_rate_isSet; + + float frequency_offset; + bool m_frequency_offset_isSet; + + float snr; + bool m_snr_isSet; + + qint32 locked; + bool m_locked_isSet; + +}; + +} + +#endif /* SWGPSK31DemodReport_H_ */ diff --git a/swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.cpp b/swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.cpp new file mode 100644 index 000000000..041c98e5d --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.cpp @@ -0,0 +1,520 @@ +/** + * 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: 7.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 "SWGPSK31DemodSettings.h" + +#include "SWGHelpers.h" + +#include +#include +#include +#include + +namespace SWGSDRangel { + +SWGPSK31DemodSettings::SWGPSK31DemodSettings(QString* json) { + init(); + this->fromJson(*json); +} + +SWGPSK31DemodSettings::SWGPSK31DemodSettings() { + input_frequency_offset = 0L; + m_input_frequency_offset_isSet = false; + rf_bandwidth = 0.0f; + m_rf_bandwidth_isSet = false; + udp_enabled = 0; + m_udp_enabled_isSet = false; + udp_address = nullptr; + m_udp_address_isSet = false; + udp_port = 0; + m_udp_port_isSet = false; + log_filename = nullptr; + m_log_filename_isSet = false; + log_enabled = 0; + m_log_enabled_isSet = false; + rgb_color = 0; + m_rgb_color_isSet = false; + title = nullptr; + m_title_isSet = false; + stream_index = 0; + m_stream_index_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_device_index = 0; + m_reverse_api_device_index_isSet = false; + reverse_api_channel_index = 0; + m_reverse_api_channel_index_isSet = false; + scope_config = nullptr; + m_scope_config_isSet = false; + channel_marker = nullptr; + m_channel_marker_isSet = false; + rollup_state = nullptr; + m_rollup_state_isSet = false; +} + +SWGPSK31DemodSettings::~SWGPSK31DemodSettings() { + this->cleanup(); +} + +void +SWGPSK31DemodSettings::init() { + input_frequency_offset = 0L; + m_input_frequency_offset_isSet = false; + rf_bandwidth = 0.0f; + m_rf_bandwidth_isSet = false; + udp_enabled = 0; + m_udp_enabled_isSet = false; + udp_address = new QString(""); + m_udp_address_isSet = false; + udp_port = 0; + m_udp_port_isSet = false; + log_filename = new QString(""); + m_log_filename_isSet = false; + log_enabled = 0; + m_log_enabled_isSet = false; + rgb_color = 0; + m_rgb_color_isSet = false; + title = new QString(""); + m_title_isSet = false; + stream_index = 0; + m_stream_index_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_device_index = 0; + m_reverse_api_device_index_isSet = false; + reverse_api_channel_index = 0; + m_reverse_api_channel_index_isSet = false; + scope_config = new SWGGLScope(); + m_scope_config_isSet = false; + channel_marker = new SWGChannelMarker(); + m_channel_marker_isSet = false; + rollup_state = new SWGRollupState(); + m_rollup_state_isSet = false; +} + +void +SWGPSK31DemodSettings::cleanup() { + + + + + + if(udp_address != nullptr) { + delete udp_address; + } + + + + + + + + if(log_filename != nullptr) { + delete log_filename; + } + + + if(title != nullptr) { + delete title; + } + + + if(reverse_api_address != nullptr) { + delete reverse_api_address; + } + + + + if(scope_config != nullptr) { + delete scope_config; + } + if(channel_marker != nullptr) { + delete channel_marker; + } + if(rollup_state != nullptr) { + delete rollup_state; + } +} + +SWGPSK31DemodSettings* +SWGPSK31DemodSettings::fromJson(QString &json) { + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject jsonObject = doc.object(); + this->fromJsonObject(jsonObject); + return this; +} + +void +SWGPSK31DemodSettings::fromJsonObject(QJsonObject &pJson) { + ::SWGSDRangel::setValue(&input_frequency_offset, pJson["inputFrequencyOffset"], "qint64", ""); + + ::SWGSDRangel::setValue(&rf_bandwidth, pJson["rfBandwidth"], "float", ""); + + ::SWGSDRangel::setValue(&udp_enabled, pJson["udpEnabled"], "qint32", ""); + + ::SWGSDRangel::setValue(&udp_address, pJson["udpAddress"], "QString", "QString"); + + ::SWGSDRangel::setValue(&udp_port, pJson["udpPort"], "qint32", ""); + + ::SWGSDRangel::setValue(&log_filename, pJson["logFilename"], "QString", "QString"); + + ::SWGSDRangel::setValue(&log_enabled, pJson["logEnabled"], "qint32", ""); + + ::SWGSDRangel::setValue(&rgb_color, pJson["rgbColor"], "qint32", ""); + + ::SWGSDRangel::setValue(&title, pJson["title"], "QString", "QString"); + + ::SWGSDRangel::setValue(&stream_index, pJson["streamIndex"], "qint32", ""); + + ::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_device_index, pJson["reverseAPIDeviceIndex"], "qint32", ""); + + ::SWGSDRangel::setValue(&reverse_api_channel_index, pJson["reverseAPIChannelIndex"], "qint32", ""); + + ::SWGSDRangel::setValue(&scope_config, pJson["scopeConfig"], "SWGGLScope", "SWGGLScope"); + + ::SWGSDRangel::setValue(&channel_marker, pJson["channelMarker"], "SWGChannelMarker", "SWGChannelMarker"); + + ::SWGSDRangel::setValue(&rollup_state, pJson["rollupState"], "SWGRollupState", "SWGRollupState"); + +} + +QString +SWGPSK31DemodSettings::asJson () +{ + QJsonObject* obj = this->asJsonObject(); + + QJsonDocument doc(*obj); + QByteArray bytes = doc.toJson(); + delete obj; + return QString(bytes); +} + +QJsonObject* +SWGPSK31DemodSettings::asJsonObject() { + QJsonObject* obj = new QJsonObject(); + if(m_input_frequency_offset_isSet){ + obj->insert("inputFrequencyOffset", QJsonValue(input_frequency_offset)); + } + if(m_rf_bandwidth_isSet){ + obj->insert("rfBandwidth", QJsonValue(rf_bandwidth)); + } + if(m_udp_enabled_isSet){ + obj->insert("udpEnabled", QJsonValue(udp_enabled)); + } + if(udp_address != nullptr && *udp_address != QString("")){ + toJsonValue(QString("udpAddress"), udp_address, obj, QString("QString")); + } + if(m_udp_port_isSet){ + obj->insert("udpPort", QJsonValue(udp_port)); + } + if(log_filename != nullptr && *log_filename != QString("")){ + toJsonValue(QString("logFilename"), log_filename, obj, QString("QString")); + } + if(m_log_enabled_isSet){ + obj->insert("logEnabled", QJsonValue(log_enabled)); + } + 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_stream_index_isSet){ + obj->insert("streamIndex", QJsonValue(stream_index)); + } + 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_device_index_isSet){ + obj->insert("reverseAPIDeviceIndex", QJsonValue(reverse_api_device_index)); + } + if(m_reverse_api_channel_index_isSet){ + obj->insert("reverseAPIChannelIndex", QJsonValue(reverse_api_channel_index)); + } + if((scope_config != nullptr) && (scope_config->isSet())){ + toJsonValue(QString("scopeConfig"), scope_config, obj, QString("SWGGLScope")); + } + if((channel_marker != nullptr) && (channel_marker->isSet())){ + toJsonValue(QString("channelMarker"), channel_marker, obj, QString("SWGChannelMarker")); + } + if((rollup_state != nullptr) && (rollup_state->isSet())){ + toJsonValue(QString("rollupState"), rollup_state, obj, QString("SWGRollupState")); + } + + return obj; +} + +qint64 +SWGPSK31DemodSettings::getInputFrequencyOffset() { + return input_frequency_offset; +} +void +SWGPSK31DemodSettings::setInputFrequencyOffset(qint64 input_frequency_offset) { + this->input_frequency_offset = input_frequency_offset; + this->m_input_frequency_offset_isSet = true; +} + +float +SWGPSK31DemodSettings::getRfBandwidth() { + return rf_bandwidth; +} +void +SWGPSK31DemodSettings::setRfBandwidth(float rf_bandwidth) { + this->rf_bandwidth = rf_bandwidth; + this->m_rf_bandwidth_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getUdpEnabled() { + return udp_enabled; +} +void +SWGPSK31DemodSettings::setUdpEnabled(qint32 udp_enabled) { + this->udp_enabled = udp_enabled; + this->m_udp_enabled_isSet = true; +} + +QString* +SWGPSK31DemodSettings::getUdpAddress() { + return udp_address; +} +void +SWGPSK31DemodSettings::setUdpAddress(QString* udp_address) { + this->udp_address = udp_address; + this->m_udp_address_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getUdpPort() { + return udp_port; +} +void +SWGPSK31DemodSettings::setUdpPort(qint32 udp_port) { + this->udp_port = udp_port; + this->m_udp_port_isSet = true; +} + +QString* +SWGPSK31DemodSettings::getLogFilename() { + return log_filename; +} +void +SWGPSK31DemodSettings::setLogFilename(QString* log_filename) { + this->log_filename = log_filename; + this->m_log_filename_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getLogEnabled() { + return log_enabled; +} +void +SWGPSK31DemodSettings::setLogEnabled(qint32 log_enabled) { + this->log_enabled = log_enabled; + this->m_log_enabled_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getRgbColor() { + return rgb_color; +} +void +SWGPSK31DemodSettings::setRgbColor(qint32 rgb_color) { + this->rgb_color = rgb_color; + this->m_rgb_color_isSet = true; +} + +QString* +SWGPSK31DemodSettings::getTitle() { + return title; +} +void +SWGPSK31DemodSettings::setTitle(QString* title) { + this->title = title; + this->m_title_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getStreamIndex() { + return stream_index; +} +void +SWGPSK31DemodSettings::setStreamIndex(qint32 stream_index) { + this->stream_index = stream_index; + this->m_stream_index_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getUseReverseApi() { + return use_reverse_api; +} +void +SWGPSK31DemodSettings::setUseReverseApi(qint32 use_reverse_api) { + this->use_reverse_api = use_reverse_api; + this->m_use_reverse_api_isSet = true; +} + +QString* +SWGPSK31DemodSettings::getReverseApiAddress() { + return reverse_api_address; +} +void +SWGPSK31DemodSettings::setReverseApiAddress(QString* reverse_api_address) { + this->reverse_api_address = reverse_api_address; + this->m_reverse_api_address_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getReverseApiPort() { + return reverse_api_port; +} +void +SWGPSK31DemodSettings::setReverseApiPort(qint32 reverse_api_port) { + this->reverse_api_port = reverse_api_port; + this->m_reverse_api_port_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getReverseApiDeviceIndex() { + return reverse_api_device_index; +} +void +SWGPSK31DemodSettings::setReverseApiDeviceIndex(qint32 reverse_api_device_index) { + this->reverse_api_device_index = reverse_api_device_index; + this->m_reverse_api_device_index_isSet = true; +} + +qint32 +SWGPSK31DemodSettings::getReverseApiChannelIndex() { + return reverse_api_channel_index; +} +void +SWGPSK31DemodSettings::setReverseApiChannelIndex(qint32 reverse_api_channel_index) { + this->reverse_api_channel_index = reverse_api_channel_index; + this->m_reverse_api_channel_index_isSet = true; +} + +SWGGLScope* +SWGPSK31DemodSettings::getScopeConfig() { + return scope_config; +} +void +SWGPSK31DemodSettings::setScopeConfig(SWGGLScope* scope_config) { + this->scope_config = scope_config; + this->m_scope_config_isSet = true; +} + +SWGChannelMarker* +SWGPSK31DemodSettings::getChannelMarker() { + return channel_marker; +} +void +SWGPSK31DemodSettings::setChannelMarker(SWGChannelMarker* channel_marker) { + this->channel_marker = channel_marker; + this->m_channel_marker_isSet = true; +} + +SWGRollupState* +SWGPSK31DemodSettings::getRollupState() { + return rollup_state; +} +void +SWGPSK31DemodSettings::setRollupState(SWGRollupState* rollup_state) { + this->rollup_state = rollup_state; + this->m_rollup_state_isSet = true; +} + + +bool +SWGPSK31DemodSettings::isSet(){ + bool isObjectUpdated = false; + do{ + if(m_input_frequency_offset_isSet){ + isObjectUpdated = true; break; + } + if(m_rf_bandwidth_isSet){ + isObjectUpdated = true; break; + } + if(m_udp_enabled_isSet){ + isObjectUpdated = true; break; + } + if(udp_address && *udp_address != QString("")){ + isObjectUpdated = true; break; + } + if(m_udp_port_isSet){ + isObjectUpdated = true; break; + } + if(log_filename && *log_filename != QString("")){ + isObjectUpdated = true; break; + } + if(m_log_enabled_isSet){ + isObjectUpdated = true; break; + } + if(m_rgb_color_isSet){ + isObjectUpdated = true; break; + } + if(title && *title != QString("")){ + isObjectUpdated = true; break; + } + if(m_stream_index_isSet){ + 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_device_index_isSet){ + isObjectUpdated = true; break; + } + if(m_reverse_api_channel_index_isSet){ + isObjectUpdated = true; break; + } + if(scope_config && scope_config->isSet()){ + isObjectUpdated = true; break; + } + if(channel_marker && channel_marker->isSet()){ + isObjectUpdated = true; break; + } + if(rollup_state && rollup_state->isSet()){ + isObjectUpdated = true; break; + } + }while(false); + return isObjectUpdated; +} +} diff --git a/swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.h b/swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.h new file mode 100644 index 000000000..cf3d732ef --- /dev/null +++ b/swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.h @@ -0,0 +1,164 @@ +/** + * 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: 7.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. + */ + +/* + * SWGPSK31DemodSettings.h + * + * PSK31Demod + */ + +#ifndef SWGPSK31DemodSettings_H_ +#define SWGPSK31DemodSettings_H_ + +#include + + +#include "SWGChannelMarker.h" +#include "SWGGLScope.h" +#include "SWGRollupState.h" +#include + +#include "SWGObject.h" +#include "export.h" + +namespace SWGSDRangel { + +class SWG_API SWGPSK31DemodSettings: public SWGObject { +public: + SWGPSK31DemodSettings(); + SWGPSK31DemodSettings(QString* json); + virtual ~SWGPSK31DemodSettings(); + void init(); + void cleanup(); + + virtual QString asJson () override; + virtual QJsonObject* asJsonObject() override; + virtual void fromJsonObject(QJsonObject &json) override; + virtual SWGPSK31DemodSettings* fromJson(QString &jsonString) override; + + qint64 getInputFrequencyOffset(); + void setInputFrequencyOffset(qint64 input_frequency_offset); + + float getRfBandwidth(); + void setRfBandwidth(float rf_bandwidth); + + qint32 getUdpEnabled(); + void setUdpEnabled(qint32 udp_enabled); + + QString* getUdpAddress(); + void setUdpAddress(QString* udp_address); + + qint32 getUdpPort(); + void setUdpPort(qint32 udp_port); + + QString* getLogFilename(); + void setLogFilename(QString* log_filename); + + qint32 getLogEnabled(); + void setLogEnabled(qint32 log_enabled); + + qint32 getRgbColor(); + void setRgbColor(qint32 rgb_color); + + QString* getTitle(); + void setTitle(QString* title); + + qint32 getStreamIndex(); + void setStreamIndex(qint32 stream_index); + + 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 getReverseApiDeviceIndex(); + void setReverseApiDeviceIndex(qint32 reverse_api_device_index); + + qint32 getReverseApiChannelIndex(); + void setReverseApiChannelIndex(qint32 reverse_api_channel_index); + + SWGGLScope* getScopeConfig(); + void setScopeConfig(SWGGLScope* scope_config); + + SWGChannelMarker* getChannelMarker(); + void setChannelMarker(SWGChannelMarker* channel_marker); + + SWGRollupState* getRollupState(); + void setRollupState(SWGRollupState* rollup_state); + + + virtual bool isSet() override; + +private: + qint64 input_frequency_offset; + bool m_input_frequency_offset_isSet; + + float rf_bandwidth; + bool m_rf_bandwidth_isSet; + + qint32 udp_enabled; + bool m_udp_enabled_isSet; + + QString* udp_address; + bool m_udp_address_isSet; + + qint32 udp_port; + bool m_udp_port_isSet; + + QString* log_filename; + bool m_log_filename_isSet; + + qint32 log_enabled; + bool m_log_enabled_isSet; + + qint32 rgb_color; + bool m_rgb_color_isSet; + + QString* title; + bool m_title_isSet; + + qint32 stream_index; + bool m_stream_index_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_device_index; + bool m_reverse_api_device_index_isSet; + + qint32 reverse_api_channel_index; + bool m_reverse_api_channel_index_isSet; + + SWGGLScope* scope_config; + bool m_scope_config_isSet; + + SWGChannelMarker* channel_marker; + bool m_channel_marker_isSet; + + SWGRollupState* rollup_state; + bool m_rollup_state_isSet; + +}; + +} + +#endif /* SWGPSK31DemodSettings_H_ */