Skip to content

Commit

Permalink
First commit transaction functional block.
Browse files Browse the repository at this point in the history
Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
  • Loading branch information
maaikez committed Feb 17, 2025
1 parent 50520ce commit 6349a4b
Show file tree
Hide file tree
Showing 5 changed files with 562 additions and 350 deletions.
34 changes: 2 additions & 32 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <ocpp/v201/functional_blocks/security.hpp>
#include <ocpp/v201/functional_blocks/smart_charging.hpp>
#include <ocpp/v201/functional_blocks/tariff_and_cost.hpp>
#include <ocpp/v201/functional_blocks/transaction.hpp>

#include <ocpp/common/charging_station_base.hpp>

Expand Down Expand Up @@ -46,7 +47,6 @@
#include <ocpp/v201/messages/GetLog.hpp>
#include <ocpp/v201/messages/GetMonitoringReport.hpp>
#include <ocpp/v201/messages/GetReport.hpp>
#include <ocpp/v201/messages/GetTransactionStatus.hpp>
#include <ocpp/v201/messages/GetVariables.hpp>
#include <ocpp/v201/messages/NotifyCustomerInformation.hpp>
#include <ocpp/v201/messages/NotifyEvent.hpp>
Expand All @@ -60,7 +60,6 @@
#include <ocpp/v201/messages/SetNetworkProfile.hpp>
#include <ocpp/v201/messages/SetVariableMonitoring.hpp>
#include <ocpp/v201/messages/SetVariables.hpp>
#include <ocpp/v201/messages/TransactionEvent.hpp>
#include <ocpp/v201/messages/TriggerMessage.hpp>
#include <ocpp/v201/messages/UnlockConnector.hpp>

Expand Down Expand Up @@ -256,11 +255,6 @@ class ChargePointInterface {

/// @}

/// \brief Gets the transaction id for a certain \p evse_id if there is an active transaction
/// \param evse_id The evse to tet the transaction for
/// \return The transaction id if a transaction is active, otherwise nullopt
virtual std::optional<std::string> get_evse_transaction_id(int32_t evse_id) = 0;

/// \brief Validates provided \p id_token \p certificate and \p ocsp_request_data using CSMS, AuthCache or AuthList
/// \param id_token
/// \param certificate
Expand Down Expand Up @@ -368,13 +362,12 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
std::unique_ptr<MeterValuesInterface> meter_values;
std::unique_ptr<SmartCharging> smart_charging;
std::unique_ptr<TariffAndCostInterface> tariff_and_cost;
std::unique_ptr<TransactionInterface> transaction;

// utility
std::shared_ptr<MessageQueue<v201::MessageType>> message_queue;
std::shared_ptr<DatabaseHandler> database_handler;

std::map<int32_t, std::pair<IdToken, int32_t>> remote_start_id_per_evse;

// timers
Everest::SteadyTimer boot_notification_timer;

Expand Down Expand Up @@ -405,11 +398,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

std::chrono::time_point<std::chrono::steady_clock> time_disconnected;

/// \brief Used when an 'OnIdle' reset is requested, to perform the reset after the charging has stopped.
bool reset_scheduled;
/// \brief If `reset_scheduled` is true and the reset is for a specific evse id, it will be stored in this member.
std::set<int32_t> reset_scheduled_evseids;

// callback struct
Callbacks callbacks;

Expand Down Expand Up @@ -487,18 +475,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
void boot_notification_req(const BootReasonEnum& reason, const bool initiated_by_trigger_message = false);
void notify_report_req(const int request_id, const std::vector<ReportData>& report_data);

// Functional Block E: Transactions
void transaction_event_req(const TransactionEventEnum& event_type, const DateTime& timestamp,
const ocpp::v201::Transaction& transaction,
const ocpp::v201::TriggerReasonEnum& trigger_reason, const int32_t seq_no,
const std::optional<int32_t>& cable_max_current,
const std::optional<ocpp::v201::EVSE>& evse,
const std::optional<ocpp::v201::IdToken>& id_token,
const std::optional<std::vector<ocpp::v201::MeterValue>>& meter_value,
const std::optional<int32_t>& number_of_phases_used, const bool offline,
const std::optional<int32_t>& reservation_id,
const bool initiated_by_trigger_message = false);

/* OCPP message handlers */

// Functional Block B: Provisioning
Expand All @@ -510,10 +486,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
void handle_set_network_profile_req(Call<SetNetworkProfileRequest> call);
void handle_reset_req(Call<ResetRequest> call);

// Functional Block E: Transaction
void handle_transaction_event_response(const EnhancedMessage<v201::MessageType>& message);
void handle_get_transaction_status(const Call<GetTransactionStatusRequest> call);

// Function Block F: Remote transaction control
void handle_unlock_connector(Call<UnlockConnectorRequest> call);
void handle_remote_start_transaction_request(Call<RequestStartTransactionRequest> call);
Expand Down Expand Up @@ -659,8 +631,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
const uint32_t evse_id, const ChargingStateEnum charging_state,
const TriggerReasonEnum trigger_reason = TriggerReasonEnum::ChargingStateChanged) override;

