TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
replacer_receiver.hpp
Go to the documentation of this file.
1 /**
2  * @file replacer_receiver.hpp
3  *
4  * @author Lucas Haug <lucas.haug@thunderatz.org>
5  *
6  * @brief Replacer receiver with UDP and protobuf
7  *
8  * @date 04/2021
9  *
10  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
11  */
12 
13 #include <queue>
14 #include <memory>
15 
19 #include "packet.pb.h"
20 
21 #ifndef __REPLACER_RECEIVER_H__
22 #define __REPLACER_RECEIVER_H__
23 
24 namespace travesim {
25 namespace proto {
26 /**
27  * @brief Replacer receiver class with UDP and protobuf
28  */
30  public:
31  /**
32  * @brief Construct a new ReplacerReceiver object
33  *
34  * @param receiver_address Replacer receiver address
35  * @param receiver_port Replacer receiver port
36  * @param force_specific_source Whether to enable source specific or not, default false
37  *
38  * @note The unicast addresses must be in the block 127.0.0.0/8, see
39  * [IANA IPv4 Address Space Registry]
40  * (https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml)
41  * or the [RFC6890](https://tools.ietf.org/html/rfc6890) for more informations.
42  */
43  ReplacerReceiver(const std::string receiver_address, const short receiver_port,
44  bool force_specific_source = false);
45 
46  /**
47  * @brief Receive the replacement commands
48  *
49  * @param p_replament_queue Pointer to a queue where to store the desired replacements
50  *
51  * @return true if a new message was received, false otherwise
52  */
53  bool receive(std::queue<std::shared_ptr<EntityState>>* p_replament_queue);
54 
55  /**
56  * @brief Set the receiver endpoint
57  *
58  * @param receiver_address Replacer receiver address
59  * @param receiver_port Replacer receiver port
60  *
61  * @note The unicast addresses must be in the block 127.0.0.0/8, see
62  * [IANA IPv4 Address Space Registry]
63  * (https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml)
64  * or the [RFC6890](https://tools.ietf.org/html/rfc6890) for more informations.
65  */
66  void set_receiver_endpoint(const std::string receiver_address, const short receiver_port);
67 
68  /**
69  * @brief Set wheter to enable any source or source specific multicast.
70  * True for specific source, false for any source, default is false.
71  *
72  * @param force_specific_source Whether to enable source specific or not.
73  */
75 
76  /**
77  * @brief Reset the receiver
78  */
79  void reset(void);
80 
81  /**
82  * @brief Convert a BallReplacement protobuf message to a EntityState
83  *
84  * @param p_ball_pb_msg Pointer the ball replacement protobuf message
85  *
86  * @return Converted EntityState
87  */
88  EntityState ball_rplcmt_pb_to_entity_state(const fira_message::sim_to_ref::BallReplacement* p_ball_pb_msg);
89 
90  /**
91  * @brief Convert a RobotReplacement protobuf message to a RobotState
92  *
93  * @param p_robot_pb_msg Pointer the robot replacement protobuf message
94  *
95  * @return Converted EntityState
96  */
97  RobotState robot_rplcmt_pb_to_robot_state(const fira_message::sim_to_ref::RobotReplacement* p_robot_pb_msg);
98 
99  private:
100  std::unique_ptr<udp::UnicastReceiver> unicast_receiver; /**< UDP unicast receiver */
101 };
102 } // namespace proto
103 } // namespace travesim
104 
105 #endif // __REPLACER_RECEIVER_H__
Entity state data structure.
Receiver data using UDP in unicast mode.
Robot state data structure.
EntityState ball_rplcmt_pb_to_entity_state(const fira_message::sim_to_ref::BallReplacement *p_ball_pb_msg)
Convert a BallReplacement protobuf message to a EntityState.
Data structure to hold the state of a robot in the simulation.
Definition: robot_state.hpp:23
ReplacerReceiver(const std::string receiver_address, const short receiver_port, bool force_specific_source=false)
Construct a new ReplacerReceiver object.
Replacer receiver class with UDP and protobuf.
void force_specific_source(bool force_specific_source)
Set wheter to enable any source or source specific multicast. True for specific source,...
bool receive(std::queue< std::shared_ptr< EntityState >> *p_replament_queue)
Receive the replacement commands.
Data structure to hold the state of a entity in the simulation.
void reset(void)
Reset the receiver.
RobotState robot_rplcmt_pb_to_robot_state(const fira_message::sim_to_ref::RobotReplacement *p_robot_pb_msg)
Convert a RobotReplacement protobuf message to a RobotState.
std::unique_ptr< udp::UnicastReceiver > unicast_receiver
void set_receiver_endpoint(const std::string receiver_address, const short receiver_port)
Set the receiver endpoint.