// // Created by zx on 2020/7/13. // #include "Terminal_communication.h" #include "process_message.pb.h" #include Terminal_communication::Terminal_communication() :m_update_msg_map_thread(nullptr) { if(m_update_msg_map_thread== nullptr) { m_publish_exit_condition.reset(false, false, false); m_update_msg_map_thread=new std::thread(thread_update_map_function,this); } } Terminal_communication::~Terminal_communication(){} //重载函数 Error_manager Terminal_communication::encapsulate_msg(Communication_message* message) { Error_manager code; switch (message->get_message_type()) { case Communication_message::eStore_command_request_msg: { message::Store_command_request_msg request; request.ParseFromString(message->get_message_buf()); //清空记录 m_store_response_msg=message::Store_command_response_msg(); //发送请求 code= Communication_socket_base::encapsulate_msg(message); break; } case Communication_message::ePickup_command_request_msg: { message::Pickup_command_request_msg request; request.ParseFromString(message->get_message_buf()); //清空记录 m_pickup_response_msg=message::Pickup_command_response_msg(); //发送请求 code= Communication_socket_base::encapsulate_msg(message); break; } default: code= Error_manager(ERROR,NEGLIGIBLE_ERROR,"terminal message table is not exist"); } return code; } Error_manager Terminal_communication::execute_msg(Communication_message* p_msg) { if(p_msg->get_message_type()==Communication_message::eStore_command_response_msg) { message::Store_command_response_msg response; if(false==response.ParseFromString(p_msg->get_message_buf())) { return Error_manager(ERROR,CRITICAL_ERROR,"停车指令反馈信息解析错误"); } message::Base_info base_info=response.base_info(); if(base_info.sender()==message::eMain && base_info.receiver()==message::eTerminor) { message::Error_manager error_code=response.code(); if(error_code.error_code()==0) { m_store_response_msg=response; return SUCCESS; } } } if(p_msg->get_message_type()==Communication_message::ePickup_command_response_msg) { message::Pickup_command_response_msg response; if(false==response.ParseFromString(p_msg->get_message_buf())) { return Error_manager(ERROR,CRITICAL_ERROR,"停车指令反馈信息解析错误"); } message::Base_info base_info=response.base_info(); if(base_info.sender()==message::eMain && base_info.receiver()==message::eTerminor) { message::Error_manager error_code=response.code(); if(error_code.error_code()==0) { m_pickup_response_msg=response; return SUCCESS; } } } if(p_msg->get_message_type()==Communication_message::eStoring_process_statu_msg) { message::Storing_process_statu_msg msg; if(msg.ParseFromString(p_msg->get_message_buf())==false) { std::cout<<" ERROR : Storing_process_statu_msg 失败"<get_message_type()==Communication_message::ePicking_process_statu_msg) { message::Picking_process_statu_msg msg; if(msg.ParseFromString(p_msg->get_message_buf())==false) { std::cout<<" ERROR : Picking_process_statu_msg 失败"<(end_time - start_time); time = 1000.0 * double(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den; std::this_thread::yield(); usleep(1000); }while(time(end_time - start_time); time = 1000.0 * double(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den; std::this_thread::yield(); usleep(1000); }while(time(t1 - start); double time = 1000.0 * double(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den; if (time > 3000) { m_storing_statu_time_point_map.erase(license); m_storing_statu_map.erase(license); } else { m_storing_license_queue.push(license); } } if (m_picking_license_queue.try_pop(license)) { std::chrono::system_clock::time_point t1 = std::chrono::system_clock::now(); std::chrono::system_clock::time_point start = m_picking_statu_time_point_map[license]; auto duration = std::chrono::duration_cast(t1 - start); double time = 1000.0 * double(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den; if (time > 3000) { m_picking_statu_time_point_map.erase(license); m_picking_statu_map.erase(license); } else { m_picking_license_queue.push(license); } } } } void Terminal_communication::thread_update_map_function(Terminal_communication *terminal) { terminal->update_map(); }