Skip to content

Commit

Permalink
Reservation all connectors reserved (#878)
Browse files Browse the repository at this point in the history
Reservation changes: some changes in the callbacks. And when a connector is 'reserved' and a plugin occured, it will not go to 'occupied' but stay in 'reserved' until it is authorized.

Signed-off-by: Maaike Zijderveld, iolar <[email protected]>
  • Loading branch information
maaikez authored Dec 16, 2024
1 parent e7a37da commit e52ac96
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
8 changes: 4 additions & 4 deletions doc/v201/ocpp_201_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,9 @@ This document contains the status of which OCPP 2.0.1 numbered functional requir
| H01.FR.17 || |
| H01.FR.18 || |
| H01.FR.19 || |
| H01.FR.20 | | |
| H01.FR.23 | | |
| H01.FR.24 | | |
| H01.FR.20 | ⛽️ | |
| H01.FR.23 | ⛽️ | |
| H01.FR.24 | ⛽️ | |

## Reservation - Cancel Reservation

Expand Down Expand Up @@ -1118,7 +1118,7 @@ This document contains the status of which OCPP 2.0.1 numbered functional requir
|-----------|--------|--------|
| H04.FR.01 || |
| H04.FR.02 || |
| H04.FR.03 | | Not all the connectors maybe? |
| H04.FR.03 | ⛽️ | |

## TariffAndCost - Show EV Driver-specific Tariff Information

Expand Down
16 changes: 16 additions & 0 deletions lib/ocpp/v201/charge_point_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ bool Callbacks::all_callbacks_valid(std::shared_ptr<DeviceModel> device_model) c
valid = false;
}
}

if (device_model->get_optional_value<bool>(ControllerComponentVariables::ReservationCtrlrAvailable)
.value_or(false)) {
if (!this->reserve_now_callback.has_value() or this->reserve_now_callback == nullptr) {
EVLOG_error << "Reservation is set to 'Available' and 'Enabled' in device model, but "
"reserve_now_callback is not implemented.";
valid = false;
}

if (!this->cancel_reservation_callback.has_value() or this->cancel_reservation_callback == nullptr) {
EVLOG_error
<< "Reservation is set to 'Available' and 'Enabled' in device model, but cancel_reservation "
"callback is not implemented";
valid = false;
}
}
}

return valid;
Expand Down
8 changes: 7 additions & 1 deletion lib/ocpp/v201/component_state_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,13 @@ OperationalStatusEnum ComponentStateManager::get_connector_persisted_operational

void ComponentStateManager::set_connector_occupied(int32_t evse_id, int32_t connector_id, bool is_occupied) {
this->individual_connector_status(evse_id, connector_id).occupied = is_occupied;
this->send_status_notification_single_connector_internal(evse_id, connector_id, true);
// Check if the connector is set to reserved. Because if it is, it should not go to occupied but stay reserved.
// If the connector is reserved and there is a plug in, the internal state should be 'occupied' and 'reserved',
// but a status notification with 'occupied' should not be sent yet. Only when the transaction is started, this
// should be sent.
if (!this->individual_connector_status(evse_id, connector_id).reserved) {
this->send_status_notification_single_connector_internal(evse_id, connector_id, true);
}
}
void ComponentStateManager::set_connector_reserved(int32_t evse_id, int32_t connector_id, bool is_reserved) {
this->individual_connector_status(evse_id, connector_id).reserved = is_reserved;
Expand Down
40 changes: 40 additions & 0 deletions tests/lib/ocpp/v201/test_charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class ChargePointCommonTestFixtureV201 : public DatabaseTestingUtils {
callbacks.update_firmware_request_callback = update_firmware_request_callback_mock.AsStdFunction();
callbacks.security_event_callback = security_event_callback_mock.AsStdFunction();
callbacks.set_charging_profiles_callback = set_charging_profiles_callback_mock.AsStdFunction();
callbacks.reserve_now_callback = reserve_now_callback_mock.AsStdFunction();
callbacks.cancel_reservation_callback = cancel_reservation_callback_mock.AsStdFunction();
}

std::shared_ptr<DeviceModel> device_model;
Expand Down Expand Up @@ -191,6 +193,8 @@ class ChargePointCommonTestFixtureV201 : public DatabaseTestingUtils {
testing::MockFunction<void(const CiString<50>& event_type, const std::optional<CiString<255>>& tech_info)>
security_event_callback_mock;
testing::MockFunction<void()> set_charging_profiles_callback_mock;
testing::MockFunction<ReserveNowStatusEnum(const ReserveNowRequest& request)> reserve_now_callback_mock;
testing::MockFunction<bool(const int32_t reservationId)> cancel_reservation_callback_mock;
ocpp::v201::Callbacks callbacks;
};

Expand Down Expand Up @@ -492,6 +496,42 @@ TEST_F(ChargePointCommonTestFixtureV201,
EXPECT_TRUE(callbacks.all_callbacks_valid(device_model));
}

TEST_F(ChargePointCommonTestFixtureV201, ReservationAvailableReserveNowCallbackNotSet) {
configure_callbacks_with_mocks();
device_model->set_value(ControllerComponentVariables::ReservationCtrlrAvailable.component,
ControllerComponentVariables::ReservationCtrlrAvailable.variable.value(),
AttributeEnum::Actual, "true", "test", true);
callbacks.reserve_now_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid(device_model));
}

TEST_F(ChargePointCommonTestFixtureV201, ReservationAvailableCancelReservationCallbackNotSet) {
configure_callbacks_with_mocks();
device_model->set_value(ControllerComponentVariables::ReservationCtrlrAvailable.component,
ControllerComponentVariables::ReservationCtrlrAvailable.variable.value(),
AttributeEnum::Actual, "true", "test", true);
callbacks.cancel_reservation_callback = nullptr;
EXPECT_FALSE(callbacks.all_callbacks_valid(device_model));
}

TEST_F(ChargePointCommonTestFixtureV201, ReservationNotAvailableReserveNowCallbackNotSet) {
configure_callbacks_with_mocks();
device_model->set_value(ControllerComponentVariables::ReservationCtrlrAvailable.component,
ControllerComponentVariables::ReservationCtrlrAvailable.variable.value(),
AttributeEnum::Actual, "false", "test", true);
callbacks.reserve_now_callback = nullptr;
EXPECT_TRUE(callbacks.all_callbacks_valid(device_model));
}

TEST_F(ChargePointCommonTestFixtureV201, ReservationNotAvailableCancelReservationCallbackNotSet) {
configure_callbacks_with_mocks();
device_model->set_value(ControllerComponentVariables::ReservationCtrlrAvailable.component,
ControllerComponentVariables::ReservationCtrlrAvailable.variable.value(),
AttributeEnum::Actual, "false", "test", true);
callbacks.cancel_reservation_callback = nullptr;
EXPECT_TRUE(callbacks.all_callbacks_valid(device_model));
}

class ChargePointConstructorTestFixtureV201 : public ChargePointCommonTestFixtureV201 {
public:
ChargePointConstructorTestFixtureV201() :
Expand Down

0 comments on commit e52ac96

Please sign in to comment.