1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-27 02:09:14 -05:00
sdrangel/plugins/feature/simpleptt/simplepttworker.h

123 lines
4.0 KiB
C
Raw Normal View History

2020-09-19 19:06:50 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2020 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 //
// (at your option) any later version. //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FEATURE_SIMPLEPTTWORKER_H_
#define INCLUDE_FEATURE_SIMPLEPTTWORKER_H_
#include <QObject>
#include <QTimer>
#include "util/message.h"
#include "util/messagequeue.h"
2021-12-29 15:20:06 -05:00
#include "audio/audiofifo.h"
2020-09-19 19:06:50 -04:00
#include "simplepttsettings.h"
class WebAPIAdapterInterface;
class SimplePTTWorker : public QObject
{
Q_OBJECT
public:
class MsgConfigureSimplePTTWorker : public Message {
MESSAGE_CLASS_DECLARATION
public:
const SimplePTTSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
static MsgConfigureSimplePTTWorker* create(const SimplePTTSettings& settings, bool force)
{
return new MsgConfigureSimplePTTWorker(settings, force);
}
private:
SimplePTTSettings m_settings;
bool m_force;
MsgConfigureSimplePTTWorker(const SimplePTTSettings& settings, bool force) :
Message(),
m_settings(settings),
m_force(force)
{ }
};
class MsgPTT : public Message {
MESSAGE_CLASS_DECLARATION
public:
bool getTx() const { return m_tx; }
static MsgPTT* create(bool tx) {
return new MsgPTT(tx);
}
private:
bool m_tx;
MsgPTT(bool tx) :
Message(),
m_tx(tx)
{ }
};
SimplePTTWorker(WebAPIAdapterInterface *webAPIAdapterInterface);
~SimplePTTWorker();
void reset();
bool startWork();
void stopWork();
bool isRunning() const { return m_running; }
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
void setMessageQueueToGUI(MessageQueue *messageQueue) { m_msgQueueToGUI = messageQueue; }
2021-12-29 15:20:06 -05:00
void getAudioPeak(float& peak)
{
peak = m_audioMagsqPeak;
m_audioMagsqPeak = 0;
}
2020-09-19 19:06:50 -04:00
private:
WebAPIAdapterInterface *m_webAPIAdapterInterface;
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
MessageQueue *m_msgQueueToGUI; //!< Queue to report state to GUI
SimplePTTSettings m_settings;
bool m_running;
bool m_tx;
2021-12-29 15:20:06 -05:00
AudioFifo m_audioFifo;
AudioVector m_audioReadBuffer;
unsigned int m_audioReadBufferFill;
int m_audioSampleRate;
float m_audioMagsqPeak;
float m_voxLevel;
int m_voxHoldCount;
bool m_voxState;
2020-09-19 19:06:50 -04:00
QTimer m_updateTimer;
QMutex m_mutex;
bool handleMessage(const Message& cmd);
void applySettings(const SimplePTTSettings& settings, bool force = false);
void sendPTT(bool tx);
bool turnDevice(bool on);
private slots:
void handleInputMessages();
void updateHardware();
2021-12-29 15:20:06 -05:00
void handleAudio();
2020-09-19 19:06:50 -04:00
};
2021-12-29 15:20:06 -05:00
#endif // INCLUDE_FEATURE_SIMPLEPTTWORKER_H_