StoreProcessTask.cpp 27 KB

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