# NOT USED
import unittest
import os
import sys
import math

# Add the project root to the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))

# Now you can import your module
from Grifo_E_1553lib.core import greet
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.enums import (TargetHistory, FrequencyAgilityType, FrequencyGroupSelector, WaveformInterleave, 
                                         LPRFThreshold, GroundTargetRejectVel, MinDetectGroundVel, ALEBlanking, AltitudeBlock, 
                                         PRFLookup, ParameterTransferEnabled, ReceiveTransmitSelector, ParamIdCode, FrequencyGrouping, 
                                         RdrModes, DesControl, IbitRequest, StbySelection, SarExecSelection, RwsSubmode, SpotSelection, 
                                         AcmSubmode, GmSubmode, Expand, RangeScale, BarsNum, ScanWidth, VelocityScale, Zoom, SarMapOrientation,
                                         BullsEyeIdentifier,WaypointFytSelection, WaypointQualifierValue, NavDataInvalidField, CrsGhostSelector, 
                                         CrsDttSelector, CrsSarSelector, DlTargetValidity, DlTargetTypeSelector, FriendFoeSelector,TwsTargetValidity, 
                                         TwsTargetWhich, TrackPriority, TargetAccurancy)
from Grifo_E_1553lib.data_types.rf_channels_grouping_options import GainsAndChgrp
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
from Grifo_E_1553lib.data_types.param_id import ParamId
from Grifo_E_1553lib.data_types.param_value import ParamValue
from Grifo_E_1553lib.data_types.rdr_mode_command import RdrModeCommandWord
from Grifo_E_1553lib.data_types.rdr_fun_and_param1 import RdrFunAndParam1
from Grifo_E_1553lib.data_types.rdr_fun_and_param2 import RdrFunAndParam2
from Grifo_E_1553lib.data_types.graphic_order import GraphicOrder
from Grifo_E_1553lib.data_types.time_to_go_to_cursor import TimeToGoToCursor
from Grifo_E_1553lib.data_types.waypoint_lat_sel_qual import WaypointLatSelQual
from Grifo_E_1553lib.data_types.waypoint_lon_code import WaypointLonCode

from Grifo_E_1553lib.data_types.waypoint_data import WaypointData, WaypointDataArray
from Grifo_E_1553lib.data_types.a4_validity_and_slew import A4ValidityAndSlew
from Grifo_E_1553lib.data_types.crs_motion_x import CrsMotionX
from Grifo_E_1553lib.data_types.crs_motion_y import CrsMotionY

from Grifo_E_1553lib.data_types.attitude_rate import AttitudeRate
from Grifo_E_1553lib.data_types.ang_acc import AngAcc
from Grifo_E_1553lib.data_types.velocity import Velocity
from Grifo_E_1553lib.data_types.relative_timetag import RelativeTimetag
from Grifo_E_1553lib.data_types.semicircle import Semicircle
from Grifo_E_1553lib.data_types.acceleration import Acceleration
from Grifo_E_1553lib.data_types.tas import Tas
from Grifo_E_1553lib.data_types.cas import Cas
from Grifo_E_1553lib.data_types.baro_altitude import BaroAltitude
from Grifo_E_1553lib.data_types.radio_altitude import RadioAltitude
from Grifo_E_1553lib.data_types.spoi_altitude import SpoiAltitude
from Grifo_E_1553lib.data_types.latlong import LatLong
from Grifo_E_1553lib.data_types.crs_slave_range import CrsSlaveRange
from Grifo_E_1553lib.data_types.dl_target_validity import DlTargetValidity
from Grifo_E_1553lib.data_types.target_presentation_data import TargetPresentationData
from Grifo_E_1553lib.data_types.target_half_call_sign import TargetHalfCallSign
from Grifo_E_1553lib.data_types.target_position import TargetPosition
from Grifo_E_1553lib.data_types.x_display_coord_of_the_hpt_target import XDisplayCoordOfTheHptTarget
from Grifo_E_1553lib.data_types.y_display_coord_of_the_hpt_target import YDisplayCoordOfTheHptTarget
from Grifo_E_1553lib.data_types.target_velocity_magnitude import TargetVelocityMagnitude
from Grifo_E_1553lib.data_types.tws_velocity import TwsVelocity
from Grifo_E_1553lib.data_types.tws_status_and_targets import (ValitidyWordAndHptIdentifier, TrackPriority0104, TrackPriority0508, TrackAccurancy0104, 
                                                          TrackAccurancy0508, TrackIdOfTwsTrackedTarget0102, TrackIdOfTwsTrackedTarget0304, TrackIdOfTwsTrackedTarget0506, 
                                                          TrackIdOfTwsTrackedTarget0708)

from Grifo_E_1553lib.messages.msg_nav_data_and_cursor import MsgNavDataAndCursor
from Grifo_E_1553lib.messages.msg_rdr_settings_and_parameters import MsgRdrSettingsAndParameters
from Grifo_E_1553lib.messages.msg_rdr_operation_command import MsgRdrOperationCommand
from Grifo_E_1553lib.messages.msg_graphic_setting import MsgGraphicSetting
from Grifo_E_1553lib.messages.msg_inu_high_speed import MsgInuHighSpeed
from Grifo_E_1553lib.messages.msg1_data_link_target import Msg1DataLinkTarget
from Grifo_E_1553lib.messages.msg2_data_link_target import Msg2DataLinkTarget
from Grifo_E_1553lib.messages.msg_reserved import MsgReserved
from Grifo_E_1553lib.messages.msg_dev0_reserved import MsgDev0Reserved
from Grifo_E_1553lib.messages.tws_status_and_targets import TwsStatusAndTargets0102

ICD1553_DL_POSITION_METERS_LSB = float(1/32767)

class TestCore(unittest.TestCase):
    def test_greet(self):
        self.assertEqual(greet("World"), "Hello, World!")

class TestRDROperationalSettings(unittest.TestCase):
    def setUp(self):
        self.settings = RDROperationalSettings()
    
    def test_history_level(self):
        self.settings.set_history_level(TargetHistory.TARGET_HISTORY_LEVEL_03)
        self.assertEqual(self.settings.get_history_level(), TargetHistory.TARGET_HISTORY_LEVEL_03)

class TestFrequency(unittest.TestCase):
    def setUp(self):
        self.frequency = Frequency()    

    def test_agility(self):
        self.frequency.set_agility(FrequencyAgilityType.ADAPTIVE)
        self.assertEqual(self.frequency.get_agility(), FrequencyAgilityType.ADAPTIVE)

    def test_frq_group1(self):
        self.frequency.set_frq_group1(FrequencyGroupSelector.FREQUENCY_GROUP_ACTIVE)
        self.assertEqual(self.frequency.get_frq_group1(), FrequencyGroupSelector.FREQUENCY_GROUP_ACTIVE)

    def test_channel(self):
        self.frequency.set_channel(15)
        self.assertEqual(self.frequency.get_channel(), 15)

    def test_waveform(self):
        self.frequency.set_waveform(WaveformInterleave.WAVEFORM_INT_02_SEL_SPARE)
        self.assertEqual(self.frequency.get_waveform(), WaveformInterleave.WAVEFORM_INT_02_SEL_SPARE)

    def test_lprf_threshold(self):
        self.frequency.set_lprf_threshold(LPRFThreshold.THRESHOLD_HIGH)
        self.assertEqual(self.frequency.get_lprf_threshold(), LPRFThreshold.THRESHOLD_HIGH)
        
class TestBeaconDelayAndCode(unittest.TestCase):
    def setUp(self):
        self.beacon = BeaconDelayAndCode()
        
    def test_delay(self):
        self.beacon.set_delay(0xABC)
        self.assertEqual(self.beacon.get_delay(), 0xABC)

    def test_code(self):
        self.beacon.set_code(0x05)
        self.assertEqual(self.beacon.get_code(), 0x05)
        
class TestGainsAndChgrp(unittest.TestCase):
    def setUp(self):
        self.gains = GainsAndChgrp()
        
    def test_if_gain(self):
        self.gains.set_if_gain(0x3F)
        self.assertEqual(self.gains.get_if_gain(), 0x3F)

    def test_moving_target_gain(self):
        self.gains.set_moving_target_gain(0x4A)
        self.assertEqual(self.gains.get_moving_target_gain(), 0x4A)

    def test_frequency_grouping_field(self):
        self.gains.set_frequency_grouping_field(FrequencyGrouping.FREQUENCY_GROUPING_OPTION_02)
        self.assertEqual(self.gains.get_frequency_grouping_field().value, FrequencyGrouping.FREQUENCY_GROUPING_OPTION_02)

    def test_spare(self):
        self.gains.set_spare(1)
        self.assertEqual(self.gains.get_spare(), 1)
        
class TestACIdentifier(unittest.TestCase):
    def setUp(self):
        self.ac_id = ACIdentifier()
    def test_ac_id(self):
        self.ac_id.set_ac_id(0xABCD)
        self.assertEqual(self.ac_id.get_ac_id(), 0xABCD)
        
