diff --git a/.gitignore b/.gitignore index 55516db49e..9aa9d4f548 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ obj-x86_64-linux-gnu/* /rescuesdriq/vendor/ /rescuesdriq/Godeps/ +/.vs diff --git a/CMakeLists.txt b/CMakeLists.txt index 4266a1c777..a2d05068d5 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/doc/img/RTTYMod_plugin.png b/doc/img/RTTYMod_plugin.png new file mode 100644 index 0000000000..8d0c862fcc Binary files /dev/null and b/doc/img/RTTYMod_plugin.png differ diff --git a/plugins/channelrx/demoddsc/dscdemodsink.cpp b/plugins/channelrx/demoddsc/dscdemodsink.cpp index 695dcab4fa..0eae78418e 100644 --- a/plugins/channelrx/demoddsc/dscdemodsink.cpp +++ b/plugins/channelrx/demoddsc/dscdemodsink.cpp @@ -227,6 +227,8 @@ void DSCDemodSink::receiveBit(bool bit) m_dscDecoder.init(m_phasingPatterns[i].m_offset); m_gotSOP = true; m_bitCount = 0; + m_rssiMagSqSum = 0.0; + m_rssiMagSqCount = 0; break; } } diff --git a/plugins/channelrx/demodnavtex/navtexdemodsink.cpp b/plugins/channelrx/demodnavtex/navtexdemodsink.cpp index eac89e944f..47b3e42d5e 100644 --- a/plugins/channelrx/demodnavtex/navtexdemodsink.cpp +++ b/plugins/channelrx/demodnavtex/navtexdemodsink.cpp @@ -329,6 +329,8 @@ void NavtexDemodSink::receiveBit(bool bit) m_gotSOP = true; m_bitCount = 0; m_sitorBDecoder.init(); + m_rssiMagSqSum = 0.0; + m_rssiMagSqCount = 0; } else { diff --git a/plugins/channelrx/demodrtty/readme.md b/plugins/channelrx/demodrtty/readme.md index 8a56457f87..27232fadc9 100644 --- a/plugins/channelrx/demodrtty/readme.md +++ b/plugins/channelrx/demodrtty/readme.md @@ -79,7 +79,12 @@ Specifies whether bits are transmitted least-significant-bit first (LSB) or most

14: Mark/Space Frequency

-When unchecked, the mark frequency is the higher frequency, when checked the space frequency is higher. +When unchecked, the mark frequency is the higher RF frequency, when checked the space frequency is higher. + +This should be unchecked when transmitter is using LSB AFSK and checked for USB AFSK and DWD +[1](https://www.dwd.de/EN/specialusers/shipping/broadcast_en/brodcast_rtty_1_052014.pdf?__blob=publicationFile&v=1) +[2](https://www.dwd.de/EN/specialusers/shipping/broadcast_en/broadcast_rtty_2_052014.pdf?__blob=publicationFile&v=1) +shipping weather broadcasts.

15: Suppress CR LF

@@ -101,3 +106,4 @@ Click to specify the name of the .txt file which received characters are logged The received text area shows characters as they are received. +Holding the cursor over an acronym may show a tooltip with the decoded acronym. diff --git a/plugins/channelrx/demodrtty/rttydemodgui.cpp b/plugins/channelrx/demodrtty/rttydemodgui.cpp index 57fda37c2d..5945a13040 100644 --- a/plugins/channelrx/demodrtty/rttydemodgui.cpp +++ b/plugins/channelrx/demodrtty/rttydemodgui.cpp @@ -34,6 +34,7 @@ #include "plugin/pluginapi.h" #include "util/simpleserializer.h" #include "util/db.h" +#include "util/rtty.h" #include "gui/basicchannelsettingsdialog.h" #include "gui/devicestreamselectiondialog.h" #include "dsp/dspengine.h" @@ -482,6 +483,8 @@ RttyDemodGUI::RttyDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor())); connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + ui->text->addAcronyms(Rtty::m_acronyms); + ui->scopeContainer->setVisible(false); // Hide developer only settings diff --git a/plugins/channelrx/demodrtty/rttydemodgui.ui b/plugins/channelrx/demodrtty/rttydemodgui.ui index a70e366f52..8ac4000d9f 100644 --- a/plugins/channelrx/demodrtty/rttydemodgui.ui +++ b/plugins/channelrx/demodrtty/rttydemodgui.ui @@ -916,7 +916,7 @@ - + Received text @@ -1293,6 +1293,12 @@
gui/glscopegui.h
1 + + AcronymView + QTextEdit +
gui/acronymview.h
+ 1 +
deltaFrequency diff --git a/plugins/channelrx/demodrtty/rttydemodsink.cpp b/plugins/channelrx/demodrtty/rttydemodsink.cpp index 2f987994d6..8e8d70fc53 100644 --- a/plugins/channelrx/demodrtty/rttydemodsink.cpp +++ b/plugins/channelrx/demodrtty/rttydemodsink.cpp @@ -154,8 +154,8 @@ void RttyDemodSink::processOneSample(Complex &ci) m_expIdx = (m_expIdx + 1) % m_expLength; //Complex exp = m_exp[m_sampleIdx]; //qDebug() << "IQ " << real(ci) << imag(ci); - Complex corr1 = ci * exp; - Complex corr2 = ci * std::conj(exp); + Complex corr1 = ci * std::conj(exp); // Conj is high/mark freq (as for matched filter, we need to time reverse and take conjugate) + Complex corr2 = ci * exp; // Low/space freq // Filter Real abs1, abs2; @@ -238,6 +238,8 @@ void RttyDemodSink::processOneSample(Complex &ci) m_clockCount = 0; m_clock = false; m_cycleCount = 0; + m_rssiMagSqSum = 0.0; + m_rssiMagSqCount = 0; } } else 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/modpacket/packetmodgui.cpp b/plugins/channeltx/modpacket/packetmodgui.cpp index 9946421119..460ca424f0 100644 --- a/plugins/channeltx/modpacket/packetmodgui.cpp +++ b/plugins/channeltx/modpacket/packetmodgui.cpp @@ -288,6 +288,7 @@ void PacketModGUI::preEmphasisSelect(const QPoint& p) { FMPreemphasisDialog dialog(m_settings.m_preEmphasisTau, m_settings.m_preEmphasisHighFreq); dialog.move(p); + new DialogPositioner(&dialog, false); if (dialog.exec() == QDialog::Accepted) { @@ -301,6 +302,7 @@ void PacketModGUI::bpfSelect(const QPoint& p) { PacketModBPFDialog dialog(m_settings.m_bpfLowCutoff, m_settings.m_bpfHighCutoff, m_settings.m_bpfTaps); dialog.move(p); + new DialogPositioner(&dialog, false); if (dialog.exec() == QDialog::Accepted) { @@ -315,6 +317,7 @@ void PacketModGUI::repeatSelect(const QPoint& p) { PacketModRepeatDialog dialog(m_settings.m_repeatDelay, m_settings.m_repeatCount); dialog.move(p); + new DialogPositioner(&dialog, false); if (dialog.exec() == QDialog::Accepted) { @@ -339,6 +342,7 @@ void PacketModGUI::txSettingsSelect(const QPoint& p) m_settings.m_writeToFile); dialog.move(p); + new DialogPositioner(&dialog, false); if (dialog.exec() == QDialog::Accepted) { diff --git a/plugins/channeltx/modpacket/packetmodsource.cpp b/plugins/channeltx/modpacket/packetmodsource.cpp index b08d57b12f..7cb5465ec0 100644 --- a/plugins/channeltx/modpacket/packetmodsource.cpp +++ b/plugins/channeltx/modpacket/packetmodsource.cpp @@ -349,7 +349,7 @@ void PacketModSource::applySettings(const PacketModSettings& settings, bool forc << " 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); + m_pulseShape.create(settings.m_beta, settings.m_symbolSpan, m_channelSampleRate/settings.m_baud); } if ((settings.m_polynomial != m_settings.m_polynomial) || force) m_scrambler.setPolynomial(settings.m_polynomial); 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..cf267e4bdc --- /dev/null +++ b/plugins/channeltx/modrtty/readme.md @@ -0,0 +1,138 @@ +

RTTY Modulator Plugin

+ +

Introduction

+ +This plugin can be used to modulate RTTY (Radioteletype) encoded text. +RTTY uses BFSK (Binary Frequency Shift Keying), where transmission of data alternates between two frequencies, +the mark frequency and the space frequency. The RTTY Modulator should be centered in between these frequencies. +The baud rate, frequency shift (difference between mark and space frequencies), filter bandwidth and baudot character set are configurable. + +

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. The following character sets are supported: + +* ITA 2 +* UK +* European +* US +* Russian +* Murray + +

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. + +The list of pre-defined text can be customised via the Transmit Settings dialog (20). + +

20: TX

+ +Press to transmit the current text. The text field will not be cleared. + +Right click to open a dialog to adjust additional Transmit Settings, including the list of pre-defined text. + +Predefined text supports the following variable substitutions: + +* ${callsign} - Gets replaced with the station name from Preferences > My Position +* ${location} = Gets replaced with the Maidenhead locator for the position specified under Preferences > My Position + +The substitutions are applied when the Transmit Settings dialog is closed. + +

21: Transmitted Text

+ +The trasnmitted text area shows characters as they are transmitted. + +Holding the cursor over an acronym may show a tooltip with the decoded acronym. + +

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/0/channel/0/actions" -d '{"channelType": "RTTYMod", "direction": 1, "RTTYModActions": { "tx": 1 }}' + +To transmit text specified on the command line: + + curl -X POST "http://127.0.0.1:8091/sdrangel/deviceset/0/channel/0/actions" -d '{"channelType": "RTTYMod", "direction": 1, "RTTYModActions": { "tx": 1, "payload": {"text": "CQ CQ CQ anyone using SDRangel CQ" }}}' + +To set the baud rate and frequency shift: + + curl -X PATCH "http://127.0.0.1:8091/sdrangel/deviceset/0/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..48b9e1ab2c --- /dev/null +++ b/plugins/channeltx/modrtty/rttymod.cpp @@ -0,0 +1,932 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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::MsgTXText, 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 (MsgTXText::match(cmd)) + { + MsgTXText* msg = new MsgTXText((const MsgTXText&)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_text: " << settings.m_text + << " m_characterSet: " << settings.m_characterSet + << " m_unshiftOnSpace: " << settings.m_unshiftOnSpace + << " m_msbFirst: " << settings.m_msbFirst + << " m_spaceHigh: " << settings.m_spaceHigh + << " m_prefixCRLF: " << settings.m_prefixCRLF + << " m_postfixCRLF: " << settings.m_postfixCRLF + << " 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_rfNoise != m_settings.m_rfNoise) || force) { + reverseAPIKeys.append("rfNoise"); + } + + if ((settings.m_text != m_settings.m_text) || force) { + reverseAPIKeys.append("text"); + } + + 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_characterSet != m_settings.m_characterSet) || force) { + reverseAPIKeys.append("characterSet"); + } + + if ((settings.m_unshiftOnSpace != m_settings.m_unshiftOnSpace) || force) { + reverseAPIKeys.append("unshiftOnSpace"); + } + + if ((settings.m_msbFirst != m_settings.m_msbFirst) || force) { + reverseAPIKeys.append("msbFirst"); + } + + if ((settings.m_spaceHigh != m_settings.m_spaceHigh) || force) { + reverseAPIKeys.append("spaceHigh"); + } + + if ((settings.m_prefixCRLF != m_settings.m_prefixCRLF) || force) { + reverseAPIKeys.append("prefixCRLF"); + } + + if ((settings.m_postfixCRLF != m_settings.m_postfixCRLF) || force) { + reverseAPIKeys.append("postfixCRLF"); + } + + 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("repeatCount")) { + settings.m_repeatCount = response.getRttyModSettings()->getRepeatCount(); + } + if (channelSettingsKeys.contains("lpfTaps")) { + settings.m_lpfTaps = response.getRttyModSettings()->getLpfTaps(); + } + if (channelSettingsKeys.contains("rfNoise")) { + settings.m_rfNoise = response.getRttyModSettings()->getRfNoise() != 0; + } + if (channelSettingsKeys.contains("text")) { + settings.m_text = *response.getRttyModSettings()->getText(); + } + if (channelSettingsKeys.contains("beta")) { + settings.m_beta = response.getRttyModSettings()->getBeta(); + } + if (channelSettingsKeys.contains("symbolSpan")) { + settings.m_symbolSpan = response.getRttyModSettings()->getSymbolSpan(); + } + if (channelSettingsKeys.contains("characterSet")) { + settings.m_characterSet = (Baudot::CharacterSet) response.getRttyModSettings()->getCharacterSet(); + } + if (channelSettingsKeys.contains("unshiftOnSpace")) { + settings.m_unshiftOnSpace = response.getRttyModSettings()->getUnshiftOnSpace(); + } + if (channelSettingsKeys.contains("msbFirst")) { + settings.m_msbFirst = response.getRttyModSettings()->getMsbFirst(); + } + if (channelSettingsKeys.contains("spaceHigh")) { + settings.m_spaceHigh = response.getRttyModSettings()->getSpaceHigh(); + } + if (channelSettingsKeys.contains("prefixCRLF")) { + settings.m_prefixCRLF = response.getRttyModSettings()->getPrefixCrlf(); + } + if (channelSettingsKeys.contains("postfixCRLF")) { + settings.m_postfixCRLF = response.getRttyModSettings()->getPostfixCrlf(); + } + 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()->getText())) + { + MsgTXText *msg = MsgTXText::create( + *swgRttyModActions->getPayload()->getText() + ); + m_basebandSource->getInputMessageQueue()->push(msg); + } + else + { + MsgTx *msg = MsgTx::create(); + m_basebandSource->getInputMessageQueue()->push(msg); + } + + return 202; + } + else + { + errorMessage = "Must contain tx action"; + return 400; + } + } + else + { + errorMessage = "Unknown RTTYMod 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()->setRepeatCount(settings.m_repeatCount); + response.getRttyModSettings()->setLpfTaps(settings.m_lpfTaps); + response.getRttyModSettings()->setRfNoise(settings.m_rfNoise ? 1 : 0); + + if (response.getRttyModSettings()->getText()) { + *response.getRttyModSettings()->getText() = settings.m_text; + } else { + response.getRttyModSettings()->setText(new QString(settings.m_text)); + } + + response.getRttyModSettings()->setPulseShaping(settings.m_pulseShaping ? 1 : 0); + response.getRttyModSettings()->setBeta(settings.m_beta); + response.getRttyModSettings()->setSymbolSpan(settings.m_symbolSpan); + + response.getRttyModSettings()->setCharacterSet((int) settings.m_characterSet); + response.getRttyModSettings()->setSymbolSpan(settings.m_symbolSpan); + response.getRttyModSettings()->setUnshiftOnSpace(settings.m_unshiftOnSpace); + response.getRttyModSettings()->setMsbFirst(settings.m_msbFirst); + response.getRttyModSettings()->setSpaceHigh(settings.m_spaceHigh); + response.getRttyModSettings()->setPrefixCrlf(settings.m_prefixCRLF); + response.getRttyModSettings()->setPostfixCrlf(settings.m_postfixCRLF); + + 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("repeatCount") || force) { + swgRttyModSettings->setRepeatCount(settings.m_repeatCount); + } + if (channelSettingsKeys.contains("lpfTaps")) { + swgRttyModSettings->setLpfTaps(settings.m_lpfTaps); + } + if (channelSettingsKeys.contains("rfNoise")) { + swgRttyModSettings->setRfNoise(settings.m_rfNoise ? 1 : 0); + } + if (channelSettingsKeys.contains("text")) { + swgRttyModSettings->setText(new QString(settings.m_text)); + } + if (channelSettingsKeys.contains("beta")) { + swgRttyModSettings->setBeta(settings.m_beta); + } + if (channelSettingsKeys.contains("symbolSpan")) { + swgRttyModSettings->setSymbolSpan(settings.m_symbolSpan); + } + if (channelSettingsKeys.contains("characterSet")) { + swgRttyModSettings->setCharacterSet((int) settings.m_characterSet); + } + if (channelSettingsKeys.contains("unshiftOnSpace")) { + swgRttyModSettings->setUnshiftOnSpace(settings.m_unshiftOnSpace); + } + if (channelSettingsKeys.contains("msbFirst")) { + swgRttyModSettings->setMsbFirst(settings.m_msbFirst); + } + if (channelSettingsKeys.contains("spaceHigh")) { + swgRttyModSettings->setSpaceHigh(settings.m_spaceHigh); + } + if (channelSettingsKeys.contains("prefixCRLF")) { + swgRttyModSettings->setPrefixCrlf(settings.m_prefixCRLF); + } + if (channelSettingsKeys.contains("postfixCRLF")) { + swgRttyModSettings->setPostfixCrlf(settings.m_postfixCRLF); + } + 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 text 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(); + MsgTXText *msg = MsgTXText::create(QString(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..b50934b874 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymod.h @@ -0,0 +1,246 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 MsgTXText : public Message { + MESSAGE_CLASS_DECLARATION + + public: + static MsgTXText* create(QString text) + { + return new MsgTXText(text); + } + + QString m_text; + + private: + + MsgTXText(QString text) : + Message(), + m_text(text) + { } + }; + + //================================================================= + + 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..5919b03a67 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodbaseband.cpp @@ -0,0 +1,200 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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.addTXText(m_settings.m_text); + + return true; + } + else if (RttyMod::MsgTXText::match(cmd)) + { + RttyMod::MsgTXText& tx = (RttyMod::MsgTXText&) cmd; + m_source.addTXText(tx.m_text); + + 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..f1fc898ea9 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodgui.cpp @@ -0,0 +1,651 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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/rtty.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_text = 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); + + ui->glSpectrum->setCenterFrequency(0); + ui->glSpectrum->setSampleRate(2000); + ui->glSpectrum->setLsbDisplay(false); + + 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("RTTY 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->transmittedText->addAcronyms(Rtty::m_acronyms); + + 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& text) +{ + RttyMod::MsgTXText*msg = RttyMod::MsgTXText::create(text); + 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); + 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_text); + + 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..b7fee75f80 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodgui.ui @@ -0,0 +1,977 @@ + + + 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 + + + + + + + + + + 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 +
+ + AcronymView + QTextEdit +
gui/acronymview.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..b9bb0e1538 --- /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 times to transmit + +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..d6682c26a4 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodsettings.cpp @@ -0,0 +1,233 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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_rfNoise = false; + m_writeToFile = false; + m_text = "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(180, 205, 130).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 = 1.0f; + 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(25, m_rfNoise); + s.writeBool(26, m_writeToFile); + s.writeString(30, m_text); + + 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(25, &m_rfNoise, false); + d.readBool(26, &m_writeToFile, false); + d.readString(30, &m_text, "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, 1.0f); + 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..52e964b742 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodsettings.h @@ -0,0 +1,80 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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_rfNoise; + bool m_writeToFile; + QString m_text; // 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..aec6351ac7 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodsource.cpp @@ -0,0 +1,437 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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(2000), + m_fmPhase(0.0), + m_spectrumSink(nullptr), + m_specSampleBufferIndex(0), + 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, true); + + m_demodBuffer.resize(1<<12); + m_demodBufferFill = 0; + + m_specSampleBuffer.resize(m_specSampleBufferSize); + 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(Complex sample) +{ + if (m_spectrumSink) + { + Complex out; + if (m_interpolator.decimate(&m_interpolatorDistanceRemain, sample, &out)) + { + m_interpolatorDistanceRemain += m_interpolatorDistance; + Real r = std::real(out) * SDR_TX_SCALEF; + Real i = std::imag(out) * SDR_TX_SCALEF; + m_specSampleBuffer[m_specSampleBufferIndex++] = Sample(r, i); + if (m_specSampleBufferIndex == m_specSampleBufferSize) + { + m_spectrumSink->feed(m_specSampleBuffer.begin(), m_specSampleBuffer.end(), false); + m_specSampleBufferIndex = 0; + } + } + } +} + +void RttyModSource::modulateSample() +{ + Real mod; + + if (m_sampleIdx == 0) + { + if (m_bitCount == 0) + { + if (!m_textToTransmit.isEmpty()) + { + // Encode a character at a time, so we get a TxReport after each character + QString s = m_textToTransmit.left(1); + m_textToTransmit = m_textToTransmit.mid(1); + encodeText(s); + } + else + { + // Transmit "diddle" + encodeText(">"); + } + initTX(); + } + + m_bit = getBit(); + } + + m_sampleIdx++; + if (m_sampleIdx >= m_samplesPerSymbol) { + m_sampleIdx = 0; + } + + // FSK + if (m_settings.m_pulseShaping) + { + if (m_sampleIdx == 1) { + mod = m_pulseShape.filter(m_bit ? 1.0f : -1.0f); + } else { + mod = m_pulseShape.filter(0.0f); + } + } + else + { + mod = m_bit ? 1.0f : -1.0f; + } + + // FM + m_fmPhase += m_phaseSensitivity * mod * (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); + + // Display in spectrum analyser + sampleToSpectrum(m_modSample); + + Real s = std::real(m_modSample); + calculateLevel(s); + + // Send to demod analyser + m_demodBuffer[m_demodBufferFill] = mod * 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) +{ + if ((settings.m_baud != m_settings.m_baud) || force) + { + m_samplesPerSymbol = m_channelSampleRate / settings.m_baud; + qDebug() << "m_samplesPerSymbol: " << m_samplesPerSymbol << " (" << m_channelSampleRate << "/" << settings.m_baud << ")"; + } + + 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, settings.m_symbolSpan, m_channelSampleRate/settings.m_baud, true); + } + + 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; + + // 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, true); + } + + 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::addTXText(QString text) +{ + int count = m_settings.m_repeat ? m_settings.m_repeatCount : 1; + + for (int i = 0; i < count; i++) { + + QString s = text; + + if (m_settings.m_prefixCRLF) { + s.prepend("\r\r\n>"); // '>' switches to letters + } + if (m_settings.m_postfixCRLF) { + s.append("\r\r\n"); + } + + m_textToTransmit.append(s); + } +} + +void RttyModSource::encodeText(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; + + m_rttyEncoder.encode(s[i], bits, bitCount); + for (unsigned int j = 0; j < bitCount; j++) + { + int txBit = (bits >> j) & 1; + addBit(txBit); + } + } + + if (getMessageQueueToGUI()) + { + RttyMod::MsgReportTx* msg = RttyMod::MsgReportTx::create(s, m_textToTransmit.size()); + getMessageQueueToGUI()->push(msg); + } +} diff --git a/plugins/channeltx/modrtty/rttymodsource.h b/plugins/channeltx/modrtty/rttymodsource.h new file mode 100644 index 0000000000..82f5277722 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodsource.h @@ -0,0 +1,133 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 addTXText(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; + 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_specSampleBuffer; + static const int m_specSampleBufferSize = 256; + int m_specSampleBufferIndex; + Interpolator m_interpolator; // Interpolator to downsample to 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_textToTransmit; // Transmit 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; } + + void encodeText(const QString& data); + 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(Complex 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..07d63b0f16 --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodtxsettingsdialog.cpp @@ -0,0 +1,110 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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), + m_settings(settings), + ui(new Ui::RttyModTXSettingsDialog) +{ + 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->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_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..3d1aa32e3c --- /dev/null +++ b/plugins/channeltx/modrtty/rttymodtxsettingsdialog.ui @@ -0,0 +1,284 @@ + + + RttyModTXSettingsDialog + + + + 0 + 0 + 351 + 554 + + + + + Liberation Sans + 9 + + + + Transmit 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 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..c86197520d --- /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/plugins/feature/demodanalyzer/demodanalyzersettings.cpp b/plugins/feature/demodanalyzer/demodanalyzersettings.cpp index 2491287327..f7a21d5039 100644 --- a/plugins/feature/demodanalyzer/demodanalyzersettings.cpp +++ b/plugins/feature/demodanalyzer/demodanalyzersettings.cpp @@ -38,6 +38,7 @@ const QStringList DemodAnalyzerSettings::m_channelTypes = { QStringLiteral("PacketDemod"), QStringLiteral("PacketMod"), QStringLiteral("RadiosondeDemod"), + QStringLiteral("RTTYMod"), QStringLiteral("SSBDemod"), QStringLiteral("SSBMod"), QStringLiteral("WFMDemod"), @@ -60,6 +61,7 @@ const QStringList DemodAnalyzerSettings::m_channelURIs = { QStringLiteral("sdrangel.channel.packetdemod"), QStringLiteral("sdrangel.channeltx.modpacket"), QStringLiteral("sdrangel.channel.radiosondedemod"), + QStringLiteral("sdrangel.channeltx.modrtty"), QStringLiteral("sdrangel.channel.ssbdemod"), QStringLiteral("sdrangel.channeltx.modssb"), QStringLiteral("sdrangel.channel.wfmdemod"), diff --git a/sdrbase/CMakeLists.txt b/sdrbase/CMakeLists.txt index 1b7369a080..5b640f7bb3 100644 --- a/sdrbase/CMakeLists.txt +++ b/sdrbase/CMakeLists.txt @@ -259,6 +259,7 @@ set(sdrbase_SOURCES util/simpleserializer.cpp util/serialutil.cpp #util/spinlock.cpp + util/rtty.cpp util/uid.cpp util/units.cpp util/timeutil.cpp @@ -491,6 +492,7 @@ set(sdrbase_HEADERS util/profiler.h util/radiosonde.h util/rtpsink.h + util/rtty.h util/syncmessenger.h util/samplesourceserializer.h util/simpleserializer.h diff --git a/sdrbase/dsp/raisedcosine.h b/sdrbase/dsp/raisedcosine.h index 630ef2ebb2..6c74383947 100644 --- a/sdrbase/dsp/raisedcosine.h +++ b/sdrbase/dsp/raisedcosine.h @@ -40,7 +40,7 @@ template class RaisedCosine { void create(double beta, int symbolSpan, int samplesPerSymbol, bool normaliseUpsampledAmplitude = false) { int nTaps = symbolSpan * samplesPerSymbol + 1; - int i, j; + int i; // check constraints if(!(nTaps & 1)) { @@ -89,18 +89,38 @@ template class RaisedCosine { else { // Calculate maximum output of filter, assuming upsampled bipolar input E.g. [1 0 0 -1 0 0..] - // This doesn't necessarily include the centre tap, so we try each offset - double maxGain = 0.0; - for (i = 0; i < samplesPerSymbol; i++) + // This doesn't necessarily include the centre tap, as ISI there should be zero, + // it's often at the midpoint between two symbols. However, depending on beta, + // the input that produces the worst case can vary, so we currently try them all + double maxGain = 0; + for (int input = 0; input < (1 << symbolSpan); input++) { - double g = 0.0; - for (j = 0; j < (int)m_taps.size() - 1; j += samplesPerSymbol) - g += std::fabs(2.0 * m_taps[j]); - if ((i & 1) == 0) - g += std::fabs(m_taps[j]); - if (g > maxGain) - maxGain = g; + double maxV = 0; + for(int i = 0; i < nTaps; i++) { + m_samples[i] = 0; + } + for (int i = 0; i < symbolSpan; i++) + { + Type sym = (input >> i) & 1 ? 1 : -1; + for (int j = 0; j < samplesPerSymbol; j++) + { + Type out; + if (j == 1) { + out = filter(sym); + } else { + out = filter(0); + } + double outAbs = abs(out); + if (outAbs > maxV) { + maxV = outAbs; + } + } + } + if (maxV > maxGain) { + maxGain = maxV; + } } + // Scale up so maximum out is 1 for(i = 0; i < (int)m_taps.size(); i++) m_taps[i] /= maxGain; diff --git a/sdrbase/util/baudot.cpp b/sdrbase/util/baudot.cpp index f113192558..56e50b2409 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", "Я", + "\r", "Д", "Р", "Й", "Ч", "Ф", "Ц", "К", + "Т", "З", "Л", "В", "Х", "Ы", "П", "Я", "О", "Б", "Г", "<", "М", "Ь", "Ж", ">" }; -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,183 @@ 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_chars[LETTERS] = Baudot::m_ita2Letter; + m_chars[FIGURES] = Baudot::m_ita2Figure; + break; + case Baudot::UK: + m_chars[LETTERS] = Baudot::m_ukLetter; + m_chars[FIGURES] = Baudot::m_ukFigure; + break; + case Baudot::EUROPEAN: + m_chars[LETTERS] = Baudot::m_europeanLetter; + m_chars[FIGURES] = Baudot::m_europeanFigure; + break; + case Baudot::US: + m_chars[LETTERS] = Baudot::m_usLetter; + m_chars[FIGURES] = Baudot::m_usFigure; + break; + case Baudot::RUSSIAN: + m_chars[LETTERS] = Baudot::m_ita2Letter; + m_chars[FIGURES] = Baudot::m_russianFigure; + break; + case Baudot::MURRAY: + m_chars[LETTERS] = Baudot::m_murrayLetter; + m_chars[FIGURES] = Baudot::m_murrayFigure; + break; + default: + qDebug() << "BaudotEncoder::BaudotEncoder: Unsupported character set " << m_characterSet; + m_chars[LETTERS] = Baudot::m_ita2Letter; + m_chars[FIGURES] = Baudot::m_ita2Figure; + m_characterSet = Baudot::ITA2; + break; + } + m_chars[(int)CYRILLIC] = Baudot::m_russianLetter; +} + +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_page = LETTERS; +} + +bool BaudotEncoder::encode(QChar c, unsigned &bits, unsigned int &bitCount) +{ + bits = 0; + bitCount = 0; + + // Only upper case is supported + c = c.toUpper(); + QString s(c); + + if (s == '>') + { + addCode(bits, bitCount, m_chars[m_page].indexOf(s)); + m_page = LETTERS; + return true; + } + else if (s == '<') + { + addCode(bits, bitCount, m_chars[m_page].indexOf(s)); + m_page = FIGURES; + return true; + } + else if ((m_characterSet == Baudot::RUSSIAN) && (s == '\0')) + { + addCode(bits, bitCount, m_chars[m_page].indexOf(s)); + m_page = CYRILLIC; + return true; + } + + // We could create reverse look-up tables to speed this up, but it's only 200 baud... + + // Is character in current page? If so, use that, as it avoids switching + if (m_chars[m_page].contains(s)) + { + addCode(bits, bitCount, m_chars[m_page].indexOf(s)); + return true; + } + else + { + // Look for character in other pages + const QString switchPage[] = { ">", "<", "\0" }; + + for (int page = m_page == LETTERS ? 1 : 0; page < ((m_characterSet == Baudot::RUSSIAN) ? 3 : 2); page++) + { + if (m_chars[page].contains(s)) + { + // Switch to page + addCode(bits, bitCount, m_chars[m_page].indexOf(switchPage[page])); + m_page = (BaudotEncoder::Page)page; + + addCode(bits, bitCount, m_chars[m_page].indexOf(s)); + return true; + } + } + } + + return false; +} + +void BaudotEncoder::addCode(unsigned& bits, unsigned int& bitCount, unsigned int code) const +{ + const unsigned int codeLen = 5; + + addStartBits(bits, bitCount); + code = reverseBits(code, codeLen); + addBits(bits, bitCount, code, codeLen); + addStopBits(bits, bitCount); +} + +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..c276c791af 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,47 @@ 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 addCode(unsigned& bits, unsigned int& bitCount, unsigned int code) const; + 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_chars[3]; + enum Page { + LETTERS, + FIGURES, + CYRILLIC + } m_page; + bool m_msbFirst; + int m_startBits; + int m_stopBits; + +}; + #endif // INCLUDE_UTIL_BAUDOT_H diff --git a/sdrbase/util/rtty.cpp b/sdrbase/util/rtty.cpp new file mode 100644 index 0000000000..1cacf96f09 --- /dev/null +++ b/sdrbase/util/rtty.cpp @@ -0,0 +1,290 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 "util/rtty.h" + +// From http://www.ct2fzi.net/abreviations/abreviations.html +const QHash Rtty::m_acronyms = { + {"AA", "After All"}, + {"AB", "All Before"}, + {"ABT", "About"}, + {"ACK", "Acknowledgement"}, + {"ADEE", "Addressee"}, + {"ADR", "Address"}, + {"AF", "Audio Frequency"}, + {"AGN", "Again"}, + {"AM", "Amplitude Modulation"}, + {"AMU", "Antenna Matching Unit"}, + {"ANS", "Answer"}, + {"ANT", "Antenna"}, + {"ARQ", "Automatic Repeat Request"}, + {"ATU", "Antenna Tuning Unit"}, + {"B4", "Before"}, + {"BCN", "Beacon"}, + {"BCNU", "Be Seeing You"}, + {"BD", "Bad"}, + {"BK", "Break"}, + {"BN", "Been"}, + {"BTH", "Both"}, + {"BTR", "Better"}, + {"BTW", "By The Way"}, + {"BTU", "Back To You"}, + {"C", "Correct"}, + {"CBA", "Callbook Address"}, + {"CFM", "Confirm"}, + {"CK", "Check"}, + {"CKT", "Circuit"}, + {"CL", "Closing Down"}, + {"CLBK", "Callbook"}, + {"CLD", "Called"}, + {"CLG", "Calling"}, + {"CMG", "Coming"}, + {"CNT", "Can't"}, + {"COMP", "Computer"}, + {"CONDX", "Conditions"}, + {"COZ", "Because"}, + {"CPI", "Copy"}, + {"CQ", "General Call"}, + {"CRD", "Card"}, + {"CS", "Callsign"}, + {"CTCSS", "Continuous Tone Coded Squelch System"}, + {"CU", "See You"}, + {"CUAGN", "See You Again"}, + {"CUD", "Could"}, + {"CUL", "See You Later"}, + {"CUM", "Come"}, + {"CUZ", "Because"}, + {"CW", "Continuous Wave / Morse"}, + {"DA", "Day"}, + {"DE", "From"}, + {"DF", "Direction Finding"}, + {"DIFF", "Difference"}, + {"DLD", "Delivered"}, + {"DLVD", "Delivered"}, + {"DN", "Down"}, + {"DR", "Dear"}, + {"DSB", "Double Side Band"}, + {"DSP", "Digital Signal Processing"}, + {"DSW", "Goodbye (Russian)"}, + {"DWN", "Down"}, + {"DX", "Distance"}, + {"EL", "Element"}, + {"EME", "Earth-Moon-Earth"}, + {"ENUF", "Enough"}, + {"ES", "And"}, + {"EU", "Europe"}, + {"EVE", "Evening"}, + {"FB", "Fine Business"}, + {"FER", "For"}, + {"FIO", "For Information Only"}, + {"FM", "Frequency Modulation"}, + {"FQ", "Frequency"}, + {"FREQ", "Frequency"}, + {"FSD", "Full Scale Deflection"}, + {"FSK", "Frequency Shift Keying"}, + {"FWD", "Forward"}, + {"FWIW", "For What It's Worth"}, + {"FYI", "For Your Information"}, + {"GA", "Good Afternoon"}, + {"GB", "Good Bye"}, + {"GD", "Good Day"}, + {"GE", "Good Evening"}, + {"GESS", "Guess"}, + {"GG", "Going"}, + {"GLD", "Glad"}, + {"GM", "Good Morning"}, + {"GMT", "Greenwich Mean Time"}, + {"GN", "Good Night"}, + {"GND", "Ground"}, + {"GP", "Ground Plane"}, + {"GPS", "Global Positioning System"}, + {"GS", "Green Stamp"}, + {"GUD", "Good"}, + {"GV", "Give"}, + {"GVG", "Giving"}, + {"HAGD", "Have A Good Day"}, + {"HAGWE", "Have A Good Weekend"}, + {"HF", "High Frequency"}, + {"HI", "High"}, + {"HPE", "Hope"}, + {"HQ", "Headquarters"}, + {"HR", "Here / Hour"}, + {"HRD", "Heard"}, + {"HV", "Have"}, + {"HVG", "Having"}, + {"HVY", "Heavy"}, + {"HW", "How"}, + {"IMHO", "In My Humble Opinion"}, + {"IMI", "Say again"}, + {"K", "Over"}, + {"KN", "Over"}, + {"LF", "Low Frequency"}, + {"LNG", "Long"}, + {"LP", "Long Path"}, + {"LSB", "Lower Sideband"}, + {"LSN", "Listen"}, + {"LTR", "Later"}, + {"LV", "Leave"}, + {"LVG", "Leaving"}, + {"LW", "Long Wire"}, + {"MGR", "Manager"}, + {"MI", "My"}, + {"MNI", "Many"}, + {"MOM", "Moment"}, + {"MS", "Meteor Scatter"}, + {"MSG", "Message"}, + {"N", "No"}, + {"NCS", "Net Control Station"}, + {"ND", "Nothing Doing"}, + {"NM", "No More"}, + {"NR", "Near / Number"}, + {"NW", "Now"}, + {"OB", "Old Boy"}, + {"OC", "Old Chap"}, + {"OM", "Old Man"}, + {"OP", "Operator"}, + {"OPR", "Operator"}, + {"OT", "Old Timer"}, + {"OW", "Old Woman"}, + {"PA", "Power Amplifier"}, + {"PBL", "Preamble"}, + {"PKG", "Package"}, + {"POV", "Point Of View"}, + {"PSE", "Please"}, + {"PSK", "Phase Shift Keying"}, + {"PT", "Point"}, + {"PTT", "Push To Talk"}, + {"PWR", "Power"}, + {"PX", "Prefix"}, + {"QRA", "Address"}, + {"QRG", "Frequency"}, + {"QRK", "Readability"}, + {"QRL", "Busy"}, + {"QRM", "Interference"}, + {"QRN", "Noise"}, + {"QRO", "High Power"}, + {"QRP", "Low Power"}, + {"QRQ", "Send Faster"}, + {"QRS", "Send Slower"}, + {"QRSS", "Send Very Slowly"}, + {"QRT", "Stop Sending"}, + {"QRU", "Nothing Further To Say"}, + {"QRV", "Ready"}, + {"QRX", "Wait"}, + {"QRZ", "Who Is Calling Me"}, + {"QSA", "Signal Strength"}, + {"QSB", "Fading"}, + {"QSK", "Break-in"}, + {"QSL", "All Received OK"}, + {"QSLL", "I Will Send A QSL Card"}, + {"QSO", "Contact"}, + {"QSP", "Relay A Message"}, + {"QSX", "Listening On Frequency"}, + {"QSY", "Change Frequency"}, + {"QTH", "Location"}, + {"R", "Received OK"}, + {"RC", "Ragchew"}, + {"RCD", "Recieved"}, + {"RCVR", "Receiver"}, + {"RE", "Regarding"}, + {"REF", "Reference"}, + {"RF", "Radio Frequency"}, + {"RFI", "Radio Frequency Interference"}, + {"RPT", "Repeat / Report"}, + {"RST", "Signal Report"}, + {"RTTY", "Radio Teletype"}, + {"RX", "Receive"}, + {"SA", "Say"}, + {"SDR", "Software Defined Radio"}, + {"SEZ", "Says"}, + {"SGD", "Signed"}, + {"SHUD", "Should"}, + {"SIG", "Signal"}, + {"SK", "End Of Work"}, + {"SKED", "Schedule"}, + {"SN", "Soon"}, + {"SP", "Short Path"}, + {"SRI", "Sorry"}, + {"SSB", "Single Sideband"}, + {"STN", "Station"}, + {"SUM", "Some"}, + {"SVC", "Service"}, + {"SWR", "Standing Wave Ratio"}, + {"TFC", "Traffic"}, + {"TIA", "Thanks In Advance"}, + {"TKS", "Thanks"}, + {"TMW", "Tomorrow"}, + {"TNC", "Terminal Node Controller"}, + {"TNX", "Thanks"}, + {"TR", "Transmit"}, + {"T/R", "Transmit/Receive"}, + {"TRBL", "Trouble"}, + {"TRF", "Tuned Radio Frequency"}, + {"TRIX", "Tricks"}, + {"TRX", "Transceiver"}, + {"TT", "That"}, + {"TTS", "That Is"}, + {"TU", "Thank You"}, + {"TVI", "Television Interference"}, + {"TX", "Transmit"}, + {"TXT", "Text"}, + {"U", "You"}, + {"UHF", "Ultra High Frequency"}, + {"UNLIS", "Unlicensed"}, + {"UR", "Your"}, + {"URS", "Yours"}, + {"UTC", "Coordinated Universal Time"}, + {"V", "Volts"}, + {"VHF", "Very High Frequency"}, + {"VE", "Understood"}, + {"VERT", "Vertical"}, + {"VFB", "Very Fine Business"}, + {"VFO", "Variable Frequency Oscillator"}, + {"VLF", "Very Low Frequency"}, + {"VOX", "Voice Operated"}, + {"VSB", "Vestigial Sideband"}, + {"VSWR", "Voltage Standing Wave Ratio"}, + {"VY", "Very"}, + {"W", "Watts"}, + {"WA", "Word After"}, + {"WAT", "What"}, + {"WATSA", "What Say"}, + {"WB", "Word Before"}, + {"WD", "Word"}, + {"WDS", "Words"}, + {"WID", "With"}, + {"WKD", "Worked"}, + {"WKG", "Working"}, + {"WL", "Will"}, + {"WPM", "Words Per Minute"}, + {"WRD", "Word"}, + {"WRK", "Work"}, + {"WUD", "Would"}, + {"WX", "Weather"}, + {"XCVR", "Transceiver"}, + {"XMTR", "Transmitter"}, + {"XTAL", "Crystal"}, + {"YF", "Wife"}, + {"YL", "Young Lady"}, + {"YR", "Year"}, + {"Z", "Zulu Time"}, + {"30", "I Have Nothing More to Send"}, + {"33", "Fondest Regards"}, + {"55", "Best Success"}, + {"73", "Best Wishes"}, + {"88", "Love And Kisses"}, +}; diff --git a/sdrbase/util/rtty.h b/sdrbase/util/rtty.h new file mode 100644 index 0000000000..d0a40f9ccc --- /dev/null +++ b/sdrbase/util/rtty.h @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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_UTIL_RTTY_H +#define INCLUDE_UTIL_RTTY_H + +#include + +#include "export.h" + +class SDRBASE_API Rtty +{ +public: + static const QHash m_acronyms; +}; + +#endif /* INCLUDE_UTIL_RTTY_H */ diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index 4febce7137..7670da0099 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -4643,7 +4643,12 @@ bool WebAPIRequestMapper::getChannelSettings( { channelSettings->setRttyDemodSettings(new SWGSDRangel::SWGRTTYDemodSettings()); channelSettings->getRttyDemodSettings()->fromJsonObject(settingsJsonObject); - } + } + else if (channelSettingsKey == "RTTYModSettings") + { + channelSettings->setRttyModSettings(new SWGSDRangel::SWGRTTYModSettings()); + channelSettings->getRttyModSettings()->fromJsonObject(settingsJsonObject); + } else if (channelSettingsKey == "SigMFFileSinkSettings") { channelSettings->setSigMfFileSinkSettings(new SWGSDRangel::SWGSigMFFileSinkSettings()); @@ -4751,6 +4756,11 @@ bool WebAPIRequestMapper::getChannelActions( channelActions->setPacketModActions(new SWGSDRangel::SWGPacketModActions()); channelActions->getPacketModActions()->fromJsonObject(actionsJsonObject); } + else if (channelActionsKey == "RTTYModActions") + { + channelActions->setRttyModActions(new SWGSDRangel::SWGRTTYModActions()); + channelActions->getRttyModActions()->fromJsonObject(actionsJsonObject); + } else if (channelActionsKey == "SigMFFileSinkActions") { channelActions->setSigMfFileSinkActions(new SWGSDRangel::SWGSigMFFileSinkActions()); @@ -5432,6 +5442,7 @@ void WebAPIRequestMapper::resetChannelSettings(SWGSDRangel::SWGChannelSettings& channelSettings.setRemoteSourceSettings(nullptr); channelSettings.setRemoteTcpSinkSettings(nullptr); channelSettings.setRttyDemodSettings(nullptr); + channelSettings.setRttyModSettings(nullptr); channelSettings.setSsbDemodSettings(nullptr); channelSettings.setSsbModSettings(nullptr); channelSettings.setUdpSourceSettings(nullptr); @@ -5468,6 +5479,7 @@ void WebAPIRequestMapper::resetChannelReport(SWGSDRangel::SWGChannelReport& chan channelReport.setRadiosondeDemodReport(nullptr); channelReport.setRemoteSourceReport(nullptr); channelReport.setRttyDemodReport(nullptr); + channelReport.setRttyModReport(nullptr); channelReport.setSsbDemodReport(nullptr); channelReport.setSsbModReport(nullptr); channelReport.setUdpSourceReport(nullptr); @@ -5488,6 +5500,7 @@ void WebAPIRequestMapper::resetChannelActions(SWGSDRangel::SWGChannelActions& ch channelActions.setIeee802154ModActions(nullptr); channelActions.setRadioAstronomyActions(nullptr); channelActions.setPacketModActions(nullptr); + channelActions.setRttyModActions(nullptr); } void WebAPIRequestMapper::resetAudioInputDevice(SWGSDRangel::SWGAudioInputDevice& audioInputDevice) diff --git a/sdrbase/webapi/webapiutils.cpp b/sdrbase/webapi/webapiutils.cpp index 8860ec507e..e9fa38d31b 100644 --- a/sdrbase/webapi/webapiutils.cpp +++ b/sdrbase/webapi/webapiutils.cpp @@ -70,6 +70,7 @@ const QMap WebAPIUtils::m_channelURIToSettingsKey = { {"sdrangel.demod.remotetcpsink", "RemoteTCPSinkSettings"}, {"sdrangel.channeltx.remotesource", "RemoteSourceSettings"}, {"sdrangel.channel.rttydemod", "RTTYDemodSettings"}, + {"sdrangel.channel.rttymod", "RTTYModSettings"}, {"sdrangel.channeltx.modssb", "SSBModSettings"}, {"sdrangel.channel.ssbdemod", "SSBDemodSettings"}, {"sdrangel.channel.ft8demod", "FT8DemodSettings"}, @@ -185,7 +186,8 @@ const QMap WebAPIUtils::m_channelTypeToSettingsKey = { {"RemoteSink", "RemoteSinkSettings"}, {"RemoteSource", "RemoteSourceSettings"}, {"RemoteTCPSink", "RemoteTCPSinkSettings"}, - {"RTTYDemodSettings", "RTTYDemodSettings"}, + {"RTTYDemod", "RTTYDemodSettings"}, + {"RTTYMod", "RTTYModSettings"}, {"SSBMod", "SSBModSettings"}, {"SSBDemod", "SSBDemodSettings"}, {"FT8Demod", "FT8DemodSettings"}, @@ -208,7 +210,8 @@ const QMap WebAPIUtils::m_channelTypeToActionsKey = { {"SigMFFileSink", "SigMFFileSinkActions"}, {"IEEE_802_15_4_Mod", "IEEE_802_15_4_ModActions"}, {"RadioAstronomy", "RadioAstronomyActions"}, - {"PacketMod", "PacketModActions"} + {"PacketMod", "PacketModActions"}, + {"RTTYMod", "RTTYModActions"} }; const QMap WebAPIUtils::m_sourceDeviceHwIdToSettingsKey = { diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index d7ab6122fb..fd3c5caa01 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -7,6 +7,7 @@ set(CMAKE_AUTOUIC OFF) set(sdrgui_SOURCES mainwindow.cpp gui/aboutdialog.cpp + gui/acronymview.cpp gui/addpresetdialog.cpp gui/audiodialog.cpp gui/audioselectdialog.cpp @@ -127,6 +128,7 @@ set(sdrgui_HEADERS gui/aboutdialog.h gui/accessiblevaluedial.h gui/accessiblevaluedialz.h + gui/acronymview.h gui/addpresetdialog.h gui/audiodialog.h gui/audioselectdialog.h diff --git a/sdrgui/gui/acronymview.cpp b/sdrgui/gui/acronymview.cpp new file mode 100644 index 0000000000..295b6f7065 --- /dev/null +++ b/sdrgui/gui/acronymview.cpp @@ -0,0 +1,68 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 "acronymview.h" + +AcronymView::AcronymView(QWidget* parent) : + QPlainTextEdit(parent) +{ + setMouseTracking(true); + setReadOnly(true); +} + +bool AcronymView::event(QEvent* event) +{ + if (event->type() == QEvent::ToolTip) + { + QHelpEvent* helpEvent = static_cast(event); + QTextCursor cursor = cursorForPosition(helpEvent->pos()); + cursor.select(QTextCursor::WordUnderCursor); + QString text = cursor.selectedText(); + // Remove trailing digits from METAR + while (text.size() > 0 && text.right(1)[0].isDigit()) { + text = text.left(text.size() - 1); + } + if (!text.isEmpty() && m_acronym.contains(text)) + { + QToolTip::showText(helpEvent->globalPos(), QString("%1 - %2").arg(text).arg(m_acronym.value(text))); + } + else + { + if (!text.isEmpty()) { + qDebug() << "AcronymView::event: No tooltip for " << text; + } + QToolTip::hideText(); + } + return true; + } + return QPlainTextEdit::event(event); +} + +void AcronymView::addAcronym(const QString& acronym, const QString& explanation) +{ + m_acronym.insert(acronym, explanation); +} + +void AcronymView::addAcronyms(const QHash& acronyms) +{ + m_acronym.insert(acronyms); +} diff --git a/sdrgui/gui/acronymview.h b/sdrgui/gui/acronymview.h new file mode 100644 index 0000000000..1e2b5c57bf --- /dev/null +++ b/sdrgui/gui/acronymview.h @@ -0,0 +1,41 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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_GUI_ACRONYMVIEW_H +#define INCLUDE_GUI_ACRONYMVIEW_H + +#include +#include + +#include "export.h" + +// Displays text like a QPlainTextEdit, but adds tooltips for acronyms in the text +class SDRGUI_API AcronymView : public QPlainTextEdit { + Q_OBJECT + + QHash m_acronym; + +public: + + AcronymView(QWidget* parent = nullptr); + bool event(QEvent* event); + void addAcronym(const QString& acronym, const QString& explanation); + void addAcronyms(const QHash& acronyms); + +}; + +#endif // INCLUDE_GUI_ACRONYMVIEW_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..2cbf1feffd --- /dev/null +++ b/swagger/sdrangel/api/swagger/include/RTTYMod.yaml @@ -0,0 +1,113 @@ +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 + rfNoise: + type: integer + description: > + Boolean + * 0 - off + * 1 - on + text: + type: string + description: Text to transmit + pulseShaping: + type: integer + description: > + Boolean + * 0 - off + * 1 - on + beta: + type: number + format: float + symbolSpan: + type: integer + characterSet: + type: integer + unshiftOnSpace: + type: integer + msbFirst: + type: integer + spaceHigh: + type: integer + prefixCRLF: + type: integer + postfixCRLF: + 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: + text: + type: string diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 495206ba07..c35209233e 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,155 @@ } }, "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" : { + "text" : { + "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" + }, + "rfNoise" : { + "type" : "integer", + "description" : "Boolean\n * 0 - off\n * 1 - on\n" + }, + "text" : { + "type" : "string", + "description" : "Text to transmit" + }, + "pulseShaping" : { + "type" : "integer", + "description" : "Boolean\n * 0 - off\n * 1 - on\n" + }, + "beta" : { + "type" : "number", + "format" : "float" + }, + "symbolSpan" : { + "type" : "integer" + }, + "characterSet" : { + "type" : "integer" + }, + "unshiftOnSpace" : { + "type" : "integer" + }, + "msbFirst" : { + "type" : "integer" + }, + "spaceHigh" : { + "type" : "integer" + }, + "prefixCRLF" : { + "type" : "integer" + }, + "postfixCRLF" : { + "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 +14613,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 +14636,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 +14660,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 +14679,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 +14769,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 +14792,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 +14851,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 +14876,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 +14925,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 +14950,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 +15007,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 +22751,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