From d1129f3d19ac2d1755edc9a778cff8ac2ef2bc80 Mon Sep 17 00:00:00 2001 From: diplfranzhoepfinger <37779037+diplfranzhoepfinger@users.noreply.github.com> Date: Mon, 18 Jul 2022 17:08:15 +0200 Subject: [PATCH] esp_err_to_name (IDFGH-7793) (#78) fix(esp-modem): Use err_to_name to log error message on error --- .../esp_system_protocols_linux/CMakeLists.txt | 3 ++- .../esp_system_protocols_linux/esp_err_to_name.c | 14 ++++++++++++++ .../esp_system_protocols_linux/include/esp_err.h | 8 ++++++++ .../esp_modem/private_include/exception_stub.hpp | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 components/esp_modem/port/linux/esp_system_protocols_linux/esp_err_to_name.c diff --git a/components/esp_modem/port/linux/esp_system_protocols_linux/CMakeLists.txt b/components/esp_modem/port/linux/esp_system_protocols_linux/CMakeLists.txt index e4149f579..44a745e87 100644 --- a/components/esp_modem/port/linux/esp_system_protocols_linux/CMakeLists.txt +++ b/components/esp_modem/port/linux/esp_system_protocols_linux/CMakeLists.txt @@ -1,2 +1,3 @@ -idf_component_register(INCLUDE_DIRS include +idf_component_register(SRCS "esp_err_to_name.c" + INCLUDE_DIRS include REQUIRES esp_netif_linux esp_event_mock) diff --git a/components/esp_modem/port/linux/esp_system_protocols_linux/esp_err_to_name.c b/components/esp_modem/port/linux/esp_system_protocols_linux/esp_err_to_name.c new file mode 100644 index 000000000..ce5cb9ed3 --- /dev/null +++ b/components/esp_modem/port/linux/esp_system_protocols_linux/esp_err_to_name.c @@ -0,0 +1,14 @@ +/* + * SPDX-FileCopyrightText: Franz Hoepfinger + * + * SPDX-License-Identifier: Apache-2.0 + */ + + + +static const char esp_unknown_msg[] = "ERROR"; + +const char *esp_err_to_name(int code) +{ + return esp_unknown_msg; +} diff --git a/components/esp_modem/port/linux/esp_system_protocols_linux/include/esp_err.h b/components/esp_modem/port/linux/esp_system_protocols_linux/include/esp_err.h index b51321624..9a4363d23 100644 --- a/components/esp_modem/port/linux/esp_system_protocols_linux/include/esp_err.h +++ b/components/esp_modem/port/linux/esp_system_protocols_linux/include/esp_err.h @@ -25,3 +25,11 @@ typedef int esp_err_t; #define ESP_ERR_NOT_FOUND 0x105 #define ESP_ERR_NOT_SUPPORTED 0x106 #define ESP_ERR_TIMEOUT 0x107 + +#ifdef __cplusplus +extern "C" { +#endif +const char *esp_err_to_name(int code); +#ifdef __cplusplus +} +#endif diff --git a/components/esp_modem/private_include/exception_stub.hpp b/components/esp_modem/private_include/exception_stub.hpp index d3f1378d3..4f2700894 100644 --- a/components/esp_modem/private_include/exception_stub.hpp +++ b/components/esp_modem/private_include/exception_stub.hpp @@ -22,7 +22,7 @@ action; \ } catch (::esp_modem::esp_err_exception& e) { \ esp_err_t err = e.get_err_t(); \ - ESP_LOGE(TAG, "%s: Exception caught with ESP err_code=%d", __func__, err); \ + ESP_LOGE(TAG, "%s: Exception caught with ESP err_code=%d %s", __func__, err, esp_err_to_name(err)); \ ESP_LOGE(TAG, "%s", e.what()); \ action; \ }