Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPP1.6: Report reason in StatusNotification.req in on_session_started and on_plugin_timeout #402

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/ocpp/v16/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ class ChargePoint {
/// authorization or the connection of cable and/or EV to the given \p connector
/// \param connector
/// \param session_id unique id of the session
/// \param reason "Authorized" or "EVConnected" TODO(piet): Convert to enum
/// \param reason for the initiation of the session
/// \param session_logging_path optional filesystem path to where the session log should be written
void on_session_started(int32_t connector, const std::string& session_id, const std::string& reason,
void on_session_started(int32_t connector, const std::string& session_id, const SessionStartedReason reason,
const std::optional<std::string>& session_logging_path);

/// \brief Notifies chargepoint that a session has been stopped at the given \p connector. This function must be
Expand Down
6 changes: 3 additions & 3 deletions include/ocpp/v16/charge_point_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ class ChargePointImpl : ocpp::ChargingStationBase {
/// authorization or the connection of cable and/or EV to the given \p connector
/// \param connector
/// \param session_id unique id of the session
/// \param reason "Authorized" or "EVConnected" TODO(piet): Convert to enum
/// \param reason for the initiation of the session
/// \param session_logging_path optional filesystem path to where the session log should be written
void on_session_started(int32_t connector, const std::string& session_id, const std::string& reason,
void on_session_started(int32_t connector, const std::string& session_id, const SessionStartedReason reason,
const std::optional<std::string>& session_logging_path);

/// \brief Notifies chargepoint that a session has been stopped at the given \p connector. This function must be
Expand Down Expand Up @@ -575,7 +575,7 @@ class ChargePointImpl : ocpp::ChargingStationBase {
void on_disabled(int32_t connector);

/// \brief Notifies chargepoint that a ConnectionTimeout occured for the given \p connector . This function should
/// be called when an EV is plugged in but the authorization is present within the specified ConnectionTimeout
/// be called when an EV is plugged in but the authorization is not present within the specified ConnectionTimeout
void on_plugin_timeout(int32_t connector);

/// \brief Notifies chargepoint that a SecurityEvent occurs. This will send a SecurityEventNotification.req to the
Expand Down
5 changes: 3 additions & 2 deletions include/ocpp/v16/charge_point_state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ChargePointFSM {
const std::optional<CiString<50>>& vendor_error_code)>;
explicit ChargePointFSM(const StatusNotificationCallback& status_notification_callback, FSMState initial_state);

bool handle_event(FSMEvent event, const ocpp::DateTime timestamp);
bool handle_event(FSMEvent event, const ocpp::DateTime timestamp, const std::optional<CiString<50>>& info);
bool handle_error(const ChargePointErrorCode& error_code, const ocpp::DateTime& timestamp,
const std::optional<CiString<50>>& info, const std::optional<CiString<255>>& vendor_id,
const std::optional<CiString<50>>& vendor_error_code);
Expand Down Expand Up @@ -78,7 +78,8 @@ class ChargePointStates {
ChargePointStates(const ConnectorStatusCallback& connector_status_callback);
void reset(std::map<int, ChargePointStatus> connector_status_map);

void submit_event(const int connector_id, FSMEvent event, const ocpp::DateTime& timestamp);
void submit_event(const int connector_id, FSMEvent event, const ocpp::DateTime& timestamp,
const std::optional<CiString<50>>& info = std::nullopt);
void submit_fault(const int connector_id, const ChargePointErrorCode& error_code, const ocpp::DateTime& timestamp,
const std::optional<CiString<50>>& info, const std::optional<CiString<255>>& vendor_id,
const std::optional<CiString<50>>& vendor_error_code);
Expand Down
3 changes: 2 additions & 1 deletion lib/ocpp/v16/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void ChargePoint::on_max_current_offered(int32_t connector, int32_t max_current)
this->charge_point->on_max_current_offered(connector, max_current);
}

void ChargePoint::on_session_started(int32_t connector, const std::string& session_id, const std::string& reason,
void ChargePoint::on_session_started(int32_t connector, const std::string& session_id,
const ocpp::SessionStartedReason reason,
const std::optional<std::string>& session_logging_path) {

this->charge_point->on_session_started(connector, session_id, reason, session_logging_path);
Expand Down
13 changes: 7 additions & 6 deletions lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3152,7 +3152,8 @@ void ChargePointImpl::start_transaction(std::shared_ptr<Transaction> transaction
this->send<StartTransactionRequest>(call);
}

void ChargePointImpl::on_session_started(int32_t connector, const std::string& session_id, const std::string& reason,
void ChargePointImpl::on_session_started(int32_t connector, const std::string& session_id,
const ocpp::SessionStartedReason reason,
const std::optional<std::string>& session_logging_path) {

EVLOG_debug << "Session on connector#" << connector << " started with reason " << reason;
Expand All @@ -3161,13 +3162,12 @@ void ChargePointImpl::on_session_started(int32_t connector, const std::string& s
this->logging->start_session_logging(session_id, session_logging_path.value());
}

const auto session_started_reason = ocpp::conversions::string_to_session_started_reason(reason);

// dont change to preparing when in reserved
if ((this->status->get_state(connector) == ChargePointStatus::Reserved &&
session_started_reason == SessionStartedReason::Authorized) ||
reason == SessionStartedReason::Authorized) ||
this->status->get_state(connector) != ChargePointStatus::Reserved) {
this->status->submit_event(connector, FSMEvent::UsageInitiated, ocpp::DateTime());
this->status->submit_event(connector, FSMEvent::UsageInitiated, ocpp::DateTime(),
ocpp::conversions::session_started_reason_to_string(reason));
}
}

Expand Down Expand Up @@ -3594,7 +3594,8 @@ void ChargePointImpl::on_disabled(int32_t connector) {
}

void ChargePointImpl::on_plugin_timeout(int32_t connector) {
this->status->submit_event(connector, FSMEvent::TransactionStoppedAndUserActionRequired, ocpp::DateTime());
this->status->submit_event(connector, FSMEvent::TransactionStoppedAndUserActionRequired, ocpp::DateTime(),
"ConnectionTimeout");
}

void ChargePointImpl::on_security_event(const std::string& type, const std::string& tech_info) {
Expand Down
12 changes: 7 additions & 5 deletions lib/ocpp/v16/charge_point_state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ FSMState ChargePointFSM::get_state() const {
return state;
}

bool ChargePointFSM::handle_event(FSMEvent event, const ocpp::DateTime timestamp) {
bool ChargePointFSM::handle_event(FSMEvent event, const ocpp::DateTime timestamp,
const std::optional<CiString<50>>& info) {
const auto& transitions = FSM_DEF.at(state);
const auto dest_state_it = transitions.find(event);

Expand All @@ -129,7 +130,7 @@ bool ChargePointFSM::handle_event(FSMEvent event, const ocpp::DateTime timestamp
state = dest_state_it->second;

if (!faulted) {
status_notification_callback(state, this->error_code, timestamp, std::nullopt, std::nullopt, std::nullopt);
status_notification_callback(state, this->error_code, timestamp, info, std::nullopt, std::nullopt);
}

return true;
Expand Down Expand Up @@ -212,13 +213,14 @@ void ChargePointStates::reset(std::map<int, ChargePointStatus> connector_status_
}
}

void ChargePointStates::submit_event(const int connector_id, FSMEvent event, const ocpp::DateTime& timestamp) {
void ChargePointStates::submit_event(const int connector_id, FSMEvent event, const ocpp::DateTime& timestamp,
const std::optional<CiString<50>>& info) {
const std::lock_guard<std::mutex> lck(state_machines_mutex);

if (connector_id == 0) {
this->state_machine_connector_zero->handle_event(event, timestamp);
this->state_machine_connector_zero->handle_event(event, timestamp, info);
} else if (connector_id > 0 && (size_t)connector_id <= this->state_machines.size()) {
this->state_machines.at(connector_id - 1).handle_event(event, timestamp);
this->state_machines.at(connector_id - 1).handle_event(event, timestamp, info);
}
}

Expand Down