/* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration */
void SpeedSupervision_Integration_SpeedSupervision_Integration_Pkg(
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::MRSP */ MRSP_Profile_t *MRSP,
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::MA */ MAs_t *MA,
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::NationalValues */ P3_NationalValues_T_Packet_Types_Pkg *NationalValues,
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::TrainPosition */ trainPosition_T_TrainPosition_Types_Pck *TrainPosition,
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::odometry */ odometry_T_Obu_BasicTypes_Pkg *odometry,
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::m_level */ M_LEVEL m_level,
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::trainProps */ trainProperties_T_TrainPosition_Types_Pck *trainProps,
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::MA_updated */ kcg_bool MA_updated,
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::MRSP_updated */ kcg_bool MRSP_updated,
  outC_SpeedSupervision_Integration_SpeedSupervision_Integration_Pkg *outC)
{
  Speeds_T_SDM_Types_Pkg tmp;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::odometry_internal */ Odometry_real_T_SDM_Types_Pkg odometry_internal;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::V_ura_internal */ V_internal_real_Type_SDM_Types_Pkg V_ura_internal;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::targetCollection */ TargetCollection_T_TargetManagement_types targetCollection;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::Trainlocations_internal */ TrainLocations_real_T_SDM_Types_Pkg Trainlocations_internal;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::MRSP_internal */ MRSP_internal_T_TargetManagement_types MRSP_internal;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::v_mrsp_internal */ V_internal_real_Type_SDM_Types_Pkg v_mrsp_internal;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::v_target_internal */ V_internal_real_Type_SDM_Types_Pkg v_target_internal;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::mrt_internal */ Target_real_T_TargetManagement_types mrt_internal;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::v_p_sbd */ V_internal_real_Type_SDM_Types_Pkg v_p_sbd;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::v_p_ebd */ V_internal_real_Type_SDM_Types_Pkg v_p_ebd;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::v_p_ebd_valid */ kcg_bool v_p_ebd_valid;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L27 */ M_LEVEL _L27;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L55 */ MAs_real_T_TargetManagement_types _L55;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L70 */ NationalValues_real_T_SDM_Types_Pkg _L70;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L74 */ V_internal_real_Type_SDM_Types_Pkg _L74;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L113 */ kcg_bool _L113;
  /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L111 */ SDM_Locations_T_SDM_Types_Pkg _L111;
  
  /* 1 */
  SDM_InputWrapper_SDM_Input_Wrappers(
    NationalValues,
    TrainPosition,
    odometry,
    m_level,
    trainProps,
    MRSP,
    MA,
    MA_updated,
    MRSP_updated,
    &_L27,
    &MRSP_internal,
    &_L55,
    &odometry_internal,
    &V_ura_internal,
    &Trainlocations_internal,
    &v_p_ebd_valid,
    &_L113,
    &_L70);
  /* 2 */
  TargetManagement_TargetManagement_pkg(
    &MRSP_internal,
    _L113,
    &_L55,
    v_p_ebd_valid,
    &Trainlocations_internal,
    &outC->Context_2);
  kcg_copy_TargetCollection_T_TargetManagement_types(
    &targetCollection,
    &outC->Context_2.targetCollection);
  _L74 = /* 1 */
    ReleaseSpeed_Selection_SDM_ReleaseSoeed_Selection_pkg(
      outC->Context_2.V_releaseFromMA,
      &_L70,
      outC->Context_2.V_releaseFromMAValid);
  /* 1 */
  CalcBrakingCurves_integration_CalcBrakingCurves_Pkg(
    (ASafe_T_CalcBrakingCurves_types *) &TestcaseA_safe_CalcBrakingCurves_Pkg,
    &Trainlocations_internal,
    &targetCollection,
    &outC->Context_1);
  /* 4 */
  SDMLimitLocations_TargetLimits_Pkg(
    &MRSP_internal,
    &odometry_internal,
    &Trainlocations_internal,
    &targetCollection,
    &outC->Context_1.curveCollection,
    _L74,
    V_ura_internal,
    _L70.q_nvinhsmicperm,
    kcg_false,
    0.0,
    0.0,
    0.0,
    &_L111,
    &mrt_internal,
    &_L113,
    &v_target_internal,
    &v_mrsp_internal,
    &v_p_sbd,
    &v_p_ebd,
    &v_p_ebd_valid);
  /* 1 */
  CalcSpeeds_SDM_Types_Pkg(
    &odometry_internal,
    v_mrsp_internal,
    _L74,
    v_target_internal,
    &mrt_internal,
    v_p_ebd,
    v_p_sbd,
    v_p_ebd_valid,
    _L111.FLOI_of_V_est,
    &tmp);
  /* 1 */
  SDM_Commands_SDM_Commands_Pkg(
    &targetCollection,
    &odometry_internal,
    &tmp,
    &_L111,
    kcg_true,
    _L27,
    &mrt_internal,
    &Trainlocations_internal,
    _L113,
    &outC->_1_Context_1);
  /* 1 */
  SDM_OutputWrapper_SDM_OutputWrapper(
    &outC->_1_Context_1.sdmCmd,
    outC->_1_Context_1.targetSpeedReached,
    outC->_1_Context_1.eoaOverpassed,
    0.0,
    &mrt_internal,
    &odometry_internal,
    &_L70,
    kcg_false,
    &outC->_2_Context_1);
  kcg_copy_speedSupervisionForDMI_T_DMI_Types_Pkg(
    &outC->sdmToDMI,
    &outC->_2_Context_1.sdmToDMI);
  kcg_copy_Target_T_TargetManagement_types(
    &outC->target,
    &outC->_2_Context_1.out_target);
  kcg_copy_SDM_Commands_T_SDM_Types_Pkg(
    &outC->sdmCommands,
    &outC->_2_Context_1.sdmCommands);
  kcg_copy_Brake_command_T_TIU_Types_Pkg(
    &outC->brakeCmd,
    &outC->_2_Context_1.brakeCmd);
  outC->EOA_overpassed = outC->_2_Context_1.EOA_overpassed;
  outC->Target_Speed_Reached = outC->_2_Context_1.Target_Speed_Reached;
}
/* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration */
void SpeedSupervision_Integration_SpeedSupervision_Integration_Pkg(
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::NationalValues */ P3_NationalValues_T_Packet_Types_Pkg *NationalValues,
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::TrainPosition */ trainPosition_T_TrainPosition_Types_Pck *TrainPosition,
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::odometry */ odometry_T_Obu_BasicTypes_Pkg *odometry,
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::trainProps */ trainProperties_T_TrainPosition_Types_Pck *trainProps,
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::trainData */ trainData_T_TIU_Types_Pkg *trainData,
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::dataFromTrackAtlas */ DataForSupervision_nextGen_t_TrackAtlasTypes *dataFromTrackAtlas,
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::Service_brake_requested_by_modes_and_levels */ kcg_bool Service_brake_requested_by_modes_and_levels,
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::Emergency_brake_requested_by_modes_and_levels */ kcg_bool Emergency_brake_requested_by_modes_and_levels,
    outC_SpeedSupervision_Integration_SpeedSupervision_Integration_Pkg *outC)
{
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration */
    static ASafe_T_CalcBrakingCurves_types tmp1;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration */
    static ASafe_T_CalcBrakingCurves_types tmp;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::targetCollection */
    static TargetCollection_T_TargetManagement_types targetCollection;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::Trainlocations_internal */
    static TrainLocations_real_T_SDM_Types_Pkg Trainlocations_internal;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::MRSP_internal */
    static MRSP_internal_T_TargetManagement_types MRSP_internal;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::MA_internal */
    static MA_section_real_T_TargetManagement_types MA_internal;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::trainData_extras */
    static trainData_internal_t_SDM_Types_Pkg trainData_extras;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::T_b */
    static t_Brake_t_SDMModelPkg T_b;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L114 */
    static kcg_bool _L114;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L112 */
    static SDM_Locations_T_SDM_Types_Pkg _L112;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L111 */
    static Speeds_T_SDM_Types_Pkg _L111;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L187 */
    static ASafe_T_CalcBrakingCurves_types _L187;
    /* SpeedSupervision_Integration_Pkg::SpeedSupervision_Integration::_L190 */
    static A_gradient_t_SDM_GradientAcceleration_types _L190;

    trainData_extras.isSB_CmdAvailable = kcg_true;
    trainData_extras.isTCOAvailable = kcg_true;
    trainData_extras.T_traction_cut_off = 800;
    /* 1 */
    SDM_InputWrapper_SDM_Input_Wrappers(
        TrainPosition,
        trainProps,
        dataFromTrackAtlas,
        &outC->Context_1);
    trainData_extras.offsetAntennaL1 = outC->Context_1.offsetAntennaL1;
    kcg_copy_MRSP_internal_T_TargetManagement_types(
        &MRSP_internal,
        &outC->Context_1.mrsp_out);
    kcg_copy_MA_section_real_T_TargetManagement_types(
        &MA_internal,
        &outC->Context_1.ma_out);
    kcg_copy_TrainLocations_real_T_SDM_Types_Pkg(
        &Trainlocations_internal,
        &outC->Context_1.trainLocations);
    /* 2 */
    TargetManagement_TargetManagement_pkg(
        &MRSP_internal,
        outC->Context_1.mrsp_update_out,
        &MA_internal,
        outC->Context_1.ma_update_out,
        &Trainlocations_internal,
        &outC->Context_2);
    kcg_copy_TargetCollection_T_TargetManagement_types(
        &targetCollection,
        &outC->Context_2.targetCollection);
    /* 1 */
    ABrakeFactory_SDMModelPkg(trainData, NationalValues, &T_b, &tmp, &_L187);
    /* 1 */
    AGradient_SDM_GradientAcceleration_Pkg(
        &Trainlocations_internal,
        &outC->Context_1.gp_out,
        outC->Context_1.gp_update_out,
        trainData,
        &targetCollection,
        &outC->_1_Context_1);
    kcg_copy_A_gradient_t_SDM_GradientAcceleration_types(
        &_L190,
        &outC->_1_Context_1.A_gradient);
    switch ((*NationalValues).q_nvsbfbperm) {
    case Q_NVSBFBPERM_Yes :
        trainData_extras.isSB_FBAvailable = kcg_true;
        break;

    default :
        trainData_extras.isSB_FBAvailable = kcg_false;
    }
    /* 3 */ addGradient_SDMModelPkg(&tmp, &_L190, &tmp1);
    /* 1 */ addGradient_SDMModelPkg(&_L187, &_L190, &tmp);
    /* 1 */
    CalcBrakingCurves_integration_CalcBrakingCurves_Pkg(
        &Trainlocations_internal,
        &targetCollection,
        &tmp1,
        &tmp,
        &outC->_2_Context_1);
    /* 4 */
    SDMLimitLocations_TargetLimits_Pkg(
        &MRSP_internal,
        odometry,
        &Trainlocations_internal,
        &targetCollection,
        &outC->_2_Context_1.curveCollection,
        &MA_internal,
        &T_b,
        NationalValues,
        &trainData_extras,
        &_L111,
        &_L112,
        &outC->target,
        &_L114);
    /* 1 */
    SDM_Commands_SDM_Commands_Pkg(
        &targetCollection,
        TrainPosition,
        &_L111,
        &_L112,
        &outC->target,
        _L114,
        Service_brake_requested_by_modes_and_levels,
        (kcg_bool)
        (Emergency_brake_requested_by_modes_and_levels | /* 1 */
         SimpleValidityCheck_SDM_Input_Wrappers(
             NationalValues,
             odometry,
             TrainPosition,
             trainData,
             dataFromTrackAtlas)),
        NationalValues,
        &trainData_extras,
        &outC->_3_Context_1);
    kcg_copy_speedSupervisionForDMI_T_DMI_Types_Pkg(
        &outC->sdmToDMI,
        &outC->_3_Context_1.sdmToDMI);
    kcg_copy_SDM_Commands_T_SDM_Types_Pkg(
        &outC->sdmCommands,
        &outC->_3_Context_1.sdmCmd);
    outC->Target_Speed_Reached = outC->_3_Context_1.targetSpeedReached;
    outC->EOA_overpassed = outC->_3_Context_1.eoaOverpassed;
    kcg_copy_Brake_command_T_TIU_Types_Pkg(
        &outC->brakeCmd,
        &outC->_3_Context_1.brakeCmd);
}