TcpLaser.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*************************
  2. sick 511 雷达 tcp协议连接控制板
  3. *************************/
  4. #pragma once
  5. #include "Laser.h"
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <netinet/in.h>
  9. #include <arpa/inet.h>
  10. #include <mutex>
  11. #define LASER_DATA_TIME_OUT 10000
  12. class CTcpLaser :
  13. public CLaser
  14. {
  15. public:
  16. CTcpLaser(int id, Automatic::stLaserCalibParam laser_param);
  17. ~CTcpLaser();
  18. virtual bool Connect();
  19. virtual void Disconnect();
  20. virtual bool Start();
  21. virtual bool Stop();
  22. protected:
  23. virtual bool RecvData(CBinaryData& data);
  24. virtual DATA_type Data2PointXYZ(CBinaryData* pData, std::vector<CPoint3D>& points);
  25. private:
  26. bool Send(char* sendbuf, int len); // 发送指令
  27. int Recv(char* recvbuf, int len); // 接收数据
  28. static int FindHead(char* buf, int b_len);
  29. static int FindTail(char* buf, int b_len);
  30. private:
  31. bool GetData(CBinaryData* pData, std::vector<float>& distance,
  32. float& freq, float& start_angle);
  33. long Str0x2Long(const char* data, int len);
  34. private:
  35. #pragma region udp相关变量
  36. int m_socket;
  37. //WSADATA m_wsd;
  38. struct sockaddr_in m_send_addr;
  39. std::mutex m_mutex;
  40. clock_t m_last_data_time;
  41. #pragma endregion
  42. };