mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-15 12:51:49 -05:00
BladeRF input: refactoring: device open close moved in the constructor and destructor respectively of the input object
This commit is contained in:
parent
527b5ef2f5
commit
5dd934320c
@ -37,28 +37,25 @@ BladerfInput::BladerfInput(DeviceSourceAPI *deviceAPI) :
|
|||||||
m_settings(),
|
m_settings(),
|
||||||
m_dev(0),
|
m_dev(0),
|
||||||
m_bladerfThread(0),
|
m_bladerfThread(0),
|
||||||
m_deviceDescription("BladeRFInput")
|
m_deviceDescription("BladeRFInput"),
|
||||||
|
m_running(false)
|
||||||
{
|
{
|
||||||
|
openDevice();
|
||||||
m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
|
m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
BladerfInput::~BladerfInput()
|
BladerfInput::~BladerfInput()
|
||||||
{
|
{
|
||||||
if (m_dev != 0)
|
if (m_running) stop();
|
||||||
{
|
closeDevice();
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_deviceAPI->setBuddySharedPtr(0);
|
m_deviceAPI->setBuddySharedPtr(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BladerfInput::start(int device)
|
bool BladerfInput::openDevice()
|
||||||
{
|
{
|
||||||
// QMutexLocker mutexLocker(&m_mutex);
|
|
||||||
|
|
||||||
if (m_dev != 0)
|
if (m_dev != 0)
|
||||||
{
|
{
|
||||||
stop();
|
closeDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
@ -110,70 +107,56 @@ bool BladerfInput::start(int device)
|
|||||||
m_sharedParams.m_dev = m_dev;
|
m_sharedParams.m_dev = m_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ((m_dev = open_bladerf_from_serial(0)) == 0) // TODO: fix; Open first available device as there is no proper handling for multiple devices
|
|
||||||
// {
|
|
||||||
// qCritical("could not open BladeRF");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fpga_loaded = bladerf_is_fpga_configured(m_dev);
|
|
||||||
//
|
|
||||||
// if (fpga_loaded < 0)
|
|
||||||
// {
|
|
||||||
// qCritical("Failed to check FPGA state: %s",
|
|
||||||
// bladerf_strerror(fpga_loaded));
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// else if (fpga_loaded == 0)
|
|
||||||
// {
|
|
||||||
// qCritical("The device's FPGA is not loaded.");
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// TODO: adjust USB transfer data according to sample rate
|
// TODO: adjust USB transfer data according to sample rate
|
||||||
if ((res = bladerf_sync_config(m_dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
|
if ((res = bladerf_sync_config(m_dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
|
||||||
{
|
{
|
||||||
qCritical("BladerfInput::start: bladerf_sync_config with return code %d", res);
|
qCritical("BladerfInput::start: bladerf_sync_config with return code %d", res);
|
||||||
goto failed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, true)) < 0)
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, true)) < 0)
|
||||||
{
|
{
|
||||||
qCritical("BladerfInput::start: bladerf_enable_module with return code %d", res);
|
qCritical("BladerfInput::start: bladerf_enable_module with return code %d", res);
|
||||||
goto failed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((m_bladerfThread = new BladerfInputThread(m_dev, &m_sampleFifo)) == NULL) {
|
return true;
|
||||||
qFatal("BladerfInput::start: out of memory");
|
|
||||||
goto failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BladerfInput::start(int device)
|
||||||
|
{
|
||||||
|
// QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
|
||||||
|
if (!m_dev) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_running) stop();
|
||||||
|
|
||||||
|
if((m_bladerfThread = new BladerfInputThread(m_dev, &m_sampleFifo)) == 0) {
|
||||||
|
qFatal("BladerfInput::start: out of memory");
|
||||||
|
stop();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim);
|
||||||
|
m_bladerfThread->setFcPos((int) m_settings.m_fcPos);
|
||||||
|
|
||||||
m_bladerfThread->startWork();
|
m_bladerfThread->startWork();
|
||||||
|
|
||||||
// mutexLocker.unlock();
|
// mutexLocker.unlock();
|
||||||
applySettings(m_settings, true);
|
applySettings(m_settings, true);
|
||||||
|
|
||||||
qDebug("BladerfInput::startInput: started");
|
qDebug("BladerfInput::startInput: started");
|
||||||
|
m_running = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
failed:
|
|
||||||
stop();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BladerfInput::stop()
|
void BladerfInput::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_RX, false)) < 0)
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, false)) < 0)
|
||||||
{
|
{
|
||||||
qCritical("BladerfInput::stop: bladerf_enable_module with return code %d", res);
|
qCritical("BladerfInput::stop: bladerf_enable_module with return code %d", res);
|
||||||
@ -209,12 +192,20 @@ void BladerfInput::stop()
|
|||||||
|
|
||||||
m_sharedParams.m_dev = 0;
|
m_sharedParams.m_dev = 0;
|
||||||
m_dev = 0;
|
m_dev = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// if(m_dev != 0)
|
void BladerfInput::stop()
|
||||||
// {
|
{
|
||||||
// bladerf_close(m_dev);
|
// QMutexLocker mutexLocker(&m_mutex);
|
||||||
// m_dev = 0;
|
|
||||||
// }
|
if(m_bladerfThread != 0)
|
||||||
|
{
|
||||||
|
m_bladerfThread->stopWork();
|
||||||
|
delete m_bladerfThread;
|
||||||
|
m_bladerfThread = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString& BladerfInput::getDeviceDescription() const
|
const QString& BladerfInput::getDeviceDescription() const
|
||||||
@ -458,7 +449,7 @@ bool BladerfInput::applySettings(const BladeRFInputSettings& settings, bool forc
|
|||||||
m_settings.m_log2Decim = settings.m_log2Decim;
|
m_settings.m_log2Decim = settings.m_log2Decim;
|
||||||
forwardChange = true;
|
forwardChange = true;
|
||||||
|
|
||||||
if(m_dev != 0)
|
if (m_bladerfThread != 0)
|
||||||
{
|
{
|
||||||
m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim);
|
m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim);
|
||||||
qDebug() << "BladerfInput::applySettings: set decimation to " << (1<<m_settings.m_log2Decim);
|
qDebug() << "BladerfInput::applySettings: set decimation to " << (1<<m_settings.m_log2Decim);
|
||||||
@ -469,7 +460,7 @@ bool BladerfInput::applySettings(const BladeRFInputSettings& settings, bool forc
|
|||||||
{
|
{
|
||||||
m_settings.m_fcPos = settings.m_fcPos;
|
m_settings.m_fcPos = settings.m_fcPos;
|
||||||
|
|
||||||
if(m_dev != 0)
|
if (m_bladerfThread != 0)
|
||||||
{
|
{
|
||||||
m_bladerfThread->setFcPos((int) m_settings.m_fcPos);
|
m_bladerfThread->setFcPos((int) m_settings.m_fcPos);
|
||||||
qDebug() << "BladerfInput::applySettings: set fc pos (enum) to " << (int) m_settings.m_fcPos;
|
qDebug() << "BladerfInput::applySettings: set fc pos (enum) to " << (int) m_settings.m_fcPos;
|
||||||
|
@ -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 BladeRFInputSettings& settings, bool force);
|
bool applySettings(const BladeRFInputSettings& settings, bool force);
|
||||||
bladerf_lna_gain getLnaGain(int lnaGain);
|
bladerf_lna_gain getLnaGain(int lnaGain);
|
||||||
// struct bladerf *open_bladerf_from_serial(const char *serial);
|
// struct bladerf *open_bladerf_from_serial(const char *serial);
|
||||||
@ -92,6 +94,7 @@ private:
|
|||||||
BladerfInputThread* m_bladerfThread;
|
BladerfInputThread* m_bladerfThread;
|
||||||
QString m_deviceDescription;
|
QString m_deviceDescription;
|
||||||
DeviceBladeRFParams m_sharedParams;
|
DeviceBladeRFParams m_sharedParams;
|
||||||
|
bool m_running;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDE_BLADERFINPUT_H
|
#endif // INCLUDE_BLADERFINPUT_H
|
||||||
|
Loading…
Reference in New Issue
Block a user