main.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. int main(int argc,char* argv[])
  40. {
  41. int t_id = 2;
  42. if ( argc == 2 )
  43. {
  44. t_id = stoi(argv[1]);
  45. }
  46. Error_manager t_error;
  47. const char* logPath = "./";
  48. google::InitGoogleLogging("LidarMeasurement");
  49. google::SetStderrLogging(google::INFO);
  50. google::SetLogDestination(0, logPath);
  51. google::SetLogFilenameExtension("zxlog");
  52. google::InstallFailureSignalHandler();
  53. google::InstallFailureWriter(&shut_down_logging);
  54. FLAGS_colorlogtostderr = true; // Set log color
  55. FLAGS_logbufsecs = 0; // Set log output speed(s)
  56. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  57. FLAGS_stop_logging_if_full_disk = true;
  58. //#define MAIN_TEST 1
  59. #ifdef MAIN_TEST
  60. // t_error = Dispatch_coordinates::get_instance_references().dispatch_coordinates_init();
  61. // std::cout << " huli test :::: " << " Dispatch_coordinates::get_instance_references().dispatch_coordinates_init() = " << t_error.to_string() << std::endl;
  62. t_error = Dispatch_communication::get_instance_references().communication_init(t_id);
  63. std::cout << " huli test :::: " << " Dispatch_communication::get_instance_references().communication_init() = " << t_error.to_string() << std::endl;
  64. std::cout << "Dispatch_communication = " << Dispatch_communication::get_instance_references().get_status() << std::endl;
  65. Dispatch_communication::Dispatch_request_from_manager_to_plc_for_data a;
  66. Dispatch_communication::Dispatch_request_from_manager_to_plc_for_key b;
  67. Dispatch_communication::Dispatch_response_from_plc_to_manager c;
  68. std::cout << " huli test :::: " << " sizeof(a) = " << sizeof(a) << std::endl;
  69. std::cout << " huli test :::: " << " sizeof(b) = " << sizeof(b) << std::endl;
  70. std::cout << " huli test :::: " << " sizeof(c) = " << sizeof(c) << std::endl;
  71. int aa = Dispatch_communication::get_instance_references().m_send_buf_map[0].m_size;
  72. int bb = Dispatch_communication::get_instance_references().m_send_buf_map[1].m_size;
  73. int cc = Dispatch_communication::get_instance_references().m_receive_buf_map[0].m_size;
  74. std::cout << " huli test :::: " << " aa = " << aa << std::endl;
  75. std::cout << " huli test :::: " << " bb = " << bb << std::endl;
  76. std::cout << " huli test :::: " << " cc = " << cc << std::endl;
  77. t_error = Dispatch_manager::get_instance_references().dispatch_manager_init(t_id);
  78. std::cout << " huli test :::: " << " Dispatch_manager::get_instance_references().dispatch_manager_init(0) = " << t_error.to_string() << std::endl;
  79. std::cout << "Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  80. System_executor::get_instance_references().system_executor_init(10);
  81. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  82. System_communication::get_instance_references().communication_init();
  83. System_communication::get_instance_references().set_encapsulate_cycle_time(1000);
  84. //20210922
  85. while (1)
  86. {
  87. std::string test_string;
  88. std::cin >> test_string ;
  89. if ( test_string == "9" )
  90. {
  91. message::Dispatch_request_msg dispatch_request_msg;
  92. dispatch_request_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_request_msg);
  93. dispatch_request_msg.mutable_base_info()->set_timeout_ms(5000000);
  94. dispatch_request_msg.mutable_base_info()->set_sender(message::Communicator::eMain);
  95. dispatch_request_msg.mutable_base_info()->set_receiver(message::Communicator::eDispatch_manager);
  96. dispatch_request_msg.set_command_key("12345678901234567890123456789012");
  97. dispatch_request_msg.set_dispatch_motion_direction(message::Dispatch_motion_direction::E_STORE_CAR);
  98. dispatch_request_msg.mutable_id_struct()->set_terminal_id(4);
  99. dispatch_request_msg.mutable_id_struct()->set_unit_id(2);
  100. message::Locate_information t_locate_information;
  101. t_locate_information.set_locate_x(-1.901);
  102. t_locate_information.set_locate_y(-5.829);
  103. t_locate_information.set_locate_angle(2);
  104. t_locate_information.set_locate_length(4.78);
  105. t_locate_information.set_locate_width(1.88);
  106. t_locate_information.set_locate_height(1.65);
  107. t_locate_information.set_locate_wheel_base(2.78);
  108. t_locate_information.set_locate_wheel_width(1.88);
  109. t_locate_information.set_locate_front_theta(0);
  110. t_locate_information.set_uniformed_car_x(0);
  111. t_locate_information.set_uniformed_car_y(0);
  112. t_locate_information.set_locate_correct(true);
  113. dispatch_request_msg.mutable_locate_information()->CopyFrom(t_locate_information);
  114. message::Parkspace_info *tp_parkspace_info = dispatch_request_msg.mutable_parkspace_info_ex()->Add();
  115. tp_parkspace_info->set_parkingspace_index_id(167);
  116. tp_parkspace_info->set_parkingspace_type(message::Parkspace_type::MID_PARKINGSPACE);
  117. tp_parkspace_info->set_parkingspace_unit_id(3);
  118. tp_parkspace_info->set_parkingspace_label_id(11);
  119. tp_parkspace_info->set_parkingspace_room_id(5);
  120. tp_parkspace_info->set_parkingspace_direction(message::Direction::eBackward);
  121. tp_parkspace_info->set_parkingspace_floor_id(3);
  122. tp_parkspace_info->set_parkingspace_width(0);
  123. tp_parkspace_info->set_parkingspace_height(0);
  124. tp_parkspace_info->set_parkingspace_status(message::Parkspace_status::eParkspace_empty);
  125. tp_parkspace_info->set_car_type(message::Car_type::MID_CAR);
  126. dispatch_request_msg.set_car_type(message::Car_type::MID_CAR);
  127. Dispatch_manager::get_instance_references().execute_for_dispatch_request_msg(dispatch_request_msg);
  128. }
  129. std::this_thread::sleep_for(std::chrono::seconds(1));
  130. }
  131. return 0;
  132. #endif
  133. while (1)
  134. {
  135. }
  136. char ch123 ;
  137. std::cin >> ch123 ;
  138. Dispatch_communication::get_instance_references().communication_uninit();
  139. return 0;
  140. int t_dispatch_id = 0;
  141. // std::cin >> t_dispatch_id ;
  142. if ( argc == 2 )
  143. {
  144. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  145. t_dispatch_id = atoi(argv[1]);
  146. }
  147. std::cout << " huli test :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
  148. Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
  149. std::cout << "Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  150. System_executor::get_instance_references().system_executor_init(8);
  151. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  152. System_communication::get_instance_references().communication_init();
  153. char ch ;
  154. std::cin >> ch ;
  155. System_communication::get_instance_references().communication_uninit();
  156. System_executor::get_instance_references().system_executor_uninit();
  157. Dispatch_manager::get_instance_references().dispatch_manager_uninit();
  158. return 0;
  159. }