123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- //
- // Created by zx on 2020/8/20.
- //
- #include "exception_solver.h"
- #include "command_manager.h"
- #include "communication_message.h"
- #include <glog/logging.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::consume_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::eProcess_manual_operation_msg:
- {
- message::Process_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;
- break;
- }
- case Communication_message::eEntrance_manual_operation_msg:
- {
- message::Entrance_manual_operation_msg msg;
- if(msg.ParseFromString(p_msg->get_message_buf())==false)
- {
- LOG(ERROR)<<" 手动消息解析失败 !!!";
- break;
- }
- LOG(INFO)<<" communication 接收到手动消息 : "<<msg.GetTypeName();
- switch (msg.process_type())
- {
- case message::eStoring:
- {
- Command_manager::get_instance_pointer()->pause_entrance(msg.terminal_id(),msg.paused());
- break;
- }
- case message::ePicking:
- {
- Command_manager::get_instance_pointer()->pause_export(msg.terminal_id(),msg.paused());
- break;
- }
- }
- break;
- }
- default:break;
- }
- return SUCCESS;
- }
- /*
- * 等待手动消息
- */
- Error_manager Exception_solver::waitfor_manual_operate_msg(Process_task* task,message::Process_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())
- {
- if(msg.license()==task->license()&& msg.step_type()==task->current_step_type()) {
- LOG(INFO) << " 查询到: " << task->license()<<" 操作类型:"<<Process_operation_type_Name(msg.operate_type());
- return SUCCESS;
- }
- else
- {
- LOG(WARNING)<<"xxxx .. .. 非当前步骤的手动操作 车牌: "<<msg.license()<<", 操作步骤:"<<Step_type_Name(msg.step_type());
- m_manual_msg_map.erase(task->license());
- }
- }
- }
- }
- return TASK_CANCEL;
- }
- /*
- * 处理故障
- */
- Error_manager Exception_solver::solve_exception(Error_manager code,Process_task* task)
- {
- //致命故障,系统急停,取消当前流程.
- if(code.get_error_level()==CRITICAL_ERROR)
- {
- Command_manager::get_instance_pointer()->pause_system();
- task->Cancel();
- return SUCCESS;
- }
- Error_manager code_operate;
- if(task->get_process_type()==message::eStoring)
- {
- switch (task->current_step_type())
- {
- case message::eAlloc_step :
- {
- code=parking_alloc_error_handling(code,task);
- }
- case message::eMeasure_step :
- case message::eCompare_step :
- case message::eDispatch_step :
- {
- }
- case message::eConfirm_step :
- case message::eComplete :
- case message::eBackConfirm_step :
- case message::eBackDispatch_step :
- case message::eBack_compare_step :
- case message::eBackMeasure_step :
- case message::eBackAlloc_step :
- case message::eBackComplete :
- {
- Command_manager::get_instance_pointer()->pause_entrance(task->terminal_id(),true);
- LOG(ERROR)<<"关闭入口:"<<task->terminal_id()<<" 故障 !!!!!! 等待手动操作 ... ";
- message::Process_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:
- {
- LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
- <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
- task->Cancel();
- break;
- }
- case message::eManual_retry:{
- LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
- <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
- break;
- }
- case message::eManual_ignore:
- {
- LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
- <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
- return SUCCESS;
- }
- }
- break;
- }
- }
- }
- if(task->get_process_type()==message::ePicking)
- {
- switch (task->current_step_type())
- {
- case message::eSearch_step :
- case message::eDispatch_step :
- {
- }
- case message::eWait_step :
- case message::eRelease_step :
- case message::eComplete :
- case message::eBackWait_step :
- case message::eBackDispatch_step :
- case message::eBackSearch_step :
- case message::eBackComplete :
- {
- Command_manager::get_instance_pointer()->pause_export(task->terminal_id(),true);
- LOG(ERROR)<<"关闭出口:"<<task->terminal_id()<<" 故障 !!!!!! 等待手动操作 ...";
- message::Process_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:
- {
- LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
- <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
- task->Cancel();
- break;
- }
- case message::eManual_retry:{
- LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
- <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
- break;
- }
- case message::eManual_ignore:
- {
- LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
- <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
- return SUCCESS;
- }
- }
- break;
- }
- }
- }
- return code;
- }
- Error_manager Exception_solver::parking_alloc_error_handling(Error_manager code,Process_task* task)
- {
- LOG(INFO) << "分配车位错误处理 ,车牌号 : " << task->license() ;
- static unsigned short perform_count = 0;
- switch (code.get_error_code())
- {
- case 0:
- //重新执行
- if (perform_count == 3)
- {
- task->next_step();
- }
- perform_count++;
- return code;
- case 1:
- //异常无法处理,回退x-special/nautilus-clipboard
- //copy
- //file:///home/wk/D_disk/wk/ChuTian_project/main_control/Terminal_process_CT/exception/exception_solver.cpp
- //file:///home/wk/D_disk/wk/ChuTian_project/main_control/Terminal_process_CT/exception/exception_solver.h
- task->updata_step_statu(message::eError);
- task->next_step();
- perform_count = 0;
- return code;
- case 2:
- //code = .....handle
- //异常已经处理,且恢复
- if (code == SUCCESS)
- {
- //处理成功
- task->updata_step_statu(message::eFinished);
- task->next_step();
- }
- else
- {
- //修复失败,回退
- task->updata_step_statu(message::eError);
- task->next_step();
- }
- perform_count = 0;
- return code;
- case 3:
- task->Cancel();
- perform_count = 0;
- return code;
- }
- return SUCCESS;
- }
|