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-11 10:26:51 -07:00
committed by Jonathan Hui
parent cefea1a3c6
commit 7130798123
38 changed files with 1476 additions and 16 deletions
+2
View File
@@ -30,8 +30,10 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
ot_platform_headers =\
alarm.h \
diag.h \
misc.h \
logging.h \
platform.h \
radio.h \
random.h \
uart.h \
+5
View File
@@ -77,6 +77,11 @@ uint32_t otPlatAlarmGetNow(void);
*/
extern void otPlatAlarmFired(void);
/**
* Signal diagnostics module that the alarm has fired.
*/
extern void otPlatDiagAlarmFired(void);
/**
* @}
*
+79
View File
@@ -0,0 +1,79 @@
/*
* 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.
*/
/**
* @file
* @brief
* This file defines the platform diag interface.
*
*/
#ifndef DIAG_H_
#define DIAG_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup diag Diag
* @ingroup platform
*
* @brief
* This module includes the platform abstraction for diagnostics features.
*
* @{
*
*/
/**
* Process the platform specific diagnostics features.
*
* @param[in] argc The argument counter of diagnostics command line.
* @param[in] argv The argument vector of diagnostics command line.
* @param[out] aOutput The diagnostics execution result.
*/
void otPlatDiagProcess(int argc, char *argv[], char *aOutput);
/**
* Set diagnostics mode.
*/
void otPlatDiagModeSet(bool aMode);
/**
* Get diagnostics mode.
*/
bool otPlatDiagModeGet(void);
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif
+59
View File
@@ -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.
*/
/**
* @file
* @brief
* This file defines the platform-specific initializers.
*/
#ifndef PLATFORM_H_
#define PLATFORM_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* This function performs all platform-specific initialization.
*
*/
void PlatformInit(int argc, char *argv[]);
/**
* This function performs all platform-specific processing.
*
*/
void PlatformProcessDrivers(void);
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // PLATFORM_H_
+22
View File
@@ -298,6 +298,28 @@ bool otPlatRadioGetPromiscuous(void);
*/
void otPlatRadioSetPromiscuous(bool aEnable);
/**
* The radio driver calls this method to notify OpenThread diagnostics module that the transmission has completed.
*
* @param[in] aFramePending TRUE if an ACK frame was received and the Frame Pending bit was set.
* @param[in] aError ::kThreadError_None when the frame was transmitted, ::kThreadError_NoAck when the frame was
* transmitted but no ACK was received, ::kThreadError_ChannelAccessFailure when the transmission
* could not take place due to activity on the channel, ::kThreadError_Abort when transmission was
* aborted for other reasons.
*
*/
extern void otPlatDiagRadioTransmitDone(bool aFramePending, ThreadError aError);
/**
* The radio driver calls this method to notify OpenThread diagnostics module of a received packet.
*
* @param[in] aPacket A pointer to the received packet or NULL if the receive operation was aborted.
* @param[in] aError ::kThreadError_None when successfully received a frame, ::kThreadError_Abort when reception
* was aborted and a frame was not received.
*
*/
extern void otPlatDiagRadioReceiveDone(RadioPacket *aPacket, ThreadError aError);
/**
* @}
*