1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 17:45:48 -05:00

PlutoSDR: fixed handling of open device status. Fixes issue #510

This commit is contained in:
f4exb 2020-05-20 09:48:24 +02:00
parent 187502b5f3
commit e79e11546c
5 changed files with 158 additions and 20 deletions

View File

@ -20,7 +20,7 @@
#include "deviceplutosdr.h"
DevicePlutoSDRParams::DevicePlutoSDRParams() :
m_box(0)
m_box(nullptr)
{
}

View File

@ -55,7 +55,12 @@ PlutoSDROutput::PlutoSDROutput(DeviceAPI *deviceAPI) :
m_deviceSampleRates.m_hb3Rate = 0;
suspendBuddies();
openDevice();
m_open = openDevice();
if (!m_open) {
qCritical("PlutoSDRInput::PlutoSDRInput: cannot open device");
}
resumeBuddies();
m_networkManager = new QNetworkAccessManager();
@ -84,11 +89,15 @@ void PlutoSDROutput::init()
bool PlutoSDROutput::start()
{
if (!m_deviceShared.m_deviceParams->getBox()) {
if (!m_deviceShared.m_deviceParams->getBox())
{
qCritical("PlutoSDROutput::start: device not open");
return false;
}
if (m_running) stop();
if (m_running) {
stop();
}
// start / stop streaming is done in the thread.
@ -267,14 +276,23 @@ bool PlutoSDROutput::openDevice()
if (kv.size() > 1)
{
if (kv.at(0) == "uri") {
m_deviceShared.m_deviceParams->openURI(kv.at(1).toStdString());
} else {
if (kv.at(0) == "uri")
{
if (!m_deviceShared.m_deviceParams->openURI(kv.at(1).toStdString()))
{
qCritical("PlutoSDROutput::openDevice: open network device uri=%s failed", qPrintable(kv.at(1)));
return false;
}
}
else
{
qCritical("PlutoSDROutput::openDevice: unexpected user parameter key %s", qPrintable(kv.at(0)));
return false;
}
}
else
{
qCritical("PlutoSDROutput::openDevice: unexpected user arguments %s", qPrintable(m_deviceAPI->getHardwareUserArguments()));
return false;
}
}
@ -282,7 +300,12 @@ bool PlutoSDROutput::openDevice()
{
char serial[256];
strcpy(serial, qPrintable(m_deviceAPI->getSamplingDeviceSerial()));
m_deviceShared.m_deviceParams->open(serial);
if (!m_deviceShared.m_deviceParams->open(serial))
{
qCritical("PlutoSDROutput::openDevice: open serial %s failed", serial);
return false;
}
}
}
@ -290,7 +313,13 @@ bool PlutoSDROutput::openDevice()
// acquire the channel
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
plutoBox->openTx();
if (!plutoBox->openTx())
{
qCritical("PlutoSDROutput::openDevice: cannot open Tx channel");
return false;
}
m_plutoTxBuffer = plutoBox->createTxBuffer(PLUTOSDR_BLOCKSIZE_SAMPLES, false); // PlutoSDR buffer size is counted in number of (I,Q) samples
return true;
@ -298,7 +327,7 @@ bool PlutoSDROutput::openDevice()
void PlutoSDROutput::closeDevice()
{
if (m_deviceShared.m_deviceParams->getBox() == 0) { // was never open
if (!m_open) { // was never open
return;
}
@ -342,6 +371,12 @@ void PlutoSDROutput::resumeBuddies()
bool PlutoSDROutput::applySettings(const PlutoSDROutputSettings& settings, bool force)
{
if (!m_open)
{
qCritical("PlutoSDROutput::applySettings: device not open");
return false;
}
bool forwardChangeOwnDSP = false;
bool forwardChangeOtherDSP = false;
bool ownThreadWasRunning = false;
@ -611,6 +646,12 @@ bool PlutoSDROutput::applySettings(const PlutoSDROutputSettings& settings, bool
void PlutoSDROutput::getRSSI(std::string& rssiStr)
{
if (!m_open)
{
qDebug("PlutoSDROutput::getRSSI: device not open");
return;
}
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
if (!plutoBox->getTxRSSI(rssiStr, 0)) {
@ -620,6 +661,12 @@ void PlutoSDROutput::getRSSI(std::string& rssiStr)
void PlutoSDROutput::getLORange(qint64& minLimit, qint64& maxLimit)
{
if (!m_open)
{
qDebug("PlutoSDROutput::getLORange: device not open");
return;
}
uint64_t min, max;
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
@ -630,6 +677,12 @@ void PlutoSDROutput::getLORange(qint64& minLimit, qint64& maxLimit)
void PlutoSDROutput::getbbLPRange(quint32& minLimit, quint32& maxLimit)
{
if (!m_open)
{
qDebug("PlutoSDROutput::getbbLPRange: device not open");
return;
}
uint32_t min, max;
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
@ -640,12 +693,24 @@ void PlutoSDROutput::getbbLPRange(quint32& minLimit, quint32& maxLimit)
bool PlutoSDROutput::fetchTemperature()
{
if (!m_open)
{
qDebug("PlutoSDRInput::fetchTemperature: device not open");
return false;
}
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
return plutoBox->fetchTemp();
}
float PlutoSDROutput::getTemperature()
{
if (!m_open)
{
qDebug("PlutoSDRInput::getTemperature: device not open");
return 0.0;
}
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
return plutoBox->getTemp();
}

View File

@ -140,6 +140,7 @@ public:
private:
DeviceAPI *m_deviceAPI;
bool m_open;
QString m_deviceDescription;
PlutoSDROutputSettings m_settings;
bool m_running;

View File

@ -58,7 +58,12 @@ PlutoSDRInput::PlutoSDRInput(DeviceAPI *deviceAPI) :
m_deviceSampleRates.m_hb3Rate = 0;
suspendBuddies();
openDevice();
m_open = openDevice();
if (!m_open) {
qCritical("PlutoSDRInput::PlutoSDRInput: cannot open device");
}
resumeBuddies();
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
@ -92,11 +97,15 @@ void PlutoSDRInput::init()
bool PlutoSDRInput::start()
{
if (!m_deviceShared.m_deviceParams->getBox()) {
if (!m_deviceShared.m_deviceParams->getBox())
{
qCritical("PlutoSDRInput::start: device not open");
return false;
}
if (m_running) stop();
if (m_running) {
stop();
}
// start / stop streaming is done in the thread.
@ -305,14 +314,23 @@ bool PlutoSDRInput::openDevice()
if (kv.size() > 1)
{
if (kv.at(0) == "uri") {
m_deviceShared.m_deviceParams->openURI(kv.at(1).toStdString());
} else {
if (kv.at(0) == "uri")
{
if (!m_deviceShared.m_deviceParams->openURI(kv.at(1).toStdString()))
{
qCritical("PlutoSDRInput::openDevice: open network device uri=%s failed", qPrintable(kv.at(1)));
return false;
}
}
else
{
qCritical("PlutoSDRInput::openDevice: unexpected user parameter key %s", qPrintable(kv.at(0)));
return false;
}
}
else
{
qCritical("PlutoSDRInput::openDevice: unexpected user arguments %s", qPrintable(m_deviceAPI->getHardwareUserArguments()));
return false;
}
}
@ -320,7 +338,12 @@ bool PlutoSDRInput::openDevice()
{
char serial[256];
strcpy(serial, qPrintable(m_deviceAPI->getSamplingDeviceSerial()));
m_deviceShared.m_deviceParams->open(serial);
if (!m_deviceShared.m_deviceParams->open(serial))
{
qCritical("PlutoSDRInput::openDevice: open serial %s failed", serial);
return false;
}
}
}
@ -328,7 +351,13 @@ bool PlutoSDRInput::openDevice()
// acquire the channel
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
plutoBox->openRx();
if (!plutoBox->openRx())
{
qCritical("PlutoSDRInput::openDevice: cannot open Rx channel");
return false;
}
m_plutoRxBuffer = plutoBox->createRxBuffer(PLUTOSDR_BLOCKSIZE_SAMPLES, false);
return true;
@ -336,7 +365,7 @@ bool PlutoSDRInput::openDevice()
void PlutoSDRInput::closeDevice()
{
if (m_deviceShared.m_deviceParams->getBox() == 0) { // was never open
if (!m_open) { // was never open
return;
}
@ -380,6 +409,12 @@ void PlutoSDRInput::resumeBuddies()
bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool force)
{
if (!m_open)
{
qCritical("PlutoSDRInput::applySettings: device not open");
return false;
}
bool forwardChangeOwnDSP = false;
bool forwardChangeOtherDSP = false;
bool ownThreadWasRunning = false;
@ -722,6 +757,12 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo
void PlutoSDRInput::getRSSI(std::string& rssiStr)
{
if (!m_open)
{
qDebug("PlutoSDRInput::getRSSI: device not open");
return;
}
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
if (!plutoBox->getRxRSSI(rssiStr, 0)) {
@ -731,8 +772,14 @@ void PlutoSDRInput::getRSSI(std::string& rssiStr)
void PlutoSDRInput::getLORange(qint64& minLimit, qint64& maxLimit)
{
if (!m_open)
{
qDebug("PlutoSDRInput::getLORange: device not open");
return;
}
uint64_t min, max;
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
plutoBox->getRxLORange(min, max);
minLimit = min;
@ -741,6 +788,12 @@ void PlutoSDRInput::getLORange(qint64& minLimit, qint64& maxLimit)
void PlutoSDRInput::getbbLPRange(quint32& minLimit, quint32& maxLimit)
{
if (!m_open)
{
qDebug("PlutoSDRInput::getbbLPRange: device not open");
return;
}
uint32_t min, max;
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
@ -751,6 +804,12 @@ void PlutoSDRInput::getbbLPRange(quint32& minLimit, quint32& maxLimit)
void PlutoSDRInput::getGain(int& gaindB)
{
if (!m_open)
{
qDebug("PlutoSDRInput::getGain: device not open");
return;
}
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
if (!plutoBox->getRxGain(gaindB, 0)) {
@ -760,12 +819,24 @@ void PlutoSDRInput::getGain(int& gaindB)
bool PlutoSDRInput::fetchTemperature()
{
if (!m_open)
{
qDebug("PlutoSDRInput::fetchTemperature: device not open");
return false;
}
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
return plutoBox->fetchTemp();
}
float PlutoSDRInput::getTemperature()
{
if (!m_open)
{
qDebug("PlutoSDRInput::getTemperature: device not open");
return 0.0;
}
DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox();
return plutoBox->getTemp();
}

View File

@ -167,6 +167,7 @@ public:
private:
DeviceAPI *m_deviceAPI;
bool m_open;
FileRecord *m_fileSink;
QString m_deviceDescription;
PlutoSDRInputSettings m_settings;