Skip to content

Commit

Permalink
Add a get write only value function
Browse files Browse the repository at this point in the history
Signed-off-by: Soumya Subramanya <[email protected]>
  • Loading branch information
SNSubramanya committed Oct 17, 2023
1 parent e212ae5 commit 0f81986
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions include/ocpp/v201/device_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ class DeviceModel {
/// \return Result of the requested operation
SetVariableStatusEnum set_read_only_value(const Component& component_id, const Variable& variable_id,
const AttributeEnum& attribute_enum, const std::string& value);

/// @brief Gets the value of write only components
/// @param component_id
/// @param variable_id
/// @param attribute_enum
/// @return Result of the requested operation
GetVariableStatusEnum get_write_only_value(const Component& component_id, const Variable& variable_id, const AttributeEnum& attribute_enum);

/// \brief Gets the VariableMetaData for the given \p component_id and \p variable_id
/// \param component_id
Expand Down
6 changes: 0 additions & 6 deletions include/ocpp/v201/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,12 +871,6 @@ enum class AttributeEnum {
MaxSet,
};

enum class MutabilityEnum {
ReadOnly,
WriteOnly,
ReadWrite
};

namespace conversions {
/// \brief Converts the given AttributeEnum \p e to human readable string
/// \returns a string representation of the AttributeEnum
Expand Down
1 change: 0 additions & 1 deletion include/ocpp/v201/ocpp_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ struct GetVariableData {
Variable variable;
std::optional<CustomData> customData;
std::optional<AttributeEnum> attributeType;
std::optional<MutabilityEnum> mutabilityType;
};
/// \brief Conversion from a given GetVariableData \p k to a given json object \p j
void to_json(json& j, const GetVariableData& k);
Expand Down
11 changes: 11 additions & 0 deletions lib/ocpp/v201/device_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ SetVariableStatusEnum DeviceModel::set_read_only_value(const Component& componen
throw std::invalid_argument("Not allowed to set read only value for component " + component.name.get());
}

GetVariableStatusEnum DeviceModel::get_write_only_value(const Component& component_id, const Variable& variable_id, const AttributeEnum& attribute_enum) {

const auto attribute_opt = this->storage->get_variable_attribute(component_id, variable_id, attribute_enum);
if (attribute_opt.value().mutability.has_value() &&
attribute_opt.value().mutability.value() == MutabilityEnum::WriteOnly) {
// if WriteOnly then return rejected
EVLOG_info << "====> WriteONLY ====== ";
return GetVariableStatusEnum::Rejected;
}
}

std::optional<VariableMetaData> DeviceModel::get_variable_meta_data(const Component& component,
const Variable& variable) {
if (this->device_model.count(component) and this->device_model.at(component).count(variable)) {
Expand Down

0 comments on commit 0f81986

Please sign in to comment.