snap7_clamp.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // Created by huli on 2020/9/25.
  3. //
  4. #pragma once
  5. #include "tool/singleton.h"
  6. #include "snap7_communication_base.h"
  7. #include <glog/logging.h>
  8. #include <pcl/point_types.h>
  9. #include <pcl/point_cloud.h>
  10. class Snap7Clamp:public Singleton<Snap7Clamp>, public Snap7_communication_base
  11. {
  12. public:
  13. //发送db快的标记位, 保证先发数据再发唯一码
  14. enum Send_database_flag
  15. {
  16. E_SEND_UNKNOW = 0,
  17. E_SEND_DATA_START = 1, //开始发送数据
  18. E_SEND_DATA_END = 2, //结束发送数据
  19. E_SEND_KEY_START = 3, //开始发送唯一码
  20. E_SEND_KEY_END = 4, //结束发送唯一码
  21. };
  22. #pragma pack(push, 1) //struct按照1个byte对齐
  23. #define CLAMP_SAFETY_HEART_DBNUMBER 9070
  24. #define CLAMP_SAFETY_PLC_DBNUMBER 9070
  25. #define CLAMP_SAFETY_WARNING_DBNUMBER 9075
  26. struct WheeLData {
  27. unsigned short wheel_exist;
  28. float offset;
  29. float gap;
  30. unsigned short clamp_completed;
  31. void info() const {
  32. if (wheel_exist == 0) {
  33. return;
  34. }
  35. DLOG(INFO) << "wheel_exist = " << wheel_exist
  36. << ", offset = " << offset
  37. << ", gap = " << gap
  38. << ", clamp_completed = " << clamp_completed;
  39. }
  40. void clear() {
  41. wheel_exist = false;
  42. offset = 0;
  43. gap = 0;
  44. clamp_completed = 0;
  45. }
  46. };
  47. struct PLCData {
  48. unsigned short pingpong;
  49. struct WheeLData wheels[4];
  50. void info() {
  51. DLOG(INFO) << "pingdong = " << pingpong;
  52. wheels[0].info();
  53. wheels[1].info();
  54. wheels[2].info();
  55. wheels[3].info();
  56. }
  57. void clear() {
  58. wheels[0].clear();
  59. wheels[1].clear();
  60. wheels[2].clear();
  61. wheels[3].clear();
  62. }
  63. };
  64. #pragma pack(pop) //取消对齐
  65. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  66. friend class Singleton<Snap7Clamp>;
  67. private:
  68. // 父类的构造函数必须保护,子类的构造函数必须私有。
  69. Snap7Clamp();
  70. public:
  71. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  72. Snap7Clamp(const Snap7Clamp& other) = delete;
  73. Snap7Clamp& operator =(const Snap7Clamp& other) = delete;
  74. ~Snap7Clamp() override;
  75. public://API functions
  76. //初始化 通信 模块。如下三选一
  77. Error_manager communication_init();
  78. //反初始化 通信 模块。
  79. Error_manager communication_uninit() override;
  80. Error_manager setCloudData(const unsigned char &device, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud);
  81. protected://member functions
  82. //更新数据
  83. Error_manager updata_receive_buf() override;
  84. Error_manager updata_send_buf() override;
  85. protected://member variable
  86. public:
  87. std::mutex m_data_lock; //数据锁
  88. PLCData plcData{};
  89. unsigned short m_heart;
  90. private:
  91. unsigned char m_warn_record;
  92. unsigned char m_save_cloud_flag;
  93. };