Browse Source

Merge pull request #2966 from srcejon/psk31

Add PSK31 Demod
chirpmodem-v8.0.0
Edouard Griffiths 2 months ago committed by GitHub
parent
commit
b249ad9c7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CMakeLists.txt
  2. BIN
      doc/img/PSK31Demod_plugin.png
  3. 6
      plugins/channelrx/CMakeLists.txt
  4. 73
      plugins/channelrx/demodpsk31/CMakeLists.txt
  5. 722
      plugins/channelrx/demodpsk31/psk31demod.cpp
  6. 229
      plugins/channelrx/demodpsk31/psk31demod.h
  7. 180
      plugins/channelrx/demodpsk31/psk31demodbaseband.cpp
  8. 105
      plugins/channelrx/demodpsk31/psk31demodbaseband.h
  9. 528
      plugins/channelrx/demodpsk31/psk31demodgui.cpp
  10. 116
      plugins/channelrx/demodpsk31/psk31demodgui.h
  11. 623
      plugins/channelrx/demodpsk31/psk31demodgui.ui
  12. 93
      plugins/channelrx/demodpsk31/psk31demodplugin.cpp
  13. 51
      plugins/channelrx/demodpsk31/psk31demodplugin.h
  14. 311
      plugins/channelrx/demodpsk31/psk31demodsettings.cpp
  15. 71
      plugins/channelrx/demodpsk31/psk31demodsettings.h
  16. 107
      plugins/channelrx/demodpsk31/psk31demodsink.cpp
  17. 69
      plugins/channelrx/demodpsk31/psk31demodsink.h
  18. 646
      plugins/channelrx/demodpsk31/psk31demodulator.cpp
  19. 195
      plugins/channelrx/demodpsk31/psk31demodulator.h
  20. 53
      plugins/channelrx/demodpsk31/psk31demodwebapiadapter.cpp
  21. 51
      plugins/channelrx/demodpsk31/psk31demodwebapiadapter.h
  22. 138
      plugins/channelrx/demodpsk31/readme.md
  23. 4
      plugins/channelrx/demodrtty/rttydemodsettings.cpp
  24. 14
      plugins/channeltx/modpsk31/psk31mod.cpp
  25. 2
      plugins/channeltx/modpsk31/psk31modgui.cpp
  26. 18
      plugins/channeltx/modpsk31/psk31modsettings.cpp
  27. 2
      plugins/channeltx/modpsk31/psk31modsettings.h
  28. 17
      plugins/channeltx/modpsk31/psk31modsource.cpp
  29. 4
      plugins/channeltx/modpsk31/psk31modtxsettingsdialog.cpp
  30. 26
      plugins/channeltx/modpsk31/psk31modtxsettingsdialog.ui
  31. 1
      sdrbase/dsp/costasloop.h
  32. 1
      sdrbase/resources/webapi.qrc
  33. 3
      sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml
  34. 3
      sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml
  35. 95
      sdrbase/resources/webapi/doc/swagger/include/PSK31Demod.yaml
  36. 10
      sdrbase/resources/webapi/doc/swagger/include/PSK31Mod.yaml
  37. 86
      sdrbase/util/psk31.cpp
  38. 20
      sdrbase/util/psk31.h
  39. 6
      sdrbase/webapi/webapirequestmapper.cpp
  40. 2
      sdrbase/webapi/webapiutils.cpp
  41. 3
      sdrbench/CMakeLists.txt
  42. 2
      sdrbench/mainbench.cpp
  43. 1
      sdrbench/mainbench.h
  44. 4
      sdrbench/parserbench.cpp
  45. 3
      sdrbench/parserbench.h
  46. 902
      sdrbench/test_psk31.cpp
  47. 219
      sdrgui/gui/acronymview.cpp
  48. 18
      sdrgui/gui/acronymview.h
  49. 3
      swagger/sdrangel/api/swagger/include/ChannelReport.yaml
  50. 3
      swagger/sdrangel/api/swagger/include/ChannelSettings.yaml
  51. 95
      swagger/sdrangel/api/swagger/include/PSK31Demod.yaml
  52. 10
      swagger/sdrangel/api/swagger/include/PSK31Mod.yaml
  53. 25
      swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp
  54. 7
      swagger/sdrangel/code/qt5/client/SWGChannelReport.h
  55. 25
      swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp
  56. 7
      swagger/sdrangel/code/qt5/client/SWGChannelSettings.h
  57. 193
      swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.cpp
  58. 82
      swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.h
  59. 520
      swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.cpp
  60. 164
      swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.h
  61. 45
      swagger/sdrangel/code/qt5/client/SWGPSK31ModSettings.cpp
  62. 12
      swagger/sdrangel/code/qt5/client/SWGPSK31ModSettings.h

1
CMakeLists.txt

@ -166,6 +166,7 @@ option(ENABLE_CHANNELRX_DEMODDSD "Enable channelrx demoddsd plugin" ON) @@ -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)

BIN
doc/img/PSK31Demod_plugin.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

6
plugins/channelrx/CMakeLists.txt

@ -211,6 +211,12 @@ else() @@ -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()

73
plugins/channelrx/demodpsk31/CMakeLists.txt

@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
project(demodpsk31)
set(demodpsk31_SOURCES
psk31demod.cpp
psk31demodsettings.cpp
psk31demodbaseband.cpp
psk31demodsink.cpp
psk31demodulator.cpp
psk31demodplugin.cpp
psk31demodwebapiadapter.cpp
)
set(demodpsk31_HEADERS
psk31demod.h
psk31demodsettings.h
psk31demodbaseband.h
psk31demodsink.h
psk31demodulator.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_PROPERTY:${TARGET_NAME},RUNTIME_OUTPUT_DIRECTORY>/${TARGET_NAME}stripped.pdb CONFIGURATIONS Release DESTINATION ${INSTALL_FOLDER} RENAME ${TARGET_NAME}.pdb )
install(FILES $<TARGET_PDB_FILE:${TARGET_NAME}> CONFIGURATIONS Debug RelWithDebInfo DESTINATION ${INSTALL_FOLDER} )
endif()

722
plugins/channelrx/demodpsk31/psk31demod.cpp

@ -0,0 +1,722 @@ @@ -0,0 +1,722 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "psk31demod.h"
#include <QTime>
#include <QDebug>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QBuffer>
#include <QThread>
#include <stdio.h>
#include <complex.h>
#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() && !report.getCharacter().isEmpty())
{
const QChar character = report.getCharacter()[0];
m_logStream << displayText(character, m_previousLogCharacter);
m_logStream.flush();
m_previousLogCharacter = character;
}
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;
}
}
QString PSK31Demod::displayText(QChar character, QChar previousCharacter)
{
if (character == '\r') {
return QStringLiteral("\n");
} else if (character == '\n') {
return previousCharacter == '\r' ? QString() : QStringLiteral("\n");
} else if ((character == '\t') || character.isPrint()) {
return QString(character);
} else {
return QString();
}
}
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<ObjectPipe*> pipes;
MainCore::instance()->getMessagePipes().getMessagePipes(this, "reportdemod", pipes);
if (pipes.size() > 0)
{
for (const auto& pipe : pipes)
{
MessageQueue *messageQueue = qobject_cast<MessageQueue*>(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()->setLocked(isLocked() ? 1 : 0);
// Only meaningful when a signal is being received
if (isLocked())
{
response.getPSK31DemodReport()->setFrequencyOffset(getFrequencyOffset());
response.getPSK31DemodReport()->setSnr(getSNR());
}
}
void PSK31Demod::webapiReverseSendSettings(const QList<QString>& 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<QString>& 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);
}

229
plugins/channelrx/demodpsk31/psk31demod.h

@ -0,0 +1,229 @@ @@ -0,0 +1,229 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_PSK31DEMOD_H
#define INCLUDE_PSK31DEMOD_H
#include <QNetworkRequest>
#include <QUdpSocket>
#include <QThread>
#include <QFile>
#include <QTextStream>
#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;
// Text to display for a received character. Senders usually end lines
// with CR LF, so CR, LF and CR LF each give a single newline. Other
// control characters, which are most likely noise, give nothing.
static QString displayText(QChar character, QChar previousCharacter);
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;
QChar m_previousLogCharacter;
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<QString>& channelSettingsKeys, const PSK31DemodSettings& settings, bool force);
void webapiFormatChannelSettings(
const QList<QString>& 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

180
plugins/channelrx/demodpsk31/psk31demodbaseband.cpp

@ -0,0 +1,180 @@ @@ -0,0 +1,180 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QDebug>
#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());
}

105
plugins/channelrx/demodpsk31/psk31demodbaseband.h

@ -0,0 +1,105 @@ @@ -0,0 +1,105 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_PSK31DEMODBASEBAND_H
#define INCLUDE_PSK31DEMODBASEBAND_H
#include <QObject>
#include <QRecursiveMutex>
#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

528
plugins/channelrx/demodpsk31/psk31demodgui.cpp

@ -0,0 +1,528 @@ @@ -0,0 +1,528 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QDockWidget>
#include <QMainWindow>
#include <QDebug>
#include <QAction>
#include <QClipboard>
#include <QFileDialog>
#include <QScrollBar>
#include <QMenu>
#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);
const QChar character = c.isEmpty() ? QChar() : c[0];
if (character == '\b')
{
ui->text->textCursor().deletePreviousChar();
}
else
{
const QString text = PSK31Demod::displayText(character, m_previousCharacter);
if (!text.isEmpty()) {
ui->text->insertPlainText(text);
}
}
m_previousCharacter = character;
// 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<const ChannelMarker*>(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<PSK31Demod*>(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);
}

116
plugins/channelrx/demodpsk31/psk31demodgui.h

@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#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;
QChar m_previousCharacter;
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

623
plugins/channelrx/demodpsk31/psk31demodgui.ui

@ -0,0 +1,623 @@ @@ -0,0 +1,623 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PSK31DemodGUI</class>
<widget class="RollupContents" name="PSK31DemodGUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>411</width>
<height>814</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>352</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Sans</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::StrongFocus</enum>
</property>
<property name="windowTitle">
<string>Packet Demodulator</string>
</property>
<widget class="QWidget" name="settingsContainer" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>181</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>350</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="powLayout">
<property name="topMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="deltaFrequencyLabel">
<property name="minimumSize">
<size>
<width>16</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Df</string>
</property>
</widget>
</item>
<item>
<widget class="ValueDialZ" name="deltaFrequency" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Mono</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::StrongFocus</enum>
</property>
<property name="toolTip">
<string>Demod shift frequency from center in Hz</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="deltaUnits">
<property name="text">
<string>Hz </string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="channelPowerLayout">
<item>
<widget class="QLabel" name="channelPower">
<property name="toolTip">
<string>Channel power</string>
</property>
<property name="layoutDirection">
<enum>Qt::LayoutDirection::RightToLeft</enum>
</property>
<property name="text">
<string>0.0</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="channelPowerUnits">
<property name="text">
<string> dB</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="powerLayout">
<item>
<widget class="QLabel" name="channelPowerMeterUnits">
<property name="text">
<string>dB</string>
</property>
</widget>
</item>
<item>
<widget class="LevelMeterSignalDB" name="channelPowerMeter" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>24</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Mono</family>
<pointsize>8</pointsize>
</font>
</property>
<property name="toolTip">
<string>Level meter (dB) top trace: average, bottom trace: instantaneous peak, tip: peak hold</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="phySettingsLayout">
<item>
<widget class="QLabel" name="rfBWLabel">
<property name="text">
<string>BW</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="rfBW">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>RF bandwidth</string>
</property>
<property name="minimum">
<number>50</number>
</property>
<property name="maximum">
<number>500</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>250</number>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="rfBWText">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>500Hz</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="udpLayout">
<item>
<widget class="QCheckBox" name="udpEnabled">
<property name="toolTip">
<string>Send messages via UDP</string>
</property>
<property name="layoutDirection">
<enum>Qt::LayoutDirection::RightToLeft</enum>
</property>
<property name="text">
<string>UDP</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="udpAddress">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Destination UDP address</string>
</property>
<property name="inputMask">
<string>000.000.000.000</string>
</property>
<property name="text">
<string>127.0.0.1</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="udpSeparator">
<property name="text">
<string>:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="udpPort">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Destination UDP port</string>
</property>
<property name="inputMask">
<string>00000</string>
</property>
<property name="text">
<string>9998</string>
</property>
</widget>
</item>
<item>
<spacer name="udpSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="toolbarLayout">
<item>
<widget class="QLabel" name="carrierStatusLabel">
<property name="text">
<string>Carrier</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="carrierStatus">
<property name="toolTip">
<string>Carrier status</string>
</property>
<property name="text">
<string>Unlocked</string>
</property>
</widget>
</item>
<item>
<spacer name="toolbarSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="ButtonSwitch" name="logEnable">
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Start/stop logging of received characters to .txt file</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../sdrgui/resources/res.qrc">
<normaloff>:/record_off.png</normaloff>:/record_off.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="logFilename">
<property name="toolTip">
<string>Set log .csv filename</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../sdrgui/resources/res.qrc">
<normaloff>:/save.png</normaloff>:/save.png</iconset>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearTable">
<property name="toolTip">
<string>Clear messages</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../sdrgui/resources/res.qrc">
<normaloff>:/bin.png</normaloff>:/bin.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="dataContainer" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>190</y>
<width>391</width>
<height>251</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Received Messages</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="AcronymView" name="text">
<property name="toolTip">
<string>Received text</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="scopeContainer" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>440</y>
<width>716</width>
<height>341</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>714</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Waveforms</string>
</property>
<layout class="QVBoxLayout" name="transmittedLayout_2">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="GLScope" name="glScope" native="true">
<property name="minimumSize">
<size>
<width>200</width>
<height>250</height>
</size>
</property>
<property name="font">
<font>
<family>Liberation Mono</family>
<pointsize>8</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="GLScopeGUI" name="scopeGUI" native="true"/>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>RollupContents</class>
<extends>QWidget</extends>
<header>gui/rollupcontents.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ValueDialZ</class>
<extends>QWidget</extends>
<header>gui/valuedialz.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ButtonSwitch</class>
<extends>QToolButton</extends>
<header>gui/buttonswitch.h</header>
</customwidget>
<customwidget>
<class>LevelMeterSignalDB</class>
<extends>QWidget</extends>
<header>gui/levelmeter.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>GLScope</class>
<extends>QWidget</extends>
<header>gui/glscope.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>GLScopeGUI</class>
<extends>QWidget</extends>
<header>gui/glscopegui.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>AcronymView</class>
<extends>QTextEdit</extends>
<header>gui/acronymview.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>deltaFrequency</tabstop>
<tabstop>rfBW</tabstop>
<tabstop>udpEnabled</tabstop>
<tabstop>logEnable</tabstop>
<tabstop>logFilename</tabstop>
<tabstop>clearTable</tabstop>
<tabstop>text</tabstop>
</tabstops>
<resources>
<include location="../../../sdrgui/resources/res.qrc"/>
</resources>
<connections/>
</ui>

