From d51e1914ea8cacc533c89931f5e589432ffe9d3b Mon Sep 17 00:00:00 2001 From: Matthias Suess Date: Wed, 4 Dec 2024 11:45:28 +0100 Subject: [PATCH 1/2] 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 3f1399590..e98080c6a 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -2423,6 +2423,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); @@ -2444,13 +2467,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 6494a4073919899aae58d2c4544688676b8c9040 Mon Sep 17 00:00:00 2001 From: Matthias Suess Date: Wed, 4 Dec 2024 11:55:57 +0100 Subject: [PATCH 2/2] 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 e98080c6a..674977003 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -2483,7 +2483,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;