tcp_udp: remove some unnecessary functions.

This commit is contained in:
chenyudong
2017-03-31 16:34:12 +08:00
parent e261e16981
commit 68bf54607a
8 changed files with 66 additions and 76 deletions

View File

@@ -5,12 +5,12 @@ menu "Example Configuration"
# default MODE_TCP_SHIELDBOX
# help
# This option set performance mode.
#
# - Testing in shieldbox for "Performance in shieldbox" setting.
#
# - for "Performance in shieldbox" setting,it will receive data by tcp.
#
# - for "Performance in air" setting, it will send data by tcp.
#
# - for "Performance in long distance" setting, it will send data by tcp.
# - Testing in air for "Performance in air" setting.
#
# - Testing in long distance for "Performance in long distance" setting.
#
#
#config MODE_TCP_SHIELDBOX
@@ -51,7 +51,7 @@ config TCP_PERF_DELAY_DEBUG
config TCP_PERF_WIFI_SSID
string "WiFi SSID"
default "tp_wifi_test1"
default "esp_wifi_test1"
help
SSID (network name) for the example to connect to.

View File

@@ -19,6 +19,12 @@ step3:
you can see the info in com port output.
*/
#include <errno.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_err.h"
#include "tcp_perf.h"
int connectedflag = 0;
@@ -57,7 +63,7 @@ static void tcp_conn(void *pvParameters)
ESP_LOGI(TAG, "creat_tcp_client.");
socret = creat_tcp_client();
#endif
if(-1 == socret) {
if(ESP_FAIL == socret) {
ESP_LOGI(TAG, "creat tcp socket error,stop.");
vTaskDelete(NULL);
}
@@ -103,7 +109,6 @@ static void tcp_conn(void *pvParameters)
void app_main(void)
{
nvs_flash_init();
#if ESP_WIFI_MODE_AP
ESP_LOGI(TAG, "ESP_WIFI_MODE_AP\n");
wifi_init_softap();

View File

@@ -1,8 +1,16 @@
#include <string.h>
#include <sys/socket.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "tcp_perf.h"
/* FreeRTOS event group to signal when we are connected & ready to make a request */
static EventGroupHandle_t wifi_event_group;
/*socket*/
static int sever_socket = 0;
static struct sockaddr_in sever_addr;
@@ -126,7 +134,7 @@ void recv_data(void *pvParameters)
}
//use this esp32 as a tcp sever. return 0:success -1:error
//use this esp32 as a tcp sever. return ESP_OK:success ESP_FAIL:error
int creat_tcp_sever()
{
ESP_LOGI(TAG, "sever socket....port=%d\n", DEFAULT_PORT);
@@ -134,7 +142,7 @@ int creat_tcp_sever()
if (sever_socket < 0) {
show_socket_error_code(sever_socket);
//perror("socket() error:");
return -1;
return ESP_FAIL;
}
sever_addr.sin_family = AF_INET;
sever_addr.sin_port = htons(DEFAULT_PORT);
@@ -143,26 +151,26 @@ int creat_tcp_sever()
show_socket_error_code(sever_socket);
//perror("bind() error");
close(sever_socket);
return -1;
return ESP_FAIL;
}
if (listen(sever_socket, 5) < 0) {
show_socket_error_code(sever_socket);
//perror("listen() error");
close(sever_socket);
return -1;
return ESP_FAIL;
}
connect_soc = accept(sever_socket, (struct sockaddr*)&client_addr, &socklen);
if (connect_soc<0) {
show_socket_error_code(connect_soc);
//perror("accept() error");
close(sever_socket);
return -1;
return ESP_FAIL;
}
/*connection establishednow can send/recv*/
ESP_LOGI(TAG, "tcp connection established!");
return 0;
return ESP_OK;
}
//use this esp32 as a tcp client. return 0:success -1:error
//use this esp32 as a tcp client. return ESP_OK:success ESP_FAIL:error
int creat_tcp_client()
{
ESP_LOGI(TAG, "client socket....severip:port=%s:%d\n",
@@ -171,7 +179,7 @@ int creat_tcp_client()
if (connect_soc < 0) {
show_socket_error_code(connect_soc);
//perror("socket failed!");
return -1;
return ESP_FAIL;
}
sever_addr.sin_family = AF_INET;
sever_addr.sin_port = htons(DEFAULT_PORT);
@@ -180,17 +188,16 @@ int creat_tcp_client()
if (connect(connect_soc, (struct sockaddr *)&sever_addr, sizeof(sever_addr)) < 0) {
show_socket_error_code(connect_soc);
//perror("connect to sever error!");
return -1;
return ESP_FAIL;
}
ESP_LOGI(TAG, "connect to sever success!");
return 0;
return ESP_OK;
}
//wifi_init_sta
void wifi_init_sta()
{
tcpip_adapter_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
@@ -214,7 +221,6 @@ void wifi_init_sta()
void wifi_init_softap()
{
tcpip_adapter_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();

View File

@@ -1,22 +1,6 @@
#ifndef __TCP_PERF_H__
#define __TCP_PERF_H__
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include "driver/uart.h"
#include "soc/uart_struct.h"
#include "esp_log.h"
#ifdef __cplusplus