1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 17:58:43 -05:00
sdrangel/plugins/samplesink/fileoutput/fileoutput.h

260 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);
}
2024-08-24 07:17:02 -04:00
private:
bool m_startStop;
2024-08-24 07:17:02 -04:00
explicit 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;
2024-08-24 07:17:02 -04:00
explicit 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;
2024-08-24 07:17:02 -04:00
explicit 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
}
2024-08-24 07:17:02 -04:00
private:
2016-10-19 12:42:57 -04:00
bool m_acquisition;
2024-08-24 07:17:02 -04:00
explicit 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
}
2024-08-24 07:17:02 -04:00
private:
2016-10-19 12:42:57 -04:00
std::size_t m_samplesCount;
2024-08-24 07:17:02 -04:00
explicit MsgReportFileOutputStreamTiming(std::size_t samplesCount) :
2016-10-19 12:42:57 -04:00
Message(),
m_samplesCount(samplesCount)
{ }
};
2024-08-24 07:17:02 -04:00
explicit FileOutput(DeviceAPI *deviceAPI);
~FileOutput() final;
void destroy() final;
2016-10-19 12:42:57 -04:00
2024-08-24 07:17:02 -04:00
void init() final;
bool start() final;
void stop() final;
2016-10-19 12:42:57 -04:00
2024-08-24 07:17:02 -04:00
QByteArray serialize() const final;
bool deserialize(const QByteArray& data) final;
2024-08-24 07:17:02 -04:00
void setMessageQueueToGUI(MessageQueue *queue) final { m_guiMessageQueue = queue; }
const QString& getDeviceDescription() const final;
int getSampleRate() const final;
void setSampleRate(int sampleRate) final { (void) sampleRate; }
quint64 getCenterFrequency() const final;
void setCenterFrequency(qint64 centerFrequency) final;
2016-10-19 12:42:57 -04:00
std::time_t getStartingTimeStamp() const;
2024-08-24 07:17:02 -04:00
bool handleMessage(const Message& message) final;
2016-10-19 12:42:57 -04:00
2024-08-24 07:17:02 -04:00
int webapiSettingsGet(
SWGSDRangel::SWGDeviceSettings& response,
QString& errorMessage) final;
2024-08-24 07:17:02 -04:00
int webapiSettingsPutPatch(
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response, // query + response
QString& errorMessage) final;
2024-08-24 07:17:02 -04:00
int webapiRunGet(
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage) final;
2024-08-24 07:17:02 -04:00
int webapiRun(
bool run,
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage) final;
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;
2024-08-24 07:17:02 -04:00
bool m_running = false;
2020-08-03 18:29:15 -04:00
FileOutputSettings m_settings;
2016-10-19 12:42:57 -04:00
std::ofstream m_ofstream;
2024-08-24 07:17:02 -04:00
FileOutputWorker* m_fileOutputWorker = nullptr;
2020-08-03 18:29:15 -04:00
QThread m_fileOutputWorkerThread;
2016-10-19 12:42:57 -04:00
QString m_deviceDescription;
2024-08-24 07:17:02 -04:00
qint64 m_startingTimeStamp = 0;
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:
2024-08-24 07:17:02 -04:00
void networkManagerFinished(QNetworkReply *reply) const;
2016-10-19 12:42:57 -04:00
};
2020-08-03 18:29:15 -04:00
#endif // INCLUDE_FILEOUTPUT_H