sdrangel/plugins/channelrx/demodlora/lorademod.cpp

152 lines
4.9 KiB
C++
Raw Normal View History

2015-01-10 19:12:58 -05:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
// written by Christian Daniel //
// (c) 2015 John Greb
// //
// 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 //
2019-04-11 00:39:30 -04:00
// (at your option) any later version. //
2015-01-10 19:12:58 -05:00
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
2019-12-03 12:49:52 -05:00
#include <stdio.h>
2015-01-10 19:12:58 -05:00
#include <QTime>
2015-08-17 02:29:34 -04:00
#include <QDebug>
2019-12-03 12:49:52 -05:00
#include <QThread>
2017-10-07 19:42:18 -04:00
#include "dsp/dspcommands.h"
2019-05-08 16:11:53 -04:00
#include "device/deviceapi.h"
2017-10-07 19:42:18 -04:00
#include "lorademod.h"
2015-01-15 05:57:05 -05:00
2015-01-10 19:12:58 -05:00
MESSAGE_CLASS_DEFINITION(LoRaDemod::MsgConfigureLoRaDemod, Message)
2018-05-30 14:22:35 -04:00
const QString LoRaDemod::m_channelIdURI = "sdrangel.channel.lorademod";
const QString LoRaDemod::m_channelId = "LoRaDemod";
2019-05-08 16:11:53 -04:00
LoRaDemod::LoRaDemod(DeviceAPI* deviceAPI) :
2019-05-09 11:27:12 -04:00
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
2020-05-15 17:12:46 -04:00
m_deviceAPI(deviceAPI),
m_spectrumVis(SDR_RX_SCALEF)
2015-01-10 19:12:58 -05:00
{
setObjectName(m_channelId);
2019-12-03 12:49:52 -05:00
m_thread = new QThread(this);
m_basebandSink = new LoRaDemodBaseband();
2020-05-15 17:12:46 -04:00
m_basebandSink->setSpectrumSink(&m_spectrumVis);
2019-12-03 12:49:52 -05:00
m_basebandSink->moveToThread(m_thread);
2015-01-15 05:57:05 -05:00
2019-12-03 12:49:52 -05:00
applySettings(m_settings, true);
2019-12-03 12:49:52 -05:00
m_deviceAPI->addChannelSink(this);
2019-05-08 16:11:53 -04:00
m_deviceAPI->addChannelSinkAPI(this);
2015-01-10 19:12:58 -05:00
}
LoRaDemod::~LoRaDemod()
{
2019-12-03 12:49:52 -05:00
m_deviceAPI->removeChannelSinkAPI(this);
m_deviceAPI->removeChannelSink(this);
delete m_basebandSink;
delete m_thread;
2015-01-22 17:30:55 -05:00
}
2015-01-13 19:48:48 -05:00
2015-01-12 14:59:45 -05:00
void LoRaDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO)
2015-01-10 19:12:58 -05:00
{
(void) pO;
2019-12-03 12:49:52 -05:00
m_basebandSink->feed(begin, end);
2015-01-10 19:12:58 -05:00
}
void LoRaDemod::start()
{
2019-12-03 12:49:52 -05:00
qDebug() << "LoRaDemod::start";
if (m_basebandSampleRate != 0) {
m_basebandSink->setBasebandSampleRate(m_basebandSampleRate);
}
m_basebandSink->reset();
m_thread->start();
2015-01-10 19:12:58 -05:00
}
void LoRaDemod::stop()
{
2019-12-03 12:49:52 -05:00
qDebug() << "LoRaDemod::stop";
m_thread->exit();
m_thread->wait();
2015-01-10 19:12:58 -05:00
}
2015-08-17 02:29:34 -04:00
bool LoRaDemod::handleMessage(const Message& cmd)
2015-01-10 19:12:58 -05:00
{
2019-12-03 12:49:52 -05:00
if (MsgConfigureLoRaDemod::match(cmd))
2015-08-17 02:29:34 -04:00
{
2019-12-03 12:49:52 -05:00
qDebug() << "LoRaDemod::handleMessage: MsgConfigureLoRaDemod";
2015-08-17 02:29:34 -04:00
MsgConfigureLoRaDemod& cfg = (MsgConfigureLoRaDemod&) cmd;
2017-10-07 19:42:18 -04:00
LoRaDemodSettings settings = cfg.getSettings();
2019-12-03 12:49:52 -05:00
applySettings(settings, cfg.getForce());
2015-08-17 02:29:34 -04:00
2015-01-10 19:12:58 -05:00
return true;
2015-08-17 02:29:34 -04:00
}
else if (DSPSignalNotification::match(cmd))
{
2019-12-03 12:49:52 -05:00
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
m_basebandSampleRate = notif.getSampleRate();
// Forward to the sink
DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
qDebug() << "LoRaDemod::handleMessage: DSPSignalNotification";
m_basebandSink->getInputMessageQueue()->push(rep);
return true;
}
2015-08-17 02:29:34 -04:00
else
{
2019-12-03 12:49:52 -05:00
return false;
2015-01-10 19:12:58 -05:00
}
}
2017-12-17 17:15:42 -05:00
QByteArray LoRaDemod::serialize() const
{
return m_settings.serialize();
}
bool LoRaDemod::deserialize(const QByteArray& data)
{
if (m_settings.deserialize(data))
{
MsgConfigureLoRaDemod *msg = MsgConfigureLoRaDemod::create(m_settings, true);
m_inputMessageQueue.push(msg);
return true;
}
else
{
m_settings.resetToDefaults();
MsgConfigureLoRaDemod *msg = MsgConfigureLoRaDemod::create(m_settings, true);
m_inputMessageQueue.push(msg);
return false;
}
}
2019-12-03 12:49:52 -05:00
void LoRaDemod::applySettings(const LoRaDemodSettings& settings, bool force)
{
qDebug() << "LoRaDemod::applySettings:"
<< " m_centerFrequency: " << settings.m_centerFrequency
<< " m_bandwidthIndex: " << settings.m_bandwidthIndex
<< " m_spread: " << settings.m_spread
<< " m_rgbColor: " << settings.m_rgbColor
<< " m_title: " << settings.m_title
<< " force: " << force;
LoRaDemodBaseband::MsgConfigureLoRaDemodBaseband *msg = LoRaDemodBaseband::MsgConfigureLoRaDemodBaseband::create(settings, force);
m_basebandSink->getInputMessageQueue()->push(msg);
m_settings = settings;
}