TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
vision_sender.hpp
Go to the documentation of this file.
1 /**
2  * @file vision_sender.hpp
3  *
4  * @author Lucas Haug <lucas.haug@thunderatz.org>
5  *
6  * @brief Vision data sender with UDP and protobuf
7  *
8  * @date 04/2021
9  *
10  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
11  */
12 
13 #include <memory>
14 
17 #include "packet.pb.h"
18 
19 #ifndef __VISION_SENDER_H__
20 #define __VISION_SENDER_H__
21 
22 namespace travesim {
23 namespace proto {
24 /**
25  * @brief Vision sender class with UDP and protobuf
26  */
27 class VisionSender {
28  public:
29  /**
30  * @brief Construct a new Vision Sender object
31  *
32  * @param multicast_address Vision multicast address
33  * @param multicast_port Vision multicast port
34  *
35  * @note The multicast addresses must be in the range 224.0.0.0 through
36  * 239.255.255.255, see multicast [IPv4 Multicast Address Space Registry]
37  * (https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml)
38  * or the [RFC1112](https://tools.ietf.org/html/rfc1112) for more informations.
39  */
40  VisionSender(const std::string multicast_address, const short multicast_port);
41 
42  /**
43  * @brief Send vision data with UDP and protobuf
44  *
45  * @param p_field_state Pointer to field state to be sent
46  *
47  * @return True if sent data successfully, false otherwise
48  */
49  bool send(FieldState* p_field_state);
50 
51  /**
52  * @brief Set the multicast endpoint
53  *
54  * @param multicast_address Vision multicast address
55  * @param multicast_port Vision multicast port
56  *
57  * @note The multicast addresses must be in the range 224.0.0.0 through
58  * 239.255.255.255, see multicast [IPv4 Multicast Address Space Registry]
59  * (https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml)
60  * or the [RFC1112](https://tools.ietf.org/html/rfc1112) for more informations.
61  */
62  void set_multicast_endpoint(const std::string multicast_address, const short multicast_port);
63 
64  /**
65  * @brief Convert a FieldState object to a Environment protobuf message object
66  *
67  * @param p_field_state Pointer to field state to be converted
68  *
69  * @return fira_message::sim_to_ref::Environment
70  */
71  static fira_message::sim_to_ref::Environment field_state_to_env_pb_msg(FieldState* p_field_state);
72 
73  private:
74  std::unique_ptr<udp::MulticastSender> multicast_sender; /**< Pointer to UDP multicast sender */
75 };
76 } // namespace proto
77 } // namespace travesim
78 
79 #endif // __VISION_SENDER_H__
Data structure to hold the field state.
Definition: field_state.hpp:25
void set_multicast_endpoint(const std::string multicast_address, const short multicast_port)
Set the multicast endpoint.
Vision sender class with UDP and protobuf.
VisionSender(const std::string multicast_address, const short multicast_port)
Construct a new Vision Sender object.
static fira_message::sim_to_ref::Environment field_state_to_env_pb_msg(FieldState *p_field_state)
Convert a FieldState object to a Environment protobuf message object.
Send data using UDP in multicast mode.
bool send(FieldState *p_field_state)
Send vision data with UDP and protobuf.
std::unique_ptr< udp::MulticastSender > multicast_sender