class TestDateOfMission(unittest.TestCase):
    def setUp(self):
        self.date = DateOfMission()
        
    def test_year_of_mission(self):
        self.date.set_year_of_mission(30)
        self.assertEqual(self.date.get_year_of_mission(), 30)

    def test_month_of_mission(self):
        self.date.set_month_of_mission(6)
        self.assertEqual(self.date.get_month_of_mission(), 6)

    def test_day_of_mission(self):
        self.date.set_day_of_mission(15)
        self.assertEqual(self.date.get_day_of_mission(), 15)

    def test_time_mark(self):
        self.date.set_time_mark(1)
        self.assertEqual(self.date.get_time_mark(), 1)
        
class TestTimeOfMission(unittest.TestCase):
    def setUp(self):
        self.time = TimeOfMission()
        
    def test_time_of_mission(self):
        self.time.set(0x1234)
        self.assertEqual(self.time.get(), 0x1234)

class TestParamId(unittest.TestCase):
    def setUp(self):
        self.param_id = ParamId()
        
    def test_enable(self):
        self.param_id.set_enable(ParameterTransferEnabled.PAR_TRANSF_ACTIVE)
        self.assertEqual(self.param_id.get_enable().value, ParameterTransferEnabled.PAR_TRANSF_ACTIVE)

    def test_tx(self):
        self.param_id.set_tx(ReceiveTransmitSelector.SELECTOR_TRANSMIT)
        self.assertEqual(self.param_id.get_tx().value, ReceiveTransmitSelector.SELECTOR_TRANSMIT)

    def test_num(self):
        self.param_id.set_num(0x42)
        self.assertEqual(self.param_id.get_num(), 0x42)

    def test_spare(self):
        self.param_id.set_spare(0x1A)
        self.assertEqual(self.param_id.get_spare(), 0x1A)
        
class TestMsgRdrSettingsAndParameters(unittest.TestCase):
    
    def setUp(self):
        self.msg = MsgRdrSettingsAndParameters()
        
    def test_msg_rdr_settings_and_parameters(self):
        # Imposta alcuni valori di esempio
        self.msg.settings.set_history_level(TargetHistory.TARGET_HISTORY_LEVEL_02)
        self.msg.frequency.set_channel(20)
        #msg.beacon.set_code(5)
        #msg.gains_and_chgrp.set_if_gain(60)
        #msg.ac_id.set_ac_id(0x1234)

        # Verifica i valori
        self.assertEqual(self.msg.settings.get_history_level(), TargetHistory.TARGET_HISTORY_LEVEL_02)
        self.assertEqual(self.msg.frequency.get_channel(), 20)
        #self.assertEqual(msg.beacon.get_code(), 5)
        #self.assertEqual(msg.gains_and_chgrp.get_if_gain(), 60)
        #self.assertEqual(msg.ac_id.get_ac_id(), 0x1234)
        
class TestRdrModeCommandWord(unittest.TestCase):
    def setUp(self):
        self.command = RdrModeCommandWord()
    def test_master_mode(self):
        self.command.set_master_mode(RdrModes.ACM)
        self.assertEqual(self.command.get_master_mode().value, RdrModes.ACM)

    def test_design_sts(self):
        self.command.set_des_ctrl(DesControl.LOCK_ON)
        self.assertEqual(self.command.get_des_ctrl().value, DesControl.LOCK_ON)

    def test_ibit(self):
        self.command.set_ibit(IbitRequest.INT_BIT)
        self.assertEqual(self.command.get_ibit().value, IbitRequest.INT_BIT)

    def test_stby(self):
        self.command.set_stby(StbySelection.STBY_ON)
        self.assertEqual(self.command.get_stby(), StbySelection.STBY_ON)

    def test_freeze(self):
        self.command.set_freeze(1)
        self.assertEqual(self.command.get_freeze(), 1)

    def test_stop_powerup(self):
        self.command.set_stop_powerup(1)
        self.assertEqual(self.command.get_stop_powerup(), 1)

    def test_reserved11(self):
        self.command.set_reserved11(1)
        self.assertEqual(self.command.get_reserved11(), 1)

    def test_rf_radiation(self):
        self.command.set_rf_radiation(1)
        self.assertEqual(self.command.get_rf_radiation(), 1)

    def test_transition_status(self):
        self.command.set_transition_status(1)
        self.assertEqual(self.command.get_transition_status(), 1)

    def test_last_acq_result(self):
        self.command.set_last_acq_result(1)
        self.assertEqual(self.command.get_last_acq_result(), 1)

    def test_sar_acquisition(self):
        self.command.set_sar_type(SarExecSelection.SAR_ON_SPOI)
        self.assertEqual(self.command.get_sar_type().value, SarExecSelection.SAR_ON_SPOI)

    def test_spare(self):
        self.command.set_spare(3)
        self.assertEqual(self.command.get_spare(), 3)
        