93
plugins/channelrx/demodpsk31/psk31demodplugin.cpp

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QtPlugin>
#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();
}

51
plugins/channelrx/demodpsk31/psk31demodplugin.h

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_PSK31DEMODPLUGIN_H
#define INCLUDE_PSK31DEMODPLUGIN_H
#include <QObject>
#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

311
plugins/channelrx/demodpsk31/psk31demodsettings.cpp

@ -0,0 +1,311 @@ @@ -0,0 +1,311 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QColor>
#include <algorithm>
#include <cmath>
#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());
}

71
plugins/channelrx/demodpsk31/psk31demodsettings.h

@ -0,0 +1,71 @@ @@ -0,0 +1,71 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_PSK31DEMODSETTINGS_H
#define INCLUDE_PSK31DEMODSETTINGS_H
#include <QByteArray>
#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 */

107
plugins/channelrx/demodpsk31/psk31demodsink.cpp

@ -0,0 +1,107 @@ @@ -0,0 +1,107 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "dsp/scopevis.h"
#include "psk31demod.h"
#include "psk31demodsink.h"
PSK31DemodSink::PSK31DemodSink() :
m_scopeSink(nullptr),
m_messageQueueToChannel(nullptr),
m_channelSampleRate(PSK31DemodSettings::PSK31DEMOD_CHANNEL_SAMPLE_RATE),
m_channelFrequencyOffset(0),
m_scopeBufferIndex(0)
{
m_scopeBuffer.resize(m_scopeBufferSize);
m_demodulator.setCharacterCallback([this](QChar character) { characterReceived(character); });
m_demodulator.setReportCallback([this]() { report(); });
m_demodulator.setScopeCallback([this](const Complex& sample) { sampleToScope(sample); });
applySettings(QStringList(), m_settings, true);
applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true);
}
void PSK31DemodSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
{
m_demodulator.feed(begin, end);
}
void PSK31DemodSink::characterReceived(QChar character)
{
if (m_messageQueueToChannel) {
m_messageQueueToChannel->push(PSK31Demod::MsgCharacter::create(QString(character)));
}
}
void PSK31DemodSink::report()
{
if (m_messageQueueToChannel)
{
m_messageQueueToChannel->push(PSK31Demod::MsgDemodReport::create(
m_demodulator.getFrequencyOffset(),
m_demodulator.getSNR(),
m_demodulator.isLocked()));
}
}
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<SampleVector::const_iterator> 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_demodulator.setChannel(channelSampleRate, channelFrequencyOffset);
m_channelSampleRate = channelSampleRate;
m_channelFrequencyOffset = channelFrequencyOffset;
}
}
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_demodulator.setRFBandwidth(validatedSettings.m_rfBandwidth);
}
if (force) {
m_settings = validatedSettings;
} else {
m_settings.applySettings(settingsKeys, validatedSettings);
}
}

69
plugins/channelrx/demodpsk31/psk31demodsink.h

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_PSK31DEMODSINK_H
#define INCLUDE_PSK31DEMODSINK_H
#include "dsp/channelsamplesink.h"
#include "util/messagequeue.h"
#include "psk31demodsettings.h"
#include "psk31demodulator.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; }
double getMagSq() const { return m_demodulator.getMagSq(); }
float getFrequencyOffset() const { return m_demodulator.getFrequencyOffset(); }
float getSNR() const { return m_demodulator.getSNR(); }
bool isLocked() const { return m_demodulator.isLocked(); }
void getMagSqLevels(double& avg, double& peak, int& nbSamples) {
m_demodulator.getMagSqLevels(avg, peak, nbSamples);
}
private:
static const int m_scopeBufferSize = 50;
ScopeVis *m_scopeSink;
MessageQueue *m_messageQueueToChannel;
PSK31DemodSettings m_settings;
int m_channelSampleRate;
int m_channelFrequencyOffset;
PSK31Demodulator m_demodulator;
SampleVector m_scopeBuffer;
int m_scopeBufferIndex;
void characterReceived(QChar character);
void report();
void sampleToScope(const Complex& sample);
};
#endif // INCLUDE_PSK31DEMODSINK_H

646
plugins/channelrx/demodpsk31/psk31demodulator.cpp

