TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
team_receiver_example.cpp File Reference

Example to read data published from a team. More...

#include <iostream>
#include <boost/asio.hpp>
#include "travesim_adapters/protobuf/team_receiver.hpp"
Include dependency graph for team_receiver_example.cpp:

Go to the source code of this file.

Macros

#define BUFFER_SIZE   1024U
 
#define CLEAR_TERMINAL   "\033[2J\033[H"
 

Functions

int main (int argc, char *argv[])
 

Detailed Description

Example to read data published from a team.

Author
Lucas Haug lucas.nosp@m..hau.nosp@m.g@thu.nosp@m.nera.nosp@m.tz.or.nosp@m.g
Lucas Schneider lucas.nosp@m..sch.nosp@m.neide.nosp@m.r@th.nosp@m.unera.nosp@m.tz.o.nosp@m.rg
Felipe Gomes de Melo felip.nosp@m.e.go.nosp@m.mes@t.nosp@m.hune.nosp@m.ratz..nosp@m.org
Date
04/2021

Definition in file team_receiver_example.cpp.

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   1024U

Definition at line 24 of file team_receiver_example.cpp.

◆ CLEAR_TERMINAL

#define CLEAR_TERMINAL   "\033[2J\033[H"

Definition at line 25 of file team_receiver_example.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 31 of file team_receiver_example.cpp.

31  {
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 }
#define CLEAR_TERMINAL
Data structure to hold the command for a team.
Team control data receiver class with UDP and protobuf.

References CLEAR_TERMINAL, and travesim::proto::TeamReceiver::receive().

Here is the call graph for this function: