StoreProcessTask.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. //
  2. // Created by zx on 2020/7/7.
  3. //
  4. #include <Parkspace_communicator.h>
  5. #include <dispatch_message.pb.h>
  6. #include "dispatch_communicator.h"
  7. #include "StoreProcessTask.h"
  8. #include "process_message.pb.h"
  9. #include "command_manager.h"
  10. #include "system_communicator.h"
  11. #include "exception_solver.h"
  12. #include "uniq_key.h"
  13. StoreProcessTask::StoreProcessTask(unsigned int terminor_id)
  14. :m_publish_statu_thread(nullptr)
  15. {
  16. m_terminor_id=terminor_id;
  17. }
  18. StoreProcessTask::~StoreProcessTask()
  19. {
  20. Exception_solver::get_instance_pointer()->delete_task_cancel_condition(m_car_info.license());
  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(message::Locate_information locate_info,message::Car_info car_info)
  34. {
  35. reset_msg();
  36. m_car_info=car_info;
  37. m_locate_info=locate_info;
  38. //添加当前流程的任务取消标志位到异常处理模块
  39. m_cancel_condition.reset(false, false, false);
  40. Error_manager code=Exception_solver::get_instance_pointer()->add_task_cancel_condition(car_info.license(),this);
  41. if(code!=SUCCESS)
  42. return code;
  43. //初始化进度状态消息基本信息
  44. message::Base_info base_info;
  45. base_info.set_msg_type(message::eStoring_process_statu_msg);
  46. base_info.set_sender(message::eMain);
  47. base_info.set_receiver(message::eEmpty);
  48. m_process_msg.mutable_base_info()->CopyFrom(base_info);
  49. m_process_msg.set_terminal_id(m_terminor_id);
  50. m_process_msg.set_license(m_car_info.license());
  51. m_step_statu=eAlloc_step;
  52. ///创建状态发布线程
  53. if(m_publish_statu_thread== nullptr)
  54. {
  55. m_publish_exit_condition.reset(false, false, false);
  56. m_publish_statu_thread=new std::thread(publish_thread_func,this);
  57. }
  58. return SUCCESS;
  59. }
  60. /*
  61. * 取消任务
  62. */
  63. void StoreProcessTask::Cancel()
  64. {
  65. m_cancel_condition.set_pass_ever(true);
  66. tq::BaseTask::Cancel();
  67. }
  68. Error_manager StoreProcessTask::locate_step() {
  69. Error_manager code;
  70. //检查测量模块状态
  71. code=Locate_communicator::get_instance_pointer()->check_statu(m_terminor_id);
  72. if(code!=SUCCESS)
  73. return code;
  74. message::Base_info base_info;
  75. base_info.set_msg_type(message::eLocate_request_msg);
  76. base_info.set_sender(message::eMain);
  77. base_info.set_receiver(message::eMeasurer);
  78. base_info.set_timeout_ms(20000); //测量超时5s
  79. m_measure_request_msg.mutable_base_info()->CopyFrom(base_info);
  80. m_measure_request_msg.set_command_key(create_key());
  81. m_measure_request_msg.set_terminal_id(m_terminor_id);
  82. code=Locate_communicator::get_instance_pointer()->locate_request(m_measure_request_msg,
  83. m_measure_response_msg,m_cancel_condition);
  84. if(code!=SUCCESS)
  85. return code;
  86. if(m_measure_response_msg.error_manager().error_code()==0) {
  87. return SUCCESS;
  88. }
  89. else
  90. return Error_manager(FAILED,MINOR_ERROR,m_measure_response_msg.error_manager().error_description().c_str());
  91. }
  92. /*
  93. * 回退定位
  94. */
  95. Error_manager StoreProcessTask::back_locate_step()
  96. {
  97. m_measure_request_msg=message::Measure_request_msg();
  98. m_measure_response_msg=message::Measure_response_msg();
  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_communicator::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. std::string key=create_key();
  129. m_dispatch_request_msg.set_command_key(key);
  130. m_dispatch_request_msg.set_terminal_id(m_terminor_id);
  131. m_dispatch_request_msg.set_dispatch_motion_direction(message::E_STORE_CAR);
  132. m_dispatch_request_msg.set_parkspace_id(m_parcspace_alloc_response_msg.allocated_space_info().parkspace_id());
  133. code=Dispatch_communicator::get_instance_pointer()->dispatch_request(m_dispatch_request_msg,
  134. m_dispatch_response_msg,m_cancel_condition);
  135. if(code!=SUCCESS)
  136. return code;
  137. if(m_dispatch_response_msg.error_manager().error_code()==0) {
  138. return SUCCESS;
  139. }
  140. else
  141. return Error_manager(FAILED,MINOR_ERROR,"dispatch response error_code error");
  142. }
  143. /*
  144. * 回退调度
  145. */
  146. Error_manager StoreProcessTask::back_dispatch_step()
  147. {
  148. //reset 调度请求数据
  149. m_dispatch_request_msg=message::Dispatch_request_msg();
  150. m_dispatch_response_msg=message::Dispatch_response_msg();
  151. return SUCCESS;
  152. }
  153. /*
  154. * 分配车位
  155. */
  156. Error_manager StoreProcessTask::alloc_space()
  157. {
  158. /*
  159. * 检查是否有测量数据
  160. */
  161. if(m_locate_info.has_locate_height()==false||m_locate_info.has_locate_width()==false)
  162. {
  163. return Error_manager(FAILED,MINOR_ERROR,"停车请求缺少车辆高度和宽度信息");
  164. }
  165. /*
  166. * 检查车位管理模块是否正常
  167. */
  168. Error_manager code=Parkspace_communicator::get_instance_pointer()->check_statu();
  169. if(code!=SUCCESS)
  170. {
  171. return code;
  172. }
  173. //发送分配请求
  174. message::Base_info base_info;
  175. base_info.set_msg_type(message::eParkspace_allocation_request_msg);
  176. base_info.set_sender(message::eMain);
  177. base_info.set_receiver(message::eParkspace);
  178. base_info.set_timeout_ms(1000); //超时1s
  179. m_alloc_request_msg.mutable_base_info()->CopyFrom(base_info);
  180. m_alloc_request_msg.mutable_car_info()->CopyFrom(m_car_info);
  181. m_alloc_request_msg.set_command_key(create_key());
  182. m_alloc_request_msg.set_terminal_id(m_terminor_id);
  183. code=Parkspace_communicator::get_instance_pointer()->alloc_request(m_alloc_request_msg,
  184. m_parcspace_alloc_response_msg,m_cancel_condition);
  185. if(code!=SUCCESS)
  186. {
  187. return code;
  188. }
  189. if(m_parcspace_alloc_response_msg.error_manager().error_code()==0)
  190. {
  191. message::Car_info alloc_car_info=m_parcspace_alloc_response_msg.allocated_space_info().car_info();
  192. if(alloc_car_info.license()!=m_car_info.license())
  193. {
  194. return Error_manager(ERROR,MINOR_ERROR,"分配车位反馈的车辆信息不匹配");
  195. }
  196. //置步骤状态为测量状态.
  197. m_step_statu=eMeasure_step;
  198. return SUCCESS;
  199. }
  200. else
  201. {
  202. return Error_manager(FAILED,MINOR_ERROR,"分配车位反馈结果错误");
  203. }
  204. }
  205. /*
  206. * 车位占用确认
  207. */
  208. Error_manager StoreProcessTask::confirm_space_step()
  209. {
  210. /*
  211. * 检查车位管理模块是否正常
  212. */
  213. Error_manager code=Parkspace_communicator::get_instance_pointer()->check_statu();
  214. if(code!=SUCCESS)
  215. return code;
  216. message::Parkspace_confirm_alloc_request_msg request;
  217. message::Base_info base_info;
  218. base_info.set_msg_type(message::eParkspace_confirm_alloc_request_msg);
  219. base_info.set_sender(message::eMain);
  220. base_info.set_receiver(message::eParkspace);
  221. base_info.set_timeout_ms(1000); //测量超时1s
  222. request.mutable_base_info()->CopyFrom(base_info);
  223. message::Parkspace_info space_info=m_parcspace_alloc_response_msg.allocated_space_info();
  224. request.mutable_confirm_space_info()->CopyFrom(space_info);
  225. request.set_command_key(create_key());
  226. message::Parkspace_confirm_alloc_response_msg confirm_response;
  227. code=Parkspace_communicator::get_instance_pointer()->confirm_request(request,confirm_response,m_cancel_condition);
  228. if(code!=SUCCESS)
  229. return code;
  230. if(m_parcspace_alloc_response_msg.allocated_space_info().parkspace_id()!=
  231. confirm_response.confirm_alloc_space_info().parkspace_id())
  232. {
  233. return Error_manager(ERROR,MINOR_ERROR,"占用车位与分配车位不一致");
  234. }
  235. if(confirm_response.error_manager().error_code()==0) {
  236. /*LOG(INFO)<<"停车流程正常,确认占用车位成功,停车终端:"<<m_terminor_id
  237. <<", 指令id:"<<m_command_info.place()+m_command_info.time()
  238. <<", 车位楼层:"<<confirm_response.confirm_alloc_space_info().floor()
  239. <<", 车位序号:"<<confirm_response.confirm_alloc_space_info().index()
  240. <<", 车牌号:"<<confirm_response.confirm_alloc_space_info().car_info().license();*/
  241. return SUCCESS;
  242. }
  243. else
  244. return Error_manager(FAILED,MINOR_ERROR,"parkspace confirm response error_code error");
  245. }
  246. /*
  247. * 回退车位分配
  248. */
  249. Error_manager StoreProcessTask::back_alloc_space_step()
  250. {
  251. /*
  252. * 检查是否曾经分配过车位
  253. */
  254. if(m_parcspace_alloc_response_msg.has_allocated_space_info()==false)
  255. {
  256. return Error_manager(FAILED,MINOR_ERROR," parkspace release request without space info");
  257. }
  258. /*
  259. * 检查车位管理模块是否正常
  260. */
  261. Error_manager code=Parkspace_communicator::get_instance_pointer()->check_statu();
  262. if(code!=SUCCESS)
  263. return code;
  264. message::Parkspace_release_request_msg request;
  265. message::Base_info base_info;
  266. base_info.set_msg_type(message::eParkspace_release_request_msg);
  267. base_info.set_sender(message::eMain);
  268. base_info.set_receiver(message::eParkspace);
  269. base_info.set_timeout_ms(1000); //测量超时1s
  270. request.mutable_base_info()->CopyFrom(base_info);
  271. message::Parkspace_info space_info=m_parcspace_alloc_response_msg.allocated_space_info();
  272. request.mutable_release_space_info()->CopyFrom(space_info);
  273. request.set_command_key(create_key());
  274. message::Parkspace_release_response_msg release_response;
  275. code=Parkspace_communicator::get_instance_pointer()->release_request(request,release_response,m_cancel_condition);
  276. if(code!=SUCCESS)
  277. return code;
  278. if(release_response.error_manager().error_code()==0) {
  279. /*LOG(WARNING)<<"停车流程异常,释放车位成功,停车终端:"<<m_terminor_id
  280. <<", 指令id:"<<m_command_info.place()+m_command_info.time()
  281. <<", 车位楼层:"<<m_parcspace_alloc_response_msg.allocated_space_info().floor()
  282. <<", 车位序号:"<<m_parcspace_alloc_response_msg.allocated_space_info().index()
  283. <<", 车牌号:"<<m_parcspace_alloc_response_msg.allocated_space_info().car_info().license();*/
  284. m_alloc_request_msg=message::Parkspace_allocation_request_msg();
  285. m_parcspace_alloc_response_msg=message::Parkspace_allocation_response_msg();
  286. return SUCCESS;
  287. }
  288. else
  289. return Error_manager(FAILED,MINOR_ERROR,"parkspace release response error_code error");
  290. }
  291. void StoreProcessTask::Main()
  292. {
  293. /*
  294. * 外部已经分配好车位,进入到此流程说明车位已经分配好, 存放在 m_parcspace_alloc_response_msg
  295. */
  296. Error_manager code;
  297. //开始执行停车指令
  298. while(m_cancel_condition.wait_for_millisecond(1)==false)
  299. {
  300. //第一步,测量
  301. if (m_step_statu == eStoring_step::eMeasure_step)
  302. {
  303. //开始定位
  304. code = locate_step();
  305. usleep(1000 * 1000 * (rand() % 5 + 1));
  306. LOG_IF(ERROR, code != SUCCESS) << "测量失败:" << code.get_error_description();
  307. m_step_statu = (code != SUCCESS) ? eStoring_step::eBackMeasure_step : eStoring_step::eDispatch_step;
  308. }
  309. //第二步,调度
  310. if (m_step_statu == eStoring_step::eDispatch_step)
  311. {
  312. //开始调度
  313. code = dispatch_step();
  314. usleep(1000 * 1000 * (rand() % 13));
  315. LOG_IF(ERROR, code != SUCCESS) << "调度失败:" << code.get_error_description();
  316. m_step_statu = (code != SUCCESS) ? eStoring_step::eBackDispatch_step : eStoring_step::eConfirm_step;
  317. }
  318. //第三步,占据车位
  319. if (m_step_statu == eStoring_step::eConfirm_step)
  320. {
  321. code = confirm_space_step();
  322. usleep(1000 * 1000);
  323. LOG_IF(ERROR, code != SUCCESS) << "终端号:" << m_terminor_id << "停车流程:" << code.get_error_description() <<
  324. " 车位id :"
  325. << m_parcspace_alloc_response_msg.allocated_space_info().parkspace_id()
  326. << ",车牌:" << m_car_info.license()<<code.to_string();
  327. //最后一步故障,提升故障等级,急停
  328. if(code!=SUCCESS)
  329. {
  330. break;
  331. }
  332. else
  333. {
  334. m_step_statu=eStoring_step::eComplete;
  335. }
  336. }
  337. //第四步,完成,退出循环
  338. if (m_step_statu == eStoring_step::eComplete)
  339. {
  340. //流程结束前,保证至少发送一次流程完成状态
  341. if(updata_step_statu_msg()==SUCCESS)
  342. {
  343. System_communicator::get_instance_pointer()->post_process_statu(m_process_msg);
  344. }
  345. break;
  346. }
  347. //回退confirm ------------------------------------华丽的分割线------------------------------------------
  348. if (m_step_statu == eStoring_step::eBackConfirm_step)
  349. {
  350. m_step_statu=eStoring_step::eBackDispatch_step;
  351. }
  352. if(m_step_statu==eStoring_step::eBackDispatch_step)
  353. {
  354. code=back_dispatch_step();
  355. if(code!=SUCCESS)
  356. {
  357. //提升错误等级为四级
  358. break;
  359. }
  360. else
  361. {
  362. m_step_statu=eStoring_step::eBackMeasure_step;
  363. }
  364. }
  365. if(m_step_statu==eStoring_step::eBackMeasure_step)
  366. {
  367. code=back_locate_step();
  368. if(code!=SUCCESS)
  369. {
  370. //提升错误等级为四级
  371. break;
  372. }
  373. else
  374. {
  375. m_step_statu=eStoring_step::eBackAlloc_step;
  376. }
  377. }
  378. if(m_step_statu==eStoring_step::eBackAlloc_step)
  379. {
  380. code=back_alloc_space_step();
  381. if(code!=SUCCESS)
  382. {
  383. //提升错误等级为四级
  384. break;
  385. }
  386. else
  387. {
  388. m_step_statu=eStoring_step::eBackComplete;
  389. break;
  390. }
  391. }
  392. }
  393. /*
  394. * 跳出循环后,判断状态,是否正常结束, 循环跳出状态只有可能是 eBackComplete(异常结束),eComplete(正常结束),任务取消状态
  395. */
  396. if(m_cancel_condition.wait_for_millisecond(1)==true) {
  397. LOG(ERROR) << "停车任务被强制取消,车牌号:" << m_car_info.license()
  398. << ", 终端号:" << m_terminor_id;
  399. return ;
  400. }
  401. if(m_step_statu==eStoring_step::eBackComplete)
  402. {
  403. //异常结束
  404. usleep(1000*10000);
  405. LOG(ERROR)<<"异常停车,回退结束"<<"车牌号:"<<m_car_info.license()
  406. <<",xxxxxxxxxxxxxx 终端:"<<m_terminor_id<<" xxxxxxxxxxxxxx";
  407. }
  408. if(m_step_statu==eStoring_step::eComplete)
  409. {
  410. //正常结束
  411. usleep(1000*1000);
  412. LOG(INFO)<<"停车结束,"<<"车牌号:"<<m_car_info.license()
  413. <<",-------------- 终端:"<<m_terminor_id<<" --------------";
  414. }
  415. }
  416. /*
  417. * 发布状态线程
  418. */
  419. void StoreProcessTask::publish_thread_func(StoreProcessTask* ptask)
  420. {
  421. if(ptask)
  422. {
  423. ptask->publish_step_status();
  424. }
  425. }
  426. void StoreProcessTask::publish_step_status()
  427. {
  428. //未收到退出信号
  429. while(false==m_publish_exit_condition.wait_for_ex(std::chrono::milliseconds(50)))
  430. {
  431. /*
  432. * 通过communicator 发布状态
  433. */
  434. if(System_communicator::get_instance_pointer())
  435. {
  436. if(updata_step_statu_msg()==SUCCESS)
  437. {
  438. System_communicator::get_instance_pointer()->post_process_statu(m_process_msg);
  439. }
  440. }
  441. }
  442. }
  443. /*
  444. * 根据当前流程状态,生成状态消息
  445. */
  446. Error_manager StoreProcessTask::updata_step_statu_msg()
  447. {
  448. switch (m_step_statu) {
  449. case eStoring_step::eAlloc_step: {
  450. message::Alloc_space_step_statu alloc_step_statu;
  451. alloc_step_statu.set_step_statu(message::eWorking);
  452. m_process_msg.mutable_alloc_space_step()->CopyFrom(alloc_step_statu);
  453. break;
  454. }
  455. case eStoring_step::eMeasure_step: {
  456. message::Measure_step_statu measure_step_statu;
  457. measure_step_statu.set_step_statu(message::eWorking);
  458. measure_step_statu.mutable_locate_info()->CopyFrom(m_locate_info);
  459. m_process_msg.mutable_measure_step()->CopyFrom(measure_step_statu);
  460. if(m_process_msg.has_alloc_space_step())
  461. {
  462. m_process_msg.mutable_alloc_space_step()->set_step_statu(message::eComplete);
  463. }
  464. break;
  465. }
  466. case eStoring_step::eCompare_step:{
  467. message::Compare_step_statu compare_step;
  468. compare_step.mutable_locate_info_wj()->CopyFrom(m_locate_info);
  469. compare_step.mutable_locate_info_dj()->CopyFrom(m_measure_response_msg.locate_information());
  470. compare_step.mutable_locate_info_result()->CopyFrom(m_compare_location_data);
  471. compare_step.set_step_statu(message::eWorking);
  472. m_process_msg.mutable_compare_step()->CopyFrom(compare_step);
  473. if(m_process_msg.has_measure_step())
  474. m_process_msg.mutable_measure_step()->set_step_statu(message::eComplete);
  475. break;
  476. }
  477. case eStoring_step::eDispatch_step: {
  478. message::Dispatch_store_step_statu dispatch_step_statu;
  479. dispatch_step_statu.set_step_statu(message::eWorking);
  480. dispatch_step_statu.mutable_locate_info()->CopyFrom(m_locate_info);
  481. dispatch_step_statu.mutable_space_info()->CopyFrom(m_parcspace_alloc_response_msg.allocated_space_info());
  482. m_process_msg.mutable_dispatch_step()->CopyFrom(dispatch_step_statu);
  483. if(m_process_msg.has_compare_step())
  484. m_process_msg.mutable_compare_step()->set_step_statu(message::eComplete);
  485. break;
  486. }
  487. case eStoring_step::eConfirm_step: {
  488. message::Confirm_space_step_statu confirm_step_statu;
  489. confirm_step_statu.set_step_statu(message::eWorking);
  490. confirm_step_statu.mutable_space_info()->CopyFrom(m_parcspace_alloc_response_msg.allocated_space_info());
  491. m_process_msg.mutable_confirm_space_step()->CopyFrom(confirm_step_statu);
  492. if(m_process_msg.has_dispatch_step())
  493. m_process_msg.mutable_dispatch_step()->set_step_statu(message::eComplete);
  494. break;
  495. }
  496. case eStoring_step::eComplete: {
  497. m_process_msg.set_completed(true);
  498. break;
  499. }
  500. case eStoring_step::eBackConfirm_step: {
  501. message::Back_confirm_space_step_statu back_confirm_step_statu;
  502. back_confirm_step_statu.set_step_statu(message::eWaiting);
  503. if (m_process_msg.has_confirm_space_step())
  504. m_process_msg.mutable_confirm_space_step()->set_step_statu(message::eError);
  505. break;
  506. }
  507. case eStoring_step::eBackDispatch_step: {
  508. message::Back_dispatch_store_step_statu back_dispatch_step_statu;
  509. back_dispatch_step_statu.set_step_statu(message::eWorking);
  510. back_dispatch_step_statu.mutable_space_info()->CopyFrom(m_parcspace_alloc_response_msg.allocated_space_info());
  511. back_dispatch_step_statu.mutable_locate_info()->CopyFrom(m_compare_location_data);
  512. m_process_msg.mutable_back_dispatch_step()->CopyFrom(back_dispatch_step_statu);
  513. if(m_process_msg.has_back_confirm_step())
  514. m_process_msg.mutable_back_confirm_step()->set_step_statu(message::eComplete);
  515. else
  516. m_process_msg.mutable_dispatch_step()->set_step_statu(message::eError);
  517. break;
  518. }
  519. case eStoring_step::eBack_compare_step:{
  520. message::Back_compare_step_statu back_compare_step_statu;
  521. back_compare_step_statu.set_step_statu(message::eWorking);
  522. back_compare_step_statu.mutable_locate_info_wj()->CopyFrom(m_locate_info);
  523. back_compare_step_statu.mutable_locate_info_dj()->CopyFrom(m_measure_response_msg.locate_information());
  524. back_compare_step_statu.mutable_locate_info_result()->CopyFrom(m_compare_location_data);
  525. m_process_msg.mutable_compare_step()->CopyFrom(back_compare_step_statu);
  526. if(m_process_msg.has_back_dispatch_step())
  527. m_process_msg.mutable_back_dispatch_step()->set_step_statu(message::eComplete);
  528. else
  529. m_process_msg.mutable_compare_step()->set_step_statu(message::eError);
  530. break;
  531. }
  532. case eStoring_step::eBackMeasure_step: {
  533. message::Back_measure_step_statu back_measure_step_statu;
  534. back_measure_step_statu.set_step_statu(message::eWorking);
  535. m_process_msg.mutable_back_measure_step()->CopyFrom(back_measure_step_statu);
  536. if(m_process_msg.has_back_compare_step())
  537. m_process_msg.mutable_back_compare_step()->set_step_statu(message::eComplete);
  538. else
  539. m_process_msg.mutable_measure_step()->set_step_statu(message::eError);
  540. break;
  541. }
  542. case eStoring_step::eBackAlloc_step: {
  543. message::Back_alloc_space_step_statu back_alloc_step_statu;
  544. back_alloc_step_statu.set_step_statu(message::eWorking);
  545. back_alloc_step_statu.mutable_space_info()->CopyFrom(m_parcspace_alloc_response_msg.allocated_space_info());
  546. m_process_msg.mutable_back_alloc_space_step()->CopyFrom(back_alloc_step_statu);
  547. if(m_process_msg.has_back_measure_step())
  548. m_process_msg.mutable_back_measure_step()->set_step_statu(message::eComplete);
  549. else
  550. m_process_msg.mutable_alloc_space_step()->set_step_statu(message::eError);
  551. break;
  552. }
  553. case eStoring_step::eBackComplete: {
  554. m_process_msg.set_back_completed(true);
  555. break;
  556. }
  557. default:
  558. break;
  559. }
  560. return SUCCESS;
  561. }
  562. /*
  563. * 初始化 接收到的消息
  564. */
  565. void StoreProcessTask::reset_msg() {
  566. m_alloc_request_msg = message::Parkspace_allocation_request_msg();
  567. m_measure_request_msg = message::Measure_request_msg();
  568. m_dispatch_request_msg = message::Dispatch_request_msg();
  569. m_confirm_request_msg = message::Parkspace_confirm_alloc_request_msg();
  570. m_locate_info = message::Locate_information();
  571. m_measure_response_msg = message::Measure_response_msg(); //测量模块的测量数据
  572. m_parcspace_alloc_response_msg = message::Parkspace_allocation_response_msg(); //分配的车位数据
  573. m_dispatch_response_msg = message::Dispatch_response_msg(); //调度模块的反馈数据
  574. }