Skip to content

Commit ea3cb61

Browse files
authored
Move provisioning callbacks and handlers to functional block (#976)
Signed-off-by: Maaike Zijderveld, iolar <git.mail@iolar.nl>
1 parent 88a3df9 commit ea3cb61

File tree

6 files changed

+889
-655
lines changed

6 files changed

+889
-655
lines changed

doc/v201/ocpp_201_status.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ This document contains the status of which OCPP 2.0.1 numbered functional requir
263263
| B01.FR.10 || |
264264
| B01.FR.11 || |
265265
| B01.FR.12 || |
266-
| B01.FR.13 | | |
266+
| B01.FR.13 | | |
267267

268268
## Provisioning - Cold Boot Charging Station – Pending
269269

@@ -412,7 +412,7 @@ This document contains the status of which OCPP 2.0.1 numbered functional requir
412412
| B11.FR.02 || |
413413
| B11.FR.03 || |
414414
| B11.FR.04 || |
415-
| B11.FR.05 | | |
415+
| B11.FR.05 | | |
416416
| B11.FR.06 | ⛽️ | In EVerest, the System module is responsible. |
417417
| B11.FR.07 | ⛽️ | In EVerest, the System module is responsible. |
418418
| B11.FR.08 || |

include/ocpp/v201/charge_point.hpp

+2-32
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <ocpp/v201/functional_blocks/display_message.hpp>
1616
#include <ocpp/v201/functional_blocks/firmware_update.hpp>
1717
#include <ocpp/v201/functional_blocks/meter_values.hpp>
18+
#include <ocpp/v201/functional_blocks/provisioning.hpp>
1819
#include <ocpp/v201/functional_blocks/reservation.hpp>
1920
#include <ocpp/v201/functional_blocks/security.hpp>
2021
#include <ocpp/v201/functional_blocks/smart_charging.hpp>
@@ -363,14 +364,12 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
363364
std::unique_ptr<SmartCharging> smart_charging;
364365
std::unique_ptr<TariffAndCostInterface> tariff_and_cost;
365366
std::unique_ptr<TransactionInterface> transaction;
367+
std::unique_ptr<ProvisioningInterface> provisioning;
366368

367369
// utility
368370
std::shared_ptr<MessageQueue<v201::MessageType>> message_queue;
369371
std::shared_ptr<DatabaseHandler> database_handler;
370372

371-
// timers
372-
Everest::SteadyTimer boot_notification_timer;
373-
374373
// states
375374
std::atomic<RegistrationStatusEnum> registration_status;
376375
UploadLogStatusEnum upload_log_status;
@@ -419,22 +418,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
419418

420419
void message_callback(const std::string& message);
421420

422-
/// \brief Helper function to determine if the requested change results in a state that the Connector(s) is/are
423-
/// already in \param request \return
424-
void handle_variable_changed(const SetVariableData& set_variable_data);
425-
void handle_variables_changed(const std::map<SetVariableData, SetVariableResult>& set_variable_results);
426-
bool validate_set_variable(const SetVariableData& set_variable_data);
427-
428-
/// \brief Sets variables specified within \p set_variable_data_vector in the device model and returns the result.
429-
/// \param set_variable_data_vector contains data of the variables to set
430-
/// \param source value source (who sets the value, for example 'csms' or 'libocpp')
431-
/// \param allow_read_only if true, setting VariableAttribute values with mutability ReadOnly is allowed
432-
/// \return Map containing the SetVariableData as a key and the SetVariableResult as a value for each requested
433-
/// change
434-
std::map<SetVariableData, SetVariableResult>
435-
set_variables_internal(const std::vector<SetVariableData>& set_variable_data_vector, const std::string& source,
436-
const bool allow_read_only);
437-
438421
///
439422
/// \brief Check if EVSE connector is reserved for another than the given id token and / or group id token.
440423
/// \param evse The evse id that must be checked. Reservation will be checked for all connectors.
@@ -471,21 +454,8 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
471454

472455
/* OCPP message requests */
473456

474-
// Functional Block B: Provisioning
475-
void boot_notification_req(const BootReasonEnum& reason, const bool initiated_by_trigger_message = false);
476-
void notify_report_req(const int request_id, const std::vector<ReportData>& report_data);
477-
478457
/* OCPP message handlers */
479458

480-
// Functional Block B: Provisioning
481-
void handle_boot_notification_response(CallResult<BootNotificationResponse> call_result);
482-
void handle_set_variables_req(Call<SetVariablesRequest> call);
483-
void handle_get_variables_req(const EnhancedMessage<v201::MessageType>& message);
484-
void handle_get_base_report_req(Call<GetBaseReportRequest> call);
485-
void handle_get_report_req(const EnhancedMessage<v201::MessageType>& message);
486-
void handle_set_network_profile_req(Call<SetNetworkProfileRequest> call);
487-
void handle_reset_req(Call<ResetRequest> call);
488-
489459
// Function Block F: Remote transaction control
490460
void handle_unlock_connector(Call<UnlockConnectorRequest> call);
491461
void handle_remote_start_transaction_request(Call<RequestStartTransactionRequest> call);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Pionix GmbH and Contributors to EVerest
3+
4+
#pragma once
5+
6+
#include <ocpp/v201/message_handler.hpp>
7+
8+
#include <ocpp/v201/message_dispatcher.hpp>
9+
10+
namespace ocpp {
11+
class EvseSecurity;
12+
13+
namespace v201 {
14+
class DeviceModel;
15+
class ConnectivityManagerInterface;
16+
class ComponentStateManagerInterface;
17+
class OcspUpdaterInterface;
18+
class EvseManagerInterface;
19+
20+
class AvailabilityInterface;
21+
class SecurityInterface;
22+
class MeterValuesInterface;
23+
class DiagnosticsInterface;
24+
class TransactionInterface;
25+
26+
struct BootNotificationResponse;
27+
struct SetVariablesRequest;
28+
struct GetBaseReportRequest;
29+
struct ResetRequest;
30+
31+
typedef std::function<void(const ocpp::DateTime& currentTime)> TimeSyncCallback;
32+
typedef std::function<void(const ocpp::v201::BootNotificationResponse& boot_notification_response)>
33+
BootNotificationCallback;
34+
typedef std::function<SetNetworkProfileStatusEnum(const int32_t configuration_slot,
35+
const NetworkConnectionProfile& network_connection_profile)>
36+
ValidateNetworkProfileCallback;
37+
typedef std::function<bool(const std::optional<const int32_t> evse_id, const ResetEnum& reset_type)>
38+
IsResetAllowedCallback;
39+
typedef std::function<void(const std::optional<const int32_t> evse_id, const ResetEnum& reset_type)> ResetCallback;
40+
typedef std::function<RequestStartStopStatusEnum(const int32_t evse_id, const ReasonEnum& stop_reason)>
41+
StopTransactionCallback;
42+
typedef std::function<void(const SetVariableData& set_variable_data)> VariableChangedCallback;
43+
44+
class ProvisioningInterface : public MessageHandlerInterface {
45+
public:
46+
/* OCPP message requests */
47+
48+
// Functional Block B: Provisioning
49+
virtual void boot_notification_req(const BootReasonEnum& reason,
50+
const bool initiated_by_trigger_message = false) = 0;
51+
virtual void stop_bootnotification_timer() = 0;
52+
/// \brief Event handler that will update the variable internally when it has been changed on the fly.
53+
/// \param set_variable_data contains data of the variable to set
54+
///
55+
virtual void on_variable_changed(const SetVariableData& set_variable_data) = 0;
56+
57+
/// \brief Gets variables specified within \p get_variable_data_vector from the device model and returns the result.
58+
/// This function is used internally in order to handle GetVariables.req messages and it can be used to get
59+
/// variables externally.
60+
/// \param get_variable_data_vector contains data of the variables to get
61+
/// \return Vector containing a result for each requested variable
62+
virtual std::vector<GetVariableResult>
63+
get_variables(const std::vector<GetVariableData>& get_variable_data_vector) = 0;
64+
65+
/// \brief Sets variables specified within \p set_variable_data_vector in the device model and returns the result.
66+
/// \param set_variable_data_vector contains data of the variables to set
67+
/// \return Map containing the SetVariableData as a key and the SetVariableResult as a value for each requested
68+
/// change
69+
virtual std::map<SetVariableData, SetVariableResult>
70+
set_variables(const std::vector<SetVariableData>& set_variable_data_vector, const std::string& source) = 0;
71+
};
72+
73+
class Provisioning : public ProvisioningInterface {
74+
public:
75+
Provisioning(DeviceModel& device_model, MessageDispatcherInterface<MessageType>& message_dispatcher,
76+
MessageQueue<v201::MessageType>& message_queue, ConnectivityManagerInterface& connectivity_manager,
77+
ComponentStateManagerInterface& component_state_manager, OcspUpdaterInterface& ocsp_updater,
78+
EvseManagerInterface& evse_manager, EvseSecurity& evse_security,
79+
80+
AvailabilityInterface& availability, MeterValuesInterface& meter_values, SecurityInterface& security,
81+
DiagnosticsInterface& diagnostics, TransactionInterface& transaction,
82+
83+
std::optional<TimeSyncCallback> time_sync_callback,
84+
std::optional<BootNotificationCallback> boot_notification_callback,
85+
std::optional<ValidateNetworkProfileCallback> validate_network_profile_callback,
86+
IsResetAllowedCallback is_reset_allowed_callback, ResetCallback reset_callback,
87+
StopTransactionCallback stop_transaction_callback,
88+
std::optional<VariableChangedCallback> variable_changed_callback,
89+
90+
std::atomic<RegistrationStatusEnum>& registration_status);
91+
void handle_message(const ocpp::EnhancedMessage<MessageType>& message) override;
92+
void boot_notification_req(const BootReasonEnum& reason, const bool initiated_by_trigger_message = false) override;
93+
void stop_bootnotification_timer() override;
94+
void on_variable_changed(const SetVariableData& set_variable_data) override;
95+
std::vector<GetVariableResult> get_variables(const std::vector<GetVariableData>& get_variable_data_vector) override;
96+
std::map<SetVariableData, SetVariableResult>
97+
set_variables(const std::vector<SetVariableData>& set_variable_data_vector, const std::string& source) override;
98+
99+
private: // Members
100+
DeviceModel& device_model;
101+
MessageDispatcherInterface<MessageType>& message_dispatcher;
102+
MessageQueue<v201::MessageType>& message_queue;
103+
ConnectivityManagerInterface& connectivity_manager;
104+
ComponentStateManagerInterface& component_state_manager;
105+
OcspUpdaterInterface& ocsp_updater;
106+
EvseManagerInterface& evse_manager;
107+
EvseSecurity& evse_security;
108+
109+
AvailabilityInterface& availability;
110+
MeterValuesInterface& meter_values;
111+
SecurityInterface& security;
112+
DiagnosticsInterface& diagnostics;
113+
TransactionInterface& transaction;
114+
115+
std::optional<TimeSyncCallback> time_sync_callback;
116+
std::optional<BootNotificationCallback> boot_notification_callback;
117+
std::optional<ValidateNetworkProfileCallback> validate_network_profile_callback;
118+
IsResetAllowedCallback is_reset_allowed_callback;
119+
ResetCallback reset_callback;
120+
StopTransactionCallback stop_transaction_callback;
121+
std::optional<VariableChangedCallback> variable_changed_callback;
122+
123+
std::atomic<RegistrationStatusEnum>& registration_status;
124+
125+
Everest::SteadyTimer boot_notification_timer;
126+
127+
private: // Functions
128+
/* OCPP message requests */
129+
130+
void notify_report_req(const int request_id, const std::vector<ReportData>& report_data);
131+
132+
/* OCPP message handlers */
133+
134+
void handle_boot_notification_response(CallResult<BootNotificationResponse> call_result);
135+
void handle_set_variables_req(Call<SetVariablesRequest> call);
136+
void handle_get_variables_req(const EnhancedMessage<v201::MessageType>& message);
137+
void handle_get_base_report_req(Call<GetBaseReportRequest> call);
138+
void handle_get_report_req(const EnhancedMessage<v201::MessageType>& message);
139+
void handle_set_network_profile_req(Call<SetNetworkProfileRequest> call);
140+
void handle_reset_req(Call<ResetRequest> call);
141+
142+
/* Helper functions. */
143+
144+
/// \brief Helper function to determine if the requested change results in a state that the Connector(s) is/are
145+
/// already in \param request \return
146+
void handle_variable_changed(const SetVariableData& set_variable_data);
147+
void handle_variables_changed(const std::map<SetVariableData, SetVariableResult>& set_variable_results);
148+
bool validate_set_variable(const SetVariableData& set_variable_data);
149+
150+
/// \brief Sets variables specified within \p set_variable_data_vector in the device model and returns the result.
151+
/// \param set_variable_data_vector contains data of the variables to set
152+
/// \param source value source (who sets the value, for example 'csms' or 'libocpp')
153+
/// \param allow_read_only if true, setting VariableAttribute values with mutability ReadOnly is allowed
154+
/// \return Map containing the SetVariableData as a key and the SetVariableResult as a value for each requested
155+
/// change
156+
std::map<SetVariableData, SetVariableResult>
157+
set_variables_internal(const std::vector<SetVariableData>& set_variable_data_vector, const std::string& source,
158+
const bool allow_read_only);
159+
};
160+
} // namespace v201
161+
} // namespace ocpp

lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ if(LIBOCPP_ENABLE_V201)
103103
ocpp/v201/functional_blocks/diagnostics.cpp
104104
ocpp/v201/functional_blocks/display_message.cpp
105105
ocpp/v201/functional_blocks/meter_values.cpp
106+
ocpp/v201/functional_blocks/provisioning.cpp
106107
ocpp/v201/functional_blocks/tariff_and_cost.cpp
107108
ocpp/v201/functional_blocks/transaction.cpp
108109
)

0 commit comments

Comments
 (0)