From 4aaef6e5e93915da85e05b17afaff5de88e10696 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Sun, 3 Nov 2024 19:49:45 +0100 Subject: [PATCH 1/2] fix initialization without fs --- .../Model/ConnectorBase/Connector.cpp | 54 ++++++++++--------- tests/ChargingSessions.cpp | 49 +++++++++++++++++ tests/Transactions.cpp | 1 + 3 files changed, 78 insertions(+), 26 deletions(-) diff --git a/src/MicroOcpp/Model/ConnectorBase/Connector.cpp b/src/MicroOcpp/Model/ConnectorBase/Connector.cpp index 244185bd..edb13154 100644 --- a/src/MicroOcpp/Model/ConnectorBase/Connector.cpp +++ b/src/MicroOcpp/Model/ConnectorBase/Connector.cpp @@ -81,37 +81,39 @@ Connector::Connector(Context& context, std::shared_ptr filesy unsigned int txNrPivot = std::numeric_limits::max(); - filesystem->ftw_root([this, txFnamePrefix, txFnamePrefixLen, &txNrPivot] (const char *fname) { - if (!strncmp(fname, txFnamePrefix, txFnamePrefixLen)) { - unsigned int parsedTxNr = 0; - for (size_t i = txFnamePrefixLen; fname[i] >= '0' && fname[i] <= '9'; i++) { - parsedTxNr *= 10; - parsedTxNr += fname[i] - '0'; - } - - if (txNrPivot == std::numeric_limits::max()) { - txNrPivot = parsedTxNr; - txNrBegin = parsedTxNr; - txNrEnd = (parsedTxNr + 1) % MAX_TX_CNT; - return 0; - } + if (filesystem) { + filesystem->ftw_root([this, txFnamePrefix, txFnamePrefixLen, &txNrPivot] (const char *fname) { + if (!strncmp(fname, txFnamePrefix, txFnamePrefixLen)) { + unsigned int parsedTxNr = 0; + for (size_t i = txFnamePrefixLen; fname[i] >= '0' && fname[i] <= '9'; i++) { + parsedTxNr *= 10; + parsedTxNr += fname[i] - '0'; + } - if ((parsedTxNr + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT < MAX_TX_CNT / 2) { - //parsedTxNr is after pivot point - if ((parsedTxNr + 1 + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT > (txNrEnd + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT) { + if (txNrPivot == std::numeric_limits::max()) { + txNrPivot = parsedTxNr; + txNrBegin = parsedTxNr; txNrEnd = (parsedTxNr + 1) % MAX_TX_CNT; + return 0; } - } else if ((txNrPivot + MAX_TX_CNT - parsedTxNr) % MAX_TX_CNT < MAX_TX_CNT / 2) { - //parsedTxNr is before pivot point - if ((txNrPivot + MAX_TX_CNT - parsedTxNr) % MAX_TX_CNT > (txNrPivot + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT) { - txNrBegin = parsedTxNr; + + if ((parsedTxNr + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT < MAX_TX_CNT / 2) { + //parsedTxNr is after pivot point + if ((parsedTxNr + 1 + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT > (txNrEnd + MAX_TX_CNT - txNrPivot) % MAX_TX_CNT) { + txNrEnd = (parsedTxNr + 1) % MAX_TX_CNT; + } + } else if ((txNrPivot + MAX_TX_CNT - parsedTxNr) % MAX_TX_CNT < MAX_TX_CNT / 2) { + //parsedTxNr is before pivot point + if ((txNrPivot + MAX_TX_CNT - parsedTxNr) % MAX_TX_CNT > (txNrPivot + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT) { + txNrBegin = parsedTxNr; + } } - } - MO_DBG_DEBUG("found %s%u.jsn - Internal range from %u to %u (exclusive)", txFnamePrefix, parsedTxNr, txNrBegin, txNrEnd); - } - return 0; - }); + MO_DBG_DEBUG("found %s%u.jsn - Internal range from %u to %u (exclusive)", txFnamePrefix, parsedTxNr, txNrBegin, txNrEnd); + } + return 0; + }); + } MO_DBG_DEBUG("found %u transactions for connector %u. Internal range from %u to %u (exclusive)", (txNrEnd + MAX_TX_CNT - txNrBegin) % MAX_TX_CNT, connectorId, txNrBegin, txNrEnd); txNrFront = txNrBegin; diff --git a/tests/ChargingSessions.cpp b/tests/ChargingSessions.cpp index bcc2cb69..ab3d8e6e 100644 --- a/tests/ChargingSessions.cpp +++ b/tests/ChargingSessions.cpp @@ -1228,5 +1228,54 @@ TEST_CASE( "Charging sessions" ) { REQUIRE( checkProcessed ); } + SECTION("No filesystem access behavior") { + + //re-init without filesystem access + mocpp_deinitialize(); + + mocpp_initialize(loopback, ChargerCredentials(), MicroOcpp::makeDefaultFilesystemAdapter(MicroOcpp::FilesystemOpt::Deactivate)); + mocpp_set_timer(custom_timer_cb); + + loop(); + + REQUIRE( getChargePointStatus() == ChargePointStatus_Available ); + REQUIRE( !ocppPermitsCharge() ); + + for (size_t i = 0; i < 3; i++) { + + beginTransaction("mIdTag"); + loop(); + + REQUIRE( getChargePointStatus() == ChargePointStatus_Charging ); + REQUIRE( ocppPermitsCharge() ); + + endTransaction(); + loop(); + + REQUIRE( getChargePointStatus() == ChargePointStatus_Available ); + REQUIRE( !ocppPermitsCharge() ); + } + + //Tx status will be lost over reboot + + beginTransaction("mIdTag"); + loop(); + + REQUIRE( getChargePointStatus() == ChargePointStatus_Charging ); + REQUIRE( ocppPermitsCharge() ); + + mocpp_deinitialize(); + + mocpp_initialize(loopback, ChargerCredentials(), MicroOcpp::makeDefaultFilesystemAdapter(MicroOcpp::FilesystemOpt::Deactivate)); + mocpp_set_timer(custom_timer_cb); + + loop(); + + REQUIRE( getChargePointStatus() == ChargePointStatus_Available ); + REQUIRE( !ocppPermitsCharge() ); + + //Note: queueing offline transactions without FS is currently not implemented + } + mocpp_deinitialize(); } diff --git a/tests/Transactions.cpp b/tests/Transactions.cpp index 4e056543..56d50c97 100644 --- a/tests/Transactions.cpp +++ b/tests/Transactions.cpp @@ -387,6 +387,7 @@ TEST_CASE( "Transactions" ) { for (auto seqNo : tx->seqNos) { MO_DBG_DEBUG("stored seqNo %u", seqNo); + (void)seqNo; } for (size_t i = 1; i < tx->seqNos.size(); i++) { From c8c700e1a665910d8fa61d5f4c3c3c8bbc3a711b Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Sun, 3 Nov 2024 19:54:18 +0100 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc31c734..60d80ac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ - Build flag `MO_REPORT_NOERROR` to report error recovery ([#331](https://github.com/matth-x/MicroOcpp/pull/331)) - Support for `parentIdTag` ([#344](https://github.com/matth-x/MicroOcpp/pull/344)) - Input validation for unsigned int Configs ([#344](https://github.com/matth-x/MicroOcpp/pull/344)) -- Support for TransactionMessageAttempts/-RetryInterval ([#345](https://github.com/matth-x/MicroOcpp/pull/345)) +- Support for TransactionMessageAttempts/-RetryInterval ([#345](https://github.com/matth-x/MicroOcpp/pull/345), [#380](https://github.com/matth-x/MicroOcpp/pull/380)) - 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)) - Benchmarks pipeline ([#369](https://github.com/matth-x/MicroOcpp/pull/369), [#376](https://github.com/matth-x/MicroOcpp/pull/376))