[diag] add diag send async command support (#11111)

The original `diag send` command is an asynchronous command. Users
must wait for a certain period of time and then run the `diag stats`
command to query how many packets have been sent to know whether all
packets have been sent. This is very inefficient, and it is not
convenient for scripts to process this command.

This commit changes the command `diag send` from an asynchronous
command to a synchronous command, and add the asynchronous command
`diag send async`.
This commit is contained in:
Zhanglong Xia
2025-01-09 03:21:13 +08:00
committed by GitHub
parent 9942b98a4a
commit 70d315af23
5 changed files with 64 additions and 14 deletions
+6 -5
View File
@@ -2579,12 +2579,13 @@ class OTCI(object):
"""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):