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 basic dynamic mode #42

Merged
merged 20 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9524065
Adding missing convert() for ScheduleExchange messages & adding de/se…
SebaLukas Sep 23, 2024
a29d3be
Adding dynamic mode to schedule_exchange state + test
SebaLukas Sep 23, 2024
b60ed79
Adding dc_pre_charge_target_voltage, dc_charge_scheduled_mode & dc_ch…
SebaLukas Sep 23, 2024
897b102
Adding present_voltage & meter_info_requested to feedback
SebaLukas Sep 26, 2024
3e52936
Now it is possible to select the control (scheduled and dynamic) and …
SebaLukas Sep 26, 2024
0faa02e
Added get_selected_mobility_needs_mode to d20/session
SebaLukas Sep 26, 2024
77ae75a
Adding cmake macro for better readability in d20 state tests
SebaLukas Sep 26, 2024
e52694e
Adding UpdateDynamicModeParameters to control_event, adding mobility_…
SebaLukas Sep 27, 2024
a135d7d
Fix dc charge loop serialization bug + Adding tests to prevent this bug
SebaLukas Oct 1, 2024
269df57
Refactoring duplicate code
SebaLukas Oct 22, 2024
e75f4dc
Adding helper function and added aliases for better readability
SebaLukas Oct 22, 2024
93006a2
Separated feedback from response handling for DcPreCharge
SebaLukas Oct 22, 2024
a254a6f
Refactoring feedback for dc_charge_loop
SebaLukas Oct 23, 2024
97959c8
Refactoring get_default_dc_parameter_list
SebaLukas Oct 23, 2024
447f190
Switched macro to function
SebaLukas Oct 23, 2024
99414c5
Refactoring dc_charge_loop & schedule_exchange state. Using UpdateDyn…
SebaLukas Nov 8, 2024
8800476
Refactoring Session get_selected_* functions into one function
SebaLukas Nov 8, 2024
49caa1f
Adding printing selected control mode and needs mobility mode
SebaLukas Nov 8, 2024
4e3a6a3
Bump libcbv2g version to 0.2.1
SebaLukas Nov 8, 2024
bd83717
Partially revert commit: Refactoring get_default_dc_parameter_list
SebaLukas Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ catch2:
cmake_condition: "ISO15118_BUILD_TESTING"
libcbv2g:
git: https://github.com/EVerest/libcbv2g.git
git_tag: v0.2.0
git_tag: v0.2.1
8 changes: 8 additions & 0 deletions include/iso15118/d20/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@

namespace iso15118::d20 {

struct ControlMobilityNeedsModes {
message_20::ControlMode control_mode;
message_20::MobilityNeedsMode mobility_mode;
};

struct EvseSetupConfig {
std::string evse_id;
std::vector<message_20::ServiceCategory> supported_energy_services;
std::vector<message_20::Authorization> authorization_services;
bool enable_certificate_install_service;
d20::DcTransferLimits dc_limits;
std::vector<ControlMobilityNeedsModes> control_mobility_modes;

Check notice on line 25 in include/iso15118/d20/config.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/d20/config.hpp#L25

struct member 'EvseSetupConfig::control_mobility_modes' is never used.
};

struct SessionConfig {
Expand All @@ -37,6 +43,8 @@
std::vector<message_20::ParkingParameterList> parking_parameter_list;

DcTransferLimits dc_limits;

std::vector<ControlMobilityNeedsModes> supported_control_mobility_modes;

Check notice on line 47 in include/iso15118/d20/config.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/d20/config.hpp#L47

struct member 'SessionConfig::supported_control_mobility_modes' is never used.
};

} // namespace iso15118::d20
7 changes: 5 additions & 2 deletions include/iso15118/d20/control_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// Copyright 2023 Pionix GmbH and Contributors to EVerest
#pragma once

#include <cstdint>
#include <optional>
#include <variant>

#include <iso15118/d20/dynamic_mode_parameters.hpp>
#include <iso15118/d20/limits.hpp>

namespace iso15118::d20 {
Expand Down Expand Up @@ -51,7 +54,7 @@ class StopCharging {
bool stop;
};

using ControlEvent =
std::variant<CableCheckFinished, PresentVoltageCurrent, AuthorizationResponse, StopCharging, DcTransferLimits>;
using ControlEvent = std::variant<CableCheckFinished, PresentVoltageCurrent, AuthorizationResponse, StopCharging,
DcTransferLimits, UpdateDynamicModeParameters>;

} // namespace iso15118::d20
17 changes: 17 additions & 0 deletions include/iso15118/d20/dynamic_mode_parameters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Pionix GmbH and Contributors to EVerest
#pragma once

