StoreProcessTask.cpp 27 KB

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