Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Networking: cleanup names and defines #25522

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions libraries/AP_Networking/AP_Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#if AP_NETWORKING_ENABLED

#include "AP_Networking.h"
#include "AP_Networking_ChibiOS.h"
#include "AP_Networking_Backend.h"
#include <GCS_MAVLink/GCS.h>
#include <AP_Math/crc.h>

extern const AP_HAL::HAL& hal;

#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
#if AP_NETWORKING_BACKEND_CHIBIOS
#include "AP_Networking_ChibiOS.h"
#include <hal_mii.h>
#include <lwip/sockets.h>
#else
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
25 changes: 10 additions & 15 deletions libraries/AP_Networking/AP_Networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
#include "AP_Networking_Config.h"

#if AP_NETWORKING_ENABLED
#include <AP_HAL/AP_HAL.h>
#include <AP_Param/AP_Param.h>

#include "AP_Networking_address.h"
#include "AP_Networking_backend.h"
#include "AP_Networking_Backend.h"

/*
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();
Expand Down Expand Up @@ -54,10 +58,7 @@ class AP_Networking
}

// 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
Expand All @@ -81,10 +82,7 @@ class AP_Networking
}

// 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
Expand Down Expand Up @@ -113,10 +111,7 @@ class AP_Networking
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
{
Expand Down Expand Up @@ -172,7 +167,7 @@ class AP_Networking
AP_Int32 options;
} param;

AP_Networking_backend *backend;
AP_Networking_Backend *backend;

HAL_Semaphore sem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

#if AP_NETWORKING_ENABLED

#include "AP_Networking.h"

class AP_Networking;

class AP_Networking_backend
class AP_Networking_Backend
{
public:
friend class AP_Networking;

AP_Networking_backend(AP_Networking &_frontend) : frontend(_frontend) {}
AP_Networking_Backend(AP_Networking &_frontend) : frontend(_frontend) {}

/* Do not allow copies */
CLASS_NO_COPY(AP_Networking_backend);
CLASS_NO_COPY(AP_Networking_Backend);

virtual bool init() = 0;
virtual void update() = 0;
Expand Down
6 changes: 2 additions & 4 deletions libraries/AP_Networking/AP_Networking_ChibiOS.cpp
Original file line number Diff line number Diff line change
@@ -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 <AP_HAL/AP_HAL.h>
#include <GCS_MAVLink/GCS.h>

#include <lwipthread.h>
Expand Down Expand Up @@ -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

10 changes: 5 additions & 5 deletions libraries/AP_Networking/AP_Networking_ChibiOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#include "AP_Networking_Config.h"

#if AP_NETWORKING_ENABLED && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
#include "AP_Networking_backend.h"
#if AP_NETWORKING_BACKEND_CHIBIOS
#include "AP_Networking_Backend.h"

class AP_Networking_ChibiOS : public AP_Networking_backend
class AP_Networking_ChibiOS : public AP_Networking_Backend
{
public:
using AP_Networking_backend::AP_Networking_backend;
using AP_Networking_Backend::AP_Networking_Backend;

/* Do not allow copies */
CLASS_NO_COPY(AP_Networking_ChibiOS);
Expand All @@ -25,5 +25,5 @@ class AP_Networking_ChibiOS : public AP_Networking_backend
uint8_t macaddr[6];
};

#endif // AP_NETWORKING_ENABLED && CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
#endif // AP_NETWORKING_BACKEND_CHIBIOS

19 changes: 18 additions & 1 deletion libraries/AP_Networking/AP_Networking_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down