|
21 | 21 | #include <rmw/ret_types.h> |
22 | 22 | #include <rmw/error_handling.h> |
23 | 23 |
|
| 24 | +// #include <uxr/client/client.h> |
| 25 | + |
24 | 26 | rmw_ret_t rmw_uros_init_options( |
25 | 27 | int argc, const char * const argv[], |
26 | 28 | rmw_init_options_t * rmw_options) |
@@ -117,6 +119,58 @@ rmw_ret_t rmw_uros_options_set_udp_address( |
117 | 119 | #endif |
118 | 120 | } |
119 | 121 |
|
| 122 | +bool on_agent_found(const TransportLocator* locator, void* args) |
| 123 | +{ |
| 124 | + rmw_init_options_t * rmw_options = (rmw_init_options_t *) args; |
| 125 | + uxrIpProtocol ip_protocol; |
| 126 | + char ip[MAX_IP_LEN]; |
| 127 | + char port_str[MAX_PORT_LEN]; |
| 128 | + uint16_t port; |
| 129 | + |
| 130 | + uxr_locator_to_ip(locator, ip, sizeof(ip), &port, &ip_protocol); |
| 131 | + sprintf(port_str, "%d", port); |
| 132 | + |
| 133 | + uxrUDPTransport transport; |
| 134 | + uxrUDPPlatform udp_platform; |
| 135 | + if(uxr_init_udp_transport(&transport, &udp_platform, ip_protocol, ip, port_str)) |
| 136 | + { |
| 137 | + uxrSession session; |
| 138 | + uxr_init_session(&session, &transport.comm, rmw_options->impl->connection_params.client_key); |
| 139 | + if(uxr_create_session_retries(&session, 1)) |
| 140 | + { |
| 141 | + sprintf(rmw_options->impl->connection_params.agent_port, "%d", port); |
| 142 | + sprintf(rmw_options->impl->connection_params.agent_address, "%s", ip); |
| 143 | + uxr_delete_session(&session); |
| 144 | + return true; |
| 145 | + } |
| 146 | + } |
| 147 | + return false; |
| 148 | +} |
| 149 | + |
| 150 | +rmw_ret_t rmw_uros_discover_agent(rmw_init_options_t * rmw_options) |
| 151 | +{ |
| 152 | +#if defined(MICRO_XRCEDDS_UDP) && defined(UCLIENT_PROFILE_DISCOVERY) |
| 153 | + if (NULL == rmw_options) { |
| 154 | + RMW_SET_ERROR_MSG("Uninitialised rmw_init_options."); |
| 155 | + return RMW_RET_INVALID_ARGUMENT; |
| 156 | + } |
| 157 | + |
| 158 | + memset(rmw_options->impl->connection_params.agent_address, 0, MAX_IP_LEN); |
| 159 | + memset(rmw_options->impl->connection_params.agent_port, 0, MAX_PORT_LEN); |
| 160 | + |
| 161 | + uxr_discovery_agents_default(1, 1000, on_agent_found, (void*) rmw_options); |
| 162 | + |
| 163 | + return (strlen(rmw_options->impl->connection_params.agent_address) > 0 )? RMW_RET_OK : RMW_RET_TIMEOUT; |
| 164 | +#else |
| 165 | + (void) ip; |
| 166 | + (void) port; |
| 167 | + (void) rmw_options; |
| 168 | + |
| 169 | + RMW_SET_ERROR_MSG("MICRO_XRCEDDS_UDP or UCLIENT_PROFILE_DISCOVERY not set."); |
| 170 | + return RMW_RET_INVALID_ARGUMENT; |
| 171 | +#endif |
| 172 | +} |
| 173 | + |
120 | 174 | rmw_ret_t rmw_uros_options_set_client_key(uint32_t client_key, rmw_init_options_t * rmw_options) |
121 | 175 | { |
122 | 176 | if (NULL == rmw_options) { |
|
0 commit comments