sistemate alcune conversioni di dati tra valore 1553 e gui

This commit is contained in:
VALLONGOL 2026-01-09 08:19:12 +01:00
parent 3b30474237
commit 15ebe4dae2
8 changed files with 40 additions and 6 deletions

View File

@ -38,6 +38,11 @@ class CursorPositionLatitude(ctypes.Union):
("crs_latitude", ctypes.c_uint16), ("crs_latitude", ctypes.c_uint16),
("str", _CursorPositionLatitudeStr) ("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): class _CursorPositionLongitudeStr(ctypes.LittleEndianStructure):
_pack_ = 1 _pack_ = 1
_fields_ = [ _fields_ = [
@ -51,3 +56,7 @@ class CursorPositionLongitude(ctypes.Union):
("crs_longitude", ctypes.c_uint16), ("crs_longitude", ctypes.c_uint16),
("str", _CursorPositionLongitudeStr) ("str", _CursorPositionLongitudeStr)
] ]
def get_value(self):
"""Return the 32-bit longitude value from LSW and MSW"""
return (self.str.longitude_msw << 16) | self.str.longitude_lsw

View File

@ -327,8 +327,8 @@ B6_FIELD_MAP = {
'CRS_AZIMUTH_tellback': 'cursor_world_pos_azimuth', 'CRS_AZIMUTH_tellback': 'cursor_world_pos_azimuth',
'CRS_LAT_tellback': 'cursor_pos_latitude', 'CRS_LAT_tellback': 'cursor_pos_latitude',
'CRS_LON_tellback': 'cursor_pos_longitude', 'CRS_LON_tellback': 'cursor_pos_longitude',
'crs_x_tellback': 'cursor_x_display_coord_qual', 'crs_x_tellback': 'cursor_x_display_coord_qual.current_x_display_coord',
'crs_y_tellback': 'cursor_y_display_coord', 'crs_y_tellback': 'cursor_y_display_coord.current_y_display_coord',
# Param tellback # Param tellback
'PARAM_ID_TB': 'param_id_tellback', 'PARAM_ID_TB': 'param_id_tellback',

View File

@ -114,6 +114,17 @@ class Msg1553Base:
# If it's a Union or has a .raw attribute, return the raw value # If it's a Union or has a .raw attribute, return the raw value
if hasattr(value, 'raw'): if hasattr(value, 'raw'):
return 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 return value
except Exception as e: except Exception as e:
self.logger.error(f"Error getting field {field_path} from {self.message_id}: {e}") self.logger.error(f"Error getting field {field_path} from {self.message_id}: {e}")
@ -153,6 +164,17 @@ class Msg1553Base:
getattr(obj_wrapper, setter_name)(int(value)) getattr(obj_wrapper, setter_name)(int(value))
else: else:
# Direct attribute access # Direct attribute access
# 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, final_field, int(value))
setattr(obj_wrapper, final_field, int(value)) setattr(obj_wrapper, final_field, int(value))

View File

@ -335,7 +335,10 @@ class CommandFrameLabels(tk.Frame):
field = self.info[f"field{i}"] field = self.info[f"field{i}"]
raw = msg.get_value_for_field(field) raw = msg.get_value_for_field(field)
val = get_correct_value(self.info, i, raw) val = get_correct_value(self.info, i, raw)
if val is not None:
self.vars[field].set("%.4f" % val) self.vars[field].set("%.4f" % val)
else:
self.vars[field].set("N/A")
class CommandFrameControls(tk.Frame): class CommandFrameControls(tk.Frame):
""" """