Wrapper class around esp-idf implementation of a esp-netif device. More...

#include <mn_basic_netif.hpp>

+ Inheritance diagram for mn::device::basic_net_if:

Classes

struct  ip_info
 

Public Types

using ip4_address_t = net::basic_ip4_address
 
using ip_info_t = ip_info
 

Public Member Functions

 basic_net_if ()
 
 basic_net_if (const basic_net_if &other)
 
basic_net_ifoperator= (const basic_net_if &other)
 
virtual bool create_default ()=0
 Creates an instance of new esp-netif object. More...
 
int set_mac (uint8_t mac[6])
 Set the mac address for the interface instance. More...
 
esp_err_t get_mac (uint8_t mac[6])
 Get the mac address for the interface instance. More...
 
const char * get_hostname ()
 Get the hostname of an interface. More...
 
bool set_hostname (const char *hostname)
 Set the hostname of an interface. More...
 
bool is_up ()
 Test if supplied interface is up. More...
 
int get_impl_name (char name[6])
 Get net interface name from network stack implementation. More...
 
int get_impl_index ()
 Get net interface index from network stack implementation. More...
 
virtual esp_netif_t * get_netif ()
 Get the Handle to esp-netif instance. More...
 
virtual esp_netif_config_t * get_config ()
 Get the config of the esp-netif instance. More...
 
int get_ip_infos (ip_info_t &ip_info)
 Get interface's IP address information. More...
 
int set_ip_infos (const ip_info_t &ip_info)
 Set interface's IP address information. More...
 
 operator bool ()
 
 operator esp_netif_t * ()
 
bool operator== (const basic_net_if &other)
 
bool operator!= (const basic_net_if &other)
 
bool operator== (const esp_netif_t *other)
 
bool operator!= (const esp_netif_t *other)
 

Static Public Member Functions

static bool start ()
 Initialize the underlying TCP/IP stack. More...
 
static bool stop ()
 Deinitialize the esp-netif component (and the underlying TCP/IP stack) More...
 

Protected Attributes

esp_netif_config_t * m_ifConfig
 
esp_netif_t * m_pNetIf
 

Detailed Description

Wrapper class around esp-idf implementation of a esp-netif device.

Note
To use this, you need to subclass it. All of your task should be derived from the basic_net_if class. Then implement the virtual create_default function.

Class Documentation

◆ mn::device::basic_net_if::ip_info

struct mn::device::basic_net_if::ip_info
+ Collaboration diagram for mn::device::basic_net_if::ip_info:
Class Members
ip4_address_t gw

Interface IPV4 gateway address

ip4_address_t ip

Interface IPV4 address

ip4_address_t netmask

Interface IPV4 netmask

Member Typedef Documentation

◆ ip4_address_t

◆ ip_info_t

Constructor & Destructor Documentation

◆ basic_net_if() [1/2]

mn::device::basic_net_if::basic_net_if ( )

constructor

◆ basic_net_if() [2/2]

mn::device::basic_net_if::basic_net_if ( const basic_net_if other)
inline

copy constructor

Member Function Documentation

◆ create_default()

virtual bool mn::device::basic_net_if::create_default ( )
pure virtual

Creates an instance of new esp-netif object.

Note
Must be overwrite, with the driver spcezific version and set m_pNetIf
Returns
  • true: on success
  • false: if initializing failed

Implemented in mn::device::basic_wifi_net_if.

◆ get_config()

virtual esp_netif_config_t* mn::device::basic_net_if::get_config ( )
inlinevirtual

Get the config of the esp-netif instance.

Returns
The config of the esp-netif instance.

◆ get_hostname()

const char * mn::device::basic_net_if::get_hostname ( void  )

Get the hostname of an interface.

Returns
Returns the hostname of an interface

◆ get_impl_index()

int mn::device::basic_net_if::get_impl_index ( )

Get net interface index from network stack implementation.

Note
This index could be used in setsockopt() to bind socket with multicast interface
Returns
implementation specific index of interface represented with supplied esp_netif

◆ get_impl_name()

int mn::device::basic_net_if::get_impl_name ( char  name[6])

Get net interface name from network stack implementation.

Note
This name could be used in setsockopt() to bind socket with appropriate interface
Parameters
[out]nameInterface name as specified in underlying TCP/IP stack. Note that the actual name will be copied to the specified buffer, which must be allocated to hold maximum interface name size (6 characters for lwIP)
Returns
  • NO_ERROR: succeed
  • ERR_MNTHREAD_INVALID_ARG: The given arcuments are wrong

◆ get_ip_infos()

int mn::device::basic_net_if::get_ip_infos ( ip_info_t ip_info)

