Skip to content

Commit

Permalink
Added OCPP BootNotification event to ocpp interface (#666)
Browse files Browse the repository at this point in the history
* Added OCPP BootNotification event to ocpp interface
---------

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried authored May 10, 2024
1 parent 966328a commit 86c9131
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
5 changes: 5 additions & 0 deletions interfaces/ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ vars:
For OCPP2.0.1: The object may contain all available properties
type: object
$ref: /ocpp#/EventData
boot_notification_response:
description: >-
Published any time a BootNotificationResponse message is received from the CSMS
type: object
$ref: /ocpp#/BootNotificationResponse
7 changes: 7 additions & 0 deletions modules/OCPP/OCPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,13 @@ void OCPP::ready() {
p_ocpp_generic->publish_ocpp_transaction_event(tevent);
});

this->charge_point->register_boot_notification_response_callback(
[this](const ocpp::v16::BootNotificationResponse& boot_notification_response) {
const auto everest_boot_notification_response =
conversions::to_everest_boot_notification_response(boot_notification_response);
this->p_ocpp_generic->publish_boot_notification_response(everest_boot_notification_response);
});

if (!this->r_data_transfer.empty()) {
this->charge_point->register_data_transfer_callback([this](const ocpp::v16::DataTransferRequest& request) {
types::ocpp::DataTransferRequest data_transfer_request;
Expand Down
23 changes: 23 additions & 0 deletions modules/OCPP/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,28 @@ types::ocpp::ChargingSchedule to_charging_schedule(const ocpp::v16::EnhancedChar
return csch;
}

types::ocpp::BootNotificationResponse
to_everest_boot_notification_response(const ocpp::v16::BootNotificationResponse& boot_notification_response) {
types::ocpp::BootNotificationResponse everest_boot_notification_response;
everest_boot_notification_response.status = to_everest_registration_status(boot_notification_response.status);
everest_boot_notification_response.current_time = boot_notification_response.currentTime.to_rfc3339();
everest_boot_notification_response.interval = boot_notification_response.interval;
return everest_boot_notification_response;
}

types::ocpp::RegistrationStatus
to_everest_registration_status(const ocpp::v16::RegistrationStatus& registration_status) {
switch (registration_status) {
case ocpp::v16::RegistrationStatus::Accepted:
return types::ocpp::RegistrationStatus::Accepted;
case ocpp::v16::RegistrationStatus::Pending:
return types::ocpp::RegistrationStatus::Pending;
case ocpp::v16::RegistrationStatus::Rejected:
return types::ocpp::RegistrationStatus::Rejected;
default:
throw std::out_of_range("Could not convert ocpp::v201::RegistrationStatus to types::ocpp::RegistrationStatus");
}
}

} // namespace conversions
} // namespace module
11 changes: 11 additions & 0 deletions modules/OCPP/conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <generated/types/system.hpp>

#include <ocpp/common/types.hpp>
#include <ocpp/v16/messages/BootNotification.hpp>
#include <ocpp/v16/messages/DataTransfer.hpp>
#include <ocpp/v16/messages/GetDiagnostics.hpp>
#include <ocpp/v16/messages/LogStatusNotification.hpp>
Expand Down Expand Up @@ -96,6 +97,16 @@ to_charging_schedule_period(const ocpp::v16::EnhancedChargingSchedulePeriod& per
/// \brief Convert ocpp::v16::EnhancedChargingSchedule to types::ocpp::ChargingSchedule
types::ocpp::ChargingSchedule to_charging_schedule(const ocpp::v16::EnhancedChargingSchedule& schedule);

/// \brief Converts a given ocpp::v16::BootNotificationResponse \p boot_notification_response to a
/// types::ocpp::BootNotificationResponse
types::ocpp::BootNotificationResponse
to_everest_boot_notification_response(const ocpp::v16::BootNotificationResponse& boot_notification_response);

/// \brief Converts a given ocpp::v16::RegistrationStatus \p registration_status to a
/// types::ocpp::RegistrationStatus
types::ocpp::RegistrationStatus
to_everest_registration_status(const ocpp::v16::RegistrationStatus& registration_status);

} // namespace conversions
} // namespace module

Expand Down
7 changes: 7 additions & 0 deletions modules/OCPP201/OCPP201.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ void OCPP201::ready() {
this->p_ocpp_generic->publish_ocpp_transaction_event_response(ocpp_transaction_event_response);
};

callbacks.boot_notification_callback =
[this](const ocpp::v201::BootNotificationResponse& boot_notification_response) {
const auto everest_boot_notification_response =
conversions::to_everest_boot_notification_response(boot_notification_response);
this->p_ocpp_generic->publish_boot_notification_response(everest_boot_notification_response);
};

