2016-06-19 03:56:49 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// 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 <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "dsp/dspengine.h"
|
2016-10-10 19:17:55 -04:00
|
|
|
#include <device/devicesourceapi.h>
|
2016-10-02 04:30:58 -04:00
|
|
|
#include <dsp/filerecord.h>
|
|
|
|
|
2017-06-09 07:58:27 -04:00
|
|
|
#include "sdrdaemonsourcegui.h"
|
|
|
|
#include "sdrdaemonsourceinput.h"
|
|
|
|
#include "sdrdaemonsourceudphandler.h"
|
2016-06-19 03:56:49 -04:00
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgConfigureSDRdaemonSource, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgConfigureSDRdaemonUDPLink, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgConfigureSDRdaemonAutoCorr, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgConfigureSDRdaemonWork, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgConfigureSDRdaemonStreamTiming, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgReportSDRdaemonAcquisition, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamData, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgReportSDRdaemonSourceStreamTiming, Message)
|
2017-09-04 18:31:45 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSourceInput::MsgFileRecord, Message)
|
2016-06-19 03:56:49 -04:00
|
|
|
|
2017-09-14 07:34:32 -04:00
|
|
|
SDRdaemonSourceInput::SDRdaemonSourceInput(DeviceSourceAPI *deviceAPI) :
|
2016-06-19 03:56:49 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
|
|
|
m_address("127.0.0.1"),
|
|
|
|
m_port(9090),
|
|
|
|
m_SDRdaemonUDPHandler(0),
|
|
|
|
m_deviceDescription(),
|
|
|
|
m_sampleRate(0),
|
|
|
|
m_centerFrequency(0),
|
|
|
|
m_startingTimeStamp(0),
|
2017-09-14 07:34:32 -04:00
|
|
|
m_masterTimer(deviceAPI->getMasterTimer()),
|
2016-06-19 03:56:49 -04:00
|
|
|
m_autoFollowRate(false),
|
|
|
|
m_autoCorrBuffer(false)
|
|
|
|
{
|
|
|
|
m_sampleFifo.setSize(96000 * 4);
|
2017-09-16 20:02:41 -04:00
|
|
|
m_SDRdaemonUDPHandler = new SDRdaemonSourceUDPHandler(&m_sampleFifo, &m_inputMessageQueue, m_deviceAPI);
|
2016-06-19 03:56:49 -04:00
|
|
|
m_SDRdaemonUDPHandler->connectTimer(&m_masterTimer);
|
2017-09-04 18:31:45 -04:00
|
|
|
|
|
|
|
char recFileNameCStr[30];
|
|
|
|
sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID());
|
|
|
|
m_fileSink = new FileRecord(std::string(recFileNameCStr));
|
|
|
|
m_deviceAPI->addSink(m_fileSink);
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
SDRdaemonSourceInput::~SDRdaemonSourceInput()
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
stop();
|
2017-09-04 18:31:45 -04:00
|
|
|
m_deviceAPI->removeSink(m_fileSink);
|
|
|
|
delete m_fileSink;
|
2016-06-19 03:56:49 -04:00
|
|
|
delete m_SDRdaemonUDPHandler;
|
|
|
|
}
|
|
|
|
|
2017-09-14 20:32:30 -04:00
|
|
|
void SDRdaemonSourceInput::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
bool SDRdaemonSourceInput::start()
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
qDebug() << "SDRdaemonInput::start";
|
|
|
|
MsgConfigureSDRdaemonWork *command = MsgConfigureSDRdaemonWork::create(true);
|
|
|
|
getInputMessageQueue()->push(command);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
void SDRdaemonSourceInput::stop()
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
qDebug() << "SDRdaemonInput::stop";
|
|
|
|
MsgConfigureSDRdaemonWork *command = MsgConfigureSDRdaemonWork::create(false);
|
|
|
|
getInputMessageQueue()->push(command);
|
|
|
|
}
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
const QString& SDRdaemonSourceInput::getDeviceDescription() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
int SDRdaemonSourceInput::getSampleRate() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
return m_sampleRate;
|
|
|
|
}
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
quint64 SDRdaemonSourceInput::getCenterFrequency() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
return m_centerFrequency;
|
|
|
|
}
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
std::time_t SDRdaemonSourceInput::getStartingTimeStamp() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
return m_startingTimeStamp;
|
|
|
|
}
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
void SDRdaemonSourceInput::getRemoteAddress(QString &s)
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
if (m_SDRdaemonUDPHandler) {
|
|
|
|
m_SDRdaemonUDPHandler->getRemoteAddress(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-09 08:14:32 -04:00
|
|
|
bool SDRdaemonSourceInput::handleMessage(const Message& message)
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2017-09-04 18:31:45 -04:00
|
|
|
if (DSPSignalNotification::match(message))
|
|
|
|
{
|
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) message;
|
|
|
|
return m_fileSink->handleMessage(notif); // forward to file sink
|
|
|
|
}
|
|
|
|
else if (MsgFileRecord::match(message))
|
|
|
|
{
|
|
|
|
MsgFileRecord& conf = (MsgFileRecord&) message;
|
|
|
|
qDebug() << "SDRdaemonSourceInput::handleMessage: MsgFileRecord: " << conf.getStartStop();
|
|
|
|
|
|
|
|
if (conf.getStartStop()) {
|
|
|
|
m_fileSink->startRecording();
|
|
|
|
} else {
|
|
|
|
m_fileSink->stopRecording();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureSDRdaemonSource::match(message))
|
2017-06-08 02:40:21 -04:00
|
|
|
{
|
2017-06-09 08:18:11 -04:00
|
|
|
qDebug() << "SDRdaemonSourceInput::handleMessage:" << message.getIdentifier();
|
|
|
|
//SDRdaemonSourceInput& conf = (MsgConfigureSDRdaemonFEC&) message;
|
2017-06-08 02:40:21 -04:00
|
|
|
//applySettings(conf.getSettings(), conf.getForce());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureSDRdaemonUDPLink::match(message))
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
MsgConfigureSDRdaemonUDPLink& conf = (MsgConfigureSDRdaemonUDPLink&) message;
|
|
|
|
m_SDRdaemonUDPHandler->configureUDPLink(conf.getAddress(), conf.getPort());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureSDRdaemonAutoCorr::match(message))
|
|
|
|
{
|
|
|
|
MsgConfigureSDRdaemonAutoCorr& conf = (MsgConfigureSDRdaemonAutoCorr&) message;
|
|
|
|
bool dcBlock = conf.getDCBlock();
|
|
|
|
bool iqImbalance = conf.getIQImbalance();
|
|
|
|
m_deviceAPI->configureCorrections(dcBlock, iqImbalance);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureSDRdaemonWork::match(message))
|
|
|
|
{
|
|
|
|
MsgConfigureSDRdaemonWork& conf = (MsgConfigureSDRdaemonWork&) message;
|
|
|
|
bool working = conf.isWorking();
|
|
|
|
|
|
|
|
if (working) {
|
|
|
|
m_SDRdaemonUDPHandler->start();
|
|
|
|
} else {
|
|
|
|
m_SDRdaemonUDPHandler->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureSDRdaemonStreamTiming::match(message))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-16 20:02:41 -04:00
|
|
|
else if (MsgReportSDRdaemonSourceStreamData::match(message))
|
|
|
|
{
|
|
|
|
// Forward message to the GUI if it is present
|
|
|
|
if (getMessageQueueToGUI()) {
|
|
|
|
getMessageQueueToGUI()->push(const_cast<Message*>(&message));
|
|
|
|
return false; // deletion of message is handled by the GUI
|
|
|
|
} else {
|
|
|
|
return true; // delete the unused message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (MsgReportSDRdaemonSourceStreamTiming::match(message))
|
|
|
|
{
|
|
|
|
// Forward message to the GUI if it is present
|
|
|
|
if (getMessageQueueToGUI()) {
|
|
|
|
getMessageQueueToGUI()->push(const_cast<Message*>(&message));
|
|
|
|
return false; // deletion of message is handled by the GUI
|
|
|
|
} else {
|
|
|
|
return true; // delete the unused message
|
|
|
|
}
|
|
|
|
}
|
2016-06-19 03:56:49 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-16 19:23:54 -04:00
|
|
|
void SDRdaemonSourceInput::setMessageQueueToGUI(MessageQueue *queue)
|
|
|
|
{
|
2017-09-16 20:02:41 -04:00
|
|
|
qDebug("SDRdaemonSourceInput::setMessageQueueToGUI: %p", queue);
|
2017-09-16 19:23:54 -04:00
|
|
|
DeviceSampleSource::setMessageQueueToGUI(queue);
|
|
|
|
m_SDRdaemonUDPHandler->setMessageQueueToGUI(queue);
|
|
|
|
}
|
|
|
|
|