terminal_client.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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:30001");
  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=3;
  78. const int n_output=1;
  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. while (c!='q') {
  98. /*int k=rand()%4;
  99. message::Storing_process_statu_msg msg;
  100. message::Base_info base_info;
  101. base_info.set_msg_type(message::eStoring_process_statu_msg);
  102. base_info.set_sender(message::eMain);
  103. base_info.set_receiver(message::eTerminor);
  104. msg.mutable_base_info()->CopyFrom(base_info);
  105. message::Alloc_space_step_statu alloc_step;
  106. alloc_step.set_step_statu(message::Step_statu(k));
  107. message::Measure_step_statu measure_step;
  108. measure_step.set_step_statu(message::eWaiting);
  109. message::Dispatch_store_step_statu store_step;
  110. store_step.set_step_statu(message::eWaiting);
  111. message::Confirm_space_step_statu confirm_step;
  112. confirm_step.set_step_statu(message::eWaiting);
  113. message::Release_space_step_statu release_step;
  114. release_step.set_step_statu(message::eWaiting);
  115. msg.mutable_alloc_space_step()->CopyFrom(alloc_step);
  116. msg.mutable_measure_step()->CopyFrom(measure_step);
  117. msg.mutable_dispatch_step()->CopyFrom(store_step);
  118. msg.mutable_confirm_space_step()->CopyFrom(confirm_step);
  119. msg.mutable_failed_release_space_step()->CopyFrom(release_step);
  120. System_communicator::get_instance_pointer()->post_entrance_statu(msg);
  121. usleep(1000*1000);*/
  122. int license_id = rand() % 90000 + 10000;
  123. char C=rand()%10+'A';
  124. char license[255] = {0};
  125. sprintf(license, "鄂%c%d",C, license_id);
  126. message::Car_info car_info;
  127. car_info.set_license(license);
  128. car_info.set_car_height(1.5);
  129. car_info.set_car_width(1.7);
  130. input_queue.push(car_info);
  131. // std::cout<<" input : "<<++n<<std::endl;
  132. n++;
  133. int in_count=input_queue.size();
  134. int out_count=output_queue.size();
  135. if(n%1==0) {
  136. usleep(1000*1000*1);
  137. }
  138. else {
  139. //暂停 5-15s 代替
  140. int delay=10*1000;//in_count*200;
  141. usleep(1000*delay+1);
  142. std::this_thread::yield();
  143. }
  144. }
  145. }