55 lines
1.5 KiB
C++
Executable File
55 lines
1.5 KiB
C++
Executable File
/**
|
|
* Send / Receive telegrams to/from PrtCnv
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2016-09-26
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QWebSocketServer>
|
|
#include <QWebSocket>
|
|
#include <QTimer>
|
|
#include <TrainingAreaBase/tab_plugin_interface.h>
|
|
#include <PrtCnv/PrtCnvApplication.hpp>
|
|
#include "convert_from_json.h"
|
|
#include "convert_to_json.h"
|
|
|
|
namespace TetraRadio
|
|
{
|
|
class SocketDispatcher final : public QObject, protected ConvertFromJson
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit SocketDispatcher(TrainingAreaBase::Plugin::DataProvider *pdp,
|
|
const std::shared_ptr<TrainingAreaBase::RecvFromTab> &recvFromTabCb);
|
|
~SocketDispatcher();
|
|
|
|
bool init(PrtCnv::PrtCnvApplication *prtCnvApp);
|
|
std::shared_ptr<TrainingAreaBase::SendToTab> sendToTab();
|
|
quint16 randomListenPort() const;
|
|
bool canSendData() const { return m_prtCnvApp != nullptr; }
|
|
Q_SIGNALS:
|
|
void tetraConnectionChanged(bool bConnected);
|
|
void warehouseMessage(const QByteArray &jsonData);
|
|
private Q_SLOTS:
|
|
void onTextMessageReceived(const QByteArray &message);
|
|
void onAckTimeout();
|
|
void onSendInitialData();
|
|
private:
|
|
void disconnectSocket(QWebSocket *s);
|
|
void handleTetraConnectionChanged(bool bConnected) override;
|
|
void handleAcknowledge(qint64 timeStamp, int counter) override;
|
|
private:
|
|
std::shared_ptr<ConvertToJson> m_txHandler;
|
|
TrainingAreaBase::Plugin::DataProvider *m_dataProvider;
|
|
PrtCnv::PrtCnvApplication *m_prtCnvApp;
|
|
QTimer *m_ackTimer;
|
|
bool m_bInitialAck;
|
|
int m_receiveCounter;
|
|
};
|
|
|
|
} // namespace TetraRadio
|