2018-10-29 11:39:25 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_
|
|
|
|
#define PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2018-10-29 20:58:39 -04:00
|
|
|
#include "soapysdr/devicesoapysdrshared.h"
|
2018-10-29 11:39:25 -04:00
|
|
|
#include "dsp/devicesamplesource.h"
|
|
|
|
|
2018-10-31 21:32:26 -04:00
|
|
|
#include "soapysdrinputsettings.h"
|
|
|
|
|
2018-10-29 11:39:25 -04:00
|
|
|
class DeviceSourceAPI;
|
2018-10-30 15:31:16 -04:00
|
|
|
class SoapySDRInputThread;
|
2018-11-01 21:33:04 -04:00
|
|
|
class FileRecord;
|
|
|
|
|
|
|
|
namespace SoapySDR
|
|
|
|
{
|
|
|
|
class Device;
|
2018-11-13 20:06:36 -05:00
|
|
|
class ArgInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace SWGSDRangel
|
|
|
|
{
|
|
|
|
class SWGArgValue;
|
|
|
|
class SWGArgInfo;
|
2018-11-01 21:33:04 -04:00
|
|
|
}
|
2018-10-29 11:39:25 -04:00
|
|
|
|
|
|
|
class SoapySDRInput : public DeviceSampleSource
|
|
|
|
{
|
|
|
|
public:
|
2018-11-01 06:43:42 -04:00
|
|
|
class MsgConfigureSoapySDRInput : public Message {
|
2018-10-31 21:32:26 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
const SoapySDRInputSettings& getSettings() const { return m_settings; }
|
|
|
|
bool getForce() const { return m_force; }
|
|
|
|
|
2018-11-01 06:43:42 -04:00
|
|
|
static MsgConfigureSoapySDRInput* create(const SoapySDRInputSettings& settings, bool force)
|
2018-10-31 21:32:26 -04:00
|
|
|
{
|
2018-11-01 06:43:42 -04:00
|
|
|
return new MsgConfigureSoapySDRInput(settings, force);
|
2018-10-31 21:32:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SoapySDRInputSettings m_settings;
|
|
|
|
bool m_force;
|
|
|
|
|
2018-11-01 06:43:42 -04:00
|
|
|
MsgConfigureSoapySDRInput(const SoapySDRInputSettings& settings, bool force) :
|
2018-10-31 21:32:26 -04:00
|
|
|
Message(),
|
|
|
|
m_settings(settings),
|
|
|
|
m_force(force)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2018-11-01 06:43:42 -04:00
|
|
|
class MsgFileRecord : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getStartStop() const { return m_startStop; }
|
|
|
|
|
|
|
|
static MsgFileRecord* create(bool startStop) {
|
|
|
|
return new MsgFileRecord(startStop);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_startStop;
|
|
|
|
|
|
|
|
MsgFileRecord(bool startStop) :
|
|
|
|
Message(),
|
|
|
|
m_startStop(startStop)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
class MsgStartStop : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getStartStop() const { return m_startStop; }
|
|
|
|
|
|
|
|
static MsgStartStop* create(bool startStop) {
|
|
|
|
return new MsgStartStop(startStop);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_startStop;
|
|
|
|
|
|
|
|
MsgStartStop(bool startStop) :
|
|
|
|
Message(),
|
|
|
|
m_startStop(startStop)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2018-11-07 17:21:37 -05:00
|
|
|
class MsgReportGainChange : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
const SoapySDRInputSettings& getSettings() const { return m_settings; }
|
|
|
|
bool getGlobalGain() const { return m_globalGain; }
|
|
|
|
bool getIndividualGains() const { return m_individualGains; }
|
|
|
|
|
|
|
|
static MsgReportGainChange* create(const SoapySDRInputSettings& settings, bool globalGain, bool individualGains)
|
|
|
|
{
|
|
|
|
return new MsgReportGainChange(settings, globalGain, individualGains);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SoapySDRInputSettings m_settings;
|
|
|
|
bool m_globalGain;
|
|
|
|
bool m_individualGains;
|
|
|
|
|
|
|
|
MsgReportGainChange(const SoapySDRInputSettings& settings, bool globalGain, bool individualGains) :
|
|
|
|
Message(),
|
|
|
|
m_settings(settings),
|
|
|
|
m_globalGain(globalGain),
|
|
|
|
m_individualGains(individualGains)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2018-10-29 11:39:25 -04:00
|
|
|
SoapySDRInput(DeviceSourceAPI *deviceAPI);
|
|
|
|
virtual ~SoapySDRInput();
|
|
|
|
virtual void destroy();
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
virtual bool start();
|
|
|
|
virtual void stop();
|
2018-10-30 15:31:16 -04:00
|
|
|
SoapySDRInputThread *getThread() { return m_thread; }
|
|
|
|
void setThread(SoapySDRInputThread *thread) { m_thread = thread; }
|
2018-10-29 11:39:25 -04:00
|
|
|
|
|
|
|
virtual QByteArray serialize() const;
|
|
|
|
virtual bool deserialize(const QByteArray& data);
|
|
|
|
|
|
|
|
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
|
|
|
|
virtual const QString& getDeviceDescription() const;
|
|
|
|
virtual int getSampleRate() const;
|
|
|
|
virtual quint64 getCenterFrequency() const;
|
|
|
|
virtual void setCenterFrequency(qint64 centerFrequency);
|
|
|
|
|
|
|
|
virtual bool handleMessage(const Message& message);
|
|
|
|
|
2018-10-31 21:32:26 -04:00
|
|
|
void getFrequencyRange(uint64_t& min, uint64_t& max);
|
2018-11-06 19:33:17 -05:00
|
|
|
void getGlobalGainRange(int& min, int& max);
|
2018-11-07 19:31:39 -05:00
|
|
|
bool isAGCSupported();
|
2018-11-04 17:54:16 -05:00
|
|
|
const std::vector<std::string>& getAntennas();
|
2018-11-04 20:19:40 -05:00
|
|
|
const SoapySDR::RangeList& getRateRanges();
|
|
|
|
const SoapySDR::RangeList& getBandwidthRanges();
|
2018-11-04 17:54:16 -05:00
|
|
|
int getAntennaIndex(const std::string& antenna);
|
2018-11-05 11:27:32 -05:00
|
|
|
const std::vector<DeviceSoapySDRParams::FrequencySetting>& getTunableElements();
|
2018-11-06 19:33:17 -05:00
|
|
|
const std::vector<DeviceSoapySDRParams::GainSetting>& getIndividualGainsRanges();
|
2018-11-10 20:30:10 -05:00
|
|
|
const SoapySDR::ArgInfoList& getStreamArgInfoList();
|
2018-11-11 19:10:51 -05:00
|
|
|
const SoapySDR::ArgInfoList& getDeviceArgInfoList();
|
2018-11-07 17:21:37 -05:00
|
|
|
void initGainSettings(SoapySDRInputSettings& settings);
|
2018-11-15 16:25:33 -05:00
|
|
|
void initTunableElementsSettings(SoapySDRInputSettings& settings);
|
2018-11-10 20:30:10 -05:00
|
|
|
void initStreamArgSettings(SoapySDRInputSettings& settings);
|
2018-11-11 19:10:51 -05:00
|
|
|
void initDeviceArgSettings(SoapySDRInputSettings& settings);
|
2018-11-08 08:35:26 -05:00
|
|
|
bool hasDCAutoCorrection();
|
|
|
|
bool hasDCCorrectionValue();
|
|
|
|
bool hasIQAutoCorrection() { return false; } // not in SoapySDR interface
|
|
|
|
bool hasIQCorrectionValue();
|
2018-10-31 21:32:26 -04:00
|
|
|
|
2018-11-14 17:34:03 -05:00
|
|
|
virtual int webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
|
|
|
virtual int webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
|
|
|
QString& errorMessage);
|
|
|
|
|
|
|
|
virtual int webapiReportGet(
|
|
|
|
SWGSDRangel::SWGDeviceReport& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
|
|
|
virtual int webapiRunGet(
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
|
|
|
virtual int webapiRun(
|
|
|
|
bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
2018-10-29 11:39:25 -04:00
|
|
|
private:
|
2018-10-29 20:58:39 -04:00
|
|
|
DeviceSourceAPI *m_deviceAPI;
|
2018-11-01 21:33:04 -04:00
|
|
|
QMutex m_mutex;
|
|
|
|
SoapySDRInputSettings m_settings;
|
2018-10-29 11:39:25 -04:00
|
|
|
QString m_deviceDescription;
|
2018-10-29 20:58:39 -04:00
|
|
|
bool m_running;
|
2018-11-01 21:33:04 -04:00
|
|
|
SoapySDRInputThread *m_thread;
|
|
|
|
DeviceSoapySDRShared m_deviceShared;
|
|
|
|
FileRecord *m_fileSink; //!< File sink to record device I/Q output
|
2018-10-29 20:58:39 -04:00
|
|
|
|
|
|
|
bool openDevice();
|
|
|
|
void closeDevice();
|
2018-11-01 21:33:04 -04:00
|
|
|
SoapySDRInputThread *findThread();
|
2018-10-30 15:31:16 -04:00
|
|
|
void moveThreadToBuddy();
|
2018-11-01 21:33:04 -04:00
|
|
|
bool applySettings(const SoapySDRInputSettings& settings, bool force = false);
|
|
|
|
bool setDeviceCenterFrequency(SoapySDR::Device *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths);
|
2018-11-07 17:21:37 -05:00
|
|
|
void updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings);
|
2018-11-15 16:25:33 -05:00
|
|
|
void updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings);
|
2018-11-13 20:06:36 -05:00
|
|
|
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SoapySDRInputSettings& settings);
|
|
|
|
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
2018-11-15 10:54:23 -05:00
|
|
|
QVariant webapiVariantFromArgValue(SWGSDRangel::SWGArgValue *argValue);
|
2018-11-13 20:06:36 -05:00
|
|
|
void webapiFormatArgValue(const QVariant& v, SWGSDRangel::SWGArgValue *argValue);
|
|
|
|
void webapiFormatArgInfo(const SoapySDR::ArgInfo& arg, SWGSDRangel::SWGArgInfo *argInfo);
|
2018-10-29 11:39:25 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_ */
|