From 0f81986e4ee070156d91cb0858bb3dbbb346925e Mon Sep 17 00:00:00 2001 From: Soumya Subramanya Date: Tue, 17 Oct 2023 05:34:56 +0200 Subject: [PATCH] Add a get write only value function Signed-off-by: Soumya Subramanya --- include/ocpp/v201/device_model.hpp | 7 +++++++ include/ocpp/v201/enums.hpp | 6 ------ include/ocpp/v201/ocpp_types.hpp | 1 - lib/ocpp/v201/device_model.cpp | 11 +++++++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/ocpp/v201/device_model.hpp b/include/ocpp/v201/device_model.hpp index 59e3d222df..0568ad9e5b 100644 --- a/include/ocpp/v201/device_model.hpp +++ b/include/ocpp/v201/device_model.hpp @@ -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 diff --git a/include/ocpp/v201/enums.hpp b/include/ocpp/v201/enums.hpp index 7cc21e3475..6babfdcddc 100644 --- a/include/ocpp/v201/enums.hpp +++ b/include/ocpp/v201/enums.hpp @@ -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 diff --git a/include/ocpp/v201/ocpp_types.hpp b/include/ocpp/v201/ocpp_types.hpp index 15bcbb55f1..d5ce588343 100644 --- a/include/ocpp/v201/ocpp_types.hpp +++ b/include/ocpp/v201/ocpp_types.hpp @@ -360,7 +360,6 @@ struct GetVariableData { Variable variable; std::optional customData; std::optional attributeType; - std::optional mutabilityType; }; /// \brief Conversion from a given GetVariableData \p k to a given json object \p j void to_json(json& j, const GetVariableData& k); diff --git a/lib/ocpp/v201/device_model.cpp b/lib/ocpp/v201/device_model.cpp index 9e91ee3e00..91b3a97653 100644 --- a/lib/ocpp/v201/device_model.cpp +++ b/lib/ocpp/v201/device_model.cpp @@ -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 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)) {