Skip to content

Commit 256556e

Browse files
committed
Check for 'optional required' variables (only required when a component is available) and if they are not used while the whole ctrlr is not available..
Signed-off-by: Maaike Zijderveld, iolar <git.mail@iolar.nl>
1 parent c4789e7 commit 256556e

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

include/ocpp/v201/ctrlr_component_variables.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct RequiredComponentVariable : ComponentVariable {
2424
///
2525
RequiredComponentVariable(const Component component, const std::optional<Variable> variable,
2626
const std::optional<CustomData> custom_data = std::nullopt,
27-
const std::set<OcppProtocolVersion> required_for = {OcppProtocolVersion::v201,
27+
const std::set<OcppProtocolVersion>& required_for = {OcppProtocolVersion::v201,
2828
OcppProtocolVersion::v21}) :
2929
ComponentVariable(), required_for(required_for) {
3030
this->component = component;

include/ocpp/v201/functional_blocks/diagnostics.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class Diagnostics : public DiagnosticsInterface {
7171

7272
/// \brief Callback function that can be called to clear customer information based on the given arguments
7373
std::optional<ClearCustomerInformationCallback> clear_customer_information_callback;
74+
const bool is_monitoring_available;
7475

7576
private: // Functions
7677
/* OCPP message requests */
@@ -109,5 +110,9 @@ class Diagnostics : public DiagnosticsInterface {
109110
void clear_customer_information(const std::optional<CertificateHashDataType> customer_certificate,
110111
const std::optional<IdToken> id_token,
111112
const std::optional<CiString<64>> customer_identifier);
113+
114+
/// \brief Check if monitoring is available and if not, throw.
115+
/// \param type Message type to include in MessageTypeNotImplementedException when thrown.
116+
void throw_when_monitoring_not_available(const MessageType type);
112117
};
113118
} // namespace ocpp::v201

lib/ocpp/v201/charge_point.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,14 @@ void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_st
709709
*this->database_handler, this->callbacks.set_charging_profiles_callback);
710710
}
711711

712-
this->tariff_and_cost = std::make_unique<TariffAndCost>(
713-
*this->message_dispatcher, *this->device_model, *this->evse_manager, *this->meter_values,
714-
this->callbacks.set_display_message_callback, this->callbacks.set_running_cost_callback, this->io_service);
712+
if (device_model->get_optional_value<bool>(ControllerComponentVariables::TariffCostCtrlrAvailableCost)
713+
.value_or(false) ||
714+
device_model->get_optional_value<bool>(ControllerComponentVariables::TariffCostCtrlrAvailableTariff)
715+
.value_or(false)) {
716+
this->tariff_and_cost = std::make_unique<TariffAndCost>(
717+
*this->message_dispatcher, *this->device_model, *this->evse_manager, *this->meter_values,
718+
this->callbacks.set_display_message_callback, this->callbacks.set_running_cost_callback, this->io_service);
719+
}
715720

716721
Component ocpp_comm_ctrlr = {"OCPPCommCtrlr"};
717722
Variable field_length = {"FieldLength"};
@@ -823,7 +828,12 @@ void ChargePoint::handle_message(const EnhancedMessage<v201::MessageType>& messa
823828
}
824829
break;
825830
case MessageType::CostUpdated:
826-
this->tariff_and_cost->handle_message(message);
831+
if (this->tariff_and_cost != nullptr) {
832+
this->tariff_and_cost->handle_message(message);
833+
} else {
834+
send_not_implemented_error(message.uniqueId, message.messageTypeId);
835+
}
836+
827837
break;
828838
default:
829839
send_not_implemented_error(message.uniqueId, message.messageTypeId);
@@ -1690,7 +1700,10 @@ void ChargePoint::handle_transaction_event_response(const EnhancedMessage<v201::
16901700
this->callbacks.transaction_event_response_callback.value()(original_msg, call_result.msg);
16911701
}
16921702

1693-
this->tariff_and_cost->handle_cost_and_tariff(call_result.msg, original_msg, message.message[CALLRESULT_PAYLOAD]);
1703+
if (tariff_and_cost != nullptr) {
1704+
this->tariff_and_cost->handle_cost_and_tariff(call_result.msg, original_msg,
1705+
message.message[CALLRESULT_PAYLOAD]);
1706+
}
16941707

16951708
if (original_msg.eventType == TransactionEventEnum::Ended) {
16961709
// nothing to do for TransactionEventEnum::Ended

lib/ocpp/v201/functional_blocks/authorization.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ void ocpp::v201::Authorization::cache_cleanup_handler() {
483483
void ocpp::v201::Authorization::handle_send_local_authorization_list_req(Call<SendLocalListRequest> call) {
484484
SendLocalListResponse response;
485485

486-
if (this->device_model.get_optional_value<bool>(ControllerComponentVariables::LocalAuthListCtrlrEnabled)
486+
if (this->device_model.get_optional_value<bool>(ControllerComponentVariables::LocalAuthListCtrlrAvailable)
487+
.value_or(false) &&
488+
this->device_model.get_optional_value<bool>(ControllerComponentVariables::LocalAuthListCtrlrEnabled)
487489
.value_or(false)) {
488490
response.status = apply_local_authorization_list(call.msg);
489491
} else {
@@ -522,7 +524,9 @@ void ocpp::v201::Authorization::handle_send_local_authorization_list_req(Call<Se
522524
void ocpp::v201::Authorization::handle_get_local_authorization_list_version_req(Call<GetLocalListVersionRequest> call) {
523525
GetLocalListVersionResponse response;
524526

525-
if (this->device_model.get_optional_value<bool>(ControllerComponentVariables::LocalAuthListCtrlrEnabled)
527+
if (this->device_model.get_optional_value<bool>(ControllerComponentVariables::LocalAuthListCtrlrAvailable)
528+
.value_or(false) &&
529+
this->device_model.get_optional_value<bool>(ControllerComponentVariables::LocalAuthListCtrlrEnabled)
526530
.value_or(false)) {
527531
try {
528532
response.versionNumber = this->database_handler.get_local_authorization_list_version();

lib/ocpp/v201/functional_blocks/diagnostics.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ Diagnostics::Diagnostics(MessageDispatcherInterface<MessageType>& message_dispat
3939
[this]() { return !this->connectivity_manager.is_websocket_connected(); }),
4040
get_log_request_callback(get_log_request_callback),
4141
get_customer_information_callback(get_customer_information_callback),
42-
clear_customer_information_callback(clear_customer_information_callback) {
42+
clear_customer_information_callback(clear_customer_information_callback),
43+
is_monitoring_available(
44+
this->device_model.get_optional_value<bool>(ControllerComponentVariables::MonitoringCtrlrAvailable)
45+
.value_or(false)) {
4346
}
4447

4548
void Diagnostics::handle_message(const ocpp::EnhancedMessage<MessageType>& message) {
@@ -52,18 +55,23 @@ void Diagnostics::handle_message(const ocpp::EnhancedMessage<MessageType>& messa
5255
this->handle_customer_information_req(json_message);
5356
break;
5457
case MessageType::SetMonitoringBase:
58+
this->throw_when_monitoring_not_available(message.messageType);
5559
this->handle_set_monitoring_base_req(json_message);
5660
break;
5761
case MessageType::SetMonitoringLevel:
62+
this->throw_when_monitoring_not_available(message.messageType);
5863
this->handle_set_monitoring_level_req(json_message);
5964
break;
6065
case MessageType::SetVariableMonitoring:
66+
this->throw_when_monitoring_not_available(message.messageType);
6167
this->handle_set_variable_monitoring_req(message);
6268
break;
6369
case MessageType::GetMonitoringReport:
70+
this->throw_when_monitoring_not_available(message.messageType);
6471
this->handle_get_monitoring_report_req(json_message);
6572
break;
6673
case MessageType::ClearVariableMonitoring:
74+
this->throw_when_monitoring_not_available(message.messageType);
6775
this->handle_clear_variable_monitoring_req(json_message);
6876
break;
6977
default:
@@ -402,4 +410,10 @@ void Diagnostics::clear_customer_information(const std::optional<CertificateHash
402410
}
403411
}
404412

413+
void Diagnostics::throw_when_monitoring_not_available(const MessageType type) {
414+
if (!is_monitoring_available) {
415+
throw MessageTypeNotImplementedException(type);
416+
}
417+
}
418+
405419
} // namespace ocpp::v201

lib/ocpp/v201/functional_blocks/display_message.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void DisplayMessageBlock::handle_set_display_message(const Call<SetDisplayMessag
101101
this->evse_manager.get_transaction_evseid(call.msg.message.transactionId.value()) != std::nullopt);
102102

103103
// Check if display messages are available.
104-
if (!display_message_available.has_value() or !display_message_available.value()) {
104+
if (!display_message_available.value_or(false)) {
105105
error = true;
106106
response.status = DisplayMessageStatusEnum::Rejected;
107107
}

0 commit comments

Comments
 (0)