#include "FrontDomain_Control.h"
#include "CAN_CH0_CAN_Communication_Matrix.h"
#include "SGMCD1020Q.h"
#include "TPS2HB35AQPWPRQ1.h"
#include "TPS4H160Q1.h"

void FrontDomain_Control_Service(void)
{
  if (Get_ID_18FFA017_Sig_Main_Power_Switch() == 1)
  {
    /*4.2.1、 雨刮喷淋(OUT11)*/
    if (SGMCD1020Q_1.bits.sg7 == 0)
    {
      TPS2HB35_SetOutput5A_OUT17(1);
    }
    else
    {
      TPS2HB35_SetOutput5A_OUT17(0);
    }
    /*4.2.2、 示廓灯/位置灯(OUT12)*/
    if ((SGMCD1020Q_2.bits.sg5 == 0) || ((SGMCD1020Q_2.bits.sg5 == 0) && (Get_ID_18FFFE9C_Sig_Small_Lamp_Control_Output() == 1)))
    {
      TPS2HB35_SetOutput5A_OUT18(1);
    }
    else
    {
      TPS2HB35_SetOutput5A_OUT18(0);
    }
    /*4.2.3、 雨刮低速(OUT16)*/
    /*1.1*/
    if ((SGMCD1020Q_1.bits.sg9 == 1) && (SGMCD1020Q_1.bits.sg8 == 0))
    {
      TPS2HB35_SetOutput10A_OUT8(1);
    }
    else
    {
      TPS2HB35_SetOutput10A_OUT8(0);
    }
    /*4.2.4、 雨刮高速(OUT17)*/
    if (SGMCD1020Q_1.bits.sg8 == 0)
    {
      TPS2HB35_SetOutput15A_OUT5(1);
    }
    else
    {
      TPS2HB35_SetOutput15A_OUT5(0);
    }
    /*4.2.5、 左昼行灯(OUT27)*/
    /*规范有问题，无此输出脚*/
    if ((SGMCD1020Q_1.bits.sg3 == 0) && (Get_ID_18FFA017_Sig_Danger_Lights() != 1))
    {
    }
    else
    {
    }
    /*4.2.6、 右昼行灯(OUT28)*/
    /*规范有问题，无此输出脚*/
    if ((SGMCD1020Q_1.bits.sg4 == 0) && (Get_ID_18FFA017_Sig_Danger_Lights() != 1) && (Get_ID_18FF4AEF_Sig_Power_On_High_Voltage_Indicator() == 1))
    {
    }
    else
    {
    }

    /*4.2.7、 开关背光灯(OUT29)*/
    /*规范有问题，无此输出脚*/
    if ((SGMCD1020Q_2.bits.sg5 == 1) || ((SGMCD1020Q_1.bits.sg5 == 1) && (Get_ID_18FFFE9C_Sig_Small_Lamp_Control_Output() == 1)))
    {
    }
    else
    {
    }
    /*4.2.8、 前门踏步灯(OUT30)*/
    /*规范有问题，无此输出脚*/
    if (SGMCD1020Q_3.bits.sp1 == 1)
    {
    }
    else
    {
    }
    /*4.2.9、 右转向辅助灯电源(OUT31)*/
    /*规范有问题，无此输出脚*/
    if (SGMCD1020Q_1.bits.sp4 == 1)
    {
    }
    else
    {
    }
  }

  /*4.2.10、 右前转向灯(OUT32)*/
  /*规范有问题，无此输出脚*/
  if (Get_ID_18FFA017_Sig_Main_Power_Switch() == 1)
  {
    if ((SGMCD1020Q_1.bits.sp4 == 1) || (Get_ID_18FFA017_Sig_Danger_Lights() == 1) || (Get_ID_18FFA017_Sig_Emergency_Switch() == 1))
    {
    }
    else
    {
    }
  }
  else
  {
    if ((Get_ID_18FFA017_Sig_Hand_Brake() == 1) && (Get_ID_18FFA017_Sig_Instrument_Igon_Wake_Up_Power() != 1) && (SGMCD1020Q_2.bits.sp7 == 1))
    {
    }
  }
  /*4.2.11、 右侧示廓灯(OUT33)*/
  /*规范有问题，无此输出脚*/
  /*4.2.12、 左侧示廓灯(OUT34)*/
  /*规范有问题，无此输出脚*/
  /*4.2.13、 启动反馈信号输出(OUT35)*/
  /*规范有问题，无此输出脚*/
  /*4.2.14、 随动仪表台电磁阀(OUT36)*/
  /*规范有问题，无此输出脚*/
  /*4.2.15、 左近光灯(OUT37)*/
  /*规范有问题，无此输出脚*/
  /*4.2.16、 右近光灯(OUT38)*/
  /*规范有问题，无此输出脚*/
  /*4.2.17、 左前转向灯(OUT39)*/
  if (((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_1.bits.sg3 == 1)) || (Get_ID_18FFA017_Sig_Danger_Lights() == 1) || (Get_ID_18FFA017_Sig_Emergency_Switch() == 1) || ((Get_ID_18FFA017_Sig_Instrument_Igon_Wake_Up_Power() != 1) && (Get_ID_18FFA017_Sig_Hand_Brake() == 1) && (Get_ID_18FFA017_Sig_Instrument_Igon_Wake_Up_Power() != 1)))
  {
    TPS2HB35_SetOutput1A_OUT8(1);
  }
  else
  {
    TPS2HB35_SetOutput1A_OUT8(0);
  }

  /*4.2.18、 左转向辅助灯电源(OUT40)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_1.bits.sg3 == 1))
  {
    TPS2HB35_SetOutput1A_OUT7(1);
  }
  else
  {
    TPS2HB35_SetOutput1A_OUT7(0);
  }
  /*4.2.19、 中门门上灯(OUT41)*/
  if (((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_3.bits.sp0 == 1)) || (Get_ID_18FFA017_Sig_Emergency_Switch() == 1))
  {
    TPS2HB35_SetOutput5A_OUT1(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT1(0);
  }
  /*4.2.20、 右远光灯(OUT42)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (((SGMCD1020Q_2.bits.sg5 == 1) && (SGMCD1020Q_2.bits.sg4 == 1)) || ((SGMCD1020Q_1.bits.sg5 == 1) && (SGMCD1020Q_1.bits.sp1 == 1) && (Get_ID_18FFFE9C_Sig_LowBeamHeadlightControlOutput() == 1))))
  {
    TPS2HB35_SetOutput3A_OUT16(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT16(0);
  }
  /*4.2.21、 左远光灯(OUT43)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (((SGMCD1020Q_2.bits.sg5 == 1) && (SGMCD1020Q_2.bits.sg4 == 1)) || ((SGMCD1020Q_1.bits.sg5 == 1) && (SGMCD1020Q_1.bits.sp1 == 1) && (Get_ID_18FFFE9C_Sig_LowBeamHeadlightControlOutput() == 1))))
  {
    TPS2HB35_SetOutput3A_OUT15(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT15(0);
  }
  /*4.2.22、 左前雾灯(OUT44)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_2.bits.sp1 == 1) && (SGMCD1020Q_2.bits.sg5 == 1))
  {
    TPS2HB35_SetOutput3A_OUT14(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT14(0);
  }
  /*4.2.23、 右前雾灯(OUT45)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_2.bits.sp1 == 1) && (SGMCD1020Q_2.bits.sg5 == 1))
  {
    TPS2HB35_SetOutput3A_OUT13(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT13(0);
  }
  /*4.2.24、 冷凝器工作电源(OUT46)*/
  if (0)
  {
    TPS2HB35_SetOutput3A_OUT12(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT12(0);
  }
  /*4.2.25、 司机顶灯(OUT47)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_2.bits.sg9 == 1))
  {
    TPS2HB35_SetOutput3A_OUT11(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT11(0);
  }
  /*4.2.26、 车门复位开关输出(OUT48)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_1.bits.sg11 == 1))
  {
    TPS2HB35_SetOutput3A_OUT10(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT10(0);
  }
  /*4.2.27、 制动灯(OUT49)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (Get_ID_189116EF_Sig_Brake_Light_Signal_Output() == 1) && (Get_ID_18FE4F0B_Sig_VDC_Brake_Light_quest() == 1) && (Get_ID_18FE4F0B_Sig_VDC_Lamp_State() == 1))
  {
    TPS2HB35_SetOutput3A_OUT9(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT9(0);
  }
  /*4.2.28、 后雾灯(OUT50)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_2.bits.sp0 == 1))
  {
    TPS2HB35_SetOutput3A_OUT8(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT8(0);
  }
  /*4.2.29、 前门门上灯(OUT51)*/
  if (((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_3.bits.sp1 == 1))||(Get_ID_18FFA017_Sig_Emergency_Switch()==1))
  {
    TPS2HB35_SetOutput3A_OUT7(1);
  }
  else
  {
    TPS2HB35_SetOutput3A_OUT7(0);
  }
  /*4.2.30、 电喇叭1(OUT52)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 0) && (Get_ID_18FFA017_Sig_Instrument_Igon_Wake_Up_Power() == 0)  && (Get_ID_18FFA017_Sig_Hand_Brake() == 0)  && (SGMCD1020Q_2.bits.sp7 == 0) && (SGMCD1020Q_1.bits.sg6 == 0))
    {
    TPS2HB35_SetOutput5A_OUT14(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT14(0);
  }
  /*4.2.31、 电喇叭2(OUT53)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 0) && (Get_ID_18FFA017_Sig_Instrument_Igon_Wake_Up_Power() == 0)  && (Get_ID_18FFA017_Sig_Hand_Brake() == 0)  && (SGMCD1020Q_2.bits.sp7 == 0) && (SGMCD1020Q_1.bits.sg6 == 0))
    {
    TPS2HB35_SetOutput5A_OUT13(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT13(0);
  }
  /*4.2.32、 顶部示廓灯(OUT54)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 0) && ((SGMCD1020Q_2.bits.sg5 == 1)||((SGMCD1020Q_1.bits.sg5 == 1)&&(Get_ID_18FFFE9C_Sig_Small_Lamp_Control_Output()==1))))
      {
    TPS2HB35_SetOutput5A_OUT12(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT12(0);
  }
  /*4.2.33、 倒车灯(OUT55)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (Get_ID_189116EF_Sig_Reverse_Prompt_Enable_Output() == 1))
  {
    TPS2HB35_SetOutput5A_OUT11(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT11(0);
  }
  /*4.2.34、 室内灯1(OUT56)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && ((SGMCD1020Q_2.bits.sg6 == 1)||(SGMCD1020Q_1.bits.sp2 == 1)))
  {
    TPS2HB35_SetOutput10A_OUT6(1);
  }
  else
  {
    TPS2HB35_SetOutput10A_OUT6(0);
  }
  /*4.2.35、 换气扇进气输出(OUT57)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && ((SGMCD1020Q_2.bits.sg0 == 1)||(SGMCD1020Q_1.bits.sp1 == 1)))
  {
    TPS2HB35_SetOutput10A_OUT5(1);
  }
  else
  {
    TPS2HB35_SetOutput10A_OUT5(0);
  }
  /*4.2.36、 换气扇排气输出(OUT58)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_2.bits.sg0 == 1))
  {
    TPS2HB35_SetOutput10A_OUT4(1);
  }
  else
  {
    TPS2HB35_SetOutput10A_OUT4(0);
  }
  /*4.2.37、 室内灯2(OUT59)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_1.bits.sp2 == 1))
  {
    TPS2HB35_SetOutput10A_OUT3(1);
  }
  else
  {
    TPS2HB35_SetOutput10A_OUT3(0);
  }
  /*4.2.38、 路牌电源1(OUT60)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_1.bits.sp6 == 1))
  {
    TPS2HB35_SetOutput10A_OUT2(1);
  }
  else
  {
    TPS2HB35_SetOutput10A_OUT2(0);
  }
  /*4.2.39、 路牌电源2(OUT61)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_1.bits.sp6 == 1))
  {
    TPS2HB35_SetOutput10A_OUT1(1);
  }
  else
  {
    TPS2HB35_SetOutput10A_OUT1(0);
  }
  /*4.2.40、 前门开电磁阀(OUT62)*/
  if (((SGMCD1020Q_1.bits.sp3 == 1)&&(SGMCD1020Q_3.bits.sp1 == 0)&&(Get_ID_18FE17EF_Sig_Speed()<5))&&\
  ((Get_ID_18FFA017_Sig_Emergency_Valve_Alarm_Switch()==1)&&(Get_ID_18FE17EF_Sig_Speed()<5))&&\
  ((SGMCD1020Q_2.bits.sp5 == 1)&&(Get_ID_18FE17EF_Sig_Speed()<5))&&\
  ((Get_ID_18FFA017_Sig_Emergency_Switch()==1)&&(Get_ID_18FE17EF_Sig_Speed()<5)))
  {
    /* DRV8242S-Q1 */
  }
  
  /*4.2.41、 前门关电磁阀(OUT63)*/
  if( (((SGMCD1020Q_3.bits.sp1 == 1))&&((SGMCD1020Q_1.bits.sp3 == 1)||(Get_ID_18FE17EF_Sig_Speed()<5)||(SGMCD1020Q_2.bits.sp5 == 1)))||\
  ((Get_ID_18FFA017_Sig_Emergency_Switch()==1)&&(Get_ID_18FFA017_Sig_Hand_Brake()==1)))
  {
    /* DRV8242S-Q1 */
  }
  /*4.2.42、 中门开电磁阀(OUT64)*/
  /*DRV8242S-Q1*/
  /*4.2.43、 中门关电磁阀(OUT65)*/
  /*DRV8242S-Q1*/
  /*4.2.44、 中门警示灯输出(OUT66)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_1.bits.sp4 == 1))
  {
    TPS2HB35_SetOutput5A_OUT3(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT3(0);
  }
  /*4.2.45、 空压机使能(OUT67)*/
  if (SGMCD1020Q_3.bits.sp3 == 1)
  {
    TPS2HB35_SetOutput5A_OUT4(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT4(0);
  }
  /*4.2.46、 路牌电源3(OUT68)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_1.bits.sp6 == 1))
  {
    TPS2HB35_SetOutput5A_OUT5(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT5(0);
  }
  /*4.2.47、 车内屏电源(OUT69)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) && (SGMCD1020Q_2.bits.sg9 == 1))
  {
    TPS2HB35_SetOutput5A_OUT6(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT6(0);
  }
  /*4.2.48、 门泵抑制阀电源(OUT70)*/
  if( (Get_ID_18FFA017_Sig_Instrument_Igon_Wake_Up_Power() == 1)&&(Get_ID_18FE17EF_Sig_Speed()>=3))
  {
    TPS2HB35_SetOutput5A_OUT7(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT7(0);
  }
  /*4.2.49、 后仓门锁电源(OUT71)*/
  if ((Get_ID_18FF4AEF_Sig_Power_On_High_Voltage_Indicator() == 1) && (SGMCD1020Q_2.bits.sg8 == 1))
  {
    TPS2HB35_SetOutput5A_OUT8(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT8(0);
  }
  /*4.2.50、 后仓灯电源(OUT72)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) ||((SGMCD1020Q_3.bits.sg4 == 1)&& (Get_ID_18FF4AEF_Sig_Reverse_Gear_Signal() == 1)))
  {
    TPS2HB35_SetOutput5A_OUT9(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT9(0);
  }
  /*4.2.51、 后顶部示廓灯(OUT73)*/
  if ((Get_ID_18FFA017_Sig_Main_Power_Switch() == 1) &&((SGMCD1020Q_2.bits.sg5 == 1)||((SGMCD1020Q_1.bits.sg5 == 1)&& (Get_ID_18FFFE9C_Sig_Small_Lamp_Control_Output() == 1))))
  {
    TPS2HB35_SetOutput5A_OUT9(1);
  }
  else
  {
    TPS2HB35_SetOutput5A_OUT9(0);
  }
  /*4.2.52、 倒车蜂鸣器(OUT76)*/
  /*4.2.53、 左后示廓灯(OUT77)*/
  /*4.2.54、 右后示廓灯(OUT78)*/
  /*4.2.55、 任意门开输出(OUT79)*/
  /*4.2.56、 雨雪模式(OUT81)*/
  /*4.2.57、 前门警示灯输出(OUT82)*/
  /*4.2.58、 ASR输出信号(OUT83)*/
  /*4.2.59、 Autohold输出信号(OUT84)*/
}
