exception_solver.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #include <glog/logging.h>
  8. Exception_solver::Exception_solver() {
  9. }
  10. Exception_solver::~Exception_solver() {
  11. }
  12. Error_manager Exception_solver::add_task_cancel_condition(std::string license,Process_task* task)
  13. {
  14. if(m_ptask_map.find(license)==true || task== nullptr)
  15. {
  16. return Error_manager(ERROR,MINOR_ERROR,"任务标识已存在,或者标识地址为null");
  17. }
  18. m_ptask_map[license]=task;
  19. return SUCCESS;
  20. }
  21. Error_manager Exception_solver::delete_task_cancel_condition(std::string license)
  22. {
  23. if(m_ptask_map.find(license)==true)
  24. {
  25. m_ptask_map.erase(license);
  26. return SUCCESS;
  27. }
  28. return Error_manager(ERROR,MINOR_ERROR,"任务取消标志不存在");
  29. }
  30. Error_manager Exception_solver::consume_msg(Communication_message* p_msg)
  31. {
  32. if(p_msg== nullptr)
  33. return Error_manager(POINTER_IS_NULL,CRITICAL_ERROR,"dispatch response msg pointer is null");
  34. switch (p_msg->get_message_type())
  35. {
  36. case Communication_message::eProcess_manual_operation_msg:
  37. {
  38. message::Process_manual_operation_msg msg;
  39. if(msg.ParseFromString(p_msg->get_message_buf())==false)
  40. {
  41. LOG(ERROR)<<" 手动消息解析失败 !!!";
  42. break;
  43. }
  44. if(msg.has_license()==false)
  45. {
  46. LOG(ERROR)<<" 手动消息解析失败 !!!";
  47. break;
  48. }
  49. LOG(INFO)<<"接收到手动消息////////////////////////// : "<<msg.license();
  50. m_manual_msg_map[msg.license()]=msg;
  51. break;
  52. }
  53. case Communication_message::eEntrance_manual_operation_msg:
  54. {
  55. message::Entrance_manual_operation_msg msg;
  56. if(msg.ParseFromString(p_msg->get_message_buf())==false)
  57. {
  58. LOG(ERROR)<<" 手动消息解析失败 !!!";
  59. break;
  60. }
  61. LOG(INFO)<<" communication 接收到手动消息 : "<<msg.GetTypeName();
  62. switch (msg.process_type())
  63. {
  64. case message::eStoring:
  65. {
  66. Command_manager::get_instance_pointer()->pause_entrance(msg.terminal_id(),msg.paused());
  67. break;
  68. }
  69. case message::ePicking:
  70. {
  71. Command_manager::get_instance_pointer()->pause_export(msg.terminal_id(),msg.paused());
  72. break;
  73. }
  74. }
  75. break;
  76. }
  77. default:break;
  78. }
  79. return SUCCESS;
  80. }
  81. /*
  82. * 等待手动消息
  83. */
  84. Error_manager Exception_solver::waitfor_manual_operate_msg(Process_task* task,message::Process_manual_operation_msg& msg)
  85. {
  86. //清除旧的手动操作消息
  87. if(m_manual_msg_map.find(task->license()))
  88. m_manual_msg_map.erase(task->license());
  89. //监控新的手动操作消息
  90. while(task->is_canceled()==false)
  91. {
  92. if(m_manual_msg_map.find(task->license(),msg))
  93. {
  94. if(msg.has_base_info() && msg.has_license() && msg.has_operate_type() && msg.has_step_type())
  95. {
  96. if(msg.license()==task->license()&& msg.step_type()==task->current_step_type()) {
  97. LOG(INFO) << " 查询到: " << task->license()<<" 操作类型:"<<Process_operation_type_Name(msg.operate_type());
  98. return SUCCESS;
  99. }
  100. else
  101. {
  102. LOG(WARNING)<<"xxxx .. .. 非当前步骤的手动操作 车牌: "<<msg.license()<<", 操作步骤:"<<Step_type_Name(msg.step_type());
  103. m_manual_msg_map.erase(task->license());
  104. }
  105. }
  106. }
  107. }
  108. return TASK_CANCEL;
  109. }
  110. /*
  111. * 处理故障
  112. */
  113. Error_manager Exception_solver::solve_exception(Error_manager code,Process_task* task)
  114. {
  115. Error_manager code_operate;
  116. if(code.get_error_level()==MAJOR_ERROR)
  117. {
  118. //四级故障,任务未完成, 且模块未能回退并恢复到初始待机状态
  119. //关闭出入口
  120. if(task->get_process_type()==message::eStoring) {
  121. Command_manager::get_instance_pointer()->pause_entrance(task->terminal_id(),true);
  122. LOG(ERROR)<<"关闭入口:"<<task->terminal_id()<<" 故障 !!!!!! 等待手动操作 ... ";
  123. message::Process_manual_operation_msg operate_msg;
  124. code_operate=waitfor_manual_operate_msg(task,operate_msg);
  125. if(code_operate!=SUCCESS)
  126. return code_operate;
  127. switch (operate_msg.operate_type())
  128. {
  129. //取消任务
  130. case message::eManual_cancel:
  131. {
  132. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()<<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  133. task->Cancel();
  134. break;
  135. }
  136. case message::eManual_retry:{
  137. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()<<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  138. break;
  139. }
  140. case message::eManual_ignore:
  141. {
  142. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()<<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  143. task->next_step();
  144. break;
  145. }
  146. }
  147. }
  148. if(task->get_process_type()==message::ePicking) {
  149. Command_manager::get_instance_pointer()->pause_export(task->terminal_id(),true);
  150. LOG(ERROR)<<"关闭出口:"<<task->terminal_id()<<" 四级故障 !!!!!! 等待手动操作 ...";
  151. message::Process_manual_operation_msg operate_msg;
  152. code_operate=waitfor_manual_operate_msg(task,operate_msg);
  153. if(code_operate!=SUCCESS)
  154. return code_operate;
  155. }
  156. //系统急停
  157. //Command_manager::get_instance_pointer()->pause_system();
  158. }
  159. if(code.get_error_level()<=MAJOR_ERROR)
  160. {
  161. //三级故障, 任务未完成,已恢复到待机状态
  162. return SUCCESS;
  163. }
  164. switch(code.get_error_code())
  165. {
  166. case ERROR:
  167. {
  168. break;
  169. }
  170. }
  171. return SUCCESS;
  172. }