SDRplay: open/close new style

This commit is contained in:
f4exb 2017-04-14 03:17:04 +02:00
parent 3fa28dab30
commit b05897d221
3 changed files with 62 additions and 49 deletions

View File

@ -39,7 +39,8 @@ FCDProInput::FCDProInput(DeviceSourceAPI *deviceAPI) :
m_dev(0), m_dev(0),
m_settings(), m_settings(),
m_FCDThread(0), m_FCDThread(0),
m_deviceDescription(fcd_traits<Pro>::displayedName) m_deviceDescription(fcd_traits<Pro>::displayedName),
m_running(false)
{ {
} }

View File

@ -96,6 +96,7 @@ private:
FCDProSettings m_settings; FCDProSettings m_settings;
FCDProThread* m_FCDThread; FCDProThread* m_FCDThread;
QString m_deviceDescription; QString m_deviceDescription;
bool m_running;
}; };
#endif // INCLUDE_FCDPROINPUT_H #endif // INCLUDE_FCDPROINPUT_H

View File

@ -40,39 +40,26 @@ SDRPlayInput::SDRPlayInput(DeviceSourceAPI *deviceAPI) :
m_devNumber(0), m_devNumber(0),
m_running(false) m_running(false)
{ {
openDevice();
} }
SDRPlayInput::~SDRPlayInput() 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(); m_devNumber = m_deviceAPI->getSampleSourceSequence();
if (m_dev != 0) if (m_dev != 0)
{ {
stop(); closeDevice();
} }
char vendor[256]; int res;
char product[256]; //int numberOfGains;
char serial[256];
int res;
int numberOfGains;
if (!m_sampleFifo.setSize(96000 * 4)) if (!m_sampleFifo.setSize(96000 * 4))
{ {
@ -80,25 +67,43 @@ bool SDRPlayInput::start(int device)
return false; return false;
} }
if ((res = mirisdr_open(&m_dev, MIRISDR_HW_SDRPLAY, m_devNumber)) < 0) 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)); qCritical("SDRPlayInput::start: could not open SDRPlay #%d: %s", m_devNumber, strerror(errno));
return false; return false;
} }
vendor[0] = '\0'; char vendor[256];
product[0] = '\0'; char product[256];
serial[0] = '\0'; char serial[256];
if ((res = mirisdr_get_device_usb_strings(m_devNumber, vendor, product, serial)) < 0) vendor[0] = '\0';
{ product[0] = '\0';
qCritical("SDRPlayInput::start: error accessing USB device"); serial[0] = '\0';
stop();
return false;
}
qWarning("SDRPlayInput::start: open: %s %s, SN: %s", vendor, product, serial); if ((res = mirisdr_get_device_usb_strings(m_devNumber, vendor, product, serial)) < 0)
m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial); {
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"; char s12FormatString[] = "336_S16";
@ -145,16 +150,28 @@ bool SDRPlayInput::start(int device)
m_sdrPlayThread->startWork(); m_sdrPlayThread->startWork();
mutexLocker.unlock(); // mutexLocker.unlock();
applySettings(m_settings, true, true); applySettings(m_settings, true, true);
m_running = true;
return true; return true;
} }
void SDRPlayInput::closeDevice()
{
if (m_dev != 0)
{
mirisdr_close(m_dev);
m_dev = 0;
}
m_deviceDescription.clear();
}
void SDRPlayInput::stop() void SDRPlayInput::stop()
{ {
QMutexLocker mutexLocker(&m_mutex); // QMutexLocker mutexLocker(&m_mutex);
if(m_sdrPlayThread != 0) if(m_sdrPlayThread != 0)
{ {
@ -163,13 +180,7 @@ void SDRPlayInput::stop()
m_sdrPlayThread = 0; m_sdrPlayThread = 0;
} }
if (m_dev != 0) m_running = false;
{
mirisdr_close(m_dev);
m_dev = 0;
}
m_deviceDescription.clear();
} }
const QString& SDRPlayInput::getDeviceDescription() const const QString& SDRPlayInput::getDeviceDescription() const