-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea0a006
commit f9bcc9d
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @file wrap_esp_err_to_name_r.h | ||
* @author TheSomeMan | ||
* @date 2023-04-09 | ||
* @copyright Ruuvi Innovations Ltd, license BSD-3-Clause. | ||
*/ | ||
|
||
#ifndef RUUVI_WRAP_ESP_ERR_TO_NAME_R_H | ||
#define RUUVI_WRAP_ESP_ERR_TO_NAME_R_H | ||
|
||
#include <esp_err.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
const char* | ||
wrap_esp_err_to_name_r(const esp_err_t code, char* const p_buf, const size_t buf_len); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RUUVI_WRAP_ESP_ERR_TO_NAME_R_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @file wrap_esp_err_to_name_r.c | ||
* @author TheSomeMan | ||
* @date 2023-04-09 | ||
* @copyright Ruuvi Innovations Ltd, license BSD-3-Clause. | ||
*/ | ||
|
||
#include "wrap_esp_err_to_name_r.h" | ||
#include <esp_err.h> | ||
#include "mbedtls/error.h" | ||
#include "esp_tls.h" | ||
|
||
const char* | ||
wrap_esp_err_to_name_r(const esp_err_t code, char* const p_buf, const size_t buf_len) | ||
{ | ||
static const char* g_esp_unknown_msg = NULL; | ||
if (NULL == g_esp_unknown_msg) | ||
{ | ||
const esp_err_t unknown_esp_err_code = 1; | ||
|
||
g_esp_unknown_msg = esp_err_to_name(unknown_esp_err_code); | ||
} | ||
const char* p_err_desc = esp_err_to_name(code); | ||
if (g_esp_unknown_msg != p_err_desc) | ||
{ | ||
(void)snprintf(p_buf, buf_len, "%s", p_err_desc); | ||
return p_buf; | ||
} | ||
|
||
if ((strerror_r(code, p_buf, buf_len) != NULL) && ('\0' != p_buf[0])) | ||
{ | ||
return p_buf; | ||
} | ||
|
||
mbedtls_strerror(code, p_buf, buf_len); | ||
|
||
const char* const p_unknown_error_code_prefix = "UNKNOWN ERROR CODE ("; | ||
if (0 == strncmp(p_unknown_error_code_prefix, p_buf, strlen(p_unknown_error_code_prefix))) | ||
{ | ||
(void)snprintf(p_buf, buf_len, "%s 0x%x(%d)", g_esp_unknown_msg, code, code); | ||
} | ||
|
||
return p_buf; | ||
} |