52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#ifndef BELTTEARINGPRESENTER_H
|
|
#define BELTTEARINGPRESENTER_H
|
|
|
|
#include <QObject>
|
|
#include <QTcpServer>
|
|
#include <QTcpSocket>
|
|
#include <QTimer>
|
|
#include <QMap>
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
// 假设ByteDataType枚举定义
|
|
enum class ByteDataType : quint8 {
|
|
Text = 1,
|
|
Image = 2
|
|
};
|
|
|
|
class BeltTearingPresenter : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit BeltTearingPresenter(QObject *parent = nullptr);
|
|
~BeltTearingPresenter();
|
|
|
|
// 初始化TCP服务器
|
|
bool startServer(quint16 port);
|
|
void stopServer();
|
|
|
|
// 模拟数据发送
|
|
void startSendingSimulatedData();
|
|
void stopSendingSimulatedData();
|
|
|
|
private slots:
|
|
void onNewConnection();
|
|
void onClientDisconnected();
|
|
void onSendSimulatedData();
|
|
|
|
private:
|
|
QTcpServer *m_tcpServer;
|
|
QMap<QString, QTcpSocket*> m_clients;
|
|
QTimer *m_dataTimer;
|
|
quint16 m_port;
|
|
|
|
// 模拟数据发送方法
|
|
void sendSimulatedImage(QTcpSocket *socket);
|
|
void sendSimulatedLogRecords(QTcpSocket *socket);
|
|
void sendSimulatedTearingData(QTcpSocket *socket);
|
|
QString generateClientId(QTcpSocket *socket);
|
|
};
|
|
|
|
#endif // BELTTEARINGPRESENTER_H
|