Skip to content

Commit

Permalink
add triggerStatusNotif which is aware about errorData
Browse files Browse the repository at this point in the history
  • Loading branch information
matth-x committed Aug 21, 2024
1 parent 7e017cf commit 9162b9a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
31 changes: 31 additions & 0 deletions src/MicroOcpp/Model/ConnectorBase/Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,37 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
return nullptr;
}

bool Connector::triggerStatusNotification() {

ErrorData errorData {nullptr};
errorData.severity = 0;

if (reportedErrorIndex >= 0) {
errorData = errorDataInputs[reportedErrorIndex].operator()();
} else {
//find errorData with maximum severity
for (auto i = errorDataInputs.size(); i >= 1; i--) {
auto index = i - 1;
ErrorData error = errorDataInputs[index].operator()();
if (error.isError && error.severity >= errorData.severity) {
errorData = error;
}
}
}

auto statusNotification = makeRequest(new Ocpp16::StatusNotification(
connectorId,
getStatus(),
context.getModel().getClock().now(),
errorData));

statusNotification->setTimeout(60000);

context.getRequestQueue().sendRequestPreBoot(std::move(statusNotification));

return true;
}

unsigned int Connector::getTxNrBeginHistory() {
return txNrBegin;
}
Expand Down
2 changes: 2 additions & 0 deletions src/MicroOcpp/Model/ConnectorBase/Connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class Connector : public RequestEmitter, public MemoryManaged {
unsigned int getFrontRequestOpNr() override;
std::unique_ptr<Request> fetchFrontRequest() override;

bool triggerStatusNotification();

unsigned int getTxNrBeginHistory(); //if getTxNrBeginHistory() != getTxNrFront(), then return value is the txNr of the oldest tx history entry. If equal to getTxNrFront(), then the history is empty
unsigned int getTxNrFront(); //if getTxNrEnd() != getTxNrFront(), then return value is the txNr of the oldest transaction queued to be sent to the server. If equal to getTxNrEnd(), then there is no tx to be sent to the server
unsigned int getTxNrEnd(); //upper limit for the range of valid txNrs
Expand Down
14 changes: 3 additions & 11 deletions src/MicroOcpp/Operations/TriggerMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <MicroOcpp/Operations/TriggerMessage.h>
#include <MicroOcpp/Model/ConnectorBase/Connector.h>
#include <MicroOcpp/Model/Metering/MeteringService.h>
#include <MicroOcpp/Operations/StatusNotification.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Core/Context.h>
#include <MicroOcpp/Core/Request.h>
Expand Down Expand Up @@ -63,16 +62,9 @@ void TriggerMessage::processReq(JsonObject payload) {

for (auto i = cIdRangeBegin; i < cIdRangeEnd; i++) {
auto connector = context.getModel().getConnector(i);

auto statusNotification = makeRequest(new Ocpp16::StatusNotification(
i,
connector->getStatus(), //will be determined in StatusNotification::initiate
context.getModel().getClock().now()));

statusNotification->setTimeout(60000);

context.getRequestQueue().sendRequestPreBoot(std::move(statusNotification));
statusMessage = "Accepted";
if (connector->triggerStatusNotification()) {
statusMessage = "Accepted";
}
}
} else {
auto msg = context.getOperationRegistry().deserializeOperation(requestedMessage);
Expand Down

0 comments on commit 9162b9a

Please sign in to comment.