SDRDaemon: create and use channel source settings

This commit is contained in:
f4exb 2018-08-23 22:45:43 +02:00
parent 0b195947d8
commit edffed4ff0
6 changed files with 212 additions and 8 deletions

View File

@ -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

View File

@ -20,9 +20,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QColor>
#include "dsp/dspengine.h"
#include "util/simpleserializer.h"
#include "settings/serializable.h"
#include "channel/sdrdaemonchannelsinksettings.h"

View File

@ -20,12 +20,16 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QDebug>
#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;
}

View File

@ -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);
};

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCESETTINGS_H_
#define SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCESETTINGS_H_
#include <QByteArray>
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_ */