test_parkspace_sample.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * @Description: 测试车位分配模块通信情况
  3. * @Author: yct
  4. * @Date: 2020-07-08 15:51:46
  5. * @LastEditTime: 2020-07-22 14:17:07
  6. * @LastEditors: yct
  7. */
  8. #include "../parkspace_allocation/parkspace_allocation_communicator.h"
  9. #include "../parkspace_allocation/parkspace_allocator.h"
  10. int main()
  11. {
  12. google::InitGoogleLogging("parkspace_allocator");
  13. google::SetStderrLogging(google::INFO);
  14. google::InstallFailureSignalHandler();
  15. FLAGS_colorlogtostderr = true;
  16. Parkspace_allocation_communicator *p_parkspace_allocation_communicater = Parkspace_allocation_communicator::get_instance_pointer();
  17. Parkspace_allocator *p_parkspace_allocator = Parkspace_allocator::get_instance_pointer();
  18. parkspace_proto::database_config config;
  19. config.set_db_ip("127.0.0.1");
  20. config.set_db_port(3306);
  21. config.set_db_username("yct");
  22. config.set_db_passwd("123456");
  23. config.set_db_name("test");
  24. config.set_db_conn_pool_size(5);
  25. p_parkspace_allocator->parkspace_allocator_init(4, config);
  26. p_parkspace_allocation_communicater->communication_bind("tcp://127.0.0.1:7001");
  27. // p_parkspace_allocation_communicater->communication_bind("tcp://192.168.2.125:7001");
  28. // p_parkspace_allocation_communicater->communication_connect("tcp://127.0.0.1:7000");
  29. p_parkspace_allocation_communicater->communication_run();
  30. // // 初始化车位,创建三个车位
  31. // message::Parkspace_allocation_status_msg parkspace_status;
  32. // for (size_t i = 1; i < 1000; i++)
  33. // {
  34. // message::Parkspace_info* space = parkspace_status.add_parkspace_info();
  35. // space->set_parkspace_id(i);
  36. // space->set_index(i);
  37. // space->set_direction(message::Direction::eForward);
  38. // space->set_floor(2+i);
  39. // space->set_length(5.5);
  40. // space->set_width(2.2);
  41. // space->set_height(1.75);
  42. // space->set_parkspace_status(message::Parkspace_status::eParkspace_empty);
  43. // }
  44. // message::Base_info base_msg;
  45. // message::Error_manager error;
  46. // base_msg.set_msg_type(message::Message_type::eParkspace_allocation_response_msg);
  47. // base_msg.set_timeout_ms(1000);
  48. // base_msg.set_sender(message::Communicator::eParkspace);
  49. // base_msg.set_receiver(message::Communicator::eMain);
  50. // error.set_error_code(0);
  51. // parkspace_status.mutable_base_info()->CopyFrom(base_msg);
  52. // parkspace_status.mutable_error_manager()->CopyFrom(error);
  53. // p_parkspace_allocation_communicater->update_parkspace_status(parkspace_status);
  54. int k=1;
  55. while(1) {
  56. // message::Parkspace_info space;
  57. // space.set_parkspace_id(3);
  58. // space.set_index(k);
  59. // space.set_direction(message::Direction::eForward);
  60. // space.set_floor(k*3);
  61. // space.set_length(5500);
  62. // space.set_width(2200);
  63. // space.set_height(k*400);
  64. // space.set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
  65. // p_parkspace_allocator->update_parkspace_status(3, space);
  66. usleep(1000*1000);
  67. k++;
  68. }
  69. p_parkspace_allocator->parkspace_allocator_uninit();
  70. return 0;
  71. }