1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-11-29 03:14:16 -05:00

BladeRF2 and Interferometer: MO operations fixes

This commit is contained in:
f4exb 2019-10-20 20:05:22 +02:00
parent d0b64daa4a
commit 235efdceec
7 changed files with 110 additions and 92 deletions

View File

@ -84,13 +84,13 @@ void Interferometer::setScopeSink(BasebandSampleSink *scopeSink)
m_sink->setScopeSink(scopeSink); m_sink->setScopeSink(scopeSink);
} }
void Interferometer::start() void Interferometer::startSinks()
{ {
m_sink->reset(); m_sink->reset();
m_thread->start(); m_thread->start();
} }
void Interferometer::stop() void Interferometer::stopSinks()
{ {
m_thread->exit(); m_thread->exit();
m_thread->wait(); m_thread->wait();

View File

@ -89,8 +89,10 @@ public:
virtual ~Interferometer(); virtual ~Interferometer();
virtual void destroy() { delete this; } virtual void destroy() { delete this; }
virtual void start(); //!< thread start() virtual void startSinks(); //!< thread start()
virtual void stop(); //!< thread exit() and wait() virtual void stopSinks(); //!< thread exit() and wait()
virtual void startSources() {}
virtual void stopSources() {}
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex); virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int sinkIndex);
virtual void pull(Sample& sample, unsigned int sourceIndex); virtual void pull(Sample& sample, unsigned int sourceIndex);
virtual bool handleMessage(const Message& cmd); //!< Processing of a message. Returns true if message has actually been processed virtual bool handleMessage(const Message& cmd); //!< Processing of a message. Returns true if message has actually been processed

View File

