Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/327 use case h01 reservation #854

Merged
merged 31 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dfb964b
Start reservation implementation.
maaikez Sep 16, 2024
92c75ac
Some changes to the reserve now callback.
maaikez Sep 17, 2024
218a1d5
Add todo's
maaikez Sep 23, 2024
0f97209
Merge branch 'main' into feature/327-use-case-h01-reservation
maaikez Sep 24, 2024
d47b009
Add todo.
maaikez Sep 26, 2024
c6b7242
Merge branch 'main' into feature/327-use-case-h01-reservation
maaikez Oct 29, 2024
d310f02
Add reservation callbacks and handlers and fix some bugs.
maaikez Oct 30, 2024
706f54c
Remove unnecessary todo's. Remove unnecessary loop to check for exist…
maaikez Oct 31, 2024
dd6e6bb
Merge branch 'main' into feature/327-use-case-h01-reservation
maaikez Oct 31, 2024
f454ce7
Fix conversion of bool for connector zero support.
maaikez Nov 4, 2024
0eb8847
Add reservation status.
maaikez Nov 4, 2024
3823b1c
Review comments.
maaikez Nov 5, 2024
27bcebb
Remove unused variable.
maaikez Nov 6, 2024
045bdaf
Review comment: change parameters of reserve now callback.
maaikez Nov 8, 2024
04b2c15
Merge branch 'main' into feature/327-use-case-h01-reservation
maaikez Nov 12, 2024
ae1d21a
Fix bug for composite schedule
maaikez Nov 13, 2024
d7c7792
Review comments. Some changes in functions to make it more readable.
maaikez Nov 13, 2024
c019173
Add new method to mock and change mock method function.
maaikez Nov 13, 2024
b6e8bb9
Bump version
maaikez Nov 14, 2024
4a93e69
get_connector_status: When connector type is unknown, it should also …
maaikez Nov 14, 2024
17fd4b4
Merge branch 'main' into feature/327-use-case-h01-reservation
maaikez Nov 14, 2024
8568af1
Change comment.
maaikez Nov 15, 2024
8145980
Merge branch 'main' into feature/327-use-case-h01-reservation
maaikez Nov 18, 2024
6c3a3ec
Fix build after merge.
maaikez Nov 18, 2024
7840131
Some changes to check if there is a reservation for an evse / id toke…
maaikez Nov 22, 2024
d9b3372
Review comments.
maaikez Nov 25, 2024
41a8ee7
Merge branch 'main' into feature/327-use-case-h01-reservation
maaikez Nov 25, 2024
0bc3c95
Fix build after merge.
maaikez Nov 25, 2024
c682827
Review comments
maaikez Nov 25, 2024
a1eb987
Formatting
maaikez Nov 25, 2024
8e9a5d7
Bump version
maaikez Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"attributes": [
{
"type": "Actual",
"mutability": "ReadOnly"
"mutability": "ReadOnly",
"value": true
}
],
"description": "If this configuration variable is present and set to true: Charging Station supports Reservation where EVSE id is not specified.",
Expand Down
58 changes: 30 additions & 28 deletions doc/v201/ocpp_201_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -1071,21 +1071,21 @@ This document contains the status of which OCPP 2.0.1 numbered functional requir

| ID | Status | Remark |
|-----------|--------|--------|
| H01.FR.01 | | |
| H01.FR.02 | | |
| H01.FR.03 | | |
| H01.FR.04 | | |
| H01.FR.06 | | |
| H01.FR.07 | | |
| H01.FR.09 | | |
| H01.FR.11 | | |
| H01.FR.12 | | |
| H01.FR.14 | | |
| H01.FR.15 | | |
| H01.FR.16 | | |
| H01.FR.17 | | |
| H01.FR.18 | | |
| H01.FR.19 | | |
| H01.FR.01 | | |
| H01.FR.02 | | |
| H01.FR.03 | | |
| H01.FR.04 | | |
| H01.FR.06 | | |
| H01.FR.07 | | |
| H01.FR.09 | | |
| H01.FR.11 | | |
| H01.FR.12 | | |
| H01.FR.14 | | |
| H01.FR.15 | | |
| H01.FR.16 | | |
| H01.FR.17 | | |
| H01.FR.18 | | |
| H01.FR.19 | | |
| H01.FR.20 | | |
| H01.FR.23 | | |
| H01.FR.24 | | |
Expand All @@ -1094,29 +1094,31 @@ This document contains the status of which OCPP 2.0.1 numbered functional requir

| ID | Status | Remark |
|-----------|--------|--------|
| H02.FR.01 | | |
| H02.FR.02 | | |
| H02.FR.01 | | |
| H02.FR.02 | | |

## Reservation - Use a reserved EVSE

