1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

XTRX MIMO

This commit is contained in:
f4exb 2020-11-11 04:06:42 +01:00
parent a12cbec658
commit e61d3da43d
20 changed files with 6232 additions and 1 deletions

View File

@ -160,3 +160,51 @@ double DeviceXTRX::setSamplerate(double rate, double master, bool output)
return m_inputRate;
}
bool DeviceXTRX::setSamplerate(double rate, uint32_t log2Decim, uint32_t log2Interp, bool output)
{
double master, rxRate, txRate;
if (output)
{
master = (log2Interp == 0) ? 0 : (rate * 4 * (1 << log2Interp));
rxRate = (rate * 4 * (1 << log2Interp)) / (4 * (1 << log2Decim));
txRate = rate;
}
else
{
master = (log2Decim == 0) ? 0 : (rate * 4 * (1 << log2Decim));
rxRate = rate;
txRate = (rate * 4 * (1 << log2Decim)) / (4 * (1 << log2Interp));
}
m_masterRate = master;
m_inputRate = rxRate;
m_outputRate = txRate;
int res = xtrx_set_samplerate(
m_dev,
master,
rxRate,
txRate,
XTRX_SAMPLERATE_FORCE_UPDATE,
&m_clockGen,
&m_actualInputRate,
&m_actualOutputRate
);
qDebug() << "DeviceXTRX::setSamplerate: sample rate set: "
<< "rate: " << rate
<< "log2Decim: " << log2Decim
<< "log2Interp: " << log2Interp
<< "output: " << output
<< "res: "<< res
<< "m_masterRate: " << m_masterRate
<< "m_inputRate: " << m_inputRate
<< "m_outputRate: " << m_outputRate
<< "m_clockGen: " << m_clockGen
<< "m_actualInputRate: " << m_actualInputRate
<< "m_actualOutputRate: " << m_actualOutputRate;
return !(res < 0);
}

View File

@ -37,6 +37,7 @@ public:
static void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices);
struct xtrx_dev *getDevice() { return m_dev; }
double setSamplerate(double rate, double master, bool output);
bool setSamplerate(double rate, uint32_t log2Decim, uint32_t log2Interp, bool output);
double getMasterRate() const { return m_masterRate; }
double getClockGen() const { return m_clockGen; }
double getActualInputRate() const { return m_actualInputRate; }

View File

@ -8,5 +8,9 @@ if(ENABLE_LIMESUITE AND LIMESUITE_FOUND)
add_subdirectory(limesdrmimo)
endif()
if(ENABLE_XTRX AND LIBXTRX_FOUND)
add_subdirectory(xtrxmimo)
endif()
add_subdirectory(testmi)
add_subdirectory(testmosync)

View File

@ -0,0 +1,62 @@
project(xtrxmimo)
set(xtrxmimo_SOURCES
xtrxmimo.cpp
xtrxmimoplugin.cpp
xtrxmithread.cpp
xtrxmothread.cpp
xtrxmimosettings.cpp
xtrxmimowebapiadapter.cpp
)
set(xtrxmimo_HEADERS
xtrxmimo.h
xtrxmimoplugin.h
xtrxmithread.h
xtrxmothread.h
xtrxmimosettings.h
xtrxmimowebapiadapter.h
)
include_directories(
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${CMAKE_SOURCE_DIR}/devices
${LIBXTRX_INCLUDE_DIRS}
)
if (NOT SERVER_MODE)
set (xtrxmimo_SOURCES
${xtrxmimo_SOURCES}
xtrxmimogui.cpp
xtrxmimogui.ui
)
set(xtrxmimo_HEADERS
${xtrxmimo_HEADERS}
xtrxmimogui.h
)
set(TARGET_NAME mimoxtrx)
set(TARGET_LIB "Qt5::Widgets")
set(TARGET_LIB_GUI "sdrgui")
set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR})
else()
set(TARGET_NAME mimoxtrxsrv)
set(TARGET_LIB "")
set(TARGET_LIB_GUI "")
set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR})
endif()
add_library(${TARGET_NAME} SHARED
${xtrxmimo_SOURCES}
)
target_link_libraries(${TARGET_NAME}
Qt5::Core
${TARGET_LIB}
sdrbase
${TARGET_LIB_GUI}
swagger
${LIBXTRX_LIBRARY}
xtrxdevice
)
install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})

View File

