mn_basic_netif.hpp
Go to the documentation of this file.
1 #ifndef _MINTHREAH_BASIC_NETIF_HPP_
2 #define _MINTHREAH_BASIC_NETIF_HPP_
3 
4 #include "mn_config.hpp"
5 
6 
7 #include <esp_interface.h>
8 #include <esp_netif.h>
9 #include <esp_wifi.h>
10 
11 #if CONFIG_ETH_USE_SPI_ETHERNET
12 #include <driver/spi_master.h>
13 #endif // CONFIG_ETH_USE_SPI_ETHERNET
14 
18 
19 #include "mn_lock.hpp"
20 
21 namespace mn {
22  namespace device {
23 
33  class basic_net_if {
34  public:
36 
37  struct ip_info {
41  };
42  using ip_info_t = ip_info;
43 
47  basic_net_if();
51  basic_net_if(const basic_net_if& other)
52  : m_ifConfig(other.m_ifConfig), m_pNetIf(other.m_pNetIf) { }
53  basic_net_if& operator = (const basic_net_if& other);
54 
63  virtual bool create_default() = 0;
64 
74  static bool start();
75 
85  static bool stop();
95  int set_mac(uint8_t mac[6]);
96 
106  esp_err_t get_mac(uint8_t mac[6]);
107 
113  const char* get_hostname();
114 
127  bool set_hostname(const char* hostname);
128 
135  bool is_up();
136 
150  int get_impl_name(char name[6]);
159  int get_impl_index();
160 
165  virtual esp_netif_t* get_netif() { return m_pNetIf; }
166 
171  virtual esp_netif_config_t* get_config() { return m_ifConfig; }
172 
186  int get_ip_infos(ip_info_t& ip_info);
187 
209  int set_ip_infos(const ip_info_t& ip_info);
210 
211  operator bool() { return is_up(); }
212  operator esp_netif_t* () { return m_pNetIf;}
213 
214  bool operator == (const basic_net_if& other);
215  bool operator != (const basic_net_if& other);
216 
217  bool operator == (const esp_netif_t* other);
218  bool operator != (const esp_netif_t* other);
219  protected:
223  esp_netif_config_t* m_ifConfig;
227  esp_netif_t* m_pNetIf;
228  };
229  }
230 }
231 
232 #endif // _MINTHREAH_BASIC_NETIF_HPP_
Wrapper class around esp-idf implementation of a esp-netif device.
Definition: mn_basic_netif.hpp:33
ip_info ip_info_t
Definition: mn_basic_netif.hpp:42
ip4_address_t ip
Definition: mn_basic_netif.hpp:38
ip4_address_t gw
Definition: mn_basic_netif.hpp:40
esp_netif_t * m_pNetIf
Definition: mn_basic_netif.hpp:227
virtual bool create_default()=0
Creates an instance of new esp-netif object.
static bool start()
Initialize the underlying TCP/IP stack.
Definition: mn_basic_netif.cpp:139
esp_err_t get_mac(uint8_t mac[6])
Get the mac address for the interface instance.
Definition: mn_basic_netif.cpp:65
bool operator==(const basic_net_if &other)
Definition: mn_basic_netif.cpp:153
int get_impl_name(char name[6])
Get net interface name from network stack implementation.
Definition: mn_basic_netif.cpp:35
esp_netif_config_t * m_ifConfig
Definition: mn_basic_netif.hpp:223
bool set_hostname(const char *hostname)
Set the hostname of an interface.
Definition: mn_basic_netif.cpp:90
int get_impl_index()
Get net interface index from network stack implementation.
Definition: mn_basic_netif.cpp:43
basic_net_if()
Definition: mn_basic_netif.cpp:21
bool is_up()
Test if supplied interface is up.
Definition: mn_basic_netif.cpp:28
virtual esp_netif_config_t * get_config()
Get the config of the esp-netif instance.
Definition: mn_basic_netif.hpp:171
int set_ip_infos(const ip_info_t &ip_info)
Set interface's IP address information.
Definition: mn_basic_netif.cpp:119
virtual esp_netif_t * get_netif()
Get the Handle to esp-netif instance.
Definition: mn_basic_netif.hpp:165
const char * get_hostname()
Get the hostname of an interface.
Definition: mn_basic_netif.cpp:80
basic_net_if & operator=(const basic_net_if &other)
Definition: mn_basic_netif.cpp:183
bool operator!=(const basic_net_if &other)
Definition: mn_basic_netif.cpp:161
int get_ip_infos(ip_info_t &ip_info)
Get interface's IP address information.
Definition: mn_basic_netif.cpp:97
ip4_address_t netmask
Definition: mn_basic_netif.hpp:39
basic_net_if(const basic_net_if &other)
Definition: mn_basic_netif.hpp:51
int set_mac(uint8_t mac[6])
Set the mac address for the interface instance.
Definition: mn_basic_netif.cpp:50
static bool stop()
Deinitialize the esp-netif component (and the underlying TCP/IP stack)
Definition: mn_basic_netif.cpp:146
Definition: mn_basic_netif.hpp:37
This class represents an internet (IP) version 6 host address.
Definition: mn_basic_ip4_address.hpp:38
Definition: mn_allocator_typetraits.hpp:25