Skip to content

Commit

Permalink
make a separate component_criteria_match for custom reports
Browse files Browse the repository at this point in the history
Signed-off-by: Soumya Subramanya <[email protected]>
  • Loading branch information
SNSubramanya committed Jan 8, 2024
1 parent 3291645 commit 51aca06
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 10 additions & 0 deletions include/ocpp/v201/device_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ class DeviceModel {
bool component_criteria_match(const Component& component_id,
const std::vector<ComponentCriterionEnum>& 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 criteria problem). If all variable's
/// value are false, this function returns false
/// \param component_id
/// \param /// component_criteria
/// \return
bool component_criteria_match_custom(const Component& component_id,
const std::vector<ComponentCriterionEnum>& component_criteria);

/// \brief Sets the variable_id attribute \p value specified by \p component_id , \p variable_id and \p
/// attribute_enum \param component_id \param variable_id \param attribute_enum \param value
/// \param force_read_only If this is true, only read-only variables can be changed,
Expand Down
26 changes: 25 additions & 1 deletion lib/ocpp/v201/device_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@ namespace v201 {

bool DeviceModel::component_criteria_match(const Component& component,
const std::vector<ComponentCriterionEnum>& 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<bool>(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<ComponentCriterionEnum>& component_criteria) {
if (component_criteria.empty()) {
return false;
}
Expand Down Expand Up @@ -260,7 +284,7 @@ DeviceModel::get_custom_report_data(const std::optional<std::vector<ComponentVar
std::vector<ReportData> report_data_vec;

for (auto const& [component, variable_map] : this->device_model) {
if (!component_criteria.has_value() or component_criteria_match(component, component_criteria.value())) {
if (!component_criteria.has_value() or component_criteria_match_custom(component, component_criteria.value())) {

// for (const auto& criteria : component_criteria.value()) {
for (auto const& [variable, variable_meta_data] : variable_map) {
Expand Down

0 comments on commit 51aca06

Please sign in to comment.