Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
stef committed Aug 3, 2019
2 parents a00e73a + b3c491d commit add3d77
Show file tree
Hide file tree
Showing 17 changed files with 1,138 additions and 279 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ find_package(libxtrxll REQUIRED)

include_directories(${LIBXTRXDSP_INCLUDE_DIRS})
include_directories(${LIBXTRXLL_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})


if(LMS_FE_OLD)
Expand All @@ -92,7 +93,7 @@ else()
include_directories(${LIBLMS7COMPACT_INCLUDE_DIRS})

add_definitions(-DHAVE_LMS_NFE)
set(LMS_FE_FILENAME "xtrx_fe_nlms7.c" "xtrx_fe_octorx0.c")
set(LMS_FE_FILENAME "xtrx_fe_nlms7.c" "xtrx_fe_octorx0.c" "xtrx_fe_octocal0.c" "octo/adf4355.c")
set(LMS_FE_LIBRARY ${LIBLMS7COMPACT_LIBRARIES})
endif()

Expand Down Expand Up @@ -153,7 +154,8 @@ set(CPACK_PACKAGE_CONTACT "http://fairwaves.co/wp/contact-us/")
set(CPACK_PACKAGE_VERSION ${LIBVER}-${MAINT_VERSION})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.17), libxtrxll (>= 0.0.1), libxtrxdsp (>= 0.0.1), liblms7002m (>= 0.0.1)")
if(ENABLE_SOAPY)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, soapysdr (>= 0.5.2)")
# TODO: need a dependency for correct soapy version
# set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, soapysdr (>= 0.5.2)")
endif(ENABLE_SOAPY)


