1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00
sdrangel/plugins/feature/simpleptt/simplepttworker.h

135 lines
4.5 KiB
C
Raw Normal View History

2020-09-19 19:06:50 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019-2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2020 Vort <vvort@yandex.ru> //
// Copyright (C) 2022 Jiří Pinkava <jiri.pinkava@rossum.ai> //
2020-09-19 19:06:50 -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 //
// (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 "dsp/dsptypes.h"
2020-09-19 19:06:50 -04:00
#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"
#include "simplepttcommand.h"
2020-09-19 19:06:50 -04:00
class WebAPIAdapterInterface;
class SimplePTTWorker : public QObject
{
Q_OBJECT
public:
class MsgConfigureSimplePTTWorker : public Message {
MESSAGE_CLASS_DECLARATION
public:
const SimplePTTSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
2020-09-19 19:06:50 -04:00
bool getForce() const { return m_force; }
static MsgConfigureSimplePTTWorker* create(const SimplePTTSettings& settings, const QList<QString>& settingsKeys, bool force)
2020-09-19 19:06:50 -04:00
{
return new MsgConfigureSimplePTTWorker(settings, settingsKeys, force);
2020-09-19 19:06:50 -04:00
}
private:
SimplePTTSettings m_settings;
QList<QString> m_settingsKeys;
2020-09-19 19:06:50 -04:00
bool m_force;
MsgConfigureSimplePTTWorker(const SimplePTTSettings& settings, const QList<QString>& settingsKeys, bool force) :
2020-09-19 19:06:50 -04:00
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
2020-09-19 19:06:50 -04:00
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();
void startWork();
2020-09-19 19:06:50 -04:00
void stopWork();
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
void setMessageQueueToGUI(MessageQueue *messageQueue)
{
m_msgQueueToGUI = messageQueue;
m_command.setMessageQueueToGUI(messageQueue);
}
2020-09-19 19:06:50 -04:00
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_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;
SimplePTTCommand m_command;
2020-09-19 19:06:50 -04:00
QTimer m_updateTimer;
QRecursiveMutex m_mutex;
2020-09-19 19:06:50 -04:00
bool handleMessage(const Message& cmd);
void applySettings(const SimplePTTSettings& settings, const QList<QString>& settingsKeys, bool force = false);
2020-09-19 19:06:50 -04:00
void sendPTT(bool tx);
bool turnDevice(bool on);
void preSwitch(bool tx);
2020-09-19 19:06:50 -04:00
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_