exception_solver.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. //致命故障,系统急停,取消当前流程.
  116. if(code.get_error_level()==CRITICAL_ERROR)
  117. {
  118. Command_manager::get_instance_pointer()->pause_system();
  119. task->Cancel();
  120. return SUCCESS;
  121. }
  122. Error_manager code_operate;
  123. if(task->get_process_type()==message::eStoring)
  124. {
  125. switch (task->current_step_type())
  126. {
  127. case message::eAlloc_step :
  128. {
  129. code=parking_alloc_error_handling(code,task);
  130. }
  131. case message::eMeasure_step :
  132. case message::eCompare_step :
  133. case message::eDispatch_step :
  134. {
  135. }
  136. case message::eConfirm_step :
  137. case message::eComplete :
  138. case message::eBackConfirm_step :
  139. case message::eBackDispatch_step :
  140. case message::eBack_compare_step :
  141. case message::eBackMeasure_step :
  142. case message::eBackAlloc_step :
  143. case message::eBackComplete :
  144. {
  145. Command_manager::get_instance_pointer()->pause_entrance(task->terminal_id(),true);
  146. LOG(ERROR)<<"关闭入口:"<<task->terminal_id()<<" 故障 !!!!!! 等待手动操作 ... ";
  147. message::Process_manual_operation_msg operate_msg;
  148. code_operate=waitfor_manual_operate_msg(task,operate_msg);
  149. if(code_operate!=SUCCESS)
  150. return code_operate;
  151. switch (operate_msg.operate_type())
  152. {
  153. //取消任务
  154. case message::eManual_cancel:
  155. {
  156. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
  157. <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  158. task->Cancel();
  159. break;
  160. }
  161. case message::eManual_retry:{
  162. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
  163. <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  164. break;
  165. }
  166. case message::eManual_ignore:
  167. {
  168. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
  169. <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  170. return SUCCESS;
  171. }
  172. }
  173. break;
  174. }
  175. }
  176. }
  177. if(task->get_process_type()==message::ePicking)
  178. {
  179. switch (task->current_step_type())
  180. {
  181. case message::eSearch_step :
  182. case message::eDispatch_step :
  183. {
  184. }
  185. case message::eWait_step :
  186. case message::eRelease_step :
  187. case message::eComplete :
  188. case message::eBackWait_step :
  189. case message::eBackDispatch_step :
  190. case message::eBackSearch_step :
  191. case message::eBackComplete :
  192. {
  193. Command_manager::get_instance_pointer()->pause_export(task->terminal_id(),true);
  194. LOG(ERROR)<<"关闭出口:"<<task->terminal_id()<<" 故障 !!!!!! 等待手动操作 ...";
  195. message::Process_manual_operation_msg operate_msg;
  196. code_operate=waitfor_manual_operate_msg(task,operate_msg);
  197. if(code_operate!=SUCCESS)
  198. return code_operate;
  199. switch (operate_msg.operate_type())
  200. {
  201. //取消任务
  202. case message::eManual_cancel:
  203. {
  204. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
  205. <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  206. task->Cancel();
  207. break;
  208. }
  209. case message::eManual_retry:{
  210. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
  211. <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  212. break;
  213. }
  214. case message::eManual_ignore:
  215. {
  216. LOG(INFO) << "手动消息 ,车牌号 : " << task->license()
  217. <<" 操作类型:"<<Process_operation_type_Name(operate_msg.operate_type());
  218. return SUCCESS;
  219. }
  220. }
  221. break;
  222. }
  223. }
  224. }
  225. return code;
  226. }
  227. Error_manager Exception_solver::parking_alloc_error_handling(Error_manager code,Process_task* task)
  228. {
  229. LOG(INFO) << "分配车位错误处理 ,车牌号 : " << task->license() ;
  230. static unsigned short perform_count = 0;
  231. switch (code.get_error_code())
  232. {
  233. case 0:
  234. //重新执行
  235. if (perform_count == 3)
  236. {
  237. task->next_step();
  238. }
  239. perform_count++;
  240. return code;
  241. case 1:
  242. //异常无法处理,回退x-special/nautilus-clipboard
  243. //copy
  244. //file:///home/wk/D_disk/wk/ChuTian_project/main_control/Terminal_process_CT/exception/exception_solver.cpp
  245. //file:///home/wk/D_disk/wk/ChuTian_project/main_control/Terminal_process_CT/exception/exception_solver.h
  246. task->updata_step_statu(message::eError);
  247. task->next_step();
  248. perform_count = 0;
  249. return code;
  250. case 2:
  251. //code = .....handle
  252. //异常已经处理,且恢复
  253. if (code == SUCCESS)
  254. {
  255. //处理成功
  256. task->updata_step_statu(message::eFinished);
  257. task->next_step();
  258. }
  259. else
  260. {
  261. //修复失败,回退
  262. task->updata_step_statu(message::eError);
  263. task->next_step();
  264. }
  265. perform_count = 0;
  266. return code;
  267. case 3:
  268. task->Cancel();
  269. perform_count = 0;
  270. return code;
  271. }
  272. return SUCCESS;
  273. }