
#include "charger_control.h"
#include "charger_config.h"
#include "lock.h"
#include "psu_control.h"

ChargingConnector_t CONN;

void CONN_Init(){

	CONN.connControl = CMD_NONE;
	CONN.connState   = Unknown;
	CONN.RequestedVoltage = PSU_MIN_VOLTAGE;

}

void CONN_Loop(){
    static CONN_State_t last_connState = Unknown;
	if(last_connState != CONN.connState){
		last_connState = CONN.connState;
		CONN.connControl = CMD_NONE;
	}

	if(GBT_LockState.error){
		CONN.chargingError = CONN_ERR_LOCK;
	} else if(PSU0.cont_fault){
		CONN.chargingError = CONN_ERR_CONTACTOR;
	} else if(PSU0.psu_fault){
		CONN.chargingError = CONN_ERR_PSU_FAULT;
	// } else if(!CTRL.ac_ok) {
	// 	CONN.chargingError = CONN_ERR_AC_FAULT;
	// } else 
    }else if (CONN.EvConnected == 0){
		CONN.chargingError = CONN_NO_ERROR;
	}

	if(ED_TraceWarning(CONN.chargingError, 0)) printf("CONN%d Error: %d\n", 0, CONN.chargingError);

}

void CONN_PrintChargingTotal(){
	printf("CONN%d Charging Finished:\n", 0);
//	printf("Charging Time: %d\n", CONN.chargingTime);
	printf("Charging Energy: %d\n", CONN.Energy);
//	printf("Charging Power: %d\n", CONN.chargingPower);
}
