mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-05 14:47:50 -04:00
SoapySDR support: output: open and close
This commit is contained in:
parent
124af5a7b4
commit
6cede7a667
@ -15,11 +15,18 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "util/simpleserializer.h"
|
#include "util/simpleserializer.h"
|
||||||
|
#include "dsp/dspcommands.h"
|
||||||
|
#include "dsp/dspengine.h"
|
||||||
|
#include "device/devicesinkapi.h"
|
||||||
|
#include "device/devicesourceapi.h"
|
||||||
|
#include "soapysdr/devicesoapysdr.h"
|
||||||
|
|
||||||
#include "soapysdroutput.h"
|
#include "soapysdroutput.h"
|
||||||
|
|
||||||
SoapySDROutput::SoapySDROutput(DeviceSinkAPI *deviceAPI __attribute__((unused))) :
|
SoapySDROutput::SoapySDROutput(DeviceSinkAPI *deviceAPI) :
|
||||||
m_deviceDescription("SoapySDROutput")
|
m_deviceAPI(deviceAPI),
|
||||||
|
m_deviceDescription("SoapySDROutput"),
|
||||||
|
m_running(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +39,105 @@ void SoapySDROutput::destroy()
|
|||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SoapySDROutput::openDevice()
|
||||||
|
{
|
||||||
|
m_sampleSourceFifo.resize(96000 * 4);
|
||||||
|
|
||||||
|
// look for Tx buddies and get reference to the device object
|
||||||
|
if (m_deviceAPI->getSinkBuddies().size() > 0) // look sink sibling first
|
||||||
|
{
|
||||||
|
qDebug("SoapySDROutput::openDevice: look in Tx buddies");
|
||||||
|
|
||||||
|
DeviceSinkAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0];
|
||||||
|
DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sinkBuddy->getBuddySharedPtr();
|
||||||
|
|
||||||
|
if (deviceSoapySDRShared == 0)
|
||||||
|
{
|
||||||
|
qCritical("SoapySDROutput::openDevice: the sink buddy shared pointer is null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoapySDR::Device *device = deviceSoapySDRShared->m_device;
|
||||||
|
|
||||||
|
if (device == 0)
|
||||||
|
{
|
||||||
|
qCritical("SoapySDROutput::openDevice: cannot get device pointer from Tx buddy");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deviceShared.m_device = device;
|
||||||
|
}
|
||||||
|
// look for Rx buddies and get reference to the device object
|
||||||
|
else if (m_deviceAPI->getSourceBuddies().size() > 0) // then source
|
||||||
|
{
|
||||||
|
qDebug("SoapySDROutput::openDevice: look in Rx buddies");
|
||||||
|
|
||||||
|
DeviceSourceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0];
|
||||||
|
DeviceSoapySDRShared *deviceSoapySDRShared = (DeviceSoapySDRShared*) sourceBuddy->getBuddySharedPtr();
|
||||||
|
|
||||||
|
if (deviceSoapySDRShared == 0)
|
||||||
|
{
|
||||||
|
qCritical("SoapySDROutput::openDevice: the source buddy shared pointer is null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoapySDR::Device *device = deviceSoapySDRShared->m_device;
|
||||||
|
|
||||||
|
if (device == 0)
|
||||||
|
{
|
||||||
|
qCritical("SoapySDROutput::openDevice: cannot get device pointer from Rx buddy");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deviceShared.m_device = device;
|
||||||
|
}
|
||||||
|
// There are no buddies then create the first BladeRF2 device
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug("SoapySDROutput::openDevice: open device here");
|
||||||
|
DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance();
|
||||||
|
m_deviceShared.m_device = deviceSoapySDR.openSoapySDR(m_deviceAPI->getSampleSinkSequence());
|
||||||
|
|
||||||
|
if (!m_deviceShared.m_device)
|
||||||
|
{
|
||||||
|
qCritical("SoapySDROutput::openDevice: cannot open SoapySDR device");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deviceShared.m_channel = m_deviceAPI->getItemIndex(); // publicly allocate channel
|
||||||
|
m_deviceShared.m_sink = this;
|
||||||
|
m_deviceAPI->setBuddySharedPtr(&m_deviceShared); // propagate common parameters to API
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoapySDROutput::closeDevice()
|
||||||
|
{
|
||||||
|
if (m_deviceShared.m_device == 0) { // was never open
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_running) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (m_thread) { // stills own the thread => transfer to a buddy
|
||||||
|
// moveThreadToBuddy();
|
||||||
|
// }
|
||||||
|
|
||||||
|
m_deviceShared.m_channel = -1; // publicly release channel
|
||||||
|
m_deviceShared.m_sink = 0;
|
||||||
|
|
||||||
|
// No buddies so effectively close the device
|
||||||
|
|
||||||
|
if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0))
|
||||||
|
{
|
||||||
|
DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance();
|
||||||
|
deviceSoapySDR.closeSoapySdr(m_deviceShared.m_device);
|
||||||
|
m_deviceShared.m_device = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SoapySDROutput::init()
|
void SoapySDROutput::init()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "dsp/devicesamplesink.h"
|
#include "dsp/devicesamplesink.h"
|
||||||
|
#include "soapysdr/devicesoapysdrshared.h"
|
||||||
|
|
||||||
class DeviceSinkAPI;
|
class DeviceSinkAPI;
|
||||||
|
|
||||||
@ -45,7 +46,13 @@ public:
|
|||||||
virtual bool handleMessage(const Message& message);
|
virtual bool handleMessage(const Message& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DeviceSinkAPI *m_deviceAPI;
|
||||||
QString m_deviceDescription;
|
QString m_deviceDescription;
|
||||||
|
DeviceSoapySDRShared m_deviceShared;
|
||||||
|
bool m_running;
|
||||||
|
|
||||||
|
bool openDevice();
|
||||||
|
void closeDevice();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user