Skip to content

Commit cad22da

Browse files
authored
add build flag MO_ENABLE_V16_RESERVATION (#302)
* add build flag MO_ENABLE_V16_RESERVATION * update changelog * fix compilation error
1 parent b5d059f commit cad22da

File tree

15 files changed

+127
-50
lines changed

15 files changed

+127
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
- File index ([#270](https://github.com/matth-x/MicroOcpp/pull/270))
1616
- Config `Cst_TxStartOnPowerPathClosed` to put back TxStartPoint ([#271](https://github.com/matth-x/MicroOcpp/pull/271))
17+
- Build flag `MO_ENABLE_V16_RESERVATION=0` disables Reservation module ([#302](https://github.com/matth-x/MicroOcpp/pull/302))
1718
- Function `bool isConnected()` in `Connection` interface ([#282](https://github.com/matth-x/MicroOcpp/pull/282))
1819
- Build flags for customizing memory limits of SmartCharging ([#260](https://github.com/matth-x/MicroOcpp/pull/260))
1920
- SConscript ([#287](https://github.com/matth-x/MicroOcpp/pull/287))

src/MicroOcpp.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,11 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
289289
new HeartbeatService(*context)));
290290
model.setAuthorizationService(std::unique_ptr<AuthorizationService>(
291291
new AuthorizationService(*context, filesystem)));
292+
293+
#if MO_ENABLE_V16_RESERVATION
292294
model.setReservationService(std::unique_ptr<ReservationService>(
293295
new ReservationService(*context, MO_NUMCONNECTORS)));
296+
#endif
294297

295298
#if MO_ENABLE_V201
296299
model.setVariableService(std::unique_ptr<VariableService>(

src/MicroOcpp/Model/ConnectorBase/Connector.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ ChargePointStatus Connector::getStatus() {
112112
} else {
113113
res = ChargePointStatus::Charging;
114114
}
115-
} else if (model.getReservationService() && model.getReservationService()->getReservation(connectorId)) {
115+
}
116+
#if MO_ENABLE_V16_RESERVATION
117+
else if (model.getReservationService() && model.getReservationService()->getReservation(connectorId)) {
116118
res = ChargePointStatus::Reserved;
117-
} else if ((!transaction || !transaction->isActive()) && //no transaction preparation
119+
}
120+
#endif
121+
else if ((!transaction || !transaction->isActive()) && //no transaction preparation
118122
(!connectorPluggedInput || !connectorPluggedInput()) && //no vehicle plugged
119123
(!occupiedInput || !occupiedInput())) { //occupied override clear
120124
res = ChargePointStatus::Available;
@@ -609,17 +613,22 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
609613
}
610614
}
611615

612-
Reservation *reservation = nullptr;
616+
int reservationId = -1;
613617
bool offlineBlockedResv = false; //if offline authorization will be blocked by reservation
614618

619+
#if MO_ENABLE_V16_RESERVATION
615620
//check if blocked by reservation
616621
if (model.getReservationService()) {
617622
const char *parentIdTag = localAuth ? localAuth->getParentIdTag() : nullptr;
618623

619-
reservation = model.getReservationService()->getReservation(
624+
auto reservation = model.getReservationService()->getReservation(
620625
connectorId,
621626
idTag,
622627
parentIdTag);
628+
629+
if (reservation) {
630+
reservationId = reservation->getReservationId();
631+
}
623632

624633
if (reservation && !reservation->matches(
625634
idTag,
@@ -640,6 +649,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
640649
}
641650
}
642651
}
652+
#endif //MO_ENABLE_V16_RESERVATION
643653

644654
transaction = allocateTransaction();
645655

@@ -661,8 +671,8 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
661671
if (localAuth && localPreAuthorizeBool && localPreAuthorizeBool->getBool()) {
662672
MO_DBG_DEBUG("Begin transaction process (%s), preauthorized locally", idTag != nullptr ? idTag : "");
663673

664-
if (reservation) {
665-
transaction->setReservationId(reservation->getReservationId());
674+
if (reservationId >= 0) {
675+
transaction->setReservationId(reservationId);
666676
}
667677
transaction->setAuthorized();
668678

@@ -692,6 +702,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
692702
return;
693703
}
694704

705+
#if MO_ENABLE_V16_RESERVATION
695706
if (model.getReservationService()) {
696707
auto reservation = model.getReservationService()->getReservation(
697708
connectorId,
@@ -714,6 +725,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
714725
}
715726
}
716727
}
728+
#endif //MO_ENABLE_V16_RESERVATION
717729

718730
MO_DBG_DEBUG("Authorized transaction process (%s)", tx->getIdTag());
719731
tx->setAuthorized();
@@ -724,13 +736,10 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
724736

725737
//capture local auth and reservation check in for timeout handler
726738
bool localAuthFound = localAuth;
727-
bool reservationFound = reservation;
728-
int reservationId = reservation ? reservation->getReservationId() : -1;
729739
authorize->setOnTimeoutListener([this, tx,
730740
offlineBlockedAuth,
731741
offlineBlockedResv,
732742
localAuthFound,
733-
reservationFound,
734743
reservationId] () {
735744

736745
if (offlineBlockedAuth) {
@@ -753,7 +762,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
753762

754763
if (localAuthFound && localAuthorizeOfflineBool && localAuthorizeOfflineBool->getBool()) {
755764
MO_DBG_DEBUG("Offline transaction process (%s), locally authorized", tx->getIdTag());
756-
if (reservationFound) {
765+
if (reservationId >= 0) {
757766
tx->setReservationId(reservationId);
758767
}
759768
tx->setAuthorized();
@@ -765,7 +774,7 @@ std::shared_ptr<Transaction> Connector::beginTransaction(const char *idTag) {
765774

766775
if (allowOfflineTxForUnknownIdBool && allowOfflineTxForUnknownIdBool->getBool()) {
767776
MO_DBG_DEBUG("Offline transaction process (%s), allow unknown ID", tx->getIdTag());
768-
if (reservationFound) {
777+
if (reservationId >= 0) {
769778
tx->setReservationId(reservationId);
770779
}
771780
tx->setAuthorized();
@@ -811,14 +820,16 @@ std::shared_ptr<Transaction> Connector::beginTransaction_authorized(const char *
811820
MO_DBG_DEBUG("Begin transaction process (%s), already authorized", idTag != nullptr ? idTag : "");
812821

813822
transaction->setAuthorized();
814-
823+
824+
#if MO_ENABLE_V16_RESERVATION
815825
if (model.getReservationService()) {
816826
if (auto reservation = model.getReservationService()->getReservation(connectorId, idTag, parentIdTag)) {
817827
if (reservation->matches(idTag, parentIdTag)) {
818828
transaction->setReservationId(reservation->getReservationId());
819829
}
820830
}
821831
}
832+
#endif //MO_ENABLE_V16_RESERVATION
822833

823834
transaction->commit();
824835

src/MicroOcpp/Model/Model.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,27 @@ void Model::loop() {
5454

5555
if (chargeControlCommon)
5656
chargeControlCommon->loop();
57-
57+
5858
if (smartChargingService)
5959
smartChargingService->loop();
60-
60+
6161
if (heartbeatService)
6262
heartbeatService->loop();
63-
63+
6464
if (meteringService)
6565
meteringService->loop();
66-
66+
6767
if (diagnosticsService)
6868
diagnosticsService->loop();
69-
69+
7070
if (firmwareService)
7171
firmwareService->loop();
72-
72+
73+
#if MO_ENABLE_V16_RESERVATION
7374
if (reservationService)
7475
reservationService->loop();
75-
76+
#endif //MO_ENABLE_V16_RESERVATION
77+
7678
if (resetService)
7779
resetService->loop();
7880

@@ -171,6 +173,7 @@ AuthorizationService *Model::getAuthorizationService() {
171173
return authorizationService.get();
172174
}
173175

176+
#if MO_ENABLE_V16_RESERVATION
174177
void Model::setReservationService(std::unique_ptr<ReservationService> rs) {
175178
reservationService = std::move(rs);
176179
capabilitiesUpdated = true;
@@ -179,6 +182,7 @@ void Model::setReservationService(std::unique_ptr<ReservationService> rs) {
179182
ReservationService *Model::getReservationService() {
180183
return reservationService.get();
181184
}
185+
#endif //MO_ENABLE_V16_RESERVATION
182186

183187
void Model::setBootService(std::unique_ptr<BootService> bs){
184188
bootService = std::move(bs);
@@ -286,12 +290,14 @@ void Model::updateSupportedStandardProfiles() {
286290
}
287291
}
288292

293+
#if MO_ENABLE_V16_RESERVATION
289294
if (reservationService) {
290295
if (!strstr(supportedFeatureProfilesString->getString(), "Reservation")) {
291296
if (!buf.empty()) buf += ',';
292297
buf += "Reservation";
293298
}
294299
}
300+
#endif //MO_ENABLE_V16_RESERVATION
295301

296302
if (smartChargingService) {
297303
if (!strstr(supportedFeatureProfilesString->getString(), "SmartCharging")) {

src/MicroOcpp/Model/Model.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ class FirmwareService;
2121
class DiagnosticsService;
2222
class HeartbeatService;
2323
class AuthorizationService;
24-
class ReservationService;
2524
class BootService;
2625
class ResetService;
2726

27+
#if MO_ENABLE_V16_RESERVATION
28+
class ReservationService;
29+
#endif //MO_ENABLE_V16_RESERVATION
30+
2831
#if MO_ENABLE_CERT_MGMT
2932
class CertificateService;
3033
#endif //MO_ENABLE_CERT_MGMT
@@ -49,10 +52,13 @@ class Model {
4952
std::unique_ptr<DiagnosticsService> diagnosticsService;
5053
std::unique_ptr<HeartbeatService> heartbeatService;
5154
std::unique_ptr<AuthorizationService> authorizationService;
52-
std::unique_ptr<ReservationService> reservationService;
5355
std::unique_ptr<BootService> bootService;
5456
std::unique_ptr<ResetService> resetService;
5557

58+
#if MO_ENABLE_V16_RESERVATION
59+
std::unique_ptr<ReservationService> reservationService;
60+
#endif //MO_ENABLE_V16_RESERVATION
61+
5662
#if MO_ENABLE_CERT_MGMT
5763
std::unique_ptr<CertificateService> certService;
5864
#endif //MO_ENABLE_CERT_MGMT
@@ -110,8 +116,10 @@ class Model {
110116
void setAuthorizationService(std::unique_ptr<AuthorizationService> authorizationService);
111117
AuthorizationService *getAuthorizationService();
112118

119+
#if MO_ENABLE_V16_RESERVATION
113120
void setReservationService(std::unique_ptr<ReservationService> reservationService);
114121
ReservationService *getReservationService();
122+
#endif //MO_ENABLE_V16_RESERVATION
115123

116124
void setBootService(std::unique_ptr<BootService> bs);
117125
BootService *getBootService() const;

src/MicroOcpp/Model/Reservation/Reservation.cpp

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

5+
#include <MicroOcpp/Version.h>
6+
7+
#if MO_ENABLE_V16_RESERVATION
8+
59
#include <MicroOcpp/Model/Reservation/Reservation.h>
610
#include <MicroOcpp/Model/Model.h>
711
#include <MicroOcpp/Debug.h>
@@ -130,3 +134,5 @@ void Reservation::clear() {
130134

131135
configuration_save();
132136
}
137+
138+
#endif //MO_ENABLE_V16_RESERVATION

src/MicroOcpp/Model/Reservation/Reservation.h

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

5-
#ifndef RESERVATION_H
6-
#define RESERVATION_H
5+
#ifndef MO_RESERVATION_H
6+
#define MO_RESERVATION_H
7+
8+
#include <MicroOcpp/Version.h>
9+
10+
#if MO_ENABLE_V16_RESERVATION
711

812
#include <MicroOcpp/Core/Configuration.h>
913
#include <MicroOcpp/Core/Time.h>
@@ -65,4 +69,5 @@ class Reservation {
6569

6670
}
6771

72+
#endif //MO_ENABLE_V16_RESERVATION
6873
#endif

src/MicroOcpp/Model/Reservation/ReservationService.cpp

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

5+
#include <MicroOcpp/Version.h>
6+
7+
#if MO_ENABLE_V16_RESERVATION
8+
59
#include <MicroOcpp/Model/Reservation/ReservationService.h>
610
#include <MicroOcpp/Core/Context.h>
711
#include <MicroOcpp/Model/Model.h>
@@ -24,8 +28,8 @@ ReservationService::ReservationService(Context& context, unsigned int numConnect
2428

2529
reserveConnectorZeroSupportedBool = declareConfiguration<bool>("ReserveConnectorZeroSupported", true, CONFIGURATION_VOLATILE, true);
2630

27-
context.getOperationRegistry().registerOperation("CancelReservation", [&context] () {
28-
return new Ocpp16::CancelReservation(context.getModel());});
31+
context.getOperationRegistry().registerOperation("CancelReservation", [this] () {
32+
return new Ocpp16::CancelReservation(*this);});
2933
context.getOperationRegistry().registerOperation("ReserveNow", [&context] () {
3034
return new Ocpp16::ReserveNow(context.getModel());});
3135
}
@@ -210,3 +214,5 @@ bool ReservationService::updateReservation(int reservationId, unsigned int conne
210214
MO_DBG_ERR("error finding blocking reservation");
211215
return false;
212216
}
217+
218+
#endif //MO_ENABLE_V16_RESERVATION

src/MicroOcpp/Model/Reservation/ReservationService.h

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

5-
#ifndef RESERVATIONSERVICE_H
6-
#define RESERVATIONSERVICE_H
5+
#ifndef MO_RESERVATIONSERVICE_H
6+
#define MO_RESERVATIONSERVICE_H
7+
8+
#include <MicroOcpp/Version.h>
9+
10+
#if MO_ENABLE_V16_RESERVATION
711

812
#include <MicroOcpp/Model/Reservation/Reservation.h>
913

@@ -44,4 +48,5 @@ class ReservationService {
4448

4549
}
4650

51+
#endif //MO_ENABLE_V16_RESERVATION
4752
#endif

src/MicroOcpp/Operations/CancelReservation.cpp

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

5+
#include <MicroOcpp/Version.h>
6+
7+
#if MO_ENABLE_V16_RESERVATION
8+
59
#include <MicroOcpp/Operations/CancelReservation.h>
6-
#include <MicroOcpp/Model/Model.h>
710
#include <MicroOcpp/Model/Reservation/ReservationService.h>
811
#include <MicroOcpp/Debug.h>
912

1013
using MicroOcpp::Ocpp16::CancelReservation;
1114

12-
CancelReservation::CancelReservation(Model& model) : model(model) {
15+
CancelReservation::CancelReservation(ReservationService& reservationService) : reservationService(reservationService) {
1316

1417
}
1518

@@ -23,13 +26,9 @@ void CancelReservation::processReq(JsonObject payload) {
2326
return;
2427
}
2528

26-
if (model.getReservationService()) {
27-
if (auto reservation = model.getReservationService()->getReservationById(payload["reservationId"])) {
28-
found = true;
29-
reservation->clear();
30-
}
31-
} else {
32-
errorCode = "InternalError";
29+
if (auto reservation = reservationService.getReservationById(payload["reservationId"])) {
30+
found = true;
31+
reservation->clear();
3332
}
3433
}
3534

@@ -43,3 +42,5 @@ std::unique_ptr<DynamicJsonDocument> CancelReservation::createConf(){
4342
}
4443
return doc;
4544
}
45+
46+
#endif //MO_ENABLE_V16_RESERVATION

0 commit comments

Comments
 (0)