XTRX input: imported code from xtrx-sdr fork

pull/269/head
f4exb 2018-12-29 01:20:48 +01:00
rodzic 87832263c0
commit 0e7f8ff125
22 zmienionych plików z 4526 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,27 @@
if(NOT LIBXTRX_FOUND)
pkg_check_modules (LIBXTRX_PKG libxtrx)
find_path(LIBXTRX_INCLUDE_DIRS NAMES xtrx_api.h
PATHS
${LIBXTRX_PKG_INCLUDE_DIRS}
/usr/include
/usr/local/include
)
find_library(LIBXTRX_LIBRARIES NAMES xtrx
PATHS
${LIBXTRX_PKG_LIBRARY_DIRS}
/usr/lib
/usr/local/lib
)
if(LIBXTRX_INCLUDE_DIRS AND LIBXTRX_LIBRARIES)
set(LIBXTRX_FOUND TRUE CACHE INTERNAL "libxtrx found")
message(STATUS "Found libxtrx: ${LIBXTRX_INCLUDE_DIRS}, ${LIBXTRX_LIBRARIES}")
else(LIBXTRX_INCLUDE_DIRS AND LIBXTRX_LIBRARIES)
set(LIBXTRX_FOUND FALSE CACHE INTERNAL "libxtrx found")
message(STATUS "libxtrx not found.")
endif(LIBXTRX_INCLUDE_DIRS AND LIBXTRX_LIBRARIES)
mark_as_advanced(LIBXTRX_LIBRARIES LIBXTRX_INCLUDE_DIRS)
endif(NOT LIBXTRX_FOUND)

Wyświetl plik

@ -12,6 +12,7 @@ if (BUILD_DEBIAN)
add_subdirectory(perseus)
add_subdirectory(plutosdr)
add_subdirectory(soapysdr)
add_subdirectory(xtrx)
else(BUILD_DEBIAN)
find_package(LibBLADERF)
if(LIBUSB_FOUND AND LIBBLADERF_FOUND)
@ -29,6 +30,11 @@ else(BUILD_DEBIAN)
add_subdirectory(limesdr)
endif(LIBUSB_FOUND AND LIMESUITE_FOUND)
find_package(LibXTRX)
if(LIBXTRX_FOUND)
add_subdirectory(xtrx)
endif(LIBXTRX_FOUND)
find_package(LibIIO)
if(LIBUSB_FOUND AND LIBIIO_FOUND)
add_subdirectory(plutosdr)

Wyświetl plik

@ -0,0 +1,31 @@
project(xtrxdevice)
set(xtrxdevice_SOURCES
devicextrxparam.cpp
devicextrxshared.cpp
)
set(xtrxdevice_HEADERS
devicextrxparam.h
devicextrxshared.h
)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${LIBXTRX_INCLUDE_DIRS}
)
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_SHARED)
add_library(xtrxdevice SHARED
${xtrxdevice_SOURCES}
)
target_link_libraries(xtrxdevice
${LIBXTRX_LIBRARIES}
sdrbase
)
install(TARGETS xtrxdevice DESTINATION lib)

Wyświetl plik

@ -0,0 +1,44 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QDebug>
#include "devicextrxparam.h"
bool DeviceXTRXParams::open(const char* deviceStr)
{
int res;
qDebug("DeviceXTRXParams::open: serial: %s", (const char *) deviceStr);
res = xtrx_open(deviceStr, XTRX_O_RESET | 4, &m_dev);
if (res)
{
qCritical() << "DeviceXTRXParams::open: cannot open device " << deviceStr;
return false;
}
return true;
}
void DeviceXTRXParams::close()
{
if (m_dev)
{
xtrx_close(m_dev);
m_dev = 0;
}
}

Wyświetl plik

@ -0,0 +1,58 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef DEVICES_XTRX_DEVICEXTRXPARAM_H_
#define DEVICES_XTRX_DEVICEXTRXPARAM_H_
#include "xtrx_api.h"
struct DeviceXTRXParams
{
struct xtrx_dev *m_dev; //!< device handle
uint32_t m_nbRxChannels; //!< number of Rx channels
uint32_t m_nbTxChannels; //!< number of Tx channels
unsigned m_log2OvSRRx;
double m_sampleRate; //!< ADC/DAC sample rate
double m_rxFrequency; //!< Rx frequency
double m_txFrequency; //!< Tx frequency
DeviceXTRXParams() :
m_dev(0),
m_nbRxChannels(2),
m_nbTxChannels(2),
m_log2OvSRRx(0),
m_sampleRate(5e6),
m_rxFrequency(30e6),
m_txFrequency(30e6)
{
}
/**
* Opens and initialize the device and obtain information (# channels, ranges, ...)
*/
bool open(const char* deviceStr);
void close();
struct xtrx_dev *getDevice() { return m_dev; }
~DeviceXTRXParams()
{
}
};
#endif /* DEVICES_XTRX_DEVICEXTRXPARAM_H_ */

Wyświetl plik

@ -0,0 +1,83 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "devicextrxshared.h"
MESSAGE_CLASS_DEFINITION(DeviceXTRXShared::MsgReportBuddyChange, Message)
MESSAGE_CLASS_DEFINITION(DeviceXTRXShared::MsgReportClockSourceChange, Message)
MESSAGE_CLASS_DEFINITION(DeviceXTRXShared::MsgReportDeviceInfo, Message)
const float DeviceXTRXShared::m_sampleFifoLengthInSeconds = 0.25;
const int DeviceXTRXShared::m_sampleFifoMinSize = 48000; // 192kS/s knee
double DeviceXTRXShared::set_samplerate(double rate,
double master,
bool output)
{
if (output)
{
m_outputRate = rate;
if (master != 0.0) {
m_masterRate = master;
}
}
else
{
m_inputRate = rate;
if (master != 0.0) {
m_masterRate = master;
}
}
int res = xtrx_set_samplerate(m_deviceParams->getDevice(),
m_masterRate,
m_inputRate,
m_outputRate,
0,
0,
0,
0);
if (res) {
//fprintf(stderr, "Unable to set samplerate, error=%d\n", res);
return 0;
}
if (output) {
return m_outputRate;
}
return m_inputRate;
}
double DeviceXTRXShared::get_temperature()
{
uint64_t val = 0;
int res = xtrx_val_get(m_deviceParams->getDevice(),
XTRX_TRX, XTRX_CH_AB, XTRX_BOARD_TEMP, &val);
if (res) {
//fprintf(stderr, "Unable to set samplerate, error=%d\n", res);
return 0;
}
return val;
}

Wyświetl plik

