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

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

#include <charge_point.hpp>

Public Member Functions

bool start (const std::map< int, ChargePointStatus > &connector_status_map={}, BootReasonEnum bootreason=BootReasonEnum::PowerUp, 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=BootReasonEnum::ApplicationReset)
 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)
 
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)
 Authorizes the provided id_token against the central system, LocalAuthorizationList or AuthorizationCache depending on the values of the ConfigurationKeys LocalPreAuthorize, LocalAuthorizeOffline, LocalAuthListEnabled and AuthorizationCacheEnabled. 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...
 
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...
 
Constructors for 1.6
 ChargePoint (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=std::nullopt)
 The main entrypoint for libOCPP for OCPP 1.6. More...
 
 ~ChargePoint ()
 
Handlers

The handlers

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 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...
 
Callbacks

Callbacks

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 successfully changed by the CSMS or internally using the set_custom_configuration_key function 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 and value. This callback is called when a configuration key 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 &session_cost, const uint32_t number_of_decimals)> &session_cost_callback)
 Registers a callback function for the session cost datatransfer message (California Pricing Requirements) More...
 
void register_set_display_message_callback (const std::function< DataTransferResponse(const std::vector< DisplayMessage > &)> set_display_message_callback)
 Register a callback function for display messages (used in California Pricing Requirements) More...
 

Detailed Description

Contains a ChargePoint implementation compatible with OCPP-J 1.6.

Member Function Documentation

◆ authorize_id_token()

IdTagInfo ocpp::v16::ChargePoint::authorize_id_token ( CiString< 20 >  id_token)

Authorizes the provided id_token against the central system, LocalAuthorizationList or AuthorizationCache depending on the values of the ConfigurationKeys LocalPreAuthorize, LocalAuthorizeOffline, LocalAuthListEnabled and AuthorizationCacheEnabled.

Returns
the IdTagInfo

◆ data_transfer()

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

◆ reset_state_machine()

void ocpp::v16::ChargePoint::reset_state_machine ( const std::map< int, ChargePointStatus > &  connector_status_map)
Parameters
connector_status_mapstate of connectors including connector 0 with reduced set of states (Available, Unavailable, Faulted)

◆ restart()

bool ocpp::v16::ChargePoint::restart ( const std::map< int, ChargePointStatus > &  connector_status_map = {},
BootReasonEnum  bootreason = BootReasonEnum::ApplicationReset 
)

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 start function

◆ set_custom_configuration_key()

ConfigurationStatus ocpp::v16::ChargePoint::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::ChargePoint::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.

Parameters
delayThe delay period (seconds)

◆ start()

bool ocpp::v16::ChargePoint::start ( const std::map< int, ChargePointStatus > &  connector_status_map = {},
BootReasonEnum  bootreason = BootReasonEnum::PowerUp,
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). connector_status_map is empty, last availability states from the persistant storage will be used
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: