system_executor.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. //
  2. // Created by huli on 2020/7/2.
  3. //
  4. #include "system_executor.h"
  5. System_executor::System_executor()
  6. {
  7. }
  8. System_executor::~System_executor()
  9. {
  10. system_executor_uninit();
  11. }
  12. //初始化
  13. Error_manager System_executor::system_executor_init(int threads_size)
  14. {
  15. m_thread_pool.thread_pool_init(threads_size);
  16. m_system_executor_status = SYSTEM_EXECUTOR_READY;
  17. return Error_code::SUCCESS;
  18. }
  19. //反初始化
  20. Error_manager System_executor::system_executor_uninit()
  21. {
  22. m_thread_pool.thread_pool_uninit();
  23. m_system_executor_status = SYSTEM_EXECUTOR_UNKNOW;
  24. return Error_code::SUCCESS;
  25. }
  26. //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
  27. Error_manager System_executor::check_msg(Communication_message* p_msg)
  28. {
  29. if ( p_msg == NULL )
  30. {
  31. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  32. " POINTER IS NULL ");
  33. }
  34. //检查接受人
  35. if ( p_msg->get_receiver() == Communication_message::Communicator::eDispatch_mamager )
  36. {
  37. //检查消息类型
  38. switch ( p_msg->get_message_type() )
  39. {
  40. case Communication_message::Message_type::eDispatch_request_msg:
  41. {
  42. message::Dispatch_request_msg t_dispatch_request_msg;
  43. //针对消息类型, 对消息进行二次解析
  44. if (t_dispatch_request_msg.ParseFromString(p_msg->get_message_buf()))
  45. {
  46. if ( t_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
  47. {
  48. if ( t_dispatch_request_msg.id_struct().has_terminal_id() &&
  49. t_dispatch_request_msg.mutable_id_struct()->terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2 ||
  50. t_dispatch_request_msg.mutable_id_struct()->terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2+1)
  51. {
  52. return Error_code::SUCCESS;
  53. }
  54. }
  55. else if ( t_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
  56. {
  57. if ( t_dispatch_request_msg.id_struct().has_unit_id() &&
  58. t_dispatch_request_msg.mutable_id_struct()->unit_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id() )
  59. {
  60. return Error_code::SUCCESS;
  61. }
  62. }
  63. }
  64. else
  65. {
  66. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  67. " message::Dispatch_request_msg ParseFromString error ");
  68. }
  69. break;
  70. }
  71. case Communication_message::Message_type::eDispatch_plan_response_msg:
  72. {
  73. return Error_code::SUCCESS;
  74. break;
  75. }
  76. case Communication_message::Message_type::eDispatch_control_request_msg:
  77. {
  78. return Error_code::SUCCESS;
  79. break;
  80. }
  81. default :
  82. ;
  83. break;
  84. }
  85. }
  86. //检查接受人
  87. if ( p_msg->get_receiver() == Communication_message::Communicator::eEmpty )
  88. {
  89. //检查消息类型
  90. switch ( p_msg->get_message_type() )
  91. {
  92. case Communication_message::Message_type::eGround_status_msg:
  93. {
  94. message::Ground_status_msg t_ground_status_msg;
  95. //针对消息类型, 对消息进行二次解析
  96. if (t_ground_status_msg.ParseFromString(p_msg->get_message_buf()))
  97. {
  98. if ( t_ground_status_msg.mutable_id_struct()->terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2 ||
  99. t_ground_status_msg.mutable_id_struct()->terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2+1)
  100. {
  101. return Error_code::SUCCESS;
  102. }
  103. }
  104. else
  105. {
  106. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  107. " message::Dispatch_request_msg ParseFromString error ");
  108. }
  109. break;
  110. }
  111. case Communication_message::Message_type::eTerminal_status_msg:
  112. {
  113. message::Terminal_status_msg t_terminal_status_msg;
  114. //针对消息类型, 对消息进行二次解析
  115. if (t_terminal_status_msg.ParseFromString(p_msg->get_message_buf()))
  116. {
  117. if ( t_terminal_status_msg.id_struct().terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2 ||
  118. t_terminal_status_msg.id_struct().terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2+1)
  119. {
  120. return Error_code::SUCCESS;
  121. }
  122. }
  123. else
  124. {
  125. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  126. " message::Dispatch_request_msg ParseFromString error ");
  127. }
  128. break;
  129. }
  130. case Communication_message::Message_type::eNotify_status_msg:
  131. {
  132. message::Notify_status_msg t_notify_status_msg;
  133. //针对消息类型, 对消息进行二次解析
  134. if (t_notify_status_msg.ParseFromString(p_msg->get_message_buf()))
  135. {
  136. if ( t_notify_status_msg.mutable_id_struct()->terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2 ||
  137. t_notify_status_msg.mutable_id_struct()->terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2+1)
  138. {
  139. return Error_code::SUCCESS;
  140. }
  141. }
  142. else
  143. {
  144. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  145. " message::Dispatch_request_msg ParseFromString error ");
  146. }
  147. break;
  148. }
  149. default :
  150. ;
  151. break;
  152. }
  153. }
  154. //无效的消息,
  155. return Error_manager(Error_code::INVALID_MESSAGE, Error_level::NEGLIGIBLE_ERROR,
  156. " INVALID_MESSAGE error ");
  157. }
  158. //检查执行者的状态, 判断能否处理这条消息,
  159. Error_manager System_executor::check_executer(Communication_message* p_msg)
  160. {
  161. if ( p_msg == NULL )
  162. {
  163. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  164. " POINTER IS NULL ");
  165. }
  166. //检查执行线程池
  167. Error_manager t_executor_result = System_executor::get_instance_references().check_status();
  168. if (t_executor_result.get_error_level() == NEGLIGIBLE_ERROR)//一级故障,轻微故障,
  169. {
  170. std::cout << "executer_is_busy , " << std::endl;
  171. //返回繁忙之后, 通信模块1秒后再次调用check
  172. return Error_code::COMMUNICATION_EXCUTER_IS_BUSY;
  173. }
  174. else if (t_executor_result.get_error_level() > NEGLIGIBLE_ERROR)
  175. {
  176. return Error_manager(Error_code::SYSTEM_EXECUTOR_STATUS_ERROR, Error_level::MINOR_ERROR,
  177. "System_executor::get_instance_references().check_status(); fun error ");
  178. }
  179. //检查接受人
  180. if ( p_msg->get_receiver() == Communication_message::Communicator::eDispatch_mamager )
  181. {
  182. return Dispatch_manager::get_instance_references().check_execute_msg(p_msg);
  183. }
  184. return Error_code::SUCCESS;
  185. }
  186. //处理消息的执行函数
  187. Error_manager System_executor::execute_msg(Communication_message* p_msg)
  188. {
  189. if ( p_msg == NULL )
  190. {
  191. return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
  192. " POINTER IS NULL ");
  193. }
  194. //检查接受人
  195. if ( p_msg->get_receiver() == Communication_message::Communicator::eDispatch_mamager )
  196. {
  197. switch ( p_msg->get_message_type() )
  198. {
  199. case Communication_message::Message_type::eDispatch_request_msg:
  200. {
  201. message::Dispatch_request_msg t_dispatch_request_msg;
  202. //针对消息类型, 对消息进行二次解析
  203. if (t_dispatch_request_msg.ParseFromString(p_msg->get_message_buf()))
  204. {
  205. //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
  206. m_thread_pool.enqueue(&System_executor::execute_for_dispatch_request_msg, this,
  207. t_dispatch_request_msg );
  208. }
  209. else
  210. {
  211. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  212. " message::Dispatch_request_msg ParseFromString error ");
  213. }
  214. break;
  215. }
  216. case Communication_message::Message_type::eDispatch_plan_response_msg:
  217. {
  218. message::Dispatch_plan_response_msg t_dispatch_plan_response_msg;
  219. //针对消息类型, 对消息进行二次解析
  220. if (t_dispatch_plan_response_msg.ParseFromString(p_msg->get_message_buf()))
  221. {
  222. //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
  223. m_thread_pool.enqueue(&System_executor::execute_for_dispatch_plan_response_msg, this,
  224. t_dispatch_plan_response_msg );
  225. }
  226. else
  227. {
  228. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  229. " message::Dispatch_request_msg ParseFromString error ");
  230. }
  231. break;
  232. }
  233. case Communication_message::Message_type::eDispatch_control_request_msg:
  234. {
  235. message::Dispatch_control_request_msg t_dispatch_control_request_msg;
  236. //针对消息类型, 对消息进行二次解析
  237. if (t_dispatch_control_request_msg.ParseFromString(p_msg->get_message_buf()))
  238. {
  239. //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
  240. m_thread_pool.enqueue(&System_executor::execute_for_dispatch_control_request_msg, this,
  241. t_dispatch_control_request_msg );
  242. }
  243. else
  244. {
  245. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  246. " message::Dispatch_request_msg ParseFromString error ");
  247. }
  248. break;
  249. }
  250. default:
  251. break;
  252. }
  253. }
  254. //检查接受人
  255. if ( p_msg->get_receiver() == Communication_message::Communicator::eEmpty )
  256. {
  257. switch ( p_msg->get_message_type() )
  258. {
  259. case Communication_message::Message_type::eGround_status_msg:
  260. {
  261. message::Ground_status_msg t_ground_status_msg;
  262. //针对消息类型, 对消息进行二次解析
  263. if (t_ground_status_msg.ParseFromString(p_msg->get_message_buf()))
  264. {
  265. //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
  266. m_thread_pool.enqueue(&System_executor::execute_for_ground_status_msg, this,
  267. t_ground_status_msg );
  268. }
  269. else
  270. {
  271. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  272. " message::Dispatch_request_msg ParseFromString error ");
  273. }
  274. break;
  275. }
  276. case Communication_message::Message_type::eTerminal_status_msg:
  277. {
  278. message::Terminal_status_msg t_terminal_status_msg;
  279. //针对消息类型, 对消息进行二次解析
  280. if (t_terminal_status_msg.ParseFromString(p_msg->get_message_buf()))
  281. {
  282. //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
  283. m_thread_pool.enqueue(&System_executor::execute_for_terminal_status_msg, this,
  284. t_terminal_status_msg );
  285. }
  286. else
  287. {
  288. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  289. " message::Dispatch_request_msg ParseFromString error ");
  290. }
  291. break;
  292. }
  293. case Communication_message::Message_type::eNotify_status_msg:
  294. {
  295. message::Notify_status_msg t_notify_status_msg;
  296. //针对消息类型, 对消息进行二次解析
  297. if (t_notify_status_msg.ParseFromString(p_msg->get_message_buf()))
  298. {
  299. //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
  300. m_thread_pool.enqueue(&System_executor::execute_for_notify_status_msg, this,
  301. t_notify_status_msg );
  302. }
  303. else
  304. {
  305. return Error_manager(Error_code::SYSTEM_EXECUTOR_PARSE_ERROR, Error_level::MINOR_ERROR,
  306. " message::Dispatch_request_msg ParseFromString error ");
  307. }
  308. break;
  309. }
  310. default:
  311. break;
  312. }
  313. }
  314. return Error_code::SUCCESS;
  315. }
  316. //检查状态
  317. Error_manager System_executor::check_status()
  318. {
  319. if ( m_system_executor_status == SYSTEM_EXECUTOR_READY )
  320. {
  321. if ( m_thread_pool.thread_is_full_load() == false )
  322. {
  323. return Error_code::SUCCESS;
  324. }
  325. else
  326. {
  327. return Error_manager(Error_code::SYSTEM_EXECUTOR_STATUS_BUSY, Error_level::NEGLIGIBLE_ERROR,
  328. " System_executor::check_status error ");
  329. }
  330. }
  331. else
  332. {
  333. return Error_manager(Error_code::SYSTEM_EXECUTOR_STATUS_ERROR, Error_level::MINOR_ERROR,
  334. " System_executor::check_status error ");
  335. }
  336. }
  337. //定时发送状态信息
  338. Error_manager System_executor::encapsulate_send_status()
  339. {
  340. Error_manager t_error;
  341. return Error_code::SUCCESS;
  342. int t_dispatch_manager_id = Dispatch_manager::get_instance_references().get_dispatch_manager_id();
  343. std::string t_msg;
  344. /*
  345. //创建一条 调度管理总管理的状态
  346. message::Dispatch_manager_status_msg t_dispatch_manager_status_msg;
  347. t_dispatch_manager_status_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_manager_status_msg);
  348. t_dispatch_manager_status_msg.mutable_base_info()->set_timeout_ms(5000);
  349. t_dispatch_manager_status_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch);
  350. t_dispatch_manager_status_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  351. t_dispatch_manager_status_msg.set_dispatch_id(t_dispatch_id);
  352. Dispatch_manager::Dispatch_manager_status t_dispatch_manager_status = Dispatch_manager::get_instance_references().get_dispatch_manager_status();
  353. t_dispatch_manager_status_msg.set_dispatch_manager_status((message::Dispatch_manager_status)t_dispatch_manager_status);
  354. t_msg = t_dispatch_manager_status_msg.SerializeAsString();
  355. System_communication::get_instance_references().encapsulate_msg(t_msg);
  356. */
  357. /*
  358. //创建4条 调度模块终端出入口的状态
  359. message::Dispatch_terminal_status_msg t_dispatch_terminal_status_msg;
  360. t_dispatch_terminal_status_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_status_msg);
  361. t_dispatch_terminal_status_msg.mutable_base_info()->set_timeout_ms(5000);
  362. t_dispatch_terminal_status_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  363. t_dispatch_terminal_status_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  364. t_dispatch_terminal_status_msg.set_terminal_id(t_dispatch_manager_id*2+0);
  365. t_dispatch_terminal_status_msg.set_terminal_status(message::Terminal_status::E_TERMINAL_READY);
  366. t_dispatch_terminal_status_msg.set_passageway_direction(message::Passageway_direction::E_INLET);
  367. t_msg = t_dispatch_terminal_status_msg.SerializeAsString();
  368. System_communication::get_instance_references().encapsulate_msg(t_msg);
  369. t_dispatch_terminal_status_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_status_msg);
  370. t_dispatch_terminal_status_msg.mutable_base_info()->set_timeout_ms(5000);
  371. t_dispatch_terminal_status_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  372. t_dispatch_terminal_status_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  373. t_dispatch_terminal_status_msg.set_terminal_id(t_dispatch_manager_id*2+0);
  374. t_dispatch_terminal_status_msg.set_terminal_status(message::Terminal_status::E_TERMINAL_READY);
  375. t_dispatch_terminal_status_msg.set_passageway_direction(message::Passageway_direction::E_OUTLET);
  376. t_msg = t_dispatch_terminal_status_msg.SerializeAsString();
  377. System_communication::get_instance_references().encapsulate_msg(t_msg);
  378. t_dispatch_terminal_status_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_status_msg);
  379. t_dispatch_terminal_status_msg.mutable_base_info()->set_timeout_ms(5000);
  380. t_dispatch_terminal_status_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  381. t_dispatch_terminal_status_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  382. t_dispatch_terminal_status_msg.set_terminal_id(t_dispatch_manager_id*2+1);
  383. t_dispatch_terminal_status_msg.set_terminal_status(message::Terminal_status::E_TERMINAL_READY);
  384. t_dispatch_terminal_status_msg.set_passageway_direction(message::Passageway_direction::E_INLET);
  385. t_msg = t_dispatch_terminal_status_msg.SerializeAsString();
  386. System_communication::get_instance_references().encapsulate_msg(t_msg);
  387. t_dispatch_terminal_status_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_status_msg);
  388. t_dispatch_terminal_status_msg.mutable_base_info()->set_timeout_ms(5000);
  389. t_dispatch_terminal_status_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  390. t_dispatch_terminal_status_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  391. t_dispatch_terminal_status_msg.set_terminal_id(t_dispatch_manager_id*2+1);
  392. t_dispatch_terminal_status_msg.set_terminal_status(message::Terminal_status::E_TERMINAL_READY);
  393. t_dispatch_terminal_status_msg.set_passageway_direction(message::Passageway_direction::E_OUTLET);
  394. t_msg = t_dispatch_terminal_status_msg.SerializeAsString();
  395. System_communication::get_instance_references().encapsulate_msg(t_msg);
  396. */
  397. return Error_code::SUCCESS;
  398. }
  399. //定时发送 调度管理的状态
  400. Error_manager System_executor::encapsulate_send_dispatch_manager_status()
  401. {
  402. return Dispatch_manager::get_instance_references().encapsulate_send_dispatch_manager_status();
  403. }
  404. //判断是否为待机,如果已经准备好,则可以执行任务。
  405. bool System_executor::is_ready()
  406. {
  407. if ( m_system_executor_status == SYSTEM_EXECUTOR_READY && m_thread_pool.thread_is_full_load() == false )
  408. {
  409. return true;
  410. }
  411. else
  412. {
  413. return false;
  414. }
  415. }
  416. System_executor::System_executor_status System_executor::get_system_executor_status()
  417. {
  418. return m_system_executor_status;
  419. }
  420. //雷达感测定位 的处理函数
  421. //input::command_id, 消息指令id, 由主控制系统生成的唯一码
  422. //input::command_id, 终端id, 对应具体的某个车位
  423. //return::void, 没有返回, 执行结果直接生成一条答复消息, 然后通过通信返回
  424. void System_executor::execute_for_measure(std::string command_key, int unit_id, int terminal_id)
  425. {
  426. Error_manager t_error;
  427. LOG(INFO) << " System_executor::execute_for_measure run "<< this;
  428. //这里要处理.......以后再写
  429. //创建一条答复消息
  430. message::Measure_response_msg t_measure_response_msg;
  431. t_measure_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eLocate_response_msg);
  432. t_measure_response_msg.mutable_base_info()->set_timeout_ms(5000);
  433. t_measure_response_msg.mutable_base_info()->set_sender(message::Communicator::eMeasurer);
  434. t_measure_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  435. t_measure_response_msg.set_command_key(command_key);
  436. t_measure_response_msg.mutable_id_struct()->set_unit_id(unit_id);
  437. t_measure_response_msg.mutable_id_struct()->set_terminal_id(terminal_id);
  438. t_measure_response_msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
  439. t_measure_response_msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
  440. t_measure_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description());
  441. t_measure_response_msg.mutable_locate_information()->set_locate_x(0);
  442. t_measure_response_msg.mutable_locate_information()->set_locate_y(0);
  443. t_measure_response_msg.mutable_locate_information()->set_locate_angle(0);
  444. t_measure_response_msg.mutable_locate_information()->set_locate_length(0);
  445. t_measure_response_msg.mutable_locate_information()->set_locate_width(0);
  446. t_measure_response_msg.mutable_locate_information()->set_locate_height(0);
  447. t_measure_response_msg.mutable_locate_information()->set_locate_wheel_base(0);
  448. t_measure_response_msg.mutable_locate_information()->set_locate_wheel_width(0);
  449. t_measure_response_msg.mutable_locate_information()->set_locate_correct(0);
  450. std::string t_msg = t_measure_response_msg.SerializeAsString();
  451. System_communication::get_instance_references().encapsulate_msg(t_msg);
  452. LOG(INFO) << " System_executor::execute_for_measure end "<< this;
  453. return ;
  454. }
  455. //调度模块的处理函数
  456. void System_executor::execute_for_dispatch(std::string command_key, Dispatch_manager::Dispatch_motion_direction dispatch_motion_direction,
  457. int terminal_id, int parkspace_id, Locate_information * p_locate_information)
  458. {
  459. Error_manager t_error;
  460. LOG(INFO) << " System_executor::execute_for_dispatch run "<< this;
  461. //这里要处理.......以后再写
  462. t_error = Dispatch_manager::get_instance_references().execute_task(dispatch_motion_direction);
  463. //创建一条答复消息
  464. message::Dispatch_response_msg t_dispatch_response_msg;
  465. t_dispatch_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_response_msg);
  466. t_dispatch_response_msg.mutable_base_info()->set_timeout_ms(5000);
  467. t_dispatch_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_manager);
  468. t_dispatch_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
  469. t_dispatch_response_msg.set_command_key(command_key);
  470. t_dispatch_response_msg.mutable_error_manager()->set_error_code(t_error.get_error_code());
  471. t_dispatch_response_msg.mutable_error_manager()->set_error_level((message::Error_level)t_error.get_error_level());
  472. t_dispatch_response_msg.mutable_error_manager()->set_error_description(t_error.get_error_description());
  473. std::string t_msg = t_dispatch_response_msg.SerializeAsString();
  474. System_communication::get_instance_references().encapsulate_msg(t_msg);
  475. std::cout << "huli test dispatch_motion_direction = " << dispatch_motion_direction << std::endl;
  476. std::cout << "huli test error = " << t_error << std::endl;
  477. LOG(INFO) << " System_executor::execute_for_dispatch end "<< this;
  478. return ;
  479. }
  480. //调度模块的处理函数
  481. void System_executor::execute_for_dispatch_request_msg(message::Dispatch_request_msg dispatch_request_msg)
  482. {
  483. Error_manager t_error;
  484. t_error = Dispatch_manager::get_instance_references().execute_for_dispatch_request_msg(dispatch_request_msg);
  485. if ( t_error != Error_code::SUCCESS )
  486. {
  487. LOG(INFO) << " System_executor::execute_for_dispatch_request_msg fun error "<< this;
  488. LOG(INFO) << t_error.to_string() << " "<< this;
  489. }
  490. return;
  491. }
  492. //调度模块 //调度总规划的答复(调度算法->调度管理)
  493. void System_executor::execute_for_dispatch_plan_response_msg(message::Dispatch_plan_response_msg dispatch_plan_response_msg)
  494. {
  495. Error_manager t_error;
  496. t_error = Dispatch_manager::get_instance_references().execute_for_dispatch_plan_response_msg(dispatch_plan_response_msg);
  497. if ( t_error != Error_code::SUCCESS )
  498. {
  499. LOG(INFO) << " System_executor::execute_for_dispatch_request_msg fun error "<< this;
  500. LOG(INFO) << t_error.to_string() << " "<< this;
  501. }
  502. return;
  503. }
  504. //调度模块 //调度控制的任务请求(调度算法->调度管理)
  505. void System_executor::execute_for_dispatch_control_request_msg(message::Dispatch_control_request_msg dispatch_control_request_msg)
  506. {
  507. Error_manager t_error;
  508. t_error = Dispatch_manager::get_instance_references().execute_for_dispatch_control_request_msg(dispatch_control_request_msg);
  509. if ( t_error != Error_code::SUCCESS )
  510. {
  511. LOG(INFO) << " System_executor::execute_for_dispatch_request_msg fun error "<< this;
  512. LOG(INFO) << t_error.to_string() << " "<< this;
  513. }
  514. return;
  515. }
  516. //地面雷达的状态消息(地面雷达->null)
  517. void System_executor::execute_for_ground_status_msg(message::Ground_status_msg ground_status_msg)
  518. {
  519. Error_manager t_error;
  520. t_error = Dispatch_manager::get_instance_references().execute_for_ground_status_msg(ground_status_msg);
  521. if ( t_error != Error_code::SUCCESS )
  522. {
  523. LOG(INFO) << " System_executor::execute_for_dispatch_request_msg fun error "<< this;
  524. LOG(INFO) << t_error.to_string() << " "<< this;
  525. }
  526. return ;
  527. }
  528. //地面雷达的状态消息(地面雷达->null)
  529. void System_executor::execute_for_terminal_status_msg(message::Terminal_status_msg terminal_status_msg)
  530. {
  531. Error_manager t_error;
  532. t_error = Dispatch_manager::get_instance_references().execute_for_singlechip_data_msg(terminal_status_msg.singlechipdata(), terminal_status_msg.singlechip_validity());
  533. if ( t_error != Error_code::SUCCESS )
  534. {
  535. LOG(INFO) << " System_executor::execute_for_singlechip_data_msg fun error "<< this;
  536. LOG(INFO) << t_error.to_string() << " "<< this;
  537. }
  538. return ;
  539. }
  540. //调度模块 ///单片机的状态消息
  541. void System_executor::execute_for_notify_status_msg(message::Notify_status_msg notify_status_msg)
  542. {
  543. // LOG(INFO) << "notify_status_msg = " << notify_status_msg.DebugString()<< this;
  544. Error_manager t_error;
  545. t_error = Dispatch_manager::get_instance_references().execute_for_singlechip_data_msg(notify_status_msg.singlechipdata(), notify_status_msg.singlechip_validity());
  546. if ( t_error != Error_code::SUCCESS )
  547. {
  548. LOG(INFO) << " System_executor::execute_for_singlechip_data_msg fun error "<< this;
  549. LOG(INFO) << t_error.to_string() << " "<< this;
  550. }
  551. return ;
  552. }