main.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. //
  2. //
  3. // 20210425, hl_dispatch 和 hl_dispatch_B的版本进行同步, 此时调度管理的功能全部完成.后续可能还需要日志记录.
  4. //
  5. //test 2022 10 26
  6. //huli 20230202
  7. //huli 20240205
  8. #include <iostream>
  9. #include "./error_code/error_code.h"
  10. //#include "LogFiles.h"
  11. #include <glog/logging.h>
  12. #include <string>
  13. #include <iostream>
  14. //#include "./communication/communication_socket_base.h"
  15. #include "./tool/thread_pool.h"
  16. #include "./system/system_communication.h"
  17. #include "./system/system_executor.h"
  18. #include "./rabbitmq/rabbitmq_base.h"
  19. #include "./dispatch/dispatch_manager.h"
  20. #include "./dispatch/dispatch_communication.h"
  21. #include "./dispatch/dispatch_coordinates.h"
  22. #include "./dispatch/database_controller.h"
  23. #include "./tool/common_data.h"
  24. #include "./tool/time_tool.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. void sql_test()
  53. {
  54. for (int i = 1; i <= CAR_WHEEL_BASE_LEVEL_MAX; ++i)
  55. {
  56. float t_wheel_base = i*0.05+2.45;
  57. //执行sql操作
  58. char update_record_sql[DB_SQL_SIZE];
  59. memset(update_record_sql, 0, DB_SQL_SIZE);
  60. sprintf(update_record_sql, "update space set wheel_base_level = %d where ( wheel_base < %f + 0.001 and wheel_base > %f - 0.001 ) ",
  61. i, t_wheel_base, t_wheel_base
  62. );
  63. LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
  64. Database_controller::get_instance_pointer()->sql_update(update_record_sql);
  65. }
  66. }
  67. #include <vector>
  68. bool myfunction (int i,int j) { return (i<j); }
  69. int main(int argc,char* argv[])
  70. {
  71. //
  72. // for (auto iter = aaa.begin(); iter != aaa.end(); ++iter)
  73. // {
  74. // std::cout << " huli test :::: " << " iter.first = " << iter->first << std::endl;
  75. // std::cout << " huli test :::: " << " iter.second = " << iter->second << std::endl;
  76. // std::cout << " huli test :::: " << " ............. = " << 0 << std::endl;
  77. // }
  78. //
  79. // std::sort(aaa.begin(), aaa.end(), myfunction);
  80. // for (auto iter = aaa.begin(); iter != aaa.end(); ++iter)
  81. // {
  82. // std::cout << " huli test :::: " << " iter.first = " << iter->first << std::endl;
  83. // std::cout << " huli test :::: " << " iter.second = " << iter->second << std::endl;
  84. // std::cout << " huli test :::: " << " ............. = " << 0 << std::endl;
  85. // }
  86. // return 0;
  87. // std::string t = SETTING_PATH RABBITMQ_PARAMETER_PATH_A;
  88. // std::cout << " huli test :::: " << " t = " << t << std::endl;
  89. // float asd = 2.95;
  90. // int qwe = Common_data::judge_wheel_base_level_new(2.95);
  91. //std::cout << " huli test :::: " << " qwe = " << qwe << std::endl;
  92. // return 0;
  93. Error_manager t_error;
  94. int t_dispatch_id = 11;
  95. // std::cin >> t_dispatch_id ;
  96. if ( argc == 2 )
  97. {
  98. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  99. t_dispatch_id = atoi(argv[1]);
  100. }
  101. //日志保存文件路径
  102. const char* logPath = "./";
  103. google::InitGoogleLogging("LidarMeasurement");
  104. google::SetStderrLogging(google::INFO);
  105. // google::SetLogDestination(0, logPath);
  106. google::SetLogDestination(google::LogSeverity::GLOG_INFO, logPath);
  107. char t_log[256] = {0};
  108. sprintf(t_log, "sgj%d.log", t_dispatch_id);
  109. google::SetLogFilenameExtension(t_log);
  110. google::InstallFailureSignalHandler();
  111. google::InstallFailureWriter(&shut_down_logging);
  112. FLAGS_colorlogtostderr = true; // Set log color
  113. FLAGS_logbufsecs = 0; // Set log output speed(s)
  114. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  115. FLAGS_stop_logging_if_full_disk = true;
  116. //#define MAIN_TEST 1
  117. #ifdef MAIN_TEST
  118. #endif
  119. LOG(INFO) << " ******************************************************************************************************************* " ;
  120. LOG(INFO) << "*********************************************dispatch run " << " t_dispatch_id = " << t_dispatch_id ;
  121. LOG(INFO) << "*********************************************dispatch run " << " start time = " << Time_tool::get_instance_references().get_current_time_millisecond() ;
  122. LOG(INFO) << " ******************************************************************************************************************* ";
  123. std::cout << "dispatch :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
  124. Database_controller::get_instance_references().database_controller_init();
  125. std::cout << "++++++++++++++++++++ Database_controller = " << Database_controller::get_instance_references().get_database_controller_status() << std::endl;
  126. // sql_test();
  127. // return 0;
  128. Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
  129. std::cout << "++++++++++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  130. Dispatch_communication::get_instance_references().communication_init(t_dispatch_id);
  131. std::cout << "+++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  132. System_executor::get_instance_references().system_executor_init(8);
  133. std::cout << "++++++++++++++++System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  134. t_error = System_communication::get_instance_references().communication_init(t_dispatch_id);
  135. std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
  136. System_communication::get_instance_references().set_encapsulate_status_cycle_time(100);
  137. t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
  138. std::cout << "++++++++++++++++++huli test network_init:::: " << " t_error = " << t_error << std::endl;
  139. LOG(INFO) << " t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);----------------------------- ";
  140. // std::this_thread::sleep_for(std::chrono::seconds(10));
  141. // Dispatch_manager::get_instance_references().m_dispatch_plc.set_carry_board(147, 1);
  142. // Led_protocol l;
  143. // l.led_protocol_init();
  144. //
  145. // while (1)
  146. // {
  147. // std::this_thread::sleep_for(std::chrono::seconds(1));
  148. // l.create_led_message(1, Time_tool::get_instance_references().get_current_time_seconds(), 0, 0, 256, 16);
  149. // l.create_led_message(2, Time_tool::get_instance_references().get_current_time_seconds(), 0, 16, 256, 16);
  150. // Dispatch_network::get_instance_references().encapsulate_msg( l.get_led_msg_total_string() , 1 );
  151. // }
  152. std::this_thread::sleep_for(std::chrono::seconds(10));
  153. Dispatch_manager::get_instance_references().m_dispatch_plc.reset_all_carry_board();
  154. // Dispatch_manager::get_instance_references().m_dispatch_plc.set_carry_board(132, 1);
  155. std::this_thread::sleep_for(std::chrono::seconds(1));
  156. Dispatch_manager::get_instance_references().m_dispatch_plc.init_all_carry_board();
  157. #ifdef CHUTIAN_PROJECT_PROJECT
  158. t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
  159. std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
  160. #endif //CHUTIAN_PROJECT_PROJECT
  161. while ( 1 )
  162. {
  163. // char ccc;
  164. // getchar();
  165. // LOG(INFO) << " 3333333333333333333333333333333 = " << 3333;
  166. // Dispatch_manager::get_instance_references().m_dispatch_plc.ttt = std::chrono::system_clock::now();
  167. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  168. }
  169. /*
  170. //led test
  171. std::string result;
  172. Led_protocol led_protocol;
  173. t_error = led_protocol.led_protocol_init();
  174. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  175. // std::string t_show_string_utf8_0 = "\\C7楚天车库\\n\\C2停车入口6\\n\\C3暂停服务";
  176. std::string t_show_string_utf8_0 = "1122cba0123456";
  177. std::string t_show_string_gbk_0 = String_convert::utf8_to_gbk(t_show_string_utf8_0);
  178. //方法1, 直接创建, 只需要设置显示内容和矩形框
  179. result = led_protocol.create_led_message(0, t_show_string_gbk_0, 0, 0, 79, 59);
  180. // std::string t_show_string_utf8_1 = "";
  181. // std::string t_show_string_gbk_1 = String_convert::utf8_to_gbk(t_show_string_utf8_1);
  182. // //方法1, 直接创建, 只需要设置显示内容和矩形框
  183. // result = led_protocol.create_led_message(1, t_show_string_gbk_1, 79, 59, 1, 1);
  184. //方法2, 自定义配置,
  185. // led_protocol.set_show_string(0, t_show_string2);
  186. // led_protocol.set_show_rectangle(0, 0, 0, 79, 59);
  187. // led_protocol.set_line_mode(0, 2, 1);
  188. // result = led_protocol.get_led_msg_total_string();
  189. //打印
  190. unsigned char * ch = (unsigned char * )result.c_str();
  191. printf("Led_communication_msg string = \n");
  192. for (int i = 0; i < result.length(); ++i)
  193. {
  194. printf("%02x", *(ch+i));
  195. }
  196. printf("\n");
  197. for (int i = 0; i < result.length(); ++i)
  198. {
  199. printf("%02x ", *(ch+i));
  200. }
  201. printf("\n");
  202. for (int i = 0; i < result.length(); ++i)
  203. {
  204. printf("\\x%02x", *(ch+i));
  205. }
  206. printf("\n");
  207. printf("result.size() = %d\n", result.size());
  208. while ( 1 )
  209. {
  210. std::this_thread::sleep_for(std::chrono::seconds(1));
  211. }
  212. */
  213. char ch ;
  214. std::cin >> ch ;
  215. System_communication::get_instance_references().rabbitmq_uninit();
  216. System_executor::get_instance_references().system_executor_uninit();
  217. Dispatch_communication::get_instance_references().communication_uninit();
  218. Dispatch_manager::get_instance_references().dispatch_manager_uninit();
  219. return 0;
  220. }