From 35188e03c3fca79013395270ed82d56a1727dc7a Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Fri, 17 Nov 2023 11:20:39 -0800 Subject: [PATCH] AP_Networking: adjustable PORT buf size --- libraries/AP_Networking/AP_Networking.h | 4 ++-- libraries/AP_Networking/AP_Networking_Config.h | 8 ++++++++ libraries/AP_Networking/AP_Networking_port.cpp | 12 ++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/libraries/AP_Networking/AP_Networking.h b/libraries/AP_Networking/AP_Networking.h index e49f25a697ba4..58adaa3ac68c8 100644 --- a/libraries/AP_Networking/AP_Networking.h +++ b/libraries/AP_Networking/AP_Networking.h @@ -206,11 +206,11 @@ class AP_Networking return false; } - void udp_client_init(void); + void udp_client_init(const uint32_t size_rx, const uint32_t size_tx); void udp_client_loop(void); private: - bool init_buffers(uint32_t size); + bool init_buffers(const uint32_t size_rx, const uint32_t size_tx); uint32_t txspace() override; void _begin(uint32_t b, uint16_t rxS, uint16_t txS) override; diff --git a/libraries/AP_Networking/AP_Networking_Config.h b/libraries/AP_Networking/AP_Networking_Config.h index bfc4af537f226..f7449065758ef 100644 --- a/libraries/AP_Networking/AP_Networking_Config.h +++ b/libraries/AP_Networking/AP_Networking_Config.h @@ -22,6 +22,14 @@ #define AP_NETWORKING_SOCKETS_ENABLED (HAL_OS_SOCKETS || AP_NETWORKING_BACKEND_CHIBIOS) +#ifndef AP_NETWORKING_PORT_UDP_CLIENT_RX_BUF_DEFAULT_SIZE +#define AP_NETWORKING_PORT_UDP_CLIENT_RX_BUF_DEFAULT_SIZE 4096 +#endif + +#ifndef AP_NETWORKING_PORT_UDP_CLIENT_TX_BUF_DEFAULT_SIZE +#define AP_NETWORKING_PORT_UDP_CLIENT_TX_BUF_DEFAULT_SIZE 4096 +#endif + // --------------------------- // IP Features // --------------------------- diff --git a/libraries/AP_Networking/AP_Networking_port.cpp b/libraries/AP_Networking/AP_Networking_port.cpp index 3a87db30cfba0..a476218955c0a 100644 --- a/libraries/AP_Networking/AP_Networking_port.cpp +++ b/libraries/AP_Networking/AP_Networking_port.cpp @@ -61,7 +61,7 @@ void AP_Networking::ports_init(void) case NetworkPortType::NONE: break; case NetworkPortType::UDP_CLIENT: - p.udp_client_init(); + p.udp_client_init(AP_NETWORKING_PORT_UDP_CLIENT_RX_BUF_DEFAULT_SIZE, AP_NETWORKING_PORT_UDP_CLIENT_TX_BUF_DEFAULT_SIZE); break; } if (p.sock != nullptr) { @@ -73,9 +73,9 @@ void AP_Networking::ports_init(void) /* initialise a UDP client */ -void AP_Networking::Port::udp_client_init(void) +void AP_Networking::Port::udp_client_init(const uint32_t size_rx, const uint32_t size_tx) { - if (!init_buffers(4096)) { + if (!init_buffers(size_rx, size_tx)) { return; } sock = new SocketAPM(true); @@ -171,10 +171,10 @@ bool AP_Networking::Port::_discard_input() /* initialise read/write buffers */ -bool AP_Networking::Port::init_buffers(uint32_t size) +bool AP_Networking::Port::init_buffers(const uint32_t size_rx, const uint32_t size_tx) { - readbuffer = new ByteBuffer(size); - writebuffer = new ByteBuffer(size); + readbuffer = new ByteBuffer(size_rx); + writebuffer = new ByteBuffer(size_tx); return readbuffer != nullptr && writebuffer != nullptr; }