Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Ocpp Configuration Module #799

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

MarzellT
Copy link
Member

@MarzellT MarzellT commented Jul 26, 2024

Describe your changes

Issue ticket number and link

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I read the contribution documentation and made sure that my changes meet its requirements

modules/Cargo.lock Outdated Show resolved Hide resolved
modules/OCPPConfiguration/main/util.hpp Outdated Show resolved Hide resolved
Comment on lines 4 to 10
#include "mapping_reader.hpp"
#include "util.hpp"
#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put includes into sections

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done but I think this should be done automatically by some tool instead of having to do it manually. Isn't this set up somehow already?

modules/OCPPConfiguration/main/event_handler.hpp Outdated Show resolved Hide resolved
@MarzellT MarzellT force-pushed the tm-adding-ocpp-configuration-module branch 2 times, most recently from 4fa1426 to 475e176 Compare August 16, 2024 07:40
@MarzellT MarzellT marked this pull request as ready for review August 21, 2024 16:10
@MarzellT MarzellT force-pushed the tm-adding-ocpp-configuration-module branch 2 times, most recently from 72147ca to 2b86368 Compare August 22, 2024 08:25
modules/OCPPConfiguration/manifest.yaml Outdated Show resolved Hide resolved
modules/Cargo.lock Outdated Show resolved Hide resolved
modules/OCPPConfiguration/docs/index.rst Outdated Show resolved Hide resolved
config/config-sil-ocpp.yaml Outdated Show resolved Hide resolved
config/config-sil-ocpp.yaml Outdated Show resolved Hide resolved
modules/OCPPConfiguration/OCPPConfiguration.cpp Outdated Show resolved Hide resolved

private:
const std::optional<EverestConfigMapping>
find_mapping_by_component_variable_or_log_error(const types::ocpp::ComponentVariable& component_variable) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be considered normal to receive event data for variables that are not part of the mapping, so I wouldnt throw a runtime_error exception here but simply do nothing in case nothing can be found in the mapping. I think its enough to only have this function:

const std::optional<EverestConfigMapping> find_mapping_by_component_variable(const types::ocpp::ComponentVariable& component_variable) const;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to keep both functions but change the high level function to not log any error.
My reasoning was that the high level function checks if the low level function returned a value and if not returns a nullopt and the other function makes the actual lookup.
This way both functions have just one responsibility and I can still use the raii approach in the caller function of the high level function

namespace module {

void OCPPConfiguration::init() {
invoke_init(*p_main);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should verify the configuration parameters in the init:

  • Check if mapping file exists and is valid and warn if it doesn't
  • Check if user config exists and warn if it doesn't

In case the configuration could not be verified this module is not operational, but it should not crash, since it doesn't provide any interface and shold not cause a crash of everest ever.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first case is handled implicitly now but I think the second case shouldn't generate a warning and just silently create the file. Do you disagree?

modules/OCPPConfiguration/config-mapping.yaml Outdated Show resolved Hide resolved
namespace module {
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes ;) you could pass the mapping file path in the constructor of the class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely changed this and I think the solution is good, so this comment would be irrelevant then

throw std::runtime_error("EVSE node must have an id");
}
const auto id_val = node["id"].val();
auto id = std::stoi(std::string{id_val.str, id_val.len});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should catch std::invalid_argument


const 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should catch std::invalid_argument

modules/OCPPConfiguration/OCPPConfiguration.cpp Outdated Show resolved Hide resolved
modules/OCPPConfiguration/main/mapping_reader.hpp Outdated Show resolved Hide resolved
modules/OCPPConfiguration/main/mapping_reader.hpp Outdated Show resolved Hide resolved
modules/OCPPConfiguration/main/event_handler.hpp Outdated Show resolved Hide resolved
modules/OCPPConfiguration/main/util.hpp Outdated Show resolved Hide resolved
@MarzellT MarzellT force-pushed the tm-adding-ocpp-configuration-module branch 2 times, most recently from a27fc7f to a7cb4be Compare August 22, 2024 15:12
Copy link
Contributor

@SirVer SirVer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not touch Rust or Bazel, so lgtm.

@MarzellT MarzellT force-pushed the tm-adding-ocpp-configuration-module branch 2 times, most recently from 85c6c08 to cae1e6b Compare August 27, 2024 11:35
@Pietfried Pietfried self-assigned this Sep 3, 2024
@MarzellT MarzellT force-pushed the tm-adding-ocpp-configuration-module branch from f6022fe to 83f3de8 Compare September 12, 2024 13:40
Signed-off-by: MarzellT <[email protected]>
* adds first documentation draft
* renames config-mapping to example-config-mapping
* removes monitor_variables from config
* small refactorings

Signed-off-by: MarzellT <[email protected]>
@MarzellT MarzellT force-pushed the tm-adding-ocpp-configuration-module branch from 83f3de8 to 10db827 Compare September 12, 2024 13:53
@Pietfried Pietfried self-requested a review October 17, 2024 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants