
#ifndef _UDS_SERVICES_COMMON_H_
#define _UDS_SERVICES_COMMON_H_
//<<Wang
#include "Std_Types.h"
//Wang>>

#include "UDS_ServicesType.h"
/* ---------------------------------------------------------------------------
 * Includes
 */
//#include "Platform_Types.h"

/* ---------------------------------------------------------------------------
 * Exported Constants
 */
#define UDS_FICOSA_SESSION UDS_SYSTEM_SUPPLIER_SPECIFIC_SESSION_ID

/** Redefine project_config.mk imports for:
 * - IDE indexing consistency
 * - Defaults set
 */
#ifndef ECU_HW_ID
	#define ECU_HW_ID "000A00"
	//#warning "Using default ECU_HW_ID"
#endif

#ifndef ECU_SW_ID
	#define ECU_SW_ID "A00RC3"
	//#warning "Using default ECU_SW_ID"
#endif

#define FICOSA_DEBUG
/** End of project_config redefines **/
#define IO_CTL_RETURN_CONTOL		((UI_8)0x00)
#define IO_CTL_RESET        		((UI_8)0x01)
#define IO_CTL_FREEZE       		((UI_8)0x02)
#define IO_CTL_CONTROL       		((UI_8)0x03)
/* ---------------------------------------------------------------------------
 * Exported Macros
 */
#define DTC_SETTING_HIGH_VOLTAGE_NUM   				((uint8)0)
#define DTC_SETTING_LOW_VOLTAGE_NUM    				((uint8)1)
#define DTC_SETTING_INVALID_TCU_NUM    				((uint8)2)
#define DTC_SETTING_INVALID_EMS_NUM    				((uint8)3)
#define DTC_SETTING_INVALID_PEDAL_NUM   			((uint8)30)
#define DTC_SETTING_INVALID_BCS_NUM    				((uint8)4)
#define DTC_SETTING_INVALID_SPEED_NUM    			((uint8)17)
#define DTC_SETTING_LOST_APA_NUM    				((uint8)5)
#define DTC_SETTING_INVALID_APA_NUM    				((uint8)6)
#define DTC_SETTING_LOST_BCM_NUM    				((uint8)7)
#define DTC_SETTING_LOST_ICM_NUM    				((uint8)9)
#define DTC_SETTING_INVALID_ICM_NUM    				((uint8)10)
#define DTC_SETTING_LOST_EMS_NUM    				((uint8)11)
//#define DTC_SETTING_LOST_TCU_NUM    				((uint8)12)
#define DTC_SETTING_LOST_VCU_NUM    				((uint8)12)
#define DTC_SETTING_LOST_BCS_NUM    				((uint8)13)
#define DTC_SETTING_LOST_SRS_NUM    				((uint8)15)
#define DTC_SETTING_BUS_OFF_NUM    					((uint8)16)
#define DTC_SETTING_SENSOR_DIE1_FAULT_NUM    		((uint8)18)
#define DTC_SETTING_SENSOR_DIE2_FAULT_NUM    		((uint8)19)
#define DTC_SETTING_SENSOR_HEAVY_FAULT_NUM    		((uint8)20)
#define DTC_SETTING_SWITCH_HEAVY_FAULT_NUM    		((uint8)21)
#define DTC_SETTING_SWITCH1_OC_FAULT_NUM    		((uint8)22)
#define DTC_SETTING_SWITCH1_GND_FAULT_NUM    		((uint8)23)
#define DTC_SETTING_SWITCH1_VCC_FAULT_NUM    		((uint8)24)
#define DTC_SETTING_SWITCH1_PRESSED_FAULT_NUM    	((uint8)25)
#define DTC_SETTING_SWITCH2_OC_FAULT_NUM    		((uint8)26)
#define DTC_SETTING_SWITCH2_GND_FAULT_NUM    		((uint8)27)
#define DTC_SETTING_SWITCH2_VCC_FAULT_NUM    		((uint8)28)
#define DTC_SETTING_SWITCH2_PRESSED_FAULT_NUM    	((uint8)29)

