1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 00:18:37 -05:00

BladeRF output: refactoring: device open close moved in the constructor and destructor respectively of the input object

This commit is contained in:
f4exb 2017-04-13 21:26:36 +02:00
parent e71e75126e
commit 72a2fd9065
2 changed files with 51 additions and 33 deletions

View File

@ -36,31 +36,28 @@ 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)
{
closeDevice();
}
if (m_dev != 0)
{
stop();
}
int res;
int res;
m_sampleSourceFifo.resize(m_settings.m_devSampleRate/(1<<(m_settings.m_log2Interp <= 4 ? m_settings.m_log2Interp : 4)));
@ -114,48 +111,53 @@ bool BladerfOutput::start(int device)
// TODO: adjust USB transfer data according to sample rate
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;
qCritical("BladerfOutput::start: bladerf_sync_config with return code %d", res);
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;
qCritical("BladerfOutput::start: bladerf_enable_module with return code %d", res);
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;
return true;
}
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;

View File

@ -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