Skip to content

Commit

Permalink
Make centralSystemURI accessible via changeConfiguration, reject if r…
Browse files Browse the repository at this point in the history
…eadOnly (#900)

* Make centralSystemURI accessible via changeConfiguration, reject if readOnly

Signed-off-by: Matthias Suess <[email protected]>

* Added log message if CentralSystemURI is changed and responding with RebootRequired if changed

Signed-off-by: Piet Gömpel <[email protected]>

---------

Signed-off-by: Matthias Suess <[email protected]>
Signed-off-by: Piet Gömpel <[email protected]>
Co-authored-by: Piet Gömpel <[email protected]>
  • Loading branch information
Matthias-NIDEC and Pietfried authored Dec 19, 2024
1 parent 8d162ae commit 61a1c54
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/ocpp/v16/charge_point_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ChargePointConfiguration {
private:
json config;
json custom_schema;
json internal_schema;
fs::path user_config_path;

std::set<SupportedFeatureProfiles> supported_feature_profiles;
Expand Down Expand Up @@ -47,6 +48,7 @@ class ChargePointConfiguration {
std::string getChargePointId();
KeyValue getChargePointIdKeyValue();
std::string getCentralSystemURI();
void setCentralSystemURI(std::string ocpp_uri);
KeyValue getCentralSystemURIKeyValue();
std::string getChargeBoxSerialNumber();
KeyValue getChargeBoxSerialNumberKeyValue();
Expand Down
23 changes: 22 additions & 1 deletion lib/ocpp/v16/charge_point_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ ChargePointConfiguration::ChargePointConfiguration(const std::string& config, co
EVLOG_AND_THROW(e);
}

try {
const auto internal_schema_path = schemas_path / "Internal.json";
std::ifstream ifs(internal_schema_path.c_str());
std::string internal_schema_file((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
this->internal_schema = json::parse(internal_schema_file);
} catch (const json::parse_error& e) {
EVLOG_error << "Error while parsing Internal.json file.";
EVLOG_AND_THROW(e);
}

try {
auto patch = schemas.get_validator()->validate(this->config);
if (patch.is_null()) {
Expand Down Expand Up @@ -541,7 +551,7 @@ KeyValue ChargePointConfiguration::getChargePointIdKeyValue() {
KeyValue ChargePointConfiguration::getCentralSystemURIKeyValue() {
KeyValue kv;
kv.key = "CentralSystemURI";
kv.readonly = true;
kv.readonly = this->internal_schema["properties"][kv.key]["readOnly"];
kv.value.emplace(this->getCentralSystemURI());
return kv;
}
Expand Down Expand Up @@ -2966,6 +2976,12 @@ ConfigurationStatus ChargePointConfiguration::setCustomKey(CiString<50> key, CiS
return ConfigurationStatus::Accepted;
}

void ChargePointConfiguration::setCentralSystemURI(std::string centralSystemUri) {
EVLOG_warning << "CentralSystemURI changed to: " << centralSystemUri;
this->config["Internal"]["CentralSystemURI"] = centralSystemUri;
this->setInUserConfig("Internal", "CentralSystemURI", centralSystemUri);
}

std::optional<KeyValue> ChargePointConfiguration::get(CiString<50> key) {
std::lock_guard<std::recursive_mutex> lock(this->configuration_mutex);
// Internal Profile
Expand Down Expand Up @@ -3874,6 +3890,11 @@ ConfigurationStatus ChargePointConfiguration::set(CiString<50> key, CiString<500
this->setLanguage(value);
}

if (key == "CentralSystemURI") {
this->setCentralSystemURI(value.get());
return ConfigurationStatus::RebootRequired;
}

if (this->config.contains("Custom") and this->config["Custom"].contains(key.get())) {
return this->setCustomKey(key, value, false);
}
Expand Down

0 comments on commit 61a1c54

Please sign in to comment.