@ -0,0 +1,165 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef DEVICES_LIMESDR_DEVICELIMESDRSHARED_H_
#define DEVICES_LIMESDR_DEVICELIMESDRSHARED_H_
#include <cstddef>
#include "devicextrxparam.h"
#include "util/message.h"
/**
* Structure shared by a buddy with other buddies
*/
class DeviceXTRXShared
{
public:
class MsgReportBuddyChange : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getDevSampleRate() const { return m_devSampleRate; }
unsigned getLog2HardDecimInterp() const { return m_log2HardDecimInterp; }
uint64_t getCenterFrequency() const { return m_centerFrequency; }
bool getRxElseTx() const { return m_rxElseTx; }
static MsgReportBuddyChange* create(
int devSampleRate,
unsigned log2HardDecimInterp,
uint64_t centerFrequency,
bool rxElseTx)
{
return new MsgReportBuddyChange(
devSampleRate,
log2HardDecimInterp,
centerFrequency,
rxElseTx);
}
private:
int m_devSampleRate; //!< device/host sample rate
unsigned m_log2HardDecimInterp; //!< log2 of hardware decimation or interpolation
uint64_t m_centerFrequency; //!< Center frequency
bool m_rxElseTx; //!< tells which side initiated the message
MsgReportBuddyChange(
int devSampleRate,
unsigned log2HardDecimInterp,
uint64_t centerFrequency,
bool rxElseTx) :
Message(),
m_devSampleRate(devSampleRate),
m_log2HardDecimInterp(log2HardDecimInterp),
m_centerFrequency(centerFrequency),
m_rxElseTx(rxElseTx)
{ }
};
class MsgReportClockSourceChange : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getExtClock() const { return m_extClock; }
uint32_t getExtClockFeq() const { return m_extClockFreq; }
static MsgReportClockSourceChange* create(
bool extClock,
uint32_t m_extClockFreq)
{
return new MsgReportClockSourceChange(
extClock,
m_extClockFreq);
}
private:
bool m_extClock; //!< True if external clock source
uint32_t m_extClockFreq; //!< Frequency (Hz) of external clock source
MsgReportClockSourceChange(
bool extClock,
uint32_t m_extClockFreq) :
Message(),
m_extClock(extClock),
m_extClockFreq(m_extClockFreq)
{ }
};
class MsgReportDeviceInfo : public Message {
MESSAGE_CLASS_DECLARATION
public:
float getTemperature() const { return m_temperature; }
static MsgReportDeviceInfo* create(float temperature)
{
return new MsgReportDeviceInfo(temperature);
}
private:
float m_temperature;
MsgReportDeviceInfo(float temperature) :
Message(),
m_temperature(temperature)
{ }
};
class ThreadInterface
{
public:
virtual void startWork() = 0;
virtual void stopWork() = 0;
virtual void setDeviceSampleRate(int sampleRate) = 0;
virtual bool isRunning() = 0;
};
DeviceXTRXParams *m_deviceParams; //!< unique hardware device parameters
xtrx_channel_t m_channel; //!< logical device channel number (-1 if none)
ThreadInterface *m_thread; //!< holds the thread address if started else 0
int m_ncoFrequency;
double m_centerFrequency;
uint32_t m_log2Soft;
bool m_threadWasRunning; //!< flag to know if thread needs to be resumed after suspend
double m_inputRate;
double m_outputRate;
double m_masterRate;
static const float m_sampleFifoLengthInSeconds;
static const int m_sampleFifoMinSize;
DeviceXTRXShared() :
m_deviceParams(0),
m_channel(XTRX_CH_AB),
m_thread(0),
m_ncoFrequency(0),
m_centerFrequency(0),
m_log2Soft(0),
m_threadWasRunning(false),
m_inputRate(0),
m_outputRate(0),
m_masterRate(0)
{}
~DeviceXTRXShared()
{}
double set_samplerate(double rate, double master, bool output);
double get_temperature();
};
#endif /* DEVICES_LIMESDR_DEVICELIMESDRSHARED_H_ */

Wyświetl plik

@ -54,6 +54,11 @@ if(LIBUSB_FOUND AND RX_SAMPLE_24BIT AND LIBPERSEUS_FOUND)
add_subdirectory(perseus)
endif(LIBUSB_FOUND AND RX_SAMPLE_24BIT AND LIBPERSEUS_FOUND)
find_package(LibXTRX)
if(LIBXTRX_FOUND)
add_subdirectory(xtrxinput)
endif(LIBXTRX_FOUND)
find_package(LibIIO)
if(LIBUSB_FOUND AND LIBIIO_FOUND)
add_subdirectory(plutosdrinput)
@ -97,6 +102,7 @@ if (BUILD_DEBIAN)
add_subdirectory(rtlsdr)
add_subdirectory(sdrdaemonsource)
add_subdirectory(sdrplay)
add_subdirectory(xtrxinput)
add_subdirectory(soapysdrinput)
endif (BUILD_DEBIAN)

Wyświetl plik

@ -0,0 +1,55 @@
project(xtrxinput)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(xtrxinput_SOURCES
xtrxinputgui.cpp
xtrxinput.cpp
xtrxinputplugin.cpp
xtrxinputsettings.cpp
xtrxinputthread.cpp
)
set(xtrxinput_HEADERS
xtrxinputgui.h
xtrxinput.h
xtrxinputplugin.h
xtrxinputsettings.h
xtrxinputthread.h
)
set(xtrxinput_FORMS
xtrxinputgui.ui
)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/devices
${LIBXTRX_INCLUDE_DIRS}
)
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED)
qt5_wrap_ui(xtrxinput_FORMS_HEADERS ${xtrxinput_FORMS})
add_library(inputxtrx SHARED
${xtrxinput_SOURCES}
${xtrxinput_HEADERS_MOC}
${xtrxinput_FORMS_HEADERS}
)
target_link_libraries(inputxtrx
${QT_LIBRARIES}
${LIBXTRX_LIBRARIES}
sdrbase
sdrgui
xtrxdevice
)
qt5_use_modules(inputxtrx Core Widgets)
install(TARGETS inputxtrx DESTINATION lib/plugins/samplesource)

Wyświetl plik

