mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 17:58:43 -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_dev(0),
|
||||
m_bladerfThread(0),
|
||||
m_deviceDescription("BladeRFOutput")
|
||||
m_deviceDescription("BladeRFOutput"),
|
||||
m_running(false)
|
||||
{
|
||||
openDevice();
|
||||
m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
|
||||
}
|
||||
|
||||
BladerfOutput::~BladerfOutput()
|
||||
{
|
||||
if (m_dev != 0)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
if (m_running) stop();
|
||||
closeDevice();
|
||||
m_deviceAPI->setBuddySharedPtr(0);
|
||||
}
|
||||
|
||||
bool BladerfOutput::start(int device)
|
||||
bool BladerfOutput::openDevice()
|
||||
{
|
||||
// QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if (m_dev != 0)
|
||||
{
|
||||
stop();
|
||||
closeDevice();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
qFatal("BladerfOutput::start: out of memory");
|
||||
goto failed;
|
||||
stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
// mutexLocker.unlock();
|
||||
applySettings(m_settings, true);
|
||||
|
||||
m_bladerfThread->setLog2Interpolation(m_settings.m_log2Interp);
|
||||
|
||||
m_bladerfThread->startWork();
|
||||
|
||||
qDebug("BladerfOutput::start: started");
|
||||
m_running = true;
|
||||
|
||||
return true;
|
||||
|
||||
failed:
|
||||
stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
void BladerfOutput::stop()
|
||||
void BladerfOutput::closeDevice()
|
||||
{
|
||||
// QMutexLocker mutexLocker(&m_mutex);
|
||||
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)
|
||||
{
|
||||
qCritical("BladerfOutput::stop: bladerf_enable_module with return code %d", res);
|
||||
@ -199,6 +201,19 @@ void BladerfOutput::stop()
|
||||
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
|
||||
{
|
||||
return m_deviceDescription;
|
||||
|
@ -81,6 +81,8 @@ public:
|
||||
virtual bool handleMessage(const Message& message);
|
||||
|
||||
private:
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
bool applySettings(const BladeRFOutputSettings& settings, bool force);
|
||||
|
||||
DeviceSinkAPI *m_deviceAPI;
|
||||
@ -90,6 +92,7 @@ private:
|
||||
BladerfOutputThread* m_bladerfThread;
|
||||
QString m_deviceDescription;
|
||||
DeviceBladeRFParams m_sharedParams;
|
||||
bool m_running;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_BLADERFOUTPUT_H
|
||||
|
Loading…
Reference in New Issue
Block a user