main.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. //
  2. //
  3. // 20210425, hl_dispatch 和 hl_dispatch_B的版本进行同步, 此时调度管理的功能全部完成.后续可能还需要日志记录.
  4. //
  5. //test 2022 10 26
  6. //huli 20230202
  7. #include <iostream>
  8. #include "./error_code/error_code.h"
  9. //#include "LogFiles.h"
  10. #include <glog/logging.h>
  11. #include <string>
  12. #include <iostream>
  13. //#include "./communication/communication_socket_base.h"
  14. #include "./tool/thread_pool.h"
  15. #include "./system/system_communication.h"
  16. #include "./system/system_executor.h"
  17. #include "./rabbitmq/rabbitmq_base.h"
  18. #include "./dispatch/dispatch_manager.h"
  19. #include "./dispatch/dispatch_communication.h"
  20. #include "./dispatch/dispatch_coordinates.h"
  21. #include "./dispatch/database_controller.h"
  22. #include "./tool/common_data.h"
  23. #include "./tool/time_tool.h"
  24. #include "./tool/mysql_statistics.h"
  25. #include "./rabbitmq/ttt.h"
  26. #include <algorithm> // std::for_each
  27. #include <google/protobuf/text_format.h>
  28. //#include <iostream>
  29. //#include <mysqlx/xdevapi.h>
  30. //
  31. //using namespace mysqlx;
  32. void shut_down_logging(const char* data, size_t size)
  33. {
  34. time_t tt;
  35. time( &tt );
  36. tt = tt + 8*3600; // transform the time zone
  37. tm* t= gmtime( &tt );
  38. char buf[255]={0};
  39. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  40. t->tm_year + 1900,
  41. t->tm_mon + 1,
  42. t->tm_mday,
  43. t->tm_hour,
  44. t->tm_min,
  45. t->tm_sec);
  46. FILE* tp_file=fopen(buf,"w");
  47. fprintf(tp_file,data,strlen(data));
  48. fclose(tp_file);
  49. }
  50. #include "./network_communication/network_base.h"
  51. #include "./dispatch/dispatch_network.h"
  52. #include <vector>
  53. bool myfunction (int i,int j) { return (i<j); }
  54. int main(int argc,char* argv[])
  55. {
  56. //
  57. // for (auto iter = aaa.begin(); iter != aaa.end(); ++iter)
  58. // {
  59. // std::cout << " huli test :::: " << " iter.first = " << iter->first << std::endl;
  60. // std::cout << " huli test :::: " << " iter.second = " << iter->second << std::endl;
  61. // std::cout << " huli test :::: " << " ............. = " << 0 << std::endl;
  62. // }
  63. //
  64. // std::sort(aaa.begin(), aaa.end(), myfunction);
  65. // for (auto iter = aaa.begin(); iter != aaa.end(); ++iter)
  66. // {
  67. // std::cout << " huli test :::: " << " iter.first = " << iter->first << std::endl;
  68. // std::cout << " huli test :::: " << " iter.second = " << iter->second << std::endl;
  69. // std::cout << " huli test :::: " << " ............. = " << 0 << std::endl;
  70. // }
  71. // return 0;
  72. // std::string t = SETTING_PATH RABBITMQ_PARAMETER_PATH_A;
  73. // std::cout << " huli test :::: " << " t = " << t << std::endl;
  74. // float asd = 2.95;
  75. // int qwe = Common_data::judge_wheel_base_level_new(2.95);
  76. //std::cout << " huli test :::: " << " qwe = " << qwe << std::endl;
  77. // return 0;
  78. Error_manager t_error;
  79. int t_dispatch_id = 31;
  80. // std::cin >> t_dispatch_id ;
  81. if ( argc == 2 )
  82. {
  83. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  84. t_dispatch_id = atoi(argv[1]);
  85. }
  86. //日志保存文件路径
  87. const char* logPath = "./";
  88. google::InitGoogleLogging("LidarMeasurement");
  89. google::SetStderrLogging(google::INFO);
  90. google::SetLogDestination(0, logPath);
  91. char t_log[256] = {0};
  92. sprintf(t_log, "sgj%d.log", t_dispatch_id);
  93. google::SetLogFilenameExtension(t_log);
  94. google::InstallFailureSignalHandler();
  95. google::InstallFailureWriter(&shut_down_logging);
  96. FLAGS_colorlogtostderr = true; // Set log color
  97. FLAGS_logbufsecs = 0; // Set log output speed(s)
  98. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  99. FLAGS_stop_logging_if_full_disk = true;
  100. //#define MAIN_TEST 1
  101. #ifdef MAIN_TEST
  102. #endif
  103. LOG(INFO) << " ******************************************************************************************************************* " ;
  104. LOG(INFO) << "*********************************************dispatch run " << " t_dispatch_id = " << t_dispatch_id ;
  105. LOG(INFO) << "*********************************************dispatch run " << " start time = " << Time_tool::get_instance_references().get_current_time_millisecond() ;
  106. LOG(INFO) << " ******************************************************************************************************************* ";
  107. std::cout << "dispatch :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
  108. Database_controller::get_instance_references().database_controller_init();
  109. std::cout << "++++++++++++++++++++ Database_controller = " << Database_controller::get_instance_references().get_database_controller_status() << std::endl;
  110. // sql_test();
  111. // sql_ttt_3();
  112. // sql_ttt_4();
  113. // return 0;
  114. // mysql_collect_daily_data_all_unit(2023, 6, 1, 30);
  115. // mysql_collect_daily_data_all_unit(2023, 7, 1, 31);
  116. // mysql_collect_daily_data_all_unit(2023, 8, 1, 31);
  117. // mysql_collect_daily_data_all_unit(2023, 9, 1, 30);
  118. // mysql_collect_daily_data_all_unit(2023, 10, 1, 31);
  119. // mysql_collect_daily_data_all_unit(2023, 11, 1, 30);
  120. // mysql_collect_daily_data_all_unit(2023, 12, 1, 31);
  121. // mysql_collect_daily_data_all_unit(2024, 1, 1, 31);
  122. // mysql_collect_daily_data_all_unit(2024, 2, 1, 29);
  123. // mysql_collect_daily_data_all_unit(2024, 3, 1, 19);
  124. // return 0;
  125. Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
  126. std::cout << "++++++++++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  127. Dispatch_communication::get_instance_references().communication_init(t_dispatch_id);
  128. std::cout << "+++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  129. System_executor::get_instance_references().system_executor_init(8);
  130. std::cout << "++++++++++++++++System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  131. t_error = System_communication::get_instance_references().communication_init(t_dispatch_id);
  132. std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
  133. System_communication::get_instance_references().set_encapsulate_status_cycle_time(100);
  134. t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
  135. std::cout << "++++++++++++++++++huli test network_init:::: " << " t_error = " << t_error << std::endl;
  136. LOG(INFO) << " t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);----------------------------- ";
  137. // Led_protocol l;
  138. // l.led_protocol_init();
  139. //
  140. // while (1)
  141. // {
  142. // std::this_thread::sleep_for(std::chrono::seconds(1));
  143. // l.create_led_message(1, Time_tool::get_instance_references().get_current_time_seconds(), 0, 0, 256, 16);
  144. // l.create_led_message(2, Time_tool::get_instance_references().get_current_time_seconds(), 0, 16, 256, 16);
  145. // Dispatch_network::get_instance_references().encapsulate_msg( l.get_led_msg_total_string() , 1 );
  146. // }
  147. #ifdef CHUTIAN_PROJECT_PROJECT
  148. t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
  149. std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
  150. #endif //CHUTIAN_PROJECT_PROJECT
  151. while ( 1 )
  152. {
  153. std::this_thread::sleep_for(std::chrono::seconds(1));
  154. }
  155. /*
  156. //led test
  157. std::string result;
  158. Led_protocol led_protocol;
  159. t_error = led_protocol.led_protocol_init();
  160. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  161. // std::string t_show_string_utf8_0 = "\\C7楚天车库\\n\\C2停车入口6\\n\\C3暂停服务";
  162. std::string t_show_string_utf8_0 = "1122cba0123456";
  163. std::string t_show_string_gbk_0 = String_convert::utf8_to_gbk(t_show_string_utf8_0);
  164. //方法1, 直接创建, 只需要设置显示内容和矩形框
  165. result = led_protocol.create_led_message(0, t_show_string_gbk_0, 0, 0, 79, 59);
  166. // std::string t_show_string_utf8_1 = "";
  167. // std::string t_show_string_gbk_1 = String_convert::utf8_to_gbk(t_show_string_utf8_1);
  168. // //方法1, 直接创建, 只需要设置显示内容和矩形框
  169. // result = led_protocol.create_led_message(1, t_show_string_gbk_1, 79, 59, 1, 1);
  170. //方法2, 自定义配置,
  171. // led_protocol.set_show_string(0, t_show_string2);
  172. // led_protocol.set_show_rectangle(0, 0, 0, 79, 59);
  173. // led_protocol.set_line_mode(0, 2, 1);
  174. // result = led_protocol.get_led_msg_total_string();
  175. //打印
  176. unsigned char * ch = (unsigned char * )result.c_str();
  177. printf("Led_communication_msg string = \n");
  178. for (int i = 0; i < result.length(); ++i)
  179. {
  180. printf("%02x", *(ch+i));
  181. }
  182. printf("\n");
  183. for (int i = 0; i < result.length(); ++i)
  184. {
  185. printf("%02x ", *(ch+i));
  186. }
  187. printf("\n");
  188. for (int i = 0; i < result.length(); ++i)
  189. {
  190. printf("\\x%02x", *(ch+i));
  191. }
  192. printf("\n");
  193. printf("result.size() = %d\n", result.size());
  194. while ( 1 )
  195. {
  196. std::this_thread::sleep_for(std::chrono::seconds(1));
  197. }
  198. */
  199. char ch ;
  200. std::cin >> ch ;
  201. System_communication::get_instance_references().rabbitmq_uninit();
  202. System_executor::get_instance_references().system_executor_uninit();
  203. Dispatch_communication::get_instance_references().communication_uninit();
  204. Dispatch_manager::get_instance_references().dispatch_manager_uninit();
  205. return 0;
  206. }