mirror of
https://github.com/espressif/openthread.git
synced 2026-10-05 07:17:39 +00:00
ncp-spinel: Add STREAM_MFG property for diagnostics module (#403)
It's a generic stream property which doesn't take care of the diagnostics feature details - get diags commands from the property with VALUE_SET command - return diags output to the property with VALUE_IS command
This commit is contained in:
@@ -43,6 +43,8 @@ void diagInit();
|
||||
|
||||
char *diagProcessCmd(int argc, char *argv[]);
|
||||
|
||||
char *diagProcessCmdLine(char *string);
|
||||
|
||||
bool isDiagEnabled();
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -354,6 +354,8 @@ void Diag::DiagReceiveDone(RadioPacket *aFrame, ThreadError aError)
|
||||
|
||||
sStats.received_packets++;
|
||||
}
|
||||
|
||||
otPlatRadioReceive(sChannel);
|
||||
}
|
||||
|
||||
void Diag::AlarmFired()
|
||||
|
||||
@@ -56,6 +56,31 @@ char *diagProcessCmd(int argc, char *argv[])
|
||||
return Diag::ProcessCmd(argc, argv);
|
||||
}
|
||||
|
||||
char *diagProcessCmdLine(char *string)
|
||||
{
|
||||
char *argv[8];
|
||||
int argc = 0;
|
||||
int length = static_cast<int>(strlen(string));
|
||||
char *cmd;
|
||||
|
||||
for (; *string == ' '; string++, length--);
|
||||
|
||||
for (cmd = string + 1; (cmd < string + length) && (cmd != NULL); ++cmd)
|
||||
{
|
||||
if (*cmd == ' ' || *cmd == '\r' || *cmd == '\n')
|
||||
{
|
||||
*cmd = '\0';
|
||||
}
|
||||
|
||||
if (*(cmd - 1) == '\0' && *cmd != ' ')
|
||||
{
|
||||
argv[argc++] = cmd;
|
||||
}
|
||||
}
|
||||
|
||||
return Diag::ProcessCmd(argc, argv);
|
||||
}
|
||||
|
||||
bool isDiagEnabled()
|
||||
{
|
||||
return Diag::isEnabled();
|
||||
|
||||
+40
-1
@@ -36,7 +36,7 @@
|
||||
#include <ncp/ncp.h>
|
||||
#include <ncp/ncp_base.hpp>
|
||||
#include <openthread.h>
|
||||
#include <openthread-config.h>
|
||||
#include <openthread-diag.h>
|
||||
#include <stdarg.h>
|
||||
#include <platform/radio.h>
|
||||
#include <platform/misc.h>
|
||||
@@ -217,6 +217,9 @@ const NcpBase::SetPropertyHandlerEntry NcpBase::mSetPropertyHandlerTable[] =
|
||||
{ SPINEL_PROP_THREAD_ROUTER_UPGRADE_THRESHOLD, &NcpBase::SetPropertyHandler_THREAD_ROUTER_UPGRADE_THRESHOLD },
|
||||
{ SPINEL_PROP_THREAD_CONTEXT_REUSE_DELAY, &NcpBase::SetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY },
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
{ SPINEL_PROP_NEST_STREAM_MFG, &NcpBase::SetPropertyHandler_NEST_STREAM_MFG },
|
||||
#endif
|
||||
};
|
||||
|
||||
const NcpBase::InsertPropertyHandlerEntry NcpBase::mInsertPropertyHandlerTable[] =
|
||||
@@ -3342,6 +3345,42 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT(uint8_t header
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
ThreadError NcpBase::SetPropertyHandler_NEST_STREAM_MFG(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len)
|
||||
{
|
||||
char *string(NULL);
|
||||
char *output(NULL);
|
||||
spinel_ssize_t parsedLength;
|
||||
ThreadError errorCode = kThreadError_None;
|
||||
|
||||
parsedLength = spinel_datatype_unpack(
|
||||
value_ptr,
|
||||
value_len,
|
||||
SPINEL_DATATYPE_UTF8_S,
|
||||
&string
|
||||
);
|
||||
|
||||
if ((parsedLength > 0) && (string != NULL))
|
||||
{
|
||||
// all diagnostics related features are processed within diagnostics module
|
||||
output = diagProcessCmdLine(string);
|
||||
|
||||
errorCode = SendPropertyUpdate(
|
||||
header,
|
||||
SPINEL_CMD_PROP_VALUE_IS,
|
||||
key,
|
||||
reinterpret_cast<uint8_t *>(output),
|
||||
static_cast<uint16_t>(strlen(output) + 1)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorCode = SendLastStatus(header, SPINEL_STATUS_PARSE_ERROR);
|
||||
}
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// MARK: Individual Property Inserters
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#define NCP_BASE_HPP_
|
||||
|
||||
#include <openthread-types.h>
|
||||
#include <openthread-config.h>
|
||||
#include <common/message.hpp>
|
||||
#include <thread/thread_netif.hpp>
|
||||
|
||||
@@ -361,6 +362,11 @@ private:
|
||||
ThreadError SetPropertyHandler_CNTR_RESET(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr,
|
||||
uint16_t value_len);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
ThreadError SetPropertyHandler_NEST_STREAM_MFG(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr,
|
||||
uint16_t value_len);
|
||||
#endif
|
||||
|
||||
ThreadError InsertPropertyHandler_IPV6_ADDRESS_TABLE(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr,
|
||||
uint16_t value_len);
|
||||
ThreadError InsertPropertyHandler_THREAD_LOCAL_ROUTES(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr,
|
||||
|
||||
@@ -1130,6 +1130,10 @@ spinel_prop_key_to_cstr(spinel_prop_key_t prop_key)
|
||||
ret = "PROP_THREAD_CONTEXT_REUSE_DELAY";
|
||||
break;
|
||||
|
||||
case SPINEL_PROP_NEST_STREAM_MFG:
|
||||
ret = "SPINEL_PROP_NEST_STREAM_MFG";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -639,6 +639,7 @@ typedef enum
|
||||
SPINEL_PROP_CNTR__END = 2048,
|
||||
|
||||
SPINEL_PROP_NEST__BEGIN = 15296,
|
||||
SPINEL_PROP_NEST_STREAM_MFG = SPINEL_PROP_NEST__BEGIN + 0,
|
||||
SPINEL_PROP_NEST__END = 15360,
|
||||
|
||||
SPINEL_PROP_VENDOR__BEGIN = 15360,
|
||||
|
||||
@@ -155,28 +155,11 @@ void TestDiag()
|
||||
for (unsigned int i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
|
||||
{
|
||||
char string[50];
|
||||
int length = strlen(tests[i].command);
|
||||
char *cmd;
|
||||
char *output = NULL;
|
||||
|
||||
argc = 0;
|
||||
memcpy(string, tests[i].command, strlen(tests[i].command) + 1);
|
||||
|
||||
memcpy(string, tests[i].command, length + 1);
|
||||
|
||||
for (cmd = string + 1; (cmd < string + length) && (cmd != NULL); ++cmd)
|
||||
{
|
||||
if (*cmd == ' ' || *cmd == '\r' || *cmd == '\n')
|
||||
{
|
||||
*cmd = '\0';
|
||||
}
|
||||
|
||||
if (*(cmd - 1) == '\0' && *cmd != ' ')
|
||||
{
|
||||
argv[argc++] = cmd;
|
||||
}
|
||||
}
|
||||
|
||||
output = diagProcessCmd(argc, argv);
|
||||
output = diagProcessCmdLine(string);
|
||||
VerifyOrQuit(memcmp(output, tests[i].output, strlen(tests[i].output)) == 0,
|
||||
"Test Diagnostics module failed\r\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user