diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2022-01-30 05:09:40 +0100 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2022-01-31 06:15:38 +0100 |
commit | 2e96c86b57b7d9aea94dce55957755643c4e192e (patch) | |
tree | 3e41e06e942dcdf70f8ff39f7376771e0ab6011b | |
parent | e0a1c077c25f862884cff5806cad4bcaa3b93974 (diff) | |
download | at-mappers-2e96c86b57b7d9aea94dce55957755643c4e192e.tar.gz at-mappers-2e96c86b57b7d9aea94dce55957755643c4e192e.tar.bz2 at-mappers-2e96c86b57b7d9aea94dce55957755643c4e192e.zip |
This command dumps the modem state to a file. The modem state is
retrieved with <AT COMMAND>?.
The Python configfile format was chosen as it's human readable and it
might also look familiar to store data as it's also used by Gammu to
store SMS.
Having an (SQLite) database intead would prevent easy comparison
between files with software like diff or Meld.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rwxr-xr-x | xmm.py | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. +import configparser import os import re import serial @@ -25,10 +26,12 @@ EX_USAGE = 64 def usage(progname): print("Usage:") - print("{} commands list ".format(progname) + print("{} commands list ".format(progname) + "# list available AT commands") - print("{} commands help ".format(progname) + print("{} commands help ".format(progname) + "# list usage of available AT commands") + print("{} dump <path/to/file> ".format(progname) + + "# dump the state for later comparison") sys.exit(EX_USAGE) def print_header(string): @@ -207,9 +210,35 @@ class UART(object): for line in usage: print (line) + def get_cmds_status(self): + results = {} + for command in self.list_commands(): + # Don't reset the modem + if command == 'ATE': + continue + if command.startswith('AT+'): + # Scans the networks: it takes a very long time and it's not + # very useful to understand better AT commands settings + if command == 'AT+COPS': + continue + # TODO: for some reasons this makes many commands fails + if command == 'AT+FCLASS': + continue + print(command) + results[command] = self.get_cmd_status(command) + return results + def close(self): self.port.close() +def dump_status(path): + config = configparser.ConfigParser() + for tty in get_ttys(): + uart = UART(tty) + config['state@' + tty] = uart.get_cmds_status() + with open(path, 'w') as configfile: + config.write(configfile) + def get_ttys(): usb = USB() if not usb.has_modem(): @@ -272,5 +301,8 @@ if __name__ == '__main__': print_header(tty_header) uart = UART(tty) uart.get_cmds_usage() + elif len(sys.argv) == 3 and sys.argv[1] == "dump": + path = sys.argv[2] + dump_status(path) else: usage(sys.argv[0]) |