#ifndef __TCU_TC_H__
#define __TCU_TC_H__
#include "tc_system.h"

void ccu_Update_serialID(const char* serialID);
void ccu_Update_UTC(void);

void ccu_Update_GUNA_Type(uint16_t type);
void ccu_Update_GUNB_Type(uint16_t type);

void ccu_Update_GUNA_IVE(uint16_t maxI, uint16_t currI, uint16_t currV, uint32_t totalE, uint32_t currE);
void ccu_Update_GUNB_IVE(uint16_t maxI, uint16_t currI, uint16_t currV, uint32_t totalE, uint32_t currE);

typedef enum workstate
{
    WORKSTATE_IDLE = 0,
    WORKSTATE_PLUGIN,
    WORKSTATE_RESV2,
    WORKSTATE_CHARGING,
    WORKSTATE_END,
    WORKSTATE_FAULT,
    WORKSTATE_RESV6,
    WORKSTATE_UPDATING,
    WORKSTATE_STARTING,
    WORKSTATE_RESV9,
    WORKSTATE_RESV10,
    WORKSTATE_RESV11,
    WORKSTATE_FORBID
}workstate_t;
void ccu_Update_GUNA_WorkState(uint16_t state);
void ccu_Update_GUNB_WorkState(uint16_t state);

typedef enum linkstate
{
    LINKSTATE_NONE = 0,
    LINKSTATE_HALF,
    LINKSTATE_FULL,
}linkstate_t;
void ccu_Update_GUNA_LinkState(uint16_t state);
void ccu_Update_GUNB_LinkState(uint16_t state);

void ccu_Update_GUNA_K1K2Voltage(uint32_t vol);
void ccu_Update_GUNB_K1K2Voltage(uint32_t vol);

void ccu_Update_GUNA_ContactorState(uint8_t K1K2);
void ccu_Update_GUNB_ContactorState(uint8_t K1K2);

void ccu_Update_GUNA_ElecLockState(uint8_t state);
void ccu_Update_GUNB_ElecLockState(uint8_t state);

void ccu_Update_GUNA_PowerOn(uint8_t state);
void ccu_Update_GUNB_PowerOn(uint8_t state);

void ccu_Update_GUNA_mac_addr(void);
void ccu_Update_GUNB_mac_addr(void);
void ccu_Update_GUNA_HMAC(void);
void ccu_Update_GUNB_HMAC(void);


typedef enum power_request_type
{
    PRT_ACDC_PLACEHOLDER = 0x1,
    PRT_INSLUATION_DETECTION_START = 0x2,
    PRT_INSLUATION_DETECTION_STOP = 0x3,
    PRT_PRECHARGING = 0x4,
    PRT_CHARGING = 0x5
}power_request_type_t;
typedef enum power_request_mode
{
    PRM_CONSTANT_VOLTAGE = 0x1,
    PRM_CONSTANT_CURRENT = 0x2
}power_request_mode_t;
void ccu_GUNA_PowerRequest(uint16_t type, uint16_t mode, float voltageV, float currentA);
void ccu_GUNB_PowerRequest(uint16_t type, uint16_t mode, float voltageV, float currentA);

typedef enum shuntdown_request_reason
{
    SRR_NORMAL = 0x0,
    SRR_GUN_FALLOFF = 0x1,
    SRR_GUN_OFFLINE = 0x2,
    SRR_GUN_INSULTION_ERR = 0x3,
    SRR_GUN_EMGSTOP = 0x4,
    SRR_GUN_PARAM_ERR = 0x5,
    SRR_GUN_SECC_ERR = 0x6,
    SRR_GUN_EVCC_ERR = 0x7,
    SRR_GUN_COMM_ERR = 0x8,
    SRR_GUN_HOST_ERR = 0x9
}shuntdown_request_reason_t;
void ccu_GUNA_ShuntdownRequest(uint16_t reason);
void ccu_GUNB_ShuntdownRequest(uint16_t reason);

void ccu_GUNA_Ctrl_K1(int close);
void ccu_GUNA_Ctrl_K2(int close);

void ccu_GUNB_Ctrl_K1(int close);
void ccu_GUNB_Ctrl_K2(int close);

int ccu_GUNA_Query_K1_State(void);
int ccu_GUNA_Query_K2_State(void);

int ccu_GUNB_Query_K1_State(void);
int ccu_GUNB_Query_K2_State(void);

uint32_t ccu_GUNA_Query_OutputVoltage(void);
uint32_t ccu_GUNB_Query_OutputVoltage(void);

void ccu_GUNA_LED_OnOff(int enable);
void ccu_GUNA_LED_Toggle(void);
void ccu_GUNA_LED_State(uint8_t state);

void ccu_GUNB_LED_OnOff(int enable);
void ccu_GUNB_LED_Toggle(void);
void ccu_GUNB_LED_State(uint8_t state);

int ccu_TCU_init(void);
void ccu_TCU_run(int quit);
void ccu_TCU_exit(void);

#endif//__TCU_TC_H__
