diff --git a/REFACTOR_SUMMARY.md b/doc/REFACTOR_SUMMARY.md similarity index 100% rename from REFACTOR_SUMMARY.md rename to doc/REFACTOR_SUMMARY.md diff --git a/pymsc/PyBusMonitor1553/Grifo_E_1553lib/data_types/cursor_info.py b/pymsc/PyBusMonitor1553/Grifo_E_1553lib/data_types/cursor_info.py index 03e11a9..c4837d8 100644 --- a/pymsc/PyBusMonitor1553/Grifo_E_1553lib/data_types/cursor_info.py +++ b/pymsc/PyBusMonitor1553/Grifo_E_1553lib/data_types/cursor_info.py @@ -38,6 +38,11 @@ class CursorPositionLatitude(ctypes.Union): ("crs_latitude", ctypes.c_uint16), ("str", _CursorPositionLatitudeStr) ] + + def get_value(self): + """Return the 32-bit latitude value from LSW and MSW""" + return (self.str.latitude_msw << 16) | self.str.latitude_lsw + class _CursorPositionLongitudeStr(ctypes.LittleEndianStructure): _pack_ = 1 _fields_ = [ @@ -50,4 +55,8 @@ class CursorPositionLongitude(ctypes.Union): _fields_ = [ ("crs_longitude", ctypes.c_uint16), ("str", _CursorPositionLongitudeStr) - ] \ No newline at end of file + ] + + def get_value(self): + """Return the 32-bit longitude value from LSW and MSW""" + return (self.str.longitude_msw << 16) | self.str.longitude_lsw \ No newline at end of file diff --git a/pymsc/core/field_mappings.py b/pymsc/core/field_mappings.py index 9d71458..357ad8c 100644 --- a/pymsc/core/field_mappings.py +++ b/pymsc/core/field_mappings.py @@ -327,8 +327,8 @@ B6_FIELD_MAP = { 'CRS_AZIMUTH_tellback': 'cursor_world_pos_azimuth', 'CRS_LAT_tellback': 'cursor_pos_latitude', 'CRS_LON_tellback': 'cursor_pos_longitude', - 'crs_x_tellback': 'cursor_x_display_coord_qual', - 'crs_y_tellback': 'cursor_y_display_coord', + 'crs_x_tellback': 'cursor_x_display_coord_qual.current_x_display_coord', + 'crs_y_tellback': 'cursor_y_display_coord.current_y_display_coord', # Param tellback 'PARAM_ID_TB': 'param_id_tellback', diff --git a/pymsc/core/message_definitions.py b/pymsc/core/message_definitions.py index ac56787..816cdea 100644 --- a/pymsc/core/message_definitions.py +++ b/pymsc/core/message_definitions.py @@ -114,6 +114,17 @@ class Msg1553Base: # If it's a Union or has a .raw attribute, return the raw value if hasattr(value, 'raw'): return value.raw + # Check for a get_value() method (for complex Union types) + if hasattr(value, 'get_value'): + return value.get_value() + # If it's a ctypes Structure/LittleEndianStructure, we can't do math with it + # Return None to indicate this field needs proper mapping to a sub-field + if isinstance(value, (ctypes.Structure, ctypes.Union)): + self.logger.warning( + f"Field {field_path} returned a ctypes Structure/Union. " + f"Consider mapping to a specific sub-field instead." + ) + return None return value except Exception as e: self.logger.error(f"Error getting field {field_path} from {self.message_id}: {e}") @@ -153,8 +164,19 @@ class Msg1553Base: getattr(obj_wrapper, setter_name)(int(value)) else: # Direct attribute access - setattr(obj, final_field, int(value)) - setattr(obj_wrapper, final_field, int(value)) + # Check if the field is a Union type with a 'raw' attribute + field_value = getattr(obj, final_field) + if hasattr(field_value, 'raw'): + # It's a Union type, set the raw value + field_value.raw = int(value) + # Do the same for the wrapper + wrapper_field_value = getattr(obj_wrapper, final_field) + if hasattr(wrapper_field_value, 'raw'): + wrapper_field_value.raw = int(value) + else: + # Simple type, direct assignment + setattr(obj, final_field, int(value)) + setattr(obj_wrapper, final_field, int(value)) # Trigger UDP transmission if hasattr(self.message_wrapper, 'send'): diff --git a/pymsc/gui/components/command_widgets.py b/pymsc/gui/components/command_widgets.py index 03faef8..f4e27da 100644 --- a/pymsc/gui/components/command_widgets.py +++ b/pymsc/gui/components/command_widgets.py @@ -335,7 +335,10 @@ class CommandFrameLabels(tk.Frame): field = self.info[f"field{i}"] raw = msg.get_value_for_field(field) val = get_correct_value(self.info, i, raw) - self.vars[field].set("%.4f" % val) + if val is not None: + self.vars[field].set("%.4f" % val) + else: + self.vars[field].set("N/A") class CommandFrameControls(tk.Frame): """ diff --git a/test_integration.py b/tests/test_integration.py similarity index 100% rename from test_integration.py rename to tests/test_integration.py diff --git a/test_new_messages.py b/tests/test_new_messages.py similarity index 100% rename from test_new_messages.py rename to tests/test_new_messages.py diff --git a/test_widget_integration.py b/tests/test_widget_integration.py similarity index 100% rename from test_widget_integration.py rename to tests/test_widget_integration.py