@ -0,0 +1,261 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_
#define PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_
#include <QString>
#include <stdint.h>
#include "dsp/devicesamplesource.h"
#include "xtrx/devicextrxshared.h"
#include "xtrxinputsettings.h"
class DeviceSourceAPI;
class XTRXInputThread;
struct DeviceXTRXParams;
class FileRecord;
class XTRXInput : public DeviceSampleSource
{
public:
class MsgConfigureXTRX : public Message {
MESSAGE_CLASS_DECLARATION
public:
const XTRXInputSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
static MsgConfigureXTRX* create(const XTRXInputSettings& settings, bool force)
{
return new MsgConfigureXTRX(settings, force);
}
private:
XTRXInputSettings m_settings;
bool m_force;
MsgConfigureXTRX(const XTRXInputSettings& 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 getSampleRate() const { return m_sampleRate; }
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 sampleRate,
float linkRate,
uint64_t timestamp
)
{
return new MsgReportStreamInfo(
success,
active,
fifoFilledCount,
fifoSize,
underrun,
overrun,
droppedPackets,
sampleRate,
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_sampleRate; //!< Sampling rate of the stream
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 sampleRate,
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_sampleRate(sampleRate),
m_linkRate(linkRate),
m_timestamp(timestamp)
{ }
};
class MsgStartStop : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getStartStop() const { return m_startStop; }
static MsgStartStop* create(bool startStop) {
return new MsgStartStop(startStop);
}
protected:
bool m_startStop;
MsgStartStop(bool startStop) :
Message(),
m_startStop(startStop)
{ }
};
class MsgFileRecord : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getStartStop() const { return m_startStop; }
static MsgFileRecord* create(bool startStop) {
return new MsgFileRecord(startStop);
}
protected:
bool m_startStop;
MsgFileRecord(bool startStop) :
Message(),
m_startStop(startStop)
{ }
};
XTRXInput(DeviceSourceAPI *deviceAPI);
virtual ~XTRXInput();
virtual void destroy();
virtual void init();
virtual bool start();
virtual void stop();
virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data);
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
virtual const QString& getDeviceDescription() const;
virtual int getSampleRate() const;
virtual quint64 getCenterFrequency() const;
virtual void setCenterFrequency(qint64 centerFrequency);
virtual bool handleMessage(const Message& message);
std::size_t getChannelIndex();
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;
uint32_t getHWLog2Decim() const;
void apply_gain_auto(double gain);
void apply_gain_lna(double gain);
void apply_gain_tia(double gain);
void apply_gain_pga(double gain);
private:
DeviceSourceAPI *m_deviceAPI;
QMutex m_mutex;
XTRXInputSettings m_settings;
XTRXInputThread* m_XTRXInputThread;
QString m_deviceDescription;
bool m_running;
DeviceXTRXShared m_deviceShared;
bool m_channelAcquired;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
bool openDevice();
void closeDevice();
bool acquireChannel();
void releaseChannel();
void suspendRxBuddies();
void resumeRxBuddies();
void suspendTxBuddies();
void resumeTxBuddies();
bool applySettings(const XTRXInputSettings& settings, bool force = false, bool forceNCOFrequency = false);
};
#endif /* PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_ */

Wyświetl plik

