Skip to content

Commit

Permalink
AP_Networking: only show NET_IP,DHCP,GW,MASK,MAC if it's actually used
Browse files Browse the repository at this point in the history
  • Loading branch information
magicrub committed Nov 28, 2023
1 parent 11a5b78 commit 44552a3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libraries/AP_Networking/AP_Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const AP_Param::GroupInfo AP_Networking::var_info[] = {
// @User: Advanced
AP_GROUPINFO_FLAGS("ENABLED", 1, AP_Networking, param.enabled, 0, AP_PARAM_FLAG_ENABLE),

#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
// @Group: IPADDR
// @Path: AP_Networking_address.cpp
AP_SUBGROUPINFO(param.ipaddr, "IPADDR", 2, AP_Networking, AP_Networking_IPV4),
Expand Down Expand Up @@ -58,6 +59,7 @@ const AP_Param::GroupInfo AP_Networking::var_info[] = {
// @Group: MACADDR
// @Path: AP_Networking_macaddr.cpp
AP_SUBGROUPINFO(param.macaddr, "MACADDR", 6, AP_Networking, AP_Networking_MAC),
#endif // AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS

#if AP_NETWORKING_TESTS_ENABLED
// @Param: TESTS
Expand Down Expand Up @@ -99,6 +101,7 @@ void AP_Networking::init()
return;
}

#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
// set default MAC Address as lower 3 bytes of the CRC of the UID
uint8_t uid[50];
uint8_t uid_len = sizeof(uid);
Expand All @@ -113,6 +116,7 @@ void AP_Networking::init()
param.macaddr.set_default_address_byte(4, crc.bytes[1]);
param.macaddr.set_default_address_byte(5, crc.bytes[2]);
}
#endif

#if AP_NETWORKING_BACKEND_CHIBIOS
backend = new AP_Networking_ChibiOS(*this);
Expand Down
28 changes: 28 additions & 0 deletions libraries/AP_Networking/AP_Networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ class AP_Networking
// returns true if DHCP is enabled
bool get_dhcp_enabled() const
{
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
return param.dhcp;
#else
return false;
#endif
}

// Sets DHCP to be enabled or disabled
void set_dhcp_enable(const bool enable)
{
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
param.dhcp.set(enable);
#endif
}

// returns the 32bit value of the active IP address that is currently in use
Expand All @@ -69,7 +75,11 @@ class AP_Networking
// returns the 32bit value of the user-parameter static IP address
uint32_t get_ip_param() const
{
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
return param.ipaddr.get_uint32();
#else
return 0;
#endif
}

/*
Expand All @@ -84,7 +94,9 @@ class AP_Networking
// sets the user-parameter static IP address from a 32bit value
void set_ip_param(const uint32_t ip)
{
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
param.ipaddr.set_uint32(ip);
#endif
}

// returns the 32bit value of the active Netmask that is currently in use
Expand All @@ -93,7 +105,11 @@ class AP_Networking
// returns the 32bit value of the of the user-parameter static Netmask
uint32_t get_netmask_param() const
{
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
return convert_netmask_bitcount_to_ip(param.netmask.get());
#else
return 0;
#endif
}

// returns a null terminated string of the active Netmask address. Example: "192.168.12.13"
Expand All @@ -114,14 +130,20 @@ class AP_Networking

void set_netmask_param(const uint32_t nm)
{
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
param.netmask.set(convert_netmask_ip_to_bitcount(nm));
#endif
}

uint32_t get_gateway_active() const;

uint32_t get_gateway_param() const
{
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
return param.gwaddr.get_uint32();
#else
return 0;
#endif
}

const char *get_gateway_active_str()
Expand All @@ -141,7 +163,9 @@ class AP_Networking

void set_gateway_param(const uint32_t gw)
{
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
param.gwaddr.set_uint32(gw);
#endif
}

// helper functions to convert between 32bit IP addresses and null terminated strings and back
Expand All @@ -163,14 +187,18 @@ class AP_Networking
void announce_address_changes();

struct {
#if AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
AP_Networking_IPV4 ipaddr{AP_NETWORKING_DEFAULT_STATIC_IP_ADDR};
AP_Int8 netmask; // bits to mask. example: (16 == 255.255.0.0) and (24 == 255.255.255.0)
AP_Networking_IPV4 gwaddr{AP_NETWORKING_DEFAULT_STATIC_GW_ADDR};

AP_Int8 dhcp;
AP_Networking_MAC macaddr{AP_NETWORKING_DEFAULT_MAC_ADDR};
#endif

AP_Int8 enabled;
AP_Int32 options;

#if AP_NETWORKING_TESTS_ENABLED
AP_Int32 tests;
AP_Networking_IPV4 test_ipaddr{AP_NETWORKING_TEST_IP};
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Networking/AP_Networking_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#define AP_NETWORKING_BACKEND_DEFAULT_ENABLED AP_NETWORKING_ENABLED
#endif

#ifndef AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS
#define AP_NETWORKING_CONTROLS_HOST_IP_SETTINGS CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
#endif

// ---------------------------
// Backends
Expand Down

0 comments on commit 44552a3

Please sign in to comment.