1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-11-10 08:10:25 -05:00
sdrangel/plugins/channelrx/demodchirpchat/chirpchatdemodgui.cpp

786 lines
26 KiB
C++
Raw Normal View History

2020-02-08 18:21:38 +01:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019-2020 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "device/deviceuiset.h"
#include <QScrollBar>
#include <QDebug>
2020-04-19 06:12:50 +02:00
#include <QDateTime>
2020-03-03 21:52:46 +01:00
#include "ui_chirpchatdemodgui.h"
2015-01-11 00:12:58 +00:00
#include "dsp/spectrumvis.h"
2020-02-08 18:21:38 +01:00
#include "dsp/dspengine.h"
#include "dsp/dspcommands.h"
2015-01-11 00:12:58 +00:00
#include "gui/glspectrum.h"
2020-02-08 18:21:38 +01:00
#include "gui/glspectrumgui.h"
2020-02-25 23:41:07 +01:00
#include "gui/basicchannelsettingsdialog.h"
#include "gui/devicestreamselectiondialog.h"
2015-01-11 00:12:58 +00:00
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
2020-02-23 16:33:21 +01:00
#include "util/db.h"
#include "mainwindow.h"
2017-10-08 00:28:42 +02:00
2020-03-03 21:52:46 +01:00
#include "chirpchatdemod.h"
#include "chirpchatdemodgui.h"
2015-01-11 00:12:58 +00:00
2020-03-03 21:52:46 +01:00
ChirpChatDemodGUI* ChirpChatDemodGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel)
2015-01-11 00:12:58 +00:00
{
2020-03-03 21:52:46 +01:00
ChirpChatDemodGUI* gui = new ChirpChatDemodGUI(pluginAPI, deviceUISet, rxChannel);
2015-01-11 00:12:58 +00:00
return gui;
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::destroy()
2015-01-11 00:12:58 +00:00
{
delete this;
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::setName(const QString& name)
2015-01-11 00:12:58 +00:00
{
setObjectName(name);
}
2020-03-03 21:52:46 +01:00
QString ChirpChatDemodGUI::getName() const
{
return objectName();
}
2020-03-03 21:52:46 +01:00
qint64 ChirpChatDemodGUI::getCenterFrequency() const {
return m_channelMarker.getCenterFrequency();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::setCenterFrequency(qint64 centerFrequency)
{
m_channelMarker.setCenterFrequency(centerFrequency);
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::resetToDefaults()
2015-01-11 00:12:58 +00:00
{
2017-10-08 00:28:42 +02:00
m_settings.resetToDefaults();
displaySettings();
applySettings(true);
2015-01-11 00:12:58 +00:00
}
2020-03-03 21:52:46 +01:00
QByteArray ChirpChatDemodGUI::serialize() const
2015-01-11 00:12:58 +00:00
{
2017-10-08 00:28:42 +02:00
return m_settings.serialize();
2015-01-11 00:12:58 +00:00
}
2020-03-03 21:52:46 +01:00
bool ChirpChatDemodGUI::deserialize(const QByteArray& data)
2015-01-11 00:12:58 +00:00
{
2020-02-19 09:26:42 +01:00
resetLoRaStatus();
2020-02-08 18:21:38 +01:00
if (m_settings.deserialize(data))
{
2017-10-08 00:28:42 +02:00
displaySettings();
applySettings(true);
return true;
2020-02-08 18:21:38 +01:00
}
else
{
2017-10-08 00:28:42 +02:00
resetToDefaults();
return false;
}
2015-01-11 00:12:58 +00:00
}
2020-03-03 21:52:46 +01:00
bool ChirpChatDemodGUI::handleMessage(const Message& message)
2015-01-11 00:12:58 +00:00
{
2020-02-08 18:21:38 +01:00
if (DSPSignalNotification::match(message))
{
DSPSignalNotification& notif = (DSPSignalNotification&) message;
int basebandSampleRate = notif.getSampleRate();
2020-03-03 21:52:46 +01:00
qDebug() << "ChirpChatDemodGUI::handleMessage: DSPSignalNotification: m_basebandSampleRate: " << basebandSampleRate;
2020-02-08 18:21:38 +01:00
if (basebandSampleRate != m_basebandSampleRate)
{
m_basebandSampleRate = basebandSampleRate;
setBandwidths();
}
return true;
}
2020-03-03 21:52:46 +01:00
else if (ChirpChatDemod::MsgReportDecodeBytes::match(message))
{
2020-03-03 21:52:46 +01:00
if (m_settings.m_codingScheme == ChirpChatDemodSettings::CodingLoRa) {
showLoRaMessage(message);
2020-02-19 09:26:42 +01:00
}
return true;
}
2020-03-03 21:52:46 +01:00
else if (ChirpChatDemod::MsgReportDecodeString::match(message))
{
2020-03-03 21:52:46 +01:00
if ((m_settings.m_codingScheme == ChirpChatDemodSettings::CodingASCII)
|| (m_settings.m_codingScheme == ChirpChatDemodSettings::CodingTTY)) {
showTextMessage(message);
}
2020-02-19 09:26:42 +01:00
return true;
}
2020-03-03 21:52:46 +01:00
else if (ChirpChatDemod::MsgConfigureChirpChatDemod::match(message))
2020-02-25 23:41:07 +01:00
{
2020-03-03 21:52:46 +01:00
qDebug("ChirpChatDemodGUI::handleMessage: NFMDemod::MsgConfigureChirpChatDemod");
const ChirpChatDemod::MsgConfigureChirpChatDemod& cfg = (ChirpChatDemod::MsgConfigureChirpChatDemod&) message;
2020-02-25 23:41:07 +01:00
m_settings = cfg.getSettings();
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
return true;
}
2020-02-08 18:21:38 +01:00
else
{
return false;
}
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::handleInputMessages()
2020-02-08 18:21:38 +01:00
{
Message* message;
while ((message = getInputMessageQueue()->pop()) != 0)
{
if (handleMessage(*message)) {
delete message;
}
}
2015-01-11 00:12:58 +00:00
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::channelMarkerChangedByCursor()
2015-01-11 00:12:58 +00:00
{
2020-02-08 18:21:38 +01:00
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency();
2015-01-11 00:12:58 +00:00
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_deltaFrequency_changed(qint64 value)
2020-02-08 18:21:38 +01:00
{
m_channelMarker.setCenterFrequency(value);
m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency();
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::channelMarkerHighlightedByCursor()
2020-02-08 18:21:38 +01:00
{
setHighlighted(m_channelMarker.getHighlighted());
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_BW_valueChanged(int value)
2015-01-11 00:12:58 +00:00
{
2017-10-08 00:28:42 +02:00
if (value < 0) {
m_settings.m_bandwidthIndex = 0;
2020-03-03 21:52:46 +01:00
} else if (value < ChirpChatDemodSettings::nbBandwidths) {
2017-10-08 00:28:42 +02:00
m_settings.m_bandwidthIndex = value;
} else {
2020-03-03 21:52:46 +01:00
m_settings.m_bandwidthIndex = ChirpChatDemodSettings::nbBandwidths - 1;
2017-10-08 00:28:42 +02:00
}
2020-03-03 21:52:46 +01:00
int thisBW = ChirpChatDemodSettings::bandwidths[value];
2015-01-12 14:25:16 +00:00
ui->BWText->setText(QString("%1 Hz").arg(thisBW));
m_channelMarker.setBandwidth(thisBW);
2020-02-08 18:21:38 +01:00
ui->glSpectrum->setSampleRate(thisBW);
ui->glSpectrum->setCenterFrequency(thisBW/2);
2017-10-08 00:28:42 +02:00
2015-01-11 00:12:58 +00:00
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_Spread_valueChanged(int value)
2015-01-12 14:25:16 +00:00
{
2020-01-30 18:26:43 +01:00
m_settings.m_spreadFactor = value;
ui->SpreadText->setText(tr("%1").arg(value));
2020-02-08 18:21:38 +01:00
ui->spectrumGUI->setFFTSize(m_settings.m_spreadFactor);
2020-01-30 18:26:43 +01:00
applySettings();
2015-01-12 14:25:16 +00:00
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_deBits_valueChanged(int value)
2020-02-08 18:21:38 +01:00
{
m_settings.m_deBits = value;
ui->deBitsText->setText(tr("%1").arg(m_settings.m_deBits));
applySettings();
}
void ChirpChatDemodGUI::on_fftWindow_currentIndexChanged(int index)
{
m_settings.m_fftWindow = (FFTWindow::Function) index;
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_preambleChirps_valueChanged(int value)
2020-02-19 09:26:42 +01:00
{
m_settings.m_preambleChirps = value;
ui->preambleChirpsText->setText(tr("%1").arg(m_settings.m_preambleChirps));
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_scheme_currentIndexChanged(int index)
{
2020-03-03 21:52:46 +01:00
m_settings.m_codingScheme = (ChirpChatDemodSettings::CodingScheme) index;
2020-02-19 09:26:42 +01:00
2020-03-03 21:52:46 +01:00
if (m_settings.m_codingScheme != ChirpChatDemodSettings::CodingLoRa) {
2020-02-19 09:26:42 +01:00
resetLoRaStatus();
}
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_mute_toggled(bool checked)
{
m_settings.m_decodeActive = !checked;
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_clear_clicked(bool checked)
{
(void) checked;
ui->messageText->clear();
ui->messageText->clear();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_eomSquelch_valueChanged(int value)
{
m_settings.m_eomSquelchTenths = value;
displaySquelch();
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_messageLength_valueChanged(int value)
{
m_settings.m_nbSymbolsMax = value;
ui->messageLengthText->setText(tr("%1").arg(m_settings.m_nbSymbolsMax));
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_messageLengthAuto_stateChanged(int state)
2020-02-25 23:41:07 +01:00
{
m_settings.m_autoNbSymbolsMax = (state == Qt::Checked);
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_header_stateChanged(int state)
2020-02-19 09:26:42 +01:00
{
m_settings.m_hasHeader = (state == Qt::Checked);
if (!m_settings.m_hasHeader) // put back values from settings
{
ui->fecParity->blockSignals(true);
ui->crc->blockSignals(true);
ui->fecParity->setValue(m_settings.m_nbParityBits);
ui->fecParityText->setText(tr("%1").arg(m_settings.m_nbParityBits));
ui->crc->setChecked(m_settings.m_hasCRC);
ui->fecParity->blockSignals(false);
ui->crc->blockSignals(false);
}
ui->fecParity->setEnabled(state != Qt::Checked);
ui->crc->setEnabled(state != Qt::Checked);
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_fecParity_valueChanged(int value)
2020-02-19 09:26:42 +01:00
{
m_settings.m_nbParityBits = value;
ui->fecParityText->setText(tr("%1").arg(m_settings.m_nbParityBits));
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_crc_stateChanged(int state)
2020-02-19 09:26:42 +01:00
{
m_settings.m_hasCRC = (state == Qt::Checked);
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_packetLength_valueChanged(int value)
2020-02-19 09:26:42 +01:00
{
m_settings.m_packetLength = value;
ui->packetLengthText->setText(tr("%1").arg(m_settings.m_packetLength));
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_udpSend_stateChanged(int state)
{
m_settings.m_sendViaUDP = (state == Qt::Checked);
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_udpAddress_editingFinished()
{
m_settings.m_udpAddress = ui->udpAddress->text();
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::on_udpPort_editingFinished()
{
bool ok;
quint16 udpPort = ui->udpPort->text().toInt(&ok);
if((!ok) || (udpPort < 1024)) {
udpPort = 9998;
}
ui->udpPort->setText(tr("%1").arg(m_settings.m_udpPort));
m_settings.m_udpPort = udpPort;
applySettings();
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown)
2015-01-11 00:12:58 +00:00
{
(void) widget;
(void) rollDown;
2015-01-11 00:12:58 +00:00
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::onMenuDialogCalled(const QPoint &p)
2020-02-25 23:41:07 +01:00
{
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.move(p);
dialog.exec();
m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency();
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);
setTitleColor(m_settings.m_rgbColor);
applySettings();
}
else if ((m_contextMenuType == ContextMenuStreamSettings) && (m_deviceUISet->m_deviceMIMOEngine))
{
DeviceStreamSelectionDialog dialog(this);
2020-03-03 21:52:46 +01:00
dialog.setNumberOfStreams(m_chirpChatDemod->getNumberOfDeviceStreams());
2020-02-25 23:41:07 +01:00
dialog.setStreamIndex(m_settings.m_streamIndex);
dialog.move(p);
dialog.exec();
m_settings.m_streamIndex = dialog.getSelectedStreamIndex();
m_channelMarker.clearStreamIndexes();
m_channelMarker.addStreamIndex(m_settings.m_streamIndex);
displayStreamIndex();
applySettings();
}
resetContextMenuType();
}
2020-03-03 21:52:46 +01:00
ChirpChatDemodGUI::ChirpChatDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent) :
2015-01-11 00:12:58 +00:00
RollupWidget(parent),
2020-03-03 21:52:46 +01:00
ui(new Ui::ChirpChatDemodGUI),
2015-01-11 00:12:58 +00:00
m_pluginAPI(pluginAPI),
m_deviceUISet(deviceUISet),
m_channelMarker(this),
2020-02-08 18:21:38 +01:00
m_basebandSampleRate(250000),
m_doApplySettings(true),
m_tickCount(0)
2015-01-11 00:12:58 +00:00
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true);
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
2020-02-25 23:41:07 +01:00
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
2015-01-11 00:12:58 +00:00
m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF, ui->glSpectrum);
2020-03-03 21:52:46 +01:00
m_chirpChatDemod = (ChirpChatDemod*) rxChannel;
m_chirpChatDemod->setSpectrumSink(m_spectrumVis);
m_chirpChatDemod->setMessageQueueToGUI(getInputMessageQueue());
2015-01-11 00:12:58 +00:00
connect(&MainWindow::getInstance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick()));
ui->glSpectrum->setDisplayWaterfall(true);
2015-01-11 00:12:58 +00:00
ui->glSpectrum->setDisplayMaxHold(true);
2020-02-08 18:21:38 +01:00
ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03)));
ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999);
ui->messageText->setReadOnly(true);
ui->messageText->setReadOnly(true);
2020-02-08 18:21:38 +01:00
m_channelMarker.setMovable(true);
m_channelMarker.setVisible(true);
2020-02-08 18:21:38 +01:00
connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor()));
connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor()));
2020-03-03 21:52:46 +01:00
m_deviceUISet->registerRxChannelInstance(ChirpChatDemod::m_channelIdURI, this);
m_deviceUISet->addChannelMarker(&m_channelMarker);
m_deviceUISet->addRollupWidget(this);
2015-01-11 00:12:58 +00:00
2017-10-08 01:42:18 +02:00
ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
2015-01-11 00:12:58 +00:00
2017-10-08 01:42:18 +02:00
m_settings.setChannelMarker(&m_channelMarker);
m_settings.setSpectrumGUI(ui->spectrumGUI);
2020-02-08 18:21:38 +01:00
connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
setBandwidths();
2017-10-08 01:42:18 +02:00
displaySettings();
2020-02-19 09:26:42 +01:00
resetLoRaStatus();
2017-10-08 01:42:18 +02:00
applySettings(true);
2015-01-11 00:12:58 +00:00
}
2020-03-03 21:52:46 +01:00
ChirpChatDemodGUI::~ChirpChatDemodGUI()
2015-01-11 00:12:58 +00:00
{
m_deviceUISet->removeRxChannelInstance(this);
2020-03-03 21:52:46 +01:00
delete m_chirpChatDemod; // TODO: check this: when the GUI closes it has to delete the demodulator
2015-01-11 00:12:58 +00:00
delete m_spectrumVis;
delete ui;
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::blockApplySettings(bool block)
{
m_doApplySettings = !block;
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::applySettings(bool force)
2015-01-11 00:12:58 +00:00
{
if (m_doApplySettings)
{
2017-10-08 01:42:18 +02:00
setTitleColor(m_channelMarker.getColor());
2020-03-03 21:52:46 +01:00
ChirpChatDemod::MsgConfigureChirpChatDemod* message = ChirpChatDemod::MsgConfigureChirpChatDemod::create( m_settings, force);
m_chirpChatDemod->getInputMessageQueue()->push(message);
}
2015-01-11 00:12:58 +00:00
}
2017-10-08 00:28:42 +02:00
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::displaySettings()
2017-10-08 00:28:42 +02:00
{
2020-03-03 21:52:46 +01:00
int thisBW = ChirpChatDemodSettings::bandwidths[m_settings.m_bandwidthIndex];
2017-10-08 01:42:18 +02:00
m_channelMarker.blockSignals(true);
2020-02-08 18:21:38 +01:00
m_channelMarker.setTitle(m_settings.m_title);
m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset);
2017-10-08 01:42:18 +02:00
m_channelMarker.setBandwidth(thisBW);
2020-02-08 18:21:38 +01:00
m_channelMarker.blockSignals(false);
2017-10-08 01:42:18 +02:00
m_channelMarker.setColor(m_settings.m_rgbColor);
setTitleColor(m_settings.m_rgbColor);
2020-02-08 18:21:38 +01:00
ui->glSpectrum->setSampleRate(thisBW);
ui->glSpectrum->setCenterFrequency(thisBW/2);
2017-10-12 01:21:30 +02:00
2020-02-19 09:26:42 +01:00
ui->fecParity->setEnabled(!m_settings.m_hasHeader);
ui->crc->setEnabled(!m_settings.m_hasHeader);
ui->packetLength->setEnabled(!m_settings.m_hasHeader);
2017-10-12 01:21:30 +02:00
blockApplySettings(true);
2020-02-08 18:21:38 +01:00
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
2017-10-12 01:21:30 +02:00
ui->BWText->setText(QString("%1 Hz").arg(thisBW));
ui->BW->setValue(m_settings.m_bandwidthIndex);
2020-02-08 18:21:38 +01:00
ui->Spread->setValue(m_settings.m_spreadFactor);
2020-01-30 18:26:43 +01:00
ui->SpreadText->setText(tr("%1").arg(m_settings.m_spreadFactor));
2020-02-08 18:21:38 +01:00
ui->deBits->setValue(m_settings.m_deBits);
ui->fftWindow->setCurrentIndex((int) m_settings.m_fftWindow);
2020-02-08 18:21:38 +01:00
ui->deBitsText->setText(tr("%1").arg(m_settings.m_deBits));
2020-02-19 09:26:42 +01:00
ui->preambleChirps->setValue(m_settings.m_preambleChirps);
ui->preambleChirpsText->setText(tr("%1").arg(m_settings.m_preambleChirps));
ui->scheme->setCurrentIndex((int) m_settings.m_codingScheme);
ui->messageLengthText->setText(tr("%1").arg(m_settings.m_nbSymbolsMax));
ui->messageLength->setValue(m_settings.m_nbSymbolsMax);
ui->udpSend->setChecked(m_settings.m_sendViaUDP);
ui->udpAddress->setText(m_settings.m_udpAddress);
ui->udpPort->setText(tr("%1").arg(m_settings.m_udpPort));
2020-02-19 09:26:42 +01:00
ui->header->setChecked(m_settings.m_hasHeader);
if (!m_settings.m_hasHeader)
{
ui->fecParity->setValue(m_settings.m_nbParityBits);
ui->fecParityText->setText(tr("%1").arg(m_settings.m_nbParityBits));
ui->crc->setChecked(m_settings.m_hasCRC);
ui->packetLength->setValue(m_settings.m_packetLength);
ui->spectrumGUI->setFFTSize(m_settings.m_spreadFactor);
}
2020-02-25 23:41:07 +01:00
ui->messageLengthAuto->setChecked(m_settings.m_autoNbSymbolsMax);
displaySquelch();
2020-02-19 09:26:42 +01:00
2017-10-12 01:21:30 +02:00
blockApplySettings(false);
2017-10-08 00:28:42 +02:00
}
2020-02-08 18:21:38 +01:00
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::displayStreamIndex()
2020-02-25 23:41:07 +01:00
{
if (m_deviceUISet->m_deviceMIMOEngine) {
setStreamIndicator(tr("%1").arg(m_settings.m_streamIndex));
} else {
setStreamIndicator("S"); // single channel indicator
}
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::displaySquelch()
{
ui->eomSquelch->setValue(m_settings.m_eomSquelchTenths);
if (m_settings.m_eomSquelchTenths == ui->eomSquelch->maximum()) {
ui->eomSquelchText->setText("---");
} else {
ui->eomSquelchText->setText(tr("%1").arg(m_settings.m_eomSquelchTenths / 10.0, 0, 'f', 1));
}
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::displayLoRaStatus(int headerParityStatus, bool headerCRCStatus, int payloadParityStatus, bool payloadCRCStatus)
2020-02-19 09:26:42 +01:00
{
if (m_settings.m_hasHeader && (headerParityStatus == (int) ParityOK)) {
2020-02-19 09:26:42 +01:00
ui->headerHammingStatus->setStyleSheet("QLabel { background-color : green; }");
} else if (m_settings.m_hasHeader && (headerParityStatus == (int) ParityError)) {
2020-02-19 09:26:42 +01:00
ui->headerHammingStatus->setStyleSheet("QLabel { background-color : red; }");
} else if (m_settings.m_hasHeader && (headerParityStatus == (int) ParityCorrected)) {
ui->headerHammingStatus->setStyleSheet("QLabel { background-color : blue; }");
2020-02-19 09:26:42 +01:00
} else {
ui->headerHammingStatus->setStyleSheet("QLabel { background:rgb(79,79,79); }");
}
if (m_settings.m_hasHeader && headerCRCStatus) {
ui->headerCRCStatus->setStyleSheet("QLabel { background-color : green; }");
} else if (m_settings.m_hasHeader && !headerCRCStatus) {
ui->headerCRCStatus->setStyleSheet("QLabel { background-color : red; }");
} else {
ui->headerCRCStatus->setStyleSheet("QLabel { background:rgb(79,79,79); }");
}
if (payloadParityStatus == (int) ParityOK) {
2020-02-19 09:26:42 +01:00
ui->payloadFECStatus->setStyleSheet("QLabel { background-color : green; }");
} else if (payloadParityStatus == (int) ParityError) {
2020-02-19 09:26:42 +01:00
ui->payloadFECStatus->setStyleSheet("QLabel { background-color : red; }");
} else if (payloadParityStatus == (int) ParityCorrected) {
ui->payloadFECStatus->setStyleSheet("QLabel { background-color : blue; }");
} else {
ui->payloadFECStatus->setStyleSheet("QLabel { background:rgb(79,79,79); }");
2020-02-19 09:26:42 +01:00
}
if (payloadCRCStatus) {
ui->payloadCRCStatus->setStyleSheet("QLabel { background-color : green; }");
} else {
ui->payloadCRCStatus->setStyleSheet("QLabel { background-color : red; }");
}
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::resetLoRaStatus()
2020-02-19 09:26:42 +01:00
{
ui->headerHammingStatus->setStyleSheet("QLabel { background:rgb(79,79,79); }");
ui->headerCRCStatus->setStyleSheet("QLabel { background:rgb(79,79,79); }");
ui->payloadFECStatus->setStyleSheet("QLabel { background:rgb(79,79,79); }");
ui->payloadCRCStatus->setStyleSheet("QLabel { background:rgb(79,79,79); }");
ui->nbSymbolsText->setText("---");
ui->nbCodewordsText->setText("---");
2020-02-19 09:26:42 +01:00
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::setBandwidths()
2020-02-08 18:21:38 +01:00
{
2020-03-03 21:52:46 +01:00
int maxBandwidth = m_basebandSampleRate/ChirpChatDemodSettings::oversampling;
2020-02-08 18:21:38 +01:00
int maxIndex = 0;
2020-03-03 21:52:46 +01:00
for (; (maxIndex < ChirpChatDemodSettings::nbBandwidths) && (ChirpChatDemodSettings::bandwidths[maxIndex] <= maxBandwidth); maxIndex++)
2020-02-08 18:21:38 +01:00
{}
if (maxIndex != 0)
{
2020-03-03 21:52:46 +01:00
qDebug("ChirpChatDemodGUI::setBandwidths: avl: %d max: %d", maxBandwidth, ChirpChatDemodSettings::bandwidths[maxIndex-1]);
2020-02-08 18:21:38 +01:00
ui->BW->setMaximum(maxIndex - 1);
int index = ui->BW->value();
2020-03-03 21:52:46 +01:00
ui->BWText->setText(QString("%1 Hz").arg(ChirpChatDemodSettings::bandwidths[index]));
2020-02-08 18:21:38 +01:00
}
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::showLoRaMessage(const Message& message)
{
2020-03-03 21:52:46 +01:00
const ChirpChatDemod::MsgReportDecodeBytes& msg = (ChirpChatDemod::MsgReportDecodeBytes&) message;
QByteArray bytes = msg.getBytes();
2020-02-23 16:33:21 +01:00
QString syncWordStr((tr("%1").arg(msg.getSyncWord(), 2, 16, QChar('0'))));
ui->sText->setText(tr("%1").arg(msg.getSingalDb(), 0, 'f', 1));
ui->snrText->setText(tr("%1").arg(msg.getSingalDb() - msg.getNoiseDb(), 0, 'f', 1));
unsigned int packetLength;
if (m_settings.m_hasHeader)
{
ui->fecParity->setValue(msg.getNbParityBits());
ui->fecParityText->setText(tr("%1").arg(msg.getNbParityBits()));
ui->crc->setChecked(msg.getHasCRC());
ui->packetLength->setValue(msg.getPacketSize());
ui->packetLengthText->setText(tr("%1").arg(msg.getPacketSize()));
packetLength = msg.getPacketSize();
}
else
{
packetLength = m_settings.m_packetLength;
}
QDateTime dt = QDateTime::currentDateTime();
QString dateStr = dt.toString("HH:mm:ss");
if (msg.getEarlyEOM())
{
QString loRaStatus = tr("%1 %2 S:%3 SN:%4 HF:%5 HC:%6 EOM:too early")
.arg(dateStr)
2020-02-23 16:33:21 +01:00
.arg(syncWordStr)
.arg(msg.getSingalDb(), 0, 'f', 1)
.arg(msg.getSingalDb() - msg.getNoiseDb(), 0, 'f', 1)
.arg(getParityStr(msg.getHeaderParityStatus()))
.arg(msg.getHeaderCRCStatus() ? "ok" : "err");
displayStatus(loRaStatus);
displayLoRaStatus(msg.getHeaderParityStatus(), msg.getHeaderCRCStatus(), (int) ParityUndefined, true);
ui->payloadCRCStatus->setStyleSheet("QLabel { background:rgb(79,79,79); }"); // reset payload CRC
}
else
{
QString loRaHeader = tr("%1 %2 S:%3 SN:%4 HF:%5 HC:%6 FEC:%7 CRC:%8")
.arg(dateStr)
2020-02-23 16:33:21 +01:00
.arg(syncWordStr)
.arg(msg.getSingalDb(), 0, 'f', 1)
.arg(msg.getSingalDb() - msg.getNoiseDb(), 0, 'f', 1)
.arg(getParityStr(msg.getHeaderParityStatus()))
.arg(msg.getHeaderCRCStatus() ? "ok" : "err")
.arg(getParityStr(msg.getPayloadParityStatus()))
.arg(msg.getPayloadCRCStatus() ? "ok" : "err");
displayStatus(loRaHeader);
displayBytes(bytes);
QByteArray bytesCopy(bytes);
bytesCopy.truncate(packetLength);
bytesCopy.replace('\0', " ");
QString str = QString(bytesCopy.toStdString().c_str());
2020-02-23 16:33:21 +01:00
QString textHeader(tr("%1 (%2)").arg(dateStr).arg(syncWordStr));
displayText(str);
displayLoRaStatus(msg.getHeaderParityStatus(), msg.getHeaderCRCStatus(), msg.getPayloadParityStatus(), msg.getPayloadCRCStatus());
}
ui->nbSymbolsText->setText(tr("%1").arg(msg.getNbSymbols()));
ui->nbCodewordsText->setText(tr("%1").arg(msg.getNbCodewords()));
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::showTextMessage(const Message& message)
{
2020-03-03 21:52:46 +01:00
const ChirpChatDemod::MsgReportDecodeString& msg = (ChirpChatDemod::MsgReportDecodeString&) message;
QDateTime dt = QDateTime::currentDateTime();
QString dateStr = dt.toString("HH:mm:ss");
ui->sText->setText(tr("%1").arg(msg.getSingalDb(), 0, 'f', 1));
ui->snrText->setText(tr("%1").arg(msg.getSingalDb() - msg.getNoiseDb(), 0, 'f', 1));
QString status = tr("%1 S:%2 SN:%3")
.arg(dateStr)
.arg(msg.getSingalDb(), 0, 'f', 1)
.arg(msg.getSingalDb() - msg.getNoiseDb(), 0, 'f', 1);
displayStatus(status);
displayText(msg.getString());
}
void ChirpChatDemodGUI::displayText(const QString& text)
{
QTextCursor cursor = ui->messageText->textCursor();
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
if (!ui->messageText->document()->isEmpty()) {
cursor.insertText("\n");
}
cursor.insertText(tr("TXT|%1").arg(text));
ui->messageText->verticalScrollBar()->setValue(ui->messageText->verticalScrollBar()->maximum());
}
void ChirpChatDemodGUI::displayBytes(const QByteArray& bytes)
2020-02-19 09:26:42 +01:00
{
QTextCursor cursor = ui->messageText->textCursor();
2020-02-19 09:26:42 +01:00
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
if (!ui->messageText->document()->isEmpty()) {
2020-02-19 09:26:42 +01:00
cursor.insertText("\n");
}
QByteArray::const_iterator it = bytes.begin();
unsigned int i = 0;
for (;it != bytes.end(); ++it, i++)
{
unsigned char b = *it;
if (i%16 == 0) {
cursor.insertText(tr("%1|").arg(i, 3, 10, QChar('0')));
}
2020-02-23 16:33:21 +01:00
cursor.insertText(tr("%1").arg(b, 2, 16, QChar('0')));
2020-02-19 09:26:42 +01:00
if (i%16 == 15) {
cursor.insertText("\n");
} else if (i%4 == 3) {
cursor.insertText("|");
} else {
cursor.insertText(" ");
}
}
ui->messageText->verticalScrollBar()->setValue(ui->messageText->verticalScrollBar()->maximum());
2020-02-19 09:26:42 +01:00
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::displayStatus(const QString& status)
{
QTextCursor cursor = ui->messageText->textCursor();
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
if (!ui->messageText->document()->isEmpty()) {
cursor.insertText("\n");
}
cursor.insertText(tr(">%1").arg(status));
ui->messageText->verticalScrollBar()->setValue(ui->messageText->verticalScrollBar()->maximum());
}
2020-03-03 21:52:46 +01:00
QString ChirpChatDemodGUI::getParityStr(int parityStatus)
{
if (parityStatus == (int) ParityError) {
return "err";
} else if (parityStatus == (int) ParityCorrected) {
return "fix";
} else if (parityStatus == (int) ParityOK) {
return "ok";
} else {
return "n/a";
}
}
2020-03-03 21:52:46 +01:00
void ChirpChatDemodGUI::tick()
{
if (m_tickCount < 10)
{
m_tickCount++;
}
else
{
m_tickCount = 0;
2020-03-03 21:52:46 +01:00
ui->nText->setText(tr("%1").arg(CalcDb::dbPower(m_chirpChatDemod->getCurrentNoiseLevel()), 0, 'f', 1));
ui->channelPower->setText(tr("%1 dB").arg(CalcDb::dbPower(m_chirpChatDemod->getTotalPower()), 0, 'f', 1));
2020-02-23 16:33:21 +01:00
2020-03-03 21:52:46 +01:00
if (m_chirpChatDemod->getDemodActive()) {
ui->mute->setStyleSheet("QToolButton { background-color : green; }");
} else {
ui->mute->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
}
}
}
2020-02-19 09:26:42 +01:00