@ -0,0 +1,590 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "xtrxinputgui.h"
#include <QDebug>
#include <QMessageBox>
#include <algorithm>
#include "ui_xtrxinputgui.h"
#include "gui/colormapper.h"
#include "gui/glspectrum.h"
#include "dsp/dspengine.h"
#include "dsp/dspcommands.h"
#include "device/devicesourceapi.h"
#include "device/deviceuiset.h"
XTRXInputGUI::XTRXInputGUI(DeviceUISet *deviceUISet, QWidget* parent) :
QWidget(parent),
ui(new Ui::XTRXInputGUI),
m_deviceUISet(deviceUISet),
m_settings(),
m_sampleRate(0),
m_lastEngineState((DSPDeviceSourceEngine::State)-1),
m_doApplySettings(true),
m_forceSettings(true),
m_statusCounter(0),
m_deviceStatusCounter(0)
{
m_XTRXInput = (XTRXInput*) m_deviceUISet->m_deviceSourceAPI->getSampleSource();
ui->setupUi(this);
float minF, maxF, stepF;
m_XTRXInput->getLORange(minF, maxF, stepF);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
ui->centerFrequency->setValueRange(7, ((uint32_t) minF)/1000, ((uint32_t) maxF)/1000); // frequency dial is in kHz
m_XTRXInput->getSRRange(minF, maxF, stepF);
ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow));
ui->sampleRate->setValueRange(8, (uint32_t) minF, (uint32_t) maxF);
m_XTRXInput->getLPRange(minF, maxF, stepF);
ui->lpf->setColorMapper(ColorMapper(ColorMapper::GrayYellow));
ui->lpf->setValueRange(6, (minF/1000)+1, maxF/1000);
ui->lpFIR->setColorMapper(ColorMapper(ColorMapper::GrayYellow));
ui->lpFIR->setValueRange(5, 1U, 56000U);
ui->ncoFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
ui->channelNumberText->setText(tr("#%1").arg(m_XTRXInput->getChannelIndex()));
ui->hwDecimLabel->setText(QString::fromUtf8("H\u2193"));
ui->swDecimLabel->setText(QString::fromUtf8("S\u2193"));
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500);
displaySettings();
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
}
XTRXInputGUI::~XTRXInputGUI()
{
delete ui;
}
void XTRXInputGUI::destroy()
{
delete this;
}
void XTRXInputGUI::setName(const QString& name)
{
setObjectName(name);
}
QString XTRXInputGUI::getName() const
{
return objectName();
}
void XTRXInputGUI::resetToDefaults()
{
m_settings.resetToDefaults();
displaySettings();
sendSettings();
}
qint64 XTRXInputGUI::getCenterFrequency() const
{
return m_settings.m_centerFrequency;
}
void XTRXInputGUI::setCenterFrequency(qint64 centerFrequency)
{
m_settings.m_centerFrequency = centerFrequency;
displaySettings();
sendSettings();
}
QByteArray XTRXInputGUI::serialize() const
{
return m_settings.serialize();
}
bool XTRXInputGUI::deserialize(const QByteArray& data)
{
if (m_settings.deserialize(data))
{
displaySettings();
m_forceSettings = true;
sendSettings();
return true;
}
else
{
resetToDefaults();
return false;
}
}
bool XTRXInputGUI::handleMessage(const Message& message)
{
if (DeviceXTRXShared::MsgReportBuddyChange::match(message))
{
DeviceXTRXShared::MsgReportBuddyChange& report = (DeviceXTRXShared::MsgReportBuddyChange&) message;
m_settings.m_devSampleRate = report.getDevSampleRate();
m_settings.m_log2HardDecim = report.getLog2HardDecimInterp();
if (report.getRxElseTx()) {
m_settings.m_centerFrequency = report.getCenterFrequency();
}
blockApplySettings(true);
displaySettings();
blockApplySettings(false);
return true;
}
else if (DeviceXTRXShared::MsgReportClockSourceChange::match(message))
{
DeviceXTRXShared::MsgReportClockSourceChange& report = (DeviceXTRXShared::MsgReportClockSourceChange&) message;
m_settings.m_extClockFreq = report.getExtClockFeq();
m_settings.m_extClock = report.getExtClock();
blockApplySettings(true);
ui->extClock->setExternalClockFrequency(m_settings.m_extClockFreq);
ui->extClock->setExternalClockActive(m_settings.m_extClock);
blockApplySettings(false);
return true;
}
else if (XTRXInput::MsgReportStreamInfo::match(message))
{
XTRXInput::MsgReportStreamInfo& report = (XTRXInput::MsgReportStreamInfo&) message;
if (report.getSuccess())
{
if (report.getActive()) {
ui->streamStatusLabel->setStyleSheet("QLabel { background-color : green; }");
} else {
ui->streamStatusLabel->setStyleSheet("QLabel { background-color : blue; }");
}
ui->streamLinkRateText->setText(tr("%1 MB/s").arg(QString::number(report.getLinkRate() / 1000000.0f, 'f', 3)));
if (report.getUnderrun() > 0) {
ui->underrunLabel->setStyleSheet("QLabel { background-color : red; }");
} else {
ui->underrunLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }");
}
if (report.getOverrun() > 0) {
ui->overrunLabel->setStyleSheet("QLabel { background-color : red; }");
} else {
ui->overrunLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }");
}
if (report.getDroppedPackets() > 0) {
ui->droppedLabel->setStyleSheet("QLabel { background-color : red; }");
} else {
ui->droppedLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }");
}
ui->fifoBar->setMaximum(report.getFifoSize());
ui->fifoBar->setValue(report.getFifoFilledCount());
ui->fifoBar->setToolTip(tr("FIFO fill %1/%2 samples").arg(QString::number(report.getFifoFilledCount())).arg(QString::number(report.getFifoSize())));
}
else
{
ui->streamStatusLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }");
}
return true;
}
else if (DeviceXTRXShared::MsgReportDeviceInfo::match(message))
{
DeviceXTRXShared::MsgReportDeviceInfo& report = (DeviceXTRXShared::MsgReportDeviceInfo&) message;
ui->temperatureText->setText(tr("%1C").arg(QString::number(report.getTemperature(), 'f', 0)));
return true;
}
else if (XTRXInput::MsgStartStop::match(message))
{
XTRXInput::MsgStartStop& notif = (XTRXInput::MsgStartStop&) message;
blockApplySettings(true);
ui->startStop->setChecked(notif.getStartStop());
blockApplySettings(false);
return true;
}
return false;
}
void XTRXInputGUI::handleInputMessages()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
{
if (DSPSignalNotification::match(*message))
{
DSPSignalNotification* notif = (DSPSignalNotification*) message;
m_sampleRate = notif->getSampleRate();
m_deviceCenterFrequency = notif->getCenterFrequency();
qDebug("XTRXInputGUI::handleInputMessages: DSPSignalNotification: SampleRate: %d, CenterFrequency: %llu", notif->getSampleRate(), notif->getCenterFrequency());
updateSampleRateAndFrequency();
delete message;
}
else
{
if (handleMessage(*message)) {
delete message;
}
}
}
}
void XTRXInputGUI::updateADCRate()
{
uint32_t adcRate = m_settings.m_devSampleRate * (1<<m_settings.m_log2HardDecim);
if (adcRate < 100000000) {
ui->adcRateLabel->setText(tr("%1k").arg(QString::number(adcRate / 1000.0f, 'g', 5)));
} else {
ui->adcRateLabel->setText(tr("%1M").arg(QString::number(adcRate / 1000000.0f, 'g', 5)));
}
}
void XTRXInputGUI::updateSampleRateAndFrequency()
{
m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate);
m_deviceUISet->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency);
ui->deviceRateLabel->setText(tr("%1k").arg(QString::number(m_sampleRate / 1000.0f, 'g', 5)));
}
void XTRXInputGUI::displaySettings()
{
ui->extClock->setExternalClockFrequency(m_settings.m_extClockFreq);
ui->extClock->setExternalClockActive(m_settings.m_extClock);
ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
ui->sampleRate->setValue(m_settings.m_devSampleRate);
ui->dcOffset->setChecked(m_settings.m_dcBlock);
ui->iqImbalance->setChecked(m_settings.m_iqCorrection);
ui->hwDecim->setCurrentIndex(m_settings.m_log2HardDecim);
ui->swDecim->setCurrentIndex(m_settings.m_log2SoftDecim);
updateADCRate();
ui->lpf->setValue(m_settings.m_lpfBW / 1000);
ui->lpFIREnable->setChecked(m_settings.m_lpfFIREnable);
ui->lpFIR->setValue(m_settings.m_lpfFIRBW / 1000);
ui->gain->setValue(m_settings.m_gain);
ui->gainText->setText(tr("%1").arg(m_settings.m_gain));
ui->antenna->setCurrentIndex((int) m_settings.m_antennaPath);
ui->gainMode->setCurrentIndex((int) m_settings.m_gainMode);
ui->lnaGain->setValue(m_settings.m_lnaGain);
ui->tiaGain->setCurrentIndex(m_settings.m_tiaGain - 1);
ui->pgaGain->setValue(m_settings.m_pgaGain);
if (m_settings.m_gainMode == XTRXInputSettings::GAIN_AUTO)
{
ui->gain->setEnabled(true);
ui->lnaGain->setEnabled(false);
ui->tiaGain->setEnabled(false);
ui->pgaGain->setEnabled(false);
}
else
{
ui->gain->setEnabled(false);
ui->lnaGain->setEnabled(true);
ui->tiaGain->setEnabled(true);
ui->pgaGain->setEnabled(true);
}
setNCODisplay();
ui->ncoEnable->setChecked(m_settings.m_ncoEnable);
}
void XTRXInputGUI::setNCODisplay()
{
int ncoHalfRange = (m_settings.m_devSampleRate * (1<<(m_settings.m_log2HardDecim)))/2;
int lowBoundary = std::max(0, (int) m_settings.m_centerFrequency - ncoHalfRange);
ui->ncoFrequency->setValueRange(7,
lowBoundary/1000,
(m_settings.m_centerFrequency + ncoHalfRange)/1000); // frequency dial is in kHz
ui->ncoFrequency->setValue((m_settings.m_centerFrequency + m_settings.m_ncoFrequency)/1000);
}
void XTRXInputGUI::sendSettings()
{
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
}
void XTRXInputGUI::updateHardware()
{
if (m_doApplySettings)
{
qDebug() << "XTRXInputGUI::updateHardware";
XTRXInput::MsgConfigureXTRX* message = XTRXInput::MsgConfigureXTRX::create(m_settings, m_forceSettings);
m_XTRXInput->getInputMessageQueue()->push(message);
m_forceSettings = false;
m_updateTimer.stop();
}
}
void XTRXInputGUI::updateStatus()
{
int state = m_deviceUISet->m_deviceSourceAPI->state();
if(m_lastEngineState != state)
{
switch(state)
{
case DSPDeviceSourceEngine::StNotStarted:
ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break;
case DSPDeviceSourceEngine::StIdle:
ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
break;
case DSPDeviceSourceEngine::StRunning:
ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
break;
case DSPDeviceSourceEngine::StError:
ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceSourceAPI->errorMessage());
break;
default:
break;
}
m_lastEngineState = state;
}
if (m_statusCounter < 1)
{
m_statusCounter++;
}
else
{
XTRXInput::MsgGetStreamInfo* message = XTRXInput::MsgGetStreamInfo::create();
m_XTRXInput->getInputMessageQueue()->push(message);
m_statusCounter = 0;
}
if (m_deviceStatusCounter < 10)
{
m_deviceStatusCounter++;
}
else
{
if (m_deviceUISet->m_deviceSourceAPI->isBuddyLeader())
{
XTRXInput::MsgGetDeviceInfo* message = XTRXInput::MsgGetDeviceInfo::create();
m_XTRXInput->getInputMessageQueue()->push(message);
}
m_deviceStatusCounter = 0;
}
}
void XTRXInputGUI::blockApplySettings(bool block)
{
m_doApplySettings = !block;
}
void XTRXInputGUI::on_startStop_toggled(bool checked)
{
if (m_doApplySettings)
{
XTRXInput::MsgStartStop *message = XTRXInput::MsgStartStop::create(checked);
m_XTRXInput->getInputMessageQueue()->push(message);
}
}
void XTRXInputGUI::on_record_toggled(bool checked)
{
if (checked) {
ui->record->setStyleSheet("QToolButton { background-color : red; }");
} else {
ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
}
XTRXInput::MsgFileRecord* message = XTRXInput::MsgFileRecord::create(checked);
m_XTRXInput->getInputMessageQueue()->push(message);
}
void XTRXInputGUI::on_centerFrequency_changed(quint64 value)
{
m_settings.m_centerFrequency = value * 1000;
setNCODisplay();
sendSettings();
}
void XTRXInputGUI::on_ncoFrequency_changed(quint64 value)
{
m_settings.m_ncoFrequency = (int64_t) value - (int64_t) m_settings.m_centerFrequency/1000;
m_settings.m_ncoFrequency *= 1000;
sendSettings();
}
void XTRXInputGUI::on_ncoEnable_toggled(bool checked)
{
m_settings.m_ncoEnable = checked;
sendSettings();
}
void XTRXInputGUI::on_ncoReset_clicked(bool checked __attribute__((unused)))
{
m_settings.m_ncoFrequency = 0;
ui->ncoFrequency->setValue(m_settings.m_centerFrequency/1000);
sendSettings();
}
void XTRXInputGUI::on_dcOffset_toggled(bool checked)
{
m_settings.m_dcBlock = checked;
sendSettings();
}
void XTRXInputGUI::on_iqImbalance_toggled(bool checked)
{
m_settings.m_iqCorrection = checked;
sendSettings();
}
void XTRXInputGUI::on_sampleRate_changed(quint64 value)
{
m_settings.m_devSampleRate = value;
updateADCRate();
setNCODisplay();
sendSettings();}
void XTRXInputGUI::on_hwDecim_currentIndexChanged(int index)
{
if ((index <0) || (index > 5))
return;
m_settings.m_log2HardDecim = index;
updateADCRate();
setNCODisplay();
sendSettings();
}
void XTRXInputGUI::on_swDecim_currentIndexChanged(int index)
{
if ((index <0) || (index > 6))
return;
m_settings.m_log2SoftDecim = index;
sendSettings();
}
void XTRXInputGUI::on_lpf_changed(quint64 value)
{
m_settings.m_lpfBW = value * 1000;
sendSettings();
}
void XTRXInputGUI::on_lpFIREnable_toggled(bool checked)
{
m_settings.m_lpfFIREnable = checked;
sendSettings();
}
void XTRXInputGUI::on_lpFIR_changed(quint64 value)
{
m_settings.m_lpfFIRBW = value * 1000;
if (m_settings.m_lpfFIREnable) { // do not send the update if the FIR is disabled
sendSettings();
}
}
void XTRXInputGUI::on_gainMode_currentIndexChanged(int index)
{
m_settings.m_gainMode = (XTRXInputSettings::GainMode) index;
if (index == 0)
{
ui->gain->setEnabled(true);
ui->lnaGain->setEnabled(false);
ui->tiaGain->setEnabled(false);
ui->pgaGain->setEnabled(false);
}
else
{
ui->gain->setEnabled(false);
ui->lnaGain->setEnabled(true);
ui->tiaGain->setEnabled(true);
ui->pgaGain->setEnabled(true);
}
sendSettings();
}
void XTRXInputGUI::on_gain_valueChanged(int value)
{
m_settings.m_gain = value;
ui->gainText->setText(tr("%1").arg(m_settings.m_gain));
sendSettings();
}
void XTRXInputGUI::on_lnaGain_valueChanged(int value)
{
m_settings.m_lnaGain = value;
ui->lnaGainText->setText(tr("%1").arg(m_settings.m_lnaGain));
sendSettings();
}
void XTRXInputGUI::on_tiaGain_currentIndexChanged(int index)
{
m_settings.m_tiaGain = index + 1;
sendSettings();
}
void XTRXInputGUI::on_pgaGain_valueChanged(int value)
{
m_settings.m_pgaGain = value;
ui->pgaGainText->setText(tr("%1").arg(m_settings.m_pgaGain));
sendSettings();
}
void XTRXInputGUI::on_antenna_currentIndexChanged(int index)
{
m_settings.m_antennaPath = (xtrx_antenna_t) index;
sendSettings();
}
void XTRXInputGUI::on_extClock_clicked()
{
m_settings.m_extClock = ui->extClock->getExternalClockActive();
m_settings.m_extClockFreq = ui->extClock->getExternalClockFrequency();
qDebug("XTRXInputGUI::on_extClock_clicked: %u Hz %s", m_settings.m_extClockFreq, m_settings.m_extClock ? "on" : "off");
sendSettings();
}
void XTRXInputGUI::on_pwrmode_currentIndexChanged(int index)
{
m_settings.m_pwrmode = index;
sendSettings();
}

