diff --git a/include/ocpp/v201/charge_point.hpp b/include/ocpp/v201/charge_point.hpp index 305ad0390..89e856fa0 100644 --- a/include/ocpp/v201/charge_point.hpp +++ b/include/ocpp/v201/charge_point.hpp @@ -581,7 +581,7 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa /// \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 connector_type); + bool is_connector_available(const uint32_t evse_id, std::optional> connector_type); /// /// \brief Check if the connector exists on the given evse id. @@ -589,7 +589,7 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa /// \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 connector_type); + bool does_connector_exist(const uint32_t evse_id, std::optional> connector_type); /// \brief Get the value optional offline flag /// \return true if the charge point is offline. std::nullopt if it is online; diff --git a/include/ocpp/v201/evse.hpp b/include/ocpp/v201/evse.hpp index babc05071..e74da9dcf 100644 --- a/include/ocpp/v201/evse.hpp +++ b/include/ocpp/v201/evse.hpp @@ -41,7 +41,7 @@ class EvseInterface { /// \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; + virtual bool does_connector_exist(CiString<20> connector_type) = 0; /// /// \brief Get connector status. @@ -54,7 +54,7 @@ class EvseInterface { /// \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 get_connector_status(std::optional connector_type) = 0; + virtual std::optional get_connector_status(std::optional> connector_type) = 0; /// \brief Opens a new transaction /// \param transaction_id id of the transaction @@ -223,7 +223,7 @@ class Evse : public EvseInterface { /// \param connector_id Connector id /// \return The connector type. If evse or connector id is not correct: std::nullopt. /// - std::optional get_evse_connector_type(const uint32_t connector_id); + std::optional> get_evse_connector_type(const uint32_t connector_id); public: /// \brief Construct a new Evse object @@ -247,8 +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 get_connector_status(std::optional connector_type) override; + bool does_connector_exist(const CiString<20> connector_type) override; + std::optional get_connector_status(std::optional> 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& id_token, diff --git a/include/ocpp/v201/types.hpp b/include/ocpp/v201/types.hpp index 9e079d824..a343b45cb 100644 --- a/include/ocpp/v201/types.hpp +++ b/include/ocpp/v201/types.hpp @@ -193,6 +193,41 @@ inline const CiString<20> NEMA = "NEMA"; inline const CiString<20> NoAuthorization = "NoAuthorization"; inline const CiString<20> VIN = "VIN"; } // namespace IdTokenEnumStringType + +namespace ConnectorEnumStringType { +inline const CiString<20> cCCS1 = "cCCS1"; // Combined Charging System 1 (captive cabled) a.k.a. Combo 1 +inline const CiString<20> cCCS2 = "cCCS2"; // Combined Charging System 2 (captive cabled) a.k.a. Combo 2 +inline const CiString<20> cChaoJi = "cChaoJi"; // ChaoJi (captive cabled) a.k.a. CHAdeMO 3.0 +inline const CiString<20> cG105 = "cG105"; // JARI G105-1993 (captive cabled) a.k.a. CHAdeMO (captive cabled) +inline const CiString<20> cGBT_DC = "cGBT-DC"; // GB/T 20234.3 DC connector (captive cabled) +inline const CiString<20> cLECCS = "cLECCS"; // Light Equipment Combined Charging System IS17017 (captive cabled) +inline const CiString<20> cMCS = "cMCS"; // Megawatt Charging System (captive cabled) +inline const CiString<20> cNACS = "cNACS"; // North American Charging Standard (captive cabled) +inline const CiString<20> cNACS_CCS1 = "cNACS-CCS1"; // Tesla MagicDock with built-in NACS to CCS1 adapter +inline const CiString<20> cTesla = "cTesla"; // Tesla Connector (captive cabled) +inline const CiString<20> cType1 = "cType1"; // IEC62196-2 Type 1 connector (captive cabled) a.k.a. J1772 +inline const CiString<20> cType2 = "cType2"; // IEC62196-2 Type 2 connector (captive cabled) a.k.a. Mennekes connector +inline const CiString<20> cUltraChaoJi = "cUltraChaoJi"; // Ultra-ChaoJi for megawatt charging +inline const CiString<20> s309_1P_16A = "s309-1P-16A "; // 16A 1 phase IEC60309 socket +inline const CiString<20> s309_1P_32A = "s309-1P-32A "; // 32A 1 phase IEC60309 socket +inline const CiString<20> s309_3P_16A = "s309-3P-16A"; // 16A 3 phase IEC60309 socket +inline const CiString<20> s309_3P_32A = "s309-3P-32A"; // 32A 3 phase IEC60309 socket +inline const CiString<20> sBS1361 = "sBS1361"; // UK domestic socket a.k.a. 13Amp +inline const CiString<20> sCEE_7_7 = "sCEE-7-7"; // CEE 7/7 16A socket. May represent 7/4 and 7/5 a.k.a Schuko +inline const CiString<20> sType2 = "sType2"; // IEC62196-2 Type 2 socket a.k.a. Mennekes connector +inline const CiString<20> sType3 = "sType3"; // IEC62196-2 Type 3 socket a.k.a. Scame +inline const CiString<20> wInductive = "wInductive"; // Wireless inductively coupled connection (generic) +inline const CiString<20> wResonant = "wResonant"; // Wireless resonant coupled connection (generic) +inline const CiString<20> Other1PhMax16A = + "Other1PhMax16A"; // Other single phase (domestic) sockets not mentioned above, rated at no more than 16A. CEE7/17, + // AS3112, NEMA 5-15, NEMA 5-20, JISC8303, TIS166, SI 32, CPCS-CCC, SEV1011, etc. +inline const CiString<20> Other1PhOver16A = + "Other1PhOver16A"; // Other single phase sockets not mentioned above (over 16A) +inline const CiString<20> Other3Ph = "Other3Ph"; // Other 3 phase sockets not mentioned above. NEMA14-30, NEMA14-50. +inline const CiString<20> Pan = "Pan"; // Pantograph connector +inline const CiString<20> Undetermined = "Undetermined"; // Yet to be determined (e.g. before plugged in) +inline const CiString<20> Unknown = "Unknown"; // Unknown/not determinable +} // namespace ConnectorEnumStringType } // namespace v201 } // namespace ocpp diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index 32371a62e..d63c04a70 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -1966,7 +1966,7 @@ void ChargePoint::set_evse_connectors_unavailable(EvseInterface& evse, bool pers } } -bool ChargePoint::is_connector_available(const uint32_t evse_id, std::optional connector_type) { +bool ChargePoint::is_connector_available(const uint32_t evse_id, std::optional> connector_type) { EvseInterface* evse; try { evse = &evse_manager->get_evse(static_cast(evse_id)); @@ -1976,7 +1976,7 @@ bool ChargePoint::is_connector_available(const uint32_t evse_id, std::optional status = - evse->get_connector_status(connector_type.value_or(ConnectorEnum::Unknown)); + evse->get_connector_status(connector_type.value_or(ConnectorEnumStringType::Unknown)); if (!status.has_value()) { return false; } @@ -1984,7 +1984,7 @@ bool ChargePoint::is_connector_available(const uint32_t evse_id, std::optional connector_type) { +bool ChargePoint::does_connector_exist(const uint32_t evse_id, std::optional> connector_type) { EvseInterface* evse; try { evse = &evse_manager->get_evse(static_cast(evse_id)); @@ -1993,7 +1993,7 @@ bool ChargePoint::does_connector_exist(const uint32_t evse_id, std::optionaldoes_connector_exist(connector_type.value_or(ConnectorEnum::Unknown)); + return evse->does_connector_exist(connector_type.value_or(ConnectorEnumStringType::Unknown)); } bool ChargePoint::is_offline() { @@ -3365,7 +3365,7 @@ void ChargePoint::handle_reserve_now_request(Call call) { // Check if there is a connector available for this evse id. if (!does_connector_exist(static_cast(evse_id.value()), request.connectorType)) { EVLOG_info << "Trying to make a reservation for connector type " - << conversions::connector_enum_to_string(request.connectorType.value_or(ConnectorEnum::Unknown)) + << request.connectorType.value_or(ConnectorEnumStringType::Unknown) << " for evse " << evse_id.value() << ", but this connector type does not exist."; send_reserve_now_rejected_response(call.uniqueId, "Connector type does not exist"); return; diff --git a/lib/ocpp/v201/evse.cpp b/lib/ocpp/v201/evse.cpp index 6bc5407ee..814ba76e1 100644 --- a/lib/ocpp/v201/evse.cpp +++ b/lib/ocpp/v201/evse.cpp @@ -86,13 +86,13 @@ uint32_t Evse::get_number_of_connectors() const { return static_cast(this->id_connector_map.size()); } -bool Evse::does_connector_exist(const ConnectorEnum connector_type) { +bool Evse::does_connector_exist(const CiString<20> connector_type) { const uint32_t number_of_connectors = this->get_number_of_connectors(); if (number_of_connectors == 0) { return false; } - if (connector_type == ConnectorEnum::Unknown) { + if (connector_type == ConnectorEnumStringType::Unknown) { return true; } @@ -110,8 +110,8 @@ bool Evse::does_connector_exist(const ConnectorEnum connector_type) { continue; } - ConnectorEnum type = this->get_evse_connector_type(i).value_or(ConnectorEnum::Unknown); - if (type == ConnectorEnum::Unknown || type == connector_type) { + CiString<20> type = this->get_evse_connector_type(i).value_or(ConnectorEnumStringType::Unknown); + if (type == ConnectorEnumStringType::Unknown || type == connector_type) { return true; } } @@ -119,7 +119,7 @@ bool Evse::does_connector_exist(const ConnectorEnum connector_type) { return false; } -std::optional Evse::get_connector_status(std::optional connector_type) { +std::optional Evse::get_connector_status(std::optional> connector_type) { bool type_found = false; ConnectorStatusEnum found_status = ConnectorStatusEnum::Unavailable; const uint32_t number_of_connectors = this->get_number_of_connectors(); @@ -143,10 +143,10 @@ std::optional Evse::get_connector_status(std::optionalget_effective_connector_status(); - const ConnectorEnum evse_connector_type = this->get_evse_connector_type(i).value_or(ConnectorEnum::Unknown); - const ConnectorEnum input_connector_type = connector_type.value_or(ConnectorEnum::Unknown); + const CiString<20> evse_connector_type = this->get_evse_connector_type(i).value_or(ConnectorEnumStringType::Unknown); + const CiString<20> input_connector_type = connector_type.value_or(ConnectorEnumStringType::Unknown); const bool connector_type_unknown = - evse_connector_type == ConnectorEnum::Unknown || input_connector_type == ConnectorEnum::Unknown; + evse_connector_type == ConnectorEnumStringType::Unknown || input_connector_type == ConnectorEnumStringType::Unknown; if (connector_type_unknown || evse_connector_type == input_connector_type) { type_found = true; @@ -205,7 +205,7 @@ void Evse::delete_database_transaction() { } } -std::optional Evse::get_evse_connector_type(const uint32_t connector_id) { +std::optional> Evse::get_evse_connector_type(const uint32_t connector_id) { auto connector = this->get_connector(static_cast(connector_id)); if (connector == nullptr) { @@ -221,12 +221,7 @@ std::optional Evse::get_evse_connector_type(const uint32_t connec return std::nullopt; } - try { - return conversions::string_to_connector_enum(connector_type.value()); - } catch (const StringToEnumException& e) { - EVLOG_warning << "Could not convert to ConnectorEnum: " << connector_type.value(); - return std::nullopt; - } + return connector_type.value(); } void Evse::open_transaction(const std::string& transaction_id, const int32_t connector_id, const DateTime& timestamp, diff --git a/tests/lib/ocpp/v201/mocks/evse_mock.hpp b/tests/lib/ocpp/v201/mocks/evse_mock.hpp index 0117a93e7..9cf1b3d35 100644 --- a/tests/lib/ocpp/v201/mocks/evse_mock.hpp +++ b/tests/lib/ocpp/v201/mocks/evse_mock.hpp @@ -12,9 +12,9 @@ class EvseMock : public EvseInterface { public: MOCK_METHOD(int32_t, get_id, (), (const)); MOCK_METHOD(uint32_t, get_number_of_connectors, (), (const)); - MOCK_METHOD(bool, does_connector_exist, (ConnectorEnum connector_type)); + MOCK_METHOD(bool, does_connector_exist, (CiString<20> connector_type)); MOCK_METHOD(std::optional, get_connector_status, - (std::optional connector_type)); + (std::optional> connector_type)); MOCK_METHOD(void, open_transaction, (const std::string& transaction_id, const int32_t connector_id, const DateTime& timestamp, const MeterValue& meter_start, const std::optional& id_token,