Skip to content

Commit c4789e7

Browse files
committed
Aligned data ctrlr and sampled data ctrlr must always be available and the required variables are really always required. Only make smart charging ctrlr if smart charging is available.
Signed-off-by: Maaike Zijderveld, iolar <git.mail@iolar.nl>
1 parent c0c4e42 commit c4789e7

File tree

3 files changed

+54
-28
lines changed

3 files changed

+54
-28
lines changed

include/ocpp/v201/ctrlr_component_variables.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ struct RequiredComponentVariable : ComponentVariable {
1515
/// \brief Constructor
1616
RequiredComponentVariable() : required_for({OcppProtocolVersion::v201, OcppProtocolVersion::v21}) {};
1717

18-
///
19-
/// \brief RequiredComponentVariable
20-
/// \param component Component
21-
/// \param variable Variable
22-
/// \param custom_data Custom data (default nullopt)
23-
/// \param required_for Required for which version. Multiple versions can be given.
24-
///
18+
///
19+
/// \brief RequiredComponentVariable
20+
/// \param component Component
21+
/// \param variable Variable
22+
/// \param custom_data Custom data (default nullopt)
23+
/// \param required_for Required for which version. Multiple versions can be given.
24+
///
2525
RequiredComponentVariable(const Component component, const std::optional<Variable> variable,
2626
const std::optional<CustomData> custom_data = std::nullopt,
2727
const std::set<OcppProtocolVersion> required_for = {OcppProtocolVersion::v201,
@@ -32,7 +32,7 @@ struct RequiredComponentVariable : ComponentVariable {
3232
this->customData = custom_data;
3333
};
3434

35-
/// \brief For which ocpp protocol version(s) this component variable is required.
35+
/// \brief For which ocpp protocol version(s) this component variable is required.
3636
std::set<OcppProtocolVersion> required_for;
3737
};
3838

lib/ocpp/v201/charge_point.cpp

+37-10
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ void ChargePoint::start(BootReasonEnum bootreason, bool start_connecting) {
100100
this->message_queue->get_persisted_messages_from_db();
101101
this->boot_notification_req(bootreason);
102102
// call clear_invalid_charging_profiles when system boots
103-
this->clear_invalid_charging_profiles();
103+
if (this->smart_charging != nullptr) {
104+
this->clear_invalid_charging_profiles();
105+
}
106+
104107
if (start_connecting) {
105108
this->connectivity_manager->connect();
106109
}
@@ -306,7 +309,9 @@ void ChargePoint::on_transaction_finished(const int32_t evse_id, const DateTime&
306309
transaction_id_token, meter_values, std::nullopt, this->is_offline(), std::nullopt);
307310

308311
// K02.FR.05 The transaction is over, so delete the TxProfiles associated with the transaction.
309-
smart_charging->delete_transaction_tx_profiles(enhanced_transaction->get_transaction().transactionId);
312+
if (smart_charging != nullptr) {
313+
smart_charging->delete_transaction_tx_profiles(enhanced_transaction->get_transaction().transactionId);
314+
}
310315
evse_handle.release_transaction();
311316

312317
bool send_reset = false;
@@ -697,9 +702,12 @@ void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_st
697702
this->callbacks.configure_network_connection_profile_callback.value());
698703
}
699704

700-
this->smart_charging = std::make_unique<SmartCharging>(
701-
*this->device_model, *this->evse_manager, *this->connectivity_manager, *this->message_dispatcher,
702-
*this->database_handler, this->callbacks.set_charging_profiles_callback);
705+
if (device_model->get_optional_value<bool>(ControllerComponentVariables::SmartChargingCtrlrAvailable)
706+
.value_or(false)) {
707+
this->smart_charging = std::make_unique<SmartCharging>(
708+
*this->device_model, *this->evse_manager, *this->connectivity_manager, *this->message_dispatcher,
709+
*this->database_handler, this->callbacks.set_charging_profiles_callback);
710+
}
703711

704712
this->tariff_and_cost = std::make_unique<TariffAndCost>(
705713
*this->message_dispatcher, *this->device_model, *this->evse_manager, *this->meter_values,
@@ -799,7 +807,11 @@ void ChargePoint::handle_message(const EnhancedMessage<v201::MessageType>& messa
799807
case MessageType::ClearChargingProfile:
800808
case MessageType::GetChargingProfiles:
801809
case MessageType::GetCompositeSchedule:
802-
this->smart_charging->handle_message(message);
810+
if (this->smart_charging != nullptr) {
811+
this->smart_charging->handle_message(message);
812+
} else {
813+
send_not_implemented_error(message.uniqueId, message.messageTypeId);
814+
}
803815
break;
804816
case MessageType::GetDisplayMessages:
805817
case MessageType::SetDisplayMessage:
@@ -2036,9 +2048,12 @@ void ChargePoint::handle_remote_start_transaction_request(Call<RequestStartTrans
20362048
// with RequestStartTransactionResponse with status = Rejected and optionally with reasonCode =
20372049
// "InvalidProfile" or "InvalidSchedule".
20382050

2039-
bool is_smart_charging_enabled =
2051+
const bool is_smart_charging_enabled =
2052+
this->device_model->get_optional_value<bool>(ControllerComponentVariables::SmartChargingCtrlrAvailable)
2053+
.value_or(false) &&
20402054
this->device_model->get_optional_value<bool>(ControllerComponentVariables::SmartChargingCtrlrEnabled)
2041-
.value_or(false);
2055+
.value_or(false) &&
2056+
this->smart_charging != nullptr;
20422057

20432058
if (is_smart_charging_enabled) {
20442059
if (msg.chargingProfile.has_value()) {
@@ -2256,8 +2271,9 @@ void ChargePoint::clear_invalid_charging_profiles() {
22562271
for (const auto& [evse_id, profiles] : evses) {
22572272
for (auto profile : profiles) {
22582273
try {
2259-
if (this->smart_charging->conform_and_validate_profile(profile, evse_id) !=
2260-
ProfileValidationResultEnum::Valid) {
2274+
if (this->smart_charging != nullptr &&
2275+
this->smart_charging->conform_and_validate_profile(profile, evse_id) !=
2276+
ProfileValidationResultEnum::Valid) {
22612277
this->database_handler->delete_charging_profile(profile.id);
22622278
}
22632279
} catch (const QueryExecutionException& e) {
@@ -2300,16 +2316,27 @@ ChargePoint::set_variables(const std::vector<SetVariableData>& set_variable_data
23002316
}
23012317

23022318
GetCompositeScheduleResponse ChargePoint::get_composite_schedule(const GetCompositeScheduleRequest& request) {
2319+
if (this->smart_charging == nullptr) {
2320+
GetCompositeScheduleResponse response;
2321+
response.status = GenericStatusEnum::Rejected;
2322+
return response;
2323+
}
23032324
return this->smart_charging->get_composite_schedule(request);
23042325
}
23052326

23062327
std::optional<CompositeSchedule> ChargePoint::get_composite_schedule(int32_t evse_id, std::chrono::seconds duration,
23072328
ChargingRateUnitEnum unit) {
2329+
if (this->smart_charging == nullptr) {
2330+
return std::nullopt;
2331+
}
23082332
return this->smart_charging->get_composite_schedule(evse_id, duration, unit);
23092333
}
23102334

23112335
std::vector<CompositeSchedule> ChargePoint::get_all_composite_schedules(const int32_t duration_s,
23122336
const ChargingRateUnitEnum& unit) {
2337+
if (this->smart_charging == nullptr) {
2338+
return {};
2339+
}
23132340
return this->smart_charging->get_all_composite_schedules(duration_s, unit);
23142341
}
23152342

lib/ocpp/v201/ctrlr_component_variables.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -1195,20 +1195,10 @@ ComponentVariable get_component_variable(const int32_t evse_id, const int32_t co
11951195

11961196
const std::vector<std::pair<ComponentVariable, std::vector<RequiredComponentVariable>>>
11971197
required_component_available_variables{
1198-
{ControllerComponentVariables::AlignedDataCtrlrAvailable,
1199-
{ControllerComponentVariables::AlignedDataInterval, ControllerComponentVariables::AlignedDataMeasurands,
1200-
ControllerComponentVariables::AlignedDataTxEndedInterval,
1201-
ControllerComponentVariables::AlignedDataTxEndedMeasurands}},
12021198
{ControllerComponentVariables::LocalAuthListCtrlrAvailable,
12031199
{ControllerComponentVariables::LocalAuthListCtrlrEntries,
12041200
ControllerComponentVariables::ItemsPerMessageSendLocalList,
12051201
ControllerComponentVariables::BytesPerMessageSendLocalList}},
1206-
{ControllerComponentVariables::SampledDataCtrlrAvailable,
1207-
{ControllerComponentVariables::SampledDataTxEndedMeasurands,
1208-
ControllerComponentVariables::SampledDataTxEndedInterval,
1209-
ControllerComponentVariables::SampledDataTxStartedMeasurands,
1210-
ControllerComponentVariables::SampledDataTxUpdatedMeasurands,
1211-
ControllerComponentVariables::SampledDataTxUpdatedInterval}},
12121202
{ControllerComponentVariables::SmartChargingCtrlrAvailable,
12131203
{ControllerComponentVariables::ChargingProfileMaxStackLevel,
12141204
ControllerComponentVariables::ChargingScheduleChargingRateUnit,
@@ -1232,6 +1222,15 @@ const std::vector<std::pair<ComponentVariable, std::vector<RequiredComponentVari
12321222
ControllerComponentVariables::DisplayMessageSupportedPriorities}}};
12331223

12341224
const std::vector<RequiredComponentVariable> required_variables{
1225+
ControllerComponentVariables::AlignedDataInterval,
1226+
ControllerComponentVariables::AlignedDataMeasurands,
1227+
ControllerComponentVariables::AlignedDataTxEndedInterval,
1228+
ControllerComponentVariables::AlignedDataTxEndedMeasurands,
1229+
ControllerComponentVariables::SampledDataTxEndedMeasurands,
1230+
ControllerComponentVariables::SampledDataTxEndedInterval,
1231+
ControllerComponentVariables::SampledDataTxStartedMeasurands,
1232+
ControllerComponentVariables::SampledDataTxUpdatedMeasurands,
1233+
ControllerComponentVariables::SampledDataTxUpdatedInterval,
12351234
ControllerComponentVariables::ChargePointId,
12361235
ControllerComponentVariables::NetworkConnectionProfiles,
12371236
ControllerComponentVariables::ChargeBoxSerialNumber,

0 commit comments

Comments
 (0)