1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-04-25 08:53:59 -04:00

Failed attempt at LimeSDRMIMO

This commit is contained in:
f4exb 2020-04-09 06:46:04 +02:00
parent 65f892beab
commit 6e7ef35df0
16 changed files with 6232 additions and 0 deletions

View File

@ -0,0 +1,62 @@
project(limesdrmimo)
set(limesdrmimo_SOURCES
limesdrmimo.cpp
limesdrmimoplugin.cpp
limesdrmithread.cpp
limesdrmothread.cpp
limesdrmimosettings.cpp
limesdrmimowebapiadapter.cpp
)
set(limesdrmimo_HEADERS
limesdrmimo.h
limesdrmimoplugin.h
limesdrmithread.h
limesdrmothread.h
limesdrmimosettings.h
limesdrmimowebapiadapter.h
)
include_directories(
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${CMAKE_SOURCE_DIR}/devices
${LIMESUITE_INCLUDE_DIR}
)
if (NOT SERVER_MODE)
set (limesdrmimo_SOURCES
${limesdrmimo_SOURCES}
limesdrmimogui.cpp
limesdrmimogui.ui
)
set(limesdrmimo_HEADERS
${limesdrmimo_HEADERS}
limesdrmimogui.h
)
set(TARGET_NAME mimolimesdr)
set(TARGET_LIB "Qt5::Widgets")
set(TARGET_LIB_GUI "sdrgui")
set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR})
else()
set(TARGET_NAME mimolimesdrsrv)
set(TARGET_LIB "")
set(TARGET_LIB_GUI "")
set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR})
endif()
add_library(${TARGET_NAME} SHARED
${limesdrmimo_SOURCES}
)
target_link_libraries(${TARGET_NAME}
Qt5::Core
${TARGET_LIB}
sdrbase
${TARGET_LIB_GUI}
swagger
${LIMESUITE_LIBRARY}
limesdrdevice
)
install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,352 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMO_H_
#define PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMO_H_
#include <stdint.h>
#include <QString>
#include <QByteArray>
#include <QNetworkRequest>
#include "lime/LimeSuite.h"
#include "dsp/devicesamplemimo.h"
#include "limesdrmimosettings.h"
class QNetworkAccessManager;
class QNetworkReply;
class DeviceAPI;
class LimeSDRMIThread;
class LimeSDRMOThread;
class DeviceLimeSDRParams;
class LimeSDRMIMO : public DeviceSampleMIMO {
Q_OBJECT
public:
class MsgConfigureLimeSDRMIMO : public Message {
MESSAGE_CLASS_DECLARATION
public:
const LimeSDRMIMOSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
static MsgConfigureLimeSDRMIMO* create(const LimeSDRMIMOSettings& settings, bool force)
{
return new MsgConfigureLimeSDRMIMO(settings, force);
}
private:
LimeSDRMIMOSettings m_settings;
bool m_force;
MsgConfigureLimeSDRMIMO(const LimeSDRMIMOSettings& settings, bool force) :
Message(),
m_settings(settings),
m_force(force)
{ }
};
class MsgGetStreamInfo : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgGetStreamInfo* create()
{
return new MsgGetStreamInfo();
}
private:
MsgGetStreamInfo() :
Message()
{ }
};
class MsgGetDeviceInfo : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgGetDeviceInfo* create()
{
return new MsgGetDeviceInfo();
}
private:
MsgGetDeviceInfo() :
Message()
{ }
};
class MsgReportStreamInfo : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getSuccess() const { return m_success; }
bool getActive() const { return m_active; }
uint32_t getFifoFilledCount() const { return m_fifoFilledCount; }
uint32_t getFifoSize() const { return m_fifoSize; }
uint32_t getUnderrun() const { return m_underrun; }
uint32_t getOverrun() const { return m_overrun; }
uint32_t getDroppedPackets() const { return m_droppedPackets; }
float getLinkRate() const { return m_linkRate; }
uint64_t getTimestamp() const { return m_timestamp; }
static MsgReportStreamInfo* create(
bool success,
bool active,
uint32_t fifoFilledCount,
uint32_t fifoSize,
uint32_t underrun,
uint32_t overrun,
uint32_t droppedPackets,
float linkRate,
uint64_t timestamp
)
{
return new MsgReportStreamInfo(
success,
active,
fifoFilledCount,
fifoSize,
underrun,
overrun,
droppedPackets,
linkRate,
timestamp
);
}
private:
bool m_success;
// everything from lms_stream_status_t
bool m_active; //!< Indicates whether the stream is currently active
uint32_t m_fifoFilledCount; //!< Number of samples in FIFO buffer
uint32_t m_fifoSize; //!< Size of FIFO buffer
uint32_t m_underrun; //!< FIFO underrun count
uint32_t m_overrun; //!< FIFO overrun count
uint32_t m_droppedPackets; //!< Number of dropped packets by HW
float m_linkRate; //!< Combined data rate of all stream of the same direction (TX or RX)
uint64_t m_timestamp; //!< Current HW timestamp
MsgReportStreamInfo(
bool success,
bool active,
uint32_t fifoFilledCount,
uint32_t fifoSize,
uint32_t underrun,
uint32_t overrun,
uint32_t droppedPackets,
float linkRate,
uint64_t timestamp
) :
Message(),
m_success(success),
m_active(active),
m_fifoFilledCount(fifoFilledCount),
m_fifoSize(fifoSize),
m_underrun(underrun),
m_overrun(overrun),
m_droppedPackets(droppedPackets),
m_linkRate(linkRate),
m_timestamp(timestamp)
{ }
};
class MsgFileRecord : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getStartStop() const { return m_startStop; }
int getStreamIndex() const { return m_streamIndex; }
static MsgFileRecord* create(bool startStop, int streamIndex) {
return new MsgFileRecord(startStop, streamIndex);
}
protected:
bool m_startStop;
int m_streamIndex;
MsgFileRecord(bool startStop, int streamIndex) :
Message(),
m_startStop(startStop),
m_streamIndex(streamIndex)
{ }
};
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)
{ }
};
LimeSDRMIMO(DeviceAPI *deviceAPI);
virtual ~LimeSDRMIMO();
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);
// TODO
// 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 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 LimeSDRMIMOSettings& settings);
static void webapiUpdateDeviceSettings(
LimeSDRMIMOSettings& settings,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response);
bool isRecording(unsigned int istream) const { (void) istream; return false; }
void getRxFrequencyRange(uint64_t& min, uint64_t& max, int& step);
void getRxSampleRateRange(int& min, int& max, int& step);
void getRxLPFRange(int& min, int& max, int& step);
void getTxFrequencyRange(uint64_t& min, uint64_t& max, int& step);
void getTxSampleRateRange(int& min, int& max, int& step);
void getTxLPFRange(int& min, int& max, int& step);
bool getRxRunning() const { return m_runningRx; }
bool getTxRunning() const { return m_runningTx; }
private:
DeviceAPI *m_deviceAPI;
QMutex m_mutex;
LimeSDRMIMOSettings m_settings;
LimeSDRMIThread* m_sourceThread;
LimeSDRMOThread* m_sinkThread;
QString m_deviceDescription;
bool m_runningRx;
bool m_runningTx;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
DeviceLimeSDRParams *m_deviceParams;
bool m_rxChannelEnabled[2];
bool m_txChannelEnabled[2];
lms_stream_t m_rxStreams[2];
bool m_rxStreamStarted[2];
lms_stream_t m_txStreams[2];
bool m_txStreamStarted[2];
bool m_open;
bool openDevice();
void closeDevice();
bool setupRxStream(unsigned int channel);
void destroyRxStream(unsigned int channel);
bool setupTxStream(unsigned int channel);
void destroyTxStream(unsigned int channel);
bool applySettings(const LimeSDRMIMOSettings& settings, bool force);
void applyRxGainMode(
unsigned int channel,
bool& doCalibration,
LimeSDRMIMOSettings::RxGainMode gainMode,
uint32_t gain,
uint32_t lnaGain,
uint32_t tiaGain,
uint32_t pgaGain
);
void applyRxGain(unsigned int channel, bool& doCalibration, uint32_t gain);
void applyRxLNAGain(unsigned int channel, bool& doCalibration, uint32_t lnaGain);
void applyRxTIAGain(unsigned int channel, bool& doCalibration, uint32_t tiaGain);
void applyRxPGAGain(unsigned int channel, bool& doCalibration, uint32_t pgaGain);
void applyRxLPFIRBW(unsigned int channel, bool lpfFIREnable, float lpfFIRBW);
void applyRxNCOFrequency(unsigned int channel, bool ncoEnable, int ncoFrequency);
void applyRxAntennaPath(unsigned int channel, bool& doCalibration, LimeSDRMIMOSettings::PathRxRFE path);
void applyRxCalibration(unsigned int channel, qint32 devSampleRate);
void applyRxLPCalibration(unsigned int channel, float lpfBW);
void applyTxGain(unsigned int channel, bool& doCalibration, uint32_t gain);
void applyTxLPFIRBW(unsigned int channel, bool lpfFIREnable, float lpfFIRBW);
void applyTxNCOFrequency(unsigned int channel, bool ncoEnable, int ncoFrequency);
void applyTxAntennaPath(unsigned int channel, bool& doCalibration, LimeSDRMIMOSettings::PathTxRFE path);
bool setRxDeviceCenterFrequency(struct bladerf *dev, quint64 freq_hz, int loPpmTenths);
bool setTxDeviceCenterFrequency(struct bladerf *dev, quint64 freq_hz, int loPpmTenths);
void applyTxCalibration(unsigned int channel, qint32 devSampleRate);
void applyTxLPCalibration(unsigned int channel, float lpfBW);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const LimeSDRMIMOSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);
private slots:
void networkManagerFinished(QNetworkReply *reply);
};
#endif // PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMO_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,141 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMOGUI_H_
#define PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMOGUI_H_
#include <QTimer>
#include <QWidget>
#include "util/messagequeue.h"
#include "plugin/plugininstancegui.h"
#include "limesdrmimosettings.h"
class DeviceUISet;
class LimeSDRMIMO;
namespace Ui {
class LimeSDRMIMOGUI;
}
class LimeSDRMIMOGUI : public QWidget, public PluginInstanceGUI {
Q_OBJECT
public:
explicit LimeSDRMIMOGUI(DeviceUISet *deviceUISet, QWidget* parent = nullptr);
virtual ~LimeSDRMIMOGUI();
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::LimeSDRMIMOGUI* ui;
DeviceUISet* m_deviceUISet;
LimeSDRMIMOSettings 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;
LimeSDRMIMO* m_limeSDRMIMO;
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;
int m_statusCounter;
int m_deviceStatusCounter;
MessageQueue m_inputMessageQueue;
bool m_sampleRateMode;
int m_srMaxRx, m_srMinRx, m_srStepRx;
int m_srMaxTx, m_srMinTx, m_srStepTx;
int m_bwMaxRx, m_bwMinRx, m_bwStepRx;
int m_bwMaxTx, m_bwMinTx, m_bwStepTx;
uint64_t m_fMinRx, m_fMaxRx;
uint64_t m_fMinTx, m_fMaxTx;
int m_fStepRx, m_fStepTx;
void blockApplySettings(bool block) { m_doApplySettings = !block; }
void displaySettings();
void setRxCenterFrequencyDisplay();
void setRxCenterFrequencySetting(uint64_t kHzValue);
void displayRxSampleRate();
void updateADCRate();
void setTxCenterFrequencyDisplay();
void setTxCenterFrequencySetting(uint64_t kHzValue);
void displayTxSampleRate();
void updateDACRate();
void setNCODisplay();
void updateFrequencyLimits();
void updateLPFLimits();
void updateSampleRateAndFrequency();
void sendSettings();
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_record_toggled(bool checked);
void on_centerFrequency_changed(quint64 value);
void on_LOppm_valueChanged(int value);
void on_ncoEnable_toggled(bool checked);
void on_ncoFrequency_changed(qint64 value);
void on_dcOffset_toggled(bool checked);
void on_iqImbalance_toggled(bool checked);
void on_extClock_clicked();
void on_hwDecim_currentIndexChanged(int index);
void on_swDecim_currentIndexChanged(int index);
void on_sampleRateMode_toggled(bool checked);
void on_sampleRate_changed(quint64 value);
void on_lpf_changed(quint64 value);
void on_lpFIREnable_toggled(bool checked);
void on_lpFIR_changed(quint64 value);
void on_transverter_clicked();
void on_gainMode_currentIndexChanged(int index);
void on_gain_valueChanged(int value);
void on_lnaGain_valueChanged(int value);
void on_tiaGain_currentIndexChanged(int index);
void on_pgaGain_valueChanged(int value);
void on_antenna_currentIndexChanged(int index);
void openDeviceSettingsDialog(const QPoint& p);
void openFileRecordDialog(const QPoint& p);
};
#endif // PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMOGUI_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,142 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 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 "limesdr/devicelimesdr.h"
#ifndef SERVER_MODE
#include "limesdrmimogui.h"
#endif
#include "limesdrmimo.h"
#include "limesdrmimoplugin.h"
#include "limesdrmimowebapiadapter.h"
const PluginDescriptor LimeSDRMIMOPlugin::m_pluginDescriptor = {
QString("LimeSDR"),
QString("LimeSDR MIMO"),
QString("5.4.0"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,
QString("https://github.com/f4exb/sdrangel")
};
const QString LimeSDRMIMOPlugin::m_hardwareID = "LimeSDR";
const QString LimeSDRMIMOPlugin::m_deviceTypeID = LIMESDRMIMO_DEVICE_TYPE_ID;
LimeSDRMIMOPlugin::LimeSDRMIMOPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& LimeSDRMIMOPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void LimeSDRMIMOPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleMIMO(m_deviceTypeID, this);
}
void LimeSDRMIMOPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices)
{
if (listedHwIds.contains(m_hardwareID)) { // check if it was done
return;
}
DeviceLimeSDR::enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
PluginInterface::SamplingDevices LimeSDRMIMOPlugin::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
PluginInstanceGUI* LimeSDRMIMOPlugin::createSampleMIMOPluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
(void) sourceId;
(void) widget;
(void) deviceUISet;
return nullptr;
}
#else
PluginInstanceGUI* LimeSDRMIMOPlugin::createSampleMIMOPluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
if (sourceId == m_deviceTypeID)
{
LimeSDRMIMOGUI* gui = new LimeSDRMIMOGUI(deviceUISet);
*widget = gui;
return gui;
}
else
{
return nullptr;
}
}
#endif
DeviceSampleMIMO *LimeSDRMIMOPlugin::createSampleMIMOPluginInstance(const QString& mimoId, DeviceAPI *deviceAPI)
{
if (mimoId == m_deviceTypeID)
{
LimeSDRMIMO* input = new LimeSDRMIMO(deviceAPI);
return input;
}
else
{
return nullptr;
}
}
DeviceWebAPIAdapter *LimeSDRMIMOPlugin::createDeviceWebAPIAdapter() const
{
return new LimeSDRMIMOWebAPIAdapter();
}

