Skip to content

Commit

Permalink
ConnectorEnum is now just a string
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass committed Dec 4, 2024
1 parent 1a6daa2 commit cdfecbf
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 29 deletions.
4 changes: 2 additions & 2 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,15 @@ 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<ConnectorEnum> connector_type);
bool is_connector_available(const uint32_t evse_id, std::optional<CiString<20>> 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);
bool does_connector_exist(const uint32_t evse_id, std::optional<CiString<20>> connector_type);

/// \brief Get the value optional offline flag
/// \return true if the charge point is offline. std::nullopt if it is online;
Expand Down
10 changes: 5 additions & 5 deletions include/ocpp/v201/evse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<ConnectorStatusEnum> get_connector_status(std::optional<ConnectorEnum> connector_type) = 0;
virtual std::optional<ConnectorStatusEnum> get_connector_status(std::optional<CiString<20>> connector_type) = 0;

/// \brief Opens a new transaction
/// \param transaction_id id of the transaction
Expand Down Expand Up @@ -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<ConnectorEnum> get_evse_connector_type(const uint32_t connector_id);
std::optional<CiString<20>> get_evse_connector_type(const uint32_t connector_id);

public:
/// \brief Construct a new Evse object
Expand All @@ -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<ConnectorStatusEnum> get_connector_status(std::optional<ConnectorEnum> connector_type) override;
bool does_connector_exist(const CiString<20> connector_type) override;
std::optional<ConnectorStatusEnum> get_connector_status(std::optional<CiString<20>> 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
35 changes: 35 additions & 0 deletions include/ocpp/v201/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectorEnum> connector_type) {
bool ChargePoint::is_connector_available(const uint32_t evse_id, std::optional<CiString<20>> connector_type) {
EvseInterface* evse;
try {
evse = &evse_manager->get_evse(static_cast<int32_t>(evse_id));
Expand All @@ -1976,15 +1976,15 @@ bool ChargePoint::is_connector_available(const uint32_t evse_id, std::optional<C
}

std::optional<ConnectorStatusEnum> 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;
}

return status.value() == ConnectorStatusEnum::Available;
}

bool ChargePoint::does_connector_exist(const uint32_t evse_id, std::optional<ConnectorEnum> connector_type) {
bool ChargePoint::does_connector_exist(const uint32_t evse_id, std::optional<CiString<20>> connector_type) {
EvseInterface* evse;
try {
evse = &evse_manager->get_evse(static_cast<int32_t>(evse_id));
Expand All @@ -1993,7 +1993,7 @@ bool ChargePoint::does_connector_exist(const uint32_t evse_id, std::optional<Con
return false;
}

return evse->does_connector_exist(connector_type.value_or(ConnectorEnum::Unknown));
return evse->does_connector_exist(connector_type.value_or(ConnectorEnumStringType::Unknown));
}

bool ChargePoint::is_offline() {
Expand Down Expand Up @@ -3365,7 +3365,7 @@ void ChargePoint::handle_reserve_now_request(Call<ReserveNowRequest> call) {
// Check if there is a connector available for this evse id.
if (!does_connector_exist(static_cast<uint32_t>(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;
Expand Down
25 changes: 10 additions & 15 deletions lib/ocpp/v201/evse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ uint32_t Evse::get_number_of_connectors() const {
return static_cast<uint32_t>(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;
}

Expand All @@ -110,16 +110,16 @@ 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;
}
}

return false;
}

std::optional<ConnectorStatusEnum> Evse::get_connector_status(std::optional<ConnectorEnum> connector_type) {
std::optional<ConnectorStatusEnum> Evse::get_connector_status(std::optional<CiString<20>> connector_type) {
bool type_found = false;
ConnectorStatusEnum found_status = ConnectorStatusEnum::Unavailable;
const uint32_t number_of_connectors = this->get_number_of_connectors();
Expand All @@ -143,10 +143,10 @@ std::optional<ConnectorStatusEnum> Evse::get_connector_status(std::optional<Conn

const ConnectorStatusEnum connector_status = connector->get_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;
Expand Down Expand Up @@ -205,7 +205,7 @@ void Evse::delete_database_transaction() {
}
}

std::optional<ConnectorEnum> Evse::get_evse_connector_type(const uint32_t connector_id) {
std::optional<CiString<20>> Evse::get_evse_connector_type(const uint32_t connector_id) {

auto connector = this->get_connector(static_cast<int32_t>(connector_id));
if (connector == nullptr) {
Expand All @@ -221,12 +221,7 @@ std::optional<ConnectorEnum> 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,
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/ocpp/v201/mocks/evse_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectorStatusEnum>, get_connector_status,
(std::optional<ConnectorEnum> connector_type));
(std::optional<CiString<20>> 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<IdToken>& id_token,
Expand Down

0 comments on commit cdfecbf

Please sign in to comment.