main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // Created by zx on 2020/6/18.
  3. //
  4. #include <fcntl.h>
  5. #include <iostream>
  6. #include <glog/logging.h>
  7. #include "TaskQueue/TQFactory.h"
  8. #include "./communication/communication_socket_base.h"
  9. #include "StoreProcessTask.h"
  10. #include "PickupProcessTask.h"
  11. #include "system_communicator.h"
  12. #include "Locate_communicator.h"
  13. #include "command_manager.h"
  14. #include "pathcreator.h"
  15. #include <glog/logging.h>
  16. #include <Parkspace_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. }
  35. getchar();
  36. return 0;
  37. }
  38. Error_manager init_communicators()
  39. {
  40. Error_manager code;
  41. /*
  42. * 初始化各个通讯模块,
  43. */
  44. if(Locate_communicator::get_instance_pointer()== nullptr)
  45. return FAILED;
  46. code=Locate_communicator::get_instance_pointer()->communication_connect("tcp://127.0.0.1:4444");
  47. if(code!=SUCCESS)
  48. {
  49. return code;
  50. }
  51. Locate_communicator::get_instance_pointer()->communication_run();
  52. //初始化车位分配通讯模块
  53. if(Parkspace_communicator::get_instance_pointer()== nullptr)
  54. return FAILED;
  55. code=Parkspace_communicator::get_instance_pointer()->communication_connect("tcp://192.168.2.125:7001");
  56. if(code!=SUCCESS)
  57. {
  58. return code;
  59. }
  60. Parkspace_communicator::get_instance_pointer()->communication_run();
  61. ///最后初始化与终端通讯的对象
  62. if(System_communicator::get_instance_pointer()== nullptr)
  63. return FAILED;
  64. System_communicator::get_instance_pointer()->communication_bind("tcp://127.0.0.1:9001");
  65. System_communicator::get_instance_pointer()->communication_run();
  66. /*
  67. * 初始化指令执行模块
  68. */
  69. if(Command_manager::get_instance_pointer()== nullptr)
  70. return Error_manager(FAILED,CRITICAL_ERROR,"创建指令执行模块失败");
  71. code=Command_manager::get_instance_pointer()->init();
  72. if(code!=SUCCESS)
  73. {
  74. return code;
  75. }
  76. usleep(1000*3000);
  77. return SUCCESS;
  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. }