View File

@ -0,0 +1,56 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 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 _LIMESDRMIMO_LIMESDRMIMOPLUGIN_H
#define _LIMESDRMIMO_LIMESDRMIMOPLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
class PluginAPI;
#define LIMESDRMIMO_DEVICE_TYPE_ID "sdrangel.samplemimo.limesdrmimo"
class LimeSDRMIMOPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID LIMESDRMIMO_DEVICE_TYPE_ID)
public:
explicit LimeSDRMIMOPlugin(QObject* parent = nullptr);
const PluginDescriptor& getPluginDescriptor() const;
void initPlugin(PluginAPI* pluginAPI);
virtual void enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices);
virtual SamplingDevices enumSampleMIMO(const OriginDevices& originDevices);
virtual PluginInstanceGUI* createSampleMIMOPluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet);
virtual DeviceSampleMIMO* createSampleMIMOPluginInstance(const QString& sourceId, DeviceAPI *deviceAPI);
virtual DeviceWebAPIAdapter* createDeviceWebAPIAdapter() const;
static const QString m_hardwareID;
static const QString m_deviceTypeID;
private:
static const PluginDescriptor m_pluginDescriptor;
};
#endif // _LIMESDRMIMO_LIMESDRMIMOPLUGIN_H

View File

@ -0,0 +1,273 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 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 "limesdrmimosettings.h"
#include "util/simpleserializer.h"
LimeSDRMIMOSettings::LimeSDRMIMOSettings()
{
resetToDefaults();
}
void LimeSDRMIMOSettings::resetToDefaults()
{
m_devSampleRate = 5000000;
m_LOppmTenths = 0;
m_gpioDir = 0;
m_gpioPins = 0;
m_extClock = false;
m_extClockFreq = 10000000; // 10 MHz
m_fileRecordName = "";
m_useReverseAPI = false;
m_reverseAPIAddress = "127.0.0.1";
m_reverseAPIPort = 8888;
m_reverseAPIDeviceIndex = 0;
m_rxCenterFrequency = 435000*1000;
m_log2HardDecim = 3;
m_log2SoftDecim = 0;
m_dcBlock = false;
m_iqCorrection = false;
m_rxTransverterMode = false;
m_rxTransverterDeltaFrequency = 0;
m_lpfBWRx0 = 4.5e6f;
m_lpfFIREnableRx0 = false;
m_lpfFIRBWRx0 = 2.5e6f;
m_gainRx0 = 50;
m_ncoEnableRx0 = false;
m_ncoFrequencyRx0 = 0;
m_antennaPathRx0 = PATH_RFE_RX_NONE;
m_gainModeRx0 = GAIN_AUTO;
m_lnaGainRx0 = 15;
m_tiaGainRx0 = 2;
m_pgaGainRx0 = 16;
m_lpfBWRx1 = 4.5e6f;
m_lpfFIREnableRx1 = false;
m_lpfFIRBWRx1 = 2.5e6f;
m_gainRx1 = 50;
m_ncoEnableRx1 = false;
m_ncoFrequencyRx1 = 0;
m_antennaPathRx1 = PATH_RFE_RX_NONE;
m_gainModeRx1 = GAIN_AUTO;
m_lnaGainRx1 = 15;
m_tiaGainRx1 = 2;
m_pgaGainRx1 = 16;
m_txCenterFrequency = 435000*1000;
m_log2HardInterp = 3;
m_log2SoftInterp = 0;
m_txTransverterMode = false;
m_txTransverterDeltaFrequency = 0;
m_lpfBWTx0 = 5.5e6f;
m_lpfFIREnableTx0 = false;
m_lpfFIRBWTx0 = 2.5e6f;
m_gainTx0 = 4;
m_ncoEnableTx0 = false;
m_ncoFrequencyTx0 = 0;
m_antennaPathTx0 = PATH_RFE_TX_NONE;
m_lpfBWTx1 = 5.5e6f;
m_lpfFIREnableTx1 = false;
m_lpfFIRBWTx1 = 2.5e6f;
m_gainTx1 = 4;
m_ncoEnableTx1 = false;
m_ncoFrequencyTx1 = 0;
m_antennaPathTx1 = PATH_RFE_TX_NONE;
}
QByteArray LimeSDRMIMOSettings::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_devSampleRate);
s.writeS32(2, m_LOppmTenths);
s.writeU32(3, m_gpioDir);
s.writeU32(4, m_gpioPins);
s.writeBool(5, m_extClock);
s.writeU32(6, m_extClockFreq);
s.writeString(7, m_fileRecordName);
s.writeBool(8, m_useReverseAPI);
s.writeString(9, m_reverseAPIAddress);
s.writeU32(10, m_reverseAPIPort);
s.writeU32(11, m_reverseAPIDeviceIndex);
s.writeU64(20, m_rxCenterFrequency);
s.writeU32(21, m_log2HardDecim);
s.writeU32(22, m_log2SoftDecim);
s.writeBool(23, m_dcBlock);
s.writeBool(24, m_iqCorrection);
s.writeBool(25, m_rxTransverterMode);
s.writeS64(26, m_rxTransverterDeltaFrequency);
s.writeFloat(30, m_lpfBWRx0);
s.writeBool(31, m_lpfFIREnableRx0);
s.writeFloat(32, m_lpfFIRBWRx0);
s.writeU32(33, m_gainRx0);
s.writeBool(34, m_ncoEnableRx0);
s.writeS32(35, m_ncoFrequencyRx0);
s.writeS32(36, (int) m_antennaPathRx0);
s.writeS32(37, (int) m_gainModeRx0);
s.writeU32(38, m_lnaGainRx0);
s.writeU32(39, m_tiaGainRx0);
s.writeU32(40, m_pgaGainRx0);
s.writeFloat(50, m_lpfBWRx1);
s.writeBool(51, m_lpfFIREnableRx1);
s.writeFloat(52, m_lpfFIRBWRx1);
s.writeU32(53, m_gainRx1);
s.writeBool(54, m_ncoEnableRx1);
s.writeS32(55, m_ncoFrequencyRx1);
s.writeS32(56, (int) m_antennaPathRx1);
s.writeS32(57, (int) m_gainModeRx1);
s.writeU32(58, m_lnaGainRx1);
s.writeU32(59, m_tiaGainRx1);
s.writeU32(60, m_pgaGainRx1);
s.writeU64(70, m_txCenterFrequency);
s.writeU32(71, m_log2HardInterp);
s.writeU32(72, m_log2SoftInterp);
s.writeBool(73, m_txTransverterMode);
s.writeS64(74, m_txTransverterDeltaFrequency);
s.writeFloat(80, m_lpfBWTx0);
s.writeBool(81, m_lpfFIREnableTx0);
s.writeFloat(82, m_lpfFIRBWTx0);
s.writeU32(83, m_gainTx0);
s.writeBool(84, m_ncoEnableTx0);
s.writeS32(85, m_ncoFrequencyTx0);
s.writeS32(86, (int) m_antennaPathTx0);
s.writeFloat(90, m_lpfBWTx1);
s.writeBool(91, m_lpfFIREnableTx1);
s.writeFloat(92, m_lpfFIRBWTx1);
s.writeU32(93, m_gainTx1);
s.writeBool(94, m_ncoEnableTx1);
s.writeS32(95, m_ncoFrequencyTx1);
s.writeS32(96, (int) m_antennaPathTx1);
return s.final();
}
bool LimeSDRMIMOSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
int intval;
uint32_t uintval;
d.readS32(1, &m_devSampleRate, 5000000);
d.readS32(2, &m_LOppmTenths, 0);
d.readU32(3, &uintval, 0);
m_gpioDir = uintval & 0xFF;
d.readU32(4, &uintval, 0);
m_gpioPins = uintval & 0xFF;
d.readBool(5, &m_extClock, false);
d.readU32(6, &m_extClockFreq, 10000000);
d.readString(7, &m_fileRecordName, "");
d.readBool(8, &m_useReverseAPI, false);
d.readString(9, &m_reverseAPIAddress, "127.0.0.1");
d.readU32(10, &uintval, 0);
if ((uintval > 1023) && (uintval < 65535)) {
m_reverseAPIPort = uintval;
} else {
m_reverseAPIPort = 8888;
}
d.readU32(11, &uintval, 0);
m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
d.readU64(20, &m_rxCenterFrequency, 435000*1000);
d.readU32(21, &m_log2HardDecim, 2);
d.readU32(22, &m_log2SoftDecim, 0);
d.readBool(23, &m_dcBlock, false);
d.readBool(24, &m_iqCorrection, false);
d.readBool(25, &m_rxTransverterMode, false);
d.readS64(26, &m_rxTransverterDeltaFrequency, 0);
d.readFloat(30, &m_lpfBWRx0, 1.5e6);
d.readBool(31, &m_lpfFIREnableRx0, false);
d.readFloat(32, &m_lpfFIRBWRx0, 1.5e6);
d.readU32(33, &m_gainRx0, 50);
d.readBool(34, &m_ncoEnableRx0, false);
d.readS32(35, &m_ncoFrequencyRx0, 0);
d.readS32(36, &intval, 0);
m_antennaPathRx0 = (PathRxRFE) intval;
d.readS32(37, &intval, 0);
m_gainModeRx0 = (RxGainMode) intval;
d.readU32(38, &m_lnaGainRx0, 15);
d.readU32(39, &m_tiaGainRx0, 2);
d.readU32(40, &m_pgaGainRx0, 16);
d.readFloat(50, &m_lpfBWRx1, 1.5e6);
d.readBool(51, &m_lpfFIREnableRx1, false);
d.readFloat(52, &m_lpfFIRBWRx1, 1.5e6);
d.readU32(53, &m_gainRx1, 50);
d.readBool(54, &m_ncoEnableRx1, false);
d.readS32(55, &m_ncoFrequencyRx1, 0);
d.readS32(56, &intval, 0);
m_antennaPathRx1 = (PathRxRFE) intval;
d.readS32(57, &intval, 0);
m_gainModeRx1 = (RxGainMode) intval;
d.readU32(58, &m_lnaGainRx1, 15);
d.readU32(59, &m_tiaGainRx1, 2);
d.readU32(60, &m_pgaGainRx1, 16);
d.readU64(70, &m_txCenterFrequency, 435000*1000);
d.readU32(71, &m_log2HardInterp, 2);
d.readU32(72, &m_log2SoftInterp, 0);
d.readBool(73, &m_txTransverterMode, false);
d.readS64(74, &m_txTransverterDeltaFrequency, 0);
d.readFloat(80, &m_lpfBWTx0, 1.5e6);
d.readBool(81, &m_lpfFIREnableTx0, false);
d.readFloat(82, &m_lpfFIRBWTx0, 1.5e6);
d.readU32(83, &m_gainTx0, 4);
d.readBool(84, &m_ncoEnableTx0, false);
d.readS32(85, &m_ncoFrequencyTx0, 0);
d.readS32(86, &intval, 0);
m_antennaPathTx0 = (PathTxRFE) intval;
d.readFloat(90, &m_lpfBWTx1, 1.5e6);
d.readBool(91, &m_lpfFIREnableTx1, false);
d.readFloat(92, &m_lpfFIRBWTx1, 1.5e6);
d.readU32(93, &m_gainTx1, 4);
d.readBool(94, &m_ncoEnableTx1, false);
d.readS32(95, &m_ncoFrequencyTx1, 0);
d.readS32(96, &intval, 0);
m_antennaPathTx1 = (PathTxRFE) intval;
return true;
}
else
{
resetToDefaults();
return false;
}
}

