Skip to content

Commit

Permalink
EvseManager: Fix 6s timeout in C1
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelius Claussen <[email protected]>
  • Loading branch information
corneliusclaussen committed Feb 22, 2024
1 parent 415b164 commit 53fdbab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions modules/EvseManager/Charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,17 @@ void Charger::process_cp_events_independent(CPEvent cp_event) {
case CPEvent::EvseReplugFinished:
shared_context.current_state = EvseState::WaitingForAuthentication;
break;
case CPEvent::CarRequestedStopPower:
shared_context.iec_allow_close_contactor = false;
break;
case CPEvent::CarUnplugged:
if (not shared_context.hlc_charging_active) {
shared_context.current_state = EvseState::StoppingCharging;
} else {
shared_context.current_state = EvseState::Finished;
}
break;

default:
break;
}
Expand Down
22 changes: 12 additions & 10 deletions modules/EvseManager/IECStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const std::string cpevent_to_string(CPEvent e) {

IECStateMachine::IECStateMachine(const std::unique_ptr<evse_board_supportIntf>& r_bsp) : r_bsp(r_bsp) {
// feed the state machine whenever the timer expires
timeout_state_c1.signal_reached.connect(&IECStateMachine::feed_state_machine, this);
timeout_state_c1.signal_reached.connect(&IECStateMachine::feed_state_machine_no_thread, this);

// Subscribe to bsp driver to receive BspEvents from the hardware
r_bsp->subscribe_event([this](const types::board_support_common::BspEvent event) {
Expand Down Expand Up @@ -111,18 +111,20 @@ void IECStateMachine::process_bsp_event(const types::board_support_common::BspEv
}

void IECStateMachine::feed_state_machine() {
std::thread feed([this]() {
auto events = state_machine();

// Process all events
while (not events.empty()) {
signal_event(events.front());
events.pop();
}
});
std::thread feed([this]() { feed_state_machine_no_thread(); });
feed.detach();
}

void IECStateMachine::feed_state_machine_no_thread() {
auto events = state_machine();

// Process all events
while (not events.empty()) {
signal_event(events.front());
events.pop();
}
}

// Main IEC state machine. Needs to be called whenever:
// - CP state changes (both events from hardware as well as duty cycle changes)
// - Allow power on changes
Expand Down
1 change: 1 addition & 0 deletions modules/EvseManager/IECStateMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class IECStateMachine {

Everest::timed_mutex_traceable state_machine_mutex;
void feed_state_machine();
void feed_state_machine_no_thread();
std::queue<CPEvent> state_machine();

types::evse_board_support::Reason power_on_reason{types::evse_board_support::Reason::PowerOff};
Expand Down

0 comments on commit 53fdbab

Please sign in to comment.