Stop charging if we're discharging

This commit is contained in:
jazzpi 2022-08-05 00:13:17 +02:00
parent 77f600ddb3
commit e3080b1f6e
3 changed files with 8 additions and 1 deletions

View File

@ -32,6 +32,7 @@ typedef struct {
int32_t BatteryVoltageVehicleSide; int32_t BatteryVoltageVehicleSide;
int32_t BatteryVoltageBatterySide; int32_t BatteryVoltageBatterySide;
int32_t shuntCurrent;
uint8_t targetTSState; uint8_t targetTSState;
uint8_t currentTSState; uint8_t currentTSState;
uint32_t precharge95ReachedTimestamp; uint32_t precharge95ReachedTimestamp;

View File

@ -113,6 +113,12 @@ uint8_t Update_AIR_State(AIRStateHandler* airstate) {
} }
} }
else if (airstate->currentTSState == TS_CHARGING) {
if (airstate->shuntCurrent < 0) {
airstate->currentTSState = TS_ERROR;
}
}
else if (airstate->currentTSState == else if (airstate->currentTSState ==
TS_PRECHARGE) // Change from Precharge to Active at 95% TS Voltage at TS_PRECHARGE) // Change from Precharge to Active at 95% TS Voltage at
// Vehicle Side // Vehicle Side

View File

@ -348,7 +348,7 @@ void InterSTMFrame() {
spirxbuf[0] << 24 | spirxbuf[1] << 16 | spirxbuf[2] << 8 | spirxbuf[3]; spirxbuf[0] << 24 | spirxbuf[1] << 16 | spirxbuf[2] << 8 | spirxbuf[3];
spi_airstates->BatteryVoltageVehicleSide = spi_airstates->BatteryVoltageVehicleSide =
spirxbuf[4] << 24 | spirxbuf[5] << 16 | spirxbuf[6] << 8 | spirxbuf[7]; spirxbuf[4] << 24 | spirxbuf[5] << 16 | spirxbuf[6] << 8 | spirxbuf[7];
uint32_t current = spi_airstates->shuntCurrent =
spirxbuf[8] << 24 | spirxbuf[9] << 16 | spirxbuf[10] << 8 | spirxbuf[11]; spirxbuf[8] << 24 | spirxbuf[9] << 16 | spirxbuf[10] << 8 | spirxbuf[11];
spi_airstates->targetTSState = spirxbuf[12]; spi_airstates->targetTSState = spirxbuf[12];
} }