1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-14 04:11:48 -05:00
sdrangel/plugins/samplesink/fileoutput/fileoutput.h

259 lines
7.6 KiB
C
Raw Normal View History

2016-10-19 12:42:57 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
// written by Christian Daniel //
// Copyright (C) 2014 John Greb <hexameron@spam.no> //
// Copyright (C) 2015-2017, 2019-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2021 Andreas Baulig <free.geronimo@hotmail.de> //
2016-10-19 12:42:57 -04:00
// //
// 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. //
2016-10-19 12:42:57 -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/>. //
///////////////////////////////////////////////////////////////////////////////////
2020-08-03 18:29:15 -04:00
#ifndef INCLUDE_FILEOUTPUT_H
#define INCLUDE_FILEOUTPUT_H
2016-10-19 12:42:57 -04:00
#include <QString>
#include <QTimer>
#include <QThread>
#include <QNetworkRequest>
2016-10-19 12:42:57 -04:00
#include <ctime>
#include <iostream>
#include <fstream>
#include "dsp/devicesamplesink.h"
2020-08-03 18:29:15 -04:00
#include "fileoutputsettings.h"
class QNetworkAccessManager;
class QNetworkReply;
2020-08-03 18:29:15 -04:00
class FileOutputWorker;
2019-05-08 16:11:53 -04:00
class DeviceAPI;
2016-10-19 12:42:57 -04:00
2020-08-03 18:29:15 -04:00
class FileOutput : public DeviceSampleSink {
2016-10-19 12:42:57 -04:00
public:
2020-08-03 18:29:15 -04:00
class MsgConfigureFileOutput : public Message {
2016-10-19 12:42:57 -04:00
MESSAGE_CLASS_DECLARATION
public:
2020-08-03 18:29:15 -04:00
const FileOutputSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
bool getForce() const { return m_force; }
2016-10-19 12:42:57 -04:00
static MsgConfigureFileOutput* create(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureFileOutput(settings, settingsKeys, force);
2016-10-19 12:42:57 -04:00
}
private:
2020-08-03 18:29:15 -04:00
FileOutputSettings m_settings;
QList<QString> m_settingsKeys;
bool m_force;
2016-10-19 12:42:57 -04:00
MsgConfigureFileOutput(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force) :
2016-10-19 12:42:57 -04:00
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
m_force(force)
2016-10-19 12:42:57 -04: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)
{ }
};
2020-08-03 18:29:15 -04:00
class MsgConfigureFileOutputName : public Message {
2016-10-19 12:42:57 -04:00
MESSAGE_CLASS_DECLARATION
public:
const QString& getFileName() const { return m_fileName; }
2020-08-03 18:29:15 -04:00
static MsgConfigureFileOutputName* create(const QString& fileName)
2016-10-19 12:42:57 -04:00
{
2020-08-03 18:29:15 -04:00
return new MsgConfigureFileOutputName(fileName);
2016-10-19 12:42:57 -04:00
}
private:
QString m_fileName;
2020-08-03 18:29:15 -04:00
MsgConfigureFileOutputName(const QString& fileName) :
2016-10-19 12:42:57 -04:00
Message(),
m_fileName(fileName)
{ }
};
2020-08-03 18:29:15 -04:00
class MsgConfigureFileOutputWork : public Message {
2016-10-19 12:42:57 -04:00
MESSAGE_CLASS_DECLARATION
public:
bool isWorking() const { return m_working; }
2020-08-03 18:29:15 -04:00
static MsgConfigureFileOutputWork* create(bool working)
2016-10-19 12:42:57 -04:00
{
2020-08-03 18:29:15 -04:00
return new MsgConfigureFileOutputWork(working);
2016-10-19 12:42:57 -04:00
}
private:
bool m_working;
2020-08-03 18:29:15 -04:00
MsgConfigureFileOutputWork(bool working) :
2016-10-19 12:42:57 -04:00
Message(),
m_working(working)
{ }
};
2020-08-03 18:29:15 -04:00
class MsgConfigureFileOutputStreamTiming : public Message {
2016-10-19 12:42:57 -04:00
MESSAGE_CLASS_DECLARATION
public:
2020-08-03 18:29:15 -04:00
static MsgConfigureFileOutputStreamTiming* create()
2016-10-19 12:42:57 -04:00
{
2020-08-03 18:29:15 -04:00
return new MsgConfigureFileOutputStreamTiming();
2016-10-19 12:42:57 -04:00
}
private:
2020-08-03 18:29:15 -04:00
MsgConfigureFileOutputStreamTiming() :
2016-10-19 12:42:57 -04:00
Message()
{ }
};
2020-08-03 18:29:15 -04:00
class MsgReportFileOutputGeneration : public Message {
2016-10-19 12:42:57 -04:00
MESSAGE_CLASS_DECLARATION
public:
bool getAcquisition() const { return m_acquisition; }
2020-08-03 18:29:15 -04:00
static MsgReportFileOutputGeneration* create(bool acquisition)
2016-10-19 12:42:57 -04:00
{
2020-08-03 18:29:15 -04:00
return new MsgReportFileOutputGeneration(acquisition);
2016-10-19 12:42:57 -04:00
}
protected:
bool m_acquisition;
2020-08-03 18:29:15 -04:00
MsgReportFileOutputGeneration(bool acquisition) :
2016-10-19 12:42:57 -04:00
Message(),
m_acquisition(acquisition)
{ }
};
2020-08-03 18:29:15 -04:00
class MsgReportFileOutputStreamTiming : public Message {
2016-10-19 12:42:57 -04:00
MESSAGE_CLASS_DECLARATION
public:
std::size_t getSamplesCount() const { return m_samplesCount; }
2020-08-03 18:29:15 -04:00
static MsgReportFileOutputStreamTiming* create(std::size_t samplesCount)
2016-10-19 12:42:57 -04:00
{
2020-08-03 18:29:15 -04:00
return new MsgReportFileOutputStreamTiming(samplesCount);
2016-10-19 12:42:57 -04:00
}
protected:
std::size_t m_samplesCount;
2020-08-03 18:29:15 -04:00
MsgReportFileOutputStreamTiming(std::size_t samplesCount) :
2016-10-19 12:42:57 -04:00
Message(),
m_samplesCount(samplesCount)
{ }
};
2020-08-03 18:29:15 -04:00
FileOutput(DeviceAPI *deviceAPI);
virtual ~FileOutput();
virtual void destroy();
2016-10-19 12:42:57 -04:00
virtual void init();
virtual bool start();
2016-10-19 12:42:57 -04:00
virtual void stop();
virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data);
virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
2016-10-19 12:42:57 -04: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; }
2016-10-19 12:42:57 -04:00
virtual quint64 getCenterFrequency() const;
virtual void setCenterFrequency(qint64 centerFrequency);
2016-10-19 12:42:57 -04:00
std::time_t getStartingTimeStamp() const;
virtual bool handleMessage(const Message& message);
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 webapiRunGet(
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
virtual int webapiRun(
bool run,
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
static void webapiFormatDeviceSettings(
SWGSDRangel::SWGDeviceSettings& response,
const FileOutputSettings& settings);
static void webapiUpdateDeviceSettings(
FileOutputSettings& settings,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response);
2016-10-19 12:42:57 -04:00
private:
2019-05-08 16:11:53 -04:00
DeviceAPI *m_deviceAPI;
2016-10-19 12:42:57 -04:00
QMutex m_mutex;
2020-08-03 18:29:15 -04:00
FileOutputSettings m_settings;
2016-10-19 12:42:57 -04:00
std::ofstream m_ofstream;
2020-08-03 18:29:15 -04:00
FileOutputWorker* m_fileOutputWorker;
QThread m_fileOutputWorkerThread;
2016-10-19 12:42:57 -04:00
QString m_deviceDescription;
qint64 m_startingTimeStamp;
2016-10-19 12:42:57 -04:00
const QTimer& m_masterTimer;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
2016-10-19 12:42:57 -04:00
void startWorker();
void stopWorker();
2016-10-19 12:42:57 -04:00
void openFileStream();
void applySettings(const FileOutputSettings& settings, const QList<QString>& settingsKeys, bool force = false);
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const FileOutputSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);
private slots:
void networkManagerFinished(QNetworkReply *reply);
2016-10-19 12:42:57 -04:00
};
2020-08-03 18:29:15 -04:00
#endif // INCLUDE_FILEOUTPUT_H