class TestRdrFunAndParam1(unittest.TestCase):
    def setUp(self):
        self.param1 = RdrFunAndParam1()
    def test_rws_submode(self):
        self.param1.set_rws_submode(RwsSubmode.RWS_ASM)
        self.assertEqual(self.param1.get_rws_submode().value, RwsSubmode.RWS_ASM)

    def test_spot(self):
        self.param1.set_spot(SpotSelection.SEL_SPOT)
        self.assertEqual(self.param1.get_spot().value, SpotSelection.SEL_SPOT)

    def test_acm_submode(self):
        self.param1.set_acm_submode(AcmSubmode.HUD)
        self.assertEqual(self.param1.get_acm_submode().value, AcmSubmode.HUD)

    def test_gm_submode(self):
        self.param1.set_gm_submode(GmSubmode.GM_DBS)
        self.assertEqual(self.param1.get_gm_submode().value, GmSubmode.GM_DBS)

    def test_expand(self):
        self.param1.set_expand(Expand.EXPAND)
        self.assertEqual(self.param1.get_expand().value, Expand.EXPAND)

    def test_range_scale(self):
        self.param1.set_range_scale(RangeScale.NM20)
        self.assertEqual(self.param1.get_range_scale().value, RangeScale.NM20)

    def test_bars_num(self):
        self.param1.set_bars_num(BarsNum.BARS_2)
        self.assertEqual(self.param1.get_bars_num().value, BarsNum.BARS_2)

    def test_scan_width(self):
        self.param1.set_scan_width(ScanWidth.W25)
        self.assertEqual(self.param1.get_scan_width().value, ScanWidth.W25)

    def test_velocity_scale(self):
        self.param1.set_velocity_scale(VelocityScale.KTS1200)
        self.assertEqual(self.param1.get_velocity_scale().value, VelocityScale.KTS1200)

    def test_spare(self):
        self.param1.set_spare(1)
        self.assertEqual(self.param1.get_spare(), 1)
        
class TestRdrFunAndParam2(unittest.TestCase):
    def setUp(self):
        self.param2 = RdrFunAndParam2()
    def test_spare_0_4(self):
        self.param2.set_spare_0_4(0x0A)
        self.assertEqual(self.param2.get_spare_0_4(), 0x0A)

    def test_zoom(self):
        self.param2.set_zoom(Zoom.ZOOM_IN)
        self.assertEqual(self.param2.get_zoom().value, Zoom.ZOOM_IN)

    def test_sar_map_orientation(self):
        self.param2.set_sar_map_orientation(SarMapOrientation.SAR_SLANT_CROSS_RANGE)
        self.assertEqual(self.param2.get_sar_map_orientation().value, SarMapOrientation.SAR_SLANT_CROSS_RANGE)

    def test_spare_8_15(self):
        self.param2.set_spare_8_15(0x55)
        self.assertEqual(self.param2.get_spare_8_15(), 0x55)
        
class TestMsgRdrOperationCommand(unittest.TestCase):
    def setUp(self):
        self.msg = MsgRdrOperationCommand()
    def test_msg_rdr_operation_command(self):

        # Imposta alcuni valori di esempio
        self.msg.rdr_mode_command.set_master_mode(RdrModes.ACM)
        self.msg.param1.set_rws_submode(RwsSubmode.RWS_ASM)
        self.msg.param2.set_zoom(Zoom.ZOOM_IN)

        # Verifica i valori
        self.assertEqual(self.msg.rdr_mode_command.get_master_mode().value, RdrModes.ACM)
        self.assertEqual(self.msg.param1.get_rws_submode().value, RwsSubmode.RWS_ASM)
        self.assertEqual(self.msg.param2.get_zoom().value, Zoom.ZOOM_IN)
        
