main.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // Created by zx on 2020/6/18.
  3. //
  4. #include <iostream>
  5. #include "./error_code/error_code.h"
  6. //#include "LogFiles.h"
  7. #include <glog/logging.h>
  8. #include "./communication/communication_socket_base.h"
  9. #include "./tool/thread_pool.h"
  10. #include "./system/system_communication.h"
  11. #include "./system/system_executor.h"
  12. #include "./dispatch/dispatch_manager.h"
  13. #include "./dispatch/dispatch_communication.h"
  14. #include <algorithm> // std::for_each
  15. #define LIVOX_NUMBER 2
  16. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  17. {
  18. time_t tt;
  19. time( &tt );
  20. tt = tt + 8*3600; // transform the time zone
  21. tm* t= gmtime( &tt );
  22. char buf[255]={0};
  23. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  24. t->tm_year + 1900,
  25. t->tm_mon + 1,
  26. t->tm_mday,
  27. t->tm_hour,
  28. t->tm_min,
  29. t->tm_sec);
  30. FILE* tp_file=fopen(buf,"w");
  31. fprintf(tp_file,data,strlen(data));
  32. fclose(tp_file);
  33. }
  34. #include <chrono>
  35. using namespace std;
  36. void myfunction (int i) { // function:
  37. std::cout << ' ' << i;
  38. }
  39. int main(int argc,char* argv[])
  40. {
  41. const char* logPath = "./";
  42. google::InitGoogleLogging("LidarMeasurement");
  43. google::SetStderrLogging(google::INFO);
  44. google::SetLogDestination(0, logPath);
  45. google::SetLogFilenameExtension("zxlog");
  46. google::InstallFailureSignalHandler();
  47. google::InstallFailureWriter(&shut_down_logging);
  48. FLAGS_colorlogtostderr = true; // Set log color
  49. FLAGS_logbufsecs = 0; // Set log output speed(s)
  50. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  51. FLAGS_stop_logging_if_full_disk = true;
  52. Error_manager t_error;
  53. std::cout << " huli test :::: " << " sizeof(Dispatch_communication::Request_from_dispatch_to_plc) = " << sizeof(Dispatch_communication::Request_from_dispatch_to_plc) << std::endl;
  54. std::cout << " huli test :::: " << " sizeof(Dispatch_communication::Response_from_plc_to_dispatch) = " << sizeof(Dispatch_communication::Response_from_plc_to_dispatch) << std::endl;
  55. std::cout << " huli test :::: " << " sizeof(Dispatch_communication::Status_from_dispatch_to_plc) = " << sizeof(Dispatch_communication::Status_from_dispatch_to_plc) << std::endl;
  56. std::cout << " huli test :::: " << " sizeof(Dispatch_communication::Status_from_plc_to_dispatch) = " << sizeof(Dispatch_communication::Status_from_plc_to_dispatch) << std::endl;
  57. t_error = Dispatch_communication::get_instance_references().communication_init();
  58. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  59. std::cout << "Dispatch_communication = " << Dispatch_communication::get_instance_references().get_status() << std::endl;
  60. Carrier_base t_carrier_base;
  61. t_carrier_base.carrier_base_init();
  62. std::shared_ptr<Carrier_task> tp_carrier_task(new Carrier_task);
  63. tp_carrier_task->task_init(NULL,std::chrono::milliseconds(15000),
  64. 1,2,3,"asd",
  65. 0,10,20,30);
  66. std::cout << " huli test :::: " << " tp_carrier_task->get_task_statu = " << tp_carrier_task->get_task_statu() << std::endl;
  67. std::cout << " huli test :::: " << " tp_carrier_task->m_respons_status = " << tp_carrier_task->m_respons_status << std::endl;
  68. std::cout << " huli test :::: " << " tp_carrier_task->m_respons_status = " << t_carrier_base.get_carrier_status() << std::endl;
  69. std::cout << " ---------------------------------------------------" << std::endl;
  70. t_error = t_carrier_base.execute_one_level_task(tp_carrier_task);
  71. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  72. while ( 1 )
  73. {
  74. std::cout << " huli test :::: " << " tp_carrier_task->get_task_statu = " << tp_carrier_task->get_task_statu() << std::endl;
  75. std::cout << " huli test :::: " << " tp_carrier_task->m_respons_status = " << tp_carrier_task->m_respons_status << std::endl;
  76. std::cout << " huli test :::: " << " t_carrier_base.get_carrier_status() = " << t_carrier_base.get_carrier_status() << std::endl;
  77. std::cout << " ---------------------------------------------------" << std::endl;
  78. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  79. }
  80. char ch123 ;
  81. std::cin >> ch123 ;
  82. Dispatch_communication::get_instance_references().communication_uninit();
  83. return 0;
  84. int t_dispatch_id = 0;
  85. // std::cin >> t_dispatch_id ;
  86. if ( argc == 2 )
  87. {
  88. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  89. t_dispatch_id = atoi(argv[1]);
  90. }
  91. std::cout << " huli test :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
  92. Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
  93. std::cout << "Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  94. System_executor::get_instance_references().system_executor_init(8);
  95. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  96. System_communication::get_instance_references().communication_init();
  97. char ch ;
  98. std::cin >> ch ;
  99. System_communication::get_instance_references().communication_uninit();
  100. System_executor::get_instance_references().system_executor_uninit();
  101. Dispatch_manager::get_instance_references().dispatch_manager_uninit();
  102. return 0;
  103. }