Skip to content

Commit 48bfe89

Browse files
committed
* Added global counter for NotifyEvent eventId
* Now using StatusNotification.req in case of OCPP2.0.1 and NotifyEvent.req in case of OCPP2.1 for status updates
1 parent 92274c3 commit 48bfe89

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Pionix GmbH and Contributors to EVerest
3+
4+
#pragma once
5+
6+
#include <atomic>
7+
8+
namespace ocpp {
9+
class IncrementalCounter {
10+
public:
11+
static int get();
12+
13+
private:
14+
static std::atomic<unsigned int> counter;
15+
};
16+
17+
} // namespace ocpp

include/ocpp/v201/charge_point.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
496496

497497
void message_callback(const std::string& message);
498498
void update_aligned_data_interval();
499+
void notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
500+
const ConnectorStatusEnum status);
499501

500502
/// \brief Helper function to determine if there is any active transaction for the given \p evse
501503
/// \param evse if optional is not set, this function will check if there is any transaction active f or the whole

lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ target_sources(ocpp
2020
PRIVATE
2121
ocpp/common/call_types.cpp
2222
ocpp/common/charging_station_base.cpp
23+
ocpp/common/incremental_counter.cpp
2324
ocpp/common/ocpp_logging.cpp
2425
ocpp/common/schemas.cpp
2526
ocpp/common/types.cpp
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Pionix GmbH and Contributors to EVerest
3+
4+
#include <ocpp/common/incremental_counter.hpp>
5+
6+
namespace ocpp {
7+
8+
std::atomic<unsigned int> IncrementalCounter::counter{0};
9+
10+
int IncrementalCounter::get() {
11+
return ++counter;
12+
}
13+
14+
} // namespace ocpp

lib/ocpp/v201/charge_point.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright Pionix GmbH and Contributors to EVerest
33

44
#include <ocpp/common/constants.hpp>
5+
#include <ocpp/common/incremental_counter.hpp>
56
#include <ocpp/common/types.hpp>
67
#include <ocpp/v201/charge_point.hpp>
78
#include <ocpp/v201/ctrlr_component_variables.hpp>
@@ -1065,6 +1066,21 @@ void ChargePoint::on_reservation_status(const int32_t reservation_id, const Rese
10651066
}
10661067
}
10671068

1069+
void ChargePoint::notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
1070+
const ConnectorStatusEnum status) {
1071+
ocpp::v201::EventData event_data;
1072+
const auto cv = ConnectorComponentVariables::get_component_variable(evse_id, connector_id,
1073+
ConnectorComponentVariables::AvailabilityState);
1074+
event_data.eventId = ocpp::IncrementalCounter::get();
1075+
event_data.actualValue = conversions::connector_status_enum_to_string(status);
1076+
event_data.trigger = EventTriggerEnum::Delta;
1077+
event_data.variable = cv.variable.value();
1078+
event_data.component = cv.component;
1079+
event_data.timestamp = ocpp::DateTime();
1080+
event_data.eventNotificationType = EventNotificationEnum::HardWiredNotification;
1081+
this->notify_event_req({event_data});
1082+
}
1083+
10681084
void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_structure,
10691085
const std::string& message_log_path) {
10701086
this->device_model->check_integrity(evse_connector_structure);
@@ -1077,7 +1093,13 @@ void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_st
10771093
this->registration_status != RegistrationStatusEnum::Accepted) {
10781094
return false;
10791095
} else {
1080-
this->status_notification_req(evse_id, connector_id, status, initiated_by_trigger_message);
1096+
if (this->ocpp_version == OcppProtocolVersion::v201) {
1097+
// OCPP2.0.1: B01.FR.05
1098+
this->status_notification_req(evse_id, connector_id, status, initiated_by_trigger_message);
1099+
} else {
1100+
// OCPP2.1: B01.FR.05
1101+
this->notify_event_req_connector_status_update(evse_id, connector_id, status);
1102+
}
10811103
return true;
10821104
}
10831105
});

0 commit comments

Comments
 (0)