@ -0,0 +1,237 @@
<h1>XTRX MIMO plugin</h1>
<h2>Introduction</h2>
This is a v5 only plugin.
This MIMO plugin sends and receives its samples to/from a [XTRX device](https://xtrx.io). It handles both input (Rx) and output (Tx) streams synchronously. There is no option to synchronize Rx with Tx streams.
&#9888; There are USB errors when first starting with XTRX after plugging it in. The only way to work around this is to restart SDRangel application.
&#9888; Reception may stall sometimes particularly with sample rates lower than 5 MS/s and also after changes. You may need to stop and restart the device (stop/start button) to recover.
&#9888; Right after (re)start you may need to move the main frequency dial back and forth if you notice that you are not on the right frequency.
&#9888; Simultaneous Rx and Tx is not supported. Dual Tx is not working either.
<h2>Build</h2>
The plugin will be built only if XTRX support libraries are installed in your system.
If libraries are installed in a custom place like `/opt/install/xtrx-images` add the following defines on `cmake` command line:
`-DXTRX_DIR=/opt/install/xtrx-images`
<h2>Real time scheduling</h2>
You may find in the log some info (green) messages from `libxtrx` mentioning that some task cannot be set with real time priority. While this is not an absolute necessity to make XTRX work you may want to allow your user or a specific group your user belongs to to set tasks with real time scheduling.
In most Linux systems this is done by editing the `/etc/security/limits.conf` file (with sudo rights). In this file you may add these lines for your user (ex: `user`):
```
user - rtprio 99
user - memlock unlimited
```
For a group the syntax is the same but the group name is prefixed with `@` like:
```
@realtime - rtprio 99
@realtime - memlock unlimited
```
<h2>Interface</h2>
![XTRX MIMO plugin GUI](../../../doc/img/XTRXMIMO_plugin.png)
<h3>1. Rx/Tx settings selection</h3>
Use this combo to target UI to Rx or Tx streams for Rx/Tx specific items.
<h3>2. Stream settings selection</h3>
Use this combo to target UI to stream 0 or stream 1 for stream specific items.
<h3>3. Rx/Tx spectrum display selection</h3>
Use this combo to select Rx or Tx side for main spectrum display.
<h3>4. Stream spectrum display selection</h3>
Use this combo to select stream 0 or stream 1 for main spectrum display.
<h3>5. Start/Stop Rx</h3>
This button controls the start/stop of the Rx subsystem.
<h3>6. Start/Stop Tx</h3>
This button controls the start/stop of the Tx subsystem.
<h3>7. Record button</h3>
- Left click: record baseband I/Q stream toggle button (inactive: waiting for synchronous streams recording)
- Right click: choose record file
<h3>8. Center frequency</h3>
This controls the center frequency of Rx or Tx subsystems in kHz depending on the Rx/Tx settings selection (1). This frequency can effectively be different for Rx and Tx but is the same for both Rx or both Tx streams.
<h3>9. ADC/DAC sample rate</h3>
This is the sample rate at which the ADC or DAC runs in kS/s (k) or MS/s (M) before hardware decimation or after hardware interpolation. Thus this is the device to host sample rate (A.7) multiplied by the hardware decimation or interpolation factor (A.8).
<h3>10. Baseband sample rate</h3>
In device to host sample rate input mode (A.6) this is the baseband I/Q sample rate in kS/s. This is the device to host sample rate (A.7) divided by the software decimation or interpolation factor (A.9).
In baseband sample rate input mode (A.6) this is the device to host sample rate in kS/s. This is the baseband sample rate (A.7) multiplied by the software decimation or interpolation factor (A.9)
<h3>A. Section</h3>
![XTRX MIMO A section plugin GUI](../../../doc/img/XTRXMIMO_plugin_A.png)
<h4>A.1. NCO toggle</h4>
The button is lit when NCO is active and dark when inactive.
Use this button to activate/deactivate the TSP NCO. The LMS7002M chip has an independent NCO in each Rx channel that can span the bandwidth received by the ADC. This effectively allows non zero digital IF.
<h4>A.2. NCO frequency shift</h4>
This is the frequency shift applied when the NCO is engaged thus the actual LO frequency is the center frequency of reception minus this value. Use the thumbwheels to adjust frequency as done with the LO (8). Pressing shift simultaneously moves digit by 5 and pressing control moves it by 2. The boundaries are dynamically calculated from the LO center frequency, sample rate and hardware decimation factor.
&#9758; Engaging the NCO shifts the center frequency of reception or transmission by the shift amount. You have to retune the center frequency (8) to get back to the frequency before the NCO was engaged. You may also select the NCO frequency and then tune the center frequency.
&#9758; In the LMS7002M TSP Rx block the NCO sits before the decimator (see Fig.14 of the [datasheet](http://www.limemicro.com/wp-content/uploads/2015/09/LMS7002M-Data-Sheet-v2.8.0.pdf) p.7) so it runs at the actual ADC rate. Hence the NCO limits are calculated as +/- half the device to host sample rate multiplied by the hardware decimation factor. For example with a 4 MS/s device to host sample rate (A.7) and a hardware decimation of 16 (A.8) you have +/- 32 MHz span around the LO for the NCO. In this example you can tune all HF frequencies with the center frequency set at its lowest (30 MHz).
A similar logic is used on the Tx / DAC side.
<h4>A.3. DC auto correction options</h4>
This button controls the local DSP DC auto remove DC component.
<h4>A.4. IQ auto correction options</h4>
This button controls the local DSP auto make I/Q balance. The DC correction must be enabled for this to be effective.
<h4>A.5. External clock control</h4>
Use this button to open a dialog that lets you choose the external clock frequency and enable or disable it. When disabled the internal 30.72 MHz VCTCXO is used.
![LimeSDR input plugin gain GUI](../../../doc/img/LimeSDR_plugin_extclock.png)
<h5>A.5.1. External clock frequency</h5>
Can be varied from 5 to 300 MHz
Use the thumbwheels to adjust frequency as done with the LO (1.1). Pressing shift simultaneously moves digit by 5 and pressing control moves it by 2. The boundaries are dynamically calculated from the LO center frequency, sample rate and hardware decimation factor.
<h5>A.5.2. Enable/disable external clock input</h5>
Use this checkbox to enable or disable the external clock input
<h5>A.5.3. Confirm changes</h5>
Use the "OK" button to confirm your changes
<h5>A.5.4. Dismiss changes</h5>
Use the "Cancel" button to dismiss your changes
<h4>A.6. Device to host sample rate / Baseband sample rate input toggle</h4>
Use this toggle button to switch the sample rate input next (A.7) between device to host sample rate and baseband sample rate input. The button shows the current mode:
- **SR**: device to host sample rate input mode. The baseband sample rate (10) is the device to host sample rate (A.7) divided by the software decimation or interpolation factor (A.9).
- **BB**: baseband sample rate input mode. The device to host sample rate (A.7) is the baseband sample rate (10) multiplied by the software decimation or interpolation factor (A.9).
<h4>A.7. Sample rate</h4>
This is the LMS7002M device to/from host stream sample rate or baseband sample rate in samples per second (S/s). The control (A.6) is used to switch between the two input modes. The device to/from host stream sample rate is the same for the Rx and Tx systems.
The limits are adjusted automatically. In baseband input mode the limits are driven by the decimation or intepolation factor (A.9). You may need to increase this factor to be able to reach lower values.
Use the wheels to adjust the sample rate. Pressing shift simultaneously moves digit by 5 and pressing control moves it by 2. Left click on a digit sets the cursor position at this digit. Right click on a digit sets all digits on the right to zero. This effectively floors value at the digit position. Wheels are moved with the mousewheel while pointing at the wheel or by selecting the wheel with the left mouse click and using the keyboard arrows.
The LMS7002M uses the same clock for both the ADCs and DACs therefore this sample rate affects all of the 2x2 MIMO channels.
<h4>A.8. Hardware decimation or interpolation factor</h4>
The TSP block in the LMS7002M hardware has a decimation/interpolation chain that acts on both Rx/Tx channels and therefore can achieve decimation/interpolation between 1 (no decimation/interpolation) and 64 in increasing powers of 2: 1, 2, 4, 8, 16, 32, 64. However the position "1" (no decimation/interpolation) is replaced by an automatic decimation/interpolation.
<h4>A.9. Software decimation or interpolation factor</h4>
The I/Q stream from the LimeSDR is downsampled/upsampled by a power of two by software inside the plugin before being sent to the passband/device. Possible values are increasing powers of two: 1 (no decimation/interpolation), 2, 4, 8, 16, 32.
<h3>B. section</h3>
![XTRX MIMO B section plugin GUI](../../../doc/img/XTRXMIMO_plugin_B.png)
<h4>B.1. Analog filter bandwidth</h4>
This is the hardware filter bandwidth in kHz in the LMS7002M device for the given channel. Boundaries are updated automatically. Use the wheels to adjust the value. Pressing shift simultaneously moves digit by 5 and pressing control moves it by 2.
<h4>B.2. Power mode</h4>
XTRX power mode
<h4>B.3. Gain mode</h4>
This is the gain mode control that applies to Rx only:
- **automatic**: AGC based on a global gain (B.4)
- **manual**: Manual. Use LNA, TIA and PGA controls (B.5 to B.7) to adjust gain
<h4>B.4. Manual gain setting</h4>
- Rx: this sets the gain manually per stream if (B.3) is set to "Manual".
- Tx: this sets the gain
<h4>B.5. LNA gain</h4>
Rx only. This is the LNA gain stage in dB
<h4>B.6. TIA gain</h4>
Rx only. This is the TIA gain block settings in 3 increasing stages.
<h4>B.7. PGA gain</h4>
Rx only. This is the PGA gain stage in dB
<h4>A.8. Antenna path select</h4>
<h5>Rx side</h5>
Use this combo box to select the input path (network):
- **Lo**: Selects the low frequency input. You should use this one and this is the default
- **Wide**: Selects the wide band frequency input. This is not connected and should not be used
- **Hi**: Selects the high frequency input. You may use this one as well with no actual difference with "Lo".
<h5>Tx side</h5>
Use this combo box to select the output path (network):
- **Hi**: Tx high range
- **Wi**: Tx wide range: you should use this one (default)
<h3>11. Stream status indicator</h3>
This label turns green when status can be obtained from the current stream. Usually this means that the stream is up and running but not necessarily streaming data. The various status elements appear next on the same line (13)
<h3>12. GPS status</h3>
This label turns green when the GPS used for the GPSDO is locked.
<h3>13. Rx FIFO status</h3>
This is the fill percentage of the Rx FIFO in the XTRX interface. It should be zero most of the time.
<h3>14. Tx FIFO status</h3>
This is the fill percentage of the Tx FIFO in the XTRX interface. It should be near 100% most of the time.
<h3>15. Board temperature</h3>
This is the board temperature in degrees Celsius updated every ~5s. Before the first probe the display marks "00C" this is normal.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,301 @@
///////////////////////////////////////////////////////////////////////////////////
// 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_XTRXMIMO_XTRXMIMO_H_
#define PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMIMO_H_
#include <stdint.h>
#include <QString>
#include <QByteArray>
#include <QNetworkRequest>
#include "dsp/devicesamplemimo.h"
#include "xtrx/devicextrxshared.h"
#include "xtrxmimosettings.h"
class QNetworkAccessManager;
class QNetworkReply;
class DeviceAPI;
class XTRXMIThread;
class XTRXMOThread;
class DeviceLimeSDRParams;
#endif // PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMIMO_H_
class XTRXMIMO : public DeviceSampleMIMO {
Q_OBJECT
public:
class MsgConfigureXTRXMIMO : public Message {
MESSAGE_CLASS_DECLARATION
public:
const XTRXMIMOSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
static MsgConfigureXTRXMIMO* create(const XTRXMIMOSettings& settings, bool force)
{
return new MsgConfigureXTRXMIMO(settings, force);
}
private:
XTRXMIMOSettings m_settings;
bool m_force;
MsgConfigureXTRXMIMO(const XTRXMIMOSettings& 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 MsgReportClockGenChange : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgReportClockGenChange* create()
{
return new MsgReportClockGenChange();
}
private:
MsgReportClockGenChange() :
Message()
{ }
};
class MsgReportStreamInfo : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getSuccess() const { return m_success; }
bool getActive() const { return m_active; }
uint32_t getFifoFilledCountRx() const { return m_fifoFilledCountRx; }
uint32_t getFifoFilledCountTx() const { return m_fifoFilledCountTx; }
uint32_t getFifoSize() const { return m_fifoSize; }
static MsgReportStreamInfo* create(
bool success,
bool active,
uint32_t fifoFilledCountRx,
uint32_t fifoFilledCountTx,
uint32_t fifoSize
)
{
return new MsgReportStreamInfo(
success,
active,
fifoFilledCountRx,
fifoFilledCountTx,
fifoSize
);
}
private:
bool m_success;
// everything from lms_stream_status_t
bool m_active; //!< Indicates whether the stream is currently active
uint32_t m_fifoFilledCountRx; //!< Number of samples in FIFO buffer (Rx)
uint32_t m_fifoFilledCountTx; //!< Number of samples in FIFO buffer (Tx)
uint32_t m_fifoSize; //!< Size of FIFO buffer
MsgReportStreamInfo(
bool success,
bool active,
uint32_t fifoFilledCountRx,
uint32_t fifoFilledCountTx,
uint32_t fifoSize
) :
Message(),
m_success(success),
m_active(active),
m_fifoFilledCountRx(fifoFilledCountRx),
m_fifoFilledCountTx(fifoFilledCountTx),
m_fifoSize(fifoSize)
{ }
};
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)
{ }
};
XTRXMIMO(DeviceAPI *deviceAPI);
virtual ~XTRXMIMO();
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);
uint32_t getRxDevSampleRate() const;
uint32_t getTxDevSampleRate() const;
uint32_t getLog2HardDecim() const;
uint32_t getLog2HardInterp() const;
double getClockGen() const;
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 XTRXMIMOSettings& settings);
static void webapiUpdateDeviceSettings(
XTRXMIMOSettings& settings,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
bool getRxRunning() const { return m_runningRx; }
bool getTxRunning() const { return m_runningTx; }
void getLORange(float& minF, float& maxF, float& stepF) const;
void getSRRange(float& minF, float& maxF, float& stepF) const;
void getLPRange(float& minF, float& maxF, float& stepF) const;
private:
DeviceAPI *m_deviceAPI;
QMutex m_mutex;
XTRXMIMOSettings m_settings;
XTRXMIThread* m_sourceThread;
XTRXMOThread* m_sinkThread;
QString m_deviceDescription;
bool m_runningRx;
bool m_runningTx;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
bool m_open;
DeviceXTRXShared m_deviceShared;
bool openDevice();
void closeDevice();
bool applySettings(const XTRXMIMOSettings& settings, bool force);
void applyGainAuto(unsigned int channel, uint32_t gain);
void applyGainLNA(unsigned int channel, double gain);
void applyGainTIA(unsigned int channel, double gain);
void applyGainPGA(unsigned int channel, double gain);
void setRxDeviceCenterFrequency(xtrx_dev *dev, quint64 freq_hz, int loPpmTenths);
void setTxDeviceCenterFrequency(xtrx_dev *dev, quint64 freq_hz, int loPpmTenths);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const XTRXMIMOSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);
static xtrx_antenna_t toXTRXAntennaRx(XTRXMIMOSettings::RxAntenna antennaPath);
static xtrx_antenna_t toXTRXAntennaTx(XTRXMIMOSettings::TxAntenna antennaPath);
static double tiaToDB(unsigned idx);
private slots:
void networkManagerFinished(QNetworkReply *reply);
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
///////////////////////////////////////////////////////////////////////////////////
// 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_XTRXMIMO_XTRXMIMOGUI_H_
#define PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMIMOGUI_H_
#include <QTimer>
#include <QWidget>
#include "util/messagequeue.h"
#include "device/devicegui.h"
#include "xtrxmimosettings.h"
class DeviceUISet;
class XTRXMIMO;
namespace Ui {
class XTRXMIMOGUI;
}
class XTRXMIMOGUI : public DeviceGUI {
Q_OBJECT
public:
explicit XTRXMIMOGUI(DeviceUISet *deviceUISet, QWidget* parent = nullptr);
virtual ~XTRXMIMOGUI();
virtual void destroy();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
private:
Ui::XTRXMIMOGUI* ui;
DeviceUISet* m_deviceUISet;
XTRXMIMOSettings 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
QTimer m_updateTimer;
QTimer m_statusTimer;
bool m_doApplySettings;
bool m_forceSettings;
XTRXMIMO* m_xtrxMIMO;
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;
void blockApplySettings(bool block) { m_doApplySettings = !block; }
void displaySettings();
void displaySampleRate();
void setNCODisplay();
void setRxCenterFrequencyDisplay();
void setRxCenterFrequencySetting(uint64_t kHzValue);
void setTxCenterFrequencyDisplay();
void setTxCenterFrequencySetting(uint64_t kHzValue);
void sendSettings();
void updateSampleRateAndFrequency();
void updateADCRate();
void updateDACRate();
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_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_pwrmode_currentIndexChanged(int index);
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);
};
#endif // PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMIMOGUI_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 "xtrx/devicextrx.h"
#ifndef SERVER_MODE
#include "xtrxmimogui.h"
#endif
#include "xtrxmimo.h"
#include "xtrxmimoplugin.h"
#include "xtrxmimowebapiadapter.h"
const PluginDescriptor XTRXMIMOPlugin::m_pluginDescriptor = {
QString("XTRX"),
QString("XTRX MIMO"),
QString("5.13.0"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,
QString("https://github.com/f4exb/sdrangel")
};
const QString XTRXMIMOPlugin::m_hardwareID = "XTRX";
const QString XTRXMIMOPlugin::m_deviceTypeID = XTRXMIMO_DEVICE_TYPE_ID;
XTRXMIMOPlugin::XTRXMIMOPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& XTRXMIMOPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void XTRXMIMOPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleMIMO(m_deviceTypeID, this);
}
void XTRXMIMOPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& originDevices)
{
if (listedHwIds.contains(m_hardwareID)) { // check if it was done
return;
}
DeviceXTRX::enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
PluginInterface::SamplingDevices XTRXMIMOPlugin::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* XTRXMIMOPlugin::createSampleMIMOPluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
(void) sourceId;
(void) widget;
(void) deviceUISet;
return nullptr;
}
#else
DeviceGUI* XTRXMIMOPlugin::createSampleMIMOPluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
if (sourceId == m_deviceTypeID)
{
XTRXMIMOGUI* gui = new XTRXMIMOGUI(deviceUISet);
*widget = gui;
return gui;
}
else
{
return nullptr;
}
}
#endif
DeviceSampleMIMO *XTRXMIMOPlugin::createSampleMIMOPluginInstance(const QString& mimoId, DeviceAPI *deviceAPI)
{
if (mimoId == m_deviceTypeID)
{
XTRXMIMO* input = new XTRXMIMO(deviceAPI);
return input;
}
else
{
return nullptr;
}
}
DeviceWebAPIAdapter *XTRXMIMOPlugin::createDeviceWebAPIAdapter() const
{
return new XTRXMIMOWebAPIAdapter();
}

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 _XTRXMIMO_XTRXMIMOPLUGIN_H
#define _XTRXMIMO_XTRXMIMOPLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
class PluginAPI;
#define XTRXMIMO_DEVICE_TYPE_ID "sdrangel.samplemimo.xtrxmimo"
class XTRXMIMOPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID XTRXMIMO_DEVICE_TYPE_ID)
public:
explicit XTRXMIMOPlugin(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;
static const QString m_hardwareID;
static const QString m_deviceTypeID;
private:
static const PluginDescriptor m_pluginDescriptor;
};
#endif // _XTRXMIMO_XTRXMIMOPLUGIN_H

View File

@ -0,0 +1,218 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "util/simpleserializer.h"
#include "xtrxmimosettings.h"
XTRXMIMOSettings::XTRXMIMOSettings()
{
resetToDefaults();
}
void XTRXMIMOSettings::resetToDefaults()
{
// common
m_extClock = false;
m_extClockFreq = 0; // Auto
m_useReverseAPI = false;
m_reverseAPIAddress = "127.0.0.1";
m_reverseAPIPort = 8888;
m_reverseAPIDeviceIndex = 0;
// Rx
m_rxDevSampleRate = 5e6;
m_rxCenterFrequency = 435000*1000;
m_log2HardDecim = 2;
m_dcBlock = false;
m_iqCorrection = false;
m_log2SoftDecim = 0;
m_ncoEnableRx = false;
m_ncoFrequencyRx = 0;
m_antennaPathRx = RXANT_LO;
m_iqOrder = true;
// Rx0
m_lpfBWRx0 = 4.5e6f;
m_gainRx0 = 50;
m_gainModeRx0 = GAIN_AUTO;
m_lnaGainRx0 = 15;
m_tiaGainRx0 = 2;
m_pgaGainRx0 = 16;
m_pwrmodeRx0 = 4;
// Rx1
m_lpfBWRx1 = 4.5e6f;
m_gainRx1 = 50;
m_gainModeRx1 = GAIN_AUTO;
m_lnaGainRx1 = 15;
m_tiaGainRx1 = 2;
m_pgaGainRx1 = 16;
m_pwrmodeRx1 = 4;
// Tx
m_txDevSampleRate = 5e6;
m_txCenterFrequency = 435000*1000;
m_log2HardInterp = 2;
m_log2SoftInterp = 4;
m_ncoEnableTx = true;
m_ncoFrequencyTx = 500000;
m_antennaPathTx = TXANT_WI;
// Tx0
m_lpfBWTx0 = 4.5e6f;
m_gainTx0 = 20;
m_pwrmodeTx0 = 4;
// Tx1
m_lpfBWTx1 = 4.5e6f;
m_gainTx1 = 20;
m_pwrmodeTx1 = 4;
}
QByteArray XTRXMIMOSettings::serialize() const
{
SimpleSerializer s(1);
// common
s.writeBool(2, m_extClock);
s.writeU32(3, m_extClockFreq);
s.writeBool(5, m_useReverseAPI);
s.writeString(6, m_reverseAPIAddress);
s.writeU32(7, m_reverseAPIPort);
s.writeU32(8, m_reverseAPIDeviceIndex);
// Rx
s.writeU32(20, m_log2HardDecim);
s.writeU32(21, m_log2SoftDecim);
s.writeBool(22, m_dcBlock);
s.writeBool(23, m_iqCorrection);
s.writeBool(24, m_ncoEnableRx);
s.writeS32(25, m_ncoFrequencyRx);
s.writeS32(26, (int) m_antennaPathRx);
s.writeDouble(27, m_rxDevSampleRate);
s.writeBool(28, m_iqOrder);
// Rx0
s.writeFloat(30, m_lpfBWRx0);
s.writeU32(31, m_gainRx0);
s.writeS32(34, (int) m_gainModeRx0);
s.writeU32(35, m_lnaGainRx0);
s.writeU32(36, m_tiaGainRx0);
s.writeU32(37, m_pgaGainRx0);
s.writeU32(38, m_pwrmodeRx0);
// Rx1
s.writeFloat(50, m_lpfBWRx0);
s.writeU32(51, m_gainRx0);
s.writeS32(54, (int) m_gainModeRx0);
s.writeU32(55, m_lnaGainRx0);
s.writeU32(56, m_tiaGainRx0);
s.writeU32(57, m_pgaGainRx0);
s.writeU32(58, m_pwrmodeRx0);
// Tx
s.writeU32(70, m_log2HardInterp);
s.writeU32(71, m_log2SoftInterp);
s.writeBool(72, m_ncoEnableTx);
s.writeS32(73, m_ncoFrequencyTx);
s.writeS32(74, (int) m_antennaPathTx);
s.writeDouble(75, m_txDevSampleRate);
// Tx0
s.writeFloat(80, m_lpfBWTx0);
s.writeU32(81, m_gainTx0);
s.writeU32(82, m_pwrmodeTx0);
// Tx1
s.writeFloat(90, m_lpfBWTx1);
s.writeU32(91, m_gainTx1);
s.writeU32(92, m_pwrmodeTx1);
return s.final();
}
bool XTRXMIMOSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
int intval;
uint32_t uintval;
// common
d.readBool(2, &m_extClock, false);
d.readU32(3, &m_extClockFreq, 0);
d.readBool(5, &m_useReverseAPI, false);
d.readString(6, &m_reverseAPIAddress, "127.0.0.1");
d.readU32(7, &uintval, 0);
if ((uintval > 1023) && (uintval < 65535)) {
m_reverseAPIPort = uintval;
} else {
m_reverseAPIPort = 8888;
}
d.readU32(8, &uintval, 0);
m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
// Rx
d.readU32(20, &m_log2HardDecim, 1);
d.readU32(21, &m_log2SoftDecim, 0);
d.readBool(22, &m_dcBlock, false);
d.readBool(23, &m_iqCorrection, false);
d.readBool(24, &m_ncoEnableRx, false);
d.readS32(25, &m_ncoFrequencyRx, 0);
d.readS32(26, &intval, 0);
m_antennaPathRx = (RxAntenna) intval;
d.readDouble(27, &m_rxDevSampleRate, 5e6);
d.readBool(28, &m_iqOrder, true);
// Rx0
d.readFloat(30, &m_lpfBWRx0, 1.5e6);
d.readU32(31, &m_gainRx0, 50);
d.readS32(34, &intval, 0);
m_gainModeRx0 = (GainMode) intval;
d.readU32(35, &m_lnaGainRx0, 15);
d.readU32(36, &m_tiaGainRx0, 2);
d.readU32(37, &m_pgaGainRx0, 16);
d.readU32(38, &m_pwrmodeRx0, 4);
// Rx1
d.readFloat(50, &m_lpfBWRx1, 1.5e6);
d.readU32(51, &m_gainRx1, 50);
d.readS32(54, &intval, 0);
m_gainModeRx1 = (GainMode) intval;
d.readU32(55, &m_lnaGainRx1, 15);
d.readU32(56, &m_tiaGainRx1, 2);
d.readU32(57, &m_pgaGainRx1, 16);
d.readU32(58, &m_pwrmodeRx1, 4);
// Tx
d.readU32(70, &m_log2HardInterp, 2);
d.readU32(71, &m_log2SoftInterp, 0);
d.readS32(72, &intval, 0);
d.readBool(73, &m_ncoEnableTx, true);
d.readS32(74, &m_ncoFrequencyTx, 500000);
m_antennaPathTx = (TxAntenna) intval;
d.readDouble(75, &m_txDevSampleRate, 5e6);
// Tx0
d.readFloat(80, &m_lpfBWTx0, 1.5e6);
d.readU32(81, &m_gainTx0, 20);
d.readU32(82, &m_pwrmodeTx0, 4);
// Tx1
d.readFloat(90, &m_lpfBWTx1, 1.5e6);
d.readU32(91, &m_gainTx1, 20);
d.readU32(92, &m_pwrmodeTx1, 4);
return true;
}
else
{
resetToDefaults();
return false;
}
}

