main.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // Created by zx on 2019/12/28.
  3. //
  4. #include <fcntl.h>
  5. #include <iostream>
  6. #include "plc/plc_communicator.h"
  7. #include "laser/Laser.h"
  8. #include "plc/plc_communicator.h"
  9. #include "locate/locater.h"
  10. #include "terminor/terminal_command_executor.h"
  11. #include "system_manager/System_Manager.h"
  12. #include "tool/pathcreator.h"
  13. #include <glog/logging.h>
  14. using google::protobuf::io::FileInputStream;
  15. using google::protobuf::io::FileOutputStream;
  16. using google::protobuf::io::ZeroCopyInputStream;
  17. using google::protobuf::io::CodedInputStream;
  18. using google::protobuf::io::ZeroCopyOutputStream;
  19. using google::protobuf::io::CodedOutputStream;
  20. using google::protobuf::Message;
  21. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  22. {
  23. time_t tt;
  24. time( &tt );
  25. tt = tt + 8*3600; // transform the time zone
  26. tm* t= gmtime( &tt );
  27. char buf[255]={0};
  28. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  29. t->tm_year + 1900,
  30. t->tm_mon + 1,
  31. t->tm_mday,
  32. t->tm_hour,
  33. t->tm_min,
  34. t->tm_sec);
  35. FILE* tp_file=fopen(buf,"w");
  36. fprintf(tp_file,data,strlen(data));
  37. fclose(tp_file);
  38. }
  39. void init_glog()
  40. {
  41. time_t tt = time(0);//时间cuo
  42. struct tm* t = localtime(&tt);
  43. char strYear[255]={0};
  44. char strMonth[255]={0};
  45. char strDay[255]={0};
  46. sprintf(strYear,"%04d", t->tm_year+1900);
  47. sprintf(strMonth,"%02d", t->tm_mon+1);
  48. sprintf(strDay,"%02d", t->tm_mday);
  49. char buf[255]={0};
  50. getcwd(buf,255);
  51. char strdir[255]={0};
  52. sprintf(strdir,"%s/log/%s/%s/%s", buf,strYear,strMonth,strDay);
  53. PathCreator creator;
  54. creator.Mkdir(strdir);
  55. char logPath[255] = { 0 };
  56. sprintf(logPath, "%s/", strdir);
  57. FLAGS_max_log_size = 100;
  58. FLAGS_logbufsecs = 0;
  59. google::InitGoogleLogging("LidarMeasurement");
  60. google::SetStderrLogging(google::INFO);
  61. google::SetLogDestination(0, logPath);
  62. google::SetLogFilenameExtension("zxlog");
  63. google::InstallFailureSignalHandler();
  64. google::InstallFailureWriter(&shut_down_logging);
  65. FLAGS_colorlogtostderr = true; // Set log color
  66. FLAGS_logbufsecs = 0; // Set log output speed(s)
  67. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  68. FLAGS_stop_logging_if_full_disk = true;
  69. }
  70. void test_classify()
  71. {
  72. Locate_information info1,info2;
  73. info1.locate_x=0;
  74. info1.locate_y=0;
  75. info1.locate_theta=45;
  76. info2.locate_x=100;
  77. info2.locate_y=0;
  78. info2.locate_theta=45;
  79. Terminor_Command_Executor::classify_location_informations(info1,info2);
  80. }
  81. int main(int argc,char* argv[])
  82. {
  83. Error_manager code;
  84. //初始化日志
  85. init_glog();
  86. //创建system实例
  87. System_Manager system_manager;
  88. //初始化实例,包括雷达,plc,locater,terminal的创建及初始化
  89. code=system_manager.init();
  90. if(code!=SUCCESS)
  91. {
  92. LOG(ERROR)<<code.to_string();
  93. printf("print ctrl-c to quite");
  94. }
  95. else
  96. {
  97. LOG(INFO)<<"SYSTEM Init OK !!!!";
  98. }
  99. getchar();
  100. return 0;
  101. }