TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
team_receiver_example.cpp
Go to the documentation of this file.
1 /**
2  * @file team_receiver_example.cpp
3  *
4  * @author Lucas Haug <lucas.haug@thuneratz.org>
5  * @author Lucas Schneider <lucas.schneider@thuneratz.org>
6  * @author Felipe Gomes de Melo <felipe.gomes@thuneratz.org>
7  *
8  * @brief Example to read data published from a team
9  *
10  * @date 04/2021
11  *
12  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
13  */
14 
15 #include <iostream>
16 #include <boost/asio.hpp>
17 
19 
20 /*****************************************
21  * Private Constants
22  *****************************************/
23 
24 #define BUFFER_SIZE 1024U
25 #define CLEAR_TERMINAL "\033[2J\033[H"
26 
27 /*****************************************
28  * Main Function
29  *****************************************/
30 
31 int main(int argc, char* argv[]) {
32  const std::string receiver_address = "127.0.0.1";
33  const short receiver_port = 20011;
34 
35  travesim::TeamCommand team_yellow_cmd;
36 
37  try {
38  boost::asio::io_context io_context;
39  boost::asio::steady_timer my_timer(io_context);
40  travesim::proto::TeamReceiver yellow_receiver(receiver_address, receiver_port, true);
41 
42  while (true) {
43  bool received_new_msg = yellow_receiver.receive(&team_yellow_cmd);
44 
45  if (received_new_msg) {
46  std::cout << CLEAR_TERMINAL << team_yellow_cmd;
47  }
48 
49  my_timer.expires_after(std::chrono::milliseconds(1));
50  my_timer.wait();
51  }
52  } catch (std::exception& e) {
53  std::cerr << "Exception: " << e.what() << "\n";
54  }
55 
56  return 0;
57 }
Team control data receiver with UDP and protobuf.
#define CLEAR_TERMINAL
Data structure to hold the command for a team.
int main(int argc, char *argv[])
Team control data receiver class with UDP and protobuf.
bool receive(TeamCommand *p_team_cmd)
Receive the command from a team.