class TestGraphicOrder(unittest.TestCase):
    def setUp(self):
        self.graphic_order = GraphicOrder()
    def test_waypoint_01_flag(self):
        self.graphic_order.set_waypoint_01_flag(1)
        self.assertEqual(self.graphic_order.get_waypoint_01_flag(), 1)

    def test_waypoint_02_flag(self):
        self.graphic_order.set_waypoint_02_flag(1)
        self.assertEqual(self.graphic_order.get_waypoint_02_flag(), 1)

    def test_waypoint_03_flag(self):
        self.graphic_order.set_waypoint_03_flag(1)
        self.assertEqual(self.graphic_order.get_waypoint_03_flag(), 1)

    def test_intercept_flight_director(self):
        self.graphic_order.set_intercept_flight_director(1)
        self.assertEqual(self.graphic_order.get_intercept_flight_director(), 1)

    def test_break_away_cue(self):
        self.graphic_order.set_break_away_cue(1)
        self.assertEqual(self.graphic_order.get_break_away_cue(), 1)

    def test_intercept_zones_and_target_tip(self):
        self.graphic_order.set_intercept_zones_and_target_tip(1)
        self.assertEqual(self.graphic_order.get_intercept_zones_and_target_tip(), 1)

    def test_time_to_go_to_cursor(self):
        self.graphic_order.set_time_to_go_to_cursor(1)
        self.assertEqual(self.graphic_order.get_time_to_go_to_cursor(), 1)

    def test_allowable_steering_error_circle(self):
        self.graphic_order.set_allowable_steering_error_circle(1)
        self.assertEqual(self.graphic_order.get_allowable_steering_error_circle(), 1)

    def test_attack_steering_cue(self):
        self.graphic_order.set_attack_steering_cue(1)
        self.assertEqual(self.graphic_order.get_attack_steering_cue(), 1)

    def test_bulls_eye_identifier(self):
        self.graphic_order.set_bulls_eye_identifier(BullsEyeIdentifier.BULLS_EYE_WAYPOINT_02)
        self.assertEqual(self.graphic_order.get_bulls_eye_identifier().value, BullsEyeIdentifier.BULLS_EYE_WAYPOINT_02)

    def test_spare(self):
        self.graphic_order.set_spare(0x10)
        self.assertEqual(self.graphic_order.get_spare(), 0x10)
        
class TestTimeToGoToCursor(unittest.TestCase):
    def test_time_to_go_to_cursor(self):
        time = TimeToGoToCursor()
        time.set(0x1234)
        self.assertEqual(time.get(), 0x1234)

class TestWaypointLatSelQual(unittest.TestCase):
    def setUp(self):
        self.lat_sel_qual = WaypointLatSelQual()
    def test_waypoint_fyt_selection_field(self):
        self.lat_sel_qual.set_waypoint_fyt_selection_field(WaypointFytSelection.FYT)
        self.assertEqual(self.lat_sel_qual.get_waypoint_fyt_selection_field().value, WaypointFytSelection.FYT)

    def test_waypoint_qualifier_validity(self):
        self.lat_sel_qual.set_waypoint_qualifier_validity(1)
        self.assertEqual(self.lat_sel_qual.get_waypoint_qualifier_validity(), 1)

    def test_waypoint_qualifier_value_field(self):
        self.lat_sel_qual.set_waypoint_qualifier_value_field(WaypointQualifierValue.WAYPOINT_DTK)
        self.assertEqual(self.lat_sel_qual.get_waypoint_qualifier_value_field().value, WaypointQualifierValue.WAYPOINT_DTK)

    def test_spare(self):
        self.lat_sel_qual.set_spare(5)
        self.assertEqual(self.lat_sel_qual.get_spare(), 5)
        
class TestWaypointLonCode(unittest.TestCase):
    def test_waypoint_code(self):
        lon_code = WaypointLonCode()
        lon_code.set_waypoint_code(50)
        self.assertEqual(lon_code.get_waypoint_code(), 50)
        
class TestMsgGraphicSetting(unittest.TestCase):
    def test_msg_graphic_setting(self):
        msg = MsgGraphicSetting()

        # Imposta alcuni valori di esempio
        msg.graphic_order.set_waypoint_01_flag(1)
        msg.time_to_go_to_cursor.set(100)

        # Verifica i valori
        self.assertEqual(msg.graphic_order.get_waypoint_01_flag(), 1)
        self.assertEqual(msg.time_to_go_to_cursor.get(), 100)

class TestA4ValidityAndSlew(unittest.TestCase):
    def setUp(self):
        self.validity = A4ValidityAndSlew()
    def test_navigation_invalid(self):
        self.validity.set_navigation_invalid(1)
        self.assertEqual(self.validity.get_navigation_invalid(), 1)

    def test_attitude_invalid(self):
        self.validity.set_attitude_invalid(1)
        self.assertEqual(self.validity.get_attitude_invalid(), 1)

    def test_baro_intertial_altitude_invalid(self):
        self.validity.set_baro_intertial_altitude_invalid(1)
        self.assertEqual(self.validity.get_baro_intertial_altitude_invalid(), 1)

    def test_correct_baro_altitude_invalid(self):
        self.validity.set_correct_baro_altitude_invalid(1)
        self.assertEqual(self.validity.get_correct_baro_altitude_invalid(), 1)

    def test_radio_altimeter_invalid(self):
        self.validity.set_radio_altimeter_invalid(1)
        self.assertEqual(self.validity.get_radio_altimeter_invalid(), 1)

    def test_spoi_altitude_invalid(self):
        self.validity.set_spoi_altitude_invalid(1)
        self.assertEqual(self.validity.get_spoi_altitude_invalid(), 1)

    def test_spoi_position_invalid(self):
        self.validity.set_spoi_position_invalid(1)
        self.assertEqual(self.validity.get_spoi_position_invalid(), 1)

    def test_tas_invalid(self):
        self.validity.set_tas_invalid(1)
        self.assertEqual(self.validity.get_tas_invalid(), 1)

    def test_cas_invalid(self):
        self.validity.set_cas_invalid(1)
        self.assertEqual(self.validity.get_cas_invalid(), 1)

    def test_present_position_invalid(self):
        self.validity.set_present_position_invalid(1)
        self.assertEqual(self.validity.get_present_position_invalid(), 1)

    def test_ant_slew_valid(self):
        self.validity.set_ant_slew_valid(1)
        self.assertEqual(self.validity.get_ant_slew_valid(), 1)

    def test_crs_rate_invalid(self):
        self.validity.set_crs_rate_invalid(1)
        self.assertEqual(self.validity.get_crs_rate_invalid(), 1)

    def test_crs_normal_slave(self):
        self.validity.set_crs_normal_slave(1)
        self.assertEqual(self.validity.get_crs_normal_slave(), 1)

    def test_crs_zero_valid_field(self):
        self.validity.set_crs_zero_valid_field(1)
        self.assertEqual(self.validity.get_crs_zero_valid_field(), 1)

    def test_crs_snowplough_valid_field(self):
        self.validity.set_crs_snowplough_valid_field(1)
        self.assertEqual(self.validity.get_crs_snowplough_valid_field(), 1)
        
