diff --git a/modules/OCPPConfiguration/CMakeLists.txt b/modules/OCPPConfiguration/CMakeLists.txt index 02f6a51a20..1780caca88 100644 --- a/modules/OCPPConfiguration/CMakeLists.txt +++ b/modules/OCPPConfiguration/CMakeLists.txt @@ -21,6 +21,7 @@ target_sources(${MODULE_NAME} "main/mapping_reader.cpp" "main/util.cpp" "main/event_handler.cpp" + "main/everest_config_mapping.cpp" ) # ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 diff --git a/modules/OCPPConfiguration/OCPPConfiguration.cpp b/modules/OCPPConfiguration/OCPPConfiguration.cpp index 46be34cabd..0abbacf78c 100644 --- a/modules/OCPPConfiguration/OCPPConfiguration.cpp +++ b/modules/OCPPConfiguration/OCPPConfiguration.cpp @@ -13,6 +13,9 @@ void OCPPConfiguration::init() { void OCPPConfiguration::ready() { invoke_ready(*p_main); + auto wait_attached = false; + while (wait_attached) { + }; const auto mapping_file_path = std::filesystem::path{config.mapping_file_path}; event_handler = std::make_unique(mapping_file_path); diff --git a/modules/OCPPConfiguration/config-mapping.yaml b/modules/OCPPConfiguration/config-mapping.yaml index 2f4fc2f5b0..96f86082cc 100644 --- a/modules/OCPPConfiguration/config-mapping.yaml +++ b/modules/OCPPConfiguration/config-mapping.yaml @@ -1,75 +1,337 @@ AllowOfflineTxForUnknownId: - module_id: allow_offline_tx_for_unknown_id - config_key: allow_offline_tx_for_unknown_id_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: allow_offline_tx_for_unknown_id + config_key: allow_offline_tx_for_unknown_id_config + - mapping: + component: + name: ocpp + instance: 2 + evse: + id: 2 + connector_id: 2 + variable: + instance: 2 + maps_to: + module_id: allow_offline_tx_for_unknown_id + config_key: allow_offline_tx_for_unknown_id_config AuthorizationCacheEnabled: - module_id: authorization_cache_enabled - config_key: authorization_cache_enabled_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: authorization_cache_enabled + config_key: authorization_cache_enabled_config AuthorizeRemoteTxRequests: - module_id: authorize_remote_tx_requests - config_key: authorize_remote_tx_requests_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: authorize_remote_tx_requests + config_key: authorize_remote_tx_requests_config BlinkRepeat: - module_id: blink_repeat - config_key: blink_repeat_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: blink_repeat + config_key: blink_repeat_config ClockAlignedDataInterval: - module_id: clock_aligned_data_interval - config_key: clock_aligned_data_interval_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: clock_aligned_data_interval + config_key: clock_aligned_data_interval_config ConnectionTimeOut: - module_id: connection_time_out - config_key: connection_time_out_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: connection_time_out + config_key: connection_time_out_config ConnectorPhaseRotation: - module_id: connector_phase_rotation - config_key: connector_phase_rotation_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: connector_phase_rotation + config_key: connector_phase_rotation_config HeartbeatInterval: - module_id: heartbeat_interval - config_key: heartbeat_interval_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: heartbeat_interval + config_key: heartbeat_interval_config LightIntensity: - module_id: light_intensity - config_key: light_intensity_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: light_intensity + config_key: light_intensity_config LocalAuthorizeOffline: - module_id: local_authorize_offline - config_key: local_authorize_offline_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: local_authorize_offline + config_key: local_authorize_offline_config LocalPreAuthorize: - module_id: local_pre_authorize - config_key: local_pre_authorize_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: local_pre_authorize + config_key: local_pre_authorize_config MaxEnergyOnInvalidId: - module_id: max_energy_on_invalid_id - config_key: max_energy_on_invalid_id_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: max_energy_on_invalid_id + config_key: max_energy_on_invalid_id_config MeterValuesAlignedData: - module_id: meter_values_aligned_data - config_key: meter_values_aligned_data_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: meter_values_aligned_data + config_key: meter_values_aligned_data_config MeterValuesSampledData: - module_id: meter_values_sampled_data - config_key: meter_values_sampled_data_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: meter_values_sampled_data + config_key: meter_values_sampled_data_config MeterValueSampleInterval: - module_id: meter_value_sample_interval - config_key: meter_value_sample_interval_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: meter_value_sample_interval + config_key: meter_value_sample_interval_config MinimumStatusDuration: - module_id: minimum_status_duration - config_key: minimum_status_duration_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: minimum_status_duration + config_key: minimum_status_duration_config ResetRetries: - module_id: reset_retries - config_key: reset_retries_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: reset_retries + config_key: reset_retries_config StopTransactionOnEVSideDisconnect: - module_id: stop_transaction_on_ev_side_disconnect - config_key: stop_transaction_on_ev_side_disconnect_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: stop_transaction_on_ev_side_disconnect + config_key: stop_transaction_on_ev_side_disconnect_config StopTransactionOnInvalidId: - module_id: stop_transaction_on_invalid_id - config_key: stop_transaction_on_invalid_id_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: stop_transaction_on_invalid_id + config_key: stop_transaction_on_invalid_id_config StopTxnAlignedData: - module_id: stop_txn_aligned_data - config_key: stop_txn_aligned_data_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: stop_txn_aligned_data + config_key: stop_txn_aligned_data_config StopTxnSampledData: - module_id: stop_txn_sampled_data - config_key: stop_txn_sampled_data_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: stop_txn_sampled_data + config_key: stop_txn_sampled_data_config TransactionMessageAttempts: - module_id: transaction_message_attempts - config_key: transaction_message_attempts_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: transaction_message_attempts + config_key: transaction_message_attempts_config TransactionMessageRetryInterval: - module_id: transaction_message_retry_interval - config_key: transaction_message_retry_interval_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: transaction_message_retry_interval + config_key: transaction_message_retry_interval_config UnlockConnectorOnEVSideDisconnect: - module_id: unlock_connector_on_ev_side_disconnect - config_key: unlock_connector_on_ev_side_disconnect_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: unlock_connector_on_ev_side_disconnect + config_key: unlock_connector_on_ev_side_disconnect_config WebsocketPingInterval: - module_id: websocket_ping_interval - config_key: websocket_ping_interval_config + - mapping: + component: + name: ocpp + instance: 1 + evse: + id: 1 + connector: 1 + variable: + instance: 1 + maps_to: + module_id: websocket_ping_interval + config_key: websocket_ping_interval_config diff --git a/modules/OCPPConfiguration/main/event_handler.cpp b/modules/OCPPConfiguration/main/event_handler.cpp index a532691e6d..4889f80351 100644 --- a/modules/OCPPConfiguration/main/event_handler.cpp +++ b/modules/OCPPConfiguration/main/event_handler.cpp @@ -8,36 +8,34 @@ namespace module { EventHandler::EventHandler(const std::filesystem::path& config_mapping_path) : - event_map(MappingReader::readMapping(config_mapping_path)) { + config_mapping(MappingReader::read_mapping(config_mapping_path)) { } void EventHandler::handleEvent(const types::ocpp::EventData& event_data, const std::string& user_config_path_string) { - // todo(tm): needs a way to handle ocpp 2.0.1 component variable combinations - // maybe add this to the mapping file - const auto& event_name = event_data.component_variable.variable.name; - const auto& component = event_data.component_variable.component; - - const auto& everest_module_mapping_opt = find_event_in_map_or_log_error(event_name); + const auto& everest_module_mapping_opt = + find_mapping_by_component_variable_or_log_error(event_data.component_variable); if (!everest_module_mapping_opt.has_value()) { return; } const auto& everest_module_mapping = everest_module_mapping_opt.value(); - write_event_to_config(event_data, user_config_path_string, everest_module_mapping, component); + write_event_to_config(event_data, user_config_path_string, everest_module_mapping); } -void EventHandler::write_event_to_config(const types::ocpp::EventData& event_data, const std::string& user_config_path_string, const EverestModuleMapping& everest_module_mapping, const types::ocpp::Component& component) { +void EventHandler::write_event_to_config(const types::ocpp::EventData& event_data, + const std::string& user_config_path_string, + const EverestConfigMapping& everest_module_mapping) { const auto user_config_path = std::filesystem::path{user_config_path_string}; auto tree = Util::load_existing_user_config(user_config_path); - Util::write_value_to_tree(everest_module_mapping, event_data.actual_value, component, tree); + Util::write_value_to_tree(everest_module_mapping, event_data.actual_value, tree); Util::save_tree_to_yaml_file(tree, user_config_path); } -const std::optional -EventHandler::find_event_in_map_or_log_error(const std::string& event_name) const { +const std::optional EventHandler::find_mapping_by_component_variable_or_log_error( + const types::ocpp::ComponentVariable& component_variable) const { try { - const auto& everest_module_mapping = find_event_in_map(event_name); + const auto& everest_module_mapping = find_mapping_by_component_variable(component_variable); return everest_module_mapping; } catch (const std::runtime_error& e) { EVLOG_error << e.what(); @@ -45,15 +43,18 @@ EventHandler::find_event_in_map_or_log_error(const std::string& event_name) cons } } -const EverestModuleMapping EventHandler::find_event_in_map(const std::string& event_name) const { - const auto& event = event_map.find(event_name); +const EverestConfigMapping +EventHandler::find_mapping_by_component_variable(const types::ocpp::ComponentVariable& component_variable) const { + const auto& mapping = config_mapping.find(component_variable); // check if event is in event_map - if (event == event_map.end()) { - throw std::runtime_error("Event not found in event map: " + std::string(event_name)); + if (mapping == config_mapping.end()) { + throw std::runtime_error("Component Variable not found in config mapping:\n Component:\t" + + std::string(component_variable.component.name) + "\n Variable:\t" + + std::string(component_variable.variable.name)); } - return event->second; + return mapping->second; } } // namespace module diff --git a/modules/OCPPConfiguration/main/event_handler.hpp b/modules/OCPPConfiguration/main/event_handler.hpp index 149af0481a..1372535edd 100644 --- a/modules/OCPPConfiguration/main/event_handler.hpp +++ b/modules/OCPPConfiguration/main/event_handler.hpp @@ -14,13 +14,14 @@ class EventHandler { void handleEvent(const types::ocpp::EventData& event_data, const std::string& user_config_path_string); private: - const std::optional find_event_in_map_or_log_error(const std::string& event_name) const; - const EverestModuleMapping find_event_in_map(const std::string& event_name) const; + const std::optional + find_mapping_by_component_variable_or_log_error(const types::ocpp::ComponentVariable& component_variable) const; + const EverestConfigMapping + find_mapping_by_component_variable(const types::ocpp::ComponentVariable& component_variable) const; - OcppToEverestModuleMapping event_map; + OcppToEverestConfigMapping config_mapping; void write_event_to_config(const types::ocpp::EventData& event_data, const std::string& user_config_path_string, - const EverestModuleMapping& everest_module_mapping, - const types::ocpp::Component& component); + const EverestConfigMapping& everest_module_mapping); }; } // namespace module diff --git a/modules/OCPPConfiguration/main/everest_config_mapping.cpp b/modules/OCPPConfiguration/main/everest_config_mapping.cpp new file mode 100644 index 0000000000..e48dce5427 --- /dev/null +++ b/modules/OCPPConfiguration/main/everest_config_mapping.cpp @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest + +#include "everest_config_mapping.hpp" + +namespace types::ocpp { + +bool operator==(const EVSE& lhs, const EVSE& rhs) { + return lhs.id == rhs.id && lhs.connector_id == rhs.connector_id; +} + +bool operator==(const Component& lhs, const Component& rhs) { + return lhs.name == rhs.name && lhs.instance == rhs.instance && lhs.evse == rhs.evse; +} + +bool operator==(const Variable& lhs, const Variable& rhs) { + return lhs.name == rhs.name && lhs.instance == rhs.instance; +} + +bool operator==(const ComponentVariable& lhs, const ComponentVariable& rhs) { + return lhs.component == rhs.component && lhs.variable == rhs.variable; +} + +} // namespace types::ocpp diff --git a/modules/OCPPConfiguration/main/everest_config_mapping.hpp b/modules/OCPPConfiguration/main/everest_config_mapping.hpp new file mode 100644 index 0000000000..8a2449a589 --- /dev/null +++ b/modules/OCPPConfiguration/main/everest_config_mapping.hpp @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "generated/types/ocpp.hpp" +#include + +// Required to use for std::unordered_map with types::ocpp::ComponentVariable as key +namespace types::ocpp { +bool operator==(const EVSE& lhs, const EVSE& rhs); +bool operator==(const Component& lhs, const Component& rhs); +bool operator==(const Variable& lhs, const Variable& rhs); +bool operator==(const ComponentVariable& lhs, const ComponentVariable& rhs); + +} // namespace types::ocpp + +template <> struct std::hash { + std::size_t operator()(const types::ocpp::EVSE& evse) const noexcept { + return std::hash{}(evse.id) ^ (std::hash>{}(evse.connector_id) << 1); + } +}; + +template <> struct std::hash { + std::size_t operator()(const types::ocpp::Component& component) const noexcept { + return std::hash{}(component.name) ^ + (std::hash>{}(component.instance) << 1 ^ + (std::hash>{}(component.evse) << 2)); + } +}; + +template <> struct std::hash { + std::size_t operator()(const types::ocpp::Variable& variable) const noexcept { + return std::hash{}(variable.name) ^ + (std::hash>{}(variable.instance) << 1); + } +}; + +template <> struct std::hash { + std::size_t operator()(const types::ocpp::ComponentVariable& component_variable) const noexcept { + return std::hash{}(component_variable.component) ^ + (std::hash{}(component_variable.variable) << 1); + } +}; + +namespace module { + +struct EverestConfigMapping { + std::string module_id; + std::string config_key; +}; + +} // namespace module diff --git a/modules/OCPPConfiguration/main/mapping_reader.cpp b/modules/OCPPConfiguration/main/mapping_reader.cpp index 41ebe43e43..4c692c5667 100644 --- a/modules/OCPPConfiguration/main/mapping_reader.cpp +++ b/modules/OCPPConfiguration/main/mapping_reader.cpp @@ -8,7 +8,79 @@ #include namespace module { -EverestModuleMapping MappingReader::parseMappingNode(const ryml::NodeRef& node) { +OcppToEverestConfigMapping MappingReader::read_mapping(const std::filesystem::path& file_path) { + const auto hacked_file_path = + std::filesystem::path{"modules"} / "OCPPConfiguration" / file_path; // TODO: this is very hacky + const auto tree = Util::load_existing_user_config(hacked_file_path); + + const auto root = tree.rootref(); + + auto mapping = OcppToEverestConfigMapping{}; + + for (const auto& variables_sequence_node : root.children()) { + const auto key = variables_sequence_node.key(); + const auto variable_name = std::string{key.str, key.len}; + + for (const auto& mappings_sequence_node : variables_sequence_node.children()) { + + for (auto const& mapping_node : mappings_sequence_node.children()) { + auto component_variable = parse_component_variable_node(variable_name, mapping_node); + + auto module_mapping = parse_mapping_node(mapping_node["maps_to"]); + + mapping.insert({std::move(component_variable), std::move(module_mapping)}); + } + } + } + + return mapping; +} + +ComponentVariable MappingReader::parse_component_variable_node(std::string variable_name, const c4::yml::NodeRef& node) { + auto component = node.has_child("component") ? parse_component_node(node["component"]) : Component{}; + auto variable = node.has_child("variable") ? parse_variable_node(variable_name, node["variable"]) + : Variable{.name = variable_name}; + return {std::move(component), std::move(variable)}; +} + +Component MappingReader::parse_component_node(const c4::yml::NodeRef& node) { + auto evse = node.has_child("evse") ? parse_evse_node(node["evse"]) : std::nullopt; + + auto instance_optinal_val = node.has_child("instance") ? std::optional{node["instance"].val()} : std::nullopt; + auto instance = instance_optinal_val.has_value() + ? std::optional{std::string{instance_optinal_val.value().str, instance_optinal_val.value().len}} + : std::nullopt; + + auto component_name = node.has_child("name") ? std::string{node["name"].val().str, node["name"].val().len} : ""; + return {std::move(component_name), std::move(instance), std::move(evse)}; +} + +Variable MappingReader::parse_variable_node(std::string variable_name, const c4::yml::NodeRef node) { + auto instance_optional_val = node.has_child("instance") ? std::optional{node["instance"].val()} : std::nullopt; + auto instance = + instance_optional_val.has_value() + ? std::optional{std::string{instance_optional_val.value().str, instance_optional_val.value().len}} + : std::nullopt; + return {std::move(variable_name), std::move(instance)}; +} + +std::optional MappingReader::parse_evse_node(const c4::yml::NodeRef node) { + if (!node.has_child("id")) { + throw std::runtime_error("EVSE node must have an id"); + } + auto id_val = node["id"].val(); + auto id = std::stoi(std::string{id_val.str, id_val.len}); + + auto connector_id_optional_val = node.has_child("id") ? std::optional{node["id"].val()} : std::nullopt; + auto connector_id = connector_id_optional_val.has_value() + ? std::optional{std::stoi(std::string{connector_id_optional_val.value().str, + connector_id_optional_val.value().len})} + : std::nullopt; + + return types::ocpp::EVSE{std::move(id), std::move(connector_id)}; +} + +EverestConfigMapping MappingReader::parse_mapping_node(const ryml::NodeRef& node) { const auto parse_node = [](const auto& node) { const auto val = node.val(); @@ -24,24 +96,4 @@ EverestModuleMapping MappingReader::parseMappingNode(const ryml::NodeRef& node) return {module_id, config_key}; } -OcppToEverestModuleMapping MappingReader::readMapping(const std::filesystem::path& file_path) { - const auto hacked_file_path = - std::filesystem::path{"modules"} / "OCPPConfiguration" / file_path; // TODO: this is very hacky - const auto tree = Util::load_existing_user_config(hacked_file_path); - - const auto root = tree.rootref(); - - auto mapping = OcppToEverestModuleMapping{}; - - for (const auto& child : root.children()) { - const auto key = child.key(); - auto message_type = std::string{key.str, key.len}; - auto module_mapping = parseMappingNode(child); - - mapping.insert({std::move(message_type), std::move(module_mapping)}); - } - - return mapping; -} - } // namespace module \ No newline at end of file diff --git a/modules/OCPPConfiguration/main/mapping_reader.hpp b/modules/OCPPConfiguration/main/mapping_reader.hpp index de9f1f9d38..922045883d 100644 --- a/modules/OCPPConfiguration/main/mapping_reader.hpp +++ b/modules/OCPPConfiguration/main/mapping_reader.hpp @@ -3,6 +3,8 @@ #pragma once +#include "everest_config_mapping.hpp" +#include "generated/types/ocpp.hpp" #include #include #include @@ -12,19 +14,22 @@ namespace module { -struct EverestModuleMapping { - std::string module_id; - std::string config_key; -}; +using types::ocpp::Component; +using types::ocpp::ComponentVariable; +using types::ocpp::Variable; -using OcppToEverestModuleMapping = std::unordered_map; +using OcppToEverestConfigMapping = std::unordered_map; class MappingReader { public: - static OcppToEverestModuleMapping readMapping(const std::filesystem::path& file_path_string); + static OcppToEverestConfigMapping read_mapping(const std::filesystem::path& file_path); private: - static EverestModuleMapping parseMappingNode(const ryml::NodeRef& node); + static EverestConfigMapping parse_mapping_node(const ryml::NodeRef& node); + static types::ocpp::Component parse_component_node(const c4::yml::NodeRef& node); + static std::optional parse_evse_node(const c4::yml::NodeRef node); + static types::ocpp::Variable parse_variable_node(std::string variable_name, const c4::yml::NodeRef node); + static ComponentVariable parse_component_variable_node(std::string variable_name, const c4::yml::NodeRef& node); }; } // namespace module \ No newline at end of file diff --git a/modules/OCPPConfiguration/main/util.cpp b/modules/OCPPConfiguration/main/util.cpp index 407b67b3b9..1f6cdd8de0 100644 --- a/modules/OCPPConfiguration/main/util.cpp +++ b/modules/OCPPConfiguration/main/util.cpp @@ -44,8 +44,8 @@ void save_tree_to_yaml_file(const ryml::Tree& tree, const std::filesystem::path& file << tree; } -void write_value_to_tree(const EverestModuleMapping& module_mapping, const std::string& config_value, - const types::ocpp::Component& component, ryml::Tree& config_tree) { +void write_value_to_tree(const EverestConfigMapping& module_mapping, const std::string& config_value, + ryml::Tree& config_tree) { auto root = config_tree.rootref(); if (!root.is_map()) { @@ -59,9 +59,6 @@ void write_value_to_tree(const EverestModuleMapping& module_mapping, const std:: auto module_id_node = active_modules[module_id_csubstr]; module_id_node |= ryml::MAP; // mark module_id as map - // component - add_component_if_exists(component, module_id_node); - auto config_module_node = module_id_node["config_module"]; config_module_node |= ryml::MAP; @@ -71,30 +68,5 @@ void write_value_to_tree(const EverestModuleMapping& module_mapping, const std:: config_key_node << config_value_csubstr; } -void add_component_if_exists(const types::ocpp::Component& component, c4::yml::NodeRef& module_id_node) { - if (component.name.empty()) { - if (module_id_node.has_child("component")) { - module_id_node.remove_child("component"); - } - return; - } - - const auto component_name_csubstr = ryml::to_csubstr(component.name.c_str()); - const auto component_instance_csubstr = - ryml::to_csubstr(component.instance.has_value() ? component.instance.value().c_str() : ""); - const auto component_evse_csubstr = - ryml::to_csubstr(component.evse.has_value() ? std::to_string(component.evse.value().id).c_str() : ""); - - auto component_node = module_id_node["component"]; - component_node |= ryml::MAP; - auto component_name_node = component_node["name"]; - - component_name_node << component_name_csubstr; - auto component_instance_node = component_node["instance"]; - component_instance_node << component_instance_csubstr; - auto component_evse_node = component_node["evse_id"]; - component_evse_node << component_evse_csubstr; -} - } // namespace Util } // namespace module \ No newline at end of file diff --git a/modules/OCPPConfiguration/main/util.hpp b/modules/OCPPConfiguration/main/util.hpp index e65018516b..ecdfacf432 100644 --- a/modules/OCPPConfiguration/main/util.hpp +++ b/modules/OCPPConfiguration/main/util.hpp @@ -19,9 +19,8 @@ ryml::Tree load_existing_user_config(const std::filesystem::path& user_config_fi ryml::Tree load_yaml_file(const std::filesystem::path& file_path); void save_tree_to_yaml_file(const ryml::Tree& tree, const std::filesystem::path& file_path); -void write_value_to_tree(const EverestModuleMapping& module_mapping, const std::string& config_value, - const types::ocpp::Component& component, ryml::Tree& config_tree); -void add_component_if_exists(const types::ocpp::Component& component, c4::yml::NodeRef& module_id_node); +void write_value_to_tree(const EverestConfigMapping& module_mapping, const std::string& config_value, + ryml::Tree& config_tree); }; // namespace Util } // namespace module \ No newline at end of file diff --git a/modules/Setup/WiFiSetup.cpp b/modules/Setup/WiFiSetup.cpp index 7cbee9f92b..68204cddc5 100644 --- a/modules/Setup/WiFiSetup.cpp +++ b/modules/Setup/WiFiSetup.cpp @@ -333,7 +333,7 @@ bool WpaCliSetup::save_config(const std::string& interface) { return false; } - auto output = run_application(wpa_cli, {"-i", interface, "save_config_tree_to_file"}); + auto output = run_application(wpa_cli, {"-i", interface, "save_config"}); return output.exit_code == 0; } diff --git a/modules/Setup/tests/RunApplicationStub.cpp b/modules/Setup/tests/RunApplicationStub.cpp index 616dce9793..4681fa5a9d 100644 --- a/modules/Setup/tests/RunApplicationStub.cpp +++ b/modules/Setup/tests/RunApplicationStub.cpp @@ -18,7 +18,7 @@ RunApplication::RunApplication() : {"disable_network", {{}, {{"OK"}}, 0}}, {"select_network", {{}, {{"OK"}}, 0}}, {"remove_network", {{}, {{"OK"}}, 0}}, - {"save_config_tree_to_file", {{}, {{"OK"}}, 0}}, + {"save_config", {{}, {{"OK"}}, 0}}, // scan_wifi uses scan and scan_results {"scan", {{}, {{"OK"}}, 0}}, {"scan_results",