1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 16:38:37 -05:00
sdrangel/plugins/samplesource/remoteinput/remoteinput.h

347 lines
11 KiB
C
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 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 //
// (at your option) any later version. //
// //
// 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 INCLUDE_REMOTEINPUT_H
#define INCLUDE_REMOTEINPUT_H
#include <ctime>
#include <iostream>
#include <stdint.h>
2018-12-26 11:08:21 -05:00
#include <QString>
#include <QByteArray>
#include <QTimer>
#include <QNetworkRequest>
#include "dsp/devicesamplesource.h"
#include "remoteinputsettings.h"
2018-12-26 11:08:21 -05:00
class QNetworkAccessManager;
class QNetworkReply;
2019-05-08 16:11:53 -04:00
class DeviceAPI;
class RemoteInputUDPHandler;
class FileRecord;
class RemoteInput : public DeviceSampleSource {
2018-12-26 11:08:21 -05:00
Q_OBJECT
public:
class MsgConfigureRemoteInput : public Message {
MESSAGE_CLASS_DECLARATION
public:
const RemoteInputSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
static MsgConfigureRemoteInput* create(const RemoteInputSettings& settings, bool force = false)
{
return new MsgConfigureRemoteInput(settings, force);
}
private:
RemoteInputSettings m_settings;
bool m_force;
MsgConfigureRemoteInput(const RemoteInputSettings& settings, bool force) :
Message(),
m_settings(settings),
m_force(force)
{ }
};
class MsgConfigureRemoteInputTiming : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgConfigureRemoteInputTiming* create()
{
return new MsgConfigureRemoteInputTiming();
}
private:
MsgConfigureRemoteInputTiming() :
Message()
{ }
};
class MsgReportRemoteInputAcquisition : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getAcquisition() const { return m_acquisition; }
static MsgReportRemoteInputAcquisition* create(bool acquisition)
{
return new MsgReportRemoteInputAcquisition(acquisition);
}
protected:
bool m_acquisition;
MsgReportRemoteInputAcquisition(bool acquisition) :
Message(),
m_acquisition(acquisition)
{ }
};
class MsgReportRemoteInputStreamData : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getSampleRate() const { return m_sampleRate; }
quint64 getCenterFrequency() const { return m_centerFrequency; }
uint32_t get_tv_msec() const { return m_tv_msec; }
static MsgReportRemoteInputStreamData* create(int sampleRate, quint64 centerFrequency, uint64_t tv_msec)
{
return new MsgReportRemoteInputStreamData(sampleRate, centerFrequency, tv_msec);
}
protected:
int m_sampleRate;
quint64 m_centerFrequency;
uint64_t m_tv_msec;
MsgReportRemoteInputStreamData(int sampleRate, quint64 centerFrequency, uint64_t tv_msec) :
Message(),
m_sampleRate(sampleRate),
m_centerFrequency(centerFrequency),
m_tv_msec(tv_msec)
{ }
};
class MsgReportRemoteInputStreamTiming : public Message {
MESSAGE_CLASS_DECLARATION
public:
uint64_t get_tv_msec() const { return m_tv_msec; }
2016-07-24 05:09:11 -04:00
int getFramesDecodingStatus() const { return m_framesDecodingStatus; }
bool allBlocksReceived() const { return m_allBlocksReceived; }
float getBufferLengthInSecs() const { return m_bufferLenSec; }
int32_t getBufferGauge() const { return m_bufferGauge; }
2016-07-17 18:39:35 -04:00
int getMinNbBlocks() const { return m_minNbBlocks; }
int getMinNbOriginalBlocks() const { return m_minNbOriginalBlocks; }
int getMaxNbRecovery() const { return m_maxNbRecovery; }
float getAvgNbBlocks() const { return m_avgNbBlocks; }
float getAvgNbOriginalBlocks() const { return m_avgNbOriginalBlocks; }
float getAvgNbRecovery() const { return m_avgNbRecovery; }
2016-07-24 05:09:11 -04:00
int getNbOriginalBlocksPerFrame() const { return m_nbOriginalBlocksPerFrame; }
int getNbFECBlocksPerFrame() const { return m_nbFECBlocksPerFrame; }
int getSampleBits() const { return m_sampleBits; }
int getSampleBytes() const { return m_sampleBytes; }
static MsgReportRemoteInputStreamTiming* create(uint64_t tv_msec,
float bufferLenSec,
int32_t bufferGauge,
2016-07-24 05:09:11 -04:00
int framesDecodingStatus,
bool allBlocksReceived,
int minNbBlocks,
int minNbOriginalBlocks,
int maxNbRecovery,
float avgNbBlocks,
float avgNbOriginalBlocks,
2016-07-24 05:09:11 -04:00
float avgNbRecovery,
int nbOriginalBlocksPerFrame,
int nbFECBlocksPerFrame,
int sampleBits,
int sampleBytes)
{
return new MsgReportRemoteInputStreamTiming(tv_msec,
bufferLenSec,
bufferGauge,
2016-07-24 05:09:11 -04:00
framesDecodingStatus,
allBlocksReceived,
minNbBlocks,
minNbOriginalBlocks,
maxNbRecovery,
avgNbBlocks,
avgNbOriginalBlocks,
2016-07-24 05:09:11 -04:00
avgNbRecovery,
nbOriginalBlocksPerFrame,
nbFECBlocksPerFrame,
sampleBits,
sampleBytes);
}
protected:
uint64_t m_tv_msec;
2016-07-24 05:09:11 -04:00
int m_framesDecodingStatus;
bool m_allBlocksReceived;
float m_bufferLenSec;
int32_t m_bufferGauge;
2016-07-17 18:39:35 -04:00
int m_minNbBlocks;
int m_minNbOriginalBlocks;
2016-07-17 18:39:35 -04:00
int m_maxNbRecovery;
float m_avgNbBlocks;
float m_avgNbOriginalBlocks;
float m_avgNbRecovery;
2016-07-24 05:09:11 -04:00
int m_nbOriginalBlocksPerFrame;
int m_nbFECBlocksPerFrame;
int m_sampleBits;
int m_sampleBytes;
MsgReportRemoteInputStreamTiming(uint64_t tv_msec,
float bufferLenSec,
int32_t bufferGauge,
2016-07-24 05:09:11 -04:00
int framesDecodingStatus,
bool allBlocksReceived,
int minNbBlocks,
int minNbOriginalBlocks,
int maxNbRecovery,
float avgNbBlocks,
float avgNbOriginalBlocks,
2016-07-24 05:09:11 -04:00
float avgNbRecovery,
int nbOriginalBlocksPerFrame,
int nbFECBlocksPerFrame,
int sampleBits,
int sampleBytes) :
Message(),
m_tv_msec(tv_msec),
2016-07-24 05:09:11 -04:00
m_framesDecodingStatus(framesDecodingStatus),
m_allBlocksReceived(allBlocksReceived),
m_bufferLenSec(bufferLenSec),
m_bufferGauge(bufferGauge),
m_minNbBlocks(minNbBlocks),
m_minNbOriginalBlocks(minNbOriginalBlocks),
m_maxNbRecovery(maxNbRecovery),
m_avgNbBlocks(avgNbBlocks),
m_avgNbOriginalBlocks(avgNbOriginalBlocks),
2016-07-24 05:09:11 -04:00
m_avgNbRecovery(avgNbRecovery),
m_nbOriginalBlocksPerFrame(nbOriginalBlocksPerFrame),
m_nbFECBlocksPerFrame(nbFECBlocksPerFrame),
m_sampleBits(sampleBits),
m_sampleBytes(sampleBytes)
{ }
};
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)
{ }
};
2019-05-08 16:11:53 -04:00
RemoteInput(DeviceAPI *deviceAPI);
virtual ~RemoteInput();
virtual void destroy();
virtual void init();
virtual bool start();
virtual void stop();
virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data);
virtual void setMessageQueueToGUI(MessageQueue *queue);
virtual const QString& getDeviceDescription() const;
virtual int getSampleRate() const;
virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
virtual quint64 getCenterFrequency() const;
virtual void setCenterFrequency(qint64 centerFrequency);
std::time_t getStartingTimeStamp() const;
bool isStreaming() const;
virtual bool handleMessage(const Message& message);
2018-05-27 05:07:24 -04: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);
static void webapiFormatDeviceSettings(
SWGSDRangel::SWGDeviceSettings& response,
const RemoteInputSettings& settings);
static void webapiUpdateDeviceSettings(
RemoteInputSettings& settings,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response);
private:
2019-05-08 16:11:53 -04:00
DeviceAPI *m_deviceAPI;
QMutex m_mutex;
RemoteInputSettings m_settings;
RemoteInputUDPHandler* m_remoteInputUDPHandler;
QString m_remoteAddress;
QString m_deviceDescription;
std::time_t m_startingTimeStamp;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
2018-12-26 11:08:21 -05:00
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
void applySettings(const RemoteInputSettings& settings, bool force = false);
2018-05-27 05:07:24 -04:00
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const RemoteInputSettings& settings, bool force);
2018-12-26 11:08:21 -05:00
void webapiReverseSendStartStop(bool start);
private slots:
void networkManagerFinished(QNetworkReply *reply);
};
#endif // INCLUDE_REMOTEINPUT_H