#define DTC_SETTING_PADDLE_OC_FAULT_NUM    			((uint8)32)
#define DTC_SETTING_PADDLE_GND_FAULT_NUM    		((uint8)33)
#define DTC_SETTING_PADDLE_VCC_FAULT_NUM    		((uint8)34)
#define DTC_SETTING_PADDLE_PRESSED_FAULT_NUM    	((uint8)35)

#define DTC_SETTING_OL_GND_FAULT_NUM    			((uint8)46)
#define DTC_SETTING_OL_VCC_FAULT_NUM    			((uint8)47)

#define DTC_SETTING_ECO_OC_FAULT_NUM    			((uint8)49)
#define DTC_SETTING_ECO_GND_FAULT_NUM    			((uint8)50)
#define DTC_SETTING_ECO_VCC_FAULT_NUM    			((uint8)51)
#define DTC_SETTING_ECO_PRESSED_FAULT_NUM    		((uint8)48)

#define DTC_SETTING_LOST_ACM_NUM    				((uint8)53)
#define DTC_SETTING_INVALID_ACM_NUM    				((uint8)54)
#define DTC_SETTING_ACM_FAULT_NUM    				((uint8)55)

#define DTC_SETTING_GSS_FAULT_NUM    				((uint8)56)
#define DTC_SETTING_SHIFT_STUCKED_FAULT_NUM    		((uint8)57)
#define DTC_SETTING_SHIFT_CALIB_FAULT_NUM    		((uint8)58)

#define TEST_DTC_SETTING_ENABLE(v)                  ((((p_dtc_setting[v/8]>>(v%8))&0x01) > 0)?1:0)

/* ---------------------------------------------------------------------------
 * Exported Types
 */
typedef uint8 t_UDS_ERR;
typedef uint8 t_UDS_Session;
extern uint8* p_dtc_setting;
extern boolean clear_dtc_flag;
extern UI_16 g16_DiagTouchPressSenRes[3][15];
/* ---------------------------------------------------------------------------
 * Exported Variables
 */
extern t_UDSIOControlSubCommands uds_io_control_commands[];
extern t_UDSRoutineControlCommands uds_routine_control_commands[];
extern t_UDSReadDidSubCommands uds_did_read_commands[];
extern t_UDSWriteDiDSubCommandsReference uds_did_write_commands_by_reference[];
extern uint8 GetRoutineServiceNumber(void);
extern uint8 GetIoControlServiceNumber(void);
extern uint8 GetWriteDidServiceNumber(void);
extern uint8 GetReadDidServiceNumber(void);
/* ---------------------------------------------------------------------------
 * Exported Functions
 */
uint8 UDS_ReadDiD_CB(uint8 id_h, uint8 id_l);
uint8 UDS_WriteDiD_CB(uint8 id_h, uint8 id_l, uint8 *buf_data_rx, uint16 size);
uint8 UDS_ReadMCAL_CB(uint16 requested_id, uint16 resp_pos);
void  UDS_RoutineControl_CB(uint8 routine_ctrl_type, uint8 id_high, uint8 id_low, uint8 *routine_entry_option, uint16 size);
void  UDS_IOControl_CB(uint8 id_h, uint8 id_l, uint8 io_ctrl_type, uint8* buf_data_rx, uint16 size);
void UDS_DTCSetting_CB(uint8 sub_function,  uint8 *buf_data_rx, uint16 size);
/* NVM DIDs */
t_UDS_ERR Get_DID_ECU_SN(uint8 *data);
t_UDS_ERR Set_DID_ECU_SN(uint8 *data);

t_UDS_ERR Get_DID_CD_SYSID_VIN(uint8 *data);
t_UDS_ERR Set_DID_CD_VIN(uint8 *data);

t_UDS_ERR Get_DID_TouchSen1_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen2_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen3_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen4_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen5_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen6_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen7_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen8_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen9_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen10_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen11_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen12_BaseLine(uint8 *data);
t_UDS_ERR Get_DID_TouchSen13_BaseLine(uint8 *data);

t_UDS_ERR Get_DID_TouchSen1_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen2_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen3_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen4_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen5_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen6_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen7_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen8_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen9_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen10_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen11_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen12_Signal(uint8 *data);
t_UDS_ERR Get_DID_TouchSen13_Signal(uint8 *data);

