mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-23 10:05:46 -05:00
TestSink output plugin
This commit is contained in:
parent
ec6645b6bb
commit
e2fd1384f7
@ -1,6 +1,7 @@
|
||||
project(samplesink)
|
||||
|
||||
add_subdirectory(filesink)
|
||||
add_subdirectory(testsink)
|
||||
add_subdirectory(localoutput)
|
||||
|
||||
if(CM256CC_FOUND)
|
||||
|
55
plugins/samplesink/testsink/CMakeLists.txt
Normal file
55
plugins/samplesink/testsink/CMakeLists.txt
Normal file
@ -0,0 +1,55 @@
|
||||
project(testsink)
|
||||
|
||||
set(testsink_SOURCES
|
||||
testsinkoutput.cpp
|
||||
testsinkplugin.cpp
|
||||
testsinksettings.cpp
|
||||
testsinkthread.cpp
|
||||
)
|
||||
|
||||
set(testsink_HEADERS
|
||||
testsinkoutput.h
|
||||
testsinkplugin.h
|
||||
testsinksettings.h
|
||||
testsinkthread.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
)
|
||||
|
||||
if(NOT SERVER_MODE)
|
||||
set(testsink_SOURCES
|
||||
${testsink_SOURCES}
|
||||
testsinkgui.cpp
|
||||
testsinkgui.ui
|
||||
)
|
||||
set(testsink_HEADERS
|
||||
${testsink_HEADERS}
|
||||
testsinkgui.h
|
||||
)
|
||||
|
||||
set(TARGET_NAME outputtestsink)
|
||||
set(TARGET_LIB "Qt5::Widgets")
|
||||
set(TARGET_LIB_GUI "sdrgui")
|
||||
set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR})
|
||||
else()
|
||||
set(TARGET_NAME outputtestsinksrv)
|
||||
set(TARGET_LIB "")
|
||||
set(TARGET_LIB_GUI "")
|
||||
set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR})
|
||||
endif()
|
||||
|
||||
add_library(${TARGET_NAME} SHARED
|
||||
${testsink_SOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(${TARGET_NAME}
|
||||
Qt5::Core
|
||||
${TARGET_LIB}
|
||||
sdrbase
|
||||
${TARGET_LIB_GUI}
|
||||
swagger
|
||||
)
|
||||
|
||||
install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})
|
274
plugins/samplesink/testsink/testsinkgui.cpp
Normal file
274
plugins/samplesink/testsink/testsinkgui.cpp
Normal file
@ -0,0 +1,274 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 <QDebug>
|
||||
|
||||
#include <QTime>
|
||||
#include <QString>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "ui_testsinkgui.h"
|
||||
#include "plugin/pluginapi.h"
|
||||
#include "gui/colormapper.h"
|
||||
#include "gui/glspectrum.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "device/deviceapi.h"
|
||||
#include "device/deviceuiset.h"
|
||||
#include "testsinkgui.h"
|
||||
|
||||
TestSinkGui::TestSinkGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::TestSinkGui),
|
||||
m_deviceUISet(deviceUISet),
|
||||
m_doApplySettings(true),
|
||||
m_forceSettings(true),
|
||||
m_settings(),
|
||||
m_deviceSampleSink(0),
|
||||
m_sampleRate(0),
|
||||
m_generation(false),
|
||||
m_samplesCount(0),
|
||||
m_tickCount(0),
|
||||
m_lastEngineState(DeviceAPI::StNotStarted)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
|
||||
ui->centerFrequency->setValueRange(7, 0, pow(10,7));
|
||||
|
||||
ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow));
|
||||
ui->sampleRate->setValueRange(7, 32000U, 9000000U);
|
||||
|
||||
connect(&(m_deviceUISet->m_deviceAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
|
||||
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
|
||||
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
||||
m_statusTimer.start(500);
|
||||
|
||||
displaySettings();
|
||||
|
||||
m_deviceSampleSink = (TestSinkOutput*) m_deviceUISet->m_deviceAPI->getSampleSink();
|
||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
TestSinkGui::~TestSinkGui()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TestSinkGui::destroy()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void TestSinkGui::setName(const QString& name)
|
||||
{
|
||||
setObjectName(name);
|
||||
}
|
||||
|
||||
QString TestSinkGui::getName() const
|
||||
{
|
||||
return objectName();
|
||||
}
|
||||
|
||||
void TestSinkGui::resetToDefaults()
|
||||
{
|
||||
m_settings.resetToDefaults();
|
||||
displaySettings();
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
qint64 TestSinkGui::getCenterFrequency() const
|
||||
{
|
||||
return m_settings.m_centerFrequency;
|
||||
}
|
||||
|
||||
void TestSinkGui::setCenterFrequency(qint64 centerFrequency)
|
||||
{
|
||||
m_settings.m_centerFrequency = centerFrequency;
|
||||
displaySettings();
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
QByteArray TestSinkGui::serialize() const
|
||||
{
|
||||
return m_settings.serialize();
|
||||
}
|
||||
|
||||
bool TestSinkGui::deserialize(const QByteArray& data)
|
||||
{
|
||||
if(m_settings.deserialize(data)) {
|
||||
displaySettings();
|
||||
m_forceSettings = true;
|
||||
sendSettings();
|
||||
return true;
|
||||
} else {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TestSinkGui::handleMessage(const Message& message)
|
||||
{
|
||||
if (TestSinkOutput::MsgConfigureTestSink::match(message))
|
||||
{
|
||||
qDebug("TestSinkGui::handleMessage: message: MsgConfigureTestSink");
|
||||
const TestSinkOutput::MsgConfigureTestSink& cfg = (TestSinkOutput::MsgConfigureTestSink&) message;
|
||||
m_settings = cfg.getSettings();
|
||||
blockApplySettings(true);
|
||||
displaySettings();
|
||||
blockApplySettings(false);
|
||||
return true;
|
||||
}
|
||||
else if (TestSinkOutput::MsgStartStop::match(message))
|
||||
{
|
||||
TestSinkOutput::MsgStartStop& notif = (TestSinkOutput::MsgStartStop&) message;
|
||||
qDebug("TestSinkOutput::handleMessage: message: MsgStartStop: %s", notif.getStartStop() ? "start" : "stop");
|
||||
blockApplySettings(true);
|
||||
ui->startStop->setChecked(notif.getStartStop());
|
||||
blockApplySettings(false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void TestSinkGui::handleInputMessages()
|
||||
{
|
||||
Message* message;
|
||||
|
||||
while ((message = m_inputMessageQueue.pop()) != 0)
|
||||
{
|
||||
|
||||
if (DSPSignalNotification::match(*message))
|
||||
{
|
||||
DSPSignalNotification* notif = (DSPSignalNotification*) message;
|
||||
qDebug("FileSinkGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
|
||||
m_sampleRate = notif->getSampleRate();
|
||||
m_deviceCenterFrequency = notif->getCenterFrequency();
|
||||
updateSampleRateAndFrequency();
|
||||
|
||||
delete message;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (handleMessage(*message))
|
||||
{
|
||||
delete message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestSinkGui::updateSampleRateAndFrequency()
|
||||
{
|
||||
m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate);
|
||||
m_deviceUISet->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency);
|
||||
ui->deviceRateText->setText(tr("%1k").arg((float)(m_sampleRate*(1<<m_settings.m_log2Interp)) / 1000));
|
||||
}
|
||||
|
||||
void TestSinkGui::displaySettings()
|
||||
{
|
||||
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
|
||||
ui->sampleRate->setValue(m_settings.m_sampleRate);
|
||||
}
|
||||
|
||||
void TestSinkGui::sendSettings()
|
||||
{
|
||||
if (!m_updateTimer.isActive()) {
|
||||
m_updateTimer.start(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestSinkGui::updateHardware()
|
||||
{
|
||||
qDebug() << "TestSinkGui::updateHardware";
|
||||
TestSinkOutput::MsgConfigureTestSink* message = TestSinkOutput::MsgConfigureTestSink::create(m_settings, m_forceSettings);
|
||||
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
||||
m_forceSettings = false;
|
||||
m_updateTimer.stop();
|
||||
}
|
||||
|
||||
void TestSinkGui::updateStatus()
|
||||
{
|
||||
int state = m_deviceUISet->m_deviceAPI->state();
|
||||
|
||||
if(m_lastEngineState != state)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case DeviceAPI::StNotStarted:
|
||||
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
|
||||
break;
|
||||
case DeviceAPI::StIdle:
|
||||
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
|
||||
break;
|
||||
case DeviceAPI::StRunning:
|
||||
ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
|
||||
break;
|
||||
case DeviceAPI::StError:
|
||||
ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
|
||||
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
m_lastEngineState = state;
|
||||
}
|
||||
}
|
||||
|
||||
void TestSinkGui::on_centerFrequency_changed(quint64 value)
|
||||
{
|
||||
m_settings.m_centerFrequency = value * 1000;
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
void TestSinkGui::on_sampleRate_changed(quint64 value)
|
||||
{
|
||||
m_settings.m_sampleRate = value;
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
void TestSinkGui::on_interp_currentIndexChanged(int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_settings.m_log2Interp = index;
|
||||
updateSampleRateAndFrequency();
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
void TestSinkGui::on_startStop_toggled(bool checked)
|
||||
{
|
||||
if (m_doApplySettings)
|
||||
{
|
||||
TestSinkOutput::MsgStartStop *message = TestSinkOutput::MsgStartStop::create(checked);
|
||||
m_deviceSampleSink->getInputMessageQueue()->push(message);
|
||||
}
|
||||
}
|
||||
|
||||
void TestSinkGui::tick()
|
||||
{
|
||||
}
|
93
plugins/samplesink/testsink/testsinkgui.h
Normal file
93
plugins/samplesink/testsink/testsinkgui.h
Normal file
@ -0,0 +1,93 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 INCLUDE_TESTSINKGUI_H
|
||||
#define INCLUDE_TESTSINKGUI_H
|
||||
|
||||
#include <plugin/plugininstancegui.h>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "util/messagequeue.h"
|
||||
|
||||
#include "testsinkoutput.h"
|
||||
#include "testsinksettings.h"
|
||||
|
||||
|
||||
class DeviceSampleSink;
|
||||
class DeviceUISet;
|
||||
|
||||
namespace Ui {
|
||||
class TestSinkGui;
|
||||
}
|
||||
|
||||
class TestSinkGui : public QWidget, public PluginInstanceGUI {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TestSinkGui(DeviceUISet *deviceUISet, QWidget* parent = nullptr);
|
||||
virtual ~TestSinkGui();
|
||||
virtual void destroy();
|
||||
|
||||
void setName(const QString& name);
|
||||
QString getName() const;
|
||||
|
||||
void resetToDefaults();
|
||||
virtual qint64 getCenterFrequency() const;
|
||||
virtual void setCenterFrequency(qint64 centerFrequency);
|
||||
QByteArray serialize() const;
|
||||
bool deserialize(const QByteArray& data);
|
||||
virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
private:
|
||||
Ui::TestSinkGui* ui;
|
||||
|
||||
DeviceUISet* m_deviceUISet;
|
||||
bool m_doApplySettings;
|
||||
bool m_forceSettings;
|
||||
TestSinkSettings m_settings;
|
||||
QTimer m_updateTimer;
|
||||
QTimer m_statusTimer;
|
||||
DeviceSampleSink* m_deviceSampleSink;
|
||||
int m_sampleRate;
|
||||
quint64 m_deviceCenterFrequency; //!< Center frequency in device
|
||||
bool m_generation;
|
||||
int m_samplesCount;
|
||||
std::size_t m_tickCount;
|
||||
int m_lastEngineState;
|
||||
MessageQueue m_inputMessageQueue;
|
||||
|
||||
void blockApplySettings(bool block) { m_doApplySettings = !block; }
|
||||
void displaySettings();
|
||||
void displayTime();
|
||||
void sendSettings();
|
||||
void configureFileName();
|
||||
void updateSampleRateAndFrequency();
|
||||
|
||||
private slots:
|
||||
void handleInputMessages();
|
||||
void on_centerFrequency_changed(quint64 value);
|
||||
void on_sampleRate_changed(quint64 value);
|
||||
void on_startStop_toggled(bool checked);
|
||||
void on_interp_currentIndexChanged(int index);
|
||||
void updateHardware();
|
||||
void updateStatus();
|
||||
void tick();
|
||||
};
|
||||
|
||||
#endif // INCLUDE_TESTSINKGUI_H
|
331
plugins/samplesink/testsink/testsinkgui.ui
Normal file
331
plugins/samplesink/testsink/testsinkgui.ui
Normal file
@ -0,0 +1,331 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TestSinkGui</class>
|
||||
<widget class="QWidget" name="TestSinkGui">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>350</width>
|
||||
<height>190</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>350</width>
|
||||
<height>190</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Liberation Sans</family>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Test Sink</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Test Sink</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_freq">
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="deviceUILayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="deviceButtonsLayout">
|
||||
<item>
|
||||
<widget class="ButtonSwitch" name="startStop">
|
||||
<property name="toolTip">
|
||||
<string>start/stop generation</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../sdrgui/resources/res.qrc">
|
||||
<normaloff>:/play.png</normaloff>
|
||||
<normalon>:/stop.png</normalon>:/play.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="deviceRateLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="deviceRateText">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>I/Q sample rate kS/s</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>00000k</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="freqLeftSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ValueDial" name="centerFrequency" native="true">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Liberation Mono</family>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Record center frequency in kHz</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="freqUnits">
|
||||
<property name="text">
|
||||
<string> kHz</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="freqRightlSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_rate">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="rateControlLayout">
|
||||
<property name="topMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="interpLabel">
|
||||
<property name="text">
|
||||
<string>Int</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="interp">
|
||||
<property name="toolTip">
|
||||
<string>Interpolation</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>4</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>8</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>16</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>32</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>64</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="sampleRateLabel">
|
||||
<property name="text">
|
||||
<string>SR</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ValueDial" name="sampleRate" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Liberation Mono</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="sampleRateUnit">
|
||||
<property name="text">
|
||||
<string>S/s</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="linePlay2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="padLayout">
|
||||
<item>
|
||||
<spacer name="verticaPadlSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ValueDial</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>gui/valuedial.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ButtonSwitch</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>gui/buttonswitch.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../sdrgui/resources/res.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
253
plugins/samplesink/testsink/testsinkoutput.cpp
Normal file
253
plugins/samplesink/testsink/testsinkoutput.cpp
Normal file
@ -0,0 +1,253 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
|
||||
#include "device/deviceapi.h"
|
||||
|
||||
#include "testsinkoutput.h"
|
||||
#include "testsinkthread.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(TestSinkOutput::MsgConfigureTestSink, Message)
|
||||
MESSAGE_CLASS_DEFINITION(TestSinkOutput::MsgStartStop, Message)
|
||||
|
||||
TestSinkOutput::TestSinkOutput(DeviceAPI *deviceAPI) :
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_settings(),
|
||||
m_testSinkThread(nullptr),
|
||||
m_deviceDescription("TestSink"),
|
||||
m_masterTimer(deviceAPI->getMasterTimer())
|
||||
{
|
||||
m_deviceAPI->setNbSinkStreams(1);
|
||||
}
|
||||
|
||||
TestSinkOutput::~TestSinkOutput()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void TestSinkOutput::destroy()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void TestSinkOutput::init()
|
||||
{
|
||||
applySettings(m_settings, true);
|
||||
}
|
||||
|
||||
bool TestSinkOutput::start()
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
qDebug() << "TestSinkOutput::start";
|
||||
|
||||
m_testSinkThread = new TestSinkThread(&m_sampleSourceFifo);
|
||||
m_testSinkThread->setSamplerate(m_settings.m_sampleRate);
|
||||
m_testSinkThread->setLog2Interpolation(m_settings.m_log2Interp);
|
||||
m_testSinkThread->connectTimer(m_masterTimer);
|
||||
m_testSinkThread->startWork();
|
||||
mutexLocker.unlock();
|
||||
|
||||
qDebug("TestSinkOutput::start: started");
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestSinkOutput::stop()
|
||||
{
|
||||
qDebug() << "TestSinkOutput::stop";
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if(m_testSinkThread != 0)
|
||||
{
|
||||
m_testSinkThread->stopWork();
|
||||
delete m_testSinkThread;
|
||||
m_testSinkThread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray TestSinkOutput::serialize() const
|
||||
{
|
||||
return m_settings.serialize();
|
||||
}
|
||||
|
||||
bool TestSinkOutput::deserialize(const QByteArray& data)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
if (!m_settings.deserialize(data))
|
||||
{
|
||||
m_settings.resetToDefaults();
|
||||
success = false;
|
||||
}
|
||||
|
||||
MsgConfigureTestSink* message = MsgConfigureTestSink::create(m_settings, true);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
MsgConfigureTestSink* messageToGUI = MsgConfigureTestSink::create(m_settings, true);
|
||||
m_guiMessageQueue->push(messageToGUI);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
const QString& TestSinkOutput::getDeviceDescription() const
|
||||
{
|
||||
return m_deviceDescription;
|
||||
}
|
||||
|
||||
int TestSinkOutput::getSampleRate() const
|
||||
{
|
||||
return m_settings.m_sampleRate;
|
||||
}
|
||||
|
||||
quint64 TestSinkOutput::getCenterFrequency() const
|
||||
{
|
||||
return m_settings.m_centerFrequency;
|
||||
}
|
||||
|
||||
void TestSinkOutput::setCenterFrequency(qint64 centerFrequency)
|
||||
{
|
||||
TestSinkSettings settings = m_settings;
|
||||
settings.m_centerFrequency = centerFrequency;
|
||||
|
||||
MsgConfigureTestSink* message = MsgConfigureTestSink::create(settings, false);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
MsgConfigureTestSink* messageToGUI = MsgConfigureTestSink::create(settings, false);
|
||||
m_guiMessageQueue->push(messageToGUI);
|
||||
}
|
||||
}
|
||||
|
||||
bool TestSinkOutput::handleMessage(const Message& message)
|
||||
{
|
||||
if (MsgStartStop::match(message))
|
||||
{
|
||||
MsgStartStop& cmd = (MsgStartStop&) message;
|
||||
qDebug() << "TestSinkOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
||||
|
||||
if (cmd.getStartStop())
|
||||
{
|
||||
if (m_deviceAPI->initDeviceEngine()) {
|
||||
m_deviceAPI->startDeviceEngine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopDeviceEngine();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureTestSink::match(message))
|
||||
{
|
||||
qDebug() << "TestSinkOutput::handleMessage: MsgConfigureTestSink";
|
||||
MsgConfigureTestSink& conf = (MsgConfigureTestSink&) message;
|
||||
applySettings(conf.getSettings(), conf.getForce());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void TestSinkOutput::applySettings(const TestSinkSettings& settings, bool force)
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
bool forwardChange = false;
|
||||
|
||||
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency))
|
||||
{
|
||||
m_settings.m_centerFrequency = settings.m_centerFrequency;
|
||||
forwardChange = true;
|
||||
}
|
||||
|
||||
if (force || (m_settings.m_sampleRate != settings.m_sampleRate))
|
||||
{
|
||||
m_settings.m_sampleRate = settings.m_sampleRate;
|
||||
|
||||
if (m_testSinkThread) {
|
||||
m_testSinkThread->setSamplerate(m_settings.m_sampleRate);
|
||||
}
|
||||
|
||||
forwardChange = true;
|
||||
}
|
||||
|
||||
if (force || (m_settings.m_log2Interp != settings.m_log2Interp))
|
||||
{
|
||||
m_settings.m_log2Interp = settings.m_log2Interp;
|
||||
|
||||
if (m_testSinkThread) {
|
||||
m_testSinkThread->setLog2Interpolation(m_settings.m_log2Interp);
|
||||
}
|
||||
|
||||
forwardChange = true;
|
||||
}
|
||||
|
||||
if (forwardChange)
|
||||
{
|
||||
qDebug("TestSinkOutput::applySettings: forward: m_centerFrequency: %llu m_sampleRate: %llu m_log2Interp: %d",
|
||||
m_settings.m_centerFrequency,
|
||||
m_settings.m_sampleRate,
|
||||
m_settings.m_log2Interp);
|
||||
DSPSignalNotification *notif = new DSPSignalNotification(m_settings.m_sampleRate, m_settings.m_centerFrequency);
|
||||
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
|
||||
}
|
||||
}
|
||||
|
||||
int TestSinkOutput::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage)
|
||||
{
|
||||
(void) errorMessage;
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int TestSinkOutput::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage)
|
||||
{
|
||||
(void) errorMessage;
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
MsgStartStop *message = MsgStartStop::create(run);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
MsgStartStop *messagetoGui = MsgStartStop::create(run);
|
||||
m_guiMessageQueue->push(messagetoGui);
|
||||
}
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
118
plugins/samplesink/testsink/testsinkoutput.h
Normal file
118
plugins/samplesink/testsink/testsinkoutput.h
Normal file
@ -0,0 +1,118 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 INCLUDE_TESTSINKOUTPUT_H
|
||||
#define INCLUDE_TESTSINKOUTPUT_H
|
||||
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "dsp/devicesamplesink.h"
|
||||
#include "testsinksettings.h"
|
||||
|
||||
class TestSinkThread;
|
||||
class DeviceAPI;
|
||||
|
||||
class TestSinkOutput : public DeviceSampleSink {
|
||||
public:
|
||||
class MsgConfigureTestSink : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
const TestSinkSettings& getSettings() const { return m_settings; }
|
||||
bool getForce() const { return m_force; }
|
||||
|
||||
static MsgConfigureTestSink* create(const TestSinkSettings& settings, bool force)
|
||||
{
|
||||
return new MsgConfigureTestSink(settings, force);
|
||||
}
|
||||
|
||||
private:
|
||||
TestSinkSettings m_settings;
|
||||
bool m_force;
|
||||
|
||||
MsgConfigureTestSink(const TestSinkSettings& settings, bool force) :
|
||||
Message(),
|
||||
m_settings(settings),
|
||||
m_force(force)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgStartStop : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
bool getStartStop() const { return m_startStop; }
|
||||
|
||||
static MsgStartStop* create(bool startStop) {
|
||||
return new MsgStartStop(startStop);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool m_startStop;
|
||||
|
||||
MsgStartStop(bool startStop) :
|
||||
Message(),
|
||||
m_startStop(startStop)
|
||||
{ }
|
||||
};
|
||||
|
||||
TestSinkOutput(DeviceAPI *deviceAPI);
|
||||
virtual ~TestSinkOutput();
|
||||
virtual void destroy();
|
||||
|
||||
virtual void init();
|
||||
virtual bool start();
|
||||
virtual void stop();
|
||||
|
||||
virtual QByteArray serialize() const;
|
||||
virtual bool deserialize(const QByteArray& data);
|
||||
|
||||
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
||||
virtual const QString& getDeviceDescription() const;
|
||||
virtual int getSampleRate() const;
|
||||
virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
|
||||
virtual quint64 getCenterFrequency() const;
|
||||
virtual void setCenterFrequency(qint64 centerFrequency);
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
private:
|
||||
DeviceAPI *m_deviceAPI;
|
||||
QMutex m_mutex;
|
||||
TestSinkSettings m_settings;
|
||||
std::ofstream m_ofstream;
|
||||
TestSinkThread* m_testSinkThread;
|
||||
QString m_deviceDescription;
|
||||
const QTimer& m_masterTimer;
|
||||
|
||||
void applySettings(const TestSinkSettings& settings, bool force = false);
|
||||
};
|
||||
|
||||
#endif // INCLUDE_TESTSINKOUTPUT_H
|
143
plugins/samplesink/testsink/testsinkplugin.cpp
Normal file
143
plugins/samplesink/testsink/testsinkplugin.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 <QtPlugin>
|
||||
|
||||
#include "plugin/pluginapi.h"
|
||||
#include "util/simpleserializer.h"
|
||||
|
||||
#ifdef SERVER_MODE
|
||||
#include "testsinkoutput.h"
|
||||
#else
|
||||
#include "testsinkgui.h"
|
||||
#endif
|
||||
#include "testsinkplugin.h"
|
||||
|
||||
const PluginDescriptor TestSinkPlugin::m_pluginDescriptor = {
|
||||
QString("Test sink output"),
|
||||
QString("4.11.12"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
QString("https://github.com/f4exb/sdrangel")
|
||||
};
|
||||
|
||||
const QString TestSinkPlugin::m_hardwareID = "TestSink";
|
||||
const QString TestSinkPlugin::m_deviceTypeID = TESTSINK_DEVICE_TYPE_ID;
|
||||
|
||||
TestSinkPlugin::TestSinkPlugin(QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
const PluginDescriptor& TestSinkPlugin::getPluginDescriptor() const
|
||||
{
|
||||
return m_pluginDescriptor;
|
||||
}
|
||||
|
||||
void TestSinkPlugin::initPlugin(PluginAPI* pluginAPI)
|
||||
{
|
||||
pluginAPI->registerSampleSink(m_deviceTypeID, this);
|
||||
}
|
||||
|
||||
void TestSinkPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices)
|
||||
{
|
||||
if (listedHwIds.contains(m_hardwareID)) { // check if it was done
|
||||
return;
|
||||
}
|
||||
|
||||
originDevices.append(OriginDevice(
|
||||
"TestSink",
|
||||
m_hardwareID,
|
||||
QString::null,
|
||||
0, // Sequence
|
||||
0, // nb Rx
|
||||
1 // nb Tx
|
||||
));
|
||||
|
||||
listedHwIds.append(m_hardwareID);
|
||||
}
|
||||
|
||||
PluginInterface::SamplingDevices TestSinkPlugin::enumSampleSinks(const OriginDevices& originDevices)
|
||||
{
|
||||
SamplingDevices result;
|
||||
|
||||
for (OriginDevices::const_iterator it = originDevices.begin(); it != originDevices.end(); ++it)
|
||||
{
|
||||
if (it->hardwareId == m_hardwareID)
|
||||
{
|
||||
result.append(SamplingDevice(
|
||||
it->displayableName,
|
||||
it->hardwareId,
|
||||
m_deviceTypeID,
|
||||
it->serial,
|
||||
it->sequence,
|
||||
PluginInterface::SamplingDevice::BuiltInDevice,
|
||||
PluginInterface::SamplingDevice::StreamSingleTx,
|
||||
1,
|
||||
0
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef SERVER_MODE
|
||||
PluginInstanceGUI* TestSinkPlugin::createSampleSinkPluginInstanceGUI(
|
||||
const QString& sinkId,
|
||||
QWidget **widget,
|
||||
DeviceUISet *deviceUISet)
|
||||
{
|
||||
(void) sinkId;
|
||||
(void) widget;
|
||||
(void) deviceUISet;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
PluginInstanceGUI* TestSinkPlugin::createSampleSinkPluginInstanceGUI(
|
||||
const QString& sinkId,
|
||||
QWidget **widget,
|
||||
DeviceUISet *deviceUISet)
|
||||
{
|
||||
if(sinkId == m_deviceTypeID)
|
||||
{
|
||||
TestSinkGui* gui = new TestSinkGui(deviceUISet);
|
||||
*widget = gui;
|
||||
return gui;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
DeviceSampleSink* TestSinkPlugin::createSampleSinkPluginInstance(const QString& sinkId, DeviceAPI *deviceAPI)
|
||||
{
|
||||
if(sinkId == m_deviceTypeID)
|
||||
{
|
||||
TestSinkOutput* output = new TestSinkOutput(deviceAPI);
|
||||
return output;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
55
plugins/samplesink/testsink/testsinkplugin.h
Normal file
55
plugins/samplesink/testsink/testsinkplugin.h
Normal file
@ -0,0 +1,55 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 INCLUDE_TESTSINKPLUGIN_H
|
||||
#define INCLUDE_TESTSINKPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#include "plugin/plugininterface.h"
|
||||
|
||||
#define TESTSINK_DEVICE_TYPE_ID "sdrangel.samplesink.testsink"
|
||||
|
||||
class PluginAPI;
|
||||
class DeviceAPI;
|
||||
|
||||
class TestSinkPlugin : public QObject, public PluginInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(PluginInterface)
|
||||
Q_PLUGIN_METADATA(IID TESTSINK_DEVICE_TYPE_ID)
|
||||
|
||||
public:
|
||||
explicit TestSinkPlugin(QObject* parent = nullptr);
|
||||
|
||||
const PluginDescriptor& getPluginDescriptor() const;
|
||||
void initPlugin(PluginAPI* pluginAPI);
|
||||
|
||||
virtual void enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices);
|
||||
virtual SamplingDevices enumSampleSinks(const OriginDevices& originDevices);
|
||||
virtual PluginInstanceGUI* createSampleSinkPluginInstanceGUI(
|
||||
const QString& sinkId,
|
||||
QWidget **widget,
|
||||
DeviceUISet *deviceUISet);
|
||||
virtual DeviceSampleSink* createSampleSinkPluginInstance(const QString& sinkId, DeviceAPI *deviceAPI);
|
||||
|
||||
static const QString m_hardwareID;
|
||||
static const QString m_deviceTypeID;
|
||||
|
||||
private:
|
||||
static const PluginDescriptor m_pluginDescriptor;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_TESTSINKPLUGIN_H
|
64
plugins/samplesink/testsink/testsinksettings.cpp
Normal file
64
plugins/samplesink/testsink/testsinksettings.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 "testsinksettings.h"
|
||||
|
||||
TestSinkSettings::TestSinkSettings()
|
||||
{
|
||||
resetToDefaults();
|
||||
}
|
||||
|
||||
void TestSinkSettings::resetToDefaults()
|
||||
{
|
||||
m_centerFrequency = 435000*1000;
|
||||
m_sampleRate = 48000;
|
||||
m_log2Interp = 0;
|
||||
}
|
||||
|
||||
QByteArray TestSinkSettings::serialize() const
|
||||
{
|
||||
SimpleSerializer s(1);
|
||||
|
||||
s.writeU64(1, m_sampleRate);
|
||||
s.writeU32(2, m_log2Interp);
|
||||
|
||||
return s.final();
|
||||
}
|
||||
|
||||
bool TestSinkSettings::deserialize(const QByteArray& data)
|
||||
{
|
||||
SimpleDeserializer d(data);
|
||||
|
||||
if (!d.isValid())
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (d.getVersion() == 1)
|
||||
{
|
||||
d.readU64(1, &m_sampleRate, 48000);
|
||||
d.readU32(2, &m_log2Interp, 0);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
34
plugins/samplesink/testsink/testsinksettings.h
Normal file
34
plugins/samplesink/testsink/testsinksettings.h
Normal file
@ -0,0 +1,34 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 PLUGINS_SAMPLESINK_TESTSINK_TESTSINKSETTINGS_H_
|
||||
#define PLUGINS_SAMPLESINK_TESTSINK_TESTSINKSETTINGS_H_
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
struct TestSinkSettings {
|
||||
quint64 m_centerFrequency;
|
||||
quint64 m_sampleRate;
|
||||
quint32 m_log2Interp;
|
||||
|
||||
TestSinkSettings();
|
||||
void resetToDefaults();
|
||||
QByteArray serialize() const;
|
||||
bool deserialize(const QByteArray& data);
|
||||
};
|
||||
|
||||
#endif /* PLUGINS_SAMPLESINK_TESTSINK_TESTSINKSETTINGS_H_ */
|
219
plugins/samplesink/testsink/testsinkthread.cpp
Normal file
219
plugins/samplesink/testsink/testsinkthread.cpp
Normal file
@ -0,0 +1,219 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include <QDebug>
|
||||
|
||||
#include "dsp/samplesourcefifo.h"
|
||||
#include "testsinkthread.h"
|
||||
|
||||
TestSinkThread::TestSinkThread(SampleSourceFifo* sampleFifo, QObject* parent) :
|
||||
QThread(parent),
|
||||
m_running(false),
|
||||
m_bufsize(0),
|
||||
m_samplesChunkSize(0),
|
||||
m_sampleFifo(sampleFifo),
|
||||
m_samplesCount(0),
|
||||
m_samplerate(0),
|
||||
m_log2Interpolation(0),
|
||||
m_throttlems(TESTSINK_THROTTLE_MS),
|
||||
m_maxThrottlems(50),
|
||||
m_throttleToggle(false),
|
||||
m_buf(0)
|
||||
{
|
||||
}
|
||||
|
||||
TestSinkThread::~TestSinkThread()
|
||||
{
|
||||
if (m_running) {
|
||||
stopWork();
|
||||
}
|
||||
|
||||
if (m_buf) delete[] m_buf;
|
||||
}
|
||||
|
||||
void TestSinkThread::startWork()
|
||||
{
|
||||
qDebug() << "TestSinkThread::startWork: ";
|
||||
m_maxThrottlems = 0;
|
||||
m_startWaitMutex.lock();
|
||||
m_elapsedTimer.start();
|
||||
start();
|
||||
while(!m_running) {
|
||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||
}
|
||||
m_startWaitMutex.unlock();
|
||||
}
|
||||
|
||||
void TestSinkThread::stopWork()
|
||||
{
|
||||
qDebug() << "TestSinkThread::stopWork";
|
||||
m_running = false;
|
||||
wait();
|
||||
}
|
||||
|
||||
void TestSinkThread::setSamplerate(int samplerate)
|
||||
{
|
||||
if (samplerate != m_samplerate)
|
||||
{
|
||||
qDebug() << "TestSinkThread::setSamplerate:"
|
||||
<< " new:" << samplerate
|
||||
<< " old:" << m_samplerate;
|
||||
|
||||
bool wasRunning = false;
|
||||
|
||||
if (m_running)
|
||||
{
|
||||
stopWork();
|
||||
wasRunning = true;
|
||||
}
|
||||
|
||||
// resize sample FIFO
|
||||
if (m_sampleFifo) {
|
||||
m_sampleFifo->resize(samplerate); // 1s buffer
|
||||
}
|
||||
|
||||
// resize output buffer
|
||||
if (m_buf) delete[] m_buf;
|
||||
m_buf = new int16_t[samplerate*(1<<m_log2Interpolation)*2];
|
||||
|
||||
m_samplerate = samplerate;
|
||||
m_samplesChunkSize = (m_samplerate * m_throttlems) / 1000;
|
||||
|
||||
if (wasRunning) {
|
||||
startWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestSinkThread::setLog2Interpolation(int log2Interpolation)
|
||||
{
|
||||
if ((log2Interpolation < 0) || (log2Interpolation > 6)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (log2Interpolation != m_log2Interpolation)
|
||||
{
|
||||
qDebug() << "TestSinkThread::setLog2Interpolation:"
|
||||
<< " new:" << log2Interpolation
|
||||
<< " old:" << m_log2Interpolation;
|
||||
|
||||
bool wasRunning = false;
|
||||
|
||||
if (m_running)
|
||||
{
|
||||
stopWork();
|
||||
wasRunning = true;
|
||||
}
|
||||
|
||||
// resize output buffer
|
||||
if (m_buf) delete[] m_buf;
|
||||
m_buf = new int16_t[m_samplerate*(1<<log2Interpolation)*2];
|
||||
|
||||
m_log2Interpolation = log2Interpolation;
|
||||
|
||||
if (wasRunning) {
|
||||
startWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestSinkThread::run()
|
||||
{
|
||||
m_running = true;
|
||||
m_startWaiter.wakeAll();
|
||||
|
||||
while(m_running) // actual work is in the tick() function
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void TestSinkThread::connectTimer(const QTimer& timer)
|
||||
{
|
||||
qDebug() << "TestSinkThread::connectTimer";
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||
}
|
||||
|
||||
void TestSinkThread::tick()
|
||||
{
|
||||
if (m_running)
|
||||
{
|
||||
qint64 throttlems = m_elapsedTimer.restart();
|
||||
|
||||
if (throttlems != m_throttlems)
|
||||
{
|
||||
m_throttlems = throttlems;
|
||||
m_samplesChunkSize = (m_samplerate * (m_throttlems+(m_throttleToggle ? 1 : 0))) / 1000;
|
||||
m_throttleToggle = !m_throttleToggle;
|
||||
}
|
||||
|
||||
// if (m_throttlems > m_maxThrottlems)
|
||||
// {
|
||||
// qDebug("FileSinkThread::tick: m_maxThrottlems: %d", m_maxThrottlems);
|
||||
// m_maxThrottlems = m_throttlems;
|
||||
// }
|
||||
|
||||
SampleVector::iterator readUntil;
|
||||
|
||||
m_sampleFifo->readAdvance(readUntil, m_samplesChunkSize);
|
||||
SampleVector::iterator beginRead = readUntil - m_samplesChunkSize;
|
||||
m_samplesCount += m_samplesChunkSize;
|
||||
int chunkSize = std::min((int) m_samplesChunkSize, m_samplerate);
|
||||
|
||||
if (m_log2Interpolation == 0)
|
||||
{
|
||||
m_interpolators.interpolate1(&beginRead, m_buf, 2*chunkSize);
|
||||
//m_ofstream->write(reinterpret_cast<char*>(&(*beginRead)), m_samplesChunkSize*sizeof(Sample));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
switch (m_log2Interpolation)
|
||||
{
|
||||
case 1:
|
||||
m_interpolators.interpolate2_cen(&beginRead, m_buf, chunkSize*(1<<m_log2Interpolation)*2);
|
||||
break;
|
||||
case 2:
|
||||
m_interpolators.interpolate4_cen(&beginRead, m_buf, chunkSize*(1<<m_log2Interpolation)*2);
|
||||
break;
|
||||
case 3:
|
||||
m_interpolators.interpolate8_cen(&beginRead, m_buf, chunkSize*(1<<m_log2Interpolation)*2);
|
||||
break;
|
||||
case 4:
|
||||
m_interpolators.interpolate16_cen(&beginRead, m_buf, chunkSize*(1<<m_log2Interpolation)*2);
|
||||
break;
|
||||
case 5:
|
||||
m_interpolators.interpolate32_cen(&beginRead, m_buf, chunkSize*(1<<m_log2Interpolation)*2);
|
||||
break;
|
||||
case 6:
|
||||
m_interpolators.interpolate64_cen(&beginRead, m_buf, chunkSize*(1<<m_log2Interpolation)*2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//m_ofstream->write(reinterpret_cast<char*>(m_buf), m_samplesChunkSize*(1<<m_log2Interpolation)*2*sizeof(int16_t));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
82
plugins/samplesink/testsink/testsinkthread.h
Normal file
82
plugins/samplesink/testsink/testsinkthread.h
Normal file
@ -0,0 +1,82 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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 INCLUDE_TESTSINKTHREAD_H
|
||||
#define INCLUDE_TESTSINKTHREAD_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#include <QTimer>
|
||||
#include <QElapsedTimer>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "dsp/inthalfbandfilter.h"
|
||||
#include "dsp/interpolators.h"
|
||||
|
||||
#define TESTSINK_THROTTLE_MS 50
|
||||
|
||||
class SampleSourceFifo;
|
||||
|
||||
class TestSinkThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestSinkThread(SampleSourceFifo* sampleFifo, QObject* parent = nullptr);
|
||||
~TestSinkThread();
|
||||
|
||||
void startWork();
|
||||
void stopWork();
|
||||
void setSamplerate(int samplerate);
|
||||
void setLog2Interpolation(int log2Interpolation);
|
||||
void setBuffer(std::size_t chunksize);
|
||||
bool isRunning() const { return m_running; }
|
||||
std::size_t getSamplesCount() const { return m_samplesCount; }
|
||||
void setSamplesCount(int samplesCount) { m_samplesCount = samplesCount; }
|
||||
|
||||
void connectTimer(const QTimer& timer);
|
||||
|
||||
private:
|
||||
QMutex m_startWaitMutex;
|
||||
QWaitCondition m_startWaiter;
|
||||
volatile bool m_running;
|
||||
|
||||
std::size_t m_bufsize;
|
||||
unsigned int m_samplesChunkSize;
|
||||
SampleSourceFifo* m_sampleFifo;
|
||||
std::size_t m_samplesCount;
|
||||
|
||||
int m_samplerate;
|
||||
int m_log2Interpolation;
|
||||
int m_throttlems;
|
||||
int m_maxThrottlems;
|
||||
QElapsedTimer m_elapsedTimer;
|
||||
bool m_throttleToggle;
|
||||
|
||||
Interpolators<qint16, SDR_TX_SAMP_SZ, 16> m_interpolators;
|
||||
int16_t *m_buf;
|
||||
|
||||
void run();
|
||||
|
||||
private slots:
|
||||
void tick();
|
||||
};
|
||||
|
||||
#endif // INCLUDE_TESTSINKTHREAD_H
|
Loading…
Reference in New Issue
Block a user