/* MessageLibBaseline2::Send_P005 */
void Send_P005_MessageLibBaseline2(
  /* MessageLibBaseline2::Send_P005::B_data_in */CompressedPackets_T_Common_Types_Pkg *B_data_in,
  /* MessageLibBaseline2::Send_P005::P005 */P005_trackside_int_T_TM *P005,
  /* MessageLibBaseline2::Send_P005::B_data_out */CompressedPackets_T_Common_Types_Pkg *B_data_out)
{
  /* TM_trackside::Write_P005::_L21 */
  static kcg_int _L21_1;
  /* TM_trackside::Write_P005::_L22 */
  static kcg_int _L22_1;
  /* TM_trackside::Write_P005::_L44 */
  static CompressedPacketData_T_Common_Types_Pkg _L44_1;
  /* TM_trackside::Write_P005::_L43 */
  static MetadataElement_T_Common_Types_Pkg _L43_1;
  
  if ((*P005).valid) {
    /* 1_1 */ C_P005_tracksim_compr_TM_conversions(P005, &_L43_1, &_L44_1);
    /* 1_1 */
    SEND_WriteBaliseMessageHeader_TM_lib_internal(
      &(*B_data_in).PacketHeaders,
      &_L43_1,
      &(*B_data_out).PacketHeaders,
      &_L21_1,
      &_L22_1);
    /* 1_1 */
    SEND_MessageData_TM_lib_internal(
      _L21_1,
      _L22_1,
      &(*B_data_in).PacketData,
      &_L44_1,
      &(*B_data_out).PacketData);
  }
  else {
    kcg_copy_CompressedPackets_T_Common_Types_Pkg(B_data_out, B_data_in);
  }
}
/* TM_trackside_baseline2::Write_P136 */
void Write_P136_TM_trackside_baseline2(
  inC_Write_P136_TM_trackside_baseline2 *inC,
  outC_Write_P136_TM_trackside_baseline2 *outC)
{
  /* TM_trackside_baseline2::Write_P136::_L21 */ kcg_int _L21;
  /* TM_trackside_baseline2::Write_P136::_L22 */ kcg_int _L22;
  /* TM_trackside_baseline2::Write_P136::_L44 */ CompressedPacketData_T_Common_Types_Pkg _L44;
  /* TM_trackside_baseline2::Write_P136::_L43 */ MetadataElement_T_Common_Types_Pkg _L43;
  
  /* 1 */ C_P136_tracksim_compr_TM_conversions(&inC->Packet136, &_L43, &_L44);
  /* 1 */
  SEND_WriteBaliseMessageHeader_TM_lib_internal(
    &inC->Packets.PacketHeaders,
    &_L43,
    &outC->RadioPacketsOut.PacketHeaders,
    &_L21,
    &_L22);
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    _L21,
    _L22,
    &inC->Packets.PacketData,
    &_L44,
    &outC->RadioPacketsOut.PacketData);
  outC->Error = kcg_false;
}
/* TM_trackside::Write_P021 */
void Write_P021_TM_trackside(
  /* TM_trackside::Write_P021::Packet21 */P021_trackside_int_T_TM *Packet21,
  /* TM_trackside::Write_P021::Packets */CompressedPackets_T_Common_Types_Pkg *Packets,
  /* TM_trackside::Write_P021::Error */kcg_bool *Error,
  /* TM_trackside::Write_P021::RadioPacketsOut */CompressedPackets_T_Common_Types_Pkg *RadioPacketsOut)
{
  /* TM_trackside::Write_P021::_L21 */
  static kcg_int _L21;
  /* TM_trackside::Write_P021::_L22 */
  static kcg_int _L22;
  /* TM_trackside::Write_P021::_L44 */
  static CompressedPacketData_T_Common_Types_Pkg _L44;
  /* TM_trackside::Write_P021::_L43 */
  static MetadataElement_T_Common_Types_Pkg _L43;
  
  *Error = kcg_false;
  /* 1 */ C_P021_tracksim_compr_TM_conversions(Packet21, &_L43, &_L44);
  /* 1 */
  SEND_WriteBaliseMessageHeader_TM_lib_internal(
    &(*Packets).PacketHeaders,
    &_L43,
    &(*RadioPacketsOut).PacketHeaders,
    &_L21,
    &_L22);
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    _L21,
    _L22,
    &(*Packets).PacketData,
    &_L44,
    &(*RadioPacketsOut).PacketData);
}
/* TM_trackside_baseline2::Write_P027V1 */
void Write_P027V1_TM_trackside_baseline2(
  /* TM_trackside_baseline2::Write_P027V1::Packet27V1 */P027V1_trackside_int_T_TM_baseline2 *Packet27V1,
  /* TM_trackside_baseline2::Write_P027V1::Packets */CompressedPackets_T_Common_Types_Pkg *Packets,
  /* TM_trackside_baseline2::Write_P027V1::Error */kcg_bool *Error,
  /* TM_trackside_baseline2::Write_P027V1::PacketsOut */CompressedPackets_T_Common_Types_Pkg *PacketsOut)
{
  struct__47107 tmp1;
  kcg_bool tmp;
  kcg_int i;
  /* TM_trackside_baseline2::Write_P027V1::_L21 */ kcg_int _L21;
  /* TM_trackside_baseline2::Write_P027V1::_L44 */ CompressedPacketData_T_Common_Types_Pkg _L44;
  /* TM_trackside_baseline2::Write_P027V1::_L43 */ MetadataElement_T_Common_Types_Pkg _L43;
  /* TM_trackside_baseline2::Write_P027V1::_L45 */ P027V1_OBU_sectionlist_int_T_TM_baseline2 _L45;
  /* TM_trackside_baseline2::Write_P027V1::_L46 */ kcg_int _L46;
  /* TM_trackside_baseline2::Write_P027V1::_L56 */ kcg_int _L56;
  /* TM_trackside_baseline2::Write_P027V1::_L59 */ Q_DIR _L59;
  
  *Error = kcg_false;
  /* 1 */
  C_P027V1_tracksim_compr_body_TM_conversions_baseline2(
    Packet27V1,
    &_L43,
    &_L44,
    &_L45,
    &_L46,
    &_L56,
    &_L59);
  /* 1 */
  SEND_WriteMessageHeader_TM_lib_internal(
    &(*Packets).PacketHeaders,
    &_L43,
    &(*PacketsOut).PacketHeaders,
    &_L21,
    &i);
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    _L21,
    i,
    &(*Packets).PacketData,
    &_L44,
    &(*PacketsOut).PacketData);
  for (i = 0; i < 33; i++) {
    kcg_copy_CompressedPackets_T_Common_Types_Pkg(&tmp1, PacketsOut);
    /* 1 */
    C_P027V1_tracksim_merge_sections_TM_conversions_baseline2(
      i,
      &tmp1,
      &_L45[i],
      _L46,
      _L56,
      _L59,
      &tmp,
      PacketsOut);
    if (!tmp) {
      break;
    }
  }
}
/* TM_trackside_baseline2::Write_P003V1 */
void Write_P003V1_TM_trackside_baseline2(
  /* TM_trackside_baseline2::Write_P003V1::Packet003V1 */P003V1_trackside_int_T_TM_baseline2 *Packet003V1,
  /* TM_trackside_baseline2::Write_P003V1::Packets */CompressedPackets_T_Common_Types_Pkg *Packets,
  outC_Write_P003V1_TM_trackside_baseline2 *outC)
{
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->_L40, Packets);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L42,
    &outC->_L40.PacketData);
  kcg_copy_P003V1_trackside_int_T_TM_baseline2(&outC->_L1, Packet003V1);
  /* 1 */
  C_P003V1_tracksim_compr_TM_conversions_baseline2(
    &outC->_L1,
    &outC->Context_1);
  kcg_copy_MetadataElement_T_Common_Types_Pkg(
    &outC->_L43,
    &outC->Context_1.Header);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L44,
    &outC->Context_1.P003V1_compressed);
  kcg_copy_Metadata_T_Common_Types_Pkg(&outC->_L41, &outC->_L40.PacketHeaders);
  /* 1 */
  SEND_WriteBaliseMessageHeader_TM_lib_internal(
    &outC->_L41,
    &outC->_L43,
    &outC->_1_Context_1);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L4,
    &outC->_1_Context_1.HeadersOut);
  outC->_L21 = outC->_1_Context_1.NewStartAddr;
  outC->_L22 = outC->_1_Context_1.NewEndAddr;
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    outC->_L21,
    outC->_L22,
    &outC->_L42,
    &outC->_L44,
    &outC->_2_Context_1);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L10,
    &outC->_2_Context_1.DataOut);
  kcg_copy_Metadata_T_Common_Types_Pkg(&outC->_L39.PacketHeaders, &outC->_L4);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L39.PacketData,
    &outC->_L10);
  outC->_L18 = kcg_false;
  outC->Error = outC->_L18;
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(
    &outC->RadioPacketsOut,
    &outC->_L39);
}
/* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections */
void C_P027V1_tracksim_merge_sections_TM_conversions_baseline2(
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::i */kcg_int i,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::PacketStream_in */CompressedPackets_T_Common_Types_Pkg *PacketStream_in,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::P027V1_sections_from_track */P027V1_section_int_T_TM_baseline2 *P027V1_sections_from_track,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::n_iter */kcg_int n_iter,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::meta_first_section_in */kcg_int meta_first_section_in,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::cont */kcg_bool *cont,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::Packets_Out */CompressedPackets_T_Common_Types_Pkg *Packets_Out)
{
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::_L432 */
  static CompressedPacketData_T_Common_Types_Pkg _L432;
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::_L431 */
  static MetadataElement_T_Common_Types_Pkg _L431;
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::_L436 */
  static kcg_int _L436;
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::_L437 */
  static kcg_int _L437;
  
  *cont = n_iter > i;
  /* 2 */
  C_P027V1_tracksim_compr_one_section_TM_conversions_baseline2(
    i,
    P027V1_sections_from_track,
    meta_first_section_in,
    &_L431,
    &_L432);
  /* 1 */
  SEND_WriteMessageHeader_TM_lib_internal(
    &(*PacketStream_in).PacketHeaders,
    &_L431,
    &(*Packets_Out).PacketHeaders,
    &_L436,
    &_L437);
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    _L436,
    _L437,
    &(*PacketStream_in).PacketData,
    &_L432,
    &(*Packets_Out).PacketData);
}
/* TM_trackside_baseline2::Write_P027V1 */
void Write_P027V1_TM_trackside_baseline2(
  /* TM_trackside_baseline2::Write_P027V1::Packet27V1 */P027V1_trackside_int_T_TM_baseline2 *Packet27V1,
  /* TM_trackside_baseline2::Write_P027V1::Packets */CompressedPackets_T_Common_Types_Pkg *Packets,
  outC_Write_P027V1_TM_trackside_baseline2 *outC)
{
  static kcg_int i2;
  static kcg_int i1;
  static CompressedPackets_T_Common_Types_Pkg tmp;
  static kcg_int i;
  static kcg_int noname;
  
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->_L40, Packets);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L42,
    &outC->_L40.PacketData);
  kcg_copy_P027V1_trackside_int_T_TM_baseline2(&outC->_L1, Packet27V1);
  /* 1 */
  C_P027V1_tracksim_compr_body_TM_conversions_baseline2(
    &outC->_L1,
    &outC->Context_1);
  kcg_copy_MetadataElement_T_Common_Types_Pkg(
    &outC->_L43,
    &outC->Context_1.Header);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L44,
    &outC->Context_1.P027V1_body_compressed);
  kcg_copy__2_P027V1_OBU_sectionlist_int_T_TM_baseline2(
    &outC->_L45,
    &outC->Context_1.P027V1_sections);
  outC->_L46 = outC->Context_1.n_iter_k_out;
  outC->_L56 = outC->Context_1.meta_first_section;
  for (i2 = 0; i2 < 33; i2++) {
    outC->_L55[i2] = outC->_L56;
  }
  for (i1 = 0; i1 < 33; i1++) {
    outC->_L54[i1] = outC->_L46;
  }
  outC->_L52 = kcg_true;
  kcg_copy_Metadata_T_Common_Types_Pkg(&outC->_L41, &outC->_L40.PacketHeaders);
  /* 1 */
  SEND_WriteMessageHeader_TM_lib_internal(
    &outC->_L41,
    &outC->_L43,
    &outC->_1_Context_1);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L4,
    &outC->_1_Context_1.HeadersOut);
  outC->_L21 = outC->_1_Context_1.NewStartAddr;
  outC->_L22 = outC->_1_Context_1.NewEndAddr;
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    outC->_L21,
    outC->_L22,
    &outC->_L42,
    &outC->_L44,
    &outC->_2_Context_1);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L10,
    &outC->_2_Context_1.DataOut);
  kcg_copy_Metadata_T_Common_Types_Pkg(&outC->_L39.PacketHeaders, &outC->_L4);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L39.PacketData,
    &outC->_L10);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->_L51, &outC->_L39);
  if (outC->_L52) {
    for (i = 0; i < 33; i++) {
      kcg_copy_CompressedPackets_T_Common_Types_Pkg(&tmp, &outC->_L51);
      /* 1 */
      C_P027V1_tracksim_merge_s_TM_conversions_baseline2(
        i,
        &tmp,
        &outC->_L45[i],
        outC->_L54[i],
        outC->_L55[i],
        &outC->_3_Context_1[i]);
      kcg_copy_CompressedPackets_T_Common_Types_Pkg(
        &outC->_L51,
        &outC->_3_Context_1[i].Packets_Out);
      outC->_L50 = i + 1;
      if (!outC->_3_Context_1[i].cont) {
        break;
      }
    }
  }
  else {
    outC->_L50 = 0;
  }
  noname = outC->_L50;
  outC->_L18 = kcg_false;
  outC->Error = outC->_L18;
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->PacketsOut, &outC->_L51);
}
/* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections */
void C_P027V1_tracksim_merge_s_TM_conversions_baseline2(
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::i */ kcg_int i,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::PacketStream_in */ CompressedPackets_T_Common_Types_Pkg *PacketStream_in,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::P027V1_sections_from_track */ P027V1_section_int_T_TM_baseline2 *P027V1_sections_from_track,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::n_iter */ kcg_int n_iter,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::meta_first_section_in */ kcg_int meta_first_section_in,
  outC_C_P027V1_tracksim_merge_s_TM_conversions_baseline2 *outC)
{
  outC->_L446 = i;
  kcg_copy_P027V1_section_int_T_TM_baseline2(
    &outC->_L440,
    P027V1_sections_from_track);
  outC->_L448 = meta_first_section_in;
  /* 2 */
  C_P027V1_tracksim_compr_o_TM_conversions_baseline2(
    outC->_L446,
    &outC->_L440,
    outC->_L448,
    &outC->Context_2);
  kcg_copy_MetadataElement_T_Common_Types_Pkg(
    &outC->_L431,
    &outC->Context_2.Header);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L432,
    &outC->Context_2.P027V1_sections_compressed);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->_L439, PacketStream_in);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L442,
    &outC->_L439.PacketHeaders);
  /* 1 */
  SEND_WriteMessageHeader_TM_lib_internal(
    &outC->_L442,
    &outC->_L431,
    &outC->Context_1);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L435,
    &outC->Context_1.HeadersOut);
  outC->_L436 = outC->Context_1.NewStartAddr;
  outC->_L437 = outC->Context_1.NewEndAddr;
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L443,
    &outC->_L439.PacketData);
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    outC->_L436,
    outC->_L437,
    &outC->_L443,
    &outC->_L432,
    &outC->_1_Context_1);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L433,
    &outC->_1_Context_1.DataOut);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L434.PacketHeaders,
    &outC->_L435);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L434.PacketData,
    &outC->_L433);
  outC->_L438 = i;
  outC->_L441 = n_iter;
  outC->_L447 = outC->_L441 > outC->_L438;
  outC->cont = outC->_L447;
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(
    &outC->Packets_Out,
    &outC->_L434);
}