From edffed4ff06114d9d402d0cf024705fd9b562a4d Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 23 Aug 2018 22:45:43 +0200 Subject: [PATCH] SDRDaemon: create and use channel source settings --- sdrdaemon/CMakeLists.txt | 2 + .../channel/sdrdaemonchannelsinksettings.cpp | 3 - sdrdaemon/channel/sdrdaemonchannelsource.cpp | 57 +++++++++++-- sdrdaemon/channel/sdrdaemonchannelsource.h | 30 +++++++ .../sdrdaemonchannelsourcesettings.cpp | 85 +++++++++++++++++++ .../channel/sdrdaemonchannelsourcesettings.h | 43 ++++++++++ 6 files changed, 212 insertions(+), 8 deletions(-) create mode 100644 sdrdaemon/channel/sdrdaemonchannelsourcesettings.cpp create mode 100644 sdrdaemon/channel/sdrdaemonchannelsourcesettings.h diff --git a/sdrdaemon/CMakeLists.txt b/sdrdaemon/CMakeLists.txt index c7f9e82c7..36f116f7a 100644 --- a/sdrdaemon/CMakeLists.txt +++ b/sdrdaemon/CMakeLists.txt @@ -10,6 +10,7 @@ set(sdrdaemon_SOURCES channel/sdrdaemondataqueue.cpp channel/sdrdaemonchannelsinkthread.cpp channel/sdrdaemonchannelsinksettings.cpp + channel/sdrdaemonchannelsourcesettings.cpp webapi/webapiadapterdaemon.cpp webapi/webapirequestmapper.cpp webapi/webapiserver.cpp @@ -26,6 +27,7 @@ set(sdrdaemon_HEADERS channel/sdrdaemondatablock.h channel/sdrdaemonchannelsinkthread.h channel/sdrdaemonchannelsinksettings.h + channel/sdrdaemonchannelsourcesettings.h webapi/webapiadapterdaemon.h webapi/webapirequestmapper.h webapi/webapiserver.h diff --git a/sdrdaemon/channel/sdrdaemonchannelsinksettings.cpp b/sdrdaemon/channel/sdrdaemonchannelsinksettings.cpp index 7a5a2e57c..f05b3a103 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsinksettings.cpp +++ b/sdrdaemon/channel/sdrdaemonchannelsinksettings.cpp @@ -20,9 +20,6 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include - -#include "dsp/dspengine.h" #include "util/simpleserializer.h" #include "settings/serializable.h" #include "channel/sdrdaemonchannelsinksettings.h" diff --git a/sdrdaemon/channel/sdrdaemonchannelsource.cpp b/sdrdaemon/channel/sdrdaemonchannelsource.cpp index f22886299..a21846337 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsource.cpp +++ b/sdrdaemon/channel/sdrdaemonchannelsource.cpp @@ -20,12 +20,16 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// +#include + #include "util/simpleserializer.h" #include "dsp/threadedbasebandsamplesource.h" #include "dsp/upchannelizer.h" #include "device/devicesinkapi.h" #include "sdrdaemonchannelsource.h" +MESSAGE_CLASS_DEFINITION(SDRDaemonChannelSource::MsgConfigureSDRDaemonChannelSource, Message) + const QString SDRDaemonChannelSource::m_channelIdURI = "sdrangel.channel.sdrdaemonsource"; const QString SDRDaemonChannelSource::m_channelId = "SDRDaemonChannelSource"; @@ -33,7 +37,9 @@ SDRDaemonChannelSource::SDRDaemonChannelSource(DeviceSinkAPI *deviceAPI) : ChannelSourceAPI(m_channelIdURI), m_deviceAPI(deviceAPI), m_running(false), - m_samplesCount(0) + m_samplesCount(0), + m_dataAddress("127.0.0.1"), + m_dataPort(9090) { setObjectName(m_channelId); @@ -78,17 +84,58 @@ void SDRDaemonChannelSource::stop() bool SDRDaemonChannelSource::handleMessage(const Message& cmd __attribute__((unused))) { - return false; + if (MsgConfigureSDRDaemonChannelSource::match(cmd)) + { + MsgConfigureSDRDaemonChannelSource& cfg = (MsgConfigureSDRDaemonChannelSource&) cmd; + qDebug() << "SDRDaemonChannelSource::handleMessage: MsgConfigureSDRDaemonChannelSource"; + applySettings(cfg.getSettings(), cfg.getForce()); + + return true; + } + else + { + return false; + } } QByteArray SDRDaemonChannelSource::serialize() const { - SimpleSerializer s(1); - return s.final(); + return m_settings.serialize(); } bool SDRDaemonChannelSource::deserialize(const QByteArray& data __attribute__((unused))) { - return false; + 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; + + if ((m_settings.m_dataAddress != settings.m_dataAddress) || force) { + m_dataAddress = settings.m_dataAddress; + } + + if ((m_settings.m_dataPort != settings.m_dataPort) || force) { + m_dataPort = settings.m_dataPort; + } + + m_settings = settings; +} + + diff --git a/sdrdaemon/channel/sdrdaemonchannelsource.h b/sdrdaemon/channel/sdrdaemonchannelsource.h index c5b543199..7259b2827 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsource.h +++ b/sdrdaemon/channel/sdrdaemonchannelsource.h @@ -25,6 +25,7 @@ #include "dsp/basebandsamplesource.h" #include "channel/channelsourceapi.h" +#include "channel/sdrdaemonchannelsourcesettings.h" class ThreadedBasebandSampleSource; class UpChannelizer; @@ -33,6 +34,29 @@ class DeviceSinkAPI; class SDRDaemonChannelSource : public BasebandSampleSource, public ChannelSourceAPI { Q_OBJECT public: + class MsgConfigureSDRDaemonChannelSource : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const SDRDaemonChannelSourceSettings& getSettings() const { return m_settings; } + bool getForce() const { return m_force; } + + static MsgConfigureSDRDaemonChannelSource* create(const SDRDaemonChannelSourceSettings& settings, bool force) + { + return new MsgConfigureSDRDaemonChannelSource(settings, force); + } + + private: + SDRDaemonChannelSourceSettings m_settings; + bool m_force; + + MsgConfigureSDRDaemonChannelSource(const SDRDaemonChannelSourceSettings& settings, bool force) : + Message(), + m_settings(settings), + m_force(force) + { } + }; + SDRDaemonChannelSource(DeviceSinkAPI *deviceAPI); ~SDRDaemonChannelSource(); virtual void destroy() { delete this; } @@ -58,7 +82,13 @@ private: UpChannelizer* m_channelizer; bool m_running; + SDRDaemonChannelSourceSettings m_settings; uint32_t m_samplesCount; + + QString m_dataAddress; + uint16_t m_dataPort; + + void applySettings(const SDRDaemonChannelSourceSettings& settings, bool force = false); }; diff --git a/sdrdaemon/channel/sdrdaemonchannelsourcesettings.cpp b/sdrdaemon/channel/sdrdaemonchannelsourcesettings.cpp new file mode 100644 index 000000000..2b14fe23b --- /dev/null +++ b/sdrdaemon/channel/sdrdaemonchannelsourcesettings.cpp @@ -0,0 +1,85 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB. // +// // +// SDRdaemon sink channel (Rx) main settings // +// // +// 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 "settings/serializable.h" +#include "channel/sdrdaemonchannelsourcesettings.h" + +SDRDaemonChannelSourceSettings::SDRDaemonChannelSourceSettings() +{ + resetToDefaults(); +} + +void SDRDaemonChannelSourceSettings::resetToDefaults() +{ + m_dataAddress = "127.0.0.1"; + m_dataPort = 9090; +} + +QByteArray SDRDaemonChannelSourceSettings::serialize() const +{ + SimpleSerializer s(1); + s.writeString(1, m_dataAddress); + s.writeU32(2, m_dataPort); + + return s.final(); +} + +bool SDRDaemonChannelSourceSettings::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if(!d.isValid()) + { + resetToDefaults(); + return false; + } + + if(d.getVersion() == 1) + { + uint32_t tmp; + QString strtmp; + + d.readString(1, &m_dataAddress, "127.0.0.1"); + d.readU32(2, &tmp, 0); + + if ((tmp > 1023) && (tmp < 65535)) { + m_dataPort = tmp; + } else { + m_dataPort = 9090; + } + + return true; + } + else + { + resetToDefaults(); + return false; + } +} + + + + + + + diff --git a/sdrdaemon/channel/sdrdaemonchannelsourcesettings.h b/sdrdaemon/channel/sdrdaemonchannelsourcesettings.h new file mode 100644 index 000000000..ebd26735f --- /dev/null +++ b/sdrdaemon/channel/sdrdaemonchannelsourcesettings.h @@ -0,0 +1,43 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB. // +// // +// SDRdaemon source channel (Tx) main settings // +// // +// 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_SDRDAEMONCHANNELSOURCESETTINGS_H_ +#define SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCESETTINGS_H_ + + +#include + +class Serializable; + +struct SDRDaemonChannelSourceSettings +{ + QString m_dataAddress; + uint16_t m_dataPort; + + SDRDaemonChannelSourceSettings(); + void resetToDefaults(); + QByteArray serialize() const; + bool deserialize(const QByteArray& data); +}; + + +#endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCESETTINGS_H_ */