| 
									
										
										
										
											2015-06-07 17:56:19 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-09 10:33:04 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | #include <libbladeRF.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ui_bladerfgui.h"
 | 
					
						
							|  |  |  | #include "plugin/pluginapi.h"
 | 
					
						
							| 
									
										
										
										
											2015-07-19 19:39:16 +02:00
										 |  |  | #include "gui/colormapper.h"
 | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  | #include "gui/glspectrum.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							|  |  |  | #include "dsp/filesink.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | #include "bladerfgui.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BladerfGui::BladerfGui(PluginAPI* pluginAPI, QWidget* parent) : | 
					
						
							|  |  |  | 	QWidget(parent), | 
					
						
							|  |  |  | 	ui(new Ui::BladerfGui), | 
					
						
							|  |  |  | 	m_pluginAPI(pluginAPI), | 
					
						
							|  |  |  | 	m_settings(), | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | 	m_sampleSource(NULL), | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  | 	m_sampleRate(0), | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | 	m_lastEngineState((DSPDeviceEngine::State)-1) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2015-07-19 22:00:38 +02:00
										 |  |  | 	ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); | 
					
						
							| 
									
										
										
										
											2015-06-09 08:18:32 +02:00
										 |  |  | 	ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN_XB200/1000, BLADERF_FREQUENCY_MAX/1000); | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ui->samplerate->clear(); | 
					
						
							|  |  |  | 	for (int i = 0; i < BladerfSampleRates::getNbRates(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		ui->samplerate->addItem(QString::number(BladerfSampleRates::getRate(i))); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ui->bandwidth->clear(); | 
					
						
							|  |  |  | 	for (int i = 0; i < BladerfBandwidths::getNbBandwidths(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		ui->bandwidth->addItem(QString::number(BladerfBandwidths::getBandwidth(i))); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | 	connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); | 
					
						
							|  |  |  | 	m_statusTimer.start(500); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	displaySettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 23:35:30 +02:00
										 |  |  | 	m_sampleSource = new BladerfInput(m_pluginAPI); | 
					
						
							| 
									
										
										
										
											2016-05-13 00:50:29 +02:00
										 |  |  | 	m_pluginAPI->setSource(m_sampleSource); | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	char recFileNameCStr[30]; | 
					
						
							|  |  |  | 	sprintf(recFileNameCStr, "test_%d.sdriq", m_pluginAPI->getDeviceUID()); | 
					
						
							|  |  |  |     m_fileSink = new FileSink(std::string(recFileNameCStr)); | 
					
						
							|  |  |  |     m_pluginAPI->addSink(m_fileSink); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     connect(m_pluginAPI->getDeviceOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BladerfGui::~BladerfGui() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  |     m_pluginAPI->removeSink(m_fileSink); | 
					
						
							|  |  |  |     delete m_fileSink; | 
					
						
							| 
									
										
										
										
											2015-08-29 03:09:44 +02:00
										 |  |  | 	delete m_sampleSource; // Valgrind memcheck
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	delete ui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::setName(const QString& name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	setObjectName(name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString BladerfGui::getName() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return objectName(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.resetToDefaults(); | 
					
						
							|  |  |  | 	displaySettings(); | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-19 02:07:40 +02:00
										 |  |  | qint64 BladerfGui::getCenterFrequency() const | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	return m_settings.m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-29 03:35:14 +02:00
										 |  |  | void BladerfGui::setCenterFrequency(qint64 centerFrequency) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.m_centerFrequency = centerFrequency; | 
					
						
							|  |  |  | 	displaySettings(); | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | QByteArray BladerfGui::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool BladerfGui::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(m_settings.deserialize(data)) { | 
					
						
							|  |  |  | 		displaySettings(); | 
					
						
							|  |  |  | 		sendSettings(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		resetToDefaults(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | bool BladerfGui::handleMessage(const Message& message) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	if (BladerfInput::MsgReportBladerf::match(message)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		displaySettings(); | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  | void BladerfGui::handleDSPMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ((message = m_pluginAPI->getDeviceOutputMessageQueue()->pop()) != 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("BladerfGui::handleDSPMessages: message: %s", message->getIdentifier()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (DSPSignalNotification::match(*message)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DSPSignalNotification* notif = (DSPSignalNotification*) message; | 
					
						
							|  |  |  |             m_sampleRate = notif->getSampleRate(); | 
					
						
							|  |  |  |             m_deviceCenterFrequency = notif->getCenterFrequency(); | 
					
						
							|  |  |  |             qDebug("BladerfGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); | 
					
						
							|  |  |  |             updateSampleRateAndFrequency(); | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  |             m_fileSink->handleMessage(*notif); // forward to file sink
 | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             delete message; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::updateSampleRateAndFrequency() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_pluginAPI->getSpectrum()->setSampleRate(m_sampleRate); | 
					
						
							|  |  |  |     m_pluginAPI->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency); | 
					
						
							|  |  |  |     ui->deviceRateLabel->setText(tr("%1k").arg((float)m_sampleRate / 1000)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | void BladerfGui::displaySettings() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:18:20 +02:00
										 |  |  | 	ui->dcOffset->setChecked(m_settings.m_dcBlock); | 
					
						
							|  |  |  | 	ui->iqImbalance->setChecked(m_settings.m_iqCorrection); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	unsigned int sampleRateIndex = BladerfSampleRates::getRateIndex(m_settings.m_devSampleRate); | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	ui->samplerate->setCurrentIndex(sampleRateIndex); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	unsigned int bandwidthIndex = BladerfBandwidths::getBandwidthIndex(m_settings.m_bandwidth); | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	ui->bandwidth->setCurrentIndex(bandwidthIndex); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	ui->decim->setCurrentIndex(m_settings.m_log2Decim); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 01:00:27 +02:00
										 |  |  | 	ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	ui->lna->setCurrentIndex(m_settings.m_lnaGain); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-26 20:44:05 +02:00
										 |  |  | 	ui->vga1Text->setText(tr("%1dB").arg(m_settings.m_vga1)); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	ui->vga1->setValue(m_settings.m_vga1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-28 23:54:17 +02:00
										 |  |  | 	ui->vga2Text->setText(tr("%1dB").arg(m_settings.m_vga2)); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	ui->vga2->setValue(m_settings.m_vga2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ui->xb200->setCurrentIndex(getXb200Index(m_settings.m_xb200, m_settings.m_xb200Path, m_settings.m_xb200Filter)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::sendSettings() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(!m_updateTimer.isActive()) | 
					
						
							|  |  |  | 		m_updateTimer.start(100); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::on_centerFrequency_changed(quint64 value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	m_settings.m_centerFrequency = value * 1000; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 03:18:20 +02:00
										 |  |  | void BladerfGui::on_dcOffset_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.m_dcBlock = checked; | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::on_iqImbalance_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.m_iqCorrection = checked; | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | void BladerfGui::on_samplerate_currentIndexChanged(int index) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	int newrate = BladerfSampleRates::getRate(index); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	m_settings.m_devSampleRate = newrate * 1000; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | void BladerfGui::on_bandwidth_currentIndexChanged(int index) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	int newbw = BladerfBandwidths::getBandwidth(index); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	m_settings.m_bandwidth = newbw * 1000; | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | void BladerfGui::on_decim_currentIndexChanged(int index) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	if ((index <0) || (index > 5)) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	m_settings.m_log2Decim = index; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-02 01:00:27 +02:00
										 |  |  | void BladerfGui::on_fcPos_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (index == 0) { | 
					
						
							| 
									
										
										
										
											2015-09-30 19:03:50 +02:00
										 |  |  | 		m_settings.m_fcPos = BladeRFSettings::FC_POS_INFRA; | 
					
						
							| 
									
										
										
										
											2015-07-02 01:00:27 +02:00
										 |  |  | 		sendSettings(); | 
					
						
							|  |  |  | 	} else if (index == 1) { | 
					
						
							| 
									
										
										
										
											2015-09-30 19:03:50 +02:00
										 |  |  | 		m_settings.m_fcPos = BladeRFSettings::FC_POS_SUPRA; | 
					
						
							| 
									
										
										
										
											2015-07-02 01:00:27 +02:00
										 |  |  | 		sendSettings(); | 
					
						
							| 
									
										
										
										
											2015-07-02 02:10:14 +02:00
										 |  |  | 	} else if (index == 2) { | 
					
						
							| 
									
										
										
										
											2015-09-30 19:03:50 +02:00
										 |  |  | 		m_settings.m_fcPos = BladeRFSettings::FC_POS_CENTER; | 
					
						
							| 
									
										
										
										
											2015-07-02 02:10:14 +02:00
										 |  |  | 		sendSettings(); | 
					
						
							| 
									
										
										
										
											2015-07-02 01:00:27 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | void BladerfGui::on_lna_currentIndexChanged(int index) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	qDebug() << "BladerfGui: LNA gain = " << index * 3 << " dB"; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	if ((index < 0) || (index > 2)) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 	m_settings.m_lnaGain = index; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::on_vga1_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ((value < BLADERF_RXVGA1_GAIN_MIN) || (value > BLADERF_RXVGA1_GAIN_MAX)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-26 20:44:05 +02:00
										 |  |  | 	ui->vga1Text->setText(tr("%1dB").arg(value)); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	m_settings.m_vga1 = value; | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::on_vga2_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ((value < BLADERF_RXVGA2_GAIN_MIN) || (value > BLADERF_RXVGA2_GAIN_MAX)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-26 20:44:05 +02:00
										 |  |  | 	ui->vga2Text->setText(tr("%1dB").arg(value)); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	m_settings.m_vga2 = value; | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BladerfGui::on_xb200_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (index == 1) // bypass
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_xb200 = true; | 
					
						
							|  |  |  | 		m_settings.m_xb200Path = BLADERF_XB200_BYPASS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (index == 2) // Auto 1dB
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_xb200 = true; | 
					
						
							|  |  |  | 		m_settings.m_xb200Path = BLADERF_XB200_MIX; | 
					
						
							|  |  |  | 		m_settings.m_xb200Filter = BLADERF_XB200_AUTO_1DB; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (index == 3) // Auto 3dB
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_xb200 = true; | 
					
						
							|  |  |  | 		m_settings.m_xb200Path = BLADERF_XB200_MIX; | 
					
						
							|  |  |  | 		m_settings.m_xb200Filter = BLADERF_XB200_AUTO_3DB; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (index == 4) // Custom
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_xb200 = true; | 
					
						
							|  |  |  | 		m_settings.m_xb200Path = BLADERF_XB200_MIX; | 
					
						
							|  |  |  | 		m_settings.m_xb200Filter = BLADERF_XB200_CUSTOM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (index == 5) // 50 MHz
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_xb200 = true; | 
					
						
							|  |  |  | 		m_settings.m_xb200Path = BLADERF_XB200_MIX; | 
					
						
							|  |  |  | 		m_settings.m_xb200Filter = BLADERF_XB200_50M; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (index == 6) // 144 MHz
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_xb200 = true; | 
					
						
							|  |  |  | 		m_settings.m_xb200Path = BLADERF_XB200_MIX; | 
					
						
							|  |  |  | 		m_settings.m_xb200Filter = BLADERF_XB200_144M; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (index == 7) // 222 MHz
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_xb200 = true; | 
					
						
							|  |  |  | 		m_settings.m_xb200Path = BLADERF_XB200_MIX; | 
					
						
							|  |  |  | 		m_settings.m_xb200Filter = BLADERF_XB200_222M; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else // no xb200
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_settings.m_xb200 = false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 23:07:19 +02:00
										 |  |  | 	if (m_settings.m_xb200) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN_XB200/1000, BLADERF_FREQUENCY_MAX/1000); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		ui->centerFrequency->setValueRange(7, BLADERF_FREQUENCY_MIN/1000, BLADERF_FREQUENCY_MAX/1000); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | void BladerfGui::on_startStop_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (checked) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (m_pluginAPI->initAcquisition()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_pluginAPI->startAcquisition(); | 
					
						
							|  |  |  |             DSPEngine::instance()->startAudio(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_pluginAPI->stopAcquistion(); | 
					
						
							|  |  |  |         DSPEngine::instance()->stopAudio(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  | void BladerfGui::on_record_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (checked) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ui->record->setStyleSheet("QToolButton { background-color : red; }"); | 
					
						
							|  |  |  |         m_fileSink->startRecording(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ui->record->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); | 
					
						
							|  |  |  |         m_fileSink->stopRecording(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | void BladerfGui::updateHardware() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-19 01:45:06 +02:00
										 |  |  | 	qDebug() << "BladerfGui::updateHardware"; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	BladerfInput::MsgConfigureBladerf* message = BladerfInput::MsgConfigureBladerf::create( m_settings); | 
					
						
							|  |  |  | 	m_sampleSource->getInputMessageQueue()->push(message); | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 	m_updateTimer.stop(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | void BladerfGui::updateStatus() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int state = m_pluginAPI->state(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(m_lastEngineState != state) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         switch(state) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             case DSPDeviceEngine::StNotStarted: | 
					
						
							|  |  |  |                 ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case DSPDeviceEngine::StIdle: | 
					
						
							|  |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : blue; }"); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case DSPDeviceEngine::StRunning: | 
					
						
							|  |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : green; }"); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case DSPDeviceEngine::StError: | 
					
						
							|  |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : red; }"); | 
					
						
							|  |  |  |                 QMessageBox::information(this, tr("Message"), m_pluginAPI->errorMessage()); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_lastEngineState = state; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | unsigned int BladerfGui::getXb200Index(bool xb_200, bladerf_xb200_path xb200Path, bladerf_xb200_filter xb200Filter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (xb_200) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (xb200Path == BLADERF_XB200_BYPASS) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if (xb200Filter == BLADERF_XB200_AUTO_1DB) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				return 2; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (xb200Filter == BLADERF_XB200_AUTO_3DB) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				return 3; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (xb200Filter == BLADERF_XB200_CUSTOM) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				return 4; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (xb200Filter == BLADERF_XB200_50M) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				return 5; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (xb200Filter == BLADERF_XB200_144M) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				return 6; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (xb200Filter == BLADERF_XB200_222M) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				return 7; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-31 19:48:06 +02:00
										 |  |  | unsigned int BladerfSampleRates::m_rates[] = {1536, 1600, 2000, 2304, 2400, 3072, 3200, 4608, 4800, 6144, 7680, 9216, 9600, 10752, 12288, 18432, 19200, 24576, 30720, 36864, 39936}; | 
					
						
							|  |  |  | unsigned int BladerfSampleRates::m_nb_rates = 21; | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | unsigned int BladerfSampleRates::getRate(unsigned int rate_index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (rate_index < m_nb_rates) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return m_rates[rate_index]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return m_rates[0]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unsigned int BladerfSampleRates::getRateIndex(unsigned int rate) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (unsigned int i=0; i < m_nb_rates; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (rate/1000 == m_rates[i]) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return i; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | unsigned int BladerfSampleRates::getNbRates() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return BladerfSampleRates::m_nb_rates; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | unsigned int BladerfBandwidths::m_halfbw[] = {750, 875, 1250, 1375, 1500, 1920, 2500, 2750, 3000, 3500, 4375, 5000, 6000, 7000, 10000, 14000}; | 
					
						
							|  |  |  | unsigned int BladerfBandwidths::m_nb_halfbw = 16; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unsigned int BladerfBandwidths::getBandwidth(unsigned int bandwidth_index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (bandwidth_index < m_nb_halfbw) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return m_halfbw[bandwidth_index] * 2; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return m_halfbw[0] * 2; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unsigned int BladerfBandwidths::getBandwidthIndex(unsigned int bandwidth) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (unsigned int i=0; i < m_nb_halfbw; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-06-09 08:18:32 +02:00
										 |  |  | 		if (bandwidth/2000 == m_halfbw[i]) | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			return i; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-03-29 17:31:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | unsigned int BladerfBandwidths::getNbBandwidths() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return BladerfBandwidths::m_nb_halfbw; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |