store_terminal.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // Created by zx on 2020/7/16.
  3. //
  4. #include "store_terminal.h"
  5. #include "Terminal_communication.h"
  6. threadsafe_queue<message::Car_info>* store_command::p_command_queue=new threadsafe_queue<message::Car_info>;
  7. store_command::store_command(message::Car_info msg)
  8. {
  9. m_car_info=msg;
  10. }
  11. store_command::~store_command()
  12. {
  13. m_exit_cond.set_pass_ever(true);
  14. }
  15. Error_manager store_command::storing(int terminal_id)
  16. {
  17. message::Store_command_request_msg request;
  18. message::Base_info base_info;
  19. base_info.set_msg_type(message::eStore_command_request_msg);
  20. base_info.set_sender(message::eTerminor);
  21. base_info.set_receiver(message::eMain);
  22. request.mutable_base_info()->CopyFrom(base_info);
  23. request.mutable_car_info()->CopyFrom(m_car_info);
  24. message::Locate_information locate_info;
  25. locate_info.set_locate_x(0.9);
  26. locate_info.set_locate_y(2.25);
  27. locate_info.set_locate_angle(90.0);
  28. locate_info.set_locate_wheel_base(2.7);
  29. locate_info.set_locate_width(m_car_info.car_width());
  30. locate_info.set_locate_height(m_car_info.car_height());
  31. locate_info.set_locate_correct(true);
  32. request.mutable_locate_information()->CopyFrom(locate_info);
  33. request.set_terminal_id(terminal_id);
  34. //发送停车请求
  35. Error_manager code;
  36. message::Store_command_response_msg response;
  37. code=Terminal_communication::get_instance_pointer()->store_request(request,response);
  38. if(code!=SUCCESS)
  39. {
  40. LOG(WARNING)<<" request_error: "<<code.to_string()<<std::endl;
  41. return ERROR;
  42. }
  43. if(response.code().error_code()!=0)
  44. {
  45. LOG(WARNING)<<" store request response code error: "<<response.code().error_description();
  46. return ERROR;
  47. }
  48. //等待停车完成
  49. bool last_signal=false;
  50. message::Storing_process_statu_msg last_msg;
  51. while(m_exit_cond.wait_for_millisecond(50)==false)
  52. {
  53. message::Storing_process_statu_msg msg;
  54. code = Terminal_communication::get_instance_pointer()->get_storing_statu(m_car_info.license(), msg);
  55. if (code == SUCCESS)
  56. {
  57. last_signal=true;
  58. last_msg=msg;
  59. }
  60. if(last_signal==true&&(last_msg.completed()==true||last_msg.back_completed()==true))
  61. {
  62. //停车完成
  63. p_command_queue->push(m_car_info);
  64. return SUCCESS;
  65. }
  66. }
  67. return FAILED;
  68. }