StoreProcessTask.cpp 26 KB

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