ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
smart_charging.hpp
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
3
4#ifndef OCPP_V16_SMART_CHARGING_HPP
5#define OCPP_V16_SMART_CHARGING_HPP
6
7#include <cstddef>
8#include <limits>
9
10#include <ocpp/v16/charge_point_configuration.hpp>
11#include <ocpp/v16/connector.hpp>
12#include <ocpp/v16/database_handler.hpp>
13#include <ocpp/v16/ocpp_types.hpp>
14#include <ocpp/v16/transaction.hpp>
15
16namespace ocpp {
17namespace v16 {
18
19const int DEFAULT_AND_MAX_NUMBER_PHASES = 3;
20const int HOURS_PER_DAY = 24;
21const int SECONDS_PER_HOUR = 3600;
22const int SECONDS_PER_DAY = 86400;
23const int DAYS_PER_WEEK = 7;
24
27 int limit;
28 int stack_level;
29};
30
33 std::optional<ChargingSchedulePeriod> period;
34 ocpp::DateTime end_time;
35};
36
40private:
41 std::map<int32_t, std::shared_ptr<Connector>> connectors;
42 std::shared_ptr<ocpp::v16::DatabaseHandler> database_handler;
43 ChargePointConfiguration& configuration;
44 std::map<int, ChargingProfile> stack_level_charge_point_max_profiles_map;
45 std::mutex charge_point_max_profiles_map_mutex;
46 std::mutex tx_default_profiles_map_mutex;
47 std::mutex tx_profiles_map_mutex;
48
49 std::unique_ptr<Everest::SteadyTimer> clear_profiles_timer;
50
51 bool clear_profiles(std::map<int32_t, ChargingProfile>& stack_level_profiles_map, std::optional<int> profile_id_opt,
52 std::optional<int> connector_id_opt, const int connector_id, std::optional<int> stack_level_opt,
53 std::optional<ChargingProfilePurposeType> charging_profile_purpose_opt, bool check_id_only);
54
55 void clear_expired_profiles();
56 int get_number_installed_profiles();
57
58public:
59 SmartChargingHandler(std::map<int32_t, std::shared_ptr<Connector>>& connectors,
60 std::shared_ptr<DatabaseHandler> database_handler, ChargePointConfiguration& configuration);
61
65 bool validate_profile(ChargingProfile& profile, const int connector_id, bool ignore_no_transaction,
66 const int profile_max_stack_level, const int max_charging_profiles_installed,
67 const int charging_schedule_max_periods,
68 const std::vector<ChargingRateUnit>& charging_schedule_allowed_charging_rate_units);
69
74
79 void add_tx_default_profile(const ChargingProfile& profile, const int connector_id);
80
85 void add_tx_profile(const ChargingProfile& profile, const int connector_id);
86
90 bool clear_all_profiles_with_filter(std::optional<int> profile_id, std::optional<int> connector_id,
91 std::optional<int> stack_level,
92 std::optional<ChargingProfilePurposeType> charging_profile_purpose,
93 bool check_id_only);
94
98 void clear_all_profiles();
99
104 std::vector<ChargingProfile>
105 get_valid_profiles(const ocpp::DateTime& start_time, const ocpp::DateTime& end_time, const int connector_id,
106 const std::set<ChargingProfilePurposeType>& purposes_to_ignore = {});
110 EnhancedChargingSchedule calculate_enhanced_composite_schedule(const std::vector<ChargingProfile>& valid_profiles,
111 const ocpp::DateTime& start_time,
112 const ocpp::DateTime& end_time,
113 const int connector_id,
114 std::optional<ChargingRateUnit> charging_rate_unit);
118 ChargingSchedule calculate_composite_schedule(const std::vector<ChargingProfile>& valid_profiles,
119 const ocpp::DateTime& start_time, const ocpp::DateTime& end_time,
120 const int connector_id,
121 std::optional<ChargingRateUnit> charging_rate_unit);
122};
123
124bool validate_schedule(const ChargingSchedule& schedule, const int charging_schedule_max_periods,
125 const std::vector<ChargingRateUnit>& charging_schedule_allowed_charging_rate_units);
126
127} // namespace v16
128} // namespace ocpp
129
130#endif // OCPP_V16_SMART_CHARGING_HPP
Contains a DateTime implementation that can parse and create RFC 3339 compatible strings.
Definition: types.hpp:109
contains the configuration of the charge point
Definition: charge_point_configuration.hpp:17
This class handles and maintains incoming ChargingProfiles and contains the logic to calculate the co...
Definition: smart_charging.hpp:39
bool validate_profile(ChargingProfile &profile, const int connector_id, bool ignore_no_transaction, const int profile_max_stack_level, const int max_charging_profiles_installed, const int charging_schedule_max_periods, const std::vector< ChargingRateUnit > &charging_schedule_allowed_charging_rate_units)
validates the given profile according to the specification
Definition: smart_charging.cpp:163
ChargingSchedule calculate_composite_schedule(const std::vector< ChargingProfile > &valid_profiles, const ocpp::DateTime &start_time, const ocpp::DateTime &end_time, const int connector_id, std::optional< ChargingRateUnit > charging_rate_unit)
Calculates the composite schedule for the given valid_profiles and the given connector_id.
Definition: smart_charging.cpp:88
void add_tx_profile(const ChargingProfile &profile, const int connector_id)
Adds the given profile to the collection of stack_level_tx_profiles_map of the respective connector.
Definition: smart_charging.cpp:294
std::vector< ChargingProfile > get_valid_profiles(const ocpp::DateTime &start_time, const ocpp::DateTime &end_time, const int connector_id, const std::set< ChargingProfilePurposeType > &purposes_to_ignore={})
Gets all valid profiles within the given absoulte start_time and absolute end_time for the given conn...
Definition: smart_charging.cpp:388
bool clear_all_profiles_with_filter(std::optional< int > profile_id, std::optional< int > connector_id, std::optional< int > stack_level, std::optional< ChargingProfilePurposeType > charging_profile_purpose, bool check_id_only)
Clears all charging profiles using optional filters.
Definition: smart_charging.cpp:340
void add_charge_point_max_profile(const ChargingProfile &profile)
Adds the given profile to the collection of stack_level_charge_point_max_profiles_map.
Definition: smart_charging.cpp:263
void add_tx_default_profile(const ChargingProfile &profile, const int connector_id)
Adds the given profile to the collection of stack_level_tx_default_profiles_map of the respective con...
Definition: smart_charging.cpp:273
void clear_all_profiles()
Clears all present profiles from all collections.
Definition: smart_charging.cpp:368
EnhancedChargingSchedule calculate_enhanced_composite_schedule(const std::vector< ChargingProfile > &valid_profiles, const ocpp::DateTime &start_time, const ocpp::DateTime &end_time, const int connector_id, std::optional< ChargingRateUnit > charging_rate_unit)
Calculates the enhanced composite schedule for the given valid_profiles and the given connector_id.
Definition: smart_charging.cpp:108
Definition: ocpp_types.hpp:146
Definition: ocpp_types.hpp:66
Enhances ChargingSchedule by containing std::vector<EnhancedChargingSchedulePeriods> instead of std::...
Definition: types.hpp:220
Helper struct to calculate Composite Schedule.
Definition: smart_charging.hpp:26
Helper struct to calculate Composite Schedule.
Definition: smart_charging.hpp:32