Skip to content

Commit

Permalink
fixes writing config failing if file doesn't exist and adds component…
Browse files Browse the repository at this point in the history
… information to the config

Signed-off-by: MarzellT <[email protected]>
  • Loading branch information
MarzellT committed Aug 16, 2024
1 parent 4cc7321 commit 475e176
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 144 deletions.
2 changes: 1 addition & 1 deletion modules/OCPPConfiguration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ target_link_libraries(${MODULE_NAME}

target_sources(${MODULE_NAME}
PRIVATE
"example_module/example_userImpl.cpp"
"main/emptyImpl.cpp"
"main/mapping_reader.cpp"
"main/util.cpp"
"main/event_handler.cpp"
Expand Down
8 changes: 2 additions & 6 deletions modules/OCPPConfiguration/OCPPConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
namespace module {

void OCPPConfiguration::init() {
invoke_init(*p_example_module);
invoke_init(*p_main);
}

void OCPPConfiguration::ready() {
invoke_ready(*p_example_module);

// auto attached = false;
// while (!attached) {
// };
invoke_ready(*p_main);

const auto mapping_file_path = std::filesystem::path{config.mapping_file_path};
event_handler = std::make_unique<EventHandler>(mapping_file_path);
Expand Down
11 changes: 4 additions & 7 deletions modules/OCPPConfiguration/OCPPConfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "ld-ev.hpp"

// headers for provided interface implementations
#include <generated/interfaces/example_user/Implementation.hpp>
#include <generated/interfaces/empty/Implementation.hpp>

// headers for required interface implementations
#include <generated/interfaces/ocpp/Interface.hpp>
Expand All @@ -32,14 +32,11 @@ struct Conf {
class OCPPConfiguration : public Everest::ModuleBase {
public:
OCPPConfiguration() = delete;
OCPPConfiguration(const ModuleInfo& info, std::unique_ptr<example_userImplBase> p_example_module,
OCPPConfiguration(const ModuleInfo& info, std::unique_ptr<emptyImplBase> p_main,
std::unique_ptr<ocppIntf> r_ocpp_module, Conf& config) :
ModuleBase(info),
p_example_module(std::move(p_example_module)),
r_ocpp_module(std::move(r_ocpp_module)),
config(config){};
ModuleBase(info), p_main(std::move(p_main)), r_ocpp_module(std::move(r_ocpp_module)), config(config){};

const std::unique_ptr<example_userImplBase> p_example_module;
const std::unique_ptr<emptyImplBase> p_main;
const std::unique_ptr<ocppIntf> r_ocpp_module;
const Conf& config;

Expand Down
125 changes: 50 additions & 75 deletions modules/OCPPConfiguration/config-mapping.yaml
Original file line number Diff line number Diff line change
@@ -1,100 +1,75 @@
AllowOfflineTxForUnknownId:
config_key: allow_offline_tx_for_unknown_id
module_name: testAllowOfflineTxForUnknownId
module_config_key: allow_offline_tx_for_unknown_id_config
module_id: allow_offline_tx_for_unknown_id
config_key: allow_offline_tx_for_unknown_id_config
AuthorizationCacheEnabled:
config_key: authorization_cache_enabled
module_name: testAuthCacheEnabled
module_config_key: authorization_cache_enabled_config
module_id: authorization_cache_enabled
config_key: authorization_cache_enabled_config
AuthorizeRemoteTxRequests:
config_key: authorize_remote_tx_requests
module_name: testAuthorizeRemoteTxRequests
module_config_key: authorize_remote_tx_requests_config
module_id: authorize_remote_tx_requests
config_key: authorize_remote_tx_requests_config
BlinkRepeat:
config_key: blink_repeat
module_name: testBlinkRepeat
module_config_key: blink_repeat_config
module_id: blink_repeat
config_key: blink_repeat_config
ClockAlignedDataInterval:
config_key: clock_aligned_data_interval
module_name: testClockAlignedDataInterval
module_config_key: clock_aligned_data_interval_config
module_id: clock_aligned_data_interval
config_key: clock_aligned_data_interval_config
ConnectionTimeOut:
config_key: connection_time_out
module_name: testConnectionTimeOut
module_config_key: connection_time_out_config
module_id: connection_time_out
config_key: connection_time_out_config
ConnectorPhaseRotation:
config_key: connector_phase_rotation
module_name: testConnectorPhaseRotation
module_config_key: connector_phase_rotation_config
module_id: connector_phase_rotation
config_key: connector_phase_rotation_config
HeartbeatInterval:
config_key: heartbeat_interval
module_name: testHeartbeatInterval
module_config_key: heartbeat_interval_config
module_id: heartbeat_interval
config_key: heartbeat_interval_config
LightIntensity:
config_key: light_intensity
module_name: testLightIntensity
module_config_key: light_intensity_config
module_id: light_intensity
config_key: light_intensity_config
LocalAuthorizeOffline:
config_key: local_authorize_offline
module_name: testLocalAuthorizeOffline
module_config_key: local_authorize_offline_config
module_id: local_authorize_offline
config_key: local_authorize_offline_config
LocalPreAuthorize:
config_key: local_pre_authorize
module_name: testLocalPreAuthorize
module_config_key: local_pre_authorize_config
module_id: local_pre_authorize
config_key: local_pre_authorize_config
MaxEnergyOnInvalidId:
config_key: max_energy_on_invalid_id
module_name: testMaxEnergyOnInvalidId
module_config_key: max_energy_on_invalid_id_config
module_id: max_energy_on_invalid_id
config_key: max_energy_on_invalid_id_config
MeterValuesAlignedData:
config_key: meter_values_aligned_data
module_name: testMeterValuesAlignedData
module_config_key: meter_values_aligned_data_config
module_id: meter_values_aligned_data
config_key: meter_values_aligned_data_config
MeterValuesSampledData:
config_key: meter_values_sampled_data
module_name: testMeterValuesSampledData
module_config_key: meter_values_sampled_data_config
module_id: meter_values_sampled_data
config_key: meter_values_sampled_data_config
MeterValueSampleInterval:
config_key: meter_value_sample_interval
module_name: testMeterValueSampleInterval
module_config_key: meter_value_sample_interval_config
module_id: meter_value_sample_interval
config_key: meter_value_sample_interval_config
MinimumStatusDuration:
config_key: minimum_status_duration
module_name: testMinimumStatusDuration
module_config_key: minimum_status_duration_config
module_id: minimum_status_duration
config_key: minimum_status_duration_config
ResetRetries:
config_key: reset_retries
module_name: testResetRetries
module_config_key: reset_retries_config
module_id: reset_retries
config_key: reset_retries_config
StopTransactionOnEVSideDisconnect:
config_key: stop_transaction_on_ev_side_disconnect
module_name: testStopTransactionOnEVSideDisconnect
module_config_key: stop_transaction_on_ev_side_disconnect_config
module_id: stop_transaction_on_ev_side_disconnect
config_key: stop_transaction_on_ev_side_disconnect_config
StopTransactionOnInvalidId:
config_key: stop_transaction_on_invalid_id
module_name: testStopTransactionOnInvalidId
module_config_key: stop_transaction_on_invalid_id_config
module_id: stop_transaction_on_invalid_id
config_key: stop_transaction_on_invalid_id_config
StopTxnAlignedData:
config_key: stop_txn_aligned_data
module_name: testStopTxnAlignedData
module_config_key: stop_txn_aligned_data_config
module_id: stop_txn_aligned_data
config_key: stop_txn_aligned_data_config
StopTxnSampledData:
config_key: stop_txn_sampled_data
module_name: testStopTxnSampledData
module_config_key: stop_txn_sampled_data_config
module_id: stop_txn_sampled_data
config_key: stop_txn_sampled_data_config
TransactionMessageAttempts:
config_key: transaction_message_attempts
module_name: testTransactionMessageAttempts
module_config_key: transaction_message_attempts_config
module_id: transaction_message_attempts
config_key: transaction_message_attempts_config
TransactionMessageRetryInterval:
config_key: transaction_message_retry_interval
module_name: testTransactionMessageRetryInterval
module_config_key: transaction_message_retry_interval_config
module_id: transaction_message_retry_interval
config_key: transaction_message_retry_interval_config
UnlockConnectorOnEVSideDisconnect:
config_key: unlock_connector_on_ev_side_disconnect
module_name: testUnlockConnectorOnEVSideDisconnect
module_config_key: unlock_connector_on_ev_side_disconnect_config
module_id: unlock_connector_on_ev_side_disconnect
config_key: unlock_connector_on_ev_side_disconnect_config
WebsocketPingInterval:
config_key: websocket_ping_interval
module_name: testWebsocketPingInterval
module_config_key: websocket_ping_interval_config
module_id: websocket_ping_interval
config_key: websocket_ping_interval_config
16 changes: 0 additions & 16 deletions modules/OCPPConfiguration/example_module/example_userImpl.cpp

This file was deleted.

16 changes: 16 additions & 0 deletions modules/OCPPConfiguration/main/emptyImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#include "emptyImpl.hpp"

namespace module {
namespace main {

void emptyImpl::init() {
}

void emptyImpl::ready() {
}

} // namespace main
} // namespace module
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef EXAMPLE_MODULE_EXAMPLE_USER_IMPL_HPP
#define EXAMPLE_MODULE_EXAMPLE_USER_IMPL_HPP
#ifndef MAIN_EMPTY_IMPL_HPP
#define MAIN_EMPTY_IMPL_HPP

//
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT
// template version 3
//

#include <generated/interfaces/example_user/Implementation.hpp>
#include <generated/interfaces/empty/Implementation.hpp>

#include "../OCPPConfiguration.hpp"

Expand All @@ -17,15 +17,15 @@
// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1

namespace module {
namespace example_module {
namespace main {

struct Conf {};

class example_userImpl : public example_userImplBase {
class emptyImpl : public emptyImplBase {
public:
example_userImpl() = delete;
example_userImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<OCPPConfiguration>& mod, Conf& config) :
example_userImplBase(ev, "example_module"), mod(mod), config(config){};
emptyImpl() = delete;
emptyImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer<OCPPConfiguration>& mod, Conf& config) :
emptyImplBase(ev, "main"), mod(mod), config(config){};

// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
Expand Down Expand Up @@ -54,7 +54,7 @@ class example_userImpl : public example_userImplBase {
// insert other definitions here
// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1

} // namespace example_module
} // namespace main
} // namespace module

#endif // EXAMPLE_MODULE_EXAMPLE_USER_IMPL_HPP
#endif // MAIN_EMPTY_IMPL_HPP
10 changes: 7 additions & 3 deletions modules/OCPPConfiguration/main/event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ EventHandler::EventHandler(const std::filesystem::path& config_mapping_path) :

void EventHandler::handleEvent(const types::ocpp::EventData& event_data, const std::string& user_config_path_string) {

// lookup event in event_map
// 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);
if (!everest_module_mapping_opt.has_value()) {
Expand All @@ -23,10 +25,12 @@ void EventHandler::handleEvent(const types::ocpp::EventData& event_data, const s

const auto& everest_module_mapping = everest_module_mapping_opt.value();

// write event to config
write_event_to_config(event_data, user_config_path_string, everest_module_mapping, component);
}
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) {
const auto user_config_path = std::filesystem::path{user_config_path_string};
auto tree = Util::load_existing_user_config(user_config_path);
tree = Util::write_value_to_tree(everest_module_mapping, event_data.actual_value, tree);
Util::write_value_to_tree(everest_module_mapping, event_data.actual_value, component, tree);
Util::save_tree_to_yaml_file(tree, user_config_path);
}

Expand Down
3 changes: 3 additions & 0 deletions modules/OCPPConfiguration/main/event_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class EventHandler {
const EverestModuleMapping find_event_in_map(const std::string& event_name) const;

OcppToEverestModuleMapping event_map;

Check notice on line 20 in modules/OCPPConfiguration/main/event_handler.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/OCPPConfiguration/main/event_handler.hpp#L20

class member 'EventHandler::event_map' is never used.
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);
};

} // namespace module
8 changes: 3 additions & 5 deletions modules/OCPPConfiguration/main/mapping_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ EverestModuleMapping MappingReader::parseMappingNode(const ryml::NodeRef& node)
return std::string{val.str, val.len};
};

const auto module_id_node = node["module_id"];
const auto config_key_node = node["config_key"];
const auto module_name_node = node["module_name"];
const auto module_config_key_node = node["module_config_key"];

const auto module_id = parse_node(module_id_node);
const auto config_key = parse_node(config_key_node);
const auto module_name = parse_node(module_name_node);
const auto module_config_key = parse_node(module_config_key_node);

return {config_key, module_name, module_config_key};
return {module_id, config_key};
}

OcppToEverestModuleMapping MappingReader::readMapping(const std::filesystem::path& file_path) {
Expand Down
3 changes: 1 addition & 2 deletions modules/OCPPConfiguration/main/mapping_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
namespace module {

struct EverestModuleMapping {
std::string module_id;

Check notice on line 16 in modules/OCPPConfiguration/main/mapping_reader.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/OCPPConfiguration/main/mapping_reader.hpp#L16

struct member 'EverestModuleMapping::module_id' is never used.
std::string config_key;

Check notice on line 17 in modules/OCPPConfiguration/main/mapping_reader.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/OCPPConfiguration/main/mapping_reader.hpp#L17

struct member 'EverestModuleMapping::config_key' is never used.
std::string module_name;
std::string module_config_key;
};

using OcppToEverestModuleMapping = std::unordered_map<std::string, EverestModuleMapping>;
Expand Down
Loading

0 comments on commit 475e176

Please sign in to comment.