StoreProcessTask.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. //
  2. // Created by zx on 2020/7/7.
  3. //
  4. #include <parkspace_excutor.h>
  5. #include <dispatch_message.pb.h>
  6. #include "dispatch_excutor.h"
  7. #include "StoreProcessTask.h"
  8. #include "process_message.pb.h"
  9. #include "command_manager.h"
  10. #include "command_accepter.h"
  11. #include "exception_solver.h"
  12. #include "uniq_key.h"
  13. StoreProcessTask::StoreProcessTask(unsigned int terminor_id,message::Car_info car_info)
  14. :Process_task(terminor_id,car_info)
  15. {
  16. }
  17. StoreProcessTask::~StoreProcessTask()
  18. {
  19. Exception_solver::get_instance_pointer()->delete_task_cancel_condition(m_car_info.license());
  20. }
  21. Error_manager StoreProcessTask::init_task(message::Locate_information locate_info)
  22. {
  23. reset_msg();
  24. m_locate_info=locate_info;
  25. //添加当前流程的任务取消标志位到异常处理模块
  26. m_cancel_condition.reset(false, false, false);
  27. Error_manager code=Exception_solver::get_instance_pointer()->add_task_cancel_condition(m_car_info.license(),this);
  28. if(code!=SUCCESS)
  29. return code;
  30. //初始化进度状态消息基本信息
  31. message::Base_info base_info;
  32. base_info.set_msg_type(message::eStoring_process_statu_msg);
  33. base_info.set_sender(message::eMain);
  34. base_info.set_receiver(message::eEmpty);
  35. m_process_msg.mutable_base_info()->CopyFrom(base_info);
  36. m_process_msg.set_terminal_id(m_terminor_id);
  37. m_process_msg.set_license(m_car_info.license());
  38. m_current_step_type=message::eAlloc_step;
  39. ///创建状态发布线程
  40. if(m_publish_statu_thread== nullptr)
  41. {
  42. m_publish_exit_condition.reset(false, false, false);
  43. m_publish_statu_thread=new std::thread(publish_thread_func,this);
  44. }
  45. return SUCCESS;
  46. }
  47. Error_manager StoreProcessTask::locate_step() {
  48. Error_manager code;
  49. //检查测量模块状态
  50. code=Measure_excutor::get_instance_pointer()->check_statu(m_terminor_id);
  51. if(code!=SUCCESS)
  52. return code;
  53. message::Base_info base_info;
  54. base_info.set_msg_type(message::eLocate_request_msg);
  55. base_info.set_sender(message::eMain);
  56. base_info.set_receiver(message::eMeasurer);
  57. base_info.set_timeout_ms(20000); //测量超时5s
  58. m_measure_request_msg.mutable_base_info()->CopyFrom(base_info);
  59. m_measure_request_msg.set_terminal_id(m_terminor_id);
  60. code=Measure_excutor::get_instance_pointer()->locate_request(m_measure_request_msg,
  61. m_measure_response_msg,m_cancel_condition);
  62. if(code!=SUCCESS)
  63. return code;
  64. if(m_measure_response_msg.error_manager().error_code()==0) {
  65. return SUCCESS;
  66. }
  67. else {
  68. Error_code t_code=(Error_code)m_measure_response_msg.error_manager().error_code();
  69. Error_level t_level=(Error_level)m_measure_response_msg.error_manager().error_level();
  70. return Error_manager(t_code, t_level, m_measure_response_msg.error_manager().error_description().c_str());
  71. }
  72. }
  73. /*
  74. * 回退定位
  75. */
  76. Error_manager StoreProcessTask::back_locate_step()
  77. {
  78. m_measure_request_msg=message::Measure_request_msg();
  79. m_measure_response_msg=message::Measure_response_msg();
  80. int k=rand()%5;
  81. if(k==0)
  82. return Error_manager(ERROR,CRITICAL_ERROR,"回退测量对比失败");
  83. return SUCCESS;
  84. }
  85. /*
  86. * 检验结果
  87. */
  88. Error_manager StoreProcessTask::compare_step()
  89. {
  90. return SUCCESS;
  91. }
  92. /*
  93. * 回退检验
  94. */
  95. Error_manager StoreProcessTask::back_compare_step()
  96. {
  97. int k=rand()%5;
  98. if(k==0)
  99. return Error_manager(ERROR,CRITICAL_ERROR,"回退检验对比失败");
  100. return SUCCESS;
  101. }
  102. /*
  103. * 调度
  104. */
  105. Error_manager StoreProcessTask::dispatch_step()
  106. {
  107. Error_manager code;
  108. /*
  109. * 判断调度所需的数据是否都正常
  110. */
  111. //1,测量信息是否存在
  112. if(m_measure_response_msg.has_base_info()== false
  113. ||m_measure_response_msg.has_locate_information()==false
  114. ||m_parcspace_alloc_response_msg.has_base_info()== false
  115. ||m_parcspace_alloc_response_msg.has_allocated_space_info()==false)
  116. {
  117. return Error_manager(ERROR,MAJOR_ERROR,"调度所需的前置数据(测量,车位)不存在");
  118. }
  119. //2,判断调度节点状态
  120. code=Dispatch_excutor::get_instance_pointer()->check_entrance_statu(m_terminor_id);
  121. if(code!=SUCCESS)
  122. return code;
  123. message::Base_info base_info;
  124. base_info.set_msg_type(message::eDispatch_request_msg);
  125. base_info.set_sender(message::eMain);
  126. base_info.set_receiver(message::eDispatch);
  127. base_info.set_timeout_ms(1000*15); //超时15s
  128. m_dispatch_request_msg.mutable_base_info()->CopyFrom(base_info);
  129. m_dispatch_request_msg.set_terminal_id(m_terminor_id);
  130. m_dispatch_request_msg.set_dispatch_motion_direction(message::E_STORE_CAR);
  131. m_dispatch_request_msg.set_parkspace_id(m_parcspace_alloc_response_msg.allocated_space_info().parkspace_id());
  132. code=Dispatch_excutor::get_instance_pointer()->dispatch_request(m_dispatch_request_msg,
  133. m_dispatch_response_msg,m_cancel_condition);
  134. if(code!=SUCCESS)
  135. return code;
  136. if(m_dispatch_response_msg.error_manager().error_code()==0) {
  137. return SUCCESS;
  138. }
  139. else
  140. {
  141. Error_code t_code=(Error_code)m_dispatch_response_msg.error_manager().error_code();
  142. Error_level t_level=(Error_level)m_dispatch_response_msg.error_manager().error_level();
  143. return Error_manager(t_code,t_level,"dispatch response error_code error");
  144. }
  145. }
  146. /*
  147. * 回退调度
  148. */
  149. Error_manager StoreProcessTask::back_dispatch_step()
  150. {
  151. //reset 调度请求数据
  152. m_dispatch_request_msg=message::Dispatch_request_msg();
  153. m_dispatch_response_msg=message::Dispatch_response_msg();
  154. return SUCCESS;
  155. }
  156. /*
  157. * 分配车位
  158. */
  159. Error_manager StoreProcessTask::alloc_space_step()
  160. {
  161. message::Base_info base_info_response;
  162. base_info_response.set_msg_type(message::eStore_command_response_msg);
  163. base_info_response.set_sender(message::eMain);
  164. base_info_response.set_receiver(message::eTerminor);
  165. m_command_response_msg.mutable_base_info()->CopyFrom(base_info_response);
  166. m_command_response_msg.set_terminal_id(m_terminor_id);
  167. if(Command_manager::get_instance_pointer()->is_paused()==true)
  168. {
  169. return Error_manager(PAUSE, MINOR_ERROR, "系统已急停");
  170. }
  171. //
  172. message::Entrance_statu statu=Command_manager::get_instance_pointer()->entrance_statu(m_terminor_id);
  173. if(statu.has_paused()==false) {
  174. return Error_manager(ERROR, MINOR_ERROR, "入口已禁止使用 Disable");
  175. }
  176. if(statu.paused()==true)
  177. {
  178. return Error_manager(ERROR, MINOR_ERROR, "入口已禁止使用 Disable");
  179. }
  180. /*
  181. * 检查是否有测量数据
  182. */
  183. if(m_locate_info.has_locate_height()==false||m_locate_info.has_locate_width()==false)
  184. {
  185. return Error_manager(FAILED,MINOR_ERROR,"停车请求缺少车辆高度和宽度信息");
  186. }
  187. /*
  188. * 检查车位管理模块是否正常
  189. */
  190. Error_manager code=Parkspace_excutor::get_instance_pointer()->check_statu();
  191. if(code!=SUCCESS)
  192. {
  193. return code;
  194. }
  195. //发送分配请求
  196. message::Base_info base_info_request;
  197. base_info_request.set_msg_type(message::eParkspace_allocation_request_msg);
  198. base_info_request.set_sender(message::eMain);
  199. base_info_request.set_receiver(message::eParkspace);
  200. base_info_request.set_timeout_ms(5000); //超时1s
  201. m_alloc_request_msg.mutable_base_info()->CopyFrom(base_info_request);
  202. m_alloc_request_msg.mutable_car_info()->CopyFrom(m_car_info);
  203. m_alloc_request_msg.set_terminal_id(m_terminor_id);
  204. code=Parkspace_excutor::get_instance_pointer()->alloc_request(m_alloc_request_msg,
  205. m_parcspace_alloc_response_msg,m_cancel_condition);
  206. if(code!=SUCCESS)
  207. {
  208. return code;
  209. }
  210. if(m_parcspace_alloc_response_msg.error_manager().error_code()==0)
  211. {
  212. message::Car_info alloc_car_info=m_parcspace_alloc_response_msg.allocated_space_info().car_info();
  213. if(alloc_car_info.license()!=m_car_info.license())
  214. {
  215. return Error_manager(ERROR,MINOR_ERROR,"分配车位反馈的车辆信息不匹配");
  216. }
  217. return SUCCESS;
  218. }
  219. else
  220. {
  221. Error_code t_code=(Error_code)m_parcspace_alloc_response_msg.error_manager().error_code();
  222. Error_level t_level=(Error_level)m_parcspace_alloc_response_msg.error_manager().error_level();
  223. return Error_manager(t_code,t_level,"分配车位反馈结果错误");
  224. }
  225. }
  226. /*
  227. * 车位占用确认
  228. */
  229. Error_manager StoreProcessTask::confirm_space_step()
  230. {
  231. /*
  232. * 检查车位管理模块是否正常
  233. */
  234. Error_manager code=Parkspace_excutor::get_instance_pointer()->check_statu();
  235. if(code!=SUCCESS)
  236. return code;
  237. message::Parkspace_confirm_alloc_request_msg request;
  238. message::Base_info base_info;
  239. base_info.set_msg_type(message::eParkspace_confirm_alloc_request_msg);
  240. base_info.set_sender(message::eMain);
  241. base_info.set_receiver(message::eParkspace);
  242. base_info.set_timeout_ms(5000); //测量超时1s
  243. request.mutable_base_info()->CopyFrom(base_info);
  244. message::Parkspace_info space_info=m_parcspace_alloc_response_msg.allocated_space_info();
  245. request.mutable_confirm_space_info()->CopyFrom(space_info);
  246. request.set_command_key(create_key());
  247. message::Parkspace_confirm_alloc_response_msg confirm_response;
  248. code=Parkspace_excutor::get_instance_pointer()->confirm_request(request,confirm_response,m_cancel_condition);
  249. if(code!=SUCCESS)
  250. return code;
  251. if(m_parcspace_alloc_response_msg.allocated_space_info().parkspace_id()!=
  252. confirm_response.confirm_alloc_space_info().parkspace_id())
  253. {
  254. return Error_manager(ERROR,MINOR_ERROR,"占用车位与分配车位不一致");
  255. }
  256. if(confirm_response.error_manager().error_code()==0) {
  257. /*LOG(INFO)<<"停车流程正常,确认占用车位成功,停车终端:"<<m_terminor_id
  258. <<", 指令id:"<<m_command_info.place()+m_command_info.time()
  259. <<", 车位楼层:"<<confirm_response.confirm_alloc_space_info().floor()
  260. <<", 车位序号:"<<confirm_response.confirm_alloc_space_info().index()
  261. <<", 车牌号:"<<confirm_response.confirm_alloc_space_info().car_info().license();*/
  262. return SUCCESS;
  263. }
  264. else
  265. {
  266. Error_code t_code=(Error_code)confirm_response.error_manager().error_code();
  267. Error_level t_level=(Error_level)confirm_response.error_manager().error_level();
  268. return Error_manager(t_code,t_level,"parkspace confirm response error_code error");
  269. }
  270. }
  271. /*
  272. * 回退车位分配
  273. */
  274. Error_manager StoreProcessTask::back_alloc_space_step()
  275. {
  276. int k=rand()%5;
  277. if(k==0)
  278. return Error_manager(ERROR,CRITICAL_ERROR,"回退车位分配失败");
  279. /*
  280. * 检查是否曾经分配过车位
  281. */
  282. if(m_parcspace_alloc_response_msg.has_allocated_space_info()==false)
  283. {
  284. return Error_manager(FAILED,CRITICAL_ERROR," parkspace release request without space info");
  285. }
  286. /*
  287. * 检查车位管理模块是否正常
  288. */
  289. Error_manager code=Parkspace_excutor::get_instance_pointer()->check_statu();
  290. if(code!=SUCCESS)
  291. return Error_manager(code.get_error_code(),CRITICAL_ERROR,code.get_error_description());
  292. message::Parkspace_release_request_msg request;
  293. message::Base_info base_info;
  294. base_info.set_msg_type(message::eParkspace_release_request_msg);
  295. base_info.set_sender(message::eMain);
  296. base_info.set_receiver(message::eParkspace);
  297. base_info.set_timeout_ms(5000); //测量超时1s
  298. request.mutable_base_info()->CopyFrom(base_info);
  299. message::Parkspace_info space_info=m_parcspace_alloc_response_msg.allocated_space_info();
  300. request.mutable_release_space_info()->CopyFrom(space_info);
  301. message::Parkspace_release_response_msg release_response;
  302. code=Parkspace_excutor::get_instance_pointer()->release_request(request,release_response,m_cancel_condition);
  303. if(code!=SUCCESS)
  304. return Error_manager(code.get_error_code(),CRITICAL_ERROR,code.get_error_description());
  305. if(release_response.error_manager().error_code()==0) {
  306. /*LOG(WARNING)<<"停车流程异常,释放车位成功,停车终端:"<<m_terminor_id
  307. <<", 指令id:"<<m_command_info.place()+m_command_info.time()
  308. <<", 车位楼层:"<<m_parcspace_alloc_response_msg.allocated_space_info().floor()
  309. <<", 车位序号:"<<m_parcspace_alloc_response_msg.allocated_space_info().index()
  310. <<", 车牌号:"<<m_parcspace_alloc_response_msg.allocated_space_info().car_info().license();*/
  311. m_alloc_request_msg=message::Parkspace_allocation_request_msg();
  312. m_parcspace_alloc_response_msg=message::Parkspace_allocation_response_msg();
  313. return SUCCESS;
  314. }
  315. else
  316. {
  317. Error_code t_code=(Error_code)release_response.error_manager().error_code();
  318. Error_level t_level=(Error_level)release_response.error_manager().error_level();
  319. return Error_manager(t_code,CRITICAL_ERROR,"back alloc response error_code error");
  320. }
  321. }
  322. /*
  323. * 控制流程到下一步
  324. */
  325. Error_manager StoreProcessTask::next_step()
  326. {
  327. if(m_current_step_statu==message::eWaiting || m_current_step_statu== message::eWorking)
  328. return Error_manager(ERROR,MINOR_ERROR,"当前状态禁止改变步骤类型");
  329. switch (m_current_step_type)
  330. {
  331. case message::eAlloc_step:
  332. m_current_step_type=(m_current_step_statu==message::eFinished)?message::eMeasure_step:message::eBackComplete;
  333. break;
  334. case message::eMeasure_step:
  335. m_current_step_type=(m_current_step_statu==message::eFinished)?message::eCompare_step:message::eBackAlloc_step;
  336. break;
  337. case message::eCompare_step:
  338. m_current_step_type=(m_current_step_statu==message::eFinished)?message::eDispatch_step:message::eBackMeasure_step;
  339. break;
  340. case message::eDispatch_step:
  341. m_current_step_type=(m_current_step_statu==message::eFinished)?message::eConfirm_step:message::eBack_compare_step;
  342. break;
  343. case message::eConfirm_step:
  344. m_current_step_type=(m_current_step_statu==message::eFinished)?message::eComplete:message::eBackDispatch_step;
  345. break;
  346. case message::eComplete:
  347. break;
  348. case message::eBackDispatch_step:
  349. m_current_step_type=message::eBack_compare_step;
  350. break;
  351. case message::eBack_compare_step:
  352. m_current_step_type=message::eBackMeasure_step;
  353. break;
  354. case message::eBackMeasure_step:
  355. m_current_step_type=message::eBackAlloc_step;
  356. break;
  357. case message::eBackAlloc_step:
  358. m_current_step_type=message::eBackComplete;
  359. break;
  360. case message::eBackComplete:
  361. break;
  362. }
  363. return SUCCESS;
  364. }
  365. /*
  366. * 流程函数
  367. */
  368. void StoreProcessTask::Main()
  369. {
  370. /*
  371. * 外部已经分配好车位,进入到此流程说明车位已经分配好, 存放在 m_parcspace_alloc_response_msg
  372. */
  373. Error_manager code;
  374. //开始执行停车指令
  375. while(is_canceled()==false)
  376. {
  377. //第一步分配车位
  378. if(m_current_step_type == message::eAlloc_step)
  379. {
  380. updata_step_statu(message::eWorking);
  381. code=alloc_space_step();
  382. //发送反馈
  383. message::Error_manager error_msg;
  384. error_msg.set_error_code(code.get_error_code());
  385. error_msg.set_error_description(code.get_error_description());
  386. m_command_response_msg.mutable_code()->CopyFrom(error_msg);
  387. Communication_message msg;
  388. msg.reset(m_command_response_msg.base_info(),m_command_response_msg.SerializeAsString());
  389. Message_communicator::get_instance_pointer()->send_msg(&msg);
  390. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  391. LOG_IF(ERROR, code != SUCCESS) << "分配失败:" <<m_car_info.license()<< code.get_error_description();
  392. }
  393. //第二步,测量
  394. if (m_current_step_type == message::eMeasure_step)
  395. {
  396. //开始定位
  397. updata_step_statu(message::eWorking);
  398. code = locate_step();
  399. usleep(1000 * 1000 );
  400. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  401. LOG_IF(ERROR, code != SUCCESS) << "测量失败:" <<m_car_info.license()<< code.get_error_description();
  402. }
  403. if(m_current_step_type== message::eCompare_step)
  404. {
  405. updata_step_statu(message::eWorking);
  406. code=compare_step();
  407. usleep(500*1000);
  408. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  409. LOG_IF(ERROR, code != SUCCESS) << "检验失败:"<<m_car_info.license() << code.get_error_description();
  410. }
  411. //第二步,调度
  412. if (m_current_step_type == message::eDispatch_step)
  413. {
  414. //开始调度
  415. updata_step_statu(message::eWorking);
  416. code = dispatch_step();
  417. usleep(1000 * 2000 );
  418. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  419. LOG_IF(ERROR, code != SUCCESS) << "调度失败:"<<m_car_info.license() << code.get_error_description();
  420. }
  421. //第三步,占据车位
  422. if (m_current_step_type == message::eConfirm_step)
  423. {
  424. updata_step_statu(message::eWorking);
  425. code = confirm_space_step();
  426. usleep(1000 * 1000);
  427. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  428. LOG_IF(ERROR, code != SUCCESS) << "终端号:" << m_terminor_id << "停车流程:" << code.get_error_description() <<
  429. " 车位id :"
  430. << m_parcspace_alloc_response_msg.allocated_space_info().parkspace_id()
  431. << ",车牌:" << m_car_info.license()<<code.to_string();
  432. }
  433. //第四步,完成,退出循环
  434. if (m_current_step_type == message::eComplete)
  435. {
  436. //流程结束前,保证至少发送一次流程完成状态
  437. updata_step_statu(message::eFinished);
  438. break;
  439. }
  440. //回退confirm ------------------------------------华丽的分割线------------------------------------------
  441. if (m_current_step_type == message::eBackConfirm_step)
  442. {
  443. updata_step_statu(message::eWorking);
  444. usleep(1000*1000);
  445. updata_step_statu(message::eFinished);
  446. }
  447. if(m_current_step_type== message::eBackDispatch_step)
  448. {
  449. updata_step_statu(message::eWorking);
  450. code=back_dispatch_step();
  451. usleep(1000*1000);
  452. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  453. if(code.get_error_level()>=MAJOR_ERROR)
  454. {
  455. //提升错误等级为四级
  456. LOG(ERROR)<<" 回退调度失败 ------进入异常处理, 车牌号:"<<m_car_info.license();
  457. Exception_solver::get_instance_pointer()->solve_exception(code,this);
  458. continue;
  459. }
  460. }
  461. if(m_current_step_type== message::eBack_compare_step)
  462. {
  463. updata_step_statu(message::eWorking);
  464. code=back_compare_step();
  465. usleep(1000*1000);
  466. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  467. if(code.get_error_level()>=MAJOR_ERROR)
  468. {
  469. LOG(ERROR)<<" 回退对比失败 ------进入异常处理, 车牌号:"<<m_car_info.license();
  470. Exception_solver::get_instance_pointer()->solve_exception(code,this);
  471. LOG(WARNING)<<" 手动处理 结果对比, 继续 ..........车牌:"<<m_car_info.license();
  472. continue;
  473. }
  474. }
  475. if(m_current_step_type== message::eBackMeasure_step)
  476. {
  477. updata_step_statu(message::eWorking);
  478. code=back_locate_step();
  479. usleep(1000*1000);
  480. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  481. if(code.get_error_level()>=MAJOR_ERROR)
  482. {
  483. //提升错误等级为四级
  484. LOG(ERROR)<<" 回退测量失败 ------进入异常处理, 车牌号:"<<m_car_info.license();
  485. Exception_solver::get_instance_pointer()->solve_exception(code,this);
  486. continue;
  487. }
  488. }
  489. if(m_current_step_type== message::eBackAlloc_step)
  490. {
  491. updata_step_statu(message::eWorking);
  492. code=back_alloc_space_step();
  493. usleep(1000*1000);
  494. code!=SUCCESS?updata_step_statu(message::eError):updata_step_statu(message::eFinished);
  495. if(code.get_error_level()>=MAJOR_ERROR)
  496. {
  497. //提升错误等级为四级
  498. LOG(ERROR)<<" 回退分配车位失败 ------进入异常处理, 车牌号:"<<m_car_info.license();
  499. Exception_solver::get_instance_pointer()->solve_exception(code,this);
  500. continue;
  501. }
  502. }
  503. if(m_current_step_type== message::eBackComplete)
  504. {
  505. break;
  506. }
  507. next_step();
  508. }
  509. /*
  510. * 跳出循环后,判断状态,是否正常结束, 循环跳出状态只有可能是 eBackComplete(异常结束),eComplete(正常结束),任务取消状态
  511. */
  512. updata_step_statu(message::eFinished);
  513. publish_step_status();
  514. if(m_cancel_condition.wait_for_millisecond(1)==true) {
  515. LOG(ERROR) << "停车任务被强制取消,车牌号:" << m_car_info.license()
  516. << ", 终端号:" << m_terminor_id;
  517. usleep(1000*200);
  518. return ;
  519. }
  520. if(m_current_step_type== message::eBackComplete)
  521. {
  522. //异常结束
  523. usleep(1000*200);
  524. LOG(ERROR)<<"异常停车,回退结束"<<"车牌号:"<<m_car_info.license()
  525. <<",xxxxxxxxxxxxxx 终端:"<<m_terminor_id<<" xxxxxxxxxxxxxx";
  526. }
  527. if(m_current_step_type== message::eComplete)
  528. {
  529. //正常结束
  530. usleep(1000*200);
  531. LOG(INFO)<<"停车结束,"<<"车牌号:"<<m_car_info.license()
  532. <<",-------------- 终端:"<<m_terminor_id<<" --------------";
  533. }
  534. }
  535. void StoreProcessTask::publish_step_status() {
  536. /*
  537. * 通过communicator 发布状态
  538. */
  539. if (Command_accepter::get_instance_pointer()) {
  540. std::lock_guard<std::mutex> lock(m_process_msg_lock);
  541. Command_accepter::get_instance_pointer()->post_process_statu(m_process_msg);
  542. }
  543. }
  544. /*
  545. * 根据当前流程状态,并修改状态消息
  546. */
  547. void StoreProcessTask::updata_step_statu(message::Step_statu statu)
  548. {
  549. m_current_step_statu=statu;
  550. std::lock_guard<std::mutex> lock(m_process_msg_lock);
  551. switch (m_current_step_type) {
  552. case message::eAlloc_step: {
  553. message::Alloc_space_step_statu alloc_step_statu;
  554. alloc_step_statu.set_step_statu(statu);
  555. m_process_msg.mutable_alloc_space_step()->CopyFrom(alloc_step_statu);
  556. break;
  557. }
  558. case message::eMeasure_step: {
  559. message::Measure_step_statu measure_step_statu;
  560. measure_step_statu.set_step_statu(statu);
  561. measure_step_statu.mutable_locate_info()->CopyFrom(m_locate_info);
  562. m_process_msg.mutable_measure_step()->CopyFrom(measure_step_statu);
  563. break;
  564. }
  565. case message::eCompare_step:{
  566. message::Compare_step_statu compare_step;
  567. compare_step.mutable_locate_info_wj()->CopyFrom(m_locate_info);
  568. compare_step.mutable_locate_info_dj()->CopyFrom(m_measure_response_msg.locate_information());
  569. compare_step.mutable_locate_info_result()->CopyFrom(m_compare_location_data);
  570. compare_step.set_step_statu(statu);
  571. m_process_msg.mutable_compare_step()->CopyFrom(compare_step);
  572. break;
  573. }
  574. case message::eDispatch_step: {
  575. message::Dispatch_store_step_statu dispatch_step_statu;
  576. dispatch_step_statu.set_step_statu(statu);
  577. dispatch_step_statu.mutable_locate_info()->CopyFrom(m_locate_info);
  578. dispatch_step_statu.mutable_space_info()->CopyFrom(m_parcspace_alloc_response_msg.allocated_space_info());
  579. m_process_msg.mutable_dispatch_step()->CopyFrom(dispatch_step_statu);
  580. break;
  581. }
  582. case message::eConfirm_step: {
  583. message::Confirm_space_step_statu confirm_step_type;
  584. confirm_step_type.set_step_statu(statu);
  585. confirm_step_type.mutable_space_info()->CopyFrom(m_parcspace_alloc_response_msg.allocated_space_info());
  586. m_process_msg.mutable_confirm_space_step()->CopyFrom(confirm_step_type);
  587. break;
  588. }
  589. case message::eComplete: {
  590. m_process_msg.set_completed(true);
  591. break;
  592. }
  593. case message::eBackConfirm_step: {
  594. message::Back_confirm_space_step_statu back_confirm_step_type;
  595. back_confirm_step_type.set_step_statu(statu);
  596. m_process_msg.mutable_back_confirm_step()->CopyFrom(back_confirm_step_type);
  597. break;
  598. }
  599. case message::eBackDispatch_step: {
  600. message::Back_dispatch_store_step_statu back_dispatch_step_statu;
  601. back_dispatch_step_statu.set_step_statu(statu);
  602. back_dispatch_step_statu.mutable_space_info()->CopyFrom(m_parcspace_alloc_response_msg.allocated_space_info());
  603. back_dispatch_step_statu.mutable_locate_info()->CopyFrom(m_compare_location_data);
  604. m_process_msg.mutable_back_dispatch_step()->CopyFrom(back_dispatch_step_statu);
  605. break;
  606. }
  607. case message::eBack_compare_step:{
  608. message::Back_compare_step_statu back_compare_step_statu;
  609. back_compare_step_statu.set_step_statu(statu);
  610. back_compare_step_statu.mutable_locate_info_wj()->CopyFrom(m_locate_info);
  611. back_compare_step_statu.mutable_locate_info_dj()->CopyFrom(m_measure_response_msg.locate_information());
  612. back_compare_step_statu.mutable_locate_info_result()->CopyFrom(m_compare_location_data);
  613. m_process_msg.mutable_back_compare_step()->CopyFrom(back_compare_step_statu);
  614. break;
  615. }
  616. case message::eBackMeasure_step: {
  617. message::Back_measure_step_statu back_measure_step_statu;
  618. back_measure_step_statu.set_step_statu(statu);
  619. m_process_msg.mutable_back_measure_step()->CopyFrom(back_measure_step_statu);
  620. break;
  621. }
  622. case message::eBackAlloc_step: {
  623. message::Back_alloc_space_step_statu back_alloc_step_statu;
  624. back_alloc_step_statu.set_step_statu(statu);
  625. back_alloc_step_statu.mutable_space_info()->CopyFrom(m_parcspace_alloc_response_msg.allocated_space_info());
  626. m_process_msg.mutable_back_alloc_space_step()->CopyFrom(back_alloc_step_statu);
  627. break;
  628. }
  629. case message::eBackComplete: {
  630. m_process_msg.set_back_completed(true);
  631. break;
  632. }
  633. default:
  634. break;
  635. }
  636. }
  637. /*
  638. * 初始化 接收到的消息
  639. */
  640. void StoreProcessTask::reset_msg() {
  641. m_alloc_request_msg = message::Parkspace_allocation_request_msg();
  642. m_measure_request_msg = message::Measure_request_msg();
  643. m_dispatch_request_msg = message::Dispatch_request_msg();
  644. m_confirm_request_msg = message::Parkspace_confirm_alloc_request_msg();
  645. m_command_response_msg=message::Store_command_response_msg();
  646. m_locate_info = message::Locate_information();
  647. m_measure_response_msg = message::Measure_response_msg(); //测量模块的测量数据
  648. m_parcspace_alloc_response_msg = message::Parkspace_allocation_response_msg(); //分配的车位数据
  649. m_dispatch_response_msg = message::Dispatch_response_msg(); //调度模块的反馈数据
  650. }