forked from espressif/esp-protocols
		
	feat(console): Added ping command to console component
This commit is contained in:
		@@ -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)
 | 
			
		||||
@@ -0,0 +1,2 @@
 | 
			
		||||
idf_component_register(SRCS "ping-basic.c"
 | 
			
		||||
                    INCLUDE_DIRS ".")
 | 
			
		||||
@@ -0,0 +1,6 @@
 | 
			
		||||
dependencies:
 | 
			
		||||
  idf:
 | 
			
		||||
    version: ">=5.0"
 | 
			
		||||
  console_cmd_ping:
 | 
			
		||||
    version: "*"
 | 
			
		||||
    override_path: '../../../'
 | 
			
		||||
@@ -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());
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
 | 
			
		||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
 | 
			
		||||
 | 
			
		||||
# -*- coding: utf-8 -*-
 | 
			
		||||
import pytest
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.mark.esp32
 | 
			
		||||
def test_examples_ping_command(dut):
 | 
			
		||||
    dut.expect('esp>', timeout=30)
 | 
			
		||||
    dut.write('ping 127.0.0.1')
 | 
			
		||||
    dut.expect('5 packets transmitted, 5 received, 0% packet loss, time 0ms', timeout=30)
 | 
			
		||||
    pass
 | 
			
		||||
		Reference in New Issue
	
	Block a user