1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-17 05:08:54 -04:00

PlutoSDR MIMO: base implementation

This commit is contained in:
f4exb
2021-05-01 09:50:51 +02:00
parent 54222ff016
commit 672c0b8a5b
40 changed files with 8312 additions and 12 deletions
+4
View File
@@ -12,6 +12,10 @@ if(ENABLE_XTRX AND LIBXTRX_FOUND)
add_subdirectory(xtrxmimo)
endif()
if(ENABLE_IIO AND LIBIIO_FOUND)
add_subdirectory(plutosdrmimo)
endif()
add_subdirectory(metismiso)
add_subdirectory(testmi)
add_subdirectory(testmosync)
@@ -0,0 +1,66 @@
project(plutosdrmimo)
set(plutosdrmimo_SOURCES
plutosdrmimo.cpp
plutosdrmimoplugin.cpp
plutosdrmithread.cpp
plutosdrmothread.cpp
plutosdrmimosettings.cpp
plutosdrmimowebapiadapter.cpp
)
set(plutosdrmimo_HEADERS
plutosdrmimo.h
plutosdrmimoplugin.h
plutosdrmithread.h
plutosdrmothread.h
plutosdrmimosettings.h
plutosdrmimowebapiadapter.h
)
include_directories(
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${CMAKE_SOURCE_DIR}/devices
${LIBBLADERF_INCLUDE_DIRS}
)
if (NOT SERVER_MODE)
set (plutosdrmimo_SOURCES
${plutosdrmimo_SOURCES}
plutosdrmimogui.cpp
plutosdrmimogui.ui
)
set(plutosdrmimo_HEADERS
${plutosdrmimo_HEADERS}
plutosdrmimogui.h
)
set(TARGET_NAME mimoplutosdr)
set(TARGET_LIB "Qt5::Widgets")
set(TARGET_LIB_GUI "sdrgui")
set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR})
else()
set(TARGET_NAME mimoplutosdrsrv)
set(TARGET_LIB "")
set(TARGET_LIB_GUI "")
set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR})
endif()
add_library(${TARGET_NAME} SHARED
${plutosdrmimo_SOURCES}
)
if(LIBIIO_EXTERNAL)
add_dependencies(${TARGET_NAME} libiio)
endif()
target_link_libraries(${TARGET_NAME}
Qt5::Core
${TARGET_LIB}
sdrbase
${TARGET_LIB_GUI}
swagger
${LIBBLADERF_LIBRARIES}
plutosdrdevice
)
install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,200 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 _PLUTOSDR_PLUTOSDRMIMO_H_
#define _PLUTOSDR_PLUTOSDRMIMO_H_
#include <stdint.h>
#include <QString>
#include <QByteArray>
#include <QNetworkRequest>
#include "dsp/devicesamplemimo.h"
#include "plutosdr/deviceplutosdrbox.h"
#include "plutosdrmimosettings.h"
class QNetworkAccessManager;
class QNetworkReply;
class DeviceAPI;
class PlutoSDRMIThread;
class PlutoSDRMOThread;
class DevicePlutoSDRParams;
class PlutoSDRMIMO : public DeviceSampleMIMO {
Q_OBJECT
public:
class MsgConfigurePlutoSDRMIMO : public Message {
MESSAGE_CLASS_DECLARATION
public:
const PlutoSDRMIMOSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
static MsgConfigurePlutoSDRMIMO* create(const PlutoSDRMIMOSettings& settings, bool force)
{
return new MsgConfigurePlutoSDRMIMO(settings, force);
}
private:
PlutoSDRMIMOSettings m_settings;
bool m_force;
MsgConfigurePlutoSDRMIMO(const PlutoSDRMIMOSettings& 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)
{ }
};
PlutoSDRMIMO(DeviceAPI *deviceAPI);
virtual ~PlutoSDRMIMO();
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 unsigned int getMIMOSampleRate() const { return getSourceSampleRate(0); }
virtual bool handleMessage(const Message& message);
virtual int webapiSettingsGet(
SWGSDRangel::SWGDeviceSettings& response,
QString& errorMessage);
virtual int webapiSettingsPutPatch(
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage);
virtual int webapiReportGet(
SWGSDRangel::SWGDeviceReport& response,
QString& errorMessage);
virtual int webapiRunGet(
int subsystemIndex,
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
virtual int webapiRun(
bool run,
int subsystemIndex,
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
static void webapiFormatDeviceSettings(
SWGSDRangel::SWGDeviceSettings& response,
const PlutoSDRMIMOSettings& settings);
static void webapiUpdateDeviceSettings(
PlutoSDRMIMOSettings& settings,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response);
int getNbRx() { return m_nbRx; }
int getNbTx() { return m_nbTx; }
bool getRxRunning() const { return m_runningRx; }
bool getTxRunning() const { return m_runningTx; }
uint32_t getADCSampleRate() const { return m_rxDeviceSampleRates.m_addaConnvRate; }
uint32_t getDACSampleRate() const { return m_txDeviceSampleRates.m_addaConnvRate; }
uint32_t getRxFIRSampleRate() const { return m_rxDeviceSampleRates.m_hb1Rate; }
uint32_t getTxFIRSampleRate() const { return m_txDeviceSampleRates.m_hb1Rate; }
void getRxRSSI(std::string& rssiStr, int chan);
void getTxRSSI(std::string& rssiStr, int chan);
void getRxGain(int& gainStr, int chan);
void getLORange(qint64& minLimit, qint64& maxLimit);
void getbbLPRange(quint32& minLimit, quint32& maxLimit);
bool fetchTemperature();
float getTemperature();
private:
DeviceAPI *m_deviceAPI;
QMutex m_mutex;
PlutoSDRMIMOSettings m_settings;
PlutoSDRMIThread* m_sourceThread;
PlutoSDRMOThread* m_sinkThread;
DevicePlutoSDRBox::SampleRates m_rxDeviceSampleRates;
DevicePlutoSDRBox::SampleRates m_txDeviceSampleRates;
QString m_deviceDescription;
bool m_runningRx;
bool m_runningTx;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
DevicePlutoSDRParams *m_plutoParams;
bool m_open;
int m_nbRx;
int m_nbTx;
bool openDevice();
void closeDevice();
bool applySettings(const PlutoSDRMIMOSettings& settings, bool force);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const PlutoSDRMIMOSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
private slots:
void networkManagerFinished(QNetworkReply *reply);
};
#endif // _PLUTOSDR_PLUTOSDRMIMO_H_
@@ -0,0 +1,848 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 <QDateTime>
#include <QString>
#include <QMessageBox>
#include "plugin/pluginapi.h"
#include "device/deviceapi.h"
#include "device/deviceuiset.h"
#include "gui/colormapper.h"
#include "gui/glspectrum.h"
#include "gui/crightclickenabler.h"
#include "gui/basicdevicesettingsdialog.h"
#include "dsp/dspengine.h"
#include "dsp/dspdevicemimoengine.h"
#include "dsp/dspcommands.h"
#include "dsp/devicesamplestatic.h"
#include "dsp/devicesamplesource.h"
#include "dsp/devicesamplesink.h"
#include "util/db.h"
#include "plutosdr/deviceplutosdr.h"
#include "mainwindow.h"
#include "plutosdrmimo.h"
#include "ui_plutosdrmimogui.h"
#include "plutosdrmimogui.h"
PlutoSDRMIMOGUI::PlutoSDRMIMOGUI(DeviceUISet *deviceUISet, QWidget* parent) :
DeviceGUI(parent),
ui(new Ui::PlutoSDRMIMOGUI),
m_deviceUISet(deviceUISet),
m_settings(),
m_rxElseTx(true),
m_streamIndex(0),
m_spectrumRxElseTx(true),
m_spectrumStreamIndex(0),
m_gainLock(false),
m_doApplySettings(true),
m_forceSettings(true),
m_sampleMIMO(nullptr),
m_tickCount(0),
m_rxBasebandSampleRate(3072000),
m_txBasebandSampleRate(3072000),
m_rxDeviceCenterFrequency(435000*1000),
m_txDeviceCenterFrequency(435000*1000),
m_lastRxEngineState(DeviceAPI::StNotStarted),
m_lastTxEngineState(DeviceAPI::StNotStarted),
m_statusCounter(0),
m_sampleRateMode(true)
{
qDebug("PlutoSDRMIMOGui::PlutoSDRMIMOGui");
ui->setupUi(this);
m_sampleMIMO = (PlutoSDRMIMO*) m_deviceUISet->m_deviceAPI->getSampleMIMO();
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
updateFrequencyLimits();
ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow));
ui->sampleRate->setValueRange(8, DevicePlutoSDR::srLowLimitFreq, DevicePlutoSDR::srHighLimitFreq);
ui->lpf->setColorMapper(ColorMapper(ColorMapper::GrayYellow));
quint32 minLimit, maxLimit;
((PlutoSDRMIMO *) m_sampleMIMO)->getbbLPRange(minLimit, maxLimit);
ui->lpf->setValueRange(5, minLimit/1000, maxLimit/1000);
ui->lpFIR->setColorMapper(ColorMapper(ColorMapper::GrayYellow));
ui->lpFIR->setValueRange(5, 1U, 56000U); // will be dynamically recalculated
ui->swDecimLabel->setText(QString::fromUtf8("S\u2193"));
ui->lpFIRDecimationLabel->setText(QString::fromUtf8("\u2193"));
CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStopRx);
connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
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);
m_sampleMIMO->setMessageQueueToGUI(&m_inputMessageQueue);
}
PlutoSDRMIMOGUI::~PlutoSDRMIMOGUI()
{
delete ui;
}
void PlutoSDRMIMOGUI::destroy()
{
delete this;
}
void PlutoSDRMIMOGUI::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
sendSettings();
}
QByteArray PlutoSDRMIMOGUI::serialize() const
{
return m_settings.serialize();
}
bool PlutoSDRMIMOGUI::deserialize(const QByteArray& data)
{
if (m_settings.deserialize(data))
{
displaySettings();
m_forceSettings = true;
sendSettings();
return true;
}
else
{
resetToDefaults();
return false;
}
}
void PlutoSDRMIMOGUI::displaySettings()
{
if (m_rxElseTx)
{
ui->transverter->setDeltaFrequency(m_settings.m_rxTransverterDeltaFrequency);
ui->transverter->setDeltaFrequencyActive(m_settings.m_rxTransverterMode);
ui->transverter->setIQOrder(m_settings.m_iqOrder);
updateFrequencyLimits();
ui->centerFrequency->setValue(m_settings.m_rxCenterFrequency / 1000);
displaySampleRate();
ui->dcOffset->setChecked(m_settings.m_dcBlock);
ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
ui->bbDCOffset->setChecked(m_settings.m_hwBBDCBlock);
ui->rfDCOffset->setChecked(m_settings.m_hwRFDCBlock);
ui->hwIQImbalance->setChecked(m_settings.m_hwIQCorrection);
ui->loPPM->setValue(m_settings.m_LOppmTenths);
ui->loPPMText->setText(QString("%1").arg(QString::number(m_settings.m_LOppmTenths/10.0, 'f', 1)));
ui->swDecim->setCurrentIndex(m_settings.m_log2Decim);
ui->fcPos->setCurrentIndex((int) m_settings.m_fcPosRx);
ui->lpf->setValue(m_settings.m_lpfBWRx / 1000);
ui->lpFIREnable->setChecked(m_settings.m_lpfRxFIREnable);
ui->lpFIR->setValue(m_settings.m_lpfRxFIRBW / 1000);
ui->lpFIRDecimation->setCurrentIndex(m_settings.m_lpfRxFIRlog2Decim);
ui->lpFIRGain->setCurrentIndex((m_settings.m_lpfRxFIRGain + 12)/6);
ui->lpFIRDecimation->setEnabled(m_settings.m_lpfRxFIREnable);
ui->lpFIRGain->setEnabled(m_settings.m_lpfRxFIREnable);
ui->gainMode->setEnabled(true);
ui->gain->setEnabled(true);
ui->att->setEnabled(false);
if (m_streamIndex == 0)
{
ui->gainMode->setCurrentIndex((int) m_settings.m_rx0GainMode);
ui->gain->setValue(m_settings.m_rx0Gain);
ui->gainText->setText(tr("%1").arg(m_settings.m_rx0Gain));
ui->antenna->setCurrentIndex((int) m_settings.m_rx0AntennaPath);
}
else
{
ui->gainMode->setCurrentIndex((int) m_settings.m_rx1GainMode);
ui->gain->setValue(m_settings.m_rx1Gain);
ui->gainText->setText(tr("%1").arg(m_settings.m_rx1Gain));
ui->antenna->setCurrentIndex((int) m_settings.m_rx1AntennaPath);
}
setFIRBWLimits();
setSampleRateLimits();
}
else
{
ui->transverter->setDeltaFrequency(m_settings.m_txTransverterDeltaFrequency);
ui->transverter->setDeltaFrequencyActive(m_settings.m_txTransverterMode);
updateFrequencyLimits();
ui->centerFrequency->setValue(m_settings.m_txCenterFrequency / 1000);
displaySampleRate();
ui->swDecim->setCurrentIndex(m_settings.m_log2Interp);
ui->fcPos->setCurrentIndex((int) m_settings.m_fcPosTx);
ui->lpf->setValue(m_settings.m_lpfBWTx / 1000);
ui->lpFIREnable->setChecked(m_settings.m_lpfTxFIREnable);
ui->lpFIR->setValue(m_settings.m_lpfTxFIRBW / 1000);
ui->lpFIRDecimation->setCurrentIndex(m_settings.m_lpfTxFIRlog2Interp);
ui->lpFIRGain->setCurrentIndex((m_settings.m_lpfTxFIRGain + 6)/6);
ui->lpFIRDecimation->setEnabled(m_settings.m_lpfTxFIREnable);
ui->lpFIRGain->setEnabled(m_settings.m_lpfTxFIREnable);
ui->gainMode->setEnabled(false);
ui->gain->setEnabled(false);
ui->att->setEnabled(true);
if (m_streamIndex == 0)
{
ui->att->setValue(m_settings.m_tx0Att);
ui->attText->setText(QString("%1 dB").arg(QString::number(m_settings.m_tx0Att*0.25, 'f', 2)));
ui->antenna->setCurrentIndex((int) m_settings.m_tx0AntennaPath);
}
else
{
ui->att->setValue(m_settings.m_tx1Att);
ui->attText->setText(QString("%1 dB").arg(QString::number(m_settings.m_tx1Att*0.25, 'f', 2)));
ui->antenna->setCurrentIndex((int) m_settings.m_tx1AntennaPath);
}
setFIRBWLimits();
setSampleRateLimits();
}
}
void PlutoSDRMIMOGUI::displaySampleRate()
{
ui->sampleRate->blockSignals(true);
displayFcTooltip();
if (m_sampleRateMode)
{
ui->sampleRateMode->setStyleSheet("QToolButton { background:rgb(60,60,60); }");
ui->sampleRateMode->setText("SR");
ui->sampleRate->setValueRange(8, DevicePlutoSDR::srLowLimitFreq, DevicePlutoSDR::srHighLimitFreq);
ui->sampleRate->setValue(m_settings.m_devSampleRate);
ui->sampleRate->setToolTip("Device to host sample rate (S/s)");
ui->deviceRateText->setToolTip("Baseband sample rate (S/s)");
uint32_t basebandSampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim);
ui->deviceRateText->setText(tr("%1k").arg(QString::number(basebandSampleRate / 1000.0f, 'g', 5)));
}
else
{
ui->sampleRateMode->setStyleSheet("QToolButton { background:rgb(50,50,50); }");
ui->sampleRateMode->setText("BB");
ui->sampleRate->setValueRange(8, DevicePlutoSDR::srLowLimitFreq/(1<<m_settings.m_log2Decim), DevicePlutoSDR::srHighLimitFreq/(1<<m_settings.m_log2Decim));
ui->sampleRate->setValue(m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim));
ui->sampleRate->setToolTip("Baseband sample rate (S/s)");
ui->deviceRateText->setToolTip("Device to host sample rate (S/s)");
ui->deviceRateText->setText(tr("%1k").arg(QString::number(m_settings.m_devSampleRate / 1000.0f, 'g', 5)));
}
ui->sampleRate->blockSignals(false);
}
void PlutoSDRMIMOGUI::displayFcTooltip()
{
if (m_rxElseTx)
{
int32_t fShift = DeviceSampleSource::calculateFrequencyShift(
m_settings.m_log2Decim,
(DeviceSampleSource::fcPos_t) m_settings.m_fcPosRx,
m_settings.m_devSampleRate,
DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD
);
ui->fcPos->setToolTip(tr("Relative position of device center frequency: %1 kHz").arg(QString::number(fShift / 1000.0f, 'g', 5)));
}
else
{
int32_t fShift = DeviceSampleSink::calculateFrequencyShift(
m_settings.m_log2Interp,
(DeviceSampleSink::fcPos_t) m_settings.m_fcPosTx,
m_settings.m_devSampleRate
);
ui->fcPos->setToolTip(tr("Relative position of device center frequency: %1 kHz").arg(QString::number(fShift / 1000.0f, 'g', 5)));
}
}
void PlutoSDRMIMOGUI::sendSettings(bool forceSettings)
{
m_forceSettings = forceSettings;
if(!m_updateTimer.isActive()) { m_updateTimer.start(100); }
}
void PlutoSDRMIMOGUI::updateHardware()
{
if (m_doApplySettings)
{
qDebug() << "PlutoSDRMIMOGUI::updateHardware";
PlutoSDRMIMO::MsgConfigurePlutoSDRMIMO* message = PlutoSDRMIMO::MsgConfigurePlutoSDRMIMO::create(m_settings, m_forceSettings);
m_sampleMIMO->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_updateTimer.stop();
}
}
void PlutoSDRMIMOGUI::blockApplySettings(bool block)
{
m_doApplySettings = !block;
}
void PlutoSDRMIMOGUI::updateSampleRateAndFrequency()
{
if (m_rxElseTx)
{
m_deviceUISet->getSpectrum()->setSampleRate(m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim));
m_deviceUISet->getSpectrum()->setCenterFrequency(m_rxDeviceCenterFrequency);
}
else
{
m_deviceUISet->getSpectrum()->setSampleRate(m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp));
m_deviceUISet->getSpectrum()->setCenterFrequency(m_txDeviceCenterFrequency);
}
displaySampleRate();
}
void PlutoSDRMIMOGUI::setFIRBWLimits()
{
if (m_rxElseTx)
{
float high = DevicePlutoSDR::firBWHighLimitFactor * m_sampleMIMO->getRxFIRSampleRate();
float low = DevicePlutoSDR::firBWLowLimitFactor * m_sampleMIMO->getRxFIRSampleRate();
ui->lpFIR->setValueRange(5, (int(low)/1000)+1, (int(high)/1000)+1);
ui->lpFIR->setValue(m_settings.m_lpfRxFIRBW/1000);
}
else
{
float high = DevicePlutoSDR::firBWHighLimitFactor * m_sampleMIMO->getTxFIRSampleRate();
float low = DevicePlutoSDR::firBWLowLimitFactor * m_sampleMIMO->getTxFIRSampleRate();
ui->lpFIR->setValueRange(5, (int(low)/1000)+1, (int(high)/1000)+1);
ui->lpFIR->setValue(m_settings.m_lpfTxFIRBW/1000);
}
}
void PlutoSDRMIMOGUI::setSampleRateLimits()
{
uint32_t low = ui->lpFIREnable->isChecked() ? DevicePlutoSDR::srLowLimitFreq / (1<<ui->lpFIRDecimation->currentIndex()) : DevicePlutoSDR::srLowLimitFreq;
ui->sampleRate->setValueRange(8, low, DevicePlutoSDR::srHighLimitFreq);
ui->sampleRate->setValue(m_settings.m_devSampleRate);
}
void PlutoSDRMIMOGUI::updateFrequencyLimits()
{
qint64 minLimit, maxLimit;
qint64 deltaFrequency;
// values should be in kHz
if (m_rxElseTx) {
deltaFrequency = m_settings.m_rxTransverterMode ? m_settings.m_rxTransverterDeltaFrequency/1000 : 0;
} else {
deltaFrequency = m_settings.m_txTransverterMode ? m_settings.m_txTransverterDeltaFrequency/1000 : 0;
}
m_sampleMIMO->getLORange(minLimit, maxLimit);
minLimit = minLimit/1000 + deltaFrequency;
maxLimit = maxLimit/1000 + deltaFrequency;
minLimit = minLimit < 0 ? 0 : minLimit > 9999999 ? 9999999 : minLimit;
maxLimit = maxLimit < 0 ? 0 : maxLimit > 9999999 ? 9999999 : maxLimit;
qDebug("PlutoSDRMIMOGUI::updateFrequencyLimits: delta: %lld min: %lld max: %lld", deltaFrequency, minLimit, maxLimit);
ui->centerFrequency->setValueRange(7, minLimit, maxLimit);
}
bool PlutoSDRMIMOGUI::handleMessage(const Message& message)
{
if (DSPMIMOSignalNotification::match(message))
{
const DSPMIMOSignalNotification& notif = (const DSPMIMOSignalNotification&) message;
int istream = notif.getIndex();
bool sourceOrSink = notif.getSourceOrSink();
if (sourceOrSink)
{
m_rxBasebandSampleRate = notif.getSampleRate();
m_rxDeviceCenterFrequency = notif.getCenterFrequency();
}
else
{
m_txBasebandSampleRate = notif.getSampleRate();
m_txDeviceCenterFrequency = notif.getCenterFrequency();
}
qDebug("PlutoSDRMIMOGUI::handleInputMessages: DSPMIMOSignalNotification: %s stream: %d SampleRate:%d, CenterFrequency:%llu",
sourceOrSink ? "source" : "sink",
istream,
notif.getSampleRate(),
notif.getCenterFrequency());
updateSampleRateAndFrequency();
return true;
}
else if (PlutoSDRMIMO::MsgConfigurePlutoSDRMIMO::match(message))
{
const PlutoSDRMIMO::MsgConfigurePlutoSDRMIMO& notif = (const PlutoSDRMIMO::MsgConfigurePlutoSDRMIMO&) message;
m_settings = notif.getSettings();
displaySettings();
return true;
}
return false;
}
void PlutoSDRMIMOGUI::handleInputMessages()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
{
if (handleMessage(*message)) {
delete message;
} else {
qDebug("PlutoSDRMIMOGUI::handleInputMessages: unhandled message: %s", message->getIdentifier());
}
}
}
void PlutoSDRMIMOGUI::updateStatus()
{
int stateRx = m_deviceUISet->m_deviceAPI->state(0);
int stateTx = m_deviceUISet->m_deviceAPI->state(1);
if (m_lastRxEngineState != stateRx)
{
switch(stateRx)
{
case DeviceAPI::StNotStarted:
ui->startStopRx->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break;
case DeviceAPI::StIdle:
ui->startStopRx->setStyleSheet("QToolButton { background-color : blue; }");
break;
case DeviceAPI::StRunning:
ui->startStopRx->setStyleSheet("QToolButton { background-color : green; }");
break;
case DeviceAPI::StError:
ui->startStopRx->setStyleSheet("QToolButton { background-color : red; }");
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
break;
default:
break;
}
m_lastRxEngineState = stateRx;
}
if (m_lastTxEngineState != stateTx)
{
switch(stateTx)
{
case DeviceAPI::StNotStarted:
ui->startStopTx->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break;
case DeviceAPI::StIdle:
ui->startStopTx->setStyleSheet("QToolButton { background-color : blue; }");
break;
case DeviceAPI::StRunning:
ui->startStopTx->setStyleSheet("QToolButton { background-color : green; }");
break;
case DeviceAPI::StError:
ui->startStopTx->setStyleSheet("QToolButton { background-color : red; }");
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
break;
default:
break;
}
m_lastTxEngineState = stateTx;
}
if (m_statusCounter % 2 == 0) // 1s
{
uint32_t samplerRate;
if (m_rxElseTx) {
samplerRate = m_sampleMIMO->getADCSampleRate();
} else {
samplerRate = m_sampleMIMO->getDACSampleRate();
}
if (samplerRate < 100000000) {
ui->adcRateText->setText(tr("%1k").arg(QString::number(samplerRate / 1000.0f, 'g', 5)));
} else {
ui->adcRateText->setText(tr("%1M").arg(QString::number(samplerRate / 1000000.0f, 'g', 5)));
}
}
if (m_statusCounter % 4 == 0) // 2s
{
std::string rssiStr;
if (m_rxElseTx) {
m_sampleMIMO->getRxRSSI(rssiStr, m_streamIndex);
} else {
m_sampleMIMO->getTxRSSI(rssiStr, m_streamIndex);
}
ui->rssiText->setText(tr("-%1").arg(QString::fromStdString(rssiStr)));
int gaindB;
if (m_rxElseTx) {
m_sampleMIMO->getRxGain(gaindB, m_streamIndex);
} else {
gaindB = 0;
}
ui->actualGainText->setText(tr("%1").arg(gaindB));
}
if (m_statusCounter % 10 == 0) // 5s
{
m_sampleMIMO->fetchTemperature();
ui->temperatureText->setText(tr("%1C").arg(QString::number(m_sampleMIMO->getTemperature(), 'f', 0)));
}
m_statusCounter++;
}
void PlutoSDRMIMOGUI::on_streamSide_currentIndexChanged(int index)
{
m_rxElseTx = index == 0;
displaySettings();
}
void PlutoSDRMIMOGUI::on_streamIndex_currentIndexChanged(int index)
{
m_streamIndex = index < 0 ? 0 : index > 1 ? 1 : index;
displaySettings();
}
void PlutoSDRMIMOGUI::on_spectrumSide_currentIndexChanged(int index)
{
m_spectrumRxElseTx = (index == 0);
m_deviceUISet->m_spectrum->setDisplayedStream(m_spectrumRxElseTx, m_spectrumStreamIndex);
m_deviceUISet->m_deviceAPI->setSpectrumSinkInput(m_spectrumRxElseTx, m_spectrumStreamIndex);
m_deviceUISet->setSpectrumScalingFactor(m_spectrumRxElseTx ? SDR_RX_SCALEF : SDR_TX_SCALEF);
updateSampleRateAndFrequency();
}
void PlutoSDRMIMOGUI::on_spectrumIndex_currentIndexChanged(int index)
{
m_spectrumStreamIndex = index < 0 ? 0 : index > 1 ? 1 : index;
m_deviceUISet->m_spectrum->setDisplayedStream(m_spectrumRxElseTx, m_spectrumStreamIndex);
m_deviceUISet->m_deviceAPI->setSpectrumSinkInput(m_spectrumRxElseTx, m_spectrumStreamIndex);
updateSampleRateAndFrequency();
}
void PlutoSDRMIMOGUI::on_startStopRx_toggled(bool checked)
{
if (m_doApplySettings)
{
PlutoSDRMIMO::MsgStartStop *message = PlutoSDRMIMO::MsgStartStop::create(checked, true);
m_sampleMIMO->getInputMessageQueue()->push(message);
}
}
void PlutoSDRMIMOGUI::on_startStopTx_toggled(bool checked)
{
if (m_doApplySettings)
{
PlutoSDRMIMO::MsgStartStop *message = PlutoSDRMIMO::MsgStartStop::create(checked, false);
m_sampleMIMO->getInputMessageQueue()->push(message);
}
}
void PlutoSDRMIMOGUI::on_centerFrequency_changed(quint64 value)
{
if (m_rxElseTx) {
m_settings.m_rxCenterFrequency = value * 1000;
} else {
m_settings.m_txCenterFrequency = value * 1000;
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_loPPM_valueChanged(int value)
{
ui->loPPMText->setText(QString("%1").arg(QString::number(value/10.0, 'f', 1)));
m_settings.m_LOppmTenths = value;
sendSettings();
}
void PlutoSDRMIMOGUI::on_dcOffset_toggled(bool checked)
{
m_settings.m_dcBlock = checked;
sendSettings();
}
void PlutoSDRMIMOGUI::on_iqImbalance_toggled(bool checked)
{
m_settings.m_iqCorrection = checked;
sendSettings();
}
void PlutoSDRMIMOGUI::on_rfDCOffset_toggled(bool checked)
{
m_settings.m_hwRFDCBlock = checked;
sendSettings();
}
void PlutoSDRMIMOGUI::on_bbDCOffset_toggled(bool checked)
{
m_settings.m_hwBBDCBlock = checked;
sendSettings();
}
void PlutoSDRMIMOGUI::on_hwIQImbalance_toggled(bool checked)
{
m_settings.m_hwIQCorrection = checked;
sendSettings();
}
void PlutoSDRMIMOGUI::on_swDecim_currentIndexChanged(int index)
{
if (m_rxElseTx) {
m_settings.m_log2Decim = index > 6 ? 6 : index;
} else {
m_settings.m_log2Interp = index > 6 ? 6 : index;
}
displaySampleRate();
m_settings.m_devSampleRate = ui->sampleRate->getValueNew();
if (!m_sampleRateMode)
{
if (m_rxElseTx) {
m_settings.m_devSampleRate <<= m_settings.m_log2Decim;
} else {
m_settings.m_devSampleRate <<= m_settings.m_log2Interp;
}
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_fcPos_currentIndexChanged(int index)
{
PlutoSDRMIMOSettings::fcPos_t fcPos = (PlutoSDRMIMOSettings::fcPos_t) (index < (int) PlutoSDRMIMOSettings::FC_POS_END ? index : PlutoSDRMIMOSettings::FC_POS_CENTER);
if (m_rxElseTx) {
m_settings.m_fcPosRx = fcPos;
} else {
m_settings.m_fcPosTx = fcPos;
}
displayFcTooltip();
sendSettings();
}
void PlutoSDRMIMOGUI::on_sampleRate_changed(quint64 value)
{
m_settings.m_devSampleRate = value;
if (!m_sampleRateMode)
{
if (m_rxElseTx) {
m_settings.m_devSampleRate <<= m_settings.m_log2Decim;
} else {
m_settings.m_devSampleRate <<= m_settings.m_log2Interp;
}
}
displayFcTooltip();
sendSettings();
}
void PlutoSDRMIMOGUI::on_lpf_changed(quint64 value)
{
if (m_rxElseTx) {
m_settings.m_lpfBWRx = value * 1000;
} else {
m_settings.m_lpfBWTx = value * 1000;
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_lpFIREnable_toggled(bool checked)
{
if (m_rxElseTx) {
m_settings.m_lpfRxFIREnable = checked;
} else {
m_settings.m_lpfTxFIREnable = checked;
}
ui->lpFIRDecimation->setEnabled(checked);
ui->lpFIRGain->setEnabled(checked);
sendSettings();
}
void PlutoSDRMIMOGUI::on_lpFIR_changed(quint64 value)
{
if (m_rxElseTx) {
m_settings.m_lpfRxFIRBW = value * 1000;
} else {
m_settings.m_lpfTxFIRBW = value * 1000;
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_lpFIRDecimation_currentIndexChanged(int index)
{
if (m_rxElseTx) {
m_settings.m_lpfRxFIRlog2Decim = index > 2 ? 2 : index;
} else {
m_settings.m_lpfTxFIRlog2Interp = index > 2 ? 2 : index;
}
setSampleRateLimits();
sendSettings();
}
void PlutoSDRMIMOGUI::on_lpFIRGain_currentIndexChanged(int index)
{
if (m_rxElseTx) {
m_settings.m_lpfRxFIRGain = 6*(index > 3 ? 3 : index) - 12;
} else {
m_settings.m_lpfTxFIRGain = 6*(index > 3 ? 3 : index) - 12;
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_gainMode_currentIndexChanged(int index)
{
if (m_streamIndex == 0)
{
m_settings.m_rx0GainMode = (PlutoSDRMIMOSettings::GainMode) (index < PlutoSDRMIMOSettings::GAIN_END ? index : 0);
ui->gain->setEnabled(m_settings.m_rx0GainMode == PlutoSDRMIMOSettings::GAIN_MANUAL);
}
else
{
m_settings.m_rx1GainMode = (PlutoSDRMIMOSettings::GainMode) (index < PlutoSDRMIMOSettings::GAIN_END ? index : 0);
ui->gain->setEnabled(m_settings.m_rx1GainMode == PlutoSDRMIMOSettings::GAIN_MANUAL);
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_gain_valueChanged(int value)
{
ui->gainText->setText(tr("%1").arg(value));
if (m_streamIndex == 0) {
m_settings.m_rx0Gain = value;
} else {
m_settings.m_rx1Gain = value;
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_antenna_currentIndexChanged(int index)
{
if (m_rxElseTx)
{
if (m_streamIndex == 0) {
m_settings.m_rx0AntennaPath = (PlutoSDRMIMOSettings::RFPathRx) (index < PlutoSDRMIMOSettings::RFPATHRX_END ? index : 0);
} else {
m_settings.m_rx1AntennaPath = (PlutoSDRMIMOSettings::RFPathRx) (index < PlutoSDRMIMOSettings::RFPATHRX_END ? index : 0);
}
}
else
{
if (m_streamIndex == 0) {
m_settings.m_tx0AntennaPath = (PlutoSDRMIMOSettings::RFPathTx) (index < PlutoSDRMIMOSettings::RFPATHTX_END ? index : 0);
} else {
m_settings.m_tx1AntennaPath = (PlutoSDRMIMOSettings::RFPathTx) (index < PlutoSDRMIMOSettings::RFPATHTX_END ? index : 0);
}
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_transverter_clicked()
{
if (m_rxElseTx)
{
m_settings.m_rxTransverterMode = ui->transverter->getDeltaFrequencyAcive();
m_settings.m_rxTransverterDeltaFrequency = ui->transverter->getDeltaFrequency();
m_settings.m_iqOrder = ui->transverter->getIQOrder();
qDebug("PlutoSDRInputGui::on_transverter_clicked: %lld Hz %s",
m_settings.m_rxTransverterDeltaFrequency, m_settings.m_rxTransverterMode ? "on" : "off");
}
else
{
m_settings.m_txTransverterMode = ui->transverter->getDeltaFrequencyAcive();
m_settings.m_txTransverterDeltaFrequency = ui->transverter->getDeltaFrequency();
qDebug("PlutoSDRInputGui::on_transverter_clicked: %lld Hz %s",
m_settings.m_rxTransverterDeltaFrequency, m_settings.m_txTransverterMode ? "on" : "off");
}
updateFrequencyLimits();
if (m_rxElseTx) {
m_settings.m_rxCenterFrequency = ui->centerFrequency->getValueNew()*1000;
} else {
m_settings.m_txCenterFrequency = ui->centerFrequency->getValueNew()*1000;
}
sendSettings();
}
void PlutoSDRMIMOGUI::on_sampleRateMode_toggled(bool checked)
{
m_sampleRateMode = checked;
displaySampleRate();
}
void PlutoSDRMIMOGUI::openDeviceSettingsDialog(const QPoint& p)
{
BasicDeviceSettingsDialog dialog(this);
dialog.setUseReverseAPI(m_settings.m_useReverseAPI);
dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress);
dialog.setReverseAPIPort(m_settings.m_reverseAPIPort);
dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex);
dialog.move(p);
dialog.exec();
m_settings.m_useReverseAPI = dialog.useReverseAPI();
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
sendSettings();
}
@@ -0,0 +1,120 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 _PLUTOSDRMIMO_PLUTOSDRMIMOGUI_H_
#define _PLUTOSDRMIMO_PLUTOSDRMIMOGUI_H_
#include <QTimer>
#include <QWidget>
#include "util/messagequeue.h"
#include "device/devicegui.h"
#include "plutosdrmimosettings.h"
class DeviceUISet;
class PlutoSDRMIMO;
namespace Ui {
class PlutoSDRMIMOGUI;
}
class PlutoSDRMIMOGUI : public DeviceGUI {
Q_OBJECT
public:
explicit PlutoSDRMIMOGUI(DeviceUISet *deviceUISet, QWidget* parent = nullptr);
virtual ~PlutoSDRMIMOGUI();
virtual void destroy();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
private:
Ui::PlutoSDRMIMOGUI* ui;
DeviceUISet* m_deviceUISet;
PlutoSDRMIMOSettings m_settings;
bool m_rxElseTx; //!< Which side is being dealt with
int m_streamIndex; //!< Current stream index being dealt with
bool m_spectrumRxElseTx;
int m_spectrumStreamIndex; //!< Index of the stream displayed on main spectrum
bool m_gainLock; //!< Lock Rx or Tx channel gains (set channel gains to gain of channel 0 when engaged)
QTimer m_updateTimer;
QTimer m_statusTimer;
bool m_doApplySettings;
bool m_forceSettings;
PlutoSDRMIMO* m_sampleMIMO;
std::size_t m_tickCount;
int m_rxBasebandSampleRate;
int m_txBasebandSampleRate;
quint64 m_rxDeviceCenterFrequency; //!< Center frequency in Rx device
quint64 m_txDeviceCenterFrequency; //!< Center frequency in Tx device
int m_lastRxEngineState;
int m_lastTxEngineState;
uint32_t m_statusCounter;
MessageQueue m_inputMessageQueue;
bool m_sampleRateMode;
void displaySettings();
void displaySampleRate();
void displayFcTooltip();
void sendSettings(bool forceSettings = false);
void blockApplySettings(bool block);
void updateSampleRateAndFrequency();
void setFIRBWLimits();
void setSampleRateLimits();
void updateFrequencyLimits();
bool handleMessage(const Message& message);
private slots:
void handleInputMessages();
void updateHardware();
void updateStatus();
void on_streamSide_currentIndexChanged(int index);
void on_streamIndex_currentIndexChanged(int index);
void on_spectrumSide_currentIndexChanged(int index);
void on_spectrumIndex_currentIndexChanged(int index);
void on_startStopRx_toggled(bool checked);
void on_startStopTx_toggled(bool checked);
void on_centerFrequency_changed(quint64 value);
void on_loPPM_valueChanged(int value);
void on_dcOffset_toggled(bool checked);
void on_iqImbalance_toggled(bool checked);
void on_sampleRate_changed(quint64 value);
void on_sampleRateMode_toggled(bool checked);
void on_fcPos_currentIndexChanged(int index);
void on_swDecim_currentIndexChanged(int index);
void on_gainLock_toggled(bool checked);
void on_gainMode_currentIndexChanged(int index);
void on_gain_valueChanged(int value);
void on_transverter_clicked();
void on_rfDCOffset_toggled(bool checked);
void on_bbDCOffset_toggled(bool checked);
void on_hwIQImbalance_toggled(bool checked);
void on_lpf_changed(quint64 value);
void on_lpFIREnable_toggled(bool checked);
void on_lpFIR_changed(quint64 value);
void on_lpFIRDecimation_currentIndexChanged(int index);
void on_lpFIRGain_currentIndexChanged(int index);
void on_antenna_currentIndexChanged(int index);
void openDeviceSettingsDialog(const QPoint& p);
};
#endif // _PLUTOSDRMIMO_PLUTOSDRMIMOGUI_H_
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,142 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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"
#include "plutosdr/deviceplutosdr.h"
#ifndef SERVER_MODE
#include "plutosdrmimogui.h"
#endif
#include "plutosdrmimo.h"
#include "plutosdrmimoplugin.h"
#include "plutosdrmimowebapiadapter.h"
const PluginDescriptor PlutoSDRMIMOPlugin::m_pluginDescriptor = {
QStringLiteral("PlutoSDR"),
QStringLiteral("PlutoSDR MIMO"),
QStringLiteral("6.11.0"),
QStringLiteral("(c) Edouard Griffiths, F4EXB"),
QStringLiteral("https://github.com/f4exb/sdrangel"),
true,
QStringLiteral("https://github.com/f4exb/sdrangel")
};
static constexpr const char* const m_hardwareID = "PlutoSDR";
static constexpr const char* const m_deviceTypeID = PLUTOSDRMIMO_DEVICE_TYPE_ID;
PlutoSDRMIMOPlugin::PlutoSDRMIMOPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& PlutoSDRMIMOPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void PlutoSDRMIMOPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleMIMO(m_deviceTypeID, this);
}
void PlutoSDRMIMOPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices)
{
if (listedHwIds.contains(m_hardwareID)) { // check if it was done
return;
}
DevicePlutoSDR::instance().enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
PluginInterface::SamplingDevices PlutoSDRMIMOPlugin::enumSampleMIMO(const OriginDevices& originDevices)
{
SamplingDevices result;
for (OriginDevices::const_iterator it = originDevices.begin(); it != originDevices.end(); ++it)
{
if (it->hardwareId == m_hardwareID)
{
QString displayedName = it->displayableName;
displayedName.replace(QString(":$1]"), QString("]"));
result.append(SamplingDevice(
displayedName,
m_hardwareID,
m_deviceTypeID,
it->serial,
it->sequence,
PluginInterface::SamplingDevice::PhysicalDevice,
PluginInterface::SamplingDevice::StreamMIMO,
1,
0
));
}
}
return result;
}
#ifdef SERVER_MODE
DeviceGUI* PlutoSDRMIMOPlugin::createSampleMIMOPluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
(void) sourceId;
(void) widget;
(void) deviceUISet;
return nullptr;
}
#else
DeviceGUI* PlutoSDRMIMOPlugin::createSampleMIMOPluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
if (sourceId == m_deviceTypeID)
{
PlutoSDRMIMOGUI* gui = new PlutoSDRMIMOGUI(deviceUISet);
*widget = gui;
return gui;
}
else
{
return nullptr;
}
}
#endif
DeviceSampleMIMO *PlutoSDRMIMOPlugin::createSampleMIMOPluginInstance(const QString& mimoId, DeviceAPI *deviceAPI)
{
if (mimoId == m_deviceTypeID)
{
PlutoSDRMIMO* input = new PlutoSDRMIMO(deviceAPI);
return input;
}
else
{
return nullptr;
}
}
DeviceWebAPIAdapter *PlutoSDRMIMOPlugin::createDeviceWebAPIAdapter() const
{
return new PlutoSDRMIMOWebAPIAdapter();
}
@@ -0,0 +1,53 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 _PLUTOSDRMIMO_PLUTOSDRMIMOPLUGIN_H
#define _PLUTOSDRMIMO_PLUTOSDRMIMOPLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
class PluginAPI;
#define PLUTOSDRMIMO_DEVICE_TYPE_ID "sdrangel.samplemimo.bladerf2mimo"
class PlutoSDRMIMOPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID PLUTOSDRMIMO_DEVICE_TYPE_ID)
public:
explicit PlutoSDRMIMOPlugin(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 DeviceGUI* createSampleMIMOPluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet);
virtual DeviceSampleMIMO* createSampleMIMOPluginInstance(const QString& sourceId, DeviceAPI *deviceAPI);
virtual DeviceWebAPIAdapter* createDeviceWebAPIAdapter() const;
private:
static const PluginDescriptor m_pluginDescriptor;
};
#endif // _PLUTOSDRMIMO_PLUTOSDRMIMOPLUGIN_H
@@ -0,0 +1,369 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 "plutosdrmimosettings.h"
#include <QtGlobal>
#include "util/simpleserializer.h"
PlutoSDRMIMOSettings::PlutoSDRMIMOSettings()
{
resetToDefaults();
}
void PlutoSDRMIMOSettings::resetToDefaults()
{
m_devSampleRate = 2500 * 1000;
m_LOppmTenths = 0;
m_rxCenterFrequency = 435000 * 1000;
m_fcPosRx = FC_POS_CENTER;
m_log2Decim = 0;
m_dcBlock = false;
m_iqCorrection = false;
m_hwBBDCBlock = true;
m_hwRFDCBlock = true;
m_hwIQCorrection = true;
m_lpfBWRx = 1500000;
m_lpfRxFIREnable = false;
m_lpfRxFIRBW = 500000U;
m_lpfRxFIRlog2Decim = 0;
m_lpfRxFIRGain = 0;
m_rxTransverterMode = false;
m_rxTransverterDeltaFrequency = 0;
m_iqOrder = true;
m_rx0Gain = 40;
m_rx0AntennaPath = RFPATHRX_A_BAL;
m_rx0GainMode = GAIN_MANUAL;
m_rx1Gain = 40;
m_rx1AntennaPath = RFPATHRX_A_BAL;
m_rx1GainMode = GAIN_MANUAL;
m_txCenterFrequency = 435000 * 1000;
m_fcPosTx = FC_POS_CENTER;
m_log2Interp = 0;
m_lpfBWTx = 1500000;
m_lpfTxFIREnable = false;
m_lpfTxFIRBW = 500000U;
m_lpfTxFIRlog2Interp = 0;
m_lpfTxFIRGain = 0;
m_txTransverterMode = false;
m_txTransverterDeltaFrequency = 0;
m_tx0Att = -50;
m_tx0AntennaPath = RFPATHTX_A;
m_tx1Att = -50;
m_tx1AntennaPath = RFPATHTX_A;
m_useReverseAPI = false;
m_reverseAPIAddress = "127.0.0.1";
m_reverseAPIPort = 8888;
m_reverseAPIDeviceIndex = 0;
}
QByteArray PlutoSDRMIMOSettings::serialize() const
{
SimpleSerializer s(1);
// Common
s.writeU64(1, m_devSampleRate);
s.writeS32(2, m_LOppmTenths);
// Rx
s.writeU64(10, m_rxCenterFrequency);
s.writeS32(11, m_fcPosRx);
s.writeU32(12, m_log2Decim);
s.writeBool(13, m_dcBlock);
s.writeBool(14, m_iqCorrection);
s.writeBool(15, m_hwBBDCBlock);
s.writeBool(16, m_hwRFDCBlock);
s.writeBool(17, m_hwIQCorrection);
s.writeU32(18, m_lpfBWRx);
s.writeBool(19, m_lpfRxFIREnable);
s.writeS32(20, m_lpfRxFIRGain);
s.writeU32(21, m_lpfRxFIRlog2Decim);
s.writeU32(22, m_lpfRxFIRBW);
s.writeBool(23, m_rxTransverterMode);
s.writeS64(24, m_rxTransverterDeltaFrequency);
s.writeBool(25, m_iqOrder);
// Rx0
s.writeU32(40, m_rx0Gain);
s.writeS32(41, (int) m_rx0AntennaPath);
s.writeS32(42, (int) m_rx0GainMode);
// Rx1
s.writeU32(50, m_rx1Gain);
s.writeS32(51, (int) m_rx1AntennaPath);
s.writeS32(52, (int) m_rx1GainMode);
// Tx
s.writeU64(60, m_txCenterFrequency);
s.writeS32(61, m_fcPosTx);
s.writeU32(62, m_log2Interp);
s.writeU32(63, m_lpfBWTx);
s.writeBool(64, m_lpfTxFIREnable);
s.writeU32(65, m_lpfTxFIRBW);
s.writeU32(66, m_lpfTxFIRlog2Interp);
s.writeS32(67, m_lpfTxFIRGain);
s.writeBool(68, m_txTransverterMode);
s.writeS64(69, m_txTransverterDeltaFrequency);
// Tx0
s.writeS32(80, m_tx0Att);
s.writeS32(81, (int) m_tx0AntennaPath);
// Tx1
s.writeS32(90, m_tx1Att);
s.writeS32(91, (int) m_tx1AntennaPath);
// Reverse API
s.writeBool(100, m_useReverseAPI);
s.writeString(101, m_reverseAPIAddress);
s.writeU32(102, m_reverseAPIPort);
s.writeU32(103, m_reverseAPIDeviceIndex);
return s.final();
}
bool PlutoSDRMIMOSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
int intval;
uint32_t uintval;
// Common
d.readU64(1, &m_devSampleRate, 2500 * 1000);
d.readS32(2, &m_LOppmTenths, 0);
// Rx
d.readU64(10, &m_rxCenterFrequency, 435000*1000);
d.readS32(11, &intval, 0);
if ((intval < 0) || (intval > 2)) {
m_fcPosRx = FC_POS_CENTER;
} else {
m_fcPosRx = (fcPos_t) intval;
}
d.readU32(12, &m_log2Decim, 0);
d.readBool(13, &m_dcBlock, false);
d.readBool(14, &m_iqCorrection, false);
d.readBool(15, &m_hwBBDCBlock, true);
d.readBool(16, &m_hwRFDCBlock, true);
d.readBool(17, &m_hwIQCorrection, true);
d.readU32(18, &m_lpfBWRx, 1500000);
d.readBool(19, &m_lpfRxFIREnable, false);
d.readS32(20, &m_lpfRxFIRGain, 0);
d.readU32(21, &uintval, 0);
if (uintval > 2) {
m_lpfRxFIRlog2Decim = 2;
} else {
m_lpfRxFIRlog2Decim = uintval;
}
d.readU32(22, &m_lpfRxFIRBW, 500000U);
d.readBool(23, &m_rxTransverterMode, false);
d.readS64(24, &m_rxTransverterDeltaFrequency, 0);
d.readBool(25, &m_iqOrder, true);
// Rx0
d.readU32(40, &m_rx0Gain, 40);
d.readS32(41, &intval, 0);
if ((intval >= 0) && (intval < (int) RFPATHRX_END)) {
m_rx0AntennaPath = (RFPathRx) intval;
} else {
m_rx0AntennaPath = RFPATHRX_A_BAL;
}
d.readS32(42, &intval, 0);
if ((intval >= 0) && (intval < (int) GAIN_END)) {
m_rx0GainMode = (GainMode) intval;
} else {
m_rx0GainMode = GAIN_MANUAL;
}
// Rx1
d.readU32(50, &m_rx0Gain, 40);
d.readS32(51, &intval, 0);
if ((intval >= 0) && (intval < (int) RFPATHRX_END)) {
m_rx0AntennaPath = (RFPathRx) intval;
} else {
m_rx0AntennaPath = RFPATHRX_A_BAL;
}
d.readS32(52, &intval, 0);
if ((intval >= 0) && (intval < (int) GAIN_END)) {
m_rx0GainMode = (GainMode) intval;
} else {
m_rx0GainMode = GAIN_MANUAL;
}
// Tx
d.readU64(60, &m_txCenterFrequency, 435000*1000);
d.readS32(61, &intval, 0);
if ((intval < 0) || (intval > 2)) {
m_fcPosTx = FC_POS_CENTER;
} else {
m_fcPosTx = (fcPos_t) intval;
}
d.readU32(62, &m_log2Interp, 0);
d.readU32(63, &m_lpfBWTx, 1500000);
d.readBool(64, &m_lpfTxFIREnable, false);
d.readU32(65, &m_lpfTxFIRBW, 500000U);
d.readU32(66, &uintval, 0);
if (uintval > 2) {
m_lpfTxFIRlog2Interp = 2;
} else {
m_lpfTxFIRlog2Interp = uintval;
}
d.readS32(67, &m_lpfTxFIRGain, 0);
d.readBool(68, &m_txTransverterMode, false);
d.readS64(69, &m_txTransverterDeltaFrequency, 0);
// Tx0
d.readS32(80, &m_tx0Att, -50);
d.readS32(81, &intval, 0);
if ((intval >= 0) && (intval < (int) RFPATHTX_END)) {
m_tx0AntennaPath = (RFPathTx) intval;
} else {
m_tx0AntennaPath = RFPATHTX_A;
}
// Tx1
d.readS32(80, &m_tx1Att, -50);
d.readS32(81, &intval, 0);
if ((intval >= 0) && (intval < (int) RFPATHTX_END)) {
m_tx1AntennaPath = (RFPathTx) intval;
} else {
m_tx1AntennaPath = RFPATHTX_A;
}
// Reverse API
d.readBool(100, &m_useReverseAPI, false);
d.readString(101, &m_reverseAPIAddress, "127.0.0.1");
d.readU32(102, &uintval, 0);
if ((uintval > 1023) && (uintval < 65535)) {
m_reverseAPIPort = uintval;
} else {
m_reverseAPIPort = 8888;
}
d.readU32(103, &uintval, 0);
m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
return true;
}
else
{
resetToDefaults();
return false;
}
}
void PlutoSDRMIMOSettings::translateRFPathTx(RFPathTx path, QString& s)
{
switch(path)
{
case RFPATHTX_A:
s = "A";
break;
case RFPATHTX_B:
s = "B";
break;
default:
s = "A";
break;
}
}
void PlutoSDRMIMOSettings::translateRFPathRx(RFPathRx path, QString& s)
{
switch(path)
{
case RFPATHRX_A_BAL:
s = "A_BALANCED";
break;
case RFPATHRX_B_BAL:
s = "B_BALANCED";
break;
case RFPATHRX_C_BAL:
s = "C_BALANCED";
break;
case RFPATHRX_A_NEG:
s = "A_N";
break;
case RFPATHRX_A_POS:
s = "A_P";
break;
case RFPATHRX_B_NEG:
s = "B_N";
break;
case RFPATHRX_B_POS:
s = "B_P";
break;
case RFPATHRX_C_NEG:
s = "C_N";
break;
case RFPATHRX_C_POS:
s = "C_P";
break;
case RFPATHRX_TX1MON:
s = "TX_MONITOR1";
break;
case RFPATHRX_TX2MON:
s = "TX_MONITOR2";
break;
case RFPATHRX_TX3MON:
s = "TX_MONITOR3";
break;
default:
s = "A_BALANCED";
break;
}
}
void PlutoSDRMIMOSettings::translateGainMode(GainMode mode, QString& s)
{
switch(mode)
{
case GAIN_MANUAL:
s = "manual";
break;
case GAIN_AGC_SLOW:
s = "slow_attack";
break;
case GAIN_AGC_FAST:
s = "fast_attack";
break;
case GAIN_HYBRID:
s = "hybrid";
break;
default:
s = "manual";
break;
}
}
@@ -0,0 +1,136 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 _PLUTOSDR_PLUTOSDRMIMOSETTINGS_H_
#define _PLUTOSDR_PLUTOSDRMIMOSETTINGS_H_
#include <QtGlobal>
#include <QString>
#include <stdint.h>
struct PlutoSDRMIMOSettings {
typedef enum {
FC_POS_INFRA = 0,
FC_POS_SUPRA,
FC_POS_CENTER,
FC_POS_END
} fcPos_t;
enum RFPathRx
{
RFPATHRX_A_BAL = 0,
RFPATHRX_B_BAL,
RFPATHRX_C_BAL,
RFPATHRX_A_NEG,
RFPATHRX_A_POS,
RFPATHRX_B_NEG,
RFPATHRX_B_POS,
RFPATHRX_C_NEG,
RFPATHRX_C_POS,
RFPATHRX_TX1MON,
RFPATHRX_TX2MON,
RFPATHRX_TX3MON,
RFPATHRX_END
};
enum RFPathTx
{
RFPATHTX_A = 0,
RFPATHTX_B,
RFPATHTX_END
};
typedef enum {
GAIN_MANUAL,
GAIN_AGC_SLOW,
GAIN_AGC_FAST,
GAIN_HYBRID,
GAIN_END
} GainMode;
// Common
quint64 m_devSampleRate; //!< Host interface sample rate
qint32 m_LOppmTenths; //!< XO correction
// Common Rx
quint64 m_rxCenterFrequency;
bool m_dcBlock;
bool m_iqCorrection;
bool m_hwBBDCBlock; //!< Hardware baseband DC blocking
bool m_hwRFDCBlock; //!< Hardware RF DC blocking
bool m_hwIQCorrection; //!< Hardware IQ correction
fcPos_t m_fcPosRx;
bool m_rxTransverterMode;
qint64 m_rxTransverterDeltaFrequency;
bool m_iqOrder;
quint32 m_lpfBWRx; //!< analog lowpass filter bandwidth (Hz)
bool m_lpfRxFIREnable; //!< enable digital lowpass FIR filter
quint32 m_lpfRxFIRBW; //!< digital lowpass FIR filter bandwidth (Hz)
quint32 m_lpfRxFIRlog2Decim; //!< digital lowpass FIR filter log2 of decimation factor (0..2)
int m_lpfRxFIRGain; //!< digital lowpass FIR filter gain (dB)
quint32 m_log2Decim;
// Rx0
quint32 m_rx0Gain; //!< "hardware" gain
GainMode m_rx0GainMode;
RFPathRx m_rx0AntennaPath;
// Rx1
quint32 m_rx1Gain; //!< "hardware" gain
GainMode m_rx1GainMode;
RFPathRx m_rx1AntennaPath;
// Common Tx
quint64 m_txCenterFrequency;
fcPos_t m_fcPosTx;
bool m_txTransverterMode;
qint64 m_txTransverterDeltaFrequency;
quint32 m_lpfBWTx; //!< analog lowpass filter bandwidth (Hz)
bool m_lpfTxFIREnable; //!< enable digital lowpass FIR filter
quint32 m_lpfTxFIRBW; //!< digital lowpass FIR filter bandwidth (Hz)
quint32 m_lpfTxFIRlog2Interp; //!< digital lowpass FIR filter log2 of interpolation factor (0..2)
int m_lpfTxFIRGain; //!< digital lowpass FIR filter gain (dB)
quint32 m_log2Interp;
// Tx0
qint32 m_tx0Att; //!< "hardware" attenuation in dB fourths
RFPathTx m_tx0AntennaPath;
// Tx1
qint32 m_tx1Att; //!< "hardware" attenuation in dB fourths
RFPathTx m_tx1AntennaPath;
// global settings to be saved
// common device settings
// individual channel settings
bool m_useReverseAPI;
QString m_reverseAPIAddress;
uint16_t m_reverseAPIPort;
uint16_t m_reverseAPIDeviceIndex;
static const int m_plutoSDRBlockSizeSamples = 64*256; //complex samples per buffer (must be multiple of 64)
PlutoSDRMIMOSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
static void translateRFPathRx(RFPathRx path, QString& s);
static void translateGainMode(GainMode mod, QString& s);
static void translateRFPathTx(RFPathTx path, QString& s);
};
#endif /* _PLUTOSDR_PLUTOSDRMIMOSETTINGS_H_ */
@@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019 Edouard Griffiths, F4EXB //
// //
// Implementation of static web API adapters used for preset serialization and //
// deserialization //
// //
// 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 "SWGDeviceSettings.h"
//#include "limesdrmimo.h"
#include "plutosdrmimowebapiadapter.h"
PlutoSDRMIMOWebAPIAdapter::PlutoSDRMIMOWebAPIAdapter()
{}
PlutoSDRMIMOWebAPIAdapter::~PlutoSDRMIMOWebAPIAdapter()
{}
int PlutoSDRMIMOWebAPIAdapter::webapiSettingsGet(
SWGSDRangel::SWGDeviceSettings& response,
QString& errorMessage)
{
(void) errorMessage;
(void) response;
return 501;
}
int PlutoSDRMIMOWebAPIAdapter::webapiSettingsPutPatch(
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage)
{
(void) force;
(void) deviceSettingsKeys;
(void) response;
(void) errorMessage;
return 501;
}
@@ -0,0 +1,49 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019 Edouard Griffiths, F4EXB //
// //
// Implementation of static web API adapters used for preset serialization and //
// deserialization //
// //
// 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 _PLUTOSDR_PLUTOSDRMIMOWEBAPIADAPTER_H_
#define _PLUTOSDR_PLUTOSDRMIMOWEBAPIADAPTER_H_
#include "device/devicewebapiadapter.h"
#include "plutosdrmimosettings.h"
class PlutoSDRMIMOWebAPIAdapter : public DeviceWebAPIAdapter
{
public:
PlutoSDRMIMOWebAPIAdapter();
virtual ~PlutoSDRMIMOWebAPIAdapter();
virtual QByteArray serialize() { return m_settings.serialize(); }
virtual bool deserialize(const QByteArray& data) { return m_settings.deserialize(data); }
virtual int webapiSettingsGet(
SWGSDRangel::SWGDeviceSettings& response,
QString& errorMessage);
virtual int webapiSettingsPutPatch(
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage);
private:
PlutoSDRMIMOSettings m_settings;
};
#endif // _PLUTOSDR_PLUTOSDRMIMOWEBAPIADAPTER_H_
@@ -0,0 +1,358 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 "plutosdr/deviceplutosdrbox.h"
#include "dsp/samplemififo.h"
#include "plutosdrmimosettings.h"
#include "plutosdrmithread.h"
PlutoSDRMIThread::PlutoSDRMIThread(DevicePlutoSDRBox* plutoBox, QObject* parent) :
QThread(parent),
m_running(false),
m_plutoBox(plutoBox),
m_sampleFifo(nullptr),
m_iqOrder(true)
{
qDebug("PlutoSDRMIThread::PlutoSDRMIThread");
m_buf[0] = new qint16[2*m_plutoSDRBlockSizeSamples];
m_buf[1] = new qint16[2*m_plutoSDRBlockSizeSamples];
for (unsigned int i = 0; i < 2; i++) {
m_convertBuffer[i].resize(m_plutoSDRBlockSizeSamples, Sample{0,0});
}
}
PlutoSDRMIThread::~PlutoSDRMIThread()
{
qDebug("PlutoSDRMIThread::~PlutoSDRMIThread");
if (m_running) {
stopWork();
}
delete[] m_buf[0];
delete[] m_buf[1];
}
void PlutoSDRMIThread::startWork()
{
m_startWaitMutex.lock();
start();
while(!m_running) {
m_startWaiter.wait(&m_startWaitMutex, 100);
}
m_startWaitMutex.unlock();
}
void PlutoSDRMIThread::stopWork()
{
m_running = false;
wait();
}
void PlutoSDRMIThread::setLog2Decimation(unsigned int log2Decim)
{
m_log2Decim = log2Decim;
}
unsigned int PlutoSDRMIThread::getLog2Decimation() const
{
return m_log2Decim;
}
void PlutoSDRMIThread::setFcPos(int fcPos)
{
m_fcPos = fcPos;
}
int PlutoSDRMIThread::getFcPos() const
{
return m_fcPos;
}
void PlutoSDRMIThread::run()
{
std::ptrdiff_t p_inc = m_plutoBox->rxBufferStep();
int sampleSize = m_plutoBox->getRxSampleSize(); // I/Q sample size in bytes
int nbChan = p_inc / sampleSize; // number of I/Q channels
qDebug("PlutoSDRMIThread::run: rxBufferStep: %ld bytes", p_inc);
qDebug("PlutoSDRMIThread::run: Rx sample size is %ld bytes", m_plutoBox->getRxSampleSize());
qDebug("PlutoSDRMIThread::run: Tx sample size is %ld bytes", m_plutoBox->getTxSampleSize());
qDebug("PlutoSDRMIThread::run: nominal nbytes_rx is %ld bytes with 1 refill", m_plutoSDRBlockSizeSamples*p_inc);
m_running = true;
m_startWaiter.wakeAll();
while (m_running)
{
ssize_t nbytes_rx;
char *p_dat, *p_end;
int ihs; // half sample index (I then Q to make a sample)
// Refill RX buffer
nbytes_rx = m_plutoBox->rxBufferRefill();
if (nbytes_rx != m_plutoSDRBlockSizeSamples*p_inc)
{
qWarning("PlutoSDRMIThread::run: error refilling buf %d / %ld", (int) nbytes_rx, (int) m_plutoSDRBlockSizeSamples*p_inc);
usleep(200000);
continue;
}
// READ: Get pointers to RX buf and read IQ from RX buf port 0
p_dat = m_plutoBox->rxBufferFirst();
p_end = m_plutoBox->rxBufferEnd();
ihs = 0;
// p_inc is 8 on a char* buffer therefore each iteration processes a couple of IQ samples,
// I and Q each being two bytes
// conversion is not needed as samples are little endian
for (; p_dat < p_end; p_dat += p_inc, ihs += 2)
{
m_buf[0][ihs] = *(((int16_t *) p_dat) + 0);
m_buf[0][ihs+1] = *(((int16_t *) p_dat) + 1);
if (nbChan == 1)
{
m_buf[1][ihs] = 0;
m_buf[1][ihs+1] = 0;
}
else if (nbChan == 2)
{
m_buf[1][ihs] = *(((int16_t *) p_dat) + 2);
m_buf[1][ihs+1] = *(((int16_t *) p_dat) + 3);
}
}
std::vector<SampleVector::const_iterator> vbegin;
int lengths[2];
for (unsigned int channel = 0; channel < 2; channel++)
{
if (m_iqOrder) {
lengths[channel] = channelCallbackIQ(m_buf[channel], 2*m_plutoSDRBlockSizeSamples, channel);
} else {
lengths[channel] = channelCallbackQI(m_buf[channel], 2*m_plutoSDRBlockSizeSamples, channel);
}
vbegin.push_back(m_convertBuffer[channel].begin());
}
if (lengths[0] == lengths[1])
{
m_sampleFifo->writeSync(vbegin, lengths[0]);
}
else
{
qWarning("PlutoSDRMIThread::run: unequal channel lengths: [0]=%d [1]=%d", lengths[0], lengths[1]);
m_sampleFifo->writeSync(vbegin, (std::min)(lengths[0], lengths[1]));
}
}
m_running = false;
}
int PlutoSDRMIThread::channelCallbackIQ(const qint16* buf, qint32 len, int channel)
{
SampleVector::iterator it = m_convertBuffer[channel].begin();
if (m_log2Decim == 0)
{
m_decimatorsIQ[channel].decimate1(&it, buf, len);
}
else
{
if (m_fcPos == 0) // Infra
{
switch (m_log2Decim)
{
case 1:
m_decimatorsIQ[channel].decimate2_inf(&it, buf, len);
break;
case 2:
m_decimatorsIQ[channel].decimate4_inf(&it, buf, len);
break;
case 3:
m_decimatorsIQ[channel].decimate8_inf(&it, buf, len);
break;
case 4:
m_decimatorsIQ[channel].decimate16_inf(&it, buf, len);
break;
case 5:
m_decimatorsIQ[channel].decimate32_inf(&it, buf, len);
break;
case 6:
m_decimatorsIQ[channel].decimate64_inf(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 1) // Supra
{
switch (m_log2Decim)
{
case 1:
m_decimatorsIQ[channel].decimate2_sup(&it, buf, len);
break;
case 2:
m_decimatorsIQ[channel].decimate4_sup(&it, buf, len);
break;
case 3:
m_decimatorsIQ[channel].decimate8_sup(&it, buf, len);
break;
case 4:
m_decimatorsIQ[channel].decimate16_sup(&it, buf, len);
break;
case 5:
m_decimatorsIQ[channel].decimate32_sup(&it, buf, len);
break;
case 6:
m_decimatorsIQ[channel].decimate64_sup(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 2) // Center
{
switch (m_log2Decim)
{
case 1:
m_decimatorsIQ[channel].decimate2_cen(&it, buf, len);
break;
case 2:
m_decimatorsIQ[channel].decimate4_cen(&it, buf, len);
break;
case 3:
m_decimatorsIQ[channel].decimate8_cen(&it, buf, len);
break;
case 4:
m_decimatorsIQ[channel].decimate16_cen(&it, buf, len);
break;
case 5:
m_decimatorsIQ[channel].decimate32_cen(&it, buf, len);
break;
case 6:
m_decimatorsIQ[channel].decimate64_cen(&it, buf, len);
break;
default:
break;
}
}
}
return it - m_convertBuffer[channel].begin();
}
int PlutoSDRMIThread::channelCallbackQI(const qint16* buf, qint32 len, int channel)
{
SampleVector::iterator it = m_convertBuffer[channel].begin();
if (m_log2Decim == 0)
{
m_decimatorsQI[channel].decimate1(&it, buf, len);
}
else
{
if (m_fcPos == 0) // Infra
{
switch (m_log2Decim)
{
case 1:
m_decimatorsQI[channel].decimate2_inf(&it, buf, len);
break;
case 2:
m_decimatorsQI[channel].decimate4_inf(&it, buf, len);
break;
case 3:
m_decimatorsQI[channel].decimate8_inf(&it, buf, len);
break;
case 4:
m_decimatorsQI[channel].decimate16_inf(&it, buf, len);
break;
case 5:
m_decimatorsQI[channel].decimate32_inf(&it, buf, len);
break;
case 6:
m_decimatorsQI[channel].decimate64_inf(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 1) // Supra
{
switch (m_log2Decim)
{
case 1:
m_decimatorsQI[channel].decimate2_sup(&it, buf, len);
break;
case 2:
m_decimatorsQI[channel].decimate4_sup(&it, buf, len);
break;
case 3:
m_decimatorsQI[channel].decimate8_sup(&it, buf, len);
break;
case 4:
m_decimatorsQI[channel].decimate16_sup(&it, buf, len);
break;
case 5:
m_decimatorsQI[channel].decimate32_sup(&it, buf, len);
break;
case 6:
m_decimatorsQI[channel].decimate64_sup(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 2) // Center
{
switch (m_log2Decim)
{
case 1:
m_decimatorsQI[channel].decimate2_cen(&it, buf, len);
break;
case 2:
m_decimatorsQI[channel].decimate4_cen(&it, buf, len);
break;
case 3:
m_decimatorsQI[channel].decimate8_cen(&it, buf, len);
break;
case 4:
m_decimatorsQI[channel].decimate16_cen(&it, buf, len);
break;
case 5:
m_decimatorsQI[channel].decimate32_cen(&it, buf, len);
break;
case 6:
m_decimatorsQI[channel].decimate64_cen(&it, buf, len);
break;
default:
break;
}
}
}
return it - m_convertBuffer[channel].begin();
}
@@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 _PLUTOSDR_PLUTOSDRMITHREAD_H_
#define _PLUTOSDR_PLUTOSDRMITHREAD_H_
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include "dsp/decimators.h"
class SampleMIFifo;
class DevicePlutoSDRBox;
class PlutoSDRMIThread : public QThread {
Q_OBJECT
public:
PlutoSDRMIThread(DevicePlutoSDRBox* plutoBox, QObject* parent = nullptr);
~PlutoSDRMIThread();
void startWork();
void stopWork();
bool isRunning() const { return m_running; }
void setLog2Decimation(unsigned int log2Decim);
unsigned int getLog2Decimation() const;
void setFcPos(int fcPos);
int getFcPos() const;
void setFifo(SampleMIFifo *sampleFifo) { m_sampleFifo = sampleFifo; }
SampleMIFifo *getFifo() { return m_sampleFifo; }
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
DevicePlutoSDRBox *m_plutoBox;
qint16 *m_buf[2]; //!< one buffer per I/Q channel
SampleVector m_convertBuffer[2];
SampleMIFifo *m_sampleFifo;
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12, true> m_decimatorsIQ[2];
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12, false> m_decimatorsQI[2];
unsigned int m_log2Decim;
int m_fcPos;
bool m_iqOrder;
static const int m_plutoSDRBlockSizeSamples = 64*256; //complex samples per buffer (must be multiple of 64)
void run();
int channelCallbackIQ(const qint16* buf, qint32 len, int channel);
int channelCallbackQI(const qint16* buf, qint32 len, int channel);
};
#endif // _PLUTOSDR_PLUTOSDRMITHREAD_H_
@@ -0,0 +1,253 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 "plutosdr/deviceplutosdrbox.h"
#include "dsp/samplemofifo.h"
#include "plutosdrmimosettings.h"
#include "plutosdrmothread.h"
PlutoSDRMOThread::PlutoSDRMOThread(DevicePlutoSDRBox* plutoBox, QObject* parent) :
QThread(parent),
m_running(false),
m_plutoBox(plutoBox),
m_log2Interp(0)
{
qDebug("PlutoSDRMOThread::PlutoSDRMOThread");
m_buf[0] = new qint16[2*PlutoSDRMIMOSettings::m_plutoSDRBlockSizeSamples];
m_buf[1] = new qint16[2*PlutoSDRMIMOSettings::m_plutoSDRBlockSizeSamples];
}
PlutoSDRMOThread::~PlutoSDRMOThread()
{
qDebug("PlutoSDRMOThread::~PlutoSDRMOThread");
if (m_running) {
stopWork();
}
delete[] m_buf[0];
delete[] m_buf[1];
}
void PlutoSDRMOThread::startWork()
{
m_startWaitMutex.lock();
start();
while(!m_running) {
m_startWaiter.wait(&m_startWaitMutex, 100);
}
m_startWaitMutex.unlock();
}
void PlutoSDRMOThread::stopWork()
{
m_running = false;
wait();
}
void PlutoSDRMOThread::setLog2Interpolation(unsigned int log2Interp)
{
qDebug("PlutoSDRMOThread::setLog2Interpolation: %u", log2Interp);
m_log2Interp = log2Interp;
}
unsigned int PlutoSDRMOThread::getLog2Interpolation() const
{
return m_log2Interp;
}
void PlutoSDRMOThread::setFcPos(int fcPos)
{
m_fcPos = fcPos;
}
int PlutoSDRMOThread::getFcPos() const
{
return m_fcPos;
}
void PlutoSDRMOThread::run()
{
std::ptrdiff_t p_inc = m_plutoBox->txBufferStep();
int sampleSize = m_plutoBox->getTxSampleSize(); // I/Q sample size in bytes
int nbChan = p_inc / sampleSize; // number of I/Q channels
qDebug("PlutoSDRMOThread::run: txBufferStep: %ld bytes", p_inc);
qDebug("PlutoSDRMOThread::run: Rx sample size is %ld bytes", m_plutoBox->getRxSampleSize());
qDebug("PlutoSDRMOThread::run: Tx sample size is %ld bytes", m_plutoBox->getTxSampleSize());
qDebug("PlutoSDRMOThread::run: nominal nbytes_tx is %ld bytes", PlutoSDRMIMOSettings::m_plutoSDRBlockSizeSamples*p_inc);
m_running = true;
m_startWaiter.wakeAll();
while (m_running)
{
ssize_t nbytes_tx;
char *p_dat, *p_end;
int ihs = 0; // half sample index (I then Q to make a sample)
// WRITE: Get pointers to TX buf and number of bytes to read from FIFO
p_dat = m_plutoBox->txBufferFirst();
p_end = m_plutoBox->txBufferEnd();
int nbOutSamples = (p_end - p_dat) / (4*nbChan);
callback(m_buf, nbOutSamples);
// p_inc is 2 on a char* buffer therefore each iteration processes only the I or Q sample
// I and Q samples are processed one after the other
// conversion is not needed as samples are little endian
for (p_dat = m_plutoBox->txBufferFirst(), ihs = 0; p_dat < p_end; p_dat += p_inc, ihs += 2)
{
m_plutoBox->txChannelConvert((int16_t*) p_dat, &m_buf[0][ihs]);
if (nbChan > 1) { // interleave with second chanel
m_plutoBox->txChannelConvert(1, (int16_t*) (p_dat+sampleSize), &m_buf[1][ihs]);
}
}
// Schedule TX buffer for sending
nbytes_tx = m_plutoBox->txBufferPush();
if (nbytes_tx != sampleSize*PlutoSDRMIMOSettings::m_plutoSDRBlockSizeSamples)
{
qDebug("PlutoSDRMOThread::run: error pushing buf %d / %d",
(int) nbytes_tx, (int) sampleSize*PlutoSDRMIMOSettings::m_plutoSDRBlockSizeSamples);
usleep(200000);
continue;
}
}
m_running = false;
}
void PlutoSDRMOThread::callback(qint16* buf[2], qint32 samplesPerChannel)
{
unsigned int iPart1Begin, iPart1End, iPart2Begin, iPart2End;
m_sampleFifo->readSync(samplesPerChannel/(1<<m_log2Interp), iPart1Begin, iPart1End, iPart2Begin, iPart2End);
if (iPart1Begin != iPart1End) {
callbackPart(buf, (iPart1End - iPart1Begin)*(1<<m_log2Interp), iPart1Begin);
}
if (iPart2Begin != iPart2End)
{
unsigned int shift = (iPart1End - iPart1Begin)*(1<<m_log2Interp);
qint16 *buf2[2];
buf2[0] = buf[0] + 2*shift;
buf2[1] = buf[1] + 2*shift;
callbackPart(buf2, (iPart2End - iPart2Begin)*(1<<m_log2Interp), 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 PlutoSDRMOThread::callbackPart(qint16* buf[2], qint32 nSamples, int iBegin)
{
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*nSamples);
}
else
{
if (m_fcPos == 0) // Infra
{
switch (m_log2Interp)
{
case 1:
m_interpolators[channel].interpolate2_inf(&begin, buf[channel], 2*nSamples);
break;
case 2:
m_interpolators[channel].interpolate4_inf(&begin, buf[channel], 2*nSamples);
break;
case 3:
m_interpolators[channel].interpolate8_inf(&begin, buf[channel], 2*nSamples);
break;
case 4:
m_interpolators[channel].interpolate16_inf(&begin, buf[channel], 2*nSamples);
break;
case 5:
m_interpolators[channel].interpolate32_inf(&begin, buf[channel], 2*nSamples);
break;
case 6:
m_interpolators[channel].interpolate64_inf(&begin, buf[channel], 2*nSamples);
break;
default:
break;
}
}
else if (m_fcPos == 1) // Supra
{
switch (m_log2Interp)
{
case 1:
m_interpolators[channel].interpolate2_sup(&begin, buf[channel], 2*nSamples);
break;
case 2:
m_interpolators[channel].interpolate4_sup(&begin, buf[channel], 2*nSamples);
break;
case 3:
m_interpolators[channel].interpolate8_sup(&begin, buf[channel], 2*nSamples);
break;
case 4:
m_interpolators[channel].interpolate16_sup(&begin, buf[channel], 2*nSamples);
break;
case 5:
m_interpolators[channel].interpolate32_sup(&begin, buf[channel], 2*nSamples);
break;
case 6:
m_interpolators[channel].interpolate64_sup(&begin, buf[channel], 2*nSamples);
break;
default:
break;
}
}
else if (m_fcPos == 2) // Center
{
switch (m_log2Interp)
{
case 1:
m_interpolators[channel].interpolate2_cen(&begin, buf[channel], 2*nSamples);
break;
case 2:
m_interpolators[channel].interpolate4_cen(&begin, buf[channel], 2*nSamples);
break;
case 3:
m_interpolators[channel].interpolate8_cen(&begin, buf[channel], 2*nSamples);
break;
case 4:
m_interpolators[channel].interpolate16_cen(&begin, buf[channel], 2*nSamples);
break;
case 5:
m_interpolators[channel].interpolate32_cen(&begin, buf[channel], 2*nSamples);
break;
case 6:
m_interpolators[channel].interpolate64_cen(&begin, buf[channel], 2*nSamples);
break;
default:
break;
}
}
}
}
}
@@ -0,0 +1,64 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2021 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 _PLUTOSDR_PLUTOSDRMOTHREAD_H_
#define _PLUTOSDR_PLUTOSDRMOTHREAD_H_
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include "dsp/interpolators.h"
class SampleMOFifo;
class DevicePlutoSDRBox;
class PlutoSDRMOThread : public QThread {
Q_OBJECT
public:
PlutoSDRMOThread(DevicePlutoSDRBox* plutoBox, QObject* parent = nullptr);
~PlutoSDRMOThread();
void startWork();
void stopWork();
bool isRunning() const { return m_running; }
void setLog2Interpolation(unsigned int log2Interp);
unsigned int getLog2Interpolation() const;
void setFcPos(int fcPos);
int getFcPos() const;
void setFifo(SampleMOFifo *sampleFifo) { m_sampleFifo = sampleFifo; }
SampleMOFifo *getFifo() { return m_sampleFifo; }
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
DevicePlutoSDRBox *m_plutoBox;
qint16 *m_buf[2]; //!< one buffer per I/Q channel
SampleMOFifo *m_sampleFifo;
Interpolators<qint16, SDR_TX_SAMP_SZ, 12> m_interpolators[2];
unsigned int m_log2Interp;
int m_fcPos;
void run();
unsigned int getNbFifos();
void callbackPart(qint16* buf[2], qint32 nSamples, int iBegin);
void callback(qint16* buf[2], qint32 samplesPerChannel);
};
#endif // _PLUTOSDR_PLUTOSDRMOTHREAD_H_