dispatch_communication.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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_reserved50 = 0; //预留
  29. unsigned char m_reserved51_69[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_reserved87_89[3] = {0}; //预留
  37. float m_request_wheelbase = 0; //机器人抓车杆前后轮距.
  38. float m_request_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  39. float m_request_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  40. };
  41. //抓车模块给plc发送请求消息的指令结构体
  42. struct Catcher_request_from_dispatch_to_plc_for_key
  43. {
  44. //指令信息
  45. unsigned char m_request_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  46. };
  47. //plc给抓车模块发送答复消息的DB编号
  48. #define CATCHER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_1 111
  49. #define CATCHER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 121
  50. //plc给抓车模块发送答复消息的指令结构体
  51. struct Catcher_response_from_plc_to_dispatch
  52. {
  53. //指令信息
  54. unsigned char m_respons_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  55. unsigned char m_respons_status = 0; //指令完成状态, 机器人答复指令, 返回任务完成的情况
  56. unsigned char m_reserved51_69[19] = {0}; //预留
  57. //请求的目标坐标和动作
  58. float m_respons_x = 0; //机器人坐标x轴,
  59. float m_respons_y = 0; //机器人坐标y轴,
  60. float m_respons_b = 0; //机器人坐标b轴, 旋转范围80~280
  61. float m_respons_z = 0; //机器人坐标z轴,
  62. unsigned char m_respons_clamp_motion = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  63. unsigned char m_reserved87_89[3] = {0}; //预留
  64. float m_respons_wheelbase = 0; //机器人抓车杆前后轮距.
  65. float m_respons_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  66. float m_respons_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  67. };
  68. //plc给抓车模块发送状态消息的DB编号
  69. #define CATCHER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 113
  70. #define CATCHER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 123
  71. //plc给抓车模块发送状态消息的指令结构体
  72. struct Catcher_status_from_plc_to_dispatch
  73. {
  74. unsigned char m_heartbeat = 0; //心跳位, 0-255循环
  75. unsigned char m_safe_status = 0; //设备的安全状态
  76. unsigned char m_work_status = 0; //机器人的硬件设备状态
  77. unsigned char m_actual_load_status = 0; //机器人的负载状态, 机器人上面是否有车.
  78. unsigned char m_reserved4_37[34] = {0}; //预留
  79. float m_actual_x = 0; //机器人坐标x轴,
  80. float m_actual_y = 0; //机器人坐标y轴,
  81. float m_actual_b = 0; //机器人坐标b轴, 旋转范围80~280
  82. float m_actual_z = 0; //机器人坐标z轴,
  83. float m_actual_d1 = 0; //机器人坐标d1轴, 机器人抓车杆纵向移动(前轮抓杆)
  84. float m_actual_d2 = 0; //机器人坐标d2轴, 机器人抓车杆纵向移动(后轮抓杆)
  85. unsigned char m_actual_clamp_motion1 = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  86. unsigned char m_actual_clamp_motion2 = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  87. unsigned char m_actual_clamp_motion3 = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  88. unsigned char m_actual_clamp_motion4 = 0; //机器人夹车杆. 0=无动作,1=夹紧,2=松开
  89. unsigned char m_reserved66_99[34] = {0}; //预留
  90. //故障信息
  91. unsigned char m_actual_error_code[50] = {0}; //搬运器错误码
  92. unsigned char m_actual_warning_code[50] = {0}; //升降机错误码
  93. unsigned char m_actual_error_description[256] = {0}; //升降机错误描述
  94. };
  95. //搬运器给plc发送请求消息的DB编号
  96. #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_1 200
  97. #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_2 270
  98. #define CARRIER_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_3 230
  99. //搬运器给plc发送请求消息的指令结构体
  100. struct Carrier_request_from_dispatch_to_plc_for_data
  101. {
  102. //指令信息
  103. unsigned char m_reserved50 = 0; //预留
  104. unsigned char m_reserved51_71[21] = {0}; //预留
  105. //请求的目标坐标和动作
  106. float m_request_x; //搬运器坐标x轴, 中跑车控制横向移动
  107. float m_request_y; //搬运器坐标y轴, 小跑车控制纵向移动
  108. float m_request_z; //搬运器坐标z轴, 电梯控制上下移动
  109. float m_request_y1; //搬运器坐标y1轴, 小跑车控制纵向移动(前轮抓杆)
  110. float m_request_y2; //搬运器坐标y2轴, 小跑车控制纵向移动(后轮抓杆)
  111. unsigned char m_request_clamp_motion; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  112. unsigned char m_request_joint_motion_x; //电梯与X轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  113. unsigned char m_request_joint_motion_y; //小跑车与Y轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  114. unsigned char m_reserved95 = 0; //预留
  115. int m_request_space_id; //搬运器空间位置的id.
  116. int m_request_floor_id; //搬运器楼层位置的id.
  117. float m_request_wheelbase; //搬运器小跑车的抓车杆前后轮距.
  118. };
  119. //搬运器给plc发送请求消息的指令结构体
  120. struct Carrier_request_from_dispatch_to_plc_for_key
  121. {
  122. //指令信息
  123. unsigned char m_request_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  124. };
  125. //plc给搬运器发送答复消息的DB编号
  126. #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_1 201
  127. #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 271
  128. #define CARRIER_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_3 231
  129. //plc给搬运器发送答复消息的指令结构体
  130. struct Carrier_response_from_plc_to_dispatch
  131. {
  132. //指令信息
  133. unsigned char m_respons_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  134. unsigned char m_respons_status = 0; //指令完成状态, 机器人答复指令, 返回任务完成的情况
  135. unsigned char m_reserved51_71[21] = {0}; //预留
  136. //请求的目标坐标和动作
  137. float m_respons_x; //搬运器坐标x轴, 中跑车控制横向移动
  138. float m_respons_y; //搬运器坐标y轴, 小跑车控制纵向移动
  139. float m_respons_z; //搬运器坐标z轴, 电梯控制上下移动
  140. float m_respons_y1; //搬运器坐标y1轴, 小跑车控制纵向移动(前轮抓杆)
  141. float m_respons_y2; //搬运器坐标y2轴, 小跑车控制纵向移动(后轮抓杆)
  142. unsigned char m_respons_clamp_motion; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  143. unsigned char m_respons_joint_motion_x; //电梯与X轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  144. unsigned char m_respons_joint_motion_y; //小跑车与Y轴的横向轨道对接,0=无动作,1=进行对接, 2=松开对接
  145. unsigned char m_reserved95 = 0; //预留
  146. int m_respons_space_id; //搬运器空间位置的id.
  147. int m_respons_floor_id; //搬运器楼层位置的id.
  148. float m_respons_wheelbase; //搬运器小跑车的抓车杆前后轮距.
  149. };
  150. //plc给搬运器发送状态消息的DB编号
  151. #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 203
  152. #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 273
  153. #define CARRIER_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_3 233
  154. //plc给搬运器发送状态消息的指令结构体
  155. struct Carrier_status_from_plc_to_dispatch
  156. {
  157. unsigned char m_heartbeat = 0; //心跳位, 0-255循环
  158. unsigned char m_safe_status = 0; //设备的安全状态
  159. unsigned char m_work_status = 0; //搬运器的硬件设备状态
  160. unsigned char m_actual_load_status = 0; //搬运器的负载状态, 小跑车上面是否有车.
  161. unsigned char m_reserved4_37[34] = {0}; //预留
  162. float m_actual_x = 0; //搬运器坐标x轴,
  163. float m_actual_y = 0; //搬运器坐标y轴,
  164. float m_actual_z = 0; //搬运器坐标z轴,
  165. float m_actual_y1 = 0; //搬运器坐标y1轴, 小跑车控制纵向移动(前轮抓杆)
  166. float m_actual_y2 = 0; //搬运器坐标y2轴, 小跑车控制纵向移动(前轮抓杆)
  167. unsigned char m_actual_clamp_motion1 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  168. unsigned char m_actual_clamp_motion2 = 0; //小跑车夹车杆. 0=无动作,1=夹紧,2=松开
  169. unsigned char m_actual_small_sports_car_motion = 0; //小跑车的位置,是否在中跑车上面, 0=无动作,1=出发到位,2=返回到位
  170. unsigned char m_actual_joint_motion_x1 = 0; //电梯与X轴的横向轨道对接,0=无动作,1=伸出到位,2=收回到位
  171. unsigned char m_actual_joint_motion_x2 = 0; //电梯与X轴的横向轨道对接,0=无动作,1=伸出到位,2=收回到位
  172. unsigned char m_reserved63_101[39] = {0}; //预留
  173. //故障信息
  174. unsigned char m_actual_error_code[50] = {0}; //搬运器错误码
  175. unsigned char m_actual_warning_code[50] = {0}; //升降机错误码
  176. unsigned char m_actual_error_description[256] = {0}; //升降机错误描述
  177. };
  178. //通道口给plc发送请求消息的DB编号
  179. #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_0 300
  180. #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_1 310
  181. #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_2 320
  182. #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_3 330
  183. #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_4 340
  184. #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_5 350
  185. #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_6 360
  186. #define PASSAGEWAY_REQUEST_FROM_DISPATCH_TO_PLC_DBNUMBER_7 370
  187. //通道口给plc发送请求消息的指令结构体
  188. struct Passageway_request_from_dispatch_to_plc_for_data
  189. {
  190. //指令信息
  191. unsigned char m_reserved50 = 0; //预留
  192. unsigned char m_reserved51_69[19] = {0}; //预留
  193. // 请求的目标坐标和动作
  194. unsigned char m_request_inside_door_motion = 0; //通道口 内门动作
  195. unsigned char m_request_outside_door_motion = 0; //通道口 外门动作
  196. unsigned char m_request_turntable_direction = 0; //通道口 转台方向
  197. };
  198. //通道口给plc发送请求消息的指令结构体
  199. struct Passageway_request_from_dispatch_to_plc_for_key
  200. {
  201. //指令信息
  202. unsigned char m_request_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  203. };
  204. //plc给通道口发送答复消息的DB编号
  205. #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_0 301
  206. #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_1 311
  207. #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_2 321
  208. #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_3 331
  209. #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_4 341
  210. #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_5 351
  211. #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_6 361
  212. #define PASSAGEWAY_RESPONSE_FROM_PLC_TO_DISPATCH_DBNUMBER_7 371
  213. //plc给通道口发送答复消息的指令结构体
  214. struct Passageway_response_from_plc_to_dispatch
  215. {
  216. //指令信息
  217. unsigned char m_respons_key[50] = {0}; //指令key(任务唯一码), 作为通信标志位
  218. unsigned char m_respons_status = 0; //指令完成状态, 机器人答复指令, 返回任务完成的情况
  219. unsigned char m_reserved51_69[19] = {0}; //预留
  220. unsigned char m_respons_inside_door_motion = 0; //通道口 内门动作
  221. unsigned char m_respons_outside_door_motion = 0; //通道口 外门动作
  222. unsigned char m_respons_turntable_direction = 0; //通道口 转台方向
  223. };
  224. //plc给通道口发送状态消息的DB编号
  225. #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_0 303
  226. #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_1 313
  227. #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_2 323
  228. #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_3 333
  229. #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_4 343
  230. #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_5 353
  231. #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_6 363
  232. #define PASSAGEWAY_STATUS_FROM_PLC_TO_DISPATCH_DBNUMBER_7 373
  233. //plc给通道口发送状态消息的指令结构体
  234. struct Passageway_status_from_plc_to_dispatch
  235. {
  236. unsigned char m_heartbeat = 0; //心跳位, 0-255循环
  237. unsigned char m_safe_status = 0; //设备的安全状态
  238. unsigned char m_sensor_status1 = 0; //设备的传感器状态1
  239. unsigned char m_sensor_status2 = 0; //设备的传感器状态2
  240. unsigned char m_reserved4_35[32] = {0}; //预留
  241. unsigned char m_actual_turntable_direction; //通道口 转台方向
  242. unsigned char m_reserved37 = 0; //预留
  243. //故障信息
  244. unsigned char m_actual_error_code[50] = {0}; //通道口错误码
  245. unsigned char m_actual_warning_code[50] = {0}; //升降机错误码
  246. unsigned char m_actual_error_description[256] = {0}; //升降机错误描述
  247. };
  248. #pragma pack(pop) //取消对齐
  249. // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
  250. friend class Singleton<Dispatch_communication>;
  251. private:
  252. // 父类的构造函数必须保护,子类的构造函数必须私有。
  253. Dispatch_communication();
  254. public:
  255. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  256. Dispatch_communication(const Dispatch_communication& other) = delete;
  257. Dispatch_communication& operator =(const Dispatch_communication& other) = delete;
  258. ~Dispatch_communication();
  259. public://API functions
  260. //初始化 通信 模块。如下三选一
  261. virtual Error_manager communication_init();
  262. //反初始化 通信 模块。
  263. virtual Error_manager communication_uninit();
  264. public://get or set member variable
  265. // std::mutex * get_data_lock();
  266. // Request_from_dispatch_to_plc * get_request_from_dispatch_to_plc();
  267. // Response_from_plc_to_dispatch * get_response_from_plc_to_dispatch();
  268. // Status_from_dispatch_to_plc * get_status_from_dispatch_to_plc();
  269. // Status_from_plc_to_dispatch * get_status_from_plc_to_dispatch();
  270. protected://member functions
  271. //更新数据
  272. virtual Error_manager updata_receive_buf();
  273. virtual Error_manager updata_send_buf();
  274. protected://member variable
  275. public:
  276. std::mutex m_data_lock; //数据锁
  277. Catcher_request_from_dispatch_to_plc_for_data m_catcher_request_from_dispatch_to_plc_for_data[2]; //抓车模块给plc发送请求消息的指令结构体
  278. Catcher_request_from_dispatch_to_plc_for_key m_catcher_request_from_dispatch_to_plc_for_key[2]; //抓车模块给plc发送请求消息的指令结构体
  279. Catcher_response_from_plc_to_dispatch m_catcher_response_from_plc_to_dispatch[2]; //plc给抓车模块发送答复消息的指令结构体
  280. Catcher_status_from_plc_to_dispatch m_catcher_status_from_plc_to_dispatch[2]; //plc给抓车模块发送状态消息的指令结构体
  281. Carrier_request_from_dispatch_to_plc_for_data m_carrier_request_from_dispatch_to_plc_for_data[3]; //搬运器给plc发送请求消息的指令结构体
  282. Carrier_request_from_dispatch_to_plc_for_key m_carrier_request_from_dispatch_to_plc_for_key[3]; //搬运器给plc发送请求消息的指令结构体
  283. Carrier_response_from_plc_to_dispatch m_carrier_response_from_plc_to_dispatch[3]; //plc给搬运器发送答复消息的指令结构体
  284. Carrier_status_from_plc_to_dispatch m_carrier_status_from_plc_to_dispatch[3]; //plc给搬运器发送状态消息的指令结构体
  285. Passageway_request_from_dispatch_to_plc_for_data m_passageway_request_from_dispatch_to_plc_for_data[8]; //通道口给plc发送请求消息的指令结构体
  286. Passageway_request_from_dispatch_to_plc_for_key m_passageway_request_from_dispatch_to_plc_for_key[8]; //通道口给plc发送请求消息的指令结构体
  287. Passageway_response_from_plc_to_dispatch m_passageway_response_from_plc_to_dispatch[8]; //plc给通道口发送答复消息的指令结构体
  288. Passageway_status_from_plc_to_dispatch m_passageway_status_from_plc_to_dispatch[8]; //plc给通道口发送状态消息的指令结构体
  289. private:
  290. };
  291. #endif //NNXX_TESTS_DISPATCH_COMMUNICATION_H