View File

@ -0,0 +1,133 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMOSETTINGS_H_
#define PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMOSETTINGS_H_
#include <QtGlobal>
#include <QString>
struct LimeSDRMIMOSettings
{
typedef enum {
FC_POS_INFRA = 0,
FC_POS_SUPRA,
FC_POS_CENTER
} fcPos_t;
enum PathRxRFE
{
PATH_RFE_RX_NONE = 0,
PATH_RFE_LNAH,
PATH_RFE_LNAL,
PATH_RFE_LNAW,
PATH_RFE_LB1,
PATH_RFE_LB2
};
typedef enum {
GAIN_AUTO,
GAIN_MANUAL
} RxGainMode;
enum PathTxRFE
{
PATH_RFE_TX_NONE = 0,
PATH_RFE_TXRF1,
PATH_RFE_TXRF2,
};
// General
qint32 m_devSampleRate;
qint32 m_LOppmTenths;
uint8_t m_gpioDir; //!< GPIO pin direction LSB first; 0 input, 1 output
uint8_t m_gpioPins; //!< GPIO pins to write; LSB first
bool m_extClock; //!< True if external clock source
uint32_t m_extClockFreq; //!< Frequency (Hz) of external clock source
QString m_fileRecordName;
bool m_useReverseAPI;
QString m_reverseAPIAddress;
uint16_t m_reverseAPIPort;
uint16_t m_reverseAPIDeviceIndex;
// Rx general
quint64 m_rxCenterFrequency;
uint32_t m_log2HardDecim;
uint32_t m_log2SoftDecim;
bool m_dcBlock;
bool m_iqCorrection;
bool m_rxTransverterMode;
qint64 m_rxTransverterDeltaFrequency;
// Rx channel 0
float m_lpfBWRx0; //!< Rx[0] LMS analog lowpass filter bandwidth (Hz)
bool m_lpfFIREnableRx0; //!< Rx[0] Enable LMS digital lowpass FIR filters
float m_lpfFIRBWRx0; //!< Rx[0] LMS digital lowpass FIR filters bandwidth (Hz)
uint32_t m_gainRx0; //!< Rx[0] Optimally distributed gain (dB)
bool m_ncoEnableRx0; //!< Rx[0] Enable TSP NCO and mixing
int m_ncoFrequencyRx0; //!< Rx[0] Actual NCO frequency (the resulting frequency with mixing is displayed)
PathRxRFE m_antennaPathRx0; //!< Rx[0] Antenna connection
RxGainMode m_gainModeRx0; //!< Rx[0] Gain mode: auto or manual
uint32_t m_lnaGainRx0; //!< Rx[0] Manual LAN gain
uint32_t m_tiaGainRx0; //!< Rx[0] Manual TIA gain
uint32_t m_pgaGainRx0; //!< Rx[0] Manual PGA gain
// Rx channel 1
float m_lpfBWRx1; //!< Rx[1] LMS analog lowpass filter bandwidth (Hz)
bool m_lpfFIREnableRx1; //!< Rx[1] Enable LMS digital lowpass FIR filters
float m_lpfFIRBWRx1; //!< Rx[1] LMS digital lowpass FIR filters bandwidth (Hz)
uint32_t m_gainRx1; //!< Rx[1] Optimally distributed gain (dB)
bool m_ncoEnableRx1; //!< Rx[1] Enable TSP NCO and mixing
int m_ncoFrequencyRx1; //!< Rx[1] Actual NCO frequency (the resulting frequency with mixing is displayed)
PathRxRFE m_antennaPathRx1; //!< Rx[1] Antenna connection
RxGainMode m_gainModeRx1; //!< Rx[1] Gain mode: auto or manual
uint32_t m_lnaGainRx1; //!< Rx[1] Manual LAN gain
uint32_t m_tiaGainRx1; //!< Rx[1] Manual TIA gain
uint32_t m_pgaGainRx1; //!< Rx[1] Manual PGA gain
// Tx general
quint64 m_txCenterFrequency;
uint32_t m_log2HardInterp;
uint32_t m_log2SoftInterp;
bool m_txTransverterMode;
qint64 m_txTransverterDeltaFrequency;
// Tx channel 0
float m_lpfBWTx0; //!< Tx[0] LMS amalog lowpass filter bandwidth (Hz)
bool m_lpfFIREnableTx0; //!< Tx[0] Enable LMS digital lowpass FIR filters
float m_lpfFIRBWTx0; //!< Tx[0] LMS digital lowpass FIR filters bandwidth (Hz)
uint32_t m_gainTx0; //!< Tx[0] Optimally distributed gain (dB)
bool m_ncoEnableTx0; //!< Tx[0] Enable TSP NCO and mixing
int m_ncoFrequencyTx0; //!< Tx[0] Actual NCO frequency (the resulting frequency with mixing is displayed)
PathTxRFE m_antennaPathTx0; //!< Tx[0] Antenna connection
// Tx channel 1
float m_lpfBWTx1; //!< Tx[1] LMS amalog lowpass filter bandwidth (Hz)
bool m_lpfFIREnableTx1; //!< Tx[1] Enable LMS digital lowpass FIR filters
float m_lpfFIRBWTx1; //!< Tx[1] LMS digital lowpass FIR filters bandwidth (Hz)
uint32_t m_gainTx1; //!< Tx[1] Optimally distributed gain (dB)
bool m_ncoEnableTx1; //!< Tx[1] Enable TSP NCO and mixing
int m_ncoFrequencyTx1; //!< Tx[1] Actual NCO frequency (the resulting frequency with mixing is displayed)
PathTxRFE m_antennaPathTx1; //!< Tx[1] Antenna connection
LimeSDRMIMOSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif // PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMIMOSETTINGS_H_

View File

@ -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 "limesdrmimowebapiadapter.h"
LimeSDRMIMOWebAPIAdapter::LimeSDRMIMOWebAPIAdapter()
{}
LimeSDRMIMOWebAPIAdapter::~LimeSDRMIMOWebAPIAdapter()
{}
int LimeSDRMIMOWebAPIAdapter::webapiSettingsGet(
SWGSDRangel::SWGDeviceSettings& response,
QString& errorMessage)
{
(void) errorMessage;
(void) response;
return 501;
}
int LimeSDRMIMOWebAPIAdapter::webapiSettingsPutPatch(
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage)
{
(void) errorMessage;
(void) force;
(void) deviceSettingsKeys;
(void) response;
return 501;
}

View File

@ -0,0 +1,44 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "device/devicewebapiadapter.h"
#include "limesdrmimosettings.h"
class LimeSDRMIMOWebAPIAdapter : public DeviceWebAPIAdapter
{
public:
LimeSDRMIMOWebAPIAdapter();
virtual ~LimeSDRMIMOWebAPIAdapter();
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:
LimeSDRMIMOSettings m_settings;
};

View File

@ -0,0 +1,238 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 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 "dsp/samplemififo.h"
#include "limesdrmithread.h"
LimeSDRMIThread::LimeSDRMIThread(lms_stream_t* stream0, lms_stream_t* stream1, QObject* parent) :
QThread(parent),
m_running(false),
m_stream0(stream0),
m_stream1(stream1),
m_sampleFifo(nullptr)
{
qDebug("LimeSDRMIThread::LimeSDRMIThread");
for (unsigned int i = 0; i < 2; i++) {
m_convertBuffer[i].resize(DeviceLimeSDR::blockSize, Sample{0,0});
}
}
LimeSDRMIThread::~LimeSDRMIThread()
{
qDebug("LimeSDRMIThread::~LimeSDRMIThread");
if (m_running) {
stopWork();
}
}
void LimeSDRMIThread::startWork()
{
if (m_running) {
return; // return if running already
}
if (m_stream0)
{
if (LMS_StartStream(m_stream0) < 0)
{
qCritical("LimeSDRMIThread::startWork: could not start stream 0");
}
else
{
usleep(50000);
qDebug("LimeSDRMIThread::startWork: stream 0 started");
}
}
if (m_stream1)
{
if (LMS_StartStream(m_stream1) < 0)
{
qCritical("LimeSDRMIThread::startWork: could not start stream 1");
}
else
{
usleep(50000);
qDebug("LimeSDRMIThread::startWork: stream 1 started");
}
}
m_startWaitMutex.lock();
start();
while(!m_running) {
m_startWaiter.wait(&m_startWaitMutex, 100);
}
m_startWaitMutex.unlock();
}
void LimeSDRMIThread::stopWork()
{
if (!m_running) {
return; // return if not running
}
m_running = false;
wait();
if (m_stream0)
{
if (LMS_StopStream(m_stream0) < 0)
{
qCritical("LimeSDRInputThread::stopWork: could not stop stream 0");
}
else
{
usleep(50000);
qDebug("LimeSDRInputThread::stopWork: stream 0 stopped");
}
}
if (m_stream1)
{
if (LMS_StopStream(m_stream1) < 0)
{
qCritical("LimeSDRInputThread::stopWork: could not stop stream 1");
}
else
{
usleep(50000);
qDebug("LimeSDRInputThread::stopWork: stream 1 stopped");
}
}
}
void LimeSDRMIThread::setLog2Decimation(unsigned int log2_decim)
{
m_log2Decim = log2_decim;
}
unsigned int LimeSDRMIThread::getLog2Decimation() const
{
return m_log2Decim;
}
void LimeSDRMIThread::run()
{
int res;
lms_stream_meta_t metadata; //Use metadata for additional control over sample receive function behaviour
metadata.flushPartialPacket = false; //Do not discard data remainder when read size differs from packet size
metadata.waitForTimestamp = false; //Do not wait for specific timestamps
std::vector<SampleVector::const_iterator> vbegin;
int lengths[2];
m_running = true;
m_startWaiter.wakeAll();
while (m_running)
{
if (m_stream0)
{
res = LMS_RecvStream(m_stream0, (void *) m_buf[0], DeviceLimeSDR::blockSize, &metadata, 1000);
if (res < 0)
{
qCritical("LimeSDRMIThread::run read stream 0 error: %s", strerror(errno));
break;
}
lengths[0] = channelCallback(m_buf[0], 2*res, 0);
}
else
{
std::fill(m_convertBuffer[0].begin(), m_convertBuffer[0].end(), Sample{0,0});
lengths[0] = m_convertBuffer[0].size();
}
vbegin.push_back(m_convertBuffer[0].begin());
if (m_stream1)
{
res = LMS_RecvStream(m_stream1, (void *) m_buf[1], DeviceLimeSDR::blockSize, &metadata, 1000);
if (res < 0)
{
qCritical("LimeSDRMIThread::run read stream 1 error: %s", strerror(errno));
break;
}
lengths[1] = channelCallback(m_buf[1], 2*res, 1);
}
else
{
std::fill(m_convertBuffer[1].begin(), m_convertBuffer[1].end(), Sample{0,0});
lengths[1] = m_convertBuffer[1].size();
}
vbegin.push_back(m_convertBuffer[1].begin());
if (lengths[0] == lengths[1])
{
m_sampleFifo->writeSync(vbegin, lengths[0]);
}
else
{
qWarning("LimeSDRMIThread::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 LimeSDRMIThread::channelCallback(const qint16* buf, qint32 len, int channel)
{
SampleVector::iterator it = m_convertBuffer[channel].begin();
if (m_log2Decim == 0)
{
m_decimators[channel].decimate1(&it, buf, len);
}
else
{
switch (m_log2Decim)
{
case 1:
m_decimators[channel].decimate2_cen(&it, buf, len);
break;
case 2:
m_decimators[channel].decimate4_cen(&it, buf, len);
break;
case 3:
m_decimators[channel].decimate8_cen(&it, buf, len);
break;
case 4:
m_decimators[channel].decimate16_cen(&it, buf, len);
break;
case 5:
m_decimators[channel].decimate32_cen(&it, buf, len);
break;
case 6:
m_decimators[channel].decimate64_cen(&it, buf, len);
break;
default:
break;
}
}
return it - m_convertBuffer[channel].begin();
}

View File

@ -0,0 +1,67 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMITHREAD_H_
#define PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMITHREAD_H_
// LimeSDR is a SISO/MIMO device. It can support one or two Rx. Here ww will
// configure two Rx
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include "lime/LimeSuite.h"
#include "limesdr/devicelimesdr.h"
#include "dsp/decimators.h"
class SampleMIFifo;
class LimeSDRMIThread : public QThread {
Q_OBJECT
public:
LimeSDRMIThread(lms_stream_t* stream0, lms_stream_t* stream1, QObject* parent = nullptr);
~LimeSDRMIThread();
void startWork();
void stopWork();
bool isRunning() const { return m_running; }
void setLog2Decimation(unsigned int log2_decim);
unsigned int getLog2Decimation() const;
void setFifo(SampleMIFifo *sampleFifo) { m_sampleFifo = sampleFifo; }
SampleMIFifo *getFifo() { return m_sampleFifo; }
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
lms_stream_t* m_stream0;
lms_stream_t* m_stream1;
qint16 m_buf[2][2*DeviceLimeSDR::blockSize];
SampleVector m_convertBuffer[2];
SampleMIFifo* m_sampleFifo;
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12> m_decimators[2];
unsigned int m_log2Decim;
void run();
int channelCallback(const qint16* buf, qint32 len, int channel);
};
#endif // PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMITHREAD_H_

View File

@ -0,0 +1,239 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 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 "dsp/samplemofifo.h"
#include "limesdrmothread.h"
LimeSDRMOThread::LimeSDRMOThread(lms_stream_t* stream0, lms_stream_t* stream1, QObject* parent) :
QThread(parent),
m_running(false),
m_stream0(stream0),
m_stream1(stream1),
m_sampleFifo(nullptr)
{
qDebug("LimeSDRMOThread::LimeSDRMOThread");
m_buf = new qint16[2*DeviceLimeSDR::blockSize*2];
std::fill(m_buf, m_buf + 2*DeviceLimeSDR::blockSize*2, 0);
}
LimeSDRMOThread::~LimeSDRMOThread()
{
qDebug("LimeSDRMOThread::~LimeSDRMOThread");
if (m_running) {
stopWork();
}
delete[] m_buf;
}
void LimeSDRMOThread::startWork()
{
if (m_running) {
return; // return if running already
}
if (m_stream0)
{
if (LMS_StartStream(m_stream0) < 0)
{
qCritical("LimeSDROutputThread::startWork: could not start stream 0");
}
else
{
usleep(50000);
qDebug("LimeSDROutputThread::startWork: stream 0 started");
}
}
if (m_stream1)
{
if (LMS_StartStream(m_stream1) < 0)
{
qCritical("LimeSDROutputThread::startWork: could not start stream 1");
}
else
{
usleep(50000);
qDebug("LimeSDROutputThread::startWork: stream 1 started");
}
}
m_startWaitMutex.lock();
start();
while(!m_running) {
m_startWaiter.wait(&m_startWaitMutex, 100);
}
m_startWaitMutex.unlock();
}
void LimeSDRMOThread::stopWork()
{
if (!m_running) {
return; // return if not running
}
m_running = false;
wait();
if (m_stream0)
{
if (LMS_StopStream(m_stream0) < 0)
{
qCritical("LimeSDROutputThread::stopWork: could not stop stream 0");
}
else
{
usleep(50000);
qDebug("LimeSDROutputThread::stopWork: stream 0 stopped");
}
}
if (m_stream1)
{
if (LMS_StopStream(m_stream1) < 0)
{
qCritical("LimeSDROutputThread::stopWork: could not stop stream 1");
}
else
{
usleep(50000);
qDebug("LimeSDROutputThread::stopWork: stream 1 stopped");
}
}
}
void LimeSDRMOThread::setLog2Interpolation(unsigned int log2Interp)
{
qDebug("LimeSDRMOThread::setLog2Interpolation: %u", log2Interp);
m_log2Interp = log2Interp;
}
unsigned int LimeSDRMOThread::getLog2Interpolation() const
{
return m_log2Interp;
}
void LimeSDRMOThread::run()
{
int res;
lms_stream_meta_t metadata; //Use metadata for additional control over sample receive function behaviour
metadata.flushPartialPacket = false; //Do not discard data remainder when read size differs from packet size
metadata.waitForTimestamp = false; //Do not wait for specific timestamps
m_running = true;
m_startWaiter.wakeAll();
while (m_running)
{
callback(m_buf, DeviceLimeSDR::blockSize);
if (m_stream0)
{
res = LMS_SendStream(m_stream0, (void *) &m_buf[0], DeviceLimeSDR::blockSize, &metadata, 1000000);
if (res < 0)
{
qCritical("LimeSDROutputThread::run stream 0 write error: %s", strerror(errno));
break;
}
else if (res != DeviceLimeSDR::blockSize)
{
qDebug("LimeSDROutputThread::run stream 0 written %d/%d samples", res, DeviceLimeSDR::blockSize);
}
}
if (m_stream1)
{
res = LMS_SendStream(m_stream1, (void *) &m_buf[2*DeviceLimeSDR::blockSize], DeviceLimeSDR::blockSize, &metadata, 1000000);
if (res < 0)
{
qCritical("LimeSDROutputThread::run stream 1 write error: %s", strerror(errno));
break;
}
else if (res != DeviceLimeSDR::blockSize)
{
qDebug("LimeSDROutputThread::run stream 1 written %d/%d samples", res, DeviceLimeSDR::blockSize);
}
}
}
m_running = false;
}
void LimeSDRMOThread::callback(qint16* buf, qint32 samplesPerChannel)
{
unsigned int iPart1Begin, iPart1End, iPart2Begin, iPart2End;
m_sampleFifo->readSync(samplesPerChannel/(1<<m_log2Interp), iPart1Begin, iPart1End, iPart2Begin, iPart2End);
if (iPart1Begin != iPart1End)
{
callbackPart(buf, (iPart1End - iPart1Begin)*(1<<m_log2Interp), iPart1Begin);
}
if (iPart2Begin != iPart2End)
{
unsigned int shift = (iPart1End - iPart1Begin)*(1<<m_log2Interp);
callbackPart(buf + 2*shift, (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 LimeSDRMOThread::callbackPart(qint16* buf, 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], 2*nSamples);
}
else
{
switch (m_log2Interp)
{
case 1:
m_interpolators[channel].interpolate2_cen(&begin, &buf[channel*2*nSamples], 2*nSamples);
break;
case 2:
m_interpolators[channel].interpolate4_cen(&begin, &buf[channel*2*nSamples], 2*nSamples);
break;
case 3:
m_interpolators[channel].interpolate8_cen(&begin, &buf[channel*2*nSamples], 2*nSamples);
break;
case 4:
m_interpolators[channel].interpolate16_cen(&begin, &buf[channel*2*nSamples], 2*nSamples);
break;
case 5:
m_interpolators[channel].interpolate32_cen(&begin, &buf[channel*2*nSamples], 2*nSamples);
break;
case 6:
m_interpolators[channel].interpolate64_cen(&begin, &buf[channel*2*nSamples], 2*nSamples);
break;
default:
break;
}
}
}
}

View File

@ -0,0 +1,67 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMOTHREAD_H_
#define PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMOTHREAD_H_
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include "lime/LimeSuite.h"
#include "limesdr/devicelimesdr.h"
#include "dsp/interpolators.h"
class SampleMOFifo;
class LimeSDRMOThread : public QThread {
Q_OBJECT
public:
LimeSDRMOThread(lms_stream_t* stream0, lms_stream_t* stream1, QObject* parent = nullptr);
~LimeSDRMOThread();
void startWork();
void stopWork();
bool isRunning() const { return m_running; }
void setLog2Interpolation(unsigned int log2Interp);
unsigned int getLog2Interpolation() const;
void setFifo(SampleMOFifo *sampleFifo) { m_sampleFifo = sampleFifo; }
SampleMOFifo *getFifo() { return m_sampleFifo; }
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
lms_stream_t* m_stream0;
lms_stream_t* m_stream1;
qint16 *m_buf; //!< Full buffer for SISO or MIMO operation
SampleMOFifo* m_sampleFifo;
Interpolators<qint16, SDR_TX_SAMP_SZ, 12> m_interpolators[2];
unsigned int m_log2Interp;
void run();
unsigned int getNbFifos();
void callbackPart(qint16* buf, qint32 nSamples, int iBegin);
void callback(qint16* buf, qint32 samplesPerChannel);
};
#endif /* PLUGINS_SAMPLEMIMO_LIMESDRMIMO_LIMESDRMOTHREAD_H_ */