From 537222c6580bb1a028b6a4d7feac20a36552fb28 Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Sun, 12 Nov 2023 17:59:59 -0800 Subject: [PATCH] AP_DDS: Add user-selectable UDP IP --- libraries/AP_DDS/AP_DDS_Client.cpp | 4 ++++ libraries/AP_DDS/AP_DDS_Client.h | 3 ++- libraries/AP_DDS/AP_DDS_UDP.cpp | 2 +- libraries/AP_DDS/AP_DDS_config.h | 10 +++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libraries/AP_DDS/AP_DDS_Client.cpp b/libraries/AP_DDS/AP_DDS_Client.cpp index 29560fcc79208..100f51de2fe3c 100644 --- a/libraries/AP_DDS/AP_DDS_Client.cpp +++ b/libraries/AP_DDS/AP_DDS_Client.cpp @@ -65,6 +65,10 @@ const AP_Param::GroupInfo AP_DDS_Client::var_info[] { // @User: Standard AP_GROUPINFO("_PORT", 2, AP_DDS_Client, udp.port, 2019), + // @Group: _IP + // @Path: ../AP_Networking/AP_Networking_address.cpp + AP_SUBGROUPINFO(udp.ip, "_IP", 3, AP_DDS_Client, AP_Networking_IPV4), + #endif AP_GROUPEND diff --git a/libraries/AP_DDS/AP_DDS_Client.h b/libraries/AP_DDS/AP_DDS_Client.h index acdf4c7ddcb16..19d20c3017d24 100644 --- a/libraries/AP_DDS/AP_DDS_Client.h +++ b/libraries/AP_DDS/AP_DDS_Client.h @@ -31,6 +31,7 @@ #if AP_DDS_UDP_ENABLED #include +#include #endif extern const AP_HAL::HAL& hal; @@ -138,7 +139,7 @@ class AP_DDS_Client struct { AP_Int32 port; // UDP endpoint - const char* ip = "127.0.0.1"; + AP_Networking_IPV4 ip{AP_DDS_DEFAULT_UDP_IP_ADDR}; // UDP Allocation uxrCustomTransport transport; SocketAPM *socket; diff --git a/libraries/AP_DDS/AP_DDS_UDP.cpp b/libraries/AP_DDS/AP_DDS_UDP.cpp index 2610291231dba..6593100618bb5 100644 --- a/libraries/AP_DDS/AP_DDS_UDP.cpp +++ b/libraries/AP_DDS/AP_DDS_UDP.cpp @@ -14,7 +14,7 @@ bool AP_DDS_Client::udp_transport_open(uxrCustomTransport *t) if (sock == nullptr) { return false; } - if (!sock->connect(dds->udp.ip, dds->udp.port.get())) { + if (!sock->connect(dds->udp.ip.get_str(), dds->udp.port.get())) { return false; } dds->udp.socket = sock; diff --git a/libraries/AP_DDS/AP_DDS_config.h b/libraries/AP_DDS/AP_DDS_config.h index 244cb0d7ffd4a..094d2d4efb96c 100644 --- a/libraries/AP_DDS/AP_DDS_config.h +++ b/libraries/AP_DDS/AP_DDS_config.h @@ -9,10 +9,18 @@ // UDP only on SITL for now #ifndef AP_DDS_UDP_ENABLED -#define AP_DDS_UDP_ENABLED AP_DDS_ENABLED && AP_NETWORKING_SOCKETS_ENABLED +#define AP_DDS_UDP_ENABLED AP_DDS_ENABLED && AP_NETWORKING_ENABLED #endif #include #ifndef AP_DDS_VISUALODOM_ENABLED #define AP_DDS_VISUALODOM_ENABLED HAL_VISUALODOM_ENABLED && AP_DDS_ENABLED #endif + +#ifndef AP_DDS_DEFAULT_UDP_IP_ADDR +#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS + #define AP_DDS_DEFAULT_UDP_IP_ADDR "192.168.13.2" +#else + #define AP_DDS_DEFAULT_UDP_IP_ADDR "127.0.0.1" +#endif +#endif