| ID | Status | Remark |
|-----------|--------|--------|
| H03.FR.01 | | |
| H03.FR.02 | | |
| H03.FR.03 | | |
| H03.FR.04 | | |
| H03.FR.05 | | |
| H03.FR.06 | | |
| H03.FR.07 | | |
| H03.FR.08 | | |
| H03.FR.01 || |
| H03.FR.02 || |
| H03.FR.03 || |
| H03.FR.04 || |
| H03.FR.05 || |
| H03.FR.06 || |
| H03.FR.07 | ⛽️ | |
| H03.FR.08 | ⛽️ | |
| H03.FR.09 || |
| H03.FR.10 || |

## Reservation - Reservation Ended, not used

| ID | Status | Remark |
|-----------|--------|--------|
| H04.FR.01 | | |
| H04.FR.02 | | |
| H04.FR.03 | | |
| H04.FR.01 | | |
| H04.FR.02 | | |
| H04.FR.03 | | Not all the connectors maybe? |

## TariffAndCost - Show EV Driver-specific Tariff Information

Expand Down
37 changes: 37 additions & 0 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ocpp/v201/messages/Get15118EVCertificate.hpp"
#include <ocpp/v201/messages/Authorize.hpp>
#include <ocpp/v201/messages/BootNotification.hpp>
#include <ocpp/v201/messages/CancelReservation.hpp>
#include <ocpp/v201/messages/CertificateSigned.hpp>
#include <ocpp/v201/messages/ChangeAvailability.hpp>
#include <ocpp/v201/messages/ClearCache.hpp>
Expand Down Expand Up @@ -60,6 +61,7 @@
#include <ocpp/v201/messages/ReportChargingProfiles.hpp>
#include <ocpp/v201/messages/RequestStartTransaction.hpp>
#include <ocpp/v201/messages/RequestStopTransaction.hpp>
#include <ocpp/v201/messages/ReserveNow.hpp>
#include <ocpp/v201/messages/Reset.hpp>
#include <ocpp/v201/messages/SecurityEventNotification.hpp>
#include <ocpp/v201/messages/SendLocalList.hpp>
Expand Down Expand Up @@ -232,6 +234,11 @@ class ChargePointInterface {
/// \param connector_id Reserved connector id
virtual void on_reserved(const int32_t evse_id, const int32_t connector_id) = 0;

/// \brief Event handler that should be called when the reservation of the connector is cleared.
/// \param evse_id Cleared EVSE id
/// \param connector_id Cleared connector id.
virtual void on_reservation_cleared(const int32_t evse_id, const int32_t connector_id) = 0;

/// \brief Event handler that will update the charging state internally when it has been changed.
/// \param evse_id The evse id of which the charging state has changed.
/// \param charging_state The new charging state.
Expand Down Expand Up @@ -273,6 +280,11 @@ class ChargePointInterface {
///
virtual void on_variable_changed(const SetVariableData& set_variable_data) = 0;

/// \brief Event handler that will send a ReservationStatusUpdate request.
/// \param reservation_id The reservation id.
/// \param status The status.
virtual void on_reservation_status(const int32_t reservation_id, const ReservationUpdateStatusEnum status) = 0;

/// @} // End handlers group

/// @}
Expand Down Expand Up @@ -583,6 +595,22 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
///
void set_evse_connectors_unavailable(EvseInterface& evse, bool persist);

///
/// \brief Check if there is a connector available with the given connector type.
/// \param evse_id The evse to check for.
/// \param connector_type The connector type.
/// \return True when a connector is available and the evse id exists.
///
bool is_connector_available(const uint32_t evse_id, std::optional<ConnectorEnum> connector_type);

///
/// \brief Check if the connector exists on the given evse id.
/// \param evse_id The evse id to check for.
/// \param connector_type The connector type.
/// \return False if evse id does not exist or evse does not have the given connector type.
///
bool does_connector_exist(const uint32_t evse_id, std::optional<ConnectorEnum> connector_type);

/// \brief Get the value optional offline flag
/// \return true if the charge point is offline. std::nullopt if it is online;
bool is_offline();
Expand Down Expand Up @@ -727,6 +755,11 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
void handle_change_availability_req(Call<ChangeAvailabilityRequest> call);
void handle_heartbeat_response(CallResult<HeartbeatResponse> call);

// Function Block H: Reservations
void handle_reserve_now_request(Call<ReserveNowRequest> call);
void handle_cancel_reservation_callback(Call<CancelReservationRequest> call);
void send_reserve_now_rejected_response(const MessageId& unique_id, const std::string& status_info);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we haven't used this anywhere yet in ChargePoint but the status_info could be a string_view. You can change it if you want but it's fine either way.


// Functional Block I: TariffAndCost
void handle_costupdated_req(const Call<CostUpdatedRequest> call);

Expand Down Expand Up @@ -916,6 +949,8 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

void on_reserved(const int32_t evse_id, const int32_t connector_id) override;

void on_reservation_cleared(const int32_t evse_id, const int32_t connector_id) override;

bool on_charging_state_changed(
const uint32_t evse_id, const ChargingStateEnum charging_state,
const TriggerReasonEnum trigger_reason = TriggerReasonEnum::ChargingStateChanged) override;
Expand All @@ -935,6 +970,8 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

void on_variable_changed(const SetVariableData& set_variable_data) override;

void on_reservation_status(const int32_t reservation_id, const ReservationUpdateStatusEnum status) override;

std::optional<DataTransferResponse> data_transfer_req(const CiString<255>& vendorId,
const std::optional<CiString<50>>& messageId,
const std::optional<json>& data) override;
Expand Down
6 changes: 6 additions & 0 deletions include/ocpp/v201/charge_point_callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ocpp/v201/messages/GetDisplayMessages.hpp>
#include <ocpp/v201/messages/GetLog.hpp>
#include <ocpp/v201/messages/RequestStartTransaction.hpp>
#include <ocpp/v201/messages/ReserveNow.hpp>
#include <ocpp/v201/messages/SetDisplayMessage.hpp>
#include <ocpp/v201/messages/TransactionEvent.hpp>
#include <ocpp/v201/messages/UnlockConnector.hpp>
Expand Down Expand Up @@ -160,6 +161,11 @@ struct Callbacks {
std::optional<std::string> currency_code)>>
set_running_cost_callback;

/// \brief Callback function is called when a reservation request is received from the CSMS
std::optional<std::function<ReserveNowStatusEnum(const ReserveNowRequest& request)>> reserve_now_callback;
/// \brief Callback function is called when a cancel reservation request is received from the CSMS
std::optional<std::function<bool(const int32_t reservationId)>> cancel_reservation_callback;

/// @} // End ocpp 201 callbacks group / topic

/// @} // End group
Expand Down
29 changes: 29 additions & 0 deletions include/ocpp/v201/evse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ class EvseInterface {
/// \return
virtual uint32_t get_number_of_connectors() const = 0;

///
/// \brief Check if the given connector type exists on this evse.
/// \param connector_type The connector type to check.
/// \return True if connector type is unknown or this evse has the given connector type.
///
virtual bool does_connector_exist(ConnectorEnum connector_type) = 0;

///
/// \brief Get connector status.
///
/// This will search if there is a connector on this evse with status 'Available'. It will search through all
/// connectors, optionally filtering by connector type, and return on the first connector that is 'Available'. If
/// there is no 'Available' connector, it will return the status of the last found connector with the given
/// connector type.
///
/// \param connector_type The connector type to filter on (optional).
/// \return Connector status. If connector type is given and does not exist, std::nullopt.
///
virtual std::optional<ConnectorStatusEnum> get_connector_status(std::optional<ConnectorEnum> connector_type) = 0;

/// \brief Opens a new transaction
/// \param transaction_id id of the transaction
/// \param connector_id id of the connector
Expand Down Expand Up @@ -198,6 +218,13 @@ class Evse : public EvseInterface {
/// \brief Component responsible for maintaining and persisting the operational status of CS, EVSEs, and connectors.
std::shared_ptr<ComponentStateManagerInterface> component_state_manager;

///
/// \brief Get connector type of Connector
/// \param connector_id Connector id
/// \return The connector type. If evse or connector id is not correct: std::nullopt.
///
std::optional<ConnectorEnum> get_evse_connector_type(const uint32_t connector_id);

public:
/// \brief Construct a new Evse object
/// \param evse_id id of the evse
Expand All @@ -220,6 +247,8 @@ class Evse : public EvseInterface {
int32_t get_id() const;

uint32_t get_number_of_connectors() const;
bool does_connector_exist(const ConnectorEnum connector_type) override;
std::optional<ConnectorStatusEnum> get_connector_status(std::optional<ConnectorEnum> connector_type) override;

void open_transaction(const std::string& transaction_id, const int32_t connector_id, const DateTime& timestamp,
const MeterValue& meter_start, const std::optional<IdToken>& id_token,
Expand Down
4 changes: 2 additions & 2 deletions include/ocpp/v201/evse_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class EvseManager : public EvseManagerInterface {
const std::function<void(int32_t evse_id)>& pause_charging_callback);

EvseInterface& get_evse(int32_t id) override;
const EvseInterface& get_evse(int32_t id) const override;
const EvseInterface& get_evse(const int32_t id) const override;

bool does_evse_exist(int32_t id) const override;
bool does_evse_exist(const int32_t id) const override;

size_t get_number_of_evses() const override;

Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v16/charge_point_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ std::optional<KeyValue> ChargePointConfiguration::getReserveConnectorZeroSupport
KeyValue kv;
kv.key = "ReserveConnectorZeroSupported";
kv.readonly = true;
kv.value.emplace(std::to_string(reserve_connector_zero_supported.value()));
kv.value.emplace(ocpp::conversions::bool_to_string(reserve_connector_zero_supported.value()));
reserve_connector_zero_supported_kv.emplace(kv);
}
return reserve_connector_zero_supported_kv;
Expand Down
Loading