mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-11-16 05:03:17 -05:00
TestMOSync plugin (1)
This commit is contained in:
parent
9619b4df52
commit
0a1dec4a23
@ -1,4 +1,8 @@
|
||||
project(samplemimo)
|
||||
|
||||
add_subdirectory(bladerf2mimo)
|
||||
if(ENABLE_BLADERF AND LIBBLADERF_FOUND)
|
||||
add_subdirectory(bladerf2mimo)
|
||||
endif()
|
||||
|
||||
add_subdirectory(testmi)
|
||||
add_subdirectory(testmosync)
|
||||
|
||||
55
plugins/samplemimo/testmosync/CMakeLists.txt
Normal file
55
plugins/samplemimo/testmosync/CMakeLists.txt
Normal file
@ -0,0 +1,55 @@
|
||||
project(testmosync)
|
||||
|
||||
set(testmosync_SOURCES
|
||||
testmosync.cpp
|
||||
testmosyncplugin.cpp
|
||||
testmosyncsettings.cpp
|
||||
testmosyncthread.cpp
|
||||
)
|
||||
|
||||
set(testmosync_HEADERS
|
||||
testmosync.h
|
||||
testmosyncplugin.h
|
||||
testmosyncsettings.h
|
||||
testmosyncthread.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
)
|
||||
|
||||
if(NOT SERVER_MODE)
|
||||
set(testmosync_SOURCES
|
||||
${testmosync_SOURCES}
|
||||
testmosyncgui.cpp
|
||||
testmosyncgui.ui
|
||||
)
|
||||
set(testmosync_HEADERS
|
||||
${testmosync_HEADERS}
|
||||
testmosyncgui.h
|
||||
)
|
||||
|
||||
set(TARGET_NAME outputtestmosync)
|
||||
set(TARGET_LIB "Qt5::Widgets")
|
||||
set(TARGET_LIB_GUI "sdrgui")
|
||||
set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR})
|
||||
else()
|
||||
set(TARGET_NAME outputtestmosyncsrv)
|
||||
set(TARGET_LIB "")
|
||||
set(TARGET_LIB_GUI "")
|
||||
set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR})
|
||||
endif()
|
||||
|
||||
add_library(${TARGET_NAME} SHARED
|
||||
${testmosync_SOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(${TARGET_NAME}
|
||||
Qt5::Core
|
||||
${TARGET_LIB}
|
||||
sdrbase
|
||||
${TARGET_LIB_GUI}
|
||||
swagger
|
||||
)
|
||||
|
||||
install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})
|
||||
304
plugins/samplemimo/testmosync/testmosync.cpp
Normal file
304
plugins/samplemimo/testmosync/testmosync.cpp
Normal file
@ -0,0 +1,304 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
#include "device/deviceapi.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "dsp/dspdevicemimoengine.h"
|
||||
#include "dsp/devicesamplesource.h"
|
||||
#include "dsp/devicesamplesink.h"
|
||||
|
||||
#include "testmosyncthread.h"
|
||||
#include "testmosync.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(TestMOSync::MsgConfigureTestMOSync, Message)
|
||||
MESSAGE_CLASS_DEFINITION(TestMOSync::MsgStartStop, Message)
|
||||
|
||||
TestMOSync::TestMOSync(DeviceAPI *deviceAPI) :
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_settings(),
|
||||
m_sinkThread(nullptr),
|
||||
m_deviceDescription("TestMOSync"),
|
||||
m_runningTx(false)
|
||||
{
|
||||
m_mimoType = MIMOHalfSynchronous;
|
||||
m_sampleMOFifo.init(2, 96000 * 4);
|
||||
m_deviceAPI->setNbSourceStreams(0);
|
||||
m_deviceAPI->setNbSinkStreams(2);
|
||||
}
|
||||
|
||||
TestMOSync::~TestMOSync()
|
||||
{}
|
||||
|
||||
void TestMOSync::destroy()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void TestMOSync::init()
|
||||
{
|
||||
applySettings(m_settings, true);
|
||||
}
|
||||
|
||||
bool TestMOSync::startTx()
|
||||
{
|
||||
qDebug("TestMOSync::startTx");
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if (m_runningTx) {
|
||||
stopTx();
|
||||
}
|
||||
|
||||
m_sinkThread = new TestMOSyncThread();
|
||||
m_sampleMOFifo.reset();
|
||||
m_sinkThread->setFifo(&m_sampleMOFifo);
|
||||
m_sinkThread->setFcPos(m_settings.m_fcPosTx);
|
||||
m_sinkThread->setLog2Interpolation(m_settings.m_log2Interp);
|
||||
m_sinkThread->startWork();
|
||||
mutexLocker.unlock();
|
||||
m_runningTx = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestMOSync::stopTx()
|
||||
{
|
||||
qDebug("TestMOSync::stopTx");
|
||||
|
||||
if (!m_sinkThread) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
m_sinkThread->stopWork();
|
||||
delete m_sinkThread;
|
||||
m_sinkThread = nullptr;
|
||||
m_runningTx = false;
|
||||
}
|
||||
|
||||
QByteArray TestMOSync::serialize() const
|
||||
{
|
||||
return m_settings.serialize();
|
||||
}
|
||||
|
||||
bool TestMOSync::deserialize(const QByteArray& data)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
if (!m_settings.deserialize(data))
|
||||
{
|
||||
m_settings.resetToDefaults();
|
||||
success = false;
|
||||
}
|
||||
|
||||
MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(m_settings, true);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(m_settings, true);
|
||||
m_guiMessageQueue->push(messageToGUI);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
const QString& TestMOSync::getDeviceDescription() const
|
||||
{
|
||||
return m_deviceDescription;
|
||||
}
|
||||
|
||||
int TestMOSync::getSourceSampleRate(int index) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestMOSync::getSinkSampleRate(int index) const
|
||||
{
|
||||
(void) index;
|
||||
int rate = m_settings.m_sampleRate;
|
||||
return (rate / (1<<m_settings.m_log2Interp));
|
||||
}
|
||||
|
||||
quint64 TestMOSync::getSourceCenterFrequency(int index) const
|
||||
{
|
||||
(void) index;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TestMOSync::setSourceCenterFrequency(qint64 centerFrequency, int index)
|
||||
{
|
||||
(void) centerFrequency;
|
||||
(void) index;
|
||||
}
|
||||
|
||||
quint64 TestMOSync::getSinkCenterFrequency(int index) const
|
||||
{
|
||||
(void) index;
|
||||
return m_settings.m_centerFrequency;
|
||||
}
|
||||
|
||||
void TestMOSync::setSinkCenterFrequency(qint64 centerFrequency, int index)
|
||||
{
|
||||
(void) index;
|
||||
TestMOSyncSettings settings = m_settings;
|
||||
settings.m_centerFrequency = centerFrequency;
|
||||
|
||||
MsgConfigureTestMOSync* message = MsgConfigureTestMOSync::create(settings, false);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
MsgConfigureTestMOSync* messageToGUI = MsgConfigureTestMOSync::create(settings, false);
|
||||
m_guiMessageQueue->push(messageToGUI);
|
||||
}
|
||||
}
|
||||
|
||||
bool TestMOSync::handleMessage(const Message& message)
|
||||
{
|
||||
if (MsgConfigureTestMOSync::match(message))
|
||||
{
|
||||
MsgConfigureTestMOSync& conf = (MsgConfigureTestMOSync&) message;
|
||||
qDebug() << "TestMOSync::handleMessage: MsgConfigureTestMOSync";
|
||||
|
||||
bool success = applySettings(conf.getSettings(), conf.getForce());
|
||||
|
||||
if (!success) {
|
||||
qDebug("TestMOSync::handleMessage: config error");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgStartStop::match(message))
|
||||
{
|
||||
MsgStartStop& cmd = (MsgStartStop&) message;
|
||||
qDebug() << "TestMOSync::handleMessage: "
|
||||
<< " " << (cmd.getRxElseTx() ? "Rx" : "Tx")
|
||||
<< " MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
||||
|
||||
bool startStopRxElseTx = cmd.getRxElseTx();
|
||||
|
||||
if (cmd.getStartStop())
|
||||
{
|
||||
if (m_deviceAPI->initDeviceEngine(startStopRxElseTx ? 0 : 1)) {
|
||||
m_deviceAPI->startDeviceEngine(startStopRxElseTx ? 0 : 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deviceAPI->stopDeviceEngine(startStopRxElseTx ? 0 : 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TestMOSync::applySettings(const TestMOSyncSettings& settings, bool force)
|
||||
{
|
||||
QList<QString> reverseAPIKeys;
|
||||
bool forwardChangeTxDSP = false;
|
||||
|
||||
qDebug() << "TestMOSync::applySettings: common: "
|
||||
<< " m_sampleRate: " << settings.m_sampleRate
|
||||
<< " m_centerFrequency: " << settings.m_centerFrequency
|
||||
<< " m_log2Interp: " << settings.m_log2Interp
|
||||
<< " m_fcPosTx: " << settings.m_fcPosTx
|
||||
<< " force: " << force;
|
||||
|
||||
if ((m_settings.m_sampleRate != settings.m_sampleRate) || force)
|
||||
{
|
||||
if (m_sinkThread) {
|
||||
m_sinkThread->setSamplerate(settings.m_sampleRate);
|
||||
}
|
||||
|
||||
forwardChangeTxDSP = true;
|
||||
}
|
||||
|
||||
if ((m_settings.m_fcPosTx != settings.m_fcPosTx) || force)
|
||||
{
|
||||
if (m_sinkThread) {
|
||||
m_sinkThread->setFcPos((int) settings.m_fcPosTx);
|
||||
}
|
||||
|
||||
forwardChangeTxDSP = true;
|
||||
}
|
||||
|
||||
if ((m_settings.m_log2Interp != settings.m_log2Interp) || force)
|
||||
{
|
||||
if (m_sinkThread)
|
||||
{
|
||||
m_sinkThread->setLog2Interpolation(settings.m_log2Interp);
|
||||
qDebug() << "BladeRF2Input::applySettings: set interpolation to " << (1<<settings.m_log2Interp);
|
||||
}
|
||||
|
||||
forwardChangeTxDSP = true;
|
||||
}
|
||||
|
||||
if (forwardChangeTxDSP)
|
||||
{
|
||||
int sampleRate = settings.m_sampleRate/(1<<settings.m_log2Interp);
|
||||
DSPMIMOSignalNotification *notif0 = new DSPMIMOSignalNotification(sampleRate, settings.m_centerFrequency, false, 0);
|
||||
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif0);
|
||||
DSPMIMOSignalNotification *notif1 = new DSPMIMOSignalNotification(sampleRate, settings.m_centerFrequency, false, 1);
|
||||
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif1);
|
||||
}
|
||||
|
||||
m_settings = settings;
|
||||
return true;
|
||||
}
|
||||
|
||||
int TestMOSync::webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage)
|
||||
{
|
||||
(void) errorMessage;
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
return 200;
|
||||
}
|
||||
|
||||
int TestMOSync::webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage)
|
||||
{
|
||||
(void) errorMessage;
|
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
||||
MsgStartStop *message = MsgStartStop::create(run, true); // TODO: Tx support
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue) // forward to GUI if any
|
||||
{
|
||||
MsgStartStop *msgToGUI = MsgStartStop::create(run, true); // TODO: Tx support
|
||||
m_guiMessageQueue->push(msgToGUI);
|
||||
}
|
||||
|
||||
return 200;
|
||||
}
|
||||
134
plugins/samplemimo/testmosync/testmosync.h
Normal file
134
plugins/samplemimo/testmosync/testmosync.h
Normal file
@ -0,0 +1,134 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNC_H_
|
||||
#define PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
|
||||
#include "dsp/devicesamplemimo.h"
|
||||
#include "testmosyncsettings.h"
|
||||
|
||||
class DeviceAPI;
|
||||
class TestMOSyncThread;
|
||||
|
||||
class TestMOSync : public DeviceSampleMIMO {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
class MsgConfigureTestMOSync : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
const TestMOSyncSettings& getSettings() const { return m_settings; }
|
||||
bool getForce() const { return m_force; }
|
||||
|
||||
static MsgConfigureTestMOSync* create(const TestMOSyncSettings& settings, bool force)
|
||||
{
|
||||
return new MsgConfigureTestMOSync(settings, force);
|
||||
}
|
||||
|
||||
private:
|
||||
TestMOSyncSettings m_settings;
|
||||
bool m_force;
|
||||
|
||||
MsgConfigureTestMOSync(const TestMOSyncSettings& settings, bool force) :
|
||||
Message(),
|
||||
m_settings(settings),
|
||||
m_force(force)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgStartStop : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
bool getStartStop() const { return m_startStop; }
|
||||
bool getRxElseTx() const { return m_rxElseTx; }
|
||||
|
||||
static MsgStartStop* create(bool startStop, bool rxElseTx) {
|
||||
return new MsgStartStop(startStop, rxElseTx);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool m_startStop;
|
||||
bool m_rxElseTx;
|
||||
|
||||
MsgStartStop(bool startStop, bool rxElseTx) :
|
||||
Message(),
|
||||
m_startStop(startStop),
|
||||
m_rxElseTx(rxElseTx)
|
||||
{ }
|
||||
};
|
||||
|
||||
TestMOSync(DeviceAPI *deviceAPI);
|
||||
virtual ~TestMOSync();
|
||||
virtual void destroy();
|
||||
|
||||
virtual void init();
|
||||
virtual bool startRx() {}
|
||||
virtual void stopRx() {}
|
||||
virtual bool startTx();
|
||||
virtual void stopTx();
|
||||
|
||||
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 getSourceSampleRate(int index) const;
|
||||
virtual void setSourceSampleRate(int sampleRate, int index) { (void) sampleRate; (void) index; }
|
||||
virtual quint64 getSourceCenterFrequency(int index) const;
|
||||
virtual void setSourceCenterFrequency(qint64 centerFrequency, int index);
|
||||
|
||||
virtual int getSinkSampleRate(int index) const;
|
||||
virtual void setSinkSampleRate(int sampleRate, int index) { (void) sampleRate; (void) index; }
|
||||
virtual quint64 getSinkCenterFrequency(int index) const;
|
||||
virtual void setSinkCenterFrequency(qint64 centerFrequency, int index);
|
||||
|
||||
virtual quint64 getMIMOCenterFrequency() const { return getSourceCenterFrequency(0); }
|
||||
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
virtual int webapiRunGet(
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
virtual int webapiRun(
|
||||
bool run,
|
||||
SWGSDRangel::SWGDeviceState& response,
|
||||
QString& errorMessage);
|
||||
|
||||
bool getRxRunning() const { return false; }
|
||||
bool getTxRunning() const { return m_runningTx; }
|
||||
|
||||
private:
|
||||
DeviceAPI *m_deviceAPI;
|
||||
QMutex m_mutex;
|
||||
TestMOSyncSettings m_settings;
|
||||
TestMOSyncThread* m_sinkThread;
|
||||
QString m_deviceDescription;
|
||||
bool m_runningTx;
|
||||
|
||||
bool applySettings(const TestMOSyncSettings& settings, bool force);
|
||||
};
|
||||
|
||||
#endif // PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNC_H_
|
||||
274
plugins/samplemimo/testmosync/testmosyncgui.cpp
Normal file
274
plugins/samplemimo/testmosync/testmosyncgui.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 "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 "testmosync.h"
|
||||
#include "ui_testmosyncgui.h"
|
||||
#include "testmosyncgui.h"
|
||||
|
||||
TestMOSyncGui::TestMOSyncGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::TestMOSyncGui),
|
||||
m_deviceUISet(deviceUISet),
|
||||
m_doApplySettings(true),
|
||||
m_forceSettings(true),
|
||||
m_settings(),
|
||||
m_sampleMIMO(nullptr),
|
||||
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_sampleMIMO = (TestMOSync*) m_deviceUISet->m_deviceAPI->getSampleMIMO();
|
||||
m_sampleMIMO->setMessageQueueToGUI(&m_inputMessageQueue);
|
||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
TestMOSyncGui::~TestMOSyncGui()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TestMOSyncGui::destroy()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
void TestMOSyncGui::setName(const QString& name)
|
||||
{
|
||||
setObjectName(name);
|
||||
}
|
||||
|
||||
QString TestMOSyncGui::getName() const
|
||||
{
|
||||
return objectName();
|
||||
}
|
||||
|
||||
void TestMOSyncGui::resetToDefaults()
|
||||
{
|
||||
m_settings.resetToDefaults();
|
||||
displaySettings();
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
qint64 TestMOSyncGui::getCenterFrequency() const
|
||||
{
|
||||
return m_settings.m_centerFrequency;
|
||||
}
|
||||
|
||||
void TestMOSyncGui::setCenterFrequency(qint64 centerFrequency)
|
||||
{
|
||||
m_settings.m_centerFrequency = centerFrequency;
|
||||
displaySettings();
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
QByteArray TestMOSyncGui::serialize() const
|
||||
{
|
||||
return m_settings.serialize();
|
||||
}
|
||||
|
||||
bool TestMOSyncGui::deserialize(const QByteArray& data)
|
||||
{
|
||||
if(m_settings.deserialize(data)) {
|
||||
displaySettings();
|
||||
m_forceSettings = true;
|
||||
sendSettings();
|
||||
return true;
|
||||
} else {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TestMOSyncGui::handleMessage(const Message& message)
|
||||
{
|
||||
if (TestMOSync::MsgConfigureTestMOSync::match(message))
|
||||
{
|
||||
qDebug("TestMOSyncGui::handleMessage: message: MsgConfigureTestMOSync");
|
||||
const TestMOSync::MsgConfigureTestMOSync& cfg = (TestMOSync::MsgConfigureTestMOSync&) message;
|
||||
m_settings = cfg.getSettings();
|
||||
blockApplySettings(true);
|
||||
displaySettings();
|
||||
blockApplySettings(false);
|
||||
return true;
|
||||
}
|
||||
else if (TestMOSync::MsgStartStop::match(message))
|
||||
{
|
||||
TestMOSync::MsgStartStop& notif = (TestMOSync::MsgStartStop&) message;
|
||||
qDebug("TestMOSyncGui::handleMessage: message: MsgStartStop: %s", notif.getStartStop() ? "start" : "stop");
|
||||
blockApplySettings(true);
|
||||
ui->startStop->setChecked(notif.getStartStop());
|
||||
blockApplySettings(false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void TestMOSyncGui::handleInputMessages()
|
||||
{
|
||||
Message* message;
|
||||
|
||||
while ((message = m_inputMessageQueue.pop()) != 0)
|
||||
{
|
||||
|
||||
if (DSPSignalNotification::match(*message))
|
||||
{
|
||||
DSPSignalNotification* notif = (DSPSignalNotification*) message;
|
||||
qDebug("TestMOSyncGui::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 TestMOSyncGui::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 TestMOSyncGui::displaySettings()
|
||||
{
|
||||
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
|
||||
ui->sampleRate->setValue(m_settings.m_sampleRate);
|
||||
}
|
||||
|
||||
void TestMOSyncGui::sendSettings()
|
||||
{
|
||||
if (!m_updateTimer.isActive()) {
|
||||
m_updateTimer.start(100);
|
||||
}
|
||||
}
|
||||
|
||||
void TestMOSyncGui::updateHardware()
|
||||
{
|
||||
qDebug() << "TestMOSyncGui::updateHardware";
|
||||
TestMOSync::MsgConfigureTestMOSync* message = TestMOSync::MsgConfigureTestMOSync::create(m_settings, m_forceSettings);
|
||||
m_sampleMIMO->getInputMessageQueue()->push(message);
|
||||
m_forceSettings = false;
|
||||
m_updateTimer.stop();
|
||||
}
|
||||
|
||||
void TestMOSyncGui::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 TestMOSyncGui::on_centerFrequency_changed(quint64 value)
|
||||
{
|
||||
m_settings.m_centerFrequency = value * 1000;
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
void TestMOSyncGui::on_sampleRate_changed(quint64 value)
|
||||
{
|
||||
m_settings.m_sampleRate = value;
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
void TestMOSyncGui::on_interp_currentIndexChanged(int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_settings.m_log2Interp = index;
|
||||
updateSampleRateAndFrequency();
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
void TestMOSyncGui::on_startStop_toggled(bool checked)
|
||||
{
|
||||
if (m_doApplySettings)
|
||||
{
|
||||
TestMOSync::MsgStartStop *message = TestMOSync::MsgStartStop::create(checked, false);
|
||||
m_sampleMIMO->getInputMessageQueue()->push(message);
|
||||
}
|
||||
}
|
||||
|
||||
void TestMOSyncGui::tick()
|
||||
{
|
||||
}
|
||||
90
plugins/samplemimo/testmosync/testmosyncgui.h
Normal file
90
plugins/samplemimo/testmosync/testmosyncgui.h
Normal file
@ -0,0 +1,90 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_TESTMOSYNCGUI_H
|
||||
#define INCLUDE_TESTMOSYNCGUI_H
|
||||
|
||||
#include <plugin/plugininstancegui.h>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "util/messagequeue.h"
|
||||
|
||||
#include "testmosyncsettings.h"
|
||||
|
||||
|
||||
class DeviceUISet;
|
||||
class TestMOSync;
|
||||
|
||||
namespace Ui {
|
||||
class TestMOSyncGui;
|
||||
}
|
||||
|
||||
class TestMOSyncGui : public QWidget, public PluginInstanceGUI {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TestMOSyncGui(DeviceUISet *deviceUISet, QWidget* parent = nullptr);
|
||||
virtual ~TestMOSyncGui();
|
||||
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::TestMOSyncGui* ui;
|
||||
|
||||
DeviceUISet* m_deviceUISet;
|
||||
bool m_doApplySettings;
|
||||
bool m_forceSettings;
|
||||
TestMOSyncSettings m_settings;
|
||||
QTimer m_updateTimer;
|
||||
QTimer m_statusTimer;
|
||||
TestMOSync* m_sampleMIMO;
|
||||
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 sendSettings();
|
||||
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_TESTMOSYNCGUI_H
|
||||
331
plugins/samplemimo/testmosync/testmosyncgui.ui
Normal file
331
plugins/samplemimo/testmosync/testmosyncgui.ui
Normal file
@ -0,0 +1,331 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TestMOSyncGui</class>
|
||||
<widget class="QWidget" name="TestMOSyncGui">
|
||||
<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 MO Sync</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string>Test MO Sync</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>
|
||||
145
plugins/samplemimo/testmosync/testmosyncplugin.cpp
Normal file
145
plugins/samplemimo/testmosync/testmosyncplugin.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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"
|
||||
|
||||
#ifndef SERVER_MODE
|
||||
#include "testmosyncgui.h"
|
||||
#endif
|
||||
#include "testmosync.h"
|
||||
#include "testmosyncplugin.h"
|
||||
|
||||
const PluginDescriptor TestMOSyncPlugin::m_pluginDescriptor = {
|
||||
QString("Test Synchronous Multiple Output"),
|
||||
QString("5.0.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
QString("https://github.com/f4exb/sdrangel")
|
||||
};
|
||||
|
||||
const QString TestMOSyncPlugin::m_hardwareID = "TestMOSync";
|
||||
const QString TestMOSyncPlugin::m_deviceTypeID = TESTMOSYNC_DEVICE_TYPE_ID;
|
||||
|
||||
TestMOSyncPlugin::TestMOSyncPlugin(QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
const PluginDescriptor& TestMOSyncPlugin::getPluginDescriptor() const
|
||||
{
|
||||
return m_pluginDescriptor;
|
||||
}
|
||||
|
||||
void TestMOSyncPlugin::initPlugin(PluginAPI* pluginAPI)
|
||||
{
|
||||
pluginAPI->registerSampleMIMO(m_deviceTypeID, this);
|
||||
}
|
||||
|
||||
void TestMOSyncPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices)
|
||||
{
|
||||
if (listedHwIds.contains(m_hardwareID)) { // check if it was done
|
||||
return;
|
||||
}
|
||||
|
||||
originDevices.append(OriginDevice(
|
||||
"TestMOSync", // Displayable name
|
||||
m_hardwareID, // Hardware ID
|
||||
QString(), // Serial
|
||||
0, // Sequence
|
||||
0, // Number of Rx streams
|
||||
2 // Number of Tx streams
|
||||
));
|
||||
|
||||
listedHwIds.append(m_hardwareID);
|
||||
}
|
||||
|
||||
PluginInterface::SamplingDevices TestMOSyncPlugin::enumSampleMIMO(const OriginDevices& originDevices)
|
||||
{
|
||||
SamplingDevices result;
|
||||
|
||||
for (OriginDevices::const_iterator it = originDevices.begin(); it != originDevices.end(); ++it)
|
||||
{
|
||||
if (it->hardwareId == m_hardwareID)
|
||||
{
|
||||
result.append(SamplingDevice(
|
||||
"TestMOSync",
|
||||
m_hardwareID,
|
||||
m_deviceTypeID,
|
||||
it->serial,
|
||||
it->sequence,
|
||||
PluginInterface::SamplingDevice::BuiltInDevice,
|
||||
PluginInterface::SamplingDevice::StreamMIMO,
|
||||
1, // MIMO is always considered as a single device
|
||||
0
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef SERVER_MODE
|
||||
PluginInstanceGUI* TestMOSyncPlugin::createSampleMIMOPluginInstanceGUI(
|
||||
const QString& sourceId,
|
||||
QWidget **widget,
|
||||
DeviceUISet *deviceUISet)
|
||||
{
|
||||
(void) sourceId;
|
||||
(void) widget;
|
||||
(void) deviceUISet;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
PluginInstanceGUI* TestMOSyncPlugin::createSampleMIMOPluginInstanceGUI(
|
||||
const QString& sourceId,
|
||||
QWidget **widget,
|
||||
DeviceUISet *deviceUISet)
|
||||
{
|
||||
if (sourceId == m_deviceTypeID)
|
||||
{
|
||||
TestMOSyncGui* gui = new TestMOSyncGui(deviceUISet);
|
||||
*widget = gui;
|
||||
return gui;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
DeviceSampleMIMO *TestMOSyncPlugin::createSampleMIMOPluginInstance(const QString& mimoId, DeviceAPI *deviceAPI)
|
||||
{
|
||||
if (mimoId == m_deviceTypeID)
|
||||
{
|
||||
TestMOSync* output = new TestMOSync(deviceAPI);
|
||||
return output;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceWebAPIAdapter *TestMOSyncPlugin::createDeviceWebAPIAdapter() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
55
plugins/samplemimo/testmosync/testmosyncplugin.h
Normal file
55
plugins/samplemimo/testmosync/testmosyncplugin.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 _TESTMOSYNC_TESTMOSYNCPLUGIN_H
|
||||
#define _TESTMOSYNC_TESTMOSYNCPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#include "plugin/plugininterface.h"
|
||||
|
||||
class PluginAPI;
|
||||
|
||||
#define TESTMOSYNC_DEVICE_TYPE_ID "sdrangel.samplemimo.testmosync"
|
||||
|
||||
class TestMOSyncPlugin : public QObject, public PluginInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(PluginInterface)
|
||||
Q_PLUGIN_METADATA(IID TESTMOSYNC_DEVICE_TYPE_ID)
|
||||
|
||||
public:
|
||||
explicit TestMOSyncPlugin(QObject* parent = nullptr);
|
||||
|
||||
const PluginDescriptor& getPluginDescriptor() const;
|
||||
void initPlugin(PluginAPI* pluginAPI);
|
||||
|
||||
virtual void enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices);
|
||||
virtual SamplingDevices enumSampleMIMO(const OriginDevices& originDevices);
|
||||
virtual PluginInstanceGUI* createSampleMIMOPluginInstanceGUI(
|
||||
const QString& sourceId,
|
||||
QWidget **widget,
|
||||
DeviceUISet *deviceUISet);
|
||||
virtual DeviceSampleMIMO* createSampleMIMOPluginInstance(const QString& sourceId, DeviceAPI *deviceAPI);
|
||||
virtual DeviceWebAPIAdapter* createDeviceWebAPIAdapter() const;
|
||||
|
||||
static const QString m_hardwareID;
|
||||
static const QString m_deviceTypeID;
|
||||
|
||||
private:
|
||||
static const PluginDescriptor m_pluginDescriptor;
|
||||
};
|
||||
|
||||
#endif // _TESTMI_TESTMIPLUGIN_H
|
||||
74
plugins/samplemimo/testmosync/testmosyncsettings.cpp
Normal file
74
plugins/samplemimo/testmosync/testmosyncsettings.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 "testmosyncsettings.h"
|
||||
|
||||
const unsigned int TestMOSyncSettings::m_msThrottle = 50U;
|
||||
const unsigned int TestMOSyncSettings::m_blockSize = 16384U;
|
||||
|
||||
TestMOSyncSettings::TestMOSyncSettings()
|
||||
{
|
||||
resetToDefaults();
|
||||
}
|
||||
|
||||
void TestMOSyncSettings::resetToDefaults()
|
||||
{
|
||||
m_centerFrequency = 435000*1000;
|
||||
m_sampleRate = 48000;
|
||||
m_log2Interp = 0;
|
||||
m_fcPosTx = FC_POS_CENTER;
|
||||
}
|
||||
|
||||
QByteArray TestMOSyncSettings::serialize() const
|
||||
{
|
||||
SimpleSerializer s(1);
|
||||
|
||||
s.writeU64(1, m_sampleRate);
|
||||
s.writeU32(2, m_log2Interp);
|
||||
s.writeS32(3, (int) m_fcPosTx);
|
||||
|
||||
return s.final();
|
||||
}
|
||||
|
||||
bool TestMOSyncSettings::deserialize(const QByteArray& data)
|
||||
{
|
||||
SimpleDeserializer d(data);
|
||||
|
||||
if (!d.isValid())
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (d.getVersion() == 1)
|
||||
{
|
||||
int intval;
|
||||
|
||||
d.readU64(1, &m_sampleRate, 48000);
|
||||
d.readU32(2, &m_log2Interp, 0);
|
||||
d.readS32(38, &intval, 2);
|
||||
m_fcPosTx = (fcPos_t) intval;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
44
plugins/samplemimo/testmosync/testmosyncsettings.h
Normal file
44
plugins/samplemimo/testmosync/testmosyncsettings.h
Normal file
@ -0,0 +1,44 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNCSETTINGS_H_
|
||||
#define PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNCSETTINGS_H_
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
struct TestMOSyncSettings {
|
||||
typedef enum {
|
||||
FC_POS_INFRA = 0,
|
||||
FC_POS_SUPRA,
|
||||
FC_POS_CENTER
|
||||
} fcPos_t;
|
||||
|
||||
quint64 m_centerFrequency;
|
||||
quint64 m_sampleRate;
|
||||
quint32 m_log2Interp;
|
||||
fcPos_t m_fcPosTx;
|
||||
|
||||
static const unsigned int m_msThrottle;
|
||||
static const unsigned int m_blockSize;
|
||||
|
||||
TestMOSyncSettings();
|
||||
void resetToDefaults();
|
||||
QByteArray serialize() const;
|
||||
bool deserialize(const QByteArray& data);
|
||||
};
|
||||
|
||||
#endif /* PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNCSETTINGS_H_ */
|
||||
290
plugins/samplemimo/testmosync/testmosyncthread.cpp
Normal file
290
plugins/samplemimo/testmosync/testmosyncthread.cpp
Normal file
@ -0,0 +1,290 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
#include "dsp/samplemofifo.h"
|
||||
|
||||
#include "testmosyncsettings.h"
|
||||
#include "testmosyncthread.h"
|
||||
|
||||
TestMOSyncThread::TestMOSyncThread(QObject* parent) :
|
||||
QThread(parent),
|
||||
m_running(false),
|
||||
m_log2Interp(0),
|
||||
m_throttlems(TestMOSyncSettings::m_msThrottle),
|
||||
m_throttleToggle(false),
|
||||
m_samplesRemainder(0)
|
||||
{
|
||||
qDebug("TestMOSyncThread::TestMOSyncThread");
|
||||
m_buf = new qint16[2*TestMOSyncSettings::m_blockSize*2];
|
||||
}
|
||||
|
||||
TestMOSyncThread::~TestMOSyncThread()
|
||||
{
|
||||
qDebug("TestMOSyncThread::~TestMOSyncThread");
|
||||
|
||||
if (m_running) {
|
||||
stopWork();
|
||||
}
|
||||
|
||||
delete[] m_buf;
|
||||
}
|
||||
|
||||
void TestMOSyncThread::startWork()
|
||||
{
|
||||
m_startWaitMutex.lock();
|
||||
m_elapsedTimer.start();
|
||||
start();
|
||||
|
||||
while(!m_running) {
|
||||
m_startWaiter.wait(&m_startWaitMutex, 100);
|
||||
}
|
||||
|
||||
m_startWaitMutex.unlock();
|
||||
}
|
||||
|
||||
void TestMOSyncThread::stopWork()
|
||||
{
|
||||
m_running = false;
|
||||
wait();
|
||||
}
|
||||
|
||||
void TestMOSyncThread::run()
|
||||
{
|
||||
m_running = true;
|
||||
m_startWaiter.wakeAll();
|
||||
|
||||
while(m_running) // actual work is in the tick() function
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void TestMOSyncThread::connectTimer(const QTimer& timer)
|
||||
{
|
||||
qDebug() << "TestMOSyncThread::connectTimer";
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||
}
|
||||
|
||||
void TestMOSyncThread::setSamplerate(int samplerate)
|
||||
{
|
||||
if (samplerate != m_samplerate)
|
||||
{
|
||||
qDebug() << "TestMOSyncThread::setSamplerate:"
|
||||
<< " new:" << samplerate
|
||||
<< " old:" << m_samplerate;
|
||||
|
||||
bool wasRunning = false;
|
||||
|
||||
if (m_running)
|
||||
{
|
||||
stopWork();
|
||||
wasRunning = true;
|
||||
}
|
||||
|
||||
m_samplerate = samplerate;
|
||||
m_samplesChunkSize = (m_samplerate * m_throttlems) / 1000;
|
||||
|
||||
if (wasRunning) {
|
||||
startWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestMOSyncThread::setLog2Interpolation(unsigned int log2Interpolation)
|
||||
{
|
||||
if ((log2Interpolation < 0) || (log2Interpolation > 6)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (log2Interpolation != m_log2Interp)
|
||||
{
|
||||
qDebug() << "TestSinkThread::setLog2Interpolation:"
|
||||
<< " new:" << log2Interpolation
|
||||
<< " old:" << m_log2Interp;
|
||||
|
||||
bool wasRunning = false;
|
||||
|
||||
if (m_running)
|
||||
{
|
||||
stopWork();
|
||||
wasRunning = true;
|
||||
}
|
||||
|
||||
m_log2Interp = log2Interpolation;
|
||||
|
||||
if (wasRunning) {
|
||||
startWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int TestMOSyncThread::getLog2Interpolation() const
|
||||
{
|
||||
return m_log2Interp;
|
||||
}
|
||||
|
||||
void TestMOSyncThread::setFcPos(int fcPos)
|
||||
{
|
||||
m_fcPos = fcPos;
|
||||
}
|
||||
|
||||
int TestMOSyncThread::getFcPos() const
|
||||
{
|
||||
return m_fcPos;
|
||||
}
|
||||
|
||||
void TestMOSyncThread::callback(qint16* buf, qint32 samplesPerChannel)
|
||||
{
|
||||
unsigned int iPart1Begin, iPart1End, iPart2Begin, iPart2End;
|
||||
m_sampleFifo->readSync(samplesPerChannel/(1<<m_log2Interp), iPart1Begin, iPart1End, iPart2Begin, iPart2End);
|
||||
|
||||
if (iPart1Begin != iPart1End)
|
||||
{
|
||||
callbackPart(buf, samplesPerChannel, iPart1Begin, iPart1End - iPart1Begin);
|
||||
}
|
||||
|
||||
if (iPart2Begin != iPart2End)
|
||||
{
|
||||
unsigned int part1Size = iPart1End - iPart1End;
|
||||
callbackPart(buf + 2*part1Size, samplesPerChannel, iPart2Begin, iPart2End - iPart2Begin);
|
||||
}
|
||||
}
|
||||
|
||||
// Interpolate according to specified log2 (ex: log2=4 => decim=16). len is a number of samples (not a number of I or Q)
|
||||
void TestMOSyncThread::callbackPart(qint16* buf, qint32 samplesPerChannel, int iBegin, qint32 nSamples)
|
||||
{
|
||||
for (unsigned int channel = 0; channel < 2; channel++)
|
||||
{
|
||||
SampleVector::iterator begin = m_sampleFifo->getData(channel).begin() + iBegin;
|
||||
|
||||
if (m_log2Interp == 0)
|
||||
{
|
||||
m_interpolators[channel].interpolate1(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_fcPos == 0) // Infra
|
||||
{
|
||||
switch (m_log2Interp)
|
||||
{
|
||||
case 1:
|
||||
m_interpolators[channel].interpolate2_inf(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 2:
|
||||
m_interpolators[channel].interpolate4_inf(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 3:
|
||||
m_interpolators[channel].interpolate8_inf(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 4:
|
||||
m_interpolators[channel].interpolate16_inf(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 5:
|
||||
m_interpolators[channel].interpolate32_inf(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 6:
|
||||
m_interpolators[channel].interpolate64_inf(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_fcPos == 1) // Supra
|
||||
{
|
||||
switch (m_log2Interp)
|
||||
{
|
||||
case 1:
|
||||
m_interpolators[channel].interpolate2_sup(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 2:
|
||||
m_interpolators[channel].interpolate4_sup(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 3:
|
||||
m_interpolators[channel].interpolate8_sup(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 4:
|
||||
m_interpolators[channel].interpolate16_sup(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 5:
|
||||
m_interpolators[channel].interpolate32_sup(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 6:
|
||||
m_interpolators[channel].interpolate64_sup(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (m_fcPos == 2) // Center
|
||||
{
|
||||
switch (m_log2Interp)
|
||||
{
|
||||
case 1:
|
||||
m_interpolators[channel].interpolate2_cen(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 2:
|
||||
m_interpolators[channel].interpolate4_cen(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 3:
|
||||
m_interpolators[channel].interpolate8_cen(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 4:
|
||||
m_interpolators[channel].interpolate16_cen(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 5:
|
||||
m_interpolators[channel].interpolate32_cen(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
case 6:
|
||||
m_interpolators[channel].interpolate64_cen(&begin, &buf[channel*2*samplesPerChannel], nSamples*2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestMOSyncThread::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;
|
||||
}
|
||||
|
||||
int chunkSize = std::min((int) m_samplesChunkSize, m_samplerate) + m_samplesRemainder;
|
||||
|
||||
while (chunkSize >= TestMOSyncSettings::m_blockSize)
|
||||
{
|
||||
callback(m_buf, TestMOSyncSettings::m_blockSize);
|
||||
chunkSize -= TestMOSyncSettings::m_blockSize;
|
||||
}
|
||||
|
||||
m_samplesRemainder = chunkSize;
|
||||
}
|
||||
}
|
||||
81
plugins/samplemimo/testmosync/testmosyncthread.h
Normal file
81
plugins/samplemimo/testmosync/testmosyncthread.h
Normal file
@ -0,0 +1,81 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNCTHREAD_H_
|
||||
#define PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNCTHREAD_H_
|
||||
|
||||
// configure two Tx
|
||||
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "dsp/interpolators.h"
|
||||
|
||||
#define TESTMOSYNC_THROTTLE_MS 50
|
||||
|
||||
class QTimer;
|
||||
class SampleMOFifo;
|
||||
|
||||
class TestMOSyncThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TestMOSyncThread(QObject* parent = nullptr);
|
||||
~TestMOSyncThread();
|
||||
|
||||
void startWork();
|
||||
void stopWork();
|
||||
bool isRunning() const { return m_running; }
|
||||
void setSamplerate(int samplerate);
|
||||
void setLog2Interpolation(unsigned int log2_interp);
|
||||
unsigned int getLog2Interpolation() const;
|
||||
void setFcPos(int fcPos);
|
||||
int getFcPos() const;
|
||||
void setFifo(SampleMOFifo *sampleFifo) { m_sampleFifo = sampleFifo; }
|
||||
SampleMOFifo *getFifo() { return m_sampleFifo; }
|
||||
void connectTimer(const QTimer& timer);
|
||||
|
||||
private:
|
||||
QMutex m_startWaitMutex;
|
||||
QWaitCondition m_startWaiter;
|
||||
bool m_running;
|
||||
|
||||
qint16 *m_buf; //!< Full buffer for SISO or MIMO operation
|
||||
SampleMOFifo* m_sampleFifo;
|
||||
Interpolators<qint16, SDR_TX_SAMP_SZ, 12> m_interpolators[2];
|
||||
unsigned int m_log2Interp;
|
||||
int m_fcPos;
|
||||
|
||||
int m_throttlems;
|
||||
QElapsedTimer m_elapsedTimer;
|
||||
bool m_throttleToggle;
|
||||
unsigned int m_samplesChunkSize;
|
||||
unsigned int m_samplesRemainder;
|
||||
int m_samplerate;
|
||||
|
||||
void run();
|
||||
unsigned int getNbFifos();
|
||||
void callbackPart(qint16* buf, qint32 samplesPerChannel, int iBegin, qint32 nSamples);
|
||||
void callback(qint16* buf, qint32 samplesPerChannel);
|
||||
|
||||
private slots:
|
||||
void tick();
|
||||
};
|
||||
|
||||
#endif // PLUGINS_SAMPLEMIMO_TESTMOSYNC_TESTMOSYNCTHREAD_H_
|
||||
Loading…
x
Reference in New Issue
Block a user