#include <cstdint>
#include <ctime>
#include <optional>

namespace iso15118::d20 {

struct UpdateDynamicModeParameters {
std::optional<std::time_t> departure_time;
std::optional<std::uint8_t> target_soc;
std::optional<std::uint8_t> min_soc;
};

} // namespace iso15118::d20
10 changes: 2 additions & 8 deletions include/iso15118/d20/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,10 @@ class Session {

void selected_service_parameters(const message_20::ServiceCategory service, const uint16_t id);

message_20::ServiceCategory get_selected_energy_service() const {
return selected_services.selected_energy_service;
auto get_selected_services() const& {
return selected_services;
}

message_20::ControlMode get_selected_control_mode() const {
return selected_services.selected_control_mode;
}

// TODO(sl): Define get_selected_*() if necessary

~Session();

OfferedServices offered_services;
Expand Down
7 changes: 7 additions & 0 deletions include/iso15118/d20/state/dc_charge_loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include "../fsm.hpp"

#include <cstdint>
#include <optional>

#include <iso15118/d20/dynamic_mode_parameters.hpp>

namespace iso15118::d20::state {

struct DC_ChargeLoop : public FsmSimpleState {
Expand All @@ -18,6 +23,8 @@ struct DC_ChargeLoop : public FsmSimpleState {
float present_current{0};
bool stop{false};

UpdateDynamicModeParameters dynamic_parameters;

bool first_entry_in_charge_loop{true};
};

Expand Down
8 changes: 8 additions & 0 deletions include/iso15118/d20/state/schedule_exchange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include "../fsm.hpp"

#include <cstdint>
#include <optional>

#include <iso15118/d20/dynamic_mode_parameters.hpp>

namespace iso15118::d20::state {

struct ScheduleExchange : public FsmSimpleState {
Expand All @@ -12,6 +17,9 @@ struct ScheduleExchange : public FsmSimpleState {
void enter() final;

HandleEventReturnType handle_event(AllocatorType&, FsmEvent) final;

private:
UpdateDynamicModeParameters dynamic_parameters;
};

} // namespace iso15118::d20::state
7 changes: 7 additions & 0 deletions include/iso15118/detail/cb_exi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
\
out##_isUsed = static_cast<bool>(in);

#define CPP2CB_STRING_IF_USED(in, out) \
if (in) { \
CPP2CB_STRING(in.value(), out); \
} \
\
out##_isUsed = static_cast<bool>(in);

template <typename T1, typename T2> void cb_convert_enum(const T1& in, T2& out) {
out = static_cast<T2>(in);
}
Expand Down
12 changes: 9 additions & 3 deletions include/iso15118/detail/d20/state/dc_charge_loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
// Copyright 2023 Pionix GmbH and Contributors to EVerest
#pragma once

#include <cstdint>
#include <ctime>
#include <optional>
#include <tuple>
#include <variant>

#include <iso15118/d20/dynamic_mode_parameters.hpp>
#include <iso15118/d20/limits.hpp>
#include <iso15118/d20/session.hpp>
#include <iso15118/message/dc_charge_loop.hpp>
Expand All @@ -13,8 +17,10 @@

namespace iso15118::d20::state {

std::tuple<message_20::DC_ChargeLoopResponse, std::optional<session::feedback::DcChargeTarget>>
handle_request(const message_20::DC_ChargeLoopRequest& req, const d20::Session& session, const float present_voltage,
const float present_current, const bool stop, const DcTransferLimits& dc_limits);
message_20::DC_ChargeLoopResponse handle_request(const message_20::DC_ChargeLoopRequest& req,
const d20::Session& session, const float present_voltage,
const float present_current, const bool stop,
const DcTransferLimits& dc_limits,
const UpdateDynamicModeParameters& dynamic_parameters);

} // namespace iso15118::d20::state
5 changes: 3 additions & 2 deletions include/iso15118/detail/d20/state/dc_pre_charge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2023 Pionix GmbH and Contributors to EVerest
#pragma once

#include <optional>
#include <tuple>

#include <iso15118/d20/session.hpp>
Expand All @@ -11,7 +12,7 @@

namespace iso15118::d20::state {

std::tuple<message_20::DC_PreChargeResponse, session::feedback::DcChargeTarget>
handle_request(const message_20::DC_PreChargeRequest& req, const d20::Session& session, const float present_voltage);
message_20::DC_PreChargeResponse handle_request(const message_20::DC_PreChargeRequest& req, const d20::Session& session,
const float present_voltage);

} // namespace iso15118::d20::state
9 changes: 8 additions & 1 deletion include/iso15118/detail/d20/state/schedule_exchange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
#include <iso15118/d20/session.hpp>
#include <iso15118/message/schedule_exchange.hpp>

#include <cstdint>
#include <ctime>
#include <optional>

#include <iso15118/d20/dynamic_mode_parameters.hpp>

namespace iso15118::d20::state {

message_20::ScheduleExchangeResponse handle_request(const message_20::ScheduleExchangeRequest& req,
const d20::Session& session,
const message_20::RationalNumber& max_power);
const message_20::RationalNumber& max_power,
const UpdateDynamicModeParameters& dynamic_parameters);

} // namespace iso15118::d20::state
3 changes: 3 additions & 0 deletions include/iso15118/message/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,7 @@ RationalNumber from_float(float in);

std::string from_Protocol(const Protocol& in);

std::string from_control_mode(const ControlMode& in);
std::string from_mobility_needs_mode(const MobilityNeedsMode& in);

} // namespace iso15118::message_20
8 changes: 5 additions & 3 deletions include/iso15118/message/dc_charge_loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@
std::optional<MeterInfo> meter_info;
std::optional<Receipt> receipt;

RationalNumber present_current;
RationalNumber present_voltage;
RationalNumber present_current{0, 0};
RationalNumber present_voltage{0, 0};

Check notice on line 96 in include/iso15118/message/dc_charge_loop.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/message/dc_charge_loop.hpp#L96

struct member 'DC_ChargeLoopResponse::present_voltage' is never used.
bool power_limit_achieved{false};
bool current_limit_achieved{false};
bool voltage_limit_achieved{false};

std::variant<Scheduled_DC_CLResControlMode, BPT_Scheduled_DC_CLResControlMode, Dynamic_DC_CLResControlMode,
BPT_Dynamic_DC_CLResControlMode>
control_mode = Scheduled_DC_CLResControlMode();
control_mode;

DC_ChargeLoopResponse() : control_mode(std::in_place_type<DC_ChargeLoopResponse::Scheduled_DC_CLResControlMode>){};

Check warning on line 105 in include/iso15118/message/dc_charge_loop.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/message/dc_charge_loop.hpp#L105

Member variable 'DC_ChargeLoopResponse::header' is not initialized in the constructor.
};

} // namespace iso15118::message_20
18 changes: 6 additions & 12 deletions include/iso15118/message/schedule_exchange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@

struct ScheduleExchangeResponse {

static constexpr auto TAX_RULE_LENGTH = 10;
static constexpr auto PRICE_RULE_STACK_LENGTH = 1024;
static constexpr auto PRICE_RULE_LENGTH = 8;
static constexpr auto OVERSTAY_RULE_LENGTH = 5;
static constexpr auto ADDITIONAL_SERVICE_LENGTH = 5;
static constexpr auto PRICE_LEVEL_SCHEDULE_LENGTH = 1024;
static constexpr auto SCHEDULED_POWER_DURATION_S = 86400;

Header header;
Expand Down Expand Up @@ -112,7 +106,7 @@

struct PriceRuleStack {
uint32_t duration;
std::array<PriceRule, PRICE_RULE_LENGTH> price_rule;
std::vector<PriceRule> price_rule;

Check notice on line 109 in include/iso15118/message/schedule_exchange.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/message/schedule_exchange.hpp#L109

struct member 'PriceRuleStack::price_rule' is never used.
};

struct OverstayRule {
Expand All @@ -125,7 +119,7 @@
struct OverstayRulesList {
std::optional<uint32_t> overstay_time_threshold;
std::optional<RationalNumber> overstay_power_threshold;
std::array<OverstayRule, OVERSTAY_RULE_LENGTH> overstay_rule;
std::vector<OverstayRule> overstay_rule;

Check notice on line 122 in include/iso15118/message/schedule_exchange.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/message/schedule_exchange.hpp#L122

struct member 'OverstayRulesList::overstay_rule' is never used.
};

struct AdditionalService {
Expand All @@ -143,10 +137,10 @@
std::string price_algorithm;
std::optional<RationalNumber> minimum_cost;
std::optional<RationalNumber> maximum_cost;
std::optional<std::array<TaxRule, TAX_RULE_LENGTH>> tax_rules;
std::array<PriceRuleStack, PRICE_RULE_STACK_LENGTH> price_rule_stacks;
std::optional<std::vector<TaxRule>> tax_rules;
std::vector<PriceRuleStack> price_rule_stacks;

Check notice on line 141 in include/iso15118/message/schedule_exchange.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/message/schedule_exchange.hpp#L141

struct member 'AbsolutePriceSchedule::price_rule_stacks' is never used.
std::optional<OverstayRulesList> overstay_rules;
std::optional<std::array<AdditionalService, ADDITIONAL_SERVICE_LENGTH>> additional_selected_services;
std::optional<std::vector<AdditionalService>> additional_selected_services;
};

struct PriceLevelScheduleEntry {
Expand All @@ -160,7 +154,7 @@
uint32_t price_schedule_id;
std::optional<std::string> price_schedule_description;
uint8_t number_of_price_levels;
std::array<PriceLevelScheduleEntry, PRICE_LEVEL_SCHEDULE_LENGTH> price_level_schedule_entries;
std::vector<PriceLevelScheduleEntry> price_level_schedule_entries;

Check notice on line 157 in include/iso15118/message/schedule_exchange.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/message/schedule_exchange.hpp#L157

struct member 'PriceLevelSchedule::price_level_schedule_entries' is never used.
};

struct Dynamic_SEResControlMode {
Expand Down
42 changes: 19 additions & 23 deletions include/iso15118/session/feedback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// Copyright 2023 Pionix GmbH and Contributors to EVerest
#pragma once

#include <cmath>
#include <functional>
#include <optional>
#include <string>
#include <variant>

#include <iso15118/message/dc_charge_loop.hpp>
#include <iso15118/message/type.hpp>

namespace iso15118::session {
Expand All @@ -24,37 +27,30 @@
DLINK_PAUSE,
};

struct DcChargeTarget {
float voltage{-1};
float current{-1};
};

struct DcMaximumLimits {
float voltage{-1};
float current{-1};
float power{-1};
float voltage{NAN};

Check notice on line 31 in include/iso15118/session/feedback.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/session/feedback.hpp#L31

struct member 'DcMaximumLimits::voltage' is never used.
float current{NAN};

Check notice on line 32 in include/iso15118/session/feedback.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/session/feedback.hpp#L32

struct member 'DcMaximumLimits::current' is never used.
float power{NAN};

Check notice on line 33 in include/iso15118/session/feedback.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/iso15118/session/feedback.hpp#L33

struct member 'DcMaximumLimits::power' is never used.
};

struct DisplayParameters {
std::optional<float> present_soc;
std::optional<float> minimum_soc;
std::optional<float> target_soc;
std::optional<float> maximum_soc;
std::optional<float> remaining_time_to_minimum_soc;
std::optional<float> remaining_time_to_target_soc;
std::optional<float> remaining_time_to_maximum_soc;
std::optional<float> battery_energy_capacity;
std::optional<bool> inlet_hot;
};
using PresentVoltage = message_20::RationalNumber;
using MeterInfoRequested = bool;
using DcReqControlMode = std::variant<message_20::DC_ChargeLoopRequest::Scheduled_DC_CLReqControlMode,
message_20::DC_ChargeLoopRequest::BPT_Scheduled_DC_CLReqControlMode,
message_20::DC_ChargeLoopRequest::Dynamic_DC_CLReqControlMode,
message_20::DC_ChargeLoopRequest::BPT_Dynamic_DC_CLReqControlMode>;

using DcChargeLoopReq =
std::variant<DcReqControlMode, message_20::DisplayParameters, PresentVoltage, MeterInfoRequested>;

struct Callbacks {
std::function<void(Signal)> signal;
std::function<void(const DcChargeTarget&)> dc_charge_target;
std::function<void(float)> dc_pre_charge_target_voltage;
std::function<void(const DcChargeLoopReq&)> dc_charge_loop_req;
std::function<void(const DcMaximumLimits&)> dc_max_limits;
std::function<void(const message_20::Type&)> v2g_message;
std::function<void(const std::string&)> evccid;
std::function<void(const std::string&)> selected_protocol;
std::function<void(const DisplayParameters&)> display_parameters;
};

} // namespace feedback
Expand All @@ -64,12 +60,12 @@
Feedback(feedback::Callbacks);

void signal(feedback::Signal) const;
void dc_charge_target(const feedback::DcChargeTarget&) const;
void dc_pre_charge_target_voltage(float) const;
void dc_charge_loop_req(const feedback::DcChargeLoopReq&) const;
void dc_max_limits(const feedback::DcMaximumLimits&) const;
void v2g_message(const message_20::Type&) const;
void evcc_id(const std::string&) const;
void selected_protocol(const std::string&) const;
void display_parameters(const feedback::DisplayParameters&) const;

private:
feedback::Callbacks callbacks;
Expand Down
Loading
Loading