View File

@ -0,0 +1,104 @@
///////////////////////////////////////////////////////////////////////////////////
// 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_XTRXMIMO_XTRXMIMOSETTINGS_H_
#define PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMIMOSETTINGS_H_
#include <stdint.h>
#include <QtGlobal>
#include <QString>
struct XTRXMIMOSettings
{
typedef enum {
GAIN_AUTO,
GAIN_MANUAL
} GainMode;
typedef enum {
RXANT_LO,
RXANT_WI,
RXANT_HI
} RxAntenna;
typedef enum {
TXANT_HI,
TXANT_WI
} TxAntenna;
// common
bool m_extClock; //!< True if external clock source
uint32_t m_extClockFreq; //!< Frequency (Hz) of external clock source
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_useReverseAPI;
QString m_reverseAPIAddress;
uint16_t m_reverseAPIPort;
uint16_t m_reverseAPIDeviceIndex;
// Rx
double m_rxDevSampleRate;
uint32_t m_log2HardDecim;
uint32_t m_log2SoftDecim;
uint64_t m_rxCenterFrequency;
bool m_dcBlock;
bool m_iqCorrection;
bool m_ncoEnableRx; //!< Enable TSP NCO and mixing
int m_ncoFrequencyRx; //!< Actual NCO frequency (the resulting frequency with mixing is displayed)
RxAntenna m_antennaPathRx;
bool m_iqOrder;
// Rx0
float m_lpfBWRx0; //!< LMS analog lowpass filter bandwidth (Hz)
uint32_t m_gainRx0; //!< Optimally distributed gain (dB)
GainMode m_gainModeRx0; //!< Gain mode: auto or manual
uint32_t m_lnaGainRx0; //!< Manual LNA gain
uint32_t m_tiaGainRx0; //!< Manual TIA gain
uint32_t m_pgaGainRx0; //!< Manual PGA gain
uint32_t m_pwrmodeRx0;
// Rx1
float m_lpfBWRx1; //!< LMS analog lowpass filter bandwidth (Hz)
uint32_t m_gainRx1; //!< Optimally distributed gain (dB)
GainMode m_gainModeRx1; //!< Gain mode: auto or manual
uint32_t m_lnaGainRx1; //!< Manual LNA gain
uint32_t m_tiaGainRx1; //!< Manual TIA gain
uint32_t m_pgaGainRx1; //!< Manual PGA gain
uint32_t m_pwrmodeRx1;
// Tx
double m_txDevSampleRate;
uint32_t m_log2HardInterp;
uint32_t m_log2SoftInterp;
uint64_t m_txCenterFrequency;
bool m_ncoEnableTx; //!< Enable TSP NCO and mixing
int m_ncoFrequencyTx; //!< Actual NCO frequency (the resulting frequency with mixing is displayed)
TxAntenna m_antennaPathTx;
// Tx0
float m_lpfBWTx0; //!< LMS analog lowpass filter bandwidth (Hz)
uint32_t m_gainTx0; //!< Optimally distributed gain (dB)
uint32_t m_pwrmodeTx0;
// Tx1
float m_lpfBWTx1; //!< LMS analog lowpass filter bandwidth (Hz)
uint32_t m_gainTx1; //!< Optimally distributed gain (dB)
uint32_t m_pwrmodeTx1;
XTRXMIMOSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif // PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMIMOSETTINGS_H_

View File

@ -0,0 +1,52 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 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 "xtrxmimo.h"
#include "xtrxmimowebapiadapter.h"
XTRXMIMOWebAPIAdapter::XTRXMIMOWebAPIAdapter()
{}
XTRXMIMOWebAPIAdapter::~XTRXMIMOWebAPIAdapter()
{}
int XTRXMIMOWebAPIAdapter::webapiSettingsGet(
SWGSDRangel::SWGDeviceSettings& response,
QString& errorMessage)
{
(void) errorMessage;
response.setXtrxMimoSettings(new SWGSDRangel::SWGXtrxMIMOSettings());
response.getXtrxMimoSettings()->init();
XTRXMIMO::webapiFormatDeviceSettings(response, m_settings);
return 200;
}
int XTRXMIMOWebAPIAdapter::webapiSettingsPutPatch(
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage)
{
(void) force;
(void) errorMessage;
XTRXMIMO::webapiUpdateDeviceSettings(m_settings, deviceSettingsKeys, response);
return 200;
}

View File

@ -0,0 +1,44 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 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 "xtrxmimosettings.h"
class XTRXMIMOWebAPIAdapter : public DeviceWebAPIAdapter
{
public:
XTRXMIMOWebAPIAdapter();
virtual ~XTRXMIMOWebAPIAdapter();
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:
XTRXMIMOSettings m_settings;
};

View File

@ -0,0 +1,261 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 <errno.h>
#include <chrono>
#include <thread>
#include "dsp/samplemififo.h"
#include "xtrxmithread.h"
XTRXMIThread::XTRXMIThread(struct xtrx_dev *dev, QObject* parent) :
QThread(parent),
m_running(false),
m_dev(dev),
m_sampleFifo(nullptr),
m_iqOrder(true)
{
qDebug("XTRXMIThread::XTRXMIThread");
for (unsigned int i = 0; i < 2; i++) {
m_channels[i].m_convertBuffer.resize(DeviceXTRX::blockSize, Sample{0,0});
}
m_vBegin.push_back(m_channels[0].m_convertBuffer.begin());
m_vBegin.push_back(m_channels[1].m_convertBuffer.begin());
}
XTRXMIThread::~XTRXMIThread()
{
qDebug("XTRXMIThread::~XTRXMIThread");
if (m_running) {
stopWork();
}
}
void XTRXMIThread::startWork()
{
if (m_running) {
return; // return if running already
}
m_startWaitMutex.lock();
start();
while (!m_running) {
m_startWaiter.wait(&m_startWaitMutex, 100);
}
m_startWaitMutex.unlock();
}
void XTRXMIThread::stopWork()
{
if (!m_running) {
return; // return if not running
}
m_running = false;
wait();
}
void XTRXMIThread::run()
{
int res;
int lengths[2];
m_running = true;
m_startWaiter.wakeAll();
xtrx_run_params params;
xtrx_run_params_init(&params);
params.dir = XTRX_RX;
params.rx.chs = XTRX_CH_AB;
params.rx.wfmt = XTRX_WF_16;
params.rx.hfmt = XTRX_IQ_INT16;
params.rx_stream_start = 2*DeviceXTRX::blockSize; // was 2*8192
params.rx.paketsize = 2*DeviceXTRX::blockSize;
res = xtrx_run_ex(m_dev, &params);
if (res != 0)
{
qCritical("XTRXInputThread::run: could not start stream err:%d", res);
m_running = false;
}
else
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));
qDebug("XTRXInputThread::run: stream started");
}
const unsigned int elemSize = 4; // XTRX uses 4 byte I+Q samples
std::vector<std::vector<char>> buffMem(2, std::vector<char>(elemSize*DeviceXTRX::blockSize));
std::vector<void *> buffs(2);
for (std::size_t i = 0; i < 2; i++) {
buffs[i] = buffMem[i].data();
}
xtrx_recv_ex_info_t nfo;
nfo.samples = DeviceXTRX::blockSize;
nfo.buffer_count = 2;
nfo.buffers = (void* const*) buffs.data();
nfo.flags = RCVEX_DONT_INSER_ZEROS | RCVEX_DROP_OLD_ON_OVERFLOW;
while (m_running)
{
res = xtrx_recv_sync_ex(m_dev, &nfo);
if (res < 0)
{
qCritical("XTRXInputThread::run read error: %d", res);
qDebug("XTRXInputThread::run: out_samples: %u out_events: %u", nfo.out_samples, nfo.out_events);
break;
}
if (nfo.out_events & RCVEX_EVENT_OVERFLOW) {
qDebug("XTRXInputThread::run: overflow");
}
if (m_iqOrder)
{
lengths[0] = callbackSIIQ(0, (const qint16*) buffs[0], 2*nfo.out_samples);
lengths[1] = callbackSIIQ(1, (const qint16*) buffs[1], 2*nfo.out_samples);
}
else
{
lengths[0] = callbackSIQI(0, (const qint16*) buffs[0], 2*nfo.out_samples);
lengths[1] = callbackSIQI(1, (const qint16*) buffs[1], 2*nfo.out_samples);
}
if (lengths[0] == lengths[1])
{
m_sampleFifo->writeSync(m_vBegin, lengths[0]);
}
else
{
qWarning("XTRXMIThread::run: unequal channel lengths: [0]=%d [1]=%d", lengths[0], lengths[1]);
m_sampleFifo->writeSync(m_vBegin, (std::min)(lengths[0], lengths[1]));
}
}
res = xtrx_stop(m_dev, XTRX_RX);
if (res != 0)
{
qCritical("XTRXInputThread::run: could not stop stream");
}
else
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));
qDebug("XTRXInputThread::run: stream stopped");
}
m_running = false;
}
void XTRXMIThread::setLog2Decimation(unsigned int log2_decim)
{
m_log2Decim = log2_decim;
}
unsigned int XTRXMIThread::getLog2Decimation() const
{
return m_log2Decim;
}
int XTRXMIThread::callbackSIIQ(unsigned int channel, const qint16* buf, qint32 len)
{
SampleVector::iterator it = m_channels[channel].m_convertBuffer.begin();
if (m_log2Decim == 0)
{
m_channels[channel].m_decimatorsIQ.decimate1(&it, buf, len);
}
else
{
switch (m_log2Decim)
{
case 1:
m_channels[channel].m_decimatorsIQ.decimate2_cen(&it, buf, len);
break;
case 2:
m_channels[channel].m_decimatorsIQ.decimate4_cen(&it, buf, len);
break;
case 3:
m_channels[channel].m_decimatorsIQ.decimate8_cen(&it, buf, len);
break;
case 4:
m_channels[channel].m_decimatorsIQ.decimate16_cen(&it, buf, len);
break;
case 5:
m_channels[channel].m_decimatorsIQ.decimate32_cen(&it, buf, len);
break;
case 6:
m_channels[channel].m_decimatorsIQ.decimate64_cen(&it, buf, len);
break;
default:
break;
}
}
return it - m_channels[channel].m_convertBuffer.begin();
}
int XTRXMIThread::callbackSIQI(unsigned int channel, const qint16* buf, qint32 len)
{
SampleVector::iterator it = m_channels[channel].m_convertBuffer.begin();
if (m_log2Decim == 0)
{
m_channels[channel].m_decimatorsQI.decimate1(&it, buf, len);
}
else
{
switch (m_log2Decim)
{
case 1:
m_channels[channel].m_decimatorsQI.decimate2_cen(&it, buf, len);
break;
case 2:
m_channels[channel].m_decimatorsQI.decimate4_cen(&it, buf, len);
break;
case 3:
m_channels[channel].m_decimatorsQI.decimate8_cen(&it, buf, len);
break;
case 4:
m_channels[channel].m_decimatorsQI.decimate16_cen(&it, buf, len);
break;
case 5:
m_channels[channel].m_decimatorsQI.decimate32_cen(&it, buf, len);
break;
case 6:
m_channels[channel].m_decimatorsQI.decimate64_cen(&it, buf, len);
break;
default:
break;
}
}
return it - m_channels[channel].m_convertBuffer.begin();
}

