/* US_Integration_June::Amsterdam_Utrecht */
void Amsterdam_Utrecht_US_Integration_June(void)
{
  Ctxt_Amsterdam_Utrecht_US_Integration_June._L2 = TrainPos;
  /* 1 */
  Amsterdam_Utrecht_Lijn1_b_AmsterdamUtrechtL2_AmsterdamUtrechtTrack1(
    Ctxt_Amsterdam_Utrecht_US_Integration_June._L2,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June.Context_1);
  kcg_copy_CompressedBaliseMessage_TM(
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L1,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June.Context_1.BaliseMessage);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L6,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L1.Messages);
  Ctxt_Amsterdam_Utrecht_US_Integration_June._L13 = Trigger_in;
  /* 1 */
  Amsterdam_Utrecht_RBC_Int_US_Integration_June(
    Ctxt_Amsterdam_Utrecht_US_Integration_June._L13,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._1_Context_1);
  kcg_copy_Radio_TrackTrain_Header_T_Radio_Types_Pkg(
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L8,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._1_Context_1.RadioTrackTrainHeader_out);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L9,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._1_Context_1.Compressed_Packets_out);
  kcg_copy_CompressedRadioMessage_TM(
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L10,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._1_Context_1.Compressed_Radio_Message_out);
  kcg_copy_CompressedRadioMessage_TM(
    &Compressed_Radio_Message_out,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L10);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(
    &Compressed_Packets_out,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L9);
  kcg_copy_Radio_TrackTrain_Header_T_Radio_Types_Pkg(
    &RadioTrackTrainHeader_out,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L8);
  kcg_copy_BaliseTelegramHeader_int_T_TM(
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L5,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L1.Header);
  /* 1 */
  CASTLIB_BaliseHeaders_TM_conversions(
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L5,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._2_Context_1);
  kcg_copy_TelegramHeader_T_BG_Types_Pkg(
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L7,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._2_Context_1.Out);
  kcg_copy_TelegramHeader_T_BG_Types_Pkg(
    &Balise_Header,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L7);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(
    &Balise_Packets,
    &Ctxt_Amsterdam_Utrecht_US_Integration_June._L6);
}
/* RBC_Messaging_Pkg::RBC_RadioTrackTrainFactory_Pkg::RadioTrackTrainFactory__CreateDefaultMsg_BSL2 */
void RadioTrackTrainFactory__CreateDefaultMsg_BSL2_RBC_Messaging_Pkg_RBC_RadioTrackTrainFactory_Pkg(
  /* RBC_Messaging_Pkg::RBC_RadioTrackTrainFactory_Pkg::RadioTrackTrainFactory__CreateDefaultMsg_BSL2::outRadioTrackTrainMessage */CompressedRadioMessage_TM *outRadioTrackTrainMessage)
{
  kcg_copy_CompressedRadioMessage_TM(
    outRadioTrackTrainMessage,
    (CompressedRadioMessage_TM *) &RADIO_TRACK_TRAIN_MESSAGE_DEFAULT);
}
/* GreenDemonstrator::Trackside::Trackside */
void Trackside_GreenDemonstrator_Trackside(
  inC_Trackside_GreenDemonstrator_Trackside *inC,
  outC_Trackside_GreenDemonstrator_Trackside *outC)
{
  CompressedRadioMessage_TM tmp;
  /* GreenDemonstrator::Trackside::Trackside::_L12 */ CompressedPackets_T_Common_Types_Pkg _L12;
  /* GreenDemonstrator::Trackside::Trackside::_L13 */ TelegramHeader_T_BG_Types_Pkg _L13;
  /* GreenDemonstrator::Trackside::Trackside::_L14 */ Radio_TrackTrain_Header_T_Radio_Types_Pkg _L14;
  /* GreenDemonstrator::Trackside::Trackside::_L15 */ CompressedPackets_T_Common_Types_Pkg _L15;
  
  if (outC->init) {
    outC->init = kcg_false;
    kcg_copy_CompressedRadioMessage_TM(
      &tmp,
      (CompressedRadioMessage_TM *) &RADIO_TRACK_TRAIN_MESSAGE_DEFAULT);
  }
  else {
    kcg_copy_CompressedRadioMessage_TM(&tmp, &outC->_L16);
  }
  /* 1 */
  RBC_New_RBC_Model_Pkg(
    (DynamicConfig_T *) &DYNAMIC_CONFIG_UTRECHT_AMSTERDAM,
    &inC->TrainTrackMessageIn,
    &tmp,
    &outC->_1_Context_1);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(
    &outC->RadioPackets_out,
    &outC->_1_Context_1.outRadioTrackTrainMessage.Messages);
  kcg_copy_Radio_TrackTrain_Header_T_TM(
    &outC->RadioMessage_out,
    &outC->_1_Context_1.outRadioTrackTrainMessage.Header);
  /* 1 */
  UtrechtAmsterdamScenarioStory00AWrapper_RBC_Scenario_Pkg(
    &outC->_1_Context_1.outSessionManagement,
    &outC->_1_Context_1.outClock,
    &outC->Context_1);
  /* 1 */
  Story_Complete_Toolbox_Functions(
    (kcg_real) inC->TrainPosition / 100.0,
    outC->Context_1.outTriggerId,
    &_L12,
    &_L13,
    &_L14,
    &_L15,
    &outC->_L16,
    &outC->BaliseMessage);
}
/* RBC_Messaging_Pkg::RBC_RadioTrackTrain_Pkg::RadioTrackTrainMessage__SetHeader */
void RadioTrackTrainMessage__SetHeader_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
  /* RBC_Messaging_Pkg::RBC_RadioTrackTrain_Pkg::RadioTrackTrainMessage__SetHeader::inRadioTrackTrainMessage */CompressedRadioMessage_TM *inRadioTrackTrainMessage,
  /* RBC_Messaging_Pkg::RBC_RadioTrackTrain_Pkg::RadioTrackTrainMessage__SetHeader::inRadioTrackTrainHeader */Radio_TrackTrain_Header_T_TM *inRadioTrackTrainHeader,
  /* RBC_Messaging_Pkg::RBC_RadioTrackTrain_Pkg::RadioTrackTrainMessage__SetHeader::outRadioTrackTrainMessage */CompressedRadioMessage_TM *outRadioTrackTrainMessage)
{
  kcg_copy_CompressedRadioMessage_TM(
    outRadioTrackTrainMessage,
    inRadioTrackTrainMessage);
  kcg_copy_Radio_TrackTrain_Header_T_TM(
    &(*outRadioTrackTrainMessage).Header,
    inRadioTrackTrainHeader);
}
/* RBC_Model_Pkg::RBC__PingTrain */
void RBC__PingTrain_RBC_Model_Pkg(
  /* RBC_Model_Pkg::RBC__PingTrain::inForceTrigger */kcg_bool inForceTrigger,
  /* RBC_Model_Pkg::RBC__PingTrain::inDataBus */RBC_Data_T_RBC_DataBus_Pkg *inDataBus,
  /* RBC_Model_Pkg::RBC__PingTrain::inRadioTrainTrackMessage */Radio_TrainTrack_Message_T_Radio_Types_Pkg *inRadioTrainTrackMessage,
  /* RBC_Model_Pkg::RBC__PingTrain::inTriggeredRadioTrackTrainMessage */CompressedRadioMessage_TM *inTriggeredRadioTrackTrainMessage,
  outC_RBC__PingTrain_RBC_Model_Pkg *outC)
{
  static Radio_TrackTrain_Header_T_TM tmp5;
  static NationalParams_T tmp4;
  static RadioTrackTrainMessageQueueEntry_T tmp3;
  static CompressedRadioMessage_TM tmp2;
  static NID_LRBG tmp1;
  static P042_trackside_int_T_TM tmp;
  /* RBC_Model_Pkg::RBC__PingTrain::IfBlock1::then::_L87 */
  static kcg_bool _L87_IfBlock1;
  /* RBC_Model_Pkg::RBC__PingTrain::IfBlock1::then::_L79 */
  static M_LEVEL _L79_IfBlock1;
  /* RBC_Model_Pkg::RBC__PingTrain::IfBlock1::then::_L21 */
  static PosData_T _L21_IfBlock1;
  /* RBC_Model_Pkg::RBC__PingTrain::Level_2_or_3 */
  static kcg_bool last_Level_2_or_3;
  /* RBC_Model_Pkg::RBC__PingTrain::trigger */
  static kcg_bool trigger;
  
  kcg_copy_CompressedRadioMessage_TM(
    &outC->outTriggeredRadioTrackTrainMessage,
    inTriggeredRadioTrackTrainMessage);
  kcg_copy_Radio_TrainTrack_Message_T_Radio_Types_Pkg(
    &outC->outRadioTrainTrackMessage,
    inRadioTrainTrackMessage);
  if (outC->init) {
    last_Level_2_or_3 = kcg_false;
  }
  else {
    last_Level_2_or_3 = outC->Level_2_or_3;
  }
  trigger = /* 2 */
    RadioTrackTrainMessage__IsValid_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
      &(*inDataBus).lastSentTrackTrainMessage);
  if (trigger) {
    /* 2 */
    RadioTrackTrainMessage__GetHeader_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
      &(*inDataBus).lastSentTrackTrainMessage,
      &tmp5);
    outC->lastRadioTrackTrainMessageWasSentTimestamp = /* 2 */
      RadioTrackTrainHeader__Get_T_TRAIN_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
        &tmp5);
  }
  else if (outC->init) {
    outC->lastRadioTrackTrainMessageWasSentTimestamp = T_TRAIN_MIN;
  }
  outC->init = kcg_false;
  /* 1 */
  DynamicConfig__GetNationalParams_RBC_Config_Pkg(&(*inDataBus).config, &tmp4);
  tmp1 = /* 1 */ NationalParams__Get_T_NVCONTACT_RBC_Config_Pkg(&tmp4);
  trigger = inForceTrigger | ((/* 1 */
        RadioTrackTrainMessageQueue__GetRemainingCapacity_RBC_Collections_Pkg(
          &(*inDataBus).messageQueue) ==
        RADIO_TRACK_TRAIN_MESSAGE_QUEUE_CAPACITY) & (/* 1 */
        Clock__GetSeconds_RBC_Time_Pkg(&(*inDataBus).clockk) -
        outC->lastRadioTrackTrainMessageWasSentTimestamp >= T_NVCONTACT_FACTOR *
        tmp1) & ((tmp1 > T_NVCONTACT_DEFAULT) & (tmp1 <
          T_NVCONTACT_UNLIMITED)));
  kcg_copy_RBC_Data_T_RBC_DataBus_Pkg(&outC->outDataBus, inDataBus);
  if (trigger) {
    /* 11 */
    SessionManagement__GetPosData_RBC_Session_Pkg(
      &(*inDataBus).session,
      &_L21_IfBlock1);
    _L79_IfBlock1 = /* 8 */
      PosData__Get_M_LEVEL_RBC_Session_Pkg(&_L21_IfBlock1);
    _L87_IfBlock1 = (M_LEVEL_Level_3 == _L79_IfBlock1) | (_L79_IfBlock1 ==
        M_LEVEL_Level_2);
    outC->Level_2_or_3 = _L87_IfBlock1;
    tmp1 = /* 3 */ PosData__Get_NID_LRBG_RBC_Session_Pkg(&_L21_IfBlock1);
    if ((!_L87_IfBlock1 & last_Level_2_or_3) | inForceTrigger) {
      kcg_copy_P042_trackside_int_T_TM(
        &tmp,
        (P042_trackside_int_T_TM *) &P042_RequestSessionTermination);
    }
    else {
      kcg_copy_P042_trackside_int_T_TM(
        &tmp,
        (P042_trackside_int_T_TM *) &P042_DEFAULT);
    }
    /* 1 */
    RadioTrackTrainFactory__CreateMsg024_BSL2_RBC_Messaging_Pkg_RBC_RadioTrackTrainFactory_Pkg(
      T_TRAIN_MIN,
      M_ACK_No_acknowledgement_required,
      tmp1,
      (P003V1_trackside_int_T_TM_baseline2 *) &P003_DEFAULT,
      (P005_trackside_int_T_TM *) &P005_DEFAULT,
      &tmp,
      (P057_trackside_int_T_TM *) &P057_DEFAULT,
      (P058_trackside_int_T_TM *) &P058_DEFAULT,
      &tmp2);
    /* 2 */
    RadioTrackTrainMessageQueueEntry__Create_RBC_Collections_Pkg(&tmp2, &tmp3);
    /* 2 */
    RadioTrackTrainMessageQueue__TryPut_RBC_Collections_Pkg(
      &(*inDataBus).messageQueue,
      &tmp3,
      &outC->outDataBus.messageQueue);
  }
  else {
    outC->Level_2_or_3 = last_Level_2_or_3;
    kcg_copy_RadioTrackTrainMessageQueue_T(
      &outC->outDataBus.messageQueue,
      &(*inDataBus).messageQueue);
  }
}
/* RBC_Model_Pkg::RBC__PingTrain */
void RBC__PingTrain_RBC_Model_Pkg(
  /* RBC_Model_Pkg::RBC__PingTrain::inP42 */P042_trackside_int_T_TM *inP42,
  /* RBC_Model_Pkg::RBC__PingTrain::inDataBus */RBC_Data_T_RBC_DataBus_Pkg *inDataBus,
  /* RBC_Model_Pkg::RBC__PingTrain::inRadioTrainTrackMessage */Radio_TrainTrack_Message_T_Radio_Types_Pkg *inRadioTrainTrackMessage,
  /* RBC_Model_Pkg::RBC__PingTrain::inTriggeredRadioTrackTrainMessage */CompressedRadioMessage_TM *inTriggeredRadioTrackTrainMessage,
  outC_RBC__PingTrain_RBC_Model_Pkg *outC)
{
  Radio_TrackTrain_Header_T_TM tmp5;
  NationalParams_T tmp4;
  RadioTrackTrainMessageQueueEntry_T tmp3;
  CompressedRadioMessage_TM tmp2;
  NID_LRBG tmp1;
  PosData_T tmp;
  /* RBC_Model_Pkg::RBC__PingTrain::trigger */ kcg_bool trigger;
  
  kcg_copy_CompressedRadioMessage_TM(
    &outC->outTriggeredRadioTrackTrainMessage,
    inTriggeredRadioTrackTrainMessage);
  kcg_copy_Radio_TrainTrack_Message_T_Radio_Types_Pkg(
    &outC->outRadioTrainTrackMessage,
    inRadioTrainTrackMessage);
  trigger = /* 2 */
    RadioTrackTrainMessage__IsValid_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
      &(*inDataBus).lastSentTrackTrainMessage);
  if (trigger) {
    /* 2 */
    RadioTrackTrainMessage__GetHeader_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
      &(*inDataBus).lastSentTrackTrainMessage,
      &tmp5);
    outC->lastRadioTrackTrainMessageWasSentTimestamp = /* 2 */
      RadioTrackTrainHeader__Get_T_TRAIN_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
        &tmp5);
  }
  else if (outC->init) {
    outC->lastRadioTrackTrainMessageWasSentTimestamp = T_TRAIN_MIN;
  }
  outC->init = kcg_false;
  /* 1 */
  DynamicConfig__GetNationalParams_RBC_Config_Pkg(&(*inDataBus).config, &tmp4);
  tmp1 = /* 1 */ NationalParams__Get_T_NVCONTACT_RBC_Config_Pkg(&tmp4);
  trigger = (/* 1 */
      RadioTrackTrainMessageQueue__GetRemainingCapacity_RBC_Collections_Pkg(
        &(*inDataBus).messageQueue) ==
      RADIO_TRACK_TRAIN_MESSAGE_QUEUE_CAPACITY) & (/* 1 */
      Clock__GetSeconds_RBC_Time_Pkg(&(*inDataBus).clockk) -
      outC->lastRadioTrackTrainMessageWasSentTimestamp >= T_NVCONTACT_FACTOR *
      tmp1) & ((tmp1 > T_NVCONTACT_DEFAULT) & (tmp1 < T_NVCONTACT_UNLIMITED));
  kcg_copy_RBC_Data_T_RBC_DataBus_Pkg(&outC->outDataBus, inDataBus);
  if (trigger) {
    /* 3 */
    SessionManagement__GetPosData_RBC_Session_Pkg(&(*inDataBus).session, &tmp);
    tmp1 = /* 3 */ PosData__Get_NID_LRBG_RBC_Session_Pkg(&tmp);
    /* 1 */
    RadioTrackTrainFactory__CreateMsg024_BSL2_RBC_Messaging_Pkg_RBC_RadioTrackTrainFactory_Pkg(
      T_TRAIN_MIN,
      M_ACK_No_acknowledgement_required,
      tmp1,
      (P003V1_trackside_int_T_TM_baseline2 *) &P003_DEFAULT,
      (P005_trackside_int_T_TM *) &P005_DEFAULT,
      inP42,
      (P057_trackside_int_T_TM *) &P057_DEFAULT,
      (P058_trackside_int_T_TM *) &P058_DEFAULT,
      &tmp2);
    /* 2 */
    RadioTrackTrainMessageQueueEntry__Create_RBC_Collections_Pkg(&tmp2, &tmp3);
    /* 2 */
    RadioTrackTrainMessageQueue__TryPut_RBC_Collections_Pkg(
      &(*inDataBus).messageQueue,
      &tmp3,
      &outC->outDataBus.messageQueue);
  }
  else {
    kcg_copy_RadioTrackTrainMessageQueue_T(
      &outC->outDataBus.messageQueue,
      &(*inDataBus).messageQueue);
  }
}
/* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop */
void RBC__ProcessConditionalEmergencyStop_RBC_Model_Pkg(
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::inDataBus */RBC_Data_T_RBC_DataBus_Pkg *inDataBus,
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::inRadioTrainTrackMessage */Radio_TrainTrack_Message_T_Radio_Types_Pkg *inRadioTrainTrackMessage,
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::inTriggeredRadioTrackTrainMessage */CompressedRadioMessage_TM *inTriggeredRadioTrackTrainMessage,
  outC_RBC__ProcessConditionalEmergencyStop_RBC_Model_Pkg *outC)
{
  NID_EM tmp5;
  Radio_TrainTrack_Header_T_Radio_Types_Pkg tmp4;
  PosData_T tmp3;
  PosData_T tmp2;
  RadioTrackTrainMessageQueueEntry_T tmp1;
  Radio_TrackTrain_Header_T_TM tmp;
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::CONDITIONAL_EMERGENCY_STOP_SM::TRY_PROCESS_ACKNOWLEDGEMENT::IfBlock1 */ kcg_bool IfBlock1_clock_CONDITIONAL_EMERGENCY_STOP_SM_TRY_PROCESS_ACKNOWLEDGEMENT;
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::invalidAck */ kcg_bool last_invalidAck;
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::radioTrackTrainMessageWasSentEmergencyStopId */ NID_EM last_radioTrackTrainMessageWasSentEmergencyStopId;
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::CONDITIONAL_EMERGENCY_STOP_SM */ SSM_ST_CONDITIONAL_EMERGENCY_STOP_SM CONDITIONAL_EMERGENCY_STOP_SM_state_sel;
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::CONDITIONAL_EMERGENCY_STOP_SM */ SSM_ST_CONDITIONAL_EMERGENCY_STOP_SM CONDITIONAL_EMERGENCY_STOP_SM_state_act;
  /* RBC_Model_Pkg::RBC__ProcessConditionalEmergencyStop::radioTrainTrackMessageId */ NID_MESSAGE radioTrainTrackMessageId;
  
  kcg_copy_CompressedRadioMessage_TM(
    &outC->outTriggeredRadioTrackTrainMessage,
    inTriggeredRadioTrackTrainMessage);
  kcg_copy_Radio_TrainTrack_Message_T_Radio_Types_Pkg(
    &outC->outRadioTrainTrackMessage,
    inRadioTrainTrackMessage);
  if (outC->init) {
    outC->init = kcg_false;
    IfBlock1_clock_CONDITIONAL_EMERGENCY_STOP_SM_TRY_PROCESS_ACKNOWLEDGEMENT =
      kcg_false;
    last_invalidAck = kcg_false;
    last_radioTrackTrainMessageWasSentEmergencyStopId = NID_EM_DEFAULT;
    CONDITIONAL_EMERGENCY_STOP_SM_state_sel =
      SSM_st_IDLE_CONDITIONAL_EMERGENCY_STOP_SM;
  }
  else {
    last_invalidAck = outC->invalidAck;
    IfBlock1_clock_CONDITIONAL_EMERGENCY_STOP_SM_TRY_PROCESS_ACKNOWLEDGEMENT =
      outC->validAck;
    last_radioTrackTrainMessageWasSentEmergencyStopId =
      outC->radioTrackTrainMessageWasSentEmergencyStopId;
    CONDITIONAL_EMERGENCY_STOP_SM_state_sel =
      outC->CONDITIONAL_EMERGENCY_STOP_SM_state_nxt;
  }
  /* 4 */
  RadioTrackTrainMessage__GetHeader_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
    &outC->outTriggeredRadioTrackTrainMessage,
    &tmp);
  tmp5 = /* 2 */
    RadioTrackTrainHeader__Get_NID_MESSAGE_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
      &tmp);
  /* 4 */
  RadioTrainTrackMessage__GetHeader_RBC_Messaging_Pkg_RBC_RadioTrainTrack_Pkg(
    &outC->outRadioTrainTrackMessage,
    &tmp4);
  radioTrainTrackMessageId = /* 2 */
    RadioTrainTrackHeader__Get_NID_MESSAGE_RBC_Messaging_Pkg_RBC_RadioTrainTrack_Pkg(
      &tmp4);
  switch (CONDITIONAL_EMERGENCY_STOP_SM_state_sel) {
    case SSM_st_IDLE_CONDITIONAL_EMERGENCY_STOP_SM :
      if (tmp5 == 15) {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_SEND_CONDITIONAL_EMERGENCY_STOP_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      else {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_IDLE_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      break;
    case SSM_st_SEND_CONDITIONAL_EMERGENCY_STOP_CONDITIONAL_EMERGENCY_STOP_SM :
      if (radioTrainTrackMessageId == 147) {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_TRY_PROCESS_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      else if (radioTrainTrackMessageId != 147) {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_AWAIT_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      else {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_SEND_CONDITIONAL_EMERGENCY_STOP_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      break;
    case SSM_st_AWAIT_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM :
      if (radioTrainTrackMessageId == 147) {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_TRY_PROCESS_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      else {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_AWAIT_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      break;
    case SSM_st_TRY_PROCESS_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM :
      if (IfBlock1_clock_CONDITIONAL_EMERGENCY_STOP_SM_TRY_PROCESS_ACKNOWLEDGEMENT &
        (tmp5 == 15)) {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_SEND_CONDITIONAL_EMERGENCY_STOP_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      else if (IfBlock1_clock_CONDITIONAL_EMERGENCY_STOP_SM_TRY_PROCESS_ACKNOWLEDGEMENT) {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_IDLE_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      else if (last_invalidAck & (radioTrainTrackMessageId == 147)) {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_TRY_PROCESS_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      else if (last_invalidAck) {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_AWAIT_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      else {
        CONDITIONAL_EMERGENCY_STOP_SM_state_act =
          SSM_st_TRY_PROCESS_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      }
      break;
    
  }
  kcg_copy_RBC_Data_T_RBC_DataBus_Pkg(&outC->outDataBus, inDataBus);
  switch (CONDITIONAL_EMERGENCY_STOP_SM_state_act) {
    case SSM_st_TRY_PROCESS_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM :
      /* 3 */
      RadioTrainTrackMessage__GetHeader_RBC_Messaging_Pkg_RBC_RadioTrainTrack_Pkg(
        &outC->outRadioTrainTrackMessage,
        &tmp4);
      IfBlock1_clock_CONDITIONAL_EMERGENCY_STOP_SM_TRY_PROCESS_ACKNOWLEDGEMENT =
        /* 1 */
        RadioTrainTrackHeader__Get_NID_EM_RBC_Messaging_Pkg_RBC_RadioTrainTrack_Pkg(
          &tmp4) == last_radioTrackTrainMessageWasSentEmergencyStopId;
      kcg_copy_RadioTrackTrainMessageQueue_T(
        &outC->outDataBus.messageQueue,
        &(*inDataBus).messageQueue);
      outC->CONDITIONAL_EMERGENCY_STOP_SM_state_nxt =
        SSM_st_TRY_PROCESS_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      outC->radioTrackTrainMessageWasSentEmergencyStopId =
        last_radioTrackTrainMessageWasSentEmergencyStopId;
      if (IfBlock1_clock_CONDITIONAL_EMERGENCY_STOP_SM_TRY_PROCESS_ACKNOWLEDGEMENT) {
        /* 5 */
        SessionManagement__GetPosData_RBC_Session_Pkg(
          &(*inDataBus).session,
          &tmp2);
        /* 5 */
        PosData__Update_RBC_Session_Pkg(
          &tmp2,
          &outC->outRadioTrainTrackMessage,
          &tmp3);
        /* 5 */
        SessionManagement__SetPosData_RBC_Session_Pkg(
          &(*inDataBus).session,
          &tmp3,
          &outC->session);
        outC->validAck = kcg_true;
        outC->invalidAck = kcg_false;
      }
      else {
        outC->validAck = kcg_false;
        outC->invalidAck = kcg_true;
      }
      break;
    case SSM_st_AWAIT_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM :
      kcg_copy_SessionManagement_T(&outC->session, &(*inDataBus).session);
      kcg_copy_RadioTrackTrainMessageQueue_T(
        &outC->outDataBus.messageQueue,
        &(*inDataBus).messageQueue);
      outC->validAck = kcg_false;
      outC->invalidAck = kcg_false;
      outC->CONDITIONAL_EMERGENCY_STOP_SM_state_nxt =
        SSM_st_AWAIT_ACKNOWLEDGEMENT_CONDITIONAL_EMERGENCY_STOP_SM;
      outC->radioTrackTrainMessageWasSentEmergencyStopId =
        last_radioTrackTrainMessageWasSentEmergencyStopId;
      break;
    case SSM_st_SEND_CONDITIONAL_EMERGENCY_STOP_CONDITIONAL_EMERGENCY_STOP_SM :
      kcg_copy_SessionManagement_T(&outC->session, &(*inDataBus).session);
      /* 3 */
      RadioTrackTrainMessageQueueEntry__Create_RBC_Collections_Pkg(
        &outC->outTriggeredRadioTrackTrainMessage,
        &tmp1);
      /* 3 */
      RadioTrackTrainMessageQueue__TryPut_RBC_Collections_Pkg(
        &(*inDataBus).messageQueue,
        &tmp1,
        &outC->outDataBus.messageQueue);
      outC->validAck = kcg_false;
      outC->invalidAck = kcg_false;
      outC->CONDITIONAL_EMERGENCY_STOP_SM_state_nxt =
        SSM_st_SEND_CONDITIONAL_EMERGENCY_STOP_CONDITIONAL_EMERGENCY_STOP_SM;
      /* 3 */
      RadioTrackTrainMessage__GetHeader_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
        &outC->outTriggeredRadioTrackTrainMessage,
        &tmp);
      outC->radioTrackTrainMessageWasSentEmergencyStopId = /* 1 */
        RadioTrackTrainHeader__Get_NID_EM_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
          &tmp);
      break;
    case SSM_st_IDLE_CONDITIONAL_EMERGENCY_STOP_SM :
      kcg_copy_SessionManagement_T(&outC->session, &(*inDataBus).session);
      kcg_copy_RadioTrackTrainMessageQueue_T(
        &outC->outDataBus.messageQueue,
        &(*inDataBus).messageQueue);
      outC->validAck = kcg_false;
      outC->invalidAck = kcg_false;
      outC->CONDITIONAL_EMERGENCY_STOP_SM_state_nxt =
        SSM_st_IDLE_CONDITIONAL_EMERGENCY_STOP_SM;
      outC->radioTrackTrainMessageWasSentEmergencyStopId =
        last_radioTrackTrainMessageWasSentEmergencyStopId;
      break;
    
  }
  kcg_copy_SessionManagement_T(&outC->outDataBus.session, &outC->session);
}
/* RBC_Messaging_Pkg::RadioTrackTrainMsgQueue */
void RadioTrackTrainMsgQueue_RBC_Messaging_Pkg(
  /* RBC_Messaging_Pkg::RadioTrackTrainMsgQueue::inDataBus */RBC_Data_T_RBC_DataBus_Pkg *inDataBus,
  /* RBC_Messaging_Pkg::RadioTrackTrainMsgQueue::outDataBus */RBC_Data_T_RBC_DataBus_Pkg *outDataBus,
  /* RBC_Messaging_Pkg::RadioTrackTrainMsgQueue::outRadioTrackTrainMessage */CompressedRadioMessage_TM *outRadioTrackTrainMessage)
{
  static Radio_TrackTrain_Header_T_TM tmp2;
  static Radio_TrackTrain_Header_T_TM tmp1;
  static T_TRAIN tmp;
  /* RBC_Messaging_Pkg::RadioTrackTrainMsgQueue::IfBlock1::then::_L35 */
  static RadioTrackTrainMessageQueueEntry_T _L35_IfBlock1;
  /* RBC_Messaging_Pkg::RadioTrackTrainMsgQueue::IfBlock1::then::_L34 */
  static RadioTrackTrainMessageQueue_T _L34_IfBlock1;
  /* RBC_Messaging_Pkg::RadioTrackTrainMsgQueue::IfBlock1::then::_L36 */
  static CompressedRadioMessage_TM _L36_IfBlock1;
  /* RBC_Messaging_Pkg::RadioTrackTrainMsgQueue::IfBlock1 */
  static kcg_bool IfBlock1_clock;
  
  IfBlock1_clock = /* 2 */
    RadioTrackTrainMessageQueue__GetRemainingCapacity_RBC_Collections_Pkg(
      &(*inDataBus).messageQueue) < RADIO_TRACK_TRAIN_MESSAGE_QUEUE_CAPACITY;
  if (IfBlock1_clock) {
    /* 2 */
    RadioTrackTrainMessageQueue__Take_RBC_Collections_Pkg(
      &(*inDataBus).messageQueue,
      &_L34_IfBlock1,
      &_L35_IfBlock1);
    /* 2 */
    RadioTrackTrainMessageQueueEntry__GetEntry_RBC_Collections_Pkg(
      &_L35_IfBlock1,
      &_L36_IfBlock1);
    /* 2 */
    RadioTrackTrainMessage__GetHeader_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
      &_L36_IfBlock1,
      &tmp1);
    tmp = /* 2 */ Clock__GetSeconds_RBC_Time_Pkg(&(*inDataBus).clockk);
    /* 2 */
    RadioTrackTrainHeader__Set_T_TRAIN_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
      &tmp1,
      tmp,
      &tmp2);
    /* 2 */
    RadioTrackTrainMessage__SetHeader_RBC_Messaging_Pkg_RBC_RadioTrackTrain_Pkg(
      &_L36_IfBlock1,
      &tmp2,
      outRadioTrackTrainMessage);
    kcg_copy_RBC_Data_T_RBC_DataBus_Pkg(outDataBus, inDataBus);
    kcg_copy_RadioTrackTrainMessageQueue_T(
      &(*outDataBus).messageQueue,
      &_L34_IfBlock1);
    kcg_copy_CompressedRadioMessage_TM(
      &(*outDataBus).lastSentTrackTrainMessage,
      outRadioTrackTrainMessage);
  }
  else {
    kcg_copy_RBC_Data_T_RBC_DataBus_Pkg(outDataBus, inDataBus);
    kcg_copy_RadioTrackTrainMessageQueue_T(
      &(*outDataBus).messageQueue,
      &(*inDataBus).messageQueue);
    /* 2 */
    RadioTrackTrainFactory__CreateDefaultMsg_BSL2_RBC_Messaging_Pkg_RBC_RadioTrackTrainFactory_Pkg(
      outRadioTrackTrainMessage);
  }
}