Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix forced unlocking #542

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions modules/EvseManager/IECStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,28 @@ void IECStateMachine::connector_lock() {

void IECStateMachine::connector_unlock() {
should_be_locked = false;
force_unlocked = false;
}

void IECStateMachine::connector_force_unlock() {
RawCPState cp;

{
Everest::scoped_lock_timeout lock(state_machine_mutex, Everest::MutexDescription::IEC_force_unlock);
cp = cp_state;
}

if (cp == RawCPState::B or cp == RawCPState::C) {
force_unlocked = true;
check_connector_lock();
}
}

void IECStateMachine::check_connector_lock() {
if (should_be_locked and not is_locked) {
if (should_be_locked and not force_unlocked and not is_locked) {
signal_lock();
is_locked = true;
} else if (not should_be_locked and is_locked and not relais_on) {
} else if ((not should_be_locked or force_unlocked) and is_locked and not relais_on) {
signal_unlock();
is_locked = false;
}
Expand Down
8 changes: 5 additions & 3 deletions modules/EvseManager/IECStateMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@ class IECStateMachine {

void enable(bool en);

void connector_lock();
void connector_unlock();
void check_connector_lock();
void connector_force_unlock();

// Signal for internal events type
sigslot::signal<CPEvent> signal_event;
sigslot::signal<> signal_lock;
sigslot::signal<> signal_unlock;

private:
void connector_lock();
void connector_unlock();
void check_connector_lock();
const std::unique_ptr<evse_board_supportIntf>& r_bsp;

bool pwm_running{false};
Expand All @@ -123,6 +124,7 @@ class IECStateMachine {
std::atomic_bool three_phases{true};
std::atomic_bool is_locked{false};
std::atomic_bool should_be_locked{false};
std::atomic_bool force_unlocked{false};

std::atomic_bool enabled{false};
std::atomic_bool relais_on{false};
Expand Down
2 changes: 1 addition & 1 deletion modules/EvseManager/evse/evse_managerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ bool evse_managerImpl::handle_external_ready_to_start_charging() {
}

bool evse_managerImpl::handle_force_unlock(int& connector_id) {
mod->bsp->connector_unlock();
mod->bsp->connector_force_unlock();
return true;
};

Expand Down
3 changes: 3 additions & 0 deletions modules/EvseManager/scoped_lock_timeout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum class MutexDescription {
IEC_set_pwm_off,
IEC_set_pwm_F,
IEC_allow_power_on,
IEC_force_unlock,
EVSE_set_ev_info,
EVSE_publish_ev_info,
EVSE_subscribe_DC_EVMaximumLimits,
Expand Down Expand Up @@ -171,6 +172,8 @@ static std::string to_string(MutexDescription d) {
return "IECStateMachine::set_pwm_F";
case MutexDescription::IEC_allow_power_on:
return "IECStateMachine::allow_power_on";
case MutexDescription::IEC_force_unlock:
return "IECStateMachine::force_unlock";
case MutexDescription::EVSE_set_ev_info:
return "EvseManager.cpp: set ev_info present_voltage/current";
case MutexDescription::EVSE_publish_ev_info:
Expand Down
Loading