Wyświetl plik

@ -0,0 +1,107 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTGUI_H_
#define PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTGUI_H_
#include <plugin/plugininstancegui.h>
#include <QTimer>
#include <QWidget>
#include "util/messagequeue.h"
#include "xtrxinput.h"
class DeviceUISet;
namespace Ui {
class XTRXInputGUI;
}
class XTRXInputGUI : public QWidget, public PluginInstanceGUI {
Q_OBJECT
public:
explicit XTRXInputGUI(DeviceUISet *deviceUISet, QWidget* parent = 0);
virtual ~XTRXInputGUI();
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::XTRXInputGUI* ui;
DeviceUISet* m_deviceUISet;
XTRXInput* m_XTRXInput; //!< Same object as above but gives easy access to XTRXInput methods and attributes that are used intensively
XTRXInputSettings m_settings;
QTimer m_updateTimer;
QTimer m_statusTimer;
int m_sampleRate;
quint64 m_deviceCenterFrequency; //!< Center frequency in device
int m_lastEngineState;
bool m_doApplySettings;
bool m_forceSettings;
int m_statusCounter;
int m_deviceStatusCounter;
MessageQueue m_inputMessageQueue;
void displaySettings();
void setNCODisplay();
void sendSettings();
void updateSampleRateAndFrequency();
void updateADCRate();
void blockApplySettings(bool block);
private slots:
void handleInputMessages();
void on_startStop_toggled(bool checked);
void on_record_toggled(bool checked);
void on_centerFrequency_changed(quint64 value);
void on_ncoFrequency_changed(quint64 value);
void on_ncoEnable_toggled(bool checked);
void on_ncoReset_clicked(bool checked);
void on_dcOffset_toggled(bool checked);
void on_iqImbalance_toggled(bool checked);
void on_sampleRate_changed(quint64 value);
void on_hwDecim_currentIndexChanged(int index);
void on_swDecim_currentIndexChanged(int index);
void on_lpf_changed(quint64 value);
void on_lpFIREnable_toggled(bool checked);
void on_lpFIR_changed(quint64 value);
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 on_extClock_clicked();
void on_pwrmode_currentIndexChanged(int index);
void updateHardware();
void updateStatus();
};
#endif /* PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTGUI_H_ */

