From f5968816ef1600a26411ad5d3d43790b4cf5f1a5 Mon Sep 17 00:00:00 2001 From: srcejon Date: Fri, 1 Sep 2023 17:10:26 +0100 Subject: [PATCH 01/24] Add initial RTTY Mod without API --- CMakeLists.txt | 1 + plugins/channeltx/CMakeLists.txt | 4 + plugins/channeltx/modrtty/CMakeLists.txt | 69 ++ plugins/channeltx/modrtty/readme.md | 113 ++ plugins/channeltx/modrtty/rttymod.cpp | 886 ++++++++++++++++ plugins/channeltx/modrtty/rttymod.h | 264 +++++ plugins/channeltx/modrtty/rttymodbaseband.cpp | 207 ++++ plugins/channeltx/modrtty/rttymodbaseband.h | 100 ++ plugins/channeltx/modrtty/rttymodgui.cpp | 663 ++++++++++++ plugins/channeltx/modrtty/rttymodgui.h | 130 +++ plugins/channeltx/modrtty/rttymodgui.ui | 975 ++++++++++++++++++ plugins/channeltx/modrtty/rttymodplugin.cpp | 92 ++ plugins/channeltx/modrtty/rttymodplugin.h | 49 + .../channeltx/modrtty/rttymodrepeatdialog.cpp | 43 + .../channeltx/modrtty/rttymodrepeatdialog.h | 39 + .../channeltx/modrtty/rttymodrepeatdialog.ui | 116 +++ plugins/channeltx/modrtty/rttymodsettings.cpp | 236 +++++ plugins/channeltx/modrtty/rttymodsettings.h | 81 ++ plugins/channeltx/modrtty/rttymodsource.cpp | 438 ++++++++ plugins/channeltx/modrtty/rttymodsource.h | 134 +++ .../modrtty/rttymodtxsettingsdialog.cpp | 112 ++ .../modrtty/rttymodtxsettingsdialog.h | 44 + .../modrtty/rttymodtxsettingsdialog.ui | 294 ++++++ .../modrtty/rttymodwebapiadapter.cpp | 53 + .../channeltx/modrtty/rttymodwebapiadapter.h | 50 + sdrbase/util/baudot.cpp | 193 +++- sdrbase/util/baudot.h | 62 +- .../api/swagger/include/ChannelActions.yaml | 2 + .../api/swagger/include/ChannelReport.yaml | 2 + .../api/swagger/include/ChannelSettings.yaml | 2 + .../sdrangel/api/swagger/include/RTTYMod.yaml | 106 ++ 31 files changed, 5533 insertions(+), 27 deletions(-) create mode 100644 plugins/channeltx/modrtty/CMakeLists.txt create mode 100644 plugins/channeltx/modrtty/readme.md create mode 100644 plugins/channeltx/modrtty/rttymod.cpp create mode 100644 plugins/channeltx/modrtty/rttymod.h create mode 100644 plugins/channeltx/modrtty/rttymodbaseband.cpp create mode 100644 plugins/channeltx/modrtty/rttymodbaseband.h create mode 100644 plugins/channeltx/modrtty/rttymodgui.cpp create mode 100644 plugins/channeltx/modrtty/rttymodgui.h create mode 100644 plugins/channeltx/modrtty/rttymodgui.ui create mode 100644 plugins/channeltx/modrtty/rttymodplugin.cpp create mode 100644 plugins/channeltx/modrtty/rttymodplugin.h create mode 100644 plugins/channeltx/modrtty/rttymodrepeatdialog.cpp create mode 100644 plugins/channeltx/modrtty/rttymodrepeatdialog.h create mode 100644 plugins/channeltx/modrtty/rttymodrepeatdialog.ui create mode 100644 plugins/channeltx/modrtty/rttymodsettings.cpp create mode 100644 plugins/channeltx/modrtty/rttymodsettings.h create mode 100644 plugins/channeltx/modrtty/rttymodsource.cpp create mode 100644 plugins/channeltx/modrtty/rttymodsource.h create mode 100644 plugins/channeltx/modrtty/rttymodtxsettingsdialog.cpp create mode 100644 plugins/channeltx/modrtty/rttymodtxsettingsdialog.h create mode 100644 plugins/channeltx/modrtty/rttymodtxsettingsdialog.ui create mode 100644 plugins/channeltx/modrtty/rttymodwebapiadapter.cpp create mode 100644 plugins/channeltx/modrtty/rttymodwebapiadapter.h create mode 100644 swagger/sdrangel/api/swagger/include/RTTYMod.yaml diff --git a/CMakeLists.txt b/CMakeLists.txt index 457247ed01..d02fea41f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ option(ENABLE_CHANNELTX_MODATV "Enable channeltx modatv plugin" ON) option(ENABLE_CHANNELTX_MOD802.15.4 "Enable channeltx mod802.15.4 plugin" ON) option(ENABLE_CHANNELTX_REMOTESOURCE "Enable channeltx remotesource plugin" ON) option(ENABLE_CHANNELTX_FILESOURCE "Enable channeltx filesource plugin" ON) +option(ENABLE_CHANNELTX_MODRTTY "Enable channeltx modrtty plugin" ON) # Channel MIMO enablers option(ENABLE_CHANNELMIMO "Enable channelmimo plugins" ON) diff --git a/plugins/channeltx/CMakeLists.txt b/plugins/channeltx/CMakeLists.txt index 586a7536a0..bb54edddbd 100644 --- a/plugins/channeltx/CMakeLists.txt +++ b/plugins/channeltx/CMakeLists.txt @@ -1,5 +1,9 @@ project(mod) +if (ENABLE_CHANNELTX_MODRTTY) + add_subdirectory(modrtty) +endif() + if (ENABLE_CHANNELTX_MODAIS) add_subdirectory(modais) endif() diff --git a/plugins/channeltx/modrtty/CMakeLists.txt b/plugins/channeltx/modrtty/CMakeLists.txt new file mode 100644 index 0000000000..32ee10bd11 --- /dev/null +++ b/plugins/channeltx/modrtty/CMakeLists.txt @@ -0,0 +1,69 @@ +project(modrtty) + +set(modrtty_SOURCES + rttymod.cpp + rttymodbaseband.cpp + rttymodsource.cpp + rttymodplugin.cpp + rttymodsettings.cpp + rttymodwebapiadapter.cpp +) + +set(modrtty_HEADERS + rttymod.h + rttymodbaseband.h + rttymodsource.h + rttymodplugin.h + rttymodsettings.h + rttymodwebapiadapter.h +) + +include_directories( + ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client +) + +if(NOT SERVER_MODE) + set(modrtty_SOURCES + ${modrtty_SOURCES} + rttymodgui.cpp + rttymodgui.ui + rttymodrepeatdialog.cpp + rttymodrepeatdialog.ui + rttymodtxsettingsdialog.cpp + rttymodtxsettingsdialog.ui + ) + set(modrtty_HEADERS + ${modrtty_HEADERS} + rttymodgui.h + rttymodrepeatdialog.h + rttymodtxsettingsdialog.h + ) + set(TARGET_NAME modrtty) + set(TARGET_LIB "Qt::Widgets") + set(TARGET_LIB_GUI "sdrgui") + set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR}) +else() + set(TARGET_NAME modrttysrv) + set(TARGET_LIB "") + set(TARGET_LIB_GUI "") + set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR}) +endif() + +add_library(${TARGET_NAME} SHARED + ${modrtty_SOURCES} +) + +target_link_libraries(${TARGET_NAME} + Qt::Core + ${TARGET_LIB} + sdrbase + ${TARGET_LIB_GUI} + swagger +) + +install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER}) + +# Install debug symbols +if (WIN32) + install(FILES $ CONFIGURATIONS Debug RelWithDebInfo DESTINATION ${INSTALL_FOLDER} ) +endif() diff --git a/plugins/channeltx/modrtty/readme.md b/plugins/channeltx/modrtty/readme.md new file mode 100644 index 0000000000..9e6dd7dc95 --- /dev/null +++ b/plugins/channeltx/modrtty/readme.md @@ -0,0 +1,113 @@ +

RTTY Modulator Plugin

+ +

Introduction

+ +This plugin can be used to transmit RTTY encoded text. + +

Interface

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

1: Frequency shift from center frequency of transmission

+ +Use the wheels to adjust the frequency shift in Hz from the center frequency of transmission. Left click on a digit sets the cursor position at this digit. Right click on a digit sets all digits on the right to zero. This effectively floors value at the digit position. Wheels are moved with the mousewheel while pointing at the wheel or by selecting the wheel with the left mouse click and using the keyboard arrows. Pressing shift simultaneously moves digit by 5 and pressing control moves it by 2. + +

2: Channel power

+ +Average total power in dB relative to a +/- 1.0 amplitude signal generated in the pass band. + +

3: Channel mute

+ +Use this button to toggle mute for this channel. + +

4: Mode

+ +Contains a list of common baud rate and frequency shift settings. To specify your own, set this option to Custom. + +45.45/170 is common for amateur RTTY. + +

5: Baud

+ +Specifies the baud rate in symbols (bits) per second. + +

6: Frequency Shift

+ +Adjusts the frequency shift (different between mark and space frequencies) in Hz. + +

7: RF Bandwidth

+ +This specifies the bandwidth of a LPF that is applied to the output signal to limit the RF bandwidth. + +

8: Gain

+ +Adjusts the gain in dB from -60 to 0dB. + +

9: Level meter in %

+ + - top bar (beige): average value + - bottom bar (brown): instantaneous peak value + - tip vertical bar (bright red): peak hold value + +

10: UDP

+ +When checked, a UDP port is opened to receive text from other features or applications that will be transmitted. + +

11: UDP address

+ +IP address of the interface to open the UDP port on, to receive text to be transmitted. + +

12: UDP port

+ +UDP port number to receive text to be transmitted on. + +

13: Baudot Character Set

+ +Specifies the Baudot character set used to encode the text to transmit. + +

14: Bit Ordering

+ +Specifies whether bits are transmitted least-significant-bit first (LSB) or most-significant-bit first (MSB). + +

15: Mark/Space Frequency

+ +When unchecked, the mark frequency is the higher RF frequency, when checked the space frequency is higher. + +

16: Unshift on Space

+ +When checked, the Baudot character set will shift to letters when a space character (' ') is transmitted. + +

17: Repeat

+ +Check this button to repeatedly transmit a packet. Right click to open the dialog to adjust the number of times the packet should be repeated. + +

18: Clear Transmitted Text

+ +Press to clear the transmitted text. + +

19: Text to Transmit

+ +Enter text to transmit. Pressing return will transmit the text and clear this field. Press the arrow to display and select a list of pre-defined text or previously transmitted text to enter in to the field. + +

20: TX

+ +Press to transmits the current text. The text field will not be cleared. + +Right click to open a dialog to adjust additional transmitter settings. + +

API

+ +Full details of the API can be found in the Swagger documentation. Below are a few examples. + +To transmit the current text simply send a "tx" action: + + curl -X POST "http://127.0.0.1:8091/sdrangel/deviceset/1/channel/0/actions" -d '{"channelType": "RttyMod", "direction": 1, "RttyModActions": { "tx": 1}}' + +To transmit a packet from the command line: + + curl -X POST "http://127.0.0.1:8091/sdrangel/deviceset/1/channel/0/actions" -d '{"channelType": "RttyMod", "direction": 1, "RttyModActions": { "tx": 1, "payload": {"text": "CQ CQ CQ anyone using SDRangel" }}}' + +To set the baud rate and frequency shift: + + curl -X PATCH "http://127.0.0.1:8091/sdrangel/deviceset/1/channel/0/settings" -d '{"channelType": "RttyMod", "direction": 1, "RttyModSettings": {"baud": 45.45; "frequencyShift": 170 }}' diff --git a/plugins/channeltx/modrtty/rttymod.cpp b/plugins/channeltx/modrtty/rttymod.cpp new file mode 100644 index 0000000000..bea3218325 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymod.cpp @@ -0,0 +1,886 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SWGChannelSettings.h" +#include "SWGWorkspaceInfo.h" +#include "SWGChannelReport.h" +#include "SWGChannelActions.h" +/*#include "SWGRttyModReport.h" +#include "SWGRttyModActions.h"*/ + +#include +#include +#include + +#include "dsp/dspengine.h" +#include "dsp/dspcommands.h" +#include "device/deviceapi.h" +#include "feature/feature.h" +#include "util/db.h" +#include "util/crc.h" +#include "maincore.h" + +#include "rttymodbaseband.h" +#include "rttymod.h" + +MESSAGE_CLASS_DEFINITION(RttyMod::MsgConfigureRttyMod, Message) +MESSAGE_CLASS_DEFINITION(RttyMod::MsgTx, Message) +MESSAGE_CLASS_DEFINITION(RttyMod::MsgReportTx, Message) +MESSAGE_CLASS_DEFINITION(RttyMod::MsgTXPacketBytes, Message) +MESSAGE_CLASS_DEFINITION(RttyMod::MsgTXPacketData, Message) + +const char* const RttyMod::m_channelIdURI = "sdrangel.channeltx.modrtty"; +const char* const RttyMod::m_channelId = "RttyMod"; + +RttyMod::RttyMod(DeviceAPI *deviceAPI) : + ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), + m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_TX_SCALEF), + m_sampleRate(48000), + m_udpSocket(nullptr) +{ + setObjectName(m_channelId); + + m_thread = new QThread(this); + m_basebandSource = new RttyModBaseband(); + m_basebandSource->setSpectrumSampleSink(&m_spectrumVis); + m_basebandSource->setChannel(this); + m_basebandSource->moveToThread(m_thread); + + applySettings(m_settings, true); + + m_deviceAPI->addChannelSource(this); + m_deviceAPI->addChannelSourceAPI(this); + + m_networkManager = new QNetworkAccessManager(); + QObject::connect( + m_networkManager, + &QNetworkAccessManager::finished, + this, + &RttyMod::networkManagerFinished + ); +} + +RttyMod::~RttyMod() +{ + closeUDP(); + QObject::connect( + m_networkManager, + &QNetworkAccessManager::finished, + this, + &RttyMod::networkManagerFinished + ); + delete m_networkManager; + m_deviceAPI->removeChannelSourceAPI(this); + m_deviceAPI->removeChannelSource(this); + delete m_basebandSource; + delete m_thread; +} + +void RttyMod::setDeviceAPI(DeviceAPI *deviceAPI) +{ + if (deviceAPI != m_deviceAPI) + { + m_deviceAPI->removeChannelSourceAPI(this); + m_deviceAPI->removeChannelSource(this); + m_deviceAPI = deviceAPI; + m_deviceAPI->addChannelSource(this); + m_deviceAPI->addChannelSinkAPI(this); + } +} + +void RttyMod::start() +{ + qDebug("RttyMod::start"); + m_basebandSource->reset(); + m_thread->start(); +} + +void RttyMod::stop() +{ + qDebug("RttyMod::stop"); + m_thread->exit(); + m_thread->wait(); +} + +void RttyMod::pull(SampleVector::iterator& begin, unsigned int nbSamples) +{ + m_basebandSource->pull(begin, nbSamples); +} + +bool RttyMod::handleMessage(const Message& cmd) +{ + if (MsgConfigureRttyMod::match(cmd)) + { + MsgConfigureRttyMod& cfg = (MsgConfigureRttyMod&) cmd; + qDebug() << "RttyMod::handleMessage: MsgConfigureRttyMod"; + + applySettings(cfg.getSettings(), cfg.getForce()); + + return true; + } + else if (MsgTx::match(cmd)) + { + MsgTx* msg = new MsgTx((const MsgTx&)cmd); + m_basebandSource->getInputMessageQueue()->push(msg); + + return true; + } + else if (MsgTXPacketData::match(cmd)) + { + MsgTXPacketData* msg = new MsgTXPacketData((const MsgTXPacketData&)cmd); + m_basebandSource->getInputMessageQueue()->push(msg); + + return true; + } + else if (DSPSignalNotification::match(cmd)) + { + // Forward to the source + DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy + qDebug() << "RttyMod::handleMessage: DSPSignalNotification"; + m_basebandSource->getInputMessageQueue()->push(rep); + // Forward to GUI if any + if (getMessageQueueToGUI()) { + getMessageQueueToGUI()->push(new DSPSignalNotification(notif)); + } + + return true; + } + else if (MainCore::MsgChannelDemodQuery::match(cmd)) + { + qDebug() << "RttyMod::handleMessage: MsgChannelDemodQuery"; + sendSampleRateToDemodAnalyzer(); + + return true; + } + else + { + return false; + } +} + +void RttyMod::setCenterFrequency(qint64 frequency) +{ + RttyModSettings settings = m_settings; + settings.m_inputFrequencyOffset = frequency; + applySettings(settings, false); + + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigureRttyMod *msgToGUI = MsgConfigureRttyMod::create(settings, false); + m_guiMessageQueue->push(msgToGUI); + } +} + +void RttyMod::applySettings(const RttyModSettings& settings, bool force) +{ + qDebug() << "RttyMod::applySettings:" + << " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset + << " m_baud: " << settings.m_baud + << " m_rfBandwidth: " << settings.m_rfBandwidth + << " m_frequencyShift: " << settings.m_frequencyShift + << " m_gain: " << settings.m_gain + << " m_channelMute: " << settings.m_channelMute + << " m_repeat: " << settings.m_repeat + << " m_repeatCount: " << settings.m_repeatCount + << " m_useReverseAPI: " << settings.m_useReverseAPI + << " m_reverseAPIAddress: " << settings.m_reverseAPIAddress + << " m_reverseAPIAddress: " << settings.m_reverseAPIPort + << " m_reverseAPIDeviceIndex: " << settings.m_reverseAPIDeviceIndex + << " m_reverseAPIChannelIndex: " << settings.m_reverseAPIChannelIndex + << " force: " << force; + + QList reverseAPIKeys; + + if ((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) { + reverseAPIKeys.append("inputFrequencyOffset"); + } + + if ((settings.m_baud != m_settings.m_baud) || force) { + reverseAPIKeys.append("baud"); + } + + if ((settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force) { + reverseAPIKeys.append("rfBandwidth"); + } + + if ((settings.m_frequencyShift != m_settings.m_frequencyShift) || force) { + reverseAPIKeys.append("frequencyShift"); + } + + if ((settings.m_gain != m_settings.m_gain) || force) { + reverseAPIKeys.append("gain"); + } + + if ((settings.m_channelMute != m_settings.m_channelMute) || force) { + reverseAPIKeys.append("channelMute"); + } + + if ((settings.m_repeat != m_settings.m_repeat) || force) { + reverseAPIKeys.append("repeat"); + } + + if ((settings.m_repeatCount != m_settings.m_repeatCount) || force) { + reverseAPIKeys.append("repeatCount"); + } + + if ((settings.m_lpfTaps != m_settings.m_lpfTaps) || force) { + reverseAPIKeys.append("lpfTaps"); + } + + if ((settings.m_bbNoise != m_settings.m_bbNoise) || force) { + reverseAPIKeys.append("bbNoise"); + } + + if ((settings.m_rfNoise != m_settings.m_rfNoise) || force) { + reverseAPIKeys.append("rfNoise"); + } + + if ((settings.m_writeToFile != m_settings.m_writeToFile) || force) { + reverseAPIKeys.append("writeToFile"); + } + + if ((settings.m_data != m_settings.m_data) || force) { + reverseAPIKeys.append("data"); + } + + if ((settings.m_beta != m_settings.m_beta) || force) { + reverseAPIKeys.append("beta"); + } + + if ((settings.m_symbolSpan != m_settings.m_symbolSpan) || force) { + reverseAPIKeys.append("symbolSpan"); + } + + if ((settings.m_udpEnabled != m_settings.m_udpEnabled) || force) { + reverseAPIKeys.append("udpEnabled"); + } + + if ((settings.m_udpAddress != m_settings.m_udpAddress) || force) { + reverseAPIKeys.append("udpAddress"); + } + + if ((settings.m_udpPort != m_settings.m_udpPort) || force) { + reverseAPIKeys.append("udpPort"); + } + + if ( (settings.m_udpEnabled != m_settings.m_udpEnabled) + || (settings.m_udpAddress != m_settings.m_udpAddress) + || (settings.m_udpPort != m_settings.m_udpPort) + || force) + { + if (settings.m_udpEnabled) + openUDP(settings); + else + closeUDP(); + } + + if (m_settings.m_streamIndex != settings.m_streamIndex) + { + if (m_deviceAPI->getSampleMIMO()) // change of stream is possible for MIMO devices only + { + m_deviceAPI->removeChannelSourceAPI(this); + m_deviceAPI->removeChannelSource(this, m_settings.m_streamIndex); + m_deviceAPI->addChannelSource(this, settings.m_streamIndex); + m_deviceAPI->addChannelSourceAPI(this); + } + + reverseAPIKeys.append("streamIndex"); + } + + RttyModBaseband::MsgConfigureRttyModBaseband *msg = RttyModBaseband::MsgConfigureRttyModBaseband::create(settings, force); + m_basebandSource->getInputMessageQueue()->push(msg); + + if (settings.m_useReverseAPI) + { + bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) || + (m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) || + (m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) || + (m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) || + (m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex); + webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force); + } + + QList pipes; + MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes); + + if (pipes.size() > 0) { + sendChannelSettings(pipes, reverseAPIKeys, settings, force); + } + + m_settings = settings; +} + +QByteArray RttyMod::serialize() const +{ + return m_settings.serialize(); +} + +bool RttyMod::deserialize(const QByteArray& data) +{ + bool success = true; + + if (!m_settings.deserialize(data)) + { + m_settings.resetToDefaults(); + success = false; + } + + MsgConfigureRttyMod *msg = MsgConfigureRttyMod::create(m_settings, true); + m_inputMessageQueue.push(msg); + + return success; +} + +void RttyMod::sendSampleRateToDemodAnalyzer() +{ + QList pipes; + MainCore::instance()->getMessagePipes().getMessagePipes(this, "reportdemod", pipes); + + if (pipes.size() > 0) + { + for (const auto& pipe : pipes) + { + MessageQueue* messageQueue = qobject_cast(pipe->m_element); + MainCore::MsgChannelDemodReport *msg = MainCore::MsgChannelDemodReport::create( + this, + getSourceChannelSampleRate() + ); + messageQueue->push(msg); + } + } +} + +int RttyMod::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + /*response.setRttyModSettings(new SWGSDRangel::SWGRttyModSettings()); + response.getRttyModSettings()->init(); + webapiFormatChannelSettings(response, m_settings); + */ + return 200; +} + +int RttyMod::webapiWorkspaceGet( + SWGSDRangel::SWGWorkspaceInfo& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setIndex(m_settings.m_workspaceIndex); + return 200; +} + +int RttyMod::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + RttyModSettings settings = m_settings; + webapiUpdateChannelSettings(settings, channelSettingsKeys, response); + + MsgConfigureRttyMod *msg = MsgConfigureRttyMod::create(settings, force); + m_inputMessageQueue.push(msg); + + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigureRttyMod *msgToGUI = MsgConfigureRttyMod::create(settings, force); + m_guiMessageQueue->push(msgToGUI); + } + + webapiFormatChannelSettings(response, settings); + + return 200; +} + +void RttyMod::webapiUpdateChannelSettings( + RttyModSettings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response) +{ + /*if (channelSettingsKeys.contains("inputFrequencyOffset")) { + settings.m_inputFrequencyOffset = response.getRttyModSettings()->getInputFrequencyOffset(); + } + if (channelSettingsKeys.contains("baud")) { + settings.m_baud = response.getRttyModSettings()->getBaud(); + } + if (channelSettingsKeys.contains("rfBandwidth")) { + settings.m_rfBandwidth = response.getRttyModSettings()->getRfBandwidth(); + } + if (channelSettingsKeys.contains("frequencyShift")) { + settings.m_frequencyShift = response.getRttyModSettings()->getFrequencyShift(); + } + if (channelSettingsKeys.contains("gain")) { + settings.m_gain = response.getRttyModSettings()->getGain(); + } + if (channelSettingsKeys.contains("channelMute")) { + settings.m_channelMute = response.getRttyModSettings()->getChannelMute() != 0; + } + if (channelSettingsKeys.contains("repeat")) { + settings.m_repeat = response.getRttyModSettings()->getRepeat() != 0; + } + if (channelSettingsKeys.contains("repeatDelay")) { + settings.m_repeatDelay = response.getRttyModSettings()->getRepeatDelay(); + } + if (channelSettingsKeys.contains("repeatCount")) { + settings.m_repeatCount = response.getRttyModSettings()->getRepeatCount(); + } + if (channelSettingsKeys.contains("lpfTaps")) { + settings.m_lpfTaps = response.getRttyModSettings()->getLpfTaps(); + } + if (channelSettingsKeys.contains("bbNoise")) { + settings.m_bbNoise = response.getRttyModSettings()->getBbNoise() != 0; + } + if (channelSettingsKeys.contains("rfNoise")) { + settings.m_rfNoise = response.getRttyModSettings()->getRfNoise() != 0; + } + if (channelSettingsKeys.contains("writeToFile")) { + settings.m_writeToFile = response.getRttyModSettings()->getWriteToFile() != 0; + } + if (channelSettingsKeys.contains("data")) { + settings.m_data = *response.getRttyModSettings()->getData(); + } + if (channelSettingsKeys.contains("beta")) { + settings.m_beta = response.getRttyModSettings()->getBeta(); + } + if (channelSettingsKeys.contains("symbolSpan")) { + settings.m_symbolSpan = response.getRttyModSettings()->getSymbolSpan(); + } + if (channelSettingsKeys.contains("rgbColor")) { + settings.m_rgbColor = response.getRttyModSettings()->getRgbColor(); + } + if (channelSettingsKeys.contains("title")) { + settings.m_title = *response.getRttyModSettings()->getTitle(); + } + if (channelSettingsKeys.contains("streamIndex")) { + settings.m_streamIndex = response.getRttyModSettings()->getStreamIndex(); + } + if (channelSettingsKeys.contains("useReverseAPI")) { + settings.m_useReverseAPI = response.getRttyModSettings()->getUseReverseApi() != 0; + } + if (channelSettingsKeys.contains("reverseAPIAddress")) { + settings.m_reverseAPIAddress = *response.getRttyModSettings()->getReverseApiAddress(); + } + if (channelSettingsKeys.contains("reverseAPIPort")) { + settings.m_reverseAPIPort = response.getRttyModSettings()->getReverseApiPort(); + } + if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) { + settings.m_reverseAPIDeviceIndex = response.getRttyModSettings()->getReverseApiDeviceIndex(); + } + if (channelSettingsKeys.contains("reverseAPIChannelIndex")) { + settings.m_reverseAPIChannelIndex = response.getRttyModSettings()->getReverseApiChannelIndex(); + } + if (channelSettingsKeys.contains("udpEnabled")) { + settings.m_udpEnabled = response.getRttyModSettings()->getUdpEnabled(); + } + if (channelSettingsKeys.contains("udpAddress")) { + settings.m_udpAddress = *response.getRttyModSettings()->getUdpAddress(); + } + if (channelSettingsKeys.contains("udpPort")) { + settings.m_udpPort = response.getRttyModSettings()->getUdpPort(); + } + if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) { + settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getRttyModSettings()->getChannelMarker()); + } + if (settings.m_rollupState && channelSettingsKeys.contains("rollupState")) { + settings.m_rollupState->updateFrom(channelSettingsKeys, response.getRttyModSettings()->getRollupState()); + }*/ +} + +int RttyMod::webapiReportGet( + SWGSDRangel::SWGChannelReport& response, + QString& errorMessage) +{ + (void) errorMessage; + /*response.setRttyModReport(new SWGSDRangel::SWGRttyModReport()); + response.getRttyModReport()->init(); + webapiFormatChannelReport(response);*/ + return 200; +} + +int RttyMod::webapiActionsPost( + const QStringList& channelActionsKeys, + SWGSDRangel::SWGChannelActions& query, + QString& errorMessage) +{ + /*SWGSDRangel::SWGRttyModActions *swgRttyModActions = query.getRttyModActions(); + + if (swgRttyModActions) + { + if (channelActionsKeys.contains("tx")) + { + if (swgRttyModActions->getTx() != 0) + { + if (channelActionsKeys.contains("payload") + && (swgRttyModActions->getPayload()->getData())) + { + MsgTXPacketData *msg = MsgTXPacketData::create( + *swgRttyModActions->getPayload()->getData( + ); + m_basebandSource->getInputMessageQueue()->push(msg); + } + else + { + MsgTx *msg = MsgTx::create(); + m_basebandSource->getInputMessageQueue()->push(msg); + } + + return 202; + } + else + { + errorMessage = "Packet must contain tx action"; + return 400; + } + } + else + { + errorMessage = "Unknown action"; + return 400; + } + } + else + { + errorMessage = "Missing RttyModActions in query"; + return 400; + }*/ + return 0; +} + +void RttyMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const RttyModSettings& settings) +{ + /*response.getRttyModSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset); + response.getRttyModSettings()->setBaud(settings.m_baud); + response.getRttyModSettings()->setRfBandwidth(settings.m_rfBandwidth); + response.getRttyModSettings()->setFrequencyShift(settings.m_frequencyShift); + response.getRttyModSettings()->setGain(settings.m_gain); + response.getRttyModSettings()->setChannelMute(settings.m_channelMute ? 1 : 0); + response.getRttyModSettings()->setRepeat(settings.m_repeat ? 1 : 0); + response.getRttyModSettings()->setRepeatDelay(settings.m_repeatDelay); + response.getRttyModSettings()->setRepeatCount(settings.m_repeatCount); + response.getRttyModSettings()->setLpfTaps(settings.m_lpfTaps); + response.getRttyModSettings()->setBbNoise(settings.m_bbNoise ? 1 : 0); + response.getRttyModSettings()->setRfNoise(settings.m_rfNoise ? 1 : 0); + response.getRttyModSettings()->setWriteToFile(settings.m_writeToFile ? 1 : 0); + + if (response.getRttyModSettings()->getData()) { + *response.getRttyModSettings()->getData() = settings.m_data; + } else { + response.getRttyModSettings()->setData(new QString(settings.m_data)); + } + + response.getRttyModSettings()->setPulseShaping(settings.m_pulseShaping ? 1 : 0); + response.getRttyModSettings()->setBeta(settings.m_beta); + response.getRttyModSettings()->setSymbolSpan(settings.m_symbolSpan); + response.getRttyModSettings()->setUdpEnabled(settings.m_udpEnabled); + response.getRttyModSettings()->setUdpAddress(new QString(settings.m_udpAddress)); + response.getRttyModSettings()->setUdpPort(settings.m_udpPort); + + response.getRttyModSettings()->setRgbColor(settings.m_rgbColor); + + if (response.getRttyModSettings()->getTitle()) { + *response.getRttyModSettings()->getTitle() = settings.m_title; + } else { + response.getRttyModSettings()->setTitle(new QString(settings.m_title)); + } + + response.getRttyModSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0); + + if (response.getRttyModSettings()->getReverseApiAddress()) { + *response.getRttyModSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress; + } else { + response.getRttyModSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress)); + } + + response.getRttyModSettings()->setReverseApiPort(settings.m_reverseAPIPort); + response.getRttyModSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex); + response.getRttyModSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex); + + if (settings.m_channelMarker) + { + if (response.getRttyModSettings()->getChannelMarker()) + { + settings.m_channelMarker->formatTo(response.getRttyModSettings()->getChannelMarker()); + } + else + { + SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + settings.m_channelMarker->formatTo(swgChannelMarker); + response.getRttyModSettings()->setChannelMarker(swgChannelMarker); + } + } + + if (settings.m_rollupState) + { + if (response.getRttyModSettings()->getRollupState()) + { + settings.m_rollupState->formatTo(response.getRttyModSettings()->getRollupState()); + } + else + { + SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + settings.m_rollupState->formatTo(swgRollupState); + response.getRttyModSettings()->setRollupState(swgRollupState); + } + }*/ +} + +void RttyMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) +{ + /*response.getRttyModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); + response.getRttyModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate());*/ +} + +void RttyMod::webapiReverseSendSettings(QList& channelSettingsKeys, const RttyModSettings& 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 RttyMod::sendChannelSettings( + const QList& pipes, + QList& channelSettingsKeys, + const RttyModSettings& settings, + bool force) +{ + for (const auto& pipe : pipes) + { + MessageQueue *messageQueue = qobject_cast(pipe->m_element); + + if (messageQueue) + { + SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings(); + webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force); + MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create( + this, + channelSettingsKeys, + swgChannelSettings, + force + ); + messageQueue->push(msg); + } + } +} + +void RttyMod::webapiFormatChannelSettings( + QList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings *swgChannelSettings, + const RttyModSettings& settings, + bool force +) +{ + /*swgChannelSettings->setDirection(1); // single source (Tx) + swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); + swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex()); + swgChannelSettings->setChannelType(new QString(m_channelId)); + swgChannelSettings->setRttyModSettings(new SWGSDRangel::SWGRttyModSettings()); + SWGSDRangel::SWGRttyModSettings *swgRttyModSettings = swgChannelSettings->getRttyModSettings(); + + // transfer data that has been modified. When force is on transfer all data except reverse API data + + if (channelSettingsKeys.contains("inputFrequencyOffset") || force) { + swgRttyModSettings->setInputFrequencyOffset(settings.m_inputFrequencyOffset); + } + if (channelSettingsKeys.contains("baud") || force) { + swgRttyModSettings->setBaud((int) settings.m_baud); + } + if (channelSettingsKeys.contains("rfBandwidth") || force) { + swgRttyModSettings->setRfBandwidth(settings.m_rfBandwidth); + } + if (channelSettingsKeys.contains("frequencyShift") || force) { + swgRttyModSettings->setFrequencyShift(settings.m_frequencyShift); + } + if (channelSettingsKeys.contains("gain") || force) { + swgRttyModSettings->setGain(settings.m_gain); + } + if (channelSettingsKeys.contains("channelMute") || force) { + swgRttyModSettings->setChannelMute(settings.m_channelMute ? 1 : 0); + } + if (channelSettingsKeys.contains("repeat") || force) { + swgRttyModSettings->setRepeat(settings.m_repeat ? 1 : 0); + } + if (channelSettingsKeys.contains("repeatDelay") || force) { + swgRttyModSettings->setRepeatDelay(settings.m_repeatDelay); + } + if (channelSettingsKeys.contains("repeatCount") || force) { + swgRttyModSettings->setRepeatCount(settings.m_repeatCount); + } + if (channelSettingsKeys.contains("lpfTaps")) { + swgRttyModSettings->setLpfTaps(settings.m_lpfTaps); + } + if (channelSettingsKeys.contains("bbNoise")) { + swgRttyModSettings->setBbNoise(settings.m_bbNoise ? 1 : 0); + } + if (channelSettingsKeys.contains("rfNoise")) { + swgRttyModSettings->setRfNoise(settings.m_rfNoise ? 1 : 0); + } + if (channelSettingsKeys.contains("writeToFile")) { + swgRttyModSettings->setWriteToFile(settings.m_writeToFile ? 1 : 0); + } + if (channelSettingsKeys.contains("data")) { + swgRttyModSettings->setData(new QString(settings.m_data)); + } + if (channelSettingsKeys.contains("beta")) { + swgRttyModSettings->setBeta(settings.m_beta); + } + if (channelSettingsKeys.contains("symbolSpan")) { + swgRttyModSettings->setSymbolSpan(settings.m_symbolSpan); + } + if (channelSettingsKeys.contains("rgbColor") || force) { + swgRttyModSettings->setRgbColor(settings.m_rgbColor); + } + if (channelSettingsKeys.contains("title") || force) { + swgRttyModSettings->setTitle(new QString(settings.m_title)); + } + if (channelSettingsKeys.contains("streamIndex") || force) { + swgRttyModSettings->setStreamIndex(settings.m_streamIndex); + } + if (channelSettingsKeys.contains("udpEnabled") || force) { + swgRttyModSettings->setUdpEnabled(settings.m_udpEnabled); + } + if (channelSettingsKeys.contains("udpAddress") || force) { + swgRttyModSettings->setUdpAddress(new QString(settings.m_udpAddress)); + } + if (channelSettingsKeys.contains("udpPort") || force) { + swgRttyModSettings->setUdpPort(settings.m_udpPort); + } + + if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force)) + { + SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker(); + settings.m_channelMarker->formatTo(swgChannelMarker); + swgRttyModSettings->setChannelMarker(swgChannelMarker); + } + + if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force)) + { + SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); + settings.m_rollupState->formatTo(swgRollupState); + swgRttyModSettings->setRollupState(swgRollupState); + }*/ +} + +void RttyMod::networkManagerFinished(QNetworkReply *reply) +{ + QNetworkReply::NetworkError replyError = reply->error(); + + if (replyError) + { + qWarning() << "RttyMod::networkManagerFinished:" + << " error(" << (int) replyError + << "): " << replyError + << ": " << reply->errorString(); + } + else + { + QString answer = reply->readAll(); + answer.chop(1); // remove last \n + qDebug("RttyMod::networkManagerFinished: reply:\n%s", answer.toStdString().c_str()); + } + + reply->deleteLater(); +} + +double RttyMod::getMagSq() const +{ + return m_basebandSource->getMagSq(); +} + +void RttyMod::setLevelMeter(QObject *levelMeter) +{ + connect(m_basebandSource, SIGNAL(levelChanged(qreal, qreal, int)), levelMeter, SLOT(levelChanged(qreal, qreal, int))); +} + +uint32_t RttyMod::getNumberOfDeviceStreams() const +{ + return m_deviceAPI->getNbSinkStreams(); +} + +int RttyMod::getSourceChannelSampleRate() const +{ + return m_basebandSource->getSourceChannelSampleRate(); +} + +void RttyMod::openUDP(const RttyModSettings& settings) +{ + closeUDP(); + m_udpSocket = new QUdpSocket(); + if (!m_udpSocket->bind(QHostAddress(settings.m_udpAddress), settings.m_udpPort)) + qCritical() << "RttyMod::openUDP: Failed to bind to port " << settings.m_udpAddress << ":" << settings.m_udpPort << ". Error: " << m_udpSocket->error(); + else + qDebug() << "RttyMod::openUDP: Listening for packets on " << settings.m_udpAddress << ":" << settings.m_udpPort; + connect(m_udpSocket, &QUdpSocket::readyRead, this, &RttyMod::udpRx); +} + +void RttyMod::closeUDP() +{ + if (m_udpSocket != nullptr) + { + disconnect(m_udpSocket, &QUdpSocket::readyRead, this, &RttyMod::udpRx); + delete m_udpSocket; + m_udpSocket = nullptr; + } +} + +void RttyMod::udpRx() +{ + while (m_udpSocket->hasPendingDatagrams()) + { + QNetworkDatagram datagram = m_udpSocket->receiveDatagram(); + MsgTXPacketBytes *msg = MsgTXPacketBytes::create(datagram.data()); + m_basebandSource->getInputMessageQueue()->push(msg); + } +} + +void RttyMod::setMessageQueueToGUI(MessageQueue* queue) { + ChannelAPI::setMessageQueueToGUI(queue); + m_basebandSource->setMessageQueueToGUI(queue); +} diff --git a/plugins/channeltx/modrtty/rttymod.h b/plugins/channeltx/modrtty/rttymod.h new file mode 100644 index 0000000000..df3d1a40a6 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymod.h @@ -0,0 +1,264 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016-2019 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_CHANNELTX_MODRTTY_RTTYMOD_H_ +#define PLUGINS_CHANNELTX_MODRTTY_RTTYMOD_H_ + +#include +#include +#include + +#include +#include + +#include "dsp/basebandsamplesource.h" +#include "dsp/spectrumvis.h" +#include "channel/channelapi.h" +#include "util/message.h" + +#include "rttymodsettings.h" + +class QNetworkAccessManager; +class QNetworkReply; +class QThread; +class QUdpSocket; +class DeviceAPI; +class RttyModBaseband; +class ObjectPipe; + +class RttyMod : public BasebandSampleSource, public ChannelAPI { +public: + class MsgConfigureRttyMod : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const RttyModSettings& getSettings() const { return m_settings; } + bool getForce() const { return m_force; } + + static MsgConfigureRttyMod* create(const RttyModSettings& settings, bool force) + { + return new MsgConfigureRttyMod(settings, force); + } + + private: + RttyModSettings m_settings; + bool m_force; + + MsgConfigureRttyMod(const RttyModSettings& settings, bool force) : + Message(), + m_settings(settings), + m_force(force) + { } + }; + + class MsgTx : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgTx* create() { + return new MsgTx(); + } + + private: + MsgTx() : + Message() + { } + }; + + class MsgReportTx : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const QString& getText() const { return m_text; } + int getBufferedCharacters() const { return m_bufferedCharacters; } + + static MsgReportTx* create(const QString& text, int bufferedCharacters) { + return new MsgReportTx(text, bufferedCharacters); + } + + private: + QString m_text; + int m_bufferedCharacters; + + MsgReportTx(const QString& text, int bufferedCharacters) : + Message(), + m_text(text), + m_bufferedCharacters(bufferedCharacters) + { } + }; + + class MsgTXPacketBytes : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgTXPacketBytes* create(QByteArray data) { + return new MsgTXPacketBytes(data); + } + + QByteArray m_data; + + private: + + MsgTXPacketBytes(QByteArray data) : + Message(), + m_data(data) + { } + }; + + class MsgTXPacketData : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgTXPacketData* create(QString data) + { + return new MsgTXPacketData(data); + } + + QString m_data; + + private: + + MsgTXPacketData(QString data) : + Message(), + m_data(data) + { } + }; + + //================================================================= + + RttyMod(DeviceAPI *deviceAPI); + virtual ~RttyMod(); + virtual void destroy() { delete this; } + virtual void setDeviceAPI(DeviceAPI *deviceAPI); + virtual DeviceAPI *getDeviceAPI() { return m_deviceAPI; } + + virtual void start(); + virtual void stop(); + virtual void pull(SampleVector::iterator& begin, unsigned int nbSamples); + virtual void pushMessage(Message *msg) { m_inputMessageQueue.push(msg); } + virtual QString getSourceName() { return objectName(); } + + virtual void getIdentifier(QString& id) { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } + 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 qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + { + (void) streamIndex; + (void) sinkElseSource; + return m_settings.m_inputFrequencyOffset; + } + + 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); + + virtual int webapiActionsPost( + const QStringList& channelActionsKeys, + SWGSDRangel::SWGChannelActions& query, + QString& errorMessage); + + static void webapiFormatChannelSettings( + SWGSDRangel::SWGChannelSettings& response, + const RttyModSettings& settings); + + static void webapiUpdateChannelSettings( + RttyModSettings& settings, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response); + + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } + double getMagSq() const; + void setLevelMeter(QObject *levelMeter); + uint32_t getNumberOfDeviceStreams() const; + int getSourceChannelSampleRate() const; + void setMessageQueueToGUI(MessageQueue* queue) override; + + static const char* const m_channelIdURI; + static const char* const m_channelId; + +private: + enum RateState { + RSInitialFill, + RSRunning + }; + + DeviceAPI* m_deviceAPI; + QThread *m_thread; + RttyModBaseband* m_basebandSource; + RttyModSettings m_settings; + SpectrumVis m_spectrumVis; + + SampleVector m_sampleBuffer; + QRecursiveMutex m_settingsMutex; + + int m_sampleRate; + + QNetworkAccessManager *m_networkManager; + QNetworkRequest m_networkRequest; + QUdpSocket *m_udpSocket; + + virtual bool handleMessage(const Message& cmd); + void applySettings(const RttyModSettings& settings, bool force = false); + void sendSampleRateToDemodAnalyzer(); + void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response); + void webapiReverseSendSettings(QList& channelSettingsKeys, const RttyModSettings& settings, bool force); + void sendChannelSettings( + const QList& pipes, + QList& channelSettingsKeys, + const RttyModSettings& settings, + bool force + ); + void webapiFormatChannelSettings( + QList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings *swgChannelSettings, + const RttyModSettings& settings, + bool force + ); + void openUDP(const RttyModSettings& settings); + void closeUDP(); + +private slots: + void networkManagerFinished(QNetworkReply *reply); + void udpRx(); +}; + + +#endif /* PLUGINS_CHANNELTX_MODRTTY_RTTYMOD_H_ */ diff --git a/plugins/channeltx/modrtty/rttymodbaseband.cpp b/plugins/channeltx/modrtty/rttymodbaseband.cpp new file mode 100644 index 0000000000..3261096639 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodbaseband.cpp @@ -0,0 +1,207 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include + +#include "dsp/upchannelizer.h" +#include "dsp/dspengine.h" +#include "dsp/dspcommands.h" + +#include "rttymodbaseband.h" +#include "rttymod.h" + +MESSAGE_CLASS_DEFINITION(RttyModBaseband::MsgConfigureRttyModBaseband, Message) + +RttyModBaseband::RttyModBaseband() +{ + m_sampleFifo.resize(SampleSourceFifo::getSizePolicy(48000)); + m_channelizer = new UpChannelizer(&m_source); + + qDebug("RttyModBaseband::RttyModBaseband"); + QObject::connect( + &m_sampleFifo, + &SampleSourceFifo::dataRead, + this, + &RttyModBaseband::handleData, + Qt::QueuedConnection + ); + + connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); +} + +RttyModBaseband::~RttyModBaseband() +{ + delete m_channelizer; +} + +void RttyModBaseband::reset() +{ + QMutexLocker mutexLocker(&m_mutex); + m_sampleFifo.reset(); +} + +void RttyModBaseband::setChannel(ChannelAPI *channel) +{ + m_source.setChannel(channel); +} + +void RttyModBaseband::pull(const SampleVector::iterator& begin, unsigned int nbSamples) +{ + unsigned int part1Begin, part1End, part2Begin, part2End; + m_sampleFifo.read(nbSamples, part1Begin, part1End, part2Begin, part2End); + SampleVector& data = m_sampleFifo.getData(); + + if (part1Begin != part1End) + { + std::copy( + data.begin() + part1Begin, + data.begin() + part1End, + begin + ); + } + + unsigned int shift = part1End - part1Begin; + + if (part2Begin != part2End) + { + std::copy( + data.begin() + part2Begin, + data.begin() + part2End, + begin + shift + ); + } +} + +void RttyModBaseband::handleData() +{ + QMutexLocker mutexLocker(&m_mutex); + SampleVector& data = m_sampleFifo.getData(); + unsigned int ipart1begin; + unsigned int ipart1end; + unsigned int ipart2begin; + unsigned int ipart2end; + qreal rmsLevel, peakLevel; + int numSamples; + + unsigned int remainder = m_sampleFifo.remainder(); + + while ((remainder > 0) && (m_inputMessageQueue.size() == 0)) + { + m_sampleFifo.write(remainder, ipart1begin, ipart1end, ipart2begin, ipart2end); + + if (ipart1begin != ipart1end) { // first part of FIFO data + processFifo(data, ipart1begin, ipart1end); + } + + if (ipart2begin != ipart2end) { // second part of FIFO data (used when block wraps around) + processFifo(data, ipart2begin, ipart2end); + } + + remainder = m_sampleFifo.remainder(); + } + + m_source.getLevels(rmsLevel, peakLevel, numSamples); + emit levelChanged(rmsLevel, peakLevel, numSamples); +} + +void RttyModBaseband::processFifo(SampleVector& data, unsigned int iBegin, unsigned int iEnd) +{ + m_channelizer->prefetch(iEnd - iBegin); + m_channelizer->pull(data.begin() + iBegin, iEnd - iBegin); +} + +void RttyModBaseband::handleInputMessages() +{ + Message* message; + + while ((message = m_inputMessageQueue.pop()) != nullptr) + { + if (handleMessage(*message)) { + delete message; + } + } +} + +bool RttyModBaseband::handleMessage(const Message& cmd) +{ + if (MsgConfigureRttyModBaseband::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + MsgConfigureRttyModBaseband& cfg = (MsgConfigureRttyModBaseband&) cmd; + qDebug() << "RttyModBaseband::handleMessage: MsgConfigureRttyModBaseband"; + + applySettings(cfg.getSettings(), cfg.getForce()); + + return true; + } + else if (RttyMod::MsgTx::match(cmd)) + { + qDebug() << "RttyModBaseband::handleMessage: MsgTx"; + m_source.addTXPacket(m_settings.m_data); + + return true; + } + else if (RttyMod::MsgTXPacketBytes::match(cmd)) + { + RttyMod::MsgTXPacketBytes& tx = (RttyMod::MsgTXPacketBytes&) cmd; + m_source.addTXPacket(tx.m_data); + + return true; + } + else if (RttyMod::MsgTXPacketData::match(cmd)) + { + RttyMod::MsgTXPacketData& tx = (RttyMod::MsgTXPacketData&) cmd; + m_source.addTXPacket(tx.m_data); + + return true; + } + else if (DSPSignalNotification::match(cmd)) + { + QMutexLocker mutexLocker(&m_mutex); + DSPSignalNotification& notif = (DSPSignalNotification&) cmd; + qDebug() << "RttyModBaseband::handleMessage: DSPSignalNotification: basebandSampleRate: " << notif.getSampleRate(); + m_sampleFifo.resize(SampleSourceFifo::getSizePolicy(notif.getSampleRate())); + m_channelizer->setBasebandSampleRate(notif.getSampleRate()); + m_source.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset()); + + return true; + } + else + { + qDebug() << "RttyModBaseband - Baseband got unknown message"; + return false; + } +} + +void RttyModBaseband::applySettings(const RttyModSettings& settings, bool force) +{ + if ((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) + { + m_channelizer->setChannelization(m_channelizer->getChannelSampleRate(), settings.m_inputFrequencyOffset); + m_source.applyChannelSettings(m_channelizer->getChannelSampleRate(), m_channelizer->getChannelFrequencyOffset()); + } + + m_source.applySettings(settings, force); + + m_settings = settings; +} + +int RttyModBaseband::getChannelSampleRate() const +{ + return m_channelizer->getChannelSampleRate(); +} diff --git a/plugins/channeltx/modrtty/rttymodbaseband.h b/plugins/channeltx/modrtty/rttymodbaseband.h new file mode 100644 index 0000000000..53f6085f70 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodbaseband.h @@ -0,0 +1,100 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_RTTYMODBASEBAND_H +#define INCLUDE_RTTYMODBASEBAND_H + +#include +#include + +#include "dsp/samplesourcefifo.h" +#include "util/message.h" +#include "util/messagequeue.h" + +#include "rttymodsource.h" + +class UpChannelizer; +class ChannelAPI; + +class RttyModBaseband : public QObject +{ + Q_OBJECT +public: + class MsgConfigureRttyModBaseband : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const RttyModSettings& getSettings() const { return m_settings; } + bool getForce() const { return m_force; } + + static MsgConfigureRttyModBaseband* create(const RttyModSettings& settings, bool force) + { + return new MsgConfigureRttyModBaseband(settings, force); + } + + private: + RttyModSettings m_settings; + bool m_force; + + MsgConfigureRttyModBaseband(const RttyModSettings& settings, bool force) : + Message(), + m_settings(settings), + m_force(force) + { } + }; + + RttyModBaseband(); + ~RttyModBaseband(); + void reset(); + void pull(const SampleVector::iterator& begin, unsigned int nbSamples); + MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication + void setMessageQueueToGUI(MessageQueue* messageQueue) { m_source.setMessageQueueToGUI(messageQueue); } + double getMagSq() const { return m_source.getMagSq(); } + int getChannelSampleRate() const; + void setSpectrumSampleSink(BasebandSampleSink* sampleSink) { m_source.setSpectrumSink(sampleSink); } + void setChannel(ChannelAPI *channel); + int getSourceChannelSampleRate() const { return m_source.getChannelSampleRate(); } + +signals: + /** + * Level changed + * \param rmsLevel RMS level in range 0.0 - 1.0 + * \param peakLevel Peak level in range 0.0 - 1.0 + * \param numSamples Number of audio samples analyzed + */ + void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples); + +private: + SampleSourceFifo m_sampleFifo; + UpChannelizer *m_channelizer; + RttyModSource m_source; + MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication + RttyModSettings m_settings; + QRecursiveMutex m_mutex; + + void processFifo(SampleVector& data, unsigned int iBegin, unsigned int iEnd); + bool handleMessage(const Message& cmd); + void applySettings(const RttyModSettings& settings, bool force = false); + +private slots: + void handleInputMessages(); + void handleData(); //!< Handle data when samples have to be processed +}; + + +#endif // INCLUDE_RTTYMODBASEBAND_H diff --git a/plugins/channeltx/modrtty/rttymodgui.cpp b/plugins/channeltx/modrtty/rttymodgui.cpp new file mode 100644 index 0000000000..f9f14370d6 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodgui.cpp @@ -0,0 +1,663 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include + +#include "dsp/spectrumvis.h" +#include "dsp/dspengine.h" +#include "dsp/dspcommands.h" +#include "device/deviceuiset.h" +#include "plugin/pluginapi.h" +#include "plugin/pluginapi.h" +#include "util/simpleserializer.h" +#include "util/db.h" +#include "util/maidenhead.h" +#include "gui/glspectrum.h" +#include "gui/crightclickenabler.h" +#include "gui/basicchannelsettingsdialog.h" +#include "gui/devicestreamselectiondialog.h" +#include "gui/fmpreemphasisdialog.h" +#include "gui/dialpopup.h" +#include "gui/dialogpositioner.h" +#include "maincore.h" + +#include "ui_rttymodgui.h" +#include "rttymodgui.h" +#include "rttymodrepeatdialog.h" +#include "rttymodtxsettingsdialog.h" + +RttyModGUI* RttyModGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx) +{ + RttyModGUI* gui = new RttyModGUI(pluginAPI, deviceUISet, channelTx); + return gui; +} + +void RttyModGUI::destroy() +{ + delete this; +} + +void RttyModGUI::resetToDefaults() +{ + m_settings.resetToDefaults(); + displaySettings(); + applySettings(true); +} + +QByteArray RttyModGUI::serialize() const +{ + return m_settings.serialize(); +} + +bool RttyModGUI::deserialize(const QByteArray& data) +{ + if(m_settings.deserialize(data)) { + displaySettings(); + applySettings(true); + return true; + } else { + resetToDefaults(); + return false; + } +} + +bool RttyModGUI::handleMessage(const Message& message) +{ + if (RttyMod::MsgConfigureRttyMod::match(message)) + { + const RttyMod::MsgConfigureRttyMod& cfg = (RttyMod::MsgConfigureRttyMod&) message; + m_settings = cfg.getSettings(); + blockApplySettings(true); + m_channelMarker.updateSettings(static_cast(m_settings.m_channelMarker)); + displaySettings(); + blockApplySettings(false); + return true; + } + else if (RttyMod::MsgReportTx::match(message)) + { + const RttyMod::MsgReportTx& report = (RttyMod::MsgReportTx&)message; + QString s = report.getText(); + int bufferedCharacters = report.getBufferedCharacters(); + + // Turn TX button green when transmitting + QString tooltip = m_initialToolTip; + if (bufferedCharacters == 0) + { + ui->txButton->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); + } + else + { + ui->txButton->setStyleSheet("QToolButton { background-color : green; }"); + tooltip.append(QString("\n\n%1 characters in buffer").arg(bufferedCharacters)); + } + ui->txButton->setToolTip(tooltip); + + s = s.replace(">", ""); // Don't display LTRS + s = s.replace("\r", ""); // Don't display carriage returns + + if (!s.isEmpty()) + { + // Is the scroll bar at the bottom? + int scrollPos = ui->transmittedText->verticalScrollBar()->value(); + bool atBottom = scrollPos >= ui->transmittedText->verticalScrollBar()->maximum(); + + // Move cursor to end where we want to append new text + // (user may have moved it by clicking / highlighting text) + ui->transmittedText->moveCursor(QTextCursor::End); + + // Restore scroll position + ui->transmittedText->verticalScrollBar()->setValue(scrollPos); + + // Insert text + ui->transmittedText->insertPlainText(s); + + // Scroll to bottom, if we we're previously at the bottom + if (atBottom) { + ui->transmittedText->verticalScrollBar()->setValue(ui->transmittedText->verticalScrollBar()->maximum()); + } + } + return true; + } + else if (DSPSignalNotification::match(message)) + { + const DSPSignalNotification& notif = (const 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 + { + return false; + } +} + +void RttyModGUI::channelMarkerChangedByCursor() +{ + ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); + m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); + applySettings(); +} + +void RttyModGUI::handleSourceMessages() +{ + Message* message; + + while ((message = getInputMessageQueue()->pop()) != 0) + { + if (handleMessage(*message)) + { + delete message; + } + } +} + +void RttyModGUI::on_deltaFrequency_changed(qint64 value) +{ + m_channelMarker.setCenterFrequency(value); + m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); + updateAbsoluteCenterFrequency(); + applySettings(); +} + +void RttyModGUI::on_mode_currentIndexChanged(int index) +{ + (void)index; + + QString mode = ui->mode->currentText(); + + bool custom = mode == "Custom"; + if (!custom) + { + QStringList settings = mode.split("/"); + int baudRate = settings[0].toInt(); + int frequencyShift = settings[1].toInt(); + int bandwidth = frequencyShift * 2 + baudRate; + ui->baudRate->setCurrentText(settings[0]); + ui->frequencyShift->setValue(frequencyShift); + ui->rfBW->setValue(bandwidth); + } + + ui->baudRateLabel->setEnabled(custom); + ui->baudRate->setEnabled(custom); + ui->frequencyShiftLabel->setEnabled(custom); + ui->frequencyShift->setEnabled(custom); + ui->frequencyShiftText->setEnabled(custom); + ui->rfBWLabel->setEnabled(custom); + ui->rfBW->setEnabled(custom); + ui->rfBWText->setEnabled(custom); + + applySettings(); +} + +void RttyModGUI::on_rfBW_valueChanged(int value) +{ + int bw = value; + ui->rfBWText->setText(formatFrequency(bw)); + m_channelMarker.setBandwidth(bw); + m_settings.m_rfBandwidth = bw; + applySettings(); +} + +void RttyModGUI::on_baudRate_currentIndexChanged(int index) +{ + (void)index; + m_settings.m_baud = ui->baudRate->currentText().toFloat(); + applySettings(); +} + +void RttyModGUI::on_frequencyShift_valueChanged(int value) +{ + m_settings.m_frequencyShift = value; + ui->frequencyShiftText->setText(formatFrequency(m_settings.m_frequencyShift)); + applySettings(); +} + +void RttyModGUI::on_characterSet_currentIndexChanged(int index) +{ + m_settings.m_characterSet = (Baudot::CharacterSet)index; + applySettings(); +} + +void RttyModGUI::on_endian_clicked(bool checked) +{ + m_settings.m_msbFirst = checked; + if (checked) { + ui->endian->setText("MSB"); + } + else { + ui->endian->setText("LSB"); + } + applySettings(); +} + +void RttyModGUI::on_spaceHigh_clicked(bool checked) +{ + m_settings.m_spaceHigh = checked; + if (checked) { + ui->spaceHigh->setText("M-S"); + } + else { + ui->spaceHigh->setText("S-M"); + } + applySettings(); +} + +void RttyModGUI::on_clearTransmittedText_clicked() +{ + ui->transmittedText->clear(); +} + +void RttyModGUI::on_gain_valueChanged(int value) +{ + ui->gainText->setText(QString("%1dB").arg(value)); + m_settings.m_gain = value; + applySettings(); +} + +void RttyModGUI::on_channelMute_toggled(bool checked) +{ + m_settings.m_channelMute = checked; + applySettings(); +} + +void RttyModGUI::on_txButton_clicked() +{ + transmit(ui->text->currentText()); +} + +void RttyModGUI::on_text_returnPressed() +{ + transmit(ui->text->currentText()); + ui->text->setCurrentText(""); +} + +void RttyModGUI::on_text_editingFinished() +{ + m_settings.m_data = ui->text->currentText(); + applySettings(); +} + +void RttyModGUI::on_repeat_toggled(bool checked) +{ + m_settings.m_repeat = checked; + applySettings(); +} + +void RttyModGUI::repeatSelect(const QPoint& p) +{ + RttyModRepeatDialog dialog(m_settings.m_repeatCount); + dialog.move(p); + new DialogPositioner(&dialog, false); + + if (dialog.exec() == QDialog::Accepted) + { + m_settings.m_repeatCount = dialog.m_repeatCount; + applySettings(); + } +} + +void RttyModGUI::txSettingsSelect(const QPoint& p) +{ + RttyModTXSettingsDialog dialog(&m_settings); + dialog.move(p); + new DialogPositioner(&dialog, false); + + if (dialog.exec() == QDialog::Accepted) + { + displaySettings(); + applySettings(); + } +} + +void RttyModGUI::on_udpEnabled_clicked(bool checked) +{ + m_settings.m_udpEnabled = checked; + applySettings(); +} + +void RttyModGUI::on_udpAddress_editingFinished() +{ + m_settings.m_udpAddress = ui->udpAddress->text(); + applySettings(); +} + +void RttyModGUI::on_udpPort_editingFinished() +{ + m_settings.m_udpPort = ui->udpPort->text().toInt(); + applySettings(); +} + +void RttyModGUI::onWidgetRolled(QWidget* widget, bool rollDown) +{ + (void) widget; + (void) rollDown; + + getRollupContents()->saveState(m_rollupState); + applySettings(); +} + +void RttyModGUI::onMenuDialogCalled(const QPoint &p) +{ + if (m_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_rttyMod->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(); + } + + resetContextMenuType(); +} + +RttyModGUI::RttyModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget* parent) : + ChannelGUI(parent), + ui(new Ui::RttyModGUI), + m_pluginAPI(pluginAPI), + m_deviceUISet(deviceUISet), + m_channelMarker(this), + m_deviceCenterFrequency(0), + m_basebandSampleRate(1), + m_doApplySettings(true) +{ + setAttribute(Qt::WA_DeleteOnClose, true); + m_helpURL = "plugins/channeltx/modrtty/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_rttyMod = (RttyMod*) channelTx; + m_rttyMod->setMessageQueueToGUI(getInputMessageQueue()); + + connect(&MainCore::instance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); + + m_spectrumVis = m_rttyMod->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); + + ui->spectrumGUI->setBuddies(m_spectrumVis, ui->glSpectrum); + + // Extra /2 here because SSB? + ui->glSpectrum->setCenterFrequency(8000/4); + ui->glSpectrum->setSampleRate(8000/2); + ui->glSpectrum->setLsbDisplay(true); + + SpectrumSettings spectrumSettings = m_spectrumVis->getSettings(); + spectrumSettings.m_ssb = false; + spectrumSettings.m_displayCurrent = true; + spectrumSettings.m_displayWaterfall = false; + spectrumSettings.m_displayMaxHold = false; + spectrumSettings.m_displayHistogram = false; + SpectrumVis::MsgConfigureSpectrumVis *msg = SpectrumVis::MsgConfigureSpectrumVis::create(spectrumSettings, false); + m_spectrumVis->getInputMessageQueue()->push(msg); + + CRightClickEnabler *repeatRightClickEnabler = new CRightClickEnabler(ui->repeat); + connect(repeatRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(repeatSelect(const QPoint &))); + + CRightClickEnabler *txRightClickEnabler = new CRightClickEnabler(ui->txButton); + connect(txRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(txSettingsSelect(const QPoint &))); + + ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); + ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); + ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999); + + m_channelMarker.blockSignals(true); + m_channelMarker.setColor(Qt::red); + m_channelMarker.setBandwidth(12500); + m_channelMarker.setCenterFrequency(0); + m_channelMarker.setTitle("Packet Modulator"); + m_channelMarker.setSourceOrSinkStream(false); + m_channelMarker.blockSignals(false); + m_channelMarker.setVisible(true); // activate signal on the last setting only + + m_deviceUISet->addChannelMarker(&m_channelMarker); + + connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor())); + + connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); + m_rttyMod->setLevelMeter(ui->volumeMeter); + + m_settings.setChannelMarker(&m_channelMarker); + m_settings.setRollupState(&m_rollupState); + + ui->spectrumContainer->setVisible(false); + + displaySettings(); + makeUIConnections(); + applySettings(); + DialPopup::addPopupsToChildDials(this); + + m_initialToolTip = ui->txButton->toolTip(); +} + +RttyModGUI::~RttyModGUI() +{ + // If we don't disconnect, we can get this signal after this has been deleted! + QObject::disconnect(ui->text->lineEdit(), &QLineEdit::editingFinished, this, &RttyModGUI::on_text_editingFinished); + delete ui; +} + +void RttyModGUI::transmit(const QString& str) +{ + QString s = str; + + if (m_settings.m_prefixCRLF) { + s.prepend("\r\r\n>"); // '>' switches to letters + } + if (m_settings.m_postfixCRLF) { + s.append("\r\r\n"); + } + + RttyMod::MsgTXPacketData *msg = RttyMod::MsgTXPacketData::create(s); + m_rttyMod->getInputMessageQueue()->push(msg); +} + +void RttyModGUI::blockApplySettings(bool block) +{ + m_doApplySettings = !block; +} + +void RttyModGUI::applySettings(bool force) +{ + if (m_doApplySettings) + { + RttyMod::MsgConfigureRttyMod *msg = RttyMod::MsgConfigureRttyMod::create(m_settings, force); + m_rttyMod->getInputMessageQueue()->push(msg); + } +} + +QString RttyModGUI::formatFrequency(int frequency) const +{ + QString suffix = ""; + if (width() > 450) { + suffix = " Hz"; + } + return QString("%1%2").arg(frequency).arg(suffix); +} + +QString RttyModGUI::substitute(const QString& text) +{ + const MainSettings& mainSettings = MainCore::instance()->getSettings(); + QString location = Maidenhead::toMaidenhead(mainSettings.getLatitude(), mainSettings.getLongitude()); + QString s = text; + + s = s.replace("${callsign}", mainSettings.getStationName().toUpper()); + s = s.replace("${location}", location); + + return s; +} + +void RttyModGUI::displaySettings() +{ + m_channelMarker.blockSignals(true); + m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); + m_channelMarker.setTitle(m_settings.m_title); + m_channelMarker.setBandwidth(m_settings.m_rfBandwidth); + 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()); + updateIndexLabel(); + + blockApplySettings(true); + + ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); + + ui->mode->setCurrentText("Custom"); + ui->rfBWText->setText(formatFrequency(m_settings.m_rfBandwidth)); + ui->rfBW->setValue(m_settings.m_rfBandwidth / 100.0); + QString baudRate; + if (m_settings.m_baud < 46.0f && m_settings.m_baud > 45.0f) { + baudRate = "45.45"; + } + else { + baudRate = QString("%1").arg(m_settings.m_baud); + } + ui->baudRate->setCurrentIndex(ui->baudRate->findText(baudRate)); + ui->frequencyShiftText->setText(formatFrequency(m_settings.m_frequencyShift)); + ui->frequencyShift->setValue(m_settings.m_frequencyShift); + ui->frequencyShift->setValue(m_settings.m_frequencyShift); + + ui->characterSet->setCurrentIndex((int)m_settings.m_characterSet); + ui->endian->setChecked(m_settings.m_msbFirst); + if (m_settings.m_msbFirst) { + ui->endian->setText("MSB"); + } + else { + ui->endian->setText("LSB"); + } + ui->spaceHigh->setChecked(m_settings.m_spaceHigh); + if (m_settings.m_spaceHigh) { + ui->spaceHigh->setText("M-S"); + } + else { + ui->spaceHigh->setText("S-M"); + } + + ui->udpEnabled->setChecked(m_settings.m_udpEnabled); + ui->udpAddress->setText(m_settings.m_udpAddress); + ui->udpPort->setText(QString::number(m_settings.m_udpPort)); + + ui->gainText->setText(QString("%1").arg((double)m_settings.m_gain, 0, 'f', 1)); + ui->gain->setValue(m_settings.m_gain); + + ui->channelMute->setChecked(m_settings.m_channelMute); + ui->repeat->setChecked(m_settings.m_repeat); + + ui->text->clear(); + for (const auto& text : m_settings.m_predefinedTexts) { + ui->text->addItem(substitute(text)); + } + ui->text->setCurrentText(m_settings.m_data); + + getRollupContents()->restoreState(m_rollupState); + updateAbsoluteCenterFrequency(); + blockApplySettings(false); +} + +void RttyModGUI::leaveEvent(QEvent* event) +{ + m_channelMarker.setHighlighted(false); + ChannelGUI::leaveEvent(event); +} + +void RttyModGUI::enterEvent(EnterEventType* event) +{ + m_channelMarker.setHighlighted(true); + ChannelGUI::enterEvent(event); +} + +void RttyModGUI::tick() +{ + double powDb = CalcDb::dbPower(m_rttyMod->getMagSq()); + m_channelPowerDbAvg(powDb); + ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.asDouble(), 0, 'f', 1)); +} + +void RttyModGUI::makeUIConnections() +{ + QObject::connect(ui->deltaFrequency, &ValueDialZ::changed, this, &RttyModGUI::on_deltaFrequency_changed); + QObject::connect(ui->mode, QOverload::of(&QComboBox::currentIndexChanged), this, &RttyModGUI::on_mode_currentIndexChanged); + QObject::connect(ui->rfBW, &QSlider::valueChanged, this, &RttyModGUI::on_rfBW_valueChanged); + QObject::connect(ui->baudRate, QOverload::of(&QComboBox::currentIndexChanged), this, &RttyModGUI::on_baudRate_currentIndexChanged); + QObject::connect(ui->frequencyShift, &QSlider::valueChanged, this, &RttyModGUI::on_frequencyShift_valueChanged); + QObject::connect(ui->characterSet, QOverload::of(&QComboBox::currentIndexChanged), this, &RttyModGUI::on_characterSet_currentIndexChanged); + QObject::connect(ui->endian, &QCheckBox::clicked, this, &RttyModGUI::on_endian_clicked); + QObject::connect(ui->spaceHigh, &QCheckBox::clicked, this, &RttyModGUI::on_spaceHigh_clicked); + QObject::connect(ui->clearTransmittedText, &QToolButton::clicked, this, &RttyModGUI::on_clearTransmittedText_clicked); + QObject::connect(ui->gain, &QDial::valueChanged, this, &RttyModGUI::on_gain_valueChanged); + QObject::connect(ui->channelMute, &QToolButton::toggled, this, &RttyModGUI::on_channelMute_toggled); + QObject::connect(ui->txButton, &QToolButton::clicked, this, &RttyModGUI::on_txButton_clicked); + QObject::connect(ui->text->lineEdit(), &QLineEdit::editingFinished, this, &RttyModGUI::on_text_editingFinished); + QObject::connect(ui->text->lineEdit(), &QLineEdit::returnPressed, this, &RttyModGUI::on_text_returnPressed); + QObject::connect(ui->repeat, &ButtonSwitch::toggled, this, &RttyModGUI::on_repeat_toggled); + QObject::connect(ui->udpEnabled, &QCheckBox::clicked, this, &RttyModGUI::on_udpEnabled_clicked); + QObject::connect(ui->udpAddress, &QLineEdit::editingFinished, this, &RttyModGUI::on_udpAddress_editingFinished); + QObject::connect(ui->udpPort, &QLineEdit::editingFinished, this, &RttyModGUI::on_udpPort_editingFinished); +} + +void RttyModGUI::updateAbsoluteCenterFrequency() +{ + setStatusFrequency(m_deviceCenterFrequency + m_settings.m_inputFrequencyOffset); +} diff --git a/plugins/channeltx/modrtty/rttymodgui.h b/plugins/channeltx/modrtty/rttymodgui.h new file mode 100644 index 0000000000..1e79e34633 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodgui.h @@ -0,0 +1,130 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_CHANNELTX_MODRTTY_RTTYMODGUI_H_ +#define PLUGINS_CHANNELTX_MODRTTY_RTTYMODGUI_H_ + +#include "channel/channelgui.h" +#include "dsp/channelmarker.h" +#include "util/movingaverage.h" +#include "util/messagequeue.h" +#include "settings/rollupstate.h" + +#include "rttymod.h" +#include "rttymodsettings.h" + +class PluginAPI; +class DeviceUISet; +class BasebandSampleSource; +class SpectrumVis; + +namespace Ui { + class RttyModGUI; +} + +class RttyModGUI : public ChannelGUI { + Q_OBJECT + +public: + static RttyModGUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx); + 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(); + +private: + Ui::RttyModGUI* ui; + PluginAPI* m_pluginAPI; + DeviceUISet* m_deviceUISet; + ChannelMarker m_channelMarker; + RollupState m_rollupState; + RttyModSettings m_settings; + qint64 m_deviceCenterFrequency; + int m_basebandSampleRate; + bool m_doApplySettings; + SpectrumVis* m_spectrumVis; + QString m_initialToolTip; + + RttyMod* m_rttyMod; + MovingAverageUtil m_channelPowerDbAvg; // Less than other mods, as packets are short + + MessageQueue m_inputMessageQueue; + + explicit RttyModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channelTx, QWidget* parent = 0); + virtual ~RttyModGUI(); + + void transmit(const QString& str); + void blockApplySettings(bool block); + void applySettings(bool force = false); + void displaySettings(); + QString formatFrequency(int frequency) const; + bool handleMessage(const Message& message); + void makeUIConnections(); + void updateAbsoluteCenterFrequency(); + QString substitute(const QString& text); + + void leaveEvent(QEvent*); + void enterEvent(EnterEventType*); + +private slots: + void handleSourceMessages(); + + void on_deltaFrequency_changed(qint64 value); + void on_mode_currentIndexChanged(int value); + void on_rfBW_valueChanged(int index); + void on_baudRate_currentIndexChanged(int index); + void on_frequencyShift_valueChanged(int value); + void on_gain_valueChanged(int value); + void on_channelMute_toggled(bool checked); + void on_characterSet_currentIndexChanged(int index); + void on_endian_clicked(bool checked); + void on_spaceHigh_clicked(bool checked); + void on_clearTransmittedText_clicked(); + void on_txButton_clicked(); + void on_text_editingFinished(); + void on_text_returnPressed(); + void on_repeat_toggled(bool checked); + void repeatSelect(const QPoint& p); + void txSettingsSelect(const QPoint& p); + void on_udpEnabled_clicked(bool checked); + void on_udpAddress_editingFinished(); + void on_udpPort_editingFinished(); + + void onWidgetRolled(QWidget* widget, bool rollDown); + void onMenuDialogCalled(const QPoint& p); + + void tick(); +}; + +#endif /* PLUGINS_CHANNELTX_MODRTTY_RTTYMODGUI_H_ */ diff --git a/plugins/channeltx/modrtty/rttymodgui.ui b/plugins/channeltx/modrtty/rttymodgui.ui new file mode 100644 index 0000000000..d418d5b667 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodgui.ui @@ -0,0 +1,975 @@ + + + RttyModGUI + + + + 0 + 0 + 396 + 702 + + + + + 0 + 0 + + + + + 390 + 0 + + + + + Liberation Sans + 9 + + + + Qt::StrongFocus + + + RTTY Modulator + + + + true + + + + 2 + 2 + 391 + 211 + + + + + 280 + 0 + + + + Settings + + + + 3 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + 2 + + + + + + + + 16 + 0 + + + + Df + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + Liberation Mono + 12 + + + + PointingHandCursor + + + Qt::StrongFocus + + + Demod shift frequency from center in Hz + + + + + + + Hz + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 60 + 0 + + + + Channel power + + + Qt::RightToLeft + + + -100.0 dB + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Mute/Unmute channel + + + ... + + + + :/txon.png + :/txoff.png:/txon.png + + + true + + + + + + + + + + + + 86 + 0 + + + + RTTY baud rate and frequency shift + + + + 45.45/170 + + + + + 50/170 + + + + + 50/450 + + + + + 75/170 + + + + + 75/850 + + + + + Custom + + + + + + + + Qt::Vertical + + + + + + + Baud + + + + + + + + 60 + 0 + + + + Baud rate in symbols per second + + + 1 + + + + 45 + + + + + 45.45 + + + + + 50 + + + + + 75 + + + + + 100 + + + + + 110 + + + + + 150 + + + + + 200 + + + + + + + + Qt::Vertical + + + + + + + Shift + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Frequency shift in Hertz + + + 100 + + + 1000 + + + 10 + + + 10 + + + 170 + + + 170 + + + Qt::Horizontal + + + + + + + + 30 + 0 + + + + 850 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + + + + BW + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + RF bandwidth + + + 1 + + + 2000 + + + 10 + + + 100 + + + 340 + + + Qt::Horizontal + + + + + + + + 30 + 0 + + + + 1700 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + + + + + + Qt::Horizontal + + + + + + + + + + 24 + 24 + + + + Gain + + + -60 + + + 0 + + + 5 + + + 1 + + + 0 + + + + + + + Gain + + + + + + + + 30 + 0 + + + + Audio input gain value + + + -80.0dB + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + Liberation Mono + 8 + + + + Level (% full range) top trace: average, bottom trace: instantaneous peak, tip: peak hold + + + + + + + + + Qt::Horizontal + + + + + + + + + Forward text received via UDP + + + Qt::RightToLeft + + + UDP + + + + + + + + 120 + 0 + + + + Qt::ClickFocus + + + UDP address to listen for text to forward on + + + 000.000.000.000 + + + 127.0.0.1 + + + + + + + : + + + Qt::AlignCenter + + + + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + Qt::ClickFocus + + + UDP port to listen for text to forward on + + + 00000 + + + 9997 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + Baudot + + + + + + + + 80 + 0 + + + + Baudot character set + + + 0 + + + + ITA 2 + + + + + UK + + + + + European + + + + + US + + + + + Russian + + + + + Murray + + + + + + + + + 30 + 0 + + + + + 24 + 16777215 + + + + Whether LSB (Least significant bit) or MSB (Most significant bit) is transmitted first + + + LSB + + + + + + + + 30 + 0 + + + + + 24 + 16777215 + + + + Whether mark is high RF frequency (unchecked) or low RF frequency (checked) + + + S-M + + + + + + + + 24 + 16777215 + + + + Unshift on space - Set character set to letter when a space character is transmitted + + + US + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Repeatedly transmit the text. Right click for additional settings. + + + ... + + + + :/playloop.png:/playloop.png + + + + + + + Clear transmitted text + + + + + + + :/bin.png:/bin.png + + + + + + + + + + + Text to send + + + true + + + + + + + Press to transmit the text. Right click for additional settings. + + + TX + + + + + + + + + + + 0 + 220 + 391 + 141 + + + + + 0 + 0 + + + + Transmitted Text + + + + 2 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + true + + + + + + + + + 0 + 370 + 381 + 284 + + + + + 0 + 0 + + + + Baseband Spectrum + + + + 2 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 0 + 0 + + + + + 200 + 250 + + + + + Liberation Mono + 8 + + + + + + + + + + + + + RollupContents + QWidget +
gui/rollupcontents.h
+ 1 +
+ + GLSpectrum + QWidget +
gui/glspectrum.h
+ 1 +
+ + GLSpectrumGUI + QWidget +
gui/glspectrumgui.h
+ 1 +
+ + ValueDialZ + QWidget +
gui/valuedialz.h
+ 1 +
+ + ButtonSwitch + QToolButton +
gui/buttonswitch.h
+
+ + LevelMeterVU + QWidget +
gui/levelmeter.h
+ 1 +
+
+ + deltaFrequency + channelMute + rfBW + txButton + transmittedText + + + + + +
diff --git a/plugins/channeltx/modrtty/rttymodplugin.cpp b/plugins/channeltx/modrtty/rttymodplugin.cpp new file mode 100644 index 0000000000..1f939dbca4 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodplugin.cpp @@ -0,0 +1,92 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include "plugin/pluginapi.h" + +#ifndef SERVER_MODE +#include "rttymodgui.h" +#endif +#include "rttymod.h" +#include "rttymodwebapiadapter.h" +#include "rttymodplugin.h" + +const PluginDescriptor RttyModPlugin::m_pluginDescriptor = { + RttyMod::m_channelId, + QStringLiteral("RTTY Modulator"), + QStringLiteral("7.16.0"), + QStringLiteral("(c) Jon Beniston, M7RCE"), + QStringLiteral("https://github.com/f4exb/sdrangel"), + true, + QStringLiteral("https://github.com/f4exb/sdrangel") +}; + +RttyModPlugin::RttyModPlugin(QObject* parent) : + QObject(parent), + m_pluginAPI(0) +{ +} + +const PluginDescriptor& RttyModPlugin::getPluginDescriptor() const +{ + return m_pluginDescriptor; +} + +void RttyModPlugin::initPlugin(PluginAPI* pluginAPI) +{ + m_pluginAPI = pluginAPI; + + m_pluginAPI->registerTxChannel(RttyMod::m_channelIdURI, RttyMod::m_channelId, this); +} + +void RttyModPlugin::createTxChannel(DeviceAPI *deviceAPI, BasebandSampleSource **bs, ChannelAPI **cs) const +{ + if (bs || cs) + { + RttyMod *instance = new RttyMod(deviceAPI); + + if (bs) { + *bs = instance; + } + + if (cs) { + *cs = instance; + } + } +} + +#ifdef SERVER_MODE +ChannelGUI* RttyModPlugin::createTxChannelGUI( + DeviceUISet *deviceUISet, + BasebandSampleSource *txChannel) const +{ + (void) deviceUISet; + (void) txChannel; + return nullptr; +} +#else +ChannelGUI* RttyModPlugin::createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const +{ + return RttyModGUI::create(m_pluginAPI, deviceUISet, txChannel); +} +#endif + +ChannelWebAPIAdapter* RttyModPlugin::createChannelWebAPIAdapter() const +{ + return new RttyModWebAPIAdapter(); +} diff --git a/plugins/channeltx/modrtty/rttymodplugin.h b/plugins/channeltx/modrtty/rttymodplugin.h new file mode 100644 index 0000000000..482a3e0383 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodplugin.h @@ -0,0 +1,49 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_RTTYMODPLUGIN_H +#define INCLUDE_RTTYMODPLUGIN_H + +#include +#include "plugin/plugininterface.h" + +class DeviceUISet; +class BasebandSampleSource; + +class RttyModPlugin : public QObject, PluginInterface { + Q_OBJECT + Q_INTERFACES(PluginInterface) + Q_PLUGIN_METADATA(IID "sdrangel.channeltx.rttymod") + +public: + explicit RttyModPlugin(QObject* parent = 0); + + const PluginDescriptor& getPluginDescriptor() const; + void initPlugin(PluginAPI* pluginAPI); + + virtual void createTxChannel(DeviceAPI *deviceAPI, BasebandSampleSource **bs, ChannelAPI **cs) const; + virtual ChannelGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *rxChannel) const; + virtual ChannelWebAPIAdapter* createChannelWebAPIAdapter() const; + +private: + static const PluginDescriptor m_pluginDescriptor; + + PluginAPI* m_pluginAPI; +}; + +#endif // INCLUDE_RTTYMODPLUGIN_H diff --git a/plugins/channeltx/modrtty/rttymodrepeatdialog.cpp b/plugins/channeltx/modrtty/rttymodrepeatdialog.cpp new file mode 100644 index 0000000000..5e92a78baf --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodrepeatdialog.cpp @@ -0,0 +1,43 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "rttymodrepeatdialog.h" +#include "rttymodsettings.h" +#include + +RttyModRepeatDialog::RttyModRepeatDialog(int repeatCount, QWidget* parent) : + QDialog(parent), + ui(new Ui::RttyModRepeatDialog) +{ + ui->setupUi(this); + QLineEdit *edit = ui->repeatCount->lineEdit(); + if (edit) { + edit->setText(QString("%1").arg(repeatCount)); + } +} + +RttyModRepeatDialog::~RttyModRepeatDialog() +{ + delete ui; +} + +void RttyModRepeatDialog::accept() +{ + QString text = ui->repeatCount->currentText(); + m_repeatCount = text.toUInt(); + QDialog::accept(); +} diff --git a/plugins/channeltx/modrtty/rttymodrepeatdialog.h b/plugins/channeltx/modrtty/rttymodrepeatdialog.h new file mode 100644 index 0000000000..6e4783016e --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodrepeatdialog.h @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_RTTYMODREPEATDIALOG_H +#define INCLUDE_RTTYMODREPEATDIALOG_H + +#include "ui_rttymodrepeatdialog.h" + +class RttyModRepeatDialog : public QDialog { + Q_OBJECT + +public: + explicit RttyModRepeatDialog(int repeatCount, QWidget* parent = 0); + ~RttyModRepeatDialog(); + + int m_repeatCount; // Number of packets to transmit (-1 = infinite) + +private slots: + void accept(); + +private: + Ui::RttyModRepeatDialog* ui; +}; + +#endif // INCLUDE_RTTYMODREPEATDIALOG_H diff --git a/plugins/channeltx/modrtty/rttymodrepeatdialog.ui b/plugins/channeltx/modrtty/rttymodrepeatdialog.ui new file mode 100644 index 0000000000..d9057a414c --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodrepeatdialog.ui @@ -0,0 +1,116 @@ + + + RttyModRepeatDialog + + + + 0 + 0 + 351 + 91 + + + + + Liberation Sans + 9 + + + + Packet Repeat Settings + + + + + + + + + Times to transmit + + + + + + + Number of times to transmit + + + true + + + + 1 + + + + + 10 + + + + + 100 + + + + + 1000 + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + repeatCount + + + + + buttonBox + accepted() + RttyModRepeatDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RttyModRepeatDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/plugins/channeltx/modrtty/rttymodsettings.cpp b/plugins/channeltx/modrtty/rttymodsettings.cpp new file mode 100644 index 0000000000..fcfcf29140 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodsettings.cpp @@ -0,0 +1,236 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include "dsp/dspengine.h" +#include "util/baudot.h" +#include "util/simpleserializer.h" +#include "settings/serializable.h" +#include "rttymodsettings.h" + +RttyModSettings::RttyModSettings() : + m_channelMarker(nullptr), + m_rollupState(nullptr) +{ + resetToDefaults(); +} + +void RttyModSettings::resetToDefaults() +{ + m_inputFrequencyOffset = 0; + m_baud = 45.45; + m_rfBandwidth = 340; + m_frequencyShift = 170; + m_gain = 0.0f; + m_channelMute = false; + m_repeat = false; + m_repeatCount = 10; + m_lpfTaps = 301; + m_bbNoise = false; + m_rfNoise = false; + m_writeToFile = false; + m_data = "CQ CQ CQ DE SDRangel CQ"; + m_characterSet = Baudot::ITA2; + m_msbFirst = false; + m_spaceHigh = false; + m_prefixCRLF = true; + m_postfixCRLF = true; + m_predefinedTexts = QStringList({ + "CQ CQ CQ DE ${callsign} ${callsign} CQ", + "DE ${callsign} ${callsign} ${callsign}", + "UR 599 QTH IS ${location}", + "TU DE ${callsign} CQ" + }); + m_rgbColor = QColor(0, 105, 2).rgb(); + m_title = "RTTY Modulator"; + m_streamIndex = 0; + m_useReverseAPI = false; + m_reverseAPIAddress = "127.0.0.1"; + m_reverseAPIPort = 8888; + m_reverseAPIDeviceIndex = 0; + m_reverseAPIChannelIndex = 0; + m_pulseShaping = false; + m_beta = 0.5f; + m_symbolSpan = 6; + m_udpEnabled = false; + m_udpAddress = "127.0.0.1"; + m_udpPort = 9998; + m_workspaceIndex = 0; + m_hidden = false; +} + +QString RttyModSettings::getMode() const +{ + return QString("%1/%2").arg(m_baud).arg(m_frequencyShift); +} + +QByteArray RttyModSettings::serialize() const +{ + SimpleSerializer s(1); + + s.writeS32(1, m_inputFrequencyOffset); + s.writeReal(2, m_baud); + s.writeS32(3, m_rfBandwidth); + s.writeS32(4, m_frequencyShift); + s.writeReal(5, m_gain); + s.writeBool(6, m_channelMute); + s.writeBool(7, m_repeat); + s.writeS32(9, m_repeatCount); + s.writeS32(23, m_lpfTaps); + s.writeBool(24, m_bbNoise); + s.writeBool(25, m_rfNoise); + s.writeBool(26, m_writeToFile); + s.writeString(30, m_data); + + s.writeS32(60, (int)m_characterSet); + s.writeBool(61, m_unshiftOnSpace); + s.writeBool(62, m_msbFirst); + s.writeBool(63, m_spaceHigh); + s.writeBool(64, m_prefixCRLF); + s.writeBool(65, m_postfixCRLF); + s.writeList(66, m_predefinedTexts); + + s.writeU32(31, m_rgbColor); + s.writeString(32, m_title); + + if (m_channelMarker) { + s.writeBlob(33, m_channelMarker->serialize()); + } + + s.writeS32(34, m_streamIndex); + s.writeBool(35, m_useReverseAPI); + s.writeString(36, m_reverseAPIAddress); + s.writeU32(37, m_reverseAPIPort); + s.writeU32(38, m_reverseAPIDeviceIndex); + s.writeU32(39, m_reverseAPIChannelIndex); + s.writeBool(46, m_pulseShaping); + s.writeReal(47, m_beta); + s.writeS32(48, m_symbolSpan); + s.writeBool(51, m_udpEnabled); + s.writeString(52, m_udpAddress); + s.writeU32(53, m_udpPort); + + if (m_rollupState) { + s.writeBlob(54, m_rollupState->serialize()); + } + + s.writeS32(55, m_workspaceIndex); + s.writeBlob(56, m_geometryBytes); + s.writeBool(57, m_hidden); + + + return s.final(); +} + +bool RttyModSettings::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if(!d.isValid()) + { + resetToDefaults(); + return false; + } + + if(d.getVersion() == 1) + { + QByteArray bytetmp; + qint32 tmp; + uint32_t utmp; + + d.readS32(1, &tmp, 0); + m_inputFrequencyOffset = tmp; + d.readReal(2, &m_baud, 45.45f); + d.readS32(3, &m_rfBandwidth, 340); + d.readS32(4, &m_frequencyShift, 170); + d.readReal(5, &m_gain, 0.0f); + d.readBool(6, &m_channelMute, false); + d.readBool(7, &m_repeat, false); + d.readS32(9, &m_repeatCount, -1); + d.readS32(23, &m_lpfTaps, 301); + d.readBool(24, &m_bbNoise, false); + d.readBool(25, &m_rfNoise, false); + d.readBool(26, &m_writeToFile, false); + d.readString(30, &m_data, "CQ CQ CQ anyone using SDRangel"); + + d.readS32(60, (int*)&m_characterSet, (int)Baudot::ITA2); + d.readBool(61, &m_unshiftOnSpace, false); + d.readBool(62, &m_msbFirst, false); + d.readBool(63, &m_spaceHigh, false); + d.readBool(64, &m_prefixCRLF, true); + d.readBool(65, &m_postfixCRLF, true); + d.readList(66, &m_predefinedTexts); + + d.readU32(31, &m_rgbColor); + d.readString(32, &m_title, "RTTY Modulator"); + + if (m_channelMarker) + { + d.readBlob(33, &bytetmp); + m_channelMarker->deserialize(bytetmp); + } + + d.readS32(34, &m_streamIndex, 0); + d.readBool(35, &m_useReverseAPI, false); + d.readString(36, &m_reverseAPIAddress, "127.0.0.1"); + d.readU32(37, &utmp, 0); + + if ((utmp > 1023) && (utmp < 65535)) { + m_reverseAPIPort = utmp; + } else { + m_reverseAPIPort = 8888; + } + + d.readU32(38, &utmp, 0); + m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp; + d.readU32(39, &utmp, 0); + m_reverseAPIChannelIndex = utmp > 99 ? 99 : utmp; + d.readBool(46, &m_pulseShaping, false); + d.readReal(47, &m_beta, 0.5f); + d.readS32(48, &m_symbolSpan, 6); + d.readBool(51, &m_udpEnabled); + d.readString(52, &m_udpAddress, "127.0.0.1"); + d.readU32(53, &utmp); + + if ((utmp > 1023) && (utmp < 65535)) { + m_udpPort = utmp; + } else { + m_udpPort = 9998; + } + + if (m_rollupState) + { + d.readBlob(54, &bytetmp); + m_rollupState->deserialize(bytetmp); + } + + d.readS32(55, &m_workspaceIndex, 0); + d.readBlob(56, &m_geometryBytes); + d.readBool(57, &m_hidden, false); + + return true; + } + else + { + qDebug() << "RttyModSettings::deserialize: ERROR"; + resetToDefaults(); + return false; + } +} diff --git a/plugins/channeltx/modrtty/rttymodsettings.h b/plugins/channeltx/modrtty/rttymodsettings.h new file mode 100644 index 0000000000..3786ae98c3 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodsettings.h @@ -0,0 +1,81 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef PLUGINS_CHANNELTX_MODRTTY_RTTYMODSETTINGS_H +#define PLUGINS_CHANNELTX_MODRTTY_RTTYMODSETTINGS_H + +#include +#include +#include "dsp/dsptypes.h" +#include "util/baudot.h" + +class Serializable; + +struct RttyModSettings +{ + qint64 m_inputFrequencyOffset; + float m_baud; + int m_rfBandwidth; + int m_frequencyShift; + Real m_gain; + bool m_channelMute; + bool m_repeat; + int m_repeatCount; + int m_lpfTaps; + bool m_bbNoise; + bool m_rfNoise; + bool m_writeToFile; + QString m_data; // Text to send + bool m_pulseShaping; + float m_beta; + int m_symbolSpan; + Baudot::CharacterSet m_characterSet; + bool m_unshiftOnSpace; + bool m_msbFirst; // false = LSB first, true = MSB first + bool m_spaceHigh; // false = mark high frequency, true = space high frequency + bool m_prefixCRLF; + bool m_postfixCRLF; + QStringList m_predefinedTexts; + + quint32 m_rgbColor; + QString m_title; + Serializable *m_channelMarker; + int m_streamIndex; + bool m_useReverseAPI; + QString m_reverseAPIAddress; + uint16_t m_reverseAPIPort; + uint16_t m_reverseAPIDeviceIndex; + uint16_t m_reverseAPIChannelIndex; + bool m_udpEnabled; + QString m_udpAddress; + uint16_t m_udpPort; + Serializable *m_rollupState; + int m_workspaceIndex; + QByteArray m_geometryBytes; + bool m_hidden; + + RttyModSettings(); + void resetToDefaults(); + void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; } + void setRollupState(Serializable *rollupState) { m_rollupState = rollupState; } + QByteArray serialize() const; + bool deserialize(const QByteArray& data); + QString getMode() const; +}; + +#endif /* PLUGINS_CHANNELTX_MODRTTY_RTTYMODSETTINGS_H */ diff --git a/plugins/channeltx/modrtty/rttymodsource.cpp b/plugins/channeltx/modrtty/rttymodsource.cpp new file mode 100644 index 0000000000..481ed4737b --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodsource.cpp @@ -0,0 +1,438 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include "dsp/basebandsamplesink.h" +#include "dsp/datafifo.h" +#include "rttymod.h" +#include "rttymodsource.h" +#include "util/messagequeue.h" +#include "maincore.h" + +RttyModSource::RttyModSource() : + m_channelSampleRate(48000), + m_channelFrequencyOffset(0), + m_spectrumRate(8000), + m_audioPhase(0.0f), + m_fmPhase(0.0), + m_spectrumSink(nullptr), + m_magsq(0.0), + m_levelCalcCount(0), + m_peakLevel(0.0f), + m_levelSum(0.0f), + m_byteIdx(0), + m_bitIdx(0), + m_bitCount(0) + { + m_bits.append(0); + m_lowpass.create(301, m_channelSampleRate, 400.0 / 2.0); + m_pulseShape.create(0.5, 6, m_channelSampleRate/45.45); + + m_demodBuffer.resize(1<<12); + m_demodBufferFill = 0; + + m_interpolatorDistanceRemain = 0; + m_interpolatorConsumed = false; + m_interpolatorDistance = (Real)m_channelSampleRate / (Real)m_spectrumRate; + m_interpolator.create(48, m_spectrumRate, m_spectrumRate / 2.2, 3.0); + + applySettings(m_settings, true); + applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); +} + +RttyModSource::~RttyModSource() +{ +} + +void RttyModSource::pull(SampleVector::iterator begin, unsigned int nbSamples) +{ + std::for_each( + begin, + begin + nbSamples, + [this](Sample& s) { + pullOne(s); + } + ); +} + +void RttyModSource::pullOne(Sample& sample) +{ + if (m_settings.m_channelMute) + { + sample.m_real = 0.0f; + sample.m_imag = 0.0f; + return; + } + + // Calculate next sample + modulateSample(); + + // Shift to carrier frequency + Complex ci = m_modSample; + ci *= m_carrierNco.nextIQ(); + + // Calculate power + double magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); + m_movingAverage(magsq); + m_magsq = m_movingAverage.asDouble(); + + // Convert from float to fixed point + sample.m_real = (FixReal) (ci.real() * SDR_TX_SCALEF); + sample.m_imag = (FixReal) (ci.imag() * SDR_TX_SCALEF); +} + +void RttyModSource::sampleToSpectrum(Real sample) +{ + if (m_spectrumSink) + { + Complex out; + Complex in; + in.real(sample); + in.imag(0.0f); + if (m_interpolator.decimate(&m_interpolatorDistanceRemain, in, &out)) + { + sample = std::real(out); + m_sampleBuffer.push_back(Sample(sample * 0.891235351562f * SDR_TX_SCALEF, 0.0f)); + m_spectrumSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), true); + m_sampleBuffer.clear(); + m_interpolatorDistanceRemain += m_interpolatorDistance; + } + } +} + +void RttyModSource::modulateSample() +{ + Real audioMod; + + if (m_sampleIdx == 0) + { + if (m_bitCount == 0) + { + if (!m_dataToTransmit.isEmpty()) + { + // Encode a character at a time, so we get a TxReport after each character + QString s = m_dataToTransmit.left(1); + m_dataToTransmit = m_dataToTransmit.mid(1); + encodePacket(s); + } + else + { + // Transmit "diddle" + encodePacket(">"); + } + initTX(); + } + + m_bit = getBit(); + } + + m_sampleIdx++; + if (m_sampleIdx >= m_samplesPerSymbol) { + m_sampleIdx = 0; + } + + if (!m_settings.m_bbNoise) + { + // FSK + if (m_settings.m_pulseShaping) + { + if (m_sampleIdx == 1) { + audioMod = m_pulseShape.filter(m_bit ? 1.0f : -1.0f); + } else { + audioMod = m_pulseShape.filter(0.0f); + } + } + else + { + audioMod = m_bit ? 1.0f : -1.0f; + } + } + else + { + audioMod = (Real)rand() / ((Real)RAND_MAX) - 0.5; // Noise to test filter frequency response + } + + // Display baseband audio in spectrum analyser + sampleToSpectrum(audioMod); + + // FM + m_fmPhase += m_phaseSensitivity * audioMod * (m_settings.m_spaceHigh ? -1.0f : 1.0f); + // Keep phase in range -pi,pi + if (m_fmPhase > M_PI) { + m_fmPhase -= 2.0f * M_PI; + } else if (m_fmPhase < -M_PI) { + m_fmPhase += 2.0f * M_PI; + } + + if (!m_settings.m_rfNoise) + { + m_modSample.real(m_linearGain * cos(m_fmPhase)); + m_modSample.imag(m_linearGain * sin(m_fmPhase)); + } + else + { + // Noise to test filter frequency response + m_modSample.real(m_linearGain * ((Real)rand()/((Real)RAND_MAX)-0.5f)); + m_modSample.imag(m_linearGain * ((Real)rand()/((Real)RAND_MAX)-0.5f)); + } + + // Apply low pass filter to limit RF BW + m_modSample = m_lowpass.filter(m_modSample); + + Real s = std::real(m_modSample); + calculateLevel(s); + + m_demodBuffer[m_demodBufferFill] = audioMod * std::numeric_limits::max(); + ++m_demodBufferFill; + + if (m_demodBufferFill >= m_demodBuffer.size()) + { + QList dataPipes; + MainCore::instance()->getDataPipes().getDataPipes(m_channel, "demod", dataPipes); + + if (dataPipes.size() > 0) + { + QList::iterator it = dataPipes.begin(); + + for (; it != dataPipes.end(); ++it) + { + DataFifo *fifo = qobject_cast((*it)->m_element); + + if (fifo) { + fifo->write((quint8*) &m_demodBuffer[0], m_demodBuffer.size() * sizeof(qint16), DataFifo::DataTypeI16); + } + } + } + + m_demodBufferFill = 0; + } +} + +void RttyModSource::calculateLevel(Real& sample) +{ + if (m_levelCalcCount < m_levelNbSamples) + { + m_peakLevel = std::max(std::fabs(m_peakLevel), sample); + m_levelSum += sample * sample; + m_levelCalcCount++; + } + else + { + m_rmsLevel = sqrt(m_levelSum / m_levelNbSamples); + m_peakLevelOut = m_peakLevel; + m_peakLevel = 0.0f; + m_levelSum = 0.0f; + m_levelCalcCount = 0; + } +} + +void RttyModSource::applySettings(const RttyModSettings& settings, bool force) +{ + // Only recreate filters if settings have changed + if ((settings.m_lpfTaps != m_settings.m_lpfTaps) || (settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force) + { + qDebug() << "RttyModSource::applySettings: Creating new lpf with taps " << settings.m_lpfTaps << " rfBW " << settings.m_rfBandwidth; + m_lowpass.create(settings.m_lpfTaps, m_channelSampleRate, settings.m_rfBandwidth / 2.0); + } + if ((settings.m_beta != m_settings.m_beta) || (settings.m_symbolSpan != m_settings.m_symbolSpan) || (settings.m_baud != m_settings.m_baud) || force) + { + qDebug() << "RttyModSource::applySettings: Recreating pulse shaping filter: " + << " beta: " << settings.m_beta + << " symbolSpan: " << settings.m_symbolSpan + << " channelSampleRate:" << m_channelSampleRate + << " baud:" << settings.m_baud; + m_pulseShape.create(settings.m_beta, m_settings.m_symbolSpan, m_channelSampleRate/settings.m_baud); + } + + if ((settings.m_characterSet != m_settings.m_characterSet) || force) { + m_rttyEncoder.setCharacterSet(settings.m_characterSet); + } + if ((settings.m_unshiftOnSpace != m_settings.m_unshiftOnSpace) || force) { + m_rttyEncoder.setUnshiftOnSpace(settings.m_unshiftOnSpace); + } + if ((settings.m_msbFirst != m_settings.m_msbFirst) || force) { + m_rttyEncoder.setMsbFirst(settings.m_msbFirst); + } + + m_settings = settings; + + m_samplesPerSymbol = m_channelSampleRate / m_settings.m_baud; + qDebug() << "m_samplesPerSymbol: " << m_samplesPerSymbol << " (" << m_channelSampleRate << "/" << m_settings.m_baud << ")"; + + // Precalculate FM sensensity and linear gain to save doing it in the loop + m_phaseSensitivity = 2.0f * M_PI * (m_settings.m_frequencyShift/2.0f) / (double)m_channelSampleRate; + m_linearGain = powf(10.0f, m_settings.m_gain/20.0f); +} + +void RttyModSource::applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force) +{ + qDebug() << "RttyModSource::applyChannelSettings:" + << " channelSampleRate: " << channelSampleRate + << " channelFrequencyOffset: " << channelFrequencyOffset + << " rfBandwidth: " << m_settings.m_rfBandwidth; + + if ((channelFrequencyOffset != m_channelFrequencyOffset) + || (channelSampleRate != m_channelSampleRate) || force) + { + m_carrierNco.setFreq(channelFrequencyOffset, channelSampleRate); + } + + if ((m_channelSampleRate != channelSampleRate) || force) + { + qDebug() << "RttyModSource::applyChannelSettings: Recreating filters"; + m_lowpass.create(m_settings.m_lpfTaps, channelSampleRate, m_settings.m_rfBandwidth / 2.0); + qDebug() << "RttyModSource::applyChannelSettings: Recreating bandpass filter: " + << " channelSampleRate:" << channelSampleRate; + qDebug() << "RttyModSource::applyChannelSettings: Recreating pulse shaping filter: " + << " beta: " << m_settings.m_beta + << " symbolSpan: " << m_settings.m_symbolSpan + << " channelSampleRate:" << m_channelSampleRate + << " baud:" << m_settings.m_baud; + m_pulseShape.create(m_settings.m_beta, m_settings.m_symbolSpan, channelSampleRate/m_settings.m_baud); + } + + if ((m_channelSampleRate != channelSampleRate) || force) + { + m_interpolatorDistanceRemain = 0; + m_interpolatorConsumed = false; + m_interpolatorDistance = (Real) channelSampleRate / (Real) m_spectrumRate; + m_interpolator.create(48, m_spectrumRate, m_spectrumRate / 2.2, 3.0); + } + + m_channelSampleRate = channelSampleRate; + m_channelFrequencyOffset = channelFrequencyOffset; + m_samplesPerSymbol = m_channelSampleRate / m_settings.m_baud; + qDebug() << "m_samplesPerSymbol: " << m_samplesPerSymbol << " (" << m_channelSampleRate << "/" << m_settings.m_baud << ")"; + // Precalculate FM sensensity to save doing it in the loop + m_phaseSensitivity = 2.0f * M_PI * (m_settings.m_frequencyShift/2.0f) / (double)m_channelSampleRate; + + QList pipes; + MainCore::instance()->getMessagePipes().getMessagePipes(m_channel, "reportdemod", pipes); + + if (pipes.size() > 0) + { + for (const auto& pipe : pipes) + { + MessageQueue* messageQueue = qobject_cast(pipe->m_element); + MainCore::MsgChannelDemodReport *msg = MainCore::MsgChannelDemodReport::create(m_channel, m_channelSampleRate); + messageQueue->push(msg); + } + } +} + +int RttyModSource::getBit() +{ + int bit; + + if (m_bitCount > 0) + { + bit = (m_bits[m_byteIdx] >> m_bitIdx) & 1; + m_bitIdx++; + m_bitCount--; + if (m_bitIdx == 8) + { + m_byteIdx++; + m_bitIdx = 0; + } + } + else + { + qDebug() << "RttyModSource::getBit: Called when empty"; + bit = 1; + } + + return bit; +} + +void RttyModSource::addBit(int bit) +{ + m_bits[m_byteIdx] |= bit << m_bitIdx; + m_bitIdx++; + m_bitCount++; + m_bitCountTotal++; + if (m_bitIdx == 8) + { + m_byteIdx++; + if (m_bits.size() <= m_byteIdx) { + m_bits.append(0); + } + m_bitIdx = 0; + } +} + +void RttyModSource::initTX() +{ + m_byteIdx = 0; + m_bitIdx = 0; + m_bitCount = m_bitCountTotal; // Reset to allow retransmission + m_bit = 0; +} + +void RttyModSource::addTXPacket(QString data) +{ + int count = m_settings.m_repeat ? m_settings.m_repeatCount : 1; + + for (int i = 0; i < count; i++) { + m_dataToTransmit.append(data); + } +} + +void RttyModSource::addTXPacket(QByteArray data) +{ + int count = m_settings.m_repeat ? m_settings.m_repeatCount : 1; + + for (int i = 0; i < count; i++) { + m_dataToTransmit.append(QString(data)); + } +} + +void RttyModSource::encodePacket(const QString& text) +{ + // RTTY encoding + m_byteIdx = 0; + m_bitIdx = 0; + m_bitCount = 0; + m_bitCountTotal = 0; + for (int i = 0; i < m_bits.size(); i++) { + m_bits[i] = 0; + } + + QString s = text.toUpper(); // RTTY only supports upper case + + for (int i = 0; i < s.size(); i++) + { + unsigned bits; + unsigned bitCount; + bool error; + + error = m_rttyEncoder.encode(s[i], bits, bitCount); + for (int j = 0; j < bitCount; j++) + { + int txBit = (bits >> j) & 1; + addBit(txBit); + } + } + + if (getMessageQueueToGUI()) + { + RttyMod::MsgReportTx* msg = RttyMod::MsgReportTx::create(s, m_dataToTransmit.size()); + getMessageQueueToGUI()->push(msg); + } +} diff --git a/plugins/channeltx/modrtty/rttymodsource.h b/plugins/channeltx/modrtty/rttymodsource.h new file mode 100644 index 0000000000..cd74215488 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodsource.h @@ -0,0 +1,134 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_RTTYMODSOURCE_H +#define INCLUDE_RTTYMODSOURCE_H + +#include +#include +#include + +#include "dsp/channelsamplesource.h" +#include "dsp/nco.h" +#include "dsp/ncof.h" +#include "dsp/interpolator.h" +#include "dsp/firfilter.h" +#include "dsp/raisedcosine.h" +#include "util/movingaverage.h" +#include "util/baudot.h" + +#include "rttymodsettings.h" + +class BasebandSampleSink; +class ChannelAPI; + +class RttyModSource : public ChannelSampleSource +{ +public: + RttyModSource(); + virtual ~RttyModSource(); + + virtual void pull(SampleVector::iterator begin, unsigned int nbSamples); + virtual void pullOne(Sample& sample); + virtual void prefetch(unsigned int nbSamples) { (void) nbSamples; } + + double getMagSq() const { return m_magsq; } + void getLevels(qreal& rmsLevel, qreal& peakLevel, int& numSamples) const + { + rmsLevel = m_rmsLevel; + peakLevel = m_peakLevelOut; + numSamples = m_levelNbSamples; + } + void setMessageQueueToGUI(MessageQueue* messageQueue) { m_messageQueueToGUI = messageQueue; } + void setSpectrumSink(BasebandSampleSink *sampleSink) { m_spectrumSink = sampleSink; } + void applySettings(const RttyModSettings& settings, bool force = false); + void applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force = false); + void addTXPacket(QString data); + void addTXPacket(QByteArray data); + //void encodePacket(uint8_t *packet, int packet_length, uint8_t *packet_end); + void encodePacket(const QString& data); + void setChannel(ChannelAPI *channel) { m_channel = channel; } + int getChannelSampleRate() const { return m_channelSampleRate; } + +private: + int m_channelSampleRate; + int m_channelFrequencyOffset; + int m_spectrumRate; + RttyModSettings m_settings; + ChannelAPI *m_channel; + + NCO m_carrierNco; + Real m_audioPhase; + double m_fmPhase; // Double gives cleaner spectrum than Real + double m_phaseSensitivity; + Real m_linearGain; + Complex m_modSample; + + int m_bit; // Current bit + RaisedCosine m_pulseShape; // Pulse shaping filter + Lowpass m_lowpass; // Low pass filter to limit RF bandwidth + + BasebandSampleSink* m_spectrumSink; // Spectrum GUI to display baseband waveform + SampleVector m_sampleBuffer; + Interpolator m_interpolator; // Interpolator to downsample to 4k in spectrum + Real m_interpolatorDistance; + Real m_interpolatorDistanceRemain; + bool m_interpolatorConsumed; + + double m_magsq; + MovingAverageUtil m_movingAverage; + + quint32 m_levelCalcCount; + qreal m_rmsLevel; + qreal m_peakLevelOut; + Real m_peakLevel; + Real m_levelSum; + + static const int m_levelNbSamples = 480; // every 10ms assuming 48k Sa/s + + int m_sampleIdx; // Sample index in to symbol + int m_samplesPerSymbol; // Number of samples per symbol + + QString m_dataToTransmit; // Transmit data buffer (before RTTY encoding) + + BaudotEncoder m_rttyEncoder; + + QList m_bits; // Bits to transmit + int m_byteIdx; // Index in to m_bits + int m_bitIdx; // Index in to current byte of m_bits + int m_bitCount; // Count of number of valid bits in m_bits + int m_bitCountTotal; + + QVector m_demodBuffer; + int m_demodBufferFill; + + MessageQueue* m_messageQueueToGUI; + + MessageQueue* getMessageQueueToGUI() { return m_messageQueueToGUI; } + + int getBit(); // Get bit from m_bits + void addBit(int bit); // Add bit to m_bits, with zero stuffing + void initTX(); + + void calculateLevel(Real& sample); + void modulateSample(); + void sampleToSpectrum(Real sample); + +}; + +#endif // INCLUDE_RTTYMODSOURCE_H diff --git a/plugins/channeltx/modrtty/rttymodtxsettingsdialog.cpp b/plugins/channeltx/modrtty/rttymodtxsettingsdialog.cpp new file mode 100644 index 0000000000..57c40c6f85 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodtxsettingsdialog.cpp @@ -0,0 +1,112 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "rttymodtxsettingsdialog.h" + +static QListWidgetItem* newItem(const QString& text) +{ + QListWidgetItem* item = new QListWidgetItem(text); + item->setFlags(item->flags() | Qt::ItemIsEditable); + return item; +} + +RttyModTXSettingsDialog::RttyModTXSettingsDialog(RttyModSettings* settings, QWidget *parent) : + QDialog(parent), + ui(new Ui::RttyModTXSettingsDialog), + m_settings(settings) +{ + 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)); + } + ui->pulseShaping->setChecked(m_settings->m_pulseShaping); + ui->beta->setValue(m_settings->m_beta); + ui->symbolSpan->setValue(m_settings->m_symbolSpan); + ui->lpfTaps->setValue(m_settings->m_lpfTaps); + ui->bbNoise->setChecked(m_settings->m_bbNoise); + ui->rfNoise->setChecked(m_settings->m_rfNoise); +} + +RttyModTXSettingsDialog::~RttyModTXSettingsDialog() +{ + delete ui; +} + +void RttyModTXSettingsDialog::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()); + } + m_settings->m_pulseShaping = ui->pulseShaping->isChecked(); + m_settings->m_beta = ui->beta->value(); + m_settings->m_symbolSpan = ui->symbolSpan->value(); + m_settings->m_lpfTaps = ui->lpfTaps->value(); + m_settings->m_bbNoise = ui->bbNoise->isChecked(); + m_settings->m_rfNoise = ui->rfNoise->isChecked(); + + QDialog::accept(); +} + +void RttyModTXSettingsDialog::on_add_clicked() +{ + QListWidgetItem* item = newItem("..."); + ui->predefinedText->addItem(item); + ui->predefinedText->setCurrentItem(item); +} + +void RttyModTXSettingsDialog::on_remove_clicked() +{ + QList items = ui->predefinedText->selectedItems(); + for (auto item : items) { + delete ui->predefinedText->takeItem(ui->predefinedText->row(item)); + } +} + +void RttyModTXSettingsDialog::on_up_clicked() +{ + QList items = ui->predefinedText->selectedItems(); + for (auto item : items) + { + int row = ui->predefinedText->row(item); + if (row > 0) + { + QListWidgetItem* item = ui->predefinedText->takeItem(row); + ui->predefinedText->insertItem(row - 1, item); + ui->predefinedText->setCurrentItem(item); + } + } +} + +void RttyModTXSettingsDialog::on_down_clicked() +{ + QList items = ui->predefinedText->selectedItems(); + for (auto item : items) + { + int row = ui->predefinedText->row(item); + if (row < ui->predefinedText->count() - 1) + { + QListWidgetItem* item = ui->predefinedText->takeItem(row); + ui->predefinedText->insertItem(row + 1, item); + ui->predefinedText->setCurrentItem(item); + } + } +} diff --git a/plugins/channeltx/modrtty/rttymodtxsettingsdialog.h b/plugins/channeltx/modrtty/rttymodtxsettingsdialog.h new file mode 100644 index 0000000000..3d18f831ec --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodtxsettingsdialog.h @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_RTTYMODTXSETTINGSDIALOG_H +#define INCLUDE_RTTYMODTXSETTINGSDIALOG_H + +#include "ui_rttymodtxsettingsdialog.h" +#include "rttymodsettings.h" + +class RttyModTXSettingsDialog : public QDialog { + Q_OBJECT + +public: + explicit RttyModTXSettingsDialog(RttyModSettings *settings, QWidget *parent = nullptr); + ~RttyModTXSettingsDialog(); + + RttyModSettings *m_settings; + +private slots: + void accept(); + void on_add_clicked(); + void on_remove_clicked(); + void on_up_clicked(); + void on_down_clicked(); + +private: + Ui::RttyModTXSettingsDialog* ui; +}; + +#endif // INCLUDE_RTTYMODTXSETTINGSDIALOG_H diff --git a/plugins/channeltx/modrtty/rttymodtxsettingsdialog.ui b/plugins/channeltx/modrtty/rttymodtxsettingsdialog.ui new file mode 100644 index 0000000000..1f38cc3ea8 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodtxsettingsdialog.ui @@ -0,0 +1,294 @@ + + + RttyModTXSettingsDialog + + + + 0 + 0 + 351 + 546 + + + + + Liberation Sans + 9 + + + + Packet TX Extra Settings + + + + + + Text + + + + + + Prefix text with carriage returns, line feed and switch to letters + + + Prefix CR+CR+LF+LTRS + + + + + + + Predefined text + + + + + + + + + + 22 + 22 + + + + Add item to list + + + + + + + + + + + + 22 + 22 + + + + Remove selected items from list + + + - + + + + + + + Move selected item up + + + Up + + + + :/arrow_up.png:/arrow_up.png + + + + + + + Move selected item down + + + + + + + :/arrow_down.png:/arrow_down.png + + + + + + + + + Postfix text with carriage returns and line feeds + + + Postfix CR+CR+LF + + + + + + + Predefined text messages + +Substitutions: +${callsign} +${location} + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + + + + + + + + Modulation + + + + + + RF BW limit LPF taps + + + + + + + Number of taps in LPF for RF BW filter. + + + 10000 + + + + + + + Enable raised cosine pulse shaping filter + + + Raised cosine pulse shaping + + + + + + + Filter rolloff (beta) + + + + + + + Roll-off of the filter + + + 1.000000000000000 + + + 0.250000000000000 + + + + + + + Filter symbol span + + + + + + + Number of symbols over which filter is applied + + + 1 + + + 20 + + + + + + + + + + Debug + + + + + + Generate white noise as baseband signal. + + + Generate BB noise + + + + + + + Generate white noise as RF signal. + + + Generate RF noise + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + RttyModTXSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RttyModTXSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/plugins/channeltx/modrtty/rttymodwebapiadapter.cpp b/plugins/channeltx/modrtty/rttymodwebapiadapter.cpp new file mode 100644 index 0000000000..9e51721bee --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodwebapiadapter.cpp @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "SWGChannelSettings.h" +#include "rttymod.h" +#include "rttymodwebapiadapter.h" + +RttyModWebAPIAdapter::RttyModWebAPIAdapter() +{} + +RttyModWebAPIAdapter::~RttyModWebAPIAdapter() +{} + +int RttyModWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + /*response.setRttyModSettings(new SWGSDRangel::SWGRttyModSettings()); + response.getRttyModSettings()->init(); + RttyMod::webapiFormatChannelSettings(response, m_settings);*/ + + return 200; +} + +int RttyModWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) force; // no action + (void) errorMessage; + RttyMod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response); + + RttyMod::webapiFormatChannelSettings(response, m_settings); + return 200; +} diff --git a/plugins/channeltx/modrtty/rttymodwebapiadapter.h b/plugins/channeltx/modrtty/rttymodwebapiadapter.h new file mode 100644 index 0000000000..72522d26f3 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodwebapiadapter.h @@ -0,0 +1,50 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// Copyright (C) 2023 Jon Beniston, M7RCE // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_RTTYMOD_WEBAPIADAPTER_H +#define INCLUDE_RTTYMOD_WEBAPIADAPTER_H + +#include "channel/channelwebapiadapter.h" +#include "rttymodsettings.h" + +/** + * Standalone API adapter only for the settings + */ +class RttyModWebAPIAdapter : public ChannelWebAPIAdapter { +public: + RttyModWebAPIAdapter(); + virtual ~RttyModWebAPIAdapter(); + + 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: + RttyModSettings m_settings; +}; + +#endif // INCLUDE_RTTYMOD_WEBAPIADAPTER_H diff --git a/sdrbase/util/baudot.cpp b/sdrbase/util/baudot.cpp index f113192558..dfac753d02 100644 --- a/sdrbase/util/baudot.cpp +++ b/sdrbase/util/baudot.cpp @@ -23,84 +23,84 @@ // We use < for FIGS and > for LTRS and ^ for Cyrillic // Unicode used for source file encoding -const QString Baudot::m_ita2Letter[] = { +const QStringList Baudot::m_ita2Letter = { "\0", "E", "\n", "A", " ", "S", "I", "U", "\r", "D", "R", "J", "N", "F", "C", "K", "T", "Z", "L", "W", "H", "Y", "P", "Q", "O", "B", "G", "<", "M", "X", "V", ">" }; -const QString Baudot::m_ita2Figure[] = { +const QStringList Baudot::m_ita2Figure = { "\0", "3", "\n", "-", " ", "\'", "8", "7", "\r", "\x5", "4", "\a", ",", "!", ":", "(", "5", "+", ")", "2", "£", "6", "0", "1", "9", "?", "&", "<", ".", "/", "=", ">" }; -const QString Baudot::m_ukLetter[] = { +const QStringList Baudot::m_ukLetter = { "\0", "A", "E", "/", "Y", "U", "I", "O", "<", "J", "G", "H", "B", "C", "F", "D", " ", "-", "X", "Z", "S", "T", "W", "V", "\b", "K", "M", "L", "R", "Q", "N", "P" }; -const QString Baudot::m_ukFigure[] = { +const QStringList Baudot::m_ukFigure = { "\0", "1", "2", "⅟", "3", "4", "³⁄", "5", " ", "6", "7", "¹", "8", "9", "⁵⁄", "0", ">", ".", "⁹⁄", ":", "⁷⁄", "²", "?", "\'", "\b", "(", ")", "=", "-", "/", "£", "+" }; -const QString Baudot::m_europeanLetter[] = { +const QStringList Baudot::m_europeanLetter = { "\0", "A", "E", "É", "Y", "U", "I", "O", "<", "J", "G", "H", "B", "C", "F", "D", " ", "t", "X", "Z", "S", "T", "W", "V", "\b", "K", "M", "L", "R", "Q", "N", "P" }; -const QString Baudot::m_europeanFigure[] = { +const QStringList Baudot::m_europeanFigure = { "\0", "1", "2", "&", "3", "4", "º", "5", " ", "6", "7", "H̱", "8", "9", "F̱", "0", ">", ".", ",", ":", ";", "!", "?", "\'", "\b", "(", ")", "=", "-", "/", "№", "%" }; -const QString Baudot::m_usLetter[] = { +const QStringList Baudot::m_usLetter = { "\0", "E", "\n", "A", " ", "S", "I", "U", "\r", "D", "R", "J", "N", "F", "C", "K", "T", "Z", "L", "W", "H", "Y", "P", "Q", "O", "B", "G", "<", "M", "X", "V", ">" }; -const QString Baudot::m_usFigure[] = { +const QStringList Baudot::m_usFigure = { "\0", "3", "\n", "-", " ", "\a", "8", "7", "\r", "\x5", "4", "\'", ",", "!", ":", "(", "5", "\"", ")", "2", "#", "6", "0", "1", "9", "?", "&", "<", ".", "/", ";", ">" }; -const QString Baudot::m_russianLetter[] = { +const QStringList Baudot::m_russianLetter = { "\0", "Е", "\n", "А", " ", "С", "И", "У", "\r", "Д", "П", "Й", "Н", "Ф", "Ц", "К", "Т", "З", "Л", "В", "Х", "Ы", "P", "Я", "О", "Б", "Г", "<", "М", "Ь", "Ж", ">" }; -const QString Baudot::m_russianFigure[] = { +const QStringList Baudot::m_russianFigure = { "\0", "3", "\n", "-", " ", "\'", "8", "7", "\r", "Ч", "4", "Ю", ",", "Э", ":", "(", "5", "+", ")", "2", "Щ", "6", "0", "1", "9", "?", "Ш", "<", ".", "/", ";", ">" }; -const QString Baudot::m_murrayLetter[] = { +const QStringList Baudot::m_murrayLetter = { " ", "E", "?", "A", ">", "S", "I", "U", "\n", "D", "R", "J", "N", "F", "C", "K", "T", "Z", "L", "W", "H", "Y", "P", "Q", "O", "B", "G", "<", "M", "X", "V", "\b" }; -const QString Baudot::m_murrayFigure[] = { +const QStringList Baudot::m_murrayFigure = { " ", "3", "?", " ", ">", "'", "8", "7", "\n", "²", "4", "⁷⁄", "-", "⅟", "(", "⁹⁄", "5", ".", "/", "2", "⁵⁄", "6", "0", "1", @@ -190,3 +190,172 @@ QString BaudotDecoder::decode(char bits) return c; } +BaudotEncoder::BaudotEncoder() +{ + setCharacterSet(Baudot::ITA2); + setUnshiftOnSpace(false); + setMsbFirst(false); + setStartBits(1); + setStopBits(1); + init(); +} + +void BaudotEncoder::setCharacterSet(Baudot::CharacterSet characterSet) +{ + m_characterSet = characterSet; + switch (m_characterSet) + { + case Baudot::ITA2: + m_letters = Baudot::m_ita2Letter; + m_figures = Baudot::m_ita2Figure; + break; + case Baudot::UK: + m_letters = Baudot::m_ukLetter; + m_figures = Baudot::m_ukFigure; + break; + case Baudot::EUROPEAN: + m_letters = Baudot::m_europeanLetter; + m_figures = Baudot::m_europeanFigure; + break; + case Baudot::US: + m_letters = Baudot::m_usLetter; + m_figures = Baudot::m_usFigure; + break; + case Baudot::RUSSIAN: + m_letters = Baudot::m_russianLetter; + m_figures = Baudot::m_russianFigure; + break; + case Baudot::MURRAY: + m_letters = Baudot::m_murrayLetter; + m_figures = Baudot::m_murrayFigure; + break; + default: + qDebug() << "BaudotEncoder::BaudotEncoder: Unsupported character set " << m_characterSet; + m_letters = Baudot::m_ita2Letter; + m_figures = Baudot::m_ita2Figure; + m_characterSet = Baudot::ITA2; + break; + } +} + +void BaudotEncoder::setUnshiftOnSpace(bool unshiftOnSpace) +{ + m_unshiftOnSpace = unshiftOnSpace; +} + +void BaudotEncoder::setMsbFirst(bool msbFirst) +{ + m_msbFirst = msbFirst; +} + +// startBits should be 0 or 1 +void BaudotEncoder::setStartBits(int startBits) +{ + m_startBits = startBits; +} + +// stopBits should be 0, 1 or 2 +void BaudotEncoder::setStopBits(int stopBits) +{ + m_stopBits = stopBits; +} + +void BaudotEncoder::init() +{ + m_figure = false; +} + +bool BaudotEncoder::encode(QChar c, unsigned &bits, unsigned int &bitCount) +{ + unsigned int code; + const unsigned int codeLen = 5; + + bits = 0; + bitCount = 0; + + // Only upper case is supported + c = c.toUpper(); + QString s(c); + + // We could create reverse look-up tables to speed this up, but it's only 200 baud... + if (m_letters.contains(s)) + { + if (m_figure) + { + // Switch to letters + addStartBits(bits, bitCount); + code = reverseBits(m_letters.indexOf(">"), codeLen); + addBits(bits, bitCount, code, codeLen); + addStopBits(bits, bitCount); + m_figure = false; + } + addStartBits(bits, bitCount); + code = reverseBits(m_letters.indexOf(s), codeLen); + addBits(bits, bitCount, code, codeLen); + addStopBits(bits, bitCount); + return true; + } + else if (m_figures.contains(s)) + { + if (!m_figure) + { + // Switch to figures + addStartBits(bits, bitCount); + code = reverseBits(m_letters.indexOf("<"), codeLen); + addBits(bits, bitCount, code, codeLen); + addStopBits(bits, bitCount); + m_figure = true; + } + addStartBits(bits, bitCount); + code = reverseBits(m_figures.indexOf(s), codeLen); + addBits(bits, bitCount, code, codeLen); + addStopBits(bits, bitCount); + if ((s == " ") && m_unshiftOnSpace) { + m_figure = false; + } + } + else + { + qDebug() << "BaudotEncoder::encode: Can't encode" << c; + return false; + } + + return true; +} + +void BaudotEncoder::addStartBits(unsigned& bits, unsigned int& bitCount) const +{ + // Start bit is 0 + addBits(bits, bitCount, 0, m_startBits); +} + +void BaudotEncoder::addStopBits(unsigned& bits, unsigned int& bitCount) const +{ + // Stop bit is 1 + addBits(bits, bitCount, ((1 << m_stopBits)) - 1, m_stopBits); +} + +void BaudotEncoder::addBits(unsigned& bits, unsigned int& bitCount, int data, int count) const +{ + bits |= data << bitCount; + bitCount += count; +} + +unsigned BaudotEncoder::reverseBits(unsigned bits, unsigned int count) const +{ + if (m_msbFirst) { + return BaudotEncoder::reverse(bits) >> (sizeof(unsigned int) * 8 - count); + } else { + return bits; + } +} + +unsigned int BaudotEncoder::reverse(unsigned int x) +{ + x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); + x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); + x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); + x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); + + return((x >> 16) | (x << 16)); +} diff --git a/sdrbase/util/baudot.h b/sdrbase/util/baudot.h index 3f714c9be0..ade131abee 100644 --- a/sdrbase/util/baudot.h +++ b/sdrbase/util/baudot.h @@ -38,18 +38,18 @@ class SDRBASE_API Baudot { }; // QString used for fractions in figure set - static const QString m_ita2Letter[]; - static const QString m_ita2Figure[]; - static const QString m_ukLetter[]; - static const QString m_ukFigure[]; - static const QString m_europeanLetter[]; - static const QString m_europeanFigure[]; - static const QString m_usLetter[]; - static const QString m_usFigure[]; - static const QString m_russianLetter[]; - static const QString m_russianFigure[]; - static const QString m_murrayLetter[]; - static const QString m_murrayFigure[]; + static const QStringList m_ita2Letter; + static const QStringList m_ita2Figure; + static const QStringList m_ukLetter; + static const QStringList m_ukFigure; + static const QStringList m_europeanLetter; + static const QStringList m_europeanFigure; + static const QStringList m_usLetter; + static const QStringList m_usFigure; + static const QStringList m_russianLetter; + static const QStringList m_russianFigure; + static const QStringList m_murrayLetter; + static const QStringList m_murrayFigure; }; @@ -58,7 +58,7 @@ class SDRBASE_API BaudotDecoder { public: BaudotDecoder(); - void setCharacterSet(Baudot::CharacterSet characterSet=Baudot::ITA2); + void setCharacterSet(Baudot::CharacterSet characterSet = Baudot::ITA2); void setUnshiftOnSpace(bool unshiftOnSpace); void init(); QString decode(char bits); @@ -67,11 +67,43 @@ class SDRBASE_API BaudotDecoder { Baudot::CharacterSet m_characterSet; bool m_unshiftOnSpace; - const QString *m_letters; - const QString *m_figures; + QStringList m_letters; + QStringList m_figures; bool m_figure; }; +class SDRBASE_API BaudotEncoder { + +public: + + BaudotEncoder(); + void setCharacterSet(Baudot::CharacterSet characterSet = Baudot::ITA2); + void setUnshiftOnSpace(bool unshiftOnSpace); + void setMsbFirst(bool msbFirst); + void setStartBits(int startBits); + void setStopBits(int stopBits); + void init(); + bool encode(QChar c, unsigned& bits, unsigned int &bitCount); + +private: + + void addStartBits(unsigned int& bits, unsigned int& bitCount) const; + void addStopBits(unsigned int& bits, unsigned int& bitCount) const; + void addBits(unsigned int& bits, unsigned int& bitCount, int data, int count) const; + unsigned reverseBits(unsigned int bits, unsigned int count) const; + static unsigned reverse(unsigned int bits); + + Baudot::CharacterSet m_characterSet; + bool m_unshiftOnSpace; + QStringList m_letters; + QStringList m_figures; + bool m_figure; + bool m_msbFirst; + int m_startBits; + int m_stopBits; + +}; + #endif // INCLUDE_UTIL_BAUDOT_H diff --git a/swagger/sdrangel/api/swagger/include/ChannelActions.yaml b/swagger/sdrangel/api/swagger/include/ChannelActions.yaml index 86ce9318a0..7eee32cf5e 100644 --- a/swagger/sdrangel/api/swagger/include/ChannelActions.yaml +++ b/swagger/sdrangel/api/swagger/include/ChannelActions.yaml @@ -31,5 +31,7 @@ ChannelActions: $ref: "http://swgserver:8081/api/swagger/include/PacketMod.yaml#/PacketModActions" RadioAstronomyActions: $ref: "http://swgserver:8081/api/swagger/include/RadioAstronomy.yaml#/RadioAstronomyActions" + RTTYModActions: + $ref: "http://swgserver:8081/api/swagger/include/RTTYMod.yaml#/RTTYModActions" SigMFFileSinkActions: $ref: "http://swgserver:8081/api/swagger/include/SigMFFileSink.yaml#/SigMFFileSinkActions" diff --git a/swagger/sdrangel/api/swagger/include/ChannelReport.yaml b/swagger/sdrangel/api/swagger/include/ChannelReport.yaml index 1489c596a8..5f8e9038b4 100644 --- a/swagger/sdrangel/api/swagger/include/ChannelReport.yaml +++ b/swagger/sdrangel/api/swagger/include/ChannelReport.yaml @@ -81,6 +81,8 @@ ChannelReport: $ref: "http://swgserver:8081/api/swagger/include/RadiosondeDemod.yaml#/RadiosondeDemodReport" RemoteSourceReport: $ref: "http://swgserver:8081/api/swagger/include/RemoteSource.yaml#/RemoteSourceReport" + RTTYModReport: + $ref: "http://swgserver:8081/api/swagger/include/RTTYMod.yaml#/RTTYModReport" PacketDemodReport: $ref: "http://swgserver:8081/api/swagger/include/PacketDemod.yaml#/PacketDemodReport" PacketModReport: diff --git a/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml b/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml index 7f671b0d2a..a504187c98 100644 --- a/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml +++ b/swagger/sdrangel/api/swagger/include/ChannelSettings.yaml @@ -69,6 +69,8 @@ ChannelSettings: $ref: "http://swgserver:8081/api/swagger/include/FT8Demod.yaml#/FT8DemodSettings" RTTYDemodSettings: $ref: "http://swgserver:8081/api/swagger/include/RTTYDemod.yaml#/RTTYDemodSettings" + RTTYModSettings: + $ref: "http://swgserver:8081/api/swagger/include/RTTYMod.yaml#/RTTYModSettings" HeatMapSettings: $ref: "http://swgserver:8081/api/swagger/include/HeatMap.yaml#/HeatMapSettings" ILSDemodSettings: diff --git a/swagger/sdrangel/api/swagger/include/RTTYMod.yaml b/swagger/sdrangel/api/swagger/include/RTTYMod.yaml new file mode 100644 index 0000000000..b616507409 --- /dev/null +++ b/swagger/sdrangel/api/swagger/include/RTTYMod.yaml @@ -0,0 +1,106 @@ +RTTYModSettings: + description: RTTYMod + properties: + inputFrequencyOffset: + type: integer + format: int64 + baud: + type: number + format: float + description: Baud rate + rfBandwidth: + type: integer + frequencyShift: + type: integer + gain: + type: number + format: float + channelMute: + type: integer + repeat: + type: integer + repeatCount: + type: integer + lpfTaps: + type: integer + bbNoise: + type: integer + description: > + Boolean + * 0 - off + * 1 - on + rfNoise: + type: integer + description: > + Boolean + * 0 - off + * 1 - on + data: + type: string + pulseShaping: + type: integer + description: > + Boolean + * 0 - off + * 1 - on + beta: + type: number + format: float + symbolSpan: + type: integer + udpEnabled: + description: "Whether to receive text to transmit on specified UDP port" + type: integer + udpAddress: + description: "UDP address to receive text to transmit via" + type: string + udpPort: + description: "UDP port to receive text to transmit via" + type: integer + rgbColor: + type: integer + title: + type: string + 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 + reverseAPIAddress: + type: string + reverseAPIPort: + type: integer + reverseAPIDeviceIndex: + type: integer + reverseAPIChannelIndex: + type: integer + channelMarker: + $ref: "http://swgserver:8081/api/swagger/include/ChannelMarker.yaml#/ChannelMarker" + rollupState: + $ref: "http://swgserver:8081/api/swagger/include/RollupState.yaml#/RollupState" + +RTTYModReport: + description: RTTYMod + properties: + channelPowerDB: + description: power transmitted in channel (dB) + type: number + format: float + channelSampleRate: + type: integer + +RTTYModActions: + description: RTTYMod + properties: + tx: + type: integer + description: > + Transmit current text + * 0 - Do nothing + * 1 - Transmit + payload: + type: object + properties: + data: + type: string From 55ccfcd98c6be337aafd559c2ee167eb42dd56e9 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Fri, 1 Sep 2023 18:25:11 +0100 Subject: [PATCH 02/24] Generate swagger files for RTTY mod --- plugins/channeltx/modrtty/rttymod.cpp | 56 +- .../modrtty/rttymodwebapiadapter.cpp | 4 +- swagger/sdrangel/code/html2/index.html | 257 +++++- .../code/qt5/client/SWGChannelActions.cpp | 25 + .../code/qt5/client/SWGChannelActions.h | 7 + .../code/qt5/client/SWGChannelReport.cpp | 25 + .../code/qt5/client/SWGChannelReport.h | 7 + .../code/qt5/client/SWGChannelSettings.cpp | 25 + .../code/qt5/client/SWGChannelSettings.h | 7 + .../code/qt5/client/SWGModelFactory.h | 24 + .../code/qt5/client/SWGRTTYModActions.cpp | 133 ++++ .../code/qt5/client/SWGRTTYModActions.h | 65 ++ .../qt5/client/SWGRTTYModActions_payload.cpp | 110 +++ .../qt5/client/SWGRTTYModActions_payload.h | 59 ++ .../code/qt5/client/SWGRTTYModReport.cpp | 131 ++++ .../code/qt5/client/SWGRTTYModReport.h | 64 ++ .../code/qt5/client/SWGRTTYModSettings.cpp | 741 ++++++++++++++++++ .../code/qt5/client/SWGRTTYModSettings.h | 223 ++++++ 18 files changed, 1882 insertions(+), 81 deletions(-) create mode 100644 swagger/sdrangel/code/qt5/client/SWGRTTYModActions.cpp create mode 100644 swagger/sdrangel/code/qt5/client/SWGRTTYModActions.h create mode 100644 swagger/sdrangel/code/qt5/client/SWGRTTYModActions_payload.cpp create mode 100644 swagger/sdrangel/code/qt5/client/SWGRTTYModActions_payload.h create mode 100644 swagger/sdrangel/code/qt5/client/SWGRTTYModReport.cpp create mode 100644 swagger/sdrangel/code/qt5/client/SWGRTTYModReport.h create mode 100644 swagger/sdrangel/code/qt5/client/SWGRTTYModSettings.cpp create mode 100644 swagger/sdrangel/code/qt5/client/SWGRTTYModSettings.h diff --git a/plugins/channeltx/modrtty/rttymod.cpp b/plugins/channeltx/modrtty/rttymod.cpp index bea3218325..3faf110461 100644 --- a/plugins/channeltx/modrtty/rttymod.cpp +++ b/plugins/channeltx/modrtty/rttymod.cpp @@ -30,8 +30,8 @@ #include "SWGWorkspaceInfo.h" #include "SWGChannelReport.h" #include "SWGChannelActions.h" -/*#include "SWGRttyModReport.h" -#include "SWGRttyModActions.h"*/ +#include "SWGRTTYModReport.h" +#include "SWGRTTYModActions.h" #include #include @@ -262,10 +262,6 @@ void RttyMod::applySettings(const RttyModSettings& settings, bool force) reverseAPIKeys.append("rfNoise"); } - if ((settings.m_writeToFile != m_settings.m_writeToFile) || force) { - reverseAPIKeys.append("writeToFile"); - } - if ((settings.m_data != m_settings.m_data) || force) { reverseAPIKeys.append("data"); } @@ -382,10 +378,10 @@ int RttyMod::webapiSettingsGet( QString& errorMessage) { (void) errorMessage; - /*response.setRttyModSettings(new SWGSDRangel::SWGRttyModSettings()); + response.setRttyModSettings(new SWGSDRangel::SWGRTTYModSettings()); response.getRttyModSettings()->init(); webapiFormatChannelSettings(response, m_settings); - */ + return 200; } @@ -427,7 +423,7 @@ void RttyMod::webapiUpdateChannelSettings( const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response) { - /*if (channelSettingsKeys.contains("inputFrequencyOffset")) { + if (channelSettingsKeys.contains("inputFrequencyOffset")) { settings.m_inputFrequencyOffset = response.getRttyModSettings()->getInputFrequencyOffset(); } if (channelSettingsKeys.contains("baud")) { @@ -448,9 +444,6 @@ void RttyMod::webapiUpdateChannelSettings( if (channelSettingsKeys.contains("repeat")) { settings.m_repeat = response.getRttyModSettings()->getRepeat() != 0; } - if (channelSettingsKeys.contains("repeatDelay")) { - settings.m_repeatDelay = response.getRttyModSettings()->getRepeatDelay(); - } if (channelSettingsKeys.contains("repeatCount")) { settings.m_repeatCount = response.getRttyModSettings()->getRepeatCount(); } @@ -463,9 +456,6 @@ void RttyMod::webapiUpdateChannelSettings( if (channelSettingsKeys.contains("rfNoise")) { settings.m_rfNoise = response.getRttyModSettings()->getRfNoise() != 0; } - if (channelSettingsKeys.contains("writeToFile")) { - settings.m_writeToFile = response.getRttyModSettings()->getWriteToFile() != 0; - } if (channelSettingsKeys.contains("data")) { settings.m_data = *response.getRttyModSettings()->getData(); } @@ -513,7 +503,7 @@ void RttyMod::webapiUpdateChannelSettings( } if (settings.m_rollupState && channelSettingsKeys.contains("rollupState")) { settings.m_rollupState->updateFrom(channelSettingsKeys, response.getRttyModSettings()->getRollupState()); - }*/ + } } int RttyMod::webapiReportGet( @@ -521,9 +511,9 @@ int RttyMod::webapiReportGet( QString& errorMessage) { (void) errorMessage; - /*response.setRttyModReport(new SWGSDRangel::SWGRttyModReport()); + response.setRttyModReport(new SWGSDRangel::SWGRTTYModReport()); response.getRttyModReport()->init(); - webapiFormatChannelReport(response);*/ + webapiFormatChannelReport(response); return 200; } @@ -532,7 +522,7 @@ int RttyMod::webapiActionsPost( SWGSDRangel::SWGChannelActions& query, QString& errorMessage) { - /*SWGSDRangel::SWGRttyModActions *swgRttyModActions = query.getRttyModActions(); + SWGSDRangel::SWGRTTYModActions *swgRttyModActions = query.getRttyModActions(); if (swgRttyModActions) { @@ -544,7 +534,7 @@ int RttyMod::webapiActionsPost( && (swgRttyModActions->getPayload()->getData())) { MsgTXPacketData *msg = MsgTXPacketData::create( - *swgRttyModActions->getPayload()->getData( + *swgRttyModActions->getPayload()->getData() ); m_basebandSource->getInputMessageQueue()->push(msg); } @@ -572,25 +562,23 @@ int RttyMod::webapiActionsPost( { errorMessage = "Missing RttyModActions in query"; return 400; - }*/ + } return 0; } void RttyMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const RttyModSettings& settings) { - /*response.getRttyModSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset); + response.getRttyModSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset); response.getRttyModSettings()->setBaud(settings.m_baud); response.getRttyModSettings()->setRfBandwidth(settings.m_rfBandwidth); response.getRttyModSettings()->setFrequencyShift(settings.m_frequencyShift); response.getRttyModSettings()->setGain(settings.m_gain); response.getRttyModSettings()->setChannelMute(settings.m_channelMute ? 1 : 0); response.getRttyModSettings()->setRepeat(settings.m_repeat ? 1 : 0); - response.getRttyModSettings()->setRepeatDelay(settings.m_repeatDelay); response.getRttyModSettings()->setRepeatCount(settings.m_repeatCount); response.getRttyModSettings()->setLpfTaps(settings.m_lpfTaps); response.getRttyModSettings()->setBbNoise(settings.m_bbNoise ? 1 : 0); response.getRttyModSettings()->setRfNoise(settings.m_rfNoise ? 1 : 0); - response.getRttyModSettings()->setWriteToFile(settings.m_writeToFile ? 1 : 0); if (response.getRttyModSettings()->getData()) { *response.getRttyModSettings()->getData() = settings.m_data; @@ -651,13 +639,13 @@ void RttyMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respo settings.m_rollupState->formatTo(swgRollupState); response.getRttyModSettings()->setRollupState(swgRollupState); } - }*/ + } } void RttyMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) { - /*response.getRttyModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); - response.getRttyModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate());*/ + response.getRttyModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq())); + response.getRttyModReport()->setChannelSampleRate(m_basebandSource->getChannelSampleRate()); } void RttyMod::webapiReverseSendSettings(QList& channelSettingsKeys, const RttyModSettings& settings, bool force) @@ -717,12 +705,12 @@ void RttyMod::webapiFormatChannelSettings( bool force ) { - /*swgChannelSettings->setDirection(1); // single source (Tx) + swgChannelSettings->setDirection(1); // single source (Tx) swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet()); swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex()); swgChannelSettings->setChannelType(new QString(m_channelId)); - swgChannelSettings->setRttyModSettings(new SWGSDRangel::SWGRttyModSettings()); - SWGSDRangel::SWGRttyModSettings *swgRttyModSettings = swgChannelSettings->getRttyModSettings(); + swgChannelSettings->setRttyModSettings(new SWGSDRangel::SWGRTTYModSettings()); + SWGSDRangel::SWGRTTYModSettings *swgRttyModSettings = swgChannelSettings->getRttyModSettings(); // transfer data that has been modified. When force is on transfer all data except reverse API data @@ -747,9 +735,6 @@ void RttyMod::webapiFormatChannelSettings( if (channelSettingsKeys.contains("repeat") || force) { swgRttyModSettings->setRepeat(settings.m_repeat ? 1 : 0); } - if (channelSettingsKeys.contains("repeatDelay") || force) { - swgRttyModSettings->setRepeatDelay(settings.m_repeatDelay); - } if (channelSettingsKeys.contains("repeatCount") || force) { swgRttyModSettings->setRepeatCount(settings.m_repeatCount); } @@ -762,9 +747,6 @@ void RttyMod::webapiFormatChannelSettings( if (channelSettingsKeys.contains("rfNoise")) { swgRttyModSettings->setRfNoise(settings.m_rfNoise ? 1 : 0); } - if (channelSettingsKeys.contains("writeToFile")) { - swgRttyModSettings->setWriteToFile(settings.m_writeToFile ? 1 : 0); - } if (channelSettingsKeys.contains("data")) { swgRttyModSettings->setData(new QString(settings.m_data)); } @@ -805,7 +787,7 @@ void RttyMod::webapiFormatChannelSettings( SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState(); settings.m_rollupState->formatTo(swgRollupState); swgRttyModSettings->setRollupState(swgRollupState); - }*/ + } } void RttyMod::networkManagerFinished(QNetworkReply *reply) diff --git a/plugins/channeltx/modrtty/rttymodwebapiadapter.cpp b/plugins/channeltx/modrtty/rttymodwebapiadapter.cpp index 9e51721bee..c86197520d 100644 --- a/plugins/channeltx/modrtty/rttymodwebapiadapter.cpp +++ b/plugins/channeltx/modrtty/rttymodwebapiadapter.cpp @@ -31,9 +31,9 @@ int RttyModWebAPIAdapter::webapiSettingsGet( QString& errorMessage) { (void) errorMessage; - /*response.setRttyModSettings(new SWGSDRangel::SWGRttyModSettings()); + response.setRttyModSettings(new SWGSDRangel::SWGRTTYModSettings()); response.getRttyModSettings()->init(); - RttyMod::webapiFormatChannelSettings(response, m_settings);*/ + RttyMod::webapiFormatChannelSettings(response, m_settings); return 200; } diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 495206ba07..9a38ff8e2b 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -3484,6 +3484,9 @@ "RadioAstronomyActions" : { "$ref" : "#/definitions/RadioAstronomyActions" }, + "RTTYModActions" : { + "$ref" : "#/definitions/RTTYModActions" + }, "SigMFFileSinkActions" : { "$ref" : "#/definitions/SigMFFileSinkActions" } @@ -3773,6 +3776,9 @@ "RemoteSourceReport" : { "$ref" : "#/definitions/RemoteSourceReport" }, + "RTTYModReport" : { + "$ref" : "#/definitions/RTTYModReport" + }, "PacketDemodReport" : { "$ref" : "#/definitions/PacketDemodReport" }, @@ -3904,6 +3910,9 @@ "RTTYDemodSettings" : { "$ref" : "#/definitions/RTTYDemodSettings" }, + "RTTYModSettings" : { + "$ref" : "#/definitions/RTTYModSettings" + }, "HeatMapSettings" : { "$ref" : "#/definitions/HeatMapSettings" }, @@ -5895,7 +5904,8 @@ }, "bandwidth" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "bandwidth ratio [0.0, 1.0]" } }, "description" : "FFT filter band definition" @@ -7269,11 +7279,13 @@ "description" : "Identifier of the channel or feature plugin providing azimuth and elevation (E.g. R0:0 ADSBDemod)" }, "azimuthOffset" : { - "type" : "integer", + "type" : "number", + "format" : "float", "description" : "Azimuth offset in degrees" }, "elevationOffset" : { - "type" : "integer", + "type" : "number", + "format" : "float", "description" : "Elevation offset in degrees" }, "azimuthMin" : { @@ -8960,7 +8972,7 @@ }, "fftOn" : { "type" : "integer", - "description" : "Activate FFT multiband filter\n * 0 - do not run flter\n * 1 - run filter\n" + "description" : "Activate FFT multiband filter\n * 0 - do not run filter\n * 1 - run filter\n" }, "log2FFT" : { "type" : "integer", @@ -8977,7 +8989,8 @@ } }, "reverseFilter" : { - "type" : "integer" + "type" : "integer", + "description" : "* 0 - band definitions are bandpass * 1 - band definitions are band reject\n" }, "streamIndex" : { "type" : "integer", @@ -9446,7 +9459,8 @@ "description" : "Angle to rotate the image by" }, "text" : { - "type" : "string" + "type" : "string", + "description" : "Text to draw on the map when item is selected" }, "latitude" : { "type" : "number", @@ -9519,7 +9533,7 @@ "labelAltitudeOffset" : { "type" : "number", "format" : "float", - "description" : "Veritical offset to position label at" + "description" : "Vertical offset to position label at" }, "modelAltitudeOffset" : { "type" : "number", @@ -9605,7 +9619,8 @@ "description" : "Angle to rotate the image by" }, "text" : { - "type" : "string" + "type" : "string", + "description" : "Text to draw on the map when item is selected" }, "latitude" : { "type" : "number", @@ -9678,7 +9693,7 @@ "labelAltitudeOffset" : { "type" : "number", "format" : "float", - "description" : "Veritical offset to position label at" + "description" : "Vertical offset to position label at" }, "modelAltitudeOffset" : { "type" : "number", @@ -11747,6 +11762,140 @@ } }, "description" : "ACARSDemod" +}; + defs.RTTYModActions = { + "properties" : { + "tx" : { + "type" : "integer", + "description" : "Transmit current text\n * 0 - Do nothing\n * 1 - Transmit\n" + }, + "payload" : { + "$ref" : "#/definitions/RTTYModActions_payload" + } + }, + "description" : "RTTYMod" +}; + defs.RTTYModActions_payload = { + "properties" : { + "data" : { + "type" : "string" + } + } +}; + defs.RTTYModReport = { + "properties" : { + "channelPowerDB" : { + "type" : "number", + "format" : "float", + "description" : "power transmitted in channel (dB)" + }, + "channelSampleRate" : { + "type" : "integer" + } + }, + "description" : "RTTYMod" +}; + defs.RTTYModSettings = { + "properties" : { + "inputFrequencyOffset" : { + "type" : "integer", + "format" : "int64" + }, + "baud" : { + "type" : "number", + "format" : "float", + "description" : "Baud rate" + }, + "rfBandwidth" : { + "type" : "integer" + }, + "frequencyShift" : { + "type" : "integer" + }, + "gain" : { + "type" : "number", + "format" : "float" + }, + "channelMute" : { + "type" : "integer" + }, + "repeat" : { + "type" : "integer" + }, + "repeatCount" : { + "type" : "integer" + }, + "lpfTaps" : { + "type" : "integer" + }, + "bbNoise" : { + "type" : "integer", + "description" : "Boolean\n * 0 - off\n * 1 - on\n" + }, + "rfNoise" : { + "type" : "integer", + "description" : "Boolean\n * 0 - off\n * 1 - on\n" + }, + "data" : { + "type" : "string" + }, + "pulseShaping" : { + "type" : "integer", + "description" : "Boolean\n * 0 - off\n * 1 - on\n" + }, + "beta" : { + "type" : "number", + "format" : "float" + }, + "symbolSpan" : { + "type" : "integer" + }, + "udpEnabled" : { + "type" : "integer", + "description" : "Whether to receive text to transmit on specified UDP port" + }, + "udpAddress" : { + "type" : "string", + "description" : "UDP address to receive text to transmit via" + }, + "udpPort" : { + "type" : "integer", + "description" : "UDP port to receive text to transmit via" + }, + "rgbColor" : { + "type" : "integer" + }, + "title" : { + "type" : "string" + }, + "streamIndex" : { + "type" : "integer", + "description" : "MIMO channel. Not relevant when connected to SI (single Rx)." + }, + "useReverseAPI" : { + "type" : "integer", + "description" : "Synchronize with reverse API (1 for yes, 0 for no)" + }, + "reverseAPIAddress" : { + "type" : "string" + }, + "reverseAPIPort" : { + "type" : "integer" + }, + "reverseAPIDeviceIndex" : { + "type" : "integer" + }, + "reverseAPIChannelIndex" : { + "type" : "integer" + }, + "channelMarker" : { + "$ref" : "#/definitions/ChannelMarker" + }, + "rollupState" : { + "$ref" : "#/definitions/RollupState" + } + }, + "description" : "RTTYMod" }; defs.RadioAstronomyActions = { "properties" : { @@ -14449,15 +14598,18 @@ }, "b" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Galactic latitude in degrees" }, "l" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Galactic longitude in degrees" }, "d" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Distance to object from Sun in kpc" } }, "description" : "Details of object to display in Star Tracker line-of-sight view. Can be sent by other plugins to startracker.display message queue" @@ -14469,15 +14621,18 @@ }, "b" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Galactic latitude in degrees" }, "l" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Galactic longitude in degrees" }, "d" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Distance to object from Sun in kpc" } }, "description" : "Details of object to display in Star Tracker line-of-sight view. Can be sent by other plugins to startracker.display message queue" @@ -14490,11 +14645,13 @@ }, "azimuth" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The azimuth angle in degrees to the target" }, "elevation" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The elevation angle in degrees to the target" } }, "description" : "Settings to display in Star Tracker. Can be sent by other plugins to startracker.display message queue." @@ -14507,11 +14664,13 @@ }, "azimuth" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The azimuth angle in degrees to the target" }, "elevation" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The elevation angle in degrees to the target" } }, "description" : "Settings to display in Star Tracker. Can be sent by other plugins to startracker.display message queue." @@ -14595,7 +14754,7 @@ "temperature" : { "type" : "number", "format" : "float", - "description" : "Air temperature in Celsuis, for refraction" + "description" : "Air temperature in Celsius, for refraction" }, "humidity" : { "type" : "number", @@ -14618,7 +14777,8 @@ "description" : "Frequency of radio waves being observed in MHz" }, "stellariumServerEnabled" : { - "type" : "integer" + "type" : "integer", + "description" : "Enable Stellarium server (1 for yes, 0 for no)" }, "stellariumPort" : { "type" : "integer", @@ -14676,15 +14836,18 @@ defs.StarTrackerTarget = { "properties" : { "name" : { - "type" : "string" + "type" : "string", + "description" : "The name of the target" }, "azimuth" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The azimuth angle in degrees to the target" }, "elevation" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The elevation angle in degrees to the target" }, "ra" : { "type" : "number", @@ -14698,11 +14861,13 @@ }, "b" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Galactic latitude in degrees" }, "l" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Galactic longitude in degrees" }, "earthRotationVelocity" : { "type" : "number", @@ -14745,15 +14910,18 @@ defs.StarTrackerTarget_2 = { "properties" : { "name" : { - "type" : "string" + "type" : "string", + "description" : "The name of the target" }, "azimuth" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The azimuth angle in degrees to the target" }, "elevation" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The elevation angle in degrees to the target" }, "ra" : { "type" : "number", @@ -14767,11 +14935,13 @@ }, "b" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Galactic latitude in degrees" }, "l" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "Galactic longitude in degrees" }, "earthRotationVelocity" : { "type" : "number", @@ -14822,15 +14992,18 @@ defs.TargetAzimuthElevation = { "properties" : { "name" : { - "type" : "string" + "type" : "string", + "description" : "The name of the target" }, "azimuth" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The azimuth angle in degrees to the target" }, "elevation" : { "type" : "number", - "format" : "float" + "format" : "float", + "description" : "The elevation angle in degrees to the target" } }, "description" : "A target azimuth and elevation" @@ -22563,7 +22736,7 @@

Parameters

Responses

-

Status: 202 - On successful semding of the message it returns the details of the device being set

+

Status: 202 - On successful sending of the message it returns the details of the device being set