Skip to content

Commit

Permalink
[diag] remove redundant messages output by the diag module (openthrea…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglongxia authored Jan 7, 2025
1 parent b6a7f07 commit 3470934
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 119 deletions.
32 changes: 10 additions & 22 deletions src/core/diags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Start diagnostics mode.

```bash
> diag start
start diagnostics mode
Done
```

Expand All @@ -47,7 +46,7 @@ Get the IEEE 802.15.4 Channel value for diagnostics module.

```bash
> diag channel
channel: 11
11
Done
```

Expand All @@ -57,7 +56,6 @@ Set the IEEE 802.15.4 Channel value for diagnostics module.

```bash
> diag channel 11
set channel to 11
Done
```

Expand Down Expand Up @@ -123,7 +121,7 @@ Get the tx power value(dBm) for diagnostics module.

```bash
> diag power
tx power: -10 dBm
-10
Done
```

Expand All @@ -133,7 +131,6 @@ Set the tx power value(dBm) for diagnostics module.

```bash
> diag power -10
set tx power to -10 dBm
Done
```

Expand Down Expand Up @@ -170,23 +167,27 @@ Done

Transmit a fixed number of packets.

Send the frame set by `diag frame` if length is omitted. Otherwise overwrite the frame set by `diag frame` and send a frame of the given length(MUST be in range [3, 127]).
- packets: The number of packets to be sent.
- length: The length of packet. The valid range is [3, 127].

Send the frame set by `diag frame` if length is omitted. Otherwise overwrite the frame set by `diag frame` and send a frame of the given length.

```bash
> diag send 20 100
sending 0x14 packet(s), length 0x64
Done
```

### diag repeat \<delay\> [length]

Transmit packets repeatedly with a fixed interval.

Send the frame set by `diag frame` if length is omitted. Otherwise overwrite the frame set by `diag frame` and send a frame of the given length (MUST be in range [3, 127]).
- delay: The interval between two consecutive packets in milliseconds.
- length: The length of packet. The valid range is [3, 127].

Send the frame set by `diag frame` if length is omitted. Otherwise overwrite the frame set by `diag frame` and send a frame of the given length.

```bash
> diag repeat 100 100
sending packets of length 0x64 at the delay of 0x64 ms
Done
```

Expand All @@ -196,7 +197,6 @@ Stop repeated packet transmission.

```bash
> diag repeat stop
repeated packet transmission is stopped
Done
```

Expand All @@ -206,7 +206,6 @@ Enter radio sleep mode.

```bash
> diag radio sleep
set radio from receive to sleep
Done
```

Expand All @@ -216,7 +215,6 @@ Set radio from sleep mode to receive mode.

```bash
> diag radio receive
set radio from sleep to receive on channel 11
Done
```

Expand Down Expand Up @@ -360,7 +358,6 @@ Clear statistics during diagnostics mode.

```bash
> diag stats clear
stats cleared
Done
```

Expand Down Expand Up @@ -419,15 +416,6 @@ Stop diagnostics mode and print statistics.

```bash
> diag stop
received packets: 10
sent success packets: 10
sent error cca packets: 0
sent error abort packets: 0
sent error others packets: 0
first received packet: rssi=-65, lqi=101
last received packet: rssi=-61, lqi=98

stop diagnostics mode
Done
```

Expand Down
29 changes: 2 additions & 27 deletions src/core/diags/factory_diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Error Diags::ProcessChannel(uint8_t aArgsLength, char *aArgs[])

if (aArgsLength == 0)
{
Output("channel: %d\r\n", mChannel);
Output("%u\r\n", mChannel);
}
else
{
Expand All @@ -344,8 +344,6 @@ Error Diags::ProcessChannel(uint8_t aArgsLength, char *aArgs[])
mChannel = channel;
IgnoreError(Get<Radio>().Receive(mChannel));
otPlatDiagChannelSet(mChannel);

Output("set channel to %d\r\n", mChannel);
}

exit:
Expand All @@ -358,7 +356,7 @@ Error Diags::ProcessPower(uint8_t aArgsLength, char *aArgs[])

if (aArgsLength == 0)
{
Output("tx power: %d dBm\r\n", mTxPower);
Output("%d\r\n", mTxPower);
}
else
{
Expand All @@ -369,8 +367,6 @@ Error Diags::ProcessPower(uint8_t aArgsLength, char *aArgs[])
mTxPower = txPower;
SuccessOrExit(error = Get<Radio>().SetTransmitPower(mTxPower));
otPlatDiagTxPowerSet(mTxPower);

Output("set tx power to %d dBm\r\n", mTxPower);
}

exit:
Expand All @@ -387,7 +383,6 @@ Error Diags::ProcessRepeat(uint8_t aArgsLength, char *aArgs[])
{
otPlatAlarmMilliStop(&GetInstance());
mRepeatActive = false;
Output("repeated packet transmission is stopped\r\n");
}
else
{
Expand Down Expand Up @@ -420,8 +415,6 @@ Error Diags::ProcessRepeat(uint8_t aArgsLength, char *aArgs[])
mRepeatActive = true;
uint32_t now = otPlatAlarmMilliGetNow();
otPlatAlarmMilliStartAt(&GetInstance(), now, mTxPeriod);
Output("sending packets of length %#x at the delay of %#x ms\r\n", static_cast<int>(mTxLen),
static_cast<int>(mTxPeriod));
}

exit:
Expand Down Expand Up @@ -457,7 +450,6 @@ Error Diags::ProcessSend(uint8_t aArgsLength, char *aArgs[])
VerifyOrExit(txLength >= OT_RADIO_FRAME_MIN_SIZE, error = kErrorInvalidArgs);
mTxLen = txLength;

Output("sending %#x packet(s), length %#x\r\n", static_cast<int>(mTxPackets), static_cast<int>(mTxLen));
TransmitPacket();

exit:
Expand Down Expand Up @@ -486,7 +478,6 @@ Error Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[])
SuccessOrExit(error = Get<Radio>().SetTransmitPower(mTxPower));
otPlatDiagModeSet(true);
mStats.Clear();
Output("start diagnostics mode\r\n");

