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; }
|
2017-12-14 12:02:49 -05:00
|
|
|
bool getForce() const { return m_force; }
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
static MsgConfigureRemoteOutput* create(const RemoteOutputSettings& settings, bool force = false)
|
2017-12-14 12:02:49 -05:00
|
|
|
{
|
2019-02-02 16:58:42 -05:00
|
|
|
return new MsgConfigureRemoteOutput(settings, force);
|
2017-12-14 12:02:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-02-02 16:58:42 -05:00
|
|
|
RemoteOutputSettings m_settings;
|
2017-12-14 12:02:49 -05:00
|
|
|
bool m_force;
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
MsgConfigureRemoteOutput(const RemoteOutputSettings& settings, bool force) :
|
2017-12-14 12:02:49 -05:00
|
|
|
Message(),
|
|
|
|
m_settings(settings),
|
|
|
|
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)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
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;
|
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;
|
2018-09-03 03:17:29 -04:00
|
|
|
uint32_t m_tickCount;
|
2018-09-03 12:13:57 -04:00
|
|
|
uint32_t m_tickMultiplier;
|
2018-09-03 03:17:29 -04:00
|
|
|
|
|
|
|
QNetworkAccessManager *m_networkManager;
|
|
|
|
QNetworkRequest m_networkRequest;
|
|
|
|
|
2018-09-04 02:43:07 -04:00
|
|
|
uint32_t m_lastRemoteSampleCount;
|
2018-09-03 03:17:29 -04:00
|
|
|
uint32_t m_lastSampleCount;
|
2018-09-04 02:43:07 -04:00
|
|
|
uint64_t m_lastRemoteTimestampRateCorrection;
|
2018-09-03 03:17:29 -04:00
|
|
|
uint64_t m_lastTimestampRateCorrection;
|
2018-09-07 03:22:17 -04:00
|
|
|
int m_lastQueueLength;
|
2018-09-04 02:43:07 -04:00
|
|
|
uint32_t m_nbRemoteSamplesSinceRateCorrection;
|
2018-09-03 03:17:29 -04:00
|
|
|
uint32_t m_nbSamplesSinceRateCorrection;
|
|
|
|
int m_chunkSizeCorrection;
|
2018-09-03 12:13:57 -04:00
|
|
|
static const uint32_t NbSamplesForRateCorrection;
|
2017-12-14 12:02:49 -05:00
|
|
|
|
2020-07-12 03:42:33 -04:00
|
|
|
void startWorker();
|
|
|
|
void stopWorker();
|
2019-02-02 16:58:42 -05:00
|
|
|
void applySettings(const RemoteOutputSettings& settings, bool force = false);
|
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);
|
2018-09-04 02:43:07 -04:00
|
|
|
void sampleRateCorrection(double remoteTimeDeltaUs, double timeDeltaUs, uint32_t remoteSampleCount, uint32_t sampleCount);
|
2019-02-02 16:58:42 -05:00
|
|
|
void webapiReverseSendSettings(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
|