From 7bc14990c8c7a8215325fc8f68723b9d2c9bf68d Mon Sep 17 00:00:00 2001 From: Zhao Wei Liang Date: Wed, 17 Sep 2025 11:14:12 +0800 Subject: [PATCH] feat(ble): add console command to get dtm rx rssi in hci example (cherry picked from commit c58f07ed1e842f860693db934bc062848c9f7c28) Co-authored-by: zwl --- .../hci/main/dtm_configuration_command.c | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/examples/bluetooth/nimble/hci/main/dtm_configuration_command.c b/examples/bluetooth/nimble/hci/main/dtm_configuration_command.c index 80c2ab6105..e7ac664405 100644 --- a/examples/bluetooth/nimble/hci/main/dtm_configuration_command.c +++ b/examples/bluetooth/nimble/hci/main/dtm_configuration_command.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -67,6 +67,36 @@ static int dtm_reconfig_uart_pins_command(int argc, char **argv) return 0; } +extern int8_t esp_ble_get_dtm_rx_rssi(void); +static int dtm_get_ble_rx_rssi_command(int argc, char **argv) +{ + int8_t rx_rssi = 0x7F; + if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) { + esp_rom_printf("\nPlease enable BLE DTM mode first by using the command enable_ble_dtm -e 1 before sending this command.\n"); + return 2; + } + + rx_rssi = esp_ble_get_dtm_rx_rssi(); + if (rx_rssi == 0x7f) { + esp_rom_printf("\nRx RSSI is not available!\n"); + } else { + esp_rom_printf("\nRx RSSI is %d dBm\n", rx_rssi); + } + + return 0; +} + +esp_err_t esp_console_register_get_ble_rx_rssi_command(void) +{ + esp_console_cmd_t command = { + .command = "get_ble_rx_rssi", + .help = "Get ble rx rssi during DTM", + .func = &dtm_get_ble_rx_rssi_command, + }; + + return esp_console_cmd_register(&command); +} + esp_err_t esp_console_register_set_ble_tx_power_command(void) { dtm_set_tx_power_cmd_args.cmd_params = arg_int1("i", "index", "","tx power level index"); @@ -122,6 +152,7 @@ esp_err_t dtm_configuration_command_enable(void) esp_console_register_set_ble_tx_power_command(); esp_console_register_get_ble_tx_power_command(); esp_console_register_reconfig_dtm_pins_command(); + esp_console_register_get_ble_rx_rssi_command(); 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)); ESP_ERROR_CHECK(esp_console_start_repl(repl));