Skip to content

Commit

Permalink
[diag] add 'diag send async' command support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglongxia committed Jan 7, 2025
1 parent 3470934 commit 83518a3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/core/diags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The diagnostics module supports common diagnostics features that are listed belo
- [diag stream](#diag-stream-start)
- [diag power](#diag-power)
- [diag powersettings](#diag-powersettings)
- [diag send](#diag-send-packets-length)
- [diag send](#diag-send-async-packets-length)
- [diag repeat](#diag-repeat-delay-length)
- [diag radio](#diag-radio-sleep)
- [diag rawpowersetting](#diag-rawpowersetting)
Expand Down Expand Up @@ -163,10 +163,11 @@ RawPowerSetting: 223344
Done
```

### diag send \<packets\> [length]
### diag send [async] \<packets\> [length]

Transmit a fixed number of packets.

- async: Use the non-blocking mode.
- packets: The number of packets to be sent.
- length: The length of packet. The valid range is [3, 127].

Expand All @@ -175,6 +176,8 @@ Send the frame set by `diag frame` if length is omitted. Otherwise overwrite the
```bash
> diag send 20 100
Done
> diag send async 20 100
Done
```

### diag repeat \<delay\> [length]
Expand Down
37 changes: 33 additions & 4 deletions src/core/diags/factory_diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Diags::Diags(Instance &aInstance)
, mTxPower(0)
, mTxLen(0)
, mIsTxPacketSet(false)
, mIsAsyncSend(false)
, mRepeatActive(false)
, mDiagSendOn(false)
, mOutputCallback(nullptr)
Expand Down Expand Up @@ -429,6 +430,18 @@ Error Diags::ProcessSend(uint8_t aArgsLength, char *aArgs[])

VerifyOrExit(aArgsLength >= 1, error = kErrorInvalidArgs);

if (StringMatch(aArgs[0], "async"))
{
aArgs++;
aArgsLength--;
VerifyOrExit(aArgsLength >= 1, error = kErrorInvalidArgs);
mIsAsyncSend = true;
}
else
{
mIsAsyncSend = false;
}

SuccessOrExit(error = Utils::CmdLineParser::ParseAsUint32(aArgs[0], txPackets));
mTxPackets = txPackets;

Expand All @@ -452,6 +465,11 @@ Error Diags::ProcessSend(uint8_t aArgsLength, char *aArgs[])

TransmitPacket();

if (!mIsAsyncSend)
{
error = kErrorPending;
}

exit:
return error;
}
Expand Down Expand Up @@ -852,11 +870,22 @@ void Diags::TransmitDone(Error aError)
break;
}

VerifyOrExit(!mRepeatActive);
VerifyOrExit(mTxPackets > 1);
mTxPackets--;
VerifyOrExit(!mRepeatActive && (mTxPackets > 0));

TransmitPacket();
if (mTxPackets > 1)
{
mTxPackets--;
TransmitPacket();
}
else
{
mTxPackets = 0;

if (!mIsAsyncSend)
{
Output("OT_ERROR_NONE");
}
}

exit:
return;
Expand Down
1 change: 1 addition & 0 deletions src/core/diags/factory_diags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class Diags : public InstanceLocator, private NonCopyable
uint8_t mTxLen;
bool mIsHeaderUpdated : 1;
bool mIsTxPacketSet : 1;
bool mIsAsyncSend : 1;
bool mRepeatActive : 1;
bool mDiagSendOn : 1;
#endif
Expand Down
20 changes: 18 additions & 2 deletions tests/scripts/expect/cli-diags.exp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,24 @@ expect_line "Done"
send "diag send 10 100\n"
expect_line "Done"

send "diag stats\n"
expect "received packets: 0"
expect "sent success packets: 10"
expect "sent error cca packets: 0"
expect "sent error abort packets: 0"
expect "sent error others packets: 0"
expect "first received packet: rssi=0, lqi=0"
expect "last received packet: rssi=0, lqi=0"
expect_line "Done"

send "diag send async 10 100\n"
expect_line "Done"

sleep 2

send "diag stats\n"
expect "received packets: 0"
expect "sent success packets: 10"
expect "sent success packets: 20"
expect "sent error cca packets: 0"
expect "sent error abort packets: 0"
expect "sent error others packets: 0"
Expand All @@ -72,7 +85,7 @@ expect_line "Done"
switch_node 1

send "diag stats\n"
expect "received packets: 10"
expect "received packets: 20"
expect "sent success packets: 0"
expect "sent error cca packets: 0"
expect "sent error abort packets: 0"
Expand Down Expand Up @@ -139,6 +152,9 @@ expect "Done"
send "diag repeat 1\n"
expect "Done"

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

send_user "send frame with security processed\n"
send "diag frame -s 112233\n"
expect "Done"
Expand Down
11 changes: 6 additions & 5 deletions tools/otci/otci/otci.py
Original file line number Diff line number Diff line change
Expand Up @@ -2579,12 +2579,13 @@ def diag_stream_stop(self):
"""Stop transmitting a stream of characters."""
self.execute_command('diag stream stop')

def diag_send(self, packets: int, length: Optional[int] = None):
def diag_send(self, packets: int, length: Optional[int] = None, is_async: bool = True):
"""Transmit a fixed number of packets."""
if length is None:
command = f'diag send {packets}'
else:
command = f'diag send {packets} {length}'
command = 'diag send '
command += 'async ' if is_async else ''
command += f'{packets} '
command += f'{length}' if length is not None else ''

self.execute_command(command)

def diag_repeat(self, delay: int, length: Optional[int] = None):
Expand Down

0 comments on commit 83518a3

Please sign in to comment.