class TestCrsMotionX(unittest.TestCase):
    def setUp(self):
        self.crs_motion_x = CrsMotionX()
    def test_rate(self):
        self.crs_motion_x.set_rate(255)
        self.assertEqual(self.crs_motion_x.get_rate(), 255)

    def test_ghost(self):
        self.crs_motion_x.set_ghost(CrsGhostSelector.GHOST_SEL)
        self.assertEqual(self.crs_motion_x.get_ghost().value, CrsGhostSelector.GHOST_SEL)

    def test_dtt(self):
        self.crs_motion_x.set_dtt(CrsDttSelector.DTT_SEL)
        self.assertEqual(self.crs_motion_x.get_dtt().value, CrsDttSelector.DTT_SEL)

    def test_sar(self):
        self.crs_motion_x.set_sar(CrsSarSelector.SAR_SEL)
        self.assertEqual(self.crs_motion_x.get_sar().value, CrsSarSelector.SAR_SEL)

    def test_abs_pos(self):
        self.crs_motion_x.set_abs_pos(1)
        self.assertEqual(self.crs_motion_x.get_abs_pos(), 1)

    def test_abs_pos_rate(self):
        self.crs_motion_x.set_abs_pos_rate(100)
        self.assertEqual(self.crs_motion_x.get_abs_pos_rate(), 100)
        
class TestCrsMotionY(unittest.TestCase):
    def setUp(self):
        self.crs_motion_y = CrsMotionY()    

    def test_rate(self):
        self.crs_motion_y.set_rate(255)
        self.assertEqual(self.crs_motion_y.get_rate(), 255)

    def test_abs_pos(self):
        self.crs_motion_y.set_abs_pos(1)
        self.assertEqual(self.crs_motion_y.get_abs_pos(), 1)
        
class TestMsgNavDataAndCursor(unittest.TestCase):
    def test_msg_nav_data_and_cursor(self):
        msg = MsgNavDataAndCursor()

        # Imposta alcuni valori di esempio
        msg.validity_and_slew.set_navigation_invalid(1)
        msg.acq_crs_x.set_rate(100)
        msg.acq_crs_y.set_rate(50)

        # Verifica i valori
        self.assertEqual(msg.validity_and_slew.get_navigation_invalid(), 1)
        self.assertEqual(msg.acq_crs_x.get_rate(), 100)
        self.assertEqual(msg.acq_crs_y.get_rate(), 50)
        
def test_msg_nav_data_and_cursor(self):
    msg = MsgNavDataAndCursor()

    # Imposta alcuni valori di esempio
    msg.validity_and_slew.set_navigation_invalid(1)
    msg.acq_crs_x.set_rate(100)
    msg.acq_crs_y.set_rate(50)
    msg.true_heading.set(180)

    # Verifica i valori
    self.assertEqual(msg.validity_and_slew.get_navigation_invalid(), 1)
    self.assertEqual(msg.acq_crs_x.get_rate(), 100)
    self.assertEqual(msg.acq_crs_y.get_rate(), 50)
    expected_heading = 180 * math.pi / 180
    if expected_heading > math.pi:
        expected_heading -= 2 * math.pi
    self.assertAlmostEqual(msg.true_heading.get(), expected_heading, places=5)
    