@ -0,0 +1,646 @@ @@ -0,0 +1,646 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <cmath>
#include "psk31demodulator.h"
PSK31Demodulator::PSK31Demodulator() :
m_rfBandwidth(100.0f),
m_channelSampleRate(m_sampleRate),
m_channelFrequencyOffset(0),
m_interpolatorDistance(1.0f),
m_interpolatorDistanceRemain(1.0f),
m_costasLoop(2.0f * M_PI / 300.0f, 2),
m_maxFrequency(0.0f),
m_trackingCutoff(0.0f),
m_trackingNoiseBandwidth(1.0f),
m_afcFrequency(0.0f),
m_afcPhase(0.0f),
m_magsq(0.0),
m_magsqSum(0.0),
m_magsqPeak(0.0),
m_magsqCount(0),
m_afcIndex(0),
m_afcCount(0),
m_afcCandidate(0.0f),
m_afcCandidateValid(false),
m_matchedFilterIndex(0),
m_historyIndex(0),
m_symbolPower(0.0f),
m_clockCount(0.0f),
m_timingIntegrator(0.0f),
m_lockMetric(0.0f),
m_lockCount(0),
m_presentCount(0),
m_unlockCount(0),
m_lockedLevel(0.0f),
m_locked(false),
m_snrInPhaseSum(0.0),
m_snrQuadratureSum(0.0),
m_snrCount(0),
m_snrSignalPower(0.0),
m_snrNoisePower(0.0),
m_snrAverageValid(false),
m_snr(0.0f),
m_reportSampleCount(0)
{
// PSK31 shapes each phase reversal with a cosine envelope, so each symbol
// is a raised cosine pulse spanning two symbol periods. Matching it
// restricts the noise at the decision point to roughly the symbol rate.
const int matchedFilterLength = 2 * m_samplesPerSymbol + 1;
m_matchedFilterTaps.resize(matchedFilterLength);
Real sum = 0.0f;
for (int i = 0; i < matchedFilterLength; ++i)
{
m_matchedFilterTaps[i] = 0.5f - 0.5f * std::cos(2.0f * M_PI * i / (matchedFilterLength - 1));
sum += m_matchedFilterTaps[i];
}
for (auto& tap : m_matchedFilterTaps) {
tap /= sum;
}
m_matchedFilterSamples.resize(matchedFilterLength);
m_history.resize(m_samplesPerSymbol + 1);
m_afcBuffer.resize(m_afcLength);
m_afcTwiddle.resize(m_afcLength);
m_afcWindow.resize(m_afcLength);
for (int i = 0; i < m_afcLength; ++i)
{
m_afcTwiddle[i] = Complex(std::cos(2.0 * M_PI * i / m_afcLength), -std::sin(2.0 * M_PI * i / m_afcLength));
m_afcWindow[i] = 0.5f - 0.5f * std::cos(2.0f * M_PI * i / m_afcLength);
}
setRFBandwidth(m_rfBandwidth);
setChannel(m_channelSampleRate, m_channelFrequencyOffset);
}
void PSK31Demodulator::setChannel(int channelSampleRate, int channelFrequencyOffset)
{
m_nco.setFreq(-channelFrequencyOffset, channelSampleRate);
m_interpolator.create(32, channelSampleRate, m_rfBandwidth / 2.0f);
m_interpolatorDistance = static_cast<Real>(channelSampleRate) / m_sampleRate;
m_interpolatorDistanceRemain = m_interpolatorDistance;
m_channelSampleRate = channelSampleRate;
m_channelFrequencyOffset = channelFrequencyOffset;
reset();
}
void PSK31Demodulator::setRFBandwidth(Real rfBandwidth)
{
m_rfBandwidth = std::isfinite(rfBandwidth) ? std::clamp(rfBandwidth, 20.0f, m_sampleRate / 2.0f) : 100.0f;
m_interpolator.create(32, m_channelSampleRate, m_rfBandwidth / 2.0f);
m_channelFilter.create(m_channelFilterTaps, m_sampleRate, m_rfBandwidth / 2.0f);
m_trackingCutoff = std::min(m_trackingBandwidth, m_rfBandwidth) / 2.0f;
m_trackingFilter.create(m_channelFilterTaps, m_sampleRate, m_trackingCutoff);
// Equivalent noise bandwidth of the tracking filter, for SNR normalization
std::vector<Real> taps;
FirFilterGenerators::generateLowPassFilter(m_channelFilterTaps, m_sampleRate, m_trackingCutoff, taps);
double sum = 0.0;
double sumSquares = 0.0;
for (size_t i = 0; i < taps.size(); ++i)
{
// Only half the symmetric taps are stored. The last is the center.
const int weight = (i == taps.size() - 1) ? 1 : 2;
sum += weight * taps[i];
sumSquares += weight * taps[i] * taps[i];
}
m_trackingNoiseBandwidth = m_sampleRate * sumSquares / (sum * sum);
// Leave room for the signal's main lobe inside the channel filter.
m_maxFrequency = std::max(5.0f, m_rfBandwidth / 2.0f - 15.0f);
m_costasLoop.setMaxFreq(m_costasRange * 2.0f * M_PI / m_sampleRate);
m_costasLoop.setMinFreq(-m_costasRange * 2.0f * M_PI / m_sampleRate);
resetSNR();
m_snrAverageValid = false;
m_snr = 0.0f;
m_reportSampleCount = 0;
}
void PSK31Demodulator::reset()
{
m_costasLoop.reset();
m_lockMetric = 0.0f;
m_levelAverage.reset();
m_signalLevelAverage.reset();
m_lockCount = 0;
m_presentCount = 0;
m_unlockCount = 0;
m_lockedLevel = 0.0f;
m_locked = false;
m_pendingCharacters.clear();
m_acquisitionSymbols.clear();
m_decoder.reset();
resetSNR();
m_snrAverageValid = false;
m_snr = 0.0f;
m_clockCount = m_samplesPerSymbol / 2;
m_timingIntegrator = 0.0f;
m_symbolPower = 0.0f;
m_afcFrequency = 0.0f;
m_afcPhase = 0.0f;
std::fill(m_matchedFilterSamples.begin(), m_matchedFilterSamples.end(), Complex(0.0f, 0.0f));
std::fill(m_history.begin(), m_history.end(), 0.0f);
std::fill(m_afcBuffer.begin(), m_afcBuffer.end(), Complex(0.0f, 0.0f));
m_afcIndex = 0;
m_afcCount = 0;
m_afcCandidate = 0.0f;
m_afcCandidateValid = false;
}
void PSK31Demodulator::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))
{
processSample(output / SDR_RX_SCALEF);
m_interpolatorDistanceRemain += m_interpolatorDistance;
}
}
else if (m_interpolator.decimate(&m_interpolatorDistanceRemain, sample, &output))
{
processSample(output / SDR_RX_SCALEF);
m_interpolatorDistanceRemain += m_interpolatorDistance;
}
}
}
void PSK31Demodulator::processSample(const Complex& input)
{
// Measure levels after the channel filter so signals outside the RF
// bandwidth do not reduce loop gain or distort the channel power reading.
const Complex sample = m_channelFilter.filter(input);
const Real magsq = std::norm(sample);
m_movingAverage(magsq);
m_magsq = m_movingAverage.asDouble();
m_magsqSum += magsq;
m_magsqPeak = std::max(m_magsqPeak, static_cast<double>(magsq));
++m_magsqCount;
if (m_magsqCount >= m_sampleRate / 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;
}
acquireCarrier(sample);
// Move the acquired carrier to the center of the narrower tracking filter,
// which keeps adjacent signals out of the carrier and timing loops.
m_afcPhase += m_afcFrequency;
if (m_afcPhase > M_PI) {
m_afcPhase -= 2.0f * M_PI;
} else if (m_afcPhase < -M_PI) {
m_afcPhase += 2.0f * M_PI;
}
const Complex tracked = m_trackingFilter.filter(sample * Complex(std::cos(m_afcPhase), -std::sin(m_afcPhase)));
// The Costas detector gain is proportional to input power. Normalize over
// two symbols so acquisition bandwidth does not depend on signal level.
m_levelAverage(std::norm(tracked));
m_signalLevelAverage(std::norm(tracked));
const Real scale = 1.0f / std::sqrt(std::max(m_levelAverage.asDouble(), 1.0e-20));
const Complex normalized = tracked * scale;
m_costasLoop.feed(normalized.real(), normalized.imag());
if (m_locked)
{
// Slowly move the Costas loop's frequency into the AFC, so the signal
// stays centered in the tracking filter as it drifts.
const Real transfer = m_costasLoop.getFreq() * m_afcTransferRate;
m_afcFrequency += transfer;
m_costasLoop.setFreq(m_costasLoop.getFreq() - transfer);
}
const Complex corrected = normalized * -std::conj(m_costasLoop.getComplex());
const Complex symbolValue = matchedFilter(corrected);
const Real filtered = symbolValue.real();
m_historyIndex = (m_historyIndex + 1) % m_history.size();
m_history[m_historyIndex] = filtered;
bool symbolSample = false;
m_clockCount -= 1.0f;
if (m_clockCount <= 0.0f)
{
// Gardner timing error: the matched filter output half way between
// opposite symbols should be zero. Transitions provide the timing
// information, so steady carrier leaves the clock free running.
const int size = m_history.size();
const Real previous = m_history[(m_historyIndex + 1) % size];
const Real middle = m_history[(m_historyIndex + 1 + m_samplesPerSymbol / 2) % size];
m_symbolPower += 0.05f * (filtered * filtered - m_symbolPower);
const Real timingError = m_symbolPower > 0.0f
? std::clamp(middle * (previous - filtered) / m_symbolPower, -m_maxTimingError, m_maxTimingError)
: 0.0f;
// Proportional plus integral, so a sample clock offset between
// transmitter and receiver does not leave a steady timing error.
m_timingIntegrator = std::clamp(
m_timingIntegrator + m_timingIntegralGain * timingError,
-m_maxTimingRate,
m_maxTimingRate);
m_clockCount += m_samplesPerSymbol + m_timingGain * timingError + m_timingIntegrator;
symbol(symbolValue);
symbolSample = true;
}
if (m_locked && (m_unlockCount == 0))
{
m_snrInPhaseSum += corrected.real() * corrected.real();
m_snrQuadratureSum += corrected.imag() * corrected.imag();
++m_snrCount;
}
if (++m_reportSampleCount >= m_sampleRate)
{
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 noisePower = std::max(2.0 * quadraturePower, 1.0e-20);
// Average over a few seconds for a steadier reading
if (m_snrAverageValid)
{
m_snrSignalPower += 0.5 * (signalPower - m_snrSignalPower);
m_snrNoisePower += 0.5 * (noisePower - m_snrNoisePower);
}
else
{
m_snrSignalPower = signalPower;
m_snrNoisePower = noisePower;
m_snrAverageValid = true;
}
const double referenceNoisePower = m_snrNoisePower * m_snrReferenceBandwidth / m_trackingNoiseBandwidth;
m_snr = std::clamp(
static_cast<float>(10.0 * std::log10(m_snrSignalPower / referenceNoisePower)),
-99.9f,
99.9f);
resetSNR();
}
if (m_reportCallback) {
m_reportCallback();
}
m_reportSampleCount = 0;
}
if (m_scopeCallback)
{
const Real normalizedFiltered = m_symbolPower > 0.0f ? filtered / std::sqrt(m_symbolPower) : 0.0f;
m_scopeCallback(Complex(normalizedFiltered, symbolSample ? 1.0f : 0.0f));
}
}
void PSK31Demodulator::acquireCarrier(const Complex& sample)
{
// Squaring BPSK removes the modulation, leaving a tone at twice the
// carrier offset. Search for it and tune there, as the Costas loop itself
// only pulls in over a few Hz.
m_afcBuffer[m_afcIndex] = sample * sample;
m_afcIndex = (m_afcIndex + 1) % m_afcLength;
if (m_afcCount < m_afcLength)
{
++m_afcCount;
return;
}
if ((m_afcIndex % m_afcInterval) != 0) {
return;
}
const Real current = getFrequencyOffset();
if (m_locked)
{
checkIdleToneLock(current);
return;
}
const int maxBin = static_cast<int>(2.0f * m_maxFrequency * m_afcLength / m_sampleRate);
int peakBin = -maxBin;
Real peakPower = 0.0f;
m_afcPowers.resize(2 * maxBin + 1);
for (int bin = -maxBin; bin <= maxBin; ++bin)
{
const Real power = afcPower(bin);
m_afcPowers[bin + maxBin] = power;
if (power > peakPower)
{
peakPower = power;
peakBin = bin;
}
}
// Compare against the median, as the signal's own tones would inflate a mean.
m_afcSorted = m_afcPowers;
std::nth_element(m_afcSorted.begin(), m_afcSorted.begin() + m_afcSorted.size() / 2, m_afcSorted.end());
const Real noisePower = m_afcSorted[m_afcSorted.size() / 2];
if ((noisePower <= 0.0f) || (peakPower < m_afcThreshold * noisePower)) {
return;
}
// Parabolic interpolation between bins
Real delta = 0.0f;
if ((peakBin > -maxBin) && (peakBin < maxBin))
{
const Real left = m_afcPowers[peakBin + maxBin - 1];
const Real right = m_afcPowers[peakBin + maxBin + 1];
const Real denominator = left - 2.0f * peakPower + right;
if (denominator != 0.0f) {
delta = std::clamp(0.5f * (left - right) / denominator, -0.5f, 0.5f);
}
}
const Real frequency = std::clamp(
(peakBin + delta) * m_sampleRate / (2.0f * m_afcLength),
-m_maxFrequency,
m_maxFrequency);
if (std::abs(frequency - current) > m_afcRetuneHz) {
retune(frequency);
}
}
void PSK31Demodulator::checkIdleToneLock(Real current)
{
// An idle signal is two tones, one symbol rate apart. To the Costas loop,
// either looks like an unmodulated carrier, so it can lock 15.6 Hz from the
// true carrier. Squared, the true carrier's tone is then 6 dB stronger than
// the one at our frequency. Only these bins are checked, so strong signals
// elsewhere in the RF bandwidth can't pull us away once locked.
const int centerBin = static_cast<int>(std::lround(2.0f * current * m_afcLength / m_sampleRate));
const int offsetBins = static_cast<int>(std::lround(m_sampleRate / static_cast<Real>(m_samplesPerSymbol) * m_afcLength / m_sampleRate));
const int maxBin = static_cast<int>(2.0f * m_maxFrequency * m_afcLength / m_sampleRate);
Real centerPower = 0.0f;
Real sidePower = 0.0f;
int sideBin = 0;
for (int bin = centerBin - 1; bin <= centerBin + 1; ++bin) {
centerPower = std::max(centerPower, afcPower(bin));
}
for (int side : {centerBin - offsetBins, centerBin + offsetBins})
{
for (int bin = side - 1; bin <= side + 1; ++bin)
{
if (std::abs(bin) > maxBin) {
continue;
}
const Real power = afcPower(bin);
if (power > sidePower)
{
sidePower = power;
sideBin = bin;
}
}
}
if (sidePower <= m_afcIdleToneRatio * centerPower)
{
m_afcCandidateValid = false;
return;
}
// Require consecutive estimates to agree before moving.
const Real frequency = sideBin * m_sampleRate / (2.0f * m_afcLength);
if (m_afcCandidateValid && (std::abs(frequency - m_afcCandidate) < m_afcRetuneHz)) {
retune(frequency);
}
else
{
m_afcCandidate = frequency;
m_afcCandidateValid = true;
}
}
Real PSK31Demodulator::afcPower(int bin) const
{
Complex sum(0.0f, 0.0f);
const int step = ((bin % m_afcLength) + m_afcLength) % m_afcLength;
int twiddleIndex = 0;
for (int i = 0; i < m_afcLength; ++i)
{
sum += m_afcWindow[i] * m_afcBuffer[(m_afcIndex + i) % m_afcLength] * m_afcTwiddle[twiddleIndex];
twiddleIndex = (twiddleIndex + step) % m_afcLength;
}
return std::norm(sum);
}
void PSK31Demodulator::retune(Real frequency)
{
m_afcFrequency = frequency * 2.0f * M_PI / m_sampleRate;
m_costasLoop.setFreq(0.0f);
m_afcCandidateValid = false;
if (m_locked)
{
// Symbols during the retuning transient are unreliable, and before it
// the loop was on an idle tone, so there's nothing worth keeping.
m_pendingCharacters.clear();
m_decoder.reset();
}
}
Complex PSK31Demodulator::matchedFilter(const Complex& sample)
{
const int size = m_matchedFilterSamples.size();
m_matchedFilterSamples[m_matchedFilterIndex] = sample;
Complex sum(0.0f, 0.0f);
int index = m_matchedFilterIndex;
for (int i = 0; i < size; ++i)
{
sum += m_matchedFilterTaps[i] * m_matchedFilterSamples[index];
index = (index == 0) ? size - 1 : index - 1;
}
m_matchedFilterIndex = (m_matchedFilterIndex + 1) % size;
return sum;
}
void PSK31Demodulator::symbol(const Complex& value)
{
// When the carrier is tracked, symbols lie on the real axis. Noise has no
// preferred phase, so this averages to zero without a signal.
const Real power = std::norm(value);
const Real lockValue = power > 0.0f ? (value.real() * value.real() - value.imag() * value.imag()) / power : 0.0f;
m_lockMetric += m_lockMetricAlpha * (lockValue - m_lockMetric);
const bool lockDetected = m_lockMetric > m_lockThreshold;
// The lock metric responds slowly when a signal ends, particularly as the
// Costas loop partly tracks noise. A drop in power from the level seen
// while locked shows that the signal has gone (or faded) much sooner.
// Average over four symbols, as power over shorter periods varies with
// the data: phase reversals have half the power of steady carrier.
const Real level = m_signalLevelAverage.asDouble();
const bool signalPresent = lockDetected && (level > m_signalLossRatio * m_lockedLevel);
// With hysteresis, so noise at low SNR doesn't look like the signal returning
const bool signalReturned = lockDetected && (level > m_signalReturnRatio * m_lockedLevel);
// Qualify lock at symbol rate. Noise can briefly cross the lock threshold,
// so require sustained acquisition before accepting bits. Once acquired,
// ride through short fades: characters decoded while the signal is absent
// are held back, then released if it returns or dropped if it doesn't.
m_lockCount = lockDetected ? std::min(m_lockCount + 1, m_lockConfirmSymbols) : 0;
m_presentCount = signalReturned ? std::min(m_presentCount + 1, m_relockConfirmSymbols) : 0;
const bool decision = value.real() >= 0.0f;
if (!m_locked)
{
if (m_lockCount >= m_lockConfirmSymbols)
{
m_locked = true;
m_lockedLevel = level;
// Start a fresh one-second measurement at acquisition. Otherwise
// the first locked report includes pre-lock samples and reads low.
resetSNR();
m_snrAverageValid = false;
m_reportSampleCount = 0;
// Lock takes a while to confirm, and a transmission may not start
// with much idle, so decode the symbols received while confirming.
m_decoder.reset();
for (bool previous : m_acquisitionSymbols) {
decode(previous);
}
}
else
{
m_acquisitionSymbols.push_back(decision);
if ((int) m_acquisitionSymbols.size() >= m_lockConfirmSymbols) {
m_acquisitionSymbols.pop_front();
}
}
}
else if (m_unlockCount > 0)
{
// Noise alone can briefly raise the lock detector, so require a few
// consecutive symbols before accepting that the signal is back.
if (m_presentCount >= m_relockConfirmSymbols) {
m_unlockCount = 0;
}
else if (++m_unlockCount >= m_unlockConfirmSymbols)
{
unlock();
}
}
else if (!signalPresent)
{
m_unlockCount = 1;
}
if (m_locked && (m_unlockCount == 0)) {
m_lockedLevel += m_lockedLevelAlpha * (level - m_lockedLevel);
}
if (m_locked)
{
decode(decision);
// The lock detector takes a few symbols to respond when a signal ends,
// so only output characters once lock has been held for that long
// after them. Otherwise noise at the end of every transmission would
// be decoded. Output is paused during a fade.
if (m_unlockCount == 0)
{
for (auto& pending : m_pendingCharacters) {
--pending.second;
}
while (!m_pendingCharacters.empty() && (m_pendingCharacters.front().second <= 0))
{
emitCharacter(m_pendingCharacters.front().first);
m_pendingCharacters.pop_front();
}
}
}
else
{
m_decoder.reset();
}
}
void PSK31Demodulator::decode(bool symbol)
{
QChar character;
if (m_decoder.decodeSymbol(symbol, character)) {
m_pendingCharacters.push_back({character, m_characterDelaySymbols});
}
}
void PSK31Demodulator::emitCharacter(QChar character)
{
if (m_characterCallback) {
m_characterCallback(character);
}
}
void PSK31Demodulator::unlock()
{
m_locked = false;
m_unlockCount = 0;
// The lock metric decays slowly, so it may still be above threshold.
// Require fresh evidence of a signal, rather than relocking on noise.
m_lockMetric = 0.0f;
m_lockCount = 0;
m_presentCount = 0;
m_pendingCharacters.clear();
m_acquisitionSymbols.clear();
m_decoder.reset();
resetSNR();
m_snr = 0.0f;
}
void PSK31Demodulator::resetSNR()
{
m_snrInPhaseSum = 0.0;
m_snrQuadratureSum = 0.0;
m_snrCount = 0;
}
float PSK31Demodulator::getFrequencyOffset() const
{
return (m_afcFrequency + m_costasLoop.getFreq()) * m_sampleRate / (2.0f * M_PI);
}

