Skip to content

Commit 71e562b

Browse files
committed
TC_049_CS Fix connectorId 0 reservation StatusNotification
1 parent 5cfcc02 commit 71e562b

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

.github/workflows/documentation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
needs: build_simulator
6262
name: Heap measurements
6363
runs-on: ubuntu-latest
64+
if: false
6465
steps:
6566
- uses: actions/checkout@v3
6667
- uses: actions/setup-python@v4

src/MicroOcpp/Model/Reservation/ReservationService.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ Reservation *ReservationService::getReservationById(int reservationId) {
183183
}
184184

185185
bool ReservationService::updateReservation(int reservationId, unsigned int connectorId, Timestamp expiryDate, const char *idTag, const char *parentIdTag) {
186+
//TC_049_CS / 2.21.2 / Reservation of a Charge Point - Transaction
187+
if (connectorId == 0) {
188+
//find the first available connector for this reservation
189+
for (unsigned int cId = 1; cId < context.getModel().getNumConnectors(); cId++) {
190+
auto connector = context.getModel().getConnector(cId);
191+
if (connector && connector->getStatus() == ChargePointStatus_Available && !getReservation(cId)) {
192+
connectorId = cId;
193+
break;
194+
}
195+
}
196+
if (connectorId == 0) {
197+
MO_DBG_DEBUG("no available connector for connectorId 0 reservation");
198+
return false;
199+
}
200+
}
201+
186202
if (auto reservation = getReservationById(reservationId)) {
187203
if (getReservation(connectorId) && getReservation(connectorId) != reservation && getReservation(connectorId)->isActive()) {
188204
MO_DBG_DEBUG("found blocking reservation at connectorId %u", connectorId);

tests/Reservation.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,37 +207,60 @@ TEST_CASE( "Reservation" ) {
207207

208208
//if connector 0 is reserved, accept at most one further reservation
209209
REQUIRE( rService->updateReservation(1000, 0, expiryDate, idTag, parentIdTag) );
210-
REQUIRE( rService->updateReservation(1001, 1, expiryDate, idTag, parentIdTag) );
211-
REQUIRE( !rService->updateReservation(1002, 2, expiryDate, idTag, parentIdTag) );
212-
REQUIRE( model.getConnector(2)->getStatus() == ChargePointStatus_Available );
210+
//first available connector reserved by connector 0 reservation
211+
REQUIRE( !rService->updateReservation(1001, 1, expiryDate, idTag, parentIdTag) );
212+
REQUIRE( rService->updateReservation(1002, 2, expiryDate, idTag, parentIdTag) );
213+
214+
loop();
215+
REQUIRE( model.getConnector(1)->getStatus() == ChargePointStatus_Reserved );
216+
REQUIRE( model.getConnector(2)->getStatus() == ChargePointStatus_Reserved );
213217

214218
//reset reservations
215219
rService->getReservationById(1000)->clear();
216-
rService->getReservationById(1001)->clear();
220+
rService->getReservationById(1002)->clear();
217221
REQUIRE( model.getConnector(1)->getStatus() == ChargePointStatus_Available );
222+
REQUIRE( model.getConnector(2)->getStatus() == ChargePointStatus_Available );
218223

219224
//if connector 0 is reserved, ensure that at least one physical connector remains available for the idTag of the reservation
220225
REQUIRE( rService->updateReservation(1000, 0, expiryDate, idTag, parentIdTag) );
221226

222-
beginTransaction("other idTag", 1);
227+
beginTransaction("other idTag", 2);
228+
loop();
229+
REQUIRE( model.getConnector(2)->getStatus() == ChargePointStatus_Charging );
230+
231+
endTransaction(nullptr, nullptr, 2);
223232
loop();
224-
REQUIRE( model.getConnector(1)->getStatus() == ChargePointStatus_Charging );
233+
234+
REQUIRE( model.getConnector(2)->getStatus() == ChargePointStatus_Available );
225235

226236
bool checkTxRejected = false;
227237
setTxNotificationOutput([&checkTxRejected] (Transaction*, TxNotification txNotification) {
228238
if (txNotification == TxNotification_ReservationConflict) {
229239
checkTxRejected = true;
230240
}
231-
}, 2);
241+
}, 1);
232242

233-
beginTransaction("other idTag 2", 2);
243+
beginTransaction("other idTag 2", 1);
234244
loop();
235245
REQUIRE( checkTxRejected );
236-
REQUIRE( model.getConnector(2)->getStatus() == ChargePointStatus_Available );
246+
REQUIRE( model.getConnector(1)->getStatus() == ChargePointStatus_Reserved );
247+
248+
beginTransaction("mIdTag", 1);
249+
loop();
237250

251+
REQUIRE( model.getConnector(1)->getStatus() == ChargePointStatus_Charging );
238252

239253
endTransaction(nullptr, nullptr, 1);
240254
loop();
255+
256+
//check if we skip connector 1 when unavailable
257+
model.getConnector(1)->setAvailabilityVolatile(false);
258+
REQUIRE( rService->updateReservation(1003, 0, expiryDate, idTag, parentIdTag) );
259+
loop();
260+
REQUIRE( model.getConnector(1)->getStatus() == ChargePointStatus_Unavailable );
261+
REQUIRE( model.getConnector(2)->getStatus() == ChargePointStatus_Reserved );
262+
//@TODO: can we reserve Unavailable connectors?
263+
// REQUIRE( !rService->updateReservation(1004, 1, expiryDate, "other idTag 3", nullptr) );
241264
}
242265

243266
SECTION("Expiry date") {

0 commit comments

Comments
 (0)