terminal_client.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #include "process_message.pb.h"
  20. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  21. {
  22. time_t tt;
  23. time( &tt );
  24. tt = tt + 8*3600; // transform the time zone
  25. tm* t= gmtime( &tt );
  26. char buf[255]={0};
  27. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump_client.txt",
  28. t->tm_year + 1900,
  29. t->tm_mon + 1,
  30. t->tm_mday,
  31. t->tm_hour,
  32. t->tm_min,
  33. t->tm_sec);
  34. FILE* tp_file=fopen(buf,"w");
  35. fprintf(tp_file,data,strlen(data));
  36. fclose(tp_file);
  37. }
  38. void init_glog()
  39. {
  40. time_t tt = time(0);//时间cuo
  41. struct tm* t = localtime(&tt);
  42. char strYear[255]={0};
  43. char strMonth[255]={0};
  44. char strDay[255]={0};
  45. sprintf(strYear,"%04d", t->tm_year+1900);
  46. sprintf(strMonth,"%02d", t->tm_mon+1);
  47. sprintf(strDay,"%02d", t->tm_mday);
  48. char buf[255]={0};
  49. getcwd(buf,255);
  50. char strdir[255]={0};
  51. sprintf(strdir,"%s/log_client/%s/%s/%s", buf,strYear,strMonth,strDay);
  52. PathCreator creator;
  53. creator.Mkdir(strdir);
  54. char logPath[255] = { 0 };
  55. sprintf(logPath, "%s/", strdir);
  56. FLAGS_max_log_size = 100;
  57. FLAGS_logbufsecs = 0;
  58. google::InitGoogleLogging("LidarMeasurement");
  59. google::SetStderrLogging(google::INFO);
  60. google::SetLogDestination(0, logPath);
  61. google::SetLogFilenameExtension("zxlog");
  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() {
  70. init_glog();
  71. Terminal_communication::get_instance_pointer()->communication_connect("tcp://192.168.2.183:30000");
  72. Terminal_communication::get_instance_pointer()->communication_run();
  73. usleep(2000*1000);
  74. threadsafe_queue<message::Car_info> input_queue;
  75. threadsafe_queue<message::Car_info> output_queue;
  76. const int n_input=6;
  77. const int n_output=6;
  78. std::vector<store_terminal*> input_terminals;
  79. std::vector<pickup_terminal*> output_terminals;
  80. for(int i=0;i<n_input;++i)
  81. {
  82. store_terminal* store=new store_terminal(i);
  83. store->init(&input_queue,&output_queue);
  84. input_terminals.push_back(store);
  85. }
  86. for(int i=0;i<n_output;++i)
  87. {
  88. pickup_terminal* picker=new pickup_terminal(i);
  89. picker->init(&output_queue);
  90. output_terminals.push_back(picker);
  91. }
  92. int n = 0;
  93. bool run = true;
  94. Error_manager code;
  95. char c=0;
  96. int license_id = 11700;
  97. while (c!='q') {
  98. char C=rand()%10+'A';
  99. char license[255] = {0};
  100. sprintf(license, "鄂%c%d",C, license_id++);
  101. message::Car_info car_info;
  102. car_info.set_license(license);
  103. car_info.set_car_height(1.5);
  104. car_info.set_car_width(1.7);
  105. input_queue.push(car_info);
  106. n++;
  107. int in_count=input_queue.size();
  108. int out_count=output_queue.size();
  109. {
  110. usleep(1000*500*in_count);
  111. std::this_thread::yield();
  112. }
  113. }
  114. }