Skip to content

Commit

Permalink
* Added global counter for NotifyEvent eventId
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Pietfried committed Jan 6, 2025
1 parent 92274c3 commit 1155b7c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
17 changes: 17 additions & 0 deletions include/ocpp/common/incremental_counter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#pragma once

#include <atomic>

namespace ocpp {
class IncrementalCounter {
public:
static int get();

private:
static std::atomic<unsigned int> counter;
};

} // namespace ocpp
2 changes: 2 additions & 0 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

void message_callback(const std::string& message);
void update_aligned_data_interval();
void notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
const ConnectorStatusEnum status);

/// \brief Helper function to determine if there is any active transaction for the given \p evse
/// \param evse if optional is not set, this function will check if there is any transaction active f or the whole
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ target_sources(ocpp
PRIVATE
ocpp/common/call_types.cpp
ocpp/common/charging_station_base.cpp
ocpp/common/incremental_counter.cpp
ocpp/common/ocpp_logging.cpp
ocpp/common/schemas.cpp
ocpp/common/types.cpp
Expand Down
14 changes: 14 additions & 0 deletions lib/ocpp/common/incremental_counter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#include <ocpp/common/incremental_counter.hpp>

namespace ocpp {

std::atomic<unsigned int> IncrementalCounter::counter{0};

int IncrementalCounter::get() {
return ++counter;
}

} // namespace ocpp
24 changes: 23 additions & 1 deletion lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright Pionix GmbH and Contributors to EVerest

#include <ocpp/common/constants.hpp>
#include <ocpp/common/incremental_counter.hpp>
#include <ocpp/common/types.hpp>
#include <ocpp/v201/charge_point.hpp>
#include <ocpp/v201/ctrlr_component_variables.hpp>
Expand Down Expand Up @@ -1065,6 +1066,21 @@ void ChargePoint::on_reservation_status(const int32_t reservation_id, const Rese
}
}

void ChargePoint::notify_event_req_connector_status_update(const int32_t evse_id, const int32_t connector_id,
const ConnectorStatusEnum status) {
ocpp::v201::EventData event_data;
const auto cv = ConnectorComponentVariables::get_component_variable(evse_id, connector_id,
ConnectorComponentVariables::AvailabilityState);
event_data.eventId = ocpp::IncrementalCounter::get();
event_data.actualValue = conversions::connector_status_enum_to_string(status);
event_data.trigger = EventTriggerEnum::Delta;
event_data.variable = cv.variable.value();
event_data.component = cv.component;
event_data.timestamp = ocpp::DateTime();
event_data.eventNotificationType = EventNotificationEnum::HardWiredNotification;
this->notify_event_req({event_data});
}

void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_structure,
const std::string& message_log_path) {
this->device_model->check_integrity(evse_connector_structure);
Expand All @@ -1077,7 +1093,13 @@ void ChargePoint::initialize(const std::map<int32_t, int32_t>& evse_connector_st
this->registration_status != RegistrationStatusEnum::Accepted) {
return false;
} else {
this->status_notification_req(evse_id, connector_id, status, initiated_by_trigger_message);
if (this->ocpp_version == OcppProtocolVersion::v201) {
// OCPP2.0.1: B01.FR.05
this->status_notification_req(evse_id, connector_id, status, initiated_by_trigger_message);
} else {
// OCPP2.1: B01.FR.05
this->notify_event_req_connector_status_update(evse_id, connector_id, status);
}
return true;
}
});
Expand Down

0 comments on commit 1155b7c

Please sign in to comment.