ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
Public Member Functions | List of all members
ocpp::v16::ChargePointImpl Class Reference

Contains a ChargePoint implementation compatible with OCPP-J 1.6. More...

#include <charge_point_impl.hpp>

Inheritance diagram for ocpp::v16::ChargePointImpl:
ocpp::ChargingStationBase

Public Member Functions

 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. More...
 
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 BootNotification.req. More...
 
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, connects to the websocket and starts to communicate OCPP messages again. More...
 
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. More...
 
bool stop ()
 Stops the ChargePoint, stops timers, transactions and the message queue and disconnects from the websocket.
 
void connect_websocket ()
 Initializes the websocket and connects to CSMS if it is not yet connected.
 
void disconnect_websocket ()
 Disconnects the the websocket connection to the CSMS if it is connected.
 
void call_set_connection_timeout ()
 Calls the set_connection_timeout_callback that can be registered. This function is used to notify an Authorization mechanism about a changed ConnectionTimeout configuration key.
 
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 AuthorizationCache depending on the values of the ConfigurationKeys LocalPreAuthorize, LocalAuthorizeOffline, LocalAuthListEnabled and AuthorizationCacheEnabled. If authorize_only_locally is true, no Authorize.req will be sent to the CSMS but only LocalAuthorizationList and LocalAuthorizationCache will be used for the validation. More...
 
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_data locally or by requesting authorzation at CSMS. This function can be called when the authorization mechanism Plug&Charge is specified as part of the ISO15118 PaymentDetailsRequest. More...
 
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 the EVCC requests the update or installation of a contract certificate as part of the ISO15118 CertificateInstallRequest or CertificateUpdateRequest. More...
 
std::optional< DataTransferResponsedata_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. More...
 
std::map< int32_t, ChargingScheduleget_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 duration_s and the given unit. More...
 
std::map< int32_t, EnhancedChargingScheduleget_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 + given duration_s and the given unit . EnhancedChargingSchedules contain EnhancedChargingSchedulePeriod(s) that are enhanced by the stackLevel that was provided for the ChargingProfile. More...
 
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 meter value is present. More...
 
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 when the value for the maximum current for the connector changes. It will be used to report the Measurand Current_Offered if it is configured. More...
 
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 when the value for the maximum power for the connector changes. It will be used to report the Measurand Power_Offered if it is configured. More...
 
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 connector with the given reason . The logs of the session will be written into session_logging_path if present. This function must be called when first interaction with user or EV occurs. This can be a valid authorization or the connection of cable and/or EV to the given connector. More...
 
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 called when the EV disconnects from the given connector . More...
 
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 started. This function must be called at the point that all conditions for charging are met, for instance, EV is connected to Charge Point and user has been authorized. More...
 
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 stopped. This function must be called at the point where one of the preconditions for charging irrevocably becomes false, for instance when a user swipes to stop the transaction and the stop is authorized or if the EV disconnects. More...
 
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. More...
 
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. More...
 
void on_resume_charging (int32_t connector)
 This function should be called when charging resumes on the given connector. More...
 
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 trigger a StatusNotification.req containing the given error_info . It will change the present state of the state machine to faulted, in case the corresponding flag is set in the given error_info. This function can be called multiple times for different errors. Errors reported using this function stay active as long as they are cleared by on_error_cleared(). More...
 
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 fact that no other error is active anymore, this function will initiate a StatusNotification.req that reports the current state and no error. More...
 
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 previously reported "Faulted" state if present. More...
 
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 Diagnostics / Log upload to indicate the current log_status . More...
 
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 be called during a Firmware Update to indicate the current firmware_update_status . More...
 
void on_reservation_start (int32_t connector)
 This function must be called when a reservation is started at the given connector . More...
 
void on_reservation_end (int32_t connector)
 This function must be called when a reservation ends at the given connector. More...
 
void on_enabled (int32_t connector)
 Notifies chargepoint that the connector is enabled . This function should be called when the connector becomes functional and operational. More...
 
