Skip to content

Commit

Permalink
Merge branch 'main' into CI/reusable-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik-K authored Jan 25, 2024
2 parents 604ffcd + 15458aa commit 82fd457
Show file tree
Hide file tree
Showing 49 changed files with 2,279 additions and 754 deletions.
2 changes: 1 addition & 1 deletion config/config-sil-dc-sae-v2g.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ active_modules:
slac:
module: JsSlacSimulator
imd:
module: JsIMDSimulator
module: IMDSimulator
car_simulator:
module: JsCarSimulator
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-dc-sae-v2h.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ active_modules:
slac:
module: JsSlacSimulator
imd:
module: JsIMDSimulator
module: IMDSimulator
car_simulator:
module: JsCarSimulator
config_module:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ active_modules:
slac:
module: JsSlacSimulator
imd:
module: JsIMDSimulator
module: IMDSimulator
car_simulator:
module: JsCarSimulator
config_module:
Expand Down
6 changes: 3 additions & 3 deletions config/config-sil-ocpp201.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ active_modules:
implementation_id: evse
- module_id: evse_manager_2
implementation_id: evse
auth:
- module_id: auth
implementation_id: main
system:
- module_id: system
implementation_id: main
security:
- module_id: evse_security
implementation_id: main
kvs:
- module_id: persistent_store
implementation_id: main
persistent_store:
module: PersistentStore
evse_security:
Expand Down
2 changes: 1 addition & 1 deletion config/config-sil-two-evse-dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ active_modules:
powersupply_dc:
module: JsDCSupplySimulator
imd:
module: JsIMDSimulator
module: IMDSimulator
car_simulator_1:
module: JsCarSimulator
config_module:
Expand Down
4 changes: 2 additions & 2 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ libcurl:
# OCPP
libocpp:
git: https://github.com/EVerest/libocpp.git
git_tag: 990e3bc
git_tag: 84b604a
# Josev
Josev:
git: https://github.com/EVerest/ext-switchev-iso15118.git
Expand All @@ -66,4 +66,4 @@ everest-utils:
# setting it here can be misleading since it does not affect the version being used
libevse-security:
git: https://github.com/EVerest/libevse-security.git
git_tag: v0.4.0
git_tag: 1604c8b
5 changes: 5 additions & 0 deletions lib/staging/ocpp/evse_security_ocpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ std::optional<ocpp::KeyPair> EvseSecurity::get_key_pair(const ocpp::CertificateS
}
}

bool EvseSecurity::update_certificate_links(const ocpp::CertificateSigningUseEnum& certificate_type) {
// TODO: Implement if required
return false;
}

std::string EvseSecurity::get_verify_file(const ocpp::CaCertificateType& certificate_type) {
return this->r_security.call_get_verify_file(conversions::from_ocpp(certificate_type));
}
Expand Down
1 change: 1 addition & 0 deletions lib/staging/ocpp/evse_security_ocpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class EvseSecurity : public ocpp::EvseSecurity {
const std::string& country, const std::string& organization,
const std::string& common, bool use_tpm) override;
std::optional<ocpp::KeyPair> get_key_pair(const ocpp::CertificateSigningUseEnum& certificate_type) override;
bool update_certificate_links(const ocpp::CertificateSigningUseEnum& certificate_type) override;
std::string get_verify_file(const ocpp::CaCertificateType& certificate_type) override;
int get_leaf_expiry_days_count(const ocpp::CertificateSigningUseEnum& certificate_type) override;
};
Expand Down
138 changes: 92 additions & 46 deletions modules/API/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace module {
static const auto NOTIFICATION_PERIOD = std::chrono::seconds(1);

SessionInfo::SessionInfo() :
state("Unknown"),
state(State::Unknown),
start_energy_import_wh(0),
end_energy_import_wh(0),
latest_total_w(0),
Expand All @@ -19,18 +19,19 @@ SessionInfo::SessionInfo() :
this->end_time_point = this->start_time_point;
}

