1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

SDRdaemon: added channel source

This commit is contained in:
f4exb 2018-08-20 00:38:33 +02:00
parent dfb619cd98
commit 39212e6317
8 changed files with 227 additions and 36 deletions

View File

@ -94,10 +94,17 @@ static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *lo
SDRDaemonMain m(logger, parser, &a);
// This will cause the application to exit when SDRdaemon is finished
QObject::connect(&m, SIGNAL(finished()), &a, SLOT(quit()));
if (m.doAbort())
{
return -1;
}
else
{
// This will cause the application to exit when SDRdaemon is finished
QObject::connect(&m, SIGNAL(finished()), &a, SLOT(quit()));
return a.exec();
return a.exec();
}
}
int main(int argc, char* argv[])

View File

@ -6,6 +6,7 @@ set(sdrdaemon_SOURCES
sdrdaemonsettings.cpp
sdrdaemonparser.cpp
channel/sdrdaemonchannelsink.cpp
channel/sdrdaemonchannelsource.cpp
webapi/webapiadapterdaemon.cpp
webapi/webapirequestmapper.cpp
webapi/webapiserver.cpp
@ -17,6 +18,7 @@ set(sdrdaemon_HEADERS
sdrdaemonsettings.h
sdrdaemonparser.h
channel/sdrdaemonchannelsink.h
channel/sdrdaemonchannelsource.h
webapi/webapiadapterdaemon.h
webapi/webapirequestmapper.h
webapi/webapiserver.h

View File

@ -58,7 +58,6 @@ private:
DownChannelizer* m_channelizer;
bool m_running;
};
#endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ */

View File

@ -0,0 +1,94 @@
///////////////////////////////////////////////////////////////////////////////////
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "util/simpleserializer.h"
#include "dsp/threadedbasebandsamplesource.h"
#include "dsp/upchannelizer.h"
#include "device/devicesinkapi.h"
#include "sdrdaemonchannelsource.h"
const QString SDRDaemonChannelSource::m_channelIdURI = "sdrangel.channel.sdrdaemonsource";
const QString SDRDaemonChannelSource::m_channelId = "SDRDaemonChannelSource";
SDRDaemonChannelSource::SDRDaemonChannelSource(DeviceSinkAPI *deviceAPI) :
ChannelSourceAPI(m_channelIdURI),
m_deviceAPI(deviceAPI),
m_running(false),
m_samplesCount(0)
{
setObjectName(m_channelId);
m_channelizer = new UpChannelizer(this);
m_threadedChannelizer = new ThreadedBasebandSampleSource(m_channelizer, this);
m_deviceAPI->addThreadedSource(m_threadedChannelizer);
m_deviceAPI->addChannelAPI(this);
}
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;
if (m_samplesCount < 1023) {
m_samplesCount++;
} else {
qDebug("SDRDaemonChannelSource::pull: 1024 samples pulled");
m_samplesCount = 0;
}
}
void SDRDaemonChannelSource::start()
{
qDebug("SDRDaemonChannelSink::start");
m_running = true;
}
void SDRDaemonChannelSource::stop()
{
qDebug("SDRDaemonChannelSink::stop");
m_running = false;
}
bool SDRDaemonChannelSource::handleMessage(const Message& cmd __attribute__((unused)))
{
return false;
}
QByteArray SDRDaemonChannelSource::serialize() const
{
SimpleSerializer s(1);
return s.final();
}
bool SDRDaemonChannelSource::deserialize(const QByteArray& data __attribute__((unused)))
{
return false;
}

View File

