sdrangel/plugins/samplesink/fileoutput/fileoutput.h

225 wiersze
5.9 KiB
C
Czysty Zwykły widok Historia

2016-10-19 16:42:57 +00: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 04:39:30 +00:00
// (at your option) any later version. //
2016-10-19 16:42:57 +00: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 22:29:15 +00:00
#ifndef INCLUDE_FILEOUTPUT_H
#define INCLUDE_FILEOUTPUT_H
2016-10-19 16:42:57 +00:00
#include <QString>
#include <QTimer>
#include <QThread>
2016-10-19 16:42:57 +00:00
#include <ctime>
#include <iostream>
#include <fstream>
#include "dsp/devicesamplesink.h"
2020-08-03 22:29:15 +00:00
#include "fileoutputsettings.h"
2020-08-03 22:29:15 +00:00
class FileOutputWorker;
2019-05-08 20:11:53 +00:00
class DeviceAPI;
2016-10-19 16:42:57 +00:00
2020-08-03 22:29:15 +00:00
class FileOutput : public DeviceSampleSink {
2016-10-19 16:42:57 +00:00
public:
2020-08-03 22:29:15 +00:00
class MsgConfigureFileOutput : public Message {
2016-10-19 16:42:57 +00:00
MESSAGE_CLASS_DECLARATION
public:
2020-08-03 22:29:15 +00:00
const FileOutputSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
2016-10-19 16:42:57 +00:00
2020-08-03 22:29:15 +00:00
static MsgConfigureFileOutput* create(const FileOutputSettings& settings, bool force)
2016-10-19 16:42:57 +00:00
{
2020-08-03 22:29:15 +00:00
return new MsgConfigureFileOutput(settings, force);
2016-10-19 16:42:57 +00:00
}
private:
2020-08-03 22:29:15 +00:00
FileOutputSettings m_settings;
bool m_force;
2016-10-19 16:42:57 +00:00
2020-08-03 22:29:15 +00:00
MsgConfigureFileOutput(const FileOutputSettings& settings, bool force) :
2016-10-19 16:42:57 +00:00
Message(),
m_settings(settings),
m_force(force)
2016-10-19 16:42:57 +00: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 22:29:15 +00:00
class MsgConfigureFileOutputName : public Message {
2016-10-19 16:42:57 +00:00
MESSAGE_CLASS_DECLARATION
public:
const QString& getFileName() const { return m_fileName; }
2020-08-03 22:29:15 +00:00
static MsgConfigureFileOutputName* create(const QString& fileName)
2016-10-19 16:42:57 +00:00
{
2020-08-03 22:29:15 +00:00
return new MsgConfigureFileOutputName(fileName);
2016-10-19 16:42:57 +00:00
}
private:
QString m_fileName;
2020-08-03 22:29:15 +00:00
MsgConfigureFileOutputName(const QString& fileName) :
2016-10-19 16:42:57 +00:00
Message(),
m_fileName(fileName)
{ }
};
2020-08-03 22:29:15 +00:00
class MsgConfigureFileOutputWork : public Message {
2016-10-19 16:42:57 +00:00
MESSAGE_CLASS_DECLARATION
public:
bool isWorking() const { return m_working; }
2020-08-03 22:29:15 +00:00
static MsgConfigureFileOutputWork* create(bool working)
2016-10-19 16:42:57 +00:00
{
2020-08-03 22:29:15 +00:00
return new MsgConfigureFileOutputWork(working);
2016-10-19 16:42:57 +00:00
}
private:
bool m_working;
2020-08-03 22:29:15 +00:00
MsgConfigureFileOutputWork(bool working) :
2016-10-19 16:42:57 +00:00
Message(),
m_working(working)
{ }
};
2020-08-03 22:29:15 +00:00
class MsgConfigureFileOutputStreamTiming : public Message {
2016-10-19 16:42:57 +00:00
MESSAGE_CLASS_DECLARATION
public:
2020-08-03 22:29:15 +00:00
static MsgConfigureFileOutputStreamTiming* create()
2016-10-19 16:42:57 +00:00
{
2020-08-03 22:29:15 +00:00
return new MsgConfigureFileOutputStreamTiming();
2016-10-19 16:42:57 +00:00
}
private:
2020-08-03 22:29:15 +00:00
MsgConfigureFileOutputStreamTiming() :
2016-10-19 16:42:57 +00:00
Message()
{ }
};
2020-08-03 22:29:15 +00:00
class MsgReportFileOutputGeneration : public Message {
2016-10-19 16:42:57 +00:00
MESSAGE_CLASS_DECLARATION
public:
bool getAcquisition() const { return m_acquisition; }
2020-08-03 22:29:15 +00:00
static MsgReportFileOutputGeneration* create(bool acquisition)
2016-10-19 16:42:57 +00:00
{
2020-08-03 22:29:15 +00:00
return new MsgReportFileOutputGeneration(acquisition);
2016-10-19 16:42:57 +00:00
}
protected:
bool m_acquisition;
2020-08-03 22:29:15 +00:00
MsgReportFileOutputGeneration(bool acquisition) :
2016-10-19 16:42:57 +00:00
Message(),
m_acquisition(acquisition)
{ }
};
2020-08-03 22:29:15 +00:00
class MsgReportFileOutputStreamTiming : public Message {
2016-10-19 16:42:57 +00:00
MESSAGE_CLASS_DECLARATION
public:
std::size_t getSamplesCount() const { return m_samplesCount; }
2020-08-03 22:29:15 +00:00
static MsgReportFileOutputStreamTiming* create(std::size_t samplesCount)
2016-10-19 16:42:57 +00:00
{
2020-08-03 22:29:15 +00:00
return new MsgReportFileOutputStreamTiming(samplesCount);
2016-10-19 16:42:57 +00:00
}
protected:
std::size_t m_samplesCount;
2020-08-03 22:29:15 +00:00
MsgReportFileOutputStreamTiming(std::size_t samplesCount) :
2016-10-19 16:42:57 +00:00
Message(),
m_samplesCount(samplesCount)
{ }
};
2020-08-03 22:29:15 +00:00
FileOutput(DeviceAPI *deviceAPI);
virtual ~FileOutput();
virtual void destroy();
2016-10-19 16:42:57 +00:00
virtual void init();
virtual bool start();
2016-10-19 16:42:57 +00: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 16:42:57 +00:00
virtual const QString& getDeviceDescription() const;
virtual int getSampleRate() const;
2019-05-09 22:34:35 +00:00
virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
2016-10-19 16:42:57 +00:00
virtual quint64 getCenterFrequency() const;
virtual void setCenterFrequency(qint64 centerFrequency);
2016-10-19 16:42:57 +00:00
std::time_t getStartingTimeStamp() const;
virtual bool handleMessage(const Message& message);
virtual int webapiRunGet(
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
virtual int webapiRun(
bool run,
SWGSDRangel::SWGDeviceState& response,
QString& errorMessage);
2016-10-19 16:42:57 +00:00
private:
2019-05-08 20:11:53 +00:00
DeviceAPI *m_deviceAPI;
2016-10-19 16:42:57 +00:00
QMutex m_mutex;
2020-08-03 22:29:15 +00:00
FileOutputSettings m_settings;
2016-10-19 16:42:57 +00:00
std::ofstream m_ofstream;
2020-08-03 22:29:15 +00:00
FileOutputWorker* m_fileOutputWorker;
QThread m_fileOutputWorkerThread;
2016-10-19 16:42:57 +00:00
QString m_deviceDescription;
QString m_fileName;
std::time_t m_startingTimeStamp;
const QTimer& m_masterTimer;
void startWorker();
void stopWorker();
2016-10-19 16:42:57 +00:00
void openFileStream();
2020-08-03 22:29:15 +00:00
void applySettings(const FileOutputSettings& settings, bool force = false);
2016-10-19 16:42:57 +00:00
};
2020-08-03 22:29:15 +00:00
#endif // INCLUDE_FILEOUTPUT_H