forked from achamaikin/CCSModuleSW30Web
Add PSU diagnostic logging for setpoints and state transitions (v1.0.26).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ extern "C" {
|
||||
/* USER CODE BEGIN EC */
|
||||
#define FW_VERSION_MAJOR 1
|
||||
#define FW_VERSION_MINOR 0
|
||||
#define FW_VERSION_PATCH 25
|
||||
#define FW_VERSION_PATCH 26
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
@@ -26,13 +26,90 @@ PSU_t PSU0;
|
||||
#define PSU_VOLTAGE_THRESHOLD 20 // Порог напряжения для определения состояния (В)
|
||||
#define PSU_ONLINE_TIMEOUT 500 // Таймаут для определения состояния (мс)
|
||||
#define PSU_STARTUP_DELAY 4000 // Задержка 2 секунды перед включением
|
||||
#define PSU_DIAG_LOG_MS 2000u
|
||||
|
||||
uint32_t can_lastpacket;
|
||||
|
||||
extern CAN_HandleTypeDef hcan2;
|
||||
|
||||
static uint16_t psu_last_can_v;
|
||||
static uint16_t psu_last_can_i_0p1A;
|
||||
|
||||
static void PSU_SendCmd(uint8_t source, uint8_t destination, uint8_t cmd, void *data);
|
||||
|
||||
static const char *PSU_StateName(PSU_State_t state)
|
||||
{
|
||||
switch (state) {
|
||||
case PSU_UNREADY: return "UNREADY";
|
||||
case PSU_INITIALIZING: return "INIT";
|
||||
case PSU_READY: return "READY";
|
||||
case PSU_WAIT_ACK_ON: return "WAIT_ON";
|
||||
case PSU_CONT_WAIT_ACK_ON: return "CONT_ON";
|
||||
case PSU_CONNECTED: return "CONNECTED";
|
||||
case PSU_FAST_DISCHARGE_OFF: return "FD_OFF";
|
||||
case PSU_FAST_DISCHARGE_WAIT: return "FD_WAIT";
|
||||
case PSU_FAST_DISCHARGE_SET: return "FD_SET";
|
||||
case PSU_FAST_DISCHARGE_ON: return "FD_ON";
|
||||
case PSU_FAST_DISCHARGE_ON_WAIT: return "FD_ON_WAIT";
|
||||
case PSU_CURRENT_DROP: return "CUR_DROP";
|
||||
case PSU_CONT_WAIT_ACK_OFF: return "CONT_OFF";
|
||||
case PSU_WAIT_ACK_OFF: return "WAIT_OFF";
|
||||
case PSU_OFF_PAUSE: return "OFF_PAUSE";
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static void PSU_LogPeriodicDiag(void)
|
||||
{
|
||||
static uint32_t last_log_ms;
|
||||
uint32_t now = HAL_GetTick();
|
||||
uint8_t block_setpoint;
|
||||
|
||||
if ((now - last_log_ms) < PSU_DIAG_LOG_MS) {
|
||||
return;
|
||||
}
|
||||
last_log_ms = now;
|
||||
|
||||
#if PSD_ENABLE
|
||||
block_setpoint = PowerSetpoint_HasPending() || PowerSetpoint_IsBusy();
|
||||
#else
|
||||
block_setpoint = 0u;
|
||||
#endif
|
||||
|
||||
log_printf(LOG_INFO,
|
||||
"PSU diag st=%s req=%uV/%u.%uA want=%uV/%u.%uA "
|
||||
"can=%uV/%u.%uA meas=%uV/%d.%uA "
|
||||
"enOut=%u out=%u rdy=%u on=%u cont=%u ac=%u hv=%u psd_blk=%u "
|
||||
"err=%u s0=0x%02x s1=0x%02x s2=0x%02x can_age=%lums\n",
|
||||
PSU_StateName(PSU0.state),
|
||||
(unsigned)CONN.RequestedVoltage,
|
||||
(unsigned)(CONN.RequestedCurrent / 10u),
|
||||
(unsigned)(CONN.RequestedCurrent % 10u),
|
||||
(unsigned)CONN.RequestedVoltage,
|
||||
(unsigned)(CONN.WantedCurrent / 10u),
|
||||
(unsigned)(CONN.WantedCurrent % 10u),
|
||||
(unsigned)psu_last_can_v,
|
||||
(unsigned)(psu_last_can_i_0p1A / 10u),
|
||||
(unsigned)(psu_last_can_i_0p1A % 10u),
|
||||
(unsigned)CONN.MeasuredVoltage,
|
||||
(int)(CONN.MeasuredCurrent / 10),
|
||||
(unsigned)(((CONN.MeasuredCurrent < 0) ?
|
||||
-CONN.MeasuredCurrent : CONN.MeasuredCurrent) % 10),
|
||||
(unsigned)CONN.EnableOutput,
|
||||
(unsigned)CONN.outputEnabled,
|
||||
(unsigned)PSU0.ready,
|
||||
(unsigned)PSU0.PSU_enabled,
|
||||
(unsigned)PSU0.CONT_enabled,
|
||||
(unsigned)PSU0.enableAC,
|
||||
(unsigned)CONN.hv_limit,
|
||||
(unsigned)block_setpoint,
|
||||
(unsigned)CONN.chargingError,
|
||||
(unsigned)PSU0.status0.raw,
|
||||
(unsigned)PSU0.status1.raw,
|
||||
(unsigned)PSU0.status2.raw,
|
||||
(unsigned long)(can_lastpacket ? (now - can_lastpacket) : 9999u));
|
||||
}
|
||||
|
||||
static void PSU_HvControl(void)
|
||||
{
|
||||
if (CONN.EnableOutput == 0u) {
|
||||
@@ -97,6 +174,17 @@ static void PSU_HvControl(void)
|
||||
}
|
||||
|
||||
static void PSU_SwitchState(PSU_State_t state){
|
||||
if (PSU0.state != state) {
|
||||
log_printf(LOG_INFO,
|
||||
"PSU st %s->%s enOut=%u rdy=%u on=%u cont=%u err=%u\n",
|
||||
PSU_StateName(PSU0.state),
|
||||
PSU_StateName(state),
|
||||
(unsigned)CONN.EnableOutput,
|
||||
(unsigned)PSU0.ready,
|
||||
(unsigned)PSU0.PSU_enabled,
|
||||
(unsigned)PSU0.CONT_enabled,
|
||||
(unsigned)CONN.chargingError);
|
||||
}
|
||||
PSU0.state = state;
|
||||
PSU0.statetick = HAL_GetTick();
|
||||
}
|
||||
@@ -281,6 +369,8 @@ void PSU_SetVoltageCurrent(uint8_t addr, uint16_t voltage, uint16_t current){
|
||||
data.moduleVoltage[2] = (voltage_mv >> 8) & 0xFF;
|
||||
data.moduleVoltage[3] = (voltage_mv >> 0) & 0xFF;
|
||||
|
||||
psu_last_can_v = voltage;
|
||||
psu_last_can_i_0p1A = current;
|
||||
PSU_SendCmd(0xF0, addr, 0x1C, &data);
|
||||
|
||||
}
|
||||
@@ -381,6 +471,10 @@ void PSU_Task(void){
|
||||
|
||||
// Обновляем ONLINE/READY по таймауту
|
||||
if((HAL_GetTick() - can_lastpacket) > PSU_ONLINE_TIMEOUT){
|
||||
if (PSU0.online) {
|
||||
log_printf(LOG_WARN, "PSU CAN timeout age=%lums -> offline\n",
|
||||
(unsigned long)(HAL_GetTick() - can_lastpacket));
|
||||
}
|
||||
PSU0.online = 0;
|
||||
PSU0.PSU_enabled = 0;
|
||||
PSU_04.moduleTemperature = 0;
|
||||
@@ -637,6 +731,8 @@ void PSU_Task(void){
|
||||
PSU_SwitchState(PSU_UNREADY);
|
||||
break;
|
||||
}
|
||||
|
||||
PSU_LogPeriodicDiag();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+32
-13
@@ -330,22 +330,41 @@ void CCS_SerialLoop(void) {
|
||||
}
|
||||
|
||||
// 10s timeout: enforce safe-state until host communication recovers.
|
||||
if (host_timeout_stop) {
|
||||
CONN.EnableOutput = 0;
|
||||
CCS_EvseState = Unknown;
|
||||
CP_SetDuty(100);
|
||||
if (CCS_ConnectorState != CCS_DISABLED && CCS_ConnectorState != CCS_UNKNOWN) {
|
||||
CCS_ConnectorState = CCS_DISABLED;
|
||||
}
|
||||
} else {
|
||||
if (last_cmd == CMD_STOP) {
|
||||
{
|
||||
static uint8_t prev_enable_output = 0xFFu;
|
||||
uint8_t new_enable_output;
|
||||
|
||||
if (host_timeout_stop) {
|
||||
CONN.EnableOutput = 0;
|
||||
} else {
|
||||
CONN.EnableOutput = ev_enable_output ? 1 : 0;
|
||||
if((CONN.EnableOutput == 0) && (CONN.connState == Preparing)){
|
||||
CONN.EnableOutput = 0;
|
||||
CCS_EvseState = Unknown;
|
||||
CP_SetDuty(100);
|
||||
if (CCS_ConnectorState != CCS_DISABLED && CCS_ConnectorState != CCS_UNKNOWN) {
|
||||
CCS_ConnectorState = CCS_DISABLED;
|
||||
}
|
||||
new_enable_output = 0u;
|
||||
} else {
|
||||
if (last_cmd == CMD_STOP) {
|
||||
CONN.EnableOutput = 0;
|
||||
} else {
|
||||
CONN.EnableOutput = ev_enable_output ? 1 : 0;
|
||||
if((CONN.EnableOutput == 0) && (CONN.connState == Preparing)){
|
||||
CONN.EnableOutput = 0;
|
||||
}
|
||||
}
|
||||
new_enable_output = CONN.EnableOutput;
|
||||
}
|
||||
|
||||
if (prev_enable_output != 0xFFu && prev_enable_output != new_enable_output) {
|
||||
log_printf(LOG_INFO,
|
||||
"EnableOutput %u->%u ev=%u stop=%u host_to=%u err=%u\n",
|
||||
(unsigned)prev_enable_output,
|
||||
(unsigned)new_enable_output,
|
||||
(unsigned)ev_enable_output,
|
||||
(unsigned)(last_cmd == CMD_STOP),
|
||||
(unsigned)host_timeout_stop,
|
||||
(unsigned)CONN.chargingError);
|
||||
}
|
||||
prev_enable_output = new_enable_output;
|
||||
}
|
||||
|
||||
if ((cp_state_buffer == EV_STATE_B_CONN_PREP) ||
|
||||
|
||||
Reference in New Issue
Block a user