3#ifndef OCPP_V16_TRANSACTION_HPP
4#define OCPP_V16_TRANSACTION_HPP
9#include <everest/timer.hpp>
10#include <ocpp/v16/ocpp_types.hpp>
11#include <ocpp/v16/types.hpp>
30 std::optional<int32_t> transaction_id;
31 int32_t internal_transaction_id;
33 std::string session_id;
35 std::shared_ptr<StampedEnergyWh> start_energy_wh;
36 std::optional<int32_t> reservation_id;
39 bool has_signed_meter_values;
40 std::unique_ptr<Everest::SteadyTimer> meter_values_sample_timer;
41 std::string start_transaction_message_id;
42 std::string stop_transaction_message_id;
43 std::shared_ptr<StampedEnergyWh> stop_energy_wh;
44 std::mutex meter_values_mutex;
45 std::vector<MeterValue> meter_values;
50 Transaction(
const int32_t transaction_id,
const int32_t& connector,
const std::string& session_id,
51 const CiString<20>& id_token,
const double meter_start, std::optional<int32_t> reservation_id,
52 const ocpp::DateTime& timestamp, std::unique_ptr<Everest::SteadyTimer> meter_values_sample_timer);
149 std::mutex active_transactions_mutex;
151 int32_t number_of_connectors;
153 std::vector<std::shared_ptr<Transaction>> active_transactions;
155 std::vector<std::shared_ptr<Transaction>> stopped_transactions;
158 std::uniform_int_distribution<int32_t> distr;
187 std::shared_ptr<Transaction>
get_transaction(
const std::string& start_transaction_message_id);
Contains a DateTime implementation that can parse and create RFC 3339 compatible strings.
Definition: types.hpp:109
Contains transactions for all available connectors and manages access to these transactions.
Definition: transaction.hpp:147
std::optional< CiString< 20 > > get_authorized_id_tag(const std::string &stop_transaction_message_id)
Definition: transaction.cpp:264
void erase_stopped_transaction(std::string stop_transaction_message_id)
Erases a transaction with the provided stop_transaction_message_id.
Definition: transaction.cpp:184
void add_transaction(std::shared_ptr< Transaction > transaction)
Adds the given transaction the vector of transactions.
Definition: transaction.cpp:163
bool remove_active_transaction(int32_t connector)
Removes a transaction from the provided connector.
Definition: transaction.cpp:172
void add_meter_value(int32_t connector, const MeterValue &meter_value)
Adds a clock aligned meter_value to the transaction on the provided connector.
Definition: transaction.cpp:247
int32_t get_negative_random_transaction_id()
Returns a negative random transaction_id.
Definition: transaction.cpp:159
TransactionHandler(int32_t number_of_connectors)
Creates and manages transactions for the provided number_of_connectors.
Definition: transaction.cpp:150
std::shared_ptr< Transaction > get_transaction_from_id_tag(const std::string &id_tag)
Returns the transaction associated with the given id tag.
Definition: transaction.cpp:218
void change_meter_values_sample_intervals(int32_t interval)
Modifies the sample interval of the meter values sample timer on all connectors. The provided interva...
Definition: transaction.cpp:255
int32_t get_connector_from_transaction_id(int32_t transaction_id)
Provides the connector on which a transaction with the given transaction_id is running.
Definition: transaction.cpp:233
bool transaction_active(int32_t connector)
Indicates if there is an active transaction at the proveded connector.
Definition: transaction.cpp:273
std::shared_ptr< Transaction > get_transaction(int32_t connector)
Returns the transaction associated with the transaction at the provided connector.
Definition: transaction.cpp:193
void add_stopped_transaction(int32_t connector)
Adds the transaction at the connector to the vector of stopped transactions.
Definition: transaction.cpp:168
Contains all transaction related data, such as the ID and power meter values.
Definition: transaction.hpp:28
std::optional< int32_t > get_reservation_id()
Provides the reservation id of the transaction if present.
Definition: transaction.cpp:146
void set_has_signed_meter_values()
Sets the has_signed_meter_value flag for this transaction, this function is called from on_transactio...
Definition: transaction.cpp:133
std::string get_stop_transaction_message_id()
Provides the stop transaction message id.
Definition: transaction.cpp:86
bool is_active()
Indicates if the transaction is active. Active means that the transaction for this session is not nul...
Definition: transaction.cpp:112
void add_meter_value(MeterValue meter_value)
Adds the provided meter_value to a chronological list of powermeter values.
Definition: transaction.cpp:38
bool is_finished()
Indicates if a StopTransaction.req for this transaction has already been pushed to the message queue.
Definition: transaction.cpp:116
int32_t get_internal_transaction_id()
Returns the internal transaction id.
Definition: transaction.cpp:66
std::optional< int32_t > get_transaction_id()
Provides the id of this transaction.
Definition: transaction.cpp:62
std::string get_start_transaction_message_id()
Provides the start transaction message id.
Definition: transaction.cpp:78
void set_finished()
Sets the finished flag for this transaction. This is done when a StopTransaction.req has been pushed ...
Definition: transaction.cpp:120
std::string get_session_id()
Provides the id of this session.
Definition: transaction.cpp:70
void stop()
Marks the transaction as stopped/inactive.
Definition: transaction.cpp:105
int32_t get_connector()
Provides the connector of this transaction.
Definition: transaction.cpp:30
Transaction(const int32_t transaction_id, const int32_t &connector, const std::string &session_id, const CiString< 20 > &id_token, const double meter_start, std::optional< int32_t > reservation_id, const ocpp::DateTime ×tamp, std::unique_ptr< Everest::SteadyTimer > meter_values_sample_timer)
Creates a new Transaction object, taking ownership of the provided meter_values_sample_timer on the p...
Definition: transaction.cpp:12
void set_start_transaction_message_id(const std::string &message_id)
Sets the start transaction message id using the provides message_id.
Definition: transaction.cpp:74
bool get_has_signed_meter_values()
Indicates if this transaction has signed meter values or not, this function is called from on_transac...
Definition: transaction.cpp:137
CiString< 20 > get_id_tag()
Provides the authorized id tag of this Transaction.
Definition: transaction.cpp:34
void set_transaction_id(int32_t transaction_id)
Sets the transaction id.
Definition: transaction.cpp:90
bool change_meter_values_sample_interval(int32_t interval)
Changes the sample interval of the powermeter values sampling timer.
Definition: transaction.cpp:57
void set_stop_transaction_message_id(const std::string &message_id)
Sets the stop transaction message id using the provides message_id.
Definition: transaction.cpp:82
std::vector< TransactionData > get_transaction_data()
Provides all recorded sampled and clock aligned powermeter values.
Definition: transaction.cpp:94
void add_clock_aligned_meter_value(MeterValue meter_value)
Adds the provided meter_value to a chronological list of clock aligned powermeter values.
void add_stop_energy_wh(std::shared_ptr< StampedEnergyWh > stop_energy_wh)
Adds the energy in Wh stop_energy_wh to the transaction. This also stops the collection of further me...
Definition: transaction.cpp:128
std::shared_ptr< StampedEnergyWh > get_stop_energy_wh()
Provides the energy in Wh at the end of the transaction.
Definition: transaction.cpp:142
std::shared_ptr< StampedEnergyWh > get_start_energy_wh()
Provides the energy in Wh at the start of the transaction.
Definition: transaction.cpp:124
std::vector< MeterValue > get_meter_values()
Provides all recorded powermeter values.
Definition: transaction.cpp:52
Definition: ocpp_types.hpp:132
A structure that contains a energy value in Wh that can be used for start/stop energy values and a co...
Definition: transaction.hpp:18
ocpp::DateTime timestamp
A timestamp associated with the energy value.
Definition: transaction.hpp:19
double energy_Wh
The energy value in Wh.
Definition: transaction.hpp:20