@ -51,7 +51,6 @@ BladeRF2MIMO::BladeRF2MIMO(DeviceAPI *deviceAPI) :
m_sourceThread(nullptr), m_sourceThread(nullptr),
m_sinkThread(nullptr), m_sinkThread(nullptr),
m_deviceDescription("BladeRF2MIMO"), m_deviceDescription("BladeRF2MIMO"),
m_startStopRxElseTx(true),
m_runningRx(false), m_runningRx(false),
m_runningTx(false), m_runningTx(false),
m_dev(nullptr), m_dev(nullptr),
@ -147,30 +146,19 @@ void BladeRF2MIMO::init()
m_fileSinks.push_back(new FileRecord(QString("test_1_%1.sdriq").arg(m_deviceAPI->getDeviceUID()))); m_fileSinks.push_back(new FileRecord(QString("test_1_%1.sdriq").arg(m_deviceAPI->getDeviceUID())));
m_deviceAPI->addAncillarySink(m_fileSinks[0], 0); m_deviceAPI->addAncillarySink(m_fileSinks[0], 0);
m_deviceAPI->addAncillarySink(m_fileSinks[1], 1); m_deviceAPI->addAncillarySink(m_fileSinks[1], 1);
applySettings(m_settings, true);
} }
bool BladeRF2MIMO::start() bool BladeRF2MIMO::startRx()
{ {
qDebug("BladeRF2MIMO::startRx");
if (!m_open) if (!m_open)
{ {
qCritical("BladeRF2MIMO::start: device could not be opened"); qCritical("BladeRF2MIMO::startRx: device was not opened");
return false; return false;
} }
applySettings(m_settings, true);
if (m_startStopRxElseTx) {
startRx();
} else {
startTx();
}
return true;
}
void BladeRF2MIMO::startRx()
{
qDebug("BladeRF2MIMO::startRx");
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
if (m_runningRx) { if (m_runningRx) {
@ -193,11 +181,20 @@ void BladeRF2MIMO::startRx()
m_sourceThread->startWork(); m_sourceThread->startWork();
mutexLocker.unlock(); mutexLocker.unlock();
m_runningRx = true; m_runningRx = true;
return true;
} }
void BladeRF2MIMO::startTx() bool BladeRF2MIMO::startTx()
{ {
qDebug("BladeRF2MIMO::startTx"); qDebug("BladeRF2MIMO::startTx");
if (!m_open)
{
qCritical("BladeRF2MIMO::startRx: device was not opened");
return false;
}
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
if (m_runningTx) { if (m_runningTx) {
@ -212,23 +209,16 @@ void BladeRF2MIMO::startTx()
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
if (!m_dev->openRx(i)) { if (!m_dev->openTx(i)) {
qCritical("BladeRF2MIMO::startTx: Rx channel %u cannot be enabled", i); qCritical("BladeRF2MIMO::startTx: Tx channel %u cannot be enabled", i);
} }
} }
m_sourceThread->startWork(); m_sinkThread->startWork();
mutexLocker.unlock(); mutexLocker.unlock();
m_runningRx = true; m_runningTx = true;
}
void BladeRF2MIMO::stop() return true;
{
if (m_startStopRxElseTx) {
stopRx();
} else {
stopTx();
}
} }
void BladeRF2MIMO::stopRx() void BladeRF2MIMO::stopRx()
@ -406,22 +396,17 @@ bool BladeRF2MIMO::handleMessage(const Message& message)
<< " " << (cmd.getRxElseTx() ? "Rx" : "Tx") << " " << (cmd.getRxElseTx() ? "Rx" : "Tx")
<< " MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop"); << " MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
m_startStopRxElseTx = cmd.getRxElseTx(); bool startStopRxElseTx = cmd.getRxElseTx();
if (cmd.getStartStop()) // start engine if not started yet if (cmd.getStartStop())
{ {
if ((m_deviceAPI->state() == DeviceAPI::StNotStarted) || (m_deviceAPI->state() == DeviceAPI::StIdle)) if (m_deviceAPI->initDeviceEngine(startStopRxElseTx ? 0 : 1)) {
{ m_deviceAPI->startDeviceEngine(startStopRxElseTx ? 0 : 1);
if (m_deviceAPI->initDeviceEngine()) {
m_deviceAPI->startDeviceEngine();
}
} }
} }
else // stop engine if the other part is not running else
{ {
if ((m_startStopRxElseTx && !m_runningTx) || (!m_startStopRxElseTx && m_runningRx)) { m_deviceAPI->stopDeviceEngine(startStopRxElseTx ? 0 : 1);
m_deviceAPI->stopDeviceEngine();
}
} }
if (m_settings.m_useReverseAPI) { if (m_settings.m_useReverseAPI) {
@ -738,6 +723,7 @@ bool BladeRF2MIMO::applySettings(const BladeRF2MIMOSettings& settings, bool forc
|| (m_settings.m_txTransverterMode != settings.m_txTransverterMode) || (m_settings.m_txTransverterMode != settings.m_txTransverterMode)
|| (m_settings.m_txTransverterDeltaFrequency != settings.m_txTransverterDeltaFrequency) || (m_settings.m_txTransverterDeltaFrequency != settings.m_txTransverterDeltaFrequency)
|| (m_settings.m_fcPosTx != settings.m_fcPosTx) || (m_settings.m_fcPosTx != settings.m_fcPosTx)
|| (m_settings.m_log2Interp != settings.m_log2Interp)
|| (m_settings.m_LOppmTenths != settings.m_LOppmTenths) || (m_settings.m_LOppmTenths != settings.m_LOppmTenths)
|| (m_settings.m_devSampleRate != settings.m_devSampleRate) || force) || (m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
{ {
@ -869,9 +855,9 @@ bool BladeRF2MIMO::applySettings(const BladeRF2MIMOSettings& settings, bool forc
if (forwardChangeTxDSP) if (forwardChangeTxDSP)
{ {
int sampleRate = settings.m_devSampleRate/(1<<settings.m_log2Interp); int sampleRate = settings.m_devSampleRate/(1<<settings.m_log2Interp);
DSPMIMOSignalNotification *notif0 = new DSPMIMOSignalNotification(sampleRate, settings.m_rxCenterFrequency, false, 0); DSPMIMOSignalNotification *notif0 = new DSPMIMOSignalNotification(sampleRate, settings.m_txCenterFrequency, false, 0);
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif0); m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif0);
DSPMIMOSignalNotification *notif1 = new DSPMIMOSignalNotification(sampleRate, settings.m_rxCenterFrequency, false, 1); DSPMIMOSignalNotification *notif1 = new DSPMIMOSignalNotification(sampleRate, settings.m_txCenterFrequency, false, 1);
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif1); m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif1);
} }

View File

@ -148,8 +148,10 @@ public:
virtual void destroy(); virtual void destroy();
virtual void init(); virtual void init();
virtual bool start(); virtual bool startRx();
virtual void stop(); virtual void stopRx();
virtual bool startTx();
virtual void stopTx();
virtual QByteArray serialize() const; virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data); virtual bool deserialize(const QByteArray& data);
@ -223,7 +225,6 @@ private:
BladeRF2MIThread* m_sourceThread; BladeRF2MIThread* m_sourceThread;
BladeRF2MOThread* m_sinkThread; BladeRF2MOThread* m_sinkThread;
QString m_deviceDescription; QString m_deviceDescription;
bool m_startStopRxElseTx;
bool m_runningRx; bool m_runningRx;
bool m_runningTx; bool m_runningTx;
QNetworkAccessManager *m_networkManager; QNetworkAccessManager *m_networkManager;
@ -235,10 +236,6 @@ private:
bool openDevice(); bool openDevice();
void closeDevice(); void closeDevice();
void startRx();
void stopRx();
void startTx();
void stopTx();
bool applySettings(const BladeRF2MIMOSettings& settings, bool force); bool applySettings(const BladeRF2MIMOSettings& settings, bool force);
bool setRxDeviceCenterFrequency(struct bladerf *dev, quint64 freq_hz, int loPpmTenths); bool setRxDeviceCenterFrequency(struct bladerf *dev, quint64 freq_hz, int loPpmTenths);

View File

@ -55,10 +55,12 @@ BladeRF2MIMOGui::BladeRF2MIMOGui(DeviceUISet *deviceUISet, QWidget* parent) :
m_forceSettings(true), m_forceSettings(true),
m_sampleMIMO(nullptr), m_sampleMIMO(nullptr),
m_tickCount(0), m_tickCount(0),
m_deviceSampleRate(3072000), m_rxBasebandSampleRate(3072000),
m_txBasebandSampleRate(3072000),
m_rxDeviceCenterFrequency(435000*1000), m_rxDeviceCenterFrequency(435000*1000),
m_txDeviceCenterFrequency(435000*1000), m_txDeviceCenterFrequency(435000*1000),
m_lastEngineState(DeviceAPI::StNotStarted), m_lastRxEngineState(DeviceAPI::StNotStarted),
m_lastTxEngineState(DeviceAPI::StNotStarted),
m_sampleRateMode(true) m_sampleRateMode(true)
{ {
qDebug("BladeRF2MIMOGui::BladeRF2MIMOGui"); qDebug("BladeRF2MIMOGui::BladeRF2MIMOGui");
@ -92,6 +94,8 @@ BladeRF2MIMOGui::BladeRF2MIMOGui(DeviceUISet *deviceUISet, QWidget* parent) :
CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStopRx); CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStopRx);
connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &))); connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
sendSettings();
} }
BladeRF2MIMOGui::~BladeRF2MIMOGui() BladeRF2MIMOGui::~BladeRF2MIMOGui()
@ -140,12 +144,15 @@ QByteArray BladeRF2MIMOGui::serialize() const
bool BladeRF2MIMOGui::deserialize(const QByteArray& data) bool BladeRF2MIMOGui::deserialize(const QByteArray& data)
{ {
if(m_settings.deserialize(data)) { if (m_settings.deserialize(data))
{
displaySettings(); displaySettings();
m_forceSettings = true; m_forceSettings = true;
sendSettings(); sendSettings();
return true; return true;
} else { }
else
{
resetToDefaults(); resetToDefaults();
return false; return false;
} }
@ -314,11 +321,15 @@ bool BladeRF2MIMOGui::handleMessage(const Message& message)
const DSPMIMOSignalNotification& notif = (const DSPMIMOSignalNotification&) message; const DSPMIMOSignalNotification& notif = (const DSPMIMOSignalNotification&) message;
int istream = notif.getIndex(); int istream = notif.getIndex();
bool sourceOrSink = notif.getSourceOrSink(); bool sourceOrSink = notif.getSourceOrSink();
m_deviceSampleRate = notif.getSampleRate();
if (sourceOrSink) { if (sourceOrSink)
{
m_rxBasebandSampleRate = notif.getSampleRate();
m_rxDeviceCenterFrequency = notif.getCenterFrequency(); m_rxDeviceCenterFrequency = notif.getCenterFrequency();
} else { }
else
{
m_txBasebandSampleRate = notif.getSampleRate();
m_txDeviceCenterFrequency = notif.getCenterFrequency(); m_txDeviceCenterFrequency = notif.getCenterFrequency();
} }
@ -370,11 +381,14 @@ void BladeRF2MIMOGui::updateHardware()
void BladeRF2MIMOGui::updateSampleRateAndFrequency() void BladeRF2MIMOGui::updateSampleRateAndFrequency()
{ {
m_deviceUISet->getSpectrum()->setSampleRate(m_deviceSampleRate); if (m_spectrumRxElseTx)
{
if (m_rxElseTx) { m_deviceUISet->getSpectrum()->setSampleRate(m_rxBasebandSampleRate);
m_deviceUISet->getSpectrum()->setCenterFrequency(m_rxDeviceCenterFrequency); m_deviceUISet->getSpectrum()->setCenterFrequency(m_rxDeviceCenterFrequency);
} else { }
else
{
m_deviceUISet->getSpectrum()->setSampleRate(m_txBasebandSampleRate);
m_deviceUISet->getSpectrum()->setCenterFrequency(m_txDeviceCenterFrequency); m_deviceUISet->getSpectrum()->setCenterFrequency(m_txDeviceCenterFrequency);
} }
} }
@ -403,7 +417,8 @@ void BladeRF2MIMOGui::on_streamIndex_currentIndexChanged(int index)
void BladeRF2MIMOGui::on_spectrumSide_currentIndexChanged(int index) void BladeRF2MIMOGui::on_spectrumSide_currentIndexChanged(int index)
{ {
m_spectrumRxElseTx = index == 0; m_spectrumRxElseTx = (index == 0);
updateSampleRateAndFrequency();
// TODO // TODO
} }
@ -695,46 +710,56 @@ void BladeRF2MIMOGui::setCenterFrequencySetting(uint64_t kHzValue)
void BladeRF2MIMOGui::updateStatus() void BladeRF2MIMOGui::updateStatus()
{ {
int state = m_deviceUISet->m_deviceAPI->state(); int stateRx = m_deviceUISet->m_deviceAPI->state(0);
int stateTx = m_deviceUISet->m_deviceAPI->state(1);
if (m_lastEngineState != state) if (m_lastRxEngineState != stateRx)
{ {
switch(state) qDebug("BladeRF2MIMOGui::updateStatus: stateRx: %d", (int) stateRx);
switch(stateRx)
{ {
case DeviceAPI::StNotStarted: case DeviceAPI::StNotStarted:
ui->startStopRx->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); ui->startStopRx->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
ui->startStopTx->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break; break;
case DeviceAPI::StIdle: case DeviceAPI::StIdle:
ui->startStopRx->setStyleSheet("QToolButton { background-color : blue; }"); ui->startStopRx->setStyleSheet("QToolButton { background-color : blue; }");
ui->startStopTx->setStyleSheet("QToolButton { background-color : blue; }");
break; break;
case DeviceAPI::StRunning: case DeviceAPI::StRunning:
{ ui->startStopRx->setStyleSheet("QToolButton { background-color : green; }");
if (m_sampleMIMO->getRxRunning()) {
ui->startStopRx->setStyleSheet("QToolButton { background-color : green; }");
} else {
ui->startStopRx->setStyleSheet("QToolButton { background-color : blue; }");
}
if (m_sampleMIMO->getTxRunning()) {
ui->startStopTx->setStyleSheet("QToolButton { background-color : green; }");
} else {
ui->startStopTx->setStyleSheet("QToolButton { background-color : blue; }");
}
}
break; break;
case DeviceAPI::StError: case DeviceAPI::StError:
if (m_rxElseTx) { ui->startStopRx->setStyleSheet("QToolButton { background-color : red; }");
ui->startStopRx->setStyleSheet("QToolButton { background-color : red; }"); QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage(0));
} else {
ui->startStopTx->setStyleSheet("QToolButton { background-color : red; }");
}
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
break; break;
default: default:
break; break;
} }
m_lastEngineState = state; m_lastRxEngineState = stateRx;
}
if (m_lastTxEngineState != stateTx)
{
qDebug("BladeRF2MIMOGui::updateStatus: stateTx: %d", (int) stateTx);
switch(stateTx)
{
case DeviceAPI::StNotStarted:
ui->startStopTx->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
break;
case DeviceAPI::StIdle:
ui->startStopTx->setStyleSheet("QToolButton { background-color : blue; }");
break;
case DeviceAPI::StRunning:
ui->startStopTx->setStyleSheet("QToolButton { background-color : green; }");
break;
case DeviceAPI::StError:
ui->startStopTx->setStyleSheet("QToolButton { background-color : red; }");
QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage(1));
break;
default:
break;
}
m_lastTxEngineState = stateTx;
} }
} }