void on_disabled (int32_t connector)
 Notifies chargepoint that the connector is disabled . This function should be called when the connector becomes inoperative. More...
 
void on_plugin_timeout (int32_t connector)
 Notifies chargepoint that a ConnectionTimeout occured for the given connector . This function should be called when an EV is plugged in but the authorization is not present within the specified ConnectionTimeout.
 
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.req to the CSMS. More...
 
ChangeAvailabilityResponse on_change_availability (const ChangeAvailabilityRequest &request)
 Handles an internal ChangeAvailabilityRequest (in the same way as if it was emitted by the CSMS). More...
 
void register_data_transfer_callback (const CiString< 255 > &vendorId, const CiString< 50 > &messageId, const std::function< DataTransferResponse(const std::optional< std::string > &msg)> &callback)
 
void register_data_transfer_callback (const std::function< DataTransferResponse(const DataTransferRequest &request)> &callback)
 
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 when a ChangeAvailaibility.req is received. More...
 
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 called when a ChangeAvailaibility.req is received. More...
 
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 called when the idTagInfo.status of a StartTransaction.conf is not Accepted More...
 
void register_resume_charging_callback (const std::function< bool(int32_t connector)> &callback)
 registers a callback function that can be used to resume charging More...
 
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_connectors to an authorization handler. prevalidated signals to the authorization handler that no further authorization is necessary. The provide_token_callback is called when a RemoteStartTransaction.req is received. More...
 
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 is called More...
 
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 reached. The reserve_now_callback is called when a ReserveNow.req is received. More...
 
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. Callback function should return false if the reservation could not be cancelled, else true . The cancel_reservation_callback is called when a CancelReservation.req is received More...
 
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 More...
 
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. This callback should trigger a process of a diagnostics upload using the given parameters of the request. This process should call the on_log_status_notification handler in order to update the status of the file upload. The upload_diagnostics_callback is called when a GetDiagnostics.req is received More...
 
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 trigger a process of a firmware update using the given parameters of the request. This process should call the on_firmware_update_status_notification handler in order to update the status of the update. The update_firmware_callback is called when a FirmwareUpdate.req is received More...
 
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. This callback should trigger a process of a signed firmware update using the given parameters of the request. This process should call the on_firmware_update_status_notification handler in order to update the status of the signed firmware update. The signed_update_firmware_callback is called when a SignedUpdateFirmware.req is received. More...
 
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. This can be used to then trigger the installation of the firmware update
 
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 process of a log upload using the given parameters of the request. This process should call the on_log_status_notification handler in order to update the status of the file upload. The upload_logs_callback is called when a GetLog.req is received More...
 
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. The set_connection_timeout_callback is called when the configuration key ConnectionTimeout has been changed by the CSMS. More...
 
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_callback is called when a Reset.req is received. More...
 
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. The reset_callback is called when a Reset.req is received and a previous execution of the is_reset_allowed_callback returned true More...
 
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. More...
 
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 More...
 
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 SetChargingProfile.req . The set_charging_profiles_callback is called when a SetChargingProfile.req is received and was accepted. The registered callback could make use of the get_all_composite_charging_schedules in order to retrieve the ChargingProfiles that have been set by the CSMS. More...
 
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. The connection_state_changed_callback is called when chargepoint has connected to or disconnected from the CSMS. More...
 
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.req wrapped in a DataTransfer.req . The get_15118_ev_certificate_response_callback is called after the response to a DataTransfer.req(Get15118EVCertificate) has been accepted. More...
 
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 chargepoint More...
 
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 chargepoint More...
 
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 CSMS. This includes the transactionId. More...
 
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. This callback is called when a configuration key has been changed by the CSMS More...
 
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. This callback is called when a configuration key and value has been changed by the CSMS, where no key based callback is assigned More...
 
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. This callback is called only if the SecurityEvent occured internally within libocpp
 
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 id_token. The is_token_reserved_for_connector_callback is called when a RemoteStartTransaction.req is received. More...
 
