editing campi corretto parte gui

This commit is contained in:
VALLONGOL 2025-12-22 13:02:26 +01:00
parent b7507d95ac
commit 2e718585eb
2 changed files with 68 additions and 4 deletions

View File

@ -35,12 +35,12 @@ class MsgRdrSettingsAndParameters(ctypes.Structure):
self.settings = RDROperationalSettings()
self.frequency = Frequency()
self.beacon = BeaconDelayAndCode()
self.rf_channels_grouping_options =RFChannelsGroupingOptions(0)
self.ac_id = ctypes.c_uint16(0)
self.rf_channels_grouping_options = RFChannelsGroupingOptions(0)
self.ac_identifier = ACIdentifier()
self.date_of_mission = DateOfMission(0)
self.time_of_mission = TimeOfMission(0)
self.param_id = ParamId()
self.param_value_1 = ParamValue() # Placeholder
self.param_value = ParamValue() # Placeholder
# self.param_value_2 = ParamValue() # Placeholder

View File

@ -596,7 +596,19 @@ class MonitorApp(tk.Frame):
# Apply change to message
try:
self._apply_edit_to_msg(field_path, str(val), msg_wrapper)
self.logger.info(f"Applied instant change: {field_path} = {val}")
# Verify the change was applied
msg = getattr(msg_wrapper, 'message', None)
if msg:
parts = [p for p in field_path.replace('/', '.').split('.') if p != '']
cur = msg
for p in parts:
cur = getattr(cur, p, None)
if cur is None:
break
verify_val = getattr(cur, 'raw', getattr(cur, 'value', cur)) if cur else None
self.logger.info(f"Applied: {field_path} = {val}, verified: {verify_val}")
else:
self.logger.info(f"Applied instant change: {field_path} = {val}")
except Exception as e:
self.logger.error(f"Failed to apply {field_path}: {e}")
except Exception as e:
@ -1735,6 +1747,7 @@ class MonitorApp(tk.Frame):
Handles dotted names and simple indexed parts. For ctypes fields, tries
to set `.raw` or `.value` if present; otherwise uses setattr.
For Union types with setter methods (e.g., set_field_name), uses those.
Attempts int then float conversion; falls back to string.
"""
msg = getattr(msg_wrapper, 'message', None)
@ -1743,6 +1756,57 @@ class MonitorApp(tk.Frame):
# resolve path parts
parts = [p for p in full_name.replace('/', '.').split('.') if p != '']
# DEBUG: Log what we're trying to apply
self.logger.info(f"_apply_edit_to_msg: full_name='{full_name}', value='{text_value}', parts={parts}")
# Special case: if path contains ".str." (Union bitfield), use setter method on parent Union
if '.str.' in full_name:
# Path like "date_of_mission.str.day_of_mission"
# We need to call date_of_mission.set_day_of_mission(value)
parts_before_str = []
field_name = None
for i, p in enumerate(parts):
if p == 'str' and i + 1 < len(parts):
field_name = parts[i + 1]
break
parts_before_str.append(p)
if field_name and parts_before_str:
# Navigate to the Union object (parent of .str)
cur = msg
for p in parts_before_str:
if '[' in p and p.endswith(']'):
key, idx = p[:-1].split('[')
if key:
cur = getattr(cur, key)
cur = cur[int(idx)]
else:
cur = getattr(cur, p)
# Try to use setter method like set_day_of_mission()
setter_name = f"set_{field_name}"
self.logger.info(f"Looking for setter '{setter_name}' on {type(cur).__name__}")
if hasattr(cur, setter_name):
val = self._coerce_text_to_type(text_value)
setter = getattr(cur, setter_name)
setter(val)
# Verify .raw was updated
raw_after = getattr(cur, 'raw', None)
self.logger.info(f"Successfully used setter {setter_name}({val}), Union.raw = {raw_after}")
# DEBUG: Log full path to verify we're modifying the right object
obj_path = '.'.join(parts_before_str)
parent_obj = msg
for p in parts_before_str:
parent_obj = getattr(parent_obj, p)
self.logger.info(f"Modified object: {type(parent_obj).__name__} at path '{obj_path}', id={id(parent_obj)}")
# Log message type to ensure we're on A1
self.logger.info(f"Message type: {type(msg).__name__}")
return
else:
self.logger.warning(f"Setter {setter_name} not found on {type(cur).__name__}, falling back to standard path")
# Standard path: navigate to parent and set attribute
cur = msg
for p in parts[:-1]:
# handle index like foo[0]