[diag] add diag output callback (#10354)

The length of diag output messages is limited by the diag buffer size.
Developers have to change the diag buffer size to allow diag module to
output long messages. If diag output messages become longer and
longer, developers have to keep changing the diag buffer size.

This commit adds an output callback to diag module to output diag
messages.  Then the length of diag output messages won't be limited by
the diag buffer size.
This commit is contained in:
Zhanglong Xia
2024-06-19 20:27:35 -07:00
committed by GitHub
parent 31e512ac7b
commit 215c23f2a6
21 changed files with 505 additions and 269 deletions
+26 -2
View File
@@ -99,6 +99,9 @@ void testFreeInstance(otInstance *aInstance)
bool sDiagMode = false;
static otPlatDiagOutputCallback sOutputCallback = nullptr;
static void *sOutputCallbackContext = nullptr;
extern "C" {
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
@@ -225,9 +228,30 @@ exit:
return error;
}
OT_TOOL_WEAK void otPlatDiagProcess(otInstance *, uint8_t, char *aArgs[], char *aOutput, size_t aOutputMaxLen)
static void DiagOutput(const char *aFormat, ...)
{
snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", aArgs[0]);
va_list args;
va_start(args, aFormat);
if (sOutputCallback != nullptr)
{
sOutputCallback(aFormat, args, sOutputCallbackContext);
}
va_end(args);
}
OT_TOOL_WEAK void otPlatDiagSetOutputCallback(otInstance *aInstance, otPlatDiagOutputCallback aCallback, void *aContext)
{
sOutputCallback = aCallback;
sOutputCallbackContext = aContext;
}
OT_TOOL_WEAK otError otPlatDiagProcess(otInstance *, uint8_t, char *aArgs[])
{
DiagOutput("diag feature '%s' is not supported\r\n", aArgs[0]);
return OT_ERROR_NONE;
}
OT_TOOL_WEAK void otPlatDiagModeSet(bool aMode) { sDiagMode = aMode; }