Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'examples/tcp_client_linux_support' into 'master'
tcp_client example: support for Linux target. Closes IDF-5636 See merge request espressif/esp-idf!19203
- Loading branch information
Showing
15 changed files
with
475 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
# The following five lines of boilerplate have to be in your project's | ||
# The following 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) | ||
|
||
# (Not part of the boilerplate) | ||
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection. | ||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) | ||
if(${IDF_TARGET} STREQUAL "linux") | ||
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/") | ||
set(COMPONENTS main) | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
else() | ||
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
endif() | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(tcp_client) |
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
6 changes: 6 additions & 0 deletions
6
examples/protocols/sockets/tcp_client/components/esp_stubs/CMakeLists.txt
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,6 @@ | ||
if(${IDF_TARGET} STREQUAL "linux") | ||
idf_component_register(SRCS | ||
esp_stubs/esp_stubs.c | ||
INCLUDE_DIRS . include/stubs | ||
REQUIRES main) | ||
endif() |
45 changes: 45 additions & 0 deletions
45
examples/protocols/sockets/tcp_client/components/esp_stubs/esp_stubs/esp_stubs.c
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,45 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include <stdlib.h> | ||
#include "esp_err.h" | ||
#include "esp_log.h" | ||
|
||
extern void app_main(void); | ||
|
||
void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression) | ||
{ | ||
ESP_LOGE("ESP_ERROR_CHECK", "Failed with esp_err_t: 0x%x", rc); | ||
ESP_LOGE("ESP_ERROR_CHECK", "Expression: %s", expression); | ||
ESP_LOGE("ESP_ERROR_CHECK", "Functions: %s %s(%d)", function, file, line); | ||
abort(); | ||
} | ||
|
||
esp_err_t esp_event_loop_create_default(void) | ||
{ | ||
return ESP_OK; | ||
} | ||
|
||
esp_err_t esp_netif_init(void) | ||
{ | ||
return ESP_OK; | ||
} | ||
|
||
esp_err_t example_connect(void) | ||
{ | ||
return ESP_OK; | ||
} | ||
|
||
esp_err_t nvs_flash_init(void) | ||
{ | ||
return ESP_OK; | ||
} | ||
|
||
int main() | ||
{ | ||
app_main(); | ||
|
||
return 0; | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/protocols/sockets/tcp_client/components/esp_stubs/include/stubs/esp_event.h
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 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include "esp_err.h" | ||
|
||
esp_err_t esp_event_loop_create_default(void); |
11 changes: 11 additions & 0 deletions
11
examples/protocols/sockets/tcp_client/components/esp_stubs/include/stubs/esp_netif.h
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,11 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include <sys/ioctl.h> | ||
#include <net/if.h> | ||
#include <ifaddrs.h> | ||
#include "esp_err.h" | ||
|
||
esp_err_t esp_netif_init(void); |
8 changes: 8 additions & 0 deletions
8
examples/protocols/sockets/tcp_client/components/esp_stubs/include/stubs/nvs_flash.h
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 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include "esp_err.h" | ||
|
||
esp_err_t nvs_flash_init(void); |
8 changes: 8 additions & 0 deletions
8
...rotocols/sockets/tcp_client/components/esp_stubs/include/stubs/protocol_examples_common.h
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 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include "esp_err.h" | ||
|
||
esp_err_t example_connect(void); |
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 |
---|---|---|
@@ -1,2 +1,13 @@ | ||
idf_component_register(SRCS "tcp_client.c" | ||
INCLUDE_DIRS ".") | ||
if(${IDF_TARGET} STREQUAL "linux") | ||
set(requires esp_stubs) | ||
endif() | ||
|
||
if("${CONFIG_EXAMPLE_IPV4}" STREQUAL y) | ||
set(tcp_client_ip tcp_client_v4.c) | ||
else() | ||
set(tcp_client_ip tcp_client_v6.c) | ||
endif() | ||
|
||
idf_component_register(SRCS "tcp_client_main.c" "${tcp_client_ip}" | ||
INCLUDE_DIRS "." | ||
REQUIRES ${requires}) |
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
27 changes: 27 additions & 0 deletions
27
examples/protocols/sockets/tcp_client/main/tcp_client_main.c
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,27 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include "nvs_flash.h" | ||
#include "esp_netif.h" | ||
#include "protocol_examples_common.h" | ||
#include "esp_event.h" | ||
|
||
|
||
extern void tcp_client(void); | ||
|
||
void app_main(void) | ||
{ | ||
ESP_ERROR_CHECK(nvs_flash_init()); | ||
ESP_ERROR_CHECK(esp_netif_init()); | ||
ESP_ERROR_CHECK(esp_event_loop_create_default()); | ||
|
||
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig. | ||
* Read "Establishing Wi-Fi or Ethernet Connection" section in | ||
* examples/protocols/README.md for more information about this function. | ||
*/ | ||
ESP_ERROR_CHECK(example_connect()); | ||
|
||
tcp_client(); | ||
} |
Oops, something went wrong.