feat(802.15.4): IEEE802.15.4 add rx buffer statistic

This commit is contained in:
Tan Yan Quan
2024-11-14 10:35:29 +08:00
parent bfac3bfd16
commit 979e1d86cb
12 changed files with 350 additions and 18 deletions
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -0,0 +1,3 @@
idf_component_register(SRCS "ieee802154_stats.c"
INCLUDE_DIRS "."
REQUIRES ieee802154 console esp_phy)
@@ -0,0 +1,174 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <string.h>
#include "esp_log.h"
#include "esp_ieee802154.h"
#include "esp_console.h"
#include "argtable3/argtable3.h"
#include "ieee802154_stats.h"
#if CONFIG_IEEE802154_DEBUG
static const char* TAG = "i154cmd";
#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
static void register_rx_buffer_statistic(void);
#endif
#if CONFIG_IEEE802154_TXRX_STATISTIC
static void register_txrx_statistic(void);
#endif
#if CONFIG_IEEE802154_RECORD
static void register_record(void);
#endif
void register_ieee802154_debug_cmd(void)
{
#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
register_rx_buffer_statistic();
#endif
#if CONFIG_IEEE802154_TXRX_STATISTIC
register_txrx_statistic();
#endif
#if CONFIG_IEEE802154_RECORD
register_record();
#endif
}
#endif
#if CONFIG_IEEE802154_DEBUG
#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
static struct {
struct arg_lit *clear;
struct arg_lit *print;
struct arg_end *end;
} rx_buff_stat_args;
static int process_rx_buffer_statistic(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **) &rx_buff_stat_args);
if (nerrors != 0) {
arg_print_errors(stderr, rx_buff_stat_args.end, argv[0]);
return 1;
}
if (rx_buff_stat_args.print->count) {
esp_ieee802154_rx_buffer_statistic_printf();
}
if (rx_buff_stat_args.clear->count) {
esp_ieee802154_rx_buffer_statistic_clear();
}
if (!rx_buff_stat_args.print->count && !rx_buff_stat_args.clear->count) {
ESP_LOGE(TAG, "no valid arguments");
return 1;
}
return 0;
}
static void register_rx_buffer_statistic(void)
{
rx_buff_stat_args.print =
arg_lit0("p", "print", "print the result of rx buffer statistic");
rx_buff_stat_args.clear =
arg_lit0("c", "clear", "clear the result of rx buffer statistic");
rx_buff_stat_args.end = arg_end(2);
const esp_console_cmd_t cmd = {
.command = "rxbufstat",
.help = "rx buffer statistic",
.hint = NULL,
.func = &process_rx_buffer_statistic,
.argtable = &rx_buff_stat_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC
#if CONFIG_IEEE802154_TXRX_STATISTIC
static struct {
struct arg_lit *clear;
struct arg_lit *print;
struct arg_end *end;
} txrx_stat_args;
static int process_txrx_statistic(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **) &txrx_stat_args);
if (nerrors != 0) {
arg_print_errors(stderr, txrx_stat_args.end, argv[0]);
return 1;
}
if (txrx_stat_args.print->count) {
esp_ieee802154_txrx_statistic_print();
}
if (txrx_stat_args.clear->count) {
esp_ieee802154_txrx_statistic_clear();
}
if (!txrx_stat_args.print->count && !txrx_stat_args.clear->count) {
ESP_LOGE(TAG, "no valid arguments");
return 1;
}
return 0;
}
static void register_txrx_statistic(void)
{
txrx_stat_args.print =
arg_lit0("p", "print", "print the result of txrx statistic");
txrx_stat_args.clear =
arg_lit0("c", "clear", "clear the result of txrx statistic");
txrx_stat_args.end = arg_end(2);
const esp_console_cmd_t cmd = {
.command = "txrxstat",
.help = "txrx statistic",
.hint = NULL,
.func = &process_txrx_statistic,
.argtable = &txrx_stat_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
#endif // CONFIG_IEEE802154_TXRX_STATISTIC
#if CONFIG_IEEE802154_RECORD
static struct {
struct arg_lit *print;
struct arg_end *end;
} record_args;
static int process_record(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **) &record_args);
if (nerrors != 0) {
arg_print_errors(stderr, record_args.end, argv[0]);
return 1;
}
if (record_args.print->count) {
esp_ieee802154_record_print();
} else {
ESP_LOGE(TAG, "no valid arguments");
return 1;
}
return 0;
}
static void register_record(void)
{
record_args.print =
arg_lit0("p", "print", "print the result of the recording");
record_args.end = arg_end(2);
const esp_console_cmd_t cmd = {
.command = "record",
.help = "print the recorded IEEE802154 state/event/cmd etc.",
.hint = NULL,
.func = &process_record,
.argtable = &record_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
#endif // CONFIG_IEEE802154_RECORD
#endif // CONFIG_IEEE802154_DEBUG
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#pragma once
#if CONFIG_IEEE802154_DEBUG
void register_ieee802154_debug_cmd(void);
#endif
@@ -6,5 +6,6 @@ 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}
PRIV_REQUIRES ieee802154 console fatfs nvs_flash esp_phy cmd_ieee802154 cmd_system
PRIV_REQUIRES ieee802154 console fatfs nvs_flash esp_phy cmd_ieee802154
cmd_ieee802154_stats cmd_system
WHOLE_ARCHIVE)
@@ -16,6 +16,7 @@
#include "esp_ieee802154.h"
#include "esp_phy_init.h"
#include "cmd_system.h"
#include "ieee802154_stats.h"
#define PROMPT_STR "ieee802154"
@@ -46,6 +47,9 @@ void app_main(void)
esp_console_register_help_command();
register_ieee802154_cmd();
register_system_common();
#if CONFIG_IEEE802154_DEBUG
register_ieee802154_debug_cmd();
#endif
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));