Expand Down
5 changes: 3 additions & 2 deletions examples/xtrx_fft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ set(mainwindow_SRCS

include_directories(${LIBXTRX_INCLUDE_DIRS})

add_executable(mainwindow ${mainwindow_SRCS})
target_link_libraries(mainwindow Qt5::Widgets Qt5::PrintSupport ${QCustomPlot_LIBRARIES} ${LIBXTRX_LIBRARIES})
add_executable(xtrx_fft ${mainwindow_SRCS})
target_link_libraries(xtrx_fft Qt5::Widgets Qt5::PrintSupport ${QCustomPlot_LIBRARIES} ${LIBXTRX_LIBRARIES})
install(TARGETS xtrx_fft DESTINATION ${XTRX_UTILS_DIR})
133 changes: 100 additions & 33 deletions examples/xtrx_fft/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,40 @@

#include <QTimer>
#include <QDebug>
#include <unistd.h>

#include "rxthread.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
x(512),
y1(512),
y2(512),
y3(512),
y4(512),
z1(512),
z2(512),
z3(512),
z4(512),

ui(new Ui::MainWindow)
{
ui->setupUi(this);
dev = NULL;

QCustomPlot* customPlot = ui->widget;
// add two new graphs and set their look:
customPlot->addGraph();
customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph

customPlot->addGraph();
customPlot->graph(1)->setPen(QPen(Qt::red)); // line color blue for first graph
Qt::GlobalColor clrs[8] = {
Qt::blue, Qt::red, Qt::green, Qt::lightGray,
Qt::cyan, Qt::magenta,Qt::yellow, Qt::darkGray,
};

Qt::GlobalColor mclrs[8] = {
Qt::darkBlue, Qt::darkRed, Qt::darkGreen, Qt::gray,
Qt::darkCyan, Qt::darkMagenta,Qt::darkYellow, Qt::black,
};

// add two new graphs and set their look:
for (int i = 0; i < MAX_DEVS; ++i) {
customPlot->addGraph();
customPlot->graph(i)->setPen(QPen(clrs[i])); // line color blue for first graph
}

//customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
for (int i = 0; i < MAX_DEVS; ++i) {
customPlot->addGraph();
customPlot->graph(MAX_DEVS + i)->setPen(QPen(mclrs[i])); // line color blue for first graph
}

connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
Expand All @@ -73,6 +78,8 @@ MainWindow::MainWindow(QWidget *parent) :
connect(rx_thread, SIGNAL(newRxData(int)), this, SLOT(redraw(int)));

update_devs();

xtrx_log_setlevel(3, "DEF");
}

void MainWindow::update_devs()
Expand All @@ -99,13 +106,15 @@ void MainWindow::redraw(int idx)
else if (idx < 0)
idx = 0;

QVector<double>* py[] = {&y1, &y2, &y3, &y4};
QVector<double>* pz[] = {&z1, &z2, &z3, &z4};
for (int i = 0; i < devices; i++) {
QVector<double>* py[] = {&y1[i], &y2[i], &y3[i], &y4[i]};
QVector<double>* pz[] = {&z1[i], &z2[i], &z3[i], &z4[i]};

customPlot->graph(0)->setData(x, *py[idx]);
customPlot->graph(i)->setData(x, *py[idx]);

if (draw_max) {
customPlot->graph(1)->setData(x, *pz[idx]);
if (draw_max) {
customPlot->graph(MAX_DEVS + i)->setData(x, *pz[idx]);
}
}

#if defined(QCUSTOMPLOT_VERSION) && (QCUSTOMPLOT_VERSION >= 0x020000)
Expand All @@ -118,9 +127,11 @@ void MainWindow::redraw(int idx)

void MainWindow::on_rescale_clicked()
{
ui->widget->graph(0)->rescaleAxes();
if (draw_max) {
ui->widget->graph(1)->rescaleAxes(true);
for (int i = 0; i < devices; i++) {
ui->widget->graph(i)->rescaleAxes();
if (draw_max) {
ui->widget->graph(MAX_DEVS + i)->rescaleAxes(true);
}
}

int ymax = 65535 + ui->widget->yAxis->range().upper * 1024 * log2(10) / 10;
Expand All @@ -133,7 +144,7 @@ void MainWindow::on_rescale_clicked()

void MainWindow::on_lna_currentIndexChanged(int idx)
{
xtrx_antenna_t a[] = { XTRX_RX_AUTO, XTRX_RX_L, XTRX_RX_W, XTRX_RX_H };
xtrx_antenna_t a[] = { XTRX_RX_AUTO, XTRX_RX_L, XTRX_RX_W, XTRX_RX_H, XTRX_RX_ADC_EXT };
xtrx_set_antenna(dev, a[idx]);
}

Expand All @@ -149,9 +160,28 @@ void MainWindow::on_btStartStop_clicked()
ui->widget->graph(1)->data()->clear();

ui->statusbar->showMessage(QString("Samplerate %1 MSPS Gain: %2").arg(samplerate).arg(gain));
res = xtrx_open(devstr.toLatin1(), 4, &dev);
if (res)
//res = xtrx_open(devstr.toLatin1(), 4, &dev);
res = xtrx_open_string(devstr.toLatin1(), &dev);
if (res < 0)
goto failed;
devices = res;
const int FFT_SIZE = 512;
for (int i = 0; i < devices; ++i) {
y1[i].resize(FFT_SIZE);
y2[i].resize(FFT_SIZE);
y3[i].resize(FFT_SIZE);
y4[i].resize(FFT_SIZE);

z1[i].resize(FFT_SIZE);
z2[i].resize(FFT_SIZE);
z3[i].resize(FFT_SIZE);
z4[i].resize(FFT_SIZE);
}

//rx_thread->dev_cnt = res;
res = xtrx_set_ref_clk(dev, 0, ui->cbe->isChecked() ? XTRX_CLKSRC_EXT : XTRX_CLKSRC_INT);
if (res)
goto failed_freq;

res = xtrx_set_samplerate(dev, 0, samplerate, 0, 0, NULL, NULL, NULL);
if (res)
Expand All @@ -174,29 +204,31 @@ void MainWindow::on_btStartStop_clicked()
params.dir = XTRX_RX;
params.rx_stream_start = 8192;
params.nflags = 0;
params.rx.chs = XTRX_CH_AB;
params.rx.chs = XTRX_CH_ALL;
params.rx.flags = 0;
params.rx.hfmt = XTRX_IQ_INT16;
params.rx.wfmt = XTRX_WF_16;
params.rx.paketsize = 8192;
params.rx.flags = XTRX_STREAMDSP_1;
params.rx.flags = XTRX_STREAMDSP_1 | (ui->cbb->isChecked() ? XTRX_RSP_SWAP_AB : 0);
} else {
params.dir = XTRX_RX;
params.rx_stream_start = 32768;
params.nflags = 0;
params.rx.chs = XTRX_CH_AB;
params.rx.chs = XTRX_CH_ALL;
params.rx.flags = 0;
params.rx.hfmt = XTRX_IQ_INT8;
params.rx.wfmt = XTRX_WF_8;
params.rx.paketsize = 0;
params.rx.flags = XTRX_RSP_SISO_MODE | XTRX_STREAMDSP_2;
params.rx.flags = XTRX_RSP_SISO_SWITCH | XTRX_RSP_SISO_MODE | XTRX_STREAMDSP_2 | (ui->cbb->isChecked() ? XTRX_RSP_SWAP_AB : 0);
}
res = xtrx_run_ex(dev, &params);
if (res)
goto failed_freq;

ui->smaplerate->setEnabled(false);
ui->softlog->setEnabled(false);
ui->cbe->setEnabled(false);
//ui->cbb->setEnabled(false);
ui->btStartStop->setText(tr("Stop"));

on_throttle_valueChanged(ui->throttle->value());
Expand All @@ -208,13 +240,16 @@ void MainWindow::on_btStartStop_clicked()
if (!(rx_thread->wait(1000))) {
rx_thread->terminate();
}
usleep(1000);
xtrx_stop(dev, XTRX_TRX);
xtrx_close(dev);
dev = NULL;


ui->smaplerate->setEnabled(true);
ui->softlog->setEnabled(true);
ui->cbe->setEnabled(true);
//ui->cbb->setEnabled(true);
ui->btStartStop->setText(tr("Start"));

ui->waterfall->stop();
Expand All @@ -236,6 +271,16 @@ void MainWindow::on_max_clicked()
rx_thread->calc_max = draw_max;
}

void MainWindow::on_cbb_clicked()
{
uint64_t val = ui->cbb->isChecked() ? 1 : 0;
if (dev == NULL)
return;

xtrx_val_set(dev, XTRX_TRX, XTRX_CH_ALL,
(xtrx_val_t)(XTRX_FE_CUSTOM_0 + 2), val);
}

void MainWindow::on_freq_valueChanged(double freq)
{
if (dev == NULL)
Expand All @@ -252,7 +297,7 @@ void MainWindow::on_bw_valueChanged(double bw)
if (dev == NULL)
return;

int res = xtrx_tune_rx_bandwidth(dev, XTRX_CH_A, bw * 1e6, NULL);
int res = xtrx_tune_rx_bandwidth(dev, XTRX_CH_ALL, bw * 1e6, NULL);
if (res) {
ui->statusbar->showMessage(QString("Failed to set bw to %1 (%2) errno %3").arg(bw).arg(strerror(-res)).arg(res));
}
Expand All @@ -263,7 +308,7 @@ void MainWindow::on_gain_valueChanged(int gain)
if (dev == NULL)
return;

int res = xtrx_set_gain(dev, XTRX_CH_A, XTRX_RX_LNA_GAIN, gain, 0);
int res = xtrx_set_gain(dev, XTRX_CH_ALL, XTRX_RX_LNA_GAIN, gain, 0);
if (res) {
ui->statusbar->showMessage(QString("Failed to set gain to %1 (%2) errno %3").arg(gain).arg(strerror(-res)).arg(res));
}
Expand All @@ -289,7 +334,29 @@ void MainWindow::on_throttle_valueChanged(int skip)
reg |= (1 << 16) | ((skip - 1) & 0xFF);
}

xtrx_val_set(dev, XTRX_TRX, XTRX_CH_AB, XTRX_DSPFE_CMD, reg);
xtrx_val_set(dev, XTRX_TRX, XTRX_CH_ALL, XTRX_DSPFE_CMD, reg);
}

void MainWindow::on_cbcal_clicked()
{
if (dev == NULL)
return;

int res = xtrx_octo_set_cal_path(dev, ui->cbcal->isChecked());
if (res) {
ui->statusbar->showMessage(QString("Failed switch CAL to %1 errno %2").arg(strerror(-res)).arg(res));
}
}

void MainWindow::on_calFreq_valueChanged(double freq)
{
if (dev == NULL)
return;

int res = xtrx_tune(dev, XTRX_TUNE_EXT_FE, freq * 1e6, NULL);
if (res) {
ui->statusbar->showMessage(QString("Failed to tune to %1 (%2) errno %3").arg(freq).arg(strerror(-res)).arg(res));
}
}

void MainWindow::wf_add_point(int x, unsigned data)
Expand Down
25 changes: 17 additions & 8 deletions examples/xtrx_fft/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <QMainWindow>
#include <QThread>
#include <xtrx_api.h>
#include "../../octo/xtrx_octo_api.h"
#include <vector>

namespace Ui {
class MainWindow;
Expand All @@ -33,22 +35,23 @@ class MainWindow : public QMainWindow
{
Q_OBJECT

static const int MAX_DEVS = 8;
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();


QVector<double> x;

QVector<double> y1;
QVector<double> y2;
QVector<double> y3;
QVector<double> y4;
QVector<double> y1[MAX_DEVS];
QVector<double> y2[MAX_DEVS];
QVector<double> y3[MAX_DEVS];
QVector<double> y4[MAX_DEVS];

QVector<double> z1;
QVector<double> z2;
QVector<double> z3;
QVector<double> z4;
QVector<double> z1[MAX_DEVS];
QVector<double> z2[MAX_DEVS];
QVector<double> z3[MAX_DEVS];
QVector<double> z4[MAX_DEVS];

xtrx_dev* dev;

Expand All @@ -64,6 +67,11 @@ public slots:
void on_rescale_clicked();
void on_max_clicked();

void on_cbcal_clicked();
void on_cbb_clicked();

void on_calFreq_valueChanged(double);

void on_freq_valueChanged(double);
void on_bw_valueChanged(double);
void on_gain_valueChanged(int);
Expand All @@ -79,6 +87,7 @@ public slots:
//private:
Ui::MainWindow *ui;
RxThread* rx_thread;
int devices;
};

#endif // MAINWINDOW_H
Loading

0 comments on commit add3d77

Please sign in to comment.