mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 14:17:47 +00:00
[diag] use OT_ARRAY_LENGTH to unify code and shrink image size (#3677)
This commit is contained in:
committed by
Jonathan Hui
parent
6dc3b28b3f
commit
c02a985609
@@ -380,9 +380,9 @@ const struct PlatformDiagCommand sCommands[] = {
|
||||
|
||||
void otPlatDiagProcess(otInstance *aInstance, int argc, char *argv[], char *aOutput, size_t aOutputMaxLen)
|
||||
{
|
||||
uint32_t i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof(sCommands) / sizeof(sCommands[0]); i++)
|
||||
for (i = 0; i < otARRAY_LENGTH(sCommands); i++)
|
||||
{
|
||||
if (strcmp(argv[0], sCommands[i].mName) == 0)
|
||||
{
|
||||
@@ -391,7 +391,7 @@ void otPlatDiagProcess(otInstance *aInstance, int argc, char *argv[], char *aOut
|
||||
}
|
||||
}
|
||||
|
||||
if (i == sizeof(sCommands) / sizeof(sCommands[0]))
|
||||
if (i == otARRAY_LENGTH(sCommands))
|
||||
{
|
||||
snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", argv[0]);
|
||||
}
|
||||
|
||||
@@ -380,9 +380,9 @@ const struct PlatformDiagCommand sCommands[] = {
|
||||
|
||||
void otPlatDiagProcess(otInstance *aInstance, int argc, char *argv[], char *aOutput, size_t aOutputMaxLen)
|
||||
{
|
||||
uint32_t i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof(sCommands) / sizeof(sCommands[0]); i++)
|
||||
for (i = 0; i < otARRAY_LENGTH(sCommands); i++)
|
||||
{
|
||||
if (strcmp(argv[0], sCommands[i].mName) == 0)
|
||||
{
|
||||
@@ -391,7 +391,7 @@ void otPlatDiagProcess(otInstance *aInstance, int argc, char *argv[], char *aOut
|
||||
}
|
||||
}
|
||||
|
||||
if (i == sizeof(sCommands) / sizeof(sCommands[0]))
|
||||
if (i == otARRAY_LENGTH(sCommands))
|
||||
{
|
||||
snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", argv[0]);
|
||||
}
|
||||
|
||||
@@ -71,4 +71,14 @@
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* This macro calculates the number of elements in an array.
|
||||
*
|
||||
* @param[in] aArray Name of the array variable.
|
||||
*
|
||||
* @returns Number of elements in the array.
|
||||
*
|
||||
*/
|
||||
#define otARRAY_LENGTH(aArray) (sizeof(aArray) / sizeof(aArray[0]))
|
||||
|
||||
#endif // CODE_UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user