mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-27 02:09:14 -05:00
BladeRF output: refactoring: device open close moved in the constructor and destructor respectively of the input object
This commit is contained in:
parent
e71e75126e
commit
72a2fd9065
@ -36,28 +36,25 @@ BladerfOutput::BladerfOutput(DeviceSinkAPI *deviceAPI) :
|
|||||||
m_settings(),
|
m_settings(),
|
||||||
m_dev(0),
|
m_dev(0),
|
||||||
m_bladerfThread(0),
|
m_bladerfThread(0),
|
||||||
m_deviceDescription("BladeRFOutput")
|
m_deviceDescription("BladeRFOutput"),
|
||||||
|
m_running(false)
|
||||||
{
|
{
|
||||||
|
openDevice();
|
||||||
m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
|
m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
BladerfOutput::~BladerfOutput()
|
BladerfOutput::~BladerfOutput()
|
||||||
{
|
{
|
||||||
if (m_dev != 0)
|
if (m_running) stop();
|
||||||
{
|
closeDevice();
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_deviceAPI->setBuddySharedPtr(0);
|
m_deviceAPI->setBuddySharedPtr(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BladerfOutput::start(int device)
|
bool BladerfOutput::openDevice()
|
||||||
{
|
{
|
||||||
// QMutexLocker mutexLocker(&m_mutex);
|
|
||||||
|
|
||||||
if (m_dev != 0)
|
if (m_dev != 0)
|
||||||
{
|
{
|
||||||
stop();
|
closeDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
@ -115,47 +112,52 @@ bool BladerfOutput::start(int device)
|
|||||||
if ((res = bladerf_sync_config(m_dev, BLADERF_MODULE_TX, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
|
if ((res = bladerf_sync_config(m_dev, BLADERF_MODULE_TX, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
|
||||||
{
|
{
|
||||||
qCritical("BladerfOutput::start: bladerf_sync_config with return code %d", res);
|
qCritical("BladerfOutput::start: bladerf_sync_config with return code %d", res);
|
||||||
goto failed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, true)) < 0)
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, true)) < 0)
|
||||||
{
|
{
|
||||||
qCritical("BladerfOutput::start: bladerf_enable_module with return code %d", res);
|
qCritical("BladerfOutput::start: bladerf_enable_module with return code %d", res);
|
||||||
goto failed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BladerfOutput::start(int device)
|
||||||
|
{
|
||||||
|
// QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
|
||||||
|
if (!m_dev) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_running) stop();
|
||||||
|
|
||||||
if((m_bladerfThread = new BladerfOutputThread(m_dev, &m_sampleSourceFifo)) == 0)
|
if((m_bladerfThread = new BladerfOutputThread(m_dev, &m_sampleSourceFifo)) == 0)
|
||||||
{
|
{
|
||||||
qFatal("BladerfOutput::start: out of memory");
|
qFatal("BladerfOutput::start: out of memory");
|
||||||
goto failed;
|
stop();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mutexLocker.unlock();
|
// mutexLocker.unlock();
|
||||||
applySettings(m_settings, true);
|
applySettings(m_settings, true);
|
||||||
|
|
||||||
|
m_bladerfThread->setLog2Interpolation(m_settings.m_log2Interp);
|
||||||
|
|
||||||
m_bladerfThread->startWork();
|
m_bladerfThread->startWork();
|
||||||
|
|
||||||
qDebug("BladerfOutput::start: started");
|
qDebug("BladerfOutput::start: started");
|
||||||
|
m_running = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
failed:
|
|
||||||
stop();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BladerfOutput::stop()
|
void BladerfOutput::closeDevice()
|
||||||
{
|
{
|
||||||
// QMutexLocker mutexLocker(&m_mutex);
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if(m_bladerfThread != 0)
|
|
||||||
{
|
|
||||||
m_bladerfThread->stopWork();
|
|
||||||
delete m_bladerfThread;
|
|
||||||
m_bladerfThread = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, false)) < 0)
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, false)) < 0)
|
||||||
{
|
{
|
||||||
qCritical("BladerfOutput::stop: bladerf_enable_module with return code %d", res);
|
qCritical("BladerfOutput::stop: bladerf_enable_module with return code %d", res);
|
||||||
@ -199,6 +201,19 @@ void BladerfOutput::stop()
|
|||||||
m_dev = 0;
|
m_dev = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BladerfOutput::stop()
|
||||||
|
{
|
||||||
|
// QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
if (m_bladerfThread != 0)
|
||||||
|
{
|
||||||
|
m_bladerfThread->stopWork();
|
||||||
|
delete m_bladerfThread;
|
||||||
|
m_bladerfThread = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_running = false;
|
||||||
|
}
|
||||||
|
|
||||||
const QString& BladerfOutput::getDeviceDescription() const
|
const QString& BladerfOutput::getDeviceDescription() const
|
||||||
{
|
{
|
||||||
return m_deviceDescription;
|
return m_deviceDescription;
|
||||||
|
@ -81,6 +81,8 @@ public:
|
|||||||
virtual bool handleMessage(const Message& message);
|
virtual bool handleMessage(const Message& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool openDevice();
|
||||||
|
void closeDevice();
|
||||||
bool applySettings(const BladeRFOutputSettings& settings, bool force);
|
bool applySettings(const BladeRFOutputSettings& settings, bool force);
|
||||||
|
|
||||||
DeviceSinkAPI *m_deviceAPI;
|
DeviceSinkAPI *m_deviceAPI;
|
||||||
@ -90,6 +92,7 @@ private:
|
|||||||
BladerfOutputThread* m_bladerfThread;
|
BladerfOutputThread* m_bladerfThread;
|
||||||
QString m_deviceDescription;
|
QString m_deviceDescription;
|
||||||
DeviceBladeRFParams m_sharedParams;
|
DeviceBladeRFParams m_sharedParams;
|
||||||
|
bool m_running;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDE_BLADERFOUTPUT_H
|
#endif // INCLUDE_BLADERFOUTPUT_H
|
||||||
|
Loading…
Reference in New Issue
Block a user