View File

@ -0,0 +1,73 @@
///////////////////////////////////////////////////////////////////////////////////
// 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_XTRXMIMO_XTRXMITHREAD_H_
#define PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMITHREAD_H_
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include "xtrx_api.h"
#include "xtrx/devicextrx.h"
#include "dsp/decimators.h"
class SampleMIFifo;
class XTRXMIThread : public QThread {
Q_OBJECT
public:
XTRXMIThread(struct xtrx_dev *dev, QObject* parent = nullptr);
~XTRXMIThread();
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; }
void setIQOrder(bool iqOrder) { m_iqOrder = iqOrder; }
private:
struct Channel
{
SampleVector m_convertBuffer;
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12, true> m_decimatorsIQ;
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12, false> m_decimatorsQI;
};
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
struct xtrx_dev* m_dev;
qint16 m_buf[2][2*DeviceXTRX::blockSize];
Channel m_channels[2];
std::vector<SampleVector::const_iterator> m_vBegin;
SampleMIFifo* m_sampleFifo;
unsigned int m_log2Decim;
bool m_iqOrder;
void run();
int callbackSIIQ(unsigned int channel, const qint16* buf, qint32 len);
int callbackSIQI(unsigned int channel, const qint16* buf, qint32 len);
};
#endif // PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMITHREAD_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 <algorithm>
#include <chrono>
#include <thread>
#include "dsp/samplemofifo.h"
#include "xtrxmothread.h"
XTRXMOThread::XTRXMOThread(struct xtrx_dev *dev, QObject* parent) :
QThread(parent),
m_running(false),
m_dev(dev),
m_sampleFifo(nullptr)
{
qDebug("XTRXMOThread::XTRXMOThread");
m_buf = new qint16[2*DeviceXTRX::blockSize*2];
std::fill(m_buf, m_buf + 2*DeviceXTRX::blockSize*2, 0);
}
XTRXMOThread::~XTRXMOThread()
{
qDebug("XTRXMOThread::~XTRXMOThread");
if (m_running) {
stopWork();
}
delete[] m_buf;
}
void XTRXMOThread::startWork()
{
m_startWaitMutex.lock();
start();
while(!m_running) {
m_startWaiter.wait(&m_startWaitMutex, 100);
}
m_startWaitMutex.unlock();
}
void XTRXMOThread::stopWork()
{
m_running = false;
wait();
}
void XTRXMOThread::setLog2Interpolation(unsigned int log2Interp)
{
qDebug("XTRXMOThread::setLog2Interpolation: %u", log2Interp);
m_log2Interp = log2Interp;
}
unsigned int XTRXMOThread::getLog2Interpolation() const
{
return m_log2Interp;
}
void XTRXMOThread::run()
{
int res;
m_running = true;
m_startWaiter.wakeAll();
xtrx_run_params params;
xtrx_run_params_init(&params);
params.dir = XTRX_TX;
params.tx_repeat_buf = 0;
params.tx.paketsize = 2*DeviceXTRX::blockSize;
params.tx.chs = XTRX_CH_AB;
params.tx.wfmt = XTRX_WF_16;
params.tx.hfmt = XTRX_IQ_INT16;
params.tx.flags |= XTRX_RSP_SWAP_IQ;
res = xtrx_run_ex(m_dev, &params);
if (res != 0)
{
qCritical("XTRXMOThread::run: could not start stream err:%d", res);
m_running = false;
}
else
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));
qDebug("XTRXMOThread::run: stream started");
}
qint16 buf0[2*DeviceXTRX::blockSize]; // I+Q = 2x16 bit samples
qint16 buf1[2*DeviceXTRX::blockSize];
std::vector<void *> buffs(2);
master_ts ts = 4096*1024;
buffs[0] = &buf0;
buffs[1] = &buf1;
xtrx_send_ex_info_t nfo;
nfo.samples = DeviceXTRX::blockSize;
nfo.buffer_count = 2;
nfo.buffers = (void* const*) buffs.data();
nfo.flags = XTRX_TX_DONT_BUFFER; // | XTRX_TX_SEND_ZEROS;
nfo.timeout = 0;
nfo.out_txlatets = 0;
nfo.ts = ts;
while (m_running)
{
callback(buf0, buf1, nfo.samples);
res = xtrx_send_sync_ex(m_dev, &nfo);
if (res < 0)
{
qCritical("XTRXMOThread::run send error: %d", res);
qDebug("XTRXMOThread::run: out_samples: %u out_flags: %u", nfo.out_samples, nfo.out_flags);
break;
}
if (nfo.out_flags & XTRX_TX_DISCARDED_TO) {
qDebug("XTRXMOThread::run: underrun");
}
if (nfo.out_txlatets) {
qDebug("XTRXMOThread::run: out_txlatets: %lu", nfo.out_txlatets);
}
nfo.ts += DeviceXTRX::blockSize;
}
res = xtrx_stop(m_dev, XTRX_TX);
if (res != 0)
{
qCritical("XTRXMOThread::run: could not stop stream");
}
else
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));
qDebug("XTRXMOThread::run: stream stopped");
}
m_running = false;
}
void XTRXMOThread::callback(qint16* buf0, qint16* buf1, qint32 samplesPerChannel)
{
unsigned int iPart1Begin, iPart1End, iPart2Begin, iPart2End;
m_sampleFifo->readSync(samplesPerChannel/(1<<m_log2Interp), iPart1Begin, iPart1End, iPart2Begin, iPart2End);
if (iPart1Begin != iPart1End)
{
callbackPart(buf0, buf1, (iPart1End - iPart1Begin)*(1<<m_log2Interp), iPart1Begin);
}
if (iPart2Begin != iPart2End)
{
unsigned int shift = (iPart1End - iPart1Begin)*(1<<m_log2Interp);
callbackPart(buf0 + 2*shift, buf1 + 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 XTRXMOThread::callbackPart(qint16* buf0, qint16* buf1, 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,
channel == 0 ? buf0 : buf1,
2*nSamples);
}
else
{
switch (m_log2Interp)
{
case 1:
m_interpolators[channel].interpolate2_cen(
&begin,
channel == 0 ? buf0 : buf1,
2*nSamples);
break;
case 2:
m_interpolators[channel].interpolate4_cen(
&begin,
channel == 0 ? buf0 : buf1,
2*nSamples);
break;
case 3:
m_interpolators[channel].interpolate8_cen(
&begin,
channel == 0 ? buf0 : buf1,
2*nSamples);
break;
case 4:
m_interpolators[channel].interpolate16_cen(
&begin,
channel == 0 ? buf0 : buf1,
2*nSamples);
break;
case 5:
m_interpolators[channel].interpolate32_cen(
&begin,
channel == 0 ? buf0 : buf1,
2*nSamples);
break;
case 6:
m_interpolators[channel].interpolate64_cen(
&begin,
channel == 0 ? buf0 : buf1,
2*nSamples);
break;
default:
break;
}
}
}
}

View File

@ -0,0 +1,63 @@
///////////////////////////////////////////////////////////////////////////////////
// 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_XTRXMIMO_XTRXMOTHREAD_H_
#define PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMOTHREAD_H_
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include "xtrx_api.h"
#include "xtrx/devicextrx.h"
#include "dsp/interpolators.h"
class SampleMOFifo;
class XTRXMOThread : public QThread {
Q_OBJECT
public:
XTRXMOThread(struct xtrx_dev *dev, QObject* parent = nullptr);
~XTRXMOThread();
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;
struct xtrx_dev* m_dev;
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();
void callback(qint16* buf0, qint16* buf1, qint32 samplesPerChannel);
void callbackPart(qint16* buf0, qint16* buf1, qint32 nSamples, int iBegin);
};
#endif // PLUGINS_SAMPLEMIMO_XTRXMIMO_XTRXMOTHREAD_H_