PlutoSDR: remove from device enumeration if device is not accessible (allocate context fails)

This commit is contained in:
f4exb 2017-09-23 03:42:58 +02:00
parent 21ed8a8391
commit 9ba88b396b
5 changed files with 130 additions and 83 deletions

View File

@ -29,6 +29,10 @@
DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) :
m_lpfFIRRxGain(0),
m_lpfFIRTxGain(0),
m_ctx(0),
m_devPhy(0),
m_devRx(0),
m_devTx(0),
m_chnRx0(0),
m_chnTx0(0),
m_rxBuf(0),
@ -36,9 +40,14 @@ DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) :
m_xoInitial(0)
{
m_ctx = iio_create_context_from_uri(uri.c_str());
m_devPhy = iio_context_find_device(m_ctx, "ad9361-phy");
m_devRx = iio_context_find_device(m_ctx, "cf-ad9361-lpc");
m_devTx = iio_context_find_device(m_ctx, "cf-ad9361-dds-core-lpc");
if (m_ctx)
{
m_devPhy = iio_context_find_device(m_ctx, "ad9361-phy");
m_devRx = iio_context_find_device(m_ctx, "cf-ad9361-lpc");
m_devTx = iio_context_find_device(m_ctx, "cf-ad9361-dds-core-lpc");
}
m_valid = m_ctx && m_devPhy && m_devRx && m_devTx;
if (m_valid) {
@ -64,6 +73,21 @@ DevicePlutoSDRBox::~DevicePlutoSDRBox()
if (m_ctx) { iio_context_destroy(m_ctx); }
}
bool DevicePlutoSDRBox::probeURI(const std::string& uri)
{
bool retVal;
struct iio_context *ctx;
ctx = iio_create_context_from_uri(uri.c_str());
retVal = (ctx != 0);
if (ctx) {
iio_context_destroy(ctx);
}
return retVal;
}
void DevicePlutoSDRBox::set_params(DeviceType devType,
const std::vector<std::string>& params)
{
@ -218,6 +242,8 @@ void DevicePlutoSDRBox::setFilter(const std::string &filterConfigStr)
bool DevicePlutoSDRBox::openRx()
{
if (!m_valid) { return false; }
if (!m_chnRx0) {
m_chnRx0 = iio_device_find_channel(m_devRx, "voltage0", false);
}
@ -243,6 +269,8 @@ bool DevicePlutoSDRBox::openRx()
bool DevicePlutoSDRBox::openTx()
{
if (!m_valid) { return false; }
if (!m_chnTx0) {
m_chnTx0 = iio_device_find_channel(m_devTx, "voltage0", true);
}

View File

@ -63,6 +63,7 @@ public:
DevicePlutoSDRBox(const std::string& uri);
~DevicePlutoSDRBox();
bool isValid() const { return m_valid; }
static bool probeURI(const std::string& uri);
void set_params(DeviceType devType, const std::vector<std::string> &params);
bool get_param(DeviceType devType, const std::string &param, std::string &value);

View File

@ -20,6 +20,7 @@
#include <regex>
#include <iio.h>
#include "deviceplutosdrbox.h"
#include "deviceplutosdrscan.h"
void DevicePlutoSDRScan::scan()
@ -50,6 +51,11 @@ void DevicePlutoSDRScan::scan()
{
const char *description = iio_context_info_get_description(info[i]);
const char *uri = iio_context_info_get_uri(info[i]);
if (!DevicePlutoSDRBox::probeURI(std::string(uri))) { // continue if not accessible
continue;
}
printf("PlutoSDRScan::scan: %d: %s [%s]\n", i, description, uri);
char *pch = strstr(const_cast<char*>(description), "PlutoSDR");

View File

@ -23,6 +23,7 @@
ValueDial::ValueDial(QWidget* parent, ColorMapper colorMapper) :
QWidget(parent),
m_delta(0),
m_animationState(0),
m_colorMapper(colorMapper)
{
@ -133,6 +134,13 @@ void ValueDial::setValueRange(uint numDigits, quint64 min, quint64 max)
setFixedWidth((m_numDigits + m_numDecimalPoints) * m_digitWidth + 2);
}
void ValueDial::setDelta(qint64 delta)
{
m_delta = delta;
m_animationTimer.start(20);
m_textNew = formatText(m_valueNew);
}
quint64 ValueDial::findExponent(int digit)
{
quint64 e = 1;
@ -158,7 +166,8 @@ QChar ValueDial::digitNeigh(QChar c, bool dir)
QString ValueDial::formatText(quint64 value)
{
QString str = QString("%1").arg(value, m_numDigits, 10, QChar('0'));
qint64 displayValue = value + m_delta > 0 ? value + m_delta : 0;
QString str = QString("%1").arg(displayValue, m_numDigits, 10, QChar('0'));
for(int i = 0; i < m_numDecimalPoints; i++)
{

View File

@ -1,79 +1,82 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
// written by Christian Daniel //
// //
// 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 <QWidget>
#include <QTimer>
#include "gui/colormapper.h"
#include "util/export.h"
class SDRANGEL_API ValueDial : public QWidget {
Q_OBJECT
public:
ValueDial(QWidget* parent = NULL, ColorMapper colorMapper = ColorMapper(ColorMapper::Normal));
void setValue(quint64 value);
void setValueRange(uint numDigits, quint64 min, quint64 max);
void setFont(const QFont& font);
void setBold(bool bold);
void setColorMapper(ColorMapper colorMapper);
quint64 getValue() const { return m_value; }
quint64 getValueNew() const { return m_valueNew; }
signals:
void changed(quint64 value);
private:
QLinearGradient m_background;
int m_numDigits;
int m_numDecimalPoints;
int m_digitWidth;
int m_digitHeight;
int m_hightlightedDigit;
int m_cursor;
bool m_cursorState;
quint64 m_value;
quint64 m_valueMax;
quint64 m_valueMin;
QString m_text;
quint64 m_valueNew;
QString m_textNew;
int m_animationState;
QTimer m_animationTimer;
QTimer m_blinkTimer;
ColorMapper m_colorMapper;
quint64 findExponent(int digit);
QChar digitNeigh(QChar c, bool dir);
QString formatText(quint64 value);
void paintEvent(QPaintEvent*);
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void wheelEvent(QWheelEvent*);
void leaveEvent(QEvent*);
void keyPressEvent(QKeyEvent*);
void focusInEvent(QFocusEvent*);
void focusOutEvent(QFocusEvent*);
private slots:
void animate();
void blink();
};
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
// written by Christian Daniel //
// //
// 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 <QWidget>
#include <QTimer>
#include "gui/colormapper.h"
#include "util/export.h"
class SDRANGEL_API ValueDial : public QWidget {
Q_OBJECT
public:
ValueDial(QWidget* parent = NULL, ColorMapper colorMapper = ColorMapper(ColorMapper::Normal));
void setValue(quint64 value);
void setValueRange(uint numDigits, quint64 min, quint64 max);
void setDelta(qint64 delta);
qint64 getDelta() const { return m_delta; }
void setFont(const QFont& font);
void setBold(bool bold);
void setColorMapper(ColorMapper colorMapper);
quint64 getValue() const { return m_value; }
quint64 getValueNew() const { return m_valueNew; }
signals:
void changed(quint64 value);
private:
QLinearGradient m_background;
int m_numDigits;
int m_numDecimalPoints;
int m_digitWidth;
int m_digitHeight;
int m_hightlightedDigit;
int m_cursor;
bool m_cursorState;
quint64 m_value;
quint64 m_valueMax;
quint64 m_valueMin;
qint64 m_delta;
QString m_text;
quint64 m_valueNew;
QString m_textNew;
int m_animationState;
QTimer m_animationTimer;
QTimer m_blinkTimer;
ColorMapper m_colorMapper;
quint64 findExponent(int digit);
QChar digitNeigh(QChar c, bool dir);
QString formatText(quint64 value);
void paintEvent(QPaintEvent*);
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
void wheelEvent(QWheelEvent*);
void leaveEvent(QEvent*);
void keyPressEvent(QKeyEvent*);
void focusInEvent(QFocusEvent*);
void focusOutEvent(QFocusEvent*);
private slots:
void animate();
void blink();
};