Wyświetl plik

@ -0,0 +1,145 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "xtrxinputplugin.h"
#include <QtPlugin>
#include <regex>
#include <string>
#include "xtrx_api.h"
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "device/devicesourceapi.h"
#ifdef SERVER_MODE
#include "xtrxinput.h"
#else
#include "xtrxinputgui.h"
#endif
const PluginDescriptor XTRXInputPlugin::m_pluginDescriptor = {
QString("XTRX Input"),
QString("0.0.1"),
QString("(c) Sergey Kostanbaev, Fairwaves"),
QString("https://github.com/xtrx-sdr/sdrangel"),
true,
QString("https://github.com/xtrx-sdr/sdrangel")
};
const QString XTRXInputPlugin::m_hardwareID = "XTRX";
const QString XTRXInputPlugin::m_deviceTypeID = XTRX_DEVICE_TYPE_ID;
XTRXInputPlugin::XTRXInputPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& XTRXInputPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void XTRXInputPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleSource(m_deviceTypeID, this);
}
PluginInterface::SamplingDevices XTRXInputPlugin::enumSampleSources()
{
SamplingDevices result;
xtrx_device_info_t devs[32];
int res = xtrx_discovery(devs, 32);
int i;
for (i = 0; i < res; i++) {
DeviceXTRXParams XTRXParams;
for (unsigned int j = 0; j < XTRXParams.m_nbRxChannels; j++)
{
qDebug("XTRXInputPlugin::enumSampleSources: device #%d channel %u: %s", i, j, devs[i].uniqname);
QString displayedName(QString("XTRX[%1:%2] %3").arg(i).arg(j).arg(devs[i].uniqname));
result.append(SamplingDevice(displayedName,
m_hardwareID,
m_deviceTypeID,
QString(devs[i].uniqname),
i,
PluginInterface::SamplingDevice::PhysicalDevice,
true,
XTRXParams.m_nbRxChannels,
j));
}
}
return result;
}
#ifdef SERVER_MODE
PluginInstanceGUI* XTRXInputPlugin::createSampleSourcePluginInstanceGUI(
const QString& sourceId __attribute((unused)),
QWidget **widget __attribute((unused)),
DeviceUISet *deviceUISet __attribute((unused)))
{
return 0;
}
#else
PluginInstanceGUI* XTRXInputPlugin::createSampleSourcePluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
{
if(sourceId == m_deviceTypeID)
{
XTRXInputGUI* gui = new XTRXInputGUI(deviceUISet);
*widget = gui;
return gui;
}
else
{
return 0;
}
}
#endif
bool XTRXInputPlugin::findSerial(const char *lmsInfoStr, std::string& serial)
{
std::regex serial_reg("serial=([0-9,A-F]+)");
std::string input(lmsInfoStr);
std::smatch result;
std::regex_search(input, result, serial_reg);
if (result[1].str().length()>0)
{
serial = result[1].str();
return true;
}
else
{
return false;
}
}
DeviceSampleSource *XTRXInputPlugin::createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI)
{
if (sourceId == m_deviceTypeID)
{
XTRXInput* input = new XTRXInput(deviceAPI);
return input;
}
else
{
return 0;
}
}

Wyświetl plik

@ -0,0 +1,55 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTPLUGIN_H_
#define PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTPLUGIN_H_
#include <QObject>
#include "plugin/plugininterface.h"
class PluginAPI;
#define XTRX_DEVICE_TYPE_ID "sdrangel.samplesource.xtrx"
class XTRXInputPlugin : public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID XTRX_DEVICE_TYPE_ID)
public:
explicit XTRXInputPlugin(QObject* parent = 0);
const PluginDescriptor& getPluginDescriptor() const;
void initPlugin(PluginAPI* pluginAPI);
virtual SamplingDevices enumSampleSources();
virtual PluginInstanceGUI* createSampleSourcePluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet);
virtual DeviceSampleSource* createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI);
static const QString m_hardwareID;
static const QString m_deviceTypeID;
private:
static const PluginDescriptor m_pluginDescriptor;
static bool findSerial(const char *lmsInfoStr, std::string& serial);
};
#endif /* PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTPLUGIN_H_ */

Wyświetl plik