Get interface's IP address information.

If the interface is up, IP information is read directly from the TCP/IP stack. If the interface is down, IP information is read from a copy kept in the ESP-NETIF instance

Parameters
ip_infoIf successful, IP information will be returned in this argument.
Returns
  • NO_ERROR: succeed
  • ERR_MNTHREAD_INVALID_ARG: The given arcuments are wrong
  • ERR_MNTHREAD_UNKN: Unbekannter fehler

◆ get_mac()

int mn::device::basic_net_if::get_mac ( uint8_t  mac[6])

Get the mac address for the interface instance.

Parameters
[out]macResultant mac address for the related network interface
Returns
  • NO_ERROR: succeed
  • ERR_MNTHREAD_NETIF_NOT_INIT - interface status error
  • ERR_MNTHREAD_NOT_SUPPORTED - mac not supported on this interface

◆ get_netif()

virtual esp_netif_t* mn::device::basic_net_if::get_netif ( )
inlinevirtual

Get the Handle to esp-netif instance.

Returns
The Handle to esp-netif instance.

◆ is_up()

bool mn::device::basic_net_if::is_up ( )

Test if supplied interface is up.

Returns
- true - Interface is up
  • false - Interface is down

◆ operator bool()

mn::device::basic_net_if::operator bool ( )
inline

◆ operator esp_netif_t *()

mn::device::basic_net_if::operator esp_netif_t * ( )
inline

◆ operator!=() [1/2]

bool mn::device::basic_net_if::operator!= ( const basic_net_if other)

◆ operator!=() [2/2]

bool mn::device::basic_net_if::operator!= ( const esp_netif_t *  other)

◆ operator=()

basic_net_if & mn::device::basic_net_if::operator= ( const basic_net_if other)

◆ operator==() [1/2]

bool mn::device::basic_net_if::operator== ( const basic_net_if other)

◆ operator==() [2/2]

bool mn::device::basic_net_if::operator== ( const esp_netif_t *  other)

◆ set_hostname()

bool mn::device::basic_net_if::set_hostname ( const char *  hostname)

Set the hostname of an interface.

The configured hostname overrides the default configuration value CONFIG_LWIP_LOCAL_HOSTNAME. Please note that when the hostname is altered after interface started/connected the changes would only be reflected once the interface restarts/reconnects

Parameters
hostnameNew hostname for the interface. Maximum length 32 bytes.
Returns
  • true The hostname was changed
    • false The hostname was not changed

◆ set_ip_infos()

int mn::device::basic_net_if::set_ip_infos ( const ip_info_t ip_info)

Set interface's IP address information.

This function is mainly used to set a static IP on an interface.

If the interface is up, the new IP information is set directly in the TCP/IP stack.

The copy of IP information kept in the ESP-NETIF instance is also updated (this copy is returned if the IP is queried while the interface is still down.)

Note
DHCP client/server must be stopped (if enabled for this interface) before setting new IP information.
Calling this interface for may generate a SYSTEM_EVENT_STA_GOT_IP or SYSTEM_EVENT_ETH_GOT_IP event.
Parameters
[in]esp_netifHandle to esp-netif instance
[in]ip_infoIP information to set on the specified interface
Returns
  • NO_ERROR: succeed
  • ERR_MNTHREAD_INVALID_ARG: The given arcuments are wrong
  • ERR_MNTHREAD_UNKN: If DHCP server or client is still running

◆ set_mac()

int mn::device::basic_net_if::set_mac ( uint8_t  mac[6])

Set the mac address for the interface instance.

Parameters
[in]macDesired mac address for the related network interface
Returns
  • NO_ERROR: succeed
  • ERR_MNTHREAD_NETIF_NOT_INIT - interface status error
  • ERR_MNTHREAD_NOT_SUPPORTED - mac not supported on this interface

◆ start()

bool mn::device::basic_net_if::start ( )
static

Initialize the underlying TCP/IP stack.

Returns
  • true: on success
  • false: if initializing failed
Note
This function should be called exactly once from application code, when the application starts up.

◆ stop()

bool mn::device::basic_net_if::stop ( )
static

Deinitialize the esp-netif component (and the underlying TCP/IP stack)

Note
Deinitialization is not supported yet
Returns
  • true: on success
  • false: if initializing failed

Member Data Documentation

◆ m_ifConfig

esp_netif_config_t* mn::device::basic_net_if::m_ifConfig
protected

A saved / cached copy of esp-netif config

◆ m_pNetIf

esp_netif_t* mn::device::basic_net_if::m_pNetIf
protected

Reference to the underlying esp-netif handle.


The documentation for this class was generated from the following files: