123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- //
- //
- // 20210425, hl_dispatch 和 hl_dispatch_B的版本进行同步, 此时调度管理的功能全部完成.后续可能还需要日志记录.
- //
- //test 2022 10 26
- //huli 20230202
- //20240112, huli create dispatch_gy
- #include <iostream>
- #include "./error_code/error_code.h"
- //#include "LogFiles.h"
- #include <glog/logging.h>
- #include <string>
- #include <iostream>
- //#include "./communication/communication_socket_base.h"
- #include "./tool/thread_pool.h"
- #include "./system/system_communication.h"
- #include "./system/system_executor.h"
- #include "./rabbitmq/rabbitmq_base.h"
- #include "./dispatch/dispatch_manager.h"
- #include "./dispatch/dispatch_communication.h"
- #include "./dispatch/dispatch_coordinates.h"
- #include "./dispatch/database_controller.h"
- #include "./tool/common_data.h"
- #include "./tool/time_tool.h"
- #include "./rabbitmq/ttt.h"
- #include <algorithm> // std::for_each
- #include <google/protobuf/text_format.h>
- //#include <iostream>
- //#include <mysqlx/xdevapi.h>
- //
- //using namespace mysqlx;
- void shut_down_logging(const char* data, size_t size)
- {
- time_t tt;
- time( &tt );
- tt = tt + 8*3600; // transform the time zone
- tm* t= gmtime( &tt );
- char buf[255]={0};
- sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
- t->tm_year + 1900,
- t->tm_mon + 1,
- t->tm_mday,
- t->tm_hour,
- t->tm_min,
- t->tm_sec);
- FILE* tp_file=fopen(buf,"w");
- fprintf(tp_file,data,strlen(data));
- fclose(tp_file);
- }
- #include "./network_communication/network_base.h"
- #include "./dispatch/dispatch_network.h"
- void sql_test()
- {
- for (int i = 1; i <= CAR_WHEEL_BASE_LEVEL_MAX; ++i)
- {
- float t_wheel_base = i*0.05+2.45;
- //执行sql操作
- char update_record_sql[DB_SQL_SIZE];
- memset(update_record_sql, 0, DB_SQL_SIZE);
- sprintf(update_record_sql, "update space set wheel_base_level = %d where ( wheel_base < %f + 0.001 and wheel_base > %f - 0.001 ) ",
- i, t_wheel_base, t_wheel_base
- );
- LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
- Database_controller::get_instance_pointer()->sql_update(update_record_sql);
- }
- }
- void sql_test2()
- {
- {
- float t_width = 1.800;
- int t_width_level = 1;
- //执行sql操作
- char update_record_sql[DB_SQL_SIZE];
- memset(update_record_sql, 0, DB_SQL_SIZE);
- 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)",
- t_width_level, t_width
- );
- LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
- Database_controller::get_instance_pointer()->sql_update(update_record_sql);
- }
- {
- float t_width = 1.950;
- int t_width_level = 2;
- //执行sql操作
- char update_record_sql[DB_SQL_SIZE];
- memset(update_record_sql, 0, DB_SQL_SIZE);
- 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)",
- t_width_level, t_width
- );
- LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
- Database_controller::get_instance_pointer()->sql_update(update_record_sql);
- }
- {
- float t_width = 1.950;
- int t_width_level = 2;
- //执行sql操作
- char update_record_sql[DB_SQL_SIZE];
- memset(update_record_sql, 0, DB_SQL_SIZE);
- 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)",
- t_width_level, t_width
- );
- LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
- Database_controller::get_instance_pointer()->sql_update(update_record_sql);
- }
- {
- float t_width = 1.800;
- int t_width_level = 1;
- //执行sql操作
- char update_record_sql[DB_SQL_SIZE];
- memset(update_record_sql, 0, DB_SQL_SIZE);
- 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)",
- t_width_level, t_width
- );
- LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
- Database_controller::get_instance_pointer()->sql_update(update_record_sql);
- }
- {
- float t_wheel_base = 3.100;
- int t_wheel_base_level = 13;
- //执行sql操作
- char update_record_sql[DB_SQL_SIZE];
- memset(update_record_sql, 0, DB_SQL_SIZE);
- 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) ",
- t_wheel_base_level, t_wheel_base
- );
- LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
- Database_controller::get_instance_pointer()->sql_update(update_record_sql);
- }
- {
- float t_wheel_base = 3.200;
- int t_wheel_base_level = 15;
- //执行sql操作
- char update_record_sql[DB_SQL_SIZE];
- memset(update_record_sql, 0, DB_SQL_SIZE);
- 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) ",
- t_wheel_base_level, t_wheel_base
- );
- LOG(INFO) << " update_record_sql = "<< update_record_sql << " --- " ;
- Database_controller::get_instance_pointer()->sql_update(update_record_sql);
- }
- }
- #include <vector>
- bool myfunction (int i,int j) { return (i<j); }
- int main(int argc,char* argv[])
- {
- //
- // for (auto iter = aaa.begin(); iter != aaa.end(); ++iter)
- // {
- // std::cout << " huli test :::: " << " iter.first = " << iter->first << std::endl;
- // std::cout << " huli test :::: " << " iter.second = " << iter->second << std::endl;
- // std::cout << " huli test :::: " << " ............. = " << 0 << std::endl;
- // }
- //
- // std::sort(aaa.begin(), aaa.end(), myfunction);
- // for (auto iter = aaa.begin(); iter != aaa.end(); ++iter)
- // {
- // std::cout << " huli test :::: " << " iter.first = " << iter->first << std::endl;
- // std::cout << " huli test :::: " << " iter.second = " << iter->second << std::endl;
- // std::cout << " huli test :::: " << " ............. = " << 0 << std::endl;
- // }
- // return 0;
- // std::string t = SETTING_PATH RABBITMQ_PARAMETER_PATH_A;
- // std::cout << " huli test :::: " << " t = " << t << std::endl;
- // float asd = 2.95;
- // int qwe = Common_data::judge_wheel_base_level_new(2.95);
- //std::cout << " huli test :::: " << " qwe = " << qwe << std::endl;
- // return 0;
- Error_manager t_error;
- int t_dispatch_id = 31;
- // std::cin >> t_dispatch_id ;
- if ( argc == 2 )
- {
- std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
- t_dispatch_id = atoi(argv[1]);
- }
- //日志保存文件路径
- const char* logPath = "./";
- google::InitGoogleLogging("LidarMeasurement");
- google::SetStderrLogging(google::INFO);
- google::SetLogDestination(0, logPath);
- char t_log[256] = {0};
- sprintf(t_log, "sgj%d.log", t_dispatch_id);
- google::SetLogFilenameExtension(t_log);
- google::InstallFailureSignalHandler();
- google::InstallFailureWriter(&shut_down_logging);
- FLAGS_colorlogtostderr = true; // Set log color
- FLAGS_logbufsecs = 0; // Set log output speed(s)
- FLAGS_max_log_size = 1024; // Set max log file size(GB)
- FLAGS_stop_logging_if_full_disk = true;
- //#define MAIN_TEST 1
- #ifdef MAIN_TEST
- #endif
- LOG(INFO) << " ******************************************************************************************************************* " ;
- LOG(INFO) << "*********************************************dispatch run " << " t_dispatch_id = " << t_dispatch_id ;
- LOG(INFO) << "*********************************************dispatch run " << " start time = " << Time_tool::get_instance_references().get_current_time_millisecond() ;
- LOG(INFO) << " ******************************************************************************************************************* ";
- std::cout << "dispatch :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
- Database_controller::get_instance_references().database_controller_init();
- std::cout << "++++++++++++++++++++ Database_controller = " << Database_controller::get_instance_references().get_database_controller_status() << std::endl;
- // sql_test();
- // sql_test2();
- // return 0;
- Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
- std::cout << "++++++++++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
- Dispatch_communication::get_instance_references().communication_init(t_dispatch_id);
- std::cout << "+++++++++++++Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
- System_executor::get_instance_references().system_executor_init(8);
- std::cout << "++++++++++++++++System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
- t_error = System_communication::get_instance_references().communication_init(t_dispatch_id);
- std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
- System_communication::get_instance_references().set_encapsulate_status_cycle_time(100);
- t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
- std::cout << "++++++++++++++++++huli test network_init:::: " << " t_error = " << t_error << std::endl;
- LOG(INFO) << " t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);----------------------------- ";
- // Led_protocol l;
- // l.led_protocol_init();
- //
- // while (1)
- // {
- // std::this_thread::sleep_for(std::chrono::seconds(1));
- // l.create_led_message(1, Time_tool::get_instance_references().get_current_time_seconds(), 0, 0, 256, 16);
- // l.create_led_message(2, Time_tool::get_instance_references().get_current_time_seconds(), 0, 16, 256, 16);
- // Dispatch_network::get_instance_references().encapsulate_msg( l.get_led_msg_total_string() , 1 );
- // }
-
- #ifdef CHUTIAN_PROJECT_PROJECT
- t_error = Dispatch_network::get_instance_references().network_init(t_dispatch_id);
- std::cout << "++++++++++++++++++huli test System_communication:::: " << " t_error = " << t_error << std::endl;
- #endif //CHUTIAN_PROJECT_PROJECT
- while ( 1 )
- {
- std::this_thread::sleep_for(std::chrono::seconds(1));
- }
- /*
- //led test
- std::string result;
- Led_protocol led_protocol;
- t_error = led_protocol.led_protocol_init();
- std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
- // std::string t_show_string_utf8_0 = "\\C7楚天车库\\n\\C2停车入口6\\n\\C3暂停服务";
- std::string t_show_string_utf8_0 = "1122cba0123456";
- std::string t_show_string_gbk_0 = String_convert::utf8_to_gbk(t_show_string_utf8_0);
- //方法1, 直接创建, 只需要设置显示内容和矩形框
- result = led_protocol.create_led_message(0, t_show_string_gbk_0, 0, 0, 79, 59);
- // std::string t_show_string_utf8_1 = "";
- // std::string t_show_string_gbk_1 = String_convert::utf8_to_gbk(t_show_string_utf8_1);
- // //方法1, 直接创建, 只需要设置显示内容和矩形框
- // result = led_protocol.create_led_message(1, t_show_string_gbk_1, 79, 59, 1, 1);
- //方法2, 自定义配置,
- // led_protocol.set_show_string(0, t_show_string2);
- // led_protocol.set_show_rectangle(0, 0, 0, 79, 59);
- // led_protocol.set_line_mode(0, 2, 1);
- // result = led_protocol.get_led_msg_total_string();
- //打印
- unsigned char * ch = (unsigned char * )result.c_str();
- printf("Led_communication_msg string = \n");
- for (int i = 0; i < result.length(); ++i)
- {
- printf("%02x", *(ch+i));
- }
- printf("\n");
- for (int i = 0; i < result.length(); ++i)
- {
- printf("%02x ", *(ch+i));
- }
- printf("\n");
- for (int i = 0; i < result.length(); ++i)
- {
- printf("\\x%02x", *(ch+i));
- }
- printf("\n");
- printf("result.size() = %d\n", result.size());
- while ( 1 )
- {
- std::this_thread::sleep_for(std::chrono::seconds(1));
- }
- */
- char ch ;
- std::cin >> ch ;
- System_communication::get_instance_references().rabbitmq_uninit();
- System_executor::get_instance_references().system_executor_uninit();
- Dispatch_communication::get_instance_references().communication_uninit();
- Dispatch_manager::get_instance_references().dispatch_manager_uninit();
- return 0;
- }
|