main.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. //
  3. // 20210425, hl_dispatch 和 hl_dispatch_B的版本进行同步, 此时调度管理的功能全部完成.后续可能还需要日志记录.
  4. //
  5. //test 2022 10 26
  6. #include <iostream>
  7. #include "./error_code/error_code.h"
  8. //#include "LogFiles.h"
  9. #include <glog/logging.h>
  10. #include <string>
  11. #include <iostream>
  12. #include "./communication/communication_socket_base.h"
  13. #include "./tool/thread_pool.h"
  14. #include "./system/system_communication.h"
  15. #include "./system/system_executor.h"
  16. #include "./rabbitmq/rabbitmq_base.h"
  17. #include "./dispatch/dispatch_manager.h"
  18. #include "./dispatch/dispatch_communication.h"
  19. #include "./dispatch/dispatch_coordinates.h"
  20. #include "./dispatch/database_controller.h"
  21. #include "./tool/common_data.h"
  22. #include "./tool/time_tool.h"
  23. #include "./rabbitmq/ttt.h"
  24. #include <algorithm> // std::for_each
  25. #include <google/protobuf/text_format.h>
  26. //#include <iostream>
  27. //#include <mysqlx/xdevapi.h>
  28. //
  29. //using namespace mysqlx;
  30. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  31. {
  32. time_t tt;
  33. time( &tt );
  34. tt = tt + 8*3600; // transform the time zone
  35. tm* t= gmtime( &tt );
  36. char buf[255]={0};
  37. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  38. t->tm_year + 1900,
  39. t->tm_mon + 1,
  40. t->tm_mday,
  41. t->tm_hour,
  42. t->tm_min,
  43. t->tm_sec);
  44. FILE* tp_file=fopen(buf,"w");
  45. fprintf(tp_file,data,strlen(data));
  46. fclose(tp_file);
  47. }
  48. #include "./network_communication/network_base.h"
  49. #include "./dispatch/dispatch_network.h"
  50. int main(int argc,char* argv[])
  51. {
  52. // Error_manager e = Dispatch_network::get_instance_references().network_init(1);
  53. // std::cout << " huli test :::: " << " e = " << e << std::endl;
  54. //
  55. // while ( 1 )
  56. // {
  57. //
  58. // }
  59. //
  60. //
  61. // return 0;
  62. Error_manager t_error;
  63. const char* logPath = "./";
  64. google::InitGoogleLogging("LidarMeasurement");
  65. google::SetStderrLogging(google::INFO);
  66. google::SetLogDestination(0, logPath);
  67. google::SetLogFilenameExtension("zxlog");
  68. google::InstallFailureSignalHandler();
  69. google::InstallFailureWriter(&shut_down_logging);
  70. FLAGS_colorlogtostderr = true; // Set log color
  71. FLAGS_logbufsecs = 0; // Set log output speed(s)
  72. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  73. FLAGS_stop_logging_if_full_disk = true;
  74. //#define MAIN_TEST 1
  75. #ifdef MAIN_TEST
  76. int t_id = 0;
  77. if ( argc == 2 )
  78. {
  79. t_id = stoi(argv[1]);
  80. }
  81. // t_error = Dispatch_coordinates::get_instance_references().dispatch_coordinates_init();
  82. // std::cout << " huli test :::: " << " Dispatch_coordinates::get_instance_references().dispatch_coordinates_init() = " << t_error.to_string() << std::endl;
  83. t_error = Dispatch_communication::get_instance_references().communication_init(t_id);
  84. std::cout << " huli test :::: " << " Dispatch_communication::get_instance_references().communication_init() = " << t_error.to_string() << std::endl;
  85. std::cout << "Dispatch_communication = " << Dispatch_communication::get_instance_references().get_status() << std::endl;
  86. t_error = Dispatch_manager::get_instance_references().dispatch_manager_init(t_id);
  87. std::cout << " huli test :::: " << " Dispatch_manager::get_instance_references().dispatch_manager_init(0) = " << t_error.to_string() << std::endl;
  88. std::cout << "Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  89. System_executor::get_instance_references().system_executor_init(10);
  90. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  91. if ( argc == 2 )
  92. {
  93. System_communication::get_instance_references().communication_init(t_id);
  94. }
  95. else
  96. {
  97. System_communication::get_instance_references().communication_init();
  98. }
  99. System_communication::get_instance_references().set_encapsulate_cycle_time(1000);
  100. //20210922
  101. while (1)
  102. {
  103. std::string test_string;
  104. std::cin >> test_string ;
  105. if ( test_string == "9" )
  106. {
  107. message::Dispatch_request_msg dispatch_request_msg;
  108. dispatch_request_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_request_msg);
  109. dispatch_request_msg.mutable_base_info()->set_timeout_ms(5000000);
  110. dispatch_request_msg.mutable_base_info()->set_sender(message::Communicator::eMain);
  111. dispatch_request_msg.mutable_base_info()->set_receiver(message::Communicator::eDispatch_manager);
  112. dispatch_request_msg.set_command_key("12345678901234567890123456789012");
  113. dispatch_request_msg.set_dispatch_motion_direction(message::Dispatch_motion_direction::E_STORE_CAR);
  114. dispatch_request_msg.mutable_id_struct()->set_terminal_id(4);
  115. dispatch_request_msg.mutable_id_struct()->set_unit_id(2);
  116. message::Locate_information t_locate_information;
  117. t_locate_information.set_locate_x(-1.901);
  118. t_locate_information.set_locate_y(-5.829);
  119. t_locate_information.set_locate_angle(2);
  120. t_locate_information.set_locate_length(4.78);
  121. t_locate_information.set_locate_width(1.88);
  122. t_locate_information.set_locate_height(1.65);
  123. t_locate_information.set_locate_wheel_base(2.78);
  124. t_locate_information.set_locate_wheel_width(1.88);
  125. t_locate_information.set_locate_front_theta(0);
  126. t_locate_information.set_uniformed_car_x(0);
  127. t_locate_information.set_uniformed_car_y(0);
  128. t_locate_information.set_locate_correct(true);
  129. dispatch_request_msg.mutable_locate_information()->CopyFrom(t_locate_information);
  130. message::Parkspace_info *tp_parkspace_info = dispatch_request_msg.mutable_parkspace_info_ex()->Add();
  131. tp_parkspace_info->set_parkingspace_index_id(167);
  132. tp_parkspace_info->set_parkingspace_type(message::Parkspace_type::MID_PARKINGSPACE);
  133. tp_parkspace_info->set_parkingspace_unit_id(3);
  134. tp_parkspace_info->set_parkingspace_label_id(11);
  135. tp_parkspace_info->set_parkingspace_room_id(5);
  136. tp_parkspace_info->set_parkingspace_direction(message::Direction::eBackward);
  137. tp_parkspace_info->set_parkingspace_floor_id(3);
  138. tp_parkspace_info->set_parkingspace_width(0);
  139. tp_parkspace_info->set_parkingspace_height(0);
  140. tp_parkspace_info->set_parkingspace_status(message::Parkspace_status::eParkspace_empty);
  141. tp_parkspace_info->set_car_type(message::Car_type::MID_CAR);
  142. dispatch_request_msg.set_car_type(message::Car_type::MID_CAR);
  143. Dispatch_manager::get_instance_references().execute_for_dispatch_request_msg(dispatch_request_msg);
  144. }
  145. std::this_thread::sleep_for(std::chrono::seconds(1));
  146. }
  147. return 0;
  148. #endif
  149. int t_dispatch_id = 1;
  150. // std::cin >> t_dispatch_id ;
  151. if ( argc == 2 )
  152. {
  153. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  154. t_dispatch_id = atoi(argv[1]);
  155. }
  156. std::cout << "+++++++++++++huli test :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
  157. Database_controller::get_instance_references().database_controller_init();
  158. std::cout << "++++++++++++++++++++ Database_controller = " << Database_controller::get_instance_references().get_database_controller_status() << std::endl;
  159. Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
  160. std::cout << "++++++++++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  161. Dispatch_communication::get_instance_references().communication_init(t_dispatch_id);
  162. std::cout << "+++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  163. System_executor::get_instance_references().system_executor_init(8);
  164. std::cout << "++++++++++++++++System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  165. t_error = System_communication::get_instance_references().communication_init(t_dispatch_id);
  166. std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
  167. t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
  168. std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
  169. while ( 1 )
  170. {
  171. std::this_thread::sleep_for(std::chrono::seconds(1));
  172. }
  173. char ch ;
  174. std::cin >> ch ;
  175. System_communication::get_instance_references().rabbitmq_uninit();
  176. System_executor::get_instance_references().system_executor_uninit();
  177. Dispatch_communication::get_instance_references().communication_uninit();
  178. Dispatch_manager::get_instance_references().dispatch_manager_uninit();
  179. return 0;
  180. }