StoreProcessTask.cpp 30 KB

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