main.cpp 4.3 KB

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