diff --git a/src/Makefile.am b/src/Makefile.am index d2e32e2c8..7d60d7e9d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,6 +65,7 @@ endif PRETTY_SUBDIRS = \ cli \ core \ + diag \ ncp \ posix \ $(NULL) diff --git a/src/diag/diag_process.cpp b/src/diag/diag_process.cpp index 4fe5af068..5ca2893f7 100644 --- a/src/diag/diag_process.cpp +++ b/src/diag/diag_process.cpp @@ -44,39 +44,33 @@ namespace ot { namespace Diagnostics { -const struct Diag::Command Diag::sCommands[] = -{ - { "start", &ProcessStart }, - { "stop", &ProcessStop }, - { "channel", &ProcessChannel }, - { "power", &ProcessPower }, - { "send", &ProcessSend }, - { "repeat", &ProcessRepeat }, - { "stats", &ProcessStats }, - { NULL, NULL }, +const struct Diag::Command Diag::sCommands[] = { + {"start", &ProcessStart}, {"stop", &ProcessStop}, {"channel", &ProcessChannel}, {"power", &ProcessPower}, + {"send", &ProcessSend}, {"repeat", &ProcessRepeat}, {"stats", &ProcessStats}, {NULL, NULL}, }; struct Diag::DiagStats Diag::sStats; -int8_t Diag::sTxPower; -uint8_t Diag::sChannel; -uint8_t Diag::sTxLen; -uint32_t Diag::sTxPeriod; -uint32_t Diag::sTxPackets; -otRadioFrame * Diag::sTxPacket; -bool Diag::sRepeatActive; -otInstance *Diag::sInstance; +int8_t Diag::sTxPower; +uint8_t Diag::sChannel; +uint8_t Diag::sTxLen; +uint32_t Diag::sTxPeriod; +uint32_t Diag::sTxPackets; +otRadioFrame *Diag::sTxPacket; +bool Diag::sRepeatActive; +otInstance * Diag::sInstance; void Diag::Init(otInstance *aInstance) { - sInstance = aInstance; - sChannel = 20; - sTxPower = 0; - sTxPeriod = 0; - sTxLen = 0; - sTxPackets = 0; + sInstance = aInstance; + sChannel = 20; + sTxPower = 0; + sTxPeriod = 0; + sTxLen = 0; + sTxPackets = 0; sRepeatActive = false; memset(&sStats, 0, sizeof(struct DiagStats)); + sTxPacket = otPlatRadioGetTransmitBuffer(sInstance); otPlatDiagChannelSet(sChannel); otPlatDiagTxPowerSet(sTxPower); @@ -170,7 +164,7 @@ otError Diag::ParseLong(char *aArgVector, long &aValue) void Diag::TxPacket(void) { - sTxPacket->mLength = sTxLen; + sTxPacket->mLength = sTxLen; sTxPacket->mChannel = sChannel; for (uint8_t i = 0; i < sTxLen; i++) @@ -185,7 +179,6 @@ void Diag::ProcessChannel(int aArgCount, char *aArgVector[], char *aOutput, size { otError error = OT_ERROR_NONE; - VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE); if (aArgCount == 0) @@ -239,7 +232,7 @@ exit: void Diag::ProcessSend(int aArgCount, char *aArgVector[], char *aOutput, size_t aOutputMaxLen) { otError error = OT_ERROR_NONE; - long value; + long value; VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE); VerifyOrExit(aArgCount == 2, error = OT_ERROR_INVALID_ARGS); @@ -286,7 +279,7 @@ void Diag::ProcessRepeat(int aArgCount, char *aArgVector[], char *aOutput, size_ sTxLen = static_cast(value); sRepeatActive = true; - uint32_t now = otPlatAlarmMilliGetNow(); + uint32_t now = otPlatAlarmMilliGetNow(); otPlatAlarmMilliStartAt(sInstance, now, sTxPeriod); snprintf(aOutput, aOutputMaxLen, "sending packets of length %#x at the delay of %#x ms\r\nstatus 0x%02x\r\n", static_cast(sTxLen), static_cast(sTxPeriod), error); @@ -307,8 +300,8 @@ void Diag::ProcessStats(int aArgCount, char *aArgVector[], char *aOutput, size_t snprintf(aOutput, aOutputMaxLen, "received packets: %d\r\nsent packets: %d\r\nfirst received packet: rssi=%d, lqi=%d\r\n", - static_cast(sStats.mReceivedPackets), static_cast(sStats.mSentPackets), - static_cast(sStats.mFirstRssi), static_cast(sStats.mFirstLqi)); + static_cast(sStats.mReceivedPackets), static_cast(sStats.mSentPackets), + static_cast(sStats.mFirstRssi), static_cast(sStats.mFirstLqi)); exit: AppendErrorResult(error, aOutput, aOutputMaxLen); @@ -347,7 +340,7 @@ void Diag::DiagReceiveDone(otInstance *aInstance, otRadioFrame *aFrame, otError if (sStats.mReceivedPackets == 0) { sStats.mFirstRssi = aFrame->mInfo.mRxInfo.mRssi; - sStats.mFirstLqi = aFrame->mInfo.mRxInfo.mLqi; + sStats.mFirstLqi = aFrame->mInfo.mRxInfo.mLqi; } sStats.mReceivedPackets++; @@ -362,7 +355,7 @@ void Diag::AlarmFired(otInstance *aInstance) { VerifyOrExit(aInstance == sInstance); - if(sRepeatActive) + if (sRepeatActive) { uint32_t now = otPlatAlarmMilliGetNow(); @@ -395,5 +388,5 @@ extern "C" void otPlatDiagRadioReceiveDone(otInstance *aInstance, otRadioFrame * Diag::DiagReceiveDone(aInstance, aFrame, aError); } -} // namespace Diagnostics -} // namespace ot +} // namespace Diagnostics +} // namespace ot diff --git a/src/diag/diag_process.hpp b/src/diag/diag_process.hpp index 8f44bd1dd..bca053f77 100644 --- a/src/diag/diag_process.hpp +++ b/src/diag/diag_process.hpp @@ -81,21 +81,23 @@ private: static void ProcessChannel(int aArgCount, char *aArgVector[], char *aOutput, size_t aOutputMaxLen); static void ProcessPower(int aArgCount, char *aArgVector[], char *aOutput, size_t aOutputMaxLen); static void TxPacket(void); + static otError ParseLong(char *aString, long &aLong); static const struct Command sCommands[]; - static struct DiagStats sStats; - static int8_t sTxPower; - static uint8_t sChannel; - static uint8_t sTxLen; - static uint32_t sTxPeriod; - static uint32_t sTxPackets; + static struct DiagStats sStats; + + static int8_t sTxPower; + static uint8_t sChannel; + static uint8_t sTxLen; + static uint32_t sTxPeriod; + static uint32_t sTxPackets; static otRadioFrame *sTxPacket; - static otInstance *sInstance; - static bool sRepeatActive; + static otInstance * sInstance; + static bool sRepeatActive; }; -} // namespace Diagnostics -} // namespace ot +} // namespace Diagnostics +} // namespace ot -#endif // CLI_HPP_ +#endif // CLI_HPP_ diff --git a/src/diag/openthread-diag.cpp b/src/diag/openthread-diag.cpp index 762054731..d4f973d84 100644 --- a/src/diag/openthread-diag.cpp +++ b/src/diag/openthread-diag.cpp @@ -59,13 +59,13 @@ void otDiagProcessCmdLine(const char *aInput, char *aOutput, size_t aOutputMaxLe { enum { - kMaxArgs = OPENTHREAD_CONFIG_DIAG_CMD_LINE_ARGS_MAX, + kMaxArgs = OPENTHREAD_CONFIG_DIAG_CMD_LINE_ARGS_MAX, kMaxCommandBuffer = OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE, }; otError error = OT_ERROR_NONE; - char buffer[kMaxCommandBuffer]; - char *argVector[kMaxArgs]; + char buffer[kMaxCommandBuffer]; + char * argVector[kMaxArgs]; uint8_t argCount = 0; VerifyOrExit(strnlen(aInput, kMaxCommandBuffer) < kMaxCommandBuffer, error = OT_ERROR_NO_BUFS);