44 lines
1023 B
C++
Executable File
44 lines
1023 B
C++
Executable File
/**
|
|
* Websocket interface for building control unit
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2017-01-30
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QTcpServer>
|
|
#include "logger.h"
|
|
#include "abstract_socket_handler.h"
|
|
|
|
namespace GuezNasat
|
|
{
|
|
class TcpSocketHandler : public AbstractSocketHandler
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit TcpSocketHandler(QObject *parent = nullptr);
|
|
|
|
bool init(quint16 listenPort) override;
|
|
bool isConnected() const override
|
|
{
|
|
return !m_tcpSockets.isEmpty();
|
|
}
|
|
protected:
|
|
bool sendTelegramInternal(const QByteArray &tele) override;
|
|
QByteArray parseBuffer(const QByteArray &buffer);
|
|
static bool findNextSyncStartByte(const QByteArray &buffer, int &iCurReadPos);
|
|
static bool findNextSyncEndByte(const QByteArray &buffer, int &iCurReadPos);
|
|
|
|
private Q_SLOTS:
|
|
void onNewConnection();
|
|
void onTcpSocketDisconnected();
|
|
void onReadyRead();
|
|
private:
|
|
QTcpServer *m_tcpSocketServer;
|
|
QHash<QTcpSocket *, QByteArray> m_tcpSockets;
|
|
};
|
|
|
|
} // namespace GuezNasat
|