View File

@ -66,10 +66,12 @@ private:
bool m_forceSettings; bool m_forceSettings;
BladeRF2MIMO* m_sampleMIMO; BladeRF2MIMO* m_sampleMIMO;
std::size_t m_tickCount; std::size_t m_tickCount;
int m_deviceSampleRate; int m_rxBasebandSampleRate;
int m_txBasebandSampleRate;
quint64 m_rxDeviceCenterFrequency; //!< Center frequency in Rx device quint64 m_rxDeviceCenterFrequency; //!< Center frequency in Rx device
quint64 m_txDeviceCenterFrequency; //!< Center frequency in Tx device quint64 m_txDeviceCenterFrequency; //!< Center frequency in Tx device
int m_lastEngineState; int m_lastRxEngineState;
int m_lastTxEngineState;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;
bool m_sampleRateMode; bool m_sampleRateMode;

View File

@ -278,6 +278,12 @@
<layout class="QHBoxLayout" name="deviceRateLayout"> <layout class="QHBoxLayout" name="deviceRateLayout">
<item> <item>
<widget class="QLabel" name="deviceRateText"> <widget class="QLabel" name="deviceRateText">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="toolTip"> <property name="toolTip">
<string>I/Q sample rate kS/s</string> <string>I/Q sample rate kS/s</string>
</property> </property>