Change in pysim[master]: shell: New 'read_records' and 'read_records_decoded' commands

laforge gerrit-no-reply at lists.osmocom.org
Wed Apr 7 07:35:13 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/23663 )


Change subject: shell: New 'read_records' and 'read_records_decoded' commands
......................................................................

shell: New 'read_records' and 'read_records_decoded' commands

Those commands can be used to read all the records available in the
selected file.

Change-Id: If457b4e02bde8aa6db8cc329411f94411c100bc9
---
M docs/shell.rst
M pySim/filesystem.py
2 files changed, 43 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/63/23663/1

diff --git a/docs/shell.rst b/docs/shell.rst
index 3cfc849..652e572 100644
--- a/docs/shell.rst
+++ b/docs/shell.rst
@@ -178,6 +178,20 @@
    :func: LinFixedEF.ShellCommands.read_rec_dec_parser
 
 
+read_records
+~~~~~~~~~~~~
+.. argparse::
+   :module: pySim.filesystem
+   :func: LinFixedEF.ShellCommands.read_recs_parser
+
+
+read_records_decoded
+~~~~~~~~~~~~~~~~~~~~
+.. argparse::
+   :module: pySim.filesystem
+   :func: LinFixedEF.ShellCommands.read_recs_dec_parser
+
+
 update_record
 ~~~~~~~~~~~~~
 .. argparse::
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index f8443f3..e97fbf6 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -568,6 +568,33 @@
             (data, sw) = self._cmd.rs.read_record_dec(opts.record_nr)
             self._cmd.poutput_json(data, opts.oneline)
 
+        read_recs_parser = argparse.ArgumentParser()
+        @cmd2.with_argparser(read_recs_parser)
+        def do_read_records(self, opts):
+            """Read all records from a record-oriented EF"""
+            num_of_rec = self._cmd.rs.selected_file_fcp['file_descriptor']['num_of_rec']
+            for recnr in range(1, 1 + num_of_rec):
+                (data, sw) = self._cmd.rs.read_record(recnr)
+                if (len(data) > 0):
+                   recstr = str(data)
+                else:
+                   recstr = "(empty)"
+                self._cmd.poutput("%03d %s" % (recnr, recstr))
+
+        read_recs_dec_parser = argparse.ArgumentParser()
+        read_recs_dec_parser.add_argument('--oneline', action='store_true',
+                                         help='No JSON pretty-printing, dump as a single line')
+        @cmd2.with_argparser(read_recs_dec_parser)
+        def do_read_records_decoded(self, opts):
+            """Read + decode all records from a record-oriented EF"""
+            num_of_rec = self._cmd.rs.selected_file_fcp['file_descriptor']['num_of_rec']
+            # collect all results in list so they are rendered as JSON list when printing
+            data_list = []
+            for recnr in range(1, 1 + num_of_rec):
+                (data, sw) = self._cmd.rs.read_record_dec(recnr)
+                data_list.append(data)
+            self._cmd.poutput_json(data_list, opts.oneline)
+
         upd_rec_parser = argparse.ArgumentParser()
         upd_rec_parser.add_argument('record_nr', type=int, help='Number of record to be read')
         upd_rec_parser.add_argument('data', help='Data bytes (hex format) to write')
@@ -965,6 +992,8 @@
             select_resp = f.decode_select_response(data)
         else:
             select_resp = self.probe_file(name, cmd_app)
+        # store the decoded FCP for later reference
+        self.selected_file_fcp = select_resp
 
         # register commands of new file
         if cmd_app and self.selected_file.shell_commands:

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23663
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: If457b4e02bde8aa6db8cc329411f94411c100bc9
Gerrit-Change-Number: 23663
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210407/96eb1fd6/attachment.htm>


More information about the gerrit-log mailing list