GrabBag/App/ScrewPosition/ScrewPositionApp/Presenter/Inc/ScrewPositionTCPProtocol.h

63 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SCREWPOSITIONTCPPROTOCOL_H
#define SCREWPOSITIONTCPPROTOCOL_H
#include "TCPServerProtocol.h"
#include "IVrConfig.h"
/**
* @brief ScrewPosition 专用TCP协议类
*
* 继承自 AppCommon 的 TCPServerProtocol 基类,
* 重写 ParseJSONCommand 实现螺杆定位项目的协议:
* - ScrewDetectRequest: 螺杆检测输出螺杆顶端中心点XYZRPY
* - ToolDiskDetectRequest: 工具盘检测(算法后续增加)
* - ScanRequest: 兼容旧协议,映射为螺杆检测
*/
class ScrewPositionTCPProtocol : public TCPServerProtocol
{
public:
/**
* @brief 检测触发回调(带检测类型)
* @param success 是否成功
* @param cameraIndex 相机索引(-1表示所有相机
* @param timestamp 请求时间戳(毫秒)
* @param detectionType 检测类型
*/
using DetectionTriggerWithTypeCallback = std::function<bool(bool success, int cameraIndex, qint64 timestamp, DetectionType detectionType)>;
ScrewPositionTCPProtocol();
~ScrewPositionTCPProtocol() override;
/**
* @brief 设置带检测类型的检测触发回调
*/
void SetDetectionTriggerWithTypeCallback(const DetectionTriggerWithTypeCallback& callback);
protected:
/**
* @brief 重写命令解析,支持螺杆/工具盘检测
*/
void ParseJSONCommand(const TCPClient* pClient, const QJsonObject& jsonData) override;
private:
/**
* @brief 处理螺杆检测命令
*/
void HandleScrewDetectCommand(const TCPClient* pClient, qint64 timestamp);
/**
* @brief 处理工具盘检测命令
*/
void HandleToolDiskDetectCommand(const TCPClient* pClient, qint64 timestamp);
/**
* @brief 触发检测(内部统一调用)
*/
bool TriggerDetection(const TCPClient* pClient, qint64 timestamp, DetectionType type, const QString& responseType, const QString& errorDesc);
private:
DetectionTriggerWithTypeCallback m_detectionTypeCallback;
};
#endif // SCREWPOSITIONTCPPROTOCOL_H