From dfb619cd98115ead84512df29145d6ca837779bc Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 19 Aug 2018 23:36:30 +0200 Subject: [PATCH] SDRdaemon: added channel sink --- sdrdaemon/CMakeLists.txt | 2 + sdrdaemon/channel/sdrdaemonchannelsink.cpp | 84 ++++++++++++++++++++++ sdrdaemon/channel/sdrdaemonchannelsink.h | 64 +++++++++++++++++ sdrdaemon/sdrdaemonmain.cpp | 8 +++ sdrdaemon/sdrdaemonmain.h | 3 + 5 files changed, 161 insertions(+) create mode 100644 sdrdaemon/channel/sdrdaemonchannelsink.cpp create mode 100644 sdrdaemon/channel/sdrdaemonchannelsink.h diff --git a/sdrdaemon/CMakeLists.txt b/sdrdaemon/CMakeLists.txt index 14dc5d93c..0950d9c12 100644 --- a/sdrdaemon/CMakeLists.txt +++ b/sdrdaemon/CMakeLists.txt @@ -5,6 +5,7 @@ set(sdrdaemon_SOURCES sdrdaemonpreferences.cpp sdrdaemonsettings.cpp sdrdaemonparser.cpp + channel/sdrdaemonchannelsink.cpp webapi/webapiadapterdaemon.cpp webapi/webapirequestmapper.cpp webapi/webapiserver.cpp @@ -15,6 +16,7 @@ set(sdrdaemon_HEADERS sdrdaemonpreferences.h sdrdaemonsettings.h sdrdaemonparser.h + channel/sdrdaemonchannelsink.h webapi/webapiadapterdaemon.h webapi/webapirequestmapper.h webapi/webapiserver.h diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.cpp b/sdrdaemon/channel/sdrdaemonchannelsink.cpp new file mode 100644 index 000000000..68f22efaf --- /dev/null +++ b/sdrdaemon/channel/sdrdaemonchannelsink.cpp @@ -0,0 +1,84 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB. // +// // +// SDRdaemon sink channel (Rx) // +// // +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "util/simpleserializer.h" +#include "dsp/threadedbasebandsamplesink.h" +#include "dsp/downchannelizer.h" +#include "device/devicesourceapi.h" +#include "sdrdaemonchannelsink.h" + +const QString SDRDaemonChannelSink::m_channelIdURI = "sdrangel.channel.sdrdaemonsink"; +const QString SDRDaemonChannelSink::m_channelId = "SDRDaemonChannelSink"; + +SDRDaemonChannelSink::SDRDaemonChannelSink(DeviceSourceAPI *deviceAPI) : + ChannelSinkAPI(m_channelIdURI), + m_deviceAPI(deviceAPI), + m_running(false) +{ + setObjectName(m_channelId); + + m_channelizer = new DownChannelizer(this); + m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); + m_deviceAPI->addThreadedSink(m_threadedChannelizer); + m_deviceAPI->addChannelAPI(this); +} + +SDRDaemonChannelSink::~SDRDaemonChannelSink() +{ + m_deviceAPI->removeChannelAPI(this); + m_deviceAPI->removeThreadedSink(m_threadedChannelizer); + delete m_threadedChannelizer; + delete m_channelizer; +} + +void SDRDaemonChannelSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused))) +{ + qDebug("SDRDaemonChannelSink::feed: received %d samples", (int) (end - begin)); +} + +void SDRDaemonChannelSink::start() +{ + qDebug("SDRDaemonChannelSink::start"); + m_running = true; +} + +void SDRDaemonChannelSink::stop() +{ + qDebug("SDRDaemonChannelSink::stop"); + m_running = false; +} + +bool SDRDaemonChannelSink::handleMessage(const Message& cmd __attribute__((unused))) +{ + return false; +} + +QByteArray SDRDaemonChannelSink::serialize() const +{ + SimpleSerializer s(1); + return s.final(); +} + +bool SDRDaemonChannelSink::deserialize(const QByteArray& data __attribute__((unused))) +{ + return false; +} diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.h b/sdrdaemon/channel/sdrdaemonchannelsink.h new file mode 100644 index 000000000..df9b117dd --- /dev/null +++ b/sdrdaemon/channel/sdrdaemonchannelsink.h @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB. // +// // +// SDRdaemon sink channel (Rx) // +// // +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ +#define SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ + +#include "dsp/basebandsamplesink.h" +#include "channel/channelsinkapi.h" + +class DeviceSourceAPI; +class ThreadedBasebandSampleSink; +class DownChannelizer; + +class SDRDaemonChannelSink : public BasebandSampleSink, public ChannelSinkAPI { + Q_OBJECT +public: + SDRDaemonChannelSink(DeviceSourceAPI *deviceAPI); + virtual ~SDRDaemonChannelSink(); + virtual void destroy() { delete this; } + + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po); + virtual void start(); + virtual void stop(); + virtual bool handleMessage(const Message& cmd); + + virtual void getIdentifier(QString& id) { id = objectName(); } + virtual void getTitle(QString& title) { title = "SDRDaemon Sink"; } + virtual qint64 getCenterFrequency() const { return 0; } + + virtual QByteArray serialize() const; + virtual bool deserialize(const QByteArray& data); + + static const QString m_channelIdURI; + static const QString m_channelId; + +private: + DeviceSourceAPI *m_deviceAPI; + ThreadedBasebandSampleSink* m_threadedChannelizer; + DownChannelizer* m_channelizer; + + bool m_running; + +}; + +#endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ */ diff --git a/sdrdaemon/sdrdaemonmain.cpp b/sdrdaemon/sdrdaemonmain.cpp index 0ed1393fa..e7faf6667 100644 --- a/sdrdaemon/sdrdaemonmain.cpp +++ b/sdrdaemon/sdrdaemonmain.cpp @@ -37,6 +37,7 @@ #include "webapi/webapiadapterdaemon.h" #include "webapi/webapirequestmapper.h" #include "webapi/webapiserver.h" +#include "channel/sdrdaemonchannelsink.h" #include "sdrdaemonparser.h" #include "sdrdaemonmain.h" @@ -85,6 +86,7 @@ SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonPa m_deviceSinkEngine = 0; m_deviceSourceAPI = 0; m_deviceSinkAPI = 0; + m_channelSink = 0; if (m_tx) { @@ -123,6 +125,7 @@ SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonPa QDebug info = qInfo(); info.noquote(); info << msg; + m_channelSink = new SDRDaemonChannelSink(m_deviceSourceAPI); } else { @@ -283,6 +286,11 @@ void SDRDaemonMain::removeDevice() m_deviceSourceEngine->stopAcquistion(); // deletes old UI and input object + + if (m_channelSink) { + m_channelSink->destroy(); + } + m_deviceSourceAPI->resetSampleSourceId(); m_deviceSourceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput( m_deviceSourceAPI->getSampleSource()); diff --git a/sdrdaemon/sdrdaemonmain.h b/sdrdaemon/sdrdaemonmain.h index f57b16f1c..8eb07211a 100644 --- a/sdrdaemon/sdrdaemonmain.h +++ b/sdrdaemon/sdrdaemonmain.h @@ -47,6 +47,7 @@ class DSPDeviceSourceEngine; class DeviceSourceAPI; class DSPDeviceSinkEngine; class DeviceSinkAPI; +class SDRDaemonChannelSink; class SDRDaemonMain : public QObject { Q_OBJECT @@ -92,11 +93,13 @@ private: DeviceSourceAPI *m_deviceSourceAPI; DSPDeviceSinkEngine *m_deviceSinkEngine; DeviceSinkAPI *m_deviceSinkAPI; + SDRDaemonChannelSink *m_channelSink; void loadSettings(); void setLoggingOptions(); int getDeviceIndex(); bool handleMessage(const Message& cmd); + void addChannelSink(); private slots: void handleMessages();