Skip to content

Commit 1098e95

Browse files
heakinsmatth-x
authored andcommitted
TC_037_1, TC037_2: Deduplicate StatusNotifications in RequestQueue
From the OCPP Spec: > The Charge Point SHOULD NOT send StatusNotification.req PDUs for > historical status change events that happened while the Charge > Point was offline. So, each time we queue another StatusNotification, we drop the StatusNotifications already in the queue for that connector.
1 parent eb41d89 commit 1098e95

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/MicroOcpp/Core/Request.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ void Request::setOperation(std::unique_ptr<Operation> msg){
3434
operation = std::move(msg);
3535
}
3636

37+
std::unique_ptr<Operation>& Request::getOperation(){
38+
return operation;
39+
}
40+
3741
void Request::setTimeout(unsigned long timeout) {
3842
this->timeout_period = timeout;
3943
}

src/MicroOcpp/Core/Request.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Request {
4949
~Request();
5050

5151
void setOperation(std::unique_ptr<Operation> msg);
52+
std::unique_ptr<Operation>& getOperation();
5253

5354
void setTimeout(unsigned long timeout); //0 = disable timeout
5455
bool isTimeoutExceeded();

src/MicroOcpp/Core/RequestQueue.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <MicroOcpp/Core/OcppError.h>
1010
#include <MicroOcpp/Core/RequestStore.h>
1111
#include <MicroOcpp/Core/OperationRegistry.h>
12+
#include <MicroOcpp/Operations/StatusNotification.h>
1213

1314
#include <MicroOcpp/Debug.h>
1415

@@ -129,7 +130,21 @@ void RequestQueue::sendRequest(std::unique_ptr<Request> op){
129130
MO_DBG_ERR("Called with null. Ignore");
130131
return;
131132
}
132-
133+
134+
// Don't queue up multiple StatusNotification messages for the same connectorId
135+
if (strcmp(op->getOperationType(), "StatusNotification") == 0)
136+
{
137+
auto new_status_notification = static_cast<Ocpp16::StatusNotification*>(op->getOperation().get());
138+
initiatedRequests->drop_if([&new_status_notification] (const std::unique_ptr<Request>& operation) {
139+
if (strcmp(operation->getOperationType(), "StatusNotification")!= 0)
140+
{
141+
return false;
142+
}
143+
auto old_status_notification = static_cast<Ocpp16::StatusNotification*>(operation->getOperation().get());
144+
return old_status_notification->getConnectorId() == new_status_notification->getConnectorId();
145+
});
146+
}
147+
133148
initiatedRequests->push_back(std::move(op));
134149
}
135150

src/MicroOcpp/Operations/StatusNotification.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class StatusNotification : public Operation {
3535
void processReq(JsonObject payload) override;
3636

3737
std::unique_ptr<DynamicJsonDocument> createConf() override;
38+
39+
int getConnectorId() {
40+
return connectorId;
41+
}
3842
};
3943

4044
} // namespace Ocpp16

0 commit comments

Comments
 (0)