t_UDS_ERR Get_DID_PressSen_Baseline(uint8 *data);
t_UDS_ERR Get_DID_PressSen_Signal(uint8 *data);
t_UDS_ERR Get_DID_Pre_Value(uint8 *data);
t_UDS_ERR Get_DID_ResetSource(uint8 *data);

t_UDS_ERR Get_DID_CD_SYSID_CALIRATION_DATE(uint8 *data);
t_UDS_ERR Set_DID_CD_CALIRATION_DATE(uint8 *data);

t_UDS_ERR Get_DID_CD_SYSID_MANUF_ECUHWNUM(uint8 *data);
t_UDS_ERR Set_DID_CD_MANUF_ECUHWNUM(uint8 *data);

t_UDS_ERR Get_DID_Dtc_Setting(uint8 *data);
t_UDS_ERR Set_DID_Dtc_Setting(uint8 *data);

t_UDS_ERR Get_DID_Transportation_Mode(uint8 *data);
t_UDS_ERR Set_DID_Transportation_Mode(uint8 *data);

t_UDS_ERR Get_DID_Reprogramming_Counter(uint8 *data);
t_UDS_ERR Get_DID_Reprogramming_Attempt_Counter(uint8 *data);
t_UDS_ERR Get_DID_Reprogramming_Date(uint8 *data);
t_UDS_ERR Set_DID_Manufacture_Date(uint8 *data);
t_UDS_ERR Set_DID_Reprogramming_Date(uint8 *data);
t_UDS_ERR Get_DID_EcuManufacture_Date(uint8 *data);
t_UDS_ERR Get_DID_EcuInstallation_Date(uint8 *data);
t_UDS_ERR Set_DID_EcuInstallation_Date(uint8 *data);
t_UDS_ERR Get_DID_App_Sw_Finger_Print(uint8 *data);
t_UDS_ERR Set_DID_CD_APP_SW_FINGERPRINT(uint8 *data);
t_UDS_ERR Get_DID_Gac_Diagnostic_Version(uint8 *data);

t_UDS_ERR Get_DID_GAC_Repair_Shop_Id(uint8 *data);
t_UDS_ERR Set_DID_Repair_Shop_Code(uint8 *data);

t_UDS_ERR Get_DID_Gac_Hw_Version(uint8 *data);
t_UDS_ERR Get_DID_Gac_Ecusw_Version(uint8 *data);
t_UDS_ERR Get_DID_Gac_Spare_Number(uint8 *data);
t_UDS_ERR Get_DID_System_Supplier_Id(uint8 *data);
t_UDS_ERR Get_DID_Gac_Kit_Part_Number(uint8 *data);
t_UDS_ERR Get_DID_System_Name(uint8 *data);
t_UDS_ERR Get_DID_Uds_Protol_Version(uint8 *data);
t_UDS_ERR Get_DID_Boot_Version(uint8 *data);
t_UDS_ERR Get_DID_DCID(uint8 *data);
t_UDS_ERR Get_DID_Boot_ID(uint8 *data);


t_UDS_ERR Set_DID_Shield_Atp(uint8 *data);
t_UDS_ERR Get_DID_Shield_Atp(uint8 *data);

t_UDS_ERR Set_DID_CD_Shared_key(uint8 *data);

void UDS_DID_initNVM(void);

uint8 Get_Drive_Mode(void);
void Set_RAM_Drive_Mode(uint8 mode);
uint8 GetNvmFaa(void);
uint8 GetNvmManufactoryMode(void);
uint8 GetNvmEolConfig(void);
uint8* GetNvmDtcSetting(void);
boolean doReset(void);

/* Enable Engineering Mode */
boolean isXCPEnabled(void);
boolean isWriteDriversAccessEnabled(void);
uint8 	Get_FC_DevMode(uint8 *data);
uint8 	Set_FC_DevMode(const uint8 *data);

//t_UDS_ERR Set_DID_CD_Drive_Mode_Configure(uint8 *data);
t_UDS_ERR Get_DID_Drive_Mode_Configure(uint8 *data);

void SupportIDCheckFor_2E(uint8 * resp, uint8 id_l);

t_UDS_ERR UDS_ReadSBCResetReason (uint8* data);

uint8 GetLastPosition(void);

#endif /* _UDS_SERVICES_COMMON_H_ */
