Skip to content

Commit 736354a

Browse files
committed
Moved new notify_event functionality into diagnostics functional block
Signed-off-by: Piet Gömpel <pietgoempel@gmail.com>
1 parent b5112b8 commit 736354a

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
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/functional_blocks/diagnostics.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class DiagnosticsInterface : public MessageHandlerInterface {
3737

3838
/* OCPP message requests */
3939
virtual void notify_event_req(const std::vector<EventData>& events) = 0;
40+
virtual void notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
41+
const ConnectorStatusEnum status) = 0;
4042

4143
/* Monitoring */
4244
virtual void stop_monitoring() = 0;
@@ -53,6 +55,8 @@ class Diagnostics : public DiagnosticsInterface {
5355
std::optional<ClearCustomerInformationCallback> clear_customer_information_callback);
5456
void handle_message(const ocpp::EnhancedMessage<MessageType>& message) override;
5557
void notify_event_req(const std::vector<EventData>& events) override;
58+
void notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
59+
const ConnectorStatusEnum status) override;
5660
void stop_monitoring() override;
5761
void start_monitoring() override;
5862
void process_triggered_monitors() override;

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,14 @@ void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_st
368368
this->registration_status != RegistrationStatusEnum::Accepted) {
369369
return false;
370370
} else {
371-
this->availability->status_notification_req(evse_id, connector_id, status,
372-
initiated_by_trigger_message);
371+
if (this->ocpp_version == OcppProtocolVersion::v201) {
372+
// OCPP2.0.1: B01.FR.05
373+
this->availability->status_notification_req(evse_id, connector_id, status,
374+
initiated_by_trigger_message);
375+
} else {
376+
// OCPP2.1: B01.FR.05
377+
this->diagnostics->notify_event_req_connector_status_update(evse_id, connector_id, status);
378+
}
373379
return true;
374380
}
375381
});

lib/ocpp/v201/functional_blocks/diagnostics.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <ocpp/v201/functional_blocks/diagnostics.hpp>
55

66
#include <ocpp/common/constants.hpp>
7+
#include <ocpp/common/incremental_counter.hpp>
8+
79
#include <ocpp/v201/connectivity_manager.hpp>
810
#include <ocpp/v201/ctrlr_component_variables.hpp>
911
#include <ocpp/v201/device_model.hpp>
@@ -81,6 +83,21 @@ void Diagnostics::notify_event_req(const std::vector<EventData>& events) {
8183
this->message_dispatcher.dispatch_call(call);
8284
}
8385

86+
void Diagnostics::notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
87+
const ConnectorStatusEnum status) {
88+
ocpp::v201::EventData event_data;
89+
const auto cv = ConnectorComponentVariables::get_component_variable(evse_id, connector_id,
90+
ConnectorComponentVariables::AvailabilityState);
91+
event_data.eventId = ocpp::IncrementalCounter::get();
92+
event_data.actualValue = conversions::connector_status_enum_to_string(status);
93+
event_data.trigger = EventTriggerEnum::Delta;
94+
event_data.variable = cv.variable.value();
95+
event_data.component = cv.component;
96+
event_data.timestamp = ocpp::DateTime();
97+
event_data.eventNotificationType = EventNotificationEnum::HardWiredNotification;
98+
this->notify_event_req({event_data});
99+
}
100+
84101
void Diagnostics::stop_monitoring() {
85102
monitoring_updater.stop_monitoring();
86103
}

0 commit comments

Comments
 (0)