Skip to content

Commit 808d294

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 Signed-off-by: Piet Gömpel <pietgoempel@gmail.com>
1 parent 9927801 commit 808d294

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
@@ -488,6 +488,8 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
488488

489489
void message_callback(const std::string& message);
490490
void update_aligned_data_interval();
491+
void notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
492+
const ConnectorStatusEnum status);
491493

492494
/// \brief Helper function to determine if there is any active transaction for the given \p evse
493495
/// \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>
@@ -806,6 +807,21 @@ void ChargePoint::on_reservation_status(const int32_t reservation_id, const Rese
806807
}
807808
}
808809

810+
void ChargePoint::notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
811+
const ConnectorStatusEnum status) {
812+
ocpp::v201::EventData event_data;
813+
const auto cv = ConnectorComponentVariables::get_component_variable(evse_id, connector_id,
814+
ConnectorComponentVariables::AvailabilityState);
815+
event_data.eventId = ocpp::IncrementalCounter::get();
816+
event_data.actualValue = conversions::connector_status_enum_to_string(status);
817+
event_data.trigger = EventTriggerEnum::Delta;
818+
event_data.variable = cv.variable.value();
819+
event_data.component = cv.component;
820+
event_data.timestamp = ocpp::DateTime();
821+
event_data.eventNotificationType = EventNotificationEnum::HardWiredNotification;
822+
this->notify_event_req({event_data});
823+
}
824+
809825
void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_structure,
810826
const std::string& message_log_path) {
811827
this->device_model->check_integrity(evse_connector_structure);
@@ -818,7 +834,13 @@ void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_st
818834
this->registration_status != RegistrationStatusEnum::Accepted) {
819835
return false;
820836
} else {
821-
this->status_notification_req(evse_id, connector_id, status, initiated_by_trigger_message);
837+
if (this->ocpp_version == OcppProtocolVersion::v201) {
838+
// OCPP2.0.1: B01.FR.05
839+
this->status_notification_req(evse_id, connector_id, status, initiated_by_trigger_message);
840+
} else {
841+
// OCPP2.1: B01.FR.05
842+
this->notify_event_req_connector_status_update(evse_id, connector_id, status);
843+
}
822844
return true;
823845
}
824846
});

0 commit comments

Comments
 (0)