@ -0,0 +1,120 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "util/simpleserializer.h"
#include "xtrxinputsettings.h"
XTRXInputSettings::XTRXInputSettings()
{
resetToDefaults();
}
void XTRXInputSettings::resetToDefaults()
{
m_centerFrequency = 435000*1000;
m_devSampleRate = 5e6;
m_log2HardDecim = 1;
m_dcBlock = false;
m_iqCorrection = false;
m_log2SoftDecim = 0;
m_lpfBW = 4.5e6f;
m_lpfFIREnable = false;
m_lpfFIRBW = 2.5e6f;
m_gain = 50;
m_ncoEnable = false;
m_ncoFrequency = 0;
m_antennaPath = XTRX_RX_L;
m_gainMode = GAIN_AUTO;
m_lnaGain = 15;
m_tiaGain = 2;
m_pgaGain = 16;
m_extClock = false;
m_extClockFreq = 0; // Auto
m_pwrmode = 1;
}
QByteArray XTRXInputSettings::serialize() const
{
SimpleSerializer s(1);
s.writeDouble(1, m_devSampleRate);
s.writeU32(2, m_log2HardDecim);
s.writeBool(3, m_dcBlock);
s.writeBool(4, m_iqCorrection);
s.writeU32(5, m_log2SoftDecim);
s.writeFloat(7, m_lpfBW);
s.writeBool(8, m_lpfFIREnable);
s.writeFloat(9, m_lpfFIRBW);
s.writeU32(10, m_gain);
s.writeBool(11, m_ncoEnable);
s.writeS32(12, m_ncoFrequency);
s.writeS32(13, (int) m_antennaPath);
s.writeS32(14, (int) m_gainMode);
s.writeU32(15, m_lnaGain);
s.writeU32(16, m_tiaGain);
s.writeU32(17, m_pgaGain);
s.writeBool(18, m_extClock);
s.writeU32(19, m_extClockFreq);
s.writeU32(20, m_pwrmode);
return s.final();
}
bool XTRXInputSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
int intval;
d.readDouble(1, &m_devSampleRate, 5e6);
d.readU32(2, &m_log2HardDecim, 2);
d.readBool(3, &m_dcBlock, false);
d.readBool(4, &m_iqCorrection, false);
d.readU32(5, &m_log2SoftDecim, 0);
d.readFloat(7, &m_lpfBW, 1.5e6);
d.readBool(8, &m_lpfFIREnable, false);
d.readFloat(9, &m_lpfFIRBW, 1.5e6);
d.readU32(10, &m_gain, 50);
d.readBool(11, &m_ncoEnable, false);
d.readS32(12, &m_ncoFrequency, 0);
d.readS32(13, &intval, 0);
m_antennaPath = (xtrx_antenna_t) intval;
d.readS32(14, &intval, 0);
m_gainMode = (GainMode) intval;
d.readU32(15, &m_lnaGain, 15);
d.readU32(16, &m_tiaGain, 2);
d.readU32(17, &m_pgaGain, 16);
d.readBool(18, &m_extClock, false);
d.readU32(19, &m_extClockFreq, 0);
d.readU32(20, &m_pwrmode, 2);
return true;
}
else
{
resetToDefaults();
return false;
}
}

Wyświetl plik

@ -0,0 +1,71 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTSETTINGS_H_
#define PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTSETTINGS_H_
#include <stdint.h>
#include <QByteArray>
#include "xtrx_api.h"
/**
* These are the settings individual to each hardware channel or software Rx chain
* Plus the settings to be saved in the presets
*/
struct XTRXInputSettings
{
typedef enum {
FC_POS_INFRA = 0,
FC_POS_SUPRA,
FC_POS_CENTER
} fcPos_t;
typedef enum {
GAIN_AUTO,
GAIN_MANUAL
} GainMode;
// global settings to be saved
uint64_t m_centerFrequency;
double m_devSampleRate;
uint32_t m_log2HardDecim;
// channel settings
bool m_dcBlock;
bool m_iqCorrection;
uint32_t m_log2SoftDecim;
float m_lpfBW; //!< LMS amalog lowpass filter bandwidth (Hz)
bool m_lpfFIREnable; //!< Enable LMS digital lowpass FIR filters
float m_lpfFIRBW; //!< LMS digital lowpass FIR filters bandwidth (Hz)
uint32_t m_gain; //!< Optimally distributed gain (dB)
bool m_ncoEnable; //!< Enable TSP NCO and mixing
int m_ncoFrequency; //!< Actual NCO frequency (the resulting frequency with mixing is displayed)
xtrx_antenna_t m_antennaPath;
GainMode m_gainMode; //!< Gain mode: auto or manual
uint32_t m_lnaGain; //!< Manual LAN gain
uint32_t m_tiaGain; //!< Manual TIA gain
uint32_t m_pgaGain; //!< Manual PGA gain
bool m_extClock; //!< True if external clock source
uint32_t m_extClockFreq; //!< Frequency (Hz) of external clock source
uint32_t m_pwrmode;
XTRXInputSettings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
#endif /* PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTSETTINGS_H_ */

Wyświetl plik

@ -0,0 +1,229 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <errno.h>
#include "xtrxinputsettings.h"
#include "xtrxinputthread.h"
XTRXInputThread::XTRXInputThread(DeviceXTRXShared* shared,
SampleSinkFifo* sampleFifo,
QObject* parent) :
QThread(parent),
m_running(false),
m_convertBuffer(XTRX_BLOCKSIZE),
m_sampleFifo(sampleFifo),
m_log2Decim(0),
m_fcPos(XTRXInputSettings::FC_POS_CENTER),
m_shared(shared)
{
}
XTRXInputThread::~XTRXInputThread()
{
stopWork();
}
void XTRXInputThread::startWork()
{
if (m_running) return; // return if running already
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.flags |= XTRX_RSP_SISO_MODE;
params.rx_stream_start = 2*8192;
// TODO: replace this
if (m_shared->m_channel == XTRX_CH_B)
params.rx.flags |= XTRX_RSP_SWAP_AB;
int res = xtrx_run_ex(m_shared->m_deviceParams->getDevice(),
&params);
if (res != 0) {
qCritical("XTRXInputThread::startWork: could not start stream err:%d", res);
} else {
usleep(50000);
qDebug("XTRXInputThread::startWork: stream started");
}
m_startWaitMutex.lock();
start();
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();
}
void XTRXInputThread::stopWork()
{
if (!m_running) return; // return if not running
m_running = false;
int res = xtrx_stop(m_shared->m_deviceParams->getDevice(), XTRX_RX);
wait();
if (res != 0) {
qCritical("XTRXInputThread::stopWork: could not stop stream");
} else {
usleep(50000);
qDebug("XTRXInputThread::stopWork: stream stopped");
}
}
void XTRXInputThread::setLog2Decimation(unsigned int log2_decim)
{
m_log2Decim = log2_decim;
}
void XTRXInputThread::setFcPos(int fcPos)
{
m_fcPos = fcPos;
}
void XTRXInputThread::run()
{
int res;
m_running = true;
m_startWaiter.wakeAll();
void* buffers[1] = { m_buf };
xtrx_recv_ex_info_t nfo;
nfo.samples = XTRX_BLOCKSIZE;
nfo.buffer_count = 1;
nfo.buffers = (void* const*)buffers;
nfo.flags = RCVEX_DONT_INSER_ZEROS | RCVEX_DROP_OLD_ON_OVERFLOW;
while (m_running)
{
//if ((res = LMS_RecvStream(m_stream, (void *) m_buf, XTRX_BLOCKSIZE, &metadata, 1000)) < 0)
res = xtrx_recv_sync_ex(m_shared->m_deviceParams->getDevice(),
&nfo);
if (res < 0)
{
qCritical("XTRXInputThread::run read error: %d", res);
break;
}
callback(m_buf, 2 * nfo.out_samples);
}
m_running = false;
}
// Decimate according to specified log2 (ex: log2=4 => decim=16)
void XTRXInputThread::callback(const qint16* buf, qint32 len)
{
SampleVector::iterator it = m_convertBuffer.begin();
if (m_log2Decim == 0)
{
m_decimators.decimate1(&it, buf, len);
}
else
{
if (m_fcPos == 0) // Infra
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_inf(&it, buf, len);
break;
case 2:
m_decimators.decimate4_inf(&it, buf, len);
break;
case 3:
m_decimators.decimate8_inf(&it, buf, len);
break;
case 4:
m_decimators.decimate16_inf(&it, buf, len);
break;
case 5:
m_decimators.decimate32_inf(&it, buf, len);
break;
case 6:
m_decimators.decimate64_inf(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 1) // Supra
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_sup(&it, buf, len);
break;
case 2:
m_decimators.decimate4_sup(&it, buf, len);
break;
case 3:
m_decimators.decimate8_sup(&it, buf, len);
break;
case 4:
m_decimators.decimate16_sup(&it, buf, len);
break;
case 5:
m_decimators.decimate32_sup(&it, buf, len);
break;
case 6:
m_decimators.decimate64_sup(&it, buf, len);
break;
default:
break;
}
}
else if (m_fcPos == 2) // Center
{
switch (m_log2Decim)
{
case 1:
m_decimators.decimate2_cen(&it, buf, len);
break;
case 2:
m_decimators.decimate4_cen(&it, buf, len);
break;
case 3:
m_decimators.decimate8_cen(&it, buf, len);
break;
case 4:
m_decimators.decimate16_cen(&it, buf, len);
break;
case 5:
m_decimators.decimate32_cen(&it, buf, len);
break;
case 6:
m_decimators.decimate64_cen(&it, buf, len);
break;
default:
break;
}
}
}
m_sampleFifo->write(m_convertBuffer.begin(), it);
}

Wyświetl plik

@ -0,0 +1,70 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTTHREAD_H_
#define PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTTHREAD_H_
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include "xtrx_api.h"
#include "dsp/samplesinkfifo.h"
#include "dsp/decimators.h"
#include "xtrx/devicextrxshared.h"
#define XTRX_BLOCKSIZE (1<<13) //complex samples per buffer
class XTRXInputThread : public QThread, public DeviceXTRXShared::ThreadInterface
{
Q_OBJECT
public:
XTRXInputThread(DeviceXTRXShared* shared, SampleSinkFifo* sampleFifo, QObject* parent = 0);
~XTRXInputThread();
virtual void startWork();
virtual void stopWork();
virtual void setDeviceSampleRate(int sampleRate __attribute__((unused))) {}
virtual bool isRunning() { return m_running; }
void setLog2Decimation(unsigned int log2_decim);
void setFcPos(int fcPos);
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
qint16 m_buf[2*XTRX_BLOCKSIZE]; //must hold I+Q values of each sample hence 2xcomplex size
SampleVector m_convertBuffer;
SampleSinkFifo* m_sampleFifo;
unsigned int m_log2Decim; // soft decimation
int m_fcPos;
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12> m_decimators;
DeviceXTRXShared* m_shared;
void run();
void callback(const qint16* buf, qint32 len);
};
#endif /* PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTTHREAD_H_ */

Wyświetl plik

@ -54,6 +54,11 @@ if(LIBUSB_FOUND AND RX_SAMPLE_24BIT AND LIBPERSEUS_FOUND)
add_subdirectory(perseus)
endif(LIBUSB_FOUND AND RX_SAMPLE_24BIT AND LIBPERSEUS_FOUND)
find_package(LibXTRX)
if(LIBXTRX_FOUND)
add_subdirectory(xtrxinput)
endif(LIBXTRX_FOUND)
find_package(LibIIO)
if(LIBUSB_FOUND AND LIBIIO_FOUND)
add_subdirectory(plutosdrinput)
@ -97,6 +102,7 @@ if (BUILD_DEBIAN)
add_subdirectory(rtlsdr)
add_subdirectory(sdrdaemonsource)
add_subdirectory(sdrplay)
add_subdirectory(xtrxinput)
endif (BUILD_DEBIAN)
add_subdirectory(filesource)

Wyświetl plik

@ -0,0 +1,46 @@
project(xtrxinput)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(PLUGIN_PREFIX "../../../plugins/samplesource/xtrxinput")
set(xtrxinput_SOURCES
${PLUGIN_PREFIX}/xtrxinput.cpp
${PLUGIN_PREFIX}/xtrxinputplugin.cpp
${PLUGIN_PREFIX}/xtrxinputsettings.cpp
${PLUGIN_PREFIX}/xtrxinputthread.cpp
)
set(xtrxinput_HEADERS
${PLUGIN_PREFIX}/xtrxinput.h
${PLUGIN_PREFIX}/xtrxinputplugin.h
${PLUGIN_PREFIX}/xtrxinputsettings.h
${PLUGIN_PREFIX}/xtrxinputthread.h
)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/devices
${LIBXTRX_INCLUDE_DIRS}
)
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED)
add_library(inputxtrxsrv SHARED
${xtrxinput_SOURCES}
${xtrxinput_HEADERS_MOC}
)
target_link_libraries(inputxtrxsrv
${QT_LIBRARIES}
${LIBXTRX_LIBRARIES}
sdrbase
xtrxdevice
)
qt5_use_modules(inputxtrxsrv Core)
install(TARGETS inputxtrxsrv DESTINATION lib/pluginssrv/samplesource)