From 1325a761e93ebd53b032120f8e4ff1e28a85b09c Mon Sep 17 00:00:00 2001 From: xiaxiaotian Date: Fri, 19 Aug 2016 12:08:45 +0800 Subject: [PATCH] add got ip event handler --- components/esp32/event.c | 6 ++++++ components/esp32/include/esp_event.h | 12 ++++++++++++ components/tcpip_adapter/tcpip_adapter_lwip.c | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/components/esp32/event.c b/components/esp32/event.c index 1a920436b..a76394eed 100644 --- a/components/esp32/event.c +++ b/components/esp32/event.c @@ -79,6 +79,7 @@ static system_event_handle_t g_system_event_handle_table[] = { {SYSTEM_EVENT_STA_CONNECTED, system_event_sta_connected_handle_default}, {SYSTEM_EVENT_STA_DISCONNECTED, system_event_sta_disconnected_handle_default}, {SYSTEM_EVENT_STA_AUTHMODE_CHANGE, NULL}, + {SYSTEM_EVENT_STA_GOTIP, NULL}, {SYSTEM_EVENT_AP_START, system_event_ap_start_handle_default}, {SYSTEM_EVENT_AP_STOP, system_event_ap_stop_handle_default}, {SYSTEM_EVENT_AP_STACONNECTED, NULL}, @@ -161,6 +162,7 @@ static esp_err_t esp_system_event_debug(system_event_t *event) system_event_sta_connected_t *connected; system_event_sta_disconnected_t *disconnected; system_event_sta_authmode_change_t *auth_change; + system_event_sta_gotip_t *got_ip; system_event_ap_staconnected_t *staconnected; system_event_ap_stadisconnected_t *stadisconnected; system_event_ap_probe_req_rx_t *ap_probereqrecved; @@ -202,6 +204,10 @@ static esp_err_t esp_system_event_debug(system_event_t *event) auth_change = &event->event_info.auth_change; os_printf("SYSTEM_EVENT_STA_AUTHMODE_CHNAGE\nold_mode:%d, new_mode:%d\n", auth_change->old_mode, auth_change->new_mode); break; + case SYSTEM_EVENT_STA_GOTIP: + got_ip = &event->event_info.got_ip; + os_printf("SYSTEM_EVENT_STA_GOTIP\n"); + break; case SYSTEM_EVENT_AP_START: os_printf("SYSTEM_EVENT_AP_START\n"); break; diff --git a/components/esp32/include/esp_event.h b/components/esp32/include/esp_event.h index 8a34eb569..51e27630b 100755 --- a/components/esp32/include/esp_event.h +++ b/components/esp32/include/esp_event.h @@ -32,6 +32,7 @@ typedef enum { SYSTEM_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */ SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected to AP */ SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP32 station changed */ + SYSTEM_EVENT_STA_GOTIP, SYSTEM_EVENT_AP_START, /**< ESP32 softap start */ SYSTEM_EVENT_AP_STOP, /**< ESP32 softap start */ SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */ @@ -40,6 +41,10 @@ typedef enum { SYSTEM_EVENT_MAX } system_event_id_t; +typedef struct { + uint32_t addr; +} esp_ip_addr_t; + typedef struct { uint32_t status; /**< status of scanning APs*/ uint8_t number; @@ -64,6 +69,12 @@ typedef struct { uint8_t new_mode; /**< the new auth mode of AP */ } system_event_sta_authmode_change_t; +typedef struct { + esp_ip_addr_t ip; + esp_ip_addr_t netmask; + esp_ip_addr_t gw; +} system_event_sta_gotip_t; + typedef struct { uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */ uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */ @@ -84,6 +95,7 @@ typedef union { system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */ system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */ system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */ + system_event_sta_gotip_t got_ip; system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */ system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */ system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 softAP receive probe request packet */ diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index e24a6a0f3..d12c636aa 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -27,6 +27,8 @@ #include "apps/dhcpserver.h" +#include "esp_event.h" + static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX]; static struct ip_info esp_ip[TCPIP_ADAPTER_IF_MAX]; @@ -183,6 +185,7 @@ esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif) { tcpip_adapter_if_t tcpip_if; + system_event_t evt; if (!netif) { TCPIP_ADAPTER_DEBUG("null netif=%p\n", netif); @@ -208,6 +211,12 @@ esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif) ip4_addr_set(&esp_ip[tcpip_if].gw, ip_2_ip4(&netif->gw)); //notify event + evt.event_id = SYSTEM_EVENT_STA_GOTIP; + memcpy(&evt.event_info.got_ip.ip, &esp_ip[tcpip_if].ip, sizeof(evt.event_info.got_ip.ip)); + memcpy(&evt.event_info.got_ip.netmask, &esp_ip[tcpip_if].netmask, sizeof(evt.event_info.got_ip.netmask)); + memcpy(&evt.event_info.got_ip.gw, &esp_ip[tcpip_if].gw, sizeof(evt.event_info.got_ip.gw)); + esp_event_send(&evt); + printf("ip: %s, ", inet_ntoa(esp_ip[tcpip_if].ip)); printf("mask: %s, ", inet_ntoa(esp_ip[tcpip_if].netmask)); printf("gw: %s\n", inet_ntoa(esp_ip[tcpip_if].gw));