Skip to content

Commit 5c01c3e

Browse files
authored
Merge pull request #5633 from paul-szczepanek-arm/master
BLE: added function converting error codes into strings
2 parents bea41d1 + 4ac75bd commit 5c01c3e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

features/FEATURE_BLE/ble/BLE.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,15 @@ class BLE
400400
*/
401401
const SecurityManager& securityManager() const;
402402

403+
/**
404+
* Translate error code into a printable string.
405+
*
406+
* @param[in] error Error code returned by BLE functions.
407+
*
408+
* @return A pointer to a const string describing the error.
409+
*/
410+
static const char* errorToString(ble_error_t error);
411+
403412
/*
404413
* Deprecation alert!
405414
* All of the following are deprecated and may be dropped in a future

features/FEATURE_BLE/source/BLE.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@
3131
#include <toolchain.h>
3232
#endif
3333

34+
static const char* error_strings[] = {
35+
"BLE_ERROR_NONE: No error",
36+
"BLE_ERROR_BUFFER_OVERFLOW: The requested action would cause a buffer overflow and has been aborted",
37+
"BLE_ERROR_NOT_IMPLEMENTED: Requested a feature that isn't yet implement or isn't supported by the target HW",
38+
"BLE_ERROR_PARAM_OUT_OF_RANGE: One of the supplied parameters is outside the valid range",
39+
"BLE_ERROR_INVALID_PARAM: One of the supplied parameters is invalid",
40+
"BLE_STACK_BUSY: The stack is busy",
41+
"BLE_ERROR_INVALID_STATE: Invalid state",
42+
"BLE_ERROR_NO_MEM: Out of Memory",
43+
"BLE_ERROR_OPERATION_NOT_PERMITTED: The operation requested is not permitted",
44+
"BLE_ERROR_INITIALIZATION_INCOMPLETE: The BLE subsystem has not completed its initialisation",
45+
"BLE_ERROR_ALREADY_INITIALIZED: The BLE system has already been initialised",
46+
"BLE_ERROR_UNSPECIFIED: Unknown error",
47+
"BLE_ERROR_INTERNAL_STACK_FAILURE: The platform-specific stack failed"
48+
};
49+
50+
const char* BLE::errorToString(ble_error_t error)
51+
{
52+
if (error > BLE_ERROR_INTERNAL_STACK_FAILURE) {
53+
return "Illegal error code";
54+
}
55+
return error_strings[error];
56+
}
57+
3458
ble_error_t
3559
BLE::initImplementation(FunctionPointerWithContext<InitializationCompleteCallbackContext*> callback)
3660
{

0 commit comments

Comments
 (0)