diff --git a/include/ocpp/v201/device_model.hpp b/include/ocpp/v201/device_model.hpp index 16009dd58..3e054969b 100644 --- a/include/ocpp/v201/device_model.hpp +++ b/include/ocpp/v201/device_model.hpp @@ -66,16 +66,6 @@ class DeviceModel { const AttributeEnum& attribute_enum, std::string& value, bool allow_write_only); - /// \brief Iterates over the given \p component_criteria and converts this to the variable names - /// (Active,Available,Enabled,Problem). If any of the variables can not be found as part of a component this - /// function returns false. If any of those variable's value is true, this function returns true. If all variable's - /// value are false, this function returns false - /// \param component_id - /// \param /// component_criteria - /// \return - bool component_criteria_match(const Component& component_id, - const std::vector& component_criteria); - /// \brief Iterates over the given \p component_criteria and converts this to the variable names /// (Active,Available,Enabled,Problem). If any of the variables can not be found as part of a component this /// function returns false. If any of those variable's value is true, this function returns true (except for @@ -83,8 +73,8 @@ class DeviceModel { /// \param component_id /// \param /// component_criteria /// \return - bool component_criteria_match_custom(const Component& component_id, - const std::vector& component_criteria); + bool component_criteria_match(const Component& component_id, + const std::vector& component_criteria); /// @brief Iterates over the given \p component_variables and filters them according to the requirement conditions. /// @param component_variables @@ -210,10 +200,7 @@ class DeviceModel { /// \param component_variables /// \param component_criteria /// \return - std::vector - get_report_data(const std::optional& report_base = std::nullopt, - const std::optional>& component_variables = std::nullopt, - const std::optional>& component_criteria = std::nullopt); + std::vector get_base_report_data(const ReportBaseEnum& report_base); /// \brief Gets the ReportData for the specifed filter \p component_variables and \p /// component_criteria diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index 5a5f3db5b..cf2c78400 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -2042,7 +2042,7 @@ void ChargePoint::handle_get_base_report_req(Call call) { if (response.status == GenericDeviceModelStatusEnum::Accepted) { // TODO(piet): Propably split this up into several NotifyReport.req depending on ItemsPerMessage / // BytesPerMessage - const auto report_data = this->device_model->get_report_data(msg.reportBase); + const auto report_data = this->device_model->get_base_report_data(msg.reportBase); this->notify_report_req(msg.requestId, report_data); } } diff --git a/lib/ocpp/v201/device_model.cpp b/lib/ocpp/v201/device_model.cpp index 51d12b579..1fd230c6d 100644 --- a/lib/ocpp/v201/device_model.cpp +++ b/lib/ocpp/v201/device_model.cpp @@ -12,30 +12,6 @@ namespace v201 { bool DeviceModel::component_criteria_match(const Component& component, const std::vector& component_criteria) { - if (component_criteria.empty()) { - return true; - } - for (const auto& criteria : component_criteria) { - const Variable variable = {conversions::component_criterion_enum_to_string(criteria)}; - // B08.FR.07 - // B08.FR.08 - // B08.FR.09 - // B08.FR.10 - if (!this->device_model.at(component).count(variable)) { - return true; - } else { - const auto response = this->request_value(component, variable, AttributeEnum::Actual); - auto value = response.value; - if (response.status == GetVariableStatusEnum::Accepted and value.has_value() and value.value()) { - return true; - } - } - } - return false; -} - -bool DeviceModel::component_criteria_match_custom(const Component& component, - const std::vector& component_criteria) { if (component_criteria.empty()) { return false; } @@ -245,49 +221,34 @@ std::optional DeviceModel::get_variable_meta_data(const Compon } } -std::vector -DeviceModel::get_report_data(const std::optional& report_base, - const std::optional>& component_variables, - const std::optional>& component_criteria) { +std::vector DeviceModel::get_base_report_data(const ReportBaseEnum& report_base) { std::vector report_data_vec; for (auto const& [component, variable_map] : this->device_model) { - // check if this component should be reported based on the component criteria - if (!component_criteria.has_value() or component_criteria_match(component, component_criteria.value())) { - for (auto const& [variable, variable_meta_data] : variable_map) { - // check if this variable should be reported based on the given component_variables - auto variable_ = variable; - auto component_ = component; - if (!component_variables.has_value() or - std::find_if(component_variables.value().begin(), component_variables.value().end(), - [variable_, component_](ComponentVariable v) { - return component_ == v.component and v.variable.has_value() and - variable_ == v.variable.value(); - }) != component_variables.value().end()) { - ReportData report_data; - report_data.component = component; - report_data.variable = 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 and ConfigurationInventory (ReadWrite - // or WriteOnly) correctly - // TODO(piet): SummaryInventory - if (report_base == ReportBaseEnum::FullInventory or - variable_attribute.mutability == MutabilityEnum::ReadWrite or - variable_attribute.mutability == MutabilityEnum::WriteOnly) { - report_data.variableAttribute.push_back(variable_attribute); - report_data.variableCharacteristics = variable_map.at(variable).characteristics; - } - } - if (!report_data.variableAttribute.empty()) { - report_data_vec.push_back(report_data); - } + for (auto const& [variable, variable_meta_data] : variable_map) { + + ReportData report_data; + report_data.component = component; + report_data.variable = 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 and ConfigurationInventory (ReadWrite + // or WriteOnly) correctly + // TODO(piet): SummaryInventory + if (report_base == ReportBaseEnum::FullInventory or + variable_attribute.mutability == MutabilityEnum::ReadWrite or + variable_attribute.mutability == MutabilityEnum::WriteOnly) { + report_data.variableAttribute.push_back(variable_attribute); + report_data.variableCharacteristics = variable_map.at(variable).characteristics; } } + if (!report_data.variableAttribute.empty()) { + report_data_vec.push_back(report_data); + } } } return report_data_vec; @@ -295,11 +256,11 @@ DeviceModel::get_report_data(const std::optional& report_base, std::vector DeviceModel::get_custom_report_data(const std::optional>& component_variables, - const std::optional>& component_criteria) { + const std::optional>& component_criteria) { std::vector report_data_vec; for (auto const& [component, variable_map] : this->device_model) { - if (!component_criteria.has_value() or component_criteria_match_custom(component, component_criteria.value())) { + if (!component_criteria.has_value() or component_criteria_match(component, component_criteria.value())) { for (auto const& [variable, variable_meta_data] : variable_map) { if (!component_variables.has_value() or