2017-12-14 12:02:49 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 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:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2017-12-14 12:02:49 -05: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 16:58:42 -05:00
|
|
|
#ifndef INCLUDE_REMOTEOUTPUT_H
|
|
|
|
#define INCLUDE_REMOTEOUTPUT_H
|
2017-12-14 12:02:49 -05:00
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
2018-09-03 12:13:57 -04:00
|
|
|
#include <QObject>
|
2018-09-03 03:17:29 -04:00
|
|
|
#include <QString>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QNetworkRequest>
|
2020-07-12 03:42:33 -04:00
|
|
|
#include <QThread>
|
2018-09-03 03:17:29 -04:00
|
|
|
|
2017-12-14 12:02:49 -05:00
|
|
|
#include "dsp/devicesamplesink.h"
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
#include "remoteoutputsettings.h"
|
2017-12-14 12:02:49 -05:00
|
|
|
|
2020-07-12 03:42:33 -04:00
|
|
|
class RemoteOutputWorker;
|
2019-05-08 16:11:53 -04:00
|
|
|
class DeviceAPI;
|
2018-09-03 03:17:29 -04:00
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
|
|
|
class QJsonObject;
|
2017-12-14 12:02:49 -05:00
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
class RemoteOutput : public DeviceSampleSink {
|
2018-09-03 12:13:57 -04:00
|
|
|
Q_OBJECT
|
2017-12-14 12:02:49 -05:00
|
|
|
public:
|
2019-02-02 16:58:42 -05:00
|
|
|
class MsgConfigureRemoteOutput : public Message {
|
2017-12-14 12:02:49 -05:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
2019-02-02 16:58:42 -05:00
|
|
|
const RemoteOutputSettings& getSettings() const { return m_settings; }
|
2022-10-31 06:18:22 -04:00
|
|
|
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
|
2017-12-14 12:02:49 -05:00
|
|
|
bool getForce() const { return m_force; }
|
|
|
|
|
2022-10-31 06:18:22 -04:00
|
|
|
static MsgConfigureRemoteOutput* create(const RemoteOutputSettings& settings, const QList<QString>& settingsKeys, bool force = false) {
|
|
|
|
return new MsgConfigureRemoteOutput(settings, settingsKeys, force);
|
2017-12-14 12:02:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-02-02 16:58:42 -05:00
|
|
|
RemoteOutputSettings m_settings;
|
2022-10-31 06:18:22 -04:00
|
|
|
QList<QString> m_settingsKeys;
|
2017-12-14 12:02:49 -05:00
|
|
|
bool m_force;
|
|
|
|
|
2022-10-31 06:18:22 -04:00
|
|
|
MsgConfigureRemoteOutput(const RemoteOutputSettings& settings, const QList<QString>& settingsKeys, bool force) :
|
2017-12-14 12:02:49 -05:00
|
|
|
Message(),
|
|
|
|
m_settings(settings),
|
2022-10-31 06:18:22 -04:00
|
|
|
m_settingsKeys(settingsKeys),
|
2017-12-14 12:02:49 -05:00
|
|
|
m_force(force)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
class MsgConfigureRemoteOutputWork : public Message {
|
2017-12-14 12:02:49 -05:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool isWorking() const { return m_working; }
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
static MsgConfigureRemoteOutputWork* create(bool working)
|
2017-12-14 12:02:49 -05:00
|
|
|
{
|
2019-02-02 16:58:42 -05:00
|
|
|
return new MsgConfigureRemoteOutputWork(working);
|
2017-12-14 12:02:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_working;
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
MsgConfigureRemoteOutputWork(bool working) :
|
2017-12-14 12:02:49 -05:00
|
|
|
Message(),
|
|
|
|
m_working(working)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
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-02-02 16:58:42 -05:00
|
|
|
class MsgConfigureRemoteOutputChunkCorrection : public Message {
|
2017-12-14 12:02:49 -05:00
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
int getChunkCorrection() const { return m_chunkCorrection; }
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
static MsgConfigureRemoteOutputChunkCorrection* create(int chunkCorrection)
|
2017-12-14 12:02:49 -05:00
|
|
|
{
|
2019-02-02 16:58:42 -05:00
|
|
|
return new MsgConfigureRemoteOutputChunkCorrection(chunkCorrection);
|
2017-12-14 12:02:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_chunkCorrection;
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
MsgConfigureRemoteOutputChunkCorrection(int chunkCorrection) :
|
2017-12-14 12:02:49 -05:00
|
|
|
Message(),
|
|
|
|
m_chunkCorrection(chunkCorrection)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2021-12-12 06:54:22 -05:00
|
|
|
class MsgReportRemoteData : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct RemoteData
|
|
|
|
{
|
|
|
|
quint64 m_centerFrequency; //!< Center frequency where the stream is placed
|
|
|
|
int m_sampleRate; //!< Sample rate requested by remote
|
|
|
|
int m_queueSize; //!< Remote data read queue size
|
|
|
|
int m_queueLength; //!< Remote data queue length
|
|
|
|
int m_unrecoverableCount; //!< Number of unrecoverable errors from FEC
|
|
|
|
int m_recoverableCount; //!< Number of recoverable errors from FEC
|
|
|
|
uint64_t m_timestampUs; //!< Unix time stamp of request in microseconds
|
|
|
|
uint32_t m_sampleCount; //!< Number of samples processed in the remote at request time
|
|
|
|
};
|
|
|
|
|
|
|
|
const RemoteData& getData() const { return m_remoteData; }
|
|
|
|
|
|
|
|
static MsgReportRemoteData* create(const RemoteData& remoteData) {
|
|
|
|
return new MsgReportRemoteData(remoteData);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RemoteData m_remoteData;
|
|
|
|
|
|
|
|
MsgReportRemoteData(const RemoteData& remoteData) :
|
|
|
|
Message(),
|
|
|
|
m_remoteData(remoteData)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MsgReportRemoteFixedData : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct RemoteData
|
|
|
|
{
|
|
|
|
QString m_version; //!< Remote SDRangel version
|
|
|
|
QString m_qtVersion; //!< Remote Qt version used to build SDRangel
|
|
|
|
QString m_architecture; //!< Remote CPU architecture
|
|
|
|
QString m_os; //!< Remote O/S
|
|
|
|
int m_rxBits; //!< Number of bits used for I or Q sample on Rx side
|
|
|
|
int m_txBits; //!< Number of bits used for I or Q sample on Tx side
|
|
|
|
};
|
|
|
|
|
|
|
|
const RemoteData& getData() const { return m_remoteData; }
|
|
|
|
|
|
|
|
static MsgReportRemoteFixedData* create(const RemoteData& remoteData) {
|
|
|
|
return new MsgReportRemoteFixedData(remoteData);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RemoteData m_remoteData;
|
|
|
|
|
|
|
|
MsgReportRemoteFixedData(const RemoteData& remoteData) :
|
|
|
|
Message(),
|
|
|
|
m_remoteData(remoteData)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MsgRequestFixedData : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
static MsgRequestFixedData* create() {
|
|
|
|
return new MsgRequestFixedData();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MsgRequestFixedData() :
|
|
|
|
Message()
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
RemoteOutput(DeviceAPI *deviceAPI);
|
2019-02-02 16:58:42 -05:00
|
|
|
virtual ~RemoteOutput();
|
2017-12-14 12:02:49 -05:00
|
|
|
virtual void destroy();
|
|
|
|
|
2017-12-25 06:59:44 -05:00
|
|
|
virtual void init();
|
2017-12-14 12:02:49 -05:00
|
|
|
virtual bool start();
|
|
|
|
virtual void stop();
|
|
|
|
|
2017-12-27 22:04:50 -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) { m_guiMessageQueue = queue; }
|
2017-12-14 12:02:49 -05:00
|
|
|
virtual const QString& getDeviceDescription() const;
|
|
|
|
virtual int getSampleRate() const;
|
2019-05-09 18:34:35 -04:00
|
|
|
virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
|
2017-12-14 12:02:49 -05:00
|
|
|
virtual quint64 getCenterFrequency() const;
|
2018-11-13 02:51:14 -05:00
|
|
|
virtual void setCenterFrequency(qint64 centerFrequency) { (void) centerFrequency; }
|
2017-12-14 12:02:49 -05:00
|
|
|
std::time_t getStartingTimeStamp() const;
|
|
|
|
|
|
|
|
virtual bool handleMessage(const Message& message);
|
|
|
|
|
2018-05-27 18:40:33 -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-14 12:22:45 -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 RemoteOutputSettings& settings);
|
|
|
|
|
|
|
|
static void webapiUpdateDeviceSettings(
|
|
|
|
RemoteOutputSettings& settings,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response);
|
|
|
|
|
2017-12-14 12:02:49 -05:00
|
|
|
private:
|
2019-05-08 16:11:53 -04:00
|
|
|
DeviceAPI *m_deviceAPI;
|
2017-12-14 12:02:49 -05:00
|
|
|
QMutex m_mutex;
|
2019-02-02 16:58:42 -05:00
|
|
|
RemoteOutputSettings m_settings;
|
2018-09-06 18:58:09 -04:00
|
|
|
uint64_t m_centerFrequency;
|
2021-12-12 13:54:57 -05:00
|
|
|
int m_sampleRate;
|
2020-07-12 03:42:33 -04:00
|
|
|
RemoteOutputWorker* m_remoteOutputWorker;
|
|
|
|
QThread m_remoteOutputWorkerThread;
|
2017-12-14 12:02:49 -05:00
|
|
|
QString m_deviceDescription;
|
|
|
|
std::time_t m_startingTimeStamp;
|
|
|
|
const QTimer& m_masterTimer;
|
2021-12-12 06:54:22 -05:00
|
|
|
uint32_t m_tickCount; // for 50 ms timer
|
|
|
|
uint32_t m_greaterTickCount; // for 1 s derived timer
|
|
|
|
uint32_t m_tickMultiplier; // for greater tick count
|
2021-12-15 16:56:18 -05:00
|
|
|
int m_queueLength;
|
|
|
|
int m_queueSize;
|
|
|
|
int m_recoverableCount;
|
|
|
|
int m_unrecoverableCount;
|
2018-09-03 03:17:29 -04:00
|
|
|
|
|
|
|
QNetworkAccessManager *m_networkManager;
|
|
|
|
QNetworkRequest m_networkRequest;
|
|
|
|
|
2020-07-12 03:42:33 -04:00
|
|
|
void startWorker();
|
|
|
|
void stopWorker();
|
2022-10-31 06:18:22 -04:00
|
|
|
void applySettings(const RemoteOutputSettings& settings, const QList<QString>& settingsKeys, bool force = false);
|
2021-12-12 13:54:57 -05:00
|
|
|
void applyCenterFrequency();
|
|
|
|
void applySampleRate();
|
2018-05-27 18:40:33 -04:00
|
|
|
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
2018-09-03 03:17:29 -04:00
|
|
|
|
2018-12-26 16:30:35 -05:00
|
|
|
void analyzeApiReply(const QJsonObject& jsonObject, const QString& answer);
|
2021-12-14 01:56:02 -05:00
|
|
|
void queueLengthCompensation(
|
|
|
|
int nominalSR,
|
|
|
|
int queueLength,
|
|
|
|
int queueSize
|
|
|
|
);
|
2022-10-31 06:18:22 -04:00
|
|
|
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const RemoteOutputSettings& settings, bool force);
|
2018-12-26 16:30:35 -05:00
|
|
|
void webapiReverseSendStartStop(bool start);
|
2018-09-03 03:17:29 -04:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void tick();
|
|
|
|
void networkManagerFinished(QNetworkReply *reply);
|
2017-12-14 12:02:49 -05:00
|
|
|
};
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
#endif // INCLUDE_REMOTEOUTPUT_H
|