14 changed files with 2508 additions and 3 deletions
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
project(testsource) |
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
||||
|
||||
set(testsource_SOURCES |
||||
testsourcegui.cpp |
||||
testsourceinput.cpp |
||||
testsourceplugin.cpp |
||||
testsourcethread.cpp |
||||
testsourcesettings.cpp |
||||
) |
||||
|
||||
set(testsource_HEADERS |
||||
testsourcegui.h |
||||
testsourceinput.h |
||||
testsourceplugin.h |
||||
testsourcethread.h |
||||
testsourcesettings.h |
||||
) |
||||
|
||||
set(testsource_FORMS |
||||
testsourcegui.ui |
||||
) |
||||
|
||||
include_directories( |
||||
. |
||||
${CMAKE_CURRENT_BINARY_DIR} |
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client |
||||
) |
||||
|
||||
#include(${QT_USE_FILE}) |
||||
add_definitions(${QT_DEFINITIONS}) |
||||
add_definitions(-DQT_PLUGIN) |
||||
add_definitions(-DQT_SHARED) |
||||
|
||||
#qt4_wrap_cpp(testsource_HEADERS_MOC ${testsource_HEADERS}) |
||||
qt5_wrap_ui(testsource_FORMS_HEADERS ${testsource_FORMS}) |
||||
|
||||
add_library(inputtestsource SHARED |
||||
${testsource_SOURCES} |
||||
${testsource_HEADERS_MOC} |
||||
${testsource_FORMS_HEADERS} |
||||
) |
||||
|
||||
target_link_libraries(inputtestsource |
||||
${QT_LIBRARIES} |
||||
sdrbase |
||||
sdrgui |
||||
swagger |
||||
) |
||||
|
||||
qt5_use_modules(inputtestsource Core Widgets) |
||||
|
||||
install(TARGETS inputtestsource DESTINATION lib/plugins/samplesource) |
||||
@ -0,0 +1,424 @@
@@ -0,0 +1,424 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QDebug> |
||||
|
||||
#include <QTime> |
||||
#include <QDateTime> |
||||
#include <QString> |
||||
#include <QFileDialog> |
||||
#include <QMessageBox> |
||||
|
||||
#include "ui_testsourcegui.h" |
||||
#include "plugin/pluginapi.h" |
||||
#include "gui/colormapper.h" |
||||
#include "gui/glspectrum.h" |
||||
#include "dsp/dspengine.h" |
||||
#include "dsp/dspcommands.h" |
||||
#include "util/db.h" |
||||
|
||||
#include "mainwindow.h" |
||||
|
||||
#include "testsourcegui.h" |
||||
#include <device/devicesourceapi.h> |
||||
#include "device/deviceuiset.h" |
||||
|
||||
TestSourceGui::TestSourceGui(DeviceUISet *deviceUISet, QWidget* parent) : |
||||
QWidget(parent), |
||||
ui(new Ui::TestSourceGui), |
||||
m_deviceUISet(deviceUISet), |
||||
m_settings(), |
||||
m_doApplySettings(true), |
||||
m_forceSettings(true), |
||||
m_sampleSource(0), |
||||
m_sampleRate(0), |
||||
m_centerFrequency(0), |
||||
m_tickCount(0), |
||||
m_lastEngineState((DSPDeviceSourceEngine::State)-1) |
||||
{ |
||||
qDebug("TestSourceGui::TestSourceGui"); |
||||
m_sampleSource = m_deviceUISet->m_deviceSourceAPI->getSampleSource(); |
||||
|
||||
ui->setupUi(this); |
||||
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); |
||||
ui->centerFrequency->setValueRange(7, 0, 9999999); |
||||
ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow)); |
||||
ui->sampleRate->setValueRange(7, 48000, 9999999); |
||||
ui->frequencyShift->setColorMapper(ColorMapper(ColorMapper::GrayGold)); |
||||
ui->frequencyShift->setValueRange(false, 7, -9999999, 9999999); |
||||
|
||||
displaySettings(); |
||||
|
||||
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); |
||||
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); |
||||
m_statusTimer.start(500); |
||||
|
||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); |
||||
} |
||||
|
||||
TestSourceGui::~TestSourceGui() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void TestSourceGui::destroy() |
||||
{ |
||||
delete this; |
||||
} |
||||
|
||||
void TestSourceGui::setName(const QString& name) |
||||
{ |
||||
setObjectName(name); |
||||
} |
||||
|
||||
QString TestSourceGui::getName() const |
||||
{ |
||||
return objectName(); |
||||
} |
||||
|
||||
void TestSourceGui::resetToDefaults() |
||||
{ |
||||
m_settings.resetToDefaults(); |
||||
displaySettings(); |
||||
sendSettings(); |
||||
} |
||||
|
||||
qint64 TestSourceGui::getCenterFrequency() const |
||||
{ |
||||
return m_centerFrequency; |
||||
} |
||||
|
||||
void TestSourceGui::setCenterFrequency(qint64 centerFrequency) |
||||
{ |
||||
m_centerFrequency = centerFrequency; |
||||
displaySettings(); |
||||
sendSettings(); |
||||
} |
||||
|
||||
QByteArray TestSourceGui::serialize() const |
||||
{ |
||||
return m_settings.serialize(); |
||||
} |
||||
|
||||
bool TestSourceGui::deserialize(const QByteArray& data) |
||||
{ |
||||
if(m_settings.deserialize(data)) { |
||||
displaySettings(); |
||||
m_forceSettings = true; |
||||
sendSettings(); |
||||
return true; |
||||
} else { |
||||
resetToDefaults(); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
void TestSourceGui::on_startStop_toggled(bool checked) |
||||
{ |
||||
if (m_doApplySettings) |
||||
{ |
||||
TestSourceInput::MsgStartStop *message = TestSourceInput::MsgStartStop::create(checked); |
||||
m_sampleSource->getInputMessageQueue()->push(message); |
||||
} |
||||
} |
||||
|
||||
void TestSourceGui::on_centerFrequency_changed(quint64 value) |
||||
{ |
||||
m_settings.m_centerFrequency = value * 1000; |
||||
sendSettings(); |
||||
} |
||||
|
||||
void TestSourceGui::on_frequencyShift_changed(qint64 value) |
||||
{ |
||||
m_settings.m_frequencyShift = value; |
||||
sendSettings(); |
||||
} |
||||
|
||||
void TestSourceGui::on_decimation_currentIndexChanged(int index) |
||||
{ |
||||
if ((index < 0) || (index > 6)) { |
||||
return; |
||||
} |
||||
|
||||
m_settings.m_log2Decim = index; |
||||
sendSettings(); |
||||
} |
||||
|
||||
void TestSourceGui::on_fcPos_currentIndexChanged(int index) |
||||
{ |
||||
if ((index < 0) || (index > 2)) { |
||||
return; |
||||
} |
||||
|
||||
m_settings.m_fcPos = (TestSourceSettings::fcPos_t) index; |
||||
sendSettings(); |
||||
} |
||||
|
||||
void TestSourceGui::on_sampleRate_changed(quint64 value) |
||||
{ |
||||
updateFrequencyShiftLimit(); |
||||
m_settings.m_frequencyShift = ui->frequencyShift->getValueNew(); |
||||
m_settings.m_sampleRate = value; |
||||
sendSettings(); |
||||
} |
||||
|
||||
void TestSourceGui::on_sampleSize_currentIndexChanged(int index) |
||||
{ |
||||
if ((index < 0) || (index > 2)) { |
||||
return; |
||||
} |
||||
|
||||
updateAmpCoarseLimit(); |
||||
updateAmpFineLimit(); |
||||
displayAmplitude(); |
||||
m_settings.m_amplitudeBits = ui->amplitudeCoarse->value() * 100 + ui->amplitudeFine->value(); |
||||
m_settings.m_sampleSizeIndex = index; |
||||
sendSettings(); |
||||
} |
||||
|
||||
void TestSourceGui::on_amplitudeCoarse_valueChanged(int value __attribute__((unused))) |
||||
{ |
||||
updateAmpFineLimit(); |
||||
displayAmplitude(); |
||||
m_settings.m_amplitudeBits = ui->amplitudeCoarse->value() * 100 + ui->amplitudeFine->value(); |
||||
sendSettings(); |
||||
} |
||||
|
||||
void TestSourceGui::on_amplitudeFine_valueChanged(int value __attribute__((unused))) |
||||
{ |
||||
displayAmplitude(); |
||||
m_settings.m_amplitudeBits = ui->amplitudeCoarse->value() * 100 + ui->amplitudeFine->value(); |
||||
sendSettings(); |
||||
} |
||||
|
||||
void TestSourceGui::on_record_toggled(bool checked) |
||||
{ |
||||
if (checked) { |
||||
ui->record->setStyleSheet("QToolButton { background-color : red; }"); |
||||
} else { |
||||
ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); |
||||
} |
||||
|
||||
TestSourceInput::MsgFileRecord* message = TestSourceInput::MsgFileRecord::create(checked); |
||||
m_sampleSource->getInputMessageQueue()->push(message); |
||||
} |
||||
|
||||
void TestSourceGui::displayAmplitude() |
||||
{ |
||||
int amplitudeInt = ui->amplitudeCoarse->value() * 100 + ui->amplitudeFine->value(); |
||||
double power; |
||||
|
||||
switch (ui->sampleSize->currentIndex()) |
||||
{ |
||||
case 0: // 8 bits: 128
|
||||
power = (double) amplitudeInt*amplitudeInt / (double) (1<<14); |
||||
break; |
||||
case 1: // 12 bits 2048
|
||||
power = (double) amplitudeInt*amplitudeInt / (double) (1<<22); |
||||
break; |
||||
case 2: // 16 bits 32768
|
||||
default: |
||||
power = (double) amplitudeInt*amplitudeInt / (double) (1<<30); |
||||
break; |
||||
} |
||||
|
||||
ui->amplitudeBits->setText(QString(tr("%1 b").arg(amplitudeInt))); |
||||
double powerDb = CalcDb::dbPower(power); |
||||
ui->power->setText(QString(tr("%1 dB").arg(QString::number(powerDb, 'f', 1)))); |
||||
} |
||||
|
||||
void TestSourceGui::updateAmpCoarseLimit() |
||||
{ |
||||
switch (ui->sampleSize->currentIndex()) |
||||
{ |
||||
case 0: // 8 bits: 128
|
||||
ui->amplitudeCoarse->setMaximum(1); |
||||
break; |
||||
case 1: // 12 bits 2048
|
||||
ui->amplitudeCoarse->setMaximum(20); |
||||
break; |
||||
case 2: // 16 bits 32768
|
||||
default: |
||||
ui->amplitudeCoarse->setMaximum(327); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void TestSourceGui::updateAmpFineLimit() |
||||
{ |
||||
switch (ui->sampleSize->currentIndex()) |
||||
{ |
||||
case 0: // 8 bits: 128
|
||||
if (ui->amplitudeCoarse->value() == 1) { |
||||
ui->amplitudeFine->setMaximum(27); |
||||
} else { |
||||
ui->amplitudeFine->setMaximum(99); |
||||
} |
||||
break; |
||||
case 1: // 12 bits 2048
|
||||
if (ui->amplitudeCoarse->value() == 20) { |
||||
ui->amplitudeFine->setMaximum(47); |
||||
} else { |
||||
ui->amplitudeFine->setMaximum(99); |
||||
} |
||||
break; |
||||
case 2: // 16 bits 32768
|
||||
default: |
||||
if (ui->amplitudeCoarse->value() == 327) { |
||||
ui->amplitudeFine->setMaximum(67); |
||||
} else { |
||||
ui->amplitudeFine->setMaximum(99); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void TestSourceGui::updateFrequencyShiftLimit() |
||||
{ |
||||
int sampleRate = ui->sampleRate->getValueNew(); |
||||
ui->frequencyShift->setValueRange(false, 7, -sampleRate, sampleRate); |
||||
} |
||||
|
||||
void TestSourceGui::displaySettings() |
||||
{ |
||||
blockApplySettings(true); |
||||
|
||||
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); |
||||
ui->decimation->setCurrentIndex(m_settings.m_log2Decim); |
||||
ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos); |
||||
ui->sampleRate->setValue(m_settings.m_sampleRate); |
||||
updateFrequencyShiftLimit(); |
||||
ui->frequencyShift->setValue(m_settings.m_frequencyShift); |
||||
ui->sampleSize->setCurrentIndex(m_settings.m_sampleSizeIndex); |
||||
updateAmpCoarseLimit(); |
||||
int amplitudeBits = m_settings.m_amplitudeBits; |
||||
ui->amplitudeCoarse->setValue(amplitudeBits/100); |
||||
updateAmpFineLimit(); |
||||
ui->amplitudeFine->setValue(amplitudeBits%100); |
||||
displayAmplitude(); |
||||
|
||||
blockApplySettings(false); |
||||
} |
||||
|
||||
void TestSourceGui::sendSettings() |
||||
{ |
||||
if(!m_updateTimer.isActive()) { |
||||
m_updateTimer.start(100); |
||||
} |
||||
} |
||||
|
||||
void TestSourceGui::updateHardware() |
||||
{ |
||||
if (m_doApplySettings) |
||||
{ |
||||
TestSourceInput::MsgConfigureTestSource* message = TestSourceInput::MsgConfigureTestSource::create(m_settings, m_forceSettings); |
||||
m_sampleSource->getInputMessageQueue()->push(message); |
||||
m_forceSettings = false; |
||||
m_updateTimer.stop(); |
||||
} |
||||
} |
||||
|
||||
void TestSourceGui::updateStatus() |
||||
{ |
||||
int state = m_deviceUISet->m_deviceSourceAPI->state(); |
||||
|
||||
if(m_lastEngineState != state) |
||||
{ |
||||
switch(state) |
||||
{ |
||||
case DSPDeviceSourceEngine::StNotStarted: |
||||
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); |
||||
break; |
||||
case DSPDeviceSourceEngine::StIdle: |
||||
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }"); |
||||
break; |
||||
case DSPDeviceSourceEngine::StRunning: |
||||
ui->startStop->setStyleSheet("QToolButton { background-color : green; }"); |
||||
break; |
||||
case DSPDeviceSourceEngine::StError: |
||||
ui->startStop->setStyleSheet("QToolButton { background-color : red; }"); |
||||
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceSourceAPI->errorMessage()); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
m_lastEngineState = state; |
||||
} |
||||
} |
||||
|
||||
bool TestSourceGui::handleMessage(const Message& message) |
||||
{ |
||||
if (TestSourceInput::MsgConfigureTestSource::match(message)) |
||||
{ |
||||
qDebug("TestSourceGui::handleMessage: MsgConfigureTestSource"); |
||||
const TestSourceInput::MsgConfigureTestSource& cfg = (TestSourceInput::MsgConfigureTestSource&) message; |
||||
m_settings = cfg.getSettings(); |
||||
displaySettings(); |
||||
return true; |
||||
} |
||||
else if (TestSourceInput::MsgStartStop::match(message)) |
||||
{ |
||||
qDebug("TestSourceGui::handleMessage: MsgStartStop"); |
||||
TestSourceInput::MsgStartStop& notif = (TestSourceInput::MsgStartStop&) message; |
||||
blockApplySettings(true); |
||||
ui->startStop->setChecked(notif.getStartStop()); |
||||
blockApplySettings(false); |
||||
|
||||
return true; |
||||
} |
||||
else |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
void TestSourceGui::handleInputMessages() |
||||
{ |
||||
Message* message; |
||||
|
||||
while ((message = m_inputMessageQueue.pop()) != 0) |
||||
{ |
||||
if (DSPSignalNotification::match(*message)) |
||||
{ |
||||
DSPSignalNotification* notif = (DSPSignalNotification*) message; |
||||
m_deviceSampleRate = notif->getSampleRate(); |
||||
m_deviceCenterFrequency = notif->getCenterFrequency(); |
||||
qDebug("TestSourceGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", |
||||
notif->getSampleRate(), |
||||
notif->getCenterFrequency()); |
||||
updateSampleRateAndFrequency(); |
||||
|
||||
delete message; |
||||
} |
||||
else |
||||
{ |
||||
if (handleMessage(*message)) |
||||
{ |
||||
delete message; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void TestSourceGui::updateSampleRateAndFrequency() |
||||
{ |
||||
m_deviceUISet->getSpectrum()->setSampleRate(m_deviceSampleRate); |
||||
m_deviceUISet->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency); |
||||
ui->deviceRateText->setText(tr("%1k").arg((float)m_deviceSampleRate / 1000)); |
||||
} |
||||
|
||||
|
||||
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _TESTSOURCE_TESTSOURCEGUI_H_ |
||||
#define _TESTSOURCE_TESTSOURCEGUI_H_ |
||||
|
||||
#include <plugin/plugininstancegui.h> |
||||
#include <QTimer> |
||||
#include <QWidget> |
||||
|
||||
#include "util/messagequeue.h" |
||||
|
||||
#include "testsourcesettings.h" |
||||
#include "testsourceinput.h" |
||||
|
||||
class DeviceUISet; |
||||
|
||||
namespace Ui { |
||||
class TestSourceGui; |
||||
} |
||||
|
||||
class TestSourceGui : public QWidget, public PluginInstanceGUI { |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit TestSourceGui(DeviceUISet *deviceUISet, QWidget* parent = 0); |
||||
virtual ~TestSourceGui(); |
||||
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::TestSourceGui* ui; |
||||
|
||||
DeviceUISet* m_deviceUISet; |
||||
TestSourceSettings m_settings; |
||||
QTimer m_updateTimer; |
||||
QTimer m_statusTimer; |
||||
bool m_doApplySettings; |
||||
bool m_forceSettings; |
||||
DeviceSampleSource* m_sampleSource; |
||||
int m_sampleRate; |
||||
quint64 m_centerFrequency; |
||||
std::size_t m_tickCount; |
||||
int m_deviceSampleRate; |
||||
quint64 m_deviceCenterFrequency; //!< Center frequency in device
|
||||
int m_lastEngineState; |
||||
MessageQueue m_inputMessageQueue; |
||||
|
||||
void blockApplySettings(bool block) { m_doApplySettings = !block; } |
||||
void displaySettings(); |
||||
void sendSettings(); |
||||
void updateSampleRateAndFrequency(); |
||||
void displayAmplitude(); |
||||
void updateAmpCoarseLimit(); |
||||
void updateAmpFineLimit(); |
||||
void updateFrequencyShiftLimit(); |
||||
|
||||
private slots: |
||||
void handleInputMessages(); |
||||
void on_startStop_toggled(bool checked); |
||||
void on_centerFrequency_changed(quint64 value); |
||||
void on_frequencyShift_changed(qint64 value); |
||||
void on_decimation_currentIndexChanged(int index); |
||||
void on_fcPos_currentIndexChanged(int index); |
||||
void on_sampleRate_changed(quint64 value); |
||||
void on_sampleSize_currentIndexChanged(int index); |
||||
void on_amplitudeCoarse_valueChanged(int value); |
||||
void on_amplitudeFine_valueChanged(int value); |
||||
void on_record_toggled(bool checked); |
||||
void updateStatus(); |
||||
void updateHardware(); |
||||
void tick(); |
||||
}; |
||||
|
||||
#endif // _TESTSOURCE_TESTSOURCEGUI_H_
|
||||
@ -0,0 +1,614 @@
@@ -0,0 +1,614 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>TestSourceGui</class> |
||||
<widget class="QWidget" name="TestSourceGui"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>360</width> |
||||
<height>220</height> |
||||
</rect> |
||||
</property> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>360</width> |
||||
<height>220</height> |
||||
</size> |
||||
</property> |
||||
<property name="font"> |
||||
<font> |
||||
<family>Sans Serif</family> |
||||
<pointsize>9</pointsize> |
||||
</font> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Test source</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>4</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 acquisition</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> |
||||
<item> |
||||
<widget class="ButtonSwitch" name="record"> |
||||
<property name="toolTip"> |
||||
<string>Toggle record I/Q samples from device</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../../../sdrgui/resources/res.qrc"> |
||||
<normaloff>:/record_off.png</normaloff>:/record_off.png</iconset> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="deviceRateLayout"> |
||||
<item> |
||||
<widget class="QLabel" name="deviceRateText"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>58</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>I/Q sample rate kS/s</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>0000.00k</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<spacer name="horizontalSpacer"> |
||||
<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="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>DejaVu Sans 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>Tuner 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="horizontalSpacer_2"> |
||||
<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_2"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="frequencyShiftLayout"> |
||||
<item> |
||||
<widget class="QLabel" name="frequencyShiftLabel"> |
||||
<property name="text"> |
||||
<string>Shift</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="ValueDialZ" name="frequencyShift" 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>DejaVu Sans Mono</family> |
||||
<pointsize>12</pointsize> |
||||
<italic>false</italic> |
||||
</font> |
||||
</property> |
||||
<property name="cursor"> |
||||
<cursorShape>PointingHandCursor</cursorShape> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Shift from center frequency</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="frequencyShiftUnits"> |
||||
<property name="text"> |
||||
<string>Hz</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<spacer name="horizontalSpacer_3"> |
||||
<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="QLabel" name="decimationLabel"> |
||||
<property name="text"> |
||||
<string>Dec</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QComboBox" name="decimation"> |
||||
<property name="maximumSize"> |
||||
<size> |
||||
<width>45</width> |
||||
<height>16777215</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Decimation factor</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="fcPosLabel"> |
||||
<property name="text"> |
||||
<string>Fp</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QComboBox" name="fcPos"> |
||||
<property name="maximumSize"> |
||||
<size> |
||||
<width>50</width> |
||||
<height>16777215</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Relative postion of generator center frequency</string> |
||||
</property> |
||||
<property name="currentIndex"> |
||||
<number>2</number> |
||||
</property> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Inf</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Sup</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Cen</string> |
||||
</property> |
||||
</item> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<widget class="Line" name="line_4"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="sampleRateLayout"> |
||||
<property name="topMargin"> |
||||
<number>2</number> |
||||
</property> |
||||
<property name="bottomMargin"> |
||||
<number>2</number> |
||||
</property> |
||||
<item> |
||||
<widget class="QLabel" name="samplerateLabel"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>28</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<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>DejaVu Sans Mono</family> |
||||
<pointsize>12</pointsize> |
||||
</font> |
||||
</property> |
||||
<property name="cursor"> |
||||
<cursorShape>PointingHandCursor</cursorShape> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Generator sample rate (S/s)</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="sampleRateUnit"> |
||||
<property name="text"> |
||||
<string>S/s</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="Line" name="line"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Vertical</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="sampleSzieLabel"> |
||||
<property name="text"> |
||||
<string>size</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QComboBox" name="sampleSize"> |
||||
<property name="maximumSize"> |
||||
<size> |
||||
<width>45</width> |
||||
<height>16777215</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Sample size</string> |
||||
</property> |
||||
<property name="currentIndex"> |
||||
<number>0</number> |
||||
</property> |
||||
<item> |
||||
<property name="text"> |
||||
<string>8</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>12</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>16</string> |
||||
</property> |
||||
</item> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="sampleSizeUnits"> |
||||
<property name="text"> |
||||
<string>bits</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<spacer name="horizontalSpacer_7"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>40</width> |
||||
<height>20</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<widget class="Line" name="line_3"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QGridLayout" name="amplitudeLayout"> |
||||
<item row="1" column="0"> |
||||
<widget class="QLabel" name="amplitudeFineLabel"> |
||||
<property name="text"> |
||||
<string>Amp fine</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="0" column="0"> |
||||
<widget class="QLabel" name="amplitudeCoarseLabel"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Amp coarse</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="0" column="1"> |
||||
<widget class="QSlider" name="amplitudeCoarse"> |
||||
<property name="enabled"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Amplitude coarse (x100)</string> |
||||
</property> |
||||
<property name="maximum"> |
||||
<number>327</number> |
||||
</property> |
||||
<property name="pageStep"> |
||||
<number>1</number> |
||||
</property> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="0" column="2"> |
||||
<widget class="QLabel" name="amplitudeBits"> |
||||
<property name="toolTip"> |
||||
<string>Amplitude in bits</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>32768 b</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="2"> |
||||
<widget class="QLabel" name="power"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>52</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Power</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>-100 dB</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="1"> |
||||
<widget class="QSlider" name="amplitudeFine"> |
||||
<property name="toolTip"> |
||||
<string>Amplitude fine (x1)</string> |
||||
</property> |
||||
<property name="pageStep"> |
||||
<number>1</number> |
||||
</property> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="fillerLayout"> |
||||
<item> |
||||
<spacer name="verticalSpacer"> |
||||
<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> |
||||
<customwidget> |
||||
<class>ValueDialZ</class> |
||||
<extends>QWidget</extends> |
||||
<header>gui/valuedialz.h</header> |
||||
<container>1</container> |
||||
</customwidget> |
||||
</customwidgets> |
||||
<resources> |
||||
<include location="../../../sdrgui/resources/res.qrc"/> |
||||
</resources> |
||||
<connections/> |
||||
</ui> |
||||
@ -0,0 +1,336 @@
@@ -0,0 +1,336 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QDebug> |
||||
#include <string.h> |
||||
#include <errno.h> |
||||
|
||||
#include "SWGDeviceSettings.h" |
||||
#include "SWGDeviceState.h" |
||||
|
||||
#include "testsourceinput.h" |
||||
#include "device/devicesourceapi.h" |
||||
#include "testsourcethread.h" |
||||
#include "dsp/dspcommands.h" |
||||
#include "dsp/dspengine.h" |
||||
#include "dsp/filerecord.h" |
||||
|
||||
MESSAGE_CLASS_DEFINITION(TestSourceInput::MsgConfigureTestSource, Message) |
||||
MESSAGE_CLASS_DEFINITION(TestSourceInput::MsgFileRecord, Message) |
||||
MESSAGE_CLASS_DEFINITION(TestSourceInput::MsgStartStop, Message) |
||||
|
||||
|
||||
TestSourceInput::TestSourceInput(DeviceSourceAPI *deviceAPI) : |
||||
m_deviceAPI(deviceAPI), |
||||
m_settings(), |
||||
m_testSourceThread(0), |
||||
m_deviceDescription(), |
||||
m_running(false), |
||||
m_masterTimer(deviceAPI->getMasterTimer()) |
||||
{ |
||||
char recFileNameCStr[30]; |
||||
sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); |
||||
m_fileSink = new FileRecord(std::string(recFileNameCStr)); |
||||
m_deviceAPI->addSink(m_fileSink); |
||||
|
||||
if (!m_sampleFifo.setSize(96000 * 4)) { |
||||
qCritical("TestSourceInput::TestSourceInput: Could not allocate SampleFifo"); |
||||
} |
||||
} |
||||
|
||||
TestSourceInput::~TestSourceInput() |
||||
{ |
||||
if (m_running) { stop(); } |
||||
m_deviceAPI->removeSink(m_fileSink); |
||||
delete m_fileSink; |
||||
} |
||||
|
||||
void TestSourceInput::destroy() |
||||
{ |
||||
delete this; |
||||
} |
||||
|
||||
void TestSourceInput::init() |
||||
{ |
||||
applySettings(m_settings, true); |
||||
} |
||||
|
||||
bool TestSourceInput::start() |
||||
{ |
||||
QMutexLocker mutexLocker(&m_mutex); |
||||
|
||||
if (m_running) stop(); |
||||
|
||||
if ((m_testSourceThread = new TestSourceThread(&m_sampleFifo)) == 0) |
||||
{ |
||||
qFatal("TestSourceInput::start: out of memory"); |
||||
stop(); |
||||
return false; |
||||
} |
||||
|
||||
m_testSourceThread->setSamplerate(m_settings.m_sampleRate); |
||||
m_testSourceThread->connectTimer(m_masterTimer); |
||||
m_testSourceThread->startWork(); |
||||
|
||||
mutexLocker.unlock(); |
||||
|
||||
applySettings(m_settings, true); |
||||
m_running = true; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
void TestSourceInput::stop() |
||||
{ |
||||
QMutexLocker mutexLocker(&m_mutex); |
||||
|
||||
if (m_testSourceThread != 0) |
||||
{ |
||||
m_testSourceThread->stopWork(); |
||||
delete m_testSourceThread; |
||||
m_testSourceThread = 0; |
||||
} |
||||
|
||||
m_running = false; |
||||
} |
||||
|
||||
QByteArray TestSourceInput::serialize() const |
||||
{ |
||||
return m_settings.serialize(); |
||||
} |
||||
|
||||
bool TestSourceInput::deserialize(const QByteArray& data) |
||||
{ |
||||
bool success = true; |
||||
|
||||
if (!m_settings.deserialize(data)) |
||||
{ |
||||
m_settings.resetToDefaults(); |
||||
success = false; |
||||
} |
||||
|
||||
MsgConfigureTestSource* message = MsgConfigureTestSource::create(m_settings, true); |
||||
m_inputMessageQueue.push(message); |
||||
|
||||
if (m_guiMessageQueue) |
||||
{ |
||||
MsgConfigureTestSource* messageToGUI = MsgConfigureTestSource::create(m_settings, true); |
||||
m_guiMessageQueue->push(messageToGUI); |
||||
} |
||||
|
||||
return success; |
||||
} |
||||
|
||||
const QString& TestSourceInput::getDeviceDescription() const |
||||
{ |
||||
return m_deviceDescription; |
||||
} |
||||
|
||||
int TestSourceInput::getSampleRate() const |
||||
{ |
||||
return m_settings.m_sampleRate; |
||||
} |
||||
|
||||
quint64 TestSourceInput::getCenterFrequency() const |
||||
{ |
||||
return m_settings.m_centerFrequency; |
||||
} |
||||
|
||||
void TestSourceInput::setCenterFrequency(qint64 centerFrequency) |
||||
{ |
||||
TestSourceSettings settings = m_settings; |
||||
settings.m_centerFrequency = centerFrequency; |
||||
|
||||
MsgConfigureTestSource* message = MsgConfigureTestSource::create(settings, false); |
||||
m_inputMessageQueue.push(message); |
||||
|
||||
if (m_guiMessageQueue) |
||||
{ |
||||
MsgConfigureTestSource* messageToGUI = MsgConfigureTestSource::create(settings, false); |
||||
m_guiMessageQueue->push(messageToGUI); |
||||
} |
||||
} |
||||
|
||||
bool TestSourceInput::handleMessage(const Message& message) |
||||
{ |
||||
if (MsgConfigureTestSource::match(message)) |
||||
{ |
||||
MsgConfigureTestSource& conf = (MsgConfigureTestSource&) message; |
||||
qDebug() << "TestSourceInput::handleMessage: MsgConfigureTestSource"; |
||||
|
||||
bool success = applySettings(conf.getSettings(), conf.getForce()); |
||||
|
||||
if (!success) |
||||
{ |
||||
qDebug("TestSourceInput::handleMessage: config error"); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
else if (MsgFileRecord::match(message)) |
||||
{ |
||||
MsgFileRecord& conf = (MsgFileRecord&) message; |
||||
qDebug() << "RTLSDRInput::handleMessage: MsgFileRecord: " << conf.getStartStop(); |
||||
|
||||
if (conf.getStartStop()) { |
||||
m_fileSink->startRecording(); |
||||
} else { |
||||
m_fileSink->stopRecording(); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
else if (MsgStartStop::match(message)) |
||||
{ |
||||
MsgStartStop& cmd = (MsgStartStop&) message; |
||||
qDebug() << "RTLSDRInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); |
||||
|
||||
if (cmd.getStartStop()) |
||||
{ |
||||
if (m_deviceAPI->initAcquisition()) |
||||
{ |
||||
m_deviceAPI->startAcquisition(); |
||||
DSPEngine::instance()->startAudioOutput(); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
m_deviceAPI->stopAcquisition(); |
||||
DSPEngine::instance()->stopAudioOutput(); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
else |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool force) |
||||
{ |
||||
if ((m_settings.m_sampleRate != settings.m_sampleRate) || force) |
||||
{ |
||||
if (m_testSourceThread != 0) |
||||
{ |
||||
m_testSourceThread->setSamplerate(settings.m_sampleRate); |
||||
qDebug("TestSourceInput::applySettings: sample rate set to %d", settings.m_sampleRate); |
||||
} |
||||
} |
||||
|
||||
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force) |
||||
{ |
||||
if (m_testSourceThread != 0) |
||||
{ |
||||
m_testSourceThread->setLog2Decimation(settings.m_log2Decim); |
||||
qDebug() << "TestSourceInput::applySettings: set decimation to " << (1<<settings.m_log2Decim); |
||||
} |
||||
} |
||||
|
||||
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency) |
||||
|| (m_settings.m_fcPos != settings.m_fcPos) |
||||
|| (m_settings.m_frequencyShift != settings.m_frequencyShift)) |
||||
{ |
||||
qint64 deviceCenterFrequency = settings.m_centerFrequency; |
||||
deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency; |
||||
qint64 f_img = 0; |
||||
quint32 devSampleRate = settings.m_sampleRate; |
||||
|
||||
if ((settings.m_log2Decim == 0) || (settings.m_fcPos == TestSourceSettings::FC_POS_CENTER)) |
||||
{ |
||||
f_img = 0; |
||||
} |
||||
else |
||||
{ |
||||
if (settings.m_fcPos == TestSourceSettings::FC_POS_INFRA) |
||||
{ |
||||
deviceCenterFrequency += (devSampleRate / 4); |
||||
f_img = devSampleRate/2; |
||||
} |
||||
else if (settings.m_fcPos == TestSourceSettings::FC_POS_SUPRA) |
||||
{ |
||||
deviceCenterFrequency -= (devSampleRate / 4); |
||||
f_img = devSampleRate/2; |
||||
} |
||||
} |
||||
|
||||
if (m_testSourceThread != 0) |
||||
{ |
||||
m_testSourceThread->setFcPos((int) settings.m_fcPos); |
||||
m_testSourceThread->setFrequencyShift(f_img + settings.m_frequencyShift); |
||||
qDebug() << "TestSourceInput::applySettings: center freq: " << settings.m_centerFrequency << " Hz" |
||||
<< " device center freq: " << deviceCenterFrequency << " Hz" |
||||
<< " device sample rate: " << devSampleRate << "Hz" |
||||
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "Hz" |
||||
<< " fc shift: " << f_img << "Hz" |
||||
<< " f shift: " << settings.m_frequencyShift; |
||||
} |
||||
} |
||||
|
||||
if ((m_settings.m_amplitudeBits != settings.m_amplitudeBits) || force) |
||||
{ |
||||
if (m_testSourceThread != 0) { |
||||
m_testSourceThread->setAmplitudeBits(settings.m_amplitudeBits); |
||||
} |
||||
} |
||||
|
||||
if ((m_settings.m_sampleSizeIndex != settings.m_sampleSizeIndex) || force) |
||||
{ |
||||
if (m_testSourceThread != 0) { |
||||
m_testSourceThread->setBitSize(settings.m_sampleSizeIndex); |
||||
} |
||||
} |
||||
|
||||
if ((m_settings.m_sampleRate != settings.m_sampleRate) |
||||
|| (m_settings.m_centerFrequency != settings.m_centerFrequency) |
||||
|| (m_settings.m_log2Decim != settings.m_log2Decim) |
||||
|| (m_settings.m_fcPos != settings.m_fcPos) || force) |
||||
{ |
||||
int sampleRate = settings.m_sampleRate/(1<<settings.m_log2Decim); |
||||
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, settings.m_centerFrequency); |
||||
m_fileSink->handleMessage(*notif); // forward to file sink
|
||||
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); |
||||
} |
||||
|
||||
m_settings = settings; |
||||
return true; |
||||
} |
||||
|
||||
int TestSourceInput::webapiRunGet( |
||||
SWGSDRangel::SWGDeviceState& response, |
||||
QString& errorMessage __attribute__((unused))) |
||||
{ |
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState()); |
||||
return 200; |
||||
} |
||||
|
||||
int TestSourceInput::webapiRun( |
||||
bool run, |
||||
SWGSDRangel::SWGDeviceState& response, |
||||
QString& errorMessage __attribute__((unused))) |
||||
{ |
||||
m_deviceAPI->getDeviceEngineStateStr(*response.getState()); |
||||
MsgStartStop *message = MsgStartStop::create(run); |
||||
m_inputMessageQueue.push(message); |
||||
|
||||
if (m_guiMessageQueue) // forward to GUI if any
|
||||
{ |
||||
MsgStartStop *msgToGUI = MsgStartStop::create(run); |
||||
m_guiMessageQueue->push(msgToGUI); |
||||
} |
||||
|
||||
return 200; |
||||
} |
||||
@ -0,0 +1,135 @@
@@ -0,0 +1,135 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _TESTSOURCE_TESTSOURCEINPUT_H_ |
||||
#define _TESTSOURCE_TESTSOURCEINPUT_H_ |
||||
|
||||
#include <QString> |
||||
#include <QByteArray> |
||||
#include <QTimer> |
||||
|
||||
#include <dsp/devicesamplesource.h> |
||||
#include "testsourcesettings.h" |
||||
|
||||
class DeviceSourceAPI; |
||||
class TestSourceThread; |
||||
class FileRecord; |
||||
|
||||
class TestSourceInput : public DeviceSampleSource { |
||||
public: |
||||
class MsgConfigureTestSource : public Message { |
||||
MESSAGE_CLASS_DECLARATION |
||||
|
||||
public: |
||||
const TestSourceSettings& getSettings() const { return m_settings; } |
||||
bool getForce() const { return m_force; } |
||||
|
||||
static MsgConfigureTestSource* create(const TestSourceSettings& settings, bool force) |
||||
{ |
||||
return new MsgConfigureTestSource(settings, force); |
||||
} |
||||
|
||||
private: |
||||
TestSourceSettings m_settings; |
||||
bool m_force; |
||||
|
||||
MsgConfigureTestSource(const TestSourceSettings& settings, bool force) : |
||||
Message(), |
||||
m_settings(settings), |
||||
m_force(force) |
||||
{ } |
||||
}; |
||||
|
||||
class MsgFileRecord : public Message { |
||||
MESSAGE_CLASS_DECLARATION |
||||
|
||||
public: |
||||
bool getStartStop() const { return m_startStop; } |
||||
|
||||
static MsgFileRecord* create(bool startStop) { |
||||
return new MsgFileRecord(startStop); |
||||
} |
||||
|
||||
protected: |
||||
bool m_startStop; |
||||
|
||||
MsgFileRecord(bool startStop) : |
||||
Message(), |
||||
m_startStop(startStop) |
||||
{ } |
||||
}; |
||||
|
||||
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) |
||||
{ } |
||||
}; |
||||
|
||||
TestSourceInput(DeviceSourceAPI *deviceAPI); |
||||
virtual ~TestSourceInput(); |
||||
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 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: |
||||
DeviceSourceAPI *m_deviceAPI; |
||||
FileRecord *m_fileSink; //!< File sink to record device I/Q output
|
||||
QMutex m_mutex; |
||||
TestSourceSettings m_settings; |
||||
TestSourceThread* m_testSourceThread; |
||||
QString m_deviceDescription; |
||||
bool m_running; |
||||
const QTimer& m_masterTimer; |
||||
|
||||
bool applySettings(const TestSourceSettings& settings, bool force); |
||||
}; |
||||
|
||||
#endif // _TESTSOURCE_TESTSOURCEINPUT_H_
|
||||
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QtPlugin> |
||||
|
||||
#include "plugin/pluginapi.h" |
||||
#include "util/simpleserializer.h" |
||||
#include <device/devicesourceapi.h> |
||||
|
||||
#ifdef SERVER_MODE |
||||
#include "testsourceinput.h" |
||||
#else |
||||
#include "testsourcegui.h" |
||||
#endif |
||||
#include "testsourceplugin.h" |
||||
|
||||
const PluginDescriptor TestSourcePlugin::m_pluginDescriptor = { |
||||
QString("Test Source input"), |
||||
QString("3.11.0"), |
||||
QString("(c) Edouard Griffiths, F4EXB"), |
||||
QString("https://github.com/f4exb/sdrangel"), |
||||
true, |
||||
QString("https://github.com/f4exb/sdrangel") |
||||
}; |
||||
|
||||
const QString TestSourcePlugin::m_hardwareID = "TestSource"; |
||||
const QString TestSourcePlugin::m_deviceTypeID = TESTSOURCE_DEVICE_TYPE_ID; |
||||
|
||||
TestSourcePlugin::TestSourcePlugin(QObject* parent) : |
||||
QObject(parent) |
||||
{ |
||||
} |
||||
|
||||
const PluginDescriptor& TestSourcePlugin::getPluginDescriptor() const |
||||
{ |
||||
return m_pluginDescriptor; |
||||
} |
||||
|
||||
void TestSourcePlugin::initPlugin(PluginAPI* pluginAPI) |
||||
{ |
||||
pluginAPI->registerSampleSource(m_deviceTypeID, this); |
||||
} |
||||
|
||||
PluginInterface::SamplingDevices TestSourcePlugin::enumSampleSources() |
||||
{ |
||||
SamplingDevices result; |
||||
|
||||
result.append(SamplingDevice( |
||||
"TestSource", |
||||
m_hardwareID, |
||||
m_deviceTypeID, |
||||
QString::null, |
||||
0, |
||||
PluginInterface::SamplingDevice::BuiltInDevice, |
||||
true, |
||||
1, |
||||
0)); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
#ifdef SERVER_MODE |
||||
PluginInstanceGUI* TestSourcePlugin::createSampleSourcePluginInstanceGUI( |
||||
const QString& sourceId __attribute((unused)), |
||||
QWidget **widget __attribute((unused)), |
||||
DeviceUISet *deviceUISet __attribute((unused))) |
||||
{ |
||||
return 0; |
||||
} |
||||
#else |
||||
PluginInstanceGUI* TestSourcePlugin::createSampleSourcePluginInstanceGUI( |
||||
const QString& sourceId, |
||||
QWidget **widget, |
||||
DeviceUISet *deviceUISet) |
||||
{ |
||||
if(sourceId == m_deviceTypeID) { |
||||
TestSourceGui* gui = new TestSourceGui(deviceUISet); |
||||
*widget = gui; |
||||
return gui; |
||||
} else { |
||||
return 0; |
||||
} |
||||
} |
||||
#endif |
||||
|
||||
DeviceSampleSource *TestSourcePlugin::createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI) |
||||
{ |
||||
if (sourceId == m_deviceTypeID) |
||||
{ |
||||
TestSourceInput* input = new TestSourceInput(deviceAPI); |
||||
return input; |
||||
} |
||||
else |
||||
{ |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _TESTSOURCE_TESTSOURCEPLUGIN_H |
||||
#define _TESTSOURCE_TESTSOURCEPLUGIN_H |
||||
|
||||
#include <QObject> |
||||
#include "plugin/plugininterface.h" |
||||
|
||||
class PluginAPI; |
||||
|
||||
#define TESTSOURCE_DEVICE_TYPE_ID "sdrangel.samplesource.testsource" |
||||
|
||||
class TestSourcePlugin : public QObject, public PluginInterface { |
||||
Q_OBJECT |
||||
Q_INTERFACES(PluginInterface) |
||||
Q_PLUGIN_METADATA(IID TESTSOURCE_DEVICE_TYPE_ID) |
||||
|
||||
public: |
||||
explicit TestSourcePlugin(QObject* parent = NULL); |
||||
|
||||
const PluginDescriptor& getPluginDescriptor() const; |
||||
void initPlugin(PluginAPI* pluginAPI); |
||||
|
||||
virtual SamplingDevices enumSampleSources(); |
||||
virtual PluginInstanceGUI* createSampleSourcePluginInstanceGUI( |
||||
const QString& sourceId, |
||||
QWidget **widget, |
||||
DeviceUISet *deviceUISet); |
||||
virtual DeviceSampleSource* createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI); |
||||
|
||||
static const QString m_hardwareID; |
||||
static const QString m_deviceTypeID; |
||||
|
||||
private: |
||||
static const PluginDescriptor m_pluginDescriptor; |
||||
}; |
||||
|
||||
#endif // _TESTSOURCE_TESTSOURCEPLUGIN_H
|
||||
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QtGlobal> |
||||
#include "util/simpleserializer.h" |
||||
#include "testsourcesettings.h" |
||||
|
||||
TestSourceSettings::TestSourceSettings() |
||||
{ |
||||
resetToDefaults(); |
||||
} |
||||
|
||||
void TestSourceSettings::resetToDefaults() |
||||
{ |
||||
m_centerFrequency = 435000*1000; |
||||
m_frequencyShift = 0; |
||||
m_sampleRate = 768*1000; |
||||
m_log2Decim = 4; |
||||
m_fcPos = FC_POS_CENTER; |
||||
m_sampleSizeIndex = 0; |
||||
m_amplitudeBits = 127; |
||||
} |
||||
|
||||
QByteArray TestSourceSettings::serialize() const |
||||
{ |
||||
SimpleSerializer s(1); |
||||
|
||||
s.writeS32(2, m_frequencyShift); |
||||
s.writeU32(3, m_sampleRate); |
||||
s.writeU32(4, m_log2Decim); |
||||
s.writeS32(5, (int) m_fcPos); |
||||
s.writeU32(6, m_sampleSizeIndex); |
||||
s.writeS32(7, m_amplitudeBits); |
||||
|
||||
return s.final(); |
||||
} |
||||
|
||||
bool TestSourceSettings::deserialize(const QByteArray& data) |
||||
{ |
||||
SimpleDeserializer d(data); |
||||
|
||||
if (!d.isValid()) |
||||
{ |
||||
resetToDefaults(); |
||||
return false; |
||||
} |
||||
|
||||
if (d.getVersion() == 1) |
||||
{ |
||||
int intval; |
||||
|
||||
d.readS32(2, &m_frequencyShift, 0); |
||||
d.readU32(3, &m_sampleRate, 768*1000); |
||||
d.readU32(4, &m_log2Decim, 4); |
||||
d.readS32(5, &intval, 0); |
||||
m_fcPos = (fcPos_t) intval; |
||||
d.readU32(6, &m_sampleSizeIndex, 0); |
||||
d.readS32(7, &m_amplitudeBits, 128); |
||||
|
||||
return true; |
||||
} |
||||
else |
||||
{ |
||||
resetToDefaults(); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _TESTSOURCE_TESTSOURCESETTINGS_H_ |
||||
#define _TESTSOURCE_TESTSOURCESETTINGS_H_ |
||||
|
||||
struct TestSourceSettings { |
||||
typedef enum { |
||||
FC_POS_INFRA = 0, |
||||
FC_POS_SUPRA, |
||||
FC_POS_CENTER |
||||
} fcPos_t; |
||||
|
||||
quint64 m_centerFrequency; |
||||
qint32 m_frequencyShift; |
||||
quint32 m_sampleRate; |
||||
quint32 m_log2Decim; |
||||
fcPos_t m_fcPos; |
||||
quint32 m_sampleSizeIndex; |
||||
qint32 m_amplitudeBits; |
||||
|
||||
TestSourceSettings(); |
||||
void resetToDefaults(); |
||||
QByteArray serialize() const; |
||||
bool deserialize(const QByteArray& data); |
||||
}; |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* _TESTSOURCE_TESTSOURCESETTINGS_H_ */ |
||||
@ -0,0 +1,223 @@
@@ -0,0 +1,223 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdio.h> |
||||
#include <errno.h> |
||||
#include "testsourcethread.h" |
||||
|
||||
#include "dsp/samplesinkfifo.h" |
||||
|
||||
#define TESTSOURCE_BLOCKSIZE 16384 |
||||
|
||||
TestSourceThread::TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent) : |
||||
QThread(parent), |
||||
m_running(false), |
||||
m_buf(0), |
||||
m_bufsize(0), |
||||
m_chunksize(0), |
||||
m_convertBuffer(TESTSOURCE_BLOCKSIZE), |
||||
m_sampleFifo(sampleFifo), |
||||
m_samplerate(48000), |
||||
m_log2Decim(4), |
||||
m_fcPos(0), |
||||
m_bitSizeIndex(0), |
||||
m_bitShift(8), |
||||
m_amplitudeBits(127), |
||||
m_frequency(435*1000), |
||||
m_fcPosShift(0), |
||||
m_throttlems(TESTSOURCE_THROTTLE_MS), |
||||
m_throttleToggle(false) |
||||
{ |
||||
m_chunksize = (m_samplerate * 4 * m_throttlems) / 1000; |
||||
setBuffers(m_chunksize); |
||||
} |
||||
|
||||
TestSourceThread::~TestSourceThread() |
||||
{ |
||||
stopWork(); |
||||
} |
||||
|
||||
void TestSourceThread::startWork() |
||||
{ |
||||
qDebug("TestSourceThread::startWork"); |
||||
m_startWaitMutex.lock(); |
||||
m_elapsedTimer.start(); |
||||
start(); |
||||
while(!m_running) |
||||
m_startWaiter.wait(&m_startWaitMutex, 100); |
||||
m_startWaitMutex.unlock(); |
||||
} |
||||
|
||||
void TestSourceThread::stopWork() |
||||
{ |
||||
qDebug("TestSourceThread::stopWork"); |
||||
m_running = false; |
||||
wait(); |
||||
} |
||||
|
||||
void TestSourceThread::setSamplerate(int samplerate) |
||||
{ |
||||
m_samplerate = samplerate; |
||||
m_chunksize = (m_samplerate * 4 * m_throttlems) / 1000; |
||||
setBuffers(m_chunksize); |
||||
} |
||||
|
||||
void TestSourceThread::setLog2Decimation(unsigned int log2_decim) |
||||
{ |
||||
m_log2Decim = log2_decim; |
||||
} |
||||
|
||||
void TestSourceThread::setFcPos(int fcPos) |
||||
{ |
||||
m_fcPos = fcPos; |
||||
} |
||||
|
||||
void TestSourceThread::setBitSize(quint32 bitSizeIndex) |
||||
{ |
||||
switch (bitSizeIndex) |
||||
{ |
||||
case 0: |
||||
m_bitShift = 7; |
||||
m_bitSizeIndex = 0; |
||||
break; |
||||
case 1: |
||||
m_bitShift = 11; |
||||
m_bitSizeIndex = 1; |
||||
break; |
||||
case 2: |
||||
default: |
||||
m_bitShift = 15; |
||||
m_bitSizeIndex = 2; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void TestSourceThread::setAmplitudeBits(int32_t amplitudeBits) |
||||
{ |
||||
m_amplitudeBits = amplitudeBits; |
||||
} |
||||
|
||||
void TestSourceThread::setFrequencyShift(int shift) |
||||
{ |
||||
m_nco.setFreq(shift, m_samplerate); |
||||
} |
||||
|
||||
void TestSourceThread::run() |
||||
{ |
||||
m_running = true; |
||||
m_startWaiter.wakeAll(); |
||||
|
||||
qDebug("TestSourceThread::run: starting"); |
||||
|
||||
while (m_running) // actual work is in the tick() function
|
||||
{ |
||||
sleep(1); |
||||
} |
||||
|
||||
qDebug("TestSourceThread::run: ending"); |
||||
|
||||
m_running = false; |
||||
} |
||||
|
||||
void TestSourceThread::setBuffers(quint32 chunksize) |
||||
{ |
||||
if (chunksize > m_bufsize) |
||||
{ |
||||
m_bufsize = chunksize; |
||||
|
||||
if (m_buf == 0) |
||||
{ |
||||
qDebug() << "TestSourceThread::setBuffer: Allocate buffer"; |
||||
m_buf = (quint8*) malloc(m_bufsize); |
||||
} |
||||
else |
||||
{ |
||||
qDebug() << "TestSourceThread::setBuffer: Re-allocate buffer"; |
||||
quint8 *buf = m_buf; |
||||
m_buf = (quint8*) realloc((void*) m_buf, m_bufsize); |
||||
if (!m_buf) free(buf); |
||||
} |
||||
|
||||
m_convertBuffer.resize(chunksize/4); |
||||
|
||||
qDebug() << "TestSourceThread::setBuffer: size: " << m_bufsize |
||||
<< " #samples: " << (m_bufsize/4); |
||||
} |
||||
} |
||||
|
||||
void TestSourceThread::generate(quint32 chunksize) |
||||
{ |
||||
quint32 n = chunksize / 2; |
||||
qint16 *buf = (qint16*) m_buf; |
||||
|
||||
for (unsigned int i = 0; i < n;) |
||||
{ |
||||
Complex c = m_nco.nextIQ(); |
||||
buf[i] = c.real() * (1<<m_bitShift); |
||||
i++; |
||||
buf[i] = c.imag() * (1<<m_bitShift); |
||||
i++; |
||||
} |
||||
|
||||
callback(m_buf, n); |
||||
} |
||||
|
||||
// call appropriate conversion (decimation) routine depending on the number of sample bits
|
||||
void TestSourceThread::callback(const quint8* buf, qint32 len) |
||||
{ |
||||
SampleVector::iterator it = m_convertBuffer.begin(); |
||||
|
||||
switch (m_bitSizeIndex) |
||||
{ |
||||
case 0: // 8 bit samples
|
||||
convert_8(&it, buf, len); |
||||
break; |
||||
case 1: // 12 bit samples
|
||||
convert_12(&it, buf, len); |
||||
break; |
||||
case 2: // 16 bit samples
|
||||
default: |
||||
convert_16(&it, buf, len); |
||||
break; |
||||
} |
||||
|
||||
m_sampleFifo->write(m_convertBuffer.begin(), it); |
||||
} |
||||
|
||||
void TestSourceThread::connectTimer(const QTimer& timer) |
||||
{ |
||||
qDebug() << "TestSourceThread::connectTimer"; |
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(tick())); |
||||
} |
||||
|
||||
void TestSourceThread::tick() |
||||
{ |
||||
if (m_running) |
||||
{ |
||||
qint64 throttlems = m_elapsedTimer.restart(); |
||||
|
||||
if (throttlems != m_throttlems) |
||||
{ |
||||
m_throttlems = throttlems; |
||||
m_chunksize = 4 * ((m_samplerate * (m_throttlems+(m_throttleToggle ? 1 : 0))) / 1000); |
||||
m_throttleToggle = !m_throttleToggle; |
||||
setBuffers(m_chunksize); |
||||
} |
||||
|
||||
generate(m_chunksize); |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,326 @@
@@ -0,0 +1,326 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _TESTSOURCE_TESTSOURCETHREAD_H_ |
||||
#define _TESTSOURCE_TESTSOURCETHREAD_H_ |
||||
|
||||
#include <QThread> |
||||
#include <QMutex> |
||||
#include <QWaitCondition> |
||||
#include <QTimer> |
||||
#include <QElapsedTimer> |
||||
#include <QDebug> |
||||
|
||||
#include "dsp/samplesinkfifo.h" |
||||
#include "dsp/decimators.h" |
||||
#include "dsp/ncof.h" |
||||
|
||||
#define TESTSOURCE_THROTTLE_MS 50 |
||||
|
||||
class TestSourceThread : public QThread { |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent = 0); |
||||
~TestSourceThread(); |
||||
|
||||
void startWork(); |
||||
void stopWork(); |
||||
void setSamplerate(int samplerate); |
||||
void setLog2Decimation(unsigned int log2_decim); |
||||
void setFcPos(int fcPos); |
||||
void setBitSize(uint32_t bitSizeIndex); |
||||
void setAmplitudeBits(int32_t amplitudeBits); |
||||
void setFrequencyShift(int shift); |
||||
|
||||
void connectTimer(const QTimer& timer); |
||||
|
||||
private: |
||||
QMutex m_startWaitMutex; |
||||
QWaitCondition m_startWaiter; |
||||
bool m_running; |
||||
|
||||
quint8 *m_buf; |
||||
quint32 m_bufsize; |
||||
quint32 m_chunksize; |
||||
SampleVector m_convertBuffer; |
||||
SampleSinkFifo* m_sampleFifo; |
||||
NCOF m_nco; |
||||
|
||||
int m_samplerate; |
||||
unsigned int m_log2Decim; |
||||
int m_fcPos; |
||||
uint32_t m_bitSizeIndex; |
||||
uint32_t m_bitShift; |
||||
int32_t m_amplitudeBits; |
||||
|
||||
uint64_t m_frequency; |
||||
int m_fcPosShift; |
||||
|
||||
int m_throttlems; |
||||
QElapsedTimer m_elapsedTimer; |
||||
bool m_throttleToggle; |
||||
|
||||
Decimators<quint8, SDR_SAMP_SZ, 8> m_decimators_8; |
||||
Decimators<quint8, SDR_SAMP_SZ, 12> m_decimators_12; |
||||
Decimators<quint8, SDR_SAMP_SZ, 16> m_decimators_16; |
||||
|
||||
void run(); |
||||
void callback(const quint8* buf, qint32 len); |
||||
void setBuffers(quint32 chunksize); |
||||
void generate(quint32 chunksize); |
||||
|
||||
// Decimate according to specified log2 (ex: log2=4 => decim=16)
|
||||
inline void convert_8(SampleVector::iterator* it, const quint8* buf, qint32 len) |
||||
{ |
||||
if (m_log2Decim == 0) { |
||||
m_decimators_8.decimate1(it, buf, len); |
||||
} else { |
||||
if (m_fcPos == 0) { // Infradyne
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_8.decimate2_inf(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_8.decimate4_inf(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_8.decimate8_inf(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_8.decimate16_inf(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_8.decimate32_inf(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_8.decimate64_inf(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} else if (m_fcPos == 1) {// Supradyne
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_8.decimate2_sup(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_8.decimate4_sup(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_8.decimate8_sup(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_8.decimate16_sup(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_8.decimate32_sup(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_8.decimate64_sup(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} else { // Centered
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_8.decimate2_cen(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_8.decimate4_cen(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_8.decimate8_cen(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_8.decimate16_cen(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_8.decimate32_cen(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_8.decimate64_cen(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void convert_12(SampleVector::iterator* it, const quint8* buf, qint32 len) |
||||
{ |
||||
if (m_log2Decim == 0) { |
||||
m_decimators_12.decimate1(it, buf, len); |
||||
} else { |
||||
if (m_fcPos == 0) { // Infradyne
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_12.decimate2_inf(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_12.decimate4_inf(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_12.decimate8_inf(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_12.decimate16_inf(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_12.decimate32_inf(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_12.decimate64_inf(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} else if (m_fcPos == 1) {// Supradyne
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_12.decimate2_sup(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_12.decimate4_sup(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_12.decimate8_sup(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_12.decimate16_sup(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_12.decimate32_sup(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_12.decimate64_sup(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} else { // Centered
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_12.decimate2_cen(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_12.decimate4_cen(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_12.decimate8_cen(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_12.decimate16_cen(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_12.decimate32_cen(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_12.decimate64_cen(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void convert_16(SampleVector::iterator* it, const quint8* buf, qint32 len) |
||||
{ |
||||
if (m_log2Decim == 0) { |
||||
m_decimators_16.decimate1(it, buf, len); |
||||
} else { |
||||
if (m_fcPos == 0) { // Infradyne
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_16.decimate2_inf(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_16.decimate4_inf(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_16.decimate8_inf(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_16.decimate16_inf(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_16.decimate32_inf(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_16.decimate64_inf(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} else if (m_fcPos == 1) {// Supradyne
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_16.decimate2_sup(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_16.decimate4_sup(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_16.decimate8_sup(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_16.decimate16_sup(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_16.decimate32_sup(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_16.decimate64_sup(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} else { // Centered
|
||||
switch (m_log2Decim) { |
||||
case 1: |
||||
m_decimators_16.decimate2_cen(it, buf, len); |
||||
break; |
||||
case 2: |
||||
m_decimators_16.decimate4_cen(it, buf, len); |
||||
break; |
||||
case 3: |
||||
m_decimators_16.decimate8_cen(it, buf, len); |
||||
break; |
||||
case 4: |
||||
m_decimators_16.decimate16_cen(it, buf, len); |
||||
break; |
||||
case 5: |
||||
m_decimators_16.decimate32_cen(it, buf, len); |
||||
break; |
||||
case 6: |
||||
m_decimators_16.decimate64_cen(it, buf, len); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
private slots: |
||||
void tick(); |
||||
}; |
||||
|
||||
#endif // _TESTSOURCE_TESTSOURCETHREAD_H_
|
||||
Loading…
Reference in new issue