60 lines
1.2 KiB
C++
Executable File
60 lines
1.2 KiB
C++
Executable File
/**
|
|
* Connection Handler for the RS232 serial connection to the sfm
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Philipp Dassow, NLST, 2018-01-29
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QTcpSocket>
|
|
|
|
#include <LtsUtilsCore/sfm_bytemessage_converter.h>
|
|
#include "logger.h"
|
|
|
|
|
|
class QTimer;
|
|
|
|
namespace EffectShowClient
|
|
{
|
|
|
|
class ConnectionHandlerTcp : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ConnectionHandlerTcp(QObject *parent = nullptr);
|
|
~ConnectionHandlerTcp();
|
|
|
|
bool init();
|
|
bool send(const QByteArray &message);
|
|
bool open();
|
|
void close();
|
|
|
|
bool isOpen() const;
|
|
|
|
signals:
|
|
/**
|
|
* @brief received emits a byte pair with command and payload byte when a available. It is guaranteed that there will be 2 bytes
|
|
* @param ba is a byte pair, with command 1st and payload 2nd.
|
|
*/
|
|
void received(const QByteArray &ba);
|
|
void connectedToSerialConverter();
|
|
|
|
private slots:
|
|
void read();
|
|
void handleError(QAbstractSocket::SocketError error);
|
|
|
|
|
|
private:
|
|
bool isValidCommandByte(const unsigned char command);
|
|
bool isValidPayloadByte(const unsigned char payload);
|
|
QTcpSocket *m_socket;
|
|
QTimer *m_timer;
|
|
QByteArray m_currentDataRead;
|
|
NGL::INGLLogger &m_logger;
|
|
};
|
|
} // namespace EffectShowClient
|