From 13fa6c7af2abe5d78a05cde2c8f0c16a802ed916 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Wed, 11 Oct 2023 19:41:20 +0800 Subject: [PATCH] feat(ieee802154): Add ieee802154 CLI example --- .gitlab/CODEOWNERS | 1 + .gitlab/ci/rules.yml | 13 - .gitlab/ci/target-test.yml | 8 +- .../test_apps/.build-test-rules.yml | 5 - .../test_apps/test_ieee802154/README.md | 3 - .../test_ieee802154/sdkconfig.defaults | 4 - examples/README.md | 1 + examples/ieee802154/.build-test-rules.yml | 19 + examples/ieee802154/README.md | 9 + .../ieee802154/ieee802154_cli}/CMakeLists.txt | 2 +- examples/ieee802154/ieee802154_cli/README.md | 476 ++++++++++++++++++ .../components/cmd_ieee802154/CMakeLists.txt | 3 + .../cmd_ieee802154}/ieee802154_cmd.c | 85 +--- .../cmd_ieee802154}/ieee802154_cmd.h | 0 .../ieee802154_cli}/main/CMakeLists.txt | 6 +- .../ieee802154_cli/main/esp_ieee802154_cli.c | 6 +- .../ieee802154_cli/main/idf_component.yml | 4 + .../ieee802154_cli}/pytest_test_ieee802154.py | 34 +- .../ieee802154_cli}/sdkconfig.ci.release | 0 .../ieee802154_cli/sdkconfig.defaults | 0 20 files changed, 555 insertions(+), 124 deletions(-) delete mode 100644 components/ieee802154/test_apps/.build-test-rules.yml delete mode 100644 components/ieee802154/test_apps/test_ieee802154/README.md delete mode 100644 components/ieee802154/test_apps/test_ieee802154/sdkconfig.defaults create mode 100644 examples/ieee802154/.build-test-rules.yml create mode 100644 examples/ieee802154/README.md rename {components/ieee802154/test_apps/test_ieee802154 => examples/ieee802154/ieee802154_cli}/CMakeLists.txt (91%) create mode 100644 examples/ieee802154/ieee802154_cli/README.md create mode 100644 examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/CMakeLists.txt rename {components/ieee802154/test_apps/test_ieee802154/main/src => examples/ieee802154/ieee802154_cli/components/cmd_ieee802154}/ieee802154_cmd.c (92%) rename {components/ieee802154/test_apps/test_ieee802154/main/include => examples/ieee802154/ieee802154_cli/components/cmd_ieee802154}/ieee802154_cmd.h (100%) rename {components/ieee802154/test_apps/test_ieee802154 => examples/ieee802154/ieee802154_cli}/main/CMakeLists.txt (72%) rename components/ieee802154/test_apps/test_ieee802154/main/test_app_main.c => examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c (93%) create mode 100644 examples/ieee802154/ieee802154_cli/main/idf_component.yml rename {components/ieee802154/test_apps/test_ieee802154 => examples/ieee802154/ieee802154_cli}/pytest_test_ieee802154.py (97%) rename {components/ieee802154/test_apps/test_ieee802154 => examples/ieee802154/ieee802154_cli}/sdkconfig.ci.release (100%) create mode 100644 examples/ieee802154/ieee802154_cli/sdkconfig.defaults diff --git a/.gitlab/CODEOWNERS b/.gitlab/CODEOWNERS index 4cc21ca35c..983c82a17c 100644 --- a/.gitlab/CODEOWNERS +++ b/.gitlab/CODEOWNERS @@ -173,6 +173,7 @@ /examples/cxx/ @esp-idf-codeowners/system /examples/ethernet/ @esp-idf-codeowners/network /examples/get-started/ @esp-idf-codeowners/system +/examples/ieee802154/ @esp-idf-codeowners/ieee802154 /examples/mesh/ @esp-idf-codeowners/wifi /examples/network/ @esp-idf-codeowners/network @esp-idf-codeowners/wifi /examples/openthread/ @esp-idf-codeowners/ieee802154 diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index 589a89528f..ae8ef4851e 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -1830,19 +1830,6 @@ - <<: *if-dev-push changes: *patterns-target_test-adc -.rules:test:component_ut-esp32c6-i154: - rules: - - <<: *if-revert-branch - when: never - - <<: *if-protected - - <<: *if-label-build-only - when: never - - <<: *if-label-component_ut - - <<: *if-label-component_ut_esp32c6 - - <<: *if-label-target_test - - <<: *if-dev-push - changes: *patterns-component_ut-i154 - .rules:test:component_ut-esp32h2: rules: - <<: *if-revert-branch diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 8e7892eb11..48ab095ef9 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -1306,12 +1306,12 @@ pytest_components_esp32c6_adc: artifacts: false tags: [ esp32c6, adc ] -pytest_components_esp32c6_i154: +pytest_examples_esp32c6_i154: extends: - - .pytest_components_dir_template - - .rules:test:component_ut-esp32c6-i154 + - .pytest_examples_dir_template + - .rules:test:example_test-esp32c6 needs: - - job: build_pytest_components_esp32c6 + - job: build_pytest_examples_esp32c6 artifacts: false tags: [ esp32c6, ieee802154 ] diff --git a/components/ieee802154/test_apps/.build-test-rules.yml b/components/ieee802154/test_apps/.build-test-rules.yml deleted file mode 100644 index 2200b10c86..0000000000 --- a/components/ieee802154/test_apps/.build-test-rules.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps - -components/ieee802154/test_apps/test_ieee802154: - enable: - - if: IDF_TARGET == "esp32c6" diff --git a/components/ieee802154/test_apps/test_ieee802154/README.md b/components/ieee802154/test_apps/test_ieee802154/README.md deleted file mode 100644 index 65eeecb079..0000000000 --- a/components/ieee802154/test_apps/test_ieee802154/README.md +++ /dev/null @@ -1,3 +0,0 @@ -| Supported Targets | ESP32-C6 | -| ----------------- | -------- | - diff --git a/components/ieee802154/test_apps/test_ieee802154/sdkconfig.defaults b/components/ieee802154/test_apps/test_ieee802154/sdkconfig.defaults deleted file mode 100644 index e625399017..0000000000 --- a/components/ieee802154/test_apps/test_ieee802154/sdkconfig.defaults +++ /dev/null @@ -1,4 +0,0 @@ -# This file was generated using idf.py save-defconfig. It can be edited manually. -# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration -# -CONFIG_IDF_TARGET_ESP32C6=y diff --git a/examples/README.md b/examples/README.md index 14877e8bbd..54a00a9ed8 100644 --- a/examples/README.md +++ b/examples/README.md @@ -14,6 +14,7 @@ The examples are grouped into subdirectories by category. Each category director - `cxx` C++ language utilization examples and experimental components. - `ethernet` Ethernet network examples. - `get-started` Simple examples with minimal functionality. Good start point for beginners. +- `ieee802154` IEEE802.15.4 examples. - `mesh` Wi-Fi Mesh examples. - `network` Examples related to general network environment, test & analysis. - `openthread` OpenThread examples. diff --git a/examples/ieee802154/.build-test-rules.yml b/examples/ieee802154/.build-test-rules.yml new file mode 100644 index 0000000000..0af66989a0 --- /dev/null +++ b/examples/ieee802154/.build-test-rules.yml @@ -0,0 +1,19 @@ +# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps + +.ieee802154_dependencies: &ieee802154_dependencies + depends_components: + - esp_coex + - esp_phy + - ieee802154 + depends_filepatterns: + - examples/ieee802154/**/* + - examples/system/console/advanced/components/cmd_system/**/* + +examples/ieee802154/ieee802154_cli: + enable: + - if: SOC_IEEE802154_SUPPORTED == 1 + disable_test: + - if: IDF_TARGET == "esp32h2" + temporary: true + reason: only test on esp32c6 + <<: *ieee802154_dependencies diff --git a/examples/ieee802154/README.md b/examples/ieee802154/README.md new file mode 100644 index 0000000000..dd9649b49d --- /dev/null +++ b/examples/ieee802154/README.md @@ -0,0 +1,9 @@ +# IEEE802.15.4 Examples + +See the [README.md](../README.md) file in the upper level [examples](../) directory for more information about examples. + +## Overview + +In this folder, it contains following IEEE802.15.4 examples: + +* [ieee802154_cli](ieee802154_cli) is an IEEE802.15.4 Command Line example, the commands it supports are listed in [README.md](./ieee802154_cli//README.md). It runs on an 802.15.4 SoC like ESP32-H2. diff --git a/components/ieee802154/test_apps/test_ieee802154/CMakeLists.txt b/examples/ieee802154/ieee802154_cli/CMakeLists.txt similarity index 91% rename from components/ieee802154/test_apps/test_ieee802154/CMakeLists.txt rename to examples/ieee802154/ieee802154_cli/CMakeLists.txt index b7ca706cb4..4aba22f75c 100644 --- a/components/ieee802154/test_apps/test_ieee802154/CMakeLists.txt +++ b/examples/ieee802154/ieee802154_cli/CMakeLists.txt @@ -6,4 +6,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) # "Trim" the build. Include the minimal set of components, main, and anything it depends on. set(COMPONENTS main) -project(test_ieee802154) +project(ieee802154_cli) diff --git a/examples/ieee802154/ieee802154_cli/README.md b/examples/ieee802154/ieee802154_cli/README.md new file mode 100644 index 0000000000..584a8d4ca8 --- /dev/null +++ b/examples/ieee802154/ieee802154_cli/README.md @@ -0,0 +1,476 @@ +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +# IEEE802.15.4 Command Line Example + +This example demonstrates an IEEE802.15.4 Command Line. The IEEE802.15.4 CLI exposes configuration and management APIs via a command line interface. + +## How to use example + +### Hardware Required + +To run this example, a board with IEEE 802.15.4 module (for example ESP32-H2) is required. + +### Configure the project + +``` +idf.py menuconfig +``` + +The example can run with the default configuration. IEEE802.15.4 Command Line is enabled with UART as the default interface. Additionally, USB JTAG is also supported and can be activated through the menuconfig: + +``` +Component config → ESP System Settings → Channel for console output → USB Serial/JTAG Controller +``` + +### Build, Flash, and Run + +Build the project and flash it to the board, then run monitor tool to view serial output: + +``` +idf.py -p PORT build flash monitor +``` + +Now you'll get an IEEE802.15.4 command line shell. + +## IEEE802.15.4 Command List + +- [cca](#cca) +- [channel](#channel) +- [coordinator](#coordinator) +- [ed](#ed) +- [esp154](#esp154) +- [extaddr](#extaddr) +- [free](#free) +- [heap](#heap) +- [panid](#panid) +- [pending](#pending) +- [promisc](#promisc) +- [reg](#reg) +- [restart](#restart) +- [rx](#rx) +- [shortaddr](#shortaddr) +- [tx](#tx) +- [txpower](#txpower) +- [version](#version) +- [help](#help) + +## IEEE802.15.4 Command Details + +Most of the commands are available in both full and abbreviated form. +For example, to enable the receive mode, both `rx -r 1` and `rx --receive=1` are valid +```bash +> rx -r 1 +I (4227508) i154cmd: RX Start +> rx --receive=1 +I (4249898) i154cmd: RX Start +``` +Only abbreviated formats are described below. + + +### cca +#### cca -g +Get the cca cfg. + +```bash +> cca -g +I (2676818) i154cmd: threshold:-60 dB, mode: 1 +``` + +#### cca -m \ +Set the cca mode. +* 0: carrier +* 1: ED +* 2: carrier or ED +* 3: carrier and ED +```bash +> cca -m 1 +I (5047618) i154cmd: set cca mode as: 1 +``` + +#### cca -v \ +Set the cca threshold. +```bash +> cca -v 60 +I (4731648) i154cmd: set cca threshold as: 60 +``` + +### channel +#### channel -g +Get the channel number. +```bash +> channel -g +I (67238) i154cmd: current channel: 11 +``` + +#### channel -s \ +Set the channel number. +```bash +> channel -s 21 +I (220268) i154cmd: set channel: 21 +``` + +### coordinator +#### coordinator -d +Enable the coordinator. +```bash +> coordinator -d +I (438228) i154cmd: hardware coordinator is disabled +``` + +#### coordinator -e +Disable the coordinator. +```bash +> coordinator -e +I (453288) i154cmd: hardware coordinator is enabled +``` + +#### coordinator -g +Get the coordinator. +```bash +> coordinator -g +I (472398) i154cmd: hardware coordinator was enabled +``` + +### ed +#### ed -d \ +Configure the duration of energy detection. +```bash +> ed -d 2 +I (668548) i154cmd: ed start +I (668548) i154cmd: ed_scan_rss_value: -98 dB +I (472398) i154cmd: hardware coordinator was enabled +``` + +### esp154 +#### esp154 -e +Enable initialize the IEEE 802.15.4 subsystem. +```bash +> esp154 -e +I (87127) i154cmd: initialize the IEEE 802.15.4 subsystem +``` + +#### esp154 -d +Disable initialize the IEEE 802.15.4 subsystem. +```bash +> esp154 -d +I (97107) i154cmd: deinitialize the IEEE 802.15.4 subsystem +``` + +### extaddr +#### extaddr \ +Set the device extended address. +```bash +> extaddr 0xaa 0xbb 0xcc 0xdd 0x00 0x11 0x22 0x33 +I (704937) i154cmd: set extaddr: 33221100ddccbbaa +``` + +#### extaddr -g +Get the device extended address. +```bash +> extaddr -g +I (615587) i154cmd: get extaddr: 0807060504030201 +``` + +### free +Get the current size of free heap memory. +```bash +> free +235024 +``` + +### heap +Get minimum size of free heap memory that was available during program execution. +```bash +> heap +min heap size: 231076 +``` + +### panid +#### panid \ +Set the device Pan ID. +```bash +> panid 0x1234 +I (1112117) i154cmd: set panid: 0x1234 +``` + +#### panid -g +Get the device Pan ID. +```bash +> panid -g +I (1128457) i154cmd: current panid: 0x1234 +``` + +### pending +#### pending \ +Add the address to pending table (2 bytes for short address, 8 bytes for extended address). +```bash +> pending 0x34 0x12 +I (1806327) i154cmd: add pending shortaddr: 0x1234 +``` + +#### pending -m \ +Set the autopending mode. +* 0: disable +* 1: enable +* 2: enhanced +```bash +> pending -m 1 +I (1828817) i154cmd: set auto pending mode as: 1 +``` + +#### pending -g +Get the autopending mode. +```bash +> pending -g +I (2007797) i154cmd: get auto pending mode as: 1 +``` + +#### pending -r +Reset the pending address table. +```bash +> pending -r +I (2113377) i154cmd: clear the pending address table +``` + +#### pending -d +Delete the address from pending table (2 bytes for short address, 8 bytes for extended address). +```bash +> pending -d 0x34 -d 0x12 +I (2322787) i154cmd: delete pending shortaddr: 0x1234 +``` + +### promisc +#### promisc [-edg] +* e: Enable the promiscuous mode. +* d: Disable the promiscuous mode. +* g: Get the promiscuous mode. +```bash +> promisc -e +I (2599357) i154cmd: promiscuous mode is enabled +> promisc -d +I (2600977) i154cmd: promiscuous mode is disabled +> promisc -g +I (2602927) i154cmd: hardware promiscuous mode was disabled +``` + +### reg +#### reg -w \ -v \ +Write the register \ with \. +```bash +> reg -w 0x0184 -v 0x00 +I (103917) i154cmd: write reg 0x184: 0x1234 +``` + +#### reg -r \ +Read the register \. +```bash +> reg -r 0x0184 +I (220967) i154cmd: reg 0x184 value: 0x1234 +``` + +### restart +Restart the program. + +### rx +#### rx -r \ +Configure the radio receive mode. +* 0: disable +* 1: enable +```bash +> rx -r 1 +I (121977) i154cmd: RX Start +> rx -r 0 +I (127267) i154cmd: radio exit receive mode +``` + +### shortaddr +#### shortaddr \ +set the device short address. +```bash +> shortaddr 0x1234 +I (543167) i154cmd: set shortaddr: 0x1234 +``` + +#### shortaddr -g +```bash +> shortaddr -g +I (568387) i154cmd: current shortaddr: 0x1234 +``` + +### tx +#### tx \ +Transmit IEEE 802154 MAC frame. +* -C: Set cca trigging tx mode true. +```bash +> tx 0x00 0x11 0x22 0x33 0x44 0x55 0x66 0x77 +I (6399947) i154cmd: tx sfd done, Radio state: 4 +I (6399957) i154cmd: Tx Done 8 bytes +I (6399957) i154cmd: 00 11 22 33 44 55 66 77 +> tx 0x00 0x11 0x22 0x33 0x44 0x55 0x66 0x77 -C +I (6580547) i154cmd: tx sfd done, Radio state: 4 +I (6580547) i154cmd: Tx Done 8 bytes +I (6580547) i154cmd: 00 11 22 33 44 55 66 77 +``` + +#### tx -l \ +Transmit IEEE 802154 MAC frame wich has a length=\. +* -C: Set cca trigging tx mode true. +```bash +> tx -l 10 +I (6721867) i154cmd: tx sfd done, Radio state: 4 +I (6721867) i154cmd: Tx Done 10 bytes +I (6721867) i154cmd: 00 01 02 03 04 05 06 07 +I (6721867) i154cmd: 08 09 00 00 00 00 00 00 +> tx -l 10 -C +I (6726067) i154cmd: tx sfd done, Radio state: 4 +I (6726067) i154cmd: Tx Done 10 bytes +I (6726067) i154cmd: 00 01 02 03 04 05 06 07 +I (6726067) i154cmd: 08 09 00 00 00 00 00 00 +``` + +### txpower +#### txpower -g +Get the txpower. +```bash +> txpower -g +I (7100077) i154cmd: current txpower: 20 +``` + +#### txpower -s \ +Set the txpower. +```bash +> txpower -s 40 +I (7116217) i154cmd: set txpower: 40 +``` + +### version +Get version of chip and SDK. +```bash +> version +IDF Version:v5.3-dev-699-gb94f6ef680-dirty +Chip info: + model:ESP32-H2 + cores:1 + feature:/BLE/External-Flash:2 MB + revision number:1 +``` + +### help +Get the summary of all registered commands. + +```bash +> help +cca [-g] [-v ] [-m ] + cca config + -v, --value= cca threshold setting + -m, --mode= cca mode, 0: carrier; 1: ED; 2: carrier or ED; 3: carrier and ED + -g, --get get the cca cfg + +channel [-g] [-s ] + get/set the channel number + -g, --get get channel number + -s, --set= set channel number + +coordinator [-edg] + enable/disable/get the coordinator + -e, --enable enable the coordinator + -d, --disable disable the coordinator + -g, --get get the coordinator + +ed [-d ] + configure the duration + -d, --duration= configure the duration of energy detection + +esp154 [-ed] + enable/disable initialize the IEEE 802.15.4 subsystem + -e, --enable initialize the IEEE 802.15.4 subsystem + -d, --disable deinitialize the IEEE 802.15.4 subsystem + +extaddr [-g] []... + set/get the device extended address + -g, --get get the device extended address + set the device extended address + +free + Get the current size of free heap memory + +heap + Get minimum size of free heap memory that was available during program + execution + +help [] + Print the summary of all registered commands if no arguments are given, + otherwise print summary of given command. + Name of command + +log_level + Set log level for all tags or a specific tag. + Log tag to set the level for, or * to set for all tags + Log level to set. Abbreviated words are accepted. + +panid [-g] [] + get/set the device Pan ID + set the device Pan ID + -g, --get get the device Pan ID + +pending [-gr] [-m ] []... [-d ]... + configure the pending address table + -m, --mode= set the autopending mode (0: disable; 1: enable; 2: enhanced) + -g, --get get the autopending mode (0: disable; 1: enable; 2: enhanced) + -r, --reset reset the pending address table + add the address to pending table (2 bytes for short address, 8 bytes for extended address) + -d, --delete= delete the address from pending table (2 bytes for short address, 8 bytes for extended address) + +promisc [-edg] + enable/disable/get the promiscuous mode + -e, --enable enable the promiscuous mode + -d, --disable disable the promiscuous mode + -g, --get get the promiscuous mode + +reg [-r
] [-w
] [-v ] + read/write the register + -r, --read=
read the register value + -w, --write=
register address to be written + -v, --value= register value to be written + +restart + Software reset of the chip + +rx [-r ] + enable/disable the receive mode + -r, --receive= configure the radio receive mode, 0: disable; 1: enable + +shortaddr [-g] [] + get/set the device short address + set the device short address + -g, --get get the device short address + +tx [-C] [-l ] []... [-o ] + transmit IEEE 802154 MAC frame + -l, --length= frame length + -C, --cca_enable set cca trigging tx mode true + transmit raw frame + -o, --offset= tx buffer offset + +txpower [-g] [-s ] + get/set the txpower + -g, --get get txpower + -s, --set= set txpower,value range -80dBm~-10dBm + +version + Get version of chip and SDK +``` + +#### help \ +Get the summary of given command. + +```bash +> help tx +tx [-C] [-l ] []... [-o ] + transmit IEEE 802154 MAC frame + -l, --length= frame length + -C, --cca_enable set cca trigging tx mode true + transmit raw frame + -o, --offset= tx buffer offset +``` diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/CMakeLists.txt b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/CMakeLists.txt new file mode 100644 index 0000000000..742f87bc43 --- /dev/null +++ b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "ieee802154_cmd.c" + INCLUDE_DIRS "." + PRIV_REQUIRES ieee802154 console esp_phy) diff --git a/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c similarity index 92% rename from components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c rename to examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c index 2a56811f47..7c4e93e43e 100644 --- a/components/ieee802154/test_apps/test_ieee802154/main/src/ieee802154_cmd.c +++ b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c @@ -18,7 +18,7 @@ #include "soc/ieee802154_reg.h" static uint8_t s_tx_frame[131] = { 0 }; -static const char* TAG = "i154test"; +static const char* TAG = "i154cmd"; static void register_rx(void); static void register_tx(void); @@ -34,8 +34,6 @@ static void register_pending(void); static void register_cca(void); static void register_esp154(void); static void register_reg(void); -static void register_free(void); -static void register_restart(void); void register_ieee802154_cmd(void) { @@ -53,8 +51,6 @@ void register_ieee802154_cmd(void) register_cca(); register_esp154(); register_reg(); - register_free(); - register_restart(); } static struct { @@ -78,8 +74,8 @@ static int process_energy(int argc, char **argv) ESP_LOGI(TAG, "ed start"); esp_ieee802154_energy_detect(duration); } else { - ESP_LOGE(TAG, "no valid arguments"); - return 1; + ESP_LOGE(TAG, "no valid arguments"); + return 1; } } else { ESP_LOGE(TAG, "no valid arguments"); @@ -364,7 +360,7 @@ static int process_extaddr(int argc, char **argv) } else if (extaddr_args.get_extaddr->count) { esp_ieee802154_get_extended_address(extaddr); ESP_LOGI(TAG, "get extaddr: %02x%02x%02x%02x%02x%02x%02x%02x", extaddr[7], extaddr[6], extaddr[5], extaddr[4], - extaddr[3], extaddr[2], extaddr[1], extaddr[0]); + extaddr[3], extaddr[2], extaddr[1], extaddr[0]); } else { ESP_LOGE(TAG, "no valid arguments"); } @@ -640,38 +636,6 @@ static void register_esp154() ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); } -/* 'fheap' command check for memory leaks */ -static struct { - struct arg_end *end; -} free_args; - -static int process_free(int argc, char **argv) -{ - int nerrors = arg_parse(argc, argv, (void **) &free_args); - if (nerrors != 0) { - arg_print_errors(stderr, free_args.end, argv[0]); - return 1; - } - - esp_get_free_heap_size(); - ESP_LOGI(TAG, "heap size: %" PRIu32, esp_get_free_heap_size()); - return 0; -} - -static void register_free() -{ - free_args.end = arg_end(2); - - const esp_console_cmd_t cmd = { - .command = "fheap", - .help = "get the size of heap memory", - .hint = NULL, - .func = &process_free, - .argtable = &free_args - }; - ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); -} - /* 'reg' command reads/writes the registers */ static struct { struct arg_int *get_reg; @@ -766,7 +730,7 @@ static int process_tx(int argc, char **argv) if (tx_args.cca_enable->count) { cca = true; } - memcpy(s_tx_frame+offset, tx_frame, sizeof(tx_frame)); + memcpy(s_tx_frame + offset, tx_frame, sizeof(tx_frame)); esp_ieee802154_transmit(s_tx_frame, cca); return 0; } @@ -841,51 +805,30 @@ static void register_rx(void) ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); } -/* 'restart' command restarts the program */ -static int restart(int argc, char **argv) +static void esp_ieee802154_frame_print(const uint8_t *frame) { - ESP_EARLY_LOGI(TAG, "Restarting"); - esp_restart(); -} - -static void register_restart(void) -{ - const esp_console_cmd_t cmd = { - .command = "restart", - .help = "Restart the program", - .hint = NULL, - .func = &restart - }; - ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); + for (uint8_t idx = 1; idx < frame[0]; idx += 8) { + ESP_EARLY_LOGI(TAG, "%02x %02x %02x %02x %02x %02x %02x %02x", + frame[idx], frame[idx + 1], frame[idx + 2], frame[idx + 3], + frame[idx + 4], frame[idx + 5], frame[idx + 6], frame[idx + 7]); + } } void esp_ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info) { ESP_EARLY_LOGI(TAG, "Tx Done %d bytes", frame[0]); - for(uint8_t idx = 1; idx < frame[0]; idx+=8) { - ESP_EARLY_LOGI(TAG, "%02x %02x %02x %02x %02x %02x %02x %02x", - frame[idx], frame[idx+1], frame[idx+2], frame[idx+3], - frame[idx+4], frame[idx+5], frame[idx+6], frame[idx+7]); - } + esp_ieee802154_frame_print(frame); if (ack != NULL) { ESP_EARLY_LOGI(TAG, "Rx ack %d bytes", ack[0]); - for(uint8_t idx = 1; idx < ack[0]; idx+=8) { - ESP_EARLY_LOGI(TAG, "%02x %02x %02x %02x %02x %02x %02x %02x", - ack[idx], ack[idx+1], ack[idx+2], ack[idx+3], - ack[idx+4], ack[idx+5], ack[idx+6], ack[idx+7]); - } + esp_ieee802154_frame_print(ack); } } void esp_ieee802154_receive_done(uint8_t *frame, esp_ieee802154_frame_info_t *frame_info) { ESP_EARLY_LOGI(TAG, "Rx Done %d bytes", frame[0]); - for(uint8_t idx = 1; idx < frame[0]; idx+=8) { - ESP_EARLY_LOGI(TAG, "%02x %02x %02x %02x %02x %02x %02x %02x", - frame[idx], frame[idx+1], frame[idx+2], frame[idx+3], - frame[idx+4], frame[idx+5], frame[idx+6], frame[idx+7]); - } + esp_ieee802154_frame_print(frame); } void esp_ieee802154_energy_detect_done(int8_t power) diff --git a/components/ieee802154/test_apps/test_ieee802154/main/include/ieee802154_cmd.h b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.h similarity index 100% rename from components/ieee802154/test_apps/test_ieee802154/main/include/ieee802154_cmd.h rename to examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.h diff --git a/components/ieee802154/test_apps/test_ieee802154/main/CMakeLists.txt b/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt similarity index 72% rename from components/ieee802154/test_apps/test_ieee802154/main/CMakeLists.txt rename to examples/ieee802154/ieee802154_cli/main/CMakeLists.txt index 625a6175c9..1407c219b1 100644 --- a/components/ieee802154/test_apps/test_ieee802154/main/CMakeLists.txt +++ b/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt @@ -1,5 +1,4 @@ -set(srcs "test_app_main.c" - "src/ieee802154_cmd.c") +set(srcs "esp_ieee802154_cli.c") set(include "." "include") @@ -7,6 +6,5 @@ set(include "." # In order for the cases defined by `TEST_CASE` to be linked into the final elf, # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} - INCLUDE_DIRS include - PRIV_REQUIRES ieee802154 console fatfs nvs_flash esp_phy + PRIV_REQUIRES ieee802154 console fatfs nvs_flash esp_phy cmd_ieee802154 cmd_system WHOLE_ARCHIVE) diff --git a/components/ieee802154/test_apps/test_ieee802154/main/test_app_main.c b/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c similarity index 93% rename from components/ieee802154/test_apps/test_ieee802154/main/test_app_main.c rename to examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c index 5436e625bc..3ad3a546f6 100644 --- a/components/ieee802154/test_apps/test_ieee802154/main/test_app_main.c +++ b/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c @@ -5,6 +5,7 @@ */ #include #include +#include "ieee802154_cmd.h" #include "esp_system.h" #include "esp_log.h" #include "esp_console.h" @@ -14,7 +15,7 @@ #include "nvs_flash.h" #include "esp_ieee802154.h" #include "esp_phy_init.h" -#include "ieee802154_cmd.h" +#include "cmd_system.h" #define PROMPT_STR "ieee802154" @@ -22,7 +23,7 @@ static void initialize_nvs(void) { esp_err_t err = nvs_flash_init(); if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { - ESP_ERROR_CHECK( nvs_flash_erase() ); + ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } ESP_ERROR_CHECK(err); @@ -44,6 +45,7 @@ void app_main(void) /* Register commands */ esp_console_register_help_command(); register_ieee802154_cmd(); + register_system_common(); esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl)); diff --git a/examples/ieee802154/ieee802154_cli/main/idf_component.yml b/examples/ieee802154/ieee802154_cli/main/idf_component.yml new file mode 100644 index 0000000000..77b231f2a7 --- /dev/null +++ b/examples/ieee802154/ieee802154_cli/main/idf_component.yml @@ -0,0 +1,4 @@ +## IDF Component Manager Manifest File +dependencies: + cmd_system: + path: ${IDF_PATH}/examples/system/console/advanced/components/cmd_system diff --git a/components/ieee802154/test_apps/test_ieee802154/pytest_test_ieee802154.py b/examples/ieee802154/ieee802154_cli/pytest_test_ieee802154.py similarity index 97% rename from components/ieee802154/test_apps/test_ieee802154/pytest_test_ieee802154.py rename to examples/ieee802154/ieee802154_cli/pytest_test_ieee802154.py index 74b8548349..965780de69 100644 --- a/components/ieee802154/test_apps/test_ieee802154/pytest_test_ieee802154.py +++ b/examples/ieee802154/ieee802154_cli/pytest_test_ieee802154.py @@ -148,7 +148,7 @@ def test_based_txrx(dut: Tuple[IdfDut, IdfDut]) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -162,7 +162,7 @@ def test_based_energy(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -177,7 +177,7 @@ def test_based_channel(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -192,7 +192,7 @@ def test_based_txpower(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -211,7 +211,7 @@ def test_based_promiscuous(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -226,7 +226,7 @@ def test_based_panid(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -241,7 +241,7 @@ def test_based_shortaddr(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -256,7 +256,7 @@ def test_based_extaddr(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -275,7 +275,7 @@ def test_based_coordinator(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -296,7 +296,7 @@ def test_based_pending(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -580,7 +580,7 @@ def test_based_transmit_failed(dut: IdfDut) -> None: @pytest.mark.esp32c6 -@pytest.mark.generic +@pytest.mark.ieee802154 @pytest.mark.parametrize( 'config', ['release',], indirect=True @@ -588,15 +588,15 @@ def test_based_transmit_failed(dut: IdfDut) -> None: def test_based_initialize(dut: IdfDut) -> None: transmit = dut transmit.expect('ieee802154>', timeout=10) - transmit.write('fheap') - fst_data = transmit.expect(r'heap size: [0-9]+', timeout=10)[0].decode() - fst_size = re.findall(r'heap size: ([0-9]+)', fst_data) + transmit.write('heap') + fst_data = transmit.expect(r'min heap size: [0-9]+', timeout=10)[0].decode() + fst_size = re.findall(r'min heap size: ([0-9]+)', fst_data) transmit.write('esp154 -e') transmit.expect('initialize the IEEE 802.15.4 subsystem', timeout=10) transmit.write('esp154 -d') transmit.expect('deinitialize the IEEE 802.15.4 subsystem', timeout=10) - transmit.write('fheap') - scd_data = transmit.expect(r'heap size: [0-9]+', timeout=10)[0].decode() - scd_size = re.findall(r'heap size: ([0-9]+)', scd_data) + transmit.write('heap') + scd_data = transmit.expect(r'min heap size: [0-9]+', timeout=10)[0].decode() + scd_size = re.findall(r'min heap size: ([0-9]+)', scd_data) print('first heap size: ', int(fst_size[0])) print('second heap size: ', int(scd_size[0])) diff --git a/components/ieee802154/test_apps/test_ieee802154/sdkconfig.ci.release b/examples/ieee802154/ieee802154_cli/sdkconfig.ci.release similarity index 100% rename from components/ieee802154/test_apps/test_ieee802154/sdkconfig.ci.release rename to examples/ieee802154/ieee802154_cli/sdkconfig.ci.release diff --git a/examples/ieee802154/ieee802154_cli/sdkconfig.defaults b/examples/ieee802154/ieee802154_cli/sdkconfig.defaults new file mode 100644 index 0000000000..e69de29bb2