mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	PlutoSDR: remove from device enumeration if device is not accessible (allocate context fails)
This commit is contained in:
		
							parent
							
								
									21ed8a8391
								
							
						
					
					
						commit
						9ba88b396b
					
				@ -29,6 +29,10 @@
 | 
				
			|||||||
DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) :
 | 
					DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) :
 | 
				
			||||||
        m_lpfFIRRxGain(0),
 | 
					        m_lpfFIRRxGain(0),
 | 
				
			||||||
        m_lpfFIRTxGain(0),
 | 
					        m_lpfFIRTxGain(0),
 | 
				
			||||||
 | 
					        m_ctx(0),
 | 
				
			||||||
 | 
					        m_devPhy(0),
 | 
				
			||||||
 | 
					        m_devRx(0),
 | 
				
			||||||
 | 
					        m_devTx(0),
 | 
				
			||||||
        m_chnRx0(0),
 | 
					        m_chnRx0(0),
 | 
				
			||||||
        m_chnTx0(0),
 | 
					        m_chnTx0(0),
 | 
				
			||||||
        m_rxBuf(0),
 | 
					        m_rxBuf(0),
 | 
				
			||||||
@ -36,9 +40,14 @@ DevicePlutoSDRBox::DevicePlutoSDRBox(const std::string& uri) :
 | 
				
			|||||||
        m_xoInitial(0)
 | 
					        m_xoInitial(0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_ctx = iio_create_context_from_uri(uri.c_str());
 | 
					    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");
 | 
					    if (m_ctx)
 | 
				
			||||||
    m_devTx = iio_context_find_device(m_ctx, "cf-ad9361-dds-core-lpc");
 | 
					    {
 | 
				
			||||||
 | 
					        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;
 | 
					    m_valid = m_ctx && m_devPhy && m_devRx && m_devTx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (m_valid) {
 | 
					    if (m_valid) {
 | 
				
			||||||
@ -64,6 +73,21 @@ DevicePlutoSDRBox::~DevicePlutoSDRBox()
 | 
				
			|||||||
    if (m_ctx) { iio_context_destroy(m_ctx); }
 | 
					    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,
 | 
					void DevicePlutoSDRBox::set_params(DeviceType devType,
 | 
				
			||||||
        const std::vector<std::string>& params)
 | 
					        const std::vector<std::string>& params)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -218,6 +242,8 @@ void DevicePlutoSDRBox::setFilter(const std::string &filterConfigStr)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool DevicePlutoSDRBox::openRx()
 | 
					bool DevicePlutoSDRBox::openRx()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    if (!m_valid) { return false; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!m_chnRx0) {
 | 
					    if (!m_chnRx0) {
 | 
				
			||||||
        m_chnRx0 = iio_device_find_channel(m_devRx, "voltage0", false);
 | 
					        m_chnRx0 = iio_device_find_channel(m_devRx, "voltage0", false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -243,6 +269,8 @@ bool DevicePlutoSDRBox::openRx()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool DevicePlutoSDRBox::openTx()
 | 
					bool DevicePlutoSDRBox::openTx()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    if (!m_valid) { return false; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!m_chnTx0) {
 | 
					    if (!m_chnTx0) {
 | 
				
			||||||
        m_chnTx0 = iio_device_find_channel(m_devTx, "voltage0", true);
 | 
					        m_chnTx0 = iio_device_find_channel(m_devTx, "voltage0", true);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -63,6 +63,7 @@ public:
 | 
				
			|||||||
    DevicePlutoSDRBox(const std::string& uri);
 | 
					    DevicePlutoSDRBox(const std::string& uri);
 | 
				
			||||||
    ~DevicePlutoSDRBox();
 | 
					    ~DevicePlutoSDRBox();
 | 
				
			||||||
    bool isValid() const { return m_valid; }
 | 
					    bool isValid() const { return m_valid; }
 | 
				
			||||||
 | 
					    static bool probeURI(const std::string& uri);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void set_params(DeviceType devType, const std::vector<std::string> ¶ms);
 | 
					    void set_params(DeviceType devType, const std::vector<std::string> ¶ms);
 | 
				
			||||||
    bool get_param(DeviceType devType, const std::string ¶m, std::string &value);
 | 
					    bool get_param(DeviceType devType, const std::string ¶m, std::string &value);
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,7 @@
 | 
				
			|||||||
#include <regex>
 | 
					#include <regex>
 | 
				
			||||||
#include <iio.h>
 | 
					#include <iio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "deviceplutosdrbox.h"
 | 
				
			||||||
#include "deviceplutosdrscan.h"
 | 
					#include "deviceplutosdrscan.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DevicePlutoSDRScan::scan()
 | 
					void DevicePlutoSDRScan::scan()
 | 
				
			||||||
@ -50,6 +51,11 @@ void DevicePlutoSDRScan::scan()
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        const char *description = iio_context_info_get_description(info[i]);
 | 
					        const char *description = iio_context_info_get_description(info[i]);
 | 
				
			||||||
        const char *uri = iio_context_info_get_uri(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);
 | 
					        printf("PlutoSDRScan::scan: %d: %s [%s]\n", i, description, uri);
 | 
				
			||||||
        char *pch = strstr(const_cast<char*>(description), "PlutoSDR");
 | 
					        char *pch = strstr(const_cast<char*>(description), "PlutoSDR");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -23,6 +23,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
ValueDial::ValueDial(QWidget* parent, ColorMapper colorMapper) :
 | 
					ValueDial::ValueDial(QWidget* parent, ColorMapper colorMapper) :
 | 
				
			||||||
	QWidget(parent),
 | 
						QWidget(parent),
 | 
				
			||||||
 | 
						m_delta(0),
 | 
				
			||||||
	m_animationState(0),
 | 
						m_animationState(0),
 | 
				
			||||||
	m_colorMapper(colorMapper)
 | 
						m_colorMapper(colorMapper)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -133,6 +134,13 @@ void ValueDial::setValueRange(uint numDigits, quint64 min, quint64 max)
 | 
				
			|||||||
	setFixedWidth((m_numDigits + m_numDecimalPoints) * m_digitWidth + 2);
 | 
						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 ValueDial::findExponent(int digit)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	quint64 e = 1;
 | 
						quint64 e = 1;
 | 
				
			||||||
@ -158,7 +166,8 @@ QChar ValueDial::digitNeigh(QChar c, bool dir)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
QString ValueDial::formatText(quint64 value)
 | 
					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++)
 | 
						for(int i = 0; i < m_numDecimalPoints; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
				
			|||||||
@ -1,79 +1,82 @@
 | 
				
			|||||||
///////////////////////////////////////////////////////////////////////////////////
 | 
					///////////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
				
			||||||
// written by Christian Daniel                                                   //
 | 
					// written by Christian Daniel                                                   //
 | 
				
			||||||
//                                                                               //
 | 
					//                                                                               //
 | 
				
			||||||
// This program is free software; you can redistribute it and/or modify          //
 | 
					// 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          //
 | 
					// it under the terms of the GNU General Public License as published by          //
 | 
				
			||||||
// the Free Software Foundation as version 3 of the License, or                  //
 | 
					// the Free Software Foundation as version 3 of the License, or                  //
 | 
				
			||||||
//                                                                               //
 | 
					//                                                                               //
 | 
				
			||||||
// This program is distributed in the hope that it will be useful,               //
 | 
					// This program is distributed in the hope that it will be useful,               //
 | 
				
			||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					// but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
				
			||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
				
			||||||
// GNU General Public License V3 for more details.                               //
 | 
					// GNU General Public License V3 for more details.                               //
 | 
				
			||||||
//                                                                               //
 | 
					//                                                                               //
 | 
				
			||||||
// You should have received a copy of the GNU General Public License             //
 | 
					// You should have received a copy of the GNU General Public License             //
 | 
				
			||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					// along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
				
			||||||
///////////////////////////////////////////////////////////////////////////////////
 | 
					///////////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QWidget>
 | 
					#include <QWidget>
 | 
				
			||||||
#include <QTimer>
 | 
					#include <QTimer>
 | 
				
			||||||
#include "gui/colormapper.h"
 | 
					#include "gui/colormapper.h"
 | 
				
			||||||
#include "util/export.h"
 | 
					#include "util/export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SDRANGEL_API ValueDial : public QWidget {
 | 
					class SDRANGEL_API ValueDial : public QWidget {
 | 
				
			||||||
	Q_OBJECT
 | 
						Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	ValueDial(QWidget* parent = NULL, ColorMapper colorMapper = ColorMapper(ColorMapper::Normal));
 | 
						ValueDial(QWidget* parent = NULL, ColorMapper colorMapper = ColorMapper(ColorMapper::Normal));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void setValue(quint64 value);
 | 
						void setValue(quint64 value);
 | 
				
			||||||
	void setValueRange(uint numDigits, quint64 min, quint64 max);
 | 
						void setValueRange(uint numDigits, quint64 min, quint64 max);
 | 
				
			||||||
	void setFont(const QFont& font);
 | 
						void setDelta(qint64 delta);
 | 
				
			||||||
	void setBold(bool bold);
 | 
						qint64 getDelta() const { return m_delta; }
 | 
				
			||||||
	void setColorMapper(ColorMapper colorMapper);
 | 
						void setFont(const QFont& font);
 | 
				
			||||||
	quint64 getValue() const { return m_value; }
 | 
						void setBold(bool bold);
 | 
				
			||||||
	quint64 getValueNew() const { return m_valueNew; }
 | 
						void setColorMapper(ColorMapper colorMapper);
 | 
				
			||||||
 | 
						quint64 getValue() const { return m_value; }
 | 
				
			||||||
signals:
 | 
						quint64 getValueNew() const { return m_valueNew; }
 | 
				
			||||||
	void changed(quint64 value);
 | 
					
 | 
				
			||||||
 | 
					signals:
 | 
				
			||||||
private:
 | 
						void changed(quint64 value);
 | 
				
			||||||
	QLinearGradient m_background;
 | 
					
 | 
				
			||||||
	int m_numDigits;
 | 
					private:
 | 
				
			||||||
	int m_numDecimalPoints;
 | 
						QLinearGradient m_background;
 | 
				
			||||||
	int m_digitWidth;
 | 
						int m_numDigits;
 | 
				
			||||||
	int m_digitHeight;
 | 
						int m_numDecimalPoints;
 | 
				
			||||||
	int m_hightlightedDigit;
 | 
						int m_digitWidth;
 | 
				
			||||||
	int m_cursor;
 | 
						int m_digitHeight;
 | 
				
			||||||
	bool m_cursorState;
 | 
						int m_hightlightedDigit;
 | 
				
			||||||
	quint64 m_value;
 | 
						int m_cursor;
 | 
				
			||||||
	quint64 m_valueMax;
 | 
						bool m_cursorState;
 | 
				
			||||||
	quint64 m_valueMin;
 | 
						quint64 m_value;
 | 
				
			||||||
	QString m_text;
 | 
						quint64 m_valueMax;
 | 
				
			||||||
 | 
						quint64 m_valueMin;
 | 
				
			||||||
	quint64 m_valueNew;
 | 
						qint64  m_delta;
 | 
				
			||||||
	QString m_textNew;
 | 
						QString m_text;
 | 
				
			||||||
	int m_animationState;
 | 
					
 | 
				
			||||||
	QTimer m_animationTimer;
 | 
						quint64 m_valueNew;
 | 
				
			||||||
	QTimer m_blinkTimer;
 | 
						QString m_textNew;
 | 
				
			||||||
 | 
						int m_animationState;
 | 
				
			||||||
	ColorMapper m_colorMapper;
 | 
						QTimer m_animationTimer;
 | 
				
			||||||
 | 
						QTimer m_blinkTimer;
 | 
				
			||||||
	quint64 findExponent(int digit);
 | 
					
 | 
				
			||||||
	QChar digitNeigh(QChar c, bool dir);
 | 
						ColorMapper m_colorMapper;
 | 
				
			||||||
	QString formatText(quint64 value);
 | 
					
 | 
				
			||||||
 | 
						quint64 findExponent(int digit);
 | 
				
			||||||
	void paintEvent(QPaintEvent*);
 | 
						QChar digitNeigh(QChar c, bool dir);
 | 
				
			||||||
 | 
						QString formatText(quint64 value);
 | 
				
			||||||
	void mousePressEvent(QMouseEvent*);
 | 
					
 | 
				
			||||||
	void mouseMoveEvent(QMouseEvent*);
 | 
						void paintEvent(QPaintEvent*);
 | 
				
			||||||
	void wheelEvent(QWheelEvent*);
 | 
					
 | 
				
			||||||
	void leaveEvent(QEvent*);
 | 
						void mousePressEvent(QMouseEvent*);
 | 
				
			||||||
	void keyPressEvent(QKeyEvent*);
 | 
						void mouseMoveEvent(QMouseEvent*);
 | 
				
			||||||
	void focusInEvent(QFocusEvent*);
 | 
						void wheelEvent(QWheelEvent*);
 | 
				
			||||||
	void focusOutEvent(QFocusEvent*);
 | 
						void leaveEvent(QEvent*);
 | 
				
			||||||
 | 
						void keyPressEvent(QKeyEvent*);
 | 
				
			||||||
private slots:
 | 
						void focusInEvent(QFocusEvent*);
 | 
				
			||||||
	void animate();
 | 
						void focusOutEvent(QFocusEvent*);
 | 
				
			||||||
	void blink();
 | 
					
 | 
				
			||||||
};
 | 
					private slots:
 | 
				
			||||||
 | 
						void animate();
 | 
				
			||||||
 | 
						void blink();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user