std::optional<std::string> get_evse_transaction_id(int32_t evse_id) override;

AuthorizeResponse validate_token(const IdToken id_token, const std::optional<CiString<5500>>& certificate,
const std::optional<std::vector<OCSPRequestData>>& ocsp_request_data) override;

Expand Down
153 changes: 153 additions & 0 deletions include/ocpp/v201/functional_blocks/transaction.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#pragma once

#include <ocpp/v201/message_handler.hpp>

#include <ocpp/v201/message_dispatcher.hpp>

namespace ocpp::v201 {
class DeviceModel;
class AuthorizationInterface;
class ConnectivityManagerInterface;
class EvseManagerInterface;
class DatabaseHandlerInterface;
class AvailabilityInterface;
class SmartChargingInterface;
class TariffAndCostInterface;

struct GetTransactionStatusRequest;

typedef std::function<void(const TransactionEventRequest& transaction_event)> TransactionEventCallback;
typedef std::function<void(const std::optional<const int32_t> evse_id, const ResetEnum& reset_type)> ResetCallback;
typedef std::function<void(const TransactionEventRequest& transaction_event,
const TransactionEventResponse& transaction_event_response)>
TransactionEventResponseCallback;
typedef std::function<RequestStartStopStatusEnum(const int32_t evse_id, const ReasonEnum& stop_reason)>
StopTransactionCallback;
typedef std::function<void(const int32_t evse_id)> PauseChargingCallback;

class TransactionInterface : public MessageHandlerInterface {
public:
virtual ~TransactionInterface() = default;

/// \brief Event handler that should be called when a transaction has started
/// \param evse_id
/// \param connector_id
/// \param session_id
/// \param timestamp
/// \param trigger_reason
/// \param meter_start
/// \param id_token
/// \param group_id_token Optional group id token
/// \param reservation_id
/// \param remote_start_id
/// \param charging_state The new charging state
virtual void
on_transaction_started(const int32_t evse_id, const int32_t connector_id, const std::string& session_id,
const DateTime& timestamp, const ocpp::v201::TriggerReasonEnum trigger_reason,
const MeterValue& meter_start, const std::optional<IdToken>& id_token,
const std::optional<IdToken>& group_id_token, const std::optional<int32_t>& reservation_id,
const std::optional<int32_t>& remote_start_id, const ChargingStateEnum charging_state) = 0;

/// \brief Event handler that should be called when a transaction has finished
/// \param evse_id
/// \param timestamp
/// \param meter_stop
/// \param reason
/// \param id_token
/// \param signed_meter_value
/// \param charging_state
virtual void on_transaction_finished(const int32_t evse_id, const DateTime& timestamp, const MeterValue& meter_stop,
const ReasonEnum reason, const TriggerReasonEnum trigger_reason,
const std::optional<IdToken>& id_token,
const std::optional<std::string>& signed_meter_value,
const ChargingStateEnum charging_state) = 0;

/* OCPP message requests */

// Functional Block E: Transactions
virtual void transaction_event_req(const TransactionEventEnum& event_type, const DateTime& timestamp,
const ocpp::v201::Transaction& transaction,
const ocpp::v201::TriggerReasonEnum& trigger_reason, const int32_t seq_no,
const std::optional<int32_t>& cable_max_current,
const std::optional<ocpp::v201::EVSE>& evse,
const std::optional<ocpp::v201::IdToken>& id_token,
const std::optional<std::vector<ocpp::v201::MeterValue>>& meter_value,
const std::optional<int32_t>& number_of_phases_used, const bool offline,
const std::optional<int32_t>& reservation_id,
const bool initiated_by_trigger_message = false) = 0;

virtual void set_remote_start_id_for_evse(const int32_t evse_id, const IdToken id_token,
const int32_t remote_start_id) = 0;
virtual void schedule_reset(const std::optional<int32_t> reset_scheduled_evseid) = 0;
};

class TransactionBlock : public TransactionInterface {
public:
TransactionBlock(MessageDispatcherInterface<MessageType>& message_dispatcher, DeviceModel& device_model,
ConnectivityManagerInterface& connectivity_manager, EvseManagerInterface& evse_manager,
MessageQueue<v201::MessageType>& message_queue, DatabaseHandlerInterface& database_handler,
AuthorizationInterface& authorization, AvailabilityInterface& availability,
SmartChargingInterface& smart_charging, TariffAndCostInterface& tariff_and_cost,
StopTransactionCallback stop_transaction_callback, PauseChargingCallback pause_charging_callback,
std::optional<TransactionEventCallback> transaction_event_callback,
std::optional<TransactionEventResponseCallback> transaction_event_response_callback,
ResetCallback reset_callback);
void handle_message(const ocpp::EnhancedMessage<MessageType>& message) override;
void on_transaction_started(const int32_t evse_id, const int32_t connector_id, const std::string& session_id,
const DateTime& timestamp, const TriggerReasonEnum trigger_reason,
const MeterValue& meter_start, const std::optional<IdToken>& id_token,
const std::optional<IdToken>& group_id_token,
const std::optional<int32_t>& reservation_id,
const std::optional<int32_t>& remote_start_id,
const ChargingStateEnum charging_state) override;
void on_transaction_finished(const int32_t evse_id, const DateTime& timestamp, const MeterValue& meter_stop,
const ReasonEnum reason, const TriggerReasonEnum trigger_reason,
const std::optional<IdToken>& id_token,
const std::optional<std::string>& signed_meter_value,
const ChargingStateEnum charging_state) override;
void transaction_event_req(const TransactionEventEnum& event_type, const DateTime& timestamp,
const Transaction& transaction, const TriggerReasonEnum& trigger_reason,
const int32_t seq_no, const std::optional<int32_t>& cable_max_current,
const std::optional<EVSE>& evse, const std::optional<IdToken>& id_token,
const std::optional<std::vector<MeterValue>>& meter_value,
const std::optional<int32_t>& number_of_phases_used, const bool offline,
const std::optional<int32_t>& reservation_id,
const bool initiated_by_trigger_message = false) override;
void set_remote_start_id_for_evse(const int32_t evse_id, const IdToken id_token,
const int32_t remote_start_id) override;
void schedule_reset(const std::optional<int32_t> reset_scheduled_evseid) override;

private: // Members
MessageDispatcherInterface<MessageType>& message_dispatcher;
DeviceModel& device_model;
ConnectivityManagerInterface& connectivity_manager;
EvseManagerInterface& evse_manager;
MessageQueue<v201::MessageType>& message_queue;
DatabaseHandlerInterface& database_handler;
AuthorizationInterface& authorization;
AvailabilityInterface& availability;
SmartChargingInterface& smart_charging;
TariffAndCostInterface& tariff_and_cost;
StopTransactionCallback stop_transaction_callback;
PauseChargingCallback pause_charging_callback;
std::optional<TransactionEventCallback> transaction_event_callback;
std::optional<TransactionEventResponseCallback> transaction_event_response_callback;
ResetCallback reset_callback;

std::map<int32_t, std::pair<IdToken, int32_t>> remote_start_id_per_evse;

Check notice on line 140 in include/ocpp/v201/functional_blocks/transaction.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/ocpp/v201/functional_blocks/transaction.hpp#L140

class member 'TransactionBlock::remote_start_id_per_evse' is never used.
/// \brief Used when an 'OnIdle' reset is requested, to perform the reset after the charging has stopped.
bool reset_scheduled;

Check notice on line 142 in include/ocpp/v201/functional_blocks/transaction.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/ocpp/v201/functional_blocks/transaction.hpp#L142

class member 'TransactionBlock::reset_scheduled' is never used.
/// \brief If `reset_scheduled` is true and the reset is for a specific evse id, it will be stored in this member.
std::set<int32_t> reset_scheduled_evseids;

Check notice on line 144 in include/ocpp/v201/functional_blocks/transaction.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/ocpp/v201/functional_blocks/transaction.hpp#L144

class member 'TransactionBlock::reset_scheduled_evseids' is never used.

private: // Functions
/* OCPP message handlers */

// Functional Block E: Transaction
void handle_transaction_event_response(const EnhancedMessage<v201::MessageType>& message);
void handle_get_transaction_status(const Call<GetTransactionStatusRequest> call);
};
} // namespace ocpp::v201
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ if(LIBOCPP_ENABLE_V201)
ocpp/v201/functional_blocks/display_message.cpp
ocpp/v201/functional_blocks/meter_values.cpp
ocpp/v201/functional_blocks/tariff_and_cost.cpp
ocpp/v201/functional_blocks/transaction.cpp
)
add_subdirectory(ocpp/v201/messages)
endif()
Expand Down
Loading

0 comments on commit 6349a4b

Please sign in to comment.