Skip to content

Commit

Permalink
Queue up session events in OCPP 1.6 module before initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored and corneliusclaussen committed Dec 12, 2023
1 parent c3cb061 commit cf68de5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 16 additions & 4 deletions modules/OCPP/OCPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ void OCPP::init_evse_subscriptions() {
}

if (!this->started) {
EVLOG_error << "OCPP not fully initialized, but received a session event on evse_id: " << evse_id
<< " that will be discarded: " << session_event.event;
EVLOG_info << "OCPP not fully initialized, but received a session event on evse_id: " << evse_id
<< " that will be queued up: " << session_event.event;
std::scoped_lock lock(this->session_event_mutex);
this->session_event_queue[evse_id].push(session_event);
return;
}

Expand Down Expand Up @@ -626,8 +628,6 @@ void OCPP::ready() {

this->charge_point->register_enable_evse_callback([this](int32_t connector) {
if (this->connector_evse_index_map.count(connector)) {
// FIXME(kai): these callbacks can already be called from within libocpp during its startup, so we might see
// some issues here...
return this->r_evse_manager.at(this->connector_evse_index_map.at(connector))->call_enable(0);
} else {
return false;
Expand Down Expand Up @@ -727,6 +727,18 @@ void OCPP::ready() {
// signal that we're started
this->started = true;
EVLOG_info << "OCPP initialized";

// process session event queue
std::scoped_lock lock(this->session_event_mutex);
for (auto& [evse_id, evse_session_event_queue] : this->session_event_queue) {
while (!evse_session_event_queue.empty()) {
auto queued_session_event = evse_session_event_queue.front();
EVLOG_info << "Processing queued session event for evse_id: " << evse_id
<< ", event: " << queued_session_event.event;
this->process_session_event(evse_id, queued_session_event);
evse_session_event_queue.pop();
}
}
}

// signal to the EVSEs that OCPP is initialized
Expand Down
2 changes: 2 additions & 0 deletions modules/OCPP/OCPP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class OCPP : public Everest::ModuleBase {
bool all_evse_ready();

std::atomic_bool started{false};
std::mutex session_event_mutex;
std::map<int32_t, std::queue<types::evse_manager::SessionEvent>> session_event_queue;
void process_session_event(int32_t evse_id, const types::evse_manager::SessionEvent& session_event);
// ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1
};
Expand Down

0 comments on commit cf68de5

Please sign in to comment.