main.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // Created by zx on 2020/6/18.
  3. //
  4. #include <fcntl.h>
  5. #include <iostream>
  6. #include <glog/logging.h>
  7. #include "command_accepter.h"
  8. #include "command_manager.h"
  9. #include "exception_solver.h"
  10. #include "proto_tool.h"
  11. #include "pathcreator.h"
  12. #include <parkspace_excutor.h>
  13. #include <dispatch_excutor.h>
  14. #include "message_communicator.h"
  15. //using google::protobuf::io::FileInputStream;
  16. //using google::protobuf::io::FileOutputStream;
  17. using google::protobuf::io::ZeroCopyInputStream;
  18. using google::protobuf::io::CodedInputStream;
  19. using google::protobuf::io::ZeroCopyOutputStream;
  20. using google::protobuf::io::CodedOutputStream;
  21. using google::protobuf::Message;
  22. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size);
  23. void init_glog();
  24. Error_manager init_communicators();
  25. int main(int argc,char* argv[])
  26. {
  27. init_glog();
  28. Error_manager code=init_communicators();
  29. if(code!=SUCCESS)
  30. {
  31. LOG(ERROR)<<code.to_string();
  32. return 0;
  33. }
  34. getchar();
  35. return 0;
  36. }
  37. Error_manager init_communicators()
  38. {
  39. Error_manager code;
  40. setting::System_setting system_setting;
  41. if(! proto_tool::read_proto_param("./setting/system_setting.prototxt",system_setting) )
  42. {
  43. return Error_manager(COMMUNICATION_READ_PROTOBUF_ERROR,MINOR_ERROR,
  44. "system_setting read_proto_param failed");
  45. }
  46. /*
  47. * 初始化通讯模块
  48. */
  49. if(Message_communicator::get_instance_pointer()== nullptr)
  50. return FAILED;
  51. char bind_string[64]={0};
  52. sprintf(bind_string,"tcp://%s:%d",system_setting.bind_ip().c_str(),system_setting.bind_port());
  53. Message_communicator::get_instance_pointer()->communication_bind(bind_string);
  54. ///初始化故障处理对象
  55. if(Exception_solver::get_instance_pointer()== nullptr)
  56. return FAILED;
  57. ///初始化与终端通讯的对象
  58. if(Command_accepter::get_instance_pointer()== nullptr)
  59. return FAILED;
  60. /*
  61. * 初始化各个模块,
  62. */
  63. if(Dispatch_excutor::get_instance_pointer()== nullptr)
  64. return FAILED;
  65. //初始化车位分配模块
  66. if(Parkspace_excutor::get_instance_pointer()== nullptr)
  67. return FAILED;
  68. Message_communicator::get_instance_pointer()->communication_run();
  69. /*
  70. * 初始化指令执行模块
  71. */
  72. if(Command_manager::get_instance_pointer()== nullptr)
  73. return Error_manager(FAILED,CRITICAL_ERROR,"创建指令执行模块失败");
  74. code=Command_manager::get_instance_pointer()->init(system_setting);
  75. if(code==SUCCESS)
  76. LOG(INFO)<<"系统初始化完成 --------------------------------------------- !!!";
  77. return code;
  78. }
  79. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  80. {
  81. time_t tt;
  82. time( &tt );
  83. tt = tt + 8*3600; // transform the time zone
  84. tm* t= gmtime( &tt );
  85. char buf[255]={0};
  86. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  87. t->tm_year + 1900,
  88. t->tm_mon + 1,
  89. t->tm_mday,
  90. t->tm_hour,
  91. t->tm_min,
  92. t->tm_sec);
  93. FILE* tp_file=fopen(buf,"w");
  94. fprintf(tp_file,data,strlen(data));
  95. fclose(tp_file);
  96. }
  97. void init_glog()
  98. {
  99. time_t tt = time(0);//时间cuo
  100. struct tm* t = localtime(&tt);
  101. char strYear[255]={0};
  102. char strMonth[255]={0};
  103. char strDay[255]={0};
  104. sprintf(strYear,"%04d", t->tm_year+1900);
  105. sprintf(strMonth,"%02d", t->tm_mon+1);
  106. sprintf(strDay,"%02d", t->tm_mday);
  107. char buf[255]={0};
  108. getcwd(buf,255);
  109. char strdir[255]={0};
  110. sprintf(strdir,"%s/log/%s/%s/%s", buf,strYear,strMonth,strDay);
  111. PathCreator creator;
  112. creator.Mkdir(strdir);
  113. char logPath[255] = { 0 };
  114. sprintf(logPath, "%s/", strdir);
  115. FLAGS_max_log_size = 100;
  116. FLAGS_logbufsecs = 0;
  117. google::InitGoogleLogging("LidarMeasurement");
  118. google::SetStderrLogging(google::INFO);
  119. google::SetLogDestination(0, logPath);
  120. google::SetLogFilenameExtension("zxlog");
  121. google::InstallFailureSignalHandler();
  122. google::InstallFailureWriter(&shut_down_logging);
  123. FLAGS_colorlogtostderr = true; // Set log color
  124. FLAGS_logbufsecs = 0; // Set log output speed(s)
  125. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  126. FLAGS_stop_logging_if_full_disk = true;
  127. }