2018-08-19 18:38:33 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 Edouard Griffiths, F4EXB. //
|
|
|
|
// //
|
|
|
|
// SDRdaemon source channel (Tx) //
|
|
|
|
// //
|
|
|
|
// SDRdaemon is a detached SDR front end that handles the interface with a //
|
|
|
|
// physical device and sends or receives the I/Q samples stream to or from a //
|
|
|
|
// SDRangel instance via UDP. It is controlled via a Web REST API. //
|
|
|
|
// //
|
|
|
|
// 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 //
|
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-23 16:45:43 -04:00
|
|
|
#include <QDebug>
|
|
|
|
|
2018-08-19 18:38:33 -04:00
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
#include "dsp/threadedbasebandsamplesource.h"
|
|
|
|
#include "dsp/upchannelizer.h"
|
|
|
|
#include "device/devicesinkapi.h"
|
|
|
|
#include "sdrdaemonchannelsource.h"
|
2018-08-26 11:22:22 -04:00
|
|
|
#include "channel/sdrdaemonchannelsourcethread.h"
|
|
|
|
#include "channel/sdrdaemondatablock.h"
|
2018-08-19 18:38:33 -04:00
|
|
|
|
2018-08-23 16:45:43 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(SDRDaemonChannelSource::MsgConfigureSDRDaemonChannelSource, Message)
|
|
|
|
|
2018-08-19 18:38:33 -04:00
|
|
|
const QString SDRDaemonChannelSource::m_channelIdURI = "sdrangel.channel.sdrdaemonsource";
|
|
|
|
const QString SDRDaemonChannelSource::m_channelId = "SDRDaemonChannelSource";
|
|
|
|
|
|
|
|
SDRDaemonChannelSource::SDRDaemonChannelSource(DeviceSinkAPI *deviceAPI) :
|
|
|
|
ChannelSourceAPI(m_channelIdURI),
|
|
|
|
m_deviceAPI(deviceAPI),
|
2018-08-26 11:22:22 -04:00
|
|
|
m_sourceThread(0),
|
2018-08-19 18:38:33 -04:00
|
|
|
m_running(false),
|
2018-08-23 16:45:43 -04:00
|
|
|
m_samplesCount(0),
|
|
|
|
m_dataAddress("127.0.0.1"),
|
|
|
|
m_dataPort(9090)
|
2018-08-19 18:38:33 -04:00
|
|
|
{
|
|
|
|
setObjectName(m_channelId);
|
|
|
|
|
|
|
|
m_channelizer = new UpChannelizer(this);
|
|
|
|
m_threadedChannelizer = new ThreadedBasebandSampleSource(m_channelizer, this);
|
|
|
|
m_deviceAPI->addThreadedSource(m_threadedChannelizer);
|
|
|
|
m_deviceAPI->addChannelAPI(this);
|
2018-08-26 11:22:22 -04:00
|
|
|
|
|
|
|
connect(&m_dataQueue, SIGNAL(dataBlockEnqueued()), this, SLOT(handleData()), Qt::QueuedConnection);
|
|
|
|
m_cm256p = m_cm256.isInitialized() ? &m_cm256 : 0;
|
2018-08-19 18:38:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SDRDaemonChannelSource::~SDRDaemonChannelSource()
|
|
|
|
{
|
|
|
|
m_deviceAPI->removeChannelAPI(this);
|
|
|
|
m_deviceAPI->removeThreadedSource(m_threadedChannelizer);
|
|
|
|
delete m_threadedChannelizer;
|
|
|
|
delete m_channelizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDaemonChannelSource::pull(Sample& sample)
|
|
|
|
{
|
|
|
|
sample.m_real = 0.0f;
|
|
|
|
sample.m_imag = 0.0f;
|
|
|
|
|
2018-08-26 11:22:22 -04:00
|
|
|
m_samplesCount++;
|
2018-08-19 18:38:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDaemonChannelSource::start()
|
|
|
|
{
|
|
|
|
qDebug("SDRDaemonChannelSink::start");
|
2018-08-26 11:22:22 -04:00
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sourceThread = new SDRDaemonChannelSourceThread(&m_dataQueue, m_cm256p);
|
|
|
|
m_sourceThread->startStop(true);
|
|
|
|
m_sourceThread->dataBind(m_dataAddress, m_dataPort);
|
2018-08-19 18:38:33 -04:00
|
|
|
m_running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDaemonChannelSource::stop()
|
|
|
|
{
|
|
|
|
qDebug("SDRDaemonChannelSink::stop");
|
2018-08-26 11:22:22 -04:00
|
|
|
|
|
|
|
if (m_sourceThread != 0)
|
|
|
|
{
|
|
|
|
m_sourceThread->startStop(false);
|
|
|
|
m_sourceThread->deleteLater();
|
|
|
|
m_sourceThread = 0;
|
|
|
|
}
|
|
|
|
|
2018-08-19 18:38:33 -04:00
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SDRDaemonChannelSource::handleMessage(const Message& cmd __attribute__((unused)))
|
|
|
|
{
|
2018-08-23 16:45:43 -04:00
|
|
|
if (MsgConfigureSDRDaemonChannelSource::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureSDRDaemonChannelSource& cfg = (MsgConfigureSDRDaemonChannelSource&) cmd;
|
|
|
|
qDebug() << "SDRDaemonChannelSource::handleMessage: MsgConfigureSDRDaemonChannelSource";
|
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-19 18:38:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray SDRDaemonChannelSource::serialize() const
|
|
|
|
{
|
2018-08-23 16:45:43 -04:00
|
|
|
return m_settings.serialize();
|
2018-08-19 18:38:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SDRDaemonChannelSource::deserialize(const QByteArray& data __attribute__((unused)))
|
|
|
|
{
|
2018-08-23 16:45:43 -04:00
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureSDRDaemonChannelSource *msg = MsgConfigureSDRDaemonChannelSource::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureSDRDaemonChannelSource *msg = MsgConfigureSDRDaemonChannelSource::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDaemonChannelSource::applySettings(const SDRDaemonChannelSourceSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "SDRDaemonChannelSource::applySettings:"
|
|
|
|
<< " m_dataAddress: " << settings.m_dataAddress
|
|
|
|
<< " m_dataPort: " << settings.m_dataPort
|
|
|
|
<< " force: " << force;
|
|
|
|
|
2018-08-26 11:22:22 -04:00
|
|
|
bool change = false;
|
|
|
|
|
|
|
|
if ((m_settings.m_dataAddress != settings.m_dataAddress) || force)
|
|
|
|
{
|
2018-08-23 16:45:43 -04:00
|
|
|
m_dataAddress = settings.m_dataAddress;
|
2018-08-26 11:22:22 -04:00
|
|
|
change = true;
|
2018-08-23 16:45:43 -04:00
|
|
|
}
|
|
|
|
|
2018-08-26 11:22:22 -04:00
|
|
|
if ((m_settings.m_dataPort != settings.m_dataPort) || force)
|
|
|
|
{
|
2018-08-23 16:45:43 -04:00
|
|
|
m_dataPort = settings.m_dataPort;
|
2018-08-26 11:22:22 -04:00
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change && m_sourceThread) {
|
|
|
|
m_sourceThread->dataBind(m_dataAddress, m_dataPort);
|
2018-08-23 16:45:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_settings = settings;
|
2018-08-19 18:38:33 -04:00
|
|
|
}
|
|
|
|
|
2018-08-26 11:22:22 -04:00
|
|
|
bool SDRDaemonChannelSource::handleDataBlock(SDRDaemonDataBlock& dataBlock __attribute__((unused)))
|
|
|
|
{
|
|
|
|
//TODO: Push into R/W buffer
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDRDaemonChannelSource::handleData()
|
|
|
|
{
|
|
|
|
SDRDaemonDataBlock* dataBlock;
|
2018-08-23 16:45:43 -04:00
|
|
|
|
2018-08-26 11:22:22 -04:00
|
|
|
while (m_running && ((dataBlock = m_dataQueue.pop()) != 0))
|
|
|
|
{
|
|
|
|
if (handleDataBlock(*dataBlock))
|
|
|
|
{
|
|
|
|
delete dataBlock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|