
#include "Warning_Processor.h"

/*** 机油压力低 ***/
volatile uint8_t  WarningLowOilPressureTel;
volatile uint8_t  WarningLowOilPressurePopup;
WarningLowOilPressureStruct WarningLowOilPressure;

/*** 驻车制动 ***/
volatile uint8_t  WarningParkingBrakeTel;
volatile uint8_t  WarningParkingBrakePopup;
WarningItemStruct WarningParkingBrake;

/*** 主驾安全带 ***/
volatile uint8_t  WarningSeatbeltDrTel;
volatile uint8_t  WarningSeatbeltDrPopup;
WarningItemStruct WarningSeatbeltDr;

/*** 安全气囊 ***/
volatile uint8_t  WarningAirbagTel;
volatile uint8_t  WarningAirbagPopup;
WarningItemStruct WarningAirBag;

/*** 副驾安全带 ***/
volatile uint8_t  WarningSeatbeltPaTel;
volatile uint8_t  WarningSeatbeltPaPopup;
WarningItemStruct WarningSeatbeltPa;

/***** 胎压 ******/
volatile uint8_t  WarningTPMSSignalAbnormal;
WarningItemStruct WarningTPMS;  

/***** 门开 *****/
volatile uint8_t  WarningDoorOpenMode;
volatile uint8_t  WarningDoorOpenSoundEnable;
volatile uint8_t  WarningDoorStatus;

/***** 蹄片报警*****/
volatile uint8_t  WarningHOOVEMode;
volatile uint8_t  WarningHOOVESoundEnable;
volatile uint8_t  WarningHOOVEStatus;

void Warning_Signal_Init(void)
{
  //请松开手刹
  WarningParkingBrakeTel      = WARNING_TEL_OFF;
  WarningParkingBrakePopup    = WARNING_POPUP_OFF;
  WarningParkingBrake.Flag    = 0;
  WarningParkingBrake.Timer   = 0;

  //主驾安全带
  WarningSeatbeltDrTel        = WARNING_TEL_OFF;
  WarningSeatbeltDrPopup      = WARNING_POPUP_OFF;
  WarningSeatbeltDr.Flag      = 0;
  WarningSeatbeltDr.Timer     = 0;

  //门开
  WarningDoorOpenMode         = WARNING_DOOR_OPEN_SINGLE;;
  WarningDoorOpenSoundEnable  = 0;
  WarningDoorStatus           = 0;
  
  //蹄片报警
  WarningHOOVEMode           = 0;;
  WarningHOOVESoundEnable    = 0;
  WarningHOOVEStatus         = 0;

}

//100ms
void Warning_Processing_Service(void)
{
  //----hyq--20180705
  //if (SYS_OPR_STAT_IGN_ON)
  //  Line_In_Enable(1);
  //else
  //  Line_In_Enable(0);         
  //----hyq--20180705
  
  //Warning_Parking_Brake_Processing();
  //Warning_Seatbelt_Dr_Processing();
  //Warning_Seatbelt_Pa_Processing();
  //Warning_Door_Open_Processing();
  //Warning_HOOVES_Processing();
  //Warning_TPMS_Processing();
}

//请松开手刹
//void Warning_Parking_Brake_Processing(void)
//{
//  if(SYS_OPR_STAT_IGN_ON)
//  {
//    if(LINE_IN_Parking_Brake_SIGNAL == 0)                               // PINA1  
//    {
//      if ((DATA_VEHICLE_SPEED_VALID  != 0) && (DATA_VEHICLE_SPEED_ACTUAL >= 30))
//      {
//        WarningParkingBrakeTel = WARNING_TEL_FLASH_1Hz;
//        WarningParkingBrakePopup = WARNING_POPUP_1;
//      }
//      else
//      {
//        WarningParkingBrakeTel = WARNING_TEL_ON;
//        WarningParkingBrakePopup = WARNING_POPUP_OFF;
//      }
//       
//    }
//    else
//    {
//      WarningParkingBrakeTel   = WARNING_TEL_OFF;
//      WarningParkingBrakePopup = WARNING_POPUP_OFF;
//    }
//  }
//  else
//  {
//    WarningParkingBrakeTel   = WARNING_TEL_OFF;
//    WarningParkingBrakePopup = WARNING_POPUP_OFF;
//  }
//}

//主驾安全带
//void Warning_Seatbelt_Dr_Processing(void)
//{
//  if (SYS_IGN_OFF_DISP_MODE)
//  {
//    WarningSeatbeltDrTel   = WARNING_TEL_OFF;
//    WarningSeatbeltDrPopup = WARNING_POPUP_OFF;
//  }
//  else
//  {
//    if (LINE_IN_SEATBELT_SIGNAL == 0)     //如果PINA2为低电平灯亮
//    {
//      WarningSeatbeltDrTel = WARNING_TEL_ON;
//      if(WarningSeatbeltDrPopup == WARNING_POPUP_OFF)
//      {
//        if(DATA_VEHICLE_SPEED_ACTUAL >= 30)
//          WarningSeatbeltDrPopup = WARNING_POPUP_1;
//        else
//          WarningSeatbeltDrPopup = WARNING_POPUP_OFF;
//      }
//      else
//      {
//        if(DATA_VEHICLE_SPEED_ACTUAL < 30)
//          WarningSeatbeltDrPopup = WARNING_POPUP_OFF;
//      }
//    }
//    else
//    {
//      WarningSeatbeltDrTel   = WARNING_TEL_OFF;
//      WarningSeatbeltDrPopup = WARNING_POPUP_OFF;
//    }
//  }
//}
////副驾安全带
//void Warning_Seatbelt_Pa_Processing(void)
//{
//  if (SYS_IGN_OFF_DISP_MODE)
//  {
//    WarningSeatbeltDrTel   = WARNING_TEL_OFF;
//    WarningSeatbeltDrPopup = WARNING_POPUP_OFF;
//  }
//  else
//  {
//    if (LINE_IN_SEATBELT_2_SIGNAL == 0)
//    {
//      WarningSeatbeltPaTel = WARNING_TEL_ON;
//      if(WarningSeatbeltPaPopup == WARNING_POPUP_OFF)
//      {
//        if(DATA_VEHICLE_SPEED_ACTUAL >= 30)
//          WarningSeatbeltPaPopup = WARNING_POPUP_1;
//        else
//          WarningSeatbeltPaPopup = WARNING_POPUP_OFF;
//      }
//      else
//      {
//        if(DATA_VEHICLE_SPEED_ACTUAL < 30)
//          WarningSeatbeltPaPopup = WARNING_POPUP_OFF;
//      }
//    }
//    else
//    {
//      WarningSeatbeltPaTel   = WARNING_TEL_OFF;
//      WarningSeatbeltPaPopup = WARNING_POPUP_OFF;
//    }
//  }
//}
////门开
//void Warning_Door_Open_Processing(void)
//{
//  if(SYS_OPR_STAT_IGN_ON)
//  {
//    if (WarningDoorOpenSoundEnable)
//    {
//      if ((DATA_ENGINE_SPEED_ACTUAL < DATA_ENGINE_STOP_THRESHOLD) || (DATA_ENGINE_SPEED_VALID == 0))
//        WarningDoorOpenSoundEnable = 0;
//    }
//    else
//    {
//      if ((DATA_ENGINE_SPEED_ACTUAL > DATA_ENGINE_RUNNING_THRESHOLD) && (DATA_ENGINE_SPEED_VALID))
//        WarningDoorOpenSoundEnable = 1;
//    }
//    WarningDoorStatus = 0;
//    if (BCM_DriverDoorStatus)      WarningDoorStatus |= WARNING_DOOR_FL;
//    if (BCM_PassengerDoorStatus)   WarningDoorStatus |= WARNING_DOOR_FR;
//    if (BCM_LeftRearDoorStatus)    WarningDoorStatus |= WARNING_DOOR_RL;
//    if (BCM_RightRearDoorStatus)   WarningDoorStatus |= WARNING_DOOR_RR;
//
//    if (WarningDoorOpenSoundEnable)         //声音被使能表示发动机在运转中
//    {
//      if (WarningDoorOpenMode == WARNING_DOOR_OPEN_HIGH_SPEED)
//      {
//        if (DATA_VEHICLE_SPEED_ACTUAL < 50)
//          WarningDoorOpenMode = WARNING_DOOR_OPEN_SINGLE;
//      }
//      else
//      {
//        if (DATA_VEHICLE_SPEED_ACTUAL >= 50)
//          WarningDoorOpenMode = WARNING_DOOR_OPEN_HIGH_SPEED;
//      }
//    }
//    else
//      WarningDoorOpenMode = WARNING_DOOR_OPEN_SINGLE;
//  }
//  else
//  {
//    WarningDoorOpenSoundEnable = 0;
//    WarningDoorOpenMode = WARNING_DOOR_OPEN_SINGLE;
//
//    if (BCM_0x350_STATUS & CAN_MSG_LOST)
//      WarningDoorStatus  = 0;
//    else
//    {
//      WarningDoorStatus = 0;
//      if (BCM_DriverDoorStatus)      WarningDoorStatus |= WARNING_DOOR_FL;
//      if (BCM_PassengerDoorStatus)   WarningDoorStatus |= WARNING_DOOR_FR;
//      if (BCM_LeftRearDoorStatus)    WarningDoorStatus |= WARNING_DOOR_RL;
//      if (BCM_RightRearDoorStatus)   WarningDoorStatus |= WARNING_DOOR_RR;
//    }
//  }
//}
//蹄片磨损
//void Warning_HOOVES_Processing(void)
//{
//  if(SYS_OPR_STAT_IGN_ON)
//  {
//    WarningHOOVEStatus = 0;
//    if (LINT_LF_HOOVES_IN_SIGNAL)   WarningHOOVEStatus |= WARNING_HOOVES_LF;
//    if (LINE_RF_HOOVES_IN_SIGNAL)   WarningHOOVEStatus |= WARNING_HOOVES_RF;
//    if (LINE_LR_HOOVES_IN_SIGNAL)   WarningHOOVEStatus |= WARNING_HOOVES_LR;
//    if (LINT_RR_HOOVES_IN_SIGNAL)   WarningHOOVEStatus |= WARNING_HOOVES_RR;
//  }
//  else 
//  {
//     WarningHOOVEStatus = 0;
//  }
//}
//胎压
void Warning_TPMS_Processing(void)
{
/*
  if(NVM_CONFIG_TPMS == NVM_FUNC_DISABLE)
  {
    WarningTPMSTel    = WARNING_TEL_OFF;
    WarningTPMS.Timer = 0;
    WarningTPMS.LostTimer = 0;
    return;
  }

  if(SYS_OPR_STAT_IGN_ON)
  {
    //if ((TPMS_TyreWarn_STATUS & CAN_MSG_LOST) || (TPMS_TyreDataInfo_STATUS & CAN_MSG_LOST) || (TPMS_TempStatusInfo_STATUS & CAN_MSG_LOST)) 
    if(0)
    {
      if(WarningTPMS.LostTimer < 3000)
        WarningTPMS.LostTimer++;
      else
        WarningTPMSSignalAbnormal = 1;
    } 
    else 
    {
      WarningTPMSSignalAbnormal = 0;
      WarningTPMS.LostTimer = 0;
    }
    
    //if (TPMS_TyreWarn_STATUS & CAN_MSG_LOST)
    if(0)
    {      
      if ((WarningTPMS.Flag == 0) && (WarningTPMS.LostTimer >= 3000))
      {
        WarningTPMS.Flag = 1;
        WarningTPMS.Timer = 0;
      }
      
      if(WarningTPMS.Flag) 
      {        
        if (WarningTPMS.Timer < 586)
        {
          WarningTPMSTel = WARNING_TEL_FLASH_1Hz;
          WarningTPMS.Timer++;                    
        }
        else 
        {
          if (FLASH_SYNC_1Hz)
            WarningTPMSTel = WARNING_TEL_ON;
        }
      } 
    }
    else
    {
      if (WarningTPMS.Flag == 1)
      {
        WarningTPMS.Flag = 0;
        WarningTPMS.Timer = 0;
        WarningTPMS.LostTimer = 0;
      }
      
      //switch (TPMS_SystemSt)
      switch(0)
      {
        case 0  : WarningTPMSTel    = WARNING_TEL_OFF;
                  WarningTPMS.Timer = 0;
                  break;
                  
        case 1  : if (WarningTPMS.Timer < 600)
                  {
                    WarningTPMSTel = WARNING_TEL_FLASH_1Hz;
                    WarningTPMS.Timer++;                    
                  }
                  else
                  {
                    if (FLASH_SYNC_1Hz)
                      WarningTPMSTel = WARNING_TEL_ON;
                  }
                  break;
                  
        case 2  : WarningTPMSTel    = WARNING_TEL_ON;
                  WarningTPMS.Timer = 0;
                  break;
                  
        case 3  : WarningTPMSTel    = WARNING_TEL_FLASH_1Hz;
                  WarningTPMS.Timer = 0;
                  break;
                  
        default : break;                  
                   
      }
    }
  }
  else
  {
    WarningTPMSTel    = WARNING_TEL_OFF;
    WarningTPMS.Timer = 0;
    WarningTPMS.Flag  = 0;
    WarningTPMS.LostTimer = 0;
  } 
  */
}

















