main.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #include <dispatch_communicator.h>
  18. //using google::protobuf::io::FileInputStream;
  19. //using google::protobuf::io::FileOutputStream;
  20. using google::protobuf::io::ZeroCopyInputStream;
  21. using google::protobuf::io::CodedInputStream;
  22. using google::protobuf::io::ZeroCopyOutputStream;
  23. using google::protobuf::io::CodedOutputStream;
  24. using google::protobuf::Message;
  25. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size);
  26. void init_glog();
  27. Error_manager init_communicators();
  28. int main(int argc,char* argv[])
  29. {
  30. init_glog();
  31. Error_manager code=init_communicators();
  32. if(code!=SUCCESS)
  33. {
  34. LOG(ERROR)<<code.to_string();
  35. }
  36. getchar();
  37. return 0;
  38. }
  39. Error_manager init_communicators()
  40. {
  41. Error_manager code;
  42. /*
  43. * 初始化各个通讯模块,
  44. */
  45. if(Locate_communicator::get_instance_pointer()== nullptr)
  46. return FAILED;
  47. code=Locate_communicator::get_instance_pointer()->communication_connect("tcp://127.0.0.1:4444");
  48. if(code!=SUCCESS)
  49. {
  50. return code;
  51. }
  52. Locate_communicator::get_instance_pointer()->communication_run();
  53. //初始化车位分配通讯模块
  54. if(Parkspace_communicator::get_instance_pointer()== nullptr)
  55. return FAILED;
  56. code=Parkspace_communicator::get_instance_pointer()->communication_connect("tcp://192.168.2.125:7001");
  57. if(code!=SUCCESS)
  58. {
  59. return code;
  60. }
  61. Parkspace_communicator::get_instance_pointer()->communication_run();
  62. /*
  63. * 初始化调度模块
  64. */
  65. Dispatch_communicator::get_instance_pointer()->communication_connect("tcp://192.168.2.192:5555");
  66. Dispatch_communicator::get_instance_pointer()->communication_run();
  67. /*
  68. *
  69. * 此处添加等待各个通讯模块正常代码
  70. *
  71. */
  72. ///最后初始化与终端通讯的对象
  73. if(System_communicator::get_instance_pointer()== nullptr)
  74. return FAILED;
  75. System_communicator::get_instance_pointer()->communication_bind("tcp://127.0.0.1:9001");
  76. System_communicator::get_instance_pointer()->communication_run();
  77. /*
  78. * 初始化指令执行模块
  79. */
  80. if(Command_manager::get_instance_pointer()== nullptr)
  81. return Error_manager(FAILED,CRITICAL_ERROR,"创建指令执行模块失败");
  82. code=Command_manager::get_instance_pointer()->init();
  83. if(code!=SUCCESS)
  84. {
  85. return code;
  86. }
  87. usleep(1000*3000);
  88. return SUCCESS;
  89. }
  90. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  91. {
  92. time_t tt;
  93. time( &tt );
  94. tt = tt + 8*3600; // transform the time zone
  95. tm* t= gmtime( &tt );
  96. char buf[255]={0};
  97. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  98. t->tm_year + 1900,
  99. t->tm_mon + 1,
  100. t->tm_mday,
  101. t->tm_hour,
  102. t->tm_min,
  103. t->tm_sec);
  104. FILE* tp_file=fopen(buf,"w");
  105. fprintf(tp_file,data,strlen(data));
  106. fclose(tp_file);
  107. }
  108. void init_glog()
  109. {
  110. time_t tt = time(0);//时间cuo
  111. struct tm* t = localtime(&tt);
  112. char strYear[255]={0};
  113. char strMonth[255]={0};
  114. char strDay[255]={0};
  115. sprintf(strYear,"%04d", t->tm_year+1900);
  116. sprintf(strMonth,"%02d", t->tm_mon+1);
  117. sprintf(strDay,"%02d", t->tm_mday);
  118. char buf[255]={0};
  119. getcwd(buf,255);
  120. char strdir[255]={0};
  121. sprintf(strdir,"%s/log/%s/%s/%s", buf,strYear,strMonth,strDay);
  122. PathCreator creator;
  123. creator.Mkdir(strdir);
  124. char logPath[255] = { 0 };
  125. sprintf(logPath, "%s/", strdir);
  126. FLAGS_max_log_size = 100;
  127. FLAGS_logbufsecs = 0;
  128. google::InitGoogleLogging("LidarMeasurement");
  129. google::SetStderrLogging(google::INFO);
  130. google::SetLogDestination(0, logPath);
  131. google::SetLogFilenameExtension("zxlog");
  132. google::InstallFailureSignalHandler();
  133. google::InstallFailureWriter(&shut_down_logging);
  134. FLAGS_colorlogtostderr = true; // Set log color
  135. FLAGS_logbufsecs = 0; // Set log output speed(s)
  136. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  137. FLAGS_stop_logging_if_full_disk = true;
  138. }