main.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. TSnap7Client t_snap7_client; //通信的客户端
  42. int result=t_snap7_client.ConnectTo("192.168.2.110",0,1);
  43. std::cout << " huli test :::: " << " result = " << result << std::endl;
  44. // std::this_thread::sleep_for(std::chrono::seconds(1));
  45. unsigned char t_read[20] = {0};
  46. memset(t_read, 0, 20);
  47. result = t_snap7_client.AsDBRead(120, 0, 1, t_read);
  48. if ( result == 0 )
  49. {
  50. t_snap7_client.WaitAsCompletion(100);
  51. }
  52. std::cout << " huli test :::: " << " t_read = " << (int)t_read[0] << std::endl;
  53. std::cout << " huli test :::: " << " AsDBRead result = " << result << std::endl;
  54. // std::this_thread::sleep_for(std::chrono::seconds(1));
  55. short f = -4;
  56. unsigned char * p_asd = (unsigned char *)&f;
  57. // unsigned char t_write[20] = {0};
  58. // memset(t_write, 20, 20);
  59. // t_write[0] = p_asd[3];
  60. // t_write[1] = p_asd[2];
  61. // t_write[2] = p_asd[1];
  62. // t_write[3] = p_asd[0];
  63. // t_write[0] = p_asd[1];
  64. // t_write[1] = p_asd[0];
  65. unsigned char t_write[20] = "鄂A123456";
  66. // t_write[19] = 's';
  67. result = t_snap7_client.AsDBWrite(120, 72, 20, t_write);
  68. if ( result == 0 )
  69. {
  70. t_snap7_client.WaitAsCompletion(100);
  71. }
  72. std::cout << " huli test :::: " << " t_read = " << (int)t_write[0] << std::endl;
  73. std::cout << " huli test :::: " << " AsDBRead result = " << result << std::endl;
  74. // return 0;
  75. char a=1;
  76. typeof(a) b=2;
  77. typeid(a).name();
  78. std::cout << " huli test :::: " << " a = " << a << std::endl;
  79. std::cout << " huli test :::: " << " typeid(a).name() = " << typeid(a).name() << std::endl;
  80. std::cout << " huli test :::: " << " b = " << b << std::endl;
  81. std::cout << " huli test :::: " << " typeid(b).name() = " << typeid(b).name() << std::endl;
  82. std::cout << " huli test :::: " << " typeid(int).name() = " << typeid(int).name() << std::endl;
  83. return 0;
  84. const char* logPath = "./";
  85. google::InitGoogleLogging("LidarMeasurement");
  86. google::SetStderrLogging(google::INFO);
  87. google::SetLogDestination(0, logPath);
  88. google::SetLogFilenameExtension("zxlog");
  89. google::InstallFailureSignalHandler();
  90. google::InstallFailureWriter(&shut_down_logging);
  91. FLAGS_colorlogtostderr = true; // Set log color
  92. FLAGS_logbufsecs = 0; // Set log output speed(s)
  93. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  94. FLAGS_stop_logging_if_full_disk = true;
  95. Error_manager t_error;
  96. std::cout << " huli test :::: " << " sizeof(Dispatch_communication::Request_from_dispatch_to_plc) = " << sizeof(Dispatch_communication::Request_from_dispatch_to_plc) << std::endl;
  97. std::cout << " huli test :::: " << " sizeof(Dispatch_communication::Response_from_plc_to_dispatch) = " << sizeof(Dispatch_communication::Response_from_plc_to_dispatch) << std::endl;
  98. std::cout << " huli test :::: " << " sizeof(Dispatch_communication::Status_from_dispatch_to_plc) = " << sizeof(Dispatch_communication::Status_from_dispatch_to_plc) << std::endl;
  99. std::cout << " huli test :::: " << " sizeof(Dispatch_communication::Status_from_plc_to_dispatch) = " << sizeof(Dispatch_communication::Status_from_plc_to_dispatch) << std::endl;
  100. t_error = Dispatch_communication::get_instance_references().communication_init();
  101. std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
  102. std::cout << "Dispatch_communication = " << Dispatch_communication::get_instance_references().get_status() << std::endl;
  103. char ch123 ;
  104. std::cin >> ch123 ;
  105. Dispatch_communication::get_instance_references().communication_uninit();
  106. return 0;
  107. int t_dispatch_id = 0;
  108. // std::cin >> t_dispatch_id ;
  109. if ( argc == 2 )
  110. {
  111. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  112. t_dispatch_id = atoi(argv[1]);
  113. }
  114. std::cout << " huli test :::: " << " t_dispatch_id = " << t_dispatch_id << std::endl;
  115. Dispatch_manager::get_instance_references().dispatch_manager_init(t_dispatch_id);
  116. std::cout << "Dispatch_manager = " << Dispatch_manager::get_instance_references().get_dispatch_manager_status() << std::endl;
  117. System_executor::get_instance_references().system_executor_init(8);
  118. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  119. System_communication::get_instance_references().communication_init();
  120. char ch ;
  121. std::cin >> ch ;
  122. System_communication::get_instance_references().communication_uninit();
  123. System_executor::get_instance_references().system_executor_uninit();
  124. Dispatch_manager::get_instance_references().dispatch_manager_uninit();
  125. return 0;
  126. }