exit:
return error;
Expand All @@ -513,7 +504,6 @@ Error Diags::ProcessStats(uint8_t aArgsLength, char *aArgs[])
if ((aArgsLength == 1) && StringMatch(aArgs[0], "clear"))
{
mStats.Clear();
Output("stats cleared\r\n");
}
else
{
Expand All @@ -535,9 +525,6 @@ Error Diags::ProcessStop(uint8_t aArgsLength, char *aArgs[])
Get<Radio>().SetPromiscuous(false);
Get<Mac::SubMac>().SetRxOnWhenIdle(false);

OutputStats();
Output("\nstop diagnostics mode\r\n");

return kErrorNone;
}

Expand Down Expand Up @@ -619,7 +606,6 @@ Error Diags::ProcessRadio(uint8_t aArgsLength, char *aArgs[])
if (StringMatch(aArgs[0], "sleep"))
{
SuccessOrExit(error = Get<Radio>().Sleep());
Output("set radio from receive to sleep \r\n");
}
else if (StringMatch(aArgs[0], "receive"))
{
Expand All @@ -631,7 +617,6 @@ Error Diags::ProcessRadio(uint8_t aArgsLength, char *aArgs[])
if (aArgsLength == 0)
{
SuccessOrExit(error = RadioReceive());
Output("set radio from sleep to receive on channel %d\r\n", mChannel);
ExitNow();
}

Expand Down Expand Up @@ -1074,14 +1059,6 @@ Error Diags::ProcessGpio(uint8_t aArgsLength, char *aArgs[])
return error;
}

void Diags::AppendErrorResult(Error aError)
{
if ((aError != kErrorNone) && (aError != kErrorPending))
{
Output("failed\r\nstatus %#x\r\n", aError);
}
}

