From 138f78644c74770d800cc917ec9886804f8d22f8 Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Mon, 25 Mar 2024 18:16:07 -0400 Subject: [PATCH 1/4] Fixed p1_print system time backwards check. --- python/fusion_engine_client/applications/p1_print.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/fusion_engine_client/applications/p1_print.py b/python/fusion_engine_client/applications/p1_print.py index 463740c7..7f0ae10b 100755 --- a/python/fusion_engine_client/applications/p1_print.py +++ b/python/fusion_engine_client/applications/p1_print.py @@ -262,7 +262,7 @@ def create_stats_entry(): return {'count': 1} else: # We allow a small tolerance to account for normal latency between measurements and computed # data like pose solutions, as well as latency between different types of measurements. - dt_sec = newest_system_time_sec - system_time_sec + dt_sec = system_time_sec - newest_system_time_sec if dt_sec < -0.2: _logger.warning( 'Backwards/restarted system time detected after %s (%s). [new_message=%s, ' From 8a49708993e3d11397dbb0b5651163bf7febe424 Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Mon, 25 Mar 2024 18:16:19 -0400 Subject: [PATCH 2/4] Fixed off-by-1 in p1_print message summary counts. --- python/fusion_engine_client/applications/p1_print.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/fusion_engine_client/applications/p1_print.py b/python/fusion_engine_client/applications/p1_print.py index 7f0ae10b..05c21e09 100755 --- a/python/fusion_engine_client/applications/p1_print.py +++ b/python/fusion_engine_client/applications/p1_print.py @@ -213,7 +213,7 @@ def main(): total_messages = 0 bytes_decoded = 0 - def create_stats_entry(): return {'count': 1} + def create_stats_entry(): return {'count': 0} message_stats = defaultdict(create_stats_entry) try: for header, message, data, offset_bytes in reader: From 8456cb1ce54622e2a720fd646dd6fc121aa57c82 Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Mon, 25 Mar 2024 18:16:41 -0400 Subject: [PATCH 3/4] Print the type name for recognized but unsupported message types. --- python/fusion_engine_client/applications/p1_print.py | 7 ++++++- python/fusion_engine_client/utils/enum_utils.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/python/fusion_engine_client/applications/p1_print.py b/python/fusion_engine_client/applications/p1_print.py index 05c21e09..97b9bbba 100755 --- a/python/fusion_engine_client/applications/p1_print.py +++ b/python/fusion_engine_client/applications/p1_print.py @@ -299,7 +299,12 @@ def create_stats_entry(): return {'count': 0} _logger.info(format_string.format('Message Name', 'Type', 'Count')) _logger.info(format_string.format('-' * 50, '-' * 5, '-' * 8)) for type, info in sorted(message_stats.items(), key=lambda x: int(x[0])): - name = message_type_to_class[type].__name__ if type in message_type_to_class else "Unknown" + if type in message_type_to_class: + name = message_type_to_class[type].__name__ + elif type.is_unrecognized(): + name = str(type) + else: + name = f'Unsupported ({str(type)})' _logger.info(format_string.format(name, int(type), info['count'])) _logger.info(format_string.format('-' * 50, '-' * 5, '-' * 8)) _logger.info(format_string.format('Total', '', total_messages)) diff --git a/python/fusion_engine_client/utils/enum_utils.py b/python/fusion_engine_client/utils/enum_utils.py index c834695e..a38853eb 100644 --- a/python/fusion_engine_client/utils/enum_utils.py +++ b/python/fusion_engine_client/utils/enum_utils.py @@ -79,7 +79,7 @@ def __str__(self): # BAR = 1 # # print(Foo.BAR) # Prints "BAR", not "Foo.BAR" - if self.name.startswith(IntEnum.UNRECOGNIZED_PREFIX): + if self.is_unrecognized(): return "(Unrecognized)" else: return self.name @@ -93,6 +93,9 @@ def to_string(self, include_value=True): else: return str(self) + def is_unrecognized(self): + return self.name.startswith(IntEnum.UNRECOGNIZED_PREFIX) + def enum_bitmask(enum_type, offset=0, define_bits=True, predicate=None): """! From 55000eba976b7c2a472bbf06b316e68801209fa9 Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Mon, 25 Mar 2024 18:50:16 -0400 Subject: [PATCH 4/4] Add is_unrecognized() to anything using DynamicEnumMeta. --- python/fusion_engine_client/utils/enum_utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/python/fusion_engine_client/utils/enum_utils.py b/python/fusion_engine_client/utils/enum_utils.py index a38853eb..c854cd59 100644 --- a/python/fusion_engine_client/utils/enum_utils.py +++ b/python/fusion_engine_client/utils/enum_utils.py @@ -9,6 +9,14 @@ class DynamicEnumMeta(EnumMeta): UNRECOGNIZED_PREFIX = '_U' + def __new__(cls, name, bases, dict): + # Add is_recognized() to the definition for the class using this metaclass. + def is_unrecognized(self): + return self.name.startswith(cls.UNRECOGNIZED_PREFIX) + dict['is_unrecognized'] = is_unrecognized + enum_class = super().__new__(cls, name, bases, dict) + return enum_class + def __call__(cls, value, *args, **kwargs): raise_on_unrecognized = kwargs.pop('raise_on_unrecognized', True) @@ -93,9 +101,6 @@ def to_string(self, include_value=True): else: return str(self) - def is_unrecognized(self): - return self.name.startswith(IntEnum.UNRECOGNIZED_PREFIX) - def enum_bitmask(enum_type, offset=0, define_bits=True, predicate=None): """!