Skip to content

Commit 2020ba7

Browse files
authored
fix offline txs, add SCons, more tests (#287)
* add contributions * clean patches (#287)
1 parent dc82574 commit 2020ba7

File tree

9 files changed

+340
-9
lines changed

9 files changed

+340
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Config `Cst_TxStartOnPowerPathClosed` to put back TxStartPoint
1515
- Function `bool isConnected()` in `Connection` interface ([#282](https://github.com/matth-x/MicroOcpp/pull/282))
1616
- Build flags for customizing memory limits of SmartCharging
17+
- SConscript ([#287](https://github.com/matth-x/MicroOcpp/pull/287))
1718
- Operation GetInstalledCertificateIds, UC M03 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
1819
- Operation DeleteCertificate, UC M04 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
1920
- Operation InstallCertificate, UC M05 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
@@ -33,7 +34,7 @@
3334
- Ignore UnlockConnector when handler not set
3435
- Reject ChargingProfile if unit not supported
3536
- Fix building with debug level warn and error
36-
- Fix transaction freeze in offline mode ([#279](https://github.com/matth-x/MicroOcpp/pull/279))
37+
- Fix transaction freeze in offline mode ([#279](https://github.com/matth-x/MicroOcpp/pull/279), [#287](https://github.com/matth-x/MicroOcpp/pull/287))
3738
- Fix compilation error caused by `PRId32` ([#279](https://github.com/matth-x/MicroOcpp/pull/279))
3839
- Don't load FW-mngt. module when no handlers set
3940

SConscript.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# matth-x/MicroOcpp
2+
# Copyright Matthias Akstaller 2019 - 2024
3+
# MIT License
4+
5+
# NOTE: This SConscript is still WIP. It has thankfully been contributed from a project using SCons,
6+
# not necessarily considering full reusability in other projects though.
7+
# Use this file as a starting point for writing your own SCons integration. And as always, any
8+
# contributions are highly welcome!
9+
10+
Import("env", "ARDUINOJSON_DIR")
11+
12+
import os, pathlib
13+
14+
def getAllDirs(root_dir):
15+
dir_list = []
16+
for root, subfolders, files in os.walk(root_dir.abspath):
17+
dir_list.append(Dir(root))
18+
return dir_list
19+
20+
SOURCE_DIR = Dir(".").srcnode()
21+
22+
source_dirs = getAllDirs(SOURCE_DIR.Dir("src"))
23+
source_dirs += getAllDirs(ARDUINOJSON_DIR.Dir("src"))
24+
25+
source_files = []
26+
27+
for folder in source_dirs:
28+
source_files += folder.glob("*.cpp")
29+
env["CPPPATH"].append(folder)
30+
31+
compiled_objects = []
32+
for source_file in source_files:
33+
obj = env.Object(
34+
target = pathlib.Path(source_file.path).stem
35+
+ ".o",
36+
source=source_file,
37+
)
38+
compiled_objects.append(obj)
39+
40+
libmicroocpp = env.StaticLibrary(
41+
target='libmicroocpp',
42+
source=sorted(compiled_objects)
43+
)
44+
45+
exports = {
46+
'library': libmicroocpp,
47+
'CPPPATH': source_dirs.copy()
48+
}
49+
50+
Return("exports")

src/MicroOcpp/Core/RequestQueueStorageStrategy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// matth-x/MicroOcpp
2-
// Copyright Matthias Akstaller 2019 - 2023
2+
// Copyright Matthias Akstaller 2019 - 2024
33
// MIT License
44

55
#include <MicroOcpp/Core/RequestQueueStorageStrategy.h>
@@ -104,12 +104,12 @@ Request *PersistentRequestQueue::front() {
104104
tailCache.pop_front();
105105
} else {
106106
//cache miss -> case B) or A) -> try to fetch operation from flash (check for case B)) or take first cached element as front
107-
auto storageHandler = opStore.makeOpHandler();
108107

109108
std::unique_ptr<Request> fetched;
110109

111110
unsigned int range = (opStore.getOpEnd() + MO_MAX_OPNR - nextOpNr) % MO_MAX_OPNR;
112111
for (size_t i = 0; i < range; i++) {
112+
auto storageHandler = opStore.makeOpHandler();
113113
bool exists = storageHandler->restore(nextOpNr);
114114
if (exists) {
115115
//case B) -> load operation from flash and take it as front element

src/MicroOcpp/Model/Diagnostics/DiagnosticsService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void DiagnosticsService::loop() {
4848
if (uploadIssued) {
4949
if (uploadStatusInput != nullptr && uploadStatusInput() == UploadStatus::Uploaded) {
5050
//success!
51-
MO_DBG_DEBUG("end upload routine (by status)")
51+
MO_DBG_DEBUG("end upload routine (by status)");
5252
uploadIssued = false;
5353
retries = 0;
5454
}

src/MicroOcpp/Model/Transactions/Transaction.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// matth-x/MicroOcpp
2-
// Copyright Matthias Akstaller 2019 - 2023
2+
// Copyright Matthias Akstaller 2019 - 2024
33
// MIT License
44

55
#include <MicroOcpp/Model/Transactions/Transaction.h>
@@ -73,6 +73,10 @@ int32_t ocpp_tx_getMeterStop(OCPP_Transaction *tx) {
7373
return reinterpret_cast<MicroOcpp::Transaction*>(tx)->getMeterStop();
7474
}
7575

76+
void ocpp_tx_setMeterStop(OCPP_Transaction* tx, int32_t meter) {
77+
return reinterpret_cast<MicroOcpp::Transaction*>(tx)->setMeterStop(meter);
78+
}
79+
7680
bool ocpp_tx_getStopTimestamp(OCPP_Transaction *tx, char *buf, size_t len) {
7781
return reinterpret_cast<MicroOcpp::Transaction*>(tx)->getStopTimestamp().toJsonString(buf, len);
7882
}

src/MicroOcpp/Model/Transactions/Transaction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ bool ocpp_tx_getStartTimestamp(OCPP_Transaction *tx, char *buf, size_t len);
347347
const char *ocpp_tx_getStopIdTag(OCPP_Transaction *tx);
348348

349349
int32_t ocpp_tx_getMeterStop(OCPP_Transaction *tx);
350+
void ocpp_tx_setMeterStop(OCPP_Transaction* tx, int32_t meter);
350351

351352
bool ocpp_tx_getStopTimestamp(OCPP_Transaction *tx, char *buf, size_t len);
352353

src/MicroOcpp/Model/Transactions/TransactionDeserialize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// matth-x/MicroOcpp
2-
// Copyright Matthias Akstaller 2019 - 2023
2+
// Copyright Matthias Akstaller 2019 - 2024
33
// MIT License
44

55
#include <limits>
@@ -234,7 +234,7 @@ bool deserializeTransaction(Transaction& tx, JsonObject state) {
234234
tx.setSilent();
235235
}
236236

237-
MO_DBG_DEBUG("DUMP TX");
237+
MO_DBG_DEBUG("DUMP TX (%s)", tx.getIdTag() ? tx.getIdTag() : "idTag missing");
238238
MO_DBG_DEBUG("Session | idTag %s, active: %i, authorized: %i, deauthorized: %i", tx.getIdTag(), tx.isActive(), tx.isAuthorized(), tx.isIdTagDeauthorized());
239239
MO_DBG_DEBUG("Start RPC | req: %i, conf: %i", tx.getStartSync().isRequested(), tx.getStartSync().isConfirmed());
240240
MO_DBG_DEBUG("Stop RPC | req: %i, conf: %i", tx.getStopSync().isRequested(), tx.getStopSync().isConfirmed());

src/MicroOcpp/Operations/GetConfiguration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// matth-x/MicroOcpp
2-
// Copyright Matthias Akstaller 2019 - 2023
2+
// Copyright Matthias Akstaller 2019 - 2024
33
// MIT License
44

55
#include <MicroOcpp/Operations/GetConfiguration.h>
@@ -135,7 +135,7 @@ std::unique_ptr<DynamicJsonDocument> GetConfiguration::createConf(){
135135
if (!unknownKeys.empty()) {
136136
JsonArray jsonUnknownKey = payload.createNestedArray("unknownKey");
137137
for (auto key : unknownKeys) {
138-
MO_DBG_DEBUG("Unknown key: %s", key)
138+
MO_DBG_DEBUG("Unknown key: %s", key);
139139
jsonUnknownKey.add(key);
140140
}
141141
}

0 commit comments

Comments
 (0)