//DCM_DTC.h
#ifndef DCM_DTC_H
#define DCM_DTC_H

#include "DCM_Types.h"



#define DCM_19SUPDTCEXTDATARECORD_COUNT      (4U)        
/* 19 06支持的DTCExtDataRecord 参数个数 */ 
#define DCM_SUPDTC_COUNT                  ( 14U )       
/* 产品支持的DTC个数 */ 


#define DTC_TEST_CYCLE_TIM	40U			// 40mS一个周期  

#define ISO_15031_6_DTC_FORMAT	0U
#define ISO_14229_1_DTC_FORMAT	1U


#define DTC_STATUS_AVAILABILITY_MASK 0x09U

typedef uint8 (*ReportDTCExtDataFun)(uint8* LeDemDtcNum,uint8 LeDemParameter,uint8* LeDemDataRecord);
/*19 06 服务支持的 DTCExtDataRecordNumber 列表结构体*/
typedef struct
{ 
	uint8 DTCExtDataRecordNumber;         /*扩展数据number*/
	ReportDTCExtDataFun Function;         /*扩展数据number 对应函数的处理函数*/
}DTCExtDataRecordType;

typedef struct
{ 
	uint8 DtcIndex;
	uint8 DtcHigh;         /*DTC 高字节*/      
	uint8 DtcMiddle;       /*DTC 中间字节*/      
	uint8 DtcLow;          /*DTC 低字节*/      
}TsDcm_h_DtcGroupType;

typedef enum
{
	TestFailed 							= 0x01,
	TestFailedThisOperationCycle		= 0x02,
	PendingDTC							= 0x04,
	ConfirmedDTC						= 0x08,
	TestNotCompletedSinceLastClea		= 0x10,
	TestFailedSinceLastClear			= 0x20,
	TestNotCompletedThisOperationCycle	= 0x40,
	WarningIndicatorRequested			=0x80,
}StatusOfDtc_T;

/******************************************************************************
 * Description:     : Global Variable Declaration Section
******************************************************************************/

extern const TsDcm_h_DtcGroupType CaDcm_u_DtcTable[DCM_SUPDTC_COUNT];
extern const DTCExtDataRecordType CaDcm_h_19DTCExtDataRecordTable[DCM_19SUPDTCEXTDATARECORD_COUNT];

typedef struct{
	uint8 DtcStutas;
	bool1 EepWrtEnable;
}DtcStutas_T;


extern DtcStutas_T DtcStutas[DCM_SUPDTC_COUNT];
#if 0
#define AC_BusOff 									0
#define AC_CommunicationLostWithHMI					1 
#define AC_CommunicationLostWithVCU					2 
#define AC_CommunicationLostWithComp				3 
#define AC_PTC_PressureSensorShortCircuit			4 
#define AC_PTC_PressureSensorOpenCircuit			5 
#define AC_BlowermotorShortCircuit					6 
#define AC_BlowermotorOpenCircuit					7 
#define AC_PressureSensorShortCircuit				8 
#define AC_PressureSensorOpenCircuit				9 
#define AC_CoolingPressureTooHight					10 
#define AC_CoolingPressureTooLow					11 
#define AC_COMP_InternalVoltageFault				12 
#define AC_COMP_UnderVoltageFault					13 
#define AC_COMP_OverVoltageFault					14 
#define AC_COMP_OverCurrentFault					15 
#define AC_COMP_TemperatureFault					16 
#define AC_COMP_BusOff								17 
#define AC_COMP_LossCommunicationWithAC				18 
#define AC_EvaporatorTemperatureSensorOpenCircuit	19		
#define AC_EvaporatorTemperatureSensorShortCircuit	20		
#define AC_ServoMotorShortCircuit					21						
#define AC_ServoMotorPositionFault					22		
#define AC_LoopMotorShortCircuit					23		
#define AC_LoopMotorPositionFault					24	

#endif	

#define AC_LOW_VOLTAGE								0  
#define AC_OVER_VOLTAGE								1  
#define AC_TEMP_MOTOR_SHORT_CUT_TO_VCC				2  
#define AC_TEMP_MOTOR_SHORT_CUT_TO_GND				3 
#define AC_TEMP_MOTOR_LOCK							4 
#define AC_MODE_MOTOR_SHORT_CUT_TO_VCC				5  
#define AC_MODE_MOTOR_SHORT_CUT_TO_GND				6  
#define AC_MODE_MOTOR_LOCK							7  
#define AC_REC_MOTOR_SHORT_CUT_TO_VCC				8  
#define AC_REC_MOTOR_SHORT_CUT_TO_GND				9  
#define AC_REC_MOTOR_LOCK							10 
#define AC_EVA_SENSOR_SHORT_CUT_TO_VCC				11 
#define AC_EVA_SENSOR_SHORT_CUT_TO_GND				12 
#define AC_BusOff 									13


extern uint8_t BusOffCnt ;


extern void CanDTC_Task(void);

extern uint8 MngDcm_ReportNumberOfDTCByStatusMask(void);
extern uint8 MngDcm_ReportDTCByStatusMask(void);
//extern uint8 MngDcm_ReportDTCSnapshotRecordByDTCNumber(void);
//extern uint8 MngDcm_ReportDTCExtendedDataRecordByDTCNumber(void);
extern uint8 MngDcm_ReportSupportedDTC(void);

extern bool1 MngDcm_CleanDtc(void);
extern void DtcInit(void);
extern void DtcStutasInit(void);
extern void DtcDiagConditionChk(void);

void ClearDtcStutas(uint8 DtcIndex);

#endif
