Skip to content

Commit 7165b05

Browse files
committed
First commit transaction functional block.
Signed-off-by: Maaike Zijderveld, iolar <git.mail@iolar.nl>
1 parent 671e961 commit 7165b05

File tree

5 files changed

+562
-350
lines changed

5 files changed

+562
-350
lines changed

include/ocpp/v201/charge_point.hpp

+2-32
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <ocpp/v201/functional_blocks/security.hpp>
2020
#include <ocpp/v201/functional_blocks/smart_charging.hpp>
2121
#include <ocpp/v201/functional_blocks/tariff_and_cost.hpp>
22+
#include <ocpp/v201/functional_blocks/transaction.hpp>
2223

2324
#include <ocpp/common/charging_station_base.hpp>
2425

@@ -46,7 +47,6 @@
4647
#include <ocpp/v201/messages/GetLog.hpp>
4748
#include <ocpp/v201/messages/GetMonitoringReport.hpp>
4849
#include <ocpp/v201/messages/GetReport.hpp>
49-
#include <ocpp/v201/messages/GetTransactionStatus.hpp>
5050
#include <ocpp/v201/messages/GetVariables.hpp>
5151
#include <ocpp/v201/messages/NotifyCustomerInformation.hpp>
5252
#include <ocpp/v201/messages/NotifyEvent.hpp>
@@ -60,7 +60,6 @@
6060
#include <ocpp/v201/messages/SetNetworkProfile.hpp>
6161
#include <ocpp/v201/messages/SetVariableMonitoring.hpp>
6262
#include <ocpp/v201/messages/SetVariables.hpp>
63-
#include <ocpp/v201/messages/TransactionEvent.hpp>
6463
#include <ocpp/v201/messages/TriggerMessage.hpp>
6564
#include <ocpp/v201/messages/UnlockConnector.hpp>
6665

@@ -256,11 +255,6 @@ class ChargePointInterface {
256255

257256
/// @}
258257

259-
/// \brief Gets the transaction id for a certain \p evse_id if there is an active transaction
260-
/// \param evse_id The evse to tet the transaction for
261-
/// \return The transaction id if a transaction is active, otherwise nullopt
262-
virtual std::optional<std::string> get_evse_transaction_id(int32_t evse_id) = 0;
263-
264258
/// \brief Validates provided \p id_token \p certificate and \p ocsp_request_data using CSMS, AuthCache or AuthList
265259
/// \param id_token
266260
/// \param certificate
@@ -368,13 +362,12 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
368362
std::unique_ptr<MeterValuesInterface> meter_values;
369363
std::unique_ptr<SmartCharging> smart_charging;
370364
std::unique_ptr<TariffAndCostInterface> tariff_and_cost;
365+
std::unique_ptr<TransactionInterface> transaction;
371366

372367
// utility
373368
std::shared_ptr<MessageQueue<v201::MessageType>> message_queue;
374369
std::shared_ptr<DatabaseHandler> database_handler;
375370

376-
std::map<int32_t, std::pair<IdToken, int32_t>> remote_start_id_per_evse;
377-
378371
// timers
379372
Everest::SteadyTimer boot_notification_timer;
380373

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

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

408-
/// \brief Used when an 'OnIdle' reset is requested, to perform the reset after the charging has stopped.
409-
bool reset_scheduled;
410-
/// \brief If `reset_scheduled` is true and the reset is for a specific evse id, it will be stored in this member.
411-
std::set<int32_t> reset_scheduled_evseids;
412-
413401
// callback struct
414402
Callbacks callbacks;
415403

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

490-
// Functional Block E: Transactions
491-
void transaction_event_req(const TransactionEventEnum& event_type, const DateTime& timestamp,
492-
const ocpp::v201::Transaction& transaction,
493-
const ocpp::v201::TriggerReasonEnum& trigger_reason, const int32_t seq_no,
494-
const std::optional<int32_t>& cable_max_current,
495-
const std::optional<ocpp::v201::EVSE>& evse,
496-
const std::optional<ocpp::v201::IdToken>& id_token,
497-
const std::optional<std::vector<ocpp::v201::MeterValue>>& meter_value,
498-
const std::optional<int32_t>& number_of_phases_used, const bool offline,
499-
const std::optional<int32_t>& reservation_id,
500-
const bool initiated_by_trigger_message = false);
501-
502478
/* OCPP message handlers */
503479

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

513-
// Functional Block E: Transaction
514-
void handle_transaction_event_response(const EnhancedMessage<v201::MessageType>& message);
515-
void handle_get_transaction_status(const Call<GetTransactionStatusRequest> call);
516-
517489
// Function Block F: Remote transaction control
518490
void handle_unlock_connector(Call<UnlockConnectorRequest> call);
519491
void handle_remote_start_transaction_request(Call<RequestStartTransactionRequest> call);
@@ -659,8 +631,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
659631
const uint32_t evse_id, const ChargingStateEnum charging_state,
660632
const TriggerReasonEnum trigger_reason = TriggerReasonEnum::ChargingStateChanged) override;
661633

