From 4178abe24b84f3cd91385d600c41dbe37cc60ec0 Mon Sep 17 00:00:00 2001 From: srcejon Date: Fri, 17 Nov 2023 13:41:35 +0000 Subject: [PATCH 1/4] Fix M17 packet type decoding. --- plugins/channelrx/demodm17/m17demodgui.ui | 2 +- plugins/channelrx/demodm17/m17demodprocessor.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/channelrx/demodm17/m17demodgui.ui b/plugins/channelrx/demodm17/m17demodgui.ui index cb47bcac06..6f1c551cb2 100644 --- a/plugins/channelrx/demodm17/m17demodgui.ui +++ b/plugins/channelrx/demodm17/m17demodgui.ui @@ -921,7 +921,7 @@ - Baud rate: 2.4k: NXDN48, dPMR 4.8k: DMR, D-Star, YSF, NXDN96 + Baud rate diff --git a/plugins/channelrx/demodm17/m17demodprocessor.cpp b/plugins/channelrx/demodm17/m17demodprocessor.cpp index 39731c27c4..2f6d42e16c 100644 --- a/plugins/channelrx/demodm17/m17demodprocessor.cpp +++ b/plugins/channelrx/demodm17/m17demodprocessor.cpp @@ -195,9 +195,9 @@ bool M17DemodProcessor::decode_lsf(modemm17::M17FrameDecoder::lsf_buffer_t const m_currentPacket.clear(); m_packetFrameCounter = 0; - if (!lsf[111]) // LSF type bit 0 + if (!(lsf[13] & 1)) // LSF type bit 0 { - uint8_t packet_type = (lsf[109] << 1) | lsf[110]; + uint8_t packet_type = (lsf[13] >> 1) & 0x3; switch (packet_type) { @@ -254,7 +254,7 @@ void M17DemodProcessor::decode_type(uint16_t type) m_typeInfo += "DAT"; break; case 2: - m_typeInfo += "UNK"; + m_typeInfo += "ENC"; // Encapsulated passes LSF up stack along with data break; case 3: m_typeInfo += "UNK"; From 66351cff306cace0ef8b8f999af4933a47b2d20a Mon Sep 17 00:00:00 2001 From: srcejon Date: Fri, 17 Nov 2023 14:17:52 +0000 Subject: [PATCH 2/4] Fix loss of constellation when device restarted in M17 demod. --- plugins/channelrx/demodm17/m17demod.cpp | 12 +++++++++++- plugins/channelrx/demodm17/m17demod.h | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/channelrx/demodm17/m17demod.cpp b/plugins/channelrx/demodm17/m17demod.cpp index 28bc1397ef..2b893b9baf 100644 --- a/plugins/channelrx/demodm17/m17demod.cpp +++ b/plugins/channelrx/demodm17/m17demod.cpp @@ -57,7 +57,8 @@ M17Demod::M17Demod(DeviceAPI *deviceAPI) : m_thread(nullptr), m_basebandSink(nullptr), m_running(false), - m_basebandSampleRate(0) + m_basebandSampleRate(0), + m_scopeXYSink(nullptr) { qDebug("M17Demod::M17Demod"); setObjectName(m_channelId); @@ -141,6 +142,7 @@ void M17Demod::start() if (m_basebandSampleRate != 0) { m_basebandSink->setBasebandSampleRate(m_basebandSampleRate); } + m_basebandSink->setScopeXYSink(m_scopeXYSink); m_basebandSink->reset(); m_thread->start(); @@ -751,3 +753,11 @@ void M17Demod::handleIndexInDeviceSetChanged(int index) m_basebandSink->setFifoLabel(fifoLabel); m_basebandSink->setAudioFifoLabel(fifoLabel); } + +void M17Demod::setScopeXYSink(BasebandSampleSink* sampleSink) +{ + m_scopeXYSink = sampleSink; + if (m_running) { + m_basebandSink->setScopeXYSink(sampleSink); + } +} diff --git a/plugins/channelrx/demodm17/m17demod.h b/plugins/channelrx/demodm17/m17demod.h index 80fe33f79d..553e67046b 100644 --- a/plugins/channelrx/demodm17/m17demod.h +++ b/plugins/channelrx/demodm17/m17demod.h @@ -209,7 +209,7 @@ class M17Demod : public BasebandSampleSink, public ChannelAPI { SWGSDRangel::SWGChannelSettings& response); uint32_t getNumberOfDeviceStreams() const; - void setScopeXYSink(BasebandSampleSink* sampleSink) { if (m_running) { m_basebandSink->setScopeXYSink(sampleSink); } } + void setScopeXYSink(BasebandSampleSink* sampleSink); void configureMyPosition(float myLatitude, float myLongitude) { if (m_running) { m_basebandSink->configureMyPosition(myLatitude, myLongitude); } } double getMagSq() { return m_running ? m_basebandSink->getMagSq() : 0.0; } bool getSquelchOpen() const { return m_running && m_basebandSink->getSquelchOpen(); } @@ -281,7 +281,7 @@ class M17Demod : public BasebandSampleSink, public ChannelAPI { bool m_running; M17DemodSettings m_settings; int m_basebandSampleRate; //!< stored from device message used when starting baseband sink - + BasebandSampleSink *m_scopeXYSink; QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; From c7436c946f387c08ad9b1fe1a6cebd61642a86dd Mon Sep 17 00:00:00 2001 From: srcejon Date: Fri, 17 Nov 2023 16:44:47 +0000 Subject: [PATCH 3/4] Fix M17 FM frequency deviation to work at +/-2.4kHz. --- plugins/channelrx/demodm17/m17demodsettings.cpp | 2 +- plugins/channelrx/demodm17/m17demodsink.cpp | 2 +- plugins/channeltx/modm17/m17modgui.cpp | 6 +++--- plugins/channeltx/modm17/m17modsettings.cpp | 4 ++-- plugins/channeltx/modm17/m17modsource.cpp | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/channelrx/demodm17/m17demodsettings.cpp b/plugins/channelrx/demodm17/m17demodsettings.cpp index a71a4fbe37..f729bde9a9 100644 --- a/plugins/channelrx/demodm17/m17demodsettings.cpp +++ b/plugins/channelrx/demodm17/m17demodsettings.cpp @@ -34,7 +34,7 @@ void M17DemodSettings::resetToDefaults() { m_inputFrequencyOffset = 0; m_rfBandwidth = 12500.0; - m_fmDeviation = 3500.0; + m_fmDeviation = 2400.0; m_volume = 2.0; m_baudRate = 4800; m_squelchGate = 5; // 10s of ms at 48000 Hz sample rate. Corresponds to 2400 for AGC attack diff --git a/plugins/channelrx/demodm17/m17demodsink.cpp b/plugins/channelrx/demodm17/m17demodsink.cpp index 8031f563fa..ae650c059a 100644 --- a/plugins/channelrx/demodm17/m17demodsink.cpp +++ b/plugins/channelrx/demodm17/m17demodsink.cpp @@ -334,7 +334,7 @@ void M17DemodSink::applySettings(const M17DemodSettings& settings, const QListfmDevText->setText(QString("%1%2k").arg(QChar(0xB1, 0x00)).arg(value / 10.0, 0, 'f', 1)); - m_settings.m_fmDeviation = value * 200.0; + m_settings.m_fmDeviation = value * 100.0; applySettings(QList{"fmDeviation"}); } @@ -570,8 +570,8 @@ void M17ModGUI::displaySettings() ui->rfBWText->setText(QString("%1k").arg(m_settings.m_rfBandwidth / 1000.0, 0, 'f', 1)); ui->rfBW->setValue(m_settings.m_rfBandwidth / 100.0); - ui->fmDevText->setText(QString("%1%2k").arg(QChar(0xB1, 0x00)).arg(m_settings.m_fmDeviation / 2000.0, 0, 'f', 1)); - ui->fmDev->setValue(m_settings.m_fmDeviation / 200.0); + ui->fmDevText->setText(QString("%1%2k").arg(QChar(0xB1, 0x00)).arg(m_settings.m_fmDeviation / 1000.0, 0, 'f', 1)); + ui->fmDev->setValue(m_settings.m_fmDeviation / 100.0); ui->volumeText->setText(QString("%1").arg(m_settings.m_volumeFactor, 0, 'f', 1)); ui->volume->setValue(m_settings.m_volumeFactor * 10.0); diff --git a/plugins/channeltx/modm17/m17modsettings.cpp b/plugins/channeltx/modm17/m17modsettings.cpp index c150a2c81d..ba58a521ae 100644 --- a/plugins/channeltx/modm17/m17modsettings.cpp +++ b/plugins/channeltx/modm17/m17modsettings.cpp @@ -35,7 +35,7 @@ void M17ModSettings::resetToDefaults() { m_inputFrequencyOffset = 0; m_rfBandwidth = 16000.0f; - m_fmDeviation = 10000.0f; //!< full deviation + m_fmDeviation = 2400.0; //!< peak deviation m_toneFrequency = 1000.0f; m_volumeFactor = 1.0f; m_channelMute = false; @@ -146,7 +146,7 @@ bool M17ModSettings::deserialize(const QByteArray& data) d.readS32(1, &tmp, 0); m_inputFrequencyOffset = tmp; d.readReal(2, &m_rfBandwidth, 12500.0); - d.readReal(4, &m_fmDeviation, 10000.0); + d.readReal(4, &m_fmDeviation, 2400.0); d.readU32(5, &m_rgbColor); d.readReal(6, &m_toneFrequency, 1000.0); d.readReal(7, &m_volumeFactor, 1.0); diff --git a/plugins/channeltx/modm17/m17modsource.cpp b/plugins/channeltx/modm17/m17modsource.cpp index 9901bd2096..7a76d4e2b5 100644 --- a/plugins/channeltx/modm17/m17modsource.cpp +++ b/plugins/channeltx/modm17/m17modsource.cpp @@ -177,7 +177,7 @@ void M17ModSource::modulateSample() calculateLevel(t); t1 = m_lowpass.filter(t) * 1.5f; - m_modPhasor += (m_settings.m_fmDeviation / (float) m_audioSampleRate) * t1; + m_modPhasor += ((2.0f * M_PI * m_settings.m_fmDeviation) / (float) m_audioSampleRate) * t1; // limit phasor range to ]-pi,pi] if (m_modPhasor > M_PI) { From 698cc3cb63adf3ea140ea6160bf1f121418f457c Mon Sep 17 00:00:00 2001 From: srcejon Date: Fri, 17 Nov 2023 17:39:57 +0000 Subject: [PATCH 4/4] Prevent demod from crashing when GUI is destroyed. --- plugins/channelrx/demodm17/m17demodgui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/channelrx/demodm17/m17demodgui.cpp b/plugins/channelrx/demodm17/m17demodgui.cpp index 44f01fc24a..abfec65992 100644 --- a/plugins/channelrx/demodm17/m17demodgui.cpp +++ b/plugins/channelrx/demodm17/m17demodgui.cpp @@ -520,6 +520,7 @@ M17DemodGUI::M17DemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseban M17DemodGUI::~M17DemodGUI() { + m_m17Demod->setScopeXYSink(nullptr); delete m_scopeVisXY; ui->screenTV->setParent(nullptr); // Prefer memory leak to core dump... ~TVScreen() is buggy delete ui;