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

Add simple EvAPI and extend EvManager with simplistic SoC calculation #891

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

Conversation

hikinggrass
Copy link
Contributor

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

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
…nnectors"

This allows both the API and EvAPI modules to run simultaneously

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
This allows an EV implementation to report more detailed information such as SoC

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
@SebaLukas
Copy link
Contributor

Maybe we can combine the new ev_manager interface with the existing car_simulator interface. I see no problem with moving the cmds and var from the car_simulator interface to the ev_manager interface.

Copy link
Contributor

@SebaLukas SebaLukas left a comment

Choose a reason for hiding this comment

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

In general, things are looking good. See my two comments.


private:
std::mutex session_info_mutex;
std::string state = "Unknown";
Copy link
Contributor

@SebaLukas SebaLukas Nov 7, 2024

Choose a reason for hiding this comment

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

I think, state should be types::board_support_common::event and not std::string


private:
std::mutex session_info_mutex;
std::string state = "Unknown";
Copy link
Member

Choose a reason for hiding this comment

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

I think an enum could be preferable here. It would make it clearer what the possible values can be

this->state = "Unknown";
}

void EvSessionInfo::update_state(const std::string& event) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rename event here? I think it might be a little bit confusing to call this variable event when it actually represents the state


std::list<std::unique_ptr<EvSessionInfo>> info;

const std::string api_base = "everest_api/";
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps make this a static inline constexpr std::string_view

EvSessionInfo::operator std::string() {
std::lock_guard<std::mutex> lock(this->session_info_mutex);

auto now = date::utc_clock::now();
Copy link
Member

Choose a reason for hiding this comment

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

Can this be made const?

Comment on lines 48 to 60
std::string var_base = ev_base + "/var/";

std::string var_ev_info = var_base + "ev_info";
ev->subscribe_ev_info([this, &ev, var_ev_info](types::evse_manager::EVInfo ev_info) {
json ev_info_json = ev_info;
this->mqtt.publish(var_ev_info, ev_info_json.dump());
});

std::string var_session_info = var_base + "session_info";
ev->subscribe_bsp_event([this, var_session_info, &session_info](const auto& bsp_event) {
session_info->update_state(types::board_support_common::event_to_string(bsp_event.event));
this->mqtt.publish(var_session_info, *session_info);
});
Copy link
Member

Choose a reason for hiding this comment

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

I think it could improve readability if those blocks are refactored to static functions like publish_ev_info and publish_session_info

};

void CarSimulation::simulate_soc() {
double ms =
Copy link
Member

Choose a reason for hiding this comment

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

Can be made const

double ms =
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - timepoint_last_update)
.count();
double factor = (1.0 / 60.0 / 60.0 / 1000.0) * ms;
Copy link
Member

Choose a reason for hiding this comment

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

Also const

const module::Conf& config;
std::chrono::time_point<std::chrono::steady_clock> timepoint_last_update;
double charge_current_a{0};
double charge_voltage_v{0};
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this is a class member? As far as I can see this is only used in one function where it's just copying the value of the config so it could live only there

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
This is was only used for AC, where we now get it via the config

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
…e enum

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
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.

3 participants