aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-01-29 16:56:01 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-01-29 17:35:12 +0100
commit12743e2d61043fab95866cb621b3c86c04d4b397 (patch)
treeac62b35a7aaec8ca0c0ca5e0987bb4c4ed62abbc
parent6d0afb93cfc56dc8058b5113aff4f18b4377d923 (diff)
downloadat-mappers-12743e2d61043fab95866cb621b3c86c04d4b397.tar.gz
at-mappers-12743e2d61043fab95866cb621b3c86c04d4b397.tar.bz2
at-mappers-12743e2d61043fab95866cb621b3c86c04d4b397.zip
Add command line interface
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rwxr-xr-xxmm.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/xmm.py b/xmm.py
index b97cce8..6352b1f 100755
--- a/xmm.py
+++ b/xmm.py
@@ -24,10 +24,17 @@ import sys
EX_USAGE = 64
def usage(progname):
- print("{} <port>".format(progname))
- print("Example: {} /dev/ttyACM0".format(progname))
+ print("Usage:")
+ print("{} commands list # list available AT commands".format(progname))
+ print("{} commands help ".format(progname)
+ + "# list usage of available AT commands")
sys.exit(EX_USAGE)
+def print_header(string):
+ print('+' + '-' * (len(string) + 2) + '+')
+ print('| ' + string + ' |')
+ print('+' + '-' * (len(string) + 2) + '+')
+
class USB(object):
def __init__(self):
self._modem_path = None
@@ -67,8 +74,7 @@ class USB(object):
def get_ttys(self):
all_ttys = self._get_ttys()
all_ttys.sort()
- # return [all_ttys[0], all_ttys[2]]
- return [all_ttys[0]]
+ return [all_ttys[0], all_ttys[3]]
def route_modem_to_usb(self):
route_command = 'echo MODEM > /sys/devices/virtual/sec/switch/usb_sel'
@@ -187,11 +193,6 @@ class UART(object):
return lines
def get_cmds_usage(self):
- def print_cmd_header(command):
- print('+' + '-' * (len(command) + 2) + '+')
- print('| ' + command + ' |')
- print('+' + '-' * (len(command) + 2) + '+')
-
for command in self.list_commands():
# Don't reset the modem
if command == 'ATE':
@@ -201,19 +202,36 @@ class UART(object):
continue
usage = self.get_cmd_usage(command)
if len(usage) > 0:
- print_cmd_header(command)
+ print_header(command)
for line in usage:
print (line)
def close(self):
self.port.close()
-if __name__ == '__main__':
+def get_ttys():
usb = USB()
if not usb.has_modem():
usb.route_modem_to_usb()
print('Please unplug and replug the device')
sys.exit(0)
- for tty in usb.get_ttys():
- uart = UART(tty)
- uart.get_cmds_usage()
+ return usb.get_ttys()
+
+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)
+ elif len(sys.argv) == 3 and \
+ sys.argv[1] == "commands" and sys.argv[2] == "help":
+ for tty in get_ttys():
+ tty_header = int((78 - len(tty)) / 2) * " " \
+ + tty + " " *int((78 - len(tty)) / 2)
+ print_header(tty_header)
+ uart = UART(tty)
+ uart.get_cmds_usage()
+ else:
+ usage(sys.argv[0])