From bd97dc4de53adc94b1f0341a19d439b81163f494 Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Sun, 12 Nov 2023 14:09:58 -0800 Subject: [PATCH] AP_Networking: cleanup backend defines --- libraries/AP_Networking/AP_Networking.cpp | 24 ++++++++++++++++--- libraries/AP_Networking/AP_Networking.h | 21 +++++++--------- .../AP_Networking/AP_Networking_ChibiOS.cpp | 6 ++--- .../AP_Networking/AP_Networking_ChibiOS.h | 4 ++-- .../AP_Networking/AP_Networking_Config.h | 19 ++++++++++++++- .../AP_Networking/AP_Networking_backend.h | 2 ++ 6 files changed, 53 insertions(+), 23 deletions(-) diff --git a/libraries/AP_Networking/AP_Networking.cpp b/libraries/AP_Networking/AP_Networking.cpp index fa1b422008..8a21c95d24 100644 --- a/libraries/AP_Networking/AP_Networking.cpp +++ b/libraries/AP_Networking/AP_Networking.cpp @@ -4,13 +4,14 @@ #if AP_NETWORKING_ENABLED #include "AP_Networking.h" -#include "AP_Networking_ChibiOS.h" +#include "AP_Networking_backend.h" #include #include extern const AP_HAL::HAL& hal; -#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#if AP_NETWORKING_BACKEND_CHIBIOS +#include "AP_Networking_ChibiOS.h" #include #include #else @@ -96,7 +97,7 @@ void AP_Networking::init() param.macaddr.set_default_address_byte(5, crc.bytes[2]); } -#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#if AP_NETWORKING_BACKEND_CHIBIOS backend = new AP_Networking_ChibiOS(*this); #endif @@ -211,6 +212,23 @@ bool AP_Networking::convert_str_to_macaddr(const char *mac_str, uint8_t addr[6]) return true; } +// returns the 32bit value of the active IP address that is currently in use +uint32_t AP_Networking::get_ip_active() const +{ + return backend?backend->activeSettings.ip:0; +} + +// returns the 32bit value of the active Netmask that is currently in use +uint32_t AP_Networking::get_netmask_active() const +{ + return backend?backend->activeSettings.nm:0; +} + +uint32_t AP_Networking::get_gateway_active() const +{ + return backend?backend->activeSettings.gw:0; +} + AP_Networking *AP_Networking::singleton; namespace AP diff --git a/libraries/AP_Networking/AP_Networking.h b/libraries/AP_Networking/AP_Networking.h index 0a5628c97e..10637c5367 100644 --- a/libraries/AP_Networking/AP_Networking.h +++ b/libraries/AP_Networking/AP_Networking.h @@ -4,7 +4,6 @@ #include "AP_Networking_Config.h" #if AP_NETWORKING_ENABLED -#include #include #include "AP_Networking_address.h" @@ -14,9 +13,14 @@ Note! all uint32_t IPv4 addresses are in host byte order */ +// declare backend classes +class AP_Networking_backend; +class AP_Networking_ChibiOS; + class AP_Networking { public: + friend class AP_Networking_backend; friend class AP_Networking_ChibiOS; AP_Networking(); @@ -54,10 +58,7 @@ public: } // returns the 32bit value of the active IP address that is currently in use - uint32_t get_ip_active() const - { - return backend?backend->activeSettings.ip:0; - } + uint32_t get_ip_active() const; // returns the 32bit value of the user-parameter static IP address uint32_t get_ip_param() const @@ -81,10 +82,7 @@ public: } // returns the 32bit value of the active Netmask that is currently in use - uint32_t get_netmask_active() const - { - return backend?backend->activeSettings.nm:0; - } + uint32_t get_netmask_active() const; // returns the 32bit value of the of the user-parameter static Netmask uint32_t get_netmask_param() const @@ -113,10 +111,7 @@ public: param.netmask.set(convert_netmask_ip_to_bitcount(nm)); } - uint32_t get_gateway_active() const - { - return backend?backend->activeSettings.gw:0; - } + uint32_t get_gateway_active() const; uint32_t get_gateway_param() const { diff --git a/libraries/AP_Networking/AP_Networking_ChibiOS.cpp b/libraries/AP_Networking/AP_Networking_ChibiOS.cpp index 511408084d..b79413c2aa 100644 --- a/libraries/AP_Networking/AP_Networking_ChibiOS.cpp +++ b/libraries/AP_Networking/AP_Networking_ChibiOS.cpp @@ -1,11 +1,9 @@ #include "AP_Networking_Config.h" -#if AP_NETWORKING_ENABLED && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#if AP_NETWORKING_BACKEND_CHIBIOS -#include "AP_Networking.h" #include "AP_Networking_ChibiOS.h" -#include #include #include @@ -174,5 +172,5 @@ int32_t AP_Networking_ChibiOS::send_udp(struct udp_pcb *pcb, const ip4_addr_t &i return err == ERR_OK ? data_len : err; } -#endif // AP_NETWORKING_ENABLED && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#endif // AP_NETWORKING_BACKEND_CHIBIOS diff --git a/libraries/AP_Networking/AP_Networking_ChibiOS.h b/libraries/AP_Networking/AP_Networking_ChibiOS.h index 196f621a07..d193469e89 100644 --- a/libraries/AP_Networking/AP_Networking_ChibiOS.h +++ b/libraries/AP_Networking/AP_Networking_ChibiOS.h @@ -2,7 +2,7 @@ #include "AP_Networking_Config.h" -#if AP_NETWORKING_ENABLED && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#if AP_NETWORKING_BACKEND_CHIBIOS #include "AP_Networking_backend.h" class AP_Networking_ChibiOS : public AP_Networking_backend @@ -25,5 +25,5 @@ private: uint8_t macaddr[6]; }; -#endif // AP_NETWORKING_ENABLED && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#endif // AP_NETWORKING_BACKEND_CHIBIOS diff --git a/libraries/AP_Networking/AP_Networking_Config.h b/libraries/AP_Networking/AP_Networking_Config.h index 54926c6d22..b5f43eec42 100644 --- a/libraries/AP_Networking/AP_Networking_Config.h +++ b/libraries/AP_Networking/AP_Networking_Config.h @@ -4,7 +4,24 @@ #define AP_NETWORKING_ENABLED 0 #endif -#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#ifndef AP_NETWORKING_BACKEND_DEFAULT_ENABLED +#define AP_NETWORKING_BACKEND_DEFAULT_ENABLED AP_NETWORKING_ENABLED +#endif + + +// --------------------------- +// Backends +// --------------------------- +#ifndef AP_NETWORKING_BACKEND_CHIBIOS +#define AP_NETWORKING_BACKEND_CHIBIOS AP_NETWORKING_BACKEND_DEFAULT_ENABLED && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS +#endif + +#define AP_NETWORKING_SOCKETS_ENABLED (HAL_OS_SOCKETS || AP_NETWORKING_BACKEND_CHIBIOS) + +// --------------------------- +// IP Features +// --------------------------- +#if AP_NETWORKING_BACKEND_CHIBIOS #define AP_NETWORKING_DHCP_AVAILABLE LWIP_DHCP #else #define AP_NETWORKING_DHCP_AVAILABLE 1 // for non-ChibiOS, assume it's available diff --git a/libraries/AP_Networking/AP_Networking_backend.h b/libraries/AP_Networking/AP_Networking_backend.h index 3689f40aa5..c97377c9e0 100644 --- a/libraries/AP_Networking/AP_Networking_backend.h +++ b/libraries/AP_Networking/AP_Networking_backend.h @@ -4,6 +4,8 @@ #if AP_NETWORKING_ENABLED +#include "AP_Networking.h" + class AP_Networking; class AP_Networking_backend