void register_session_cost_callback (const std::function< DataTransferResponse(const RunningCost &running_cost, const uint32_t number_of_decimals)> &session_cost_callback)
 
void register_set_display_message_callback (const std::function< DataTransferResponse(const std::vector< DisplayMessage > &)> set_display_message_callback)
 
GetConfigurationResponse get_configuration_key (const GetConfigurationRequest &request)
 Gets the configured configuration key requested in the given request. More...
 
ConfigurationStatus set_custom_configuration_key (CiString< 50 > key, CiString< 500 > value)
 Sets a custom configuration key. More...
 
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 first. More...
 

Detailed Description

Contains a ChargePoint implementation compatible with OCPP-J 1.6.

Constructor & Destructor Documentation

◆ ChargePointImpl()

ocpp::v16::ChargePointImpl::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 
)
explicit

The main entrypoint for libOCPP for OCPP 1.6.

Parameters
configa nlohmann json config object that contains the libocpp 1.6 config. There are example configs that work with a SteVe installation running in Docker, for example: config/v16/config-docker.json
share_pathThis path contains the following files and directories and is installed by the libocpp install target
user_config_paththis points to a "user config", which we call a configuration file that's merged with the config that's provided in the "config" parameter. Here you can add, remove and overwrite settings without modifying the config passed in the first parameter directly. This is also used by libocpp to persistently modify config entries that are changed by the CSMS that should persist across restarts
database_paththis points to the location of the sqlite database that libocpp uses to keep track of connector availability, the authorization cache and auth list, charging profiles and transaction data
sql_init_paththis points to the init.sql file which contains the database schema used by libocpp for its sqlite database
message_log_paththis points to the directory in which libocpp can put OCPP communication logfiles for debugging purposes. This behavior can be controlled by the "LogMessages" (set to true by default) and "LogMessagesFormat" (set to ["log", "html", "session_logging"] by default, "console" and "console_detailed" are also available) configuration keys in the "Internal" section of the config file. Please note that this is intended for debugging purposes only as it logs all communication, including authentication messages.
evse_securityPointer to evse_security that manages security related operations

Member Function Documentation

◆ authorize_id_token()

IdTagInfo ocpp::v16::ChargePointImpl::authorize_id_token ( CiString< 20 >  id_token,
const bool  authorize_only_locally = false 
)

Authorizes the provided id_token against the central system, LocalAuthorizationList or AuthorizationCache depending on the values of the ConfigurationKeys LocalPreAuthorize, LocalAuthorizeOffline, LocalAuthListEnabled and AuthorizationCacheEnabled. If authorize_only_locally is true, no Authorize.req will be sent to the CSMS but only LocalAuthorizationList and LocalAuthorizationCache will be used for the validation.

Returns
the IdTagInfo

◆ data_transfer()

std::optional< DataTransferResponse > ocpp::v16::ChargePointImpl::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.

Returns
the DataTransferResponse
Parameters
vendorId
messageId
data
Returns
the DataTransferResponse from the CSMS. In case no response is received from the CSMS because the message timed out or the charging station is offline, std::nullopt is returned

◆ data_transfer_pnc_authorize()

ocpp::v2::AuthorizeResponse ocpp::v16::ChargePointImpl::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_data locally or by requesting authorzation at CSMS. This function can be called when the authorization mechanism Plug&Charge is specified as part of the ISO15118 PaymentDetailsRequest.

Parameters
emaid
certificatecontract certificate that the EVCC provides
iso15118_certificate_hash_data
Returns

◆ data_transfer_pnc_get_15118_ev_certificate()

void ocpp::v16::ChargePointImpl::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 the EVCC requests the update or installation of a contract certificate as part of the ISO15118 CertificateInstallRequest or CertificateUpdateRequest.

