mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-05 14:47:50 -04:00
Airspy: refactoring: device open close moved in the constructor and destructor respectively of the input object
This commit is contained in:
parent
0c972455da
commit
bb812b4b47
@ -38,7 +38,10 @@ AirspyGui::AirspyGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
|
|||||||
m_sampleSource(0),
|
m_sampleSource(0),
|
||||||
m_lastEngineState((DSPDeviceSourceEngine::State)-1)
|
m_lastEngineState((DSPDeviceSourceEngine::State)-1)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
m_sampleSource = new AirspyInput(m_deviceAPI);
|
||||||
|
m_deviceAPI->setSource(m_sampleSource);
|
||||||
|
|
||||||
|
ui->setupUi(this);
|
||||||
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
|
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
|
||||||
ui->centerFrequency->setValueRange(7, 24000U, 1900000U);
|
ui->centerFrequency->setValueRange(7, 24000U, 1900000U);
|
||||||
|
|
||||||
@ -48,11 +51,9 @@ AirspyGui::AirspyGui(DeviceSourceAPI *deviceAPI, QWidget* parent) :
|
|||||||
|
|
||||||
displaySettings();
|
displaySettings();
|
||||||
|
|
||||||
m_sampleSource = new AirspyInput(m_deviceAPI);
|
|
||||||
m_rates = ((AirspyInput*) m_sampleSource)->getSampleRates();
|
m_rates = ((AirspyInput*) m_sampleSource)->getSampleRates();
|
||||||
displaySampleRates();
|
displaySampleRates();
|
||||||
connect(m_sampleSource->getOutputMessageQueueToGUI(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
|
connect(m_sampleSource->getOutputMessageQueueToGUI(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
|
||||||
m_deviceAPI->setSource(m_sampleSource);
|
|
||||||
|
|
||||||
char recFileNameCStr[30];
|
char recFileNameCStr[30];
|
||||||
sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID());
|
sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID());
|
||||||
@ -123,17 +124,18 @@ bool AirspyGui::deserialize(const QByteArray& data)
|
|||||||
|
|
||||||
bool AirspyGui::handleMessage(const Message& message)
|
bool AirspyGui::handleMessage(const Message& message)
|
||||||
{
|
{
|
||||||
if (AirspyInput::MsgReportAirspy::match(message))
|
return false;
|
||||||
{
|
// if (AirspyInput::MsgReportAirspy::match(message))
|
||||||
qDebug() << "AirspyGui::handleMessage: MsgReportAirspy";
|
// {
|
||||||
m_rates = ((AirspyInput::MsgReportAirspy&) message).getSampleRates();
|
// qDebug() << "AirspyGui::handleMessage: MsgReportAirspy";
|
||||||
displaySampleRates();
|
// m_rates = ((AirspyInput::MsgReportAirspy&) message).getSampleRates();
|
||||||
return true;
|
// displaySampleRates();
|
||||||
}
|
// return true;
|
||||||
else
|
// }
|
||||||
{
|
// else
|
||||||
return false;
|
// {
|
||||||
}
|
// return false;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void AirspyGui::handleDSPMessages()
|
void AirspyGui::handleDSPMessages()
|
||||||
|
@ -28,99 +28,114 @@
|
|||||||
#include "airspythread.h"
|
#include "airspythread.h"
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(AirspyInput::MsgConfigureAirspy, Message)
|
MESSAGE_CLASS_DEFINITION(AirspyInput::MsgConfigureAirspy, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(AirspyInput::MsgReportAirspy, Message)
|
//MESSAGE_CLASS_DEFINITION(AirspyInput::MsgReportAirspy, Message)
|
||||||
|
|
||||||
AirspyInput::AirspyInput(DeviceSourceAPI *deviceAPI) :
|
AirspyInput::AirspyInput(DeviceSourceAPI *deviceAPI) :
|
||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
m_settings(),
|
m_settings(),
|
||||||
m_dev(0),
|
m_dev(0),
|
||||||
m_airspyThread(0),
|
m_airspyThread(0),
|
||||||
m_deviceDescription("Airspy")
|
m_deviceDescription("Airspy"),
|
||||||
|
m_running(false)
|
||||||
{
|
{
|
||||||
m_sampleRates.push_back(10000000);
|
openDevice();
|
||||||
m_sampleRates.push_back(2500000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AirspyInput::~AirspyInput()
|
AirspyInput::~AirspyInput()
|
||||||
{
|
{
|
||||||
stop();
|
if (m_running) stop();
|
||||||
|
closeDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AirspyInput::openDevice()
|
||||||
|
{
|
||||||
|
if (m_dev != 0)
|
||||||
|
{
|
||||||
|
closeDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
airspy_error rc;
|
||||||
|
|
||||||
|
rc = (airspy_error) airspy_init();
|
||||||
|
|
||||||
|
if (rc != AIRSPY_SUCCESS)
|
||||||
|
{
|
||||||
|
qCritical("AirspyInput::start: failed to initiate Airspy library %s", airspy_error_name(rc));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_sampleFifo.setSize(1<<19))
|
||||||
|
{
|
||||||
|
qCritical("AirspyInput::start: could not allocate SampleFifo");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int device = m_deviceAPI->getSampleSourceSequence();
|
||||||
|
|
||||||
|
if ((m_dev = open_airspy_from_sequence(device)) == 0)
|
||||||
|
{
|
||||||
|
qCritical("AirspyInput::start: could not open Airspy #%d", device);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef LIBAIRSPY_DYN_RATES
|
||||||
|
uint32_t nbSampleRates;
|
||||||
|
uint32_t *sampleRates;
|
||||||
|
|
||||||
|
airspy_get_samplerates(m_dev, &nbSampleRates, 0);
|
||||||
|
|
||||||
|
sampleRates = new uint32_t[nbSampleRates];
|
||||||
|
|
||||||
|
airspy_get_samplerates(m_dev, sampleRates, nbSampleRates);
|
||||||
|
|
||||||
|
if (nbSampleRates == 0)
|
||||||
|
{
|
||||||
|
qCritical("AirspyInput::start: could not obtain Airspy sample rates");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug("AirspyInput::start: %d sample rates", nbSampleRates);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_sampleRates.clear();
|
||||||
|
|
||||||
|
for (int i=0; i<nbSampleRates; i++)
|
||||||
|
{
|
||||||
|
m_sampleRates.push_back(sampleRates[i]);
|
||||||
|
qDebug("AirspyInput::start: sampleRates[%d] = %u Hz", i, sampleRates[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] sampleRates;
|
||||||
|
#else
|
||||||
|
qDebug("AirspyInput::start: detault rates");
|
||||||
|
m_sampleRates.clear();
|
||||||
|
m_sampleRates.push_back(10000000);
|
||||||
|
m_sampleRates.push_back(2500000);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// MsgReportAirspy *message = MsgReportAirspy::create(m_sampleRates);
|
||||||
|
// getOutputMessageQueueToGUI()->push(message);
|
||||||
|
|
||||||
|
rc = (airspy_error) airspy_set_sample_type(m_dev, AIRSPY_SAMPLE_INT16_IQ);
|
||||||
|
|
||||||
|
if (rc != AIRSPY_SUCCESS)
|
||||||
|
{
|
||||||
|
qCritical("AirspyInput::start: could not set sample type to INT16_IQ");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AirspyInput::start(int device)
|
bool AirspyInput::start(int device)
|
||||||
{
|
{
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
airspy_error rc;
|
|
||||||
|
|
||||||
rc = (airspy_error) airspy_init();
|
if (!m_dev) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (rc != AIRSPY_SUCCESS)
|
if (m_running) stop();
|
||||||
{
|
|
||||||
qCritical("AirspyInput::start: failed to initiate Airspy library %s", airspy_error_name(rc));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_dev != 0)
|
|
||||||
{
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_sampleFifo.setSize(1<<19))
|
|
||||||
{
|
|
||||||
qCritical("AirspyInput::start: could not allocate SampleFifo");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((m_dev = open_airspy_from_sequence(device)) == 0)
|
|
||||||
{
|
|
||||||
qCritical("AirspyInput::start: could not open Airspy #%d", device);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LIBAIRSPY_DYN_RATES
|
|
||||||
uint32_t nbSampleRates;
|
|
||||||
uint32_t *sampleRates;
|
|
||||||
|
|
||||||
airspy_get_samplerates(m_dev, &nbSampleRates, 0);
|
|
||||||
|
|
||||||
sampleRates = new uint32_t[nbSampleRates];
|
|
||||||
|
|
||||||
airspy_get_samplerates(m_dev, sampleRates, nbSampleRates);
|
|
||||||
|
|
||||||
if (nbSampleRates == 0)
|
|
||||||
{
|
|
||||||
qCritical("AirspyInput::start: could not obtain Airspy sample rates");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug("AirspyInput::start: %d sample rates", nbSampleRates);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sampleRates.clear();
|
|
||||||
|
|
||||||
for (int i=0; i<nbSampleRates; i++)
|
|
||||||
{
|
|
||||||
m_sampleRates.push_back(sampleRates[i]);
|
|
||||||
qDebug("AirspyInput::start: sampleRates[%d] = %u Hz", i, sampleRates[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] sampleRates;
|
|
||||||
#else
|
|
||||||
qDebug("AirspyInput::start: detault rates");
|
|
||||||
m_sampleRates.clear();
|
|
||||||
m_sampleRates.push_back(10000000);
|
|
||||||
m_sampleRates.push_back(2500000);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MsgReportAirspy *message = MsgReportAirspy::create(m_sampleRates);
|
|
||||||
getOutputMessageQueueToGUI()->push(message);
|
|
||||||
|
|
||||||
rc = (airspy_error) airspy_set_sample_type(m_dev, AIRSPY_SAMPLE_INT16_IQ);
|
|
||||||
|
|
||||||
if (rc != AIRSPY_SUCCESS)
|
|
||||||
{
|
|
||||||
qCritical("AirspyInput::start: could not set sample type to INT16_IQ");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((m_airspyThread = new AirspyThread(m_dev, &m_sampleFifo)) == 0)
|
if((m_airspyThread = new AirspyThread(m_dev, &m_sampleFifo)) == 0)
|
||||||
{
|
{
|
||||||
@ -136,30 +151,37 @@ bool AirspyInput::start(int device)
|
|||||||
applySettings(m_settings, true);
|
applySettings(m_settings, true);
|
||||||
|
|
||||||
qDebug("AirspyInput::startInput: started");
|
qDebug("AirspyInput::startInput: started");
|
||||||
|
m_running = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AirspyInput::closeDevice()
|
||||||
|
{
|
||||||
|
if (m_dev != 0)
|
||||||
|
{
|
||||||
|
airspy_stop_rx(m_dev);
|
||||||
|
airspy_close(m_dev);
|
||||||
|
m_dev = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_deviceDescription.clear();
|
||||||
|
airspy_exit();
|
||||||
|
}
|
||||||
|
|
||||||
void AirspyInput::stop()
|
void AirspyInput::stop()
|
||||||
{
|
{
|
||||||
qDebug("AirspyInput::stop");
|
qDebug("AirspyInput::stop");
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
|
|
||||||
if(m_airspyThread != 0)
|
if (m_airspyThread != 0)
|
||||||
{
|
{
|
||||||
m_airspyThread->stopWork();
|
m_airspyThread->stopWork();
|
||||||
delete m_airspyThread;
|
delete m_airspyThread;
|
||||||
m_airspyThread = 0;
|
m_airspyThread = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_dev != 0)
|
m_running = false;
|
||||||
{
|
|
||||||
airspy_stop_rx(m_dev);
|
|
||||||
airspy_close(m_dev);
|
|
||||||
m_dev = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
airspy_exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString& AirspyInput::getDeviceDescription() const
|
const QString& AirspyInput::getDeviceDescription() const
|
||||||
|
@ -48,25 +48,25 @@ public:
|
|||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
class MsgReportAirspy : public Message {
|
// class MsgReportAirspy : public Message {
|
||||||
MESSAGE_CLASS_DECLARATION
|
// MESSAGE_CLASS_DECLARATION
|
||||||
|
//
|
||||||
public:
|
// public:
|
||||||
const std::vector<uint32_t>& getSampleRates() const { return m_sampleRates; }
|
// const std::vector<uint32_t>& getSampleRates() const { return m_sampleRates; }
|
||||||
|
//
|
||||||
static MsgReportAirspy* create(const std::vector<uint32_t>& sampleRates)
|
// static MsgReportAirspy* create(const std::vector<uint32_t>& sampleRates)
|
||||||
{
|
// {
|
||||||
return new MsgReportAirspy(sampleRates);
|
// return new MsgReportAirspy(sampleRates);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
protected:
|
// protected:
|
||||||
std::vector<uint32_t> m_sampleRates;
|
// std::vector<uint32_t> m_sampleRates;
|
||||||
|
//
|
||||||
MsgReportAirspy(const std::vector<uint32_t>& sampleRates) :
|
// MsgReportAirspy(const std::vector<uint32_t>& sampleRates) :
|
||||||
Message(),
|
// Message(),
|
||||||
m_sampleRates(sampleRates)
|
// m_sampleRates(sampleRates)
|
||||||
{ }
|
// { }
|
||||||
};
|
// };
|
||||||
|
|
||||||
AirspyInput(DeviceSourceAPI *deviceAPI);
|
AirspyInput(DeviceSourceAPI *deviceAPI);
|
||||||
virtual ~AirspyInput();
|
virtual ~AirspyInput();
|
||||||
@ -82,6 +82,8 @@ public:
|
|||||||
virtual bool handleMessage(const Message& message);
|
virtual bool handleMessage(const Message& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool openDevice();
|
||||||
|
void closeDevice();
|
||||||
bool applySettings(const AirspySettings& settings, bool force);
|
bool applySettings(const AirspySettings& settings, bool force);
|
||||||
struct airspy_device *open_airspy_from_sequence(int sequence);
|
struct airspy_device *open_airspy_from_sequence(int sequence);
|
||||||
void setCenterFrequency(quint64 freq);
|
void setCenterFrequency(quint64 freq);
|
||||||
@ -93,6 +95,7 @@ private:
|
|||||||
AirspyThread* m_airspyThread;
|
AirspyThread* m_airspyThread;
|
||||||
QString m_deviceDescription;
|
QString m_deviceDescription;
|
||||||
std::vector<uint32_t> m_sampleRates;
|
std::vector<uint32_t> m_sampleRates;
|
||||||
|
bool m_running;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDE_AIRSPYINPUT_H
|
#endif // INCLUDE_AIRSPYINPUT_H
|
||||||
|
@ -44,7 +44,6 @@ RTLSDRInput::RTLSDRInput(DeviceSourceAPI *deviceAPI) :
|
|||||||
|
|
||||||
RTLSDRInput::~RTLSDRInput()
|
RTLSDRInput::~RTLSDRInput()
|
||||||
{
|
{
|
||||||
//stop();
|
|
||||||
if (m_running) stop();
|
if (m_running) stop();
|
||||||
closeDevice();
|
closeDevice();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user