195
plugins/channelrx/demodpsk31/psk31demodulator.h

@ -0,0 +1,195 @@ @@ -0,0 +1,195 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_PSK31DEMODULATOR_H
#define INCLUDE_PSK31DEMODULATOR_H
#include <deque>
#include <functional>
#include <utility>
#include <vector>
#include <QString>
#include "dsp/costasloop.h"
#include "dsp/dsptypes.h"
#include "dsp/firfilter.h"
#include "dsp/interpolator.h"
#include "dsp/nco.h"
#include "util/movingaverage.h"
#include "util/psk31.h"
// PSK31 receiver core: channel filter, carrier acquisition, tracking filter,
// carrier tracking, matched filter, symbol timing recovery, differential
// detection and Varicode decoding. Samples are resampled to an internal rate
// of 1000 samples/s.
class PSK31Demodulator
{
public:
static constexpr int m_sampleRate = 1000;
static constexpr int m_samplesPerSymbol = 32;
PSK31Demodulator();
// Resamples from channelSampleRate after mixing channelFrequencyOffset to 0 Hz.
void setChannel(int channelSampleRate, int channelFrequencyOffset);
void setRFBandwidth(Real rfBandwidth);
Real getRFBandwidth() const { return m_rfBandwidth; }
void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end);
// Process one sample at the internal rate, normalized so full scale is 1.0.
void processSample(const Complex& sample);
void reset();
void setCharacterCallback(const std::function<void(QChar)>& callback) { m_characterCallback = callback; }
// Called once per second of samples.
void setReportCallback(const std::function<void()>& callback) { m_reportCallback = callback; }
// Called for every internal sample: real is the normalized matched filter
// output, imag is 1.0 at the symbol sampling instants and 0.0 otherwise.
void setScopeCallback(const std::function<void(const Complex&)>& callback) { m_scopeCallback = callback; }
double getMagSq() const { return m_magsq; }
void getMagSqLevels(double& avg, double& peak, int& nbSamples) const
{
avg = m_magSqLevelStore.m_magsq;
peak = m_magSqLevelStore.m_magsqPeak;
nbSamples = m_magSqLevelStore.m_nbSamples;
}
float getFrequencyOffset() const; //!< Carrier offset from channel center in Hz
float getSNR() const { return m_snr; } //!< Only valid when isLocked()
bool isLocked() const { return m_locked; }
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 constexpr int m_channelFilterTaps = 255;
static constexpr int m_lockConfirmSymbols = 20;
static constexpr int m_relockConfirmSymbols = 4;
static constexpr int m_unlockConfirmSymbols = 20;
static constexpr int m_characterDelaySymbols = 8;
static constexpr Real m_lockMetricAlpha = 1.0f / 16.0f;
static constexpr Real m_lockThreshold = 0.5f;
static constexpr Real m_signalLossRatio = 0.35f;
static constexpr Real m_signalReturnRatio = 0.5f;
static constexpr Real m_lockedLevelAlpha = 1.0f / 32.0f;
static constexpr int m_afcLength = 512;
static constexpr int m_afcInterval = 256;
static constexpr Real m_snrReferenceBandwidth = 100.0f;
static constexpr Real m_trackingBandwidth = 70.0f;
static constexpr Real m_costasRange = 15.0f;
static constexpr Real m_timingGain = 1.0f;
static constexpr Real m_timingIntegralGain = 0.02f;
static constexpr Real m_maxTimingError = 2.0f;
static constexpr Real m_maxTimingRate = 1.0f;
static constexpr Real m_afcThreshold = 20.0f;
static constexpr Real m_afcRetuneHz = 2.0f;
static constexpr Real m_afcIdleToneRatio = 2.0f;
static constexpr Real m_afcTransferRate = 0.001f;
Real m_rfBandwidth;
int m_channelSampleRate;
int m_channelFrequencyOffset;
NCO m_nco;
Interpolator m_interpolator;
Real m_interpolatorDistance;
Real m_interpolatorDistanceRemain;
Lowpass<Complex> m_channelFilter;
Lowpass<Complex> m_trackingFilter;
CostasLoop m_costasLoop;
Real m_maxFrequency;
Real m_trackingCutoff;
Real m_trackingNoiseBandwidth; //!< Hz
// Levels
MovingAverageUtil<Real, double, 16> m_movingAverage;
MovingAverageUtil<Real, double, m_samplesPerSymbol * 2> m_levelAverage;
MovingAverageUtil<Real, double, m_samplesPerSymbol * 4> m_signalLevelAverage;
double m_magsq;
double m_magsqSum;
double m_magsqPeak;
int m_magsqCount;
MagSqLevelsStore m_magSqLevelStore;
// Carrier acquisition
std::vector<Complex> m_afcBuffer;
std::vector<Complex> m_afcTwiddle;
std::vector<Real> m_afcWindow;
std::vector<Real> m_afcPowers;
std::vector<Real> m_afcSorted;
int m_afcIndex;
int m_afcCount;
Real m_afcCandidate; //!< Hz
bool m_afcCandidateValid;
Real m_afcFrequency; //!< radians/sample
Real m_afcPhase;
// Matched filter and symbol timing
std::vector<Real> m_matchedFilterTaps;
std::vector<Complex> m_matchedFilterSamples;
int m_matchedFilterIndex;
std::vector<Real> m_history;
int m_historyIndex;
Real m_symbolPower;
Real m_clockCount;
Real m_timingIntegrator;
// Lock detection
Real m_lockMetric;
int m_lockCount;
int m_presentCount;
int m_unlockCount;
Real m_lockedLevel; //!< Tracked signal power while locked
bool m_locked;
std::deque<std::pair<QChar, int>> m_pendingCharacters; //!< Character and symbols until output
std::deque<bool> m_acquisitionSymbols;
// SNR
double m_snrInPhaseSum;
double m_snrQuadratureSum;
int m_snrCount;
double m_snrSignalPower;
double m_snrNoisePower;
bool m_snrAverageValid;
float m_snr;
int m_reportSampleCount;
PSK31Decoder m_decoder;
std::function<void(QChar)> m_characterCallback;
std::function<void()> m_reportCallback;
std::function<void(const Complex&)> m_scopeCallback;
void acquireCarrier(const Complex& sample);
void checkIdleToneLock(Real current);
Real afcPower(int bin) const;
void retune(Real frequency);
Complex matchedFilter(const Complex& sample);
void symbol(const Complex& value);
void decode(bool symbol);
void emitCharacter(QChar character);
void unlock();
void resetSNR();
};
#endif // INCLUDE_PSK31DEMODULATOR_H

53
plugins/channelrx/demodpsk31/psk31demodwebapiadapter.cpp

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#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;
}

51
plugins/channelrx/demodpsk31/psk31demodwebapiadapter.h

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#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

138
plugins/channelrx/demodpsk31/readme.md

@ -0,0 +1,138 @@ @@ -0,0 +1,138 @@
<h1>PSK31 Demodulator Plugin</h1>
<h2>Introduction</h2>
This channel receives PSK31 text at the standard 31.25 baud rate. It searches the
RF bandwidth for the signal's carrier, centers it in a narrow tracking filter,
recovers carrier phase and symbol timing, and makes differential BPSK decisions
from a filter matched to the PSK31 pulse shape. The decoder supports the same
extended Latin-1 Varicode table as the [PSK31 modulator](../../channeltx/modpsk31/readme.md).
<h2>Interface</h2>
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)
<h3>1: Frequency offset</h3>
Tune the channel marker to the PSK31 signal. The demodulator finds the carrier
within the RF bandwidth (3) and tracks it from there, so the marker does not need
to be exactly on frequency: with the default 100 Hz bandwidth, signals within
about 30 Hz of the marker are acquired. The carrier status (7) shows the
carrier's offset from the marker once locked.
<h3>2: Channel power and level meter</h3>
Power within the RF bandwidth (3), in dB relative to a full-scale signal. The
level meter shows average power, instantaneous peak power, and peak hold.
<h3>3: RF bandwidth</h3>
This sets the bandwidth searched for a signal. Signals up to 15 Hz inside either
edge are acquired. Once acquired, the signal is kept centered in a fixed 70 Hz
tracking filter (or the RF bandwidth, if that is narrower) followed by the
matched filter, so the RF bandwidth has little effect on adjacent-channel
rejection after lock. The default 100 Hz bandwidth suits most use. Reduce it if a
stronger signal nearby is acquired instead of the one wanted; increase it to
allow a larger tuning error.
<h3>4: UDP</h3>
When checked, received characters are forwarded to the specified UDP address (5) and port (6).
<h3>5: UDP address</h3>
IP address of the host to forward received characters to via UDP.
<h3>6: UDP port</h3>
UDP port number to forward received characters to.
<h3>7: Carrier status</h3>
Shows whether the demodulator is locked to a PSK31 signal. Once locked, it also
shows the carrier's frequency offset from the channel marker and the estimated
SNR. The SNR is measured from the carrier-corrected signal each second and
averaged over a few seconds. Its noise power is normalized to a 100 Hz reference
bandwidth, so it does not depend on the RF bandwidth setting. The first SNR value
is displayed after one complete second of lock; samples collected before
acquisition are excluded.
Lock is confirmed over 20 symbols, which keeps noise from being decoded as text.
Symbols received while confirming are decoded once lock is confirmed, so text
that follows a short idle preamble is not lost. Characters are output after an
8 symbol delay. If the signal level drops more than about 4.6 dB in that time,
output is paused, so noise received as a transmission ends is not displayed.
During a fade of up to about half a second, lock is held and output paused; if
the signal returns, decoding continues without having to reacquire.
<h3>8: Start/stop Logging Messages to .txt File</h3>
When checked, writes all received characters to the .txt file specified by (9).
<h3>9: .txt Log Filename</h3>
Click to specify the name of the .txt file which received characters are logged to.
<h3>10: Clear</h3>
Clear the received text view (11) of received characters.
<h3>11: Received text</h3>
Decoded text is appended to the text view. CR, LF and CR LF line endings each
start a new line. Other control characters are not displayed.
<h2>Measured performance</h2>
The sample-level benchmark sends a raised-cosine PSK31 waveform, as generated by
the PSK31 modulator, with 256 idle symbols followed by the 30-character test frame
`CQ CQ DE SDRANGEL 0123456789\r\n`. Some tests instead use the classic PSK31
cosine envelope, or a short idle preamble. A frame passes only when every
character is correct. Run it with:
```
sdrangelbench -t psk31 -a perf
```
Measurements with the default 100 Hz RF bandwidth gave these results:
| Test | Result |
|---|---|
| AWGN, acquired carrier | 26% exact frames at 3 dB SNR; 66% at 4 dB; 90% at 5 dB; 94% at 6 dB; 98% at 7 and 8 dB; 100% from 9 dB. The classic cosine envelope gives the same results within a frame or two |
| Frequency offset, random starting phase | At 10 dB SNR, 10/10 exact frames at every offset from -33 Hz through +30 Hz. At 5 dB SNR, 7/10 to 10/10 from -30 Hz through +30 Hz |
| Short preamble, random phase and offset within +/-15 Hz, 10 dB SNR | 20/20 exact frames with 32 or more idle symbols; 19/20 with 24; 13/20 with 16 |
| 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 -100 dBFS |
| Noise only at -40 dBFS | Zero lock acquisitions and zero decoded characters in one simulated hour |
| Transmission ending without a carrier tail, followed by noise | No characters decoded after the end in 100/100 trials at 20 dB and 10 dB SNR; 94/100 at 5 dB, with a single character in the others |
| Fade to -40 dB in the middle of text, 15 dB SNR | Average character errors: 0.2 for 50 ms; 0.8 for 100 ms; 2.2 for 200 ms; 2.7 for 300 ms; 3.8 for 500 ms |
| CW interferer, 15 dB SNR | 5/5 exact frames with the interferer 10 dB weaker at 25 Hz separation, equal power at 50 Hz, and 40 dB stronger at 75, 100 or 150 Hz |
| PSK31 interferer, 15 dB SNR | 5/5 exact frames with the interferer 10 dB weaker at 25 Hz separation, equal power at 50 Hz, 30 dB stronger at 75 Hz, and 40 dB stronger at 100 or 150 Hz |
| Full channel path at 1536 samples/s, 10 dB SNR | 5/5 exact frames with PSK31 interferers 20 dB stronger at both +/-75 Hz, 30 dB stronger at 100 Hz, or a CW carrier 40 dB stronger at 300 Hz or at -600 Hz, which aliases when resampled |
| Core demodulator CPU throughput | 4.45-4.49 million internal samples/s, or about 4500 times real time at 1000 samples/s |
SNR is average wanted-signal power divided by complex AWGN power in a 100 Hz
reference bandwidth. At 31.25 baud, 3 dB in 100 Hz corresponds to about 8 dB
Eb/N0. In the regression test, a 20 dB input is reported as about 21.5 dB with
either a 100 Hz or a 200 Hz RF bandwidth. 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 to the demodulator at its internal rate. At 1000 samples/s, this
corresponds to roughly 0.02% of one CPU core. It measures filtering, carrier
acquisition and tracking, symbol timing, and decoding; device input,
channelization, scope rendering, and other application overhead are not
included. Run this focused measurement with:
```
sdrangelbench -t psk31 -a cpu
```
Run the standalone noise test with:
```
sdrangelbench -t psk31 -a noise
```