662-
std::optional<std::string> get_evse_transaction_id(int32_t evse_id) override;
663-
664634
AuthorizeResponse validate_token(const IdToken id_token, const std::optional<CiString<5500>>& certificate,
665635
const std::optional<std::vector<OCSPRequestData>>& ocsp_request_data) override;
666636

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Pionix GmbH and Contributors to EVerest
3+
4+
#pragma once
5+
6+
#include <ocpp/v201/message_handler.hpp>
7+
8+
#include <ocpp/v201/message_dispatcher.hpp>
9+
10+
namespace ocpp::v201 {
11+
class DeviceModel;
12+
class AuthorizationInterface;
13+
class ConnectivityManagerInterface;
14+
class EvseManagerInterface;
15+
class DatabaseHandlerInterface;
16+
class AvailabilityInterface;
17+
class SmartChargingInterface;
18+
class TariffAndCostInterface;
19+
20+
struct GetTransactionStatusRequest;
21+
22+
typedef std::function<void(const TransactionEventRequest& transaction_event)> TransactionEventCallback;
23+
typedef std::function<void(const std::optional<const int32_t> evse_id, const ResetEnum& reset_type)> ResetCallback;
24+
typedef std::function<void(const TransactionEventRequest& transaction_event,
25+
const TransactionEventResponse& transaction_event_response)>
26+
TransactionEventResponseCallback;
27+
typedef std::function<RequestStartStopStatusEnum(const int32_t evse_id, const ReasonEnum& stop_reason)>
28+
StopTransactionCallback;
29+
typedef std::function<void(const int32_t evse_id)> PauseChargingCallback;
30+
31+
class TransactionInterface : public MessageHandlerInterface {
32+
public:
33+
virtual ~TransactionInterface() = default;
34+
35+
/// \brief Event handler that should be called when a transaction has started
36+
/// \param evse_id
37+
/// \param connector_id
38+
/// \param session_id
39+
/// \param timestamp
40+
/// \param trigger_reason
41+
/// \param meter_start
42+
/// \param id_token
43+
/// \param group_id_token Optional group id token
44+
/// \param reservation_id
45+
/// \param remote_start_id
46+
/// \param charging_state The new charging state
47+
virtual void
48+
on_transaction_started(const int32_t evse_id, const int32_t connector_id, const std::string& session_id,
49+
const DateTime& timestamp, const ocpp::v201::TriggerReasonEnum trigger_reason,
50+
const MeterValue& meter_start, const std::optional<IdToken>& id_token,
51+
const std::optional<IdToken>& group_id_token, const std::optional<int32_t>& reservation_id,
52+
const std::optional<int32_t>& remote_start_id, const ChargingStateEnum charging_state) = 0;
53+
54+
/// \brief Event handler that should be called when a transaction has finished
55+
/// \param evse_id
56+
/// \param timestamp
57+
/// \param meter_stop
58+
/// \param reason
59+
/// \param id_token
60+
/// \param signed_meter_value
61+
/// \param charging_state
62+
virtual void on_transaction_finished(const int32_t evse_id, const DateTime& timestamp, const MeterValue& meter_stop,
63+
const ReasonEnum reason, const TriggerReasonEnum trigger_reason,
64+
const std::optional<IdToken>& id_token,
65+
const std::optional<std::string>& signed_meter_value,
66+
const ChargingStateEnum charging_state) = 0;
67+
68+
/* OCPP message requests */
69+
70+
// Functional Block E: Transactions
71+
virtual void transaction_event_req(const TransactionEventEnum& event_type, const DateTime& timestamp,
72+
const ocpp::v201::Transaction& transaction,
73+
const ocpp::v201::TriggerReasonEnum& trigger_reason, const int32_t seq_no,
74+
const std::optional<int32_t>& cable_max_current,
75+
const std::optional<ocpp::v201::EVSE>& evse,
76+
const std::optional<ocpp::v201::IdToken>& id_token,
77+
const std::optional<std::vector<ocpp::v201::MeterValue>>& meter_value,
78+
const std::optional<int32_t>& number_of_phases_used, const bool offline,
79+
const std::optional<int32_t>& reservation_id,
80+
const bool initiated_by_trigger_message = false) = 0;
81+
82+
virtual void set_remote_start_id_for_evse(const int32_t evse_id, const IdToken id_token,
83+
const int32_t remote_start_id) = 0;
84+
virtual void schedule_reset(const std::optional<int32_t> reset_scheduled_evseid) = 0;
85+
};
86+
87+
class TransactionBlock : public TransactionInterface {
88+
public:
89+
TransactionBlock(MessageDispatcherInterface<MessageType>& message_dispatcher, DeviceModel& device_model,
90+
ConnectivityManagerInterface& connectivity_manager, EvseManagerInterface& evse_manager,
91+
MessageQueue<v201::MessageType>& message_queue, DatabaseHandlerInterface& database_handler,
92+
AuthorizationInterface& authorization, AvailabilityInterface& availability,
93+
SmartChargingInterface& smart_charging, TariffAndCostInterface& tariff_and_cost,
94+
StopTransactionCallback stop_transaction_callback, PauseChargingCallback pause_charging_callback,
95+
std::optional<TransactionEventCallback> transaction_event_callback,
96+
std::optional<TransactionEventResponseCallback> transaction_event_response_callback,
97+
ResetCallback reset_callback);
98+
void handle_message(const ocpp::EnhancedMessage<MessageType>& message) override;
99+
void on_transaction_started(const int32_t evse_id, const int32_t connector_id, const std::string& session_id,
100+
const DateTime& timestamp, const TriggerReasonEnum trigger_reason,
101+
const MeterValue& meter_start, const std::optional<IdToken>& id_token,
102+
const std::optional<IdToken>& group_id_token,
103+
const std::optional<int32_t>& reservation_id,
104+
const std::optional<int32_t>& remote_start_id,
105+
const ChargingStateEnum charging_state) override;
106+
void on_transaction_finished(const int32_t evse_id, const DateTime& timestamp, const MeterValue& meter_stop,
107+
const ReasonEnum reason, const TriggerReasonEnum trigger_reason,
108+
const std::optional<IdToken>& id_token,
109+
const std::optional<std::string>& signed_meter_value,
110+
const ChargingStateEnum charging_state) override;
111+
void transaction_event_req(const TransactionEventEnum& event_type, const DateTime& timestamp,
112+
const Transaction& transaction, const TriggerReasonEnum& trigger_reason,
113+
const int32_t seq_no, const std::optional<int32_t>& cable_max_current,
114+
const std::optional<EVSE>& evse, const std::optional<IdToken>& id_token,
115+
const std::optional<std::vector<MeterValue>>& meter_value,
116+
const std::optional<int32_t>& number_of_phases_used, const bool offline,
117+
const std::optional<int32_t>& reservation_id,
118+
const bool initiated_by_trigger_message = false) override;
119+
void set_remote_start_id_for_evse(const int32_t evse_id, const IdToken id_token,
120+
const int32_t remote_start_id) override;
121+
void schedule_reset(const std::optional<int32_t> reset_scheduled_evseid) override;
122+
123+
private: // Members
124+
MessageDispatcherInterface<MessageType>& message_dispatcher;
125+
DeviceModel& device_model;
126+
ConnectivityManagerInterface& connectivity_manager;
127+
EvseManagerInterface& evse_manager;
128+
MessageQueue<v201::MessageType>& message_queue;
129+
DatabaseHandlerInterface& database_handler;
130+
AuthorizationInterface& authorization;
131+
AvailabilityInterface& availability;
132+
SmartChargingInterface& smart_charging;
133+
TariffAndCostInterface& tariff_and_cost;
134+
StopTransactionCallback stop_transaction_callback;
135+
PauseChargingCallback pause_charging_callback;
136+
std::optional<TransactionEventCallback> transaction_event_callback;
137+
std::optional<TransactionEventResponseCallback> transaction_event_response_callback;
138+
ResetCallback reset_callback;
139+
140+
std::map<int32_t, std::pair<IdToken, int32_t>> remote_start_id_per_evse;
141+
/// \brief Used when an 'OnIdle' reset is requested, to perform the reset after the charging has stopped.
142+
bool reset_scheduled;
143+
/// \brief If `reset_scheduled` is true and the reset is for a specific evse id, it will be stored in this member.
144+
std::set<int32_t> reset_scheduled_evseids;
145+
146+
private: // Functions
147+
/* OCPP message handlers */
148+
149+
// Functional Block E: Transaction
150+
void handle_transaction_event_response(const EnhancedMessage<v201::MessageType>& message);
151+
void handle_get_transaction_status(const Call<GetTransactionStatusRequest> call);
152+
};
153+
} // namespace ocpp::v201

lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ if(LIBOCPP_ENABLE_V201)
104104
ocpp/v201/functional_blocks/display_message.cpp
105105
ocpp/v201/functional_blocks/meter_values.cpp
106106
ocpp/v201/functional_blocks/tariff_and_cost.cpp
107+
ocpp/v201/functional_blocks/transaction.cpp
107108
)
108109
add_subdirectory(ocpp/v201/messages)
109110
endif()

0 commit comments

Comments
 (0)