-
Notifications
You must be signed in to change notification settings - Fork 79
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
hikinggrass
wants to merge
26
commits into
main
Choose a base branch
from
feature/ev-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b7a727d
Add simple EvAPI and extend EvManager with simplistic SoC calculation
hikinggrass 5fcc16b
Merge branch 'main' into feature/ev-api
hikinggrass feeb598
cleanup
hikinggrass 921a7f7
Public EvAPI connectors in "ev_connectors" do not use regular API "co…
hikinggrass ed02b39
Remove session event from ev manager interface since it is not used
hikinggrass 3a919b2
Add EVInfo variable to ev board support interface
hikinggrass fad56c4
Remove car manufacturer from ev manager interface since it is not used
hikinggrass 038a90e
Re-publish bsp event in exeisting subscriber
hikinggrass 59bc9b9
Re-publish ev info coming from ev board support
hikinggrass 5e9a275
Add description to ev manager provide
hikinggrass eb4f634
Remove wring years from license header
hikinggrass 81a79d8
Fix naming of charge current/voltage, add AC nominal voltage to config
hikinggrass d7a67ae
Remove EvAPI from config-sil again
hikinggrass fcf43bf
Use EvSessionInfo in EvAPI with reduced information compared to API
hikinggrass 5060f53
clang-format
hikinggrass ba781f8
Refactor EvSessioninfo
hikinggrass 2ec49b9
cleanup + const
hikinggrass 8bc6ab4
Remove unnecessary charge_voltage_v member variables
hikinggrass 536e8fb
make ms factor constexpr
hikinggrass 17c9998
Replace charge_ac and charge_three_phase bool members with charge_mod…
hikinggrass c679a32
Adding iso_dc_power_on cmd to all node-red config-sil files. With thi…
SebaLukas a86c62d
Merge remote-tracking branch 'origin/main' into feature/ev-api
hikinggrass 633fc08
fix codacy issue
hikinggrass a902c7f
clang-format
hikinggrass 5879dd3
Merge branch 'main' into feature/ev-api
Pietfried a89c6c3
Merge branch 'main' into feature/ev-api
hikinggrass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
description: >- | ||
This interface defines the ev manager. An ev manager represents the | ||
charging logic of the ev side | ||
cmds: {} | ||
vars: | ||
bsp_event: | ||
description: >- | ||
Events from CP/Relais | ||
type: object | ||
$ref: /board_support_common#/BspEvent | ||
ev_info: | ||
description: More details about the EV if available | ||
type: object | ||
$ref: /evse_manager#/EVInfo | ||
errors: | ||
- reference: /errors/evse_manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# AUTO GENERATED - MARKED REGIONS WILL BE KEPT | ||
# template version 3 | ||
# | ||
|
||
# module setup: | ||
# - ${MODULE_NAME}: module name | ||
ev_setup_cpp_module() | ||
|
||
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 | ||
# insert your custom targets and additional config variables here | ||
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 | ||
|
||
target_sources(${MODULE_NAME} | ||
PRIVATE | ||
"main/emptyImpl.cpp" | ||
) | ||
|
||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1 | ||
# insert other things like install cmds etc here | ||
# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
#include "EvAPI.hpp" | ||
#include <utils/date.hpp> | ||
|
||
namespace module { | ||
|
||
static const auto NOTIFICATION_PERIOD = std::chrono::seconds(1); | ||
|
||
void EvSessionInfo::reset() { | ||
std::lock_guard<std::mutex> lock(this->session_info_mutex); | ||
this->event = std::nullopt; | ||
} | ||
|
||
void EvSessionInfo::update_event(const types::board_support_common::Event& event) { | ||
std::lock_guard<std::mutex> lock(this->session_info_mutex); | ||
this->event = event; | ||
} | ||
|
||
EvSessionInfo::operator std::string() { | ||
std::lock_guard<std::mutex> lock(this->session_info_mutex); | ||
|
||
const auto now = date::utc_clock::now(); | ||
|
||
std::string state = "Unknown"; | ||
if (this->event.has_value()) { | ||
state = types::board_support_common::event_to_string(this->event.value()); | ||
} | ||
|
||
json session_info = json::object({ | ||
{"state", state}, | ||
{"datetime", Everest::Date::to_rfc3339(now)}, | ||
}); | ||
|
||
return session_info.dump(); | ||
} | ||
|
||
void EvAPI::init() { | ||
invoke_init(*p_main); | ||
|
||
std::vector<std::string> ev_connectors; | ||
std::string var_ev_connectors = this->api_base + "ev_connectors"; | ||
|
||
for (auto& ev : this->r_ev_manager) { | ||
auto& session_info = this->info.emplace_back(std::make_unique<EvSessionInfo>()); | ||
const std::string ev_base = this->api_base + ev->module_id; | ||
ev_connectors.push_back(ev->module_id); | ||
|
||
// API variables | ||
const std::string var_base = ev_base + "/var/"; | ||
|
||
const 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()); | ||
}); | ||
|
||
const 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_event(bsp_event.event); | ||
this->mqtt.publish(var_session_info, *session_info); | ||
}); | ||
|
||
const std::string var_datetime = var_base + "datetime"; | ||
this->api_threads.push_back(std::thread([this, var_datetime, var_session_info, &session_info]() { | ||
auto next_tick = std::chrono::steady_clock::now(); | ||
while (this->running) { | ||
std::string datetime_str = Everest::Date::to_rfc3339(date::utc_clock::now()); | ||
this->mqtt.publish(var_datetime, datetime_str); | ||
this->mqtt.publish(var_session_info, *session_info); | ||
|
||
next_tick += NOTIFICATION_PERIOD; | ||
std::this_thread::sleep_until(next_tick); | ||
} | ||
})); | ||
|
||
// API commands | ||
const std::string cmd_base = ev_base + "/cmd/"; | ||
} | ||
|
||
this->api_threads.push_back(std::thread([this, var_ev_connectors, ev_connectors]() { | ||
auto next_tick = std::chrono::steady_clock::now(); | ||
while (this->running) { | ||
const json ev_connectors_array = ev_connectors; | ||
this->mqtt.publish(var_ev_connectors, ev_connectors_array.dump()); | ||
|
||
next_tick += NOTIFICATION_PERIOD; | ||
std::this_thread::sleep_until(next_tick); | ||
} | ||
})); | ||
} | ||
|
||
void EvAPI::ready() { | ||
invoke_ready(*p_main); | ||
|
||
const std::string var_active_errors = this->api_base + "errors/var/active_errors"; | ||
this->api_threads.push_back(std::thread([this, var_active_errors]() { | ||
auto next_tick = std::chrono::steady_clock::now(); | ||
while (this->running) { | ||
if (not r_error_history.empty()) { | ||
// request active errors | ||
types::error_history::FilterArguments filter; | ||
filter.state_filter = types::error_history::State::Active; | ||
const auto active_errors = r_error_history.at(0)->call_get_errors(filter); | ||
json errors_json = json(active_errors); | ||
|
||
// publish | ||
this->mqtt.publish(var_active_errors, errors_json.dump()); | ||
} | ||
next_tick += NOTIFICATION_PERIOD; | ||
std::this_thread::sleep_until(next_tick); | ||
} | ||
})); | ||
} | ||
|
||
} // namespace module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Pionix GmbH and Contributors to EVerest | ||
#ifndef EVAPI_HPP | ||
#define EVAPI_HPP | ||
|
||
// | ||
// AUTO GENERATED - MARKED REGIONS WILL BE KEPT | ||
// template version 2 | ||
// | ||
|
||
#include "ld-ev.hpp" | ||
|
||
// headers for provided interface implementations | ||
#include <generated/interfaces/empty/Implementation.hpp> | ||
|
||
// headers for required interface implementations | ||
#include <generated/interfaces/error_history/Interface.hpp> | ||
#include <generated/interfaces/ev_manager/Interface.hpp> | ||
|
||
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1 | ||
// insert your custom include headers here | ||
#include <condition_variable> | ||
#include <list> | ||
#include <memory> | ||
#include <mutex> | ||
#include <sstream> | ||
|
||
#include <date/date.h> | ||
#include <date/tz.h> | ||
|
||
#include <generated/types/board_support_common.hpp> | ||
|
||
namespace module { | ||
|
||
class LimitDecimalPlaces; | ||
|
||
class EvSessionInfo { | ||
public: | ||
EvSessionInfo(){}; | ||
|
||
void reset(); | ||
void update_event(const types::board_support_common::Event& event); | ||
|
||
/// \brief Converts this struct into a serialized json object | ||
operator std::string(); | ||
|
||
private: | ||
std::mutex session_info_mutex; | ||
std::optional<types::board_support_common::Event> event; | ||
}; | ||
} // namespace module | ||
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1 | ||
|
||
namespace module { | ||
|
||
struct Conf {}; | ||
|
||
class EvAPI : public Everest::ModuleBase { | ||
public: | ||
EvAPI() = delete; | ||
EvAPI(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider, std::unique_ptr<emptyImplBase> p_main, | ||
std::vector<std::unique_ptr<ev_managerIntf>> r_ev_manager, | ||
std::vector<std::unique_ptr<error_historyIntf>> r_error_history, Conf& config) : | ||
ModuleBase(info), | ||
mqtt(mqtt_provider), | ||
p_main(std::move(p_main)), | ||
r_ev_manager(std::move(r_ev_manager)), | ||
r_error_history(std::move(r_error_history)), | ||
config(config){}; | ||
|
||
Everest::MqttProvider& mqtt; | ||
const std::unique_ptr<emptyImplBase> p_main; | ||
const std::vector<std::unique_ptr<ev_managerIntf>> r_ev_manager; | ||
const std::vector<std::unique_ptr<error_historyIntf>> r_error_history; | ||
const Conf& config; | ||
|
||
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1 | ||
// insert your public definitions here | ||
// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1 | ||
|
||
protected: | ||
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1 | ||
// insert your protected definitions here | ||
// ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1 | ||
|
||
private: | ||
friend class LdEverest; | ||
void init(); | ||
void ready(); | ||
|
||
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1 | ||
// insert your private definitions here | ||
std::vector<std::thread> api_threads; | ||
bool running = true; | ||
|
||
std::list<std::unique_ptr<EvSessionInfo>> info; | ||
|
||
const std::string api_base = "everest_api/"; | ||
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1 | ||
}; | ||
|
||
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1 | ||
// insert other definitions here | ||
// ev@087e516b-124c-48df-94fb-109508c7cda9:v1 | ||
|
||
} // namespace module | ||
|
||
#endif // EVAPI_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# EvAPI module documentation | ||
Check notice on line 1 in modules/EvAPI/README.md Codacy Production / Codacy Static Code Analysismodules/EvAPI/README.md#L1
|
||
This module is responsible for providing a simple MQTT based API to EVerest internals exposing EvManager related functionality | ||
Check notice on line 2 in modules/EvAPI/README.md Codacy Production / Codacy Static Code Analysismodules/EvAPI/README.md#L2
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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