123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // 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;
- }
- LOG(INFO)<<"接收到手动消息////////////////////////// : "<<msg.license();
- m_manual_msg_map[msg.license()]=msg;
- }
- default:break;
- }
- return SUCCESS;
- }
- /*
- * 检测消息是否可被处理
- */
- Error_manager Exception_solver::check_msg(Communication_message* p_msg)
- {
- return SUCCESS;
- }
- /*
- * 心跳发送函数,重载
- */
- 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())
- {
- LOG(INFO)<<"查询到手动消息||||||||||||||| : "<<msg.license();
- 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)<<"关闭入口:"<<task->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)<<"关闭出口:"<<task->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;
- }
|