#ifndef BMS_DI_DO_H_
#define BMS_DI_DO_H_

#ifdef __cplusplus
extern "C" {
#endif 

#include "kit_macro.h"
#include "logic_ctrl.h"

#define MAX_DI_NUM  9
#define	RELAY_CTRL_NO_DLY		1


typedef enum
{
	kDoStatus_Off, 		
	kDoStatus_On,  		
    kDoStatus_ForceOff, 	
	kDoStatus_ForceOn,
    kDoStatus_Adhesion,
    kDoStatus_Open,
    kDoStatus_End,
} DoStatus;

typedef enum
{
    kDoCtrlStatus_Off,
    kDoCtrlStatus_On,
    kDoCtrlStatus_None,
    kDoCtrlStatus_End,
}DoCtrlStatus;

typedef enum
{
    kDoType_Start = 0,
	kDoType_Unused = kDoType_Start,
    kDoType_Chg,
    kDoType_Dis,
    kDoType_PreChg,	//3
    kDoType_Positive,	//4
    kDoType_Negative,//5
	kDoType_End,	
}DoType;


typedef void (*DoLogic)(uint32_t base_time, uint8_t idx);

typedef enum
{
	kDoErrSrc_Start = 0,
	kDoErrSrc_None = kDoErrSrc_Start, //0
	kDoErrSrc_HV1, //1
	kDoErrSrc_HV2, //2
	kDoErrSrc_DI1,
	kDoErrSrc_DI2,
	kDoErrSrc_DI3,
	kDoErrSrc_DI4,
	kDoErrSrc_DI5,
	kDoErrSrc_DI6,
	kDoErrSrc_DI7,
	kDoErrSrc_DI8,
	kDoErrSrc_DI9,
	kDoErrSrc_End,
}DoErrSrc;


typedef enum
{
	kDiType_Start = 0,
	kDiType_Unused= kDiType_Start,
    kDiType_FireAlarm1,      //消防1
	kDiType_EmergStop1,      //急停
    kDiType_Do1Feedback,
	kDiType_Do2Feedback,
    kDiType_Do3Feedback,
    kDiType_Do4Feedback,  
	kDiType_Do5Feedback,
    kDiType_Do6Feedback,
    kDiType_Do7Feedback,  
	kDiType_Do8Feedback,
    kDiType_End
}DiType;

typedef enum
{
	kDiStatus_None,
	kDiStatus_Trigger,
	kDiStatus_End,
}DiStatus;

typedef enum
{
	kDiPolarity_Start = 0,
	kDiPolarity_Open = kDiPolarity_Start,//常开
	kDiPolarity_Close,//常闭
	kDiPolarity_End,
}DiPolarity;//DI极性枚举


void bms_cut_all_relay(void);
bool bms_is_do_config(DoType type);
void bms_poll_di_do(uint32_t base_time);
void bms_set_do_fault(DoType type, DoStatus status);
void bms_force_crtl_do_status(uint8_t idx, DoCtrlStatus status);
typedef void (*DiFun)(uint32_t base_time, DiStatus di_st, DiType di);
void bms_crtl_do_status(DoType type, DoCtrlStatus status, uint16_t dly);
void bms_crtl_do_status_by_idx(uint8_t idx, DoCtrlStatus status, uint16_t dly);
void bms_init_di_do(const DoLogic *do_main_poll_array, uint8_t do_main_poll_len, const DoLogic *do_poll_array);

DiType   bms_get_di_type(uint8_t idx);
DiStatus bms_get_di_status(DiType type);
DiPolarity bms_get_di_polarity(uint8_t idx);

DoType   bms_get_do_type(uint8_t idx);
DoErrSrc bms_get_do_err_src(DoType type);
DoStatus bms_get_do_status_by_idx(uint8_t idx);
DoStatus bms_get_do_status_by_type(DoType type);
DoCtrlStrategy bms_get_main_ctrl_strategy(void);


#ifdef __cplusplus
}
#endif

#endif
