main.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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::InstallFailureSignalHandler();
  63. google::InstallFailureWriter(&shut_down_logging);
  64. FLAGS_colorlogtostderr = true; // Set log color
  65. FLAGS_logbufsecs = 0; // Set log output speed(s)
  66. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  67. FLAGS_stop_logging_if_full_disk = true;
  68. }
  69. int main(int argc,char* argv[])
  70. {
  71. Error_manager code;
  72. //初始化日志
  73. init_glog();
  74. //创建system实例
  75. System_Manager system_manager;
  76. //初始化实例,包括雷达,plc,locater,terminal的创建及初始化
  77. code=system_manager.init();
  78. if(code!=SUCCESS)
  79. {
  80. LOG(ERROR)<<code.to_string();
  81. printf("print ctrl-c to quite");
  82. }
  83. else
  84. {
  85. LOG(INFO)<<"SYSTEM Init OK !!!!";
  86. }
  87. getchar();
  88. return 0;
  89. }