class TestMsgInuHighSpeed(unittest.TestCase):
    def test_msg_inu_high_speed(self):
        msg = MsgInuHighSpeed()

        # Imposta alcuni valori di esempio
        msg.timetag.set(1000)   # 1000 unità di 64 usec
        msg.x_vel.set(10.5)
        msg.y_vel.set(-5.2)
        msg.z_vel.set(0.0)
        msg.platform_azimuth.set(45)

        # Verifica i valori
        
        self.assertEqual(msg.timetag.get(), 1000) # Verifica che il valore sia 1000
        self.assertAlmostEqual(msg.x_vel.get(), 10.5, places=5)
        self.assertAlmostEqual(msg.y_vel.get(), -5.2, places=5)
        self.assertAlmostEqual(msg.z_vel.get(), 0.0, places=5)
        self.assertAlmostEqual(msg.platform_azimuth.get(), 45 , places=5)
        
class TestDlTargetValidity(unittest.TestCase):
    def test_dl_target_validity(self):
        dl_validity = DlTargetValidity()
        dl_validity.set_dl_target_validity_01(1)
        self.assertEqual(dl_validity.get_dl_target_validity_01(), 1)
        dl_validity.set_dl_target_validity_02(1)
        self.assertEqual(dl_validity.get_dl_target_validity_02(), 1)
        dl_validity.set_dl_target_validity_03(1)
        self.assertEqual(dl_validity.get_dl_target_validity_03(), 1)
        dl_validity.set_dl_target_validity_04(1)
        self.assertEqual(dl_validity.get_dl_target_validity_04(), 1)
        dl_validity.set_dl_target_validity_05(1)
        self.assertEqual(dl_validity.get_dl_target_validity_05(), 1)
        dl_validity.set_dl_target_validity_06(1)
        self.assertEqual(dl_validity.get_dl_target_validity_06(), 1)
        dl_validity.set_dl_target_validity_07(1)
        self.assertEqual(dl_validity.get_dl_target_validity_07(), 1)
        dl_validity.set_dl_target_validity_08(1)
        self.assertEqual(dl_validity.get_dl_target_validity_08(), 1)
        dl_validity.set_dl_target_validity_09(1)
        self.assertEqual(dl_validity.get_dl_target_validity_09(), 1)
        dl_validity.set_dl_target_validity_10(1)
        self.assertEqual(dl_validity.get_dl_target_validity_10(), 1)
        dl_validity.set_spare(1)
        self.assertEqual(dl_validity.get_spare(), 1)

class TestTargetPresentationData(unittest.TestCase):
    def test_target_presentation_data(self):
        target_presentation_data = TargetPresentationData()
        target_presentation_data.set_dl_target_type_selector(DlTargetTypeSelector.DL_HIGH_PRIORITY_TARGET)
        self.assertEqual(target_presentation_data.get_dl_target_type_selector().value, DlTargetTypeSelector.DL_HIGH_PRIORITY_TARGET)

class TestTargetHalfCallSign(unittest.TestCase):
    def test_target_half_call_sign(self):
        target_half_call_sign = TargetHalfCallSign()
        target_half_call_sign.set_character1_msw(65)
        target_half_call_sign.set_character2_msw(66)
        self.assertEqual(target_half_call_sign.get_character1_msw(), 65)
        self.assertEqual(target_half_call_sign.get_character2_msw(), 66)

class TestMsg1DataLinkTarget(unittest.TestCase):
    def test_msg1_data_link_target(self):
        msg = Msg1DataLinkTarget()

        # Imposta alcuni valori di esempio
        msg.dl_target_validity.set_dl_target_validity_01(1)
        msg.tgt_01_pos_x.set(100)
        msg.tgt_01_pos_y.set(50)
        msg.tgt_01_ground_track_angle.set(45)
        msg.tgt_01_presentation_data.set_dl_target_type_selector(DlTargetTypeSelector.DL_HIGH_PRIORITY_TARGET)
        msg.tgt_01_call_sign[0].set_character1_msw(65)
        msg.tgt_01_call_sign[0].set_character2_msw(66)
        msg.tgt_01_call_sign[1].set_character1_msw(67)
        msg.tgt_01_call_sign[1].set_character2_msw(68)

        # Verifica i valori
        self.assertEqual(msg.dl_target_validity.get_dl_target_validity_01(), 1)
        self.assertAlmostEqual(msg.tgt_01_pos_x.get(), (100/100) * ICD1553_DL_POSITION_METERS_LSB * 32767, places=4)
        self.assertAlmostEqual(msg.tgt_01_pos_y.get(), (50/100) * ICD1553_DL_POSITION_METERS_LSB * 32767, places=4)
        self.assertEqual(msg.tgt_01_ground_track_angle.get(), 45)
        self.assertEqual(msg.tgt_01_presentation_data.get_dl_target_type_selector().value, DlTargetTypeSelector.DL_HIGH_PRIORITY_TARGET)
        self.assertEqual(msg.tgt_01_call_sign[0].get_character1_msw(), 65)
        self.assertEqual(msg.tgt_01_call_sign[0].get_character2_msw(), 66)
        self.assertEqual(msg.tgt_01_call_sign[1].get_character1_msw(), 67)
        self.assertEqual(msg.tgt_01_call_sign[1].get_character2_msw(), 68)
        