4
plugins/channelrx/demodrtty/rttydemodsettings.cpp

@ -102,7 +102,9 @@ QByteArray RttyDemodSettings::serialize() const @@ -102,7 +102,9 @@ QByteArray RttyDemodSettings::serialize() const
s.writeS32(31, m_scopeCh1);
s.writeS32(32, m_scopeCh2);
s.writeBlob(33, m_scopeGUI->serialize());
if (m_scopeGUI) {
s.writeBlob(33, m_scopeGUI->serialize());
}
s.writeString(25, m_logFilename);
s.writeBool(26, m_logEnabled);

14
plugins/channeltx/modpsk31/psk31mod.cpp

@ -374,12 +374,6 @@ void PSK31::webapiUpdateChannelSettings( @@ -374,12 +374,6 @@ void PSK31::webapiUpdateChannelSettings(
if (channelSettingsKeys.contains("symbolSpan")) {
settings.m_symbolSpan = response.getPsk31ModSettings()->getSymbolSpan();
}
if (channelSettingsKeys.contains("prefixCRLF")) {
settings.m_prefixCRLF = response.getPsk31ModSettings()->getPrefixCrlf();
}
if (channelSettingsKeys.contains("postfixCRLF")) {
settings.m_postfixCRLF = response.getPsk31ModSettings()->getPostfixCrlf();
}
if (channelSettingsKeys.contains("rgbColor")) {
settings.m_rgbColor = response.getPsk31ModSettings()->getRgbColor();
}
@ -502,8 +496,6 @@ void PSK31::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respons @@ -502,8 +496,6 @@ void PSK31::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respons
response.getPsk31ModSettings()->setBeta(settings.m_beta);
response.getPsk31ModSettings()->setSymbolSpan(settings.m_symbolSpan);
response.getPsk31ModSettings()->setPrefixCrlf(settings.m_prefixCRLF);
response.getPsk31ModSettings()->setPostfixCrlf(settings.m_postfixCRLF);
response.getPsk31ModSettings()->setUdpEnabled(settings.m_udpEnabled);
if (response.getPsk31ModSettings()->getUdpAddress()) {
@ -675,12 +667,6 @@ void PSK31::webapiFormatChannelSettings( @@ -675,12 +667,6 @@ void PSK31::webapiFormatChannelSettings(
if (channelSettingsKeys.contains("symbolSpan")) {
swgPSK31ModSettings->setSymbolSpan(settings.m_symbolSpan);
}
if (channelSettingsKeys.contains("prefixCRLF")) {
swgPSK31ModSettings->setPrefixCrlf(settings.m_prefixCRLF);
}
if (channelSettingsKeys.contains("postfixCRLF")) {
swgPSK31ModSettings->setPostfixCrlf(settings.m_postfixCRLF);
}
if (channelSettingsKeys.contains("rgbColor") || force) {
swgPSK31ModSettings->setRgbColor(settings.m_rgbColor);
}

2
plugins/channeltx/modpsk31/psk31modgui.cpp

@ -477,7 +477,7 @@ void PSK31GUI::displaySettings() @@ -477,7 +477,7 @@ void PSK31GUI::displaySettings()
ui->udpAddress->setText(m_settings.m_udpAddress);
ui->udpPort->setText(QString::number(m_settings.m_udpPort));
ui->gainText->setText(QString("%1dB").arg((double)m_settings.m_gain, 0, 'f', 1));
ui->gainText->setText(QString("%1 dB").arg((double)m_settings.m_gain, 0, 'f', 1));
ui->gain->setValue(m_settings.m_gain);
ui->channelMute->setChecked(m_settings.m_channelMute);

18
plugins/channeltx/modpsk31/psk31modsettings.cpp

@ -41,8 +41,6 @@ void PSK31Settings::resetToDefaults() @@ -41,8 +41,6 @@ void PSK31Settings::resetToDefaults()
m_lpfTaps = 301;
m_rfNoise = false;
m_text = "CQ CQ CQ DE SDRangel CQ";
m_prefixCRLF = true;
m_postfixCRLF = true;
m_predefinedTexts = QStringList({
"CQ CQ CQ DE ${callsign} ${callsign} CQ",
"DE ${callsign} ${callsign} ${callsign}",
@ -82,8 +80,6 @@ QByteArray PSK31Settings::serialize() const @@ -82,8 +80,6 @@ QByteArray PSK31Settings::serialize() const
s.writeBool(25, m_rfNoise);
s.writeString(30, m_text);
s.writeBool(64, m_prefixCRLF);
s.writeBool(65, m_postfixCRLF);
s.writeList(66, m_predefinedTexts);
s.writeU32(31, m_rgbColor);
@ -145,8 +141,6 @@ bool PSK31Settings::deserialize(const QByteArray& data) @@ -145,8 +141,6 @@ bool PSK31Settings::deserialize(const QByteArray& data)
d.readBool(25, &m_rfNoise, false);
d.readString(30, &m_text, "CQ CQ CQ anyone using SDRangel");
d.readBool(64, &m_prefixCRLF, true);
d.readBool(65, &m_postfixCRLF, true);
d.readList(66, &m_predefinedTexts);
d.readU32(31, &m_rgbColor);
@ -247,12 +241,6 @@ void PSK31Settings::applySettings(const QStringList& settingsKeys, const PSK31Se @@ -247,12 +241,6 @@ void PSK31Settings::applySettings(const QStringList& settingsKeys, const PSK31Se
if (settingsKeys.contains("symbolSpan")) {
m_symbolSpan = settings.m_symbolSpan;
}
if (settingsKeys.contains("prefixCRLF")) {
m_prefixCRLF = settings.m_prefixCRLF;
}
if (settingsKeys.contains("postfixCRLF")) {
m_postfixCRLF = settings.m_postfixCRLF;
}
if (settingsKeys.contains("predefinedTexts")) {
m_predefinedTexts = settings.m_predefinedTexts;
}
@ -343,12 +331,6 @@ QString PSK31Settings::getDebugString(const QStringList& settingsKeys, bool forc @@ -343,12 +331,6 @@ QString PSK31Settings::getDebugString(const QStringList& settingsKeys, bool forc
if (settingsKeys.contains("symbolSpan") || force) {
ostr << " m_symbolSpan: " << m_symbolSpan;
}
if (settingsKeys.contains("prefixCRLF") || force) {
ostr << " m_prefixCRLF: " << m_prefixCRLF;
}
if (settingsKeys.contains("postfixCRLF") || force) {
ostr << " m_postfixCRLF: " << m_postfixCRLF;
}
if (settingsKeys.contains("rgbColor") || force) {
ostr << " m_rgbColor: " << m_rgbColor;
}

2
plugins/channeltx/modpsk31/psk31modsettings.h

@ -43,8 +43,6 @@ struct PSK31Settings @@ -43,8 +43,6 @@ struct PSK31Settings
bool m_pulseShaping;
float m_beta;
int m_symbolSpan;
bool m_prefixCRLF;
bool m_postfixCRLF;
QStringList m_predefinedTexts;
quint32 m_rgbColor;

17
plugins/channeltx/modpsk31/psk31modsource.cpp

@ -373,18 +373,15 @@ void PSK31Source::addTXText(QString text) @@ -373,18 +373,15 @@ void PSK31Source::addTXText(QString text)
{
int count = m_settings.m_repeat ? m_settings.m_repeatCount : 1;
for (int i = 0; i < count; i++) {
QString s = text;
// PSK31 defines both CR and LF Varicode characters but no message delimiter.
// Terminate messages with a single LF unless the caller supplied a line ending.
if (!text.endsWith('\r') && !text.endsWith('\n')) {
text.append('\n');
}
if (m_settings.m_prefixCRLF) {
s.prepend("\r\r\n");
}
if (m_settings.m_postfixCRLF) {
s.append("\r\r\n");
}
for (int i = 0; i < count; i++) {
m_textToTransmit.append(s);
m_textToTransmit.append(text);
}
}

4
plugins/channeltx/modpsk31/psk31modtxsettingsdialog.cpp

@ -30,8 +30,6 @@ PSK31TXSettingsDialog::PSK31TXSettingsDialog(PSK31Settings* settings, QWidget *p @@ -30,8 +30,6 @@ PSK31TXSettingsDialog::PSK31TXSettingsDialog(PSK31Settings* settings, QWidget *p
ui(new Ui::PSK31TXSettingsDialog)
{
ui->setupUi(this);
ui->prefixCRLF->setChecked(m_settings->m_prefixCRLF);
ui->postfixCRLF->setChecked(m_settings->m_postfixCRLF);
for (const auto& text : m_settings->m_predefinedTexts) {
ui->predefinedText->addItem(newItem(text));
}
@ -49,8 +47,6 @@ PSK31TXSettingsDialog::~PSK31TXSettingsDialog() @@ -49,8 +47,6 @@ PSK31TXSettingsDialog::~PSK31TXSettingsDialog()
void PSK31TXSettingsDialog::accept()
{
m_settings->m_prefixCRLF = ui->prefixCRLF->isChecked();
m_settings->m_postfixCRLF = ui->postfixCRLF->isChecked();
m_settings->m_predefinedTexts.clear();
for (int i = 0; i < ui->predefinedText->count(); i++) {
m_settings->m_predefinedTexts.append(ui->predefinedText->item(i)->text());

26
plugins/channeltx/modpsk31/psk31modtxsettingsdialog.ui

@ -26,24 +26,14 @@ @@ -26,24 +26,14 @@
<string>Text</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="prefixCRLF">
<property name="toolTip">
<string>Prefix text with carriage returns and line feed</string>
</property>
<property name="text">
<string>Prefix CR+CR+LF</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Predefined text</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="add">
@ -107,17 +97,7 @@ @@ -107,17 +97,7 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="postfixCRLF">
<property name="toolTip">
<string>Postfix text with carriage returns and line feeds</string>
</property>
<property name="text">
<string>Postfix CR+CR+LF</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="1" column="0" colspan="2">
<widget class="QListWidget" name="predefinedText">
<property name="toolTip">
<string>Predefined text messages

1
sdrbase/dsp/costasloop.h

@ -40,6 +40,7 @@ public: @@ -40,6 +40,7 @@ public:
void setSampleRate(unsigned int sampleRate);
void setMaxFreq(float freq) { m_maxFreq = freq; }
void setMinFreq(float freq) { m_minFreq = freq; }
void setFreq(float freq) { m_freq = freq; }
void feed(float re, float im);
const std::complex<float>& getComplex() const { return m_y; }
float getReal() const { return m_y.real(); }

1
sdrbase/resources/webapi.qrc

@ -112,6 +112,7 @@ @@ -112,6 +112,7 @@
<file>webapi/doc/swagger/include/RollupState.yaml</file>
<file>webapi/doc/swagger/include/RtlSdr.yaml</file>
<file>webapi/doc/swagger/include/RTTYDemod.yaml</file>
<file>webapi/doc/swagger/include/PSK31Demod.yaml</file>
<file>webapi/doc/swagger/include/RTTYMod.yaml</file>
<file>webapi/doc/swagger/include/SatelliteTracker.yaml</file>
<file>webapi/doc/swagger/include/SDRPlay.yaml</file>

3
sdrbase/resources/webapi/doc/swagger/include/ChannelReport.yaml

@ -160,6 +160,9 @@ ChannelReport: @@ -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."

3
sdrbase/resources/webapi/doc/swagger/include/ChannelSettings.yaml

@ -166,6 +166,9 @@ ChannelSettings: @@ -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."

95
sdrbase/resources/webapi/doc/swagger/include/PSK31Demod.yaml

@ -0,0 +1,95 @@ @@ -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: "Carrier-frequency estimate in Hz relative to the selected channel frequency. Only present when locked."
snr:
type: number
format: float
description: "Signal-to-noise ratio in dB, normalized to a 100 Hz noise bandwidth. Only present when locked."
locked:
type: integer
minimum: 0
maximum: 1
description: "Whether a PSK31 signal is locked and being decoded."

10
sdrbase/resources/webapi/doc/swagger/include/PSK31Mod.yaml

@ -54,16 +54,6 @@ PSK31ModSettings: @@ -54,16 +54,6 @@ PSK31ModSettings:
symbolSpan:
type: integer
description: "Symbol span setting for Psk31 mod."
prefixCRLF:
type: integer
description: "Enable prefix crlf (1 enabled, 0 disabled)."
minimum: 0
maximum: 1
postfixCRLF:
type: integer
description: "Enable postfix crlf (1 enabled, 0 disabled)."
minimum: 0
maximum: 1
udpEnabled:
description: "Whether to receive text to transmit on specified UDP port"
type: integer

86
sdrbase/util/psk31.cpp

@ -327,3 +327,89 @@ void PSK31Encoder::addBits(unsigned& bits, unsigned int& bitCount, int data, int @@ -327,3 +327,89 @@ 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_discard = false;
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_discard)
{
m_zeroCount = 0;
return false;
}
if ((m_zeroCount == 1) && !m_code.isEmpty()) {
m_code.append('0');
}
m_zeroCount = 0;
m_code.append('1');
// No Varicode is longer than 12 bits, so this is not a character, but
// e.g. an unmodulated carrier. Its tail could look like a valid code,
// so ignore everything up to the next character gap.
if (m_code.size() > 12)
{
m_code.clear();
m_discard = true;
}
return false;
}
++m_zeroCount;
if (m_zeroCount < 2) {
return false;
}
const bool decoded = !m_discard && decodeCode(character);
m_code.clear();
m_zeroCount = 0;
m_discard = false;
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<char>(index));
return true;
}

20
sdrbase/util/psk31.h

@ -49,5 +49,23 @@ private: @@ -49,5 +49,23 @@ 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_discard;
bool m_havePreviousSymbol;
bool m_previousSymbol;
bool decodeCode(QChar& character) const;
};
#endif // INCLUDE_UTIL_PSK31_H

6
sdrbase/webapi/webapirequestmapper.cpp

@ -5177,6 +5177,12 @@ bool WebAPIRequestMapper::getChannelSettings( @@ -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());

2
sdrbase/webapi/webapiutils.cpp

@ -71,6 +71,7 @@ const QMap<QString, QString> WebAPIUtils::m_channelURIToSettingsKey = { @@ -71,6 +71,7 @@ const QMap<QString, QString> 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<QString, QString> WebAPIUtils::m_channelTypeToSettingsKey = { @@ -195,6 +196,7 @@ const QMap<QString, QString> WebAPIUtils::m_channelTypeToSettingsKey = {
{"PacketMod", "PacketModSettings"},
{"PagerDemod", "PagerDemodSettings"},
{"PSK31Mod", "PSK31ModSettings"},
{"PSK31Demod", "PSK31DemodSettings"},
{"LocalSink", "LocalSinkSettings"},
{"LocalSource", "LocalSourceSettings"},
{"RadioAstronomy", "RadioAstronomySettings"},

3
sdrbench/CMakeLists.txt

@ -15,6 +15,8 @@ set(sdrbench_SOURCES @@ -15,6 +15,8 @@ set(sdrbench_SOURCES
test_fftrrc.cpp
test_firrrc.cpp
test_meshtastic.cpp
test_psk31.cpp
../plugins/channelrx/demodpsk31/psk31demodulator.cpp
)
set(sdrbench_HEADERS
@ -33,6 +35,7 @@ include_directories( @@ -33,6 +35,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/sdrbase
${CMAKE_SOURCE_DIR}/logging
${CMAKE_SOURCE_DIR}/modemmeshtastic
${CMAKE_SOURCE_DIR}/plugins/channelrx/demodpsk31
${CMAKE_SOURCE_DIR}
)

2
sdrbench/mainbench.cpp

@ -81,6 +81,8 @@ void MainBench::run() @@ -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();
}

1
sdrbench/mainbench.h

@ -60,6 +60,7 @@ private: @@ -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);

4
sdrbench/parserbench.cpp

@ -24,7 +24,7 @@ @@ -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 @@ -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;
}

3
sdrbench/parserbench.h

@ -44,7 +44,8 @@ public: @@ -44,7 +44,8 @@ public:
TestFT8Protocols,
TestFFTRRCFilter,
TestFIRRRCFilter,
TestMeshtastic
TestMeshtastic,
TestPSK31
} TestType;
ParserBench();

902
sdrbench/test_psk31.cpp

@ -0,0 +1,902 @@ @@ -0,0 +1,902 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2026 Jon Beniston, M7RCE <jon@beniston.com> //
// 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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <cmath>
#include <limits>
#include <random>
#include <QDebug>
#include <QElapsedTimer>
#include <QVector>
#include "dsp/raisedcosine.h"
#include "mainbench.h"
#include "psk31demodulator.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;
enum class PulseShape
{
RaisedCosine, // As generated by SDRangel's PSK31 modulator
CosineEnvelope // Classic PSK31: cosine amplitude envelope on each reversal
};
struct TrialOptions
{
float snrDb100Hz = std::numeric_limits<float>::infinity();
float frequencyOffset = 0.0f;
float clockErrorPpm = 0.0f;
int timingOffset = 0;
float amplitude = 0.2f;
float initialPhase = std::numeric_limits<float>::quiet_NaN();
float interfererOffset = 0.0f;
float interfererRelativeDb = -std::numeric_limits<float>::infinity();
bool interfererPSK31 = false; // PSK31 station rather than a CW carrier
float rfBandwidth = measurementBandwidth;
int phaseGlitchStart = -1;
int phaseGlitchLength = 0;
int fadeStart = -1;
int fadeLength = 0;
float fadeDb = -40.0f;
quint32 seed = 1;
};
struct TrialResult
{
QString received;
float snr = 0.0f;
bool locked = false;
float frequencyOffset = 0.0f;
};
struct NoiseResult
{
int characters = 0;
qint64 lockedSamples = 0;
int lockAcquisitions = 0;
};
QVector<bool> encodeBits(const QString& text, int carrierTailSymbols = 0, int preambleSymbols = 256)
{
PSK31Encoder encoder;
QVector<bool> bits;
// Reversing phase on every idle zero gives the Costas loop and symbol clock
// time to acquire before any scored text arrives.
bits.fill(false, preambleSymbols);
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);
}
// Unmodulated carrier, as sent at the end of a transmission
for (int i = 0; i < carrierTailSymbols; ++i) {
bits.append(true);
}
return bits;
}
QVector<float> modulate(const QVector<bool>& bits, PulseShape shape = PulseShape::RaisedCosine)
{
QVector<float> waveform;
waveform.reserve((bits.size() + 4) * samplesPerSymbol);
RaisedCosine<Real> pulseShape;
pulseShape.create(1.0, 2, samplesPerSymbol, true);
std::vector<float> cosinePulse(2 * samplesPerSymbol);
for (int i = 0; i < 2 * samplesPerSymbol; ++i) {
cosinePulse[i] = 0.5f - 0.5f * std::cos(2.0f * M_PI * i / (2 * samplesPerSymbol));
}
std::vector<float> symbols;
bool symbol = false;
for (bool bit : bits)
{
if (!bit) {
symbol = !symbol;
}
if (shape == PulseShape::RaisedCosine)
{
for (int sample = 0; sample < samplesPerSymbol; ++sample) {
waveform.append(pulseShape.filter(sample == 1 ? (symbol ? 1.0f : -1.0f) : 0.0f));
}
}
else
{
symbols.push_back(symbol ? 1.0f : -1.0f);
}
}
if (shape == PulseShape::RaisedCosine)
{
// Flush the pulse-shaping filter.
for (int i = 0; i < 3 * samplesPerSymbol; ++i) {
waveform.append(pulseShape.filter(0.0f));
}
}
else
{
waveform.fill(0.0f, (symbols.size() + 2) * samplesPerSymbol);
for (int k = 0; k < (int) symbols.size(); ++k)
{
for (int i = 0; i < 2 * samplesPerSymbol; ++i) {
waveform[k * samplesPerSymbol + i] += symbols[k] * cosinePulse[i];
}
}
}
return waveform;
}
QVector<float> appendSilence(QVector<float> waveform, int samples)
{
for (int i = 0; i < samples; ++i) {
waveform.append(0.0f);
}
return waveform;
}
QVector<float> prependSilence(const QVector<float>& waveform, int samples)
{
QVector<float> result(samples, 0.0f);
result.append(waveform);
return result;
}
// An unrelated PSK31 transmission used as an adjacent channel interferer
const QVector<float>& interfererWaveform()
{
static const QVector<float> waveform = modulate(encodeBits(
"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 1234567890 the quick brown fox jumps over the lazy dog "
"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG 1234567890 the quick brown fox jumps over the lazy dog "));
return waveform;
}
double meanPower(const QVector<float>& waveform)
{
double power = 0.0;
for (float sample : waveform) {
power += sample * sample;
}
return power / waveform.size();
}
QVector<float> resample(const QVector<float>& source, double scale, double offset)
{
QVector<float> resampled;
resampled.reserve(static_cast<int>(source.size() * scale) + 1);
for (double position = offset; position < source.size() - 1; position += 1.0 / scale)
{
const int index = static_cast<int>(position);
const float fraction = static_cast<float>(position - index);
resampled.append(source[index] + fraction * (source[index + 1] - source[index]));
}
return resampled;
}
TrialResult runTrial(const QVector<float>& source, const TrialOptions& options)
{
const QVector<float> resampled = resample(source, 1.0 + options.clockErrorPpm * 1.0e-6, options.timingOffset);
const double meanSignalPower = options.amplitude * options.amplitude * meanPower(resampled);
// 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<float> gaussian(0.0f, std::sqrt(noisePower / 2.0));
std::uniform_real_distribution<float> phaseDistribution(-M_PI, M_PI);
const float initialPhase = std::isfinite(options.initialPhase)
? options.initialPhase : phaseDistribution(generator);
const QVector<float>& psk31Interferer = interfererWaveform();
const float interfererScale = options.interfererPSK31 ? 1.0f / std::sqrt(meanPower(psk31Interferer)) : 1.0f;
const float interfererAmplitude = std::isfinite(options.interfererRelativeDb)
? std::sqrt(meanSignalPower) * std::pow(10.0f, options.interfererRelativeDb / 20.0f)
: 0.0f;
const float fadeAmplitude = std::pow(10.0f, options.fadeDb / 20.0f);
PSK31Demodulator demod;
demod.setRFBandwidth(options.rfBandwidth);
TrialResult result;
demod.setCharacterCallback([&result](QChar character) { result.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 ((i >= options.fadeStart) && (i < options.fadeStart + options.fadeLength)) {
sample *= fadeAmplitude;
}
if (interfererAmplitude > 0.0f)
{
const float interfererPhase = 0.37f + 2.0f * M_PI * options.interfererOffset * i / sampleRate;
const float modulation = options.interfererPSK31
? interfererScale * psk31Interferer[(i + 1234) % psk31Interferer.size()]
: 1.0f;
sample += interfererAmplitude * modulation * Complex(std::cos(interfererPhase), std::sin(interfererPhase));
}
sample += Complex(gaussian(generator), gaussian(generator));
demod.processSample(sample);
}
result.snr = demod.getSNR();
result.locked = demod.isLocked();
result.frequencyOffset = demod.getFrequencyOffset();
return result;
}
struct ChannelInterferer
{
float offset; // Hz relative to the wanted signal
float relativeDb; // Power relative to the wanted signal
bool psk31;
};
// Run the full channel path: NCO, resampling to the internal rate and
// fixed-point samples, as used by the plugin.
QString runChannelTrial(
const QVector<float>& source,
int channelSampleRate,
int channelFrequencyOffset,
float residualOffset,
const std::vector<ChannelInterferer>& interferers,
float snrDb100Hz,
quint32 seed)
{
const double scale = channelSampleRate / sampleRate;
const QVector<float> resampled = resample(source, scale, 0.0);
const float amplitude = 0.01f; // -40 dBFS, leaving headroom for strong interferers
const double meanSignalPower = amplitude * amplitude * meanPower(resampled);
double noisePower = 0.0;
if (std::isfinite(snrDb100Hz)) {
noisePower = meanSignalPower * (channelSampleRate / measurementBandwidth) / std::pow(10.0, snrDb100Hz / 10.0);
}
std::mt19937 generator(seed);
std::normal_distribution<float> gaussian(0.0f, std::sqrt(noisePower / 2.0));
const QVector<float>& psk31Interferer = interfererWaveform();
const float interfererScale = 1.0f / std::sqrt(meanPower(psk31Interferer));
PSK31Demodulator demod;
demod.setChannel(channelSampleRate, channelFrequencyOffset);
QString received;
demod.setCharacterCallback([&received](QChar character) { received.append(character); });
SampleVector samples;
samples.reserve(resampled.size());
const float signalFrequency = channelFrequencyOffset + residualOffset;
for (int i = 0; i < resampled.size(); ++i)
{
const double t = i / static_cast<double>(channelSampleRate);
const double phase = 0.5 + 2.0 * M_PI * signalFrequency * t;
Complex sample = amplitude * resampled[i] * Complex(std::cos(phase), std::sin(phase));
for (const auto& interferer : interferers)
{
const double interfererPhase = 1.1 + 2.0 * M_PI * (signalFrequency + interferer.offset) * t;
const float interfererAmplitude = std::sqrt(meanSignalPower) * std::pow(10.0f, interferer.relativeDb / 20.0f);
const float modulation = interferer.psk31
? interfererScale * psk31Interferer[static_cast<int>(t * sampleRate + 777) % psk31Interferer.size()]
: 1.0f;
sample += interfererAmplitude * modulation * Complex(std::cos(interfererPhase), std::sin(interfererPhase));
}
sample += Complex(gaussian(generator), gaussian(generator));
samples.push_back(Sample(sample.real() * SDR_RX_SCALEF, sample.imag() * SDR_RX_SCALEF));
}
constexpr int blockSize = 1000;
for (int i = 0; i < samples.size(); i += blockSize) {
demod.feed(samples.begin() + i, samples.begin() + std::min<int>(i + blockSize, samples.size()));
}
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<float> gaussian(0.0f, std::sqrt(noisePower / 2.0f));
PSK31Demodulator demod;
demod.setRFBandwidth(measurementBandwidth);
NoiseResult result;
demod.setCharacterCallback([&result](QChar) { ++result.characters; });
bool wasLocked = false;
const int sampleCount = static_cast<int>(durationSeconds * sampleRate);
for (int i = 0; i < sampleCount; ++i)
{
demod.processSample(Complex(gaussian(generator), gaussian(generator)));
const bool locked = demod.isLocked();
result.lockedSamples += locked;
result.lockAcquisitions += locked && !wasLocked;
wasLocked = locked;
}
return result;
}
QString escaped(const QString& text)
{
QString result;
for (QChar character : text)
{
if ((character.unicode() < 0x20) || (character.unicode() >= 0x7f)) {
result.append(QString("<%1>").arg(static_cast<int>(character.unicode()), 2, 16, QChar('0')));
} else {
result.append(character);
}
}
return result;
}
int editDistance(const QString& a, const QString& b)
{
std::vector<int> previous(b.size() + 1);
std::vector<int> current(b.size() + 1);
for (int j = 0; j <= b.size(); ++j) {
previous[j] = j;
}
for (int i = 1; i <= a.size(); ++i)
{
current[0] = i;
for (int j = 1; j <= b.size(); ++j)
{
current[j] = std::min({
previous[j] + 1,
current[j - 1] + 1,
previous[j - 1] + (a[i - 1] != b[j - 1] ? 1 : 0)});
}
std::swap(previous, current);
}
return previous[b.size()];
}
// Number of trials where characters are decoded after a transmission that
// ends without a carrier tail, followed by noise
int abruptEndTrials(const QVector<float>& waveform, const QString& payload, float snrDb, int trials)
{
const QVector<float> abrupt = appendSilence(waveform, 3000);
int extra = 0;
for (int trial = 0; trial < trials; ++trial)
{
TrialOptions options;
options.snrDb100Hz = snrDb;
options.seed = 9000 + trial;
const QString received = runTrial(abrupt, options).received;
const int index = received.indexOf(payload);
extra += (index >= 0) && (received.size() > index + payload.size());
}
return extra;
}
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<Complex> 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);
}
PSK31Demodulator demod;
demod.setRFBandwidth(measurementBandwidth);
qint64 processedSamples = 0;
QElapsedTimer timer;
timer.start();
do
{
for (const Complex& sample : block) {
demod.processSample(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<float>& waveform, const QString& payload, const TrialOptions& options)
{
return runTrial(waveform, options).received.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<float>& waveform, const QVector<float>& cosineWaveform, const QString& payload, const QString& argsStr)
{
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,raised_cosine_frames_passed,cosine_envelope_frames_passed,frames_total";
for (int snrDb = -2; snrDb <= 12; ++snrDb)
{
int passed = 0;
int cosinePassed = 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);
cosinePassed += framePassed(cosineWaveform, payload, options);
}
qInfo().noquote() << QString("%1,%2,%3,%4").arg(snrDb).arg(passed).arg(cosinePassed).arg(trials);
}
qInfo().noquote() << "Frequency_offset_Hz,frames_passed_10dB,frames_passed_5dB,frames_total (random starting phase)";
for (int offset = -45; offset <= 45; offset += 3)
{
int passed = 0;
int weakPassed = 0;
constexpr int trials = 10;
for (int trial = 0; trial < trials; ++trial)
{
TrialOptions options;
options.frequencyOffset = offset + 0.37f * trial;
options.snrDb100Hz = 10.0f;
options.seed = 2000 + trial;
const TrialResult result = runTrial(waveform, options);
passed += result.received.contains(payload);
if (argsStr.contains("trace", Qt::CaseInsensitive) && !result.received.contains(payload)) {
qInfo().noquote() << " " << options.frequencyOffset << result.frequencyOffset << result.locked << escaped(result.received);
}
options.snrDb100Hz = 5.0f;
weakPassed += framePassed(waveform, payload, options);
}
qInfo().noquote() << QString("%1,%2,%3,%4").arg(offset).arg(passed).arg(weakPassed).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).received;
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 >= -100; levelDb -= 10)
{
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);
}
for (bool psk31 : {false, true})
{
qInfo().noquote() << QString("%1_interferer_offset_Hz,interferer_over_signal_dB,frames_passed,frames_total (15 dB SNR)")
.arg(psk31 ? "PSK31" : "CW");
for (int offset : {25, 50, 75, 100, 150})
{
for (int relativeDb : {-20, -10, 0, 10, 20, 30, 40})
{
int passed = 0;
constexpr int trials = 5;
for (int trial = 0; trial < trials; ++trial)
{
TrialOptions options;
options.interfererOffset = (trial & 1) ? -offset : offset;
options.interfererRelativeDb = relativeDb;
options.interfererPSK31 = psk31;
options.snrDb100Hz = 15.0f;
options.seed = 5000 + trial;
passed += framePassed(waveform, payload, options);
}
qInfo().noquote() << QString("%1,%2,%3,%4")
.arg(offset).arg(relativeDb).arg(passed).arg(trials);
}
}
}
qInfo().noquote() << "Preamble_symbols,frames_passed,frames_total (noise before signal, random phase, offset within +/-15 Hz, 10 dB SNR)";
for (int preamble : {8, 16, 24, 32, 48, 64})
{
const QVector<float> shortWaveform = prependSilence(modulate(encodeBits(payload, 0, preamble)), 2000);
int passed = 0;
constexpr int trials = 20;
for (int trial = 0; trial < trials; ++trial)
{
TrialOptions options;
options.snrDb100Hz = 10.0f;
options.frequencyOffset = -15.0f + 1.5f * (trial % 21);
options.seed = 8000 + trial;
passed += framePassed(shortWaveform, payload, options);
}
qInfo().noquote() << QString("%1,%2,%3").arg(preamble).arg(passed).arg(trials);
}
qInfo().noquote() << "Abrupt_end_SNR_dB,trials_with_characters_after_end,trials_total (no carrier tail, then noise)";
for (int snrDb : {20, 10, 5})
{
constexpr int trials = 100;
qInfo().noquote() << QString("%1,%2,%3").arg(snrDb).arg(abruptEndTrials(waveform, payload, snrDb, trials)).arg(trials);
}
qInfo().noquote() << "Fade_ms,average_character_errors (fade to -40 dB inside text, 15 dB SNR)";
for (int fadeMs : {0, 50, 100, 200, 300, 500})
{
int errors = 0;
constexpr int trials = 10;
for (int trial = 0; trial < trials; ++trial)
{
TrialOptions options;
options.snrDb100Hz = 15.0f;
options.fadeStart = 256 * samplesPerSymbol + 40 * samplesPerSymbol + trial * 7;
options.fadeLength = fadeMs;
options.seed = 6000 + trial;
const QString received = runTrial(waveform, options).received;
errors += editDistance(received, payload);
if (argsStr.contains("trace", Qt::CaseInsensitive)) {
qInfo().noquote() << " " << escaped(received);
}
}
qInfo().noquote() << QString("%1,%2").arg(fadeMs).arg(errors / static_cast<float>(trials), 0, 'f', 1);
}
qInfo().noquote() << "Channel_path_interferers,frames_passed,frames_total (1536 S/s channel, 10 dB SNR)";
const std::vector<std::pair<QString, std::vector<ChannelInterferer>>> channelCases = {
{"none", {}},
{"PSK31 +20 dB at +/-75 Hz", {{75.0f, 20.0f, true}, {-75.0f, 20.0f, true}}},
{"PSK31 +30 dB at 100 Hz", {{100.0f, 30.0f, true}}},
{"CW +40 dB at 300 Hz", {{300.0f, 40.0f, false}}},
{"CW +40 dB at -600 Hz (aliases)", {{-600.0f, 40.0f, false}}},
};
for (const auto& channelCase : channelCases)
{
int passed = 0;
constexpr int trials = 5;
for (int trial = 0; trial < trials; ++trial) {
passed += runChannelTrial(waveform, 1536, 200, 7.0f, channelCase.second, 10.0f, 7000 + trial).contains(payload);
}
qInfo().noquote() << QString("%1,%2,%3").arg(channelCase.first).arg(passed).arg(trials);
}
measureNoiseRejection();
measureCPUPerformance();
}
bool testDecoder()
{
PSK31Encoder encoder;
PSK31Decoder decoder;
QVector<int> decoded;
bool success = true;
// 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<char>(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);
}
// Overlong runs of ones, such as unmodulated carrier, must not decode.
// A 14-bit run would leave "1" (space) after a naive overflow reset.
for (int ones : {13, 14, 15, 17, 40})
{
for (int i = 0; i < ones; ++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);
}
return success && (received == message);
}
}
void MainBench::testPSK31(const QString& argsStr)
{
const bool decoderPassed = testDecoder();
bool success = decoderPassed;
const QString payload("CQ CQ DE SDRANGEL 0123456789\r\n");
const QVector<float> waveform = modulate(encodeBits(payload));
const QVector<float> cosineWaveform = modulate(encodeBits(payload), PulseShape::CosineEnvelope);
TrialOptions nominal;
nominal.snrDb100Hz = 20.0f;
const TrialResult nominalResult = runTrial(waveform, nominal);
const bool nominalPassed = nominalResult.received.contains(payload);
const bool snrPassed = std::abs(nominalResult.snr - nominal.snrDb100Hz) < 2.0f;
const bool cosinePassed = framePassed(cosineWaveform, payload, nominal);
TrialOptions wideBandwidth = nominal;
wideBandwidth.rfBandwidth = 200.0f;
const TrialResult wideResult = runTrial(waveform, wideBandwidth);
const bool wideBandwidthPassed = wideResult.received.contains(payload);
const bool bandwidthNormalized = std::abs(wideResult.snr - nominalResult.snr) < 1.0f;
TrialOptions glitch;
glitch.phaseGlitchStart = 250 * samplesPerSymbol + 2;
glitch.phaseGlitchLength = 12;
const bool glitchPassed = framePassed(waveform, payload, glitch);
// Carrier acquisition beyond the Costas loop's own pull-in range
bool offsetPassed = true;
for (float offset : {-30.0f, -20.0f, 20.0f, 30.0f})
{
TrialOptions options = nominal;
options.frequencyOffset = offset;
offsetPassed = offsetPassed && framePassed(waveform, payload, options);
}
// Unmodulated carrier at the end of a transmission must not produce a
// character. Afterwards, lock and SNR must not be left stale.
TrialOptions tail = nominal;
const TrialResult tailResult = runTrial(appendSilence(modulate(encodeBits(payload, 40)), 3000), tail);
const bool tailPassed = tailResult.received.endsWith(payload);
const bool unlockPassed = !tailResult.locked && (tailResult.snr == 0.0f);
// Transmission ending without a carrier tail must not have noise decoded
// after it
const int abruptEndExtra = abruptEndTrials(waveform, payload, 20.0f, 40);
const bool abruptEndPassed = abruptEndExtra == 0;
// Transmission starting with a typical one second of idle
TrialOptions shortPreamble = nominal;
shortPreamble.frequencyOffset = 12.0f;
const bool shortPreamblePassed = framePassed(
prependSilence(modulate(encodeBits(payload, 0, 32)), 2000), payload, shortPreamble);
// Short fade inside text must not lose lock
TrialOptions fade = nominal;
fade.fadeStart = 256 * samplesPerSymbol + 40 * samplesPerSymbol;
fade.fadeLength = 100;
const int fadeErrors = editDistance(runTrial(waveform, fade).received, payload);
const bool fadePassed = fadeErrors <= 2;
// Full channel path with strong adjacent signals
const QString channelReceived = runChannelTrial(
waveform, 1536, 200, 7.0f,
{{100.0f, 30.0f, true}, {-75.0f, 20.0f, true}, {-600.0f, 40.0f, false}},
15.0f, 7000);
const bool channelPassed = channelReceived.contains(payload);
if (!tailPassed) {
qWarning().noquote() << "PSK31 carrier tail received:" << escaped(tailResult.received);
}
if (!channelPassed) {
qWarning().noquote() << "PSK31 channel path received:" << escaped(channelReceived);
}
success = success && nominalPassed && snrPassed && cosinePassed && wideBandwidthPassed && bandwidthNormalized
&& glitchPassed && offsetPassed && tailPassed && unlockPassed && abruptEndPassed && shortPreamblePassed
&& fadePassed && channelPassed;
qInfo() << "PSK31 regressions: decoder" << decoderPassed
<< "nominal" << nominalPassed
<< "reported SNR" << nominalResult.snr << "valid" << snrPassed
<< "cosine envelope" << cosinePassed
<< "200 Hz SNR" << wideResult.snr << "normalized" << bandwidthNormalized
<< "phase glitch" << glitchPassed
<< "frequency offset" << offsetPassed
<< "carrier tail" << tailPassed << "unlock" << unlockPassed
<< "abrupt end extra" << abruptEndExtra
<< "short preamble" << shortPreamblePassed
<< "fade errors" << fadeErrors
<< "channel path" << channelPassed;
const NoiseResult noise = runNoiseTrial(noiseDurationSeconds, noiseLevelDbFS, 6000);
success = success && (noise.characters == 0);
if (argsStr.contains("perf", Qt::CaseInsensitive)) {
measurePerformance(waveform, cosineWaveform, payload, argsStr);
}
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).received;
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";
}
}

219
sdrgui/gui/acronymview.cpp

@ -19,10 +19,18 @@ @@ -19,10 +19,18 @@
///////////////////////////////////////////////////////////////////////////////////
#include <QEvent>
#include <QDesktopServices>
#include <QHelpEvent>
#include <QMouseEvent>
#include <QRegularExpression>
#include <QTextBlock>
#include <QToolTip>
#include <QUrl>
#include <QDebug>
#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) @@ -37,21 +45,45 @@ bool AcronymView::event(QEvent* event)
if (event->type() == QEvent::ToolTip)
{
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(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) @@ -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);

18
sdrgui/gui/acronymview.h

@ -26,11 +26,27 @@ @@ -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<QString, QString> 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:

3
swagger/sdrangel/api/swagger/include/ChannelReport.yaml

@ -160,6 +160,9 @@ ChannelReport: @@ -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."

3
swagger/sdrangel/api/swagger/include/ChannelSettings.yaml

@ -166,6 +166,9 @@ ChannelSettings: @@ -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."

95
swagger/sdrangel/api/swagger/include/PSK31Demod.yaml

@ -0,0 +1,95 @@ @@ -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: "Carrier-frequency estimate in Hz relative to the selected channel frequency. Only present when locked."
snr:
type: number
format: float
description: "Signal-to-noise ratio in dB, normalized to a 100 Hz noise bandwidth. Only present when locked."
locked:
type: integer
minimum: 0
maximum: 1
description: "Whether a PSK31 signal is locked and being decoded."

10
swagger/sdrangel/api/swagger/include/PSK31Mod.yaml

@ -54,16 +54,6 @@ PSK31ModSettings: @@ -54,16 +54,6 @@ PSK31ModSettings:
symbolSpan:
type: integer
description: "Symbol span setting for Psk31 mod."
prefixCRLF:
type: integer
description: "Enable prefix crlf (1 enabled, 0 disabled)."
minimum: 0
maximum: 1
postfixCRLF:
type: integer
description: "Enable postfix crlf (1 enabled, 0 disabled)."
minimum: 0
maximum: 1
udpEnabled:
description: "Whether to receive text to transmit on specified UDP port"
type: integer

25
swagger/sdrangel/code/qt5/client/SWGChannelReport.cpp

@ -130,6 +130,8 @@ SWGChannelReport::SWGChannelReport() { @@ -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() { @@ -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() { @@ -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) { @@ -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() { @@ -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) { @@ -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(){ @@ -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(){ @@ -1555,4 +1579,3 @@ SWGChannelReport::isSet(){
return isObjectUpdated;
}
}

7
swagger/sdrangel/code/qt5/client/SWGChannelReport.h

@ -65,6 +65,7 @@ @@ -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: @@ -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: @@ -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;

25
swagger/sdrangel/code/qt5/client/SWGChannelSettings.cpp

@ -134,6 +134,8 @@ SWGChannelSettings::SWGChannelSettings() { @@ -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() { @@ -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() { @@ -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) { @@ -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() { @@ -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 @@ -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(){ @@ -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(){ @@ -1826,4 +1850,3 @@ SWGChannelSettings::isSet(){
return isObjectUpdated;
}
}

7
swagger/sdrangel/code/qt5/client/SWGChannelSettings.h

@ -72,6 +72,7 @@ @@ -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: @@ -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: @@ -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;

193
swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.cpp

@ -0,0 +1,193 @@ @@ -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 <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
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;
}
}

82
swagger/sdrangel/code/qt5/client/SWGPSK31DemodReport.h

@ -0,0 +1,82 @@ @@ -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 <QJsonObject>
#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_ */

520
swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.cpp

@ -0,0 +1,520 @@ @@ -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 <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
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;
}
}

164
swagger/sdrangel/code/qt5/client/SWGPSK31DemodSettings.h

@ -0,0 +1,164 @@ @@ -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 <QJsonObject>
#include "SWGChannelMarker.h"
#include "SWGGLScope.h"
#include "SWGRollupState.h"
#include <QString>
#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_ */

45
swagger/sdrangel/code/qt5/client/SWGPSK31ModSettings.cpp

@ -52,10 +52,6 @@ SWGPSK31ModSettings::SWGPSK31ModSettings() { @@ -52,10 +52,6 @@ SWGPSK31ModSettings::SWGPSK31ModSettings() {
m_beta_isSet = false;
symbol_span = 0;
m_symbol_span_isSet = false;
prefix_crlf = 0;
m_prefix_crlf_isSet = false;
postfix_crlf = 0;
m_postfix_crlf_isSet = false;
udp_enabled = 0;
m_udp_enabled_isSet = false;
udp_address = nullptr;
@ -114,10 +110,6 @@ SWGPSK31ModSettings::init() { @@ -114,10 +110,6 @@ SWGPSK31ModSettings::init() {
m_beta_isSet = false;
symbol_span = 0;
m_symbol_span_isSet = false;
prefix_crlf = 0;
m_prefix_crlf_isSet = false;
postfix_crlf = 0;
m_postfix_crlf_isSet = false;
udp_enabled = 0;
m_udp_enabled_isSet = false;
udp_address = new QString("");
@ -224,10 +216,6 @@ SWGPSK31ModSettings::fromJsonObject(QJsonObject &pJson) { @@ -224,10 +216,6 @@ SWGPSK31ModSettings::fromJsonObject(QJsonObject &pJson) {
::SWGSDRangel::setValue(&symbol_span, pJson["symbolSpan"], "qint32", "");
::SWGSDRangel::setValue(&prefix_crlf, pJson["prefixCRLF"], "qint32", "");
::SWGSDRangel::setValue(&postfix_crlf, pJson["postfixCRLF"], "qint32", "");
::SWGSDRangel::setValue(&udp_enabled, pJson["udpEnabled"], "qint32", "");
::SWGSDRangel::setValue(&udp_address, pJson["udpAddress"], "QString", "QString");
@ -306,12 +294,6 @@ SWGPSK31ModSettings::asJsonObject() { @@ -306,12 +294,6 @@ SWGPSK31ModSettings::asJsonObject() {
if(m_symbol_span_isSet){
obj->insert("symbolSpan", QJsonValue(symbol_span));
}
if(m_prefix_crlf_isSet){
obj->insert("prefixCRLF", QJsonValue(prefix_crlf));
}
if(m_postfix_crlf_isSet){
obj->insert("postfixCRLF", QJsonValue(postfix_crlf));
}
if(m_udp_enabled_isSet){
obj->insert("udpEnabled", QJsonValue(udp_enabled));
}
@ -475,26 +457,6 @@ SWGPSK31ModSettings::setSymbolSpan(qint32 symbol_span) { @@ -475,26 +457,6 @@ SWGPSK31ModSettings::setSymbolSpan(qint32 symbol_span) {
this->m_symbol_span_isSet = true;
}
qint32
SWGPSK31ModSettings::getPrefixCrlf() {
return prefix_crlf;
}
void
SWGPSK31ModSettings::setPrefixCrlf(qint32 prefix_crlf) {
this->prefix_crlf = prefix_crlf;
this->m_prefix_crlf_isSet = true;
}
qint32
SWGPSK31ModSettings::getPostfixCrlf() {
return postfix_crlf;
}
void
SWGPSK31ModSettings::setPostfixCrlf(qint32 postfix_crlf) {
this->postfix_crlf = postfix_crlf;
this->m_postfix_crlf_isSet = true;
}
qint32
SWGPSK31ModSettings::getUdpEnabled() {
return udp_enabled;
@ -666,12 +628,6 @@ SWGPSK31ModSettings::isSet(){ @@ -666,12 +628,6 @@ SWGPSK31ModSettings::isSet(){
if(m_symbol_span_isSet){
isObjectUpdated = true; break;
}
if(m_prefix_crlf_isSet){
isObjectUpdated = true; break;
}
if(m_postfix_crlf_isSet){
isObjectUpdated = true; break;
}
if(m_udp_enabled_isSet){
isObjectUpdated = true; break;
}
@ -715,4 +671,3 @@ SWGPSK31ModSettings::isSet(){ @@ -715,4 +671,3 @@ SWGPSK31ModSettings::isSet(){
return isObjectUpdated;
}
}

12
swagger/sdrangel/code/qt5/client/SWGPSK31ModSettings.h

@ -80,12 +80,6 @@ public: @@ -80,12 +80,6 @@ public:
qint32 getSymbolSpan();
void setSymbolSpan(qint32 symbol_span);
qint32 getPrefixCrlf();
void setPrefixCrlf(qint32 prefix_crlf);
qint32 getPostfixCrlf();
void setPostfixCrlf(qint32 postfix_crlf);
qint32 getUdpEnabled();
void setUdpEnabled(qint32 udp_enabled);
@ -165,12 +159,6 @@ private: @@ -165,12 +159,6 @@ private:
qint32 symbol_span;
bool m_symbol_span_isSet;
qint32 prefix_crlf;
bool m_prefix_crlf_isSet;
qint32 postfix_crlf;
bool m_postfix_crlf_isSet;
qint32 udp_enabled;
bool m_udp_enabled_isSet;

Loading…
Cancel
Save