Parameters
connector_id
exi_requestprovided by the EVCC
iso15118_schema_versionprovided by the EVCC
certificate_actionInstall or Update

◆ get_all_composite_charging_schedules()

std::map< int32_t, ChargingSchedule > ocpp::v16::ChargePointImpl::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 duration_s and the given unit.

Parameters
duration_s
unitdefaults to A
Returns
ChargingSchedules of all connectors

◆ get_all_enhanced_composite_charging_schedules()

std::map< int32_t, EnhancedChargingSchedule > ocpp::v16::ChargePointImpl::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 + given duration_s and the given unit . EnhancedChargingSchedules contain EnhancedChargingSchedulePeriod(s) that are enhanced by the stackLevel that was provided for the ChargingProfile.

Parameters
duration_s
unitdefaults to A
Returns
ChargingSchedules of all connectors

◆ get_configuration_key()

GetConfigurationResponse ocpp::v16::ChargePointImpl::get_configuration_key ( const GetConfigurationRequest request)

Gets the configured configuration key requested in the given request.

Parameters
requestspecifies the keys that should be returned. If empty or not set, all keys will be reported
Returns
a response containing the requested key(s) including the values and unkown keys if present

◆ on_all_errors_cleared()

void ocpp::v16::ChargePointImpl::on_all_errors_cleared ( int32_t  connector)

Clears all previously reported errors at the same time for the given connector . This will clear a previously reported "Faulted" state if present.

Parameters
connector

◆ on_change_availability()

ChangeAvailabilityResponse ocpp::v16::ChargePointImpl::on_change_availability ( const ChangeAvailabilityRequest request)

Handles an internal ChangeAvailabilityRequest (in the same way as if it was emitted by the CSMS).

Parameters
request

◆ on_disabled()

void ocpp::v16::ChargePointImpl::on_disabled ( int32_t  connector)

Notifies chargepoint that the connector is disabled . This function should be called when the connector becomes inoperative.

Parameters
connector

◆ on_enabled()

void ocpp::v16::ChargePointImpl::on_enabled ( int32_t  connector)

Notifies chargepoint that the connector is enabled . This function should be called when the connector becomes functional and operational.

Parameters
connector

◆ on_error()

void ocpp::v16::ChargePointImpl::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 trigger a StatusNotification.req containing the given error_info . It will change the present state of the state machine to faulted, in case the corresponding flag is set in the given error_info. This function can be called multiple times for different errors. Errors reported using this function stay active as long as they are cleared by on_error_cleared().

Parameters
connector
error_infoAdditional information related to the error

◆ on_error_cleared()

void ocpp::v16::ChargePointImpl::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 fact that no other error is active anymore, this function will initiate a StatusNotification.req that reports the current state and no error.

Parameters
connector
uuidof a previously reported error. If uuid is not known, the event will be ignored

◆ on_firmware_update_status_notification()

void ocpp::v16::ChargePointImpl::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 be called during a Firmware Update to indicate the current firmware_update_status .

Parameters
request_idA request_id of -1 indicates a FirmwareStatusNotification.req, else a SignedFirmwareUpdateStatusNotification.req .
firmware_update_statusThe firmware_update_status

◆ on_log_status_notification()

void ocpp::v16::ChargePointImpl::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 Diagnostics / Log upload to indicate the current log_status .

Parameters
request_idA request_id of -1 indicates a DiagnosticsStatusNotification.req, else a LogStatusNotification.req.
log_statusThe log_status should be either be convertable to the ocpp::v16::UploadLogStatusEnumType enum or ocpp::v16::DiagnosticsStatus enum depending on the previous request, which could have been a DiagnosticsUpload.req or a GetLog.req (Security Whitepaper)

◆ on_max_current_offered()

void ocpp::v16::ChargePointImpl::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 when the value for the maximum current for the connector changes. It will be used to report the Measurand Current_Offered if it is configured.

Parameters
connector
max_currentin Amps

◆ on_max_power_offered()

void ocpp::v16::ChargePointImpl::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 when the value for the maximum power for the connector changes. It will be used to report the Measurand Power_Offered if it is configured.

Parameters
connector
max_powerin Watts

◆ on_meter_values()

void ocpp::v16::ChargePointImpl::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 meter value is present.

Parameters
connector
measurementstructure that can contain all kinds of measurands

◆ on_reservation_end()

void ocpp::v16::ChargePointImpl::on_reservation_end ( int32_t  connector)

This function must be called when a reservation ends at the given connector.

Parameters
connector

◆ on_reservation_start()

void ocpp::v16::ChargePointImpl::on_reservation_start ( int32_t  connector)

This function must be called when a reservation is started at the given connector .

Parameters
connector

◆ on_resume_charging()

void ocpp::v16::ChargePointImpl::on_resume_charging ( int32_t  connector)

This function should be called when charging resumes on the given connector.

Parameters
connector

◆ on_security_event()

void ocpp::v16::ChargePointImpl::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.req to the CSMS.

Parameters
event_typetype of the security event
tech_infoadditional info of the security event
criticalif set this overwrites the default criticality recommended in the OCPP 1.6 security whitepaper. A critical security event is transmitted as a message to the CSMS, a non-critical one is just written to the security log
timestampwhen this security event occured, if absent the current datetime is assumed

◆ on_session_started()

void ocpp::v16::ChargePointImpl::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 connector with the given reason . The logs of the session will be written into session_logging_path if present. This function must be called when first interaction with user or EV occurs. This can be a valid authorization or the connection of cable and/or EV to the given connector.

Parameters
connector
session_idunique id of the session
reasonfor the initiation of the session
session_logging_pathoptional filesystem path to where the session log should be written

◆ on_session_stopped()

void ocpp::v16::ChargePointImpl::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 called when the EV disconnects from the given connector .

Parameters
connector
session_id

◆ on_suspend_charging_ev()

void ocpp::v16::ChargePointImpl::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.

Parameters
connector
info

◆ on_suspend_charging_evse()

void ocpp::v16::ChargePointImpl::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.

Parameters
connector
info

◆ on_transaction_started()

void ocpp::v16::ChargePointImpl::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 started. This function must be called at the point that all conditions for charging are met, for instance, EV is connected to Charge Point and user has been authorized.

Parameters
connector
session_id
id_tokenthat has been used to authorize the transaction
meter_startstart meter value in Wh
reservation_id
timestampof the start of transaction
signed_meter_valuee.g. in OCMF format

◆ on_transaction_stopped()

void ocpp::v16::ChargePointImpl::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 stopped. This function must be called at the point where one of the preconditions for charging irrevocably becomes false, for instance when a user swipes to stop the transaction and the stop is authorized or if the EV disconnects.

Parameters
connector
session_id
reason
timestampof the end of transaction
energy_wh_importstop meter value in Wh
id_tag_end
signed_meter_valuee.g. in OCMF format

◆ register_boot_notification_response_callback()

void ocpp::v16::ChargePointImpl::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

Parameters
callback

◆ register_cancel_reservation_callback()

void ocpp::v16::ChargePointImpl::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. Callback function should return false if the reservation could not be cancelled, else true . The cancel_reservation_callback is called when a CancelReservation.req is received

Parameters
callback

◆ register_configuration_key_changed_callback()

void ocpp::v16::ChargePointImpl::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. This callback is called when a configuration key has been changed by the CSMS

Parameters
keythe configuration key for which the callback is registered
callbackexecuted when this configuration key changed

◆ register_connection_state_changed_callback()

void ocpp::v16::ChargePointImpl::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. The connection_state_changed_callback is called when chargepoint has connected to or disconnected from the CSMS.

Parameters
callback

◆ register_data_transfer_callback() [1/2]

