mirror of
https://github.com/espressif/openthread.git
synced 2026-09-04 16:20:05 +00:00
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:
@@ -45,10 +45,6 @@ if OPENTHREAD_EXAMPLES_CC2538
|
||||
SUBDIRS = cc2538
|
||||
endif
|
||||
|
||||
noinst_HEADERS = \
|
||||
platform.h \
|
||||
$(NULL)
|
||||
|
||||
# Always pretty (e.g. for 'make pretty') these subdirectories.
|
||||
|
||||
PRETTY_SUBDIRS = \
|
||||
|
||||
@@ -46,6 +46,12 @@ libopenthread_cc2538_a_SOURCES = \
|
||||
startup-gcc.c \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_DIAG
|
||||
libopenthread_cc2538_a_SOURCES += \
|
||||
diag.c \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
noinst_HEADERS = \
|
||||
cc2538-reg.h \
|
||||
platform-cc2538.h \
|
||||
|
||||
@@ -35,7 +35,9 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <openthread-config.h>
|
||||
#include <platform/alarm.h>
|
||||
#include <platform/diag.h>
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
enum
|
||||
@@ -99,7 +101,18 @@ void cc2538AlarmProcess(void)
|
||||
if (fire)
|
||||
{
|
||||
sIsRunning = false;
|
||||
otPlatAlarmFired();
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagAlarmFired();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatAlarmFired();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <platform/alarm.h>
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
/**
|
||||
* diagnostics mode flag.
|
||||
*
|
||||
*/
|
||||
static bool sDiagMode = false;
|
||||
|
||||
void otPlatDiagProcess(int argc, char *argv[], char *aOutput)
|
||||
{
|
||||
// add more plarform specific diagnostics features here
|
||||
|
||||
sprintf(aOutput, "diag feature '%s' is not supported\r\n", argv[0]);
|
||||
(void)argc;
|
||||
}
|
||||
|
||||
void otPlatDiagModeSet(bool aMode)
|
||||
{
|
||||
sDiagMode = aMode;
|
||||
}
|
||||
|
||||
bool otPlatDiagModeGet()
|
||||
{
|
||||
return sDiagMode;
|
||||
}
|
||||
@@ -33,9 +33,11 @@
|
||||
*/
|
||||
|
||||
#include <openthread-types.h>
|
||||
#include <openthread-config.h>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/radio.h>
|
||||
#include <platform/diag.h>
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
enum
|
||||
@@ -371,7 +373,17 @@ void cc2538RadioProcess(void)
|
||||
|
||||
if ((sState == kStateReceive) && (sReceiveFrame.mLength > 0))
|
||||
{
|
||||
otPlatRadioReceiveDone(&sReceiveFrame, sReceiveError);
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioReceiveDone(&sReceiveFrame, sReceiveError);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioReceiveDone(&sReceiveFrame, sReceiveError);
|
||||
}
|
||||
}
|
||||
|
||||
if (sState == kStateTransmit)
|
||||
@@ -379,14 +391,36 @@ void cc2538RadioProcess(void)
|
||||
if (sTransmitError != kThreadError_None || (sTransmitFrame.mPsdu[0] & IEEE802154_ACK_REQUEST) == 0)
|
||||
{
|
||||
sState = kStateReceive;
|
||||
otPlatRadioTransmitDone(false, sTransmitError);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone(false, sTransmitError);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioTransmitDone(false, sTransmitError);
|
||||
}
|
||||
}
|
||||
else if (sReceiveFrame.mLength == IEEE802154_ACK_LENGTH &&
|
||||
(sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_TYPE_MASK) == IEEE802154_FRAME_TYPE_ACK &&
|
||||
(sReceiveFrame.mPsdu[IEEE802154_DSN_OFFSET] == sTransmitFrame.mPsdu[IEEE802154_DSN_OFFSET]))
|
||||
{
|
||||
sState = kStateReceive;
|
||||
otPlatRadioTransmitDone((sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone((sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioTransmitDone((sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,12 @@ libopenthread_posix_a_SOURCES = \
|
||||
uart.c \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_DIAG
|
||||
libopenthread_posix_a_SOURCES += \
|
||||
diag.c \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
if OPENTHREAD_ENABLE_NCP_SPI
|
||||
libopenthread_posix_a_SOURCES += \
|
||||
spi-stubs.c \
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <openthread-config.h>
|
||||
#include <platform/alarm.h>
|
||||
#include <platform/diag.h>
|
||||
#include "platform-posix.h"
|
||||
|
||||
static bool s_is_running = false;
|
||||
@@ -106,7 +108,18 @@ void posixAlarmProcess(void)
|
||||
if (remaining <= 0)
|
||||
{
|
||||
s_is_running = false;
|
||||
otPlatAlarmFired();
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagAlarmFired();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatAlarmFired();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,25 +26,33 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file includes the posix platform-specific initializers.
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifndef PLATFORM_H_
|
||||
#define PLATFORM_H_
|
||||
#include <platform/alarm.h>
|
||||
#include "platform-posix.h"
|
||||
|
||||
/**
|
||||
* This function performs all platform-specific initialization.
|
||||
* diagnostics mode flag.
|
||||
*
|
||||
*/
|
||||
void PlatformInit(int argc, char *argv[]);
|
||||
static bool sDiagMode = false;
|
||||
|
||||
/**
|
||||
* This function performs all platform-specific processing.
|
||||
*
|
||||
*/
|
||||
void PlatformProcessDrivers(void);
|
||||
void otPlatDiagProcess(int argc, char *argv[], char *aOutput)
|
||||
{
|
||||
// no more diagnostics features for Posix platform
|
||||
sprintf(aOutput, "diag feature '%s' is not supported\r\n", argv[0]);
|
||||
(void)argc;
|
||||
}
|
||||
|
||||
#endif // PLATFORM_H_
|
||||
void otPlatDiagModeSet(bool aMode)
|
||||
{
|
||||
sDiagMode = aMode;
|
||||
}
|
||||
|
||||
bool otPlatDiagModeGet()
|
||||
{
|
||||
return sDiagMode;
|
||||
}
|
||||
@@ -39,7 +39,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <openthread-config.h>
|
||||
#include <platform/radio.h>
|
||||
#include <platform/diag.h>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include "platform-posix.h"
|
||||
@@ -456,7 +458,18 @@ void radioReceive(void)
|
||||
{
|
||||
sState = kStateReceive;
|
||||
sAckWait = false;
|
||||
otPlatRadioTransmitDone(isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone(isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioTransmitDone(isFramePending(sReceiveFrame.mPsdu), kThreadError_None);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sState == kStateReceive &&
|
||||
@@ -478,7 +491,18 @@ void radioSendMessage(void)
|
||||
if (!sAckWait)
|
||||
{
|
||||
sState = kStateReceive;
|
||||
otPlatRadioTransmitDone(false, kThreadError_None);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone(false, kThreadError_None);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioTransmitDone(false, kThreadError_None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -609,5 +633,16 @@ void radioProcessFrame(void)
|
||||
|
||||
exit:
|
||||
|
||||
otPlatRadioReceiveDone(error == kThreadError_None ? &sReceiveFrame : NULL, error);
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioReceiveDone(error == kThreadError_None ? &sReceiveFrame : NULL, error);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatRadioReceiveDone(error == kThreadError_None ? &sReceiveFrame : NULL, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user