class TestMsg2DataLinkTarget(unittest.TestCase):
    def test_msg2_data_link_target(self):
        msg = Msg2DataLinkTarget()

        # Imposta alcuni valori di esempio
        msg.tgt_06_pos_x.set(100)
        msg.tgt_06_pos_y.set(50)
        msg.tgt_06_ground_track_angle.set(45)
        msg.tgt_06_presentation_data.set_dl_target_type_selector(DlTargetTypeSelector.DL_HIGH_PRIORITY_TARGET)
        msg.tgt_06_call_sign[0].set_character1_msw(65)
        msg.tgt_06_call_sign[0].set_character2_msw(66)
        msg.tgt_06_call_sign[1].set_character1_msw(67)
        msg.tgt_06_call_sign[1].set_character2_msw(68)

        # Verifica i valori
        self.assertAlmostEqual(msg.tgt_06_pos_x.get(), (100/100) * ICD1553_DL_POSITION_METERS_LSB * 32767, places=4)
        self.assertAlmostEqual(msg.tgt_06_pos_y.get(), (50/100) * ICD1553_DL_POSITION_METERS_LSB * 32767, places=4)
        self.assertEqual(msg.tgt_06_ground_track_angle.get(), 45)
        self.assertEqual(msg.tgt_06_presentation_data.get_dl_target_type_selector().value, DlTargetTypeSelector.DL_HIGH_PRIORITY_TARGET)
        self.assertEqual(msg.tgt_06_call_sign[0].get_character1_msw(), 65)
        self.assertEqual(msg.tgt_06_call_sign[0].get_character2_msw(), 66)
        self.assertEqual(msg.tgt_06_call_sign[1].get_character1_msw(), 67)
        self.assertEqual(msg.tgt_06_call_sign[1].get_character2_msw(), 68)
        
class TestMsgReserved(unittest.TestCase):
    def test_msg_reserved(self):
        msg = MsgReserved()

        # Imposta alcuni valori di esempio
        msg.raw[0] = 0x1234
        msg.raw[1] = 0x5678
        msg.raw[31] = 0x9ABC

        # Verifica i valori
        self.assertEqual(msg.raw[0], 0x1234)
        self.assertEqual(msg.raw[1], 0x5678)
        self.assertEqual(msg.raw[31], 0x9ABC)
        
class TestMsgDev0Reserved(unittest.TestCase):
    def test_msg_dev0_reserved(self):
        msg = MsgDev0Reserved()

        # Imposta alcuni valori di esempio
        msg.marker = 0x1234
        msg.dbg_ctrl = 0x5678
        msg.dbg_mode = 0x9ABC
        msg.gc_dbg_ctrl = 0xDEF0
        msg.gc_dbg_crs_xy = 0x1357
        msg.raw[0] = 0x2468
        msg.raw[26] = 0x3579

        # Verifica i valori
        self.assertEqual(msg.marker, 0x1234)
        self.assertEqual(msg.dbg_ctrl, 0x5678)
        self.assertEqual(msg.dbg_mode, 0x9ABC)
        self.assertEqual(msg.gc_dbg_ctrl, 0xDEF0)
        self.assertEqual(msg.gc_dbg_crs_xy, 0x1357)
        self.assertEqual(msg.raw[0], 0x2468)
        self.assertEqual(msg.raw[26], 0x3579)
        
class TestTwsStatusAndTargets0102(unittest.TestCase):
    def test_tws_status_and_targets_01_02(self):
        msg = TwsStatusAndTargets0102()

        # Imposta alcuni valori di esempio
        msg.valitidy_word_and_hpt_identifier.set_track_01_validity(1)
        msg.track_priority_01_04.set_track_01_priority_field(TrackPriority.PRIORITY_LEVEL_2)
        #msg.target_01_position_x.set(100)
        #msg.target_01_position_y.set(50)

        # Verifica i valori
        self.assertEqual(msg.valitidy_word_and_hpt_identifier.get_track_01_validity().value, 1)
        self.assertEqual(msg.track_priority_01_04.get_track_01_priority_field().value, TrackPriority.PRIORITY_LEVEL_2)
        #self.assertEqual(msg.target_01_position_x.get(), 100)
        #self.assertEqual(msg.target_01_position_y.get(), 50)

if __name__ == '__main__':
    unittest.main()