-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common_examples): Add common examples aplicable for all phys
- Loading branch information
1 parent
a631cfe
commit 741cd12
Showing
34 changed files
with
2,383 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# For more information about build system see | ||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(iperf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS "iperf.c" | ||
INCLUDE_DIRS ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
menu "Iperf example-specific options" | ||
config EXAMPLE_ACT_AS_DHCP_SERVER | ||
bool "Act sa DHCP server" | ||
default n | ||
help | ||
Set ESP32 to act as DHCP server instead of as a client. | ||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dependencies: | ||
espressif/ethernet_init: | ||
override_path: '../../../ethernet_init/' | ||
espressif/iperf-cmd: "^0.1.1" | ||
espressif/iperf: "^0.1.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "esp_netif.h" | ||
#include "esp_eth.h" | ||
#include "esp_event.h" | ||
#include "esp_console.h" | ||
#include "ethernet_init.h" | ||
#include "iperf_cmd.h" | ||
#include "sdkconfig.h" | ||
|
||
static void my_event_connected_handler(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data) | ||
{ | ||
esp_netif_dhcps_start(esp_netif); | ||
} | ||
|
||
|
||
void app_main(void) | ||
{ | ||
uint8_t eth_port_cnt = 0; | ||
esp_eth_handle_t *eth_handles; | ||
esp_netif_init(); | ||
esp_event_loop_create_default(); | ||
ethernet_init_all(ð_handles, ð_port_cnt); | ||
|
||
//esp_netif_config_t cfg; | ||
#if CONFIG_EXAMPLE_ACT_AS_DHCP_SERVER | ||
// Act as DHCP server | ||
esp_netif_ip_info_t ip_info = { | ||
.ip = {.addr = ESP_IP4TOADDR(192, 168, 1, 1)}, | ||
.netmask = {.addr = ESP_IP4TOADDR(255, 255, 255, 0)}, | ||
.gw = {.addr = ESP_IP4TOADDR(192, 168, 1, 255)} | ||
}; | ||
const esp_netif_inherent_config_t eth_behav_cfg = { | ||
.get_ip_event = IP_EVENT_ETH_GOT_IP, | ||
.lost_ip_event = 0, | ||
.flags = ESP_NETIF_DHCP_SERVER, | ||
.ip_info = &ip_info, | ||
.if_key = "ETH_DHCPS", | ||
.if_desc = "eth", | ||
.route_prio = 50 | ||
}; | ||
esp_netif_config_t cfg = { .base = ð_behav_cfg, .stack = ESP_NETIF_NETSTACK_DEFAULT_ETH }; | ||
|
||
esp_netif_t *eth_netif = esp_netif_new(&cfg); | ||
esp_eth_handle_t eth_handle = eth_handles[0]; | ||
esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handles[0])); | ||
|
||
esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_CONNECTED, my_event_connected_handler, eth_netif); | ||
esp_netif_dhcpc_stop(eth_netif); | ||
esp_netif_set_ip_info(eth_netif, &ip_info); | ||
#else | ||
// Act as DHCP client, usual behaviour | ||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); | ||
esp_netif_t *eth_netif = esp_netif_new(&cfg); | ||
esp_eth_handle_t eth_handle = eth_handles[0]; | ||
esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handles[0])); | ||
#endif | ||
esp_eth_start(eth_handle); | ||
esp_console_repl_t *repl = NULL; | ||
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); | ||
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); | ||
esp_console_new_repl_uart(&uart_config, &repl_config, &repl); | ||
app_register_iperf_commands(); | ||
esp_console_start_repl(repl); | ||
} |
Oops, something went wrong.