dispatch_communication.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. //
  2. // Created by huli on 2020/9/25.
  3. //
  4. #include "dispatch_communication.h"
  5. Dispatch_communication::Dispatch_communication()
  6. {
  7. }
  8. Dispatch_communication::~Dispatch_communication()
  9. {
  10. }
  11. //初始化 通信 模块。如下三选一
  12. Error_manager Dispatch_communication::communication_init(int plc_id)
  13. {
  14. m_plc_id = plc_id;
  15. int t_index = 0;
  16. std::vector<Snap7_buf::Variable_information> t_variable_information_vector;
  17. //往map通信缓存里面添加所需要的buf
  18. std::unique_lock<std::mutex> t_lock1(m_receive_buf_lock);
  19. std::unique_lock<std::mutex> t_lock2(m_send_buf_lock);
  20. Snap7_buf t_snap7_buf;
  21. //调度指令
  22. t_index = 0;
  23. t_variable_information_vector.clear();
  24. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_status", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  25. t_index += sizeof(unsigned char)*1;
  26. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved51_73", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 23 });
  27. t_index += sizeof(unsigned char)*23;
  28. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_dispatch_motion_direction", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  29. t_index += sizeof(unsigned char)*1;
  30. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved75_79", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 5 });
  31. t_index += sizeof(unsigned char)*5;
  32. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_passageway_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  33. t_index += sizeof(unsigned int)*1;
  34. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_passageway_direction", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  35. t_index += sizeof(unsigned char)*1;
  36. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved85_89", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 5 });
  37. t_index += sizeof(unsigned char)*5;
  38. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_index_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  39. t_index += sizeof(unsigned int)*1;
  40. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_unit_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  41. t_index += sizeof(unsigned int)*1;
  42. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_label_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  43. t_index += sizeof(unsigned int)*1;
  44. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_floor_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  45. t_index += sizeof(unsigned int)*1;
  46. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_room_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  47. t_index += sizeof(unsigned int)*1;
  48. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_direction", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  49. t_index += sizeof(unsigned char)*1;
  50. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved111", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  51. t_index += sizeof(unsigned char)*1;
  52. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_center_x", typeid(float).name(), t_index,sizeof(float), 1 });
  53. t_index += sizeof(float)*1;
  54. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_center_y", typeid(float).name(), t_index,sizeof(float), 1 });
  55. t_index += sizeof(float)*1;
  56. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_angle", typeid(float).name(), t_index,sizeof(float), 1 });
  57. t_index += sizeof(float)*1;
  58. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_front_theta", typeid(float).name(), t_index,sizeof(float), 1 });
  59. t_index += sizeof(float)*1;
  60. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_length", typeid(float).name(), t_index,sizeof(float), 1 });
  61. t_index += sizeof(float)*1;
  62. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_width", typeid(float).name(), t_index,sizeof(float), 1 });
  63. t_index += sizeof(float)*1;
  64. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_height", typeid(float).name(), t_index,sizeof(float), 1 });
  65. t_index += sizeof(float)*1;
  66. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_wheel_base", typeid(float).name(), t_index,sizeof(float), 1 });
  67. t_index += sizeof(float)*1;
  68. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_wheel_width", typeid(float).name(), t_index,sizeof(float), 1 });
  69. t_index += sizeof(float)*1;
  70. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_license", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 20 });
  71. t_index += sizeof(unsigned char)*20;
  72. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved168_187", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 20 });
  73. t_index += sizeof(unsigned char)*20;
  74. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_type", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  75. t_index += sizeof(unsigned char)*1;
  76. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved189_209", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 21 });
  77. t_index += sizeof(unsigned char)*21;
  78. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_anticollision_lidar_flag", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  79. t_index += sizeof(unsigned char)*1;
  80. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved211_215", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 5 });
  81. t_index += sizeof(unsigned char)*5;
  82. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_wheel_base_exact_value", typeid(float).name(), t_index,sizeof(float), 1 });
  83. t_index += sizeof(float)*1;
  84. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved217_231", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 25 });
  85. t_index += sizeof(unsigned char)*25;
  86. t_snap7_buf.init(DISPATCH_REQUEST_FROM_MANAGER_TO_PLC_DBNUMBER_0 +m_plc_id*100, 50, sizeof(Dispatch_request_from_manager_to_plc_for_data), t_variable_information_vector, Snap7_buf::LOOP_COMMUNICATION);
  87. m_send_buf_map[0] = t_snap7_buf;
  88. t_index = 0;
  89. t_variable_information_vector.clear();
  90. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_key", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 50 });
  91. t_index += sizeof(unsigned char)*50;
  92. t_snap7_buf.init(DISPATCH_REQUEST_FROM_MANAGER_TO_PLC_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Dispatch_request_from_manager_to_plc_for_key), t_variable_information_vector, Snap7_buf::LOOP_COMMUNICATION);
  93. m_send_buf_map[1] = t_snap7_buf;
  94. t_index = 0;
  95. t_variable_information_vector.clear();
  96. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_response_key", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 50 });
  97. t_index += sizeof(unsigned char)*50;
  98. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved50", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  99. t_index += sizeof(unsigned char)*1;
  100. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved51_73", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 23 });
  101. t_index += sizeof(unsigned char)*23;
  102. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_dispatch_motion_direction", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  103. t_index += sizeof(unsigned char)*1;
  104. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved75_79", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 5 });
  105. t_index += sizeof(unsigned char)*5;
  106. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_passageway_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  107. t_index += sizeof(unsigned int)*1;
  108. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_passageway_direction", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  109. t_index += sizeof(unsigned char)*1;
  110. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved85_89", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 5 });
  111. t_index += sizeof(unsigned char)*5;
  112. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_index_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  113. t_index += sizeof(unsigned int)*1;
  114. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_unit_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  115. t_index += sizeof(unsigned int)*1;
  116. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_label_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  117. t_index += sizeof(unsigned int)*1;
  118. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_floor_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  119. t_index += sizeof(unsigned int)*1;
  120. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_room_id", typeid(unsigned int).name(), t_index,sizeof(unsigned int), 1 });
  121. t_index += sizeof(unsigned int)*1;
  122. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_parkingspace_direction", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  123. t_index += sizeof(unsigned char)*1;
  124. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved111", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  125. t_index += sizeof(unsigned char)*1;
  126. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_center_x", typeid(float).name(), t_index,sizeof(float), 1 });
  127. t_index += sizeof(float)*1;
  128. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_center_y", typeid(float).name(), t_index,sizeof(float), 1 });
  129. t_index += sizeof(float)*1;
  130. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_angle", typeid(float).name(), t_index,sizeof(float), 1 });
  131. t_index += sizeof(float)*1;
  132. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_front_theta", typeid(float).name(), t_index,sizeof(float), 1 });
  133. t_index += sizeof(float)*1;
  134. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_length", typeid(float).name(), t_index,sizeof(float), 1 });
  135. t_index += sizeof(float)*1;
  136. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_width", typeid(float).name(), t_index,sizeof(float), 1 });
  137. t_index += sizeof(float)*1;
  138. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_height", typeid(float).name(), t_index,sizeof(float), 1 });
  139. t_index += sizeof(float)*1;
  140. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_wheel_base", typeid(float).name(), t_index,sizeof(float), 1 });
  141. t_index += sizeof(float)*1;
  142. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_wheel_width", typeid(float).name(), t_index,sizeof(float), 1 });
  143. t_index += sizeof(float)*1;
  144. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_license", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 20 });
  145. t_index += sizeof(unsigned char)*20;
  146. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved168_187", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 20 });
  147. t_index += sizeof(unsigned char)*20;
  148. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_type", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  149. t_index += sizeof(unsigned char)*1;
  150. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved189_209", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 21 });
  151. t_index += sizeof(unsigned char)*21;
  152. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_anticollision_lidar_flag", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  153. t_index += sizeof(unsigned char)*1;
  154. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved211_215", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 5 });
  155. t_index += sizeof(unsigned char)*5;
  156. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_wheel_base_exact_value", typeid(float).name(), t_index,sizeof(float), 1 });
  157. t_index += sizeof(float)*1;
  158. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved217_231", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 25 });
  159. t_index += sizeof(unsigned char)*25;
  160. t_snap7_buf.init(DISPATCH_RESPONSE_FROM_PLC_TO_MANAGER_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Dispatch_response_from_plc_to_manager), t_variable_information_vector, Snap7_buf::LOOP_COMMUNICATION);
  161. m_receive_buf_map[0] = t_snap7_buf;
  162. //调度状态
  163. t_index = 0;
  164. t_variable_information_vector.clear();
  165. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_heartbeat", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  166. t_index += sizeof(unsigned char)*1;
  167. t_snap7_buf.init(DISPATCH_PLC_STATUS_FROM_MANAGER_TO_PLC_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Dispatch_plc_status_from_manager_to_plc), t_variable_information_vector, Snap7_buf::LOOP_COMMUNICATION);
  168. m_send_buf_map[2] = t_snap7_buf;
  169. t_index = 0;
  170. t_variable_information_vector.clear();
  171. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_heartbeat", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  172. t_index += sizeof(unsigned char)*1;
  173. t_snap7_buf.init(DISPATCH_PLC_STATUS_FROM_PLC_TO_MANAGER_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Dispatch_plc_status_from_plc_to_manager), t_variable_information_vector, Snap7_buf::NO_COMMUNICATION);
  174. m_receive_buf_map[1] = t_snap7_buf;
  175. //地面雷达指令
  176. t_index = 0;
  177. t_variable_information_vector.clear();
  178. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_center_x", typeid(float).name(), t_index,sizeof(float), 1 });
  179. t_index += sizeof(float)*1;
  180. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_center_y", typeid(float).name(), t_index,sizeof(float), 1 });
  181. t_index += sizeof(float)*1;
  182. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_angle", typeid(float).name(), t_index,sizeof(float), 1 });
  183. t_index += sizeof(float)*1;
  184. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_front_theta", typeid(float).name(), t_index,sizeof(float), 1 });
  185. t_index += sizeof(float)*1;
  186. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_length", typeid(float).name(), t_index,sizeof(float), 1 });
  187. t_index += sizeof(float)*1;
  188. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_width", typeid(float).name(), t_index,sizeof(float), 1 });
  189. t_index += sizeof(float)*1;
  190. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_height", typeid(float).name(), t_index,sizeof(float), 1 });
  191. t_index += sizeof(float)*1;
  192. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_wheel_base", typeid(float).name(), t_index,sizeof(float), 1 });
  193. t_index += sizeof(float)*1;
  194. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_request_car_wheel_width", typeid(float).name(), t_index,sizeof(float), 1 });
  195. t_index += sizeof(float)*1;
  196. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_response_locate_correct", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  197. t_index += sizeof(unsigned char)*1;
  198. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved37_40", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 3 });
  199. t_index += sizeof(unsigned char)*3;
  200. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_heartbeat", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  201. t_index += sizeof(unsigned char)*1;
  202. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_communication_mode", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  203. t_index += sizeof(unsigned char)*1;
  204. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_refresh_command", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  205. t_index += sizeof(unsigned char)*1;
  206. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_data_validity", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  207. t_index += sizeof(unsigned char)*1;
  208. t_snap7_buf.init(GROUND_LIDAR_RESPONSE_FROM_MANAGER_TO_PLC_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Ground_lidar_response_from_manager_to_plc_for_data), t_variable_information_vector, Snap7_buf::LOOP_COMMUNICATION);
  209. m_send_buf_map[3] = t_snap7_buf;
  210. t_snap7_buf.init(GROUND_LIDAR_RESPONSE_FROM_MANAGER_TO_PLC_DBNUMBER_1 +m_plc_id*100, 0, sizeof(Ground_lidar_response_from_manager_to_plc_for_data), t_variable_information_vector, Snap7_buf::LOOP_COMMUNICATION);
  211. m_send_buf_map[4] = t_snap7_buf;
  212. t_index = 0;
  213. t_variable_information_vector.clear();
  214. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_heartbeat", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  215. t_index += sizeof(unsigned char)*1;
  216. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_communication_mode", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  217. t_index += sizeof(unsigned char)*1;
  218. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_refresh_command", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  219. t_index += sizeof(unsigned char)*1;
  220. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_data_validity", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  221. t_index += sizeof(unsigned char)*1;
  222. t_snap7_buf.init(GROUND_LIDAR_RESPONSE_FROM_MANAGER_TO_PLC_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Ground_lidar_response_from_manager_to_plc_for_key), t_variable_information_vector, Snap7_buf::NO_COMMUNICATION);
  223. m_send_buf_map[5] = t_snap7_buf;
  224. t_snap7_buf.init(GROUND_LIDAR_RESPONSE_FROM_MANAGER_TO_PLC_DBNUMBER_1 +m_plc_id*100, 0, sizeof(Ground_lidar_response_from_manager_to_plc_for_key), t_variable_information_vector, Snap7_buf::NO_COMMUNICATION);
  225. m_send_buf_map[6] = t_snap7_buf;
  226. t_index = 0;
  227. t_variable_information_vector.clear();
  228. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_heartbeat", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  229. t_index += sizeof(unsigned char)*1;
  230. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_communication_mode", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  231. t_index += sizeof(unsigned char)*1;
  232. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_refresh_command", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  233. t_index += sizeof(unsigned char)*1;
  234. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_data_validity", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  235. t_index += sizeof(unsigned char)*1;
  236. t_snap7_buf.init(GROUND_LIDAR_REQUEST_FROM_PLC_TO_MANAGER_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Ground_lidar_request_from_plc_to_manager), t_variable_information_vector, Snap7_buf::NO_COMMUNICATION);
  237. m_receive_buf_map[2] = t_snap7_buf;
  238. t_snap7_buf.init(GROUND_LIDAR_REQUEST_FROM_PLC_TO_MANAGER_DBNUMBER_1 +m_plc_id*100, 0, sizeof(Ground_lidar_request_from_plc_to_manager), t_variable_information_vector, Snap7_buf::NO_COMMUNICATION);
  239. m_receive_buf_map[3] = t_snap7_buf;
  240. //防撞雷达
  241. t_index = 0;
  242. t_variable_information_vector.clear();
  243. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_response_anticollision_lidar_flag", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  244. t_index += sizeof(unsigned char)*1;
  245. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_reserved5_7", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 3 });
  246. t_index += sizeof(unsigned char)*3;
  247. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_response_offset_x", typeid(float).name(), t_index,sizeof(float), 1 });
  248. t_index += sizeof(float)*1;
  249. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_response_offset_angle", typeid(float).name(), t_index,sizeof(float), 1 });
  250. t_index += sizeof(float)*1;
  251. t_snap7_buf.init(ANTICOLLISION_LIDAR_RESPONSE_FROM_MANAGER_TO_PLC_DBNUMBER_0 +m_plc_id*100, 4, sizeof(Anticollision_lidar_response_from_manager_to_plc_for_data), t_variable_information_vector, Snap7_buf::LOOP_COMMUNICATION);
  252. m_send_buf_map[7] = t_snap7_buf;
  253. t_index = 0;
  254. t_variable_information_vector.clear();
  255. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_heartbeat", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  256. t_index += sizeof(unsigned char)*1;
  257. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_communication_mode", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  258. t_index += sizeof(unsigned char)*1;
  259. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_refresh_command", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  260. t_index += sizeof(unsigned char)*1;
  261. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_data_validity", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  262. t_index += sizeof(unsigned char)*1;
  263. t_snap7_buf.init(ANTICOLLISION_LIDAR_RESPONSE_FROM_MANAGER_TO_PLC_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Anticollision_lidar_response_from_manager_to_plc_for_key), t_variable_information_vector, Snap7_buf::LOOP_COMMUNICATION);
  264. m_send_buf_map[8] = t_snap7_buf;
  265. t_index = 0;
  266. t_variable_information_vector.clear();
  267. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_heartbeat", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  268. t_index += sizeof(unsigned char)*1;
  269. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_communication_mode", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  270. t_index += sizeof(unsigned char)*1;
  271. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_refresh_command", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  272. t_index += sizeof(unsigned char)*1;
  273. t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_data_validity", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
  274. t_index += sizeof(unsigned char)*1;
  275. t_snap7_buf.init(ANTICOLLISION_LIDAR_REQUEST_FROM_PLC_TO_MANAGER_DBNUMBER_0 +m_plc_id*100, 0, sizeof(Anticollision_lidar_request_from_plc_to_manager), t_variable_information_vector, Snap7_buf::NO_COMMUNICATION);
  276. m_receive_buf_map[4] = t_snap7_buf;
  277. return Snap7_communication_base::communication_init();
  278. }
  279. //反初始化 通信 模块。
  280. Error_manager Dispatch_communication::communication_uninit()
  281. {
  282. return Snap7_communication_base::communication_uninit();
  283. }
  284. //更新数据
  285. Error_manager Dispatch_communication::updata_receive_buf()
  286. {
  287. // return Error_code::SUCCESS;
  288. std::unique_lock<std::mutex> t_lock1(m_receive_buf_lock);
  289. std::unique_lock<std::mutex> t_lock2(m_data_lock);
  290. memcpy(&m_dispatch_response_from_plc_to_manager, m_receive_buf_map[0].mp_buf_obverse, m_receive_buf_map[0].m_size);
  291. memcpy(&m_dispatch_plc_status_from_plc_to_manager, m_receive_buf_map[1].mp_buf_obverse, m_receive_buf_map[1].m_size);
  292. memcpy(&m_ground_lidar_request_from_plc_to_manager[0], m_receive_buf_map[2].mp_buf_obverse, m_receive_buf_map[2].m_size);
  293. memcpy(&m_ground_lidar_request_from_plc_to_manager[1], m_receive_buf_map[3].mp_buf_obverse, m_receive_buf_map[3].m_size);
  294. memcpy(&m_anticollision_lidar_request_from_plc_to_manager, m_receive_buf_map[4].mp_buf_obverse, m_receive_buf_map[4].m_size);
  295. return Error_code::SUCCESS;
  296. }
  297. Error_manager Dispatch_communication::updata_send_buf()
  298. {
  299. std::unique_lock<std::mutex> t_lock1(m_send_buf_lock);
  300. std::unique_lock<std::mutex> t_lock2(m_data_lock);
  301. memcpy(m_send_buf_map[0].mp_buf_obverse, &m_dispatch_request_from_manager_to_plc_for_data, m_send_buf_map[0].m_size);
  302. memcpy(m_send_buf_map[1].mp_buf_obverse, &m_dispatch_request_from_manager_to_plc_for_key, m_send_buf_map[1].m_size);
  303. memcpy(m_send_buf_map[2].mp_buf_obverse, &m_dispatch_plc_status_from_manager_to_plc, m_send_buf_map[2].m_size);
  304. memcpy(m_send_buf_map[3].mp_buf_obverse, &m_ground_lidar_response_from_manager_to_plc_for_data[0], m_send_buf_map[3].m_size);
  305. memcpy(m_send_buf_map[4].mp_buf_obverse, &m_ground_lidar_response_from_manager_to_plc_for_data[1], m_send_buf_map[4].m_size);
  306. memcpy(m_send_buf_map[5].mp_buf_obverse, &m_ground_lidar_response_from_manager_to_plc_for_key[0], m_send_buf_map[5].m_size);
  307. memcpy(m_send_buf_map[6].mp_buf_obverse, &m_ground_lidar_response_from_manager_to_plc_for_key[1], m_send_buf_map[6].m_size);
  308. memcpy(m_send_buf_map[7].mp_buf_obverse, &m_anticollision_lidar_response_from_manager_to_plc_for_data, m_send_buf_map[7].m_size);
  309. memcpy(m_send_buf_map[8].mp_buf_obverse, &m_anticollision_lidar_response_from_manager_to_plc_for_key, m_send_buf_map[8].m_size);
  310. return Error_code::SUCCESS;
  311. }