void ocpp::v16::ChargePointImpl::register_data_transfer_callback ( const CiString< 255 > &  vendorId,
const CiString< 50 > &  messageId,
const std::function< DataTransferResponse(const std::optional< std::string > &msg)> &  callback 
)

registers a callback function that can be used to receive a arbitrary data transfer for the given vendorId and messageId

Parameters
vendorId
messageId
callback

◆ register_data_transfer_callback() [2/2]

void ocpp::v16::ChargePointImpl::register_data_transfer_callback ( const std::function< DataTransferResponse(const DataTransferRequest &request)> &  callback)

registers a callback function that can be used to handle arbitrary data transfers for all vendorId an messageId

Parameters
callback

◆ register_disable_evse_callback()

void ocpp::v16::ChargePointImpl::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 called when a ChangeAvailaibility.req is received.

Parameters
callback

◆ register_enable_evse_callback()

void ocpp::v16::ChargePointImpl::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 when a ChangeAvailaibility.req is received.

Parameters
callback

◆ register_generic_configuration_key_changed_callback()

void ocpp::v16::ChargePointImpl::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. This callback is called when a configuration key and value has been changed by the CSMS, where no key based callback is assigned

Parameters
callbackexecuted when this configuration key changed

◆ register_get_15118_ev_certificate_response_callback()

void ocpp::v16::ChargePointImpl::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.req wrapped in a DataTransfer.req . The get_15118_ev_certificate_response_callback is called after the response to a DataTransfer.req(Get15118EVCertificate) has been accepted.

Parameters
callback

◆ register_is_reset_allowed_callback()

void ocpp::v16::ChargePointImpl::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_callback is called when a Reset.req is received.

Parameters
callback

◆ register_is_token_reserved_for_connector_callback()

void ocpp::v16::ChargePointImpl::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 id_token. The is_token_reserved_for_connector_callback is called when a RemoteStartTransaction.req is received.

Parameters
callback

◆ register_pause_charging_callback()

void ocpp::v16::ChargePointImpl::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 called when the idTagInfo.status of a StartTransaction.conf is not Accepted

Parameters
callback

◆ register_provide_token_callback()

void ocpp::v16::ChargePointImpl::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_connectors to an authorization handler. prevalidated signals to the authorization handler that no further authorization is necessary. The provide_token_callback is called when a RemoteStartTransaction.req is received.

Parameters
callback

◆ register_reserve_now_callback()

void ocpp::v16::ChargePointImpl::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 reached. The reserve_now_callback is called when a ReserveNow.req is received.

Parameters
callback

◆ register_reset_callback()

void ocpp::v16::ChargePointImpl::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. The reset_callback is called when a Reset.req is received and a previous execution of the is_reset_allowed_callback returned true

Parameters
callback

◆ register_resume_charging_callback()

void ocpp::v16::ChargePointImpl::register_resume_charging_callback ( const std::function< bool(int32_t connector)> &  callback)

registers a callback function that can be used to resume charging

Parameters
callback

◆ register_set_connection_timeout_callback()

void ocpp::v16::ChargePointImpl::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. The set_connection_timeout_callback is called when the configuration key ConnectionTimeout has been changed by the CSMS.

Parameters
callback

◆ register_set_system_time_callback()

void ocpp::v16::ChargePointImpl::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.

Parameters
callback

◆ register_signal_set_charging_profiles_callback()

void ocpp::v16::ChargePointImpl::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 SetChargingProfile.req . The set_charging_profiles_callback is called when a SetChargingProfile.req is received and was accepted. The registered callback could make use of the get_all_composite_charging_schedules in order to retrieve the ChargingProfiles that have been set by the CSMS.

Parameters
callback

◆ register_signed_update_firmware_callback()

void ocpp::v16::ChargePointImpl::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. This callback should trigger a process of a signed firmware update using the given parameters of the request. This process should call the on_firmware_update_status_notification handler in order to update the status of the signed firmware update. The signed_update_firmware_callback is called when a SignedUpdateFirmware.req is received.

