#include <FU68xx_5.h>
#include <Myproject.h>


FaultStateType data mcFaultSource;      ///< 故障类型




/**
    @brief      偏置电压检测
*/
void Fault_GetCurrentOffset(void)
{
    if (mcCurOffset.OffsetFlag == 1)
    {
        #if (VHALF_EN == Enable)                                              //有加VHALF偏置，理论值为16383
        {
            #if (Shunt_Resistor_Mode == Single_Resistor)                   //单电阻模式
            {
                if ((mcCurOffset.Iw_busOffset < GetCurrentOffsetValueLow) || (mcCurOffset.Iw_busOffset > GetCurrentOffsetValueHigh))
                {
                    mcFaultSource = FaultGetOffset;
                }
            }
            #elif (Shunt_Resistor_Mode == Double_Resistor)                 //双电阻模式
            {
                if ((mcCurOffset.IuOffset < GetCurrentOffsetValueLow) || (mcCurOffset.IuOffset > GetCurrentOffsetValueHigh)
                    || (mcCurOffset.IvOffset < GetCurrentOffsetValueLow) || (mcCurOffset.IvOffset > GetCurrentOffsetValueHigh))
                {
                    mcFaultSource = FaultGetOffset;
                }
            }
            #elif (Shunt_Resistor_Mode == Three_Resistor)                 //三电阻模式
            {
                if ((mcCurOffset.IuOffset < GetCurrentOffsetValueLow) || (mcCurOffset.IuOffset > GetCurrentOffsetValueHigh)
                    || (mcCurOffset.IvOffset < GetCurrentOffsetValueLow) || (mcCurOffset.IvOffset > GetCurrentOffsetValueHigh)
                    || (mcCurOffset.Iw_busOffset < GetCurrentOffsetValueLow) || (mcCurOffset.Iw_busOffset > GetCurrentOffsetValueHigh))
                {
                    mcFaultSource = FaultGetOffset;
                }
            }
            #endif
        }
        #else                                                              //没加VHALF偏置,理论值在0
        {
            #if (Shunt_Resistor_Mode == Single_Resistor)                   //单电阻模式
            {
                if (mcCurOffset.Iw_busOffset > GetCurrentOffsetValue)
                {
                    mcFaultSource = FaultGetOffset;
                }
        
            }
            #elif (Shunt_Resistor_Mode == Double_Resistor)                 //双电阻模式
            {
                if ((mcCurOffset.IuOffset > GetCurrentOffsetValue) || (mcCurOffset.IvOffset > GetCurrentOffsetValue))
                {
                    mcFaultSource = FaultGetOffset;
                }
            }
            #elif (Shunt_Resistor_Mode == Three_Resistor)                 //三电阻模式
            {
                if ((mcCurOffset.IuOffset > GetCurrentOffsetValue) || (mcCurOffset.IvOffset > GetCurrentOffsetValue) || (mcCurOffset.Iw_busOffset > GetCurrentOffsetValue))
                {
                    mcFaultSource = FaultGetOffset;
                }
            }
            #endif
        }
        #endif
    }
}
