56 lines
1.3 KiB
C++
Executable File
56 lines
1.3 KiB
C++
Executable File
#pragma once
|
|
|
|
#include "dds_handler.h"
|
|
#include "logger.h"
|
|
#include <taboc_dtc.h>
|
|
#include <QWebSocket>
|
|
|
|
class QTimer;
|
|
|
|
namespace TrainingAreaBaseOC {
|
|
|
|
enum class WebSocketState {
|
|
DISCONNECTED = 0, // should not happen
|
|
CONNECTEDTOSERVER, // 1
|
|
CONNECTTOPPM, // 2
|
|
CONNECTEDTOPPM, // 3
|
|
};
|
|
|
|
class WebsocketHandler : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
WebsocketHandler(QObject *parent, int exerciseId,
|
|
const std::shared_ptr<Interface::Dts> dtsTabOc, const std::shared_ptr<Interface::Dtc> dtcTabOc);
|
|
|
|
private slots:
|
|
void onTryConnectionTimerTimeout();
|
|
void onFetchPositionTimerTimeout();
|
|
void onNewSocketState(QAbstractSocket::SocketState state);
|
|
void onNewTextMessageFromSocket(const QString &message);
|
|
|
|
private:
|
|
void connectToExPPM(int exPort);
|
|
void sendPositionRequest();
|
|
void onSendOwnPosition(const QString &message);
|
|
|
|
void connectToServer();
|
|
void sendServicePortRequest();
|
|
void parseServices(const QString &message);
|
|
|
|
WebSocketState m_state = WebSocketState::DISCONNECTED;
|
|
int m_exerciseId = 0;
|
|
int m_ownEquipmentId = 0;
|
|
std::shared_ptr<Interface::Dts> m_dtsTaboc;
|
|
std::shared_ptr<Interface::Dtc> m_dtcTaboc;
|
|
QTimer *m_tryConnectionTimer = nullptr;
|
|
QTimer *m_fetchPositionTimer = nullptr;
|
|
QWebSocket *m_socket = nullptr;
|
|
|
|
LOGGER_T &m_logger;
|
|
|
|
};
|
|
|
|
|
|
} // namespace TrainingAreaBaseOc
|