Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
54 changes: 28 additions & 26 deletions src/MicroOcpp/Model/ConnectorBase/Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,39 @@ Connector::Connector(Context& context, std::shared_ptr<FilesystemAdapter> filesy

unsigned int txNrPivot = std::numeric_limits<unsigned int>::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<unsigned int>::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<unsigned int>::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;
Expand Down
49 changes: 49 additions & 0 deletions tests/ChargingSessions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions tests/Transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down