bool SessionInfo::is_state_charging(const std::string& current_state) {
if (current_state == "AuthRequired" || current_state == "Charging" || current_state == "ChargingPausedEV" ||
current_state == "ChargingPausedEVSE") {
bool SessionInfo::is_state_charging(const SessionInfo::State current_state) {
if (current_state == State::AuthRequired || current_state == State::Charging ||
current_state == State::ChargingPausedEV || current_state == State::ChargingPausedEVSE) {
return true;
}
return false;
}

void SessionInfo::reset() {
std::lock_guard<std::mutex> lock(this->session_info_mutex);
this->state = "Unknown";
this->state_info = "";
this->state = State::Unknown;
this->active_permanent_faults.clear();
this->active_errors.clear();
this->start_energy_import_wh = 0;
this->end_energy_import_wh = 0;
this->start_energy_export_wh = 0;
Expand Down Expand Up @@ -65,43 +66,80 @@ types::energy::ExternalLimits get_external_limits(const std::string& data, bool
return external_limits;
}

void SessionInfo::update_state(const std::string& event, const std::string& state_info) {
static void remove_error_from_list(std::vector<module::SessionInfo::Error>& list, const std::string& error_type) {
list.erase(std::remove_if(list.begin(), list.end(),
[error_type](const module::SessionInfo::Error& err) { return err.type == error_type; }),
list.end());
}

void SessionInfo::update_state(const types::evse_manager::SessionEventEnum event, const SessionInfo::Error& error) {
std::lock_guard<std::mutex> lock(this->session_info_mutex);
using Event = types::evse_manager::SessionEventEnum;

if (event == Event::Enabled) {
this->state = State::Unplugged;
} else if (event == Event::Disabled) {
this->state = State::Disabled;
} else if (event == Event::SessionStarted) {
this->state = State::Preparing;
} else if (event == Event::ReservationStart) {
this->state = State::Reserved;
} else if (event == Event::ReservationEnd) {
this->state = State::Unplugged;
} else if (event == Event::AuthRequired) {
this->state = State::AuthRequired;
} else if (event == Event::WaitingForEnergy) {
this->state = State::WaitingForEnergy;
} else if (event == Event::TransactionStarted) {
this->state = State::Preparing;
} else if (event == Event::ChargingPausedEV) {
this->state = State::ChargingPausedEV;
} else if (event == Event::ChargingPausedEVSE) {
this->state = State::ChargingPausedEVSE;
} else if (event == Event::ChargingStarted) {
this->state = State::Charging;
} else if (event == Event::ChargingResumed) {
this->state = State::Charging;
} else if (event == Event::TransactionFinished) {
this->state = State::Finished;
} else if (event == Event::SessionFinished) {
this->state = State::Unplugged;
} else if (event == Event::PermanentFault) {
this->active_permanent_faults.push_back(error);
} else if (event == Event::Error) {
this->active_errors.push_back(error);
} else if (event == Event::PermanentFaultCleared or event == Event::ErrorCleared) {
remove_error_from_list(this->active_permanent_faults, error.type);
} else if (event == Event::AllErrorsCleared) {
this->active_permanent_faults.clear();
this->active_errors.clear();
}
}

this->state_info = state_info;
if (event == "Enabled") {
this->state = "Unplugged";
} else if (event == "Disabled") {
this->state = "Disabled";
} else if (event == "SessionStarted") {
this->state = "Preparing";
} else if (event == "ReservationStart") {
this->state = "Reserved";
} else if (event == "ReservationEnd") {
this->state = "Unplugged";
} else if (event == "AuthRequired") {
this->state = "AuthRequired";
} else if (event == "WaitingForEnergy") {
this->state = "WaitingForEnergy";
} else if (event == "TransactionStarted") {
this->state = "Preparing";
} else if (event == "ChargingPausedEV") {
this->state = "ChargingPausedEV";
} else if (event == "ChargingPausedEVSE") {
this->state = "ChargingPausedEVSE";
} else if (event == "ChargingStarted") {
this->state = "Charging";
} else if (event == "ChargingResumed") {
this->state = "Charging";
} else if (event == "TransactionFinished") {
this->state = "Finished";
} else if (event == "SessionFinished") {
this->state = "Unplugged";
} else if (event == "Error") {
this->state = "Error";
} else if (event == "PermanentFault") {
this->state = "PermanentFault";
std::string SessionInfo::state_to_string(SessionInfo::State s) {
switch (s) {
case SessionInfo::State::Unplugged:
return "Unplugged";
case SessionInfo::State::Disabled:
return "Disabled";
case SessionInfo::State::Preparing:
return "Preparing";
case SessionInfo::State::Reserved:
return "Reserved";
case SessionInfo::State::AuthRequired:
return "AuthRequired";
case SessionInfo::State::WaitingForEnergy:
return "WaitingForEnergy";
case SessionInfo::State::ChargingPausedEV:
return "ChargingPausedEV";
case SessionInfo::State::ChargingPausedEVSE:
return "ChargingPausedEVSE";
case SessionInfo::State::Charging:
return "Charging";
case SessionInfo::State::Finished:
return "Finished";
}
return "Unknown";
}

void SessionInfo::set_start_energy_import_wh(int32_t start_energy_import_wh) {
Expand Down Expand Up @@ -152,6 +190,10 @@ void SessionInfo::set_latest_total_w(double latest_total_w) {
this->latest_total_w = latest_total_w;
}

static void to_json(json& j, const SessionInfo::Error& e) {
j = json{{"type", e.type}, {"description", e.description}, {"severity", e.severity}};
}

SessionInfo::operator std::string() {
std::lock_guard<std::mutex> lock(this->session_info_mutex);

Expand All @@ -165,8 +207,9 @@ SessionInfo::operator std::string() {
auto charging_duration_s =
std::chrono::duration_cast<std::chrono::seconds>(this->end_time_point - this->start_time_point);

json session_info = json::object({{"state", this->state},
{"state_info", this->state_info},
json session_info = json::object({{"state", state_to_string(this->state)},
{"active_permanent_faults", this->active_permanent_faults},
{"active_errors", this->active_errors},
{"charged_energy_wh", charged_energy_wh},
{"discharged_energy_wh", discharged_energy_wh},
{"latest_total_w", this->latest_total_w},
Expand Down Expand Up @@ -252,12 +295,15 @@ void API::init() {

evse->subscribe_session_event(
[this, var_session_info, var_logging_path, &session_info](types::evse_manager::SessionEvent session_event) {
auto event = types::evse_manager::session_event_enum_to_string(session_event.event);
std::string state_info = "";
SessionInfo::Error error;
if (session_event.error.has_value()) {
state_info = types::evse_manager::error_enum_to_string(session_event.error.value().error_code);
error.type = types::evse_manager::error_enum_to_string(session_event.error.value().error_code);
error.description = session_event.error.value().error_description;
error.severity =
types::evse_manager::error_severity_to_string(session_event.error.value().error_severity);
}
session_info->update_state(event, state_info);

session_info->update_state(session_event.event, error);

if (session_event.event == types::evse_manager::SessionEventEnum::SessionStarted) {
if (session_event.session_started.has_value()) {
Expand Down
54 changes: 38 additions & 16 deletions modules/API/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,22 @@ namespace module {
class LimitDecimalPlaces;

class SessionInfo {
private:
std::mutex session_info_mutex;

std::string state; ///< Latest state of the EVSE
std::string state_info; ///< Additional information of this state
int32_t start_energy_import_wh; ///< Energy reading (import) at the beginning of this charging session in Wh
int32_t end_energy_import_wh; ///< Energy reading (import) at the end of this charging session in Wh
int32_t start_energy_export_wh; ///< Energy reading (export) at the beginning of this charging session in Wh
int32_t end_energy_export_wh; ///< Energy reading (export) at the end of this charging session in Wh
std::chrono::time_point<date::utc_clock> start_time_point; ///< Start of the charging session
std::chrono::time_point<date::utc_clock> end_time_point; ///< End of the charging session
double latest_total_w; ///< Latest total power reading in W

bool is_state_charging(const std::string& current_state);

public:
SessionInfo();

struct Error {
std::string type;
std::string description;
std::string severity;
};

bool start_energy_export_wh_was_set{
false}; ///< Indicate if start export energy value (optional) has been received or not
bool end_energy_export_wh_was_set{
false}; ///< Indicate if end export energy value (optional) has been received or not

void reset();
void update_state(const std::string& event, const std::string& state_info);
void update_state(const types::evse_manager::SessionEventEnum event, const SessionInfo::Error& error);
void set_start_energy_import_wh(int32_t start_energy_import_wh);
void set_end_energy_import_wh(int32_t end_energy_import_wh);
void set_latest_energy_import_wh(int32_t latest_energy_wh);
Expand All @@ -69,6 +60,37 @@ class SessionInfo {

/// \brief Converts this struct into a serialized json object
operator std::string();

private:
std::mutex session_info_mutex;

std::vector<Error> active_permanent_faults; ///< Array of currently active permanent faults that prevent charging
std::vector<Error> active_errors; ///< Array of currently active errors that do not prevent charging
int32_t start_energy_import_wh; ///< Energy reading (import) at the beginning of this charging session in Wh
int32_t end_energy_import_wh; ///< Energy reading (import) at the end of this charging session in Wh
int32_t start_energy_export_wh; ///< Energy reading (export) at the beginning of this charging session in Wh
int32_t end_energy_export_wh; ///< Energy reading (export) at the end of this charging session in Wh
std::chrono::time_point<date::utc_clock> start_time_point; ///< Start of the charging session
std::chrono::time_point<date::utc_clock> end_time_point; ///< End of the charging session
double latest_total_w; ///< Latest total power reading in W

enum class State {
Unknown,
Unplugged,
Disabled,
Preparing,
Reserved,
AuthRequired,
WaitingForEnergy,
ChargingPausedEV,
ChargingPausedEVSE,
Charging,
Finished
} state;

bool is_state_charging(const SessionInfo::State current_state);

std::string state_to_string(State s);
};
} // namespace module
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
Expand Down
Loading

0 comments on commit 82fd457

Please sign in to comment.