From 22f5e7afc03785ea53afec8a9957f57ed511fc91 Mon Sep 17 00:00:00 2001 From: dgburr Date: Wed, 10 Jan 2024 15:50:16 +0100 Subject: [PATCH] Add --unbuffered option to sbp2json.py (#1400) Add a new `--unbuffered` command line option to sbp2json.py which enables a mode where it reads and parses messages one-at-a-time. The existing behaviour (which remains the default) waits for 4096 bytes before parsing, which means that when decoding real-time streams which only output messages intermittently, there are often large pauses where no output is produced, followed by a large batch of decoded messages at once. --- python/sbp/__init__.py | 0 python/sbp/acquisition.py | 0 python/sbp/bootload.py | 0 python/sbp/logging.py | 0 python/sbp/msg.py | 0 python/sbp/navigation.py | 0 python/sbp/piksi.py | 0 python/sbp/sbp2json.py | 65 ++++++++++++++++++++++++++++--- python/sbp/table.py | 0 python/sbp/utils.py | 0 python/tests/sbp/test_sbp2json.py | 20 ++++++++-- 11 files changed, 77 insertions(+), 8 deletions(-) mode change 100755 => 100644 python/sbp/__init__.py mode change 100755 => 100644 python/sbp/acquisition.py mode change 100755 => 100644 python/sbp/bootload.py mode change 100755 => 100644 python/sbp/logging.py mode change 100755 => 100644 python/sbp/msg.py mode change 100755 => 100644 python/sbp/navigation.py mode change 100755 => 100644 python/sbp/piksi.py mode change 100755 => 100644 python/sbp/table.py mode change 100755 => 100644 python/sbp/utils.py diff --git a/python/sbp/__init__.py b/python/sbp/__init__.py old mode 100755 new mode 100644 diff --git a/python/sbp/acquisition.py b/python/sbp/acquisition.py old mode 100755 new mode 100644 diff --git a/python/sbp/bootload.py b/python/sbp/bootload.py old mode 100755 new mode 100644 diff --git a/python/sbp/logging.py b/python/sbp/logging.py old mode 100755 new mode 100644 diff --git a/python/sbp/msg.py b/python/sbp/msg.py old mode 100755 new mode 100644 diff --git a/python/sbp/navigation.py b/python/sbp/navigation.py old mode 100755 new mode 100644 diff --git a/python/sbp/piksi.py b/python/sbp/piksi.py old mode 100755 new mode 100644 diff --git a/python/sbp/sbp2json.py b/python/sbp/sbp2json.py index 5d4b0b9abe..d564fa857e 100644 --- a/python/sbp/sbp2json.py +++ b/python/sbp/sbp2json.py @@ -39,6 +39,8 @@ def base_cl_options(): help="the JSON serialization library to use, default: {}".format(DEFAULT_JSON)) parser.add_argument('--include', nargs="+", type=int, default=[], help="list of SBP message IDs to include, empty means all") + parser.add_argument("--unbuffered", action="store_true", + help="disable buffering when reading data from input (slower)") parser.add_argument('file', nargs='?', metavar='FILE', type=argparse.FileType('rb'), default=sys.stdin, help="the input file, stdin by default") @@ -61,6 +63,13 @@ def get_args(): return args +# return the read and expected CRCs from 'buf' +def get_crcs(buf, payload_len): + crc_read, = struct.unpack("