[clang-format] add diags to make pretty (#3252)

This commit is contained in:
Zhanglong Xia
2018-11-01 21:37:46 -07:00
committed by Jonathan Hui
parent 2aed617140
commit e2abb405c2
4 changed files with 44 additions and 48 deletions
+1
View File
@@ -65,6 +65,7 @@ endif
PRETTY_SUBDIRS = \
cli \
core \
diag \
ncp \
posix \
$(NULL)
+27 -34
View File
@@ -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<uint8_t>(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<int>(sTxLen), static_cast<int>(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<int>(sStats.mReceivedPackets), static_cast<int>(sStats.mSentPackets),
static_cast<int>(sStats.mFirstRssi), static_cast<int>(sStats.mFirstLqi));
static_cast<int>(sStats.mReceivedPackets), static_cast<int>(sStats.mSentPackets),
static_cast<int>(sStats.mFirstRssi), static_cast<int>(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
+13 -11
View File
@@ -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_
+3 -3
View File
@@ -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);