|
| 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 |
0 commit comments