From ebe4fd514a60612c5a30a5213abd6f40d73ac3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piet=20G=C3=B6mpel?= <37657534+Pietfried@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:44:12 +0200 Subject: [PATCH] added support for SummaryInventory in OCPP201 (#716) Signed-off-by: pietfried --- .../ocpp/v201/ctrlr_component_variables.hpp | 9 +++++-- lib/ocpp/v201/charge_point.cpp | 4 --- lib/ocpp/v201/ctrlr_component_variables.cpp | 7 +++++ lib/ocpp/v201/device_model.cpp | 27 ++++++++++++++++--- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/ocpp/v201/ctrlr_component_variables.hpp b/include/ocpp/v201/ctrlr_component_variables.hpp index 39f757319..24a95027d 100644 --- a/include/ocpp/v201/ctrlr_component_variables.hpp +++ b/include/ocpp/v201/ctrlr_component_variables.hpp @@ -16,11 +16,9 @@ extern const Component& AuthCacheCtrlr; extern const Component& AuthCtrlr; extern const Component& ChargingStation; extern const Component& ClockCtrlr; -extern const Component& Connector; extern const Component& CustomizationCtrlr; extern const Component& DeviceDataCtrlr; extern const Component& DisplayMessageCtrlr; -extern const Component& EVSE; extern const Component& ISO15118Ctrlr; extern const Component& LocalAuthListCtrlr; extern const Component& MonitoringCtrlr; @@ -33,6 +31,13 @@ extern const Component& TariffCostCtrlr; extern const Component& TxCtrlr; } // namespace ControllerComponents +namespace StandardizedVariables { +extern const Variable& Problem; +extern const Variable& Tripped; +extern const Variable& Overload; +extern const Variable& Fallback; +}; // namespace StandardizedVariables + // Provides access to standardized variables of OCPP2.0.1 spec namespace ControllerComponentVariables { extern const ComponentVariable& InternalCtrlrEnabled; diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index c0bda44af..40df73db1 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -2404,10 +2404,6 @@ void ChargePoint::handle_get_base_report_req(Call call) { GetBaseReportResponse response; response.status = GenericDeviceModelStatusEnum::Accepted; - if (msg.reportBase == ReportBaseEnum::SummaryInventory) { - response.status = GenericDeviceModelStatusEnum::NotSupported; - } - ocpp::CallResult call_result(response, call.uniqueId); this->send(call_result); diff --git a/lib/ocpp/v201/ctrlr_component_variables.cpp b/lib/ocpp/v201/ctrlr_component_variables.cpp index 577e1465c..9070ec80f 100644 --- a/lib/ocpp/v201/ctrlr_component_variables.cpp +++ b/lib/ocpp/v201/ctrlr_component_variables.cpp @@ -28,6 +28,13 @@ const Component& TariffCostCtrlr = {"TariffCostCtrlr"}; const Component& TxCtrlr = {"TxCtrlr"}; } // namespace ControllerComponents +namespace StandardizedVariables { +const Variable& Problem = {"Problem"}; +const Variable& Tripped = {"Tripped"}; +const Variable& Overload = {"Overload"}; +const Variable& Fallback = {"Fallback"}; +}; // namespace StandardizedVariables + namespace ControllerComponentVariables { const ComponentVariable& InternalCtrlrEnabled = { diff --git a/lib/ocpp/v201/device_model.cpp b/lib/ocpp/v201/device_model.cpp index 3fec38bd9..86d43b527 100644 --- a/lib/ocpp/v201/device_model.cpp +++ b/lib/ocpp/v201/device_model.cpp @@ -198,6 +198,24 @@ bool validate_value(const VariableCharacteristics& characteristics, const std::s } } +bool include_in_summary_inventory(const ComponentVariable& cv, const VariableAttribute& attribute) { + if (cv == ControllerComponentVariables::ChargingStationAvailabilityState) { + return true; + } + if (cv.component.name == "EVSE" and cv.variable == EvseComponentVariables::AvailabilityState) { + return true; + } + if (cv.component.name == "Connector" and cv.variable == ConnectorComponentVariables::AvailabilityState) { + return true; + } + if ((cv.variable == StandardizedVariables::Fallback or cv.variable == StandardizedVariables::Overload or + cv.variable == StandardizedVariables::Problem or cv.variable == StandardizedVariables::Tripped) and + attribute.value.value_or("") == "true") { + return true; + } + return false; +} + GetVariableStatusEnum DeviceModel::request_value_internal(const Component& component_id, const Variable& variable_id, const AttributeEnum& attribute_enum, std::string& value, bool allow_write_only) { @@ -327,14 +345,13 @@ std::vector DeviceModel::get_base_report_data(const ReportBaseEnum& report_data.component = component; report_data.variable = variable; + ComponentVariable cv = {component, std::nullopt, variable}; + // request the variable attribute from the device model storage const auto variable_attributes = this->storage->get_variable_attributes(component, variable); // iterate over possibly (Actual, Target, MinSet, MaxSet) for (const auto& variable_attribute : variable_attributes) { - // FIXME(piet): Right now this reports only FullInventory (ReadOnly, - // ReadWrite or WriteOnly) and ConfigurationInventory (ReadWrite or WriteOnly) correctly - // TODO(piet): SummaryInventory if (report_base == ReportBaseEnum::FullInventory or (report_base == ReportBaseEnum::ConfigurationInventory and (variable_attribute.mutability == MutabilityEnum::ReadWrite or @@ -345,6 +362,10 @@ std::vector DeviceModel::get_base_report_data(const ReportBaseEnum& report_data.variableAttribute.back().value.reset(); } report_data.variableCharacteristics = variable_map.at(variable).characteristics; + } else if (report_base == ReportBaseEnum::SummaryInventory) { + if (include_in_summary_inventory(cv, variable_attribute)) { + report_data.variableAttribute.push_back(variable_attribute); + } } } if (!report_data.variableAttribute.empty()) {