Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TxMessageAttempts optionally ignores offline attempts #398

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Support for TransactionMessageAttempts/-RetryInterval ([#345](https://github.com/matth-x/MicroOcpp/pull/345))
- Heap profiler and custom allocator support ([#350](https://github.com/matth-x/MicroOcpp/pull/350))
- Migration of persistent storage ([#355](https://github.com/matth-x/MicroOcpp/pull/355))
- Build flag `MO_TX_ATTEMPT_TIMEOUT` to ignore offline attempts ([#398](https://github.com/matth-x/MicroOcpp/pull/398))

### Removed

Expand Down
28 changes: 28 additions & 0 deletions src/MicroOcpp/Model/ConnectorBase/Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,7 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
return nullptr;
}

const auto attemptNr_capture = transactionFront->getStartSync().getAttemptNr();
transactionFront->getStartSync().advanceAttemptNr();
transactionFront->getStartSync().setAttemptTime(model.getClock().now());
transactionFront->commit();
Expand Down Expand Up @@ -1203,6 +1204,19 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
}
});

#if MO_TX_ATTEMPT_TIMEOUT == 0
//a timeout should not increase the attemptNr. Roll back to previous attemptNr
startTx->setOnTimeoutListener([transactionFront_capture, attemptNr_capture] () {
MO_DBG_DEBUG("StartTx timeout -> roll back attemptNr and try again");
if (transactionFront_capture) {
transactionFront_capture->getStartSync().setAttemptNr(attemptNr_capture);
transactionFront_capture->commit();
}
});
#else
(void)attemptNr_capture;
#endif

return startTx;
}

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

const auto attemptNr_capture = transactionFront->getStopSync().getAttemptNr();
transactionFront->getStopSync().advanceAttemptNr();
transactionFront->getStopSync().setAttemptTime(model.getClock().now());
transactionFront->commit();
Expand Down Expand Up @@ -1264,6 +1279,19 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
}
});

#if MO_TX_ATTEMPT_TIMEOUT == 0
//a timeout should not increase the attemptNr. Roll back to previous attemptNr
stopTx->setOnTimeoutListener([transactionFront_capture, attemptNr_capture] () {
MO_DBG_DEBUG("StopTx timeout -> roll back attemptNr and try again");
if (transactionFront_capture) {
transactionFront_capture->getStopSync().setAttemptNr(attemptNr_capture);
transactionFront_capture->commit();
}
});
#else
(void)attemptNr_capture;
#endif

return stopTx;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/MicroOcpp/Model/ConnectorBase/Connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#define MO_REPORT_NOERROR 0
#endif

#ifndef MO_TX_ATTEMPT_TIMEOUT
#define MO_TX_ATTEMPT_TIMEOUT 1 //if the timeout of a tx-related msg should increase its attempt counter
#endif

namespace MicroOcpp {

class Context;
Expand Down