terminal_client.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #include "system_communicator.h"
  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_client.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_client/%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. int main() {
  71. init_glog();
  72. Terminal_communication::get_instance_pointer()->communication_connect("tcp://192.168.2.183:30000");
  73. Terminal_communication::get_instance_pointer()->communication_run();
  74. usleep(2000*1000);
  75. threadsafe_queue<message::Car_info> input_queue;
  76. threadsafe_queue<message::Car_info> output_queue;
  77. const int n_input=6;
  78. const int n_output=6;
  79. std::vector<store_terminal*> input_terminals;
  80. std::vector<pickup_terminal*> output_terminals;
  81. for(int i=0;i<n_input;++i)
  82. {
  83. store_terminal* store=new store_terminal(i);
  84. store->init(&input_queue,&output_queue);
  85. input_terminals.push_back(store);
  86. }
  87. for(int i=0;i<n_output;++i)
  88. {
  89. pickup_terminal* picker=new pickup_terminal(i);
  90. picker->init(&output_queue);
  91. output_terminals.push_back(picker);
  92. }
  93. int n = 0;
  94. bool run = true;
  95. Error_manager code;
  96. char c=0;
  97. int license_id = 11100;
  98. while (c!='q') {
  99. char C=rand()%10+'A';
  100. char license[255] = {0};
  101. sprintf(license, "鄂%c%d",C, license_id++);
  102. message::Car_info car_info;
  103. car_info.set_license(license);
  104. car_info.set_car_height(1.5);
  105. car_info.set_car_width(1.7);
  106. input_queue.push(car_info);
  107. n++;
  108. int in_count=input_queue.size();
  109. int out_count=output_queue.size();
  110. {
  111. usleep(1000*1000*in_count);
  112. std::this_thread::yield();
  113. }
  114. }
  115. }