diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2022-01-29 17:29:45 +0100 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2022-01-30 05:09:51 +0100 |
commit | e0a1c077c25f862884cff5806cad4bcaa3b93974 (patch) | |
tree | 3debda3a37fd47c5b6a278ff995822c760527a15 | |
parent | 12743e2d61043fab95866cb621b3c86c04d4b397 (diff) | |
download | at-mappers-e0a1c077c25f862884cff5806cad4bcaa3b93974.tar.gz at-mappers-e0a1c077c25f862884cff5806cad4bcaa3b93974.tar.bz2 at-mappers-e0a1c077c25f862884cff5806cad4bcaa3b93974.zip |
Improve commands listing
This checks if all the commands are available on all the UARTS as it is
common for AT modem not to expose all the commands on all the UARTs.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rwxr-xr-x | xmm.py | 53 |
1 files changed, 46 insertions, 7 deletions
@@ -25,8 +25,9 @@ EX_USAGE = 64 def usage(progname): print("Usage:") - print("{} commands list # list available AT commands".format(progname)) - print("{} commands help ".format(progname) + print("{} commands list ".format(progname) + + "# list available AT commands") + print("{} commands help ".format(progname) + "# list usage of available AT commands") sys.exit(EX_USAGE) @@ -217,14 +218,52 @@ def get_ttys(): sys.exit(0) return usb.get_ttys() + +def list_commands(): + commands = { + 'all' : [], + } + + ttys = get_ttys() + + assert(len(ttys) == 2) + + for tty in ttys: + uart = UART(tty) + commands[tty] = uart.list_commands() + for command in commands[tty]: + if command not in commands['all']: + commands['all'].append(command) + + commands[ttys[0]].sort() + commands[ttys[1]].sort() + commands['all'].sort() + + tty_specific_commands = False + for tty in ttys: + for command in commands['all']: + if command not in commands[tty]: + tty_specific_commands = True + break + + if not tty_specific_commands: + print_header(ttys[0] + " and " + ttys[1]) + for command in commands['all']: + print(command) + else: + print_header("All available commands:") + for command in commands['all']: + print(command) + for tty in ttys: + print_header(tty) + for command in commands['all']: + if command not in commands[tty]: + print("- {}".format(command)) + if __name__ == '__main__': if len(sys.argv) == 3 and \ sys.argv[1] == "commands" and sys.argv[2] == "list": - for tty in get_ttys(): - print_header(tty) - uart = UART(tty) - for command in uart.list_commands(): - print(command) + list_commands() elif len(sys.argv) == 3 and \ sys.argv[1] == "commands" and sys.argv[2] == "help": for tty in get_ttys(): |