1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

BladeRF: Rx/Tx opem/close new style

This commit is contained in:
f4exb 2017-04-13 23:40:14 +02:00
parent 72a2fd9065
commit afaf3428f5
3 changed files with 26 additions and 92 deletions

View File

@ -63,8 +63,8 @@ bool BladerfOutput::openDevice()
if (m_deviceAPI->getSourceBuddies().size() > 0)
{
DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[0];
DeviceBladeRFParams *buddySharedParams = (DeviceBladeRFParams *) buddy->getBuddySharedPtr();
DeviceSourceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0];
DeviceBladeRFParams *buddySharedParams = (DeviceBladeRFParams *) sourceBuddy->getBuddySharedPtr();
if (buddySharedParams == 0)
{
@ -72,33 +72,17 @@ bool BladerfOutput::openDevice()
return false;
}
if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::StRunning) // Rx side is running so it must have device ownership
if (buddySharedParams->m_dev == 0) // device is not opened by buddy
{
qDebug("BladerfOutput::start: Rx side is running");
if ((m_dev = buddySharedParams->m_dev) == 0) // get device handle from Rx but do not take ownership
{
qCritical("BladerfOutput::start: could not get BladeRF handle from buddy");
return false;
}
qCritical("BladerfOutput::start: could not get BladeRF handle from buddy");
return false;
}
else // Rx is not running so Tx opens device and takes ownership
{
qDebug("BladerfOutput::start: Rx side is not running");
if (!DeviceBladeRF::open_bladerf(&m_dev, 0)) // TODO: fix; Open first available device as there is no proper handling for multiple devices
{
qCritical("BladerfOutput::start: could not open BladeRF");
return false;
}
m_sharedParams.m_dev = m_dev;
}
m_sharedParams = *(buddySharedParams); // copy parameters from buddy
m_dev = m_sharedParams.m_dev; // get BladeRF handle
}
else // No Rx part open so Tx opens device and takes ownership
else
{
qDebug("BladerfOutput::start: Rx side is not open");
if (!DeviceBladeRF::open_bladerf(&m_dev, 0)) // TODO: fix; Open first available device as there is no proper handling for multiple devices
{
qCritical("BladerfOutput::start: could not open BladeRF");
@ -160,38 +144,14 @@ void BladerfOutput::closeDevice()
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::closeDevice: bladerf_enable_module with return code %d", res);
}
if (m_deviceAPI->getSourceBuddies().size() > 0)
if (m_deviceAPI->getSourceBuddies().size() == 0)
{
DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[0];
DeviceBladeRFParams *buddySharedParams = (DeviceBladeRFParams *) buddy->getBuddySharedPtr();
qDebug("BladerfOutput::closeDevice: closing device since Rx side is not open");
if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::StRunning) // Rx side running
{
qDebug("BladerfOutput::stop: Rx side is running");
if ((m_sharedParams.m_dev != 0) && (buddySharedParams->m_dev == 0)) // Tx has the ownership but not the Rx
{
buddySharedParams->m_dev = m_dev; // transfer ownership
}
}
else // Rx is not running so Tx must have the ownership
{
qDebug("BladerfOutput::stop: Rx side is not running");
if(m_dev != 0) // close BladeRF
{
bladerf_close(m_dev);
}
}
}
else // No Rx part open
{
qDebug("BladerfOutput::stop: Rx side is not open");
if(m_dev != 0) // close BladeRF
if (m_dev != 0) // close BladeRF
{
bladerf_close(m_dev);
}

View File

@ -62,41 +62,31 @@ bool BladerfInput::openDevice()
if (!m_sampleFifo.setSize(96000 * 4))
{
qCritical("BladerfInput::start: could not allocate SampleFifo");
qCritical("BladerfInput::openDevice: could not allocate SampleFifo");
return false;
}
if (m_deviceAPI->getSinkBuddies().size() > 0)
{
DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[0];
DeviceBladeRFParams *buddySharedParams = (DeviceBladeRFParams *) buddy->getBuddySharedPtr();
DeviceSinkAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0];
DeviceBladeRFParams *buddySharedParams = (DeviceBladeRFParams *) sinkBuddy->getBuddySharedPtr();
if (buddySharedParams == 0)
{
qCritical("BladerfInput::start: could not get shared parameters from buddy");
qCritical("BladerfInput::openDevice: could not get shared parameters from buddy");
return false;
}
if (buddy->getDeviceSinkEngine()->state() == DSPDeviceSinkEngine::StRunning) // Tx side is running so it must have device ownership
if (buddySharedParams->m_dev == 0) // device is not opened by buddy
{
if ((m_dev = buddySharedParams->m_dev) == 0) // get device handle from Tx but do not take ownership
{
qCritical("BladerfInput::start: could not get BladeRF handle from buddy");
return false;
}
qCritical("BladerfInput::openDevice: could not get BladeRF handle from buddy");
return false;
}
else // Tx is not running so Rx opens device and takes ownership
{
if (!DeviceBladeRF::open_bladerf(&m_dev, 0)) // TODO: fix; Open first available device as there is no proper handling for multiple devices
{
qCritical("BladerfInput::start: could not open BladeRF");
return false;
}
m_sharedParams.m_dev = m_dev;
}
m_sharedParams = *(buddySharedParams); // copy parameters from buddy
m_dev = m_sharedParams.m_dev; // get BladeRF handle
}
else // No Tx part open so Rx opens device and takes ownership
else
{
if (!DeviceBladeRF::open_bladerf(&m_dev, 0)) // TODO: fix; Open first available device as there is no proper handling for multiple devices
{
@ -162,28 +152,10 @@ void BladerfInput::closeDevice()
qCritical("BladerfInput::stop: bladerf_enable_module with return code %d", res);
}
if (m_deviceAPI->getSinkBuddies().size() > 0)
if (m_deviceAPI->getSinkBuddies().size() == 0)
{
DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[0];
DeviceBladeRFParams *buddySharedParams = (DeviceBladeRFParams *) buddy->getBuddySharedPtr();
qDebug("BladerfInput::closeDevice: closing device since Tx side is not open");
if (buddy->getDeviceSinkEngine()->state() == DSPDeviceSinkEngine::StRunning) // Tx side running
{
if ((m_sharedParams.m_dev != 0) && (buddySharedParams->m_dev == 0)) // Rx has the ownership but not the Tx
{
buddySharedParams->m_dev = m_dev; // transfer ownership
}
}
else // Tx is not running so Rx must have the ownership
{
if(m_dev != 0) // close BladeRF
{
bladerf_close(m_dev);
}
}
}
else // No Tx part open
{
if(m_dev != 0) // close BladeRF
{
bladerf_close(m_dev);

View File

@ -104,6 +104,8 @@ void LimeSDRInput::closeDevice()
{
m_deviceParams.close();
}
m_deviceParams.m_dev = 0;
}
bool LimeSDRInput::start(int device)