Skip to content

Commit 62e05dc

Browse files
committed
optional attemptNr rollback if offline
1 parent 974b7b9 commit 62e05dc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/MicroOcpp/Model/ConnectorBase/Connector.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,7 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
11721172
return nullptr;
11731173
}
11741174

1175+
const auto attemptNr_capture = transactionFront->getStartSync().getAttemptNr();
11751176
transactionFront->getStartSync().advanceAttemptNr();
11761177
transactionFront->getStartSync().setAttemptTime(model.getClock().now());
11771178
transactionFront->commit();
@@ -1203,6 +1204,19 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12031204
}
12041205
});
12051206

1207+
#if MO_TX_ATTEMPT_TIMEOUT == 0
1208+
//a timeout should not increase the attemptNr. Roll back to previous attemptNr
1209+
startTx->setOnTimeoutListener([transactionFront_capture, attemptNr_capture] () {
1210+
MO_DBG_DEBUG("StartTx timeout -> roll back attemptNr and try again");
1211+
if (transactionFront_capture) {
1212+
transactionFront_capture->getStartSync().setAttemptNr(attemptNr_capture);
1213+
transactionFront_capture->commit();
1214+
}
1215+
});
1216+
#else
1217+
(void)attemptNr_capture;
1218+
#endif
1219+
12061220
return startTx;
12071221
}
12081222

@@ -1229,6 +1243,7 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12291243
return nullptr;
12301244
}
12311245

1246+
const auto attemptNr_capture = transactionFront->getStopSync().getAttemptNr();
12321247
transactionFront->getStopSync().advanceAttemptNr();
12331248
transactionFront->getStopSync().setAttemptTime(model.getClock().now());
12341249
transactionFront->commit();
@@ -1264,6 +1279,19 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12641279
}
12651280
});
12661281

1282+
#if MO_TX_ATTEMPT_TIMEOUT == 0
1283+
//a timeout should not increase the attemptNr. Roll back to previous attemptNr
1284+
stopTx->setOnTimeoutListener([transactionFront_capture, attemptNr_capture] () {
1285+
MO_DBG_DEBUG("StopTx timeout -> roll back attemptNr and try again");
1286+
if (transactionFront_capture) {
1287+
transactionFront_capture->getStopSync().setAttemptNr(attemptNr_capture);
1288+
transactionFront_capture->commit();
1289+
}
1290+
});
1291+
#else
1292+
(void)attemptNr_capture;
1293+
#endif
1294+
12671295
return stopTx;
12681296
}
12691297
}

src/MicroOcpp/Model/ConnectorBase/Connector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#define MO_REPORT_NOERROR 0
2929
#endif
3030

31+
#ifndef MO_TX_ATTEMPT_TIMEOUT
32+
#define MO_TX_ATTEMPT_TIMEOUT 1 //if the timeout of a tx-related msg should increase its attempt counter
33+
#endif
34+
3135
namespace MicroOcpp {
3236

3337
class Context;

0 commit comments

Comments
 (0)