diff options
Diffstat (limited to 'mpm/tools')
-rwxr-xr-x | mpm/tools/mpm_debug.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/mpm/tools/mpm_debug.py b/mpm/tools/mpm_debug.py index 1a97a103c..dff1c78bd 100755 --- a/mpm/tools/mpm_debug.py +++ b/mpm/tools/mpm_debug.py @@ -3,6 +3,7 @@ import socket from mprpc import RPCClient import usrp_mpm as mpm import argparse +import random def parse_args(): @@ -16,6 +17,7 @@ def parse_args(): rpc_parser.add_argument("arguments", nargs="*") disc_parser = sub_parsers.add_parser("disc", help="Issue discovery") + echo_parser = sub_parsers.add_parser("echo", help="Issue UDP echo") return parser.parse_args() @@ -24,6 +26,7 @@ def rpc(address, port, command, *args): port = mpm.types.MPM_RPC_PORT client = RPCClient(address, port) if args: + args = [eval(arg.lstrip("=")) if arg.startswith("=") else arg for arg in args] result = client.call(command, *args) else: result = client.call(command) @@ -40,13 +43,31 @@ def discovery(address, port): sock.settimeout(1.0) # wait max 1 second while True: try: - data, sender = sock.recvfrom(4096) - print("Received respons from: {}".format(sender[0])) + data, sender = sock.recvfrom(8000) + print("Received response from: {}".format(sender[0])) print("Dicovery data: {}".format(data)) except: break +def echo(address, port): + if not port: + port = mpm.types.MPM_DISCOVERY_PORT + sock = socket.socket( + socket.AF_INET, + socket.SOCK_DGRAM) + message = "MPM-ECHO" + bytearray(random.getrandbits(8) for _ in xrange(8000-8)) + sock.sendto(message, (address, port)) + sock.settimeout(0.05) # wait max 50 ms + while True: + try: + data, sender = sock.recvfrom(9000) + print("Received response from: {}".format(sender[0])) + print("Echo data size: {}".format(len(data))) + except: + break + + def main(): args = parse_args() if args.command == "rpc": @@ -57,6 +78,11 @@ def main(): print(result) elif args.command == "disc": discovery(args.address, args.port) + result = True + elif args.command == "echo": + echo(args.address, args.port) + result = True + return result if __name__ == "__main__": |