Skip to content

Commit

Permalink
* changed type of id_tag of TransactionFinished and StopTransactionRe…
Browse files Browse the repository at this point in the history
…quest types from string to ProvidedIdToken in order to be able to use the additional data

* refactored Auth, OCPP, OCPP201 and EvseManager module by adressing the type changes

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried committed Jan 9, 2024
1 parent 90b74fd commit 703530a
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 29 deletions.
4 changes: 2 additions & 2 deletions modules/Auth/lib/AuthHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ TokenHandlingResult AuthHandler::handle_token(const ProvidedIdToken& provided_to
if (connector_used_for_transaction != -1) {
StopTransactionRequest req;
req.reason = StopTransactionReason::Local;
req.id_tag.emplace(provided_token.id_token);
req.id_tag.emplace(provided_token);
this->stop_transaction_callback(this->connectors.at(connector_used_for_transaction)->evse_index, req);
EVLOG_info << "Transaction was stopped because id_token was used for transaction";
return TokenHandlingResult::USED_TO_STOP_TRANSACTION;
Expand Down Expand Up @@ -154,7 +154,7 @@ TokenHandlingResult AuthHandler::handle_token(const ProvidedIdToken& provided_to
} else {
StopTransactionRequest req;
req.reason = StopTransactionReason::Local;
req.id_tag.emplace(provided_token.id_token);
req.id_tag.emplace(provided_token);
this->stop_transaction_callback(this->connectors.at(connector_used_for_transaction)->evse_index,
req);
EVLOG_info << "Transaction was stopped because parent_id_token was used for transaction";
Expand Down
8 changes: 4 additions & 4 deletions modules/EvseManager/Charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ bool Charger::cancelTransaction(const types::evse_manager::StopTransactionReques
transaction_active = false;
last_stop_transaction_reason = request.reason;
if (request.id_tag) {
stop_transaction_id_tag = request.id_tag.value();
stop_transaction_id_token = request.id_tag.value();
}
signalEvent(types::evse_manager::SessionEventEnum::ChargingFinished);
signalEvent(types::evse_manager::SessionEventEnum::TransactionFinished);
Expand Down Expand Up @@ -963,7 +963,7 @@ void Charger::stopSession() {

void Charger::startTransaction() {
std::lock_guard<std::recursive_mutex> lock(stateMutex);
stop_transaction_id_tag.clear();
stop_transaction_id_token.reset();
transaction_active = true;
signalEvent(types::evse_manager::SessionEventEnum::TransactionStarted);
}
Expand All @@ -976,9 +976,9 @@ void Charger::stopTransaction() {
signalEvent(types::evse_manager::SessionEventEnum::TransactionFinished);
}

std::string Charger::getStopTransactionIdTag() {
std::optional<types::authorization::ProvidedIdToken> Charger::getStopTransactionIdToken() {
std::lock_guard<std::recursive_mutex> lock(stateMutex);
return stop_transaction_id_tag;
return stop_transaction_id_token;
}

types::evse_manager::StopTransactionReason Charger::getTransactionFinishedReason() {
Expand Down
5 changes: 3 additions & 2 deletions modules/EvseManager/Charger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Charger {
void Authorize(bool a, const types::authorization::ProvidedIdToken& token);
bool DeAuthorize();
types::authorization::ProvidedIdToken getIdToken();
std::optional<types::authorization::ProvidedIdToken> getStopTransactionIdToken();

bool Authorized_PnC();
bool Authorized_EIM();
Expand All @@ -107,7 +108,6 @@ class Charger {

bool cancelTransaction(const types::evse_manager::StopTransactionRequest&
request); // cancel transaction ahead of time when car is still plugged
std::string getStopTransactionIdTag();
types::evse_manager::StopTransactionReason getTransactionFinishedReason(); // get reason for last finished event
types::evse_manager::StartSessionReason getSessionStartedReason(); // get reason for last session start event

Expand Down Expand Up @@ -214,7 +214,6 @@ class Charger {
bool transactionActive();
bool transaction_active;
bool session_active;
std::string stop_transaction_id_tag;
types::evse_manager::StopTransactionReason last_stop_transaction_reason;
types::evse_manager::StartSessionReason last_start_session_reason;

Expand Down Expand Up @@ -270,6 +269,8 @@ class Charger {
bool authorized_pnc;

types::authorization::ProvidedIdToken id_token;
std::optional<types::authorization::ProvidedIdToken>
stop_transaction_id_token; // only set in case transaction was stopped locally

// AC or DC
ChargeMode charge_mode{0};
Expand Down
6 changes: 1 addition & 5 deletions modules/EvseManager/evse/evse_managerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,8 @@ void evse_managerImpl::ready() {
transaction_finished.meter_value = mod->get_latest_powermeter_data_billing();

auto reason = mod->charger->getTransactionFinishedReason();
const auto id_tag = mod->charger->getStopTransactionIdTag();

transaction_finished.reason.emplace(reason);
if (!id_tag.empty()) {
transaction_finished.id_tag.emplace(id_tag);
}
transaction_finished.id_tag = mod->charger->getStopTransactionIdToken();

double energy_import = transaction_finished.meter_value.energy_Wh_import.total;

Expand Down
4 changes: 2 additions & 2 deletions modules/OCPP/OCPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ void OCPP::process_session_event(int32_t evse_id, const types::evse_manager::Ses
types::evse_manager::stop_transaction_reason_to_string(transaction_finished.reason.value()));
const auto signed_meter_value = transaction_finished.signed_meter_value;
std::optional<ocpp::CiString<20>> id_tag_opt = std::nullopt;
if (transaction_finished.id_tag) {
id_tag_opt.emplace(ocpp::CiString<20>(transaction_finished.id_tag.value()));
if (transaction_finished.id_tag.has_value()) {
id_tag_opt.emplace(ocpp::CiString<20>(transaction_finished.id_tag.value().id_token));
}
this->charge_point->on_transaction_stopped(ocpp_connector_id, session_event.uuid, reason, timestamp,
energy_Wh_import, id_tag_opt, signed_meter_value);
Expand Down
48 changes: 38 additions & 10 deletions modules/OCPP201/OCPP201.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,38 @@ ocpp::v201::ReasonEnum get_reason(types::evse_manager::StopTransactionReason rea
}
}

ocpp::v201::IdTokenEnum get_id_token_enum(types::authorization::IdTokenType id_token_type) {
switch (id_token_type) {
case types::authorization::IdTokenType::Central:
return ocpp::v201::IdTokenEnum::Central;
case types::authorization::IdTokenType::eMAID:
return ocpp::v201::IdTokenEnum::eMAID;
case types::authorization::IdTokenType::MacAddress:
return ocpp::v201::IdTokenEnum::MacAddress;
case types::authorization::IdTokenType::ISO14443:
return ocpp::v201::IdTokenEnum::ISO14443;
case types::authorization::IdTokenType::ISO15693:
return ocpp::v201::IdTokenEnum::ISO15693;
case types::authorization::IdTokenType::KeyCode:
return ocpp::v201::IdTokenEnum::KeyCode;
case types::authorization::IdTokenType::Local:
return ocpp::v201::IdTokenEnum::Local;
case types::authorization::IdTokenType::NoAuthorization:
return ocpp::v201::IdTokenEnum::NoAuthorization;
default:
throw std::runtime_error("Could not convert IdTokenEnum");
}
}

ocpp::v201::IdToken get_id_token(const types::authorization::ProvidedIdToken& provided_id_token) {
ocpp::v201::IdToken id_token;
id_token.idToken = provided_id_token.id_token;
if (provided_id_token.id_token_type.has_value()) {
id_token.type = get_id_token_enum(provided_id_token.id_token_type.value());
}
return id_token;
}

void OCPP201::init_evse_ready_map() {
std::lock_guard<std::mutex> lk(this->evse_ready_mutex);
for (size_t evse_id = 1; evse_id <= this->r_evse_manager.size(); evse_id++) {
Expand Down Expand Up @@ -853,15 +885,7 @@ void OCPP201::ready() {
const auto reservation_id = transaction_started.reservation_id;
const auto remote_start_id = transaction_started.id_tag.request_id;

ocpp::v201::IdToken id_token;
id_token.idToken = transaction_started.id_tag.id_token;
if (transaction_started.id_tag.id_token_type.has_value()) {
id_token.type =
ocpp::v201::conversions::string_to_id_token_enum(types::authorization::id_token_type_to_string(
transaction_started.id_tag.id_token_type.value()));
} else {
id_token.type = ocpp::v201::IdTokenEnum::Local; // FIXME(piet)
}
ocpp::v201::IdToken id_token = get_id_token(transaction_started.id_tag);

// assume cable has been plugged in first and then authorized
auto trigger_reason = ocpp::v201::TriggerReasonEnum::Authorized;
Expand Down Expand Up @@ -893,8 +917,12 @@ void OCPP201::ready() {
reason = get_reason(transaction_finished.reason.value());
}

std::optional<ocpp::v201::IdToken> id_token = std::nullopt;
if (transaction_finished.id_tag.has_value()) {
id_token = get_id_token(transaction_finished.id_tag.value());
}

const auto signed_meter_value = transaction_finished.signed_meter_value;
const auto id_token = transaction_finished.id_tag;

this->charge_point->on_transaction_finished(evse_id, timestamp, meter_value, reason, id_token,
signed_meter_value,
Expand Down
10 changes: 6 additions & 4 deletions types/evse_manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ types:
type: string
$ref: /evse_manager#/StopTransactionReason
id_tag:
description: Id tag that was used to stop the transaction.
type: string
description: Id tag that was used to stop the transaction. Only present if transaction was stopped locally.
type: object
$ref: /authorization#/ProvidedIdToken
StopTransactionReason:
description: >-
Reason for stopping transaction
Expand Down Expand Up @@ -219,8 +220,9 @@ types:
type: string
$ref: /evse_manager#/StopTransactionReason
id_tag:
description: Id tag that was used to stop the transaction
type: string
description: Id tag that was used to stop the transaction. Only present if transaction was stopped locally.
type: object
$ref: /authorization#/ProvidedIdToken
ErrorEnum:
description: >-
Note this is only kept for compatibility with the legacy error handling and will be removed soon.
Expand Down

0 comments on commit 703530a

Please sign in to comment.