Parameters
callback

◆ register_stop_transaction_callback()

void ocpp::v16::ChargePointImpl::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 is called

  • when the idTagInfo.status of a StartTransaction.conf is not Accepted
  • when a RemoteStopTransaction.req is received
  • when a UnlockConnector.req is received
    Parameters
    callback

◆ register_transaction_started_callback()

void ocpp::v16::ChargePointImpl::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 chargepoint

Parameters
callback

◆ register_transaction_stopped_callback()

void ocpp::v16::ChargePointImpl::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 chargepoint

Parameters
callback

◆ register_transaction_updated_callback()

void ocpp::v16::ChargePointImpl::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 CSMS. This includes the transactionId.

Parameters
callback

◆ register_unlock_connector_callback()

void ocpp::v16::ChargePointImpl::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

  • when receiving a UnlockConnector.req and
  • when a transaction has on_transaction_stopped is called and the configuration key UnlockConnectorOnEVSideDisconnect is true
    Parameters
    callback

◆ register_update_firmware_callback()

void ocpp::v16::ChargePointImpl::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 trigger a process of a firmware update using the given parameters of the request. This process should call the on_firmware_update_status_notification handler in order to update the status of the update. The update_firmware_callback is called when a FirmwareUpdate.req is received

Parameters
callback

◆ register_upload_diagnostics_callback()

void ocpp::v16::ChargePointImpl::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. This callback should trigger a process of a diagnostics upload using the given parameters of the request. This process should call the on_log_status_notification handler in order to update the status of the file upload. The upload_diagnostics_callback is called when a GetDiagnostics.req is received

Parameters
callback

◆ register_upload_logs_callback()

void ocpp::v16::ChargePointImpl::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 process of a log upload using the given parameters of the request. This process should call the on_log_status_notification handler in order to update the status of the file upload. The upload_logs_callback is called when a GetLog.req is received

Parameters
callback

◆ reset_state_machine()

void ocpp::v16::ChargePointImpl::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.

Parameters
connector_status_mapstate of connectors including connector 0 with reduced set of states (Available, Unavailable, Faulted)

◆ restart()

bool ocpp::v16::ChargePointImpl::restart ( const std::map< int, ChargePointStatus > &  connector_status_map,
BootReasonEnum  bootreason 
)

Restarts the ChargePoint if it has been stopped before. The ChargePoint is reinitialized, connects to the websocket and starts to communicate OCPP messages again.

Parameters
connector_status_mapinitial state of connectors including connector 0 with reduced set of states (Available, Unavailable, Faulted). connector_status_map is empty, last availability states from the persistant storage will be used
bootreasonreason for calling the restart function

◆ set_custom_configuration_key()

ConfigurationStatus ocpp::v16::ChargePointImpl::set_custom_configuration_key ( CiString< 50 >  key,
CiString< 500 >  value 
)

Sets a custom configuration key.

Parameters
key
value
Returns
Indicates the result of the operation

◆ set_message_queue_resume_delay()

void ocpp::v16::ChargePointImpl::set_message_queue_resume_delay ( std::chrono::seconds  delay)
inline

Delay draining the message queue after reconnecting, so the CSMS can perform post-reconnect checks first.

Parameters
delayThe delay period (seconds)

◆ start()

bool ocpp::v16::ChargePointImpl::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 BootNotification.req.

Parameters
connector_status_mapinitial state of connectors including connector 0 with reduced set of states (Available, Unavailable, Faulted)
bootreasonreason for calling the start function
resuming_session_idscan optionally contain active session ids from previous executions. If empty and libocpp has transactions in its internal database that have not been stopped yet, calling this function will initiate a StopTransaction.req for those transactions. If this vector contains session_ids this function will not stop transactions with this session_id even in case it has an internal database entry for this session and it hasnt been stopped yet. Its ignored if this vector contains session_ids that are unknown to libocpp.
Returns

The documentation for this class was generated from the following files: