main.cpp 4.3 KB

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