2016-06-19 03:56:49 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 //
|
2019-04-11 00:57:41 -04:00
|
|
|
// (at your option) any later version. //
|
2016-06-19 03:56:49 -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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
#ifndef INCLUDE_REMOTEINPUT_H
|
|
|
|
#define INCLUDE_REMOTEINPUT_H
|
2016-06-19 03:56:49 -04:00
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2018-12-26 11:08:21 -05:00
|
|
|
#include <QString>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
#include "dsp/devicesamplesource.h"
|
|
|
|
|
|
|
|
#include "remoteinputsettings.h"
|
2017-06-07 20:06:36 -04:00
|
|
|
|
2018-12-26 11:08:21 -05:00
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
2019-05-08 16:11:53 -04:00
|
|
|
class DeviceAPI;
|
2019-02-02 18:26:26 -05:00
|
|
|
class RemoteInputUDPHandler;
|
2016-06-19 03:56:49 -04:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
class RemoteInput : public DeviceSampleSource {
|
2018-12-26 11:08:21 -05:00
|
|
|
Q_OBJECT
|
2016-06-19 03:56:49 -04:00
|
|
|
public:
|
2019-02-02 18:26:26 -05:00
|
|
|
class MsgConfigureRemoteInput : public Message {
|
2017-06-07 20:06:36 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
2019-02-02 18:26:26 -05:00
|
|
|
const RemoteInputSettings& getSettings() const { return m_settings; }
|
2017-06-07 20:06:36 -04:00
|
|
|
bool getForce() const { return m_force; }
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
static MsgConfigureRemoteInput* create(const RemoteInputSettings& settings, bool force = false)
|
2017-06-07 20:06:36 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
return new MsgConfigureRemoteInput(settings, force);
|
2017-06-07 20:06:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-02-02 18:26:26 -05:00
|
|
|
RemoteInputSettings m_settings;
|
2017-06-07 20:06:36 -04:00
|
|
|
bool m_force;
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgConfigureRemoteInput(const RemoteInputSettings& settings, bool force) :
|
2017-06-07 20:06:36 -04:00
|
|
|
Message(),
|
|
|
|
m_settings(settings),
|
|
|
|
m_force(force)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
class MsgConfigureRemoteInputTiming : public Message {
|
2016-06-19 03:56:49 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
static MsgConfigureRemoteInputTiming* create()
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
return new MsgConfigureRemoteInputTiming();
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgConfigureRemoteInputTiming() :
|
2016-06-19 03:56:49 -04:00
|
|
|
Message()
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
class MsgReportRemoteInputAcquisition : public Message {
|
2016-06-19 03:56:49 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool getAcquisition() const { return m_acquisition; }
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
static MsgReportRemoteInputAcquisition* create(bool acquisition)
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
return new MsgReportRemoteInputAcquisition(acquisition);
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_acquisition;
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgReportRemoteInputAcquisition(bool acquisition) :
|
2016-06-19 03:56:49 -04:00
|
|
|
Message(),
|
|
|
|
m_acquisition(acquisition)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
class MsgReportRemoteInputStreamData : public Message {
|
2016-06-19 03:56:49 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
int getSampleRate() const { return m_sampleRate; }
|
|
|
|
quint64 getCenterFrequency() const { return m_centerFrequency; }
|
2018-11-13 07:45:55 -05:00
|
|
|
uint32_t get_tv_msec() const { return m_tv_msec; }
|
2016-06-19 03:56:49 -04:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
static MsgReportRemoteInputStreamData* create(int sampleRate, quint64 centerFrequency, uint64_t tv_msec)
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
return new MsgReportRemoteInputStreamData(sampleRate, centerFrequency, tv_msec);
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_sampleRate;
|
|
|
|
quint64 m_centerFrequency;
|
2018-11-13 07:45:55 -05:00
|
|
|
uint64_t m_tv_msec;
|
2016-06-19 03:56:49 -04:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgReportRemoteInputStreamData(int sampleRate, quint64 centerFrequency, uint64_t tv_msec) :
|
2016-06-19 03:56:49 -04:00
|
|
|
Message(),
|
|
|
|
m_sampleRate(sampleRate),
|
|
|
|
m_centerFrequency(centerFrequency),
|
2018-11-13 07:45:55 -05:00
|
|
|
m_tv_msec(tv_msec)
|
2016-06-19 03:56:49 -04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
class MsgReportRemoteInputStreamTiming : public Message {
|
2016-06-19 03:56:49 -04:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
2018-11-13 07:45:55 -05:00
|
|
|
uint64_t get_tv_msec() const { return m_tv_msec; }
|
2016-07-24 05:09:11 -04:00
|
|
|
int getFramesDecodingStatus() const { return m_framesDecodingStatus; }
|
2016-07-27 22:49:33 -04:00
|
|
|
bool allBlocksReceived() const { return m_allBlocksReceived; }
|
2016-06-19 03:56:49 -04:00
|
|
|
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; }
|
2016-07-27 12:49:17 -04:00
|
|
|
int getMinNbOriginalBlocks() const { return m_minNbOriginalBlocks; }
|
|
|
|
int getMaxNbRecovery() const { return m_maxNbRecovery; }
|
2016-06-19 18:45:24 -04:00
|
|
|
float getAvgNbBlocks() const { return m_avgNbBlocks; }
|
2016-07-27 12:49:17 -04:00
|
|
|
float getAvgNbOriginalBlocks() const { return m_avgNbOriginalBlocks; }
|
2016-06-19 18:45:24 -04:00
|
|
|
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; }
|
2018-09-09 11:39:36 -04:00
|
|
|
int getSampleBits() const { return m_sampleBits; }
|
2018-09-09 15:26:47 -04:00
|
|
|
int getSampleBytes() const { return m_sampleBytes; }
|
2016-06-19 03:56:49 -04:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
static MsgReportRemoteInputStreamTiming* create(uint64_t tv_msec,
|
2016-06-19 03:56:49 -04:00
|
|
|
float bufferLenSec,
|
2016-06-19 18:45:24 -04:00
|
|
|
int32_t bufferGauge,
|
2016-07-24 05:09:11 -04:00
|
|
|
int framesDecodingStatus,
|
2016-07-27 22:49:33 -04:00
|
|
|
bool allBlocksReceived,
|
2016-07-27 12:49:17 -04:00
|
|
|
int minNbBlocks,
|
|
|
|
int minNbOriginalBlocks,
|
|
|
|
int maxNbRecovery,
|
2016-06-19 18:45:24 -04:00
|
|
|
float avgNbBlocks,
|
2016-07-27 12:49:17 -04:00
|
|
|
float avgNbOriginalBlocks,
|
2016-07-24 05:09:11 -04:00
|
|
|
float avgNbRecovery,
|
|
|
|
int nbOriginalBlocksPerFrame,
|
2018-09-09 11:39:36 -04:00
|
|
|
int nbFECBlocksPerFrame,
|
2018-09-09 15:26:47 -04:00
|
|
|
int sampleBits,
|
|
|
|
int sampleBytes)
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
return new MsgReportRemoteInputStreamTiming(tv_msec,
|
2016-06-19 03:56:49 -04:00
|
|
|
bufferLenSec,
|
2016-06-19 18:45:24 -04:00
|
|
|
bufferGauge,
|
2016-07-24 05:09:11 -04:00
|
|
|
framesDecodingStatus,
|
2016-07-27 22:49:33 -04:00
|
|
|
allBlocksReceived,
|
2016-07-27 12:49:17 -04:00
|
|
|
minNbBlocks,
|
|
|
|
minNbOriginalBlocks,
|
|
|
|
maxNbRecovery,
|
2016-06-19 18:45:24 -04:00
|
|
|
avgNbBlocks,
|
2016-07-27 12:49:17 -04:00
|
|
|
avgNbOriginalBlocks,
|
2016-07-24 05:09:11 -04:00
|
|
|
avgNbRecovery,
|
|
|
|
nbOriginalBlocksPerFrame,
|
2018-09-09 11:39:36 -04:00
|
|
|
nbFECBlocksPerFrame,
|
2018-09-09 15:26:47 -04:00
|
|
|
sampleBits,
|
|
|
|
sampleBytes);
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-11-13 07:45:55 -05:00
|
|
|
uint64_t m_tv_msec;
|
2016-07-24 05:09:11 -04:00
|
|
|
int m_framesDecodingStatus;
|
2016-07-27 22:49:33 -04:00
|
|
|
bool m_allBlocksReceived;
|
2016-06-19 18:45:24 -04:00
|
|
|
float m_bufferLenSec;
|
|
|
|
int32_t m_bufferGauge;
|
2016-07-17 18:39:35 -04:00
|
|
|
int m_minNbBlocks;
|
2016-07-27 12:49:17 -04:00
|
|
|
int m_minNbOriginalBlocks;
|
2016-07-17 18:39:35 -04:00
|
|
|
int m_maxNbRecovery;
|
2016-06-19 18:45:24 -04:00
|
|
|
float m_avgNbBlocks;
|
2016-07-27 12:49:17 -04:00
|
|
|
float m_avgNbOriginalBlocks;
|
2016-06-19 18:45:24 -04:00
|
|
|
float m_avgNbRecovery;
|
2016-07-24 05:09:11 -04:00
|
|
|
int m_nbOriginalBlocksPerFrame;
|
|
|
|
int m_nbFECBlocksPerFrame;
|
2018-09-09 11:39:36 -04:00
|
|
|
int m_sampleBits;
|
2018-09-09 15:26:47 -04:00
|
|
|
int m_sampleBytes;
|
2016-06-19 18:45:24 -04:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgReportRemoteInputStreamTiming(uint64_t tv_msec,
|
2016-06-19 03:56:49 -04:00
|
|
|
float bufferLenSec,
|
2016-06-19 18:45:24 -04:00
|
|
|
int32_t bufferGauge,
|
2016-07-24 05:09:11 -04:00
|
|
|
int framesDecodingStatus,
|
2016-07-27 22:49:33 -04:00
|
|
|
bool allBlocksReceived,
|
2016-07-27 12:49:17 -04:00
|
|
|
int minNbBlocks,
|
|
|
|
int minNbOriginalBlocks,
|
|
|
|
int maxNbRecovery,
|
2016-06-19 18:45:24 -04:00
|
|
|
float avgNbBlocks,
|
2016-07-27 12:49:17 -04:00
|
|
|
float avgNbOriginalBlocks,
|
2016-07-24 05:09:11 -04:00
|
|
|
float avgNbRecovery,
|
|
|
|
int nbOriginalBlocksPerFrame,
|
2018-09-09 11:39:36 -04:00
|
|
|
int nbFECBlocksPerFrame,
|
2018-09-09 15:26:47 -04:00
|
|
|
int sampleBits,
|
|
|
|
int sampleBytes) :
|
2016-06-19 03:56:49 -04:00
|
|
|
Message(),
|
2018-11-13 07:45:55 -05:00
|
|
|
m_tv_msec(tv_msec),
|
2016-07-24 05:09:11 -04:00
|
|
|
m_framesDecodingStatus(framesDecodingStatus),
|
2016-07-27 22:49:33 -04:00
|
|
|
m_allBlocksReceived(allBlocksReceived),
|
2016-06-19 03:56:49 -04:00
|
|
|
m_bufferLenSec(bufferLenSec),
|
2016-06-19 18:45:24 -04:00
|
|
|
m_bufferGauge(bufferGauge),
|
2016-07-27 12:49:17 -04:00
|
|
|
m_minNbBlocks(minNbBlocks),
|
|
|
|
m_minNbOriginalBlocks(minNbOriginalBlocks),
|
|
|
|
m_maxNbRecovery(maxNbRecovery),
|
2016-06-19 18:45:24 -04:00
|
|
|
m_avgNbBlocks(avgNbBlocks),
|
2016-07-27 12:49:17 -04:00
|
|
|
m_avgNbOriginalBlocks(avgNbOriginalBlocks),
|
2016-07-24 05:09:11 -04:00
|
|
|
m_avgNbRecovery(avgNbRecovery),
|
|
|
|
m_nbOriginalBlocksPerFrame(nbOriginalBlocksPerFrame),
|
2018-09-09 11:39:36 -04:00
|
|
|
m_nbFECBlocksPerFrame(nbFECBlocksPerFrame),
|
2018-09-09 15:26:47 -04:00
|
|
|
m_sampleBits(sampleBits),
|
|
|
|
m_sampleBytes(sampleBytes)
|
2016-06-19 03:56:49 -04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2017-12-13 18:19:59 -05:00
|
|
|
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);
|
2019-02-02 18:26:26 -05:00
|
|
|
virtual ~RemoteInput();
|
2017-09-14 20:32:30 -04:00
|
|
|
virtual void destroy();
|
2016-06-19 03:56:49 -04:00
|
|
|
|
2017-12-25 03:10:19 -05:00
|
|
|
virtual void init();
|
2017-04-13 21:40:45 -04:00
|
|
|
virtual bool start();
|
2016-06-19 03:56:49 -04:00
|
|
|
virtual void stop();
|
|
|
|
|
2017-12-27 21:21:48 -05:00
|
|
|
virtual QByteArray serialize() const;
|
|
|
|
virtual bool deserialize(const QByteArray& data);
|
|
|
|
|
2017-12-24 13:58:26 -05:00
|
|
|
virtual void setMessageQueueToGUI(MessageQueue *queue);
|
2016-06-19 03:56:49 -04:00
|
|
|
virtual const QString& getDeviceDescription() const;
|
|
|
|
virtual int getSampleRate() const;
|
2019-05-01 22:02:40 -04:00
|
|
|
virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
|
2016-06-19 03:56:49 -04:00
|
|
|
virtual quint64 getCenterFrequency() const;
|
2017-12-27 21:21:48 -05:00
|
|
|
virtual void setCenterFrequency(qint64 centerFrequency);
|
2016-06-19 03:56:49 -04:00
|
|
|
std::time_t getStartingTimeStamp() const;
|
2017-12-25 20:18:30 -05:00
|
|
|
bool isStreaming() const;
|
2016-06-19 03:56:49 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-12-09 06:41:42 -05:00
|
|
|
virtual int webapiRunGet(
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
|
|
|
virtual int webapiRun(
|
|
|
|
bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
QString& errorMessage);
|
|
|
|
|
2019-08-04 14:24:44 -04:00
|
|
|
static void webapiFormatDeviceSettings(
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
|
|
|
const RemoteInputSettings& settings);
|
|
|
|
|
|
|
|
static void webapiUpdateDeviceSettings(
|
|
|
|
RemoteInputSettings& settings,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response);
|
|
|
|
|
2016-06-19 03:56:49 -04:00
|
|
|
private:
|
2019-05-08 16:11:53 -04:00
|
|
|
DeviceAPI *m_deviceAPI;
|
2020-06-28 00:56:21 -04:00
|
|
|
int m_sampleRate;
|
2016-06-19 03:56:49 -04:00
|
|
|
QMutex m_mutex;
|
2019-02-02 18:26:26 -05:00
|
|
|
RemoteInputSettings m_settings;
|
|
|
|
RemoteInputUDPHandler* m_remoteInputUDPHandler;
|
2017-12-25 20:18:30 -05:00
|
|
|
QString m_remoteAddress;
|
2016-06-19 03:56:49 -04:00
|
|
|
QString m_deviceDescription;
|
|
|
|
std::time_t m_startingTimeStamp;
|
2018-12-26 11:08:21 -05:00
|
|
|
QNetworkAccessManager *m_networkManager;
|
|
|
|
QNetworkRequest m_networkRequest;
|
2017-12-25 20:18:30 -05:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void applySettings(const RemoteInputSettings& settings, bool force = false);
|
2018-05-27 05:07:24 -04:00
|
|
|
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
2019-02-02 18:26:26 -05:00
|
|
|
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);
|
2016-06-19 03:56:49 -04:00
|
|
|
};
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
#endif // INCLUDE_REMOTEINPUT_H
|