@@ -25,97 +25,99 @@ Author: i11 - Embedded Software, RWTH Aachen University
25
25
#ifndef RTPS_LOCATOR_T_H
26
26
#define RTPS_LOCATOR_T_H
27
27
28
- #include " ucdr/microcdr.h"
29
- #include " rtps/utils/udpUtils.h"
30
28
#include " rtps/communication/UdpDriver.h"
29
+ #include " rtps/utils/udpUtils.h"
30
+ #include " ucdr/microcdr.h"
31
31
32
32
#include < array>
33
33
34
- namespace rtps {
35
- enum class LocatorKind_t : int32_t {
36
- LOCATOR_KIND_INVALID = -1 ,
37
- LOCATOR_KIND_RESERVED = 0 ,
38
- LOCATOR_KIND_UDPv4 = 1 ,
39
- LOCATOR_KIND_UDPv6 = 2
40
- };
41
-
42
- const uint32_t LOCATOR_PORT_INVALID = 0 ;
43
- const std::array<uint8_t , 16 > LOCATOR_ADDRESS_INVALID = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 };
44
-
45
- struct Locator {
46
- LocatorKind_t kind = LocatorKind_t::LOCATOR_KIND_INVALID;
47
- uint32_t port = LOCATOR_PORT_INVALID;
48
- std::array<uint8_t ,16 > address = LOCATOR_ADDRESS_INVALID; // TODO make private such that kind and address always match?
49
-
50
- static Locator createUDPv4Locator (uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint32_t port){
51
- Locator locator;
52
- locator.kind = LocatorKind_t::LOCATOR_KIND_UDPv4;
53
- locator.address = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,a,b,c,d};
54
- locator.port = port;
55
- return locator;
56
- }
57
-
58
- void setInvalid (){
59
- kind = LocatorKind_t::LOCATOR_KIND_INVALID;
60
- }
61
-
62
- bool isValid () const {
63
- return kind != LocatorKind_t::LOCATOR_KIND_INVALID;
64
- }
65
-
66
- bool readFromUcdrBuffer (ucdrBuffer& buffer){
67
- if (ucdr_buffer_remaining (&buffer) < sizeof (Locator)){
68
- return false ;
69
- }else {
70
- ucdr_deserialize_array_uint8_t (&buffer, reinterpret_cast <uint8_t *>(this ), sizeof (Locator));
71
- return true ;
72
- }
73
- }
74
-
75
- bool serializeIntoUdcrBuffer (ucdrBuffer& buffer){
76
- if (ucdr_buffer_remaining (&buffer) < sizeof (Locator)){
77
- return false ;
78
- }else {
79
- ucdr_serialize_array_uint8_t (&buffer, reinterpret_cast <uint8_t *>(this ), sizeof (Locator));
80
- }
81
- }
82
-
83
- ip4_addr_t getIp4Address () const {
84
- return transformIP4ToU32 (address[12 ], address[13 ], address[14 ], address[15 ]);
85
- }
86
-
87
- inline bool isSameSubnet () const {
88
- return UdpDriver::isSameSubnet (getIp4Address ());
89
- }
90
-
91
- } __attribute__((packed));
92
-
93
- inline Locator getBuiltInUnicastLocator (ParticipantId_t participantId) {
94
- return Locator::createUDPv4Locator (Config::IP_ADDRESS[0 ], Config::IP_ADDRESS[1 ],
95
- Config::IP_ADDRESS[2 ], Config::IP_ADDRESS[3 ],
96
- getBuiltInUnicastPort (participantId));
34
+ namespace rtps {
35
+ enum class LocatorKind_t : int32_t {
36
+ LOCATOR_KIND_INVALID = -1 ,
37
+ LOCATOR_KIND_RESERVED = 0 ,
38
+ LOCATOR_KIND_UDPv4 = 1 ,
39
+ LOCATOR_KIND_UDPv6 = 2
40
+ };
41
+
42
+ const uint32_t LOCATOR_PORT_INVALID = 0 ;
43
+ const std::array<uint8_t , 16 > LOCATOR_ADDRESS_INVALID = {
44
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
45
+
46
+ struct Locator {
47
+ LocatorKind_t kind = LocatorKind_t::LOCATOR_KIND_INVALID;
48
+ uint32_t port = LOCATOR_PORT_INVALID;
49
+ std::array<uint8_t , 16 > address =
50
+ LOCATOR_ADDRESS_INVALID; // TODO make private such that kind and address
51
+ // always match?
52
+
53
+ static Locator createUDPv4Locator (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
54
+ uint32_t port) {
55
+ Locator locator;
56
+ locator.kind = LocatorKind_t::LOCATOR_KIND_UDPv4;
57
+ locator.address = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , a, b, c, d};
58
+ locator.port = port;
59
+ return locator;
60
+ }
61
+
62
+ void setInvalid () { kind = LocatorKind_t::LOCATOR_KIND_INVALID; }
63
+
64
+ bool isValid () const { return kind != LocatorKind_t::LOCATOR_KIND_INVALID; }
65
+
66
+ bool readFromUcdrBuffer (ucdrBuffer &buffer) {
67
+ if (ucdr_buffer_remaining (&buffer) < sizeof (Locator)) {
68
+ return false ;
69
+ } else {
70
+ ucdr_deserialize_array_uint8_t (&buffer, reinterpret_cast <uint8_t *>(this ),
71
+ sizeof (Locator));
72
+ return true ;
97
73
}
98
-
99
- inline Locator getBuiltInMulticastLocator () {
100
- return Locator::createUDPv4Locator (239 , 255 , 0 , 1 , getBuiltInMulticastPort ());
74
+ }
75
+
76
+ bool serializeIntoUdcrBuffer (ucdrBuffer &buffer) {
77
+ if (ucdr_buffer_remaining (&buffer) < sizeof (Locator)) {
78
+ return false ;
79
+ } else {
80
+ ucdr_serialize_array_uint8_t (&buffer, reinterpret_cast <uint8_t *>(this ),
81
+ sizeof (Locator));
101
82
}
83
+ }
102
84
103
- inline Locator getUserUnicastLocator (ParticipantId_t participantId) {
104
- return Locator::createUDPv4Locator (Config::IP_ADDRESS[0 ], Config::IP_ADDRESS[1 ],
105
- Config::IP_ADDRESS[2 ], Config::IP_ADDRESS[3 ],
106
- getUserUnicastPort (participantId));
107
- }
85
+ ip4_addr_t getIp4Address () const {
86
+ return transformIP4ToU32 (address[12 ], address[13 ], address[14 ],
87
+ address[15 ]);
88
+ }
108
89
109
- inline Locator getUserMulticastLocator () {
110
- return Locator::createUDPv4Locator (Config::IP_ADDRESS[0 ], Config::IP_ADDRESS[1 ],
111
- Config::IP_ADDRESS[2 ], Config::IP_ADDRESS[3 ],
112
- getUserMulticastPort ());
113
- }
90
+ inline bool isSameSubnet () const {
91
+ return UdpDriver::isSameSubnet (getIp4Address ());
92
+ }
114
93
115
- inline Locator getDefaultSendMulticastLocator () {
116
- return Locator::createUDPv4Locator (239 , 255 , 0 , 1 ,
117
- getBuiltInMulticastPort ());
118
- }
94
+ } __attribute__((packed));
95
+
96
+ inline Locator getBuiltInUnicastLocator (ParticipantId_t participantId) {
97
+ return Locator::createUDPv4Locator (
98
+ Config::IP_ADDRESS[0 ], Config::IP_ADDRESS[1 ], Config::IP_ADDRESS[2 ],
99
+ Config::IP_ADDRESS[3 ], getBuiltInUnicastPort (participantId));
100
+ }
101
+
102
+ inline Locator getBuiltInMulticastLocator () {
103
+ return Locator::createUDPv4Locator (239 , 255 , 0 , 1 , getBuiltInMulticastPort ());
104
+ }
105
+
106
+ inline Locator getUserUnicastLocator (ParticipantId_t participantId) {
107
+ return Locator::createUDPv4Locator (
108
+ Config::IP_ADDRESS[0 ], Config::IP_ADDRESS[1 ], Config::IP_ADDRESS[2 ],
109
+ Config::IP_ADDRESS[3 ], getUserUnicastPort (participantId));
110
+ }
111
+
112
+ inline Locator getUserMulticastLocator () {
113
+ return Locator::createUDPv4Locator (
114
+ Config::IP_ADDRESS[0 ], Config::IP_ADDRESS[1 ], Config::IP_ADDRESS[2 ],
115
+ Config::IP_ADDRESS[3 ], getUserMulticastPort ());
116
+ }
117
+
118
+ inline Locator getDefaultSendMulticastLocator () {
119
+ return Locator::createUDPv4Locator (239 , 255 , 0 , 1 , getBuiltInMulticastPort ());
119
120
}
121
+ } // namespace rtps
120
122
121
- #endif // RTPS_LOCATOR_T_H
123
+ #endif // RTPS_LOCATOR_T_H
0 commit comments