Add diagnostics module in OpenThread (#343)

* Add diagnostics module in OpenThread

  - provide the same diagnostics interface for both CLI and NCP usage
  - implement common diagnostics features based on existing platform interface defined in 'include/platform/'
  - other more platform specific diagnostics features will be processed under platform layer
  - update CLI interface to support diagnostics feature
  - update both Posix and CC2538 platform to support diagnostics feature

* Add diagnostics module unit test

   - move platform.h from "examples/platform" to "include/platform"
   - add test_diag.cpp to test diagnostics module

* Add a configuration option that would enable/disable diagnostics module

Add --enable-diag configuration option to enable/disable diagnostics module when building OpenThread.
This commit is contained in:
Shu Chen
2016-08-12 01:26:51 +08:00
committed by Jonathan Hui
parent cefea1a3c6
commit 7130798123
38 changed files with 1476 additions and 16 deletions
+17 -1
View File
@@ -36,7 +36,7 @@
#include <string.h>
#include <openthread.h>
#include <openthread-config.h>
#include <openthread-diag.h>
#include "cli.hpp"
#include "cli_dataset.hpp"
@@ -86,6 +86,9 @@ const struct Command Interpreter::sCommands[] =
{ "thread", &ProcessThread },
{ "version", &ProcessVersion },
{ "whitelist", &ProcessWhitelist },
#if OPENTHREAD_ENABLE_DIAG
{ "diag", &ProcessDiag },
#endif
};
otNetifAddress Interpreter::sAddress;
@@ -1477,6 +1480,14 @@ exit:
AppendResult(error);
}
#if OPENTHREAD_ENABLE_DIAG
void Interpreter::ProcessDiag(int argc, char *argv[])
{
// all diagnostics related features are processed within diagnostics module
sServer->OutputFormat("%s\r\n", diagProcessCmd(argc, argv));
}
#endif
void Interpreter::ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer)
{
char *argv[kMaxArgs];
@@ -1504,6 +1515,11 @@ void Interpreter::ProcessLine(char *aBuf, uint16_t aBufLength, Server &aServer)
cmd = aBuf;
#if OPENTHREAD_ENABLE_DIAG
VerifyOrExit((!isDiagEnabled() || (strcmp(cmd, "diag") == 0)),
sServer->OutputFormat("under diagnostics mode, execute 'diag stop' before running any other commands.\r\n"));
#endif
for (unsigned int i = 0; i < sizeof(sCommands) / sizeof(sCommands[0]); i++)
{
if (strcmp(cmd, sCommands[i].mName) == 0)