TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
replacer_receiver_example.cpp
Go to the documentation of this file.
1 /**
2  * @file replacer_receiver_example.cpp
3  *
4  * @author Lucas Haug <lucas.haug@thuneratz.org>
5  * @author Lucas Schneider <lucas.schneider@thuneratz.org>
6  *
7  * @brief Example to read data published from VSSReplacer
8  *
9  * @date 05/2021
10  *
11  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
12  */
13 
14 #include <queue>
15 #include <memory>
16 #include <iostream>
17 
19 
20 /*****************************************
21  * Main Function
22  *****************************************/
23 
24 int main(int argc, char* argv[]) {
25  const std::string receiver_address = "127.0.0.1";
26  const short receiver_port = 20011;
27 
28  std::queue<std::shared_ptr<travesim::EntityState>> states_queue;
29 
30  try {
31  travesim::proto::ReplacerReceiver replacer_receiver(receiver_address, receiver_port, true);
32 
33  while (true) {
34  bool received_new_msg = replacer_receiver.receive(&states_queue);
35 
36  if (received_new_msg) {
37  while (!states_queue.empty()) {
38  std::shared_ptr<travesim::RobotState> state = std::dynamic_pointer_cast<travesim::RobotState>(
39  states_queue.front());
40 
41  if (state != nullptr) {
42  std::cout << *state;
43  } else {
44  std::cout << "BALL" << std::endl;
45  std::cout << *states_queue.front();
46  }
47 
48  states_queue.pop();
49 
50  std::cout << std::endl;
51  }
52  }
53  }
54  } catch (std::exception& e) {
55  std::cerr << "Exception: " << e.what() << "\n";
56  }
57 
58  return 0;
59 }
int main(int argc, char *argv[])
Replacer receiver with UDP and protobuf.
Replacer receiver class with UDP and protobuf.
bool receive(std::queue< std::shared_ptr< EntityState >> *p_replament_queue)
Receive the replacement commands.