terminal_client.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Created by zx on 2020/7/10.
  3. //
  4. //
  5. // Created by zx on 2020/7/3.
  6. //
  7. #include <unistd.h>
  8. #include <iostream>
  9. #include <nnxx/message>
  10. #include <nnxx/socket.h>
  11. #include <nnxx/bus.h>
  12. #include "terminal_message.pb.h"
  13. #include <thread>
  14. #include "threadSafeQueue.h"
  15. #include "Terminal_communication.h"
  16. #include "store_terminal.h"
  17. #include "pickup_terminal.h"
  18. #include "pathcreator.h"
  19. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  20. {
  21. time_t tt;
  22. time( &tt );
  23. tt = tt + 8*3600; // transform the time zone
  24. tm* t= gmtime( &tt );
  25. char buf[255]={0};
  26. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump_client.txt",
  27. t->tm_year + 1900,
  28. t->tm_mon + 1,
  29. t->tm_mday,
  30. t->tm_hour,
  31. t->tm_min,
  32. t->tm_sec);
  33. FILE* tp_file=fopen(buf,"w");
  34. fprintf(tp_file,data,strlen(data));
  35. fclose(tp_file);
  36. }
  37. void init_glog()
  38. {
  39. time_t tt = time(0);//时间cuo
  40. struct tm* t = localtime(&tt);
  41. char strYear[255]={0};
  42. char strMonth[255]={0};
  43. char strDay[255]={0};
  44. sprintf(strYear,"%04d", t->tm_year+1900);
  45. sprintf(strMonth,"%02d", t->tm_mon+1);
  46. sprintf(strDay,"%02d", t->tm_mday);
  47. char buf[255]={0};
  48. getcwd(buf,255);
  49. char strdir[255]={0};
  50. sprintf(strdir,"%s/log_client/%s/%s/%s", buf,strYear,strMonth,strDay);
  51. PathCreator creator;
  52. creator.Mkdir(strdir);
  53. char logPath[255] = { 0 };
  54. sprintf(logPath, "%s/", strdir);
  55. FLAGS_max_log_size = 100;
  56. FLAGS_logbufsecs = 0;
  57. google::InitGoogleLogging("LidarMeasurement");
  58. google::SetStderrLogging(google::INFO);
  59. google::SetLogDestination(0, logPath);
  60. google::SetLogFilenameExtension("zxlog");
  61. google::InstallFailureSignalHandler();
  62. google::InstallFailureWriter(&shut_down_logging);
  63. FLAGS_colorlogtostderr = true; // Set log color
  64. FLAGS_logbufsecs = 0; // Set log output speed(s)
  65. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  66. FLAGS_stop_logging_if_full_disk = true;
  67. }
  68. int main() {
  69. init_glog();
  70. Terminal_communication::get_instance_pointer()->communication_connect("tcp://127.0.0.1:9001");
  71. Terminal_communication::get_instance_pointer()->communication_run();
  72. usleep(2000*1000);
  73. threadsafe_queue<message::Car_info> input_queue;
  74. threadsafe_queue<message::Car_info> output_queue;
  75. const int n_input=2;
  76. const int n_output=2;
  77. std::vector<store_terminal*> input_terminals;
  78. std::vector<pickup_terminal*> output_terminals;
  79. for(int i=0;i<n_input;++i)
  80. {
  81. store_terminal* store=new store_terminal(i);
  82. store->init(&input_queue,&output_queue);
  83. input_terminals.push_back(store);
  84. }
  85. for(int i=0;i<n_output;++i)
  86. {
  87. pickup_terminal* picker=new pickup_terminal(i);
  88. picker->init(&output_queue);
  89. output_terminals.push_back(picker);
  90. }
  91. int n = 0;
  92. bool run = true;
  93. Error_manager code;
  94. while (run) {
  95. int license_id = rand() % 90000 + 10000;
  96. char C=rand()%10+'A';
  97. char license[255] = {0};
  98. sprintf(license, "鄂%c%d",C, license_id);
  99. message::Car_info car_info;
  100. car_info.set_license(license);
  101. car_info.set_car_height(1.5);
  102. car_info.set_car_width(1.7);
  103. input_queue.push(car_info);
  104. // std::cout<<" input : "<<++n<<std::endl;
  105. int in_count=input_queue.size();
  106. int out_count=output_queue.size();
  107. //暂停 5-15s 代替
  108. int delay=in_count*200;
  109. usleep(1000*delay+1);
  110. std::this_thread::yield();
  111. }
  112. }