dispatch_communication.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // Created by huli on 2020/9/25.
  3. //
  4. #ifndef NNXX_TESTS_DISPATCH_COMMUNICATION_H
  5. #define NNXX_TESTS_DISPATCH_COMMUNICATION_H
  6. #include "../tool/singleton.h"
  7. #include "../snap7_communication/snap7_communication_base.h"
  8. class Dispatch_communication:public Singleton<Dispatch_communication>, public Snap7_communication_base
  9. {
  10. public:
  11. //发送db快的标记位, 保证先发数据再发唯一码
  12. enum Send_database_flag
  13. {
  14. E_SEND_UNKNOW = 0,
  15. E_SEND_DATA_START = 1, //开始发送数据
  16. E_SEND_DATA_END = 2, //结束发送数据
  17. E_SEND_KEY_START = 3, //开始发送唯一码
  18. E_SEND_KEY_END = 4, //结束发送唯一码
  19. };
  20. #pragma pack(push, 1) //struct按照1个byte对齐
  21. //抓车模块给plc发送请求消息的DB编号
  22. #define CATCHER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_1 110
  23. #define CATCHER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_2 120
  24. //抓车模块给plc发送请求消息的指令结构体
  25. struct Catcher_request_from_dispatch_to_plc_for_data
  26. {
  27. //指令信息
  28. unsigned char m_reserved = 0; //预留
  29. unsigned char m_reserved257_275[19] = {0}; //预留
  30. // 请求的目标坐标和动作
  31. float m_request_x = 0; //机器人坐标x轴,
  32. float m_request_y = 0; //机器人坐标y轴,
  33. float m_request_b = 0; //机器人坐标b轴, 旋转范围80~280
  34. float m_request_z = 0; //机器人坐标z轴,
  35. unsigned char m_request_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  36. unsigned char m_reserved293 = 0; //预留
  37. unsigned char m_reserved294 = 0; //预留
  38. unsigned char m_reserved295 = 0; //预留
  39. float m_request_wheelbase = 0; //机器人抓车杆前后轮距.
  40. float m_request_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  41. float m_request_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  42. };
  43. //抓车模块给plc发送请求消息的指令结构体
  44. struct Catcher_request_from_dispatch_to_plc_for_key
  45. {
  46. //指令信息
  47. unsigned char m_request_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  48. };
  49. //plc给抓车模块发送答复消息的DB编号
  50. #define CATCHER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_1 111
  51. #define CATCHER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 121
  52. //plc给抓车模块发送答复消息的指令结构体
  53. struct Catcher_response_from_plc_to_dispatch
  54. {
  55. //指令信息
  56. unsigned char m_respons_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  57. unsigned char m_respons_status = 0; //指令完成状态, 机器人答复指令, 返回任务完成的情况
  58. unsigned char m_reserved257_275[19] = {0}; //预留
  59. //请求的目标坐标和动作
  60. float m_respons_x = 0; //机器人坐标x轴,
  61. float m_respons_y = 0; //机器人坐标y轴,
  62. float m_respons_b = 0; //机器人坐标b轴, 旋转范围80~280
  63. float m_respons_z = 0; //机器人坐标z轴,
  64. unsigned char m_respons_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  65. unsigned char m_reserved293 = 0; //预留
  66. unsigned char m_reserved294 = 0; //预留
  67. unsigned char m_reserved295 = 0; //预留
  68. float m_respons_wheelbase = 0; //机器人抓车杆前后轮距.
  69. float m_respons_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  70. float m_respons_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  71. };
  72. //plc给抓车模块发送状态消息的DB编号
  73. #define CATCHER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 113
  74. #define CATCHER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 123
  75. //plc给抓车模块发送状态消息的指令结构体
  76. struct Catcher_status_from_plc_to_dispatch
  77. {
  78. unsigned char m_heartbeat = 0; //心跳位, 0-255循环
  79. unsigned char m_safe_status = 0; //设备的安全状态
  80. unsigned char m_work_status = 0; //机器人的硬件设备状态
  81. unsigned char m_actual_load_status = 0; //机器人的负载状态, 小跑车上面是否有车.
  82. unsigned char m_reserved4_37[34] = {0}; //预留
  83. float m_actual_x = 0; //机器人坐标x轴,
  84. float m_actual_y = 0; //机器人坐标y轴,
  85. float m_actual_b = 0; //机器人坐标b轴, 旋转范围80~280
  86. float m_actual_z = 0; //机器人坐标z轴,
  87. float m_actual_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  88. float m_actual_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  89. unsigned char m_actual_clamp_motion1 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  90. unsigned char m_actual_clamp_motion2 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  91. unsigned char m_actual_clamp_motion3 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  92. unsigned char m_actual_clamp_motion4 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  93. unsigned char m_reserved66_99[34] = {0}; //预留
  94. //故障信息
  95. unsigned char m_actual_error_code[50] = {0}; //搬运器错误码
  96. unsigned char m_actual_warning_code[50] = {0}; //升降机错误码
  97. unsigned char m_actual_error_description[256] = {0}; //升降机错误描述
  98. };
  99. //搬运器给plc发送请求消息的DB编号
  100. #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_1 200
  101. #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_2 270
  102. #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_3 230
  103. //搬运器给plc发送请求消息的指令结构体
  104. struct Carrier_request_from_dispatch_to_plc_for_data
  105. {
  106. //指令信息
  107. unsigned char m_reserved = 0; //预留
  108. unsigned char m_reserved257_275[19] = {0}; //预留
  109. // 请求的目标坐标和动作
  110. float m_request_x = 0; //机器人坐标x轴,
  111. float m_request_y = 0; //机器人坐标y轴,
  112. float m_request_b = 0; //机器人坐标b轴, 旋转范围80~280
  113. float m_request_z = 0; //机器人坐标z轴,
  114. unsigned char m_request_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  115. unsigned char m_reserved293 = 0; //预留
  116. unsigned char m_reserved294 = 0; //预留
  117. unsigned char m_reserved295 = 0; //预留
  118. float m_request_wheelbase = 0; //机器人抓车杆前后轮距.
  119. float m_request_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  120. float m_request_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  121. };
  122. //搬运器给plc发送请求消息的指令结构体
  123. struct Carrier_request_from_dispatch_to_plc_for_key
  124. {
  125. //指令信息
  126. unsigned char m_request_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  127. };
  128. //plc给搬运器发送答复消息的DB编号
  129. #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_1 201
  130. #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 271
  131. #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 231
  132. //plc给搬运器发送答复消息的指令结构体
  133. struct Carrier_response_from_plc_to_dispatch
  134. {
  135. //指令信息
  136. unsigned char m_respons_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  137. unsigned char m_respons_status = 0; //指令完成状态, 机器人答复指令, 返回任务完成的情况
  138. unsigned char m_reserved257_275[19] = {0}; //预留
  139. //请求的目标坐标和动作
  140. float m_respons_x = 0; //机器人坐标x轴,
  141. float m_respons_y = 0; //机器人坐标y轴,
  142. float m_respons_b = 0; //机器人坐标b轴, 旋转范围80~280
  143. float m_respons_z = 0; //机器人坐标z轴,
  144. unsigned char m_respons_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  145. unsigned char m_reserved293 = 0; //预留
  146. unsigned char m_reserved294 = 0; //预留
  147. unsigned char m_reserved295 = 0; //预留
  148. float m_respons_wheelbase = 0; //机器人抓车杆前后轮距.
  149. float m_respons_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  150. float m_respons_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  151. };
  152. //plc给搬运器发送状态消息的DB编号
  153. #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 113
  154. #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 123
  155. //plc给搬运器发送状态消息的指令结构体
  156. struct Carrier_status_from_plc_to_dispatch
  157. {
  158. unsigned char m_heartbeat = 0; //心跳位, 0-255循环
  159. unsigned char m_safe_status = 0; //设备的安全状态
  160. unsigned char m_work_status = 0; //机器人的硬件设备状态
  161. unsigned char m_actual_load_status = 0; //机器人的负载状态, 小跑车上面是否有车.
  162. unsigned char m_reserved4_37[34] = {0}; //预留
  163. float m_actual_x = 0; //机器人坐标x轴,
  164. float m_actual_y = 0; //机器人坐标y轴,
  165. float m_actual_b = 0; //机器人坐标b轴, 旋转范围80~280
  166. float m_actual_z = 0; //机器人坐标z轴,
  167. float m_actual_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  168. float m_actual_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  169. unsigned char m_actual_clamp_motion1 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  170. unsigned char m_actual_clamp_motion2 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  171. unsigned char m_actual_clamp_motion3 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  172. unsigned char m_actual_clamp_motion4 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  173. unsigned char m_reserved66_99[34] = {0}; //预留
  174. //故障信息
  175. unsigned char m_actual_error_code[50] = {0}; //搬运器错误码
  176. unsigned char m_actual_warning_code[50] = {0}; //升降机错误码
  177. unsigned char m_actual_error_description[256] = {0}; //升降机错误描述
  178. };
  179. #pragma pack(pop) //取消对齐
  180. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  181. friend class Singleton<Dispatch_communication>;
  182. private:
  183. // 父类的构造函数必须保护,子类的构造函数必须私有。
  184. Dispatch_communication();
  185. public:
  186. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  187. Dispatch_communication(const Dispatch_communication& other) = delete;
  188. Dispatch_communication& operator =(const Dispatch_communication& other) = delete;
  189. ~Dispatch_communication();
  190. public://API functions
  191. //初始化 通信 模块。如下三选一
  192. virtual Error_manager communication_init();
  193. //反初始化 通信 模块。
  194. virtual Error_manager communication_uninit();
  195. public://get or set member variable
  196. // std::mutex * get_data_lock();
  197. // Request_from_dispatch_to_plc * get_request_from_dispatch_to_plc();
  198. // Response_from_plc_to_dispatch * get_response_from_plc_to_dispatch();
  199. // Status_from_dispatch_to_plc * get_status_from_dispatch_to_plc();
  200. // Status_from_plc_to_dispatch * get_status_from_plc_to_dispatch();
  201. protected://member functions
  202. //更新数据
  203. virtual Error_manager updata_receive_buf();
  204. virtual Error_manager updata_send_buf();
  205. protected://member variable
  206. public:
  207. std::mutex m_data_lock; //数据锁
  208. Catcher_request_from_dispatch_to_plc_for_data m_catcher_request_from_dispatch_to_plc_for_data[2]; //抓车模块给plc发送请求消息的指令结构体
  209. Catcher_request_from_dispatch_to_plc_for_key m_catcher_request_from_dispatch_to_plc_for_key[2]; //抓车模块给plc发送请求消息的指令结构体
  210. Catcher_response_from_plc_to_dispatch m_catcher_response_from_plc_to_dispatch[2]; //plc给抓车模块发送答复消息的指令结构体
  211. Catcher_status_from_plc_to_dispatch m_catcher_status_from_plc_to_dispatch[2]; //plc给抓车模块发送状态消息的指令结构体
  212. Carrier_request_from_dispatch_to_plc_for_data m_carrier_request_from_dispatch_to_plc_for_data[2]; //搬运器给plc发送请求消息的指令结构体
  213. Carrier_request_from_dispatch_to_plc_for_key m_carrier_request_from_dispatch_to_plc_for_key[2]; //搬运器给plc发送请求消息的指令结构体
  214. Carrier_response_from_plc_to_dispatch m_carrier_response_from_plc_to_dispatch[2]; //plc给搬运器发送答复消息的指令结构体
  215. Carrier_status_from_plc_to_dispatch m_carrier_status_from_plc_to_dispatch[2]; //plc给搬运器发送状态消息的指令结构体
  216. private:
  217. };
  218. #endif //NNXX_TESTS_DISPATCH_COMMUNICATION_H