bool Diags::IsChannelValid(uint8_t aChannel)
{
return (aChannel >= Radio::kChannelMin && aChannel <= Radio::kChannelMax);
Expand Down Expand Up @@ -1183,8 +1160,6 @@ Error Diags::ProcessCmd(uint8_t aArgsLength, char *aArgs[])
Output("diag feature '%s' is not supported\r\n", aArgs[0]);
}

AppendErrorResult(error);

return error;
}

Expand Down
1 change: 0 additions & 1 deletion src/core/diags/factory_diags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ class Diags : public InstanceLocator, private NonCopyable

void TransmitPacket(void);
void Output(const char *aFormat, ...);
void AppendErrorResult(Error aError);
void ResetTxPacket(void);
void OutputStats(void);

Expand Down
23 changes: 0 additions & 23 deletions tests/scripts/expect/cli-diags.exp
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,26 @@ spawn_node 2

switch_node 1
send "diag start\n"
expect "start diagnostics mode"
expect_line "Done"

send "diag channel 11\n"
expect "set channel to 11"
expect_line "Done"

send "diag stats clear\n"
expect "stats cleared"
expect_line "Done"

switch_node 2

send "diag start\n"
expect "start diagnostics mode"
expect_line "Done"

send "diag channel 11\n"
expect "set channel to 11"
expect_line "Done"

send "diag stats clear\n"
expect "stats cleared"
expect_line "Done"

send "diag send 10 100\n"
expect "sending 0xa packet(s), length 0x64"
expect_line "Done"

sleep 2
Expand Down Expand Up @@ -89,17 +82,14 @@ expect "last received packet: rssi=-20, lqi=0"
expect_line "Done"

send "diag stats clear\n"
expect "stats cleared"
expect_line "Done"

switch_node 2

send "diag repeat 20 100\n"
expect "sending packets of length 0x64 at the delay of 0x14 ms"
expect_line "Done"
sleep 1
send "diag repeat stop\n"
expect "repeated packet transmission is stopped"
expect_line "Done"

switch_node 1
Expand All @@ -115,7 +105,6 @@ expect "last received packet: rssi=-20, lqi=0"
expect_line "Done"

send "diag stats clear\n"
expect "stats cleared"
expect_line "Done"

dispose_all
Expand All @@ -124,7 +113,6 @@ dispose_all
spawn_node 1

send "diag start\n"
expect "start diagnostics mode"
expect_line "Done"

send_user "input too short test\n"
Expand All @@ -143,58 +131,49 @@ send_user "shortest frame test\n"
send "diag frame 112233\n"
expect "Done"
send "diag send 1\n"
expect "length 0x3"
expect "Done"

send_user "longest frame test\n"
send "diag frame 11223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677\n"
expect "Done"
send "diag repeat 1\n"
expect "length 0x7f"
expect "Done"

send_user "send frame with security processed\n"
send "diag frame -s 112233\n"
expect "Done"
send "diag send 1\n"
expect "length 0x3"
expect "Done"

send_user "send frame with CSMA/CA enabled\n"
send "diag frame -c 112233\n"
expect "Done"
send "diag send 1\n"
expect "length 0x3"
expect "Done"

send_user "send frame with tx power\n"
send "diag frame -p 11 112233\n"
expect "Done"
send "diag send 1\n"
expect "length 0x3"
expect "Done"

send "diag repeat stop\n"
expect "Done"

send "diag channel 11\n"
expect "set channel to 11"
expect_line "Done"

send "diag power 10\n"
expect "set tx power to 10 dBm"
expect_line "Done"

send "diag radio sleep\n"
expect "set radio from receive to sleep"
expect_line "Done"

send "diag radio state\n"
expect "sleep"
expect_line "Done"

send "diag radio receive\n"
expect "set radio from sleep to receive on channel 11"
expect_line "Done"

send "diag radio state\n"
Expand Down Expand Up @@ -254,8 +233,6 @@ send "diag stop\n"
expect_line "Done"

send "diag channel\n"
expect "failed"
expect "status 0xd"
expect "Error 13: InvalidState"

dispose_all
Loading

0 comments on commit 3470934

Please sign in to comment.