Skip to content

Commit 974b7b9

Browse files
authored
Support errorCode in triggered StatusNotifications (#359)
* add triggerStatusNotif which is aware about errorData * update changelog
1 parent 7e017cf commit 974b7b9

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- UnlockConnector NotSupported if connectorId invalid ([#344](https://github.com/matth-x/MicroOcpp/pull/344))
4444
- Fix regression bug of [#345](https://github.com/matth-x/MicroOcpp/pull/345) ([#353](https://github.com/matth-x/MicroOcpp/pull/353), [#356](https://github.com/matth-x/MicroOcpp/pull/356))
4545
- Correct MeterValue PreBoot timestamp ([#354](https://github.com/matth-x/MicroOcpp/pull/354))
46+
- Send errorCode in triggered StatusNotif ([#359](https://github.com/matth-x/MicroOcpp/pull/359))
4647

4748
## [1.1.0] - 2024-05-21
4849

src/MicroOcpp/Model/ConnectorBase/Connector.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,37 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12711271
return nullptr;
12721272
}
12731273

1274+
bool Connector::triggerStatusNotification() {
1275+
1276+
ErrorData errorData {nullptr};
1277+
errorData.severity = 0;
1278+
1279+
if (reportedErrorIndex >= 0) {
1280+
errorData = errorDataInputs[reportedErrorIndex].operator()();
1281+
} else {
1282+
//find errorData with maximum severity
1283+
for (auto i = errorDataInputs.size(); i >= 1; i--) {
1284+
auto index = i - 1;
1285+
ErrorData error = errorDataInputs[index].operator()();
1286+
if (error.isError && error.severity >= errorData.severity) {
1287+
errorData = error;
1288+
}
1289+
}
1290+
}
1291+
1292+
auto statusNotification = makeRequest(new Ocpp16::StatusNotification(
1293+
connectorId,
1294+
getStatus(),
1295+
context.getModel().getClock().now(),
1296+
errorData));
1297+
1298+
statusNotification->setTimeout(60000);
1299+
1300+
context.getRequestQueue().sendRequestPreBoot(std::move(statusNotification));
1301+
1302+
return true;
1303+
}
1304+
12741305
unsigned int Connector::getTxNrBeginHistory() {
12751306
return txNrBegin;
12761307
}

src/MicroOcpp/Model/ConnectorBase/Connector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ class Connector : public RequestEmitter, public MemoryManaged {
158158
unsigned int getFrontRequestOpNr() override;
159159
std::unique_ptr<Request> fetchFrontRequest() override;
160160

161+
bool triggerStatusNotification();
162+
161163
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
162164
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
163165
unsigned int getTxNrEnd(); //upper limit for the range of valid txNrs

src/MicroOcpp/Operations/TriggerMessage.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <MicroOcpp/Operations/TriggerMessage.h>
66
#include <MicroOcpp/Model/ConnectorBase/Connector.h>
77
#include <MicroOcpp/Model/Metering/MeteringService.h>
8-
#include <MicroOcpp/Operations/StatusNotification.h>
98
#include <MicroOcpp/Model/Model.h>
109
#include <MicroOcpp/Core/Context.h>
1110
#include <MicroOcpp/Core/Request.h>
@@ -63,16 +62,9 @@ void TriggerMessage::processReq(JsonObject payload) {
6362

6463
for (auto i = cIdRangeBegin; i < cIdRangeEnd; i++) {
6564
auto connector = context.getModel().getConnector(i);
66-
67-
auto statusNotification = makeRequest(new Ocpp16::StatusNotification(
68-
i,
69-
connector->getStatus(), //will be determined in StatusNotification::initiate
70-
context.getModel().getClock().now()));
71-
72-
statusNotification->setTimeout(60000);
73-
74-
context.getRequestQueue().sendRequestPreBoot(std::move(statusNotification));
75-
statusMessage = "Accepted";
65+
if (connector->triggerStatusNotification()) {
66+
statusMessage = "Accepted";
67+
}
7668
}
7769
} else {
7870
auto msg = context.getOperationRegistry().deserializeOperation(requestedMessage);

0 commit comments

Comments
 (0)