main.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. //
  2. //
  3. // 20210425, hl_dispatch 和 hl_dispatch_B的版本进行同步, 此时调度管理的功能全部完成.后续可能还需要日志记录.
  4. //
  5. #include <iostream>
  6. #include "./error_code/error_code.h"
  7. //#include "LogFiles.h"
  8. #include <glog/logging.h>
  9. #include "./communication/communication_socket_base.h"
  10. #include "./tool/thread_pool.h"
  11. #include "./system/system_communication.h"
  12. #include "./system/system_executor.h"
  13. #include "./dispatch/dispatch_manager.h"
  14. #include "./dispatch/dispatch_communication.h"
  15. #include "./dispatch/dispatch_coordinates.h"
  16. #include "./tool/common_data.h"
  17. #include <algorithm> // std::for_each
  18. #define LIVOX_NUMBER 2
  19. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  20. {
  21. time_t tt;
  22. time( &tt );
  23. tt = tt + 8*3600; // transform the time zone
  24. tm* t= gmtime( &tt );
  25. char buf[255]={0};
  26. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  27. t->tm_year + 1900,
  28. t->tm_mon + 1,
  29. t->tm_mday,
  30. t->tm_hour,
  31. t->tm_min,
  32. t->tm_sec);
  33. FILE* tp_file=fopen(buf,"w");
  34. fprintf(tp_file,data,strlen(data));
  35. fclose(tp_file);
  36. }
  37. #include <chrono>
  38. using namespace std;
  39. class AAA
  40. {
  41. public:
  42. int a;
  43. };
  44. class BBB:public AAA
  45. {
  46. public:
  47. int b;
  48. };
  49. int main(int argc,char* argv[])
  50. {
  51. // char buf[4];
  52. // sprintf(buf, "ads");
  53. // std::cout << " huli test :::: " << " buf = " << buf << std::endl;
  54. // std::string str = buf;
  55. // std::cout << " huli test :::: " << " str = " << str << std::endl;
  56. // std::cout << " huli test :::: " << " str.size() = " << str.size() << std::endl;
  57. //
  58. // return 0;
  59. Error_manager t_error;
  60. const char* logPath = "./";
  61. google::InitGoogleLogging("LidarMeasurement");
  62. google::SetStderrLogging(google::INFO);
  63. google::SetLogDestination(0, logPath);
  64. google::SetLogFilenameExtension("zxlog");
  65. google::InstallFailureSignalHandler();
  66. google::InstallFailureWriter(&shut_down_logging);
  67. FLAGS_colorlogtostderr = true; // Set log color
  68. FLAGS_logbufsecs = 0; // Set log output speed(s)
  69. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  70. FLAGS_stop_logging_if_full_disk = true;
  71. //#define MAIN_TEST 1
  72. #ifdef MAIN_TEST
  73. t_error = Dispatch_coordinates::get_instance_references().dispatch_coordinates_init();
  74. std::cout << " huli test :::: " << " Dispatch_coordinates::get_instance_references().dispatch_coordinates_init() = " << t_error.to_string() << std::endl;
  75. t_error = Dispatch_communication::get_instance_references().communication_init();
  76. std::cout << " huli test :::: " << " Dispatch_communication::get_instance_references().communication_init() = " << t_error.to_string() << std::endl;
  77. std::cout << "Dispatch_communication = " << Dispatch_communication::get_instance_references().get_status() << std::endl;
  78. t_error = Dispatch_manager::get_instance_references().dispatch_manager_init(0);
  79. std::cout << " huli test :::: " << " Dispatch_manager::get_instance_references().dispatch_manager_init(0) = " << t_error.to_string() << std::endl;
  80. std::cout << "Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  81. System_executor::get_instance_references().system_executor_init(10);
  82. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  83. System_communication::get_instance_references().communication_init();
  84. System_communication::get_instance_references().set_encapsulate_cycle_time(1000);
  85. while (1)
  86. {
  87. std::this_thread::sleep_for(std::chrono::seconds(1));
  88. }
  89. return 0;
  90. #endif
  91. // Error_manager t_error;
  92. t_error = Dispatch_communication::get_instance_references().communication_init();
  93. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  94. std::cout << "Dispatch_communication = " << Dispatch_communication::get_instance_references().get_status() << std::endl;
  95. std::this_thread::sleep_for(std::chrono::seconds(2));
  96. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  97. std::cout << "Dispatch_communication = " << Dispatch_communication::get_instance_references().get_status() << std::endl;
  98. std::cout << " ---------------------------------------------------" << std::endl;
  99. std::cout << " ---------------------------------------------------" << std::endl;
  100. Catcher t_catcher;
  101. t_error = t_catcher.dispatch_device_base_init(1, 102);
  102. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  103. std::this_thread::sleep_for(std::chrono::milliseconds(2));
  104. std::shared_ptr<Task_Base> tp_task_Base1(new Catcher_task);
  105. Catcher_task * tp_catcher_task1 = (Catcher_task *)tp_task_Base1.get();
  106. tp_catcher_task1->task_init(NULL,std::chrono::milliseconds(15000));
  107. tp_catcher_task1->m_request_key = "x23456789012345678901234567890r1";
  108. tp_catcher_task1->m_request_x = 21000;
  109. tp_catcher_task1->m_request_y = 3000;
  110. tp_catcher_task1->m_request_b = 90;
  111. tp_catcher_task1->m_request_z = 5410;
  112. tp_catcher_task1->m_request_d1 = 355;
  113. tp_catcher_task1->m_request_d2 = 455;
  114. tp_catcher_task1->m_request_wheelbase = 2800;
  115. tp_catcher_task1->m_request_clamp_motion = Catcher_task::E_CLAMP_LOOSE;
  116. t_error = t_catcher.execute_task(tp_task_Base1, Dispatch_device_base::DISPATCH_TASK_ONE_LEVEL);
  117. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  118. std::cout << " ---------------------------------------------------" << std::endl;
  119. Carrier t_carrier20;
  120. t_error = t_carrier20.dispatch_device_base_init(0, 200);
  121. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  122. std::this_thread::sleep_for(std::chrono::milliseconds(2));
  123. std::shared_ptr<Task_Base> tp_task_Base20(new Carrier_task);
  124. Carrier_task * tp_carrier_task20 = (Carrier_task *)tp_task_Base20.get();
  125. tp_carrier_task20->task_init(NULL,std::chrono::milliseconds(15000));
  126. tp_carrier_task20->m_request_key = "x23456789012345678901234567890c0";
  127. tp_carrier_task20->m_request_x = 1;
  128. // tp_carrier_task20->m_request_x = 25400;
  129. // tp_carrier_task20->m_request_x = 32600;
  130. tp_carrier_task20->m_request_y = 3000;
  131. tp_carrier_task20->m_request_z = 2525;
  132. tp_carrier_task20->m_request_z = 15525;
  133. tp_carrier_task20->m_request_y1 = 4500;
  134. tp_carrier_task20->m_request_y2 = 1700;
  135. tp_carrier_task20->m_request_clamp_motion = Carrier_task::E_CLAMP_LOOSE;
  136. tp_carrier_task20->m_request_joint_motion_x = Carrier_task::E_JOINT_HOLD_OUT;
  137. tp_carrier_task20->m_request_joint_motion_y = Carrier_task::E_JOINT_HOLD_OUT;
  138. tp_carrier_task20->m_request_space_id = 555;
  139. tp_carrier_task20->m_request_floor_id = 555;
  140. tp_carrier_task20->m_request_wheelbase = 555;
  141. t_error = t_carrier20.execute_task(tp_task_Base20, Dispatch_device_base::DISPATCH_TASK_ONE_LEVEL);
  142. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  143. std::cout << " ---------------------------------------------------" << std::endl;
  144. Carrier t_carrier21;
  145. t_error = t_carrier21.dispatch_device_base_init(1, 207);
  146. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  147. std::this_thread::sleep_for(std::chrono::milliseconds(2));
  148. std::shared_ptr<Task_Base> tp_task_Base21(new Carrier_task);
  149. Carrier_task * tp_carrier_task21 = (Carrier_task *)tp_task_Base21.get();
  150. tp_carrier_task21->task_init(NULL,std::chrono::milliseconds(15000));
  151. tp_carrier_task21->m_request_key = "x23456789012345678901234567890c1";
  152. // tp_carrier_task21->m_request_x = 1;
  153. tp_carrier_task21->m_request_x = 32600;
  154. tp_carrier_task21->m_request_y = 3000;
  155. tp_carrier_task21->m_request_z = 2525;
  156. tp_carrier_task21->m_request_z = 5125;
  157. tp_carrier_task21->m_request_y1 = 4500;
  158. tp_carrier_task21->m_request_y2 = 1700;
  159. tp_carrier_task21->m_request_clamp_motion = Carrier_task::E_CLAMP_LOOSE;
  160. tp_carrier_task21->m_request_joint_motion_x = Carrier_task::E_JOINT_HOLD_OUT;
  161. tp_carrier_task21->m_request_joint_motion_y = Carrier_task::E_JOINT_HOLD_OUT;
  162. tp_carrier_task21->m_request_space_id = 555;
  163. tp_carrier_task21->m_request_floor_id = 555;
  164. tp_carrier_task21->m_request_wheelbase = 555;
  165. t_error = t_carrier21.execute_task(tp_task_Base21, Dispatch_device_base::DISPATCH_TASK_ONE_LEVEL);
  166. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  167. std::cout << " ---------------------------------------------------" << std::endl;
  168. Carrier t_carrier22;
  169. t_error = t_carrier22.dispatch_device_base_init(2, 203);
  170. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  171. std::this_thread::sleep_for(std::chrono::milliseconds(2));
  172. std::shared_ptr<Task_Base> tp_task_Base22(new Carrier_task);
  173. Carrier_task * tp_carrier_task22 = (Carrier_task *)tp_task_Base22.get();
  174. tp_carrier_task22->task_init(NULL,std::chrono::milliseconds(15000));
  175. tp_carrier_task22->m_request_key = "x23456789012345678901234567890c2";
  176. tp_carrier_task22->m_request_x = 21000;
  177. // tp_carrier_task22->m_request_x = 4700;
  178. tp_carrier_task22->m_request_y = 3000;
  179. tp_carrier_task22->m_request_z = 5125;
  180. tp_carrier_task22->m_request_y1 = 4500;
  181. tp_carrier_task22->m_request_y2 = 1700;
  182. tp_carrier_task22->m_request_clamp_motion = Carrier_task::E_CLAMP_LOOSE;
  183. tp_carrier_task22->m_request_joint_motion_x = Carrier_task::E_JOINT_HOLD_OUT;
  184. tp_carrier_task22->m_request_joint_motion_y = Carrier_task::E_JOINT_HOLD_OUT;
  185. tp_carrier_task22->m_request_space_id = 555;
  186. tp_carrier_task22->m_request_floor_id = 555;
  187. tp_carrier_task22->m_request_wheelbase = 555;
  188. t_error = t_carrier22.execute_task(tp_task_Base22, Dispatch_device_base::DISPATCH_TASK_ONE_LEVEL);
  189. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  190. std::cout << " ---------------------------------------------------" << std::endl;
  191. /*
  192. Passageway t_passageway;
  193. t_error = t_passageway.dispatch_device_base_init(1);
  194. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  195. std::this_thread::sleep_for(std::chrono::milliseconds(2));
  196. std::shared_ptr<Task_Base> tp_task_Base3(new Passageway_task);
  197. Passageway_task * tp_passageway_task = (Passageway_task *)tp_task_Base3.get();
  198. tp_passageway_task->task_init(NULL,std::chrono::milliseconds(15000));
  199. tp_passageway_task->m_request_key = "ABCDEF";
  200. tp_passageway_task->m_request_inside_door_motion = Passageway_task::DOOR_OPEN;
  201. tp_passageway_task->m_request_outside_door_motion = Passageway_task::DOOR_CLOSE;
  202. tp_passageway_task->m_request_turntable_direction = Passageway_task::TURNTABLE_DIRECTION_OUTSIDE;
  203. t_error = t_passageway.execute_task(tp_task_Base3, Dispatch_device_base::E_ONE_LEVEL);
  204. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  205. std::cout << " ---------------------------------------------------" << std::endl;
  206. char zxczxcxzc3 ;
  207. std::cin >> zxczxcxzc3 ;
  208. while ( 1 )
  209. {
  210. std::cout << " huli test :::: " << " ===================================== " << std::endl;
  211. std::cout << " huli test :::: " << " tp_passageway_task->get_task_statu = " << tp_passageway_task->get_task_statu() << std::endl;
  212. std::cout << " huli test :::: " << " tp_passageway_task->m_respons_status = " << tp_passageway_task->m_respons_status << std::endl;
  213. std::cout << " huli test :::: " << " m_respons_key = " << tp_passageway_task->m_respons_key << std::endl;
  214. std::cout << " huli test :::: " << " m_respons_status = " << tp_passageway_task->m_respons_status << std::endl;
  215. std::cout << " huli test :::: " << " m_respons_inside_door_motion = " << tp_passageway_task->m_respons_inside_door_motion << std::endl;
  216. std::cout << " huli test :::: " << " m_respons_outside_door_motion = " << tp_passageway_task->m_respons_outside_door_motion << std::endl;
  217. std::cout << " huli test :::: " << " m_respons_turntable_direction = " << tp_passageway_task->m_respons_turntable_direction << std::endl;
  218. std::cout << " ---------------------------------------------------" << std::endl;
  219. std::cout << " huli test :::: " << " *********************************************** = " << std::endl;
  220. std::cout << " huli test :::: " << " t_passageway_base.get_passageway_status() = " << t_passageway.get_dispatch_device_status() << std::endl;
  221. int heat = t_passageway.m_last_heartbeat;
  222. std::cout << " huli test :::: " << " m_last_heartbeat = " << heat << std::endl;
  223. std::cout << " huli test :::: " << " m_actual_device_status = " << t_passageway.m_actual_device_status << std::endl;
  224. std::cout << " huli test :::: " << " m_actual_inside_load_status = " << t_passageway.m_actual_inside_load_status << std::endl;
  225. std::cout << " huli test :::: " << " m_actual_outside_load_status = " << t_passageway.m_actual_outside_load_status << std::endl;
  226. std::cout << " huli test :::: " << " m_actual_front_overstep_the_boundary = " << t_passageway.m_actual_front_overstep_the_boundary << std::endl;
  227. std::cout << " huli test :::: " << " m_actual_back_overstep_the_boundary = " << t_passageway.m_actual_back_overstep_the_boundary << std::endl;
  228. std::cout << " huli test :::: " << " m_actual_height_overstep_the_boundary = " << t_passageway.m_actual_height_overstep_the_boundary << std::endl;
  229. std::cout << " huli test :::: " << " m_actual_outside_door_sensor = " << t_passageway.m_actual_outside_door_sensor << std::endl;
  230. std::cout << " huli test :::: " << " m_actual_inside_door_motion = " << t_passageway.m_actual_inside_door_motion << std::endl;
  231. std::cout << " huli test :::: " << " m_actual_outside_door_motion = " << t_passageway.m_actual_outside_door_motion << std::endl;
  232. std::cout << " huli test :::: " << " m_actual_turntable_load_status = " << t_passageway.m_actual_turntable_load_status << std::endl;
  233. std::cout << " huli test :::: " << " m_actual_turntable_direction = " << t_passageway.m_actual_turntable_direction << std::endl;
  234. std::cout << " huli test :::: " << " m_actual_error_code = " << std::endl;
  235. for (int i = 0; i < 50; ++i)
  236. {
  237. printf("0x%x ", t_passageway.m_actual_error_code[i]);
  238. }
  239. std::cout << std::endl;
  240. std::cout << " huli test :::: " << " m_actual_warning_code = " << std::endl;
  241. for (int i = 0; i < 50; ++i)
  242. {
  243. printf("0x%x ", t_passageway.m_actual_warning_code[i]);
  244. }
  245. std::cout << std::endl;
  246. std::cout << " huli test :::: " << " m_actual_error_description = " << t_passageway.m_actual_error_description << std::endl;
  247. std::cout << " huli test :::: " << " *********************************************** = " << std::endl;
  248. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  249. }
  250. */
  251. while (1)
  252. {
  253. }
  254. char ch123 ;
  255. std::cin >> ch123 ;
  256. Dispatch_communication::get_instance_references().communication_uninit();
  257. return 0;
  258. int t_dispatch_id = 0;
  259. // std::cin >> t_dispatch_id ;
  260. if ( argc == 2 )
  261. {
  262. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  263. t_dispatch_id = atoi(argv[1]);
  264. }
  265. std::cout << " huli test :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
  266. Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
  267. std::cout << "Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  268. System_executor::get_instance_references().system_executor_init(8);
  269. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  270. System_communication::get_instance_references().communication_init();
  271. char ch ;
  272. std::cin >> ch ;
  273. System_communication::get_instance_references().communication_uninit();
  274. System_executor::get_instance_references().system_executor_uninit();
  275. Dispatch_manager::get_instance_references().dispatch_manager_uninit();
  276. return 0;
  277. }