2025-08-24 23:24:33 +08:00
|
|
|
|
#ifndef BELTTEARINGPRESENTER_H
|
|
|
|
|
|
#define BELTTEARINGPRESENTER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "IVrBeltTearingConfig.h"
|
2025-09-18 23:49:32 +08:00
|
|
|
|
#include "IVrTCPClient.h"
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
|
|
|
|
|
#include "IStatusUpdate.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QWidget>
|
2025-08-24 23:24:33 +08:00
|
|
|
|
#include <QObject>
|
|
|
|
|
|
#include <QString>
|
2025-09-18 23:49:32 +08:00
|
|
|
|
#include <QTimer>
|
2025-08-24 23:24:33 +08:00
|
|
|
|
|
2025-08-27 23:10:36 +08:00
|
|
|
|
|
2025-08-24 23:24:33 +08:00
|
|
|
|
class BeltTearingPresenter : public QWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
2025-08-31 21:08:28 +08:00
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
void tearingDataReceived(const QJsonObject &data);
|
2025-09-29 00:56:53 +08:00
|
|
|
|
void serverDataReceived(const QString &serverName, const QJsonObject &data);
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-08-24 23:24:33 +08:00
|
|
|
|
public:
|
|
|
|
|
|
explicit BeltTearingPresenter(QWidget* parent = nullptr);
|
|
|
|
|
|
~BeltTearingPresenter();
|
|
|
|
|
|
|
2025-09-18 23:49:32 +08:00
|
|
|
|
void Init(); // 状态更新接口
|
2025-08-24 23:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
QStringList getServerNames() const;
|
|
|
|
|
|
QString getServerIp(const QString &serverName) const ;
|
|
|
|
|
|
quint16 getServerPort(const QString &serverName) const ;
|
|
|
|
|
|
QString getServerDisplayName(const QString &serverName) const ;
|
|
|
|
|
|
|
2025-08-27 23:10:36 +08:00
|
|
|
|
// 设置状态更新接口
|
|
|
|
|
|
void setStatusUpdate(IStatusUpdate* statusUpdate) { m_statusUpdate = statusUpdate; }
|
|
|
|
|
|
|
2025-09-29 00:56:53 +08:00
|
|
|
|
// 获取服务器信息和配置接口
|
|
|
|
|
|
QMap<QString, ServerInfo> getServerInfos() const { return m_serverInfos; }
|
|
|
|
|
|
IVrBeltTearingConfig* getBeltTearingConfig() const { return m_config; }
|
|
|
|
|
|
|
|
|
|
|
|
// 发送参数到服务器
|
|
|
|
|
|
bool sendParametersToServer(const ByteDataType dataType, const QString& serverName, const QByteArray& paramData);
|
|
|
|
|
|
|
|
|
|
|
|
// 处理服务器信息响应
|
|
|
|
|
|
void handleServerInfoResponse(const QString& serverName, const QJsonObject& responseObj);
|
|
|
|
|
|
|
2025-08-24 23:24:33 +08:00
|
|
|
|
private:
|
|
|
|
|
|
// IBeltTearingPresenter interface implementation
|
|
|
|
|
|
bool initializeConfig(const QString &configPath);
|
|
|
|
|
|
bool connectToServer(const ServerInfo &serverInfo, const QString &serverName = QString());
|
|
|
|
|
|
void disconnectFromServer(const QString &serverName = QString()) ;
|
|
|
|
|
|
bool isConnected(const QString &serverName = QString()) const ;
|
|
|
|
|
|
bool sendData(const QByteArray &data, const QString &serverName = QString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
void onConnected(const QString &serverName);
|
|
|
|
|
|
void onDisconnected(const QString &serverName);
|
|
|
|
|
|
void onTcpError(const QString &serverName, const QString &error);
|
|
|
|
|
|
|
2025-09-18 23:49:32 +08:00
|
|
|
|
private:
|
|
|
|
|
|
// 静态回调函数(用于C接口)- 已弃用,使用lambda替代
|
|
|
|
|
|
// static void tcpDataReceivedCallback(const char* pData, const int nLen);
|
|
|
|
|
|
// static void tcpLinkStatusCallback(bool connected);
|
|
|
|
|
|
|
|
|
|
|
|
// 实例方法
|
|
|
|
|
|
void handleTcpDataReceived(const QString &serverName, const char* pData, const int nLen);
|
|
|
|
|
|
void handleTcpLinkStatus(const QString &serverName, bool connected);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
IVrBeltTearingConfig * m_config = nullptr; // 配置接口
|
|
|
|
|
|
IStatusUpdate* m_statusUpdate = nullptr; // 状态更新接口
|
|
|
|
|
|
QMap<QString, IVrTCPClient*> m_tcpClients; // 服务器名称 -> TCP客户端映射
|
|
|
|
|
|
QMap<QString, ServerInfo> m_serverInfos; // 服务器名称 -> 服务器信息映射
|
|
|
|
|
|
QMap<QString, bool> m_connectionStatus; // 连接状态
|
2025-09-21 22:20:24 +08:00
|
|
|
|
QMap<QString, bool> m_workThreadStarted; // 工作线程启动状态
|
|
|
|
|
|
QMap<QString, QByteArray> m_dataBuffers; // 每个服务器的数据缓存
|
|
|
|
|
|
|
|
|
|
|
|
// 处理完整数据包的方法
|
|
|
|
|
|
void processCompletePacket(const QString &serverName, const QByteArray &completeData);
|
2025-08-24 23:24:33 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // BELTTEARINGPRESENTER_H
|