2014-05-18 11:52:39 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// //
|
|
|
|
// 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 //
|
2019-04-11 00:57:41 -04:00
|
|
|
// (at your option) any later version. //
|
2014-05-18 11:52:39 -04:00
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2016-10-10 19:17:55 -04:00
|
|
|
|
2018-12-17 02:51:59 -05:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
|
|
|
|
2017-12-06 17:49:14 -05:00
|
|
|
#include "SWGDeviceSettings.h"
|
|
|
|
#include "SWGRtlSdrSettings.h"
|
2017-12-08 11:12:33 -05:00
|
|
|
#include "SWGDeviceState.h"
|
2018-05-26 08:28:06 -04:00
|
|
|
#include "SWGDeviceReport.h"
|
2020-03-08 23:01:23 -04:00
|
|
|
#include "SWGDeviceActions.h"
|
2018-05-26 08:28:06 -04:00
|
|
|
#include "SWGRtlSdrReport.h"
|
2016-10-10 19:17:55 -04:00
|
|
|
|
2017-12-06 17:49:14 -05:00
|
|
|
#include "rtlsdrinput.h"
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "rtlsdrthread.h"
|
2015-08-19 16:12:08 -04:00
|
|
|
#include "dsp/dspcommands.h"
|
2015-09-27 06:50:38 -04:00
|
|
|
#include "dsp/dspengine.h"
|
2022-12-22 06:04:12 -05:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include "util/android.h"
|
|
|
|
#endif
|
2014-05-18 11:52:39 -04:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgConfigureRTLSDR, Message)
|
2017-12-14 12:02:49 -05:00
|
|
|
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgStartStop, Message)
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2018-03-17 14:56:07 -04:00
|
|
|
const quint64 RTLSDRInput::frequencyLowRangeMin = 0UL;
|
2017-09-23 13:15:56 -04:00
|
|
|
const quint64 RTLSDRInput::frequencyLowRangeMax = 275000UL;
|
|
|
|
const quint64 RTLSDRInput::frequencyHighRangeMin = 24000UL;
|
2022-11-05 14:10:45 -04:00
|
|
|
const quint64 RTLSDRInput::frequencyHighRangeMax = 2400000UL;
|
2020-10-29 02:56:05 -04:00
|
|
|
const int RTLSDRInput::sampleRateLowRangeMin = 225001;
|
|
|
|
const int RTLSDRInput::sampleRateLowRangeMax = 300000;
|
|
|
|
const int RTLSDRInput::sampleRateHighRangeMin = 900001;
|
|
|
|
const int RTLSDRInput::sampleRateHighRangeMax = 3200000;
|
2017-09-23 13:15:56 -04:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
RTLSDRInput::RTLSDRInput(DeviceAPI *deviceAPI) :
|
2016-05-15 20:14:36 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
2014-05-18 11:52:39 -04:00
|
|
|
m_settings(),
|
2015-08-17 02:29:34 -04:00
|
|
|
m_dev(0),
|
2020-06-21 05:46:08 -04:00
|
|
|
m_rtlSDRThread(nullptr),
|
2022-03-17 16:10:30 -04:00
|
|
|
m_deviceDescription("RTLSDR"),
|
2023-08-25 10:04:57 -04:00
|
|
|
m_tunerType(RTLSDR_TUNER_UNKNOWN),
|
2017-04-12 19:21:25 -04:00
|
|
|
m_running(false)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2022-03-17 16:10:30 -04:00
|
|
|
m_sampleFifo.setLabel(m_deviceDescription);
|
2017-04-12 19:21:25 -04:00
|
|
|
openDevice();
|
2017-09-04 05:29:27 -04:00
|
|
|
|
2019-05-20 18:27:08 -04:00
|
|
|
m_deviceAPI->setNbSourceStreams(1);
|
2018-12-17 12:38:52 -05:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::connect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&RTLSDRInput::networkManagerFinished
|
|
|
|
);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
RTLSDRInput::~RTLSDRInput()
|
|
|
|
{
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::disconnect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&RTLSDRInput::networkManagerFinished
|
|
|
|
);
|
2018-12-17 12:38:52 -05:00
|
|
|
delete m_networkManager;
|
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
2018-12-18 00:14:18 -05:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
closeDevice();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:32:30 -04:00
|
|
|
void RTLSDRInput::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
bool RTLSDRInput::openDevice()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2017-04-12 19:21:25 -04:00
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
closeDevice();
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
char vendor[256];
|
|
|
|
char product[256];
|
|
|
|
char serial[256];
|
|
|
|
int res;
|
|
|
|
int numberOfGains;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if (!m_sampleFifo.setSize(96000 * 4))
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: Could not allocate SampleFifo");
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2022-03-15 17:21:06 -04:00
|
|
|
m_sampleFifo.setWrittenSignalRateDivider(32);
|
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
int device;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2022-12-22 06:04:12 -05:00
|
|
|
#ifdef ANDROID
|
|
|
|
int fd;
|
|
|
|
if ((fd = Android::openUSBDevice(m_deviceAPI->getSamplingDeviceSerial())) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: could not open USB device %s", qPrintable(m_deviceAPI->getSamplingDeviceSerial()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((res = rtlsdr_open_fd(&m_dev, fd)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: could not open RTLSDR: %s", strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
2019-05-08 16:11:53 -04:00
|
|
|
if ((device = rtlsdr_get_index_by_serial(qPrintable(m_deviceAPI->getSamplingDeviceSerial()))) < 0)
|
2017-04-12 19:21:25 -04:00
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: could not get RTLSDR serial number");
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if ((res = rtlsdr_open(&m_dev, device)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: could not open RTLSDR #%d: %s", device, strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
2022-12-22 06:04:12 -05:00
|
|
|
#endif
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
vendor[0] = '\0';
|
|
|
|
product[0] = '\0';
|
|
|
|
serial[0] = '\0';
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if ((res = rtlsdr_get_usb_strings(m_dev, vendor, product, serial)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: error accessing USB device");
|
|
|
|
stop();
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2023-08-25 10:04:57 -04:00
|
|
|
m_tunerType = rtlsdr_get_tuner_type(m_dev);
|
|
|
|
|
|
|
|
qInfo("RTLSDRInput::openDevice: open: %s %s, SN: %s Tuner: %s", vendor, product, serial, getTunerName());
|
2017-04-12 19:21:25 -04:00
|
|
|
m_deviceDescription = QString("%1 (SN %2)").arg(product).arg(serial);
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if ((res = rtlsdr_set_sample_rate(m_dev, 1152000)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: could not set sample rate: 1024k S/s");
|
|
|
|
stop();
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if ((res = rtlsdr_set_tuner_gain_mode(m_dev, 1)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: error setting tuner gain mode");
|
|
|
|
stop();
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if ((res = rtlsdr_set_agc_mode(m_dev, 0)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: error setting agc mode");
|
|
|
|
stop();
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
numberOfGains = rtlsdr_get_tuner_gains(m_dev, NULL);
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if (numberOfGains < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: error getting number of gain values supported");
|
|
|
|
stop();
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
m_gains.resize(numberOfGains);
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if (rtlsdr_get_tuner_gains(m_dev, &m_gains[0]) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: error getting gain values");
|
|
|
|
stop();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "RTLSDRInput::openDevice: " << m_gains.size() << "gains";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((res = rtlsdr_reset_buffer(m_dev)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::openDevice: could not reset USB EP buffers: %s", strerror(errno));
|
|
|
|
stop();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-25 03:10:19 -05:00
|
|
|
void RTLSDRInput::init()
|
|
|
|
{
|
2022-10-26 14:48:17 -04:00
|
|
|
applySettings(m_settings, QList<QString>(), true);
|
2017-12-25 03:10:19 -05:00
|
|
|
}
|
|
|
|
|
2017-04-13 21:40:45 -04:00
|
|
|
bool RTLSDRInput::start()
|
2017-04-12 19:21:25 -04:00
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
|
|
if (!m_dev) {
|
|
|
|
return false;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if (m_running) stop();
|
|
|
|
|
2018-02-24 04:29:27 -05:00
|
|
|
m_rtlSDRThread = new RTLSDRThread(m_dev, &m_sampleFifo);
|
2017-04-12 19:21:25 -04:00
|
|
|
m_rtlSDRThread->setSamplerate(m_settings.m_devSampleRate);
|
|
|
|
m_rtlSDRThread->setLog2Decimation(m_settings.m_log2Decim);
|
|
|
|
m_rtlSDRThread->setFcPos((int) m_settings.m_fcPos);
|
2020-06-21 05:46:08 -04:00
|
|
|
m_rtlSDRThread->setIQOrder(m_settings.m_iqOrder);
|
2014-05-18 11:52:39 -04:00
|
|
|
m_rtlSDRThread->startWork();
|
|
|
|
|
|
|
|
mutexLocker.unlock();
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
applySettings(m_settings, QList<QString>(), true);
|
2017-04-12 19:21:25 -04:00
|
|
|
m_running = true;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
return true;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
void RTLSDRInput::closeDevice()
|
|
|
|
{
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
rtlsdr_close(m_dev);
|
|
|
|
m_dev = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_deviceDescription.clear();
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
void RTLSDRInput::stop()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
2020-06-21 05:46:08 -04:00
|
|
|
if (m_rtlSDRThread)
|
2015-08-17 02:29:34 -04:00
|
|
|
{
|
2014-05-18 11:52:39 -04:00
|
|
|
m_rtlSDRThread->stopWork();
|
|
|
|
delete m_rtlSDRThread;
|
2020-06-21 05:46:08 -04:00
|
|
|
m_rtlSDRThread = nullptr;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
m_running = false;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2017-12-27 21:21:48 -05:00
|
|
|
QByteArray RTLSDRInput::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RTLSDRInput::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if (!m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
MsgConfigureRTLSDR* message = MsgConfigureRTLSDR::create(m_settings, QList<QString>(), true);
|
2017-12-27 21:21:48 -05:00
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
2022-10-26 14:48:17 -04:00
|
|
|
MsgConfigureRTLSDR* messageToGUI = MsgConfigureRTLSDR::create(m_settings, QList<QString>(), true);
|
2017-12-27 21:21:48 -05:00
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
const QString& RTLSDRInput::getDeviceDescription() const
|
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RTLSDRInput::getSampleRate() const
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
int rate = m_settings.m_devSampleRate;
|
2015-05-09 10:44:26 -04:00
|
|
|
return (rate / (1<<m_settings.m_log2Decim));
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
quint64 RTLSDRInput::getCenterFrequency() const
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
return m_settings.m_centerFrequency;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2017-12-27 21:21:48 -05:00
|
|
|
void RTLSDRInput::setCenterFrequency(qint64 centerFrequency)
|
|
|
|
{
|
|
|
|
RTLSDRSettings settings = m_settings;
|
|
|
|
settings.m_centerFrequency = centerFrequency;
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
MsgConfigureRTLSDR* message = MsgConfigureRTLSDR::create(settings, QList<QString>{"centerFrequency"}, false);
|
2017-12-27 21:21:48 -05:00
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
2022-10-26 14:48:17 -04:00
|
|
|
MsgConfigureRTLSDR* messageToGUI = MsgConfigureRTLSDR::create(settings, QList<QString>{"centerFrequency"}, false);
|
2017-12-27 21:21:48 -05:00
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool RTLSDRInput::handleMessage(const Message& message)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2017-02-20 23:35:20 -05:00
|
|
|
if (MsgConfigureRTLSDR::match(message))
|
|
|
|
{
|
|
|
|
MsgConfigureRTLSDR& conf = (MsgConfigureRTLSDR&) message;
|
|
|
|
qDebug() << "RTLSDRInput::handleMessage: MsgConfigureRTLSDR";
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
bool success = applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2017-02-20 23:35:20 -05:00
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
qDebug("RTLSDRInput::handleMessage: config error");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-14 12:02:49 -05:00
|
|
|
else if (MsgStartStop::match(message))
|
|
|
|
{
|
|
|
|
MsgStartStop& cmd = (MsgStartStop&) message;
|
|
|
|
qDebug() << "RTLSDRInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
|
|
|
|
|
|
|
if (cmd.getStartStop())
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
if (m_deviceAPI->initDeviceEngine()) {
|
|
|
|
m_deviceAPI->startDeviceEngine();
|
2017-12-14 12:02:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->stopDeviceEngine();
|
2017-12-14 12:02:49 -05:00
|
|
|
}
|
|
|
|
|
2018-12-17 09:00:13 -05:00
|
|
|
if (m_settings.m_useReverseAPI) {
|
|
|
|
webapiReverseSendStartStop(cmd.getStartStop());
|
|
|
|
}
|
|
|
|
|
2017-12-14 12:02:49 -05:00
|
|
|
return true;
|
|
|
|
}
|
2017-02-20 23:35:20 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, const QList<QString>& settingsKeys, bool force)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2022-10-26 14:48:17 -04:00
|
|
|
qDebug() << "RTLSDRInput::applySettings: force: " << force << settings.getDebugString(settingsKeys, force);
|
2015-08-19 16:12:08 -04:00
|
|
|
bool forwardChange = false;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("agc") || force)
|
2017-07-23 10:57:13 -04:00
|
|
|
{
|
2018-12-19 16:45:48 -05:00
|
|
|
if (rtlsdr_set_agc_mode(m_dev, settings.m_agc ? 1 : 0) < 0) {
|
2017-12-07 18:56:29 -05:00
|
|
|
qCritical("RTLSDRInput::applySettings: could not set AGC mode %s", settings.m_agc ? "on" : "off");
|
2018-12-19 16:45:48 -05:00
|
|
|
} else {
|
2017-12-07 18:56:29 -05:00
|
|
|
qDebug("RTLSDRInput::applySettings: AGC mode %s", settings.m_agc ? "on" : "off");
|
2017-07-23 10:57:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("dcBlock") || settingsKeys.contains("iqImbalance") || force)
|
2017-02-20 23:35:20 -05:00
|
|
|
{
|
2018-12-19 16:45:48 -05:00
|
|
|
m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqImbalance);
|
2017-12-09 04:49:20 -05:00
|
|
|
qDebug("RTLSDRInput::applySettings: corrections: DC block: %s IQ imbalance: %s",
|
2018-12-19 16:45:48 -05:00
|
|
|
settings.m_dcBlock ? "true" : "false",
|
|
|
|
settings.m_iqImbalance ? "true" : "false");
|
2017-02-20 23:35:20 -05:00
|
|
|
}
|
2014-11-08 18:42:43 -05:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("loPpmCorrection") || force)
|
2017-02-20 23:35:20 -05:00
|
|
|
{
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
2018-12-19 16:45:48 -05:00
|
|
|
if (rtlsdr_set_freq_correction(m_dev, settings.m_loPpmCorrection) < 0) {
|
2017-11-12 10:34:38 -05:00
|
|
|
qCritical("RTLSDRInput::applySettings: could not set LO ppm correction: %d", settings.m_loPpmCorrection);
|
2018-12-19 16:45:48 -05:00
|
|
|
} else {
|
2017-11-12 10:34:38 -05:00
|
|
|
qDebug("RTLSDRInput::applySettings: LO ppm correction set to: %d", settings.m_loPpmCorrection);
|
2017-02-20 23:35:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-08 18:54:01 -04:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("devSampleRate") || force)
|
2017-02-20 23:35:20 -05:00
|
|
|
{
|
2015-08-19 16:12:08 -04:00
|
|
|
forwardChange = true;
|
2016-05-12 17:35:30 -04:00
|
|
|
|
2017-02-20 23:35:20 -05:00
|
|
|
if(m_dev != 0)
|
|
|
|
{
|
|
|
|
if( rtlsdr_set_sample_rate(m_dev, settings.m_devSampleRate) < 0)
|
|
|
|
{
|
|
|
|
qCritical("RTLSDRInput::applySettings: could not set sample rate: %d", settings.m_devSampleRate);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-19 16:45:48 -05:00
|
|
|
if (m_rtlSDRThread) {
|
|
|
|
m_rtlSDRThread->setSamplerate(settings.m_devSampleRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("RTLSDRInput::applySettings: sample rate set to %d", settings.m_devSampleRate);
|
2017-02-20 23:35:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-09 10:44:26 -04:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("log2Decim") || force)
|
2015-08-19 16:12:08 -04:00
|
|
|
{
|
|
|
|
forwardChange = true;
|
|
|
|
|
2020-06-21 05:46:08 -04:00
|
|
|
if (m_rtlSDRThread) {
|
2017-02-20 23:35:20 -05:00
|
|
|
m_rtlSDRThread->setLog2Decimation(settings.m_log2Decim);
|
|
|
|
}
|
2017-12-09 04:49:20 -05:00
|
|
|
|
2018-12-19 16:45:48 -05:00
|
|
|
qDebug("RTLSDRInput::applySettings: log2decim set to %d", settings.m_log2Decim);
|
2017-02-20 23:35:20 -05:00
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("fcPos") || force)
|
2019-01-04 18:31:16 -05:00
|
|
|
{
|
2020-06-21 05:46:08 -04:00
|
|
|
if (m_rtlSDRThread) {
|
2019-01-04 18:31:16 -05:00
|
|
|
m_rtlSDRThread->setFcPos((int) settings.m_fcPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "RTLSDRInput::applySettings: set fc pos (enum) to " << (int) settings.m_fcPos;
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("iqOrder") || force)
|
2020-06-21 05:46:08 -04:00
|
|
|
{
|
|
|
|
if (m_rtlSDRThread) {
|
|
|
|
m_rtlSDRThread->setIQOrder(settings.m_iqOrder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("centerFrequency")
|
|
|
|
|| settingsKeys.contains("fcPos")
|
|
|
|
|| settingsKeys.contains("log2Decim")
|
|
|
|
|| settingsKeys.contains("devSampleRate")
|
|
|
|
|| settingsKeys.contains("transverterMode")
|
|
|
|
|| settingsKeys.contains("transverterDeltaFrequency") || force)
|
2017-02-20 23:35:20 -05:00
|
|
|
{
|
2018-05-10 05:48:06 -04:00
|
|
|
qint64 deviceCenterFrequency = DeviceSampleSource::calculateDeviceCenterFrequency(
|
|
|
|
settings.m_centerFrequency,
|
|
|
|
settings.m_transverterDeltaFrequency,
|
|
|
|
settings.m_log2Decim,
|
|
|
|
(DeviceSampleSource::fcPos_t) settings.m_fcPos,
|
|
|
|
settings.m_devSampleRate,
|
2019-04-01 19:10:03 -04:00
|
|
|
DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
|
2018-05-10 05:48:06 -04:00
|
|
|
settings.m_transverterMode);
|
|
|
|
|
2017-02-20 23:35:20 -05:00
|
|
|
forwardChange = true;
|
2015-10-01 00:30:50 -04:00
|
|
|
|
2017-04-12 19:21:25 -04:00
|
|
|
if (m_dev != 0)
|
2017-02-20 23:35:20 -05:00
|
|
|
{
|
2018-12-19 16:45:48 -05:00
|
|
|
if (rtlsdr_set_center_freq(m_dev, deviceCenterFrequency) != 0) {
|
2018-05-10 05:48:06 -04:00
|
|
|
qWarning("RTLSDRInput::applySettings: rtlsdr_set_center_freq(%lld) failed", deviceCenterFrequency);
|
|
|
|
} else {
|
|
|
|
qDebug("RTLSDRInput::applySettings: rtlsdr_set_center_freq(%lld)", deviceCenterFrequency);
|
2017-02-20 23:35:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 00:30:50 -04:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("noModMode") || force)
|
2017-09-23 13:15:56 -04:00
|
|
|
{
|
2018-12-19 16:45:48 -05:00
|
|
|
qDebug() << "RTLSDRInput::applySettings: set noModMode to " << settings.m_noModMode;
|
2017-09-23 13:15:56 -04:00
|
|
|
|
|
|
|
// Direct Modes: 0: off, 1: I, 2: Q, 3: NoMod.
|
2018-12-19 16:45:48 -05:00
|
|
|
if (settings.m_noModMode) {
|
2017-09-23 13:15:56 -04:00
|
|
|
set_ds_mode(3);
|
|
|
|
} else {
|
|
|
|
set_ds_mode(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("rfBandwidth") || force)
|
2018-01-15 19:01:24 -05:00
|
|
|
{
|
|
|
|
m_settings.m_rfBandwidth = settings.m_rfBandwidth;
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
2018-11-26 02:54:06 -05:00
|
|
|
if (rtlsdr_set_tuner_bandwidth( m_dev, m_settings.m_rfBandwidth) != 0) {
|
2018-01-15 19:01:24 -05:00
|
|
|
qCritical("RTLSDRInput::applySettings: could not set RF bandwidth to %u", m_settings.m_rfBandwidth);
|
2018-11-26 02:54:06 -05:00
|
|
|
} else {
|
2018-01-15 19:01:24 -05:00
|
|
|
qDebug() << "RTLSDRInput::applySettings: set RF bandwidth to " << m_settings.m_rfBandwidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-25 10:04:57 -04:00
|
|
|
// Reapply offset_tuning setting if bandwidth is changed, otherwise frequency response of filter looks wrong on E4000
|
|
|
|
if (settingsKeys.contains("offsetTuning") || settingsKeys.contains("rfBandwidth") || force)
|
2018-11-26 02:54:06 -05:00
|
|
|
{
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
if (rtlsdr_set_offset_tuning(m_dev, m_settings.m_offsetTuning ? 0 : 1) != 0) {
|
2018-12-19 16:45:48 -05:00
|
|
|
qCritical("RTLSDRInput::applySettings: could not set offset tuning to %s", settings.m_offsetTuning ? "on" : "off");
|
2018-11-26 02:54:06 -05:00
|
|
|
} else {
|
2018-12-19 16:45:48 -05:00
|
|
|
qDebug("RTLSDRInput::applySettings: offset tuning set to %s", settings.m_offsetTuning ? "on" : "off");
|
2018-11-26 02:54:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("gain") || force)
|
2019-04-03 17:01:29 -04:00
|
|
|
{
|
|
|
|
if(m_dev != 0)
|
|
|
|
{
|
2023-08-25 10:04:57 -04:00
|
|
|
// Nooelec E4000 SDRs appear to require tuner_gain_mode to be reset to manual before
|
|
|
|
// each call to set_tuner_gain, otherwise tuner AGC seems to be reenabled
|
|
|
|
if (rtlsdr_set_tuner_gain_mode(m_dev, 1) < 0) {
|
|
|
|
qCritical("RTLSDRInput::applySettings: error setting tuner gain mode to manual");
|
|
|
|
}
|
2022-10-17 08:43:32 -04:00
|
|
|
qDebug() << "Set tuner gain " << settings.m_gain;
|
2019-04-03 17:01:29 -04:00
|
|
|
if (rtlsdr_set_tuner_gain(m_dev, settings.m_gain) != 0) {
|
|
|
|
qCritical("RTLSDRInput::applySettings: rtlsdr_set_tuner_gain() failed");
|
|
|
|
} else {
|
|
|
|
qDebug("RTLSDRInput::applySettings: rtlsdr_set_tuner_gain() to %d", settings.m_gain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-08 18:42:43 -05:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("biasTee") || force)
|
2020-06-27 00:13:48 -04:00
|
|
|
{
|
|
|
|
if(m_dev != 0)
|
|
|
|
{
|
|
|
|
if (rtlsdr_set_bias_tee(m_dev, settings.m_biasTee ? 1 : 0) != 0) {
|
|
|
|
qCritical("RTLSDRInput::applySettings: rtlsdr_set_bias_tee() failed");
|
|
|
|
} else {
|
|
|
|
qDebug("RTLSDRInput::applySettings: rtlsdr_set_bias_tee() to %d", settings.m_biasTee ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (settingsKeys.contains("useReverseAPI"))
|
2018-12-17 02:51:59 -05:00
|
|
|
{
|
2022-10-26 14:48:17 -04:00
|
|
|
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
|
|
|
|
settingsKeys.contains("reverseAPIAddress") ||
|
|
|
|
settingsKeys.contains("reverseAPIPort") ||
|
|
|
|
settingsKeys.contains("reverseAPIDeviceIndex");
|
|
|
|
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
|
2018-12-17 02:51:59 -05:00
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
if (force) {
|
|
|
|
m_settings = settings;
|
|
|
|
} else {
|
|
|
|
m_settings.applySettings(settingsKeys, settings);
|
|
|
|
}
|
2018-12-19 16:45:48 -05:00
|
|
|
|
|
|
|
if (forwardChange)
|
|
|
|
{
|
|
|
|
int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim);
|
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
|
|
|
|
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
|
|
|
|
}
|
|
|
|
|
2017-02-20 23:35:20 -05:00
|
|
|
return true;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
2014-11-07 14:26:02 -05:00
|
|
|
|
2023-08-25 10:04:57 -04:00
|
|
|
QString RTLSDRInput::getTunerName() const
|
|
|
|
{
|
|
|
|
const static QStringList names = {"Unknown", "E4000", "FC0012", "FC0013", "FC2580", "R820T", "R828D"};
|
|
|
|
|
|
|
|
if ((int) m_tunerType <= names.size()) {
|
|
|
|
return names[(int) m_tunerType];
|
|
|
|
} else {
|
|
|
|
return names[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-08 18:42:43 -05:00
|
|
|
void RTLSDRInput::set_ds_mode(int on)
|
|
|
|
{
|
2014-11-07 14:26:02 -05:00
|
|
|
rtlsdr_set_direct_sampling(m_dev, on);
|
2014-11-08 18:42:43 -05:00
|
|
|
}
|
|
|
|
|
2017-12-06 17:49:14 -05:00
|
|
|
int RTLSDRInput::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2017-12-06 17:49:14 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2017-12-06 17:49:14 -05:00
|
|
|
response.setRtlSdrSettings(new SWGSDRangel::SWGRtlSdrSettings());
|
2018-02-21 07:50:50 -05:00
|
|
|
response.getRtlSdrSettings()->init();
|
2017-12-26 19:46:33 -05:00
|
|
|
webapiFormatDeviceSettings(response, m_settings);
|
2017-12-06 17:49:14 -05:00
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
int RTLSDRInput::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
2017-12-26 19:46:33 -05:00
|
|
|
const QStringList& deviceSettingsKeys,
|
2017-12-07 12:50:36 -05:00
|
|
|
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2017-12-07 12:50:36 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2017-12-26 19:46:33 -05:00
|
|
|
RTLSDRSettings settings = m_settings;
|
2019-08-04 14:24:44 -04:00
|
|
|
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
2017-12-26 19:46:33 -05:00
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
MsgConfigureRTLSDR *msg = MsgConfigureRTLSDR::create(settings, deviceSettingsKeys, force);
|
2019-08-04 14:24:44 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2022-10-26 14:48:17 -04:00
|
|
|
MsgConfigureRTLSDR *msgToGUI = MsgConfigureRTLSDR::create(settings, deviceSettingsKeys, force);
|
2019-08-04 14:24:44 -04:00
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatDeviceSettings(response, settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLSDRInput::webapiUpdateDeviceSettings(
|
|
|
|
RTLSDRSettings& settings,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response)
|
|
|
|
{
|
2017-12-26 19:46:33 -05:00
|
|
|
if (deviceSettingsKeys.contains("agc")) {
|
|
|
|
settings.m_agc = response.getRtlSdrSettings()->getAgc() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("centerFrequency")) {
|
|
|
|
settings.m_centerFrequency = response.getRtlSdrSettings()->getCenterFrequency();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("dcBlock")) {
|
|
|
|
settings.m_dcBlock = response.getRtlSdrSettings()->getDcBlock() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("devSampleRate")) {
|
|
|
|
settings.m_devSampleRate = response.getRtlSdrSettings()->getDevSampleRate();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("fcPos")) {
|
|
|
|
settings.m_fcPos = (RTLSDRSettings::fcPos_t) response.getRtlSdrSettings()->getFcPos();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("gain")) {
|
|
|
|
settings.m_gain = response.getRtlSdrSettings()->getGain();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("iqImbalance")) {
|
|
|
|
settings.m_iqImbalance = response.getRtlSdrSettings()->getIqImbalance() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("loPpmCorrection")) {
|
|
|
|
settings.m_loPpmCorrection = response.getRtlSdrSettings()->getLoPpmCorrection();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("log2Decim")) {
|
|
|
|
settings.m_log2Decim = response.getRtlSdrSettings()->getLog2Decim();
|
|
|
|
}
|
2020-06-21 20:10:35 -04:00
|
|
|
if (deviceSettingsKeys.contains("iqOrder")) {
|
|
|
|
settings.m_iqOrder = response.getRtlSdrSettings()->getIqOrder() != 0;
|
|
|
|
}
|
2017-12-26 19:46:33 -05:00
|
|
|
if (deviceSettingsKeys.contains("lowSampleRate")) {
|
|
|
|
settings.m_lowSampleRate = response.getRtlSdrSettings()->getLowSampleRate() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("noModMode")) {
|
|
|
|
settings.m_noModMode = response.getRtlSdrSettings()->getNoModMode() != 0;
|
|
|
|
}
|
2018-11-26 07:31:51 -05:00
|
|
|
if (deviceSettingsKeys.contains("offsetTuning")) {
|
|
|
|
settings.m_offsetTuning = response.getRtlSdrSettings()->getOffsetTuning() != 0;
|
|
|
|
}
|
2017-12-26 19:46:33 -05:00
|
|
|
if (deviceSettingsKeys.contains("transverterDeltaFrequency")) {
|
|
|
|
settings.m_transverterDeltaFrequency = response.getRtlSdrSettings()->getTransverterDeltaFrequency();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("transverterMode")) {
|
|
|
|
settings.m_transverterMode = response.getRtlSdrSettings()->getTransverterMode() != 0;
|
|
|
|
}
|
2018-01-16 14:03:18 -05:00
|
|
|
if (deviceSettingsKeys.contains("rfBandwidth")) {
|
2018-07-29 18:43:08 -04:00
|
|
|
settings.m_rfBandwidth = response.getRtlSdrSettings()->getRfBandwidth();
|
2018-01-16 14:03:18 -05:00
|
|
|
}
|
2020-06-27 00:13:48 -04:00
|
|
|
if (deviceSettingsKeys.contains("biasTee")) {
|
|
|
|
settings.m_biasTee = response.getRtlSdrSettings()->getBiasTee() != 0;
|
|
|
|
}
|
2018-12-18 15:46:03 -05:00
|
|
|
if (deviceSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getRtlSdrSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIAddress")) {
|
2019-01-13 05:35:31 -05:00
|
|
|
settings.m_reverseAPIAddress = *response.getRtlSdrSettings()->getReverseApiAddress();
|
2018-12-18 15:46:03 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getRtlSdrSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getRtlSdrSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
2017-12-07 12:50:36 -05:00
|
|
|
}
|
2017-12-08 11:12:33 -05:00
|
|
|
|
2017-12-26 19:46:33 -05:00
|
|
|
void RTLSDRInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const RTLSDRSettings& settings)
|
|
|
|
{
|
|
|
|
response.getRtlSdrSettings()->setAgc(settings.m_agc ? 1 : 0);
|
|
|
|
response.getRtlSdrSettings()->setCenterFrequency(settings.m_centerFrequency);
|
|
|
|
response.getRtlSdrSettings()->setDcBlock(settings.m_dcBlock ? 1 : 0);
|
|
|
|
response.getRtlSdrSettings()->setDevSampleRate(settings.m_devSampleRate);
|
|
|
|
response.getRtlSdrSettings()->setFcPos((int) settings.m_fcPos);
|
|
|
|
response.getRtlSdrSettings()->setGain(settings.m_gain);
|
|
|
|
response.getRtlSdrSettings()->setIqImbalance(settings.m_iqImbalance ? 1 : 0);
|
|
|
|
response.getRtlSdrSettings()->setLoPpmCorrection(settings.m_loPpmCorrection);
|
|
|
|
response.getRtlSdrSettings()->setLog2Decim(settings.m_log2Decim);
|
2020-06-21 20:10:35 -04:00
|
|
|
response.getRtlSdrSettings()->setIqOrder(settings.m_iqOrder ? 1 : 0);
|
2017-12-26 19:46:33 -05:00
|
|
|
response.getRtlSdrSettings()->setLowSampleRate(settings.m_lowSampleRate ? 1 : 0);
|
|
|
|
response.getRtlSdrSettings()->setNoModMode(settings.m_noModMode ? 1 : 0);
|
2018-11-26 07:31:51 -05:00
|
|
|
response.getRtlSdrSettings()->setOffsetTuning(settings.m_offsetTuning ? 1 : 0);
|
2020-06-27 00:13:48 -04:00
|
|
|
response.getRtlSdrSettings()->setBiasTee(settings.m_biasTee ? 1 : 0);
|
2017-12-26 19:46:33 -05:00
|
|
|
response.getRtlSdrSettings()->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
|
|
|
|
response.getRtlSdrSettings()->setTransverterMode(settings.m_transverterMode ? 1 : 0);
|
2018-01-16 14:03:18 -05:00
|
|
|
response.getRtlSdrSettings()->setRfBandwidth(settings.m_rfBandwidth);
|
2018-05-09 12:59:39 -04:00
|
|
|
|
2018-12-18 15:46:03 -05:00
|
|
|
response.getRtlSdrSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getRtlSdrSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getRtlSdrSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getRtlSdrSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getRtlSdrSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getRtlSdrSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
2017-12-26 19:46:33 -05:00
|
|
|
}
|
|
|
|
|
2017-12-09 04:49:20 -05:00
|
|
|
int RTLSDRInput::webapiRunGet(
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2017-12-09 04:49:20 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2017-12-09 04:49:20 -05:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-12-08 11:12:33 -05:00
|
|
|
int RTLSDRInput::webapiRun(
|
|
|
|
bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2017-12-08 11:12:33 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2017-12-14 17:29:12 -05:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
2017-12-14 12:02:49 -05:00
|
|
|
MsgStartStop *message = MsgStartStop::create(run);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
2017-12-08 11:12:33 -05:00
|
|
|
{
|
2017-12-14 12:02:49 -05:00
|
|
|
MsgStartStop *msgToGUI = MsgStartStop::create(run);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
2017-12-08 11:12:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
2018-05-26 08:28:06 -04:00
|
|
|
|
|
|
|
int RTLSDRInput::webapiReportGet(
|
|
|
|
SWGSDRangel::SWGDeviceReport& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-05-26 08:28:06 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-05-26 08:28:06 -04:00
|
|
|
response.setRtlSdrReport(new SWGSDRangel::SWGRtlSdrReport());
|
|
|
|
response.getRtlSdrReport()->init();
|
|
|
|
webapiFormatDeviceReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RTLSDRInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
|
|
|
|
{
|
2018-05-27 13:54:33 -04:00
|
|
|
response.getRtlSdrReport()->setGains(new QList<SWGSDRangel::SWGGain*>);
|
2018-05-26 08:28:06 -04:00
|
|
|
|
|
|
|
for (std::vector<int>::const_iterator it = getGains().begin(); it != getGains().end(); ++it)
|
|
|
|
{
|
2018-05-27 13:54:33 -04:00
|
|
|
response.getRtlSdrReport()->getGains()->append(new SWGSDRangel::SWGGain);
|
|
|
|
response.getRtlSdrReport()->getGains()->back()->setGainCb(*it);
|
2018-05-26 08:28:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:48:17 -04:00
|
|
|
void RTLSDRInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const RTLSDRSettings& settings, bool force)
|
2018-12-17 02:51:59 -05:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgDeviceSettings->setDirection(0); // single Rx
|
2018-12-17 02:51:59 -05:00
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("RTLSDR"));
|
2019-03-24 20:15:27 -04:00
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
2018-12-17 02:51:59 -05:00
|
|
|
swgDeviceSettings->setRtlSdrSettings(new SWGSDRangel::SWGRtlSdrSettings());
|
|
|
|
SWGSDRangel::SWGRtlSdrSettings *swgRtlSdrSettings = swgDeviceSettings->getRtlSdrSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
2018-05-26 08:28:06 -04:00
|
|
|
|
2018-12-17 02:51:59 -05:00
|
|
|
if (deviceSettingsKeys.contains("agc") || force) {
|
|
|
|
swgRtlSdrSettings->setAgc(settings.m_agc ? 1 : 0);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("centerFrequency") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setCenterFrequency(settings.m_centerFrequency);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("dcBlock") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setDcBlock(settings.m_dcBlock ? 1 : 0);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("devSampleRate") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setDevSampleRate(settings.m_devSampleRate);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("fcPos") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setFcPos(settings.m_fcPos);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("gain") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setGain(settings.m_gain);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("iqImbalance") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setIqImbalance(settings.m_iqImbalance ? 1 : 0);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("loPpmCorrection") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setLoPpmCorrection(settings.m_loPpmCorrection);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("log2Decim") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setLog2Decim(settings.m_log2Decim);
|
|
|
|
}
|
2020-06-21 20:10:35 -04:00
|
|
|
if (deviceSettingsKeys.contains("iqOrder") || force) {
|
|
|
|
swgRtlSdrSettings->setIqOrder(settings.m_iqOrder ? 1 : 0);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("lowSampleRate") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setLowSampleRate(settings.m_lowSampleRate);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("noModMode") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setNoModMode(settings.m_noModMode ? 1 : 0);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("offsetTuning") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setOffsetTuning(settings.m_offsetTuning ? 1 : 0);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("transverterDeltaFrequency") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("transverterMode") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setTransverterMode(settings.m_transverterMode ? 1 : 0);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("rfBandwidth") || force) {
|
2018-12-17 02:51:59 -05:00
|
|
|
swgRtlSdrSettings->setRfBandwidth(settings.m_rfBandwidth);
|
|
|
|
}
|
2020-06-27 00:13:48 -04:00
|
|
|
if (deviceSettingsKeys.contains("biasTee") || force) {
|
|
|
|
swgRtlSdrSettings->setBiasTee(settings.m_biasTee ? 1 : 0);
|
|
|
|
}
|
2018-12-17 02:51:59 -05:00
|
|
|
|
2018-12-17 12:38:52 -05:00
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/settings")
|
2018-12-17 02:51:59 -05:00
|
|
|
.arg(settings.m_reverseAPIAddress)
|
|
|
|
.arg(settings.m_reverseAPIPort)
|
|
|
|
.arg(settings.m_reverseAPIDeviceIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
2018-12-19 02:52:50 -05:00
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
2018-12-17 02:51:59 -05:00
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
QBuffer *buffer = new QBuffer();
|
2018-12-17 02:51:59 -05:00
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
2019-11-12 12:46:21 -05:00
|
|
|
QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
buffer->setParent(reply);
|
2018-12-17 02:51:59 -05:00
|
|
|
|
|
|
|
delete swgDeviceSettings;
|
|
|
|
}
|
|
|
|
|
2018-12-17 09:00:13 -05:00
|
|
|
void RTLSDRInput::webapiReverseSendStartStop(bool start)
|
|
|
|
{
|
2019-03-25 10:10:31 -04:00
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgDeviceSettings->setDirection(0); // single Rx
|
2019-03-25 10:10:31 -04:00
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("RTLSDR"));
|
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
|
|
|
|
2018-12-17 09:00:13 -05:00
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/run")
|
|
|
|
.arg(m_settings.m_reverseAPIAddress)
|
|
|
|
.arg(m_settings.m_reverseAPIPort)
|
|
|
|
.arg(m_settings.m_reverseAPIDeviceIndex);
|
2018-12-18 00:14:18 -05:00
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
2019-03-25 10:10:31 -04:00
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
QBuffer *buffer = new QBuffer();
|
2019-03-25 10:10:31 -04:00
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
2019-11-12 12:46:21 -05:00
|
|
|
QNetworkReply *reply;
|
2018-12-17 09:00:13 -05:00
|
|
|
|
|
|
|
if (start) {
|
2019-11-12 12:46:21 -05:00
|
|
|
reply = m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer);
|
2018-12-17 09:00:13 -05:00
|
|
|
} else {
|
2019-11-12 12:46:21 -05:00
|
|
|
reply = m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer);
|
2018-12-17 09:00:13 -05:00
|
|
|
}
|
2019-06-14 10:58:09 -04:00
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
buffer->setParent(reply);
|
2019-06-14 10:58:09 -04:00
|
|
|
delete swgDeviceSettings;
|
2018-12-17 09:00:13 -05:00
|
|
|
}
|
|
|
|
|
2018-12-17 02:51:59 -05:00
|
|
|
void RTLSDRInput::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
2018-12-17 02:51:59 -05:00
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
qWarning() << "TestSourceInput::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
2019-11-12 12:46:21 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("RTLSDRInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2018-12-17 02:51:59 -05:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
reply->deleteLater();
|
2018-12-17 02:51:59 -05:00
|
|
|
}
|