54 lines
1.5 KiB
C
54 lines
1.5 KiB
C
|
|
#pragma once
|
|||
|
|
|
|||
|
|
#include <QObject>
|
|||
|
|
#include <QString>
|
|||
|
|
#include <functional>
|
|||
|
|
#include <memory>
|
|||
|
|
#include "IVrConfig.h"
|
|||
|
|
#include "RobotPose6D.h"
|
|||
|
|
|
|||
|
|
using DetectionTriggerCallback = std::function<void(int cameraIndex, const RobotPose6D& robotPose)>;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief JiuruiWorkpiecePose TCP 文本协议(PIMPL 模式)
|
|||
|
|
*
|
|||
|
|
* 眼在手外(Eye-to-Hand)模式:相机固定,无需机械臂位姿。
|
|||
|
|
*
|
|||
|
|
* 协议格式:
|
|||
|
|
* - 请求: D1 触发相机1的工件检测
|
|||
|
|
* - 响应: count_X1_Y1_Z1_A1_B1_C1_X2_Y2_Z2_A2_B2_C2_...
|
|||
|
|
* (count 个目标,每个 6 个浮点:XYZ + 姿态 A/B/C)
|
|||
|
|
*
|
|||
|
|
* 内部持有 IYTCPServer 生命周期与行缓冲,通过回调驱动 QObject 信号。
|
|||
|
|
*/
|
|||
|
|
class JiuruiWorkpiecePoseTCPProtocol : public QObject
|
|||
|
|
{
|
|||
|
|
Q_OBJECT
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
explicit JiuruiWorkpiecePoseTCPProtocol(QObject* parent = nullptr);
|
|||
|
|
~JiuruiWorkpiecePoseTCPProtocol();
|
|||
|
|
|
|||
|
|
bool StartServer(uint16_t port);
|
|||
|
|
void StopServer();
|
|||
|
|
bool IsConnected() const;
|
|||
|
|
|
|||
|
|
void SetDetectionTriggerCallback(DetectionTriggerCallback callback);
|
|||
|
|
void SendResult(const QString& resultText);
|
|||
|
|
|
|||
|
|
signals:
|
|||
|
|
void ConnectionChanged(bool connected);
|
|||
|
|
void DataReceived(const QString& data);
|
|||
|
|
void DetectionTriggered(int cameraIndex, const RobotPose6D& robotPose);
|
|||
|
|
|
|||
|
|
private slots:
|
|||
|
|
void OnNewConnection();
|
|||
|
|
void OnDisconnected();
|
|||
|
|
void OnReadyRead(const QByteArray& data);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
void ProcessCommand(const QString& command);
|
|||
|
|
class Impl;
|
|||
|
|
std::unique_ptr<Impl> m_pImpl;
|
|||
|
|
};
|