From 9e315b5f410e18f6843925541bcae675c6e16579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piet=20G=C3=B6mpel?= Date: Thu, 10 Oct 2024 14:59:52 +0200 Subject: [PATCH] addressed requested changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piet Gömpel --- modules/API/API.cpp | 37 ++++++++++++++++++++----------------- modules/OCPP/OCPP.cpp | 2 +- modules/OCPP/doc.rst | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/modules/API/API.cpp b/modules/API/API.cpp index c64d550dd..65eee0b82 100644 --- a/modules/API/API.cpp +++ b/modules/API/API.cpp @@ -489,12 +489,15 @@ void API::init() { std::string cmd_set_limit = cmd_base + "set_limit_amps"; - this->mqtt.subscribe(cmd_set_limit, [&evse, &r_evse_manager_energy_sink = this->r_evse_manager_energy_sink, + const auto& evse_energy_sink = this->r_evse_manager_energy_sink.at(evse_id); + + this->mqtt.subscribe(cmd_set_limit, [&evse_manager_check = this->evse_manager_check, + &evse_energy_sink = evse_energy_sink, evse_id](const std::string& data) { try { const auto external_limits = get_external_limits(data, false); - this->evse_manager_check.wait_ready(); - r_evse_manager_energy_sink.at(evse_id - 1)->call_set_external_limits(external_limits); + evse_manager_check.wait_ready(); + evse_energy_sink->call_set_external_limits(external_limits); } catch (const std::invalid_argument& e) { EVLOG_warning << "Invalid limit: No conversion of given input could be performed."; } catch (const std::out_of_range& e) { @@ -504,20 +507,20 @@ void API::init() { std::string cmd_set_limit_watts = cmd_base + "set_limit_watts"; - this->mqtt.subscribe( - cmd_set_limit_watts, - [&evse, &r_evse_manager_energy_sink = this->r_evse_manager_energy_sink, evse_id](const std::string& data) { - try { - const auto external_limits = get_external_limits(data, true); - this->evse_manager_check.wait_ready(); - r_evse_manager_energy_sink.at(evse_id - 1)->call_set_external_limits(external_limits); // FIX access - } catch (const std::invalid_argument& e) { - EVLOG_warning << "Invalid limit: No conversion of given input could be performed."; - } catch (const std::out_of_range& e) { - EVLOG_warning << "Invalid limit: Out of range."; - } - }); - + this->mqtt.subscribe(cmd_set_limit_watts, [&evse_manager_check = this->evse_manager_check, + &evse_energy_sink = evse_energy_sink, + evse_id](const std::string& data) { + try { + const auto external_limits = get_external_limits(data, true); + evse_manager_check.wait_ready(); + evse_energy_sink->call_set_external_limits(external_limits); + } catch (const std::invalid_argument& e) { + EVLOG_warning << "Invalid limit: No conversion of given input could be performed."; + } catch (const std::out_of_range& e) { + EVLOG_warning << "Invalid limit: Out of range."; + } + }); + std::string cmd_force_unlock = cmd_base + "force_unlock"; this->mqtt.subscribe(cmd_force_unlock, [this, &evse](const std::string& data) { int connector_id = 1; diff --git a/modules/OCPP/OCPP.cpp b/modules/OCPP/OCPP.cpp index 52cc6b771..c7aa5b14a 100644 --- a/modules/OCPP/OCPP.cpp +++ b/modules/OCPP/OCPP.cpp @@ -102,7 +102,7 @@ void OCPP::set_external_limits(const std::mapr_evse_manager_energy_sink.empty()) { EVLOG_debug << "OCPP sets the following external limits for connector 0: \n" << limits; - this->r_evse_manager_energy_sink.at(0)->call_set_external_limits(limits); + this->r_evse_manager_energy_sink.first()->call_set_external_limits(limits); } else { EVLOG_debug << "OCPP cannot set external limits for connector 0. No " "sink is configured."; diff --git a/modules/OCPP/doc.rst b/modules/OCPP/doc.rst index 0201ce257..c1b382fec 100644 --- a/modules/OCPP/doc.rst +++ b/modules/OCPP/doc.rst @@ -38,7 +38,7 @@ OCPP1.6 defines the SmartCharging feature profile to allow the CSMS to control o This module integrates the composite schedule(s) within EVerests energy management. For further information about smart charging and the composite schedule calculation please refer to the OCPP1.6 specification. -The integration of the composite schedules are turned out by the optional requirement(s) `evse_manager_energy_sink`(interface: `external_energy_limits`) +The integration of the composite schedules are implemented through the optional requirement(s) `evse_manager_energy_sink`(interface: `external_energy_limits`) of this module. Depending on the number of EVSEs configured, each composite limit is communicated via a seperate sink, including the composite schedule for EVSE with id 0 (representing the whole charging station). The easiest way to explain this is with an example. If your charging station has two EVSEs you need to connect three modules that implement the `external_energy_limits` interface: One representing evse id 0 and