if (!this->r_data_transfer.empty()) {
callbacks.data_transfer_callback = [this](const ocpp::v201::DataTransferRequest& request) {
types::ocpp::DataTransferRequest data_transfer_request =
Expand Down
35 changes: 35 additions & 0 deletions modules/OCPP201/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,41 @@ to_everest_transaction_event_response(const ocpp::v201::TransactionEventResponse
return everest_transaction_event_response;
}

types::ocpp::BootNotificationResponse
to_everest_boot_notification_response(const ocpp::v201::BootNotificationResponse& boot_notification_response) {
types::ocpp::BootNotificationResponse everest_boot_notification_response;
everest_boot_notification_response.status = to_everest_registration_status(boot_notification_response.status);
everest_boot_notification_response.current_time = boot_notification_response.currentTime.to_rfc3339();
everest_boot_notification_response.interval = boot_notification_response.interval;
if (boot_notification_response.statusInfo.has_value()) {
everest_boot_notification_response.status_info =
to_everest_status_info_type(boot_notification_response.statusInfo.value());
}
return everest_boot_notification_response;
}

types::ocpp::RegistrationStatus
to_everest_registration_status(const ocpp::v201::RegistrationStatusEnum& registration_status) {
switch (registration_status) {
case ocpp::v201::RegistrationStatusEnum::Accepted:
return types::ocpp::RegistrationStatus::Accepted;
case ocpp::v201::RegistrationStatusEnum::Pending:
return types::ocpp::RegistrationStatus::Pending;
case ocpp::v201::RegistrationStatusEnum::Rejected:
return types::ocpp::RegistrationStatus::Rejected;
default:
throw std::out_of_range(
"Could not convert ocpp::v201::RegistrationStatusEnum to types::ocpp::RegistrationStatus");
}
}

types::ocpp::StatusInfoType to_everest_status_info_type(const ocpp::v201::StatusInfo& status_info) {
types::ocpp::StatusInfoType everest_status_info;
everest_status_info.reason_code = status_info.reasonCode;
everest_status_info.additional_info = status_info.additionalInfo;
return everest_status_info;
}

std::vector<types::ocpp::GetVariableResult>
to_everest_get_variable_result_vector(const std::vector<ocpp::v201::GetVariableResult>& get_variable_result_vector) {
std::vector<types::ocpp::GetVariableResult> response;
Expand Down
15 changes: 15 additions & 0 deletions modules/OCPP201/conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <generated/types/system.hpp>

#include <ocpp/v201/messages/Authorize.hpp>
#include <ocpp/v201/messages/BootNotification.hpp>
#include <ocpp/v201/messages/DataTransfer.hpp>
#include <ocpp/v201/messages/FirmwareStatusNotification.hpp>
#include <ocpp/v201/messages/Get15118EVCertificate.hpp>
Expand Down Expand Up @@ -178,6 +179,20 @@ types::ocpp::MessageContent to_everest_message_content(const ocpp::v201::Message
types::ocpp::OcppTransactionEventResponse
to_everest_transaction_event_response(const ocpp::v201::TransactionEventResponse& transaction_event_response);

/// \brief Converts a given ocpp::v201::BootNotificationResponse \p boot_notification_response to a
/// types::ocpp::BootNotificationResponse
types::ocpp::BootNotificationResponse
to_everest_boot_notification_response(const ocpp::v201::BootNotificationResponse& boot_notification_response);

/// \brief Converts a given ocpp::v201::RegistrationStatusEnum \p registration_status to a
/// types::ocpp::RegistrationStatus
types::ocpp::RegistrationStatus
to_everest_registration_status(const ocpp::v201::RegistrationStatusEnum& registration_status);

/// \brief Converts a given ocpp::v201::StatusInfo \p status_info to a
/// types::ocpp::StatusInfoType
types::ocpp::StatusInfoType to_everest_status_info_type(const ocpp::v201::StatusInfo& status_info);

/// \brief Converts a given ocpp::v201::GetVariableResult \p get_variable_result_vector to a
/// std::vector<types::ocpp::GetVariableResult>
std::vector<types::ocpp::GetVariableResult>
Expand Down
33 changes: 33 additions & 0 deletions types/ocpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,36 @@ types:
description: Detailed status information.
type: object
$ref: /ocpp#/StatusInfoType
RegistrationStatus:
description: Indicates whether the Charging Station has been registered within the OCPP CSMS
type: string
enum:
- Accepted
- Pending
- Rejected
BootNotificationResponse:
description: OCPP BootNotificationResponse
type: object
required:
- status
- current_time
- interval
properties:
status:
description: Indicates whether the Charging Station has been registered within the OCPP CSMS
type: string
$ref: /ocpp#/RegistrationStatus
current_time:
description: Contains the CSMS current time in RFC3339 format
type: string
format: date-time
interval:
description: >-
When Status is Accepted, this contains the heartbeat interval in seconds. If the CSMS
returns something other than Accepted, the value of the interval field indicates the
minimum wait time before sending a next BootNotification request.
type: integer
status_info:
description: Detailed status information.
type: object
$ref: /ocpp#/StatusInfoType

0 comments on commit 86c9131

Please sign in to comment.