exception_solver.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // Created by zx on 2020/8/20.
  3. //
  4. #include "exception_solver.h"
  5. #include "command_manager.h"
  6. #include "communication_message.h"
  7. Exception_solver::Exception_solver() {
  8. }
  9. Exception_solver::~Exception_solver() {
  10. }
  11. Error_manager Exception_solver::add_task_cancel_condition(std::string license,Process_task* task)
  12. {
  13. if(m_ptask_map.find(license)==true || task== nullptr)
  14. {
  15. return Error_manager(ERROR,MINOR_ERROR,"任务标识已存在,或者标识地址为null");
  16. }
  17. m_ptask_map[license]=task;
  18. return SUCCESS;
  19. }
  20. Error_manager Exception_solver::delete_task_cancel_condition(std::string license)
  21. {
  22. if(m_ptask_map.find(license)==true)
  23. {
  24. m_ptask_map.erase(license);
  25. return SUCCESS;
  26. }
  27. return Error_manager(ERROR,MINOR_ERROR,"任务取消标志不存在");
  28. }
  29. Error_manager Exception_solver::encapsulate_msg(Communication_message* message)
  30. {
  31. Error_manager code;
  32. //记录请求
  33. switch (message->get_message_type())
  34. {
  35. default:
  36. code= Communication_socket_base::encapsulate_msg(message);
  37. break;
  38. }
  39. return code;
  40. }
  41. Error_manager Exception_solver::execute_msg(Communication_message* p_msg)
  42. {
  43. if(p_msg== nullptr)
  44. return Error_manager(POINTER_IS_NULL,CRITICAL_ERROR,"dispatch response msg pointer is null");
  45. switch (p_msg->get_message_type())
  46. {
  47. case Communication_message::eManual_operation_msg:
  48. {
  49. message::Manual_operation_msg msg;
  50. if(msg.ParseFromString(p_msg->get_message_buf())==false)
  51. {
  52. LOG(ERROR)<<" 手动消息解析失败 !!!";
  53. break;
  54. }
  55. if(msg.has_license()==false)
  56. {
  57. LOG(ERROR)<<" 手动消息解析失败 !!!";
  58. break;
  59. }
  60. LOG(INFO)<<"接收到手动消息////////////////////////// : "<<msg.license();
  61. m_manual_msg_map[msg.license()]=msg;
  62. }
  63. default:break;
  64. }
  65. return SUCCESS;
  66. }
  67. /*
  68. * 检测消息是否可被处理
  69. */
  70. Error_manager Exception_solver::check_msg(Communication_message* p_msg)
  71. {
  72. return SUCCESS;
  73. }
  74. /*
  75. * 心跳发送函数,重载
  76. */
  77. Error_manager Exception_solver::encapsulate_send_data()
  78. {
  79. return SUCCESS;
  80. }
  81. //检查消息是否可以被解析, 需要重载
  82. Error_manager Exception_solver::check_executer(Communication_message* p_msg)
  83. {
  84. return SUCCESS;
  85. }
  86. /*
  87. * 等待手动消息
  88. */
  89. Error_manager Exception_solver::waitfor_manual_operate_msg(Process_task* task,message::Manual_operation_msg msg)
  90. {
  91. //清除旧的手动操作消息
  92. if(m_manual_msg_map.find(task->license()))
  93. m_manual_msg_map.erase(task->license());
  94. //监控新的手动操作消息
  95. while(task->is_canceled()==false)
  96. {
  97. if(m_manual_msg_map.find(task->license(),msg))
  98. {
  99. if(msg.has_base_info() && msg.has_license() && msg.has_operate_type() && msg.has_step_type())
  100. {
  101. LOG(INFO)<<"查询到手动消息||||||||||||||| : "<<msg.license();
  102. return SUCCESS;
  103. }
  104. }
  105. }
  106. return TASK_CANCEL;
  107. }
  108. /*
  109. * 处理故障
  110. */
  111. Error_manager Exception_solver::solve_exception(Error_manager code,Process_task* task)
  112. {
  113. Error_manager code_operate;
  114. if(code.get_error_level()==CRITICAL_ERROR)
  115. {
  116. //四级故障,任务未完成, 且模块未能回退并恢复到初始待机状态
  117. //关闭出入口
  118. if(task->GetCategory()==message::eStoring) {
  119. Command_manager::get_instance_pointer()->enable_entrance(task->terminal_id(),Command_manager::Entrance_statu::Disable);
  120. LOG(ERROR)<<"关闭入口:"<<task->terminal_id()<<" 四级故障 !!!!!! 等待手动操作 ... ";
  121. message::Manual_operation_msg operate_msg;
  122. code_operate=waitfor_manual_operate_msg(task,operate_msg);
  123. if(code_operate!=SUCCESS)
  124. return code_operate;
  125. switch (operate_msg.operate_type())
  126. {
  127. //取消任务
  128. case message::eManual_cancel: {
  129. task->Cancel();
  130. return SUCCESS;
  131. }
  132. }
  133. }
  134. if(task->GetCategory()==message::ePicking) {
  135. Command_manager::get_instance_pointer()->enable_export(task->terminal_id(),Command_manager::Entrance_statu::Disable);
  136. LOG(ERROR)<<"关闭出口:"<<task->terminal_id()<<" 四级故障 !!!!!! 等待手动操作 ...";
  137. message::Manual_operation_msg operate_msg;
  138. code_operate=waitfor_manual_operate_msg(task,operate_msg);
  139. if(code_operate!=SUCCESS)
  140. return code_operate;
  141. }
  142. //系统急停
  143. //Command_manager::get_instance_pointer()->pause_system();
  144. }
  145. if(code.get_error_level()<=MAJOR_ERROR)
  146. {
  147. //三级故障, 任务未完成,已恢复到待机状态
  148. return SUCCESS;
  149. }
  150. switch(code.get_error_code())
  151. {
  152. case ERROR:
  153. {
  154. break;
  155. }
  156. }
  157. return SUCCESS;
  158. }