latest version
This commit is contained in:
BIN
Core/.DS_Store
vendored
BIN
Core/.DS_Store
vendored
Binary file not shown.
@@ -7,6 +7,7 @@
|
||||
|
||||
#ifndef INC_CHARGER_GBT_H_
|
||||
#define INC_CHARGER_GBT_H_
|
||||
|
||||
#include "main.h"
|
||||
#include "connector.h"
|
||||
|
||||
@@ -23,6 +24,13 @@
|
||||
#define GBT_CST_CURRENT_MISMATCH 0x0000F0F1 // Неправильный ток
|
||||
#define GBT_CST_ABNORMALVOLTAGEERROR 0x0000F0F4 // Ненормальное напряжение
|
||||
|
||||
typedef enum {
|
||||
GBT_STOP_EVSE = 0,
|
||||
GBT_STOP_EV = 1,
|
||||
GBT_STOP_OCPP = 2,
|
||||
|
||||
}GBT_StopSource_t;
|
||||
|
||||
|
||||
typedef enum{
|
||||
GBT_CC_UNKNOWN,
|
||||
@@ -33,6 +41,16 @@ typedef enum{
|
||||
|
||||
}gbtCcState_t;
|
||||
|
||||
typedef enum __attribute__((packed)){
|
||||
CONN_NO_ERROR = 0,
|
||||
CONN_ERR_INSULATION = 1,
|
||||
CONN_ERR_EMERGENCY = 2,
|
||||
CONN_ERR_DOOR_OPEN = 3,
|
||||
CONN_ERR_LOCK = 4,
|
||||
CONN_ERR_CONN_TEMP = 5,
|
||||
|
||||
}CONN_Error_t;
|
||||
|
||||
typedef enum{
|
||||
GBT_DISABLED = 0x10,
|
||||
// GBT_S0_UNCONNECTED = 0x10, //СС1 12V/6V СС2 12V
|
||||
@@ -54,12 +72,6 @@ typedef enum{
|
||||
|
||||
}gbtState_t;
|
||||
|
||||
typedef enum __attribute__((packed)){
|
||||
GBT_ERR_OKAY = 0,
|
||||
GBT_ERR_INSULATION = 1,
|
||||
|
||||
}GBT_Error_t;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct {
|
||||
@@ -165,6 +177,7 @@ typedef struct {
|
||||
uint8_t chargingElapsedTimeSec; //
|
||||
|
||||
CONN_State_t connectorState;
|
||||
CONN_Error_t outputError; // 0 if okay
|
||||
|
||||
|
||||
}GBT_EDCAN_Output_t;
|
||||
@@ -175,7 +188,7 @@ typedef struct {
|
||||
uint16_t measuredCurrent; // 0.1A/bit
|
||||
|
||||
CONN_Control_t chargeControl;
|
||||
GBT_Error_t chargingError; // 0 if okay
|
||||
CONN_Error_t chargingError; // 0 if okay
|
||||
|
||||
}GBT_EDCAN_Input_t;
|
||||
|
||||
@@ -223,10 +236,15 @@ extern uint8_t GBT_BRO;
|
||||
|
||||
extern uint8_t GBT_Charger_Enable;
|
||||
|
||||
extern GBT_StopSource_t GBT_StopSource;
|
||||
|
||||
void GBT_Init();
|
||||
void GBT_Start();
|
||||
void GBT_Reset();
|
||||
void GBT_Stop(uint32_t causecode);
|
||||
//void GBT_Stop(uint32_t causecode);
|
||||
void GBT_StopEV(uint32_t causecode);
|
||||
void GBT_StopEVSE(uint32_t causecode);
|
||||
void GBT_StopOCPP(uint32_t causecode);
|
||||
void GBT_ForceStop();
|
||||
void GBT_ChargerTask();
|
||||
void GBT_Error(uint32_t errorcode);
|
||||
|
||||
@@ -13,16 +13,24 @@
|
||||
|
||||
|
||||
void GBT_Lock(uint8_t state);
|
||||
void GBT_ManageLock();
|
||||
void GBT_ManageLockSolenoid();
|
||||
void GBT_ManageLockMotor();
|
||||
uint8_t GBT_LockGetState();
|
||||
void GBT_ForceLock(uint8_t state);
|
||||
void GBT_ResetErrorTimeout();
|
||||
|
||||
typedef struct {
|
||||
// uint8_t state;
|
||||
uint8_t demand;
|
||||
uint8_t error;
|
||||
uint8_t action_requested; // 0 = unlock, 1 = lock, 255 = no action
|
||||
uint8_t motor_state; // 0 = idle, 1 = motor_on, 2 = waiting_off
|
||||
uint32_t last_action_time; // время последнего изменения состояния мотора
|
||||
uint8_t retry_count; // счетчик попыток
|
||||
uint32_t error_tick; // время установки ошибки (для таймаута сброса)
|
||||
} GBT_LockState_t;
|
||||
|
||||
extern GBT_LockState_t GBT_LockState;
|
||||
|
||||
#endif /* INC_LOCK_H_ */
|
||||
|
||||
BIN
Core/Src/.DS_Store
vendored
BIN
Core/Src/.DS_Store
vendored
Binary file not shown.
@@ -56,6 +56,8 @@ uint32_t GBT_TimeChargingStarted;
|
||||
uint32_t GBT_StopCauseCode;
|
||||
uint32_t GBT_ErrorCode;
|
||||
|
||||
GBT_StopSource_t GBT_StopSource;
|
||||
|
||||
extern GBT_EDCAN_Output_t GBT_EDCAN_Output;
|
||||
extern GBT_EDCAN_Input_t GBT_EDCAN_Input;
|
||||
|
||||
@@ -64,11 +66,23 @@ void GBT_Init(){
|
||||
GBT_State = GBT_DISABLED;
|
||||
GBT_EDCAN_Input.chargeControl = CHARGING_NOT_ALLOWED;
|
||||
GBT_Reset();
|
||||
|
||||
|
||||
GBT_MaxLoad.maxOutputVoltage = 1000*10;
|
||||
GBT_MaxLoad.minOutputVoltage = 1500; //150V
|
||||
//GBT_MaxLoad[conn].maxOutputCurrent = 4000 - (GBT_MAX_CURRENT*10); //250A
|
||||
GBT_MaxLoad.maxOutputCurrent = 4000 - (100*10*2); //200A
|
||||
GBT_MaxLoad.minOutputCurrent = 3990; //400 - 1A
|
||||
|
||||
//TODO Linux registers
|
||||
GBT_ChargerInfo.chargerLocation[0] = 'R';
|
||||
GBT_ChargerInfo.chargerLocation[1] = 'U';
|
||||
GBT_ChargerInfo.chargerLocation[2] = 'S';
|
||||
GBT_ChargerInfo.chargerNumber = 00001;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void GBT_ChargerTask(){
|
||||
|
||||
//GBT_LockTask();
|
||||
@@ -226,8 +240,8 @@ void GBT_ChargerTask(){
|
||||
GBT_EDCAN_Output.enablePSU = 1;
|
||||
|
||||
//TODO: Isolation test trigger
|
||||
if(GBT_EDCAN_Input.chargingError == GBT_ERR_INSULATION){
|
||||
GBT_Stop(GBT_CST_OTHERFALUT);
|
||||
if(GBT_EDCAN_Input.chargingError != CONN_NO_ERROR){
|
||||
GBT_StopEVSE(GBT_CST_OTHERFALUT);
|
||||
}
|
||||
|
||||
if(GBT_StateTick()>5000){
|
||||
@@ -341,16 +355,20 @@ void GBT_ChargerTask(){
|
||||
case GBT_S10_CHARGING:
|
||||
//CHARGING
|
||||
//TODO BCL BCS BSM missing ERRORS
|
||||
if(GBT_EDCAN_Input.chargeControl == CHARGING_NOT_ALLOWED) GBT_Stop(GBT_CST_SUSPENDS_ARTIFICIALLY);
|
||||
if(GBT_EDCAN_Input.chargeControl == FORCE_UNLOCK) GBT_Stop(GBT_CST_SUSPENDS_ARTIFICIALLY);//GBT_ForceStop();
|
||||
if(GBT_LockState.error) GBT_Stop(GBT_CST_OTHERFALUT);
|
||||
if(GBT_EDCAN_Input.chargeControl == CHARGING_NOT_ALLOWED) GBT_StopOCPP(GBT_CST_SUSPENDS_ARTIFICIALLY);
|
||||
if(GBT_EDCAN_Input.chargeControl == FORCE_UNLOCK) GBT_StopOCPP(GBT_CST_SUSPENDS_ARTIFICIALLY); // --> Finished
|
||||
if(GBT_LockState.error) {
|
||||
GBT_StopEVSE(GBT_CST_OTHERFALUT); // --> Suspend EVSE
|
||||
GBT_EDCAN_Output.outputError = CONN_ERR_LOCK;
|
||||
}
|
||||
if((GBT_ReadTemp(0) > 90) || (GBT_ReadTemp(1) > 90)) {
|
||||
GBT_Stop(GBT_CST_CONNECTOR_OVER_TEMP);
|
||||
GBT_StopEVSE(GBT_CST_CONNECTOR_OVER_TEMP);
|
||||
GBT_EDCAN_Output.outputError = CONN_ERR_CONN_TEMP;
|
||||
EDCAN_printf(LOG_WARN, "Connector overheat %d %d\n", GBT_ReadTemp(0), GBT_ReadTemp(1));
|
||||
}
|
||||
if(GBT_EDCAN_Input.chargingError == GBT_ERR_INSULATION) {
|
||||
GBT_Stop(GBT_CST_OTHERFALUT);
|
||||
EDCAN_printf(LOG_WARN, "Isolation error\n");
|
||||
if(GBT_EDCAN_Input.chargingError != CONN_NO_ERROR){ // --> Suspend EVSE
|
||||
GBT_StopEVSE(GBT_CST_OTHERFALUT);
|
||||
// EDCAN_printf(LOG_WARN, "Isolation error\n");
|
||||
}
|
||||
|
||||
//GBT_ChargerCurrentStatus.chargingPermissible = 0b1111111111111100;//NOT PERMITTED
|
||||
@@ -365,7 +383,14 @@ void GBT_ChargerTask(){
|
||||
|
||||
if(j_rx.state == 0) GBT_SendCCS();
|
||||
|
||||
GBT_Delay(50);
|
||||
if(j_rx.state == 0) {
|
||||
GBT_SendCCS();
|
||||
GBT_Delay(49);
|
||||
}else{
|
||||
GBT_Delay(10); // Resend packet if not sent
|
||||
// log_printf(LOG_WARN, "Resend packet\n");
|
||||
}
|
||||
|
||||
//TODO: снижение тока если перегрев контактов
|
||||
|
||||
break;
|
||||
@@ -408,7 +433,10 @@ void GBT_ChargerTask(){
|
||||
break;
|
||||
|
||||
case GBT_COMPLETE:
|
||||
if(connectorState != CONN_Finishing) GBT_SwitchState(GBT_DISABLED);
|
||||
if(connectorState != CONN_Finishing) {
|
||||
GBT_SwitchState(GBT_DISABLED);
|
||||
GBT_Reset();//CHECK
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -422,23 +450,23 @@ void GBT_SwitchState(gbtState_t state){
|
||||
GBT_State = state;
|
||||
ED_status = state;
|
||||
GBT_state_tick = HAL_GetTick();
|
||||
if(GBT_State == GBT_DISABLED) printf ("GBT_DISABLED\n");
|
||||
// if(GBT_State == GBT_DISABLED) printf ("GBT_DISABLED\n");
|
||||
// if(GBT_State == GBT_S0_UNCONNECTED) printf ("GBT_S0_UNCONNECTED\n");
|
||||
// if(GBT_State == GBT_S1_CONNECTED) printf ("GBT_S1_CONNECTED\n");
|
||||
// if(GBT_State == GBT_S2_LOCKED) printf ("GBT_S2_LOCKED\n");
|
||||
if(GBT_State == GBT_S3_STARTED) printf ("GBT_S3_STARTED\n");
|
||||
if(GBT_State == GBT_S31_WAIT_BHM) printf ("GBT_S31_WAIT_BHM\n");
|
||||
if(GBT_State == GBT_S4_ISOTEST) printf ("GBT_S4_ISOTEST\n");
|
||||
if(GBT_State == GBT_S5_BAT_INFO) printf ("GBT_S5_BAT_INFO\n");
|
||||
if(GBT_State == GBT_S6_BAT_STAT) printf ("GBT_S6_BAT_STAT\n");
|
||||
if(GBT_State == GBT_S7_BMS_WAIT) printf ("GBT_S7_BMS_WAIT\n");
|
||||
if(GBT_State == GBT_S8_INIT_CHARGER)printf ("GBT_S8_INIT_CHARGER\n");
|
||||
if(GBT_State == GBT_S9_WAIT_BCL) printf ("GBT_S9_WAIT_BCL\n");
|
||||
if(GBT_State == GBT_S10_CHARGING) printf ("GBT_S10_CHARGING\n");
|
||||
if(GBT_State == GBT_STOP) printf ("GBT_STOP\n");
|
||||
if(GBT_State == GBT_STOP_CSD) printf ("GBT_STOP_CSD\n");
|
||||
if(GBT_State == GBT_ERROR) printf ("GBT_ERROR\n");
|
||||
if(GBT_State == GBT_COMPLETE) printf ("GBT_COMPLETE\n");
|
||||
// if(GBT_State == GBT_S3_STARTED) printf ("GBT_S3_STARTED\n");
|
||||
// if(GBT_State == GBT_S31_WAIT_BHM) printf ("GBT_S31_WAIT_BHM\n");
|
||||
// if(GBT_State == GBT_S4_ISOTEST) printf ("GBT_S4_ISOTEST\n");
|
||||
// if(GBT_State == GBT_S5_BAT_INFO) printf ("GBT_S5_BAT_INFO\n");
|
||||
// if(GBT_State == GBT_S6_BAT_STAT) printf ("GBT_S6_BAT_STAT\n");
|
||||
// if(GBT_State == GBT_S7_BMS_WAIT) printf ("GBT_S7_BMS_WAIT\n");
|
||||
// if(GBT_State == GBT_S8_INIT_CHARGER)printf ("GBT_S8_INIT_CHARGER\n");
|
||||
// if(GBT_State == GBT_S9_WAIT_BCL) printf ("GBT_S9_WAIT_BCL\n");
|
||||
// if(GBT_State == GBT_S10_CHARGING) printf ("GBT_S10_CHARGING\n");
|
||||
// if(GBT_State == GBT_STOP) printf ("GBT_STOP\n");
|
||||
// if(GBT_State == GBT_STOP_CSD) printf ("GBT_STOP_CSD\n");
|
||||
// if(GBT_State == GBT_ERROR) printf ("GBT_ERROR\n");
|
||||
// if(GBT_State == GBT_COMPLETE) printf ("GBT_COMPLETE\n");
|
||||
|
||||
if(GBT_State == GBT_DISABLED) EDCAN_printf(LOG_INFO, "GBT_DISABLED\n");
|
||||
if(GBT_State == GBT_S3_STARTED) EDCAN_printf(LOG_INFO, "GBT_S3_STARTED\n");
|
||||
@@ -467,24 +495,44 @@ void GBT_Delay(uint32_t delay){
|
||||
GBT_delay = delay;
|
||||
}
|
||||
|
||||
void GBT_Stop(uint32_t causecode){
|
||||
void GBT_StopEV(uint32_t causecode){ // --> Suspend EV
|
||||
if (GBT_EDCAN_Input.chargingError || GBT_EDCAN_Output.outputError){
|
||||
GBT_StopSource = GBT_STOP_EVSE;
|
||||
}else{
|
||||
GBT_StopSource = GBT_STOP_EV;
|
||||
}
|
||||
GBT_StopCauseCode = causecode;
|
||||
if(GBT_State != GBT_STOP) GBT_SwitchState(GBT_STOP);
|
||||
}
|
||||
|
||||
void GBT_Error(uint32_t errorcode){
|
||||
EDCAN_printf(LOG_WARN, "GBT Error code: 0x%X\n", errorcode);
|
||||
GBT_ErrorCode = errorcode;
|
||||
GBT_SwitchState(GBT_ERROR);
|
||||
void GBT_StopEVSE(uint32_t causecode){ // --> Suspend EVSE
|
||||
GBT_StopSource = GBT_STOP_EVSE;
|
||||
GBT_StopCauseCode = causecode;
|
||||
if(GBT_State != GBT_STOP) GBT_SwitchState(GBT_STOP);
|
||||
}
|
||||
|
||||
void GBT_ForceStop(){
|
||||
void GBT_StopOCPP(uint32_t causecode){ // --> Finished
|
||||
GBT_StopSource = GBT_STOP_OCPP;
|
||||
GBT_StopCauseCode = causecode;
|
||||
if(GBT_State != GBT_STOP) GBT_SwitchState(GBT_STOP);
|
||||
}
|
||||
|
||||
void GBT_ForceStop(){ // --> Suspend EV
|
||||
GBT_StopSource = GBT_STOP_EV;
|
||||
GBT_EDCAN_Output.enablePSU = 0;
|
||||
GBT_SwitchState(GBT_COMPLETE);
|
||||
GBT_Lock(0);
|
||||
RELAY_Write(RELAY_AUX, 0);
|
||||
}
|
||||
|
||||
void GBT_Error(uint32_t errorcode){ // --> Suspend EV
|
||||
GBT_StopSource = GBT_STOP_EV;
|
||||
EDCAN_printf(LOG_WARN, "GBT Error code: 0x%X\n", errorcode);
|
||||
GBT_ErrorCode = errorcode;
|
||||
GBT_SwitchState(GBT_ERROR);
|
||||
}
|
||||
|
||||
|
||||
void GBT_Reset(){
|
||||
GBT_BAT_INFO_recv = 0;
|
||||
GBT_BAT_STAT_recv = 0;
|
||||
@@ -492,6 +540,11 @@ void GBT_Reset(){
|
||||
GBT_BHM_recv = 0;
|
||||
GBT_BSD_recv = 0;
|
||||
EV_ready = 0;
|
||||
GBT_EDCAN_Output.chargingPercentage = 0;
|
||||
GBT_EDCAN_Output.enablePSU = 0;
|
||||
GBT_EDCAN_Output.requestedCurrent = 0;
|
||||
GBT_EDCAN_Output.requestedVoltage = 500;
|
||||
GBT_EDCAN_Output.outputError = 0;
|
||||
memset(&GBT_EVInfo, 0, sizeof (GBT_EVInfo));
|
||||
memset(&GBT_BATStat, 0, sizeof (GBT_BATStat));
|
||||
memset(&GBT_ReqPower, 0, sizeof (GBT_ReqPower));
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "connector.h"
|
||||
#include "lock.h"
|
||||
#include "board.h"
|
||||
#include "edcan.h"
|
||||
|
||||
|
||||
CONN_State_t connectorState;
|
||||
@@ -25,25 +26,29 @@ void CONN_Task(){
|
||||
case CONN_Initializing: // unlocked
|
||||
GBT_Lock(0);
|
||||
CONN_SetState(CONN_Available);
|
||||
GBT_LockState.error = 0;
|
||||
break;
|
||||
|
||||
case CONN_Faulted: //unlocked
|
||||
GBT_Lock(0);
|
||||
if(GBT_EDCAN_Input.chargingError == 0) CONN_SetState(CONN_Available);
|
||||
if(GBT_EDCAN_Input.chargeControl == FORCE_UNLOCK) GBT_ForceLock(0);
|
||||
|
||||
break;
|
||||
case CONN_Available: //unlocked, waiting to connect
|
||||
GBT_Lock(0);
|
||||
GBT_LockState.error = 0;
|
||||
if(GBT_EDCAN_Input.chargingError != 0) CONN_SetState(CONN_Faulted);
|
||||
if(GBT_EDCAN_Input.chargeControl == FORCE_UNLOCK) GBT_ForceLock(0);
|
||||
|
||||
if((CONN_CC_GetState()==GBT_CC_4V) && (GBT_EDCAN_Input.chargeControl != FORCE_UNLOCK)){ // Исправить
|
||||
CONN_SetState(CONN_Preparing);
|
||||
GBT_Lock(1);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
// Выйти из двух состояний в Finished если force unlock
|
||||
case CONN_Preparing: //locked, waiting to charge
|
||||
GBT_Lock(1);
|
||||
case CONN_Preparing: //unlocked, waiting to charge
|
||||
GBT_Lock(0);
|
||||
if(GBT_EDCAN_Input.chargeControl == FORCE_UNLOCK) GBT_ForceLock(0);
|
||||
if(CONN_CC_GetState()==GBT_CC_4V){
|
||||
if(GBT_EDCAN_Input.chargeControl == CHARGING_ALLOWED){
|
||||
// RELAY_Write(RELAY_AUX, 1);
|
||||
@@ -62,22 +67,44 @@ void CONN_Task(){
|
||||
GBT_Lock(1);
|
||||
|
||||
if(GBT_State == GBT_COMPLETE){
|
||||
if(GBT_StopSource == GBT_STOP_EVSE){
|
||||
CONN_SetState(CONN_Suspended_EVSE);
|
||||
}else if(GBT_StopSource == GBT_STOP_EV){
|
||||
CONN_SetState(CONN_Suspended_EV);
|
||||
}else if(GBT_StopSource == GBT_STOP_OCPP){
|
||||
CONN_SetState(CONN_Finishing);
|
||||
}else{
|
||||
CONN_SetState(CONN_Suspended_EVSE);
|
||||
}
|
||||
|
||||
}//FIXME
|
||||
//
|
||||
break;
|
||||
|
||||
case CONN_Suspended_EV://charging completed by EV, waiting to transaction stop
|
||||
GBT_Lock(0);
|
||||
if(GBT_EDCAN_Input.chargeControl == CHARGING_NOT_ALLOWED) CONN_SetState(CONN_Finishing);
|
||||
if(GBT_EDCAN_Input.chargeControl == FORCE_UNLOCK) CONN_SetState(CONN_Finishing); // --> Finished
|
||||
break;
|
||||
|
||||
case CONN_Suspended_EVSE://charging completed by EVSE, waiting to transaction stop
|
||||
GBT_Lock(0);
|
||||
if(GBT_EDCAN_Input.chargeControl == CHARGING_NOT_ALLOWED) CONN_SetState(CONN_Finishing);
|
||||
if(GBT_EDCAN_Input.chargeControl == FORCE_UNLOCK) CONN_SetState(CONN_Finishing); // --> Finished
|
||||
|
||||
break;
|
||||
|
||||
case CONN_Finishing://charging completed, waiting to disconnect, unlocked
|
||||
GBT_Lock(0);
|
||||
// RELAY_Write(RELAY_AUX, 0);
|
||||
//TODO: Reconnection
|
||||
// if(GBT_EDCAN_Input.chargeControl == CHARGING_NOT_ALLOWED){
|
||||
// CONN_SetState(CONN_Initializing);
|
||||
// }
|
||||
|
||||
//TODO Force unlock time limit
|
||||
if(GBT_EDCAN_Input.chargeControl == FORCE_UNLOCK) GBT_ForceLock(0);
|
||||
|
||||
if(CONN_CC_GetState()==GBT_CC_6V){
|
||||
CONN_SetState(CONN_Initializing);
|
||||
GBT_Lock(0);
|
||||
CONN_SetState(CONN_Available);
|
||||
}
|
||||
//Проблема, если нажать кнопку и не вынуть пистолет, то он снова блочится
|
||||
|
||||
break;
|
||||
default:
|
||||
CONN_SetState(CONN_Initializing);
|
||||
@@ -93,12 +120,15 @@ void CONN_Task(){
|
||||
|
||||
void CONN_SetState(CONN_State_t state){
|
||||
connectorState = state;
|
||||
if(connectorState == CONN_Initializing) printf ("CONN_Initializing\n");
|
||||
if(connectorState == CONN_Faulted) printf ("CONN_Error\n");
|
||||
if(connectorState == CONN_Available) printf ("CONN_Available\n");
|
||||
if(connectorState == CONN_Preparing) printf ("CONN_Occupied_waiting\n");
|
||||
if(connectorState == CONN_Charging) printf ("CONN_Occupied_charging\n");
|
||||
if(connectorState == CONN_Finishing) printf ("CONN_Occupied_complete\n");
|
||||
if(connectorState == CONN_Initializing) EDCAN_printf(LOG_INFO,"CONN_Initializing\n");
|
||||
if(connectorState == CONN_Faulted) EDCAN_printf(LOG_INFO,"CONN_Faulted\n");
|
||||
if(connectorState == CONN_Available) EDCAN_printf(LOG_INFO,"CONN_Available\n");
|
||||
if(connectorState == CONN_Preparing) EDCAN_printf(LOG_INFO,"CONN_Preparing\n");
|
||||
if(connectorState == CONN_Charging) EDCAN_printf(LOG_INFO,"CONN_Charging\n");
|
||||
if(connectorState == CONN_Finishing) EDCAN_printf(LOG_INFO,"CONN_Finishing\n");
|
||||
if(connectorState == CONN_Suspended_EV) EDCAN_printf(LOG_INFO,"CONN_Suspended_EV\n");
|
||||
if(connectorState == CONN_Suspended_EVSE) EDCAN_printf(LOG_INFO,"CONN_Suspended_EVSE\n");
|
||||
|
||||
GBT_EDCAN_Output.connectorState = state;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ void parse_command(uint8_t* buffer, size_t length) {
|
||||
|
||||
} else if (strncmp((const char*)buffer, "stop", length) == 0) {
|
||||
printf("Stopped\n");
|
||||
GBT_Stop(GBT_CST_SUSPENDS_ARTIFICIALLY);
|
||||
GBT_StopEVSE(GBT_CST_SUSPENDS_ARTIFICIALLY);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "stop1", length) == 0) {
|
||||
printf("Stopped\n");
|
||||
|
||||
@@ -146,7 +146,7 @@ void EDCAN_WriteUserRegister(uint16_t addr, uint8_t value){
|
||||
|
||||
//0x220
|
||||
case EDCAN_REG_MAX_LOAD ... (EDCAN_REG_MAX_LOAD+sizeof(GBT_CML_t)):
|
||||
((uint8_t*)&GBT_MaxLoad)[addr - EDCAN_REG_MAX_LOAD] = value;
|
||||
// ((uint8_t*)&GBT_MaxLoad)[addr - EDCAN_REG_MAX_LOAD] = value;
|
||||
break;
|
||||
|
||||
//0x200
|
||||
@@ -165,7 +165,7 @@ void EDCAN_WriteUserRegister(uint16_t addr, uint8_t value){
|
||||
|
||||
|
||||
default:
|
||||
printf ("Unknown register\n");
|
||||
//printf ("Unknown register\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
|
||||
case 0x1E00: //PGN BEM (ERROR)
|
||||
//Error force stop
|
||||
// --> Suspend EV
|
||||
EDCAN_printf(LOG_WARN, "BEM Received, force stopping...\n");
|
||||
EDCAN_printf(LOG_WARN, "BEM: %02X %02X %02X %02X", RxData[0], RxData[1], RxData[2], RxData[3]);
|
||||
EDCAN_printf(LOG_WARN, " %02X %02X %02X %02X\n", RxData[4], RxData[5], RxData[6], RxData[7]);
|
||||
@@ -87,10 +88,12 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
|
||||
case 0x1900: //PGN BST (STOP)
|
||||
//Normal stop
|
||||
|
||||
// --> Suspend EV
|
||||
EDCAN_printf(LOG_WARN, "BST Received, stopping...\n");
|
||||
EDCAN_printf(LOG_WARN, "BST: %02X %02X %02X %02X", RxData[0], RxData[1], RxData[2], RxData[3]);
|
||||
EDCAN_printf(LOG_WARN, " %02X %02X %02X %02X\n", RxData[4], RxData[5], RxData[6], RxData[7]);
|
||||
GBT_Stop(GBT_CST_BMS_ACTIVELY_SUSPENDS);
|
||||
GBT_StopEV(GBT_CST_BMS_ACTIVELY_SUSPENDS);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
160
Core/Src/lock.c
160
Core/Src/lock.c
@@ -5,36 +5,29 @@
|
||||
* Author: colorbass
|
||||
*/
|
||||
#include "lock.h"
|
||||
#include "debug.h"
|
||||
#include "edcan.h"
|
||||
|
||||
uint8_t LOCK_POLARITY = 1;
|
||||
|
||||
uint8_t LOCK_POLARITY = 0; // 1 for v1
|
||||
uint8_t LOCK_MOTOR_POLARITY = 1;
|
||||
uint8_t LOCK_DELAY = 50;
|
||||
uint16_t LOCK_DELAY = 100;
|
||||
|
||||
GBT_LockState_t GBT_LockState;
|
||||
GBT_LockState_t GBT_LockState = {
|
||||
.demand = 0,
|
||||
.error = 0,
|
||||
.action_requested = 255, // нет запрошенного действия
|
||||
.motor_state = 0, // idle
|
||||
.last_action_time = 0,
|
||||
.retry_count = 0,
|
||||
.error_tick = 0
|
||||
};
|
||||
|
||||
|
||||
void GBT_ForceLock(uint8_t state){
|
||||
if(LOCK_MOTOR_POLARITY){
|
||||
if(state){//LOCK
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 1);
|
||||
HAL_Delay(LOCK_DELAY);
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 0);
|
||||
}else{ //UNLOCK
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 1);
|
||||
HAL_Delay(LOCK_DELAY);
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 0);
|
||||
}
|
||||
}else{
|
||||
if(state){//LOCK
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 1);
|
||||
HAL_Delay(LOCK_DELAY);
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 0);
|
||||
}else{ //UNLOCK
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 1);
|
||||
HAL_Delay(LOCK_DELAY);
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 0);
|
||||
}
|
||||
}
|
||||
// Устанавливаем флаг для выполнения действия
|
||||
GBT_LockState.action_requested = state ? 1 : 0;
|
||||
GBT_LockState.retry_count = 0;
|
||||
}
|
||||
|
||||
uint8_t GBT_LockGetState(){
|
||||
@@ -52,37 +45,122 @@ void GBT_Lock(uint8_t state){
|
||||
GBT_LockState.demand = state;
|
||||
}
|
||||
|
||||
void GBT_ManageLock(){
|
||||
uint8_t MAX_RETRIES = 5;
|
||||
void GBT_ManageLockSolenoid(){
|
||||
static uint32_t tick;
|
||||
|
||||
if(HAL_GetTick() - tick < 50) return;
|
||||
tick = HAL_GetTick();
|
||||
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, GBT_LockState.demand ? 1 : 0);
|
||||
}
|
||||
|
||||
void GBT_ManageLockMotor(){
|
||||
static const uint8_t MAX_RETRIES = 5;
|
||||
uint32_t current_tick = HAL_GetTick();
|
||||
|
||||
// Проверяем таймаут сброса ошибки (до проверки error, чтобы можно было сбросить)
|
||||
GBT_ResetErrorTimeout();
|
||||
|
||||
if (GBT_LockState.error) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Проверяем, нужно ли выполнить действие
|
||||
bool lock_is_open = GBT_LockGetState() == 0;
|
||||
bool lock_should_be_open = GBT_LockState.demand == 0;
|
||||
uint8_t retry_count = 0;
|
||||
|
||||
if (lock_is_open != lock_should_be_open) {
|
||||
while (retry_count < MAX_RETRIES) {
|
||||
if (lock_should_be_open) {
|
||||
GBT_ForceLock(0);
|
||||
} else {
|
||||
GBT_ForceLock(1);
|
||||
// Если есть запрошенное действие или состояние не соответствует требуемому
|
||||
if (GBT_LockState.action_requested != 255 || (lock_is_open != lock_should_be_open)) {
|
||||
// Если действие еще не запрошено, запрашиваем его
|
||||
if (GBT_LockState.action_requested == 255) {
|
||||
GBT_LockState.action_requested = lock_should_be_open ? 0 : 1;
|
||||
GBT_LockState.retry_count = 0;
|
||||
}
|
||||
|
||||
lock_is_open = GBT_LockGetState() == 0;
|
||||
// Управление мотором через машину состояний
|
||||
switch (GBT_LockState.motor_state) {
|
||||
case 0: // idle - мотор выключен
|
||||
// Определяем, какой пин нужно включить
|
||||
if (LOCK_MOTOR_POLARITY) {
|
||||
if (GBT_LockState.action_requested == 1) { // LOCK
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 1);
|
||||
} else { // UNLOCK
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 1);
|
||||
}
|
||||
} else {
|
||||
if (GBT_LockState.action_requested == 1) { // LOCK
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 1);
|
||||
} else { // UNLOCK
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 1);
|
||||
}
|
||||
}
|
||||
GBT_LockState.motor_state = 1; // motor_on
|
||||
GBT_LockState.last_action_time = current_tick;
|
||||
break;
|
||||
|
||||
if (lock_is_open == lock_should_be_open) {
|
||||
case 1: // motor_on - мотор включен, ждем LOCK_DELAY
|
||||
if (current_tick - GBT_LockState.last_action_time >= LOCK_DELAY) {
|
||||
// Выключаем оба пина
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 0);
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 0);
|
||||
GBT_LockState.motor_state = 2; // waiting_off
|
||||
GBT_LockState.last_action_time = current_tick;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // waiting_off - ждем немного перед проверкой состояния
|
||||
// Небольшая задержка перед проверкой состояния (например, 50мс)
|
||||
if (current_tick - GBT_LockState.last_action_time >= 50) {
|
||||
// Проверяем, достигнуто ли требуемое состояние
|
||||
lock_is_open = GBT_LockGetState() == 0;
|
||||
bool action_success = (lock_is_open == (GBT_LockState.action_requested == 0));
|
||||
|
||||
if (action_success) {
|
||||
// Действие выполнено успешно
|
||||
GBT_LockState.action_requested = 255; // сбрасываем флаг
|
||||
GBT_LockState.motor_state = 0; // idle
|
||||
GBT_LockState.retry_count = 0;
|
||||
} else {
|
||||
// Действие не выполнено, повторяем попытку
|
||||
GBT_LockState.retry_count++;
|
||||
if (GBT_LockState.retry_count >= MAX_RETRIES) {
|
||||
// Превышено количество попыток
|
||||
GBT_LockState.error = 1;
|
||||
GBT_LockState.error_tick = current_tick; // сохраняем время установки ошибки
|
||||
GBT_LockState.action_requested = 0; // пытаемся разблокировать
|
||||
GBT_LockState.motor_state = 0;
|
||||
GBT_LockState.retry_count = 0;
|
||||
EDCAN_printf(LOG_ERR, "Lock error\n");
|
||||
} else {
|
||||
// Повторяем попытку
|
||||
GBT_LockState.motor_state = 0; // возвращаемся к началу
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
retry_count++;
|
||||
} else {
|
||||
// Состояние соответствует требуемому, сбрасываем флаги
|
||||
if (GBT_LockState.motor_state != 0) {
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 0);
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 0);
|
||||
GBT_LockState.motor_state = 0;
|
||||
}
|
||||
GBT_LockState.action_requested = 255;
|
||||
GBT_LockState.retry_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (retry_count >= MAX_RETRIES) {
|
||||
GBT_LockState.error = 1;
|
||||
GBT_ForceLock(0);
|
||||
printf ("Lock error\n");
|
||||
void GBT_ResetErrorTimeout(){
|
||||
static const uint32_t ERROR_TIMEOUT_MS = 300000; // 5 минут
|
||||
|
||||
if (GBT_LockState.error && GBT_LockState.error_tick != 0) {
|
||||
|
||||
if ((HAL_GetTick()-GBT_LockState.error_tick) >= ERROR_TIMEOUT_MS) {
|
||||
// Прошло 5 минут, сбрасываем ошибку
|
||||
GBT_LockState.error = 0;
|
||||
GBT_LockState.error_tick = 0;
|
||||
EDCAN_printf(LOG_WARN, "Lock error timeout reset\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ void SystemClock_Config(void);
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
uint32_t lasttick;
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
@@ -115,7 +115,7 @@ int main(void)
|
||||
printf("Startup (type \'help\' for command list)\n");
|
||||
debug_init();
|
||||
EDCAN_Init(SW_GetAddr()); //0x20..0x23
|
||||
EDCAN_printf(LOG_INFO, "Startup\n");
|
||||
EDCAN_printf(LOG_INFO, "Startup FWVER = %d\n", FWVER);
|
||||
//EDCAN_Init(0x20); //Адрес EDCAN
|
||||
GBT_CAN_ReInit();
|
||||
CAN_ReInit();
|
||||
@@ -135,10 +135,15 @@ int main(void)
|
||||
//can_task();
|
||||
debug_task();
|
||||
CONN_CC_ReadStateFiltered();
|
||||
GBT_ManageLock();
|
||||
// GBT_ManageLock();
|
||||
CONN_Task();
|
||||
GBT_ChargerTask();
|
||||
|
||||
// if((HAL_GetTick() - lasttick)>100){
|
||||
// lasttick = HAL_GetTick();
|
||||
// EDCAN_printf(LOG_INFO, "Temp %d %d\n", GBT_ReadTemp(0), GBT_ReadTemp(0));
|
||||
// }
|
||||
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
0
Debug/Core/Src/board.cyclo
Normal file → Executable file
0
Debug/Core/Src/board.cyclo
Normal file → Executable file
@@ -1,10 +1,12 @@
|
||||
../Core/Src/charger_gbt.c:63:6:GBT_Init 1
|
||||
../Core/Src/charger_gbt.c:72:6:GBT_ChargerTask 76
|
||||
../Core/Src/charger_gbt.c:421:6:GBT_SwitchState 29
|
||||
../Core/Src/charger_gbt.c:461:10:GBT_StateTick 1
|
||||
../Core/Src/charger_gbt.c:465:6:GBT_Delay 1
|
||||
../Core/Src/charger_gbt.c:470:6:GBT_Stop 2
|
||||
../Core/Src/charger_gbt.c:475:6:GBT_Error 1
|
||||
../Core/Src/charger_gbt.c:481:6:GBT_ForceStop 1
|
||||
../Core/Src/charger_gbt.c:488:6:GBT_Reset 1
|
||||
../Core/Src/charger_gbt.c:509:6:GBT_Start 1
|
||||
../Core/Src/charger_gbt.c:65:6:GBT_Init 1
|
||||
../Core/Src/charger_gbt.c:86:6:GBT_ChargerTask 77
|
||||
../Core/Src/charger_gbt.c:449:6:GBT_SwitchState 15
|
||||
../Core/Src/charger_gbt.c:489:10:GBT_StateTick 1
|
||||
../Core/Src/charger_gbt.c:493:6:GBT_Delay 1
|
||||
../Core/Src/charger_gbt.c:498:6:GBT_StopEV 4
|
||||
../Core/Src/charger_gbt.c:508:6:GBT_StopEVSE 2
|
||||
../Core/Src/charger_gbt.c:514:6:GBT_StopOCPP 2
|
||||
../Core/Src/charger_gbt.c:520:6:GBT_ForceStop 1
|
||||
../Core/Src/charger_gbt.c:528:6:GBT_Error 1
|
||||
../Core/Src/charger_gbt.c:536:6:GBT_Reset 1
|
||||
../Core/Src/charger_gbt.c:562:6:GBT_Start 1
|
||||
|
||||
14
Debug/Core/Src/connector.cyclo
Normal file → Executable file
14
Debug/Core/Src/connector.cyclo
Normal file → Executable file
@@ -1,7 +1,7 @@
|
||||
../Core/Src/connector.c:18:6:CONN_Init 1
|
||||
../Core/Src/connector.c:22:6:CONN_Task 14
|
||||
../Core/Src/connector.c:94:6:CONN_SetState 7
|
||||
../Core/Src/connector.c:105:6:CONN_CC_ReadStateFiltered 4
|
||||
../Core/Src/connector.c:162:9:CONN_CC_GetState 1
|
||||
../Core/Src/connector.c:165:9:CONN_CC_GetStateRaw 9
|
||||
../Core/Src/connector.c:192:7:CONN_CC_GetAdc 1
|
||||
../Core/Src/connector.c:19:6:CONN_Init 1
|
||||
../Core/Src/connector.c:23:6:CONN_Task 29
|
||||
../Core/Src/connector.c:121:6:CONN_SetState 9
|
||||
../Core/Src/connector.c:135:6:CONN_CC_ReadStateFiltered 4
|
||||
../Core/Src/connector.c:192:9:CONN_CC_GetState 1
|
||||
../Core/Src/connector.c:195:9:CONN_CC_GetStateRaw 9
|
||||
../Core/Src/connector.c:222:7:CONN_CC_GetAdc 1
|
||||
|
||||
0
Debug/Core/Src/debug.cyclo
Normal file → Executable file
0
Debug/Core/Src/debug.cyclo
Normal file → Executable file
0
Debug/Core/Src/gbt_packet.cyclo
Normal file → Executable file
0
Debug/Core/Src/gbt_packet.cyclo
Normal file → Executable file
10
Debug/Core/Src/j1939.cyclo
Normal file → Executable file
10
Debug/Core/Src/j1939.cyclo
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
../Core/Src/j1939.c:20:6:HAL_CAN_RxFifo0MsgPendingCallback 20
|
||||
../Core/Src/j1939.c:114:6:GBT_CAN_ReInit 1
|
||||
../Core/Src/j1939.c:122:6:J_SendPacket 1
|
||||
../Core/Src/j1939.c:143:6:J_SendCTS 2
|
||||
../Core/Src/j1939.c:161:6:J_SendACK 1
|
||||
../Core/Src/j1939.c:176:6:GBT_CAN_FilterInit 2
|
||||
../Core/Src/j1939.c:117:6:GBT_CAN_ReInit 1
|
||||
../Core/Src/j1939.c:125:6:J_SendPacket 1
|
||||
../Core/Src/j1939.c:146:6:J_SendCTS 2
|
||||
../Core/Src/j1939.c:164:6:J_SendACK 1
|
||||
../Core/Src/j1939.c:179:6:GBT_CAN_FilterInit 2
|
||||
|
||||
10
Debug/Core/Src/lock.cyclo
Executable file → Normal file
10
Debug/Core/Src/lock.cyclo
Executable file → Normal file
@@ -1,4 +1,6 @@
|
||||
../Core/Src/lock.c:16:6:GBT_ForceLock 4
|
||||
../Core/Src/lock.c:40:9:GBT_LockGetState 2
|
||||
../Core/Src/lock.c:51:6:GBT_Lock 1
|
||||
../Core/Src/lock.c:55:6:GBT_ManageLock 7
|
||||
../Core/Src/lock.c:27:6:GBT_ForceLock 1
|
||||
../Core/Src/lock.c:33:9:GBT_LockGetState 2
|
||||
../Core/Src/lock.c:44:6:GBT_Lock 1
|
||||
../Core/Src/lock.c:48:6:GBT_ManageLockSolenoid 2
|
||||
../Core/Src/lock.c:57:6:GBT_ManageLockMotor 17
|
||||
../Core/Src/lock.c:154:6:GBT_ResetErrorTimeout 4
|
||||
|
||||
@@ -33,5 +33,5 @@
|
||||
/Users/colorbass/STM32CubeIDE/workspace_1.12.0/lib_EDCAN/edcan_log.c:49:6:EDCAN_Log 2
|
||||
/Users/colorbass/STM32CubeIDE/workspace_1.12.0/lib_EDCAN/edcan_log.c:74:6:EDCAN_SendPacketLog 1
|
||||
../Core/Src/main.c:79:5:main 1
|
||||
../Core/Src/main.c:150:6:SystemClock_Config 4
|
||||
../Core/Src/main.c:210:6:Error_Handler 1
|
||||
../Core/Src/main.c:155:6:SystemClock_Config 4
|
||||
../Core/Src/main.c:215:6:Error_Handler 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
# Toolchain: GNU Tools for STM32 (12.3.rel1)
|
||||
# Toolchain: GNU Tools for STM32 (13.3.rel1)
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
# Toolchain: GNU Tools for STM32 (12.3.rel1)
|
||||
# Toolchain: GNU Tools for STM32 (13.3.rel1)
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
# Toolchain: GNU Tools for STM32 (12.3.rel1)
|
||||
# Toolchain: GNU Tools for STM32 (13.3.rel1)
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
|
||||
42127
Debug/GbTModuleSW.list
42127
Debug/GbTModuleSW.list
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
# Toolchain: GNU Tools for STM32 (12.3.rel1)
|
||||
# Toolchain: GNU Tools for STM32 (13.3.rel1)
|
||||
################################################################################
|
||||
|
||||
USER_OBJS :=
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
# Toolchain: GNU Tools for STM32 (12.3.rel1)
|
||||
# Toolchain: GNU Tools for STM32 (13.3.rel1)
|
||||
################################################################################
|
||||
|
||||
ELF_SRCS :=
|
||||
|
||||
Reference in New Issue
Block a user