Skip to content

Commit dc82574

Browse files
authored
v2.0.1 Reset (UCs B11 - B12) (#286)
* implement UCs B11, B12 * add Reset test cases and fixes
1 parent 80da31d commit dc82574

File tree

13 files changed

+788
-16
lines changed

13 files changed

+788
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Transactions (preview only), UCs E01 - E12 ([#247](https://github.com/matth-x/MicroOcpp/pull/247))
2424
- StatusNotification compatibility ([#247](https://github.com/matth-x/MicroOcpp/pull/247))
2525
- ChangeAvailability compatibility ([#285](https://github.com/matth-x/MicroOcpp/pull/285))
26+
- Reset compatibility, UCs B11 - B12 ([#286](https://github.com/matth-x/MicroOcpp/pull/286))
2627

2728
### Fixed
2829

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ set(MO_SRC_UNIT
140140
tests/Metering.cpp
141141
tests/Configuration.cpp
142142
tests/Reservation.cpp
143+
tests/Reset.cpp
143144
tests/LocalAuthList.cpp
144145
tests/Variables.cpp
145146
tests/Transactions.cpp

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ The following OCPP 2.0.1 use cases are implemented:
8080
| UC | Description | Note |
8181
| :--- | :--- | :--- |
8282
| M03 - M05 | Certificate management | Enable Mbed-TLS to use the built-in certificate store |
83-
| B05 - B06 | Variables | No persistency yet |
83+
| B05 - B07 | Variables | No persistency yet |
84+
| B01 - B04<br>B11 - B12 | Provisioning | Ported from OCPP 1.6 |
8485
| E01 - E12 | Transactions | |
8586
| - | Protocol negotiation | The charger can select the OCPP version at runtime |
8687

src/MicroOcpp.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
289289
new AuthorizationService(*context, filesystem)));
290290
model.setReservationService(std::unique_ptr<ReservationService>(
291291
new ReservationService(*context, MO_NUMCONNECTORS)));
292-
model.setResetService(std::unique_ptr<ResetService>(
293-
new ResetService(*context)));
294292

295293
#if MO_ENABLE_V201
296294
model.setVariableService(std::unique_ptr<VariableService>(
@@ -299,6 +297,18 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
299297
new TransactionService(*context)));
300298
#endif
301299

300+
#if MO_ENABLE_V201
301+
if (version.major == 2) {
302+
//depends on VariableService
303+
model.setResetServiceV201(std::unique_ptr<Ocpp201::ResetService>(
304+
new Ocpp201::ResetService(*context)));
305+
} else
306+
#endif
307+
{
308+
model.setResetService(std::unique_ptr<ResetService>(
309+
new ResetService(*context)));
310+
}
311+
302312
std::unique_ptr<CertificateStore> certStoreUse;
303313
if (certStore) {
304314
certStoreUse = std::move(certStore);
@@ -322,8 +332,7 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
322332
#endif //MO_PLATFORM == MO_PLATFORM_ARDUINO && !defined(MO_CUSTOM_UPDATER)
323333

324334
#if MO_PLATFORM == MO_PLATFORM_ARDUINO && (defined(ESP32) || defined(ESP8266))
325-
if (!model.getResetService()->getExecuteReset())
326-
model.getResetService()->setExecuteReset(makeDefaultResetFn());
335+
setOnResetExecute(makeDefaultResetFn());
327336
#endif
328337

329338
model.getBootService()->setChargePointCredentials(bootNotificationCredentials);
@@ -883,6 +892,15 @@ void setOnResetNotify(std::function<bool(bool)> onResetNotify) {
883892
return;
884893
}
885894

895+
#if MO_ENABLE_V201
896+
if (context->getVersion().major == 2) {
897+
if (auto rService = context->getModel().getResetServiceV201()) {
898+
rService->setNotifyReset([onResetNotify] (ResetType) {return onResetNotify(true);});
899+
}
900+
return;
901+
}
902+
#endif
903+
886904
if (auto rService = context->getModel().getResetService()) {
887905
rService->setPreReset(onResetNotify);
888906
}
@@ -894,6 +912,15 @@ void setOnResetExecute(std::function<void(bool)> onResetExecute) {
894912
return;
895913
}
896914

915+
#if MO_ENABLE_V201
916+
if (context->getVersion().major == 2) {
917+
if (auto rService = context->getModel().getResetServiceV201()) {
918+
rService->setExecuteReset([onResetExecute] () {onResetExecute(true); return true;});
919+
}
920+
return;
921+
}
922+
#endif
923+
897924
if (auto rService = context->getModel().getResetService()) {
898925
rService->setExecuteReset(onResetExecute);
899926
}

src/MicroOcpp/Model/Model.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ void Model::loop() {
7979
#if MO_ENABLE_V201
8080
if (transactionService)
8181
transactionService->loop();
82+
83+
if (resetServiceV201)
84+
resetServiceV201->loop();
8285
#endif
8386
}
8487

@@ -222,6 +225,15 @@ void Model::setTransactionService(std::unique_ptr<TransactionService> ts) {
222225
TransactionService *Model::getTransactionService() const {
223226
return transactionService.get();
224227
}
228+
229+
void Model::setResetServiceV201(std::unique_ptr<Ocpp201::ResetService> rs) {
230+
this->resetServiceV201 = std::move(rs);
231+
capabilitiesUpdated = true;
232+
}
233+
234+
Ocpp201::ResetService *Model::getResetServiceV201() const {
235+
return resetServiceV201.get();
236+
}
225237
#endif
226238

227239
Clock& Model::getClock() {

src/MicroOcpp/Model/Model.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class CertificateService;
2929
#if MO_ENABLE_V201
3030
class VariableService;
3131
class TransactionService;
32+
33+
namespace Ocpp201 {
34+
class ResetService;
35+
}
3236
#endif
3337

3438
class Model {
@@ -50,6 +54,7 @@ class Model {
5054
#if MO_ENABLE_V201
5155
std::unique_ptr<VariableService> variableService;
5256
std::unique_ptr<TransactionService> transactionService;
57+
std::unique_ptr<Ocpp201::ResetService> resetServiceV201;
5358
#endif
5459

5560
Clock clock;
@@ -117,6 +122,9 @@ class Model {
117122

118123
void setTransactionService(std::unique_ptr<TransactionService> ts);
119124
TransactionService *getTransactionService() const;
125+
126+
void setResetServiceV201(std::unique_ptr<Ocpp201::ResetService> rs);
127+
Ocpp201::ResetService *getResetServiceV201() const;
120128
#endif
121129

122130
Clock &getClock();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// matth-x/MicroOcpp
2+
// Copyright Matthias Akstaller 2019 - 2024
3+
// MIT License
4+
5+
#ifndef MO_RESETDEFS_H
6+
#define MO_RESETDEFS_H
7+
8+
#include <MicroOcpp/Version.h>
9+
10+
#if MO_ENABLE_V201
11+
12+
typedef enum ResetType {
13+
ResetType_Immediate,
14+
ResetType_OnIdle
15+
} ResetType;
16+
17+
typedef enum ResetStatus {
18+
ResetStatus_Accepted,
19+
ResetStatus_Rejected,
20+
ResetStatus_Scheduled
21+
} ResetStatus;
22+
23+
#endif //MO_ENABLE_V201
24+
#endif

0 commit comments

Comments
 (0)