Skip to content

Commit

Permalink
feat(common): Added simple component for console initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
espressif-abhikroy committed Oct 9, 2023
1 parent 6dcca59 commit 9a27a40
Show file tree
Hide file tree
Showing 27 changed files with 498 additions and 53 deletions.
1 change: 0 additions & 1 deletion components/console_cmd_ifconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
idf_component_register(SRCS "console_ifconfig.c"
INCLUDE_DIRS "."
REQUIRES "ethernet_init"
PRIV_REQUIRES esp_netif console esp_eth)
6 changes: 3 additions & 3 deletions components/console_cmd_ifconfig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ The component offers a console that enables runtime network interface configurat
```
4. In your app_main() function, add the following line as the last line:
```c
console_cmd_init(); // Initialize console
ESP_ERROR_CHECK(console_cmd_init()); // Initialize console
ESP_ERROR_CHECK(console_cmd_ifconfig_register());
console_cmd_start(); // Start console
ESP_ERROR_CHECK(console_cmd_start()); // Start console
```


## Suported commands:
## Suported command:

### Ifconfig:
```
Expand Down
18 changes: 0 additions & 18 deletions components/console_cmd_ifconfig/console_ifconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ esp_err_t ifcfg_netif_op(netif_op *self, int argc, char *argv[], esp_netif_t *es
esp_err_t ifcfg_eth_op(netif_op *self, int argc, char *argv[], esp_netif_t *esp_netif);

static const char *TAG = "console_ifconfig";
static esp_console_repl_t *s_repl = NULL;

netif_op cmd_list[] = {
{.name = "help", .operation = ifcfg_help_op, .arg_cnt = 2, .start_index = 1, .netif_flag = false, .help = "ifconfig help: Prints the help text for all ifconfig commands"},
Expand Down Expand Up @@ -640,20 +639,3 @@ esp_err_t console_cmd_ifconfig_register(void)

return ret;
}

__attribute__((weak)) void console_cmd_init(void)
{
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();

// install console REPL environment
#if CONFIG_ESP_CONSOLE_UART
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &s_repl));
#endif
}

__attribute__((weak)) int console_cmd_start(void)
{
// start console REPL
return esp_console_start_repl(s_repl);
}
3 changes: 1 addition & 2 deletions components/console_cmd_ifconfig/console_ifconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

__attribute__((weak)) void console_cmd_init(void);
__attribute__((weak)) int console_cmd_start(void);
#include "console_simple_init.h"

esp_err_t console_cmd_ifconfig_register(void);
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(ifconfig-basic)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
idf_component_register(SRCS "ifconfig-basic.c"
INCLUDE_DIRS ".")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
idf:
version: '>=5.1'
console_cmd_ifconfig:
version: "*"
override_path: '../../../'
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include "esp_netif.h"
#include "nvs_flash.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "console_ifconfig.h"


void app_main(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_err_t ret = nvs_flash_init(); //Initialize NVS
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);

// Initialize console REPL
ESP_ERROR_CHECK(console_cmd_init());

ESP_ERROR_CHECK(console_cmd_ifconfig_register());

// start console REPL
ESP_ERROR_CHECK(console_cmd_start());

}
6 changes: 4 additions & 2 deletions components/console_cmd_ifconfig/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: 0.0.9
version: 1.0.0
url: https://github.com/espressif/esp-protocols/tree/master/components/console_cmd_ifconfig
description: The component offers a console that enables runtime network interface configuration and monitoring.
dependencies:
idf:
version: '>=5.0'
ethernet_init:
espressif/console_simple_init:
version: '>=0.0.1'
espressif/ethernet_init:
version: '>=0.0.7'
6 changes: 3 additions & 3 deletions components/console_cmd_ping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ The component provides a console where the 'ping' command can be executed.
```
4. In your app_main() function, add the following line as the last line:
```c
console_cmd_init(); // Initialize console
ESP_ERROR_CHECK(console_cmd_init()); // Initialize console
ESP_ERROR_CHECK(console_cmd_ping_register());
console_cmd_start(); // Start console
ESP_ERROR_CHECK(console_cmd_start()); // Start console
```


## Suported commands:
## Suported command:

### ping:
```
Expand Down
20 changes: 0 additions & 20 deletions components/console_cmd_ping/console_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


static const char *TAG = "console_ping";
static esp_console_repl_t *s_repl = NULL;

static void cmd_ping_on_ping_success(esp_ping_handle_t hdl, void *args)
{
Expand Down Expand Up @@ -186,22 +185,3 @@ esp_err_t console_cmd_ping_register(void)

return ret;
}


__attribute__((weak)) void console_cmd_init(void)
{
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();

// install console REPL environment
#if CONFIG_ESP_CONSOLE_UART
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &s_repl));
#endif
}


__attribute__((weak)) int console_cmd_start(void)
{
// start console REPL
return esp_console_start_repl(s_repl);
}
4 changes: 1 addition & 3 deletions components/console_cmd_ping/console_ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

__attribute__((weak)) void console_cmd_init(void);
__attribute__((weak)) int console_cmd_start(void);
#include "console_simple_init.h"

esp_err_t console_cmd_ping_register(void);
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(ping-basic)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
idf_component_register(SRCS "ping-basic.c"
INCLUDE_DIRS ".")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
idf:
version: '>=5.1'
console_cmd_ping:
version: "*"
override_path: '../../../'
34 changes: 34 additions & 0 deletions components/console_cmd_ping/examples/ping-basic/main/ping-basic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include "esp_netif.h"
#include "nvs_flash.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "console_ping.h"


void app_main(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_err_t ret = nvs_flash_init(); //Initialize NVS
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);

// Initialize console REPL
ESP_ERROR_CHECK(console_cmd_init());

// Register ping command
ESP_ERROR_CHECK(console_cmd_ping_register());

// start console REPL
ESP_ERROR_CHECK(console_cmd_start());

}
4 changes: 3 additions & 1 deletion components/console_cmd_ping/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version: 0.0.4
version: 1.0.0
url: https://github.com/espressif/esp-protocols/tree/master/components/console_cmd_ping
description: The component provides a console where the 'ping' command can be executed.
dependencies:
idf:
version: '>=5.0'
espressif/console_simple_init:
version: '>=0.0.1'
3 changes: 3 additions & 0 deletions components/console_simple_init/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRCS "console_simple_init.c"
INCLUDE_DIRS "."
PRIV_REQUIRES console)
Loading

0 comments on commit 9a27a40

Please sign in to comment.