Locate_client.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Created by zx on 2020/7/3.
  3. //
  4. #include <unistd.h>
  5. #include <iostream>
  6. #include <nnxx/message>
  7. #include <nnxx/socket.h>
  8. #include <nnxx/bus.h>
  9. #include "measure_message.pb.h"
  10. #include <thread>
  11. int main()
  12. {
  13. nnxx::socket socket{ nnxx::SP, nnxx::BUS };
  14. socket.bind("tcp://127.0.0.1:4444");
  15. int n=0;
  16. while(1)
  17. {
  18. std::string t_receive_string = socket.recv<std::string>(0);
  19. if(t_receive_string.length()>0) {
  20. message::Base_info base_msg;
  21. message::Measure_response_msg response;
  22. message::Measure_request_msg request;
  23. message::Error_manager error_code;
  24. request.ParseFromString(t_receive_string);
  25. base_msg.set_msg_type(message::eLocate_response_msg);
  26. base_msg.set_sender(message::eMeasurer);
  27. base_msg.set_receiver(message::eMain);
  28. response.set_command_id(request.command_id());
  29. response.set_terminal_id(request.terminal_id());
  30. response.mutable_base_info()->CopyFrom(base_msg);
  31. int succ=int((rand()%1000)/999);
  32. if(succ==0)
  33. {
  34. message::Locate_information locate_info;
  35. locate_info.set_locate_x(0.9);
  36. locate_info.set_locate_y(2.25);
  37. locate_info.set_locate_height(1.5);
  38. locate_info.set_locate_width(1.7);
  39. locate_info.set_locate_length(4.5);
  40. locate_info.set_locate_wheel_base(2.7);
  41. locate_info.set_locate_angle(90.0);
  42. locate_info.set_locate_correct(true);
  43. response.mutable_locate_information()->CopyFrom(locate_info);
  44. }
  45. error_code.set_error_code(succ);
  46. response.mutable_error_manager()->CopyFrom(error_code);
  47. std::cout<<request.DebugString()<<std::endl;
  48. socket.send(response.SerializeAsString());
  49. usleep(1000);
  50. std::this_thread::yield();
  51. }
  52. }
  53. }