import ctypes
from Grifo_E_1553lib.data_types.rdr_settings import RDROperationalSettings
from Grifo_E_1553lib.data_types.frequency import Frequency, BeaconDelayAndCode
from Grifo_E_1553lib.data_types.rf_channels_grouping_options import RFChannelsGroupingOptions
from Grifo_E_1553lib.data_types.param_value import ParamValue, ParamId
from Grifo_E_1553lib.data_types.ac_identifier import ACIdentifier
from Grifo_E_1553lib.data_types.date_of_mission import DateOfMission
from Grifo_E_1553lib.data_types.time_of_mission import TimeOfMission



class MsgRdrSettingsAndParameters(ctypes.Structure):
    """
    A1: Radar Operational Setting and Parameter Transfer.

    Contains radar settings, frequency agility settings, beacon delay and code,
    gains, A/C identifier, date and time of mission, and parameter identifiers.
    """
    _pack_ = 1  # Forza l'allineamento a 1 byte
    _fields_ = [
        ("settings", RDROperationalSettings),
        ("frequency", Frequency),
        ("beacon", BeaconDelayAndCode),
        ("rf_channels_grouping_options", RFChannelsGroupingOptions), 
        ("ac_identifier", ACIdentifier), 
        ("date_of_mission", DateOfMission), 
        ("time_of_mission", TimeOfMission), 
        ("param_id", ParamId),
        ("param_value", ParamValue),  # Placeholder
        # ("param_value_2", ParamValue)   # Placeholder
    ]

    def __init__(self):
        super().__init__()
        self.settings = RDROperationalSettings()
        self.frequency = Frequency()
        self.beacon = BeaconDelayAndCode()
        self.rf_channels_grouping_options =RFChannelsGroupingOptions(0)  
        self.ac_id = ctypes.c_uint16(0)  
        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_2 = ParamValue()  # Placeholder





# typedef uint16_t avb_1553_word_t;

# typedef struct {
#   unsigned int wc: 5;
#   unsigned int sa: 5;
#   unsigned int tr: 1;
#   unsigned int rt: 5;
# } avb_1553_cw_structure_t;

# typedef union {
#   avb_1553_word_t raw;
#   avb_1553_cw_structure_t str;
# } avb_1553_cmd_word_t;

# typedef struct {
#     unsigned int tf: 1;
#     unsigned int bca: 1;
#     unsigned int sf: 1;
#     unsigned int busy: 1;
#     unsigned int brcs: 1;
#     unsigned int reserved: 3;
#     unsigned int sr: 1;
#     unsigned int instr: 1;
#     unsigned int me: 1;
#     unsigned int rt: 5;
# } avb_1553_sw_structure_t;

# typedef union {
#   avb_1553_word_t raw;
#   avb_1553_sw_structure_t str;
# } avb_1553_sts_word_t;