ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
charge_point_impl.hpp
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
3#ifndef OCPP_V16_CHARGE_POINT_IMPL_HPP
4#define OCPP_V16_CHARGE_POINT_IMPL_HPP
5#include <atomic>
6#include <chrono>
7#include <date/date.h>
8#include <date/tz.h>
9#include <future>
10#include <iostream>
11#include <mutex>
12#include <ocpp/common/support_older_cpp_versions.hpp>
13#include <set>
14
15#include <everest/timer.hpp>
16
17#include <ocpp/common/aligned_timer.hpp>
18#include <ocpp/common/charging_station_base.hpp>
19#include <ocpp/common/message_dispatcher.hpp>
20#include <ocpp/common/message_queue.hpp>
21#include <ocpp/common/schemas.hpp>
22#include <ocpp/common/types.hpp>
23#include <ocpp/common/websocket/websocket.hpp>
24#include <ocpp/v16/charge_point_configuration.hpp>
25#include <ocpp/v16/connector.hpp>
26#include <ocpp/v16/database_handler.hpp>
27#include <ocpp/v16/message_dispatcher.hpp>
28#include <ocpp/v16/messages/Authorize.hpp>
29#include <ocpp/v16/messages/BootNotification.hpp>
30#include <ocpp/v16/messages/CancelReservation.hpp>
31#include <ocpp/v16/messages/CertificateSigned.hpp>
32#include <ocpp/v16/messages/ChangeAvailability.hpp>
33#include <ocpp/v16/messages/ChangeConfiguration.hpp>
34#include <ocpp/v16/messages/ClearCache.hpp>
35#include <ocpp/v16/messages/ClearChargingProfile.hpp>
36#include <ocpp/v16/messages/DataTransfer.hpp>
37#include <ocpp/v16/messages/DeleteCertificate.hpp>
38#include <ocpp/v16/messages/DiagnosticsStatusNotification.hpp>
39#include <ocpp/v16/messages/ExtendedTriggerMessage.hpp>
40#include <ocpp/v16/messages/FirmwareStatusNotification.hpp>
41#include <ocpp/v16/messages/GetCompositeSchedule.hpp>
42#include <ocpp/v16/messages/GetConfiguration.hpp>
43#include <ocpp/v16/messages/GetDiagnostics.hpp>
44#include <ocpp/v16/messages/GetInstalledCertificateIds.hpp>
45#include <ocpp/v16/messages/GetLocalListVersion.hpp>
46#include <ocpp/v16/messages/GetLog.hpp>
47#include <ocpp/v16/messages/Heartbeat.hpp>
48#include <ocpp/v16/messages/InstallCertificate.hpp>
49#include <ocpp/v16/messages/LogStatusNotification.hpp>
50#include <ocpp/v16/messages/MeterValues.hpp>
51#include <ocpp/v16/messages/RemoteStartTransaction.hpp>
52#include <ocpp/v16/messages/RemoteStopTransaction.hpp>
53#include <ocpp/v16/messages/ReserveNow.hpp>
54#include <ocpp/v16/messages/Reset.hpp>
55#include <ocpp/v16/messages/SecurityEventNotification.hpp>
56#include <ocpp/v16/messages/SendLocalList.hpp>
57#include <ocpp/v16/messages/SetChargingProfile.hpp>
58#include <ocpp/v16/messages/SignCertificate.hpp>
59#include <ocpp/v16/messages/SignedFirmwareStatusNotification.hpp>
60#include <ocpp/v16/messages/SignedUpdateFirmware.hpp>
61#include <ocpp/v16/messages/StartTransaction.hpp>
62#include <ocpp/v16/messages/StatusNotification.hpp>
63#include <ocpp/v16/messages/StopTransaction.hpp>
64#include <ocpp/v16/messages/TriggerMessage.hpp>
65#include <ocpp/v16/messages/UnlockConnector.hpp>
66#include <ocpp/v16/messages/UpdateFirmware.hpp>
67#include <ocpp/v16/ocpp_types.hpp>
68#include <ocpp/v16/smart_charging.hpp>
69#include <ocpp/v16/transaction.hpp>
70#include <ocpp/v16/types.hpp>
71
72// for OCPP1.6 PnC
73#include <ocpp/v2/messages/Authorize.hpp>
74#include <ocpp/v2/messages/CertificateSigned.hpp>
75#include <ocpp/v2/messages/DeleteCertificate.hpp>
76#include <ocpp/v2/messages/Get15118EVCertificate.hpp>
77#include <ocpp/v2/messages/GetCertificateStatus.hpp>
78#include <ocpp/v2/messages/GetInstalledCertificateIds.hpp>
79#include <ocpp/v2/messages/InstallCertificate.hpp>
80#include <ocpp/v2/messages/SignCertificate.hpp>
81#include <ocpp/v2/messages/TriggerMessage.hpp>
82
83namespace ocpp {
84namespace v16 {
85
88private:
89 BootReasonEnum bootreason;
90 ChargePointConnectionState connection_state;
91 bool boot_notification_callerror;
92 std::atomic<RegistrationStatus> registration_status;
93 DiagnosticsStatus diagnostics_status;
94 FirmwareStatus firmware_status;
95 bool firmware_update_is_pending = false;
96 UploadLogStatusEnumType log_status;
97 std::string message_log_path;
98
99 std::unique_ptr<Websocket> websocket;
100 std::unique_ptr<ocpp::MessageDispatcherInterface<MessageType>> message_dispatcher;
101 Everest::SteadyTimer websocket_timer;
102 std::unique_ptr<MessageQueue<v16::MessageType>> message_queue;
103 std::map<int32_t, std::shared_ptr<Connector>> connectors;
104 std::unique_ptr<SmartChargingHandler> smart_charging_handler;
105 int32_t heartbeat_interval;
106 bool stopped;
107 std::chrono::time_point<date::utc_clock> boot_time;
108 std::set<MessageType> allowed_message_types;
109 std::mutex allowed_message_types_mutex;
110 std::unique_ptr<ChargePointStates> status;
111 std::shared_ptr<ChargePointConfiguration> configuration;
112 std::shared_ptr<ocpp::v16::DatabaseHandler> database_handler;
113 std::unique_ptr<Everest::SteadyTimer> boot_notification_timer;
114 std::unique_ptr<Everest::SteadyTimer> heartbeat_timer;
115 std::unique_ptr<ClockAlignedTimer> clock_aligned_meter_values_timer;
116 std::vector<std::unique_ptr<Everest::SteadyTimer>> status_notification_timers;
117 std::unique_ptr<Everest::SteadyTimer> ocsp_request_timer;
118 std::unique_ptr<Everest::SteadyTimer> client_certificate_timer;
119 std::unique_ptr<Everest::SteadyTimer> v2g_certificate_timer;
120 std::unique_ptr<Everest::SystemTimer> change_time_offset_timer;
121 std::chrono::time_point<date::utc_clock> clock_aligned_meter_values_time_point;
122 std::mutex meter_values_mutex;
123 std::mutex measurement_mutex;
124 std::map<int32_t, AvailabilityChange> change_availability_queue; // TODO: move to Connectors
125 std::mutex change_availability_mutex; // TODO: move to Connectors
126 std::unique_ptr<TransactionHandler> transaction_handler;
127 std::vector<v16::MessageType> external_notify;
128
129 std::map<std::string,
130 std::map<std::string, std::function<DataTransferResponse(const std::optional<std::string>& msg)>>>
131 data_transfer_callbacks;
132 std::function<DataTransferResponse(const DataTransferRequest& request)> data_transfer_callback;
133 std::map<std::string, std::function<void(Call<DataTransferRequest> call)>> data_transfer_pnc_callbacks;
134 std::mutex data_transfer_callbacks_mutex;
135 std::map<CiString<50>, std::function<void(const KeyValue& key_value)>> configuration_key_changed_callbacks;
136 std::function<void(const KeyValue& key_value)> generic_configuration_key_changed_callback;
137
138 std::mutex stop_transaction_mutex;
139 std::condition_variable stop_transaction_cv;
140
141 std::thread reset_thread;
142
143 int log_status_request_id;
144
145 FirmwareStatusEnumType signed_firmware_status;
146 int signed_firmware_status_request_id;
147
149 std::chrono::seconds message_queue_resume_delay = std::chrono::seconds(0);
150
151 // callbacks
152 std::function<bool(int32_t connector)> enable_evse_callback;
153 std::function<bool(int32_t connector)> disable_evse_callback;
154 std::function<bool(int32_t connector)> pause_charging_callback;
155 std::function<bool(int32_t connector)> resume_charging_callback;
156 std::function<void(const std::string& id_token, std::vector<int32_t> referenced_connectors, bool prevalidated)>
157 provide_token_callback;
158 std::function<bool(int32_t connector, Reason reason)> stop_transaction_callback;
159 std::function<UnlockStatus(int32_t connector)> unlock_connector_callback;
160 std::function<bool(int32_t connector, int32_t max_current)> set_max_current_callback;
161 std::function<bool(const ResetType& reset_type)> is_reset_allowed_callback;
162 std::function<void(const ResetType& reset_type)> reset_callback;
163 std::function<void(const std::string& system_time)> set_system_time_callback;
164 std::function<void(const BootNotificationResponse& boot_notification_response)> boot_notification_response_callback;
165 std::function<void()> signal_set_charging_profiles_callback;
166 std::function<void(bool is_connected)> connection_state_changed_callback;
167
168 std::function<GetLogResponse(const GetDiagnosticsRequest& request)> upload_diagnostics_callback;
169 std::function<void(const UpdateFirmwareRequest msg)> update_firmware_callback;
170
171 std::function<UpdateFirmwareStatusEnumType(const SignedUpdateFirmwareRequest msg)> signed_update_firmware_callback;
172 std::function<void(const std::string& type, const std::string& tech_info)> security_event_callback;
173
174 std::function<void()> all_connectors_unavailable_callback;
175
176 std::function<ReservationStatus(int32_t reservation_id, int32_t connector, ocpp::DateTime expiryDate,
177 CiString<20> idTag, std::optional<CiString<20>> parent_id)>
178 reserve_now_callback;
179 std::function<bool(int32_t reservation_id)> cancel_reservation_callback;
180 std::function<void()> switch_security_profile_callback;
181 std::function<GetLogResponse(GetLogRequest msg)> upload_logs_callback;
182 std::function<void(int32_t connection_timeout)> set_connection_timeout_callback;
183
184 std::function<void(const int32_t connector, const std::string& session_id)> transaction_started_callback;
185 std::function<void(const int32_t connector, const std::string& session_id, const int32_t transaction_id,
186 const IdTagInfo& id_tag_info)>
187 transaction_updated_callback;
188 std::function<void(const int32_t connector, const std::string& session_id, const int32_t transaction_id)>
189 transaction_stopped_callback;
190 std::function<ocpp::ReservationCheckStatus(const int32_t connector, const std::string& id_token)>
191 is_token_reserved_for_connector_callback;
192
193 // iso15118 callback
194 std::function<void(const int32_t connector, const ocpp::v2::Get15118EVCertificateResponse& certificate_response,
195 const ocpp::v2::CertificateActionEnum& certificate_action)>
196 get_15118_ev_certificate_response_callback;
197
198 // tariff and cost callback
199 std::function<DataTransferResponse(const RunningCost& running_cost, const uint32_t number_of_decimals)>
200 session_cost_callback;
201 std::function<DataTransferResponse(const std::vector<DisplayMessage>& display_message)>
202 set_display_message_callback;
203
205 void connected_callback();
206 void init_websocket();
207 void init_state_machine(const std::map<int, ChargePointStatus>& connector_status_map);
208 WebsocketConnectionOptions get_ws_connection_options();
209 std::unique_ptr<ocpp::MessageQueue<v16::MessageType>> create_message_queue();
210 void message_callback(const std::string& message);
211 void handle_message(const EnhancedMessage<v16::MessageType>& message);
212 void heartbeat(bool initiated_by_trigger_message = false);
213 void boot_notification(bool initiated_by_trigger_message = false);
214 void clock_aligned_meter_values_sample();
215 void update_heartbeat_interval();
216 void update_meter_values_sample_interval();
217 void update_clock_aligned_meter_values_interval();
218 std::optional<MeterValue> get_latest_meter_value(int32_t connector,
219 std::vector<MeasurandWithPhase> values_of_interest,
220 ReadingContext context);
221 MeterValue get_signed_meter_value(const std::string& signed_value, const ReadingContext& context,
222 const ocpp::DateTime& datetime);
223 void send_meter_value(int32_t connector, MeterValue meter_value, bool initiated_by_trigger_message = false);
224 void send_meter_value_on_pricing_trigger(const int32_t connector_number, std::shared_ptr<Connector> connector,
225 const Measurement& measurement);
226 void reset_pricing_triggers(const int32_t connector_number);
227 void status_notification(const int32_t connector, const ChargePointErrorCode errorCode,
228 const ChargePointStatus status, const ocpp::DateTime& timestamp,
229 const std::optional<CiString<50>>& info = std::nullopt,
230 const std::optional<CiString<255>>& vendor_id = std::nullopt,
231 const std::optional<CiString<50>>& vendor_error_code = std::nullopt,
232 bool initiated_by_trigger_message = false);
233 void diagnostic_status_notification(DiagnosticsStatus status, bool initiated_by_trigger_message = false);
234 void firmware_status_notification(FirmwareStatus status, bool initiated_by_trigger_message = false);
235 void log_status_notification(UploadLogStatusEnumType status, int requestId,
236 bool initiated_by_trigger_message = false);
237 void signed_firmware_update_status_notification(FirmwareStatusEnumType status, int requestId,
238 bool initiated_by_trigger_message = false);
239
243 void change_all_connectors_to_unavailable_for_firmware_update();
244
250 void try_resume_transactions(const std::set<std::string>& resuming_session_ids);
251 void stop_all_transactions();
252 void stop_all_transactions(Reason reason);
253 bool validate_against_cache_entries(CiString<20> id_tag);
254
255 // new transaction handling:
256 void start_transaction(std::shared_ptr<Transaction> transaction);
257
258 void stop_transaction(int32_t connector, Reason reason, std::optional<CiString<20>> id_tag_end);
259
263 std::vector<Measurand> get_measurands_vec(const std::string& measurands_csv);
264
268 std::vector<TransactionData> get_filtered_transaction_data(const std::shared_ptr<Transaction>& transaction);
269
271 void load_charging_profiles();
272
273 // security
276 void sign_certificate(const ocpp::CertificateSigningUseEnum& certificate_signing_use,
277 bool initiated_by_trigger_message = false);
278
281 void update_ocsp_cache();
282
283 // core profile
284 void handleBootNotificationResponse(
285 CallResult<BootNotificationResponse> call_result); // TODO(kai):: async/promise based version?
286 void handleChangeAvailabilityRequest(Call<ChangeAvailabilityRequest> call);
287 void handleChangeConfigurationRequest(Call<ChangeConfigurationRequest> call);
288 void handleClearCacheRequest(Call<ClearCacheRequest> call);
289 void handleDataTransferRequest(Call<DataTransferRequest> call);
290 void handleGetConfigurationRequest(Call<GetConfigurationRequest> call);
291 void handleRemoteStartTransactionRequest(Call<RemoteStartTransactionRequest> call);
292 void handleRemoteStopTransactionRequest(Call<RemoteStopTransactionRequest> call);
293 void handleResetRequest(Call<ResetRequest> call);
294 void handleStartTransactionResponse(CallResult<StartTransactionResponse> call_result);
295 void handleStopTransactionResponse(const EnhancedMessage<v16::MessageType>& message);
296 void handleUnlockConnectorRequest(Call<UnlockConnectorRequest> call);
297 void handleHeartbeatResponse(CallResult<HeartbeatResponse> call_result);
298
299 // smart charging profile
300 void handleSetChargingProfileRequest(Call<SetChargingProfileRequest> call);
301 void handleGetCompositeScheduleRequest(Call<GetCompositeScheduleRequest> call);
302 void handleClearChargingProfileRequest(Call<ClearChargingProfileRequest> call);
303
304 // plug&charge for 1.6 whitepaper
305 bool is_pnc_enabled();
306 void data_transfer_pnc_sign_certificate();
307 void data_transfer_pnc_get_certificate_status(const ocpp::v2::OCSPRequestData& ocsp_request_data);
308
309 void handle_data_transfer_pnc_trigger_message(Call<DataTransferRequest> call);
310 void handle_data_transfer_pnc_certificate_signed(Call<DataTransferRequest> call);
311 void handle_data_transfer_pnc_get_installed_certificates(Call<DataTransferRequest> call);
312 void handle_data_transfer_delete_certificate(Call<DataTransferRequest> call);
313 void handle_data_transfer_install_certificate(Call<DataTransferRequest> call);
314
317 void handleReserveNowRequest(Call<ReserveNowRequest> call);
318
322 void handleCancelReservationRequest(Call<CancelReservationRequest> call);
323
324 // RemoteTrigger profile
325 void handleTriggerMessageRequest(Call<TriggerMessageRequest> call);
326
327 // FirmwareManagement profile
328 void handleGetDiagnosticsRequest(Call<GetDiagnosticsRequest> call);
329 void handleUpdateFirmwareRequest(Call<UpdateFirmwareRequest> call);
330
331 // Security profile
332 void handleExtendedTriggerMessageRequest(Call<ExtendedTriggerMessageRequest> call);
333 void handleCertificateSignedRequest(Call<CertificateSignedRequest> call);
334 void handleGetInstalledCertificateIdsRequest(Call<GetInstalledCertificateIdsRequest> call);
335 void handleDeleteCertificateRequest(Call<DeleteCertificateRequest> call);
336 void handleInstallCertificateRequest(Call<InstallCertificateRequest> call);
337 void handleGetLogRequest(Call<GetLogRequest> call);
338 void handleSignedUpdateFirmware(Call<SignedUpdateFirmwareRequest> call);
339 void securityEventNotification(const CiString<50>& event_type, const std::optional<CiString<255>>& tech_info,
340 const bool triggered_internally, const std::optional<bool>& critical = std::nullopt,
341 const std::optional<DateTime>& timestamp = std::nullopt);
342 void switchSecurityProfile(int32_t new_security_profile, int32_t max_connection_attempts);
343 // Local Authorization List profile
344 void handleSendLocalListRequest(Call<SendLocalListRequest> call);
345 void handleGetLocalListVersionRequest(Call<GetLocalListVersionRequest> call);
346
347 // California Pricing
348 DataTransferResponse handle_set_user_price(const std::optional<std::string>& msg);
349 DataTransferResponse handle_set_session_cost(const RunningCostState& type,
350 const std::optional<std::string>& message);
356 void set_connector_trigger_metervalue_timer(const DateTime& date_time, std::shared_ptr<Connector> connector);
357
362 void set_time_offset_timer(const std::string& date_time);
363
364 // //brief Preprocess a ChangeAvailabilityRequest: Determine response;
365 // - if connector is 0, availability change is also propagated for all connectors
366 // - for each connector (except "0"), if transaction is ongoing the change is scheduled,
367 // otherwise the OCPP connector id is appended to the `accepted_connector_availability_changes` vector
368 void preprocess_change_availability_request(const ChangeAvailabilityRequest& request,
370 std::vector<int32_t>& accepted_connector_availability_changes);
371
372 // \brief TExecutes availability change for the provided connectors:
373 // - if persist == true: store availability in database
374 // - submit state event (for the whole ChargePoint if "0" in set of connectors; otherwise for each connector
375 // individually)
376 // - call according EVSE enable or disable callback, respectively
380 void execute_connectors_availability_change(const std::vector<int32_t>& changed_connectors,
381 const ocpp::v16::AvailabilityType availability, bool persist);
382
383public:
403 explicit ChargePointImpl(const std::string& config, const fs::path& share_path, const fs::path& user_config_path,
404 const fs::path& database_path, const fs::path& sql_init_path,
405 const fs::path& message_log_path, const std::shared_ptr<EvseSecurity> evse_security,
406 const std::optional<SecurityConfiguration> security_configuration);
407
409 }
410
422 bool start(const std::map<int, ChargePointStatus>& connector_status_map, BootReasonEnum bootreason,
423 const std::set<std::string>& resuming_session_ids);
424
431 bool restart(const std::map<int, ChargePointStatus>& connector_status_map, BootReasonEnum bootreason);
432
436 void reset_state_machine(const std::map<int, ChargePointStatus>& connector_status_map);
437
440 bool stop();
441
443 void connect_websocket();
444
447
451
452 // public API for Core profile
453
459 IdTagInfo authorize_id_token(CiString<20> id_token, const bool authorize_only_locally = false);
460
461 // for plug&charge 1.6 whitepaper
462
471 const std::string& emaid, const std::optional<std::string>& certificate,
472 const std::optional<std::vector<ocpp::v2::OCSPRequestData>>& iso15118_certificate_hash_data);
473
481 void data_transfer_pnc_get_15118_ev_certificate(const int32_t connector_id, const std::string& exi_request,
482 const std::string& iso15118_schema_version,
483 const ocpp::v2::CertificateActionEnum& certificate_action);
484
492 std::optional<DataTransferResponse> data_transfer(const CiString<255>& vendorId,
493 const std::optional<CiString<50>>& messageId,
494 const std::optional<std::string>& data);
495
501 std::map<int32_t, ChargingSchedule>
502 get_all_composite_charging_schedules(const int32_t duration_s, const ChargingRateUnit unit = ChargingRateUnit::A);
503
510 std::map<int32_t, EnhancedChargingSchedule>
511 get_all_enhanced_composite_charging_schedules(const int32_t duration_s,
512 const ChargingRateUnit unit = ChargingRateUnit::A);
513
518 void on_meter_values(int32_t connector, const Measurement& measurement);
519
525 void on_max_current_offered(int32_t connector, int32_t max_current);
526
532 void on_max_power_offered(int32_t connector, int32_t max_power);
533
542 void on_session_started(int32_t connector, const std::string& session_id, const SessionStartedReason reason,
543 const std::optional<std::string>& session_logging_path);
544
549 void on_session_stopped(int32_t connector, const std::string& session_id);
550
561 void on_transaction_started(const int32_t& connector, const std::string& session_id, const std::string& id_token,
562 const double meter_start, std::optional<int32_t> reservation_id,
563 const ocpp::DateTime& timestamp, std::optional<std::string> signed_meter_value);
564
576 void on_transaction_stopped(const int32_t connector, const std::string& session_id, const Reason& reason,
577 ocpp::DateTime timestamp, float energy_wh_import,
578 std::optional<CiString<20>> id_tag_end, std::optional<std::string> signed_meter_value);
579
583 void on_suspend_charging_ev(int32_t connector, const std::optional<CiString<50>> info = std::nullopt);
584
588 void on_suspend_charging_evse(int32_t connector, const std::optional<CiString<50>> info = std::nullopt);
589
592 void on_resume_charging(int32_t connector);
593
601 void on_error(int32_t connector, const ErrorInfo& error_info);
602
609 void on_error_cleared(int32_t connector, const std::string uuid);
610
614 void on_all_errors_cleared(int32_t connector);
615
623 void on_log_status_notification(int32_t request_id, std::string log_status);
624
630 void on_firmware_update_status_notification(int32_t request_id,
631 const ocpp::FirmwareStatusNotification firmware_update_status);
632
635 void on_reservation_start(int32_t connector);
636
639 void on_reservation_end(int32_t connector);
640
644 void on_enabled(int32_t connector);
645
649 void on_disabled(int32_t connector);
650
653 void on_plugin_timeout(int32_t connector);
654
663 void on_security_event(const CiString<50>& event_type, const std::optional<CiString<255>>& tech_info,
664 const std::optional<bool>& critical = std::nullopt,
665 const std::optional<DateTime>& timestamp = std::nullopt);
666
670
677 const CiString<255>& vendorId, const CiString<50>& messageId,
678 const std::function<DataTransferResponse(const std::optional<std::string>& msg)>& callback);
679
684 const std::function<DataTransferResponse(const DataTransferRequest& request)>& callback);
685
689 void register_enable_evse_callback(const std::function<bool(int32_t connector)>& callback);
690
694 void register_disable_evse_callback(const std::function<bool(int32_t connector)>& callback);
695
699 void register_pause_charging_callback(const std::function<bool(int32_t connector)>& callback);
700
703 void register_resume_charging_callback(const std::function<bool(int32_t connector)>& callback);
704
711 const std::function<void(const std::string& id_token, std::vector<int32_t> referenced_connectors,
712 bool prevalidated)>& callback);
713
720 void register_stop_transaction_callback(const std::function<bool(int32_t connector, Reason reason)>& callback);
721
726 const std::function<ReservationStatus(int32_t reservation_id, int32_t connector, ocpp::DateTime expiryDate,
727 CiString<20> idTag, std::optional<CiString<20>> parent_id)>& callback);
728
733 void register_cancel_reservation_callback(const std::function<bool(int32_t reservation_id)>& callback);
734
736 // active at the specified connector, the \p callback shall stop the transaction before unlocking the connector. The
737 // unlock_connector_callback is called:
742 void register_unlock_connector_callback(const std::function<UnlockStatus(int32_t connector)>& callback);
743
750 const std::function<GetLogResponse(const GetDiagnosticsRequest& request)>& callback);
751
757 void register_update_firmware_callback(const std::function<void(const UpdateFirmwareRequest msg)>& callback);
758
765 const std::function<UpdateFirmwareStatusEnumType(const SignedUpdateFirmwareRequest msg)>& callback);
766
769 void register_all_connectors_unavailable_callback(const std::function<void()>& callback);
770
776 void register_upload_logs_callback(const std::function<GetLogResponse(GetLogRequest req)>& callback);
777
782 void register_set_connection_timeout_callback(const std::function<void(int32_t connection_timeout)>& callback);
783
787 void register_is_reset_allowed_callback(const std::function<bool(const ResetType& reset_type)>& callback);
788
793 void register_reset_callback(const std::function<void(const ResetType& reset_type)>& callback);
794
797 void register_set_system_time_callback(const std::function<void(const std::string& system_time)>& callback);
798
802 const std::function<void(const BootNotificationResponse& boot_notification_response)>& callback);
803
809 void register_signal_set_charging_profiles_callback(const std::function<void()>& callback);
810
814 void register_connection_state_changed_callback(const std::function<void(bool is_connected)>& callback);
815
821 const std::function<void(const int32_t connector,
822 const ocpp::v2::Get15118EVCertificateResponse& certificate_response,
823 const ocpp::v2::CertificateActionEnum& certificate_action)>& callback);
824
829 const std::function<void(const int32_t connector, const std::string& session_id)>& callback);
830
835 const std::function<void(const int32_t connector, const std::string& session_id, const int32_t transaction_id)>&
836 callback);
837
842 const std::function<void(const int32_t connector, const std::string& session_id, const int32_t transaction_id,
843 const IdTagInfo& id_tag_info)>
844 callback);
845
851 const std::function<void(const KeyValue& key_value)>& callback);
852
857 void
858 register_generic_configuration_key_changed_callback(const std::function<void(const KeyValue& key_value)>& callback);
859
863 const std::function<void(const std::string& type, const std::string& tech_info)>& callback);
864
870 const std::function<ReservationCheckStatus(const int32_t connector, const std::string& id_token)>& callback);
871
872 void register_session_cost_callback(
873 const std::function<DataTransferResponse(const RunningCost& running_cost, const uint32_t number_of_decimals)>&
874 session_cost_callback);
875 void register_set_display_message_callback(
876 const std::function<DataTransferResponse(const std::vector<DisplayMessage>&)> set_display_message_callback);
877
882
887 ConfigurationStatus set_custom_configuration_key(CiString<50> key, CiString<500> value);
888
891 void set_message_queue_resume_delay(std::chrono::seconds delay) {
892 this->message_queue_resume_delay = delay;
893 }
894};
895
896} // namespace v16
897} // namespace ocpp
898#endif
Common base class for OCPP1.6 and OCPP2.0.1 charging stations.
Definition: charging_station_base.hpp:16
Contains a DateTime implementation that can parse and create RFC 3339 compatible strings.
Definition: types.hpp:109
Contains a ChargePoint implementation compatible with OCPP-J 1.6.
Definition: charge_point_impl.hpp:87
ChargePointImpl(const std::string &config, const fs::path &share_path, const fs::path &user_config_path, const fs::path &database_path, const fs::path &sql_init_path, const fs::path &message_log_path, const std::shared_ptr< EvseSecurity > evse_security, const std::optional< SecurityConfiguration > security_configuration)
The main entrypoint for libOCPP for OCPP 1.6.
Definition: charge_point_impl.cpp:38
void register_set_connection_timeout_callback(const std::function< void(int32_t connection_timeout)> &callback)
registers a callback function that can be used to set the authorization or plug in connection timeout...
Definition: charge_point_impl.cpp:4539
std::map< int32_t, EnhancedChargingSchedule > get_all_enhanced_composite_charging_schedules(const int32_t duration_s, const ChargingRateUnit unit=ChargingRateUnit::A)
Calculates EnhancedChargingSchedule(s) configured by the CSMS of all connectors from now until now + ...
Definition: charge_point_impl.cpp:3436
void register_set_system_time_callback(const std::function< void(const std::string &system_time)> &callback)
registers a callback function that can be used to set the system time.
Definition: charge_point_impl.cpp:4502
ConfigurationStatus set_custom_configuration_key(CiString< 50 > key, CiString< 500 > value)
Sets a custom configuration key.
Definition: charge_point_impl.cpp:4684
void connect_websocket()
Initializes the websocket and connects to CSMS if it is not yet connected.
Definition: charge_point_impl.cpp:398
void on_transaction_started(const int32_t &connector, const std::string &session_id, const std::string &id_token, const double meter_start, std::optional< int32_t > reservation_id, const ocpp::DateTime &timestamp, std::optional< std::string > signed_meter_value)
Notifies chargepoint that a transaction at the given connector with the given parameters has been sta...
Definition: charge_point_impl.cpp:4142
void on_all_errors_cleared(int32_t connector)
Clears all previously reported errors at the same time for the given connector . This will clear a pr...
Definition: charge_point_impl.cpp:4377
void register_data_transfer_callback(const CiString< 255 > &vendorId, const CiString< 50 > &messageId, const std::function< DataTransferResponse(const std::optional< std::string > &msg)> &callback)
Definition: charge_point_impl.cpp:4036
void register_provide_token_callback(const std::function< void(const std::string &id_token, std::vector< int32_t > referenced_connectors, bool prevalidated)> &callback)
registers a callback function that can be used to provide an id_token for the given referenced_connec...
Definition: charge_point_impl.cpp:4467
void on_plugin_timeout(int32_t connector)
Notifies chargepoint that a ConnectionTimeout occured for the given connector . This function should ...
Definition: charge_point_impl.cpp:4622
GetConfigurationResponse get_configuration_key(const GetConfigurationRequest &request)
Gets the configured configuration key requested in the given request.
Definition: charge_point_impl.cpp:4648
void register_transaction_stopped_callback(const std::function< void(const int32_t connector, const std::string &session_id, const int32_t transaction_id)> &callback)
registers a callback function that is called when a StopTransaction.req message is sent by the charge...
Definition: charge_point_impl.cpp:4561
ocpp::v2::AuthorizeResponse data_transfer_pnc_authorize(const std::string &emaid, const std::optional< std::string > &certificate, const std::optional< std::vector< ocpp::v2::OCSPRequestData > > &iso15118_certificate_hash_data)
Uses data_transfer mechanism to authorize given emaid , certificate and iso15118_certificate_hash_dat...
Definition: charge_point_impl.cpp:3466
void on_error(int32_t connector, const ErrorInfo &error_info)
This function should be called if an error with the given error_info is present. This function will t...
Definition: charge_point_impl.cpp:4369
void on_max_power_offered(int32_t connector, int32_t max_power)
Stores the given max_power for the given connector offered to the EV. This function can be called whe...
Definition: charge_point_impl.cpp:4068
void set_message_queue_resume_delay(std::chrono::seconds delay)
Delay draining the message queue after reconnecting, so the CSMS can perform post-reconnect checks fi...
Definition: charge_point_impl.hpp:891
void register_boot_notification_response_callback(const std::function< void(const BootNotificationResponse &boot_notification_response)> &callback)
registers a callback function that can be used receive the BootNotificationResponse
Definition: charge_point_impl.cpp:4507
void register_all_connectors_unavailable_callback(const std::function< void()> &callback)
registers a callback function that is called when all connectors are set to unavailable....
Definition: charge_point_impl.cpp:4531
void on_disabled(int32_t connector)
Notifies chargepoint that the connector is disabled . This function should be called when the connect...
Definition: charge_point_impl.cpp:4618
void on_reservation_start(int32_t connector)
This function must be called when a reservation is started at the given connector .
Definition: charge_point_impl.cpp:4606
void on_firmware_update_status_notification(int32_t request_id, const ocpp::FirmwareStatusNotification firmware_update_status)
Chargepoint notifies about new firmware update status firmware_update_status . This function should b...
Definition: charge_point_impl.cpp:4395
void on_max_current_offered(int32_t connector, int32_t max_current)
Stores the given max_current for the given connector offered to the EV. This function can be called w...
Definition: charge_point_impl.cpp:4061
void on_meter_values(int32_t connector, const Measurement &measurement)
Stores the given powermeter values for the given connector . This function can be called when a new m...
Definition: charge_point_impl.cpp:4048
void register_upload_logs_callback(const std::function< GetLogResponse(GetLogRequest req)> &callback)
registers a callback function that can be used to upload logfiles. This callback should trigger a pro...
Definition: charge_point_impl.cpp:4535
void disconnect_websocket()
Disconnects the the websocket connection to the CSMS if it is connected.
Definition: charge_point_impl.cpp:404
bool start(const std::map< int, ChargePointStatus > &connector_status_map, BootReasonEnum bootreason, const std::set< std::string > &resuming_session_ids)
Starts the ChargePoint, initializes and connects to the Websocket endpoint and initializes a BootNoti...
Definition: charge_point_impl.cpp:1086
IdTagInfo authorize_id_token(CiString< 20 > id_token, const bool authorize_only_locally=false)
Authorizes the provided id_token against the central system, LocalAuthorizationList or AuthorizationC...
Definition: charge_point_impl.cpp:3334
ChangeAvailabilityResponse on_change_availability(const ChangeAvailabilityRequest &request)
Handles an internal ChangeAvailabilityRequest (in the same way as if it was emitted by the CSMS).
Definition: charge_point_impl.cpp:4632
void call_set_connection_timeout()
Calls the set_connection_timeout_callback that can be registered. This function is used to notify an ...
Definition: charge_point_impl.cpp:410
void register_get_15118_ev_certificate_response_callback(const std::function< void(const int32_t connector, const ocpp::v2::Get15118EVCertificateResponse &certificate_response, const ocpp::v2::CertificateActionEnum &certificate_action)> &callback)
registers a callback function that can be used to publish the response to a Get15118Certificate....
Definition: charge_point_impl.cpp:4549
void on_suspend_charging_evse(int32_t connector, const std::optional< CiString< 50 > > info=std::nullopt)
This function should be called when EVSE indicates that it suspends charging on the given connector.
Definition: charge_point_impl.cpp:4361
bool restart(const std::map< int, ChargePointStatus > &connector_status_map, BootReasonEnum bootreason)
Restarts the ChargePoint if it has been stopped before. The ChargePoint is reinitialized,...
Definition: charge_point_impl.cpp:1130
std::map< int32_t, ChargingSchedule > get_all_composite_charging_schedules(const int32_t duration_s, const ChargingRateUnit unit=ChargingRateUnit::A)
Calculates ChargingProfiles configured by the CSMS of all connectors from now until now + given durat...
Definition: charge_point_impl.cpp:3409
void register_update_firmware_callback(const std::function< void(const UpdateFirmwareRequest msg)> &callback)
registers a callback function that can be used to trigger a firmware update. This callback should tri...
Definition: charge_point_impl.cpp:4521
void register_reset_callback(const std::function< void(const ResetType &reset_type)> &callback)
registers a callback function that can be used to trigger a reset of the chargepoint....
Definition: charge_point_impl.cpp:4498
void on_reservation_end(int32_t connector)
This function must be called when a reservation ends at the given connector.
Definition: charge_point_impl.cpp:4610
void on_log_status_notification(int32_t request_id, std::string log_status)
Chargepoint notifies about new log status log_status . This function should be called during a Diagno...
Definition: charge_point_impl.cpp:4381
void register_disable_evse_callback(const std::function< bool(int32_t connector)> &callback)
registers a callback function that can be used to disable the evse. The disable_evse_callback is call...
Definition: charge_point_impl.cpp:4455
void register_enable_evse_callback(const std::function< bool(int32_t connector)> &callback)
registers a callback function that can be used to enable the evse. The enable_evse_callback is called...
Definition: charge_point_impl.cpp:4451
void data_transfer_pnc_get_15118_ev_certificate(const int32_t connector_id, const std::string &exi_request, const std::string &iso15118_schema_version, const ocpp::v2::CertificateActionEnum &certificate_action)
Uses data transfer mechanism to get 15118 ev certificate from CSMS. This function can be called when ...
Definition: charge_point_impl.cpp:3677
void register_transaction_started_callback(const std::function< void(const int32_t connector, const std::string &session_id)> &callback)
registers a callback function that is called when a StartTransaction.req message is sent by the charg...
Definition: charge_point_impl.cpp:4556
void register_stop_transaction_callback(const std::function< bool(int32_t connector, Reason reason)> &callback)
registers a callback function that can be used to stop a transaction. Ths stop_transaction_callback i...
Definition: charge_point_impl.cpp:4473
void register_is_reset_allowed_callback(const std::function< bool(const ResetType &reset_type)> &callback)
registers a callback function that can be used to check if a reset is allowed . The is_reset_allowed_...
Definition: charge_point_impl.cpp:4493
void register_pause_charging_callback(const std::function< bool(int32_t connector)> &callback)
registers a callback function that can be used to pause charging. The pause_charging_callback is call...
Definition: charge_point_impl.cpp:4459
void on_session_started(int32_t connector, const std::string &session_id, const SessionStartedReason reason, const std::optional< std::string > &session_logging_path)
Notifies chargepoint that a new session with the given session_id has been started at the given conne...
Definition: charge_point_impl.cpp:4112
void on_resume_charging(int32_t connector)
This function should be called when charging resumes on the given connector.
Definition: charge_point_impl.cpp:4365
void register_configuration_key_changed_callback(const CiString< 50 > &key, const std::function< void(const KeyValue &key_value)> &callback)
registers a callback function that can be used to react on changed configuration keys....
Definition: charge_point_impl.cpp:4574
void register_signal_set_charging_profiles_callback(const std::function< void()> &callback)
registers a callback function that can be used to signal that the chargepoint received a SetChargingP...
Definition: charge_point_impl.cpp:4512
void register_security_event_callback(const std::function< void(const std::string &type, const std::string &tech_info)> &callback)
registers a callback function that can be used to react to a security event callback....
Definition: charge_point_impl.cpp:4584
void on_error_cleared(int32_t connector, const std::string uuid)
This function should be called if an error with the given uuid has been cleared. If this leads to the...
Definition: charge_point_impl.cpp:4373
bool stop()
Stops the ChargePoint, stops timers, transactions and the message queue and disconnects from the webs...
Definition: charge_point_impl.cpp:1196
void on_suspend_charging_ev(int32_t connector, const std::optional< CiString< 50 > > info=std::nullopt)
This function should be called when EV indicates that it suspends charging on the given connector.
Definition: charge_point_impl.cpp:4357
void on_transaction_stopped(const int32_t connector, const std::string &session_id, const Reason &reason, ocpp::DateTime timestamp, float energy_wh_import, std::optional< CiString< 20 > > id_tag_end, std::optional< std::string > signed_meter_value)
Notifies chargepoint that the transaction on the given connector with the given reason has been stopp...
Definition: charge_point_impl.cpp:4196
void register_generic_configuration_key_changed_callback(const std::function< void(const KeyValue &key_value)> &callback)
registers a callback function that can be used to react on changed configuration key....
Definition: charge_point_impl.cpp:4579
void on_security_event(const CiString< 50 > &event_type, const std::optional< CiString< 255 > > &tech_info, const std::optional< bool > &critical=std::nullopt, const std::optional< DateTime > &timestamp=std::nullopt)
Notifies chargepoint that a SecurityEvent occurs. This will send a SecurityEventNotification....
Definition: charge_point_impl.cpp:4627
void register_resume_charging_callback(const std::function< bool(int32_t connector)> &callback)
registers a callback function that can be used to resume charging
Definition: charge_point_impl.cpp:4463
void on_session_stopped(int32_t connector, const std::string &session_id)
Notifies chargepoint that a session has been stopped at the given connector. This function must be ca...
Definition: charge_point_impl.cpp:4131
void register_is_token_reserved_for_connector_callback(const std::function< ReservationCheckStatus(const int32_t connector, const std::string &id_token)> &callback)
registers a callback function that can be used to check, if the connector is reserved for the given i...
Definition: charge_point_impl.cpp:4589
void reset_state_machine(const std::map< int, ChargePointStatus > &connector_status_map)
Resets the internal state machine for the connectors using the given connector_status_map.
Definition: charge_point_impl.cpp:1145
void register_signed_update_firmware_callback(const std::function< UpdateFirmwareStatusEnumType(const SignedUpdateFirmwareRequest msg)> &callback)
registers a callback function that can be used to trigger a signed firmware update....
Definition: charge_point_impl.cpp:4526
std::optional< DataTransferResponse > data_transfer(const CiString< 255 > &vendorId, const std::optional< CiString< 50 > > &messageId, const std::optional< std::string > &data)
Allows the exchange of arbitrary data identified by a vendorId and messageId with a central system.
Definition: charge_point_impl.cpp:3992
void register_transaction_updated_callback(const std::function< void(const int32_t connector, const std::string &session_id, const int32_t transaction_id, const IdTagInfo &id_tag_info)> callback)
registers a callback function that is called when a StartTransaction.conf message is received by the ...
Definition: charge_point_impl.cpp:4567
void register_unlock_connector_callback(const std::function< UnlockStatus(int32_t connector)> &callback)
registers a callback function that can be used to unlock the connector. In case a transaction is
Definition: charge_point_impl.cpp:4488
void register_connection_state_changed_callback(const std::function< void(bool is_connected)> &callback)
registers a callback function that can be used when the connection state to CSMS changes....
Definition: charge_point_impl.cpp:4544
void register_reserve_now_callback(const std::function< ReservationStatus(int32_t reservation_id, int32_t connector, ocpp::DateTime expiryDate, CiString< 20 > idTag, std::optional< CiString< 20 > > parent_id)> &callback)
registers a callback function that can be used to reserve a connector for a idTag until a timeout is ...
Definition: charge_point_impl.cpp:4478
void register_upload_diagnostics_callback(const std::function< GetLogResponse(const GetDiagnosticsRequest &request)> &callback)
registers a callback function that can be used to trigger an upload of diagnostics....
Definition: charge_point_impl.cpp:4516
void register_cancel_reservation_callback(const std::function< bool(int32_t reservation_id)> &callback)
registers a callback function that can be used to cancel a reservation on a connector....
Definition: charge_point_impl.cpp:4484
void on_enabled(int32_t connector)
Notifies chargepoint that the connector is enabled . This function should be called when the connecto...
Definition: charge_point_impl.cpp:4614
Contains a OCPP CallResult message.
Definition: call_types.hpp:105
Contains a OCPP Call message.
Definition: call_types.hpp:60
Contains a OCPP message in json form with additional information.
Definition: message_queue.hpp:54
Definition: types.hpp:339
Definition: types.hpp:414
Definition: websocket_base.hpp:18
Contains a OCPP BootNotificationResponse message.
Definition: BootNotification.hpp:46
Contains a OCPP ChangeAvailability message.
Definition: ChangeAvailability.hpp:17
Contains a OCPP ChangeAvailabilityResponse message.
Definition: ChangeAvailability.hpp:37
Contains a OCPP DataTransfer message.
Definition: DataTransfer.hpp:19
Contains a OCPP DataTransferResponse message.
Definition: DataTransfer.hpp:40
Contains all relevant information to handle errros in OCPP1.6.
Definition: charge_point_state_machine.hpp:41
Contains a OCPP GetConfiguration message.
Definition: GetConfiguration.hpp:18
Contains a OCPP GetConfigurationResponse message.
Definition: GetConfiguration.hpp:37
Contains a OCPP GetDiagnostics message.
Definition: GetDiagnostics.hpp:18
Contains a OCPP GetLog message.
Definition: GetLog.hpp:19
Contains a OCPP GetLogResponse message.
Definition: GetLog.hpp:42
Definition: ocpp_types.hpp:20
Definition: ocpp_types.hpp:83
Definition: ocpp_types.hpp:132
Contains a OCPP SignedUpdateFirmware message.
Definition: SignedUpdateFirmware.hpp:18
Contains a OCPP UpdateFirmware message.
Definition: UpdateFirmware.hpp:17
Contains a OCPP AuthorizeResponse message.
Definition: Authorize.hpp:41
Contains a OCPP Get15118EVCertificateResponse message.
Definition: Get15118EVCertificate.hpp:42
Definition: ocpp_types.hpp:52