From 52f82bfc9ad383f3e50cfb14870f609ed6eb682d Mon Sep 17 00:00:00 2001 From: Matthias Suess Date: Wed, 4 Dec 2024 11:45:28 +0100 Subject: [PATCH 1/4] Integrate of send of present connector or reject if non is present Signed-off-by: Matthias Suess --- lib/ocpp/v16/charge_point_impl.cpp | 54 ++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index a8f2176dc..3586c8056 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -2435,6 +2435,29 @@ void ChargePointImpl::handleTriggerMessageRequest(ocpp::Call thereIsMeterValueForRequest; + if (call.msg.connectorId.has_value()) { + if (this->connectors.find(connector) != this->connectors.end() && + this->connectors.at(connector)->measurement.has_value()) { + thereIsMeterValueForRequest.push_back(connector); + } + } else { + for (int32_t c = 0; c <= this->configuration->getNumberOfConnectors(); c++) { + if (this->connectors.find(c) != this->connectors.end() && + this->connectors.at(c)->measurement.has_value()) { + thereIsMeterValueForRequest.push_back(c); + } + } + } + if (thereIsMeterValueForRequest.size() == 0) { + response.status = TriggerMessageStatus::Rejected; + valid = false; + } + } + ocpp::CallResult call_result(response, call.uniqueId); this->message_dispatcher->dispatch_call_result(call_result); @@ -2456,13 +2479,30 @@ void ChargePointImpl::handleTriggerMessageRequest(ocpp::Callheartbeat(true); break; case MessageTrigger::MeterValues: { - const auto meter_value = this->get_latest_meter_value( - connector, this->configuration->getMeterValuesSampledDataVector(), ReadingContext::Trigger); - if (meter_value.has_value()) { - this->send_meter_value(connector, meter_value.value(), true); - } else { - EVLOG_warning << "Could not send triggered meter value for uninitialized measurement at connector#" - << connector; + for (int32_t c = 0; c <= this->configuration->getNumberOfConnectors(); c++) { + bool doExecute = false; + bool doBreak = false; + if (call.msg.connectorId.has_value()) { + if (call.msg.connectorId.value() == c) { + doBreak = true; + doExecute = true; + } + } else { + doExecute = true; + doBreak = false; + } + if (doExecute) { + const auto meter_value = this->get_latest_meter_value( + c, this->configuration->getMeterValuesSampledDataVector(), ReadingContext::Trigger); + if (meter_value.has_value()) { + this->send_meter_value_trigger(c, meter_value.value(), true); + } else { + EVLOG_warning << "Could not send triggered meter value for uninitialized measurement at connector#" + << c; + } + } + if (doBreak) + break; } break; } From a6e3bff7522781b588002cbd899e87393b1dd681 Mon Sep 17 00:00:00 2001 From: Matthias Suess Date: Wed, 4 Dec 2024 11:55:57 +0100 Subject: [PATCH 2/4] correct call syntax of send_meter_value Signed-off-by: Matthias Suess --- lib/ocpp/v16/charge_point_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 3586c8056..6d781415b 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -2495,7 +2495,7 @@ void ChargePointImpl::handleTriggerMessageRequest(ocpp::Callget_latest_meter_value( c, this->configuration->getMeterValuesSampledDataVector(), ReadingContext::Trigger); if (meter_value.has_value()) { - this->send_meter_value_trigger(c, meter_value.value(), true); + this->send_meter_value(c, meter_value.value(), true); } else { EVLOG_warning << "Could not send triggered meter value for uninitialized measurement at connector#" << c; From 83e413926b4590f208a2993acd9380ea060fd931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piet=20G=C3=B6mpel?= Date: Mon, 23 Dec 2024 14:24:59 +0100 Subject: [PATCH 3/4] Refactored implementation of TriggerMessage.req handling for MeterValues if no connectorId is given MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piet Gömpel --- lib/ocpp/v16/charge_point_impl.cpp | 63 +++++++++++------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 6d781415b..6583a6a83 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -2429,39 +2429,28 @@ void ChargePointImpl::handleTriggerMessageRequest(ocpp::Call this->configuration->getNumberOfConnectors()) { response.status = TriggerMessageStatus::Rejected; - valid = false; + trigger_message = false; } - // We have to reject if there is no metervalue - if (MessageTrigger::MeterValues == call.msg.requestedMessage && valid) { - // the case if connectorId has value - std::vector thereIsMeterValueForRequest; + if (trigger_message and call.msg.requestedMessage == MessageTrigger::MeterValues) { if (call.msg.connectorId.has_value()) { - if (this->connectors.find(connector) != this->connectors.end() && - this->connectors.at(connector)->measurement.has_value()) { - thereIsMeterValueForRequest.push_back(connector); - } + trigger_message = this->connectors.at(call.msg.connectorId.value())->measurement.has_value(); } else { - for (int32_t c = 0; c <= this->configuration->getNumberOfConnectors(); c++) { - if (this->connectors.find(c) != this->connectors.end() && - this->connectors.at(c)->measurement.has_value()) { - thereIsMeterValueForRequest.push_back(c); - } - } + trigger_message = std::any_of(this->connectors.begin(), this->connectors.end(), + [](const auto& connector) { return connector.second->measurement.has_value(); }); } - if (thereIsMeterValueForRequest.size() == 0) { + if (not trigger_message) { response.status = TriggerMessageStatus::Rejected; - valid = false; } } ocpp::CallResult call_result(response, call.uniqueId); this->message_dispatcher->dispatch_call_result(call_result); - if (!valid) { + if (not trigger_message) { return; } @@ -2479,30 +2468,24 @@ void ChargePointImpl::handleTriggerMessageRequest(ocpp::Callheartbeat(true); break; case MessageTrigger::MeterValues: { - for (int32_t c = 0; c <= this->configuration->getNumberOfConnectors(); c++) { - bool doExecute = false; - bool doBreak = false; - if (call.msg.connectorId.has_value()) { - if (call.msg.connectorId.value() == c) { - doBreak = true; - doExecute = true; - } + const auto send_meter_value_func = [this](const int32_t connector_id) { + auto meter_value = this->get_latest_meter_value( + connector_id, this->configuration->getMeterValuesSampledDataVector(), ReadingContext::Trigger); + if (meter_value.has_value()) { + this->send_meter_value(connector_id, meter_value.value(), true); } else { - doExecute = true; - doBreak = false; + EVLOG_warning << "Could not send triggered meter value for uninitialized measurement at connector#" + << connector_id; } - if (doExecute) { - const auto meter_value = this->get_latest_meter_value( - c, this->configuration->getMeterValuesSampledDataVector(), ReadingContext::Trigger); - if (meter_value.has_value()) { - this->send_meter_value(c, meter_value.value(), true); - } else { - EVLOG_warning << "Could not send triggered meter value for uninitialized measurement at connector#" - << c; - } + }; + + if (!call.msg.connectorId.has_value()) { + // send a MeterValue.req for every connector + for (int32_t c = 0; c <= this->configuration->getNumberOfConnectors(); c++) { + send_meter_value_func(c); } - if (doBreak) - break; + } else { + send_meter_value_func(call.msg.connectorId.value()); } break; } From 8ce54d53cf62ef691d89e14318231b33fe848dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piet=20G=C3=B6mpel?= Date: Mon, 23 Dec 2024 14:32:42 +0100 Subject: [PATCH 4/4] clang format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Piet Gömpel --- lib/ocpp/v16/charge_point_impl.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 6583a6a83..d64b92000 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -2439,8 +2439,9 @@ void ChargePointImpl::handleTriggerMessageRequest(ocpp::Callconnectors.at(call.msg.connectorId.value())->measurement.has_value(); } else { - trigger_message = std::any_of(this->connectors.begin(), this->connectors.end(), - [](const auto& connector) { return connector.second->measurement.has_value(); }); + trigger_message = std::any_of(this->connectors.begin(), this->connectors.end(), [](const auto& connector) { + return connector.second->measurement.has_value(); + }); } if (not trigger_message) { response.status = TriggerMessageStatus::Rejected;