2016-10-02 07:18:07 -04:00
|
|
|
#include "../../channelrx/demodlora/lorademodgui.h"
|
|
|
|
#include "../../channelrx/demodlora/lorademodgui.h"
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
#include <dsp/downchannelizer.h>
|
2015-01-10 19:12:58 -05:00
|
|
|
#include <QDockWidget>
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include "ui_lorademodgui.h"
|
|
|
|
#include "ui_lorademodgui.h"
|
|
|
|
#include "dsp/threadedsamplesink.h"
|
|
|
|
#include "dsp/spectrumvis.h"
|
|
|
|
#include "gui/glspectrum.h"
|
|
|
|
#include "plugin/pluginapi.h"
|
2016-05-16 04:05:09 -04:00
|
|
|
#include "device/deviceapi.h"
|
2015-01-10 19:12:58 -05:00
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
#include "gui/basicchannelsettingswidget.h"
|
2015-08-17 02:29:34 -04:00
|
|
|
#include "dsp/dspengine.h"
|
2016-10-02 07:18:07 -04:00
|
|
|
#include "../../channelrx/demodlora/lorademod.h"
|
2015-01-10 19:12:58 -05:00
|
|
|
|
2016-05-16 13:37:53 -04:00
|
|
|
const QString LoRaDemodGUI::m_channelID = "de.maintech.sdrangelove.channel.lora";
|
|
|
|
|
2016-05-16 04:05:09 -04:00
|
|
|
LoRaDemodGUI* LoRaDemodGUI::create(PluginAPI* pluginAPI, DeviceAPI *deviceAPI)
|
2015-01-10 19:12:58 -05:00
|
|
|
{
|
2016-05-16 04:05:09 -04:00
|
|
|
LoRaDemodGUI* gui = new LoRaDemodGUI(pluginAPI, deviceAPI);
|
2015-01-10 19:12:58 -05:00
|
|
|
return gui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoRaDemodGUI::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoRaDemodGUI::setName(const QString& name)
|
|
|
|
{
|
|
|
|
setObjectName(name);
|
|
|
|
}
|
|
|
|
|
2015-06-06 21:30:28 -04:00
|
|
|
QString LoRaDemodGUI::getName() const
|
|
|
|
{
|
|
|
|
return objectName();
|
|
|
|
}
|
|
|
|
|
2015-07-18 20:07:40 -04:00
|
|
|
qint64 LoRaDemodGUI::getCenterFrequency() const {
|
2015-08-24 17:56:12 -04:00
|
|
|
return m_channelMarker.getCenterFrequency();
|
2015-07-18 20:07:40 -04:00
|
|
|
}
|
|
|
|
|
2015-09-28 21:35:14 -04:00
|
|
|
void LoRaDemodGUI::setCenterFrequency(qint64 centerFrequency)
|
|
|
|
{
|
|
|
|
m_channelMarker.setCenterFrequency(centerFrequency);
|
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
2015-01-10 19:12:58 -05:00
|
|
|
void LoRaDemodGUI::resetToDefaults()
|
|
|
|
{
|
2015-08-18 19:02:52 -04:00
|
|
|
blockApplySettings(true);
|
2016-05-11 12:29:01 -04:00
|
|
|
|
2015-01-10 19:12:58 -05:00
|
|
|
ui->BW->setValue(0);
|
2015-01-12 09:25:16 -05:00
|
|
|
ui->Spread->setValue(0);
|
2016-05-11 12:29:01 -04:00
|
|
|
|
2015-08-18 19:02:52 -04:00
|
|
|
blockApplySettings(false);
|
2015-01-10 19:12:58 -05:00
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray LoRaDemodGUI::serialize() const
|
|
|
|
{
|
|
|
|
SimpleSerializer s(1);
|
2015-08-24 17:56:12 -04:00
|
|
|
s.writeS32(1, m_channelMarker.getCenterFrequency());
|
2015-01-10 19:12:58 -05:00
|
|
|
s.writeS32(2, ui->BW->value());
|
2015-01-12 09:25:16 -05:00
|
|
|
s.writeS32(3, ui->Spread->value());
|
|
|
|
s.writeBlob(4, ui->spectrumGUI->serialize());
|
2015-01-10 19:12:58 -05:00
|
|
|
return s.final();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoRaDemodGUI::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
SimpleDeserializer d(data);
|
|
|
|
|
2016-05-11 12:29:01 -04:00
|
|
|
if(!d.isValid())
|
2015-08-18 19:02:52 -04:00
|
|
|
{
|
2015-01-10 19:12:58 -05:00
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-11 12:29:01 -04:00
|
|
|
if(d.getVersion() == 1)
|
2015-08-18 19:02:52 -04:00
|
|
|
{
|
2015-01-10 19:12:58 -05:00
|
|
|
QByteArray bytetmp;
|
|
|
|
qint32 tmp;
|
2016-05-11 12:29:01 -04:00
|
|
|
|
2015-08-18 19:02:52 -04:00
|
|
|
blockApplySettings(true);
|
2015-08-24 17:56:12 -04:00
|
|
|
m_channelMarker.blockSignals(true);
|
2016-05-11 12:29:01 -04:00
|
|
|
|
2015-01-10 19:12:58 -05:00
|
|
|
d.readS32(1, &tmp, 0);
|
2015-08-24 17:56:12 -04:00
|
|
|
m_channelMarker.setCenterFrequency(tmp);
|
2015-01-10 19:12:58 -05:00
|
|
|
d.readS32(2, &tmp, 0);
|
|
|
|
ui->BW->setValue(tmp);
|
2015-01-12 09:25:16 -05:00
|
|
|
d.readS32(3, &tmp, 0);
|
|
|
|
ui->Spread->setValue(tmp);
|
|
|
|
d.readBlob(4, &bytetmp);
|
2015-01-10 19:12:58 -05:00
|
|
|
ui->spectrumGUI->deserialize(bytetmp);
|
2016-05-11 12:29:01 -04:00
|
|
|
|
2015-08-18 19:02:52 -04:00
|
|
|
blockApplySettings(false);
|
2015-08-24 17:56:12 -04:00
|
|
|
m_channelMarker.blockSignals(false);
|
2016-05-11 12:29:01 -04:00
|
|
|
|
2015-01-10 19:12:58 -05:00
|
|
|
applySettings();
|
|
|
|
return true;
|
2016-05-11 12:29:01 -04:00
|
|
|
}
|
|
|
|
else
|
2015-08-18 19:02:52 -04:00
|
|
|
{
|
2015-01-10 19:12:58 -05:00
|
|
|
resetToDefaults();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool LoRaDemodGUI::handleMessage(const Message& message)
|
2015-01-10 19:12:58 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoRaDemodGUI::viewChanged()
|
|
|
|
{
|
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoRaDemodGUI::on_BW_valueChanged(int value)
|
|
|
|
{
|
2015-02-20 03:45:57 -05:00
|
|
|
const int loraBW[] = BANDWIDTHSTRING;
|
2015-01-12 09:25:16 -05:00
|
|
|
int thisBW = loraBW[value];
|
|
|
|
ui->BWText->setText(QString("%1 Hz").arg(thisBW));
|
2015-08-24 17:56:12 -04:00
|
|
|
m_channelMarker.setBandwidth(thisBW);
|
2015-01-10 19:12:58 -05:00
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
2015-01-12 09:25:16 -05:00
|
|
|
void LoRaDemodGUI::on_Spread_valueChanged(int value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-10 19:12:58 -05:00
|
|
|
void LoRaDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if((widget == ui->spectrumContainer) && (m_LoRaDemod != NULL))
|
|
|
|
m_LoRaDemod->setSpectrum(m_threadedSampleSink->getMessageQueue(), rollDown);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoRaDemodGUI::onMenuDoubleClicked()
|
|
|
|
{
|
|
|
|
if(!m_basicSettingsShown) {
|
|
|
|
m_basicSettingsShown = true;
|
2015-08-24 17:56:12 -04:00
|
|
|
BasicChannelSettingsWidget* bcsw = new BasicChannelSettingsWidget(&m_channelMarker, this);
|
2015-01-10 19:12:58 -05:00
|
|
|
bcsw->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 04:05:09 -04:00
|
|
|
LoRaDemodGUI::LoRaDemodGUI(PluginAPI* pluginAPI, DeviceAPI *deviceAPI, QWidget* parent) :
|
2015-01-10 19:12:58 -05:00
|
|
|
RollupWidget(parent),
|
|
|
|
ui(new Ui::LoRaDemodGUI),
|
|
|
|
m_pluginAPI(pluginAPI),
|
2016-05-16 04:05:09 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
2015-08-24 17:56:12 -04:00
|
|
|
m_channelMarker(this),
|
2015-08-18 19:02:52 -04:00
|
|
|
m_basicSettingsShown(false),
|
|
|
|
m_doApplySettings(true)
|
2015-01-10 19:12:58 -05:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
|
|
|
|
connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));
|
|
|
|
|
|
|
|
m_spectrumVis = new SpectrumVis(ui->glSpectrum);
|
|
|
|
m_LoRaDemod = new LoRaDemod(m_spectrumVis);
|
2016-10-02 15:52:39 -04:00
|
|
|
m_channelizer = new DownChannelizer(m_LoRaDemod);
|
2015-08-21 02:54:28 -04:00
|
|
|
m_threadedChannelizer = new ThreadedSampleSink(m_channelizer);
|
2016-05-16 04:05:09 -04:00
|
|
|
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
2015-01-10 19:12:58 -05:00
|
|
|
|
2015-01-12 09:25:16 -05:00
|
|
|
ui->glSpectrum->setCenterFrequency(16000);
|
|
|
|
ui->glSpectrum->setSampleRate(32000);
|
2015-01-10 19:12:58 -05:00
|
|
|
ui->glSpectrum->setDisplayWaterfall(true);
|
|
|
|
ui->glSpectrum->setDisplayMaxHold(true);
|
|
|
|
|
2015-01-13 14:14:36 -05:00
|
|
|
setTitleColor(Qt::magenta);
|
|
|
|
|
2015-08-24 17:56:12 -04:00
|
|
|
//m_channelMarker = new ChannelMarker(this);
|
|
|
|
m_channelMarker.setColor(Qt::magenta);
|
|
|
|
m_channelMarker.setBandwidth(7813);
|
|
|
|
m_channelMarker.setCenterFrequency(0);
|
|
|
|
m_channelMarker.setVisible(true);
|
2016-05-16 13:37:53 -04:00
|
|
|
|
2015-08-24 17:56:12 -04:00
|
|
|
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged()));
|
2016-05-16 13:37:53 -04:00
|
|
|
|
|
|
|
m_deviceAPI->registerChannelInstance(m_channelID, this);
|
2016-05-16 04:05:09 -04:00
|
|
|
m_deviceAPI->addChannelMarker(&m_channelMarker);
|
|
|
|
m_deviceAPI->addRollupWidget(this);
|
2015-01-10 19:12:58 -05:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
ui->spectrumGUI->setBuddies(m_channelizer->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
|
2015-01-10 19:12:58 -05:00
|
|
|
|
|
|
|
applySettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
LoRaDemodGUI::~LoRaDemodGUI()
|
|
|
|
{
|
2016-05-16 13:37:53 -04:00
|
|
|
m_deviceAPI->removeChannelInstance(this);
|
2016-05-16 04:05:09 -04:00
|
|
|
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
2015-08-21 02:54:28 -04:00
|
|
|
delete m_threadedChannelizer;
|
2015-01-10 19:12:58 -05:00
|
|
|
delete m_channelizer;
|
|
|
|
delete m_LoRaDemod;
|
|
|
|
delete m_spectrumVis;
|
2015-08-24 17:56:12 -04:00
|
|
|
//delete m_channelMarker;
|
2015-01-10 19:12:58 -05:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2015-08-18 19:02:52 -04:00
|
|
|
void LoRaDemodGUI::blockApplySettings(bool block)
|
|
|
|
{
|
|
|
|
m_doApplySettings = !block;
|
|
|
|
}
|
|
|
|
|
2015-01-10 19:12:58 -05:00
|
|
|
void LoRaDemodGUI::applySettings()
|
|
|
|
{
|
2015-08-23 22:09:36 -04:00
|
|
|
if (m_doApplySettings)
|
|
|
|
{
|
|
|
|
const int loraBW[] = BANDWIDTHSTRING;
|
|
|
|
int thisBW = loraBW[ui->BW->value()];
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2015-08-23 22:09:36 -04:00
|
|
|
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
|
|
|
thisBW,
|
2015-08-24 17:56:12 -04:00
|
|
|
m_channelMarker.getCenterFrequency());
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2015-08-23 22:09:36 -04:00
|
|
|
m_LoRaDemod->configure(m_LoRaDemod->getInputMessageQueue(), thisBW);
|
|
|
|
}
|
2015-01-10 19:12:58 -05:00
|
|
|
}
|