/**
	******************************************************************************
	* @file
	* @author
	* @version
	* @date
	* @brief
	* @function List:
	******************************************************************************
	* @attention
	*
	*
	* <h2><center>&copy; COPYRIGHT 2021 </center></h2>
	******************************************************************************
	* @History:
	* @Author:
	* @Data:
	* @Version:
*/
#ifndef _DEMM_H_
#define _DEMM_H_

#include "Dem_Types.h"
#include "DEM_Cfg.h"
#include "error.h"
#include "common_types.h"

#define DEM_ENTER_CRITICAL_METHOD  (3u)

#if 1  //把目前沒有用到的放一起注明
#define DEM_DEV_ERR_CHECK (0u)  //目前好像沒用到

#define DESC_TOTAL_ROUTINE_CONTROL_NUM          1u
#define DESC_TOTAL_ROUTINE_CONTROL_TYPE_NUM     3u
#define DEM_EEPROM_RES_PROTECTED  1u   /* DEM 用到的存储EPROM 服务是否启用资源保护*/
#endif

/* Define ControlDTCSetting sub service */
#define DESC_CONTROL_DTC_SETTING_ON                               (TRUE) //  1
#define DESC_CONTROL_DTC_SETTING_OFF                              (FALSE) //  2

#if 1  //把目前沒有用到的放一起注明
/* Define Read Memory BY Address Sub Service */
#define DESC_READ_MEMORY_BY_ADDRESS_SHORT_ADDR                      0x14
#define DESC_READ_MEMORY_BY_ADDRESS_LONG_ADDR                       0x24

/* Define Read Memory BY Address Sub Service */
#define DESC_WRITE_MEMORY_BY_ADDRESS_SHORT_ADDR                     0x14
#define DESC_WRITE_MEMORY_BY_ADDRESS_LONG_ADDR                      0x24


#define DESC_SERVICE_REQ_LENGTH_NEED_CHECK                          0xff

#define DESC_TIMER_100MS                                            20 /* unit: can_desc_task Call Cycle Time * Value, here 5 ms * 20 =  100ms */
#define DESC_TESTER_PRESENT_TIME_OUT_DELAY_TIME                     140 /* unit: 100ms, here 50 * 100 ms =  5s */
#endif

/* 應用程序接口*/
//void dem_set_test_result(dtc_handle_t dtc_index, test_result_state_e result);
//void dem_clear_test_result(dtc_handle_t dtc_index);
//void dem_task_init(void);

void dem_task_init(void);
/**
* @brief dtc_task 任務
* @retval none
*/
void dem_task(void);

/*
用於通過本地條件是否使能DTC 檢測*/
void dem_enable_dtc_record_update(void);
void dem_disable_dtc_record_update(void);


/* DCM 模塊接口*/

/*
用於通過來自網絡的UDS 命令, 控制DTC 是否使能DTC檢測
*/
void dem_enable_dtc_setting(void);
void dem_disable_dtc_setting(void);


void dem_set_test_result(dtc_handle_t dtc_index, test_result_state_e result);


void dem_clear_test_result(dtc_handle_t dtc_index);

/*
void dem_get_status_of_dtc(void);
void dem_dcm_cancel_operation(void);
void dem_clear_all_dtc_record_information(void);
*/
/* 供DCM調用--根據 DTC三字節的id來清除*/
err_flag_e  dem_clear_dtc(const u8 *dtc);
/*
返回DTC_RECORD.STATE
*/
/*bool_t dtc_get_state(u8 dtc_index, u8 *state);*/
u8  _dem_get_state(dtc_handle_t dtc_index);
void dem_test_fun(void);

/* 19 04  函數調用, dtc index 範圍由調用函數處理,  此函數內部不檢查有效範圍*/
bool demm_copy_snap_short_data_to_dcm_txbuff(dtc_handle_t dtc_index, u8 *dcm_txbuff);
/* 19 06  函數調用, dtc index 範圍由調用函數處理,  此函數內部不檢查有效範圍*/
bool demm_copy_extdata_to_dcm_txbuff(dtc_handle_t dtc_index, u8 *dcm_txbuff);

void demm_operation_cycle_chaned_event_proc(void);



typedef struct
{
	u16 test[TOTAL_DTC_NUM]; /* debug only */
}demm_test_t;


//#define DEMM_DEBUG_EN  //用于debug的

void dem_test_init(void);

#endif
