12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //
- // Created by zx on 2020/7/16.
- //
- #include "pickup_terminal.h"
- #include "Terminal_communication.h"
- pickup_terminal::pickup_terminal(int terminal_id)
- {
- m_terminal_id=terminal_id;
- m_thread_safe_queue= nullptr;
- }
- Error_manager pickup_terminal::init(threadsafe_queue<message::Car_info>* queue)
- {
- m_thread_safe_queue=queue;
- m_exit_cond.reset(false,false,false);
- m_pthread=new std::thread(pickup_thread,this);
- return SUCCESS;
- }
- pickup_terminal::~pickup_terminal()
- {
- m_exit_cond.set_pass_ever(true);
- if(m_pthread)
- {
- if(m_pthread->joinable())
- m_pthread->join();
- delete m_pthread;
- m_pthread=nullptr;
- }
- }
- Error_manager pickup_terminal::pickup(message::Car_info& car_info)
- {
- message::Pickup_command_request_msg request;
- message::Base_info base_info;
- base_info.set_msg_type(message::ePickup_command_request_msg);
- base_info.set_sender(message::eTerminor);
- base_info.set_receiver(message::eMain);
- request.mutable_base_info()->CopyFrom(base_info);
- request.mutable_car_info()->CopyFrom(car_info);
- request.set_terminal_id(m_terminal_id);
- //发送停车请求
- Error_manager code;
- message::Pickup_command_response_msg response;
- code=Terminal_communication::get_instance_pointer()->pickup_request(request,response);
- if(code!=SUCCESS)
- {
- std::cout<<"取车请求失败:"<<code.to_string()<<std::endl;
- return ERROR;
- }
- //等待停车完成
- bool last_signal=false;
- while(m_exit_cond.wait_for_millisecond(200)==false)
- {
- message::Picking_process_statu_msg msg;
- code = Terminal_communication::get_instance_pointer()->get_picking_statu(car_info.license(), msg);
- if (code != SUCCESS) {
- if(last_signal==true)
- {
- return SUCCESS;
- }
- }
- else
- {
- last_signal=true;
- }
- }
- return FAILED;
- }
- void pickup_terminal::pickup_thread(pickup_terminal* picker)
- {
- while(picker->m_exit_cond.wait_for_millisecond(200)==false)
- {
- message::Car_info car_info;
- if(picker->m_thread_safe_queue== nullptr)
- continue;
- if(picker->m_thread_safe_queue->try_pop(car_info)==true)
- {
- /*LOG(WARNING)<<"取车终端:"<<picker->m_terminal_id<<",车辆:"<<car_info.license().c_str()
- <<",开始取车,剩余out:"<<picker->m_thread_safe_queue->size();*/
- Error_manager code=picker->pickup(car_info);
- }
- }
- }
|