@ -0,0 +1,65 @@
///////////////////////////////////////////////////////////////////////////////////
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCE_H_
#define SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCE_H_
#include "dsp/basebandsamplesource.h"
#include "channel/channelsourceapi.h"
class ThreadedBasebandSampleSource;
class UpChannelizer;
class DeviceSinkAPI;
class SDRDaemonChannelSource : public BasebandSampleSource, public ChannelSourceAPI {
Q_OBJECT
public:
SDRDaemonChannelSource(DeviceSinkAPI *deviceAPI);
~SDRDaemonChannelSource();
virtual void destroy() { delete this; }
virtual void pull(Sample& sample);
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 Source"; }
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:
DeviceSinkAPI *m_deviceAPI;
ThreadedBasebandSampleSource* m_threadedChannelizer;
UpChannelizer* m_channelizer;
bool m_running;
uint32_t m_samplesCount;
};
#endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCE_H_ */

View File

@ -38,6 +38,7 @@
#include "webapi/webapirequestmapper.h"
#include "webapi/webapiserver.h"
#include "channel/sdrdaemonchannelsink.h"
#include "channel/sdrdaemonchannelsource.h"
#include "sdrdaemonparser.h"
#include "sdrdaemonmain.h"
@ -48,7 +49,8 @@ SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonPa
m_logger(logger),
m_settings(),
m_dspEngine(DSPEngine::instance()),
m_lastEngineState(DSPDeviceSourceEngine::StNotStarted)
m_lastEngineState(DSPDeviceSourceEngine::StNotStarted),
m_abort(false)
{
qDebug() << "SDRDaemonMain::SDRDaemonMain: start";
@ -87,6 +89,7 @@ SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonPa
m_deviceSourceAPI = 0;
m_deviceSinkAPI = 0;
m_channelSink = 0;
m_channelSource = 0;
if (m_tx)
{
@ -103,11 +106,12 @@ SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonPa
QDebug info = qInfo();
info.noquote();
info << msg;
m_channelSource = new SDRDaemonChannelSource(m_deviceSinkAPI);
}
else
{
qCritical("SDRDaemonMain::SDRDaemonMain: sink device not found aborting");
emit finished();
m_abort = true;
}
}
else
@ -130,7 +134,7 @@ SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonPa
else
{
qCritical("SDRDaemonMain::SDRDaemonMain: source device not found aborting");
emit finished();
m_abort = true;
}
}
@ -211,20 +215,20 @@ void SDRDaemonMain::setLoggingOptions()
bool SDRDaemonMain::addSinkDevice()
{
DSPDeviceSinkEngine *dspDeviceSinkEngine = m_dspEngine->addDeviceSinkEngine();
dspDeviceSinkEngine->start();
uint dspDeviceSinkEngineUID = dspDeviceSinkEngine->getUID();
char uidCStr[16];
sprintf(uidCStr, "UID:%d", dspDeviceSinkEngineUID);
m_deviceSinkEngine = dspDeviceSinkEngine;
m_deviceSinkAPI = new DeviceSinkAPI(0, dspDeviceSinkEngine);
int deviceIndex = getDeviceIndex();
if (deviceIndex >= 0)
{
DSPDeviceSinkEngine *dspDeviceSinkEngine = m_dspEngine->addDeviceSinkEngine();
dspDeviceSinkEngine->start();
uint dspDeviceSinkEngineUID = dspDeviceSinkEngine->getUID();
char uidCStr[16];
sprintf(uidCStr, "UID:%d", dspDeviceSinkEngineUID);
m_deviceSinkEngine = dspDeviceSinkEngine;
m_deviceSinkAPI = new DeviceSinkAPI(0, dspDeviceSinkEngine);
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(deviceIndex);
m_deviceSinkAPI->setSampleSinkSequence(samplingDevice.sequence);
m_deviceSinkAPI->setNbItems(samplingDevice.deviceNbItems);
@ -246,20 +250,20 @@ bool SDRDaemonMain::addSinkDevice()
bool SDRDaemonMain::addSourceDevice()
{
DSPDeviceSourceEngine *dspDeviceSourceEngine = m_dspEngine->addDeviceSourceEngine();
dspDeviceSourceEngine->start();
uint dspDeviceSourceEngineUID = dspDeviceSourceEngine->getUID();
char uidCStr[16];
sprintf(uidCStr, "UID:%d", dspDeviceSourceEngineUID);
m_deviceSourceEngine = dspDeviceSourceEngine;
m_deviceSourceAPI = new DeviceSourceAPI(0, dspDeviceSourceEngine);
int deviceIndex = getDeviceIndex();
if (deviceIndex >= 0)
{
DSPDeviceSourceEngine *dspDeviceSourceEngine = m_dspEngine->addDeviceSourceEngine();
dspDeviceSourceEngine->start();
uint dspDeviceSourceEngineUID = dspDeviceSourceEngine->getUID();
char uidCStr[16];
sprintf(uidCStr, "UID:%d", dspDeviceSourceEngineUID);
m_deviceSourceEngine = dspDeviceSourceEngine;
m_deviceSourceAPI = new DeviceSourceAPI(0, dspDeviceSourceEngine);
PluginInterface::SamplingDevice samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(deviceIndex);
m_deviceSourceAPI->setSampleSourceSequence(samplingDevice.sequence);
m_deviceSourceAPI->setNbItems(samplingDevice.deviceNbItems);
@ -307,6 +311,11 @@ void SDRDaemonMain::removeDevice()
m_deviceSinkEngine->stopGeneration();
// deletes old UI and output object
if (m_channelSource) {
m_channelSource->destroy();
}
m_deviceSinkAPI->resetSampleSinkId();
m_deviceSinkAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput(
m_deviceSinkAPI->getSampleSink());

View File

@ -48,6 +48,7 @@ class DeviceSourceAPI;
class DSPDeviceSinkEngine;
class DeviceSinkAPI;
class SDRDaemonChannelSink;
class SDRDaemonChannelSource;
class SDRDaemonMain : public QObject {
Q_OBJECT
@ -65,6 +66,8 @@ public:
bool addSinkDevice();
void removeDevice();
bool doAbort() const { return m_abort; }
friend class WebAPIAdapterDaemon;
signals:
@ -94,6 +97,9 @@ private:
DSPDeviceSinkEngine *m_deviceSinkEngine;
DeviceSinkAPI *m_deviceSinkAPI;
SDRDaemonChannelSink *m_channelSink;
SDRDaemonChannelSource *m_channelSource;
bool m_abort;
void loadSettings();
void setLoggingOptions();

View File

@ -146,22 +146,31 @@ void SDRDaemonParser::parse(const QCoreApplication& app)
// device type
QString deviceType = m_parser.value(m_deviceTypeOption);
QRegExp deviceTypeRegex("^[A-Z][A-Za-z0-9]+$");
QRegExpValidator deviceTypeValidator(deviceTypeRegex);
if (deviceTypeValidator.validate(deviceType, pos) == QValidator::Acceptable)
if (m_parser.isSet(m_deviceTypeOption))
{
m_deviceType = deviceType;
qDebug() << "SDRDaemonParser::parse: device type: " << m_deviceType;
QString deviceType = m_parser.value(m_deviceTypeOption);
QRegExp deviceTypeRegex("^[A-Z][A-Za-z0-9]+$");
QRegExpValidator deviceTypeValidator(deviceTypeRegex);
if (deviceTypeValidator.validate(deviceType, pos) == QValidator::Acceptable)
{
m_deviceType = deviceType;
qDebug() << "SDRDaemonParser::parse: device type: " << m_deviceType;
}
else
{
m_deviceType = m_tx ? "FileSink" : "TestSource";
qWarning() << "SDRDaemonParser::parse: device type invalid. Defaulting to " << m_deviceType;
}
}
else
{
m_deviceType = m_tx ? "FileSink" : "TestSource";
qWarning() << "SDRDaemonParser::parse: device type invalid. Defaulting to " << m_deviceType;
qInfo() << "SDRDaemonParser::parse: device type not specified. defaulting to " << m_deviceType;
}
// serial
m_hasSerial = m_parser.isSet(m_serialOption);