Skip to content
Draft
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
54 changes: 47 additions & 7 deletions libraries/AP_Networking/AP_Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,18 @@ void AP_Networking::init()
*/
void AP_Networking::announce_address_changes()
{
const auto &as = backend->activeSettings;
uint32_t last_change_ms = 0;

if (as.last_change_ms == 0 || as.last_change_ms == announce_ms) {
if (backend != nullptr) {
last_change_ms = backend->activeSettings.last_change_ms;
}
#if AP_NETWORKING_BACKEND_SWITCHPORT_LWIP
else if (port_lwip != nullptr) {
last_change_ms = port_lwip->get_last_change_ms();
}
#endif

if (last_change_ms == 0 || last_change_ms == announce_ms) {
// nothing changed and we've already printed it at least once. Nothing to do.
return;
}
Expand All @@ -406,7 +415,7 @@ void AP_Networking::announce_address_changes()
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "NET: Gateway %s", SocketAPM::inet_addr_to_str(get_gateway_active(), ipstr, sizeof(ipstr)));
#endif

announce_ms = as.last_change_ms;
announce_ms = last_change_ms;
}

/*
Expand All @@ -417,7 +426,14 @@ void AP_Networking::update()
if (!is_healthy()) {
return;
}
backend->update();
if (backend != nullptr) {
backend->update();
}
#if AP_NETWORKING_BACKEND_SWITCH
if (hub != nullptr) {
hub->update();
}
#endif
#if AP_NETWORKING_CAPTURE_ENABLED
// Manage per-port-type packet captures based on NET_CAPMASK
#if AP_NETWORKING_BACKEND_SWITCHPORT_LWIP
Expand Down Expand Up @@ -520,18 +536,42 @@ bool AP_Networking::convert_str_to_macaddr(const char *mac_str, uint8_t addr[6])
// 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;
if (backend != nullptr) {
return backend->activeSettings.ip;
}
#if AP_NETWORKING_BACKEND_SWITCHPORT_LWIP
if (port_lwip != nullptr) {
return port_lwip->get_active_ip();
}
#endif
return 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;
if (backend != nullptr) {
return backend->activeSettings.nm;
}
#if AP_NETWORKING_BACKEND_SWITCHPORT_LWIP
if (port_lwip != nullptr) {
return port_lwip->get_active_netmask();
}
#endif
return 0;
}

uint32_t AP_Networking::get_gateway_active() const
{
return backend?backend->activeSettings.gw:0;
if (backend != nullptr) {
return backend->activeSettings.gw;
}
#if AP_NETWORKING_BACKEND_SWITCHPORT_LWIP
if (port_lwip != nullptr) {
return port_lwip->get_active_gateway();
}
#endif
return 0;
}

/*
Expand Down
6 changes: 4 additions & 2 deletions libraries/AP_Networking/AP_Networking_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@
#endif

#ifndef AP_NETWORKING_BACKEND_SWITCHPORT_LWIP
// lwIP switchport - for MAC gateway clients, NOT enabled on SITL by default
// lwIP switchport - enabled when switch has Ethernet (replaces old ChibiOS backend)
// or for MAC gateway clients. NOT enabled on SITL by default
// (SITL uses native sockets by default for compatibility)
#define AP_NETWORKING_BACKEND_SWITCHPORT_LWIP \
(AP_NETWORKING_LWIP_AVAILABLE && AP_NETWORKING_BACKEND_IS_MAC_GATEWAY_CLIENT)
(AP_NETWORKING_LWIP_AVAILABLE && \
(AP_NETWORKING_BACKEND_IS_MAC_GATEWAY_CLIENT || AP_NETWORKING_BACKEND_SWITCHPORT_ETHERNET))
#endif

#ifndef AP_NETWORKING_BACKEND_SWITCHPORT_MAVLINK_COBS
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_Networking/AP_Networking_SwitchPort_lwIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AP_Networking_SwitchPort_lwIP : public AP_Networking_SwitchPort
uint32_t get_active_ip() const;
uint32_t get_active_netmask() const;
uint32_t get_active_gateway() const;
uint32_t get_last_change_ms() const { return activeSettings.last_change_ms; }

private:
AP_Networking_Switch *hub;
Expand Down
Loading