sistemate alcune conversioni di dati tra valore 1553 e gui
This commit is contained in:
parent
3b30474237
commit
15ebe4dae2
@ -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_ = [
|
||||
@ -51,3 +56,7 @@ class CursorPositionLongitude(ctypes.Union):
|
||||
("crs_longitude", ctypes.c_uint16),
|
||||
("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
|
||||
@ -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',
|
||||
|
||||
@ -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'):
|
||||
|
||||
@ -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):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user