Skip to content

Commit 28cab78

Browse files
committed
feat(test): add espressif test
1 parent b010bc9 commit 28cab78

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

.github/workflows/build_test.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build_espressif:
13+
strategy:
14+
matrix:
15+
idf_ver: ["latest"]
16+
runs-on: ubuntu-latest
17+
container: espressif/idf:${{ matrix.idf_ver }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
submodules: 'recursive'
22+
- name: Build with espressif idf ${{ matrix.idf_ver }}
23+
shell: bash
24+
run: |
25+
. ${IDF_PATH}/export.sh
26+
pip install idf-component-manager ruamel.yaml idf-build-apps --upgrade
27+
idf-build-apps build -p ./test/espressif --recursive --target esp32s3

test/espressif/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
7+
list(APPEND EXTRA_COMPONENT_DIRS "../../../ctshell")
8+
9+
project(ctshell)

test/espressif/main/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
idf_component_register(SRCS "main.c"
2+
INCLUDE_DIRS "."
3+
REQUIRES esp_driver_uart
4+
WHOLE_ARCHIVE)

test/espressif/main/main.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: CC0-1.0
5+
*/
6+
#include <esp_log.h>
7+
#include <stdio.h>
8+
#include <inttypes.h>
9+
#include "sdkconfig.h"
10+
#include "freertos/FreeRTOS.h"
11+
#include "freertos/task.h"
12+
#include "esp_chip_info.h"
13+
#include "esp_system.h"
14+
#include "ctshell_esp32.h"
15+
16+
/*
17+
* 注册根菜单: "net"
18+
* func=NULL, attr=MENU, 这是一个纯容器
19+
*/
20+
CTSHELL_EXPORT_CMD(net, NULL, "Network tools", CTSHELL_ATTR_MENU);
21+
22+
/*
23+
* 注册二级具体命令: "net ip"
24+
* parent="net", 挂载在 net 下
25+
* 这是一个叶子节点,输入 "net ip" 直接执行
26+
*/
27+
int cmd_net_ip(int argc, char *argv[]) {
28+
ctshell_printf("IP Address : 192.168.1.100\r\n");
29+
ctshell_printf("Subnet Mask: 255.255.255.0\r\n");
30+
return 0;
31+
}
32+
CTSHELL_EXPORT_SUBCMD(net, ip, cmd_net_ip, "Show IP address");
33+
34+
/*
35+
* 注册二级菜单容器: "net wifi"
36+
* parent="net"
37+
* func=NULL, 这是一个纯容器
38+
*/
39+
CTSHELL_EXPORT_SUBCMD(net, wifi, NULL, "WiFi management");
40+
41+
/*
42+
* 注册三级具体命令: "net wifi connect"
43+
* parent="net_wifi", 注意:父节点名是前两级名称的拼接 (net + _ + wifi)
44+
*/
45+
int cmd_wifi_connect(int argc, char *argv[]) {
46+
ctshell_arg_parser_t parser;
47+
ctshell_args_init(&parser, argc, argv);
48+
49+
// 定义参数: -s <ssid> 和 -p <password>
50+
ctshell_expect_str(&parser, "-s", "ssid");
51+
ctshell_expect_str(&parser, "-p", "password");
52+
53+
ctshell_args_parse(&parser);
54+
55+
if (ctshell_has(&parser, "ssid") && ctshell_has(&parser, "password")) {
56+
char *ssid = ctshell_get_str(&parser, "ssid");
57+
char *pwd = ctshell_get_str(&parser, "password");
58+
59+
ctshell_printf("Connecting to %s (Key: %s)...\r\n", ssid, pwd);
60+
} else {
61+
ctshell_printf("Usage: net wifi connect -s <ssid> -p <password>\r\n");
62+
}
63+
return 0;
64+
}
65+
CTSHELL_EXPORT_SUBCMD(net_wifi, connect, cmd_wifi_connect, "Connect to AP");
66+
67+
void app_main(void) {
68+
ctshell_esp32_init();
69+
70+
for (;;) {
71+
vTaskDelay(portMAX_DELAY);
72+
}
73+
}

test/espressif/sdkconfig.defaults

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file was generated using idf.py save-defconfig. It can be edited manually.
2+
# Espressif IoT Development Framework (ESP-IDF) x.x.x Project Minimal Configuration
3+
#
4+
CONFIG_CTSHELL_PORT_ESP32=y

0 commit comments

Comments
 (0)