test_locate_sample.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // Created by zx on 2020/7/3.
  3. //
  4. #include <iostream>
  5. #include "../lidar_locate/Locate_communicator.h"
  6. #include <unistd.h>
  7. #include "../tool/thread_safe_list.h"
  8. int main(int argc,char* argv[])
  9. {
  10. int exe_id=rand()%1000000;
  11. Locate_communicator* pLocator=Locate_communicator::get_instance_pointer();
  12. pLocator->communication_connect("tcp://127.0.0.1:9006");
  13. pLocator->communication_run();
  14. int k=1;
  15. Thread_safe_list<std::string*> list;
  16. /*nnxx::socket socket{ nnxx::SP, nnxx::BUS };
  17. socket.bind("tcp://127.0.0.1:9005");
  18. socket.connect("tcp://127.0.0.1:9006");*/
  19. int n=0;
  20. while(1) {
  21. message::Measure_request_msg request;
  22. //message::Base_info base_msg;
  23. //request.mutable_base_info()->CopyFrom(base_msg);
  24. request.mutable_base_info()->set_msg_type(message::eLocate_request_msg);
  25. request.mutable_base_info()->set_sender(message::eMain);
  26. request.mutable_base_info()->set_receiver(message::eMeasurer);
  27. //request.mutable_base_info()->set_timeout_ms(1000);
  28. request.set_command_id(exe_id+n++);
  29. request.set_terminal_id(rand()%6);
  30. message::Measure_response_msg response;
  31. message::Measure_request_msg request_1;
  32. std::string str=request.SerializeAsString();
  33. Error_manager code=pLocator->locate_request(request,response);
  34. if(code!=SUCCESS)
  35. {
  36. std::cout<<code.to_string()<<std::endl;
  37. }
  38. else if(request.command_id()==response.command_id()){
  39. std::cout<<" Success request command :"<<response.DebugString()<<std::endl;
  40. std::cout<<" n == "<<n<<std::endl;
  41. }
  42. k++;
  43. usleep(1000*500);
  44. }
  45. return 0;
  46. }