StoreProcessTask.cpp 27 KB

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