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

Make supported OCPP protocol version configurable (v201, v21) #923

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
21 changes: 20 additions & 1 deletion config/v201/component_config/standardized/InternalCtrlr.json
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,24 @@
"description": "If enabled we allow connections using security level 0. This does pose a security risk and is not allowed according to the OCPP spec",
"default": false,
"type": "boolean"
},
"SupportedOcppVersions": {
"variable_name": "SupportedOcppVersions",
"characteristics": {
"supportsMonitoring": true,
"dataType": "SequenceList",
"valuesList": "ocpp2.0.1,ocpp2.1"
},
"attributes": [
{
"type": "Actual",
"mutability": "ReadOnly",
"value": "ocpp2.1,ocpp2.0.1"
}
],
"description": "List of supported OCPP versions in order of preference",
"default": "ocpp2.1,ocpp2.0.1",
"type": "string"
}
},
"required": [
Expand All @@ -830,6 +848,7 @@
"NetworkConnectionProfiles",
"NumberOfConnectors",
"SupportedCiphers12",
"SupportedCiphers13"
"SupportedCiphers13",
"SupportedOcppVersions"
]
}
5 changes: 4 additions & 1 deletion include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

// states
std::atomic<RegistrationStatusEnum> registration_status;
std::atomic<OcppProtocolVersion> ocpp_version =
OcppProtocolVersion::Unknown; // version that is currently in use, selected by CSMS in websocket handshake
FirmwareStatusEnum firmware_status;
// The request ID in the last firmware update status received
std::optional<int32_t> firmware_status_id;
Expand Down Expand Up @@ -477,7 +479,8 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
void scheduled_check_client_certificate_expiration();
void scheduled_check_v2g_certificate_expiration();
void websocket_connected_callback(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile);
const NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion ocpp_version);
void websocket_disconnected_callback(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile);
void websocket_connection_failed(ConnectionFailedReason reason);
Expand Down
3 changes: 2 additions & 1 deletion include/ocpp/v201/charge_point_callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ struct Callbacks {

/// \brief Callback function is called when the websocket connection status changes
std::optional<std::function<void(const bool is_connected, const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile)>>
const NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion ocpp_version)>>
connection_state_changed_callback;

/// \brief Callback functions called for get / set / clear display messages
Expand Down
5 changes: 3 additions & 2 deletions include/ocpp/v201/connectivity_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace v201 {

class DeviceModel;

using WebsocketConnectionCallback = std::function<void(
int configuration_slot, const NetworkConnectionProfile& network_connection_profile, OcppProtocolVersion version)>;
using WebsocketConnectionCallback =
std::function<void(int configuration_slot, const NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion version)>;
using WebsocketConnectionFailedCallback = std::function<void(ConnectionFailedReason reason)>;
using ConfigureNetworkConnectionProfileCallback = std::function<std::future<ConfigNetworkResult>(
const int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)>;
Expand Down
1 change: 1 addition & 0 deletions include/ocpp/v201/ctrlr_component_variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern const ComponentVariable MessageQueueSizeThreshold;
extern const ComponentVariable MaxMessageSize;
extern const ComponentVariable ResumeTransactionsOnBoot;
extern const ComponentVariable AllowSecurityLevelZeroConnections;
extern const RequiredComponentVariable SupportedOcppVersions;
extern const ComponentVariable AlignedDataCtrlrEnabled;
extern const ComponentVariable AlignedDataCtrlrAvailable;
extern const RequiredComponentVariable AlignedDataInterval;
Expand Down
3 changes: 3 additions & 0 deletions include/ocpp/v201/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ bool is_critical(const std::string& security_event);
/// \brief Converts the given \p csl of ChargingProfilePurpose strings into a std::set<ChargingProfilePurposeEnum>
std::set<ChargingProfilePurposeEnum> get_purposes_to_ignore(const std::string& csl, const bool is_offline);

/// \brief Converts the given \p csl of OcppProtocolVersion strings into a std::vector<OcppProtocolVersion>
std::vector<OcppProtocolVersion> get_ocpp_protocol_versions(const std::string& csl);

} // namespace utils
} // namespace v201
} // namespace ocpp
Expand Down
19 changes: 11 additions & 8 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,9 @@ void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_st
std::bind(&ChargePoint::message_callback, this, std::placeholders::_1));

this->connectivity_manager->set_websocket_connected_callback(
[this](int configuration_slot, const NetworkConnectionProfile& network_connection_profile, auto) {
this->websocket_connected_callback(configuration_slot, network_connection_profile);
[this](int configuration_slot, const NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion ocpp_version) {
this->websocket_connected_callback(configuration_slot, network_connection_profile, ocpp_version);
});
this->connectivity_manager->set_websocket_disconnected_callback(
[this](int configuration_slot, const NetworkConnectionProfile& network_connection_profile, auto) {
Expand Down Expand Up @@ -3020,7 +3021,7 @@ void ChargePoint::handle_trigger_message(Call<TriggerMessageRequest> call) {
return;
}

auto send_evse_message = [&](std::function<void(int32_t evse_id, EvseInterface& evse)> send) {
auto send_evse_message = [&](std::function<void(int32_t evse_id, EvseInterface & evse)> send) {
if (evse_ptr != nullptr) {
send(msg.evse.value().id, *evse_ptr);
} else {
Expand Down Expand Up @@ -4170,9 +4171,10 @@ void ChargePoint::scheduled_check_v2g_certificate_expiration() {
}

void ChargePoint::websocket_connected_callback(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile) {
const NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion ocpp_version) {
this->message_queue->resume(this->message_queue_resume_delay);

this->ocpp_version = ocpp_version;
if (this->registration_status == RegistrationStatusEnum::Accepted) {
this->connectivity_manager->confirm_successful_connection();

Expand Down Expand Up @@ -4203,7 +4205,8 @@ void ChargePoint::websocket_connected_callback(const int configuration_slot,
this->skip_invalid_csms_certificate_notifications = false;

if (this->callbacks.connection_state_changed_callback.has_value()) {
this->callbacks.connection_state_changed_callback.value()(true, configuration_slot, network_connection_profile);
this->callbacks.connection_state_changed_callback.value()(true, configuration_slot, network_connection_profile,
ocpp_version);
}
}

Expand All @@ -4220,8 +4223,8 @@ void ChargePoint::websocket_disconnected_callback(const int configuration_slot,
this->client_certificate_expiration_check_timer.stop();
this->v2g_certificate_expiration_check_timer.stop();
if (this->callbacks.connection_state_changed_callback.has_value()) {
this->callbacks.connection_state_changed_callback.value()(false, configuration_slot,
network_connection_profile);
this->callbacks.connection_state_changed_callback.value()(false, configuration_slot, network_connection_profile,
this->ocpp_version);
}
}

Expand Down
6 changes: 5 additions & 1 deletion lib/ocpp/v201/connectivity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <everest/logging.hpp>
#include <ocpp/v201/ctrlr_component_variables.hpp>
#include <ocpp/v201/device_model.hpp>
#include <ocpp/v201/utils.hpp>

namespace {
const auto WEBSOCKET_INIT_DELAY = std::chrono::seconds(2);
Expand Down Expand Up @@ -337,8 +338,11 @@ ConnectivityManager::get_ws_connection_options(const int32_t configuration_slot)
this->device_model.get_value<std::string>(ControllerComponentVariables::SecurityCtrlrIdentity),
network_connection_profile.securityProfile);

const auto ocpp_versions = utils::get_ocpp_protocol_versions(
this->device_model.get_value<std::string>(ControllerComponentVariables::SupportedOcppVersions));

WebsocketConnectionOptions connection_options{
{OcppProtocolVersion::v201},
ocpp_versions,
uri,
network_connection_profile.securityProfile,
this->device_model.get_optional_value<std::string>(ControllerComponentVariables::BasicAuthPassword),
Expand Down
5 changes: 5 additions & 0 deletions lib/ocpp/v201/ctrlr_component_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ const ComponentVariable AllowSecurityLevelZeroConnections = {
"AllowSecurityLevelZeroConnections",
}),
};
const RequiredComponentVariable SupportedOcppVersions = {
ControllerComponents::InternalCtrlr,
std::nullopt,
std::optional<Variable>({"SupportedOcppVersions"}),
};
const ComponentVariable AlignedDataCtrlrEnabled = {
ControllerComponents::AlignedDataCtrlr,
std::nullopt,
Expand Down
17 changes: 17 additions & 0 deletions lib/ocpp/v201/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ std::set<ChargingProfilePurposeEnum> get_purposes_to_ignore(const std::string& c
return purposes_to_ignore;
}

std::vector<OcppProtocolVersion> get_ocpp_protocol_versions(const std::string& csl) {
if (csl.empty()) {
return {};
}

std::vector<OcppProtocolVersion> ocpp_versions;
const auto ocpp_versions_str = ocpp::split_string(csl, ',');
for (const auto ocpp_version_str : ocpp_versions_str) {
try {
ocpp_versions.push_back(ocpp::conversions::string_to_ocpp_protocol_version(ocpp_version_str));
} catch (std::out_of_range& e) {
EVLOG_warning << "Error while converting ocpp protocol version: " << ocpp_version_str;
}
}
return ocpp_versions;
}

} // namespace utils
} // namespace v201
} // namespace ocpp