Skip to content

Commit

Permalink
B07 get base report simplifications (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
SNSubramanya authored Jan 15, 2024
1 parent 5ee114c commit 8d7642d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 81 deletions.
19 changes: 3 additions & 16 deletions include/ocpp/v201/device_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,15 @@ 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<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);
bool component_criteria_match(const Component& component_id,
const std::vector<ComponentCriterionEnum>& component_criteria);

/// @brief Iterates over the given \p component_variables and filters them according to the requirement conditions.
/// @param component_variables
Expand Down Expand Up @@ -210,10 +200,7 @@ class DeviceModel {
/// \param component_variables
/// \param component_criteria
/// \return
std::vector<ReportData>
get_report_data(const std::optional<ReportBaseEnum>& report_base = std::nullopt,
const std::optional<std::vector<ComponentVariable>>& component_variables = std::nullopt,
const std::optional<std::vector<ComponentCriterionEnum>>& component_criteria = std::nullopt);
std::vector<ReportData> get_base_report_data(const ReportBaseEnum& report_base);

/// \brief Gets the ReportData for the specifed filter \p component_variables and \p
/// component_criteria
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,7 @@ void ChargePoint::handle_get_base_report_req(Call<GetBaseReportRequest> 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);
}
}
Expand Down
89 changes: 25 additions & 64 deletions lib/ocpp/v201/device_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,6 @@ 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 @@ -245,61 +221,46 @@ std::optional<VariableMetaData> DeviceModel::get_variable_meta_data(const Compon
}
}

std::vector<ReportData>
DeviceModel::get_report_data(const std::optional<ReportBaseEnum>& report_base,
const std::optional<std::vector<ComponentVariable>>& component_variables,
const std::optional<std::vector<ComponentCriterionEnum>>& component_criteria) {
std::vector<ReportData> DeviceModel::get_base_report_data(const ReportBaseEnum& report_base) {
std::vector<ReportData> 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;
}

std::vector<ReportData>
DeviceModel::get_custom_report_data(const std::optional<std::vector<ComponentVariable>>& component_variables,
const std::optional<std::vector<ComponentCriterionEnum>>& component_criteria) {
const std::optional<std::vector<ComponentCriterionEnum>>& component_criteria) {
std::vector<ReportData> 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
Expand Down

0 comments on commit 8d7642d

Please sign in to comment.