// // Created by zx on 2020/8/20. // #include "exception_solver.h" #include "command_manager.h" #include "communication_message.h" Exception_solver::Exception_solver() { } Exception_solver::~Exception_solver() { } Error_manager Exception_solver::add_task_cancel_condition(std::string license,Process_task* task) { if(m_ptask_map.find(license)==true || task== nullptr) { return Error_manager(ERROR,MINOR_ERROR,"任务标识已存在,或者标识地址为null"); } m_ptask_map[license]=task; return SUCCESS; } Error_manager Exception_solver::delete_task_cancel_condition(std::string license) { if(m_ptask_map.find(license)==true) { m_ptask_map.erase(license); return SUCCESS; } return Error_manager(ERROR,MINOR_ERROR,"任务取消标志不存在"); } Error_manager Exception_solver::encapsulate_msg(Communication_message* message) { Error_manager code; //记录请求 switch (message->get_message_type()) { default: code= Communication_socket_base::encapsulate_msg(message); break; } return code; } Error_manager Exception_solver::execute_msg(Communication_message* p_msg) { if(p_msg== nullptr) return Error_manager(POINTER_IS_NULL,CRITICAL_ERROR,"dispatch response msg pointer is null"); switch (p_msg->get_message_type()) { case Communication_message::eManual_operation_msg: { message::Manual_operation_msg msg; if(msg.ParseFromString(p_msg->get_message_buf())==false) { LOG(ERROR)<<" 手动消息解析失败 !!!"; break; } if(msg.has_license()==false) { LOG(ERROR)<<" 手动消息解析失败 !!!"; break; } m_manual_msg_map[msg.license()]=msg; } default:break; } return SUCCESS; } /* * 检测消息是否可被处理 */ Error_manager Exception_solver::check_msg(Communication_message* p_msg) { //通过 p_msg->get_message_type() 和 p_msg->get_receiver() 判断这条消息是不是给我的. //子类重载时, 增加自己模块的判断逻辑, 以后再写. /*if ( (p_msg->get_message_type() == Communication_message::Message_type::eDispatch_response_msg ||p_msg->get_message_type() == Communication_message::Message_type::eDispatch_status_msg) && p_msg->get_receiver() == Communication_message::Communicator::eMain ) { return Error_code::SUCCESS; } else { //认为接受人 return Error_code::INVALID_MESSAGE; }*/ } /* * 心跳发送函数,重载 */ Error_manager Exception_solver::encapsulate_send_data() { return SUCCESS; } //检查消息是否可以被解析, 需要重载 Error_manager Exception_solver::check_executer(Communication_message* p_msg) { return SUCCESS; } /* * 等待手动消息 */ Error_manager Exception_solver::waitfor_manual_operate_msg(Process_task* task,message::Manual_operation_msg msg) { //清除旧的手动操作消息 if(m_manual_msg_map.find(task->license())) m_manual_msg_map.erase(task->license()); //监控新的手动操作消息 while(task->is_canceled()==false) { if(m_manual_msg_map.find(task->license(),msg)) { if(msg.has_base_info() && msg.has_license() && msg.has_operate_type() && msg.has_step_type()) { return SUCCESS; } } } return TASK_CANCEL; } /* * 处理故障 */ Error_manager Exception_solver::solve_exception(Error_manager code,Process_task* task) { Error_manager code_operate; if(code.get_error_level()==CRITICAL_ERROR) { //四级故障,任务未完成, 且模块未能回退并恢复到初始待机状态 //关闭出入口 if(task->GetCategory()==message::eStoring) { Command_manager::get_instance_pointer()->enable_entrance(task->terminal_id(),Command_manager::Entrance_statu::Disable); LOG(ERROR)<<"关闭入口:"<terminal_id()<<" 四级故障 !!!!!! 等待手动操作 ... "; message::Manual_operation_msg operate_msg; code_operate=waitfor_manual_operate_msg(task,operate_msg); if(code_operate!=SUCCESS) return code_operate; switch (operate_msg.operate_type()) { //取消任务 case message::eManual_cancel: { task->Cancel(); return SUCCESS; } } } if(task->GetCategory()==message::ePicking) { Command_manager::get_instance_pointer()->enable_export(task->terminal_id(),Command_manager::Entrance_statu::Disable); LOG(ERROR)<<"关闭出口:"<terminal_id()<<" 四级故障 !!!!!! 等待手动操作 ..."; message::Manual_operation_msg operate_msg; code_operate=waitfor_manual_operate_msg(task,operate_msg); if(code_operate!=SUCCESS) return code_operate; } //系统急停 //Command_manager::get_instance_pointer()->pause_system(); } if(code.get_error_level()<=MAJOR_ERROR) { //三级故障, 任务未完成,已恢复到待机状态 return SUCCESS; } switch(code.get_error_code()) { case ERROR: { break; } } return SUCCESS; }