| 
									
										
										
										
											2016-05-12 11:10:10 +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-26 02:03:20 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "rtlsdrgui.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-02 10:30:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | #include <device/devicesourceapi.h>
 | 
					
						
							| 
									
										
										
										
											2016-10-02 10:30:58 +02:00
										 |  |  | #include <dsp/filerecord.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "ui_rtlsdrgui.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-02 01:45:53 +02:00
										 |  |  | #include "gui/colormapper.h"
 | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  | #include "gui/glspectrum.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 01:17:55 +02:00
										 |  |  | RTLSDRGui::RTLSDRGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	QWidget(parent), | 
					
						
							|  |  |  | 	ui(new Ui::RTLSDRGui), | 
					
						
							| 
									
										
										
										
											2016-05-16 01:12:37 +02:00
										 |  |  | 	m_deviceAPI(deviceAPI), | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	m_settings(), | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | 	m_sampleSource(0), | 
					
						
							| 
									
										
										
										
											2016-10-03 18:29:05 +02:00
										 |  |  | 	m_lastEngineState((DSPDeviceSourceEngine::State)-1) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-12 23:41:30 +02:00
										 |  |  |     m_sampleSource = new RTLSDRInput(m_deviceAPI); | 
					
						
							|  |  |  |     m_deviceAPI->setSource(m_sampleSource); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2017-05-16 18:27:36 +02:00
										 |  |  | 	ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); | 
					
						
							| 
									
										
										
										
											2015-10-01 05:44:33 +02:00
										 |  |  | 	ui->centerFrequency->setValueRange(7, 24000U, 1900000U); | 
					
						
							| 
									
										
										
										
											2016-03-29 16:22:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-16 18:27:36 +02:00
										 |  |  |     ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow)); | 
					
						
							| 
									
										
										
										
											2017-04-02 03:34:03 +02:00
										 |  |  |     ui->sampleRate->setValueRange(7, 950000U, 2400000U); | 
					
						
							| 
									
										
										
										
											2016-03-29 16:22:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01: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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	displaySettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 09:25:02 +02:00
										 |  |  | 	connect(m_sampleSource->getOutputMessageQueueToGUI(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     char recFileNameCStr[30]; | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID()); | 
					
						
							| 
									
										
										
										
											2016-10-02 10:30:58 +02:00
										 |  |  |     m_fileSink = new FileRecord(std::string(recFileNameCStr)); | 
					
						
							| 
									
										
										
										
											2016-05-16 01:12:37 +02:00
										 |  |  |     m_deviceAPI->addSink(m_fileSink); | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     connect(m_deviceAPI->getDeviceOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleDSPMessages()), Qt::QueuedConnection); | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     queryDeviceReport(); // will reply with MsgReportRTLSDR to report gain list
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RTLSDRGui::~RTLSDRGui() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     m_deviceAPI->removeSink(m_fileSink); | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  |     delete m_fileSink; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	delete ui; | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  | 	delete m_sampleSource; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RTLSDRGui::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RTLSDRGui::setName(const QString& name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	setObjectName(name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | QString RTLSDRGui::getName() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return objectName(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void RTLSDRGui::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.resetToDefaults(); | 
					
						
							|  |  |  | 	displaySettings(); | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-19 02:07:40 +02:00
										 |  |  | qint64 RTLSDRGui::getCenterFrequency() const | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	return m_settings.m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-29 03:35:14 +02:00
										 |  |  | void RTLSDRGui::setCenterFrequency(qint64 centerFrequency) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.m_centerFrequency = centerFrequency; | 
					
						
							|  |  |  | 	displaySettings(); | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 05:05:46 +02:00
										 |  |  | void RTLSDRGui::on_dcOffset_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.m_dcBlock = checked; | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RTLSDRGui::on_iqImbalance_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.m_iqImbalance = checked; | 
					
						
							|  |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | QByteArray RTLSDRGui::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-02-21 05:35:20 +01:00
										 |  |  |     return m_settings.serialize(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool RTLSDRGui::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-02-21 05:35:20 +01:00
										 |  |  |     if(m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  |         displayGains(); | 
					
						
							| 
									
										
										
										
											2017-02-21 05:35:20 +01:00
										 |  |  |         displaySettings(); | 
					
						
							|  |  |  |         sendSettings(); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | bool RTLSDRGui::handleMessage(const Message& message) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	if (RTLSDRInput::MsgReportRTLSDR::match(message)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-08-26 02:03:20 +02:00
										 |  |  | 		qDebug() << "RTLSDRGui::handleMessage: MsgReportRTLSDR"; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		m_gains = ((RTLSDRInput::MsgReportRTLSDR&) message).getGains(); | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  | 		displayGains(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  | void RTLSDRGui::handleDSPMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     while ((message = m_deviceAPI->getDeviceOutputMessageQueue()->pop()) != 0) | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         qDebug("RTLSDRGui::handleDSPMessages: message: %s", message->getIdentifier()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (DSPSignalNotification::match(*message)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DSPSignalNotification* notif = (DSPSignalNotification*) message; | 
					
						
							|  |  |  |             m_sampleRate = notif->getSampleRate(); | 
					
						
							|  |  |  |             m_deviceCenterFrequency = notif->getCenterFrequency(); | 
					
						
							|  |  |  |             qDebug("RTLSDRGui::handleDSPMessages: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency()); | 
					
						
							|  |  |  |             updateSampleRateAndFrequency(); | 
					
						
							|  |  |  |             m_fileSink->handleMessage(*notif); // forward to file sink
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             delete message; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-26 09:25:02 +02:00
										 |  |  | void RTLSDRGui::handleSourceMessages() | 
					
						
							| 
									
										
										
										
											2015-08-26 02:03:20 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while ((message = m_sampleSource->getOutputMessageQueueToGUI()->pop()) != 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		qDebug("RTLSDRGui::HandleSourceMessages: message: %s", message->getIdentifier()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (handleMessage(*message)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			delete message; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  | void RTLSDRGui::updateSampleRateAndFrequency() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     m_deviceAPI->getSpectrum()->setSampleRate(m_sampleRate); | 
					
						
							|  |  |  |     m_deviceAPI->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency); | 
					
						
							| 
									
										
										
										
											2017-04-02 03:34:03 +02:00
										 |  |  |     ui->deviceRateText->setText(tr("%1k").arg(QString::number(m_sampleRate / 1000.0f, 'g', 5))); | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  | void RTLSDRGui::displayGains() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_gains.size() > 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int dist = abs(m_settings.m_gain - m_gains[0]); | 
					
						
							|  |  |  |         int pos = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (uint i = 1; i < m_gains.size(); i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (abs(m_settings.m_gain - m_gains[i]) < dist) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 dist = abs(m_settings.m_gain - m_gains[i]); | 
					
						
							|  |  |  |                 pos = i; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ui->gainText->setText(tr("%1.%2").arg(m_gains[pos] / 10).arg(abs(m_gains[pos] % 10))); | 
					
						
							|  |  |  |         ui->gain->setMaximum(m_gains.size() - 1); | 
					
						
							|  |  |  |         ui->gain->setEnabled(true); | 
					
						
							|  |  |  |         ui->gain->setValue(pos); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ui->gain->setMaximum(0); | 
					
						
							|  |  |  |         ui->gain->setEnabled(false); | 
					
						
							|  |  |  |         ui->gain->setValue(0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void RTLSDRGui::displaySettings() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); | 
					
						
							| 
									
										
										
										
											2017-04-02 03:34:03 +02:00
										 |  |  | 	ui->sampleRate->setValue(m_settings.m_devSampleRate); | 
					
						
							| 
									
										
										
										
											2015-10-01 05:05:46 +02:00
										 |  |  | 	ui->dcOffset->setChecked(m_settings.m_dcBlock); | 
					
						
							|  |  |  | 	ui->iqImbalance->setChecked(m_settings.m_iqImbalance); | 
					
						
							| 
									
										
										
										
											2015-05-10 00:08:42 +02:00
										 |  |  | 	ui->ppm->setValue(m_settings.m_loPpmCorrection); | 
					
						
							|  |  |  | 	ui->ppmText->setText(tr("%1").arg(m_settings.m_loPpmCorrection)); | 
					
						
							| 
									
										
										
										
											2016-03-29 16:22:24 +02:00
										 |  |  | 	ui->decim->setCurrentIndex(m_settings.m_log2Decim); | 
					
						
							| 
									
										
										
										
											2015-10-01 06:30:50 +02:00
										 |  |  | 	ui->fcPos->setCurrentIndex((int) m_settings.m_fcPos); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RTLSDRGui::sendSettings() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(!m_updateTimer.isActive()) | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		m_updateTimer.start(100); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RTLSDRGui::on_centerFrequency_changed(quint64 value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	m_settings.m_centerFrequency = value * 1000; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 16:22:24 +02:00
										 |  |  | void RTLSDRGui::on_decim_currentIndexChanged(int index) | 
					
						
							| 
									
										
										
										
											2015-05-09 16:44:26 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-10 02:19:21 +02:00
										 |  |  | 	if ((index <0) || (index > 5)) | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-05-09 16:44:26 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 16:22:24 +02:00
										 |  |  | 	m_settings.m_log2Decim = index; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 16:44:26 +02:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 06:30:50 +02:00
										 |  |  | void RTLSDRGui::on_fcPos_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (index == 0) { | 
					
						
							|  |  |  | 		m_settings.m_fcPos = RTLSDRSettings::FC_POS_INFRA; | 
					
						
							|  |  |  | 		sendSettings(); | 
					
						
							|  |  |  | 	} else if (index == 1) { | 
					
						
							|  |  |  | 		m_settings.m_fcPos = RTLSDRSettings::FC_POS_SUPRA; | 
					
						
							|  |  |  | 		sendSettings(); | 
					
						
							|  |  |  | 	} else if (index == 2) { | 
					
						
							|  |  |  | 		m_settings.m_fcPos = RTLSDRSettings::FC_POS_CENTER; | 
					
						
							|  |  |  | 		sendSettings(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 00:54:01 +02:00
										 |  |  | void RTLSDRGui::on_ppm_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	if ((value > 99) || (value < -99)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-05-09 00:54:01 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 00:54:01 +02:00
										 |  |  | 	ui->ppmText->setText(tr("%1").arg(value)); | 
					
						
							|  |  |  | 	m_settings.m_loPpmCorrection = value; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-09 00:54:01 +02:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void RTLSDRGui::on_gain_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	if (value > (int)m_gains.size()) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	int gain = m_gains[value]; | 
					
						
							|  |  |  | 	ui->gainText->setText(tr("%1.%2").arg(gain / 10).arg(abs(gain % 10))); | 
					
						
							|  |  |  | 	m_settings.m_gain = gain; | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	sendSettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 16:22:24 +02:00
										 |  |  | void RTLSDRGui::on_sampleRate_currentIndexChanged(int index) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | void RTLSDRGui::on_startStop_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (checked) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |         if (m_deviceAPI->initAcquisition()) | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |             m_deviceAPI->startAcquisition(); | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  |             DSPEngine::instance()->startAudioOutput(); | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |         m_deviceAPI->stopAcquisition(); | 
					
						
							| 
									
										
										
										
											2016-11-29 01:09:06 +01:00
										 |  |  |         DSPEngine::instance()->stopAudioOutput(); | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-12 11:10:10 +02:00
										 |  |  | void RTLSDRGui::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(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  | void RTLSDRGui::queryDeviceReport() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     RTLSDRInput::MsgQueryRTLSDR* message = RTLSDRInput::MsgQueryRTLSDR::create(); | 
					
						
							|  |  |  |     m_sampleSource->getInputMessageQueue()->push(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void RTLSDRGui::updateHardware() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	RTLSDRInput::MsgConfigureRTLSDR* message = RTLSDRInput::MsgConfigureRTLSDR::create(m_settings); | 
					
						
							|  |  |  | 	m_sampleSource->getInputMessageQueue()->push(message); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	m_updateTimer.stop(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-11-07 19:26:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | void RTLSDRGui::updateStatus() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |     int state = m_deviceAPI->state(); | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if(m_lastEngineState != state) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         switch(state) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2016-10-03 18:29:05 +02:00
										 |  |  |             case DSPDeviceSourceEngine::StNotStarted: | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  |                 ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2016-10-03 18:29:05 +02:00
										 |  |  |             case DSPDeviceSourceEngine::StIdle: | 
					
						
							| 
									
										
										
										
											2016-05-12 10:31:57 +02:00
										 |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : blue; }"); | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2016-10-03 18:29:05 +02:00
										 |  |  |             case DSPDeviceSourceEngine::StRunning: | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : green; }"); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2016-10-03 18:29:05 +02:00
										 |  |  |             case DSPDeviceSourceEngine::StError: | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : red; }"); | 
					
						
							| 
									
										
										
										
											2016-05-16 02:14:36 +02:00
										 |  |  |                 QMessageBox::information(this, tr("Message"), m_deviceAPI->errorMessage()); | 
					
						
							| 
									
										
										
										
											2016-05-11 23:35:16 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_lastEngineState = state; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | void RTLSDRGui::on_checkBox_stateChanged(int state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (state == Qt::Checked) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-11-09 12:56:53 +00:00
										 |  |  | 		// Direct Modes: 0: off, 1: I, 2: Q, 3: NoMod.
 | 
					
						
							|  |  |  | 		((RTLSDRInput*)m_sampleSource)->set_ds_mode(3); | 
					
						
							| 
									
										
										
										
											2014-11-07 19:26:02 +00:00
										 |  |  | 		ui->gain->setEnabled(false); | 
					
						
							| 
									
										
										
										
											2014-11-09 12:56:53 +00:00
										 |  |  | 		ui->centerFrequency->setValueRange(7, 1000U, 275000U); | 
					
						
							|  |  |  | 		ui->centerFrequency->setValue(7000); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		m_settings.m_centerFrequency = 7000 * 1000; | 
					
						
							| 
									
										
										
										
											2014-11-07 19:26:02 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-11-07 19:26:02 +00:00
										 |  |  | 		((RTLSDRInput*)m_sampleSource)->set_ds_mode(0); | 
					
						
							|  |  |  | 		ui->gain->setEnabled(true); | 
					
						
							| 
									
										
										
										
											2014-11-09 12:56:53 +00:00
										 |  |  | 		ui->centerFrequency->setValueRange(7, 28500U, 1700000U); | 
					
						
							|  |  |  | 		ui->centerFrequency->setValue(434000); | 
					
						
							|  |  |  | 		ui->gain->setValue(0); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 		m_settings.m_centerFrequency = 435000 * 1000; | 
					
						
							| 
									
										
										
										
											2014-11-07 19:26:02 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-09 12:56:53 +00:00
										 |  |  | 	sendSettings(); | 
					
						
							| 
									
										
										
										
											2014-11-07 19:26:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 03:34:03 +02:00
										 |  |  | void RTLSDRGui::on_sampleRate_changed(quint64 value) | 
					
						
							| 
									
										
										
										
											2015-05-10 00:08:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  |     m_settings.m_devSampleRate = value; | 
					
						
							|  |  |  |     sendSettings(); | 
					
						
							| 
									
										
										
										
											2015-05-10 00:08:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  | void RTLSDRGui::on_lowSampleRate_toggled(bool checked) | 
					
						
							| 
									
										
										
										
											2015-05-10 00:08:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  |     if (checked) { | 
					
						
							| 
									
										
										
										
											2017-04-02 03:34:03 +02:00
										 |  |  |         ui->sampleRate->setValueRange(7, 230000U, 300000U); | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2017-04-02 03:34:03 +02:00
										 |  |  |         ui->sampleRate->setValueRange(7, 950000U, 2400000U); | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-29 16:22:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-02 03:34:03 +02:00
										 |  |  |     m_settings.m_devSampleRate = ui->sampleRate->getValueNew(); | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  |     qDebug("RTLSDRGui::on_lowSampleRate_toggled: %d S/s", m_settings.m_devSampleRate); | 
					
						
							|  |  |  |     sendSettings(); | 
					
						
							| 
									
										
										
										
											2016-03-29 16:22:24 +02:00
										 |  |  | } |