65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
#ifndef SCREWPOSITIONTCPPROTOCOL_H
|
|
#define SCREWPOSITIONTCPPROTOCOL_H
|
|
|
|
#include <functional>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include "IVrConfig.h"
|
|
#include "IYTCPServer.h"
|
|
|
|
struct RobotPose6D
|
|
{
|
|
double x = 0.0;
|
|
double y = 0.0;
|
|
double z = 0.0;
|
|
double a = 0.0;
|
|
double b = 0.0;
|
|
double c = 0.0;
|
|
};
|
|
|
|
class ScrewPositionTCPProtocol
|
|
{
|
|
public:
|
|
using ConnectionCallback = std::function<void(bool connected)>;
|
|
using DetectionTriggerCallback = std::function<bool(int cameraIndex,
|
|
DetectionType detectionType,
|
|
const RobotPose6D& robotPose)>;
|
|
|
|
ScrewPositionTCPProtocol();
|
|
~ScrewPositionTCPProtocol();
|
|
|
|
int Initialize(uint16_t port = 7800);
|
|
void Deinitialize();
|
|
bool IsRunning() const;
|
|
|
|
void SetConnectionCallback(const ConnectionCallback& callback);
|
|
void SetDetectionTriggerCallback(const DetectionTriggerCallback& callback);
|
|
|
|
// Protocol:
|
|
// request : T1_X_Y_Z_A_B_C\r\n
|
|
// response: PointNum_AX1_AY1_AZ1_A1_B1_C1_X1_Y1_Z1_A1_B1_C1/.../\r\n
|
|
// 每个目标 12 个浮点:先接近点(AX/AY/AZ + A/B/C),后目标点(X/Y/Z + A/B/C),两者姿态相同
|
|
int SendTextResult(const std::string& text, const TCPClient* pClient = nullptr);
|
|
|
|
private:
|
|
void OnTCPEvent(const TCPClient* pClient, TCPServerEventType eventType);
|
|
void OnTCPDataReceived(const TCPClient* pClient, const char* pData, unsigned int nLen);
|
|
void ParseTextCommand(const TCPClient* pClient, const QByteArray& line);
|
|
|
|
private:
|
|
IYTCPServer* m_pTCPServer = nullptr;
|
|
bool m_bServerRunning = false;
|
|
uint16_t m_nPort = 7800;
|
|
|
|
ConnectionCallback m_connectionCallback;
|
|
DetectionTriggerCallback m_detectionTriggerCallback;
|
|
|
|
std::map<const TCPClient*, QByteArray> m_clientBuffers;
|
|
};
|
|
|
|
#endif // SCREWPOSITIONTCPPROTOCOL_H
|