examples: Standardise naming of files, symbols, etc. in examples

* Use "example" in all example function & variable names,
  ie use i2c_example_xxx instead of i2c_xxx for example functions.
  Closes #198 https://github.com/espressif/esp-idf/issues/198
* Mark example functions, etc. static
* Replace uses of "test" & "demo" with "example"
* Split the UART example into two
* Rename "main" example files to end with "_main.c" for disambiguation
This commit is contained in:
Angus Gratton
2017-03-22 12:36:11 +08:00
parent 8ee6f8227e
commit 821c70f5d7
40 changed files with 624 additions and 598 deletions
@@ -7,8 +7,8 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#ifndef _OPENSSL_DEMO_H_
#define _OPENSSL_DEMO_H_
#ifndef _OPENSSL_EXAMPLE_H_
#define _OPENSSL_EXAMPLE_H_
/* The examples use simple WiFi configuration that you can set via
'make menuconfig'.
@@ -23,21 +23,21 @@
you can set via 'make menuconfig'.
If you'd rather not, just change the below entries to strings with
the config you want - ie #define OPENSSL_DEMO_TARGET_NAME "www.baidu.com"
and ie #define OPENSSL_DEMO_TARGET_TCP_PORT 433
the config you want - ie #define OPENSSL_EXAMPLE_TARGET_NAME "www.baidu.com"
and ie #define OPENSSL_EXAMPLE_TARGET_TCP_PORT 433
*/
#define OPENSSL_DEMO_TARGET_NAME CONFIG_TARGET_DOMAIN
#define OPENSSL_DEMO_TARGET_TCP_PORT CONFIG_TARGET_PORT_NUMBER
#define OPENSSL_EXAMPLE_TARGET_NAME CONFIG_TARGET_DOMAIN
#define OPENSSL_EXAMPLE_TARGET_TCP_PORT CONFIG_TARGET_PORT_NUMBER
#define OPENSSL_DEMO_REQUEST "{\"path\": \"/v1/ping/\", \"method\": \"GET\"}\r\n"
#define OPENSSL_EXAMPLE_REQUEST "{\"path\": \"/v1/ping/\", \"method\": \"GET\"}\r\n"
#define OPENSSL_DEMO_THREAD_NAME "OpenSSL_demo"
#define OPENSSL_DEMO_THREAD_STACK_WORDS 10240
#define OPENSSL_DEMO_THREAD_PRORIOTY 8
#define OPENSSL_EXAMPLE_TASK_NAME "openssl_example"
#define OPENSSL_EXAMPLE_TASK_STACK_WORDS 10240
#define OPENSSL_EXAMPLE_TASK_PRORIOTY 8
#define OPENSSL_DEMO_RECV_BUF_LEN 1024
#define OPENSSL_EXAMPLE_RECV_BUF_LEN 1024
#define OPENSSL_DEMO_LOCAL_TCP_PORT 443
#define OPENSSL_EXAMPLE_LOCAL_TCP_PORT 443
#endif
@@ -7,7 +7,7 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "openssl_client.h"
#include "openssl_client_example.h"
#include <string.h>
@@ -33,9 +33,9 @@ static EventGroupHandle_t wifi_event_group;
to the AP with an IP? */
const static int CONNECTED_BIT = BIT0;
const static char *TAG = "Openssl_demo";
const static char *TAG = "openssl_example";
void openssl_demo_thread(void *p)
static void openssl_example_task(void *p)
{
int ret;
SSL_CTX *ctx;
@@ -46,15 +46,15 @@ void openssl_demo_thread(void *p)
struct ip4_addr *ip4_addr;
int recv_bytes = 0;
char recv_buf[OPENSSL_DEMO_RECV_BUF_LEN];
char recv_buf[OPENSSL_EXAMPLE_RECV_BUF_LEN];
const char send_data[] = OPENSSL_DEMO_REQUEST;
const char send_data[] = OPENSSL_EXAMPLE_REQUEST;
const int send_bytes = sizeof(send_data);
ESP_LOGI(TAG, "OpenSSL demo thread start OK");
ESP_LOGI(TAG, "get target IP address");
hp = gethostbyname(OPENSSL_DEMO_TARGET_NAME);
hp = gethostbyname(OPENSSL_EXAMPLE_TARGET_NAME);
if (!hp) {
ESP_LOGI(TAG, "failed");
goto failed1;
@@ -84,7 +84,7 @@ void openssl_demo_thread(void *p)
memset(&sock_addr, 0, sizeof(sock_addr));
sock_addr.sin_family = AF_INET;
sock_addr.sin_addr.s_addr = 0;
sock_addr.sin_port = htons(OPENSSL_DEMO_LOCAL_TCP_PORT);
sock_addr.sin_port = htons(OPENSSL_EXAMPLE_LOCAL_TCP_PORT);
ret = bind(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
if (ret) {
ESP_LOGI(TAG, "failed");
@@ -92,11 +92,11 @@ void openssl_demo_thread(void *p)
}
ESP_LOGI(TAG, "OK");
ESP_LOGI(TAG, "socket connect to remote %s ......", OPENSSL_DEMO_TARGET_NAME);
ESP_LOGI(TAG, "socket connect to remote %s ......", OPENSSL_EXAMPLE_TARGET_NAME);
memset(&sock_addr, 0, sizeof(sock_addr));
sock_addr.sin_family = AF_INET;
sock_addr.sin_addr.s_addr = ip4_addr->addr;
sock_addr.sin_port = htons(OPENSSL_DEMO_TARGET_TCP_PORT);
sock_addr.sin_port = htons(OPENSSL_EXAMPLE_TARGET_TCP_PORT);
ret = connect(socket, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
if (ret) {
ESP_LOGI(TAG, "failed");
@@ -115,7 +115,7 @@ void openssl_demo_thread(void *p)
SSL_set_fd(ssl, socket);
ESP_LOGI(TAG, "SSL connected to %s port %d ......",
OPENSSL_DEMO_TARGET_NAME, OPENSSL_DEMO_TARGET_TCP_PORT);
OPENSSL_EXAMPLE_TARGET_NAME, OPENSSL_EXAMPLE_TARGET_TCP_PORT);
ret = SSL_connect(ssl);
if (!ret) {
ESP_LOGI(TAG, "failed " );
@@ -124,7 +124,7 @@ void openssl_demo_thread(void *p)
ESP_LOGI(TAG, "OK");
ESP_LOGI(TAG, "send https request to %s port %d ......",
OPENSSL_DEMO_TARGET_NAME, OPENSSL_DEMO_TARGET_TCP_PORT);
OPENSSL_EXAMPLE_TARGET_NAME, OPENSSL_EXAMPLE_TARGET_TCP_PORT);
ret = SSL_write(ssl, send_data, send_bytes);
if (ret <= 0) {
ESP_LOGI(TAG, "failed");
@@ -133,7 +133,7 @@ void openssl_demo_thread(void *p)
ESP_LOGI(TAG, "OK");
do {
ret = SSL_read(ssl, recv_buf, OPENSSL_DEMO_RECV_BUF_LEN - 1);
ret = SSL_read(ssl, recv_buf, OPENSSL_EXAMPLE_RECV_BUF_LEN - 1);
if (ret <= 0) {
break;
}
@@ -141,7 +141,7 @@ void openssl_demo_thread(void *p)
ESP_LOGI(TAG, "%s", recv_buf);
} while (1);
ESP_LOGI(TAG, "totaly read %d bytes data from %s ......", recv_bytes, OPENSSL_DEMO_TARGET_NAME);
ESP_LOGI(TAG, "totaly read %d bytes data from %s ......", recv_bytes, OPENSSL_EXAMPLE_TARGET_NAME);
failed5:
SSL_shutdown(ssl);
@@ -159,20 +159,20 @@ failed1:
return ;
}
static void openssl_client_init(void)
static void openssl_example_client_init(void)
{
int ret;
xTaskHandle openssl_handle;
ret = xTaskCreate(openssl_demo_thread,
OPENSSL_DEMO_THREAD_NAME,
OPENSSL_DEMO_THREAD_STACK_WORDS,
ret = xTaskCreate(openssl_example_task,
OPENSSL_EXAMPLE_TASK_NAME,
OPENSSL_EXAMPLE_TASK_STACK_WORDS,
NULL,
OPENSSL_DEMO_THREAD_PRORIOTY,
&openssl_handle);
OPENSSL_EXAMPLE_TASK_PRORIOTY,
&openssl_handle);
if (ret != pdPASS) {
ESP_LOGI(TAG, "create thread %s failed", OPENSSL_DEMO_THREAD_NAME);
ESP_LOGI(TAG, "create thread %s failed", OPENSSL_EXAMPLE_TASK_NAME);
}
}
@@ -184,7 +184,7 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
break;
case SYSTEM_EVENT_STA_GOT_IP:
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
openssl_client_init();
openssl_example_client_init();
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
/* This is a workaround as ESP32 WiFi libs don't currently