main.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. //
  2. //
  3. // 20210425, hl_dispatch 和 hl_dispatch_B的版本进行同步, 此时调度管理的功能全部完成.后续可能还需要日志记录.
  4. //
  5. //test 2022 10 26
  6. //huli 20230202
  7. //20240112, huli create dispatch_gy
  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. void sql_test2()
  68. {
  69. {
  70. float t_width = 1.800;
  71. int t_width_level = 1;
  72. //执行sql操作
  73. char update_record_sql[DB_SQL_SIZE];
  74. memset(update_record_sql, 0, DB_SQL_SIZE);
  75. sprintf(update_record_sql, "update space set width_level = %d, width = %f where ((room_id=1 or room_id=2 or room_id=3 or room_id=7 or room_id=8 or room_id=9) and unit = 21)",
  76. t_width_level, t_width
  77. );
  78. LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
  79. Database_controller::get_instance_pointer()->sql_update(update_record_sql);
  80. }
  81. {
  82. float t_width = 1.950;
  83. int t_width_level = 2;
  84. //执行sql操作
  85. char update_record_sql[DB_SQL_SIZE];
  86. memset(update_record_sql, 0, DB_SQL_SIZE);
  87. sprintf(update_record_sql, "update space set width_level = %d, width = %f where ((room_id=4 or room_id=5 or room_id=6 or room_id=10 or room_id=11 or room_id=12) and unit = 21)",
  88. t_width_level, t_width
  89. );
  90. LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
  91. Database_controller::get_instance_pointer()->sql_update(update_record_sql);
  92. }
  93. {
  94. float t_width = 1.950;
  95. int t_width_level = 2;
  96. //执行sql操作
  97. char update_record_sql[DB_SQL_SIZE];
  98. memset(update_record_sql, 0, DB_SQL_SIZE);
  99. sprintf(update_record_sql, "update space set width_level = %d, width = %f where ((room_id=1 or room_id=2 or room_id=3 or room_id=7 or room_id=8 or room_id=9) and unit = 11)",
  100. t_width_level, t_width
  101. );
  102. LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
  103. Database_controller::get_instance_pointer()->sql_update(update_record_sql);
  104. }
  105. {
  106. float t_width = 1.800;
  107. int t_width_level = 1;
  108. //执行sql操作
  109. char update_record_sql[DB_SQL_SIZE];
  110. memset(update_record_sql, 0, DB_SQL_SIZE);
  111. sprintf(update_record_sql, "update space set width_level = %d, width = %f where ((room_id=4 or room_id=5 or room_id=6 or room_id=10 or room_id=11 or room_id=12) and unit = 11)",
  112. t_width_level, t_width
  113. );
  114. LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
  115. Database_controller::get_instance_pointer()->sql_update(update_record_sql);
  116. }
  117. {
  118. float t_wheel_base = 3.100;
  119. int t_wheel_base_level = 13;
  120. //执行sql操作
  121. char update_record_sql[DB_SQL_SIZE];
  122. memset(update_record_sql, 0, DB_SQL_SIZE);
  123. sprintf(update_record_sql, "update space set wheel_base_level = %d, wheel_base = %f where (room_id=1 or room_id=2 or room_id=3 or room_id=4 or room_id=5 or room_id=6) ",
  124. t_wheel_base_level, t_wheel_base
  125. );
  126. LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
  127. Database_controller::get_instance_pointer()->sql_update(update_record_sql);
  128. }
  129. {
  130. float t_wheel_base = 3.200;
  131. int t_wheel_base_level = 15;
  132. //执行sql操作
  133. char update_record_sql[DB_SQL_SIZE];
  134. memset(update_record_sql, 0, DB_SQL_SIZE);
  135. sprintf(update_record_sql, "update space set wheel_base_level = %d, wheel_base = %f where (room_id=7 or room_id=8 or room_id=9 or room_id=10 or room_id=11 or room_id=12) ",
  136. t_wheel_base_level, t_wheel_base
  137. );
  138. LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
  139. Database_controller::get_instance_pointer()->sql_update(update_record_sql);
  140. }
  141. }
  142. #include <vector>
  143. bool myfunction (int i,int j) { return (i<j); }
  144. int main(int argc,char* argv[])
  145. {
  146. //
  147. // for (auto iter = aaa.begin(); iter != aaa.end(); ++iter)
  148. // {
  149. // std::cout << " huli test :::: " << " iter.first = " << iter->first << std::endl;
  150. // std::cout << " huli test :::: " << " iter.second = " << iter->second << std::endl;
  151. // std::cout << " huli test :::: " << " ............. = " << 0 << std::endl;
  152. // }
  153. //
  154. // std::sort(aaa.begin(), aaa.end(), myfunction);
  155. // for (auto iter = aaa.begin(); iter != aaa.end(); ++iter)
  156. // {
  157. // std::cout << " huli test :::: " << " iter.first = " << iter->first << std::endl;
  158. // std::cout << " huli test :::: " << " iter.second = " << iter->second << std::endl;
  159. // std::cout << " huli test :::: " << " ............. = " << 0 << std::endl;
  160. // }
  161. // return 0;
  162. // std::string t = SETTING_PATH RABBITMQ_PARAMETER_PATH_A;
  163. // std::cout << " huli test :::: " << " t = " << t << std::endl;
  164. // float asd = 2.95;
  165. // int qwe = Common_data::judge_wheel_base_level_new(2.95);
  166. //std::cout << " huli test :::: " << " qwe = " << qwe << std::endl;
  167. // return 0;
  168. Error_manager t_error;
  169. int t_dispatch_id = 31;
  170. // std::cin >> t_dispatch_id ;
  171. if ( argc == 2 )
  172. {
  173. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  174. t_dispatch_id = atoi(argv[1]);
  175. }
  176. //日志保存文件路径
  177. const char* logPath = "./";
  178. google::InitGoogleLogging("LidarMeasurement");
  179. google::SetStderrLogging(google::INFO);
  180. google::SetLogDestination(0, logPath);
  181. char t_log[256] = {0};
  182. sprintf(t_log, "sgj%d.log", t_dispatch_id);
  183. google::SetLogFilenameExtension(t_log);
  184. google::InstallFailureSignalHandler();
  185. google::InstallFailureWriter(&shut_down_logging);
  186. FLAGS_colorlogtostderr = true; // Set log color
  187. FLAGS_logbufsecs = 0; // Set log output speed(s)
  188. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  189. FLAGS_stop_logging_if_full_disk = true;
  190. //#define MAIN_TEST 1
  191. #ifdef MAIN_TEST
  192. #endif
  193. LOG(INFO) << " ******************************************************************************************************************* " ;
  194. LOG(INFO) << "*********************************************dispatch run " << " t_dispatch_id = " << t_dispatch_id ;
  195. LOG(INFO) << "*********************************************dispatch run " << " start time = " << Time_tool::get_instance_references().get_current_time_millisecond() ;
  196. LOG(INFO) << " ******************************************************************************************************************* ";
  197. std::cout << "dispatch :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
  198. Database_controller::get_instance_references().database_controller_init();
  199. std::cout << "++++++++++++++++++++ Database_controller = " << Database_controller::get_instance_references().get_database_controller_status() << std::endl;
  200. // sql_test();
  201. // sql_test2();
  202. // return 0;
  203. Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
  204. std::cout << "++++++++++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  205. Dispatch_communication::get_instance_references().communication_init(t_dispatch_id);
  206. std::cout << "+++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  207. System_executor::get_instance_references().system_executor_init(8);
  208. std::cout << "++++++++++++++++System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  209. t_error = System_communication::get_instance_references().communication_init(t_dispatch_id);
  210. std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
  211. System_communication::get_instance_references().set_encapsulate_status_cycle_time(100);
  212. t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
  213. std::cout << "++++++++++++++++++huli test network_init:::: " << " t_error = " << t_error << std::endl;
  214. LOG(INFO) << " t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);----------------------------- ";
  215. // Led_protocol l;
  216. // l.led_protocol_init();
  217. //
  218. // while (1)
  219. // {
  220. // std::this_thread::sleep_for(std::chrono::seconds(1));
  221. // l.create_led_message(1, Time_tool::get_instance_references().get_current_time_seconds(), 0, 0, 256, 16);
  222. // l.create_led_message(2, Time_tool::get_instance_references().get_current_time_seconds(), 0, 16, 256, 16);
  223. // Dispatch_network::get_instance_references().encapsulate_msg( l.get_led_msg_total_string() , 1 );
  224. // }
  225. #ifdef CHUTIAN_PROJECT_PROJECT
  226. t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
  227. std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
  228. #endif //CHUTIAN_PROJECT_PROJECT
  229. while ( 1 )
  230. {
  231. std::this_thread::sleep_for(std::chrono::seconds(1));
  232. }
  233. /*
  234. //led test
  235. std::string result;
  236. Led_protocol led_protocol;
  237. t_error = led_protocol.led_protocol_init();
  238. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  239. // std::string t_show_string_utf8_0 = "\\C7楚天车库\\n\\C2停车入口6\\n\\C3暂停服务";
  240. std::string t_show_string_utf8_0 = "1122cba0123456";
  241. std::string t_show_string_gbk_0 = String_convert::utf8_to_gbk(t_show_string_utf8_0);
  242. //方法1, 直接创建, 只需要设置显示内容和矩形框
  243. result = led_protocol.create_led_message(0, t_show_string_gbk_0, 0, 0, 79, 59);
  244. // std::string t_show_string_utf8_1 = "";
  245. // std::string t_show_string_gbk_1 = String_convert::utf8_to_gbk(t_show_string_utf8_1);
  246. // //方法1, 直接创建, 只需要设置显示内容和矩形框
  247. // result = led_protocol.create_led_message(1, t_show_string_gbk_1, 79, 59, 1, 1);
  248. //方法2, 自定义配置,
  249. // led_protocol.set_show_string(0, t_show_string2);
  250. // led_protocol.set_show_rectangle(0, 0, 0, 79, 59);
  251. // led_protocol.set_line_mode(0, 2, 1);
  252. // result = led_protocol.get_led_msg_total_string();
  253. //打印
  254. unsigned char * ch = (unsigned char * )result.c_str();
  255. printf("Led_communication_msg string = \n");
  256. for (int i = 0; i < result.length(); ++i)
  257. {
  258. printf("%02x", *(ch+i));
  259. }
  260. printf("\n");
  261. for (int i = 0; i < result.length(); ++i)
  262. {
  263. printf("%02x ", *(ch+i));
  264. }
  265. printf("\n");
  266. for (int i = 0; i < result.length(); ++i)
  267. {
  268. printf("\\x%02x", *(ch+i));
  269. }
  270. printf("\n");
  271. printf("result.size() = %d\n", result.size());
  272. while ( 1 )
  273. {
  274. std::this_thread::sleep_for(std::chrono::seconds(1));
  275. }
  276. */
  277. char ch ;
  278. std::cin >> ch ;
  279. System_communication::get_instance_references().rabbitmq_uninit();
  280. System_executor::get_instance_references().system_executor_uninit();
  281. Dispatch_communication::get_instance_references().communication_uninit();
  282. Dispatch_manager::get_instance_references().dispatch_manager_uninit();
  283. return 0;
  284. }