From b05897d22125c67a24892b89b486783b9e7d8c7e Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 14 Apr 2017 03:17:04 +0200 Subject: [PATCH] SDRplay: open/close new style --- plugins/samplesource/fcdpro/fcdproinput.cpp | 3 +- plugins/samplesource/fcdpro/fcdproinput.h | 1 + plugins/samplesource/sdrplay/sdrplayinput.cpp | 107 ++++++++++-------- 3 files changed, 62 insertions(+), 49 deletions(-) diff --git a/plugins/samplesource/fcdpro/fcdproinput.cpp b/plugins/samplesource/fcdpro/fcdproinput.cpp index 78eb1032b..87710d72b 100644 --- a/plugins/samplesource/fcdpro/fcdproinput.cpp +++ b/plugins/samplesource/fcdpro/fcdproinput.cpp @@ -39,7 +39,8 @@ FCDProInput::FCDProInput(DeviceSourceAPI *deviceAPI) : m_dev(0), m_settings(), m_FCDThread(0), - m_deviceDescription(fcd_traits::displayedName) + m_deviceDescription(fcd_traits::displayedName), + m_running(false) { } diff --git a/plugins/samplesource/fcdpro/fcdproinput.h b/plugins/samplesource/fcdpro/fcdproinput.h index 435003638..84c46d6b6 100644 --- a/plugins/samplesource/fcdpro/fcdproinput.h +++ b/plugins/samplesource/fcdpro/fcdproinput.h @@ -96,6 +96,7 @@ private: FCDProSettings m_settings; FCDProThread* m_FCDThread; QString m_deviceDescription; + bool m_running; }; #endif // INCLUDE_FCDPROINPUT_H diff --git a/plugins/samplesource/sdrplay/sdrplayinput.cpp b/plugins/samplesource/sdrplay/sdrplayinput.cpp index 9c4a80ac2..29f024722 100644 --- a/plugins/samplesource/sdrplay/sdrplayinput.cpp +++ b/plugins/samplesource/sdrplay/sdrplayinput.cpp @@ -40,39 +40,26 @@ SDRPlayInput::SDRPlayInput(DeviceSourceAPI *deviceAPI) : m_devNumber(0), m_running(false) { + openDevice(); } SDRPlayInput::~SDRPlayInput() { - stop(); + if (m_running) stop(); + closeDevice(); } -bool openDevice() +bool SDRPlayInput::openDevice() { - -} - -void closeDevice() -{ - -} - -bool SDRPlayInput::start(int device) -{ - QMutexLocker mutexLocker(&m_mutex); - m_devNumber = m_deviceAPI->getSampleSourceSequence(); - if (m_dev != 0) - { - stop(); - } + if (m_dev != 0) + { + closeDevice(); + } - char vendor[256]; - char product[256]; - char serial[256]; - int res; - int numberOfGains; + int res; + //int numberOfGains; if (!m_sampleFifo.setSize(96000 * 4)) { @@ -80,25 +67,43 @@ bool SDRPlayInput::start(int device) return false; } - if ((res = mirisdr_open(&m_dev, MIRISDR_HW_SDRPLAY, m_devNumber)) < 0) - { - qCritical("SDRPlayInput::start: could not open SDRPlay #%d: %s", m_devNumber, strerror(errno)); - return false; - } + if ((res = mirisdr_open(&m_dev, MIRISDR_HW_SDRPLAY, m_devNumber)) < 0) + { + qCritical("SDRPlayInput::start: could not open SDRPlay #%d: %s", m_devNumber, strerror(errno)); + return false; + } - vendor[0] = '\0'; - product[0] = '\0'; - serial[0] = '\0'; + char vendor[256]; + char product[256]; + char serial[256]; - if ((res = mirisdr_get_device_usb_strings(m_devNumber, vendor, product, serial)) < 0) - { - qCritical("SDRPlayInput::start: error accessing USB device"); - stop(); - return false; - } + vendor[0] = '\0'; + product[0] = '\0'; + serial[0] = '\0'; - qWarning("SDRPlayInput::start: open: %s %s, SN: %s", vendor, product, serial); - m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial); + if ((res = mirisdr_get_device_usb_strings(m_devNumber, vendor, product, serial)) < 0) + { + qCritical("SDRPlayInput::start: error accessing USB device"); + stop(); + return false; + } + + qWarning("SDRPlayInput::start: open: %s %s, SN: %s", vendor, product, serial); + m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial); + + return true; +} + +bool SDRPlayInput::start(int device) +{ +// QMutexLocker mutexLocker(&m_mutex); + int res; + + if (!m_dev) { + return false; + } + + if (m_running) stop(); char s12FormatString[] = "336_S16"; @@ -145,16 +150,28 @@ bool SDRPlayInput::start(int device) m_sdrPlayThread->startWork(); - mutexLocker.unlock(); +// mutexLocker.unlock(); applySettings(m_settings, true, true); + m_running = true; return true; } +void SDRPlayInput::closeDevice() +{ + if (m_dev != 0) + { + mirisdr_close(m_dev); + m_dev = 0; + } + + m_deviceDescription.clear(); +} + void SDRPlayInput::stop() { - QMutexLocker mutexLocker(&m_mutex); +// QMutexLocker mutexLocker(&m_mutex); if(m_sdrPlayThread != 0) { @@ -163,13 +180,7 @@ void SDRPlayInput::stop() m_sdrPlayThread = 0; } - if (m_dev != 0) - { - mirisdr_close(m_dev); - m_dev = 0; - } - - m_deviceDescription.clear(); + m_running = false; } const QString& SDRPlayInput::getDeviceDescription() const