Skip to content

Commit

Permalink
Changes needed by EVerest/everest-framework#87
Browse files Browse the repository at this point in the history
- note, there are quite many places where the proper usage of the
  std::optional api might improve readability

Signed-off-by: aw <[email protected]>
  • Loading branch information
a-w50 committed May 30, 2023
1 parent 44bb0de commit b42f7d2
Show file tree
Hide file tree
Showing 34 changed files with 239 additions and 233 deletions.
4 changes: 2 additions & 2 deletions dependencies.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
everest-framework:
git: https://github.com/EVerest/everest-framework.git
git_tag: 61318a6
git_tag: 8386e31
sigslot:
git: https://github.com/palacaze/sigslot
git_tag: v1.2.0
Expand Down Expand Up @@ -38,7 +38,7 @@ RISE-V2G:
# OCPP
libocpp:
git: https://github.com/EVerest/libocpp.git
git_tag: v0.8.0
git_tag: '2341358'
# Josev
Josev:
git: https://github.com/EVerest/ext-switchev-iso15118.git
Expand Down
11 changes: 7 additions & 4 deletions modules/Auth/include/Connector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
#ifndef _CONNECTOR_HPP_
#define _CONNECTOR_HPP_

#include <optional>

#include <everest/timer.hpp>

#include <utils/types.hpp>


#include <ConnectorStateMachine.hpp>
#include <generated/types/authorization.hpp>

Expand All @@ -17,9 +20,9 @@ namespace module {
struct Identifier {
std::string id_token; ///< Arbitrary id token string: this has to be printable case insensitive ascii
types::authorization::TokenType type; ///< Type of the provider of the identifier
boost::optional<types::authorization::AuthorizationStatus> authorization_status;
boost::optional<std::string> expiry_time; ///< Absolute UTC time point when reservation expires in RFC3339 format
boost::optional<std::string> parent_id_token; ///< Parent id token of the id token
std::optional<types::authorization::AuthorizationStatus> authorization_status;
std::optional<std::string> expiry_time; ///< Absolute UTC time point when reservation expires in RFC3339 format
std::optional<std::string> parent_id_token; ///< Parent id token of the id token
};

struct Connector {
Expand All @@ -36,7 +39,7 @@ struct Connector {
ConnectorStateMachine state_machine;

// identifier is set when transaction is running and none if not
boost::optional<Identifier> identifier = boost::none;
std::optional<Identifier> identifier = std::nullopt;

bool is_reservable;
bool reserved;
Expand Down
2 changes: 1 addition & 1 deletion modules/Auth/include/ReservationHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ReservationHandler {
* @return true
* @return false
*/
bool matches_reserved_identifier(int connector, const std::string& id_token, boost::optional<std::string> parent_id_token);
bool matches_reserved_identifier(int connector, const std::string& id_token, std::optional<std::string> parent_id_token);

/**
* @brief Function tries to reserve the given \p connector using the given \p reservation
Expand Down
8 changes: 4 additions & 4 deletions modules/Auth/lib/AuthHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ int AuthHandler::used_for_transaction(const std::vector<int>& connector_ids, con
return connector_id;
}
// check against parent_id_token
else if (identifier.parent_id_token.has_value() && identifier.parent_id_token.get() == token) {
else if (identifier.parent_id_token.has_value() && identifier.parent_id_token.value() == token) {
return connector_id;
}
}
Expand Down Expand Up @@ -353,7 +353,7 @@ void AuthHandler::notify_evse(int connector_id, const ProvidedIdToken& provided_
->timeout_timer.timeout(
[this, evse_index, connector_id]() {
EVLOG_info << "Authorization timeout for evse#" << evse_index;
this->connectors.at(connector_id)->connector.identifier = boost::none;
this->connectors.at(connector_id)->connector.identifier.reset();
this->withdraw_authorization_callback(evse_index);
},
std::chrono::seconds(this->connection_timeout));
Expand Down Expand Up @@ -418,11 +418,11 @@ void AuthHandler::handle_session_event(const int connector_id, const SessionEven
break;
case SessionEventEnum::TransactionFinished:
this->connectors.at(connector_id)->connector.transaction_active = false;
this->connectors.at(connector_id)->connector.identifier = boost::none;
this->connectors.at(connector_id)->connector.identifier.reset();
break;
case SessionEventEnum::SessionFinished:
this->connectors.at(connector_id)->connector.is_reservable = true;
this->connectors.at(connector_id)->connector.identifier = boost::none;
this->connectors.at(connector_id)->connector.identifier.reset();
this->connectors.at(connector_id)->connector.submit_event(ConnectorEvent::SESSION_FINISHED);
this->connectors.at(connector_id)->connector.submit_event(ConnectorEvent::ERROR_CLEARED);
this->connectors.at(connector_id)->timeout_timer.stop();
Expand Down
2 changes: 1 addition & 1 deletion modules/Auth/lib/ReservationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void ReservationHandler::init_connector(int connector_id) {
}

bool ReservationHandler::matches_reserved_identifier(int connector, const std::string& id_token,
boost::optional<std::string> parent_id_token) {
std::optional<std::string> parent_id_token) {
// return true if id tokens match or parent id tokens exists and match
return this->reservations[connector].id_token == id_token ||
(parent_id_token && this->reservations[connector].parent_id_token &&
Expand Down
4 changes: 2 additions & 2 deletions modules/Auth/tests/auth_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ static SessionEvent get_session_started_event(const types::evse_manager::StartSe
}

static ProvidedIdToken get_provided_token(const std::string& id_token,
boost::optional<std::vector<int32_t>> connectors = boost::none,
boost::optional<bool> prevalidated = boost::none) {
std::optional<std::vector<int32_t>> connectors = std::nullopt,
std::optional<bool> prevalidated = std::nullopt) {
ProvidedIdToken provided_token;
provided_token.id_token = id_token;
provided_token.type = types::authorization::TokenType::RFID;
Expand Down
20 changes: 10 additions & 10 deletions modules/EnergyManager/Offer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ std::ostream& operator<<(std::ostream& out, const Offer& self) {
}

template <class T> static void apply_one_limit_if_smaller(T& a, const T& b) {
if (b.is_initialized()) {
if (a.is_initialized()) {
if (a.get() > b.get()) {
a = b.get();
if (b) {
if (a) {
if (a.value() > b.value()) {
a = b.value();
}
} else {
a = b.get();
a = b.value();
}
}
}

template <class T> static void apply_one_limit_if_greater(T& a, const T& b) {
if (b.is_initialized()) {
if (a.is_initialized()) {
if (a.get() < b.get()) {
a = b.get();
if (b) {
if (a) {
if (a.value() < b.value()) {
a = b.value();
}
} else {
a = b.get();
a = b.value();
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions modules/EnergyManager/Offer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
#ifndef OFFER_HPP
#define OFFER_HPP

#include <vector>
#include <optional>

#include "Market.hpp"
#include <generated/interfaces/energy/Interface.hpp>
#include <vector>


namespace module {

class Offer {
public:
Offer(Market& market);

boost::optional<types::energy::OptimizerTarget> optimizer_target;
std::optional<types::energy::OptimizerTarget> optimizer_target;
ScheduleReq import_offer, export_offer;

private:
Expand Down
128 changes: 64 additions & 64 deletions modules/EvseManager/EvseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void EvseManager::ready() {

if (config.hack_present_current_offset > 0) {
present_values.EVSEPresentCurrent =
present_values.EVSEPresentCurrent.get() + config.hack_present_current_offset;
present_values.EVSEPresentCurrent.value() + config.hack_present_current_offset;
}

if (config.hack_pause_imd_during_precharge && m.voltage_V * m.current_A > 1000) {
Expand Down Expand Up @@ -552,10 +552,10 @@ void EvseManager::ready() {
if (r_powermeter_billing().size() > 0) {
r_powermeter_billing()[0]->subscribe_powermeter([this](types::powermeter::Powermeter p) {
// Inform charger about current charging current. This is used for slow OC detection.
if (p.current_A.is_initialized() && p.current_A.get().L1.is_initialized() &&
p.current_A.get().L2.is_initialized() && p.current_A.get().L3.is_initialized()) {
charger->setCurrentDrawnByVehicle(p.current_A.get().L1.get(), p.current_A.get().L2.get(),
p.current_A.get().L3.get());
if (p.current_A && p.current_A.value().L1 &&
p.current_A.value().L2 && p.current_A.value().L3) {
charger->setCurrentDrawnByVehicle(p.current_A.value().L1.value(), p.current_A.value().L2.value(),
p.current_A.value().L3.value());
}

// Inform HLC about the power meter data
Expand All @@ -570,17 +570,17 @@ void EvseManager::ready() {
}

// External Nodered interface
if (p.phase_seq_error.is_initialized()) {
if (p.phase_seq_error) {
mqtt.publish(fmt::format("everest_external/nodered/{}/powermeter/phaseSeqError", config.connector_id),
p.phase_seq_error.get());
p.phase_seq_error.value());
}

mqtt.publish(fmt::format("everest_external/nodered/{}/powermeter/time_stamp", config.connector_id),
p.timestamp);

if (p.power_W.is_initialized()) {
if (p.power_W) {
mqtt.publish(fmt::format("everest_external/nodered/{}/powermeter/totalKw", config.connector_id),
p.power_W.get().total / 1000., 1);
p.power_W.value().total / 1000., 1);
}

mqtt.publish(fmt::format("everest_external/nodered/{}/powermeter/totalKWattHr", config.connector_id),
Expand Down Expand Up @@ -677,96 +677,96 @@ void EvseManager::ready() {
auto p = get_latest_powermeter_data_billing();
Everest::TelemetryMap telemetry_data{{"timestamp", p.timestamp},
{"type", "power_meter"},
{"meter_id", p.meter_id.get_value_or("N/A")},
{"meter_id", p.meter_id.value_or("N/A")},
{"energy_import_total_Wh", p.energy_Wh_import.total}};

if (p.energy_Wh_import.L1.is_initialized()) {
telemetry_data["energy_import_L1_Wh"] = p.energy_Wh_import.L1.get();
if (p.energy_Wh_import.L1) {
telemetry_data["energy_import_L1_Wh"] = p.energy_Wh_import.L1.value();
}
if (p.energy_Wh_import.L2.is_initialized()) {
telemetry_data["energy_import_L2_Wh"] = p.energy_Wh_import.L2.get();
if (p.energy_Wh_import.L2) {
telemetry_data["energy_import_L2_Wh"] = p.energy_Wh_import.L2.value();
}
if (p.energy_Wh_import.L3.is_initialized()) {
telemetry_data["energy_import_L3_Wh"] = p.energy_Wh_import.L3.get();
if (p.energy_Wh_import.L3) {
telemetry_data["energy_import_L3_Wh"] = p.energy_Wh_import.L3.value();
}

if (p.energy_Wh_export.is_initialized()) {
telemetry_data["energy_export_total_Wh"] = p.energy_Wh_export.get().total;
if (p.energy_Wh_export) {
telemetry_data["energy_export_total_Wh"] = p.energy_Wh_export.value().total;
}
if (p.energy_Wh_export.is_initialized() && p.energy_Wh_export.get().L1.is_initialized()) {
telemetry_data["energy_export_L1_Wh"] = p.energy_Wh_export.get().L1.get();
if (p.energy_Wh_export && p.energy_Wh_export.value().L1) {
telemetry_data["energy_export_L1_Wh"] = p.energy_Wh_export.value().L1.value();
}
if (p.energy_Wh_export.is_initialized() && p.energy_Wh_export.get().L2.is_initialized()) {
telemetry_data["energy_export_L2_Wh"] = p.energy_Wh_export.get().L2.get();
if (p.energy_Wh_export && p.energy_Wh_export.value().L2) {
telemetry_data["energy_export_L2_Wh"] = p.energy_Wh_export.value().L2.value();
}
if (p.energy_Wh_export.is_initialized() && p.energy_Wh_export.get().L3.is_initialized()) {
telemetry_data["energy_export_L3_Wh"] = p.energy_Wh_export.get().L3.get();
if (p.energy_Wh_export && p.energy_Wh_export.value().L3) {
telemetry_data["energy_export_L3_Wh"] = p.energy_Wh_export.value().L3.value();
}

if (p.power_W.is_initialized()) {
telemetry_data["power_total_W"] = p.power_W.get().total;
if (p.power_W) {
telemetry_data["power_total_W"] = p.power_W.value().total;
}
if (p.power_W.is_initialized() && p.power_W.get().L1.is_initialized()) {
telemetry_data["power_L1_W"] = p.power_W.get().L1.get();
if (p.power_W && p.power_W.value().L1) {
telemetry_data["power_L1_W"] = p.power_W.value().L1.value();
}
if (p.power_W.is_initialized() && p.power_W.get().L2.is_initialized()) {
telemetry_data["power_L3_W"] = p.power_W.get().L2.get();
if (p.power_W && p.power_W.value().L2) {
telemetry_data["power_L3_W"] = p.power_W.value().L2.value();
}
if (p.power_W.is_initialized() && p.power_W.get().L3.is_initialized()) {
telemetry_data["power_L3_W"] = p.power_W.get().L3.get();
if (p.power_W && p.power_W.value().L3) {
telemetry_data["power_L3_W"] = p.power_W.value().L3.value();
}

if (p.VAR.is_initialized()) {
telemetry_data["var_total"] = p.VAR.get().total;
if (p.VAR) {
telemetry_data["var_total"] = p.VAR.value().total;
}
if (p.VAR.is_initialized() && p.VAR.get().L1.is_initialized()) {
telemetry_data["var_L1"] = p.VAR.get().L1.get();
if (p.VAR && p.VAR.value().L1) {
telemetry_data["var_L1"] = p.VAR.value().L1.value();
}
if (p.VAR.is_initialized() && p.VAR.get().L2.is_initialized()) {
telemetry_data["var_L1"] = p.VAR.get().L2.get();
if (p.VAR && p.VAR.value().L2) {
telemetry_data["var_L1"] = p.VAR.value().L2.value();
}
if (p.VAR.is_initialized() && p.VAR.get().L3.is_initialized()) {
telemetry_data["var_L1"] = p.VAR.get().L3.get();
if (p.VAR && p.VAR.value().L3) {
telemetry_data["var_L1"] = p.VAR.value().L3.value();
}

if (p.voltage_V.is_initialized() && p.voltage_V.get().L1.is_initialized()) {
telemetry_data["voltage_L1_V"] = p.voltage_V.get().L1.get();
if (p.voltage_V && p.voltage_V.value().L1) {
telemetry_data["voltage_L1_V"] = p.voltage_V.value().L1.value();
}
if (p.voltage_V.is_initialized() && p.voltage_V.get().L2.is_initialized()) {
telemetry_data["voltage_L2_V"] = p.voltage_V.get().L2.get();
if (p.voltage_V && p.voltage_V.value().L2) {
telemetry_data["voltage_L2_V"] = p.voltage_V.value().L2.value();
}
if (p.voltage_V.is_initialized() && p.voltage_V.get().L3.is_initialized()) {
telemetry_data["voltage_L3_V"] = p.voltage_V.get().L3.get();
if (p.voltage_V && p.voltage_V.value().L3) {
telemetry_data["voltage_L3_V"] = p.voltage_V.value().L3.value();
}
if (p.voltage_V.is_initialized() && p.voltage_V.get().DC.is_initialized()) {
telemetry_data["voltage_DC_V"] = p.voltage_V.get().DC.get();
if (p.voltage_V && p.voltage_V.value().DC) {
telemetry_data["voltage_DC_V"] = p.voltage_V.value().DC.value();
}

if (p.current_A.is_initialized() && p.current_A.get().L1.is_initialized()) {
telemetry_data["current_L1_A"] = p.current_A.get().L1.get();
if (p.current_A && p.current_A.value().L1) {
telemetry_data["current_L1_A"] = p.current_A.value().L1.value();
}
if (p.current_A.is_initialized() && p.current_A.get().L2.is_initialized()) {
telemetry_data["current_L2_A"] = p.current_A.get().L2.get();
if (p.current_A && p.current_A.value().L2) {
telemetry_data["current_L2_A"] = p.current_A.value().L2.value();
}
if (p.current_A.is_initialized() && p.current_A.get().L3.is_initialized()) {
telemetry_data["current_L3_A"] = p.current_A.get().L3.get();
if (p.current_A && p.current_A.value().L3) {
telemetry_data["current_L3_A"] = p.current_A.value().L3.value();
}
if (p.current_A.is_initialized() && p.current_A.get().DC.is_initialized()) {
telemetry_data["current_DC_A"] = p.current_A.get().DC.get();
if (p.current_A && p.current_A.value().DC) {
telemetry_data["current_DC_A"] = p.current_A.value().DC.value();
}

if (p.frequency_Hz.is_initialized()) {
telemetry_data["frequency_L1_Hz"] = p.frequency_Hz.get().L1;
if (p.frequency_Hz) {
telemetry_data["frequency_L1_Hz"] = p.frequency_Hz.value().L1;
}
if (p.frequency_Hz.is_initialized() && p.frequency_Hz.get().L2.is_initialized()) {
telemetry_data["frequency_L2_Hz"] = p.frequency_Hz.get().L2.get();
if (p.frequency_Hz && p.frequency_Hz.value().L2) {
telemetry_data["frequency_L2_Hz"] = p.frequency_Hz.value().L2.value();
}
if (p.frequency_Hz.is_initialized() && p.frequency_Hz.get().L3.is_initialized()) {
telemetry_data["frequency_L3_Hz"] = p.frequency_Hz.get().L3.get();
if (p.frequency_Hz && p.frequency_Hz.value().L3) {
telemetry_data["frequency_L3_Hz"] = p.frequency_Hz.value().L3.value();
}

if (p.phase_seq_error.is_initialized()) {
telemetry_data["phase_seq_error"] = p.phase_seq_error.get();
if (p.phase_seq_error) {
telemetry_data["phase_seq_error"] = p.phase_seq_error.value();
}

// Publish as external telemetry data
Expand Down
6 changes: 3 additions & 3 deletions modules/EvseManager/SessionLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void SessionLog::enable() {
enabled = true;
}

boost::optional<std::string> SessionLog::startSession(const std::string& suffix_string) {
std::optional<std::string> SessionLog::startSession(const std::string& suffix_string) {
if (enabled) {
if (session_active) {
stopSession();
Expand Down Expand Up @@ -93,10 +93,10 @@ boost::optional<std::string> SessionLog::startSession(const std::string& suffix_
"</style>";
logfile_html << "</head><body><table class=\"log\">\n";
sys("Session logging started.");
return boost::optional<std::string>(logpath);
return logpath;
}

return boost::optional<std::string>();
return std::string();
}

void SessionLog::stopSession() {
Expand Down
Loading

0 comments on commit b42f7d2

Please sign in to comment.