From 2e9f9b491a03b262b62c9e674c395462186113d5 Mon Sep 17 00:00:00 2001 From: pietfried Date: Fri, 5 Jan 2024 16:53:29 +0100 Subject: [PATCH] made CentralSystemURI of OCPP1.6 writable by CSMS. Change to this configuration key is applied only after reboot Signed-off-by: pietfried --- config/v16/profile_schemas/Internal.json | 2 +- include/ocpp/v16/charge_point_configuration.hpp | 1 + lib/ocpp/v16/charge_point_configuration.cpp | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config/v16/profile_schemas/Internal.json b/config/v16/profile_schemas/Internal.json index d431ecaf1..868c38269 100644 --- a/config/v16/profile_schemas/Internal.json +++ b/config/v16/profile_schemas/Internal.json @@ -18,7 +18,7 @@ }, "CentralSystemURI": { "type": "string", - "readOnly": true, + "readOnly": false, "minLength": 1 }, "ChargeBoxSerialNumber": { diff --git a/include/ocpp/v16/charge_point_configuration.hpp b/include/ocpp/v16/charge_point_configuration.hpp index d0bad8058..7acc6c6d3 100644 --- a/include/ocpp/v16/charge_point_configuration.hpp +++ b/include/ocpp/v16/charge_point_configuration.hpp @@ -42,6 +42,7 @@ class ChargePointConfiguration { std::string getChargePointId(); KeyValue getChargePointIdKeyValue(); std::string getCentralSystemURI(); + void setCentralSystemURI(std::string central_system_uri); KeyValue getCentralSystemURIKeyValue(); std::string getChargeBoxSerialNumber(); KeyValue getChargeBoxSerialNumberKeyValue(); diff --git a/lib/ocpp/v16/charge_point_configuration.cpp b/lib/ocpp/v16/charge_point_configuration.cpp index a4f57b272..962355ea7 100644 --- a/lib/ocpp/v16/charge_point_configuration.cpp +++ b/lib/ocpp/v16/charge_point_configuration.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -214,6 +215,9 @@ std::string ChargePointConfiguration::getChargePointId() { std::string ChargePointConfiguration::getCentralSystemURI() { return this->config["Internal"]["CentralSystemURI"]; } +void ChargePointConfiguration::setCentralSystemURI(std::string central_system_uri) { + this->setInUserConfig("Internal", "CentralSystemURI", central_system_uri); +} std::string ChargePointConfiguration::getChargeBoxSerialNumber() { return this->config["Internal"]["ChargeBoxSerialNumber"]; } @@ -324,7 +328,7 @@ KeyValue ChargePointConfiguration::getChargePointIdKeyValue() { KeyValue ChargePointConfiguration::getCentralSystemURIKeyValue() { KeyValue kv; kv.key = "CentralSystemURI"; - kv.readonly = true; + kv.readonly = false; kv.value.emplace(this->getCentralSystemURI()); return kv; } @@ -2401,6 +2405,16 @@ std::vector ChargePointConfiguration::get_all_key_value() { } ConfigurationStatus ChargePointConfiguration::set(CiString<50> key, CiString<500> value) { + if (key == "CentralSystemURI") { + try { + Uri::parse_and_validate(value.get(), this->getChargePointId(), this->getSecurityProfile()); + } catch (const std::invalid_argument& e) { + // given CentralSystemURI is not valid + return ConfigurationStatus::Rejected; + } + this->setCentralSystemURI(value.get()); + return ConfigurationStatus::RebootRequired; + } if (key == "AllowOfflineTxForUnknownId") { if (this->getAllowOfflineTxForUnknownId() == std::nullopt) { return ConfigurationStatus::NotSupported;