diff --git a/.gitignore b/.gitignore index aa47f25f30..7116824271 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ workspace.yaml CMakeLists.txt.user .idea/ MODULE.bazel.lock +/lib/everest/api_types/tests/test_file_autogenerator/pythonProject/__pycache__/ diff --git a/compile_commands.json b/compile_commands.json new file mode 120000 index 0000000000..4079783ed4 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1 @@ +/home/jchh/development/everest-core/build/TESTING//compile_commands.json \ No newline at end of file diff --git a/lib/everest/CMakeLists.txt b/lib/everest/CMakeLists.txt index 6ec5690577..e417073f3c 100644 --- a/lib/everest/CMakeLists.txt +++ b/lib/everest/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(can_dpm1000) add_subdirectory(conversions) +add_subdirectory(everest_api_types) add_subdirectory(external_energy_limits) add_subdirectory(helpers) add_subdirectory(run_application) diff --git a/lib/everest/everest_api_types/CMakeLists.txt b/lib/everest/everest_api_types/CMakeLists.txt new file mode 100644 index 0000000000..8b26806d12 --- /dev/null +++ b/lib/everest/everest_api_types/CMakeLists.txt @@ -0,0 +1,134 @@ +find_package(everest-cmake 0.1 REQUIRED + PATHS ../everest-cmake +) + + +if(DISABLE_EDM) + find_package(nlohmann_json REQUIRED) + find_package(date REQUIRED) +endif() + + +# SO for API with structs and (de)serialization codec +add_library(everest_api_types SHARED) +add_library(everest::everest_api_types ALIAS everest_api_types) + +add_dependencies(everest_api_types generate_cpp_files) + +target_compile_options(everest_api_types + PUBLIC -Wall -Wextra -pedantic -Werror=switch) + +set_target_properties(everest_api_types PROPERTIES + VERSION 0.1.0 + SOVERSION 0 +) + +target_include_directories(everest_api_types + PUBLIC $ + PUBLIC $ + + PUBLIC $ + + PRIVATE "private_include/everest_api_types" + PRIVATE "include/everest_api_types" + PRIVATE "${CMAKE_BINARY_DIR}/generated/include" +) + +target_sources(everest_api_types + PRIVATE + + src/everest_api_types/auth/codec.cpp + src/everest_api_types/auth/json_codec.cpp + src/everest_api_types/auth/wrapper.cpp + + src/everest_api_types/display_message/codec.cpp + src/everest_api_types/display_message/json_codec.cpp + src/everest_api_types/display_message/wrapper.cpp + + src/everest_api_types/energy/codec.cpp + src/everest_api_types/energy/json_codec.cpp + src/everest_api_types/energy/wrapper.cpp + + src/everest_api_types/error_history/codec.cpp + src/everest_api_types/error_history/json_codec.cpp + src/everest_api_types/error_history/wrapper.cpp + + src/everest_api_types/evse_board_support/codec.cpp + src/everest_api_types/evse_board_support/json_codec.cpp + src/everest_api_types/evse_board_support/wrapper.cpp + + src/everest_api_types/evse_manager/codec.cpp + src/everest_api_types/evse_manager/json_codec.cpp + src/everest_api_types/evse_manager/wrapper.cpp + + src/everest_api_types/iso15118_charger/codec.cpp + src/everest_api_types/iso15118_charger/json_codec.cpp + src/everest_api_types/iso15118_charger/wrapper.cpp + + src/everest_api_types/isolation_monitor/codec.cpp + src/everest_api_types/isolation_monitor/json_codec.cpp + src/everest_api_types/isolation_monitor/wrapper.cpp + + src/everest_api_types/ocpp/codec.cpp + src/everest_api_types/ocpp/json_codec.cpp + src/everest_api_types/ocpp/wrapper.cpp + + src/everest_api_types/over_voltage_monitor/codec.cpp + src/everest_api_types/over_voltage_monitor/json_codec.cpp + + src/everest_api_types/power_supply_DC/codec.cpp + src/everest_api_types/power_supply_DC/json_codec.cpp + src/everest_api_types/power_supply_DC/wrapper.cpp + + src/everest_api_types/powermeter/codec.cpp + src/everest_api_types/powermeter/json_codec.cpp + src/everest_api_types/powermeter/wrapper.cpp + + src/everest_api_types/slac/codec.cpp + src/everest_api_types/slac/json_codec.cpp + + src/everest_api_types/system/codec.cpp + src/everest_api_types/system/json_codec.cpp + src/everest_api_types/system/wrapper.cpp + + src/everest_api_types/uk_random_delay/codec.cpp + src/everest_api_types/uk_random_delay/json_codec.cpp + src/everest_api_types/uk_random_delay/wrapper.cpp + + src/everest_api_types/generic/codec.cpp + src/everest_api_types/generic/json_codec.cpp + src/everest_api_types/generic/string.cpp + + src/everest_api_types/utilities/codec.cpp + src/everest_api_types/utilities/Topics.cpp + + src/utils/date.cpp +) + +target_link_libraries(everest_api_types + PRIVATE nlohmann_json::nlohmann_json + PRIVATE date::date + PRIVATE date::date-tz +) + +install(TARGETS everest_api_types + EXPORT everest_api_types-targets + LIBRARY +) + +install( + DIRECTORY include/everest_api_types + DESTINATION include +) + +evc_setup_package( + NAME everest-api-types + EXPORT everest_api_types-targets + NAMESPACE everest +) + +if(${BUILD_TESTING}) + add_subdirectory(tests) +endif() + + diff --git a/lib/everest/everest_api_types/include/everest_api_types/auth/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/auth/API.hpp new file mode 100644 index 0000000000..ce5849e0ab --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/auth/API.hpp @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once +#include +#include +#include +#include + +namespace everest::lib::API::V1_0::types::auth { + +enum class AuthorizationStatus { + Accepted, + Blocked, + ConcurrentTx, + Expired, + Invalid, + NoCredit, + NotAllowedTypeEVSE, + NotAtThisLocation, + NotAtThisTime, + Unknown, +}; + +enum class CertificateStatus { + Accepted, + SignatureError, + CertificateExpired, + CertificateRevoked, + NoCertificateAvailable, + CertChainError, + ContractCancelled, +}; + +enum class TokenValidationStatus { + Processing, + Accepted, + Rejected, + TimedOut, + Withdrawn, +}; + +enum class SelectionAlgorithm { + UserInput, + PlugEvents, + FindFirst, +}; + +enum class AuthorizationType { + OCPP, + RFID, + Autocharge, + PlugAndCharge, + BankCard, +}; + +enum class IdTokenType { + Central, + eMAID, + MacAddress, + ISO14443, + ISO15693, + KeyCode, + Local, + NoAuthorization, +}; + +enum class WithdrawAuthorizationResult { + Accepted, + AuthorizationNotFound, + EvseNotFound, + Rejected, +}; + +struct CustomIdToken { + std::string value; + std::string type; +}; + +struct IdToken { + std::string value; + IdTokenType type; + std::optional> additional_info; +}; + +struct ProvidedIdToken { + IdToken id_token; + AuthorizationType authorization_type; + std::optional request_id; + std::optional parent_id_token; + std::optional> connectors; + std::optional prevalidated; + std::optional certificate; + // std::optional> iso15118CertificateHashData; + // FIXME: Provide datatype +}; + +struct TokenValidationStatusMessage { + ProvidedIdToken token; + TokenValidationStatus status; + std::optional> messages; +}; + +struct ValidationResult { + AuthorizationStatus authorization_status; + std::optional certificate_status; + std::optional reason; + std::optional expiry_time; + std::optional parent_id_token; + std::optional> evse_ids; + std::optional reservation_id; +}; + +struct ValidationResultUpdate { + ValidationResult validation_result; + int32_t connector_id; +}; + +struct WithdrawAuthorizationRequest { + std::optional evse_id; + std::optional id_token; +}; + +} // namespace everest::lib::API::V1_0::types::auth diff --git a/lib/everest/everest_api_types/include/everest_api_types/auth/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/auth/codec.hpp new file mode 100644 index 0000000000..fa2d0aa7a7 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/auth/codec.hpp @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::auth { + +std::string serialize(AuthorizationStatus val) noexcept; +std::string serialize(CertificateStatus val) noexcept; +std::string serialize(TokenValidationStatus val) noexcept; +std::string serialize(SelectionAlgorithm val) noexcept; +std::string serialize(AuthorizationType val) noexcept; +std::string serialize(IdTokenType val) noexcept; +std::string serialize(WithdrawAuthorizationResult val) noexcept; +std::string serialize(CustomIdToken const& val) noexcept; +std::string serialize(IdToken const& val) noexcept; +std::string serialize(ProvidedIdToken const& val) noexcept; +std::string serialize(TokenValidationStatusMessage const& val) noexcept; +std::string serialize(ValidationResult const& val) noexcept; +std::string serialize(ValidationResultUpdate const& val) noexcept; +std::string serialize(WithdrawAuthorizationRequest const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, AuthorizationStatus const& val); +std::ostream& operator<<(std::ostream& os, CertificateStatus const& val); +std::ostream& operator<<(std::ostream& os, TokenValidationStatus const& val); +std::ostream& operator<<(std::ostream& os, SelectionAlgorithm const& val); +std::ostream& operator<<(std::ostream& os, AuthorizationType const& val); +std::ostream& operator<<(std::ostream& os, IdTokenType const& val); +std::ostream& operator<<(std::ostream& os, WithdrawAuthorizationResult const& val); +std::ostream& operator<<(std::ostream& os, CustomIdToken const& val); +std::ostream& operator<<(std::ostream& os, IdToken const& val); +std::ostream& operator<<(std::ostream& os, ProvidedIdToken const& val); +std::ostream& operator<<(std::ostream& os, TokenValidationStatusMessage const& val); +std::ostream& operator<<(std::ostream& os, ValidationResult const& val); +std::ostream& operator<<(std::ostream& os, ValidationResultUpdate const& val); +std::ostream& operator<<(std::ostream& os, WithdrawAuthorizationRequest const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::auth diff --git a/lib/everest/everest_api_types/include/everest_api_types/display_message/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/display_message/API.hpp new file mode 100644 index 0000000000..93db51ad59 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/display_message/API.hpp @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once +#include +#include +#include + +namespace everest::lib::API::V1_0::types::display_message { + +enum class MessagePriorityEnum { + AlwaysFront, + InFront, + NormalCycle, +}; + +enum class MessageStateEnum { + Charging, + Faulted, + Idle, + Unavailable, + Suspending, + Discharging, +}; + +enum class DisplayMessageStatusEnum { + Accepted, + NotSupportedMessageFormat, + Rejected, + NotSupportedPriority, + NotSupportedState, + UnknownTransaction, +}; + +enum class ClearMessageResponseEnum { + Accepted, + Unknown, +}; + +enum class MessageFormat { + ASCII, + HTML, + URI, + UTF8, + QRCODE, +}; + +enum class Identifier_type { + IdToken, + SessionId, + TransactionId, +}; + +struct MessageContent { + std::string content; + std::optional format; + std::optional language; +}; + +struct DisplayMessage { + MessageContent message; + std::optional id; + std::optional priority; + std::optional state; + std::optional timestamp_from; + std::optional timestamp_to; + std::optional identifier_id; + std::optional identifier_type; + std::optional qr_code; +}; + +struct SetDisplayMessageRequest { + std::vector display_messages; +}; + +struct SetDisplayMessageResponse { + DisplayMessageStatusEnum status; + std::optional status_info; +}; + +struct GetDisplayMessageRequest { + std::optional> id; + std::optional priority; + std::optional state; +}; + +struct GetDisplayMessageResponse { + std::optional status_info; + std::optional> messages; +}; + +struct ClearDisplayMessageRequest { + int32_t id; +}; + +struct ClearDisplayMessageResponse { + ClearMessageResponseEnum status; + std::optional status_info; +}; + +} // namespace everest::lib::API::V1_0::types::display_message diff --git a/lib/everest/everest_api_types/include/everest_api_types/display_message/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/display_message/codec.hpp new file mode 100644 index 0000000000..ffe6bc8715 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/display_message/codec.hpp @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once +#include + +namespace everest::lib::API::V1_0::types::display_message { + +std::string serialize(MessagePriorityEnum val) noexcept; +std::string serialize(MessageStateEnum val) noexcept; +std::string serialize(DisplayMessageStatusEnum val) noexcept; +std::string serialize(ClearMessageResponseEnum val) noexcept; +std::string serialize(MessageFormat val) noexcept; +std::string serialize(Identifier_type val) noexcept; +std::string serialize(MessageContent const& val) noexcept; +std::string serialize(DisplayMessage const& val) noexcept; +std::string serialize(SetDisplayMessageRequest const& val) noexcept; +std::string serialize(SetDisplayMessageResponse const& val) noexcept; +std::string serialize(GetDisplayMessageRequest const& val) noexcept; +std::string serialize(GetDisplayMessageResponse const& val) noexcept; +std::string serialize(ClearDisplayMessageRequest const& val) noexcept; +std::string serialize(ClearDisplayMessageResponse const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, MessagePriorityEnum const& val); +std::ostream& operator<<(std::ostream& os, MessageStateEnum const& val); +std::ostream& operator<<(std::ostream& os, DisplayMessageStatusEnum const& val); +std::ostream& operator<<(std::ostream& os, ClearMessageResponseEnum const& val); +std::ostream& operator<<(std::ostream& os, MessageFormat const& val); +std::ostream& operator<<(std::ostream& os, Identifier_type const& val); +std::ostream& operator<<(std::ostream& os, MessageContent const& val); +std::ostream& operator<<(std::ostream& os, DisplayMessage const& val); +std::ostream& operator<<(std::ostream& os, SetDisplayMessageRequest const& val); +std::ostream& operator<<(std::ostream& os, SetDisplayMessageResponse const& val); +std::ostream& operator<<(std::ostream& os, GetDisplayMessageRequest const& val); +std::ostream& operator<<(std::ostream& os, GetDisplayMessageResponse const& val); +std::ostream& operator<<(std::ostream& os, ClearDisplayMessageRequest const& val); +std::ostream& operator<<(std::ostream& os, ClearDisplayMessageResponse const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::display_message diff --git a/lib/everest/everest_api_types/include/everest_api_types/energy/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/energy/API.hpp new file mode 100644 index 0000000000..995cc87315 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/energy/API.hpp @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include +#include +#include + +namespace everest::lib::API::V1_0::types::energy { + +struct NumberWithSource { + float value; + std::string source; +}; + +struct IntegerWithSource { + int32_t value; + std::string source; +}; + +struct FrequencyWattPoint { + float frequency_Hz; + float total_power_W; +}; + +struct SetpointType { + int32_t priority; + std::string source; + std::optional ac_current_A; + std::optional total_power_W; + std::optional> frequency_table; +}; + +struct PricePerkWh { + std::string timestamp; + float value; + std::string currency; +}; + +struct LimitsReq { + std::optional total_power_W; + std::optional ac_max_current_A; + std::optional ac_min_current_A; + std::optional ac_max_phase_count; + std::optional ac_min_phase_count; + std::optional ac_supports_changing_phases_during_charging; + std::optional ac_number_of_active_phases; +}; + +struct LimitsRes { + std::optional total_power_W; + std::optional ac_max_current_A; + std::optional ac_max_phase_count; +}; + +struct ScheduleReqEntry { + std::string timestamp; + LimitsReq limits_to_root; + LimitsReq limits_to_leaves; + std::optional conversion_efficiency; + std::optional price_per_kwh; +}; + +struct ScheduleResEntry { + std::string timestamp; + LimitsRes limits_to_root; + std::optional price_per_kwh; +}; + +struct ScheduleSetpointEntry { + std::string timestamp; + std::optional setpoint; +}; + +struct ExternalLimits { + std::vector schedule_import; + std::vector schedule_export; + std::vector schedule_setpoints; +}; + +struct EnforcedLimits { + std::string uuid; + int32_t valid_for; + LimitsRes limits_root_side; + std::vector schedule; +}; + +} // namespace everest::lib::API::V1_0::types::energy diff --git a/lib/everest/everest_api_types/include/everest_api_types/energy/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/energy/codec.hpp new file mode 100644 index 0000000000..4f2656e775 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/energy/codec.hpp @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::energy { + +std::string serialize(NumberWithSource const& val) noexcept; +std::string serialize(IntegerWithSource const& val) noexcept; +std::string serialize(FrequencyWattPoint const& val) noexcept; +std::string serialize(SetpointType const& val) noexcept; +std::string serialize(PricePerkWh const& val) noexcept; +std::string serialize(LimitsReq const& val) noexcept; +std::string serialize(LimitsRes const& val) noexcept; +std::string serialize(ScheduleReqEntry const& val) noexcept; +std::string serialize(ScheduleResEntry const& val) noexcept; +std::string serialize(ScheduleSetpointEntry const& val) noexcept; +std::string serialize(ExternalLimits const& val) noexcept; +std::string serialize(EnforcedLimits const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, NumberWithSource const& val); +std::ostream& operator<<(std::ostream& os, IntegerWithSource const& val); +std::ostream& operator<<(std::ostream& os, FrequencyWattPoint const& val); +std::ostream& operator<<(std::ostream& os, SetpointType const& val); +std::ostream& operator<<(std::ostream& os, PricePerkWh const& val); +std::ostream& operator<<(std::ostream& os, LimitsReq const& val); +std::ostream& operator<<(std::ostream& os, LimitsRes const& val); +std::ostream& operator<<(std::ostream& os, ScheduleReqEntry const& val); +std::ostream& operator<<(std::ostream& os, ScheduleResEntry const& val); +std::ostream& operator<<(std::ostream& os, ScheduleSetpointEntry const& val); +std::ostream& operator<<(std::ostream& os, ExternalLimits const& val); +std::ostream& operator<<(std::ostream& os, EnforcedLimits const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::energy diff --git a/lib/everest/everest_api_types/include/everest_api_types/error_history/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/error_history/API.hpp new file mode 100644 index 0000000000..b35c9cf7f7 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/error_history/API.hpp @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once +#include +#include +#include + +namespace everest::lib::API::V1_0::types::error_history { + +enum class State { + Active, + ClearedByModule, + ClearedByReboot, +}; + +enum class SeverityFilter { + HIGH_GE, + MEDIUM_GE, + LOW_GE, +}; + +enum class Severity { + High, + Medium, + Low, +}; + +struct ImplementationIdentifier { + std::string module_id; + std::string implementation_id; +}; + +struct TimeperiodFilter { + std::string timestamp_from; + std::string timestamp_to; +}; + +struct FilterArguments { + std::optional state_filter; + std::optional origin_filter; + std::optional type_filter; + std::optional severity_filter; + std::optional timeperiod_filter; + std::optional handle_filter; +}; + +struct ErrorObject { + std::string type; + std::string description; + std::string message; + Severity severity; + ImplementationIdentifier origin; + std::string timestamp; + std::string uuid; + State state; + std::optional sub_type; +}; + +struct ErrorList { + std::vector errors; +}; + +} // namespace everest::lib::API::V1_0::types::error_history diff --git a/lib/everest/everest_api_types/include/everest_api_types/error_history/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/error_history/codec.hpp new file mode 100644 index 0000000000..4c9fcdd552 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/error_history/codec.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::error_history { + +std::string serialize(State val) noexcept; +std::string serialize(SeverityFilter val) noexcept; +std::string serialize(Severity val) noexcept; +std::string serialize(ImplementationIdentifier const& val) noexcept; +std::string serialize(TimeperiodFilter const& val) noexcept; +std::string serialize(FilterArguments const& val) noexcept; +std::string serialize(ErrorObject const& val) noexcept; +std::string serialize(ErrorList const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, State const& val); +std::ostream& operator<<(std::ostream& os, SeverityFilter const& val); +std::ostream& operator<<(std::ostream& os, Severity const& val); +std::ostream& operator<<(std::ostream& os, ImplementationIdentifier const& val); +std::ostream& operator<<(std::ostream& os, TimeperiodFilter const& val); +std::ostream& operator<<(std::ostream& os, FilterArguments const& val); +std::ostream& operator<<(std::ostream& os, ErrorObject const& val); +std::ostream& operator<<(std::ostream& os, ErrorList const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::error_history diff --git a/lib/everest/everest_api_types/include/everest_api_types/evse_board_support/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/evse_board_support/API.hpp new file mode 100644 index 0000000000..53a99d3845 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/evse_board_support/API.hpp @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include +#include + +namespace everest::lib::API::V1_0::types::evse_board_support { + +enum class Event { + A, + B, + C, + D, + E, + F, + PowerOn, + PowerOff, + EvseReplugStarted, + EvseReplugFinished, + Disconnected, +}; + +struct BspEvent { + Event event; +}; + +enum class ErrorEnum { + DiodeFault, + VentilationNotAvailable, + BrownOut, + EnergyManagement, + PermanentFault, + MREC2GroundFailure, + MREC3HighTemperature, + MREC4OverCurrentFailure, + MREC5OverVoltage, + MREC6UnderVoltage, + MREC8EmergencyStop, + MREC10InvalidVehicleMode, + MREC14PilotFault, + MREC15PowerLoss, + MREC17EVSEContactorFault, + MREC18CableOverTempDerate, + MREC19CableOverTempStop, + MREC20PartialInsertion, + MREC23ProximityFault, + MREC24ConnectorVoltageHigh, + MREC25BrokenLatch, + MREC26CutCable, + ConnectorLockCapNotCharged, + ConnectorLockUnexpectedOpen, + ConnectorLockUnexpectedClose, + ConnectorLockFailedLock, + ConnectorLockFailedUnlock, + MREC1ConnectorLockFailure, + Selftest, + DC, + AC, + VendorError, + VendorWarning, + CommunicationFault +}; + +struct Error { + ErrorEnum type; + std::optional sub_type; + std::optional message; +}; + +enum class Connector_type { + IEC62196Type2Cable, + IEC62196Type2Socket, +}; + +struct HardwareCapabilities { + float max_current_A_import; + float min_current_A_import; + int32_t max_phase_count_import; + int32_t min_phase_count_import; + float max_current_A_export; + float min_current_A_export; + int32_t max_phase_count_export; + int32_t min_phase_count_export; + bool supports_changing_phases_during_charging; + Connector_type connector_type; + std::optional max_plug_temperature_C; +}; + +enum class Reason { + DCCableCheck, + DCPreCharge, + FullPowerCharging, + PowerOff, +}; + +struct PowerOnOff { + bool allow_power_on{false}; + Reason reason{Reason::PowerOff}; +}; + +enum class Ampacity { + None, + A_13, + A_20, + A_32, + A_63_3ph_70_1ph, +}; + +struct ProximityPilot { + Ampacity ampacity; +}; + +} // namespace everest::lib::API::V1_0::types::evse_board_support diff --git a/lib/everest/everest_api_types/include/everest_api_types/evse_board_support/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/evse_board_support/codec.hpp new file mode 100644 index 0000000000..0499ee954a --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/evse_board_support/codec.hpp @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::evse_board_support { + +std::string serialize(Event val) noexcept; +std::string serialize(BspEvent const& val) noexcept; +std::string serialize(ErrorEnum val) noexcept; +std::string serialize(Error const& val) noexcept; +std::string serialize(Connector_type val) noexcept; +std::string serialize(HardwareCapabilities const& val) noexcept; +std::string serialize(Reason val) noexcept; +std::string serialize(PowerOnOff const& val) noexcept; +std::string serialize(Ampacity val) noexcept; +std::string serialize(ProximityPilot const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, Event const& val); +std::ostream& operator<<(std::ostream& os, BspEvent const& val); +std::ostream& operator<<(std::ostream& os, Error const& val); +std::ostream& operator<<(std::ostream& os, ErrorEnum const& val); +std::ostream& operator<<(std::ostream& os, Connector_type const& val); +std::ostream& operator<<(std::ostream& os, HardwareCapabilities const& val); +std::ostream& operator<<(std::ostream& os, Reason const& val); +std::ostream& operator<<(std::ostream& os, PowerOnOff const& val); +std::ostream& operator<<(std::ostream& os, Ampacity const& val); +std::ostream& operator<<(std::ostream& os, ProximityPilot const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::evse_board_support diff --git a/lib/everest/everest_api_types/include/everest_api_types/evse_manager/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/evse_manager/API.hpp new file mode 100644 index 0000000000..5174a9a21e --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/evse_manager/API.hpp @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include +#include +#include + +namespace everest::lib::API::V1_0::types::evse_manager { + +enum class StopTransactionReason { + EmergencyStop, + EVDisconnected, + HardReset, + Local, + Other, + PowerLoss, + Reboot, + Remote, + SoftReset, + UnlockCommand, + DeAuthorized, + EnergyLimitReached, + GroundFault, + LocalOutOfCredit, + MasterPass, + OvercurrentFault, + PowerQuality, + SOCLimitReached, + StoppedByEV, + TimeLimitReached, + Timeout, + ReqEnergyTransferRejected +}; + +struct StopTransactionRequest { + types::evse_manager::StopTransactionReason reason; +}; + +enum class StartSessionReason { + EVConnected, + Authorized, +}; + +enum class SessionEventEnum { + Authorized, + Deauthorized, + Enabled, + Disabled, + SessionStarted, + AuthRequired, + TransactionStarted, + PrepareCharging, + ChargingStarted, + ChargingPausedEV, + ChargingPausedEVSE, + WaitingForEnergy, + ChargingResumed, + StoppingCharging, + ChargingFinished, + TransactionFinished, + SessionFinished, + ReservationStart, + ReservationEnd, + ReplugStarted, + ReplugFinished, + PluginTimeout, + SwitchingPhases, + SessionResumed, +}; + +struct SessionStarted { + StartSessionReason reason; + powermeter::PowermeterValues meter_value; + std::optional signed_meter_value; + std::optional reservation_id; + std::optional logging_path; +}; + +struct SessionFinished { + powermeter::PowermeterValues meter_value; +}; + +struct TransactionStarted { + auth::ProvidedIdToken id_tag; + powermeter::PowermeterValues meter_value; + std::optional signed_meter_value; + std::optional reservation_id; +}; + +struct TransactionFinished { + types::powermeter::PowermeterValues meter_value; + std::optional start_signed_meter_value; + std::optional signed_meter_value; + std::optional reason; +}; + +struct ChargingStateChangedEvent { + powermeter::PowermeterValues meter_value; +}; + +struct AuthorizationEvent { + powermeter::PowermeterValues meter_value; +}; + +enum class ErrorSeverity { + High, + Medium, + Low, +}; + +enum class ErrorState { + Active, + ClearedByModule, + ClearedByReboot +}; + +struct ErrorOrigin { + std::string module_id; + std::string implementation_id; +}; + +struct Error { + std::string type; + std::string sub_type; + + std::string description; + std::string message; + ErrorSeverity severity; + ErrorOrigin origin; + std::string timestamp; + std::string uuid; + ErrorState state; +}; + +struct SessionEvent { + std::string uuid; + std::string timestamp; + types::evse_manager::SessionEventEnum event; + std::optional connector_id; + // FIXME Add remaining optional memebers and their internals + std::optional session_started; + std::optional session_finished; + std::optional transaction_started; + std::optional transaction_finished; + std::optional charging_state_changed_event; + std::optional authorization_event; +}; + +struct Limits { + float max_current; + int32_t nr_of_phases_available; + std::optional uuid; +}; + +struct EVInfo { + std::optional soc; + std::optional present_voltage; + std::optional present_current; + std::optional target_voltage; + std::optional target_current; + std::optional maximum_current_limit; + std::optional minimum_current_limit; + std::optional maximum_voltage_limit; + std::optional maximum_power_limit; + std::optional estimated_time_full; + std::optional departure_time; + std::optional estimated_time_bulk; + std::optional evcc_id; + std::optional remaining_energy_needed; + std::optional battery_capacity; + std::optional battery_full_soc; + std::optional battery_bulk_soc; +}; + +enum class CarManufacturer { + VolkswagenGroup, + Tesla, + Unknown, +}; + +enum class ConnectorTypeEnum { + cCCS1, + cCCS2, + cG105, + cTesla, + cType1, + cType2, + s309_1P_16A, + s309_1P_32A, + s309_3P_16A, + s309_3P_32A, + sBS1361, + sCEE_7_7, + sType2, + sType3, + Other1PhMax16A, + Other1PhOver16A, + Other3Ph, + Pan, + wInductive, + wResonant, + Undetermined, + Unknown, +}; + +struct Connector { + int32_t id; + std::optional type; +}; + +struct Evse { + int32_t id; + std::vector connectors; +}; + +enum class EnableSourceEnum { + Unspecified, + LocalAPI, + LocalKeyLock, + ServiceTechnician, + RemoteKeyLock, + MobileApp, + FirmwareUpdate, + CSMS, +}; + +enum class EnableStateEnum { + Unassigned, + Disable, + Enable, +}; + +struct EnableDisableSource { + EnableSourceEnum enable_source; + EnableStateEnum enable_state; + int32_t enable_priority; +}; + +struct EnableDisableRequest { + int32_t connector_id; + EnableDisableSource source; +}; + +struct AuthorizeResponseArgs { + auth::ProvidedIdToken token; + auth::ValidationResult result; +}; + +struct PlugAndChargeConfiguration { + std::optional pnc_enabled; + std::optional central_contract_validation_allowed; + std::optional contract_certificate_installation_enabled; +}; + +} // namespace everest::lib::API::V1_0::types::evse_manager diff --git a/lib/everest/everest_api_types/include/everest_api_types/evse_manager/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/evse_manager/codec.hpp new file mode 100644 index 0000000000..f128856e37 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/evse_manager/codec.hpp @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::evse_manager { + +std::string serialize(StopTransactionReason val) noexcept; +std::string serialize(StopTransactionRequest const& val) noexcept; +std::string serialize(StartSessionReason val) noexcept; +std::string serialize(SessionEventEnum val) noexcept; +std::string serialize(SessionEvent const& val) noexcept; +std::string serialize(Limits const& val) noexcept; +std::string serialize(EVInfo const& val) noexcept; +std::string serialize(CarManufacturer val) noexcept; +std::string serialize(SessionStarted const& val) noexcept; +std::string serialize(SessionFinished const& val) noexcept; +std::string serialize(TransactionStarted const& val) noexcept; +std::string serialize(TransactionFinished const& val) noexcept; +std::string serialize(ChargingStateChangedEvent const& val) noexcept; +std::string serialize(AuthorizationEvent const& val) noexcept; +std::string serialize(ErrorSeverity val) noexcept; +std::string serialize(ErrorState val) noexcept; +std::string serialize(ErrorOrigin const& val) noexcept; +std::string serialize(Error const& val) noexcept; +std::string serialize(ConnectorTypeEnum const& val) noexcept; +std::string serialize(Connector const& val) noexcept; +std::string serialize(Evse const& val) noexcept; +std::string serialize(EnableSourceEnum const& val) noexcept; +std::string serialize(EnableStateEnum const& val) noexcept; +std::string serialize(EnableDisableSource const& val) noexcept; +std::string serialize(EnableDisableRequest const& val) noexcept; +std::string serialize(AuthorizeResponseArgs const& val) noexcept; +std::string serialize(PlugAndChargeConfiguration const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, StopTransactionReason const& val); +std::ostream& operator<<(std::ostream& os, StopTransactionRequest const& val); +std::ostream& operator<<(std::ostream& os, StartSessionReason const& val); +std::ostream& operator<<(std::ostream& os, SessionEventEnum const& val); +std::ostream& operator<<(std::ostream& os, SessionEvent const& val); +std::ostream& operator<<(std::ostream& os, Limits const& val); +std::ostream& operator<<(std::ostream& os, EVInfo const& val); +std::ostream& operator<<(std::ostream& os, CarManufacturer const& val); +std::ostream& operator<<(std::ostream& os, SessionStarted const& val); +std::ostream& operator<<(std::ostream& os, SessionFinished const& val); +std::ostream& operator<<(std::ostream& os, TransactionStarted const& val); +std::ostream& operator<<(std::ostream& os, TransactionFinished const& val); +std::ostream& operator<<(std::ostream& os, ChargingStateChangedEvent const& val); +std::ostream& operator<<(std::ostream& os, AuthorizationEvent const& val); +std::ostream& operator<<(std::ostream& os, ErrorSeverity const& val); +std::ostream& operator<<(std::ostream& os, ErrorState const& val); +std::ostream& operator<<(std::ostream& os, ErrorOrigin const& val); +std::ostream& operator<<(std::ostream& os, Error const& val); +std::ostream& operator<<(std::ostream& os, ConnectorTypeEnum const& val); +std::ostream& operator<<(std::ostream& os, Connector const& val); +std::ostream& operator<<(std::ostream& os, Evse const& val); +std::ostream& operator<<(std::ostream& os, EnableSourceEnum const& val); +std::ostream& operator<<(std::ostream& os, EnableStateEnum const& val); +std::ostream& operator<<(std::ostream& os, EnableDisableSource const& val); +std::ostream& operator<<(std::ostream& os, EnableDisableRequest const& val); +std::ostream& operator<<(std::ostream& os, AuthorizeResponseArgs const& val); +std::ostream& operator<<(std::ostream& os, PlugAndChargeConfiguration const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) noexcept { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} + +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::evse_manager diff --git a/lib/everest/everest_api_types/include/everest_api_types/generic/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/generic/API.hpp new file mode 100644 index 0000000000..33d7757dbc --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/generic/API.hpp @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::lib::API::V1_0::types::generic { + +enum class ErrorEnum { + CommunicationFault, + VendorError, + VendorWarning +}; + +struct Error { + ErrorEnum type; + std::optional sub_type; + std::optional message; +}; + +struct RequestReply { + std::string replyTo; + std::string payload; +}; + +} // namespace everest::lib::API::V1_0::types::generic diff --git a/lib/everest/everest_api_types/include/everest_api_types/generic/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/generic/codec.hpp new file mode 100644 index 0000000000..378bc7d2cd --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/generic/codec.hpp @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::generic { + +std::string serialize(bool val) noexcept; +std::string serialize(int val) noexcept; +std::string serialize(double val) noexcept; +std::string serialize(float val) noexcept; +std::string serialize(std::string const& val) noexcept; +std::string serialize(RequestReply const& val); +std::string serialize(ErrorEnum val) noexcept; +std::string serialize(Error const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, RequestReply const& val); +std::ostream& operator<<(std::ostream& os, const Error& val); +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::generic diff --git a/lib/everest/everest_api_types/include/everest_api_types/generic/string.hpp b/lib/everest/everest_api_types/include/everest_api_types/generic/string.hpp new file mode 100644 index 0000000000..279e66b831 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/generic/string.hpp @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::lib::API::V1_0::types::generic { + +std::string trimmed(std::string const& str); +std::optional compress_json(std::string data); + +} // namespace everest::lib::API::V1_0::types::generic diff --git a/lib/everest/everest_api_types/include/everest_api_types/iso15118_charger/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/iso15118_charger/API.hpp new file mode 100644 index 0000000000..593072a891 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/iso15118_charger/API.hpp @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::lib::API::V1_0::types::iso15118_charger { + +enum class CertificateActionEnum { + Install, + Update, +}; + +enum class Status { + Accepted, + Failed, +}; + +struct RequestExiStreamSchema { + std::string exi_request; + std::string iso15118_schema_version; + CertificateActionEnum certificate_action; +}; + +struct ResponseExiStreamStatus { + Status status; + CertificateActionEnum certificate_action; + std::optional exi_response; +}; + +} // namespace everest::lib::API::V1_0::types::iso15118_charger diff --git a/lib/everest/everest_api_types/include/everest_api_types/iso15118_charger/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/iso15118_charger/codec.hpp new file mode 100644 index 0000000000..73997961ab --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/iso15118_charger/codec.hpp @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::iso15118_charger { + +std::string serialize(CertificateActionEnum val) noexcept; +std::string serialize(Status val) noexcept; +std::string serialize(RequestExiStreamSchema const& val) noexcept; +std::string serialize(ResponseExiStreamStatus const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, CertificateActionEnum const& val); +std::ostream& operator<<(std::ostream& os, Status const& val); +std::ostream& operator<<(std::ostream& os, RequestExiStreamSchema const& val); +std::ostream& operator<<(std::ostream& os, ResponseExiStreamStatus const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) noexcept { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} + +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::iso15118_charger diff --git a/lib/everest/everest_api_types/include/everest_api_types/isolation_monitor/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/isolation_monitor/API.hpp new file mode 100644 index 0000000000..7d79427b3c --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/isolation_monitor/API.hpp @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::lib::API::V1_0::types::isolation_monitor { + +struct IsolationMeasurement { + float resistance_F_Ohm; + std::optional voltage_V; +}; + +enum class ErrorEnum { + DeviceFault, + CommunicationFault, + VendorError, + VendorWarning +}; + +struct Error { + ErrorEnum type; + std::optional sub_type; + std::optional message; +}; + +} // namespace everest::lib::API::V1_0::types::isolation_monitor diff --git a/lib/everest/everest_api_types/include/everest_api_types/isolation_monitor/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/isolation_monitor/codec.hpp new file mode 100644 index 0000000000..153c549d66 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/isolation_monitor/codec.hpp @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::isolation_monitor { + +std::string serialize(IsolationMeasurement const& val) noexcept; +std::string serialize(ErrorEnum val) noexcept; +std::string serialize(Error const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, IsolationMeasurement const& val); +std::ostream& operator<<(std::ostream& os, const Error& val); +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::isolation_monitor diff --git a/lib/everest/everest_api_types/include/everest_api_types/ocpp/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/ocpp/API.hpp new file mode 100644 index 0000000000..a22d1e5d9e --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/ocpp/API.hpp @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once +#include +#include +#include + +namespace everest::lib::API::V1_0::types::ocpp { + +enum class AttributeEnum { + Actual, + Target, + MinSet, + MaxSet, +}; + +enum class GetVariableStatusEnumType { + Accepted, + Rejected, + UnknownComponent, + UnknownVariable, + NotSupportedAttributeType, +}; + +enum class SetVariableStatusEnumType { + Accepted, + Rejected, + UnknownComponent, + UnknownVariable, + NotSupportedAttributeType, + RebootRequired, +}; + +enum class DataTransferStatus { + Accepted, + Rejected, + UnknownMessageId, + UnknownVendorId, + Offline, +}; + +enum class RegistrationStatus { + Accepted, + Pending, + Rejected, +}; + +enum class TransactionEvent { + Started, + Updated, + Ended, +}; + +struct CustomData { + std::string vendor_id; + std::string data; +}; + +struct DataTransferRequest { + std::string vendor_id; + std::optional message_id; + std::optional data; + std::optional custom_data; +}; + +struct DataTransferResponse { + DataTransferStatus status; + std::optional data; + std::optional custom_data; +}; + +struct EVSE { + int32_t id; + std::optional connector_id; +}; + +struct Component { + std::string name; + std::optional instance; + std::optional evse; +}; + +struct Variable { + std::string name; + std::optional instance; +}; + +struct ComponentVariable { + Component component; + Variable variable; +}; + +struct GetVariableRequest { + ComponentVariable component_variable; + std::optional attribute_type; +}; + +struct GetVariableResult { + GetVariableStatusEnumType status; + ComponentVariable component_variable; + std::optional attribute_type; + std::optional value; +}; + +struct SetVariableRequest { + ComponentVariable component_variable; + std::string value; + std::optional attribute_type; +}; + +struct SetVariableResult { + SetVariableStatusEnumType status; + ComponentVariable component_variable; + std::optional attribute_type; +}; + +struct GetVariableRequestList { + std::vector items; +}; + +struct GetVariableResultList { + std::vector items; +}; + +struct SetVariableRequestList { + std::vector items; +}; + +struct SetVariableResultList { + std::vector items; +}; + +struct SetVariablesArgs { + SetVariableRequestList variables; + std::string source; +}; + +struct SecurityEvent { + std::string type; + std::optional info; +}; + +struct StatusInfoType { + std::string reason_code; + std::optional additional_info; +}; + +struct BootNotificationResponse { + RegistrationStatus status; + std::string current_time; + int32_t interval; + std::optional status_info; +}; + +struct OcppTransactionEvent { + TransactionEvent transaction_event; + std::string session_id; + std::optional evse; + std::optional transaction_id; +}; + +} // namespace everest::lib::API::V1_0::types::ocpp diff --git a/lib/everest/everest_api_types/include/everest_api_types/ocpp/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/ocpp/codec.hpp new file mode 100644 index 0000000000..422191320a --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/ocpp/codec.hpp @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::ocpp { + +std::string serialize(AttributeEnum val) noexcept; +std::string serialize(GetVariableStatusEnumType val) noexcept; +std::string serialize(SetVariableStatusEnumType val) noexcept; +std::string serialize(DataTransferStatus val) noexcept; +std::string serialize(RegistrationStatus val) noexcept; +std::string serialize(TransactionEvent val) noexcept; +std::string serialize(CustomData const& val) noexcept; +std::string serialize(DataTransferRequest const& val) noexcept; +std::string serialize(DataTransferResponse const& val) noexcept; +std::string serialize(EVSE const& val) noexcept; +std::string serialize(Component const& val) noexcept; +std::string serialize(Variable const& val) noexcept; +std::string serialize(ComponentVariable const& val) noexcept; +std::string serialize(GetVariableRequest const& val) noexcept; +std::string serialize(GetVariableResult const& val) noexcept; +std::string serialize(SetVariableRequest const& val) noexcept; +std::string serialize(SetVariableResult const& val) noexcept; +std::string serialize(GetVariableRequestList const& val) noexcept; +std::string serialize(GetVariableResultList const& val) noexcept; +std::string serialize(SetVariableRequestList const& val) noexcept; +std::string serialize(SetVariableResultList const& val) noexcept; +std::string serialize(SetVariablesArgs const& val) noexcept; +std::string serialize(SecurityEvent const& val) noexcept; +std::string serialize(StatusInfoType const& val) noexcept; +std::string serialize(BootNotificationResponse const& val) noexcept; +std::string serialize(OcppTransactionEvent const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, AttributeEnum const& val); +std::ostream& operator<<(std::ostream& os, GetVariableStatusEnumType const& val); +std::ostream& operator<<(std::ostream& os, SetVariableStatusEnumType const& val); +std::ostream& operator<<(std::ostream& os, DataTransferStatus const& val); +std::ostream& operator<<(std::ostream& os, RegistrationStatus const& val); +std::ostream& operator<<(std::ostream& os, TransactionEvent const& val); +std::ostream& operator<<(std::ostream& os, CustomData const& val); +std::ostream& operator<<(std::ostream& os, DataTransferRequest const& val); +std::ostream& operator<<(std::ostream& os, DataTransferResponse const& val); +std::ostream& operator<<(std::ostream& os, EVSE const& val); +std::ostream& operator<<(std::ostream& os, Component const& val); +std::ostream& operator<<(std::ostream& os, Variable const& val); +std::ostream& operator<<(std::ostream& os, ComponentVariable const& val); +std::ostream& operator<<(std::ostream& os, GetVariableRequest const& val); +std::ostream& operator<<(std::ostream& os, GetVariableResult const& val); +std::ostream& operator<<(std::ostream& os, SetVariableRequest const& val); +std::ostream& operator<<(std::ostream& os, SetVariableResult const& val); +std::ostream& operator<<(std::ostream& os, GetVariableRequestList const& val); +std::ostream& operator<<(std::ostream& os, GetVariableResultList const& val); +std::ostream& operator<<(std::ostream& os, SetVariableRequestList const& val); +std::ostream& operator<<(std::ostream& os, SetVariableResultList const& val); +std::ostream& operator<<(std::ostream& os, SetVariablesArgs const& val); +std::ostream& operator<<(std::ostream& os, SecurityEvent const& val); +std::ostream& operator<<(std::ostream& os, StatusInfoType const& val); +std::ostream& operator<<(std::ostream& os, BootNotificationResponse const& val); +std::ostream& operator<<(std::ostream& os, OcppTransactionEvent const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::ocpp diff --git a/lib/everest/everest_api_types/include/everest_api_types/over_voltage_monitor/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/over_voltage_monitor/API.hpp new file mode 100644 index 0000000000..f44fe36cc3 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/over_voltage_monitor/API.hpp @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::lib::API::V1_0::types::over_voltage_monitor { + +enum class ErrorEnum { + MREC5OverVoltage, + DeviceFault, + CommunicationFault, + VendorError, + VendorWarning +}; + +struct Error { + ErrorEnum type; + std::optional sub_type; + std::optional message; +}; + +} // namespace everest::lib::API::V1_0::types::over_voltage_monitor diff --git a/lib/everest/everest_api_types/include/everest_api_types/over_voltage_monitor/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/over_voltage_monitor/codec.hpp new file mode 100644 index 0000000000..1e8f4cb309 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/over_voltage_monitor/codec.hpp @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include +#include + +namespace everest::lib::API::V1_0::types::over_voltage_monitor { + +std::string serialize(ErrorEnum val) noexcept; +std::string serialize(Error const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, const Error& val); +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::over_voltage_monitor diff --git a/lib/everest/everest_api_types/include/everest_api_types/power_supply_DC/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/power_supply_DC/API.hpp new file mode 100644 index 0000000000..e80edbeedc --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/power_supply_DC/API.hpp @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::lib::API::V1_0::types::power_supply_DC { + +struct Capabilities { + bool bidirectional; + float current_regulation_tolerance_A; + float peak_current_ripple_A; + float max_export_voltage_V; + float min_export_voltage_V; + float max_export_current_A; + float min_export_current_A; + float max_export_power_W; + std::optional max_import_voltage_V; + std::optional min_import_voltage_V; + std::optional max_import_current_A; + std::optional min_import_current_A; + std::optional max_import_power_W; + std::optional conversion_efficiency_import; + std::optional conversion_efficiency_export; +}; + +enum class Mode { + Off, + Export, + Import, + Fault, +}; + +enum class ChargingPhase { + Other, + CableCheck, + PreCharge, + Charging, +}; + +struct ModeRequest { + Mode mode; + ChargingPhase charging_phase; +}; + +struct VoltageCurrent { + float voltage_V; ///< Voltage in V + float current_A; ///< Current in A +}; + +enum class ErrorEnum { + CommunicationFault, + HardwareFault, + OverTemperature, + UnderTemperature, + UnderVoltageAC, + OverVoltageAC, + UnderVoltageDC, + OverVoltageDC, + OverCurrentAC, + OverCurrentDC, + VendorError, + VendorWarning +}; + +struct Error { + ErrorEnum type; + std::optional sub_type; + std::optional message; +}; + +} // namespace everest::lib::API::V1_0::types::power_supply_DC diff --git a/lib/everest/everest_api_types/include/everest_api_types/power_supply_DC/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/power_supply_DC/codec.hpp new file mode 100644 index 0000000000..6617f84d20 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/power_supply_DC/codec.hpp @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include +#include + +namespace everest::lib::API::V1_0::types::power_supply_DC { + +std::string serialize(Capabilities const& val) noexcept; +std::string serialize(Mode val) noexcept; +std::string serialize(ModeRequest val) noexcept; +std::string serialize(ChargingPhase val) noexcept; +std::string serialize(VoltageCurrent const& val) noexcept; +std::string serialize(ErrorEnum val) noexcept; +std::string serialize(Error const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, const Capabilities& val); +std::ostream& operator<<(std::ostream& os, const Mode& val); +std::ostream& operator<<(std::ostream& os, const ChargingPhase& val); +std::ostream& operator<<(std::ostream& os, const ModeRequest& val); +std::ostream& operator<<(std::ostream& os, const VoltageCurrent& val); +std::ostream& operator<<(std::ostream& os, const Error& val); +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::power_supply_DC diff --git a/lib/everest/everest_api_types/include/everest_api_types/powermeter/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/powermeter/API.hpp new file mode 100644 index 0000000000..48de19a5df --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/powermeter/API.hpp @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once +#include +#include +#include + +namespace everest::lib::API::V1_0::types::powermeter { + +enum class OCMFUserIdentificationStatus { + ASSIGNED, + NOT_ASSIGNED, +}; + +enum class OCMFIdentificationFlags { + RFID_NONE, + RFID_PLAIN, + RFID_RELATED, + RFID_PSK, + OCPP_NONE, + OCPP_RS, + OCPP_AUTH, + OCPP_RS_TLS, + OCPP_AUTH_TLS, + OCPP_CACHE, + OCPP_WHITELIST, + OCPP_CERTIFIED, + ISO15118_NONE, + ISO15118_PNC, + PLMN_NONE, + PLMN_RING, + PLMN_SMS, +}; + +enum class OCMFIdentificationType { + NONE, + DENIED, + UNDEFINED, + ISO14443, + ISO15693, + EMAID, + EVCCID, + EVCOID, + ISO7812, + CARD_TXN_NR, + CENTRAL, + CENTRAL_1, + CENTRAL_2, + LOCAL, + LOCAL_1, + LOCAL_2, + PHONE_NUMBER, + KEY_CODE, +}; + +enum class OCMFIdentificationLevel { + NONE, + HEARSAY, + TRUSTED, + VERIFIED, + CERTIFIED, + SECURE, + MISMATCH, + INVALID, + OUTDATED, + UNKNOWN, +}; + +enum class TransactionStatus { + OK, + NOT_SUPPORTED, + UNEXPECTED_ERROR, +}; + +struct Current { + std::optional DC; ///< DC current + std::optional L1; ///< AC L1 value only + std::optional L2; ///< AC L2 value only + std::optional L3; ///< AC L3 value only + std::optional N; ///< AC Neutral value only +}; + +struct Voltage { + std::optional DC; ///< DC voltage + std::optional L1; ///< AC L1 value only + std::optional L2; ///< AC L2 value only + std::optional L3; ///< AC L3 value only +}; + +struct Frequency { + float L1; ///< AC L1 value + std::optional L2; ///< AC L2 value + std::optional L3; ///< AC L3 value +}; + +struct Power { + float total; ///< DC / AC Sum value + std::optional L1; ///< AC L1 value only + std::optional L2; ///< AC L2 value only + std::optional L3; ///< AC L3 value only +}; + +struct Energy { + float total; ///< DC / AC Sum value (which is relevant for billing) + std::optional L1; ///< AC L1 value only + std::optional L2; ///< AC L2 value only + std::optional L3; ///< AC L3 value only +}; + +struct ReactivePower { + float total; ///< VAR total + std::optional L1; ///< VAR phase A + std::optional L2; ///< VAR phase B + std::optional L3; ///< VAR phase C +}; + +struct SignedMeterValue { + std::string signed_meter_data; ///< Signed meter data (encoded in a string representation with eg. Base64) + std::string signing_method; ///< Method used to create the signature + std::string encoding_method; ///< Method used to encode the meter values before signing them + std::optional public_key; ///< Public key (encoded in a string representation with eg. Base64) + std::optional timestamp; ///< Timestamp of measurement +}; + +struct SignedCurrent { + std::optional DC; ///< DC current + std::optional L1; ///< AC L1 value only + std::optional L2; ///< AC L2 value only + std::optional L3; ///< AC L3 value only + std::optional N; ///< AC Neutral value only +}; + +struct SignedVoltage { + std::optional DC; ///< DC voltage + std::optional L1; ///< AC L1 value only + std::optional L2; ///< AC L2 value only + std::optional L3; ///< AC L3 value only +}; + +struct SignedFrequency { + std::optional L1; ///< AC L1 value + std::optional L2; ///< AC L2 value + std::optional L3; ///< AC L3 value +}; + +struct SignedPower { + std::optional total; ///< DC / AC Sum value + std::optional L1; ///< AC L1 value only + std::optional L2; ///< AC L2 value only + std::optional L3; ///< AC L3 value only +}; + +struct SignedEnergy { + std::optional total; ///< DC / AC Sum value (which is relevant for billing) + std::optional L1; ///< AC L1 value only + std::optional L2; ///< AC L2 value only + std::optional L3; ///< AC L3 value only +}; + +struct SignedReactivePower { + std::optional total; ///< VAR total + std::optional L1; ///< VAR phase A + std::optional L2; ///< VAR phase B + std::optional L3; ///< VAR phase C +}; + +struct Temperature { + float temperature; + std::optional identification; +}; + +struct PowermeterValues { + std::string timestamp; + Energy energy_Wh_import; + std::optional meter_id; + std::optional phase_seq_error; + std::optional energy_Wh_export; + std::optional power_W; + std::optional voltage_V; + std::optional VAR; + std::optional current_A; + std::optional frequency_Hz; + std::optional energy_Wh_import_signed; + std::optional energy_Wh_export_signed; + std::optional power_W_signed; + std::optional voltage_V_signed; + std::optional VAR_signed; + std::optional current_A_signed; + std::optional frequency_Hz_signed; + std::optional signed_meter_value; + std::optional> temperatures; +}; + +struct ReplyStartTransaction { + TransactionStatus status; + std::optional error; + std::optional transaction_min_stop_time; + std::optional transaction_max_stop_time; +}; + +struct ReplyStopTransaction { + TransactionStatus status; + std::optional signed_meter_value; + std::optional error; +}; + +struct RequestStartTransaction { + std::string evse_id; + std::string transaction_id; + OCMFUserIdentificationStatus identification_status; + std::vector identification_flags; + OCMFIdentificationType identification_type; + std::optional identification_level; + std::optional identification_data; + std::optional tariff_text; +}; + +} // namespace everest::lib::API::V1_0::types::powermeter diff --git a/lib/everest/everest_api_types/include/everest_api_types/powermeter/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/powermeter/codec.hpp new file mode 100644 index 0000000000..6d5ebfec78 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/powermeter/codec.hpp @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::powermeter { + +std::string serialize(OCMFUserIdentificationStatus val) noexcept; +std::string serialize(OCMFIdentificationFlags val) noexcept; +std::string serialize(OCMFIdentificationType val) noexcept; +std::string serialize(OCMFIdentificationLevel val) noexcept; +std::string serialize(Current const& val) noexcept; +std::string serialize(Voltage const& val) noexcept; +std::string serialize(Frequency const& val) noexcept; +std::string serialize(Power const& val) noexcept; +std::string serialize(Energy const& val) noexcept; +std::string serialize(ReactivePower const& val) noexcept; +std::string serialize(SignedMeterValue const& val) noexcept; +std::string serialize(SignedCurrent const& val) noexcept; +std::string serialize(SignedVoltage const& val) noexcept; +std::string serialize(SignedFrequency const& val) noexcept; +std::string serialize(SignedPower const& val) noexcept; +std::string serialize(SignedEnergy const& val) noexcept; +std::string serialize(SignedReactivePower const& val) noexcept; +std::string serialize(Temperature const& val) noexcept; +std::string serialize(PowermeterValues const& val) noexcept; +std::string serialize(TransactionStatus val) noexcept; +std::string serialize(ReplyStartTransaction const& val) noexcept; +std::string serialize(ReplyStopTransaction const& val) noexcept; +std::string serialize(RequestStartTransaction const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, OCMFUserIdentificationStatus const& val); +std::ostream& operator<<(std::ostream& os, OCMFIdentificationFlags const& val); +std::ostream& operator<<(std::ostream& os, OCMFIdentificationType const& val); +std::ostream& operator<<(std::ostream& os, OCMFIdentificationLevel const& val); +std::ostream& operator<<(std::ostream& os, Current const& val); +std::ostream& operator<<(std::ostream& os, Voltage const& val); +std::ostream& operator<<(std::ostream& os, Frequency const& val); +std::ostream& operator<<(std::ostream& os, Power const& val); +std::ostream& operator<<(std::ostream& os, Energy const& val); +std::ostream& operator<<(std::ostream& os, ReactivePower const& val); +std::ostream& operator<<(std::ostream& os, SignedMeterValue const& val); +std::ostream& operator<<(std::ostream& os, SignedCurrent const& val); +std::ostream& operator<<(std::ostream& os, SignedVoltage const& val); +std::ostream& operator<<(std::ostream& os, SignedFrequency const& val); +std::ostream& operator<<(std::ostream& os, SignedPower const& val); +std::ostream& operator<<(std::ostream& os, SignedEnergy const& val); +std::ostream& operator<<(std::ostream& os, SignedReactivePower const& val); +std::ostream& operator<<(std::ostream& os, Temperature const& val); +std::ostream& operator<<(std::ostream& os, PowermeterValues const& val); +std::ostream& operator<<(std::ostream& os, TransactionStatus const& val); +std::ostream& operator<<(std::ostream& os, ReplyStartTransaction const& val); +std::ostream& operator<<(std::ostream& os, ReplyStopTransaction const& val); +std::ostream& operator<<(std::ostream& os, RequestStartTransaction const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) noexcept { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::powermeter diff --git a/lib/everest/everest_api_types/include/everest_api_types/slac/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/slac/API.hpp new file mode 100644 index 0000000000..2bac484d3d --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/slac/API.hpp @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +namespace everest::lib::API::V1_0::types::slac { + +enum class State { + UNMATCHED, + MATCHING, + MATCHED, +}; + +} // namespace everest::lib::API::V1_0::types::slac diff --git a/lib/everest/everest_api_types/include/everest_api_types/slac/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/slac/codec.hpp new file mode 100644 index 0000000000..17e5e4bdb3 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/slac/codec.hpp @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::slac { + +std::string serialize(State val) noexcept; + +std::ostream& operator<<(std::ostream& os, State const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) noexcept { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} + +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::slac diff --git a/lib/everest/everest_api_types/include/everest_api_types/system/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/system/API.hpp new file mode 100644 index 0000000000..7d710fe590 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/system/API.hpp @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::lib::API::V1_0::types::system { + +enum class UpdateFirmwareResponse { + Accepted, + Rejected, + AcceptedCanceled, + InvalidCertificate, + RevokedCertificate, +}; + +enum class UploadLogsStatus { + Accepted, + Rejected, + AcceptedCanceled, +}; + +enum class LogStatusEnum { + BadMessage, + Idle, + NotSupportedOperation, + PermissionDenied, + Uploaded, + UploadFailure, + Uploading, + AcceptedCanceled, +}; + +enum class FirmwareUpdateStatusEnum { + Downloaded, + DownloadFailed, + Downloading, + DownloadScheduled, + DownloadPaused, + Idle, + InstallationFailed, + Installing, + Installed, + InstallRebooting, + InstallScheduled, + InstallVerificationFailed, + InvalidSignature, + SignatureVerified, +}; + +enum class ResetType { + Soft, + Hard, + NotSpecified, +}; + +enum class BootReason { + ApplicationReset, + FirmwareUpdate, + LocalReset, + PowerUp, + RemoteReset, + ScheduledReset, + Triggered, + Unknown, + Watchdog, +}; + +struct FirmwareUpdateRequest { + int32_t request_id; + std::string location; + std::optional retries; + std::optional retry_interval_s; + std::optional retrieve_timestamp; + std::optional install_timestamp; + std::optional signing_certificate; + std::optional signature; +}; + +struct UploadLogsRequest { + std::string location; + std::optional retries; + std::optional retry_interval_s; + std::optional oldest_timestamp; + std::optional latest_timestamp; + std::optional type; + std::optional request_id; +}; + +struct UploadLogsResponse { + UploadLogsStatus upload_logs_status; + std::optional file_name; +}; + +struct LogStatus { + LogStatusEnum log_status; + int32_t request_id; +}; + +struct FirmwareUpdateStatus { + FirmwareUpdateStatusEnum firmware_update_status; + int32_t request_id; +}; + +struct ResetRequest { + ResetType type; + bool scheduled; +}; + +} // namespace everest::lib::API::V1_0::types::system diff --git a/lib/everest/everest_api_types/include/everest_api_types/system/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/system/codec.hpp new file mode 100644 index 0000000000..aeb9bd2d65 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/system/codec.hpp @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::system { + +std::string serialize(UpdateFirmwareResponse val) noexcept; +std::string serialize(UploadLogsStatus val) noexcept; +std::string serialize(LogStatusEnum val) noexcept; +std::string serialize(FirmwareUpdateStatusEnum val) noexcept; +std::string serialize(ResetType val) noexcept; +std::string serialize(BootReason val) noexcept; +std::string serialize(FirmwareUpdateRequest const& val) noexcept; +std::string serialize(UploadLogsRequest const& val) noexcept; +std::string serialize(UploadLogsResponse const& val) noexcept; +std::string serialize(LogStatus const& val) noexcept; +std::string serialize(FirmwareUpdateStatus const& val) noexcept; +std::string serialize(ResetRequest const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, UpdateFirmwareResponse const& val); +std::ostream& operator<<(std::ostream& os, UploadLogsStatus const& val); +std::ostream& operator<<(std::ostream& os, LogStatusEnum const& val); +std::ostream& operator<<(std::ostream& os, FirmwareUpdateStatusEnum const& val); +std::ostream& operator<<(std::ostream& os, ResetType const& val); +std::ostream& operator<<(std::ostream& os, BootReason const& val); +std::ostream& operator<<(std::ostream& os, FirmwareUpdateRequest const& val); +std::ostream& operator<<(std::ostream& os, UploadLogsRequest const& val); +std::ostream& operator<<(std::ostream& os, LogStatus const& val); +std::ostream& operator<<(std::ostream& os, FirmwareUpdateStatus const& val); +std::ostream& operator<<(std::ostream& os, UploadLogsResponse const& val); +std::ostream& operator<<(std::ostream& os, ResetRequest const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::system diff --git a/lib/everest/everest_api_types/include/everest_api_types/uk_random_delay/API.hpp b/lib/everest/everest_api_types/include/everest_api_types/uk_random_delay/API.hpp new file mode 100644 index 0000000000..10ec44ee47 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/uk_random_delay/API.hpp @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::lib::API::V1_0::types::uk_random_delay { + +struct CountDown { + int32_t countdown_s; + float current_limit_after_delay_A; + float current_limit_during_delay_A; + std::optional start_time; +}; + +} // namespace everest::lib::API::V1_0::types::uk_random_delay diff --git a/lib/everest/everest_api_types/include/everest_api_types/uk_random_delay/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/uk_random_delay/codec.hpp new file mode 100644 index 0000000000..8419c17c20 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/uk_random_delay/codec.hpp @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest +#pragma once + +#include "API.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::uk_random_delay { + +std::string serialize(CountDown const& val) noexcept; + +std::ostream& operator<<(std::ostream& os, CountDown const& val); + +template T deserialize(std::string const& val); +template std::optional try_deserialize(std::string const& val) { + try { + return deserialize(val); + } catch (...) { + return std::nullopt; + } +} +template bool adl_deserialize(std::string const& json_data, T& obj) { + auto opt = try_deserialize(json_data); + if (opt) { + obj = opt.value(); + return true; + } + return false; +} + +} // namespace everest::lib::API::V1_0::types::uk_random_delay diff --git a/lib/everest/everest_api_types/include/everest_api_types/utilities/AsyncApiRequestReply.hpp b/lib/everest/everest_api_types/include/everest_api_types/utilities/AsyncApiRequestReply.hpp new file mode 100644 index 0000000000..ab3f9c386e --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/utilities/AsyncApiRequestReply.hpp @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace everest::lib::companion { + +namespace internal { +template T toInternalApi(T x) { + return x; +} +static const auto empty_payload = json(); +} // namespace internal + +using namespace std::chrono_literals; + +template class AsyncApiRequestReply { +public: + AsyncApiRequestReply(Everest::MqttProvider& mqtt_, Topics const& topic_generator_, + std::chrono::seconds timeout_ = 5s) : + mqtt(mqtt_), topic_generator(topic_generator_), timeout(timeout_) { + } + std::optional create(std::string const& topic_id, json payload = json()) { + using namespace std::literals::chrono_literals; + using weak_promise = std::weak_ptr>; + auto reply_topic = topic_generator.reply_to_everest(boost::uuids::to_string(uuid_create())); + auto value_prom = std::make_shared>(); + auto value_fut = value_prom->get_future(); + auto unsubscribe = + mqtt.subscribe(reply_topic, [value_prom = weak_promise(value_prom)](const auto& raw_data) mutable { + try { + auto shared = value_prom.lock(); + if (shared) { + auto data = json::parse(raw_data); + shared->set_value(data); + } else { + EVLOG_info << "Request expired before arrival of response!\n\n" << raw_data; + } + + } catch (std::exception const& e) { + EVLOG_info << "Could not parse: Exception!\n" << e.what() << "\n\n" << raw_data; + } catch (...) { + EVLOG_info << "Could not parse: Reply with valid data!\n\n" << raw_data; + } + }); + json req; + req["headers"]["replyTo"] = reply_topic; + if (not payload.empty()) { + req["payload"] = payload; + } + mqtt.publish(topic_generator.everest_to_extern(topic_id), req.dump()); + + std::optional result = std::nullopt; + if (value_fut.wait_for(timeout) == std::future_status::ready) { + result = value_fut.get(); + } + unsubscribe(); + return result; + } + +private: + Everest::MqttProvider& mqtt; + Topics const& topic_generator; + std::chrono::seconds timeout; + boost::uuids::random_generator uuid_create; +}; + +template +auto request_reply_handler(Everest::MqttProvider& mqtt, Topics const& topic_generator, ReqT const& request, + std::string const& topic, int timeout_s) { + using namespace internal; + using ResultT = std::optional()))>; + ResultT result = std::nullopt; + auto timeout = timeout_s < 1 ? std::chrono::seconds(999999) : std::chrono::seconds(timeout_s); + AsyncApiRequestReply requestReply(mqtt, topic_generator, timeout); + auto reply = requestReply.create(topic, request); + if (reply) { + result.emplace(toInternalApi(reply.value())); + } else { + EVLOG_warning << "topic: '" << topic + "' -> Reply to requested topic" << std::endl; + } + return result; +} + +template +auto request_reply_handler(Everest::MqttProvider& mqtt, Topics const& topic_generator, std::string const& topic, + int timeout_s) { + return request_reply_handler(mqtt, topic_generator, internal::empty_payload, topic, timeout_s); +} + +} // namespace everest::lib::companion diff --git a/lib/everest/everest_api_types/include/everest_api_types/utilities/CommCheckHandler.hpp b/lib/everest/everest_api_types/include/everest_api_types/utilities/CommCheckHandler.hpp new file mode 100644 index 0000000000..6aa2ddbeca --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/utilities/CommCheckHandler.hpp @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "VarContainer.hpp" +#include "everest/logging.hpp" +#include +#include +#include +#include +#include + +namespace everest::lib::API { + +template class CommCheckHandler { +public: + using ErrorClearFtor = std::function; + using ErrorRaiseFtor = std::function; + using ErrorCheckFtor = std::function; + using HeartBeatFtor = std::function; + CommCheckHandler(std::string const& error_type_, std::string const& default_sub_type_, + std::shared_ptr const& interface) : + error_type(error_type_), default_sub_type(default_sub_type_) { + raise_error = [this, interface](std::string const& sub_type) { + const std::string message{"Send communication_check to clear the error"}; + auto error = + interface->error_factory->create_error(error_type, sub_type, message, Everest::error::Severity::High); + try { + return interface->raise_error(error); + } catch (...) { + } + }; + clear_error = [this, interface]() { + try { + if (interface->error_state_monitor->is_error_active(error_type, default_sub_type)) { + interface->clear_error(error_type, default_sub_type); + } + if (interface->error_state_monitor->is_error_active(error_type, init_sub_type)) { + interface->clear_error(error_type, init_sub_type); + } + } catch (...) { + EVLOG_info << "Failed to clear error: " << error_type; + } + }; + check_error = [this, interface]() { + return interface->error_state_monitor->is_error_active(error_type, default_sub_type) || + interface->error_state_monitor->is_error_active(error_type, init_sub_type); + }; + } + + ~CommCheckHandler() { + check_active.store(false); + } + + void set_value(bool value) { + comm_check_value.set(value); + } + + void set_error() { + if (check_active.load()) { + raise_error(default_sub_type); + } + } + + void start(int timeout_s) { + timeout = std::chrono::seconds(timeout_s); + if (timeout_s < 1) { + EVLOG_info << "No communication checks" << std::endl; + check_active.store(false); + } else { + handler = std::thread([this]() { this->communication_check_handler(); }); + } + } + + bool heartbeat(int interval_ms, HeartBeatFtor const& ftor) { + if (interval_ms <= 0) { + return false; + } + auto interval = std::chrono::milliseconds(interval_ms); + heartbeat_active.store(true); + auto action = [this, interval, ftor]() { + while (heartbeat_active.load()) { + auto now = std::chrono::steady_clock::now(); + auto result = ftor(); + if (not result) { + heartbeat_active.store(false); + break; + } + std::this_thread::sleep_until(now + interval); + } + }; + heartbeat_handler = std::thread(action); + return true; + } + +private: + void communication_check_handler() { + raise_error(init_sub_type); + while (check_active.load()) { + auto check = comm_check_value.wait_for(timeout); + if (check.has_value()) { + check_active.store(check.value()); + if (check_error()) { + EVLOG_info << "Communication check: SUCCESS " << std::endl; + clear_error(); + } + } else { + if (!check_error()) { + EVLOG_info << "Communication check: FAILURE " << std::endl; + raise_error(default_sub_type); + } + } + } + } + + std::chrono::seconds timeout; + ErrorRaiseFtor raise_error; + ErrorClearFtor clear_error; + ErrorCheckFtor check_error; + VarContainer comm_check_value; + std::thread handler; + std::thread heartbeat_handler; + std::atomic_bool check_active{true}; + std::atomic_bool heartbeat_active{false}; + const std::string error_type; + const std::string init_sub_type{"Initial communication check"}; + const std::string default_sub_type; +}; + +} // namespace everest::lib::API diff --git a/lib/everest/everest_api_types/include/everest_api_types/utilities/Topics.hpp b/lib/everest/everest_api_types/include/everest_api_types/utilities/Topics.hpp new file mode 100644 index 0000000000..644aef256e --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/utilities/Topics.hpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once +#include +#include + +namespace everest::lib::API { + +class Topics { +public: + Topics() = default; + Topics(const std::string& target_module_id); + + void setTargetApiModuleID(const std::string& target_moduel_id, const std::string& api_type); + + std::string everest_to_extern(const std::string& var) const; + std::string extern_to_everest(const std::string& var) const; + std::string reply_to_everest(const std::string& reply) const; + + static std::string cloud_connector(const std::string_view& var); + + static const std::string api_base; + static const std::string api_version; + static const std::string api_out; + static const std::string api_in; + static const std::string cloud_base; + +private: + std::string target_module_id; + std::string api_type; +}; + +} // namespace everest::lib::API diff --git a/lib/everest/everest_api_types/include/everest_api_types/utilities/VarContainer.hpp b/lib/everest/everest_api_types/include/everest_api_types/utilities/VarContainer.hpp new file mode 100644 index 0000000000..c290551e7f --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/utilities/VarContainer.hpp @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#ifndef VARCONTAINER_HPP +#define VARCONTAINER_HPP + +#include +#include +#include +#include + +namespace everest::lib::API { + +/* @brief VarContainer provides thread safe synchronisation and caching for the wrapped type. + * + * @details + * It is desinged for two distinct use cases: + * - Single producer / single consumer pattern with queue size of one + * - Asynchronious production of a cached value, which can be read without delay. + * + * @tpatem T Type to be wrapped. Requirements: default constructable, assignable + */ +template class VarContainer { +public: + /** + * @brief Producer interface. + * @details Sets the value for wrapped type @p T. Set flags for + * - new available data, + * - data cached to + * the consumer side. + * @param[in] value New Value + */ + void set(const T& value) { + { + std::scoped_lock lock(data_mutex); + data = value; + unread_data = true; + cached_data = true; + } + condvar.notify_one(); + } + + /** + * @brief Clear wrapper status. + * @details Clears all flags. After calling this function cached data is no longer available. Call @ref "set" to + * make data available again. + */ + void clear() { + std::scoped_lock lock(data_mutex); + unread_data = false; + cached_data = false; + }; + + /** + * @brief Waits for a new value. + * @details Waits until @p timeout for a new value to be set. Returns as soon as new data is available. + * @param[in] d If new data is available, it is written to @p d. In case of a timeout @p d is unchanged. + * @param[in] timeout Maximum time to for a new data. + * @return Returns @a true if new data was written to @p d. @a otherwise. + */ + template bool wait_for(T& d, const std::chrono::duration& timeout) { + std::unique_lock lock(data_mutex); + auto result = cond_wait_impl(lock, timeout); + if (result) { + d = data; + } + return result; + } + + /** + * @brief Waits for a new value. + * @details Waits until @p timeout for a new value to be set. Returns as soon as new data is available. + * @param[in] timeout Maximum time to for a new data. + * @return The @p std::optional holds the new data. It is empty in case of timeout. + */ + template std::optional wait_for(const std::chrono::duration& timeout) { + std::unique_lock lock(data_mutex); + if (cond_wait_impl(lock, timeout)) { + return data; + } + return {}; + } + + /** + * @brief Access cached data or wait for a new value. + * @details If available return cached data immediately. If no cached data is available, it waits until @p timeout + * for a new value to be set. + * @param[in] timeout Maximum time to for a new data. + * @return The @p std::optional holds the new data. It is empty in case of timeout. + */ + template + std::optional cached_or_wait_for(const std::chrono::duration& timeout) { + std::unique_lock lock(data_mutex); + if (cached_data) { + return data; + } else if (cond_wait_impl(lock, timeout)) { + return data; + } + return {}; + } + +private: + template + bool cond_wait_impl(std::unique_lock& lock, const std::chrono::duration& timeout) { + if (condvar.wait_for(lock, timeout, [this] { return unread_data; })) { + // wait_for did NOT timeout + unread_data = false; + return true; + } + return false; + } + + T data; + std::condition_variable condvar; + std::mutex data_mutex; + bool unread_data{false}; + bool cached_data{false}; +}; +} // namespace everest::lib::API +#endif diff --git a/lib/everest/everest_api_types/include/everest_api_types/utilities/codec.hpp b/lib/everest/everest_api_types/include/everest_api_types/utilities/codec.hpp new file mode 100644 index 0000000000..6f8b0ca085 --- /dev/null +++ b/lib/everest/everest_api_types/include/everest_api_types/utilities/codec.hpp @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include + +namespace everest::lib::API { + +template bool deserialize(std::string const& json_data, T& obj) { + return adl_deserialize(json_data, obj); +} + +template <> bool deserialize(std::string const& data, bool& obj); +template <> bool deserialize(std::string const& data, int& obj); +template <> bool deserialize(std::string const& data, double& obj); +template <> bool deserialize(std::string const& data, float& obj); +template <> bool deserialize(std::string const& data, std::string& obj); + +} // namespace everest::lib::API diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/auth/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/auth/json_codec.hpp new file mode 100644 index 0000000000..2dd990b40d --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/auth/json_codec.hpp @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::auth { + +using json = nlohmann::json; + +void to_json(json& j, AuthorizationStatus const& k) noexcept; +void from_json(const json& j, AuthorizationStatus& k); + +void to_json(json& j, CertificateStatus const& k) noexcept; +void from_json(const json& j, CertificateStatus& k); + +void to_json(json& j, TokenValidationStatus const& k) noexcept; +void from_json(const json& j, TokenValidationStatus& k); + +void to_json(json& j, SelectionAlgorithm const& k) noexcept; +void from_json(const json& j, SelectionAlgorithm& k); + +void to_json(json& j, AuthorizationType const& k) noexcept; +void from_json(const json& j, AuthorizationType& k); + +void to_json(json& j, IdTokenType const& k) noexcept; +void from_json(const json& j, IdTokenType& k); + +void to_json(json& j, WithdrawAuthorizationResult const& k) noexcept; +void from_json(const json& j, WithdrawAuthorizationResult& k); + +void to_json(json& j, CustomIdToken const& k) noexcept; +void from_json(const json& j, CustomIdToken& k); + +void to_json(json& j, IdToken const& k) noexcept; +void from_json(const json& j, IdToken& k); + +void to_json(json& j, ProvidedIdToken const& k) noexcept; +void from_json(const json& j, ProvidedIdToken& k); + +void to_json(json& j, TokenValidationStatusMessage const& k) noexcept; +void from_json(const json& j, TokenValidationStatusMessage& k); + +void to_json(json& j, ValidationResult const& k) noexcept; +void from_json(const json& j, ValidationResult& k); + +void to_json(json& j, ValidationResultUpdate const& k) noexcept; +void from_json(const json& j, ValidationResultUpdate& k); + +void to_json(json& j, WithdrawAuthorizationRequest const& k) noexcept; +void from_json(const json& j, WithdrawAuthorizationRequest& k); + +} // namespace everest::lib::API::V1_0::types::auth diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/auth/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/auth/wrapper.hpp new file mode 100644 index 0000000000..be4ba74ccc --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/auth/wrapper.hpp @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/authorization.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::auth { + +using AuthorizationStatus_Internal = ::types::authorization::AuthorizationStatus; +using AuthorizationStatus_External = AuthorizationStatus; + +AuthorizationStatus_Internal toInternalApi(AuthorizationStatus_External const& val); +AuthorizationStatus_External toExternalApi(AuthorizationStatus_Internal const& val); + +using CertificateStatus_Internal = ::types::authorization::CertificateStatus; +using CertificateStatus_External = CertificateStatus; + +CertificateStatus_Internal toInternalApi(CertificateStatus_External const& val); +CertificateStatus_External toExternalApi(CertificateStatus_Internal const& val); + +using TokenValidationStatus_Internal = ::types::authorization::TokenValidationStatus; +using TokenValidationStatus_External = TokenValidationStatus; + +TokenValidationStatus_Internal toInternalApi(TokenValidationStatus_External const& val); +TokenValidationStatus_External toExternalApi(TokenValidationStatus_Internal const& val); + +using SelectionAlgorithm_Internal = ::types::authorization::SelectionAlgorithm; +using SelectionAlgorithm_External = SelectionAlgorithm; + +SelectionAlgorithm_Internal toInternalApi(SelectionAlgorithm_External const& val); +SelectionAlgorithm_External toExternalApi(SelectionAlgorithm_Internal const& val); + +using AuthorizationType_Internal = ::types::authorization::AuthorizationType; +using AuthorizationType_External = AuthorizationType; + +AuthorizationType_Internal toInternalApi(AuthorizationType_External const& val); +AuthorizationType_External toExternalApi(AuthorizationType_Internal const& val); + +using IdTokenType_Internal = ::types::authorization::IdTokenType; +using IdTokenType_External = IdTokenType; + +IdTokenType_Internal toInternalApi(IdTokenType_External const& val); +IdTokenType_External toExternalApi(IdTokenType_Internal const& val); + +using WithdrawAuthorizationResult_Internal = ::types::authorization::WithdrawAuthorizationResult; +using WithdrawAuthorizationResult_External = WithdrawAuthorizationResult; + +WithdrawAuthorizationResult_Internal toInternalApi(WithdrawAuthorizationResult_External const& val); +WithdrawAuthorizationResult_External toExternalApi(WithdrawAuthorizationResult_Internal const& val); + +using CustomIdToken_Internal = ::types::authorization::CustomIdToken; +using CustomIdToken_External = CustomIdToken; + +CustomIdToken_Internal toInternalApi(CustomIdToken_External const& val); +CustomIdToken_External toExternalApi(CustomIdToken_Internal const& val); + +using IdToken_Internal = ::types::authorization::IdToken; +using IdToken_External = IdToken; + +IdToken_Internal toInternalApi(IdToken_External const& val); +IdToken_External toExternalApi(IdToken_Internal const& val); + +using ProvidedIdToken_Internal = ::types::authorization::ProvidedIdToken; +using ProvidedIdToken_External = ProvidedIdToken; + +ProvidedIdToken_Internal toInternalApi(ProvidedIdToken_External const& val); +ProvidedIdToken_External toExternalApi(ProvidedIdToken_Internal const& val); + +using TokenValidationStatusMessage_Internal = ::types::authorization::TokenValidationStatusMessage; +using TokenValidationStatusMessage_External = TokenValidationStatusMessage; + +TokenValidationStatusMessage_Internal toInternalApi(TokenValidationStatusMessage_External const& val); +TokenValidationStatusMessage_External toExternalApi(TokenValidationStatusMessage_Internal const& val); + +using ValidationResult_Internal = ::types::authorization::ValidationResult; +using ValidationResult_External = ValidationResult; + +ValidationResult_Internal toInternalApi(ValidationResult_External const& val); +ValidationResult_External toExternalApi(ValidationResult_Internal const& val); + +using ValidationResultUpdate_Internal = ::types::authorization::ValidationResultUpdate; +using ValidationResultUpdate_External = ValidationResultUpdate; + +ValidationResultUpdate_Internal toInternalApi(ValidationResultUpdate_External const& val); +ValidationResultUpdate_External toExternalApi(ValidationResultUpdate_Internal const& val); + +using WithdrawAuthorizationRequest_Internal = ::types::authorization::WithdrawAuthorizationRequest; +using WithdrawAuthorizationRequest_External = WithdrawAuthorizationRequest; + +WithdrawAuthorizationRequest_Internal toInternalApi(WithdrawAuthorizationRequest_External const& val); +WithdrawAuthorizationRequest_External toExternalApi(WithdrawAuthorizationRequest_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::auth diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/display_message/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/display_message/json_codec.hpp new file mode 100644 index 0000000000..d0f5cc49c5 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/display_message/json_codec.hpp @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::display_message { + +using json = nlohmann::json; + +void to_json(json& j, MessagePriorityEnum const& k) noexcept; +void from_json(const json& j, MessagePriorityEnum& k); + +void to_json(json& j, MessageStateEnum const& k) noexcept; +void from_json(const json& j, MessageStateEnum& k); + +void to_json(json& j, DisplayMessageStatusEnum const& k) noexcept; +void from_json(const json& j, DisplayMessageStatusEnum& k); + +void to_json(json& j, ClearMessageResponseEnum const& k) noexcept; +void from_json(const json& j, ClearMessageResponseEnum& k); + +void to_json(json& j, MessageFormat const& k) noexcept; +void from_json(const json& j, MessageFormat& k); + +void to_json(json& j, Identifier_type const& k) noexcept; +void from_json(const json& j, Identifier_type& k); + +void to_json(json& j, MessageContent const& k) noexcept; +void from_json(const json& j, MessageContent& k); + +void to_json(json& j, DisplayMessage const& k) noexcept; +void from_json(const json& j, DisplayMessage& k); + +void to_json(json& j, SetDisplayMessageRequest const& k) noexcept; +void from_json(const json& j, SetDisplayMessageRequest& k); + +void to_json(json& j, SetDisplayMessageResponse const& k) noexcept; +void from_json(const json& j, SetDisplayMessageResponse& k); + +void to_json(json& j, GetDisplayMessageRequest const& k) noexcept; +void from_json(const json& j, GetDisplayMessageRequest& k); + +void to_json(json& j, GetDisplayMessageResponse const& k) noexcept; +void from_json(const json& j, GetDisplayMessageResponse& k); + +void to_json(json& j, ClearDisplayMessageRequest const& k) noexcept; +void from_json(const json& j, ClearDisplayMessageRequest& k); + +void to_json(json& j, ClearDisplayMessageResponse const& k) noexcept; +void from_json(const json& j, ClearDisplayMessageResponse& k); + +} // namespace everest::lib::API::V1_0::types::display_message diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/display_message/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/display_message/wrapper.hpp new file mode 100644 index 0000000000..1c2eb6e5ee --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/display_message/wrapper.hpp @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/display_message.hpp" +#include "generated/types/text_message.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::display_message { + +using MessagePriorityEnum_Internal = ::types::display_message::MessagePriorityEnum; +using MessagePriorityEnum_External = MessagePriorityEnum; + +MessagePriorityEnum_Internal toInternalApi(MessagePriorityEnum_External const& val); +MessagePriorityEnum_External toExternalApi(MessagePriorityEnum_Internal const& val); + +using MessageStateEnum_Internal = ::types::display_message::MessageStateEnum; +using MessageStateEnum_External = MessageStateEnum; + +MessageStateEnum_Internal toInternalApi(MessageStateEnum_External const& val); +MessageStateEnum_External toExternalApi(MessageStateEnum_Internal const& val); + +using DisplayMessageStatusEnum_Internal = ::types::display_message::DisplayMessageStatusEnum; +using DisplayMessageStatusEnum_External = DisplayMessageStatusEnum; + +DisplayMessageStatusEnum_Internal toInternalApi(DisplayMessageStatusEnum_External const& val); +DisplayMessageStatusEnum_External toExternalApi(DisplayMessageStatusEnum_Internal const& val); + +using ClearMessageResponseEnum_Internal = ::types::display_message::ClearMessageResponseEnum; +using ClearMessageResponseEnum_External = ClearMessageResponseEnum; + +ClearMessageResponseEnum_Internal toInternalApi(ClearMessageResponseEnum_External const& val); +ClearMessageResponseEnum_External toExternalApi(ClearMessageResponseEnum_Internal const& val); + +using MessageFormat_Internal = ::types::text_message::MessageFormat; +using MessageFormat_External = MessageFormat; + +MessageFormat_Internal toInternalApi(MessageFormat_External const& val); +MessageFormat_External toExternalApi(MessageFormat_Internal const& val); + +using Identifier_type_Internal = ::types::display_message::IdentifierType; +using Identifier_type_External = Identifier_type; + +Identifier_type_Internal toInternalApi(Identifier_type_External const& val); +Identifier_type_External toExternalApi(Identifier_type_Internal const& val); + +using MessageContent_Internal = ::types::text_message::MessageContent; +using MessageContent_External = MessageContent; + +MessageContent_Internal toInternalApi(MessageContent_External const& val); +MessageContent_External toExternalApi(MessageContent_Internal const& val); + +using DisplayMessage_Internal = ::types::display_message::DisplayMessage; +using DisplayMessage_External = DisplayMessage; + +DisplayMessage_Internal toInternalApi(DisplayMessage_External const& val); +DisplayMessage_External toExternalApi(DisplayMessage_Internal const& val); + +using SetDisplayMessageResponse_Internal = ::types::display_message::SetDisplayMessageResponse; +using SetDisplayMessageResponse_External = SetDisplayMessageResponse; + +SetDisplayMessageResponse_Internal toInternalApi(SetDisplayMessageResponse_External const& val); +SetDisplayMessageResponse_External toExternalApi(SetDisplayMessageResponse_Internal const& val); + +using GetDisplayMessageRequest_Internal = ::types::display_message::GetDisplayMessageRequest; +using GetDisplayMessageRequest_External = GetDisplayMessageRequest; + +GetDisplayMessageRequest_Internal toInternalApi(GetDisplayMessageRequest_External const& val); +GetDisplayMessageRequest_External toExternalApi(GetDisplayMessageRequest_Internal const& val); + +using GetDisplayMessageResponse_Internal = ::types::display_message::GetDisplayMessageResponse; +using GetDisplayMessageResponse_External = GetDisplayMessageResponse; + +GetDisplayMessageResponse_Internal toInternalApi(GetDisplayMessageResponse_External const& val); +GetDisplayMessageResponse_External toExternalApi(GetDisplayMessageResponse_Internal const& val); + +using ClearDisplayMessageRequest_Internal = ::types::display_message::ClearDisplayMessageRequest; +using ClearDisplayMessageRequest_External = ClearDisplayMessageRequest; + +ClearDisplayMessageRequest_Internal toInternalApi(ClearDisplayMessageRequest_External const& val); +ClearDisplayMessageRequest_External toExternalApi(ClearDisplayMessageRequest_Internal const& val); + +using ClearDisplayMessageResponse_Internal = ::types::display_message::ClearDisplayMessageResponse; +using ClearDisplayMessageResponse_External = ClearDisplayMessageResponse; + +ClearDisplayMessageResponse_Internal toInternalApi(ClearDisplayMessageResponse_External const& val); +ClearDisplayMessageResponse_External toExternalApi(ClearDisplayMessageResponse_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::display_message diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/energy/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/energy/json_codec.hpp new file mode 100644 index 0000000000..54fb252886 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/energy/json_codec.hpp @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::energy { + +using json = nlohmann::json; + +void to_json(json& j, NumberWithSource const& k) noexcept; +void from_json(const json& j, NumberWithSource& k); + +void to_json(json& j, IntegerWithSource const& k) noexcept; +void from_json(const json& j, IntegerWithSource& k); + +void to_json(json& j, FrequencyWattPoint const& k) noexcept; +void from_json(const json& j, FrequencyWattPoint& k); + +void to_json(json& j, SetpointType const& k) noexcept; +void from_json(const json& j, SetpointType& k); + +void to_json(json& j, PricePerkWh const& k) noexcept; +void from_json(const json& j, PricePerkWh& k); + +void to_json(json& j, LimitsReq const& k) noexcept; +void from_json(const json& j, LimitsReq& k); + +void to_json(json& j, LimitsRes const& k) noexcept; +void from_json(const json& j, LimitsRes& k); + +void to_json(json& j, ScheduleReqEntry const& k) noexcept; +void from_json(const json& j, ScheduleReqEntry& k); + +void to_json(json& j, ScheduleResEntry const& k) noexcept; +void from_json(const json& j, ScheduleResEntry& k); + +void to_json(json& j, ScheduleSetpointEntry const& k) noexcept; +void from_json(const json& j, ScheduleSetpointEntry& k); + +void to_json(json& j, ExternalLimits const& k) noexcept; +void from_json(const json& j, ExternalLimits& k); + +void to_json(json& j, EnforcedLimits const& k) noexcept; +void from_json(const json& j, EnforcedLimits& k); + +} // namespace everest::lib::API::V1_0::types::energy diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/energy/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/energy/wrapper.hpp new file mode 100644 index 0000000000..0306ca2bc1 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/energy/wrapper.hpp @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/energy.hpp" +#include "generated/types/energy_price_information.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::energy { + +using NumberWithSource_Internal = ::types::energy::NumberWithSource; +using NumberWithSource_External = NumberWithSource; + +NumberWithSource_Internal toInternalApi(NumberWithSource_External const& val); +NumberWithSource_External toExternalApi(NumberWithSource_Internal const& val); + +using IntegerWithSource_Internal = ::types::energy::IntegerWithSource; +using IntegerWithSource_External = IntegerWithSource; + +IntegerWithSource_Internal toInternalApi(IntegerWithSource_External const& val); +IntegerWithSource_External toExternalApi(IntegerWithSource_Internal const& val); + +using FrequencyWattPoint_Internal = ::types::energy::FrequencyWattPoint; +using FrequencyWattPoint_External = FrequencyWattPoint; + +FrequencyWattPoint_Internal toInternalApi(FrequencyWattPoint_External const& val); +FrequencyWattPoint_External toExternalApi(FrequencyWattPoint_Internal const& val); + +using SetpointType_Internal = ::types::energy::SetpointType; +using SetpointType_External = SetpointType; + +SetpointType_Internal toInternalApi(SetpointType_External const& val); +SetpointType_External toExternalApi(SetpointType_Internal const& val); + +using PricePerkWh_Internal = ::types::energy_price_information::PricePerkWh; +using PricePerkWh_External = PricePerkWh; + +PricePerkWh_Internal toInternalApi(PricePerkWh_External const& val); +PricePerkWh_External toExternalApi(PricePerkWh_Internal const& val); + +using LimitsReq_Internal = ::types::energy::LimitsReq; +using LimitsReq_External = LimitsReq; + +LimitsReq_Internal toInternalApi(LimitsReq_External const& val); +LimitsReq_External toExternalApi(LimitsReq_Internal const& val); + +using LimitsRes_Internal = ::types::energy::LimitsRes; +using LimitsRes_External = LimitsRes; + +LimitsRes_Internal toInternalApi(LimitsRes_External const& val); +LimitsRes_External toExternalApi(LimitsRes_Internal const& val); + +using ScheduleReqEntry_Internal = ::types::energy::ScheduleReqEntry; +using ScheduleReqEntry_External = ScheduleReqEntry; + +ScheduleReqEntry_Internal toInternalApi(ScheduleReqEntry_External const& val); +ScheduleReqEntry_External toExternalApi(ScheduleReqEntry_Internal const& val); + +using ScheduleResEntry_Internal = ::types::energy::ScheduleResEntry; +using ScheduleResEntry_External = ScheduleResEntry; + +ScheduleResEntry_Internal toInternalApi(ScheduleResEntry_External const& val); +ScheduleResEntry_External toExternalApi(ScheduleResEntry_Internal const& val); + +using ScheduleSetpointEntry_Internal = ::types::energy::ScheduleSetpointEntry; +using ScheduleSetpointEntry_External = ScheduleSetpointEntry; + +ScheduleSetpointEntry_Internal toInternalApi(ScheduleSetpointEntry_External const& val); +ScheduleSetpointEntry_External toExternalApi(ScheduleSetpointEntry_Internal const& val); + +using ExternalLimits_Internal = ::types::energy::ExternalLimits; +using ExternalLimits_External = ExternalLimits; + +ExternalLimits_Internal toInternalApi(ExternalLimits_External const& val); +ExternalLimits_External toExternalApi(ExternalLimits_Internal const& val); + +using EnforcedLimits_Internal = ::types::energy::EnforcedLimits; +using EnforcedLimits_External = EnforcedLimits; + +EnforcedLimits_Internal toInternalApi(EnforcedLimits_External const& val); +EnforcedLimits_External toExternalApi(EnforcedLimits_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::energy diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/error_history/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/error_history/json_codec.hpp new file mode 100644 index 0000000000..ea99b2ca0c --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/error_history/json_codec.hpp @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::error_history { + +using json = nlohmann::json; + +void to_json(json& j, State const& k) noexcept; +void from_json(const json& j, State& k); + +void to_json(json& j, SeverityFilter const& k) noexcept; +void from_json(const json& j, SeverityFilter& k); + +void to_json(json& j, Severity const& k) noexcept; +void from_json(const json& j, Severity& k); + +void to_json(json& j, ImplementationIdentifier const& k) noexcept; +void from_json(const json& j, ImplementationIdentifier& k); + +void to_json(json& j, TimeperiodFilter const& k) noexcept; +void from_json(const json& j, TimeperiodFilter& k); + +void to_json(json& j, FilterArguments const& k) noexcept; +void from_json(const json& j, FilterArguments& k); + +void to_json(json& j, ErrorObject const& k) noexcept; +void from_json(const json& j, ErrorObject& k); + +void to_json(json& j, ErrorList const& k) noexcept; +void from_json(const json& j, ErrorList& k); + +} // namespace everest::lib::API::V1_0::types::error_history diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/error_history/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/error_history/wrapper.hpp new file mode 100644 index 0000000000..7309bd05ee --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/error_history/wrapper.hpp @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/error_history.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::error_history { + +using State_Internal = ::types::error_history::State; +using State_External = State; + +State_Internal toInternalApi(State_External const& val); +State_External toExternalApi(State_Internal const& val); + +using SeverityFilter_Internal = ::types::error_history::SeverityFilter; +using SeverityFilter_External = SeverityFilter; + +SeverityFilter_Internal toInternalApi(SeverityFilter_External const& val); +SeverityFilter_External toExternalApi(SeverityFilter_Internal const& val); + +using Severity_Internal = ::types::error_history::Severity; +using Severity_External = Severity; + +Severity_Internal toInternalApi(Severity_External const& val); +Severity_External toExternalApi(Severity_Internal const& val); + +using ImplementationIdentifier_Internal = ::types::error_history::ImplementationIdentifier; +using ImplementationIdentifier_External = ImplementationIdentifier; + +ImplementationIdentifier_Internal toInternalApi(ImplementationIdentifier_External const& val); +ImplementationIdentifier_External toExternalApi(ImplementationIdentifier_Internal const& val); + +using TimeperiodFilter_Internal = ::types::error_history::TimeperiodFilter; +using TimeperiodFilter_External = TimeperiodFilter; + +TimeperiodFilter_Internal toInternalApi(TimeperiodFilter_External const& val); +TimeperiodFilter_External toExternalApi(TimeperiodFilter_Internal const& val); + +using FilterArguments_Internal = ::types::error_history::FilterArguments; +using FilterArguments_External = FilterArguments; + +FilterArguments_Internal toInternalApi(FilterArguments_External const& val); +FilterArguments_External toExternalApi(FilterArguments_Internal const& val); + +using ErrorObject_Internal = ::types::error_history::ErrorObject; +using ErrorObject_External = ErrorObject; + +ErrorObject_Internal toInternalApi(ErrorObject_External const& val); +ErrorObject_External toExternalApi(ErrorObject_Internal const& val); + +using ErrorList_Internal = std::vector; +using ErrorList_External = ErrorList; + +ErrorList_Internal toInternalApi(ErrorList_External const& val); +ErrorList_External toExternalApi(ErrorList_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::error_history diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/evse_board_support/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/evse_board_support/json_codec.hpp new file mode 100644 index 0000000000..90d2080d34 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/evse_board_support/json_codec.hpp @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::evse_board_support { + +using json = nlohmann::json; + +void to_json(json& j, Event const& k) noexcept; +void from_json(const json& j, Event& k); + +void to_json(json& j, BspEvent const& k) noexcept; +void from_json(const json& j, BspEvent& k); + +void to_json(json& j, const ErrorEnum& k) noexcept; +void from_json(const json& j, ErrorEnum& k); + +void to_json(json& j, const Error& k) noexcept; +void from_json(const json& j, Error& k); + +void to_json(json& j, Connector_type const& k) noexcept; +void from_json(const json& j, Connector_type& k); + +void to_json(json& j, HardwareCapabilities const& k) noexcept; +void from_json(const json& j, HardwareCapabilities& k); + +void to_json(json& j, Reason const& k) noexcept; +void from_json(const json& j, Reason& k); + +void to_json(json& j, PowerOnOff const& k) noexcept; +void from_json(const json& j, PowerOnOff& k); + +void to_json(json& j, Ampacity const& k) noexcept; +void from_json(json const& j, Ampacity& k); + +void to_json(json& j, ProximityPilot const& k) noexcept; +void from_json(json const& j, ProximityPilot& k); + +} // namespace everest::lib::API::V1_0::types::evse_board_support diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/evse_board_support/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/evse_board_support/wrapper.hpp new file mode 100644 index 0000000000..d19b3ddf85 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/evse_board_support/wrapper.hpp @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/board_support_common.hpp" +#include "generated/types/evse_board_support.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::evse_board_support { + +using Event_Internal = ::types::board_support_common::Event; +using Event_External = Event; + +Event_Internal toInternalApi(Event_External const& val); +Event_External toExternalApi(Event_Internal const& val); + +using BspEvent_Internal = ::types::board_support_common::BspEvent; +using BspEvent_External = BspEvent; + +BspEvent_Internal toInternalApi(BspEvent_External const& val); +BspEvent_External toExternalApi(BspEvent_Internal const& val); + +using Connector_type_Internal = ::types::evse_board_support::Connector_type; +using Connector_type_External = Connector_type; + +Connector_type_Internal toInternalApi(Connector_type_External const& val); +Connector_type_External toExternalApi(Connector_type_Internal const& val); + +using HardwareCapabilities_Internal = ::types::evse_board_support::HardwareCapabilities; +using HardwareCapabilities_External = HardwareCapabilities; + +HardwareCapabilities_Internal toInternalApi(HardwareCapabilities_External const& val); +HardwareCapabilities_External toExternalApi(HardwareCapabilities_Internal const& val); + +using Reason_Internal = ::types::evse_board_support::Reason; +; +using Reason_External = Reason; + +Reason_Internal toInternalApi(Reason_External const& val); +Reason_External toExternalApi(Reason_Internal const& val); + +using PowerOnOff_Internal = ::types::evse_board_support::PowerOnOff; +; +using PowerOnOff_External = PowerOnOff; + +PowerOnOff_Internal toInternalApi(PowerOnOff_External const& val); +PowerOnOff_External toExternalApi(PowerOnOff_Internal const& val); + +using Ampacity_Internal = ::types::board_support_common::Ampacity; +using Ampacity_External = Ampacity; + +Ampacity_Internal toInternalApi(Ampacity_External const& val); +Ampacity_External toExternalApi(Ampacity_Internal const& val); + +using ProximityPilot_Internal = ::types::board_support_common::ProximityPilot; +using ProximityPilot_External = ProximityPilot; + +ProximityPilot_Internal toInternalApi(ProximityPilot_External const& val); +ProximityPilot_External toExternalApi(ProximityPilot_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::evse_board_support diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/evse_manager/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/evse_manager/json_codec.hpp new file mode 100644 index 0000000000..ec95fad53f --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/evse_manager/json_codec.hpp @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::evse_manager { + +using json = nlohmann::json; + +void to_json(json& j, StopTransactionReason const& k) noexcept; +void from_json(json const& j, StopTransactionReason& k); + +void to_json(json& j, StopTransactionRequest const& k) noexcept; +void from_json(json const& j, StopTransactionRequest& k); + +void to_json(json& j, StartSessionReason const& k) noexcept; +void from_json(json const& j, StartSessionReason& k); + +void to_json(json& j, SessionEventEnum const& k) noexcept; +void from_json(json const& j, SessionEventEnum& k); + +void to_json(json& j, SessionEvent const& k) noexcept; +void from_json(json const& j, SessionEvent& k); + +void to_json(json& j, Limits const& k) noexcept; +void from_json(json const& j, Limits& k); + +void to_json(json& j, EVInfo const& k) noexcept; +void from_json(json const& j, EVInfo& k); + +void to_json(json& j, CarManufacturer const& k) noexcept; +void from_json(json const& j, CarManufacturer& k); + +void to_json(json& j, SessionStarted const& k) noexcept; +void from_json(json const& j, SessionStarted& k); + +void to_json(json& j, SessionFinished const& k) noexcept; +void from_json(json const& j, SessionFinished& k); + +void to_json(json& j, TransactionStarted const& k) noexcept; +void from_json(json const& j, TransactionStarted& k); + +void to_json(json& j, TransactionFinished const& k) noexcept; +void from_json(json const& j, TransactionFinished& k); + +void to_json(json& j, ChargingStateChangedEvent const& k) noexcept; +void from_json(json const& j, ChargingStateChangedEvent& k); + +void to_json(json& j, AuthorizationEvent const& k) noexcept; +void from_json(json const& j, AuthorizationEvent& k); + +void to_json(json& j, ErrorSeverity const& k) noexcept; +void from_json(json const& j, ErrorSeverity& k); + +void to_json(json& j, ErrorState const& k) noexcept; +void from_json(json const& j, ErrorState& k); + +void to_json(json& j, ErrorOrigin const& k) noexcept; +void from_json(json const& j, ErrorOrigin& k); + +void to_json(json& j, Error const& k) noexcept; +void from_json(json const& j, Error& k); + +void to_json(json& j, ConnectorTypeEnum const& k) noexcept; +void from_json(json const& j, ConnectorTypeEnum& k); + +void to_json(json& j, Connector const& k) noexcept; +void from_json(json const& j, Connector& k); + +void to_json(json& j, Evse const& k) noexcept; +void from_json(json const& j, Evse& k); + +void to_json(json& j, EnableSourceEnum const& k) noexcept; +void from_json(json const& j, EnableSourceEnum& k); + +void to_json(json& j, EnableStateEnum const& k) noexcept; +void from_json(json const& j, EnableStateEnum& k); + +void to_json(json& j, EnableDisableSource const& k) noexcept; +void from_json(json const& j, EnableDisableSource& k); + +void to_json(json& j, EnableDisableRequest const& k) noexcept; +void from_json(json const& j, EnableDisableRequest& k); + +void to_json(json& j, AuthorizeResponseArgs const& k) noexcept; +void from_json(json const& j, AuthorizeResponseArgs& k); + +void to_json(json& j, PlugAndChargeConfiguration const& k) noexcept; +void from_json(json const& j, PlugAndChargeConfiguration& k); + +} // namespace everest::lib::API::V1_0::types::evse_manager diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/evse_manager/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/evse_manager/wrapper.hpp new file mode 100644 index 0000000000..b1e412e144 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/evse_manager/wrapper.hpp @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +// #include "utils/types.hpp" +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/evse_manager.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::evse_manager { + +using StopTransactionReason_Internal = ::types::evse_manager::StopTransactionReason; +using StopTransactionReason_External = StopTransactionReason; + +StopTransactionReason_Internal toInternalApi(StopTransactionReason_External const& val); +StopTransactionReason_External toExternalApi(StopTransactionReason_Internal const& val); + +using StopTransactionRequest_Internal = ::types::evse_manager::StopTransactionRequest; +using StopTransactionRequest_External = StopTransactionRequest; + +StopTransactionRequest_Internal toInternalApi(StopTransactionRequest_External const& val); +StopTransactionRequest_External toExternalApi(StopTransactionRequest_Internal const& val); + +using StartSessionReason_Internal = ::types::evse_manager::StartSessionReason; +using StartSessionReason_External = StartSessionReason; + +StartSessionReason_Internal toInternalApi(StartSessionReason_External const& val); +StartSessionReason_External toExternalApi(StartSessionReason_Internal const& val); + +using SessionEventEnum_Internal = ::types::evse_manager::SessionEventEnum; +using SessionEventEnum_External = SessionEventEnum; + +SessionEventEnum_Internal toInternalApi(SessionEventEnum_External const& val); +SessionEventEnum_External toExternalApi(SessionEventEnum_Internal const& val); + +using SessionEvent_Internal = ::types::evse_manager::SessionEvent; +using SessionEvent_External = SessionEvent; + +SessionEvent_Internal toInternalApi(SessionEvent_External const& val); +SessionEvent_External toExternalApi(SessionEvent_Internal const& val); + +using Limits_Internal = ::types::evse_manager::Limits; +using Limits_External = Limits; + +Limits_Internal toInternalApi(Limits_External const& val); +Limits_External toExternalApi(Limits_Internal const& val); + +using EVInfo_Internal = ::types::evse_manager::EVInfo; +using EVInfo_External = EVInfo; + +EVInfo_Internal toInternalApi(EVInfo_External const& val); +EVInfo_External toExternalApi(EVInfo_Internal const& val); + +using CarManufacturer_Internal = ::types::evse_manager::CarManufacturer; +using CarManufacturer_External = CarManufacturer; + +CarManufacturer_Internal toInternalApi(CarManufacturer_External const& val); +CarManufacturer_External toExternalApi(CarManufacturer_Internal const& val); + +using SessionStarted_Internal = ::types::evse_manager::SessionStarted; +using SessionStarted_External = SessionStarted; + +SessionStarted_Internal toInternalApi(SessionStarted_External const& val); +SessionStarted_External toExternalApi(SessionStarted_Internal const& val); + +using SessionFinished_Internal = ::types::evse_manager::SessionFinished; +using SessionFinished_External = SessionFinished; + +SessionFinished_Internal toInternalApi(SessionFinished_External const& val); +SessionFinished_External toExternalApi(SessionFinished_Internal const& val); + +using TransactionStarted_Internal = ::types::evse_manager::TransactionStarted; +using TransactionStarted_External = TransactionStarted; + +TransactionStarted_Internal toInternalApi(TransactionStarted_External const& val); +TransactionStarted_External toExternalApi(TransactionStarted_Internal const& val); + +using TransactionFinished_Internal = ::types::evse_manager::TransactionFinished; +using TransactionFinished_External = TransactionFinished; + +TransactionFinished_Internal toInternalApi(TransactionFinished_External const& val); +TransactionFinished_External toExternalApi(TransactionFinished_Internal const& val); + +using ChargingStateChangedEvent_Internal = ::types::evse_manager::ChargingStateChangedEvent; +using ChargingStateChangedEvent_External = ChargingStateChangedEvent; + +ChargingStateChangedEvent_Internal toInternalApi(ChargingStateChangedEvent_External const& val); +ChargingStateChangedEvent_External toExternalApi(ChargingStateChangedEvent_Internal const& val); + +using AuthorizationEvent_Internal = ::types::evse_manager::AuthorizationEvent; +using AuthorizationEvent_External = AuthorizationEvent; + +AuthorizationEvent_Internal toInternalApi(AuthorizationEvent_External const& val); +AuthorizationEvent_External toExternalApi(AuthorizationEvent_Internal const& val); + +using ConnectorTypeEnum_Internal = ::types::evse_manager::ConnectorTypeEnum; +using ConnectorTypeEnum_External = ConnectorTypeEnum; + +ConnectorTypeEnum_Internal toInternalApi(ConnectorTypeEnum_External const& val); +ConnectorTypeEnum_External toExternalApi(ConnectorTypeEnum_Internal const& val); + +using Connector_Internal = ::types::evse_manager::Connector; +using Connector_External = Connector; + +Connector_Internal toInternalApi(Connector_External const& val); +Connector_External toExternalApi(Connector_Internal const& val); + +using Evse_Internal = ::types::evse_manager::Evse; +using Evse_External = Evse; + +Evse_Internal toInternalApi(Evse_External const& val); +Evse_External toExternalApi(Evse_Internal const& val); + +using EnableSourceEnum_Internal = ::types::evse_manager::Enable_source; +using EnableSourceEnum_External = EnableSourceEnum; + +EnableSourceEnum_Internal toInternalApi(EnableSourceEnum_External const& val); +EnableSourceEnum_External toExternalApi(EnableSourceEnum_Internal const& val); + +using EnableStateEnum_Internal = ::types::evse_manager::Enable_state; +using EnableStateEnum_External = EnableStateEnum; + +EnableStateEnum_Internal toInternalApi(EnableStateEnum_External const& val); +EnableStateEnum_External toExternalApi(EnableStateEnum_Internal const& val); + +using EnableDisableSource_Internal = ::types::evse_manager::EnableDisableSource; +using EnableDisableSource_External = EnableDisableSource; + +EnableDisableSource_Internal toInternalApi(EnableDisableSource_External const& val); +EnableDisableSource_External toExternalApi(EnableDisableSource_Internal const& val); + +using PlugAndChargeConfiguration_Internal = ::types::evse_manager::PlugAndChargeConfiguration; +using PlugAndChargeConfiguration_External = PlugAndChargeConfiguration; + +PlugAndChargeConfiguration_Internal toInternalApi(PlugAndChargeConfiguration_External const& val); +PlugAndChargeConfiguration_External toExternalApi(PlugAndChargeConfiguration_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::evse_manager diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/generic/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/generic/json_codec.hpp new file mode 100644 index 0000000000..544e6bb641 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/generic/json_codec.hpp @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::generic { + +using json = nlohmann::json; + +void to_json(json& j, RequestReply const& k); +void from_json(json const& j, RequestReply& k); + +void from_json(const json& j, ErrorEnum& k); +void to_json(json& j, const ErrorEnum& k) noexcept; + +void from_json(const json& j, Error& k); +void to_json(json& j, const Error& k) noexcept; + +} // namespace everest::lib::API::V1_0::types::generic diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/iso15118_charger/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/iso15118_charger/json_codec.hpp new file mode 100644 index 0000000000..d3c44211a2 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/iso15118_charger/json_codec.hpp @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::iso15118_charger { + +using json = nlohmann::json; + +void to_json(json& j, CertificateActionEnum const& k) noexcept; +void from_json(json const& j, CertificateActionEnum& k); + +void to_json(json& j, Status const& k) noexcept; +void from_json(json const& j, Status& k); + +void to_json(json& j, RequestExiStreamSchema const& k) noexcept; +void from_json(json const& j, RequestExiStreamSchema& k); + +void to_json(json& j, ResponseExiStreamStatus const& k) noexcept; +void from_json(json const& j, ResponseExiStreamStatus& k); + +} // namespace everest::lib::API::V1_0::types::iso15118_charger diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/iso15118_charger/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/iso15118_charger/wrapper.hpp new file mode 100644 index 0000000000..5873e4b186 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/iso15118_charger/wrapper.hpp @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/iso15118.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::iso15118_charger { + +using CertificateActionEnum_Internal = ::types::iso15118::CertificateActionEnum; +using CertificateActionEnum_External = CertificateActionEnum; + +CertificateActionEnum_Internal toInternalApi(CertificateActionEnum_External const& val); +CertificateActionEnum_External toExternalApi(CertificateActionEnum_Internal const& val); + +using Status_Internal = ::types::iso15118::Status; +using Status_External = Status; + +Status_Internal toInternalApi(Status_External const& val); +Status_External toExternalApi(Status_Internal const& val); + +using RequestExiStreamSchema_Internal = ::types::iso15118::RequestExiStreamSchema; +using RequestExiStreamSchema_External = RequestExiStreamSchema; + +RequestExiStreamSchema_Internal toInternalApi(RequestExiStreamSchema_External const& val); +RequestExiStreamSchema_External toExternalApi(RequestExiStreamSchema_Internal const& val); + +using ResponseExiStreamStatus_Internal = ::types::iso15118::ResponseExiStreamStatus; +using ResponseExiStreamStatus_External = ResponseExiStreamStatus; + +ResponseExiStreamStatus_Internal toInternalApi(ResponseExiStreamStatus_External const& val); +ResponseExiStreamStatus_External toExternalApi(ResponseExiStreamStatus_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::iso15118_charger diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/isolation_monitor/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/isolation_monitor/json_codec.hpp new file mode 100644 index 0000000000..d5a106bdd3 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/isolation_monitor/json_codec.hpp @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::isolation_monitor { + +using json = nlohmann::json; + +void to_json(json& j, IsolationMeasurement const& k) noexcept; +void from_json(const json& j, IsolationMeasurement& k); + +void from_json(const json& j, ErrorEnum& k); +void to_json(json& j, const ErrorEnum& k) noexcept; + +void from_json(const json& j, Error& k); +void to_json(json& j, const Error& k) noexcept; + +} // namespace everest::lib::API::V1_0::types::isolation_monitor diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/isolation_monitor/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/isolation_monitor/wrapper.hpp new file mode 100644 index 0000000000..b4f77d283a --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/isolation_monitor/wrapper.hpp @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "everest_api_types/isolation_monitor/API.hpp" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/isolation_monitor.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::isolation_monitor { + +using IsolationMeasurement_Internal = ::types::isolation_monitor::IsolationMeasurement; +using IsolationMeasurement_External = IsolationMeasurement; + +IsolationMeasurement_Internal toInternalApi(IsolationMeasurement_External const& val); +IsolationMeasurement_External toExternalApi(IsolationMeasurement_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::isolation_monitor diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/ocpp/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/ocpp/json_codec.hpp new file mode 100644 index 0000000000..5480d33c85 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/ocpp/json_codec.hpp @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::ocpp { + +using json = nlohmann::json; + +void to_json(json& j, AttributeEnum const& k) noexcept; +void from_json(const json& j, AttributeEnum& k); + +void to_json(json& j, GetVariableStatusEnumType const& k) noexcept; +void from_json(const json& j, GetVariableStatusEnumType& k); + +void to_json(json& j, SetVariableStatusEnumType const& k) noexcept; +void from_json(const json& j, SetVariableStatusEnumType& k); + +void to_json(json& j, DataTransferStatus const& k) noexcept; +void from_json(const json& j, DataTransferStatus& k); + +void to_json(json& j, RegistrationStatus const& k) noexcept; +void from_json(const json& j, RegistrationStatus& k); + +void to_json(json& j, TransactionEvent const& k) noexcept; +void from_json(const json& j, TransactionEvent& k); + +void to_json(json& j, CustomData const& k) noexcept; +void from_json(const json& j, CustomData& k); + +void to_json(json& j, DataTransferRequest const& k) noexcept; +void from_json(const json& j, DataTransferRequest& k); + +void to_json(json& j, DataTransferResponse const& k) noexcept; +void from_json(const json& j, DataTransferResponse& k); + +void to_json(json& j, EVSE const& k) noexcept; +void from_json(const json& j, EVSE& k); + +void to_json(json& j, Component const& k) noexcept; +void from_json(const json& j, Component& k); + +void to_json(json& j, Variable const& k) noexcept; +void from_json(const json& j, Variable& k); + +void to_json(json& j, ComponentVariable const& k) noexcept; +void from_json(const json& j, ComponentVariable& k); + +void to_json(json& j, GetVariableRequest const& k) noexcept; +void from_json(const json& j, GetVariableRequest& k); + +void to_json(json& j, GetVariableResult const& k) noexcept; +void from_json(const json& j, GetVariableResult& k); + +void to_json(json& j, SetVariableRequest const& k) noexcept; +void from_json(const json& j, SetVariableRequest& k); + +void to_json(json& j, SetVariableResult const& k) noexcept; +void from_json(const json& j, SetVariableResult& k); + +void to_json(json& j, GetVariableRequestList const& k) noexcept; +void from_json(const json& j, GetVariableRequestList& k); + +void to_json(json& j, GetVariableResultList const& k) noexcept; +void from_json(const json& j, GetVariableResultList& k); + +void to_json(json& j, SetVariableRequestList const& k) noexcept; +void from_json(const json& j, SetVariableRequestList& k); + +void to_json(json& j, SetVariableResultList const& k) noexcept; +void from_json(const json& j, SetVariableResultList& k); + +void to_json(json& j, SetVariablesArgs const& k) noexcept; +void from_json(const json& j, SetVariablesArgs& k); + +void to_json(json& j, SecurityEvent const& k) noexcept; +void from_json(const json& j, SecurityEvent& k); + +void to_json(json& j, StatusInfoType const& k) noexcept; +void from_json(const json& j, StatusInfoType& k); + +void to_json(json& j, BootNotificationResponse const& k) noexcept; +void from_json(const json& j, BootNotificationResponse& k); + +void to_json(json& j, OcppTransactionEvent const& k) noexcept; +void from_json(const json& j, OcppTransactionEvent& k); + +} // namespace everest::lib::API::V1_0::types::ocpp diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/ocpp/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/ocpp/wrapper.hpp new file mode 100644 index 0000000000..1915c6a6a2 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/ocpp/wrapper.hpp @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/ocpp.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::ocpp { + +using AttributeEnum_Internal = ::types::ocpp::AttributeEnum; +using AttributeEnum_External = AttributeEnum; + +AttributeEnum_Internal toInternalApi(AttributeEnum_External const& val); +AttributeEnum_External toExternalApi(AttributeEnum_Internal const& val); + +using GetVariableStatusEnumType_Internal = ::types::ocpp::GetVariableStatusEnumType; +using GetVariableStatusEnumType_External = GetVariableStatusEnumType; + +GetVariableStatusEnumType_Internal toInternalApi(GetVariableStatusEnumType_External const& val); +GetVariableStatusEnumType_External toExternalApi(GetVariableStatusEnumType_Internal const& val); + +using SetVariableStatusEnumType_Internal = ::types::ocpp::SetVariableStatusEnumType; +using SetVariableStatusEnumType_External = SetVariableStatusEnumType; + +SetVariableStatusEnumType_Internal toInternalApi(SetVariableStatusEnumType_External const& val); +SetVariableStatusEnumType_External toExternalApi(SetVariableStatusEnumType_Internal const& val); + +using DataTransferStatus_Internal = ::types::ocpp::DataTransferStatus; +using DataTransferStatus_External = DataTransferStatus; + +DataTransferStatus_Internal toInternalApi(DataTransferStatus_External const& val); +DataTransferStatus_External toExternalApi(DataTransferStatus_Internal const& val); + +using RegistrationStatus_Internal = ::types::ocpp::RegistrationStatus; +using RegistrationStatus_External = RegistrationStatus; + +RegistrationStatus_Internal toInternalApi(RegistrationStatus_External const& val); +RegistrationStatus_External toExternalApi(RegistrationStatus_Internal const& val); + +using TransactionEvent_Internal = ::types::ocpp::TransactionEvent; +using TransactionEvent_External = TransactionEvent; + +TransactionEvent_Internal toInternalApi(TransactionEvent_External const& val); +TransactionEvent_External toExternalApi(TransactionEvent_Internal const& val); + +using CustomData_Internal = ::types::ocpp::CustomData; +using CustomData_External = CustomData; + +CustomData_Internal toInternalApi(CustomData_External const& val); +CustomData_External toExternalApi(CustomData_Internal const& val); + +using DataTransferRequest_Internal = ::types::ocpp::DataTransferRequest; +using DataTransferRequest_External = DataTransferRequest; + +DataTransferRequest_Internal toInternalApi(DataTransferRequest_External const& val); +DataTransferRequest_External toExternalApi(DataTransferRequest_Internal const& val); + +using DataTransferResponse_Internal = ::types::ocpp::DataTransferResponse; +using DataTransferResponse_External = DataTransferResponse; + +DataTransferResponse_Internal toInternalApi(DataTransferResponse_External const& val); +DataTransferResponse_External toExternalApi(DataTransferResponse_Internal const& val); + +using EVSE_Internal = ::types::ocpp::EVSE; +using EVSE_External = EVSE; + +EVSE_Internal toInternalApi(EVSE_External const& val); +EVSE_External toExternalApi(EVSE_Internal const& val); + +using Component_Internal = ::types::ocpp::Component; +using Component_External = Component; + +Component_Internal toInternalApi(Component_External const& val); +Component_External toExternalApi(Component_Internal const& val); + +using Variable_Internal = ::types::ocpp::Variable; +using Variable_External = Variable; + +Variable_Internal toInternalApi(Variable_External const& val); +Variable_External toExternalApi(Variable_Internal const& val); + +using ComponentVariable_Internal = ::types::ocpp::ComponentVariable; +using ComponentVariable_External = ComponentVariable; + +ComponentVariable_Internal toInternalApi(ComponentVariable_External const& val); +ComponentVariable_External toExternalApi(ComponentVariable_Internal const& val); + +using GetVariableRequest_Internal = ::types::ocpp::GetVariableRequest; +using GetVariableRequest_External = GetVariableRequest; + +GetVariableRequest_Internal toInternalApi(GetVariableRequest_External const& val); +GetVariableRequest_External toExternalApi(GetVariableRequest_Internal const& val); + +using GetVariableResult_Internal = ::types::ocpp::GetVariableResult; +using GetVariableResult_External = GetVariableResult; + +GetVariableResult_Internal toInternalApi(GetVariableResult_External const& val); +GetVariableResult_External toExternalApi(GetVariableResult_Internal const& val); + +using SetVariableRequest_Internal = ::types::ocpp::SetVariableRequest; +using SetVariableRequest_External = SetVariableRequest; + +SetVariableRequest_Internal toInternalApi(SetVariableRequest_External const& val); +SetVariableRequest_External toExternalApi(SetVariableRequest_Internal const& val); + +using SetVariableResult_Internal = ::types::ocpp::SetVariableResult; +using SetVariableResult_External = SetVariableResult; + +SetVariableResult_Internal toInternalApi(SetVariableResult_External const& val); +SetVariableResult_External toExternalApi(SetVariableResult_Internal const& val); + +using GetVariableRequestList_Internal = std::vector<::types::ocpp::GetVariableRequest>; +using GetVariableRequestList_External = GetVariableRequestList; + +GetVariableRequestList_Internal toInternalApi(GetVariableRequestList_External const& val); +GetVariableRequestList_External toExternalApi(GetVariableRequestList_Internal const& val); + +using GetVariableResultList_Internal = std::vector<::types::ocpp::GetVariableResult>; +using GetVariableResultList_External = GetVariableResultList; + +GetVariableResultList_Internal toInternalApi(GetVariableResultList_External const& val); +GetVariableResultList_External toExternalApi(GetVariableResultList_Internal const& val); + +using SetVariableRequestList_Internal = std::vector<::types::ocpp::SetVariableRequest>; +using SetVariableRequestList_External = SetVariableRequestList; + +SetVariableRequestList_Internal toInternalApi(SetVariableRequestList_External const& val); +SetVariableRequestList_External toExternalApi(SetVariableRequestList_Internal const& val); + +using SetVariableResultList_Internal = std::vector<::types::ocpp::SetVariableResult>; +using SetVariableResultList_External = SetVariableResultList; + +SetVariableResultList_Internal toInternalApi(SetVariableResultList_External const& val); +SetVariableResultList_External toExternalApi(SetVariableResultList_Internal const& val); + +using SecurityEvent_Internal = ::types::ocpp::SecurityEvent; +using SecurityEvent_External = SecurityEvent; + +SecurityEvent_Internal toInternalApi(SecurityEvent_External const& val); +SecurityEvent_External toExternalApi(SecurityEvent_Internal const& val); + +using StatusInfoType_Internal = ::types::ocpp::StatusInfoType; +using StatusInfoType_External = StatusInfoType; + +StatusInfoType_Internal toInternalApi(StatusInfoType_External const& val); +StatusInfoType_External toExternalApi(StatusInfoType_Internal const& val); + +using BootNotificationResponse_Internal = ::types::ocpp::BootNotificationResponse; +using BootNotificationResponse_External = BootNotificationResponse; + +BootNotificationResponse_Internal toInternalApi(BootNotificationResponse_External const& val); +BootNotificationResponse_External toExternalApi(BootNotificationResponse_Internal const& val); + +using OcppTransactionEvent_Internal = ::types::ocpp::OcppTransactionEvent; +using OcppTransactionEvent_External = OcppTransactionEvent; + +OcppTransactionEvent_Internal toInternalApi(OcppTransactionEvent_External const& val); +OcppTransactionEvent_External toExternalApi(OcppTransactionEvent_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::ocpp diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/over_voltage_monitor/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/over_voltage_monitor/json_codec.hpp new file mode 100644 index 0000000000..7eb31a1647 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/over_voltage_monitor/json_codec.hpp @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::over_voltage_monitor { + +using json = nlohmann::json; + +void from_json(const json& j, ErrorEnum& k); +void to_json(json& j, const ErrorEnum& k) noexcept; + +void from_json(const json& j, Error& k); +void to_json(json& j, const Error& k) noexcept; + +} // namespace everest::lib::API::V1_0::types::over_voltage_monitor diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/power_supply_DC/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/power_supply_DC/json_codec.hpp new file mode 100644 index 0000000000..def8205413 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/power_supply_DC/json_codec.hpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::power_supply_DC { + +using json = nlohmann::json; + +void from_json(const json& j, Capabilities& k); +void to_json(json& j, const Capabilities& k) noexcept; + +void from_json(const json& j, Mode& k); +void to_json(json& j, const Mode& k) noexcept; + +void from_json(const json& j, ChargingPhase& k); +void to_json(json& j, const ChargingPhase& k) noexcept; + +void from_json(const json& j, ModeRequest& k); +void to_json(json& j, const ModeRequest& k) noexcept; + +void from_json(const json& j, VoltageCurrent& k); +void to_json(json& j, const VoltageCurrent& k) noexcept; + +void from_json(const json& j, ErrorEnum& k); +void to_json(json& j, const ErrorEnum& k) noexcept; + +void from_json(const json& j, Error& k); +void to_json(json& j, const Error& k) noexcept; + +} // namespace everest::lib::API::V1_0::types::power_supply_DC diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/power_supply_DC/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/power_supply_DC/wrapper.hpp new file mode 100644 index 0000000000..8909fec636 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/power_supply_DC/wrapper.hpp @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/power_supply_DC.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::power_supply_DC { + +using Capabilities_Internal = ::types::power_supply_DC::Capabilities; +using Capabilities_External = Capabilities; + +Capabilities_Internal toInternalApi(Capabilities_External const& val); +Capabilities_External toExternalApi(Capabilities_Internal const& val); + +using Mode_Internal = ::types::power_supply_DC::Mode; +using Mode_External = Mode; + +Mode_Internal toInternalApi(Mode_External val); +Mode_External toExternalApi(Mode_Internal val); + +using ChargingPhase_Internal = ::types::power_supply_DC::ChargingPhase; +using ChargingPhase_External = ChargingPhase; + +ChargingPhase_Internal toInternalApi(ChargingPhase_External val); +ChargingPhase_External toExternalApi(ChargingPhase_Internal val); + +using VoltageCurrent_Internal = ::types::power_supply_DC::VoltageCurrent; +using VoltageCurrent_External = VoltageCurrent; + +VoltageCurrent_Internal toInternalApi(VoltageCurrent_External const& val); +VoltageCurrent_External toExternalApi(VoltageCurrent_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::power_supply_DC diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/powermeter/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/powermeter/json_codec.hpp new file mode 100644 index 0000000000..3a38486041 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/powermeter/json_codec.hpp @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::powermeter { + +using json = nlohmann::json; + +void from_json(const json& j, OCMFUserIdentificationStatus& k); +void to_json(json& j, const OCMFUserIdentificationStatus& k) noexcept; + +void from_json(const json& j, OCMFIdentificationFlags& k); +void to_json(json& j, const OCMFIdentificationFlags& k) noexcept; + +void from_json(const json& j, OCMFIdentificationType& k); +void to_json(json& j, const OCMFIdentificationType& k) noexcept; + +void from_json(const json& j, OCMFIdentificationLevel& k); +void to_json(json& j, const OCMFIdentificationLevel& k) noexcept; + +void from_json(const json& j, TransactionStatus& k); +void to_json(json& j, const TransactionStatus& k) noexcept; + +void from_json(const json& j, Current& k); +void to_json(json& j, const Current& k) noexcept; + +void from_json(const json& j, Voltage& k); +void to_json(json& j, const Voltage& k) noexcept; + +void from_json(const json& j, Frequency& k); +void to_json(json& j, const Frequency& k) noexcept; + +void from_json(const json& j, Power& k); +void to_json(json& j, const Power& k) noexcept; + +void from_json(const json& j, Energy& k); +void to_json(json& j, const Energy& k) noexcept; + +void from_json(const json& j, ReactivePower& k); +void to_json(json& j, const ReactivePower& k) noexcept; + +void from_json(const json& j, SignedMeterValue& k); +void to_json(json& j, const SignedMeterValue& k) noexcept; + +void from_json(const json& j, SignedCurrent& k); +void to_json(json& j, const SignedCurrent& k) noexcept; + +void from_json(const json& j, SignedVoltage& k); +void to_json(json& j, const SignedVoltage& k) noexcept; + +void from_json(const json& j, SignedFrequency& k); +void to_json(json& j, const SignedFrequency& k) noexcept; + +void from_json(const json& j, SignedEnergy& k); +void to_json(json& j, const SignedEnergy& k) noexcept; + +void from_json(const json& j, SignedPower& k); +void to_json(json& j, const SignedPower& k) noexcept; + +void from_json(const json& j, SignedReactivePower& k); +void to_json(json& j, const SignedReactivePower& k) noexcept; + +void from_json(const json& j, Temperature& k); +void to_json(json& j, const Temperature& k) noexcept; + +void from_json(const json& j, PowermeterValues& k); +void to_json(json& j, const PowermeterValues& k) noexcept; + +void from_json(const json& j, ReplyStartTransaction& k); +void to_json(json& j, const ReplyStartTransaction& k) noexcept; + +void from_json(const json& j, ReplyStopTransaction& k); +void to_json(json& j, const ReplyStopTransaction& k) noexcept; + +void from_json(const json& j, RequestStartTransaction& k); +void to_json(json& j, const RequestStartTransaction& k) noexcept; + +} // namespace everest::lib::API::V1_0::types::powermeter diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/powermeter/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/powermeter/wrapper.hpp new file mode 100644 index 0000000000..06e232c823 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/powermeter/wrapper.hpp @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "generated/types/temperature.hpp" +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/powermeter.hpp" +#include "generated/types/units_signed.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::powermeter { + +using OCMFUserIdentificationStatus_Internal = ::types::powermeter::OCMFUserIdentificationStatus; +using OCMFUserIdentificationStatus_External = OCMFUserIdentificationStatus; + +OCMFUserIdentificationStatus_Internal toInternalApi(OCMFUserIdentificationStatus_External const& val); +OCMFUserIdentificationStatus_External toExternalApi(OCMFUserIdentificationStatus_Internal const& val); + +using OCMFIdentificationFlags_Internal = ::types::powermeter::OCMFIdentificationFlags; +using OCMFIdentificationFlags_External = OCMFIdentificationFlags; + +OCMFIdentificationFlags_Internal toInternalApi(OCMFIdentificationFlags_External const& val); +OCMFIdentificationFlags_External toExternalApi(OCMFIdentificationFlags_Internal const& val); + +using OCMFIdentificationType_Internal = ::types::powermeter::OCMFIdentificationType; +using OCMFIdentificationType_External = OCMFIdentificationType; + +OCMFIdentificationType_Internal toInternalApi(OCMFIdentificationType_External const& val); +OCMFIdentificationType_External toExternalApi(OCMFIdentificationType_Internal const& val); + +using OCMFIdentificationLevel_Internal = ::types::powermeter::OCMFIdentificationLevel; +using OCMFIdentificationLevel_External = OCMFIdentificationLevel; + +OCMFIdentificationLevel_Internal toInternalApi(OCMFIdentificationLevel_External const& val); +OCMFIdentificationLevel_External toExternalApi(OCMFIdentificationLevel_Internal const& val); + +using Current_Internal = ::types::units::Current; +using Current_External = Current; + +Current_Internal toInternalApi(Current_External const& val); +Current_External toExternalApi(Current_Internal const& val); + +using Voltage_Internal = ::types::units::Voltage; +using Voltage_External = Voltage; + +Voltage_Internal toInternalApi(Voltage_External const& val); +Voltage_External toExternalApi(Voltage_Internal const& val); + +using Frequency_Internal = ::types::units::Frequency; +using Frequency_External = Frequency; + +Frequency_Internal toInternalApi(Frequency_External const& val); +Frequency_External toExternalApi(Frequency_Internal const& val); + +using Power_Internal = ::types::units::Power; +using Power_External = Power; + +Power_Internal toInternalApi(Power_External const& val); +Power_External toExternalApi(Power_Internal const& val); + +using ReactivePower_Internal = ::types::units::ReactivePower; +using ReactivePower_External = ReactivePower; + +ReactivePower_Internal toInternalApi(ReactivePower_External const& val); +ReactivePower_External toExternalApi(ReactivePower_Internal const& val); + +using Energy_Internal = ::types::units::Energy; +using Energy_External = Energy; + +Energy_Internal toInternalApi(Energy_External const& val); +Energy_External toExternalApi(Energy_Internal const& val); + +using SignedMeterValue_Internal = ::types::units_signed::SignedMeterValue; +using SignedMeterValue_External = SignedMeterValue; + +SignedMeterValue_Internal toInternalApi(SignedMeterValue_External const& val); +SignedMeterValue_External toExternalApi(SignedMeterValue_Internal const& val); + +using SignedCurrent_Internal = ::types::units_signed::Current; +using SignedCurrent_External = SignedCurrent; + +SignedCurrent_Internal toInternalApi(SignedCurrent_External const& val); +SignedCurrent_External toExternalApi(SignedCurrent_Internal const& val); + +using SignedVoltage_Internal = ::types::units_signed::Voltage; +using SignedVoltage_External = SignedVoltage; + +SignedVoltage_Internal toInternalApi(SignedVoltage_External const& val); +SignedVoltage_External toExternalApi(SignedVoltage_Internal const& val); + +using SignedFrequency_Internal = ::types::units_signed::Frequency; +using SignedFrequency_External = SignedFrequency; + +SignedFrequency_Internal toInternalApi(SignedFrequency_External const& val); +SignedFrequency_External toExternalApi(SignedFrequency_Internal const& val); + +using SignedPower_Internal = ::types::units_signed::Power; +using SignedPower_External = SignedPower; + +SignedPower_Internal toInternalApi(SignedPower_External const& val); +SignedPower_External toExternalApi(SignedPower_Internal const& val); + +using SignedReactivePower_Internal = ::types::units_signed::ReactivePower; +using SignedReactivePower_External = SignedReactivePower; + +SignedReactivePower_Internal toInternalApi(SignedReactivePower_External const& val); +SignedReactivePower_External toExternalApi(SignedReactivePower_Internal const& val); + +using SignedEnergy_Internal = ::types::units_signed::Energy; +using SignedEnergy_External = SignedEnergy; + +SignedEnergy_Internal toInternalApi(SignedEnergy_External const& val); +SignedEnergy_External toExternalApi(SignedEnergy_Internal const& val); + +using Temperature_Internal = ::types::temperature::Temperature; +using Temperature_External = Temperature; + +Temperature_Internal toInternalApi(Temperature_External const& val); +Temperature_External toExternalApi(Temperature_Internal const& val); + +using PowermeterValues_Internal = ::types::powermeter::Powermeter; +using PowermeterValues_External = PowermeterValues; + +PowermeterValues_Internal toInternalApi(PowermeterValues_External const& val); +PowermeterValues_External toExternalApi(PowermeterValues_Internal const& val); + +using TransactionStatus_Internal = ::types::powermeter::TransactionRequestStatus; +using TransactionStatus_External = TransactionStatus; + +TransactionStatus_Internal toInternalApi(TransactionStatus_External const& val); +TransactionStatus_External toExternalApi(TransactionStatus_Internal const& val); + +using ReplyStartTransaction_Internal = ::types::powermeter::TransactionStartResponse; +using ReplyStartTransaction_External = ReplyStartTransaction; + +ReplyStartTransaction_Internal toInternalApi(ReplyStartTransaction_External const& val); +ReplyStartTransaction_External toExternalApi(ReplyStartTransaction_Internal const& val); + +using ReplyStopTransaction_Internal = ::types::powermeter::TransactionStopResponse; +using ReplyStopTransaction_External = ReplyStopTransaction; + +ReplyStopTransaction_Internal toInternalApi(ReplyStopTransaction_External const& val); +ReplyStopTransaction_External toExternalApi(ReplyStopTransaction_Internal const& val); + +using RequestStartTransaction_Internal = ::types::powermeter::TransactionReq; +using RequestStartTransaction_External = RequestStartTransaction; + +RequestStartTransaction_External toExternalApi(RequestStartTransaction_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::powermeter diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/slac/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/slac/json_codec.hpp new file mode 100644 index 0000000000..34fa7fe173 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/slac/json_codec.hpp @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::slac { + +using json = nlohmann::json; + +void to_json(json& j, State const& k) noexcept; +void from_json(json const& j, State& k); + +} // namespace everest::lib::API::V1_0::types::slac diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/system/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/system/json_codec.hpp new file mode 100644 index 0000000000..0be9f97b63 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/system/json_codec.hpp @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::system { + +using json = nlohmann::json; + +void to_json(json& j, const FirmwareUpdateRequest& k) noexcept; +void from_json(const json& j, FirmwareUpdateRequest& k); + +void to_json(json& j, const UploadLogsRequest& k) noexcept; +void from_json(const json& j, UploadLogsRequest& k); + +void to_json(json& j, const UploadLogsResponse& k) noexcept; +void from_json(const json& j, UploadLogsResponse& k); + +void to_json(json& j, const LogStatus& k) noexcept; +void from_json(const json& j, LogStatus& k); + +void to_json(json& j, const FirmwareUpdateStatus& k) noexcept; +void from_json(const json& j, FirmwareUpdateStatus& k); + +void to_json(json& j, const ResetRequest& k) noexcept; +void from_json(const json& j, ResetRequest& k); + +void to_json(json& j, const UpdateFirmwareResponse& k) noexcept; +void from_json(const json& j, UpdateFirmwareResponse& k); + +void to_json(json& j, const UploadLogsStatus& k) noexcept; +void from_json(const json& j, UploadLogsStatus& k); + +void to_json(json& j, const LogStatusEnum& k) noexcept; +void from_json(const json& j, LogStatusEnum& k); + +void to_json(json& j, const FirmwareUpdateStatusEnum& k) noexcept; +void from_json(const json& j, FirmwareUpdateStatusEnum& k); + +void to_json(json& j, const ResetType& k) noexcept; +void from_json(const json& j, ResetType& k); + +void to_json(json& j, const BootReason& k) noexcept; +void from_json(const json& j, BootReason& k); + +} // namespace everest::lib::API::V1_0::types::system diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/system/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/system/wrapper.hpp new file mode 100644 index 0000000000..7ee2e52964 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/system/wrapper.hpp @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/system.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::system { + +using UpdateFirmwareResponse_Internal = ::types::system::UpdateFirmwareResponse; +using UpdateFirmwareResponse_External = UpdateFirmwareResponse; + +UpdateFirmwareResponse_Internal toInternalApi(UpdateFirmwareResponse_External const& val); +UpdateFirmwareResponse_External toExternalApi(UpdateFirmwareResponse_Internal const& val); + +using UploadLogsStatus_Internal = ::types::system::UploadLogsStatus; +using UploadLogsStatus_External = UploadLogsStatus; + +UploadLogsStatus_Internal toInternalApi(UploadLogsStatus_External const& val); +UploadLogsStatus_External toExternalApi(UploadLogsStatus_Internal const& val); + +using LogStatusEnum_Internal = ::types::system::LogStatusEnum; +using LogStatusEnum_External = LogStatusEnum; + +LogStatusEnum_Internal toInternalApi(LogStatusEnum_External const& val); +LogStatusEnum_External toExternalApi(LogStatusEnum_Internal const& val); + +using FirmwareUpdateStatusEnum_Internal = ::types::system::FirmwareUpdateStatusEnum; +using FirmwareUpdateStatusEnum_External = FirmwareUpdateStatusEnum; + +FirmwareUpdateStatusEnum_Internal toInternalApi(FirmwareUpdateStatusEnum_External const& val); +FirmwareUpdateStatusEnum_External toExternalApi(FirmwareUpdateStatusEnum_Internal const& val); + +using ResetType_Internal = ::types::system::ResetType; +using ResetType_External = ResetType; + +ResetType_Internal toInternalApi(ResetType_External const& val); +ResetType_External toExternalApi(ResetType_Internal const& val); + +using BootReason_Internal = ::types::system::BootReason; +using BootReason_External = BootReason; + +BootReason_Internal toInternalApi(BootReason_External const& val); +BootReason_External toExternalApi(BootReason_Internal const& val); + +using FirmwareUpdateRequest_Internal = ::types::system::FirmwareUpdateRequest; +using FirmwareUpdateRequest_External = FirmwareUpdateRequest; + +FirmwareUpdateRequest_Internal toInternalApi(FirmwareUpdateRequest_External const& val); +FirmwareUpdateRequest_External toExternalApi(FirmwareUpdateRequest_Internal const& val); + +using UploadLogsRequest_Internal = ::types::system::UploadLogsRequest; +using UploadLogsRequest_External = UploadLogsRequest; + +UploadLogsRequest_Internal toInternalApi(UploadLogsRequest_External const& val); +UploadLogsRequest_External toExternalApi(UploadLogsRequest_Internal const& val); + +using UploadLogsResponse_Internal = ::types::system::UploadLogsResponse; +using UploadLogsResponse_External = UploadLogsResponse; + +UploadLogsResponse_Internal toInternalApi(UploadLogsResponse_External const& val); +UploadLogsResponse_External toExternalApi(UploadLogsResponse_Internal const& val); + +using LogStatus_Internal = ::types::system::LogStatus; +using LogStatus_External = LogStatus; + +LogStatus_Internal toInternalApi(LogStatus_External const& val); +LogStatus_External toExternalApi(LogStatus_Internal const& val); + +using FirmwareUpdateStatus_Internal = ::types::system::FirmwareUpdateStatus; +using FirmwareUpdateStatus_External = FirmwareUpdateStatus; + +FirmwareUpdateStatus_Internal toInternalApi(FirmwareUpdateStatus_External const& val); +FirmwareUpdateStatus_External toExternalApi(FirmwareUpdateStatus_Internal const& val); + +using FirmwareUpdateStatus_Internal = ::types::system::FirmwareUpdateStatus; +using FirmwareUpdateStatus_External = FirmwareUpdateStatus; + +FirmwareUpdateStatus_Internal toInternalApi(FirmwareUpdateStatus_External const& val); +FirmwareUpdateStatus_External toExternalApi(FirmwareUpdateStatus_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::system diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/uk_random_delay/json_codec.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/uk_random_delay/json_codec.hpp new file mode 100644 index 0000000000..313babb2db --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/uk_random_delay/json_codec.hpp @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include "nlohmann/json_fwd.hpp" +#include + +namespace everest::lib::API::V1_0::types::uk_random_delay { + +using json = nlohmann::json; + +void to_json(json& j, const CountDown& k) noexcept; +void from_json(const json& j, CountDown& k); + +} // namespace everest::lib::API::V1_0::types::uk_random_delay diff --git a/lib/everest/everest_api_types/private_include/everest_api_types/uk_random_delay/wrapper.hpp b/lib/everest/everest_api_types/private_include/everest_api_types/uk_random_delay/wrapper.hpp new file mode 100644 index 0000000000..c76cbf8040 --- /dev/null +++ b/lib/everest/everest_api_types/private_include/everest_api_types/uk_random_delay/wrapper.hpp @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include "generated/types/uk_random_delay.hpp" +#pragma GCC diagnostic pop + +namespace everest::lib::API::V1_0::types::uk_random_delay { + +using CountDown_Internal = ::types::uk_random_delay::CountDown; +using CountDown_External = CountDown; + +CountDown_Internal toInternalApi(CountDown_External const& val); +CountDown_External toExternalApi(CountDown_Internal const& val); + +} // namespace everest::lib::API::V1_0::types::uk_random_delay diff --git a/lib/everest/everest_api_types/private_include/utils/date.hpp b/lib/everest/everest_api_types/private_include/utils/date.hpp new file mode 100644 index 0000000000..59a3c22cbc --- /dev/null +++ b/lib/everest/everest_api_types/private_include/utils/date.hpp @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once + +#include +#include + +namespace everest::utils { + +std::string to_rfc3339(const std::chrono::time_point& t); + +std::chrono::time_point from_rfc3339(const std::string& t); + +} // namespace everest::utils diff --git a/lib/everest/everest_api_types/src/everest_api_types/auth/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/auth/codec.cpp new file mode 100644 index 0000000000..168bf4ae2e --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/auth/codec.cpp @@ -0,0 +1,237 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "auth/codec.hpp" +#include "auth/API.hpp" +#include "auth/json_codec.hpp" +#include "nlohmann/json.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::auth { + +std::string serialize(AuthorizationStatus val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(CertificateStatus val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(TokenValidationStatus val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SelectionAlgorithm val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(AuthorizationType val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(IdTokenType val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(CustomIdToken const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(IdToken const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(WithdrawAuthorizationResult val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ProvidedIdToken const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(TokenValidationStatusMessage const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ValidationResult const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ValidationResultUpdate const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(WithdrawAuthorizationRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, AuthorizationStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, CertificateStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, TokenValidationStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SelectionAlgorithm const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, AuthorizationType const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, IdTokenType const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, WithdrawAuthorizationResult const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, CustomIdToken const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, IdToken const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ProvidedIdToken const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, TokenValidationStatusMessage const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ValidationResult const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ValidationResultUpdate const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, WithdrawAuthorizationRequest const& val) { + os << serialize(val); + return os; +} + +template <> AuthorizationStatus deserialize(std::string const& val) { + auto data = json::parse(val); + AuthorizationStatus obj = data; + return obj; +} + +template <> CertificateStatus deserialize<>(std::string const& val) { + auto data = json::parse(val); + CertificateStatus obj = data; + return obj; +} + +template <> TokenValidationStatus deserialize<>(std::string const& val) { + auto data = json::parse(val); + TokenValidationStatus obj = data; + return obj; +} + +template <> SelectionAlgorithm deserialize<>(std::string const& val) { + auto data = json::parse(val); + SelectionAlgorithm obj = data; + return obj; +} + +template <> AuthorizationType deserialize<>(std::string const& val) { + auto data = json::parse(val); + AuthorizationType obj = data; + return obj; +} + +template <> IdTokenType deserialize<>(std::string const& val) { + auto data = json::parse(val); + IdTokenType obj = data; + return obj; +} + +template <> WithdrawAuthorizationResult deserialize<>(std::string const& val) { + auto data = json::parse(val); + WithdrawAuthorizationResult obj = data; + return obj; +} + +template <> CustomIdToken deserialize<>(const std::string& val) { + auto data = json::parse(val); + CustomIdToken obj = data; + return obj; +} + +template <> IdToken deserialize<>(const std::string& val) { + auto data = json::parse(val); + IdToken obj = data; + return obj; +} + +template <> ProvidedIdToken deserialize<>(const std::string& val) { + auto data = json::parse(val); + ProvidedIdToken obj = data; + return obj; +} + +template <> TokenValidationStatusMessage deserialize<>(const std::string& val) { + auto data = json::parse(val); + TokenValidationStatusMessage obj = data; + return obj; +} + +template <> ValidationResult deserialize<>(const std::string& val) { + auto data = json::parse(val); + ValidationResult obj = data; + return obj; +} + +template <> ValidationResultUpdate deserialize<>(const std::string& val) { + auto data = json::parse(val); + ValidationResultUpdate obj = data; + return obj; +} + +template <> WithdrawAuthorizationRequest deserialize<>(std::string const& val) { + auto data = json::parse(val); + WithdrawAuthorizationRequest obj = data; + return obj; +} + +} // namespace everest::lib::API::V1_0::types::auth diff --git a/lib/everest/everest_api_types/src/everest_api_types/auth/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/auth/json_codec.cpp new file mode 100644 index 0000000000..ced95032a3 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/auth/json_codec.cpp @@ -0,0 +1,631 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "display_message/json_codec.hpp" +#include "auth/API.hpp" +#include "auth/codec.hpp" +#include "auth/json_codec.hpp" +#include "nlohmann/json.hpp" + +namespace everest::lib::API::V1_0::types::auth { + +void to_json(json& j, AuthorizationStatus const& k) noexcept { + switch (k) { + case AuthorizationStatus::Accepted: + j = "Accepted"; + return; + case AuthorizationStatus::Blocked: + j = "Blocked"; + return; + case AuthorizationStatus::ConcurrentTx: + j = "ConcurrentTx"; + return; + case AuthorizationStatus::Expired: + j = "Expired"; + return; + case AuthorizationStatus::Invalid: + j = "Invalid"; + return; + case AuthorizationStatus::NoCredit: + j = "NoCredit"; + return; + case AuthorizationStatus::NotAllowedTypeEVSE: + j = "NotAllowedTypeEVSE"; + return; + case AuthorizationStatus::NotAtThisLocation: + j = "NotAtThisLocation"; + return; + case AuthorizationStatus::NotAtThisTime: + j = "NotAtThisTime"; + return; + case AuthorizationStatus::Unknown: + j = "Unknown"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::auth::AuthorizationStatus"; +} + +void from_json(const json& j, AuthorizationStatus& k) { + std::string s = j; + if (s == "Accepted") { + k = AuthorizationStatus::Accepted; + return; + } + if (s == "Blocked") { + k = AuthorizationStatus::Blocked; + return; + } + if (s == "ConcurrentTx") { + k = AuthorizationStatus::ConcurrentTx; + return; + } + if (s == "Expired") { + k = AuthorizationStatus::Expired; + return; + } + if (s == "Invalid") { + k = AuthorizationStatus::Invalid; + return; + } + if (s == "NoCredit") { + k = AuthorizationStatus::NoCredit; + return; + } + if (s == "NotAllowedTypeEVSE") { + k = AuthorizationStatus::NotAllowedTypeEVSE; + return; + } + if (s == "NotAtThisLocation") { + k = AuthorizationStatus::NotAtThisLocation; + return; + } + if (s == "NotAtThisTime") { + k = AuthorizationStatus::NotAtThisTime; + return; + } + if (s == "Unknown") { + k = AuthorizationStatus::Unknown; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::AuthorizationStatus"); +} + +void to_json(json& j, CertificateStatus const& k) noexcept { + switch (k) { + case CertificateStatus::Accepted: + j = "Accepted"; + return; + case CertificateStatus::SignatureError: + j = "SignatureError"; + return; + case CertificateStatus::CertificateExpired: + j = "CertificateExpired"; + return; + case CertificateStatus::CertificateRevoked: + j = "CertificateRevoked"; + return; + case CertificateStatus::NoCertificateAvailable: + j = "NoCertificateAvailable"; + return; + case CertificateStatus::CertChainError: + j = "CertChainError"; + return; + case CertificateStatus::ContractCancelled: + j = "ContractCancelled"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::auth::CertificateStatus"; +} + +void from_json(const json& j, CertificateStatus& k) { + std::string s = j; + if (s == "Accepted") { + k = CertificateStatus::Accepted; + return; + } + if (s == "SignatureError") { + k = CertificateStatus::SignatureError; + return; + } + if (s == "CertificateExpired") { + k = CertificateStatus::CertificateExpired; + return; + } + if (s == "CertificateRevoked") { + k = CertificateStatus::CertificateRevoked; + return; + } + if (s == "NoCertificateAvailable") { + k = CertificateStatus::NoCertificateAvailable; + return; + } + if (s == "CertChainError") { + k = CertificateStatus::CertChainError; + return; + } + if (s == "ContractCancelled") { + k = CertificateStatus::ContractCancelled; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::CertificateStatus"); +} + +void to_json(json& j, TokenValidationStatus const& k) noexcept { + switch (k) { + case TokenValidationStatus::Processing: + j = "Processing"; + return; + case TokenValidationStatus::Accepted: + j = "Accepted"; + return; + case TokenValidationStatus::Rejected: + j = "Rejected"; + return; + case TokenValidationStatus::TimedOut: + j = "TimedOut"; + return; + case TokenValidationStatus::Withdrawn: + j = "Withdrawn"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::auth::TokenValidationStatus"; +} + +void from_json(const json& j, TokenValidationStatus& k) { + std::string s = j; + if (s == "Processing") { + k = TokenValidationStatus::Processing; + return; + } + if (s == "Accepted") { + k = TokenValidationStatus::Accepted; + return; + } + if (s == "Rejected") { + k = TokenValidationStatus::Rejected; + return; + } + if (s == "TimedOut") { + k = TokenValidationStatus::TimedOut; + return; + } + if (s == "Withdrawn") { + k = TokenValidationStatus::Withdrawn; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::TokenValidationStatus"); +} + +void to_json(json& j, SelectionAlgorithm const& k) noexcept { + switch (k) { + case SelectionAlgorithm::UserInput: + j = "UserInput"; + return; + case SelectionAlgorithm::PlugEvents: + j = "PlugEvents"; + return; + case SelectionAlgorithm::FindFirst: + j = "FindFirst"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::auth::SelectedAlgorithm"; +} + +void from_json(const json& j, SelectionAlgorithm& k) { + std::string s = j; + if (s == "UserInput") { + k = SelectionAlgorithm::UserInput; + return; + } + if (s == "PlugEvents") { + k = SelectionAlgorithm::PlugEvents; + return; + } + if (s == "FindFirst") { + k = SelectionAlgorithm::FindFirst; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::SelectionAlgorithm"); +} + +void to_json(json& j, AuthorizationType const& k) noexcept { + switch (k) { + case AuthorizationType::OCPP: + j = "OCPP"; + return; + case AuthorizationType::RFID: + j = "RFID"; + return; + case AuthorizationType::Autocharge: + j = "Autocharge"; + return; + case AuthorizationType::PlugAndCharge: + j = "PlugAndCharge"; + return; + case AuthorizationType::BankCard: + j = "BankCard"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::auth::AuthorizationType"; +} + +void from_json(const json& j, AuthorizationType& k) { + std::string s = j; + if (s == "OCPP") { + k = AuthorizationType::OCPP; + return; + } + if (s == "RFID") { + k = AuthorizationType::RFID; + return; + } + if (s == "Autocharge") { + k = AuthorizationType::Autocharge; + return; + } + if (s == "PlugAndCharge") { + k = AuthorizationType::PlugAndCharge; + return; + } + if (s == "BankCard") { + k = AuthorizationType::BankCard; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::AuthorizationType"); +} + +void to_json(json& j, IdTokenType const& k) noexcept { + switch (k) { + case IdTokenType::Central: + j = "Central"; + return; + case IdTokenType::eMAID: + j = "eMAID"; + return; + case IdTokenType::MacAddress: + j = "MacAddress"; + return; + case IdTokenType::ISO14443: + j = "ISO14443"; + return; + case IdTokenType::ISO15693: + j = "ISO15693"; + return; + case IdTokenType::KeyCode: + j = "KeyCode"; + return; + case IdTokenType::Local: + j = "Local"; + return; + case IdTokenType::NoAuthorization: + j = "NoAuthorization"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::auth::IdTokenType"; +} + +void from_json(const json& j, IdTokenType& k) { + std::string s = j; + if (s == "Central") { + k = IdTokenType::Central; + return; + } + if (s == "eMAID") { + k = IdTokenType::eMAID; + return; + } + if (s == "MacAddress") { + k = IdTokenType::MacAddress; + return; + } + if (s == "ISO14443") { + k = IdTokenType::ISO14443; + return; + } + if (s == "ISO15693") { + k = IdTokenType::ISO15693; + return; + } + if (s == "KeyCode") { + k = IdTokenType::KeyCode; + return; + } + if (s == "Local") { + k = IdTokenType::Local; + return; + } + if (s == "NoAuthorization") { + k = IdTokenType::NoAuthorization; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::IdTokenType"); +} + +void to_json(json& j, WithdrawAuthorizationResult const& k) noexcept { + switch (k) { + case WithdrawAuthorizationResult::Accepted: + j = "Accepted"; + return; + case WithdrawAuthorizationResult::AuthorizationNotFound: + j = "AuthorizationNotFound"; + return; + case WithdrawAuthorizationResult::EvseNotFound: + j = "EvseNotFound"; + return; + case WithdrawAuthorizationResult::Rejected: + j = "Rejected"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::auth::WithdrawAuthorizationResult"; +} + +void from_json(const json& j, WithdrawAuthorizationResult& k) { + std::string s = j; + if (s == "Accepted") { + k = WithdrawAuthorizationResult::Accepted; + return; + } + if (s == "AuthorizationNotFound") { + k = WithdrawAuthorizationResult::AuthorizationNotFound; + return; + } + if (s == "EvseNotFound") { + k = WithdrawAuthorizationResult::EvseNotFound; + return; + } + if (s == "Rejected") { + k = WithdrawAuthorizationResult::Rejected; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::WithdrawAuthorizationResult"); +} + +void to_json(json& j, CustomIdToken const& k) noexcept { + j = json{ + {"value", k.value}, + {"type", k.type}, + }; +} + +void from_json(const json& j, CustomIdToken& k) { + k.value = j.at("value"); + k.type = j.at("type"); +} + +void to_json(json& j, IdToken const& k) noexcept { + j = json{ + {"value", k.value}, + {"type", k.type}, + }; + if (k.additional_info) { + j["additional_info"] = json::array(); + for (auto val : k.additional_info.value()) { + j["additional_info"].push_back(val); + } + + // j["additional_info"] = k.additional_info.value(); + } +} + +void from_json(const json& j, IdToken& k) { + k.value = j.at("value"); + k.type = j.at("type"); + + if (j.contains("additional_info")) { + // std::vector vec = j.at("additional_info"); + json arr = j.at("additional_info"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.additional_info.emplace(vec); + } +} + +void to_json(json& j, ProvidedIdToken const& k) noexcept { + j = json{ + {"id_token", k.id_token}, + {"authorization_type", k.authorization_type}, + }; + + if (k.request_id) { + j["request_id"] = k.request_id.value(); + } + if (k.parent_id_token) { + j["parent_id_token"] = k.parent_id_token.value(); + } + if (k.connectors) { + j["connectors"] = json::array(); + for (auto val : k.connectors.value()) { + j["connectors"].push_back(val); + } + } + if (k.prevalidated) { + j["prevalidated"] = k.prevalidated.value(); + } + if (k.certificate) { + j["certificate"] = k.certificate.value(); + } + /* if (k.iso15118CertificateHashData) { + j["iso15118CertificateHashData"] = json::array(); + for (auto val : k.iso15118CertificateHashData.value()) { + j["iso15118CertificateHashData"].push_back(val); + } + } + */ +} + +void from_json(const json& j, ProvidedIdToken& k) { + k.id_token = j.at("id_token"); + k.authorization_type = j.at("authorization_type"); + + if (j.contains("request_id")) { + k.request_id.emplace(j.at("request_id")); + } + if (j.contains("parent_id_token")) { + k.parent_id_token.emplace(j.at("parent_id_token")); + } + if (j.contains("connectors")) { + json arr = j.at("connectors"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.connectors.emplace(vec); + } + if (j.contains("prevalidated")) { + k.prevalidated.emplace(j.at("prevalidated")); + } + if (j.contains("certificate")) { + k.certificate.emplace(j.at("certificate")); + } + /* if (j.contains("iso15118CertificateHashData")) { + json arr = j.at("iso15118CertificateHashData"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.iso15118CertificateHashData.emplace(vec); + }*/ +} + +void to_json(json& j, TokenValidationStatusMessage const& k) noexcept { + j = json{ + {"token", k.token}, + {"status", k.status}, + }; + if (k.messages) { + j["messages"] = json::array(); + for (auto val : k.messages.value()) { + j["messages"].push_back(val); + } + } +} + +void from_json(const json& j, TokenValidationStatusMessage& k) { + k.token = j.at("token"); + k.status = j.at("status"); + if (j.contains("messages")) { + json arr = j.at("messages"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.messages.emplace(vec); + } +} + +void to_json(json& j, ValidationResult const& k) noexcept { + j = json{ + {"authorization_status", k.authorization_status}, + }; + + if (k.certificate_status) { + j["certificate_status"] = k.certificate_status.value(); + } + if (k.reason) { + j["reason"] = k.reason.value(); + } + if (k.expiry_time) { + j["expiry_time"] = k.expiry_time.value(); + } + if (k.parent_id_token) { + j["parent_id_token"] = k.parent_id_token.value(); + } + if (k.evse_ids) { + j["evse_ids"] = json::array(); + for (auto val : k.evse_ids.value()) { + j["evse_ids"].push_back(val); + } + } + if (k.reservation_id) { + j["reservation_id"] = k.reservation_id.value(); + } +} + +void from_json(const json& j, ValidationResult& k) { + k.authorization_status = j.at("authorization_status"); + + if (j.contains("certificate_status")) { + k.certificate_status.emplace(j.at("certificate_status")); + } + if (j.contains("reason")) { + k.reason.emplace(j.at("reason")); + } + if (j.contains("expiry_time")) { + k.expiry_time.emplace(j.at("expiry_time")); + } + if (j.contains("parent_id_token")) { + k.parent_id_token.emplace(j.at("parent_id_token")); + } + if (j.contains("evse_ids")) { + json arr = j.at("evse_ids"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.evse_ids.emplace(vec); + } + if (j.contains("reservation_id")) { + k.reservation_id.emplace(j.at("reservation_id")); + } +} + +void to_json(json& j, ValidationResultUpdate const& k) noexcept { + j = json{ + {"validation_result", k.validation_result}, + {"connector_id", k.connector_id}, + }; +} + +void from_json(const json& j, ValidationResultUpdate& k) { + k.validation_result = j.at("validation_result"); + k.connector_id = j.at("connector_id"); +} + +void to_json(json& j, WithdrawAuthorizationRequest const& k) noexcept { + j = json({}); + if (k.evse_id) { + j["evse_id"] = k.evse_id.value(); + } + if (k.id_token) { + j["id_token"] = k.id_token.value(); + } +} + +void from_json(json const& j, WithdrawAuthorizationRequest& k) { + if (j.contains("evse_id")) { + k.evse_id.emplace(j.at("evse_id")); + } + if (j.contains("id_token")) { + k.id_token.emplace(j.at("id_token")); + } +} + +} // namespace everest::lib::API::V1_0::types::auth diff --git a/lib/everest/everest_api_types/src/everest_api_types/auth/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/auth/wrapper.cpp new file mode 100644 index 0000000000..99cb61c664 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/auth/wrapper.cpp @@ -0,0 +1,476 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "auth/wrapper.hpp" +#include "auth/API.hpp" +#include "display_message/wrapper.hpp" +#include + +namespace everest::lib::API::V1_0::types { + +namespace { +using namespace auth; +using namespace display_message; +template +auto srcToTarOpt(std::optional const& src, ConvT const& converter) + -> std::optional { + if (src) { + return std::make_optional(converter(src.value())); + } + return std::nullopt; +} + +template auto srcToTarVec(std::vector const& src, ConvT const& converter) { + using TarT = decltype(converter(src[0])); + std::vector result; + for (SrcT const& elem : src) { + result.push_back(converter(elem)); + } + return result; +} + +template +auto optToInternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toInternalApi(val); }); +} + +template +auto optToExternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToExternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToInternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toInternalApi(val); }); +} +} // namespace + +namespace auth { + +AuthorizationStatus_Internal toInternalApi(AuthorizationStatus_External const& val) { + using SrcT = AuthorizationStatus_External; + using TarT = AuthorizationStatus_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Blocked: + return TarT::Blocked; + case SrcT::ConcurrentTx: + return TarT::ConcurrentTx; + case SrcT::Expired: + return TarT::Expired; + case SrcT::Invalid: + return TarT::Invalid; + case SrcT::NoCredit: + return TarT::NoCredit; + case SrcT::NotAllowedTypeEVSE: + return TarT::NotAllowedTypeEVSE; + case SrcT::NotAtThisLocation: + return TarT::NotAtThisLocation; + case SrcT::NotAtThisTime: + return TarT::NotAtThisTime; + case SrcT::Unknown: + return TarT::Unknown; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::AuthorizationStatus_External"); +} + +AuthorizationStatus_External toExternalApi(AuthorizationStatus_Internal const& val) { + using SrcT = AuthorizationStatus_Internal; + using TarT = AuthorizationStatus_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Blocked: + return TarT::Blocked; + case SrcT::ConcurrentTx: + return TarT::ConcurrentTx; + case SrcT::Expired: + return TarT::Expired; + case SrcT::Invalid: + return TarT::Invalid; + case SrcT::NoCredit: + return TarT::NoCredit; + case SrcT::NotAllowedTypeEVSE: + return TarT::NotAllowedTypeEVSE; + case SrcT::NotAtThisLocation: + return TarT::NotAtThisLocation; + case SrcT::NotAtThisTime: + return TarT::NotAtThisTime; + case SrcT::Unknown: + return TarT::Unknown; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::AuthorizationStatus_Internal"); +} + +CertificateStatus_Internal toInternalApi(CertificateStatus_External const& val) { + using SrcT = CertificateStatus_External; + using TarT = CertificateStatus_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::SignatureError: + return TarT::SignatureError; + case SrcT::CertificateExpired: + return TarT::CertificateExpired; + case SrcT::CertificateRevoked: + return TarT::CertificateRevoked; + case SrcT::NoCertificateAvailable: + return TarT::NoCertificateAvailable; + case SrcT::CertChainError: + return TarT::CertChainError; + case SrcT::ContractCancelled: + return TarT::ContractCancelled; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::CertifgicateStatus_External"); +} +CertificateStatus_External toExternalApi(CertificateStatus_Internal const& val) { + using SrcT = CertificateStatus_Internal; + using TarT = CertificateStatus_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::SignatureError: + return TarT::SignatureError; + case SrcT::CertificateExpired: + return TarT::CertificateExpired; + case SrcT::CertificateRevoked: + return TarT::CertificateRevoked; + case SrcT::NoCertificateAvailable: + return TarT::NoCertificateAvailable; + case SrcT::CertChainError: + return TarT::CertChainError; + case SrcT::ContractCancelled: + return TarT::ContractCancelled; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::CertifgicateStatus_Internal"); +} + +TokenValidationStatus_Internal toInternalApi(TokenValidationStatus_External const& val) { + using SrcT = TokenValidationStatus_External; + using TarT = TokenValidationStatus_Internal; + switch (val) { + case SrcT::Processing: + return TarT::Processing; + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::TimedOut: + return TarT::TimedOut; + case SrcT::Withdrawn: + return TarT::Withdrawn; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::auth::TokenValidationStatus_External"); +} +TokenValidationStatus_External toExternalApi(TokenValidationStatus_Internal const& val) { + using SrcT = TokenValidationStatus_Internal; + using TarT = TokenValidationStatus_External; + switch (val) { + case SrcT::Processing: + return TarT::Processing; + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::TimedOut: + return TarT::TimedOut; + case SrcT::Withdrawn: + return TarT::Withdrawn; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::auth::TokenValidationStatus_Internal"); +} + +SelectionAlgorithm_Internal toInternalApi(SelectionAlgorithm_External const& val) { + using SrcT = SelectionAlgorithm_External; + using TarT = SelectionAlgorithm_Internal; + switch (val) { + case SrcT::UserInput: + return TarT::UserInput; + case SrcT::PlugEvents: + return TarT::PlugEvents; + case SrcT::FindFirst: + return TarT::FindFirst; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::SelectedAlgorithm_External"); +} +SelectionAlgorithm_External toExternalApi(SelectionAlgorithm_Internal const& val) { + using SrcT = SelectionAlgorithm_Internal; + using TarT = SelectionAlgorithm_External; + switch (val) { + case SrcT::UserInput: + return TarT::UserInput; + case SrcT::PlugEvents: + return TarT::PlugEvents; + case SrcT::FindFirst: + return TarT::FindFirst; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::SelectedAlgorithm_Internal"); +} + +AuthorizationType_Internal toInternalApi(AuthorizationType_External const& val) { + using SrcT = AuthorizationType_External; + using TarT = AuthorizationType_Internal; + switch (val) { + case SrcT::OCPP: + return TarT::OCPP; + case SrcT::RFID: + return TarT::RFID; + case SrcT::Autocharge: + return TarT::Autocharge; + case SrcT::PlugAndCharge: + return TarT::PlugAndCharge; + case SrcT::BankCard: + return TarT::BankCard; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::AuthoriozationType_External"); +} + +AuthorizationType_External toExternalApi(AuthorizationType_Internal const& val) { + using SrcT = AuthorizationType_Internal; + using TarT = AuthorizationType_External; + switch (val) { + case SrcT::OCPP: + return TarT::OCPP; + case SrcT::RFID: + return TarT::RFID; + case SrcT::Autocharge: + return TarT::Autocharge; + case SrcT::PlugAndCharge: + return TarT::PlugAndCharge; + case SrcT::BankCard: + return TarT::BankCard; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::AuthoriozationType_Internal"); +} + +IdTokenType_Internal toInternalApi(IdTokenType_External const& val) { + using SrcT = IdTokenType_External; + using TarT = IdTokenType_Internal; + switch (val) { + case SrcT::Central: + return TarT::Central; + case SrcT::eMAID: + return TarT::eMAID; + case SrcT::MacAddress: + return TarT::MacAddress; + case SrcT::ISO14443: + return TarT::ISO14443; + case SrcT::ISO15693: + return TarT::ISO15693; + case SrcT::KeyCode: + return TarT::KeyCode; + case SrcT::Local: + return TarT::Local; + case SrcT::NoAuthorization: + return TarT::NoAuthorization; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::IdTokenType_External"); +} + +IdTokenType_External toExternalApi(IdTokenType_Internal const& val) { + using SrcT = IdTokenType_Internal; + using TarT = IdTokenType_External; + switch (val) { + case SrcT::Central: + return TarT::Central; + case SrcT::eMAID: + return TarT::eMAID; + case SrcT::MacAddress: + return TarT::MacAddress; + case SrcT::ISO14443: + return TarT::ISO14443; + case SrcT::ISO15693: + return TarT::ISO15693; + case SrcT::KeyCode: + return TarT::KeyCode; + case SrcT::Local: + return TarT::Local; + case SrcT::NoAuthorization: + return TarT::NoAuthorization; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::auth::IdTokenType_Internal"); +} + +WithdrawAuthorizationResult_Internal toInternalApi(WithdrawAuthorizationResult_External const& val) { + using SrcT = WithdrawAuthorizationResult_External; + using TarT = WithdrawAuthorizationResult_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::AuthorizationNotFound: + return TarT::AuthorizationNotFound; + case SrcT::EvseNotFound: + return TarT::EvseNotFound; + case SrcT::Rejected: + return TarT::Rejected; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::auth::WithdrawAuthorizationResult_External"); +} +WithdrawAuthorizationResult_External toExternalApi(WithdrawAuthorizationResult_Internal const& val) { + using SrcT = WithdrawAuthorizationResult_Internal; + using TarT = WithdrawAuthorizationResult_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::AuthorizationNotFound: + return TarT::AuthorizationNotFound; + case SrcT::EvseNotFound: + return TarT::EvseNotFound; + case SrcT::Rejected: + return TarT::Rejected; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::auth::WithdrawAuthorizationResult_Internal"); +} + +//////// + +CustomIdToken_Internal toInternalApi(CustomIdToken_External const& val) { + CustomIdToken_Internal result; + result.value = val.value; + result.type = val.type; + return result; +} + +CustomIdToken_External toExternalApi(CustomIdToken_Internal const& val) { + CustomIdToken_External result; + result.value = val.value; + result.type = val.type; + return result; +} + +IdToken_Internal toInternalApi(IdToken_External const& val) { + IdToken_Internal result; + result.value = val.value; + result.type = toInternalApi(val.type); + if (val.additional_info) { + std::vector vec; + for (auto const& item : val.additional_info.value()) { + vec.push_back(toInternalApi(item)); + } + result.additional_info.emplace(vec); + } + return result; +} + +IdToken_External toExternalApi(IdToken_Internal const& val) { + IdToken_External result; + result.value = val.value; + result.type = toExternalApi(val.type); + if (val.additional_info) { + std::vector vec; + for (auto const& item : val.additional_info.value()) { + vec.push_back(toExternalApi(item)); + } + result.additional_info.emplace(vec); + } + return result; +} + +ProvidedIdToken_Internal toInternalApi(ProvidedIdToken_External const& val) { + ProvidedIdToken_Internal result; + result.id_token = toInternalApi(val.id_token); + result.authorization_type = toInternalApi(val.authorization_type); + result.request_id = val.request_id; + result.parent_id_token = optToInternal(val.parent_id_token); + result.connectors = val.connectors; + result.prevalidated = val.prevalidated; + result.certificate = val.certificate; + return result; +} + +ProvidedIdToken_External toExternalApi(ProvidedIdToken_Internal const& val) { + ProvidedIdToken_External result; + result.id_token = toExternalApi(val.id_token); + result.authorization_type = toExternalApi(val.authorization_type); + result.request_id = val.request_id; + result.parent_id_token = optToExternal(val.parent_id_token); + result.connectors = val.connectors; + result.prevalidated = val.prevalidated; + result.certificate = val.certificate; + return result; +} + +TokenValidationStatusMessage_Internal toInternalApi(TokenValidationStatusMessage_External const& val) { + TokenValidationStatusMessage_Internal result; + result.token = toInternalApi(val.token); + result.status = toInternalApi(val.status); + if (val.messages) { + result.messages = vecToInternal(val.messages.value()); + } + return result; +} + +TokenValidationStatusMessage_External toExternalApi(TokenValidationStatusMessage_Internal const& val) { + TokenValidationStatusMessage_External result; + result.token = toExternalApi(val.token); + result.status = toExternalApi(val.status); + if (val.messages) { + result.messages = vecToExternal(val.messages.value()); + } + return result; +} + +ValidationResult_Internal toInternalApi(ValidationResult_External const& val) { + ValidationResult_Internal result; + result.authorization_status = toInternalApi(val.authorization_status); + result.certificate_status = optToInternal(val.certificate_status); + // Removed due to incompatible changes in everest-core. Never contained any useful information. + // result.reason = optToInternal(val.reason); + result.expiry_time = val.expiry_time; + result.parent_id_token = optToInternal(val.parent_id_token); + result.evse_ids = val.evse_ids; + result.reservation_id = val.reservation_id; + return result; +} + +ValidationResult_External toExternalApi(ValidationResult_Internal const& val) { + ValidationResult_External result; + result.authorization_status = toExternalApi(val.authorization_status); + result.certificate_status = optToExternal(val.certificate_status); + // Removed due to incompatible changes in everest-core. Never contained any useful information. + // result.reason = optToExternal(val.reason); + result.expiry_time = val.expiry_time; + result.parent_id_token = optToExternal(val.parent_id_token); + result.evse_ids = val.evse_ids; + result.reservation_id = val.reservation_id; + return result; +} + +ValidationResultUpdate_Internal toInternalApi(ValidationResultUpdate_External const& val) { + ValidationResultUpdate_Internal result; + result.validation_result = toInternalApi(val.validation_result); + result.connector_id = val.connector_id; + return result; +} + +ValidationResultUpdate_External toExternalApi(ValidationResultUpdate_Internal const& val) { + ValidationResultUpdate_External result; + result.validation_result = toExternalApi(val.validation_result); + result.connector_id = val.connector_id; + return result; +} + +WithdrawAuthorizationRequest_Internal toInternalApi(WithdrawAuthorizationRequest_External const& val) { + WithdrawAuthorizationRequest_Internal result; + result.evse_id = val.evse_id; + result.id_token = optToInternal(val.id_token); + return result; +} + +WithdrawAuthorizationRequest_External toExternalApi(WithdrawAuthorizationRequest_Internal const& val) { + WithdrawAuthorizationRequest_External result; + result.evse_id = val.evse_id; + result.id_token = optToExternal(val.id_token); + return result; +} + +} // namespace auth +} // namespace everest::lib::API::V1_0::types diff --git a/lib/everest/everest_api_types/src/everest_api_types/display_message/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/display_message/codec.cpp new file mode 100644 index 0000000000..089094e88d --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/display_message/codec.cpp @@ -0,0 +1,234 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "display_message/codec.hpp" +#include "display_message/json_codec.hpp" +#include "nlohmann/json.hpp" + +namespace everest::lib::API::V1_0::types::display_message { + +std::string serialize(MessagePriorityEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(MessageStateEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(DisplayMessageStatusEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ClearMessageResponseEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(MessageFormat val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Identifier_type val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(MessageContent const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(DisplayMessage const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetDisplayMessageRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetDisplayMessageResponse const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(GetDisplayMessageRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(GetDisplayMessageResponse const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ClearDisplayMessageRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ClearDisplayMessageResponse const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, MessagePriorityEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, MessageStateEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, DisplayMessageStatusEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ClearMessageResponseEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, MessageFormat const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Identifier_type const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, MessageContent const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, DisplayMessage const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetDisplayMessageRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetDisplayMessageResponse const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, GetDisplayMessageRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, GetDisplayMessageResponse const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ClearDisplayMessageRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ClearDisplayMessageResponse const& val) { + os << serialize(val); + return os; +} + +template <> MessagePriorityEnum deserialize(std::string const& val) { + auto data = json::parse(val); + MessagePriorityEnum obj = data; + return obj; +} + +template <> MessageStateEnum deserialize(std::string const& val) { + auto data = json::parse(val); + MessageStateEnum obj = data; + return obj; +} + +template <> DisplayMessageStatusEnum deserialize(std::string const& val) { + auto data = json::parse(val); + DisplayMessageStatusEnum obj = data; + return obj; +} + +template <> ClearMessageResponseEnum deserialize(std::string const& val) { + auto data = json::parse(val); + ClearMessageResponseEnum obj = data; + return obj; +} + +template <> MessageFormat deserialize(std::string const& val) { + auto data = json::parse(val); + MessageFormat obj = data; + return obj; +} + +template <> Identifier_type deserialize(std::string const& val) { + auto data = json::parse(val); + Identifier_type obj = data; + return obj; +} + +template <> MessageContent deserialize(std::string const& val) { + auto data = json::parse(val); + MessageContent obj = data; + return obj; +} + +template <> DisplayMessage deserialize(std::string const& val) { + auto data = json::parse(val); + DisplayMessage obj = data; + return obj; +} + +template <> SetDisplayMessageRequest deserialize(std::string const& val) { + auto data = json::parse(val); + SetDisplayMessageRequest obj = data; + return obj; +} + +template <> SetDisplayMessageResponse deserialize(std::string const& val) { + auto data = json::parse(val); + SetDisplayMessageResponse obj = data; + return obj; +} + +template <> GetDisplayMessageRequest deserialize(std::string const& val) { + auto data = json::parse(val); + GetDisplayMessageRequest obj = data; + return obj; +} + +template <> GetDisplayMessageResponse deserialize(std::string const& val) { + auto data = json::parse(val); + GetDisplayMessageResponse obj = data; + return obj; +} + +template <> ClearDisplayMessageRequest deserialize(std::string const& val) { + auto data = json::parse(val); + ClearDisplayMessageRequest obj = data; + return obj; +} + +template <> ClearDisplayMessageResponse deserialize(std::string const& val) { + auto data = json::parse(val); + ClearDisplayMessageResponse obj = data; + return obj; +} + +} // namespace everest::lib::API::V1_0::types::display_message diff --git a/lib/everest/everest_api_types/src/everest_api_types/display_message/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/display_message/json_codec.cpp new file mode 100644 index 0000000000..cd04b59013 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/display_message/json_codec.cpp @@ -0,0 +1,477 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "display_message/json_codec.hpp" +#include "display_message/API.hpp" +#include "display_message/codec.hpp" +#include "nlohmann/json.hpp" + +namespace everest::lib::API::V1_0::types::display_message { + +void to_json(json& j, MessagePriorityEnum const& k) noexcept { + switch (k) { + case MessagePriorityEnum::AlwaysFront: + j = "AlwaysFront"; + return; + case MessagePriorityEnum::InFront: + j = "InFront"; + return; + case MessagePriorityEnum::NormalCycle: + j = "NormalCycle"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::display_message::MessagePriorityEnum"; +} + +void from_json(const json& j, MessagePriorityEnum& k) { + std::string s = j; + if (s == "AlwaysFront") { + k = MessagePriorityEnum::AlwaysFront; + return; + } + if (s == "InFront") { + k = MessagePriorityEnum::InFront; + return; + } + if (s == "NormalCycle") { + k = MessagePriorityEnum::NormalCycle; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::MessagePriorityEnum"); +} + +void to_json(json& j, MessageStateEnum const& k) noexcept { + switch (k) { + case MessageStateEnum::Charging: + j = "Charging"; + return; + case MessageStateEnum::Faulted: + j = "Faulted"; + return; + case MessageStateEnum::Idle: + j = "Idle"; + return; + case MessageStateEnum::Unavailable: + j = "Unavailable"; + return; + case MessageStateEnum::Suspending: + j = "Suspending"; + return; + case MessageStateEnum::Discharging: + j = "Discharging"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::display_message::MessageStateEnum"; +} + +void from_json(const json& j, MessageStateEnum& k) { + std::string s = j; + if (s == "Charging") { + k = MessageStateEnum::Charging; + return; + } + if (s == "Faulted") { + k = MessageStateEnum::Faulted; + return; + } + if (s == "Idle") { + k = MessageStateEnum::Idle; + return; + } + if (s == "Unavailable") { + k = MessageStateEnum::Unavailable; + return; + } + if (s == "Suspending") { + k = MessageStateEnum::Suspending; + return; + } + if (s == "Discharging") { + k = MessageStateEnum::Discharging; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::MessageStateEnum"); +} + +void to_json(json& j, DisplayMessageStatusEnum const& k) noexcept { + switch (k) { + case DisplayMessageStatusEnum::Accepted: + j = "Accepted"; + return; + case DisplayMessageStatusEnum::NotSupportedMessageFormat: + j = "NotSupportedMessageFormat"; + return; + case DisplayMessageStatusEnum::Rejected: + j = "Rejected"; + return; + case DisplayMessageStatusEnum::NotSupportedPriority: + j = "NotSupportedPriority"; + return; + case DisplayMessageStatusEnum::NotSupportedState: + j = "NotSupportedState"; + return; + case DisplayMessageStatusEnum::UnknownTransaction: + j = "UnknownTransaction"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::display_message::MessageStateEnum"; +} + +void from_json(const json& j, DisplayMessageStatusEnum& k) { + std::string s = j; + if (s == "Accepted") { + k = DisplayMessageStatusEnum::Accepted; + return; + } + if (s == "NotSupportedMessageFormat") { + k = DisplayMessageStatusEnum::NotSupportedMessageFormat; + return; + } + if (s == "Rejected") { + k = DisplayMessageStatusEnum::Rejected; + return; + } + if (s == "NotSupportedPriority") { + k = DisplayMessageStatusEnum::NotSupportedPriority; + return; + } + if (s == "NotSupportedState") { + k = DisplayMessageStatusEnum::NotSupportedState; + return; + } + if (s == "UnknownTransaction") { + k = DisplayMessageStatusEnum::UnknownTransaction; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::MessageStateEnum"); +} + +void to_json(json& j, ClearMessageResponseEnum const& k) noexcept { + switch (k) { + case ClearMessageResponseEnum::Accepted: + j = "Accepted"; + return; + case ClearMessageResponseEnum::Unknown: + j = "Unknown"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::display_message::ClearMessageResponseEnum"; +} + +void from_json(const json& j, ClearMessageResponseEnum& k) { + std::string s = j; + if (s == "Accepted") { + k = ClearMessageResponseEnum::Accepted; + return; + } + if (s == "Unknown") { + k = ClearMessageResponseEnum::Unknown; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::auth::ClearMessageResponseEnum"); +} + +void to_json(json& j, MessageFormat const& k) noexcept { + switch (k) { + case MessageFormat::ASCII: + j = "ASCII"; + return; + case MessageFormat::HTML: + j = "HTML"; + return; + case MessageFormat::URI: + j = "URI"; + return; + case MessageFormat::UTF8: + j = "UTF8"; + return; + case MessageFormat::QRCODE: + j = "QRCODE"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::display_message::MessageFormat"; +} + +void from_json(const json& j, MessageFormat& k) { + std::string s = j; + if (s == "ASCII") { + k = MessageFormat::ASCII; + return; + } + if (s == "HTML") { + k = MessageFormat::HTML; + return; + } + if (s == "URI") { + k = MessageFormat::URI; + return; + } + if (s == "UTF8") { + k = MessageFormat::UTF8; + return; + } + if (s == "QRCODE") { + k = MessageFormat::QRCODE; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::display_messages::MessageFormat"); +} + +void to_json(json& j, Identifier_type const& k) noexcept { + switch (k) { + case Identifier_type::IdToken: + j = "IdToken"; + return; + case Identifier_type::SessionId: + j = "SessionId"; + return; + case Identifier_type::TransactionId: + j = "TransactionId"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::display_message::Identifier_type"; +} + +void from_json(const json& j, Identifier_type& k) { + std::string s = j; + if (s == "IdToken") { + k = Identifier_type::IdToken; + return; + } + if (s == "SessionId") { + k = Identifier_type::SessionId; + return; + } + if (s == "TransactionId") { + k = Identifier_type::TransactionId; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::dispaly_messages::Identifier_type"); +} + +void to_json(json& j, MessageContent const& k) noexcept { + j = json{ + {"content", k.content}, + }; + if (k.format) { + j["format"] = k.format.value(); + } + if (k.language) { + j["language"] = k.language.value(); + } +} +void from_json(const json& j, MessageContent& k) { + k.content = j.at("content"); + if (j.contains("format")) { + k.format.emplace(j.at("format")); + } + if (j.contains("language")) { + k.language.emplace(j.at("language")); + } +} + +void to_json(json& j, DisplayMessage const& k) noexcept { + j = json{ + {"message", k.message}, + }; + if (k.id) { + j["id"] = k.id.value(); + } + if (k.priority) { + j["priority"] = k.priority.value(); + } + if (k.state) { + j["state"] = k.state.value(); + } + if (k.timestamp_from) { + j["timestamp_from"] = k.timestamp_from.value(); + } + if (k.timestamp_to) { + j["timestamp_to"] = k.timestamp_to.value(); + } + if (k.identifier_id) { + j["identifier_id"] = k.identifier_id.value(); + } + if (k.identifier_type) { + j["identifier_type"] = k.identifier_type.value(); + } + if (k.qr_code) { + j["qr_code"] = k.qr_code.value(); + } +} + +void from_json(const json& j, DisplayMessage& k) { + k.message = j.at("message"); + if (j.contains("id")) { + k.id.emplace(j.at("id")); + } + if (j.contains("priority")) { + k.priority.emplace(j.at("priority")); + } + if (j.contains("state")) { + k.state.emplace(j.at("state")); + } + if (j.contains("timestamp_from")) { + k.timestamp_from.emplace(j.at("timestamp_from")); + } + if (j.contains("timestamp_to")) { + k.timestamp_to.emplace(j.at("timestamp_to")); + } + if (j.contains("identifier_id")) { + k.identifier_id.emplace(j.at("identifier_id")); + } + if (j.contains("identifier_type")) { + k.identifier_type.emplace(j.at("identifier_type")); + } + if (j.contains("qr_code")) { + k.qr_code.emplace(j.at("qr_code")); + } +} + +void to_json(json& j, SetDisplayMessageRequest const& k) noexcept { + j = json::array(); + for (auto val : k.display_messages) { + j.push_back(val); + } +} + +void from_json(const json& j, SetDisplayMessageRequest& k) { + k.display_messages.clear(); + for (auto val : j) { + k.display_messages.push_back(val); + } +} + +void to_json(json& j, SetDisplayMessageResponse const& k) noexcept { + j = json{ + {"status", k.status}, + }; + if (k.status_info) { + j["status_info"] = k.status_info.value(); + } +} + +void from_json(const json& j, SetDisplayMessageResponse& k) { + k.status = j.at("status"); + if (j.contains("status_info")) { + k.status_info.emplace(j.at("status_info")); + } +} + +void to_json(json& j, GetDisplayMessageRequest const& k) noexcept { + j = json({}); + if (k.id) { + if (j.size() == 0) { + j = json{{"id", json::array()}}; + } else { + j["id"] = json::array(); + } + for (auto val : k.id.value()) { + j["id"].push_back(val); + } + } + if (k.priority) { + j["priority"] = k.priority.value(); + } + if (k.state) { + j["state"] = k.state.value(); + } +} + +void from_json(const json& j, GetDisplayMessageRequest& k) { + if (j.contains("id")) { + json arr = j.at("id"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.id.emplace(vec); + } + if (j.contains("priority")) { + k.priority.emplace(j.at("priority")); + } + if (j.contains("state")) { + k.state.emplace(j.at("state")); + } +} + +void to_json(json& j, GetDisplayMessageResponse const& k) noexcept { + j = json({}); + if (k.status_info) { + j["status_info"] = k.status_info.value(); + } + if (k.messages) { + if (j.size() == 0) { + j = json{{"messages", json::array()}}; + } else { + j["messages"] = json::array(); + } + for (auto val : k.messages.value()) { + j["messages"].push_back(val); + } + } +} + +void from_json(const json& j, GetDisplayMessageResponse& k) { + if (j.contains("status_info")) { + k.status_info.emplace(j.at("status_info")); + } + if (j.contains("messages")) { + json arr = j.at("messages"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.messages.emplace(vec); + } +} + +void to_json(json& j, ClearDisplayMessageRequest const& k) noexcept { + j = json{ + {"id", k.id}, + }; +} + +void from_json(const json& j, ClearDisplayMessageRequest& k) { + k.id = j.at("id"); +} + +void to_json(json& j, ClearDisplayMessageResponse const& k) noexcept { + j = json{ + {"status", k.status}, + }; + if (k.status_info) { + j["status_info"] = k.status_info.value(); + } +} + +void from_json(const json& j, ClearDisplayMessageResponse& k) { + k.status = j.at("status"); + if (j.contains("status_info")) { + k.status_info.emplace(j.at("status_info")); + } +} + +} // namespace everest::lib::API::V1_0::types::display_message diff --git a/lib/everest/everest_api_types/src/everest_api_types/display_message/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/display_message/wrapper.cpp new file mode 100644 index 0000000000..f856f721e7 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/display_message/wrapper.cpp @@ -0,0 +1,378 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "display_message/wrapper.hpp" +#include "display_message/API.hpp" +#include + +namespace everest::lib::API::V1_0::types::display_message { + +namespace { +template +auto srcToTarOpt(std::optional const& src, ConvT const& converter) + -> std::optional { + if (src) { + return std::make_optional(converter(src.value())); + } + return std::nullopt; +} + +template auto srcToTarVec(std::vector const& src, ConvT const& converter) { + using TarT = decltype(converter(src[0])); + std::vector result; + for (SrcT const& elem : src) { + result.push_back(converter(elem)); + } + return result; +} + +template +auto optToInternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toInternalApi(val); }); +} + +template +auto optToExternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToExternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToInternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toInternalApi(val); }); +} +} // namespace + +MessagePriorityEnum_Internal toInternalApi(MessagePriorityEnum_External const& val) { + using SrcT = MessagePriorityEnum_External; + using TarT = MessagePriorityEnum_Internal; + switch (val) { + case SrcT::AlwaysFront: + return TarT::AlwaysFront; + case SrcT::InFront: + return TarT::InFront; + case SrcT::NormalCycle: + return TarT::NormalCycle; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::MessagePriorityEnum_External"); +} + +MessagePriorityEnum_External toExternalApi(MessagePriorityEnum_Internal const& val) { + using SrcT = MessagePriorityEnum_Internal; + using TarT = MessagePriorityEnum_External; + switch (val) { + case SrcT::AlwaysFront: + return TarT::AlwaysFront; + case SrcT::InFront: + return TarT::InFront; + case SrcT::NormalCycle: + return TarT::NormalCycle; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::MessagePriorityEnum_Internal"); +} + +MessageStateEnum_Internal toInternalApi(MessageStateEnum_External const& val) { + using SrcT = MessageStateEnum_External; + using TarT = MessageStateEnum_Internal; + switch (val) { + case SrcT::Charging: + return TarT::Charging; + case SrcT::Faulted: + return TarT::Faulted; + case SrcT::Idle: + return TarT::Idle; + case SrcT::Unavailable: + return TarT::Unavailable; + case SrcT::Suspending: + return TarT::Suspending; + case SrcT::Discharging: + return TarT::Discharging; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::MessageStateEnum_External"); +} + +MessageStateEnum_External toExternalApi(MessageStateEnum_Internal const& val) { + using SrcT = MessageStateEnum_Internal; + using TarT = MessageStateEnum_External; + switch (val) { + case SrcT::Charging: + return TarT::Charging; + case SrcT::Faulted: + return TarT::Faulted; + case SrcT::Idle: + return TarT::Idle; + case SrcT::Unavailable: + return TarT::Unavailable; + case SrcT::Suspending: + return TarT::Suspending; + case SrcT::Discharging: + return TarT::Discharging; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::MessageStateEnum_Internal"); +} + +DisplayMessageStatusEnum_Internal toInternalApi(DisplayMessageStatusEnum_External const& val) { + using SrcT = DisplayMessageStatusEnum_External; + using TarT = DisplayMessageStatusEnum_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::NotSupportedMessageFormat: + return TarT::NotSupportedMessageFormat; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::NotSupportedPriority: + return TarT::NotSupportedPriority; + case SrcT::NotSupportedState: + return TarT::NotSupportedState; + case SrcT::UnknownTransaction: + return TarT::UnknownTransaction; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::DisplayMessageStatusEnum_External"); +} + +DisplayMessageStatusEnum_External toExternalApi(DisplayMessageStatusEnum_Internal const& val) { + using SrcT = DisplayMessageStatusEnum_Internal; + using TarT = DisplayMessageStatusEnum_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::NotSupportedMessageFormat: + return TarT::NotSupportedMessageFormat; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::NotSupportedPriority: + return TarT::NotSupportedPriority; + case SrcT::NotSupportedState: + return TarT::NotSupportedState; + case SrcT::UnknownTransaction: + return TarT::UnknownTransaction; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::DisplayMessageStatusEnum_Internal"); +} + +ClearMessageResponseEnum_Internal toInternalApi(ClearMessageResponseEnum_External const& val) { + using SrcT = ClearMessageResponseEnum_External; + using TarT = ClearMessageResponseEnum_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Unknown: + return TarT::Unknown; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::ClearMessageResponseEnum_External"); +} + +ClearMessageResponseEnum_External toExternalApi(ClearMessageResponseEnum_Internal const& val) { + using SrcT = ClearMessageResponseEnum_Internal; + using TarT = ClearMessageResponseEnum_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Unknown: + return TarT::Unknown; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::ClearMessageResponseEnum_Internal"); +} + +MessageFormat_Internal toInternalApi(MessageFormat_External const& val) { + using SrcT = MessageFormat_External; + using TarT = MessageFormat_Internal; + switch (val) { + case SrcT::ASCII: + return TarT::ASCII; + case SrcT::HTML: + return TarT::HTML; + case SrcT::URI: + return TarT::URI; + case SrcT::UTF8: + return TarT::UTF8; + case SrcT::QRCODE: + return TarT::QRCODE; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::MessageFormat_External"); +} + +MessageFormat_External toExternalApi(MessageFormat_Internal const& val) { + using SrcT = MessageFormat_Internal; + using TarT = MessageFormat_External; + switch (val) { + case SrcT::ASCII: + return TarT::ASCII; + case SrcT::HTML: + return TarT::HTML; + case SrcT::URI: + return TarT::URI; + case SrcT::UTF8: + return TarT::UTF8; + case SrcT::QRCODE: + return TarT::QRCODE; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::MessageFormat_Internal"); +} + +Identifier_type_Internal toInternalApi(Identifier_type_External const& val) { + using SrcT = Identifier_type_External; + using TarT = Identifier_type_Internal; + switch (val) { + case SrcT::IdToken: + return TarT::IdToken; + case SrcT::SessionId: + return TarT::SessionId; + case SrcT::TransactionId: + return TarT::TransactionId; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::Identifier_type_External"); +} + +Identifier_type_External toExternalApi(Identifier_type_Internal const& val) { + using SrcT = Identifier_type_Internal; + using TarT = Identifier_type_External; + switch (val) { + case SrcT::IdToken: + return TarT::IdToken; + case SrcT::SessionId: + return TarT::SessionId; + case SrcT::TransactionId: + return TarT::TransactionId; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::display_message::Identifier_type_Internal"); +} + +MessageContent_Internal toInternalApi(MessageContent_External const& val) { + MessageContent_Internal result; + result.content = val.content; + result.format = optToInternal(val.format); + result.language = val.language; + return result; +} + +MessageContent_External toExternalApi(MessageContent_Internal const& val) { + MessageContent_External result; + result.content = val.content; + result.format = optToExternal(val.format); + result.language = val.language; + return result; +} + +DisplayMessage_Internal toInternalApi(DisplayMessage_External const& val) { + DisplayMessage_Internal result; + result.message = toInternalApi(val.message); + result.id = val.id; + result.priority = optToInternal(val.priority); + result.state = optToInternal(val.state); + result.timestamp_from = val.timestamp_from; + result.timestamp_to = val.timestamp_to; + result.identifier_id = val.identifier_id; + result.identifier_type = optToInternal(val.identifier_type); + result.qr_code = val.qr_code; + return result; +} + +DisplayMessage_External toExternalApi(DisplayMessage_Internal const& val) { + DisplayMessage_External result; + result.message = toExternalApi(val.message); + result.id = val.id; + result.priority = optToExternal(val.priority); + result.state = optToExternal(val.state); + result.timestamp_from = val.timestamp_from; + result.timestamp_to = val.timestamp_to; + result.identifier_id = val.identifier_id; + result.identifier_type = optToExternal(val.identifier_type); + result.qr_code = val.qr_code; + return result; +} + +SetDisplayMessageResponse_Internal toInternalApi(SetDisplayMessageResponse_External const& val) { + SetDisplayMessageResponse_Internal result; + result.status = toInternalApi(val.status); + result.status_info = val.status_info; + return result; +} + +SetDisplayMessageResponse_External toExternalApi(SetDisplayMessageResponse_Internal const& val) { + SetDisplayMessageResponse_External result; + result.status = toExternalApi(val.status); + result.status_info = val.status_info; + return result; +} + +GetDisplayMessageRequest_Internal toInternalApi(GetDisplayMessageRequest_External const& val) { + GetDisplayMessageRequest_Internal result; + if (val.id) { + result.id = val.id.value(); + } + result.priority = optToInternal(val.priority); + result.state = optToInternal(val.state); + return result; +} + +GetDisplayMessageRequest_External toExternalApi(GetDisplayMessageRequest_Internal const& val) { + GetDisplayMessageRequest_External result; + if (val.id) { + result.id = val.id.value(); + } + result.priority = optToExternal(val.priority); + result.state = optToExternal(val.state); + return result; +} + +GetDisplayMessageResponse_Internal toInternalApi(GetDisplayMessageResponse_External const& val) { + GetDisplayMessageResponse_Internal result; + result.status_info = val.status_info; + if (val.messages) { + result.messages = vecToInternal(val.messages.value()); + } + return result; +} + +GetDisplayMessageResponse_External toExternalApi(GetDisplayMessageResponse_Internal const& val) { + GetDisplayMessageResponse_External result; + result.status_info = val.status_info; + if (val.messages) { + result.messages = vecToExternal(val.messages.value()); + } + return result; +} + +ClearDisplayMessageRequest_Internal toInternalApi(ClearDisplayMessageRequest_External const& val) { + ClearDisplayMessageRequest_Internal result; + result.id = val.id; + return result; +} + +ClearDisplayMessageRequest_External toExternalApi(ClearDisplayMessageRequest_Internal const& val) { + ClearDisplayMessageRequest_External result; + result.id = val.id; + return result; +} + +ClearDisplayMessageResponse_Internal toInternalApi(ClearDisplayMessageResponse_External const& val) { + ClearDisplayMessageResponse_Internal result; + result.status = toInternalApi(val.status); + result.status_info = val.status_info; + return result; +} + +ClearDisplayMessageResponse_External toExternalApi(ClearDisplayMessageResponse_Internal const& val) { + ClearDisplayMessageResponse_External result; + result.status = toExternalApi(val.status); + result.status_info = val.status_info; + return result; +} + +} // namespace everest::lib::API::V1_0::types::display_message diff --git a/lib/everest/everest_api_types/src/everest_api_types/energy/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/energy/codec.cpp new file mode 100644 index 0000000000..e58acdd0cc --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/energy/codec.cpp @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "energy/codec.hpp" +#include "energy/API.hpp" +#include "energy/json_codec.hpp" +#include "nlohmann/json.hpp" + +namespace everest::lib::API::V1_0::types::energy { + +std::string serialize(NumberWithSource const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(IntegerWithSource const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(FrequencyWattPoint const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetpointType const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(PricePerkWh const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(LimitsReq const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(LimitsRes const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ScheduleReqEntry const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ScheduleResEntry const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ScheduleSetpointEntry const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ExternalLimits const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(EnforcedLimits const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, NumberWithSource const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, IntegerWithSource const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, FrequencyWattPoint const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetpointType const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, PricePerkWh const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, LimitsReq const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, LimitsRes const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ScheduleReqEntry const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ScheduleResEntry const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ScheduleSetpointEntry const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ExternalLimits const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, EnforcedLimits const& val) { + os << serialize(val); + return os; +} + +template <> NumberWithSource deserialize(std::string const& val) { + auto data = json::parse(val); + NumberWithSource obj = data; + return obj; +} + +template <> IntegerWithSource deserialize(std::string const& val) { + auto data = json::parse(val); + IntegerWithSource obj = data; + return obj; +} + +template <> FrequencyWattPoint deserialize(std::string const& val) { + auto data = json::parse(val); + FrequencyWattPoint obj = data; + return obj; +} + +template <> SetpointType deserialize(std::string const& val) { + auto data = json::parse(val); + SetpointType obj = data; + return obj; +} + +template <> PricePerkWh deserialize(std::string const& val) { + auto data = json::parse(val); + PricePerkWh obj = data; + return obj; +} + +template <> LimitsReq deserialize(std::string const& val) { + auto data = json::parse(val); + LimitsReq obj = data; + return obj; +} + +template <> LimitsRes deserialize(std::string const& val) { + auto data = json::parse(val); + LimitsRes obj = data; + return obj; +} + +template <> ScheduleReqEntry deserialize(std::string const& val) { + auto data = json::parse(val); + ScheduleReqEntry obj = data; + return obj; +} + +template <> ScheduleResEntry deserialize(std::string const& val) { + auto data = json::parse(val); + ScheduleResEntry obj = data; + return obj; +} + +template <> ScheduleSetpointEntry deserialize(std::string const& val) { + auto data = json::parse(val); + ScheduleSetpointEntry obj = data; + return obj; +} + +template <> ExternalLimits deserialize(std::string const& val) { + auto data = json::parse(val); + ExternalLimits obj = data; + return obj; +} + +template <> EnforcedLimits deserialize(std::string const& val) { + auto data = json::parse(val); + EnforcedLimits obj = data; + return obj; +} + +} // namespace everest::lib::API::V1_0::types::energy diff --git a/lib/everest/everest_api_types/src/everest_api_types/energy/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/energy/json_codec.cpp new file mode 100644 index 0000000000..c2d0be4ae2 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/energy/json_codec.cpp @@ -0,0 +1,275 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "energy/json_codec.hpp" +#include "energy/API.hpp" +#include "nlohmann/json.hpp" + +namespace everest::lib::API::V1_0::types::energy { + +void to_json(json& j, NumberWithSource const& k) noexcept { + j = json{ + {"value", k.value}, + {"source", k.source}, + }; +} + +void from_json(const json& j, NumberWithSource& k) { + k.value = j.at("value"); + k.source = j.at("source"); +} + +void to_json(json& j, IntegerWithSource const& k) noexcept { + j = json{ + {"value", k.value}, + {"source", k.source}, + }; +} + +void from_json(const json& j, IntegerWithSource& k) { + k.value = j.at("value"); + k.source = j.at("source"); +} + +void to_json(json& j, FrequencyWattPoint const& k) noexcept { + j = json{ + {"frequency_Hz", k.frequency_Hz}, + {"total_power_W", k.total_power_W}, + }; +} + +void from_json(const json& j, FrequencyWattPoint& k) { + k.frequency_Hz = j.at("frequency_Hz"); + k.total_power_W = j.at("total_power_W"); +} + +void to_json(json& j, SetpointType const& k) noexcept { + j = json{ + {"priority", k.priority}, + {"source", k.source}, + }; + if (k.ac_current_A) { + j["ac_current_A"] = k.ac_current_A.value(); + } + if (k.total_power_W) { + j["total_power_W"] = k.total_power_W.value(); + } + if (k.frequency_table) { + j["frequency_table"] = json::array(); + for (auto val : k.frequency_table.value()) { + j["frequency_table"].push_back(val); + } + } +} + +void from_json(const json& j, SetpointType& k) { + k.priority = j.at("priority"); + k.source = j.at("source"); + + if (j.contains("ac_current_A")) { + k.ac_current_A.emplace(j.at("ac_current_A")); + } + if (j.contains("total_power_W")) { + k.total_power_W.emplace(j.at("total_power_W")); + } + if (j.contains("frequency_table")) { + json arr = j.at("frequency_table"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.frequency_table.emplace(vec); + } +} + +void to_json(json& j, PricePerkWh const& k) noexcept { + j = json{ + {"timestamp", k.timestamp}, + {"value", k.value}, + {"currency", k.currency}, + }; +} + +void from_json(const json& j, PricePerkWh& k) { + k.timestamp = j.at("timestamp"); + k.value = j.at("value"); + k.currency = j.at("currency"); +} + +void to_json(json& j, LimitsReq const& k) noexcept { + j = json({}); + // the optional parts of the type + if (k.total_power_W) { + j["total_power_W"] = k.total_power_W.value(); + } + if (k.ac_max_current_A) { + j["ac_max_current_A"] = k.ac_max_current_A.value(); + } + if (k.ac_min_current_A) { + j["ac_min_current_A"] = k.ac_min_current_A.value(); + } + if (k.ac_max_phase_count) { + j["ac_max_phase_count"] = k.ac_max_phase_count.value(); + } + if (k.ac_min_phase_count) { + j["ac_min_phase_count"] = k.ac_min_phase_count.value(); + } + if (k.ac_supports_changing_phases_during_charging) { + j["ac_supports_changing_phases_during_charging"] = k.ac_supports_changing_phases_during_charging.value(); + } + if (k.ac_number_of_active_phases) { + j["ac_number_of_active_phases"] = k.ac_number_of_active_phases.value(); + } +} + +void from_json(const json& j, LimitsReq& k) { + if (j.contains("total_power_W")) { + k.total_power_W.emplace(j.at("total_power_W")); + } + if (j.contains("ac_max_current_A")) { + k.ac_max_current_A.emplace(j.at("ac_max_current_A")); + } + if (j.contains("ac_min_current_A")) { + k.ac_min_current_A.emplace(j.at("ac_min_current_A")); + } + if (j.contains("ac_max_phase_count")) { + k.ac_max_phase_count.emplace(j.at("ac_max_phase_count")); + } + if (j.contains("ac_min_phase_count")) { + k.ac_min_phase_count.emplace(j.at("ac_min_phase_count")); + } + if (j.contains("ac_supports_changing_phases_during_charging")) { + k.ac_supports_changing_phases_during_charging.emplace(j.at("ac_supports_changing_phases_during_charging")); + } + if (j.contains("ac_number_of_active_phases")) { + k.ac_number_of_active_phases.emplace(j.at("ac_number_of_active_phases")); + } +} + +void to_json(json& j, LimitsRes const& k) noexcept { + j = json({}); + if (k.total_power_W) { + j["total_power_W"] = k.total_power_W.value(); + } + if (k.ac_max_current_A) { + j["ac_max_current_A"] = k.ac_max_current_A.value(); + } + if (k.ac_max_phase_count) { + j["ac_max_phase_count"] = k.ac_max_phase_count.value(); + } +} + +void from_json(const json& j, LimitsRes& k) { + if (j.contains("total_power_W")) { + k.total_power_W.emplace(j.at("total_power_W")); + } + if (j.contains("ac_max_current_A")) { + k.ac_max_current_A.emplace(j.at("ac_max_current_A")); + } + if (j.contains("ac_max_phase_count")) { + k.ac_max_phase_count.emplace(j.at("ac_max_phase_count")); + } +} + +void to_json(json& j, ScheduleReqEntry const& k) noexcept { + j = json{ + {"timestamp", k.timestamp}, + {"limits_to_root", k.limits_to_root}, + {"limits_to_leaves", k.limits_to_leaves}, + }; + + if (k.conversion_efficiency) { + j["conversion_efficiency"] = k.conversion_efficiency.value(); + } + if (k.price_per_kwh) { + j["price_per_kwh"] = k.price_per_kwh.value(); + } +} + +void from_json(const json& j, ScheduleReqEntry& k) { + k.timestamp = j.at("timestamp"); + k.limits_to_root = j.at("limits_to_root"); + k.limits_to_leaves = j.at("limits_to_leaves"); + + if (j.contains("conversion_efficiency")) { + k.conversion_efficiency.emplace(j.at("conversion_efficiency")); + } + if (j.contains("price_per_kwh")) { + k.price_per_kwh.emplace(j.at("price_per_kwh")); + } +} + +void to_json(json& j, ScheduleResEntry const& k) noexcept { + j = json{ + {"timestamp", k.timestamp}, + {"limits_to_root", k.limits_to_root}, + }; + if (k.price_per_kwh) { + j["price_per_kwh"] = k.price_per_kwh.value(); + } +} + +void from_json(const json& j, ScheduleResEntry& k) { + k.timestamp = j.at("timestamp"); + k.limits_to_root = j.at("limits_to_root"); + + if (j.contains("price_per_kwh")) { + k.price_per_kwh.emplace(j.at("price_per_kwh")); + } +} + +void to_json(json& j, ScheduleSetpointEntry const& k) noexcept { + j = json{ + {"timestamp", k.timestamp}, + }; + if (k.setpoint) { + j["setpoint"] = k.setpoint.value(); + } +} + +void from_json(const json& j, ScheduleSetpointEntry& k) { + k.timestamp = j.at("timestamp"); + if (j.contains("setpoint")) { + k.setpoint.emplace(j.at("setpoint")); + } +} + +void to_json(json& j, ExternalLimits const& k) noexcept { + j = json{ + {"schedule_import", k.schedule_import}, + {"schedule_export", k.schedule_export}, + {"schedule_setpoints", k.schedule_setpoints}, + }; +} + +void from_json(const json& j, ExternalLimits& k) { + for (auto val : j.at("schedule_import")) { + k.schedule_import.push_back(val); + } + for (auto val : j.at("schedule_export")) { + k.schedule_export.push_back(val); + } + for (auto val : j.at("schedule_setpoints")) { + k.schedule_setpoints.push_back(val); + } +} + +void to_json(json& j, EnforcedLimits const& k) noexcept { + j = json{ + {"uuid", k.uuid}, + {"valid_for", k.valid_for}, + {"limits_root_side", k.limits_root_side}, + {"schedule", k.schedule}, + }; +} + +void from_json(const json& j, EnforcedLimits& k) { + k.uuid = j.at("uuid"); + k.valid_for = j.at("valid_for"); + k.limits_root_side = j.at("limits_root_side"); + for (auto val : j.at("schedule")) { + k.schedule.push_back(val); + } +} + +} // namespace everest::lib::API::V1_0::types::energy diff --git a/lib/everest/everest_api_types/src/everest_api_types/energy/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/energy/wrapper.cpp new file mode 100644 index 0000000000..58b75c3e83 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/energy/wrapper.cpp @@ -0,0 +1,253 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "energy/wrapper.hpp" +#include "energy/API.hpp" +#include + +namespace everest::lib::API::V1_0::types::energy { + +namespace { +template +auto srcToTarOpt(std::optional const& src, ConvT const& converter) + -> std::optional { + if (src) { + return std::make_optional(converter(src.value())); + } + return std::nullopt; +} + +template auto srcToTarVec(std::vector const& src, ConvT const& converter) { + using TarT = decltype(converter(src[0])); + std::vector result; + for (SrcT const& elem : src) { + result.push_back(converter(elem)); + } + return result; +} + +template +auto optToInternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toInternalApi(val); }); +} + +template +auto optToExternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToExternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToInternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toInternalApi(val); }); +} +} // namespace + +NumberWithSource_Internal toInternalApi(NumberWithSource_External const& val) { + NumberWithSource_Internal result; + result.source = val.source; + result.value = val.value; + return result; +} + +NumberWithSource_External toExternalApi(NumberWithSource_Internal const& val) { + NumberWithSource_External result; + result.source = val.source; + result.value = val.value; + return result; +} + +IntegerWithSource_Internal toInternalApi(IntegerWithSource_External const& val) { + IntegerWithSource_Internal result; + result.source = val.source; + result.value = val.value; + return result; +} + +IntegerWithSource_External toExternalApi(IntegerWithSource_Internal const& val) { + IntegerWithSource_External result; + result.source = val.source; + result.value = val.value; + return result; +} + +FrequencyWattPoint_Internal toInternalApi(FrequencyWattPoint_External const& val) { + FrequencyWattPoint_Internal result; + result.frequency_Hz = val.frequency_Hz; + result.total_power_W = val.total_power_W; + return result; +} + +FrequencyWattPoint_External toExternalApi(FrequencyWattPoint_Internal const& val) { + FrequencyWattPoint_External result; + result.frequency_Hz = val.frequency_Hz; + result.total_power_W = val.total_power_W; + return result; +} + +SetpointType_Internal toInternalApi(SetpointType_External const& val) { + SetpointType_Internal result; + result.priority = val.priority; + result.source = val.source; + result.ac_current_A = val.ac_current_A; + result.total_power_W = val.total_power_W; + if (val.frequency_table) { + result.frequency_table = vecToInternal(val.frequency_table.value()); + } + return result; +} + +SetpointType_External toExternalApi(SetpointType_Internal const& val) { + SetpointType_External result; + result.priority = val.priority; + result.source = val.source; + result.ac_current_A = val.ac_current_A; + result.total_power_W = val.total_power_W; + if (val.frequency_table) { + result.frequency_table = vecToExternal(val.frequency_table.value()); + } + return result; +} + +PricePerkWh_Internal toInternalApi(PricePerkWh_External const& val) { + PricePerkWh_Internal result; + result.timestamp = val.timestamp; + result.value = val.value; + result.currency = val.currency; + return result; +} + +PricePerkWh_External toExternalApi(PricePerkWh_Internal const& val) { + PricePerkWh_External result; + result.timestamp = val.timestamp; + result.value = val.value; + result.currency = val.currency; + return result; +} + +LimitsReq_Internal toInternalApi(LimitsReq_External const& val) { + LimitsReq_Internal result; + result.total_power_W = optToInternal(val.total_power_W); + result.ac_max_current_A = optToInternal(val.ac_max_current_A); + result.ac_min_current_A = optToInternal(val.ac_min_current_A); + result.ac_max_phase_count = optToInternal(val.ac_max_phase_count); + result.ac_min_phase_count = optToInternal(val.ac_min_phase_count); + result.ac_supports_changing_phases_during_charging = val.ac_supports_changing_phases_during_charging; + result.ac_number_of_active_phases = val.ac_number_of_active_phases; + return result; +} + +LimitsReq_External toExternalApi(LimitsReq_Internal const& val) { + LimitsReq_External result; + result.total_power_W = optToExternal(val.total_power_W); + result.ac_max_current_A = optToExternal(val.ac_max_current_A); + result.ac_min_current_A = optToExternal(val.ac_min_current_A); + result.ac_max_phase_count = optToExternal(val.ac_max_phase_count); + result.ac_min_phase_count = optToExternal(val.ac_min_phase_count); + result.ac_supports_changing_phases_during_charging = val.ac_supports_changing_phases_during_charging; + result.ac_number_of_active_phases = val.ac_number_of_active_phases; + return result; +} + +LimitsRes_Internal toInternalApi(LimitsRes_External const& val) { + LimitsRes_Internal result; + result.total_power_W = optToInternal(val.total_power_W); + result.ac_max_current_A = optToInternal(val.ac_max_current_A); + result.ac_max_phase_count = optToInternal(val.ac_max_phase_count); + return result; +} + +LimitsRes_External toExternalApi(LimitsRes_Internal const& val) { + LimitsRes_External result; + result.total_power_W = optToExternal(val.total_power_W); + result.ac_max_current_A = optToExternal(val.ac_max_current_A); + result.ac_max_phase_count = optToExternal(val.ac_max_phase_count); + return result; +} + +ScheduleReqEntry_Internal toInternalApi(ScheduleReqEntry_External const& val) { + ScheduleReqEntry_Internal result; + result.timestamp = val.timestamp; + result.limits_to_root = toInternalApi(val.limits_to_root); + result.limits_to_leaves = toInternalApi(val.limits_to_leaves); + result.conversion_efficiency = val.conversion_efficiency; + result.price_per_kwh = optToInternal(val.price_per_kwh); + return result; +} + +ScheduleReqEntry_External toExternalApi(ScheduleReqEntry_Internal const& val) { + ScheduleReqEntry_External result; + result.timestamp = val.timestamp; + result.limits_to_root = toExternalApi(val.limits_to_root); + result.limits_to_leaves = toExternalApi(val.limits_to_leaves); + result.conversion_efficiency = val.conversion_efficiency; + result.price_per_kwh = optToExternal(val.price_per_kwh); + return result; +} + +ScheduleResEntry_Internal toInternalApi(ScheduleResEntry_External const& val) { + ScheduleResEntry_Internal result; + result.timestamp = val.timestamp; + result.limits_to_root = toInternalApi(val.limits_to_root); + result.price_per_kwh = optToInternal(val.price_per_kwh); + return result; +} + +ScheduleResEntry_External toExternalApi(ScheduleResEntry_Internal const& val) { + ScheduleResEntry_External result; + result.timestamp = val.timestamp; + result.limits_to_root = toExternalApi(val.limits_to_root); + result.price_per_kwh = optToExternal(val.price_per_kwh); + return result; +} + +ScheduleSetpointEntry_Internal toInternalApi(ScheduleSetpointEntry_External const& val) { + ScheduleSetpointEntry_Internal result; + result.setpoint = optToInternal(val.setpoint); + result.timestamp = val.timestamp; + return result; +} + +ScheduleSetpointEntry_External toExternalApi(ScheduleSetpointEntry_Internal const& val) { + ScheduleSetpointEntry_External result; + result.setpoint = optToExternal(val.setpoint); + result.timestamp = val.timestamp; + return result; +} + +ExternalLimits_Internal toInternalApi(ExternalLimits_External const& val) { + ExternalLimits_Internal result; + result.schedule_import = vecToInternal(val.schedule_import); + result.schedule_export = vecToInternal(val.schedule_export); + result.schedule_setpoints = vecToInternal(val.schedule_setpoints); + return result; +} + +ExternalLimits_External toExternalApi(ExternalLimits_Internal const& val) { + ExternalLimits_External result; + result.schedule_import = vecToExternal(val.schedule_import); + result.schedule_export = vecToExternal(val.schedule_export); + return result; +} + +EnforcedLimits_Internal toInternalApi(EnforcedLimits_External const& val) { + EnforcedLimits_Internal result; + result.uuid = val.uuid; + result.valid_for = val.valid_for; + result.limits_root_side = toInternalApi(val.limits_root_side); + result.schedule = vecToInternal(val.schedule); + return result; +} + +EnforcedLimits_External toExternalApi(EnforcedLimits_Internal const& val) { + EnforcedLimits_External result; + result.uuid = val.uuid; + result.valid_for = val.valid_for; + result.limits_root_side = toExternalApi(val.limits_root_side); + result.schedule = vecToExternal(val.schedule); + return result; +} + +} // namespace everest::lib::API::V1_0::types::energy diff --git a/lib/everest/everest_api_types/src/everest_api_types/error_history/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/error_history/codec.cpp new file mode 100644 index 0000000000..c05fe28c68 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/error_history/codec.cpp @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "error_history/codec.hpp" +#include "error_history/API.hpp" +#include "error_history/json_codec.hpp" +#include "nlohmann/json.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::error_history { + +std::string serialize(State val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SeverityFilter val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Severity val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ImplementationIdentifier const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(TimeperiodFilter const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(FilterArguments const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorObject const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorList const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, State const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SeverityFilter const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Severity const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ImplementationIdentifier const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, TimeperiodFilter const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, FilterArguments const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ErrorObject const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ErrorList const& val) { + os << serialize(val); + return os; +} + +template <> State deserialize(std::string const& val) { + auto data = json::parse(val); + State obj = data; + return obj; +} + +template <> SeverityFilter deserialize<>(std::string const& val) { + auto data = json::parse(val); + SeverityFilter obj = data; + return obj; +} + +template <> Severity deserialize<>(std::string const& val) { + auto data = json::parse(val); + Severity obj = data; + return obj; +} + +template <> ImplementationIdentifier deserialize<>(std::string const& val) { + auto data = json::parse(val); + ImplementationIdentifier obj = data; + return obj; +} + +template <> TimeperiodFilter deserialize<>(std::string const& val) { + auto data = json::parse(val); + TimeperiodFilter obj = data; + return obj; +} + +template <> FilterArguments deserialize<>(std::string const& val) { + auto data = json::parse(val); + FilterArguments obj = data; + return obj; +} + +template <> ErrorObject deserialize<>(const std::string& val) { + auto data = json::parse(val); + ErrorObject obj = data; + return obj; +} + +template <> ErrorList deserialize<>(const std::string& val) { + auto data = json::parse(val); + ErrorList obj = data; + return obj; +} + +} // namespace everest::lib::API::V1_0::types::error_history diff --git a/lib/everest/everest_api_types/src/everest_api_types/error_history/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/error_history/json_codec.cpp new file mode 100644 index 0000000000..3053092adc --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/error_history/json_codec.cpp @@ -0,0 +1,222 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "error_history//json_codec.hpp" +#include "error_history/API.hpp" +#include "error_history/codec.hpp" +#include "nlohmann/json.hpp" + +namespace everest::lib::API::V1_0::types::error_history { + +void to_json(json& j, State const& k) noexcept { + switch (k) { + case State::Active: + j = "Active"; + return; + case State::ClearedByModule: + j = "ClearedByModule"; + return; + case State::ClearedByReboot: + j = "ClearedByReboot"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::error_history::State"; +} + +void from_json(const json& j, State& k) { + std::string s = j; + if (s == "Active") { + k = State::Active; + return; + } + if (s == "ClearedByModule") { + k = State::ClearedByModule; + return; + } + if (s == "ClearedByReboot") { + k = State::ClearedByReboot; + return; + } + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::error_history::State"); +} + +void to_json(json& j, SeverityFilter const& k) noexcept { + switch (k) { + case SeverityFilter::HIGH_GE: + j = "HIGH_GE"; + return; + case SeverityFilter::MEDIUM_GE: + j = "MEDIUM_GE"; + return; + case SeverityFilter::LOW_GE: + j = "LOW_GE"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::error_history::SeverityFilter"; +} + +void from_json(const json& j, SeverityFilter& k) { + std::string s = j; + if (s == "HIGH_GE") { + k = SeverityFilter::HIGH_GE; + return; + } + if (s == "MEDIUM_GE") { + k = SeverityFilter::MEDIUM_GE; + return; + } + if (s == "LOW_GE") { + k = SeverityFilter::LOW_GE; + return; + } + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::error_history::SeverityFilter"); +} + +void to_json(json& j, Severity const& k) noexcept { + switch (k) { + case Severity::High: + j = "High"; + return; + case Severity::Medium: + j = "Medium"; + return; + case Severity::Low: + j = "Low"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::error_history::Severity"; +} + +void from_json(const json& j, Severity& k) { + std::string s = j; + if (s == "High") { + k = Severity::High; + return; + } + if (s == "Medium") { + k = Severity::Medium; + return; + } + if (s == "Low") { + k = Severity::Low; + return; + } + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::error_history::Severity"); +} + +void to_json(json& j, ImplementationIdentifier const& k) noexcept { + j = json{ + {"module_id", k.module_id}, + {"implementation_id", k.implementation_id}, + }; +} + +void from_json(const json& j, ImplementationIdentifier& k) { + k.module_id = j.at("module_id"); + k.implementation_id = j.at("implementation_id"); +} + +void to_json(json& j, TimeperiodFilter const& k) noexcept { + j = json{ + {"timestamp_from", k.timestamp_from}, + {"timestamp_to", k.timestamp_to}, + }; +} + +void from_json(const json& j, TimeperiodFilter& k) { + k.timestamp_from = j.at("timestamp_from"); + k.timestamp_to = j.at("timestamp_to"); +} + +void to_json(json& j, FilterArguments const& k) noexcept { + j = json({}); + if (k.state_filter) { + j["state_filter"] = k.state_filter.value(); + } + if (k.origin_filter) { + j["origin_filter"] = k.origin_filter.value(); + } + if (k.type_filter) { + j["type_filter"] = k.type_filter.value(); + } + if (k.severity_filter) { + j["severity_filter"] = k.severity_filter.value(); + } + if (k.timeperiod_filter) { + j["timeperiod_filter"] = k.timeperiod_filter.value(); + } + if (k.handle_filter) { + j["handle_filter"] = k.handle_filter.value(); + } +} + +void from_json(const json& j, FilterArguments& k) { + if (j.contains("state_filter")) { + k.state_filter.emplace(j.at("state_filter")); + } + if (j.contains("origin_filter")) { + k.origin_filter.emplace(j.at("origin_filter")); + } + if (j.contains("type_filter")) { + k.type_filter.emplace(j.at("type_filter")); + } + if (j.contains("severity_filter")) { + k.severity_filter.emplace(j.at("severity_filter")); + } + if (j.contains("timeperiod_filter")) { + k.timeperiod_filter.emplace(j.at("timeperiod_filter")); + } + if (j.contains("handle_filter")) { + k.handle_filter.emplace(j.at("handle_filter")); + } +} + +void to_json(json& j, ErrorObject const& k) noexcept { + j = json{ + {"type", k.type}, {"description", k.description}, {"message", k.message}, {"severity", k.severity}, + {"origin", k.origin}, {"timestamp", k.timestamp}, {"uuid", k.uuid}, {"state", k.state}, + }; + if (k.sub_type) { + j["sub_type"] = k.sub_type.value(); + } +} + +void from_json(const json& j, ErrorObject& k) { + k.type = j.at("type"); + k.description = j.at("description"); + k.message = j.at("message"); + k.severity = j.at("severity"); + k.origin = j.at("origin"); + k.timestamp = j.at("timestamp"); + k.uuid = j.at("uuid"); + k.state = j.at("state"); + + if (j.contains("sub_type")) { + k.sub_type.emplace(j.at("sub_type")); + } +} + +void to_json(json& j, ErrorList const& k) noexcept { + j["errors"] = json::array(); + for (auto val : k.errors) { + j["errors"].push_back(val); + } +} + +void from_json(const json& j, ErrorList& k) { + k.errors.clear(); + for (auto val : j.at("errors")) { + k.errors.push_back(val); + } +} + +} // namespace everest::lib::API::V1_0::types::error_history diff --git a/lib/everest/everest_api_types/src/everest_api_types/error_history/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/error_history/wrapper.cpp new file mode 100644 index 0000000000..766145b984 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/error_history/wrapper.cpp @@ -0,0 +1,226 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "error_history/wrapper.hpp" +#include "error_history/API.hpp" +#include + +namespace everest::lib::API::V1_0::types::error_history { + +namespace { + +template +auto srcToTarOpt(std::optional const& src, ConvT const& converter) + -> std::optional { + if (src) { + return std::make_optional(converter(src.value())); + } + return std::nullopt; +} + +template auto srcToTarVec(std::vector const& src, ConvT const& converter) { + using TarT = decltype(converter(src[0])); + std::vector result; + for (SrcT const& elem : src) { + result.push_back(converter(elem)); + } + return result; +} + +template +auto optToInternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toInternalApi(val); }); +} + +template +auto optToExternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToExternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToInternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toInternalApi(val); }); +} + +} // namespace + +State_Internal toInternalApi(State_External const& val) { + using SrcT = State_External; + using TarT = State_Internal; + switch (val) { + case SrcT::Active: + return TarT::Active; + case SrcT::ClearedByModule: + return TarT::ClearedByModule; + case SrcT::ClearedByReboot: + return TarT::ClearedByReboot; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::error_history::State_External"); +} + +State_External toExternalApi(State_Internal const& val) { + using SrcT = State_Internal; + using TarT = State_External; + switch (val) { + case SrcT::Active: + return TarT::Active; + case SrcT::ClearedByModule: + return TarT::ClearedByModule; + case SrcT::ClearedByReboot: + return TarT::ClearedByReboot; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::error_history::State_Internal"); +} + +SeverityFilter_Internal toInternalApi(SeverityFilter_External const& val) { + using SrcT = SeverityFilter_External; + using TarT = SeverityFilter_Internal; + switch (val) { + case SrcT::HIGH_GE: + return TarT::HIGH_GE; + case SrcT::MEDIUM_GE: + return TarT::MEDIUM_GE; + case SrcT::LOW_GE: + return TarT::LOW_GE; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::error_history::SeverityFilter_External"); +} + +SeverityFilter_External toExternalApi(SeverityFilter_Internal const& val) { + using SrcT = SeverityFilter_Internal; + using TarT = SeverityFilter_External; + switch (val) { + case SrcT::HIGH_GE: + return TarT::HIGH_GE; + case SrcT::MEDIUM_GE: + return TarT::MEDIUM_GE; + case SrcT::LOW_GE: + return TarT::LOW_GE; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::error_history::SeverityFilter_Internal"); +} + +Severity_Internal toInternalApi(Severity_External const& val) { + using SrcT = Severity_External; + using TarT = Severity_Internal; + switch (val) { + case SrcT::High: + return TarT::High; + case SrcT::Medium: + return TarT::Medium; + case SrcT::Low: + return TarT::Low; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::error_history::Severity_External"); +} + +Severity_External toExternalApi(Severity_Internal const& val) { + using SrcT = Severity_Internal; + using TarT = Severity_External; + switch (val) { + case SrcT::High: + return TarT::High; + case SrcT::Medium: + return TarT::Medium; + case SrcT::Low: + return TarT::Low; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::error_history::Severity_Internal"); +} + +ImplementationIdentifier_Internal toInternalApi(ImplementationIdentifier_External const& val) { + ImplementationIdentifier_Internal result; + result.module_id = val.module_id; + result.implementation_id = val.implementation_id; + return result; +} + +ImplementationIdentifier_External toExternalApi(ImplementationIdentifier_Internal const& val) { + ImplementationIdentifier_External result; + result.module_id = val.module_id; + result.implementation_id = val.implementation_id; + return result; +} + +TimeperiodFilter_Internal toInternalApi(TimeperiodFilter_External const& val) { + TimeperiodFilter_Internal result; + result.timestamp_from = val.timestamp_from; + result.timestamp_to = val.timestamp_to; + return result; +} + +TimeperiodFilter_External toExternalApi(TimeperiodFilter_Internal const& val) { + TimeperiodFilter_External result; + result.timestamp_from = val.timestamp_from; + result.timestamp_to = val.timestamp_to; + return result; +} + +FilterArguments_Internal toInternalApi(FilterArguments_External const& val) { + FilterArguments_Internal result; + result.state_filter = optToInternal(val.state_filter); + result.origin_filter = optToInternal(val.origin_filter); + result.type_filter = val.type_filter; + result.severity_filter = optToInternal(val.severity_filter); + result.timeperiod_filter = optToInternal(val.timeperiod_filter); + result.handle_filter = val.handle_filter; + return result; +} + +FilterArguments_External toExternalApi(FilterArguments_Internal const& val) { + FilterArguments_External result; + result.state_filter = optToExternal(val.state_filter); + result.origin_filter = optToExternal(val.origin_filter); + result.type_filter = val.type_filter; + result.severity_filter = optToExternal(val.severity_filter); + result.timeperiod_filter = optToExternal(val.timeperiod_filter); + result.handle_filter = val.handle_filter; + return result; +} + +ErrorObject_Internal toInternalApi(ErrorObject_External const& val) { + ErrorObject_Internal result; + result.type = val.type; + result.description = val.description; + result.message = val.message; + result.severity = toInternalApi(val.severity); + result.origin = toInternalApi(val.origin); + result.timestamp = val.timestamp; + result.uuid = val.uuid; + result.state = toInternalApi(val.state); + result.sub_type = val.sub_type; + return result; +} + +ErrorObject_External toExternalApi(ErrorObject_Internal const& val) { + ErrorObject_External result; + result.type = val.type; + result.description = val.description; + result.message = val.message; + result.severity = toExternalApi(val.severity); + result.origin = toExternalApi(val.origin); + result.timestamp = val.timestamp; + result.uuid = val.uuid; + result.state = toExternalApi(val.state); + result.sub_type = val.sub_type; + return result; +} + +ErrorList_Internal toInternalApi(ErrorList_External const& val) { + ErrorList_Internal result; + result = vecToInternal(val.errors); + return result; +} + +ErrorList_External toExternalApi(ErrorList_Internal const& val) { + ErrorList_External result; + result.errors = vecToExternal(val); + return result; +} + +} // namespace everest::lib::API::V1_0::types::error_history diff --git a/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/codec.cpp new file mode 100644 index 0000000000..3b8a88092d --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/codec.cpp @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "evse_board_support/codec.hpp" +#include "evse_board_support/API.hpp" +#include "evse_board_support/json_codec.hpp" +#include "nlohmann/json.hpp" +#include + +namespace everest::lib::API::V1_0::types::evse_board_support { + +std::string serialize(Event val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(BspEvent const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Error const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Connector_type val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(HardwareCapabilities const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Reason val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(PowerOnOff const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Ampacity val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ProximityPilot const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, Event const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const BspEvent& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Error& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Connector_type& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const HardwareCapabilities& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Reason& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const PowerOnOff& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Ampacity& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const ProximityPilot& val) { + os << serialize(val); + return os; +} + +template <> Event deserialize(std::string const& s) { + auto data = json::parse(s); + Event result = data; + return result; +} + +template <> BspEvent deserialize(std::string const& s) { + auto data = json::parse(s); + BspEvent result = data; + return result; +} + +template <> ErrorEnum deserialize(std::string const& s) { + auto data = json::parse(s); + ErrorEnum result = data; + return result; +} + +template <> Error deserialize(std::string const& s) { + auto data = json::parse(s); + Error result = data; + return result; +} + +template <> Connector_type deserialize(std::string const& s) { + auto data = json::parse(s); + Connector_type result = data; + return result; +} + +template <> HardwareCapabilities deserialize(std::string const& s) { + auto data = json::parse(s); + HardwareCapabilities result = data; + return result; +} + +template <> Reason deserialize(std::string const& s) { + auto data = json::parse(s); + Reason result = data; + return result; +} + +template <> PowerOnOff deserialize(std::string const& s) { + auto data = json::parse(s); + PowerOnOff result = data; + return result; +} + +template <> Ampacity deserialize(std::string const& s) { + auto data = json::parse(s); + Ampacity result = data; + return result; +} + +template <> ProximityPilot deserialize(std::string const& s) { + auto data = json::parse(s); + ProximityPilot result = data; + return result; +} + +} // namespace everest::lib::API::V1_0::types::evse_board_support diff --git a/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/json_codec.cpp new file mode 100644 index 0000000000..b3cf43a5b4 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/json_codec.cpp @@ -0,0 +1,566 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "evse_board_support/json_codec.hpp" +#include "evse_board_support/API.hpp" +#include "evse_board_support/codec.hpp" +#include "nlohmann/json.hpp" +#include + +namespace everest::lib::API::V1_0::types::evse_board_support { + +void to_json(json& j, Event const& k) noexcept { + switch (k) { + case Event::A: + j = "A"; + return; + case Event::B: + j = "B"; + return; + case Event::C: + j = "C"; + return; + case Event::D: + j = "D"; + return; + case Event::E: + j = "E"; + return; + case Event::F: + j = "F"; + return; + case Event::PowerOn: + j = "PowerOn"; + return; + case Event::PowerOff: + j = "PowerOff"; + return; + case Event::EvseReplugStarted: + j = "EvseReplugStarted"; + return; + case Event::EvseReplugFinished: + j = "EvseReplugFinished"; + return; + case Event::Disconnected: + j = "Disconnected"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_board_support::Event"; +} + +void from_json(json const& j, Event& k) { + std::string s = j; + if (s == "A") { + k = Event::A; + return; + } + if (s == "B") { + k = Event::B; + return; + } + if (s == "C") { + k = Event::C; + return; + } + if (s == "D") { + k = Event::D; + return; + } + if (s == "E") { + k = Event::E; + return; + } + if (s == "F") { + k = Event::F; + return; + } + if (s == "PowerOn") { + k = Event::PowerOn; + return; + } + if (s == "PowerOff") { + k = Event::PowerOff; + return; + } + if (s == "EvseReplugStarted") { + k = Event::EvseReplugStarted; + return; + } + if (s == "EvseReplugFinished") { + k = Event::EvseReplugFinished; + return; + } + if (s == "Disconnected") { + k = Event::Disconnected; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::1_0::types::evse_board_support::Event"); +} + +void to_json(json& j, BspEvent const& k) noexcept { + j = json{ + {"event", k.event}, + }; +} + +void from_json(const json& j, BspEvent& k) { + k.event = j.at("event"); +} + +void to_json(json& j, ErrorEnum const& k) noexcept { + switch (k) { + case ErrorEnum::DiodeFault: + j = "DiodeFault"; + return; + case ErrorEnum::VentilationNotAvailable: + j = "VentilationNotAvailable"; + return; + case ErrorEnum::BrownOut: + j = "BrownOut"; + return; + case ErrorEnum::EnergyManagement: + j = "EnergyManagement"; + return; + case ErrorEnum::PermanentFault: + j = "PermanentFault"; + return; + case ErrorEnum::MREC2GroundFailure: + j = "MREC2GroundFailure"; + return; + case ErrorEnum::MREC3HighTemperature: + j = "MREC3HighTemperature"; + return; + case ErrorEnum::MREC4OverCurrentFailure: + j = "MREC4OverCurrentFailure"; + return; + case ErrorEnum::MREC5OverVoltage: + j = "MREC5OverVoltage"; + return; + case ErrorEnum::MREC6UnderVoltage: + j = "MREC6UnderVoltage"; + return; + case ErrorEnum::MREC8EmergencyStop: + j = "MREC8EmergencyStop"; + return; + case ErrorEnum::MREC10InvalidVehicleMode: + j = "MREC10InvalidVehicleMode"; + return; + case ErrorEnum::MREC14PilotFault: + j = "MREC14PilotFault"; + return; + case ErrorEnum::MREC15PowerLoss: + j = "MREC15PowerLoss"; + return; + case ErrorEnum::MREC17EVSEContactorFault: + j = "MREC17EVSEContactorFault"; + return; + case ErrorEnum::MREC18CableOverTempDerate: + j = "MREC18CableOverTempDerate"; + return; + case ErrorEnum::MREC19CableOverTempStop: + j = "MREC19CableOverTempStop"; + return; + case ErrorEnum::MREC20PartialInsertion: + j = "MREC20PartialInsertion"; + return; + case ErrorEnum::MREC23ProximityFault: + j = "MREC23ProximityFault"; + return; + case ErrorEnum::MREC24ConnectorVoltageHigh: + j = "MREC24ConnectorVoltageHigh"; + return; + case ErrorEnum::MREC25BrokenLatch: + j = "MREC25BrokenLatch"; + return; + case ErrorEnum::MREC26CutCable: + j = "MREC26CutCable"; + return; + case ErrorEnum::ConnectorLockCapNotCharged: + j = "ConnectorLockCapNotCharged"; + return; + case ErrorEnum::ConnectorLockUnexpectedOpen: + j = "ConnectorLockUnexpectedOpen"; + return; + case ErrorEnum::ConnectorLockUnexpectedClose: + j = "ConnectorLockUnexpectedClose"; + return; + case ErrorEnum::ConnectorLockFailedLock: + j = "ConnectorLockFailedLock"; + return; + case ErrorEnum::ConnectorLockFailedUnlock: + j = "ConnectorLockFailedUnlock"; + return; + case ErrorEnum::MREC1ConnectorLockFailure: + j = "MREC1ConnectorLockFailure"; + return; + case ErrorEnum::Selftest: + j = "Selftest"; + return; + case ErrorEnum::DC: + j = "DC"; + return; + case ErrorEnum::AC: + j = "AC"; + return; + case ErrorEnum::VendorError: + j = "VendorError"; + return; + case ErrorEnum::VendorWarning: + j = "VendorWarning"; + return; + case ErrorEnum::CommunicationFault: + j = "CommunicationFault"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_board_support::ErrorEnum"; +} + +void from_json(json const& j, ErrorEnum& k) { + std::string s = j; + if (s == "DiodeFault") { + k = ErrorEnum::DiodeFault; + return; + } + if (s == "VentilationNotAvailable") { + k = ErrorEnum::VentilationNotAvailable; + return; + } + if (s == "BrownOut") { + k = ErrorEnum::BrownOut; + return; + } + if (s == "EnergyManagement") { + k = ErrorEnum::EnergyManagement; + return; + } + if (s == "PermanentFault") { + k = ErrorEnum::PermanentFault; + return; + } + if (s == "MREC2GroundFailure") { + k = ErrorEnum::MREC2GroundFailure; + return; + } + if (s == "MREC3HighTemperature") { + k = ErrorEnum::MREC3HighTemperature; + return; + } + if (s == "MREC4OverCurrentFailure") { + k = ErrorEnum::MREC4OverCurrentFailure; + return; + } + if (s == "MREC5OverVoltage") { + k = ErrorEnum::MREC5OverVoltage; + return; + } + if (s == "MREC6UnderVoltage") { + k = ErrorEnum::MREC6UnderVoltage; + return; + } + if (s == "MREC8EmergencyStop") { + k = ErrorEnum::MREC8EmergencyStop; + return; + } + if (s == "MREC10InvalidVehicleMode") { + k = ErrorEnum::MREC10InvalidVehicleMode; + return; + } + if (s == "MREC14PilotFault") { + k = ErrorEnum::MREC14PilotFault; + return; + } + if (s == "MREC15PowerLoss") { + k = ErrorEnum::MREC15PowerLoss; + return; + } + if (s == "MREC17EVSEContactorFault") { + k = ErrorEnum::MREC17EVSEContactorFault; + return; + } + if (s == "MREC18CableOverTempDerate") { + k = ErrorEnum::MREC18CableOverTempDerate; + return; + } + if (s == "MREC19CableOverTempStop") { + k = ErrorEnum::MREC19CableOverTempStop; + return; + } + if (s == "MREC20PartialInsertion") { + k = ErrorEnum::MREC20PartialInsertion; + return; + } + if (s == "MREC23ProximityFault") { + k = ErrorEnum::MREC23ProximityFault; + return; + } + if (s == "MREC24ConnectorVoltageHigh") { + k = ErrorEnum::MREC24ConnectorVoltageHigh; + return; + } + if (s == "MREC25BrokenLatch") { + k = ErrorEnum::MREC25BrokenLatch; + return; + } + if (s == "MREC26CutCable") { + k = ErrorEnum::MREC26CutCable; + return; + } + if (s == "ConnectorLockCapNotCharged") { + k = ErrorEnum::ConnectorLockCapNotCharged; + return; + } + if (s == "ConnectorLockUnexpectedOpen") { + k = ErrorEnum::ConnectorLockUnexpectedOpen; + return; + } + if (s == "ConnectorLockUnexpectedClose") { + k = ErrorEnum::ConnectorLockUnexpectedClose; + return; + } + if (s == "ConnectorLockFailedLock") { + k = ErrorEnum::ConnectorLockFailedLock; + return; + } + if (s == "ConnectorLockFailedUnlock") { + k = ErrorEnum::ConnectorLockFailedUnlock; + return; + } + if (s == "MREC1ConnectorLockFailure") { + k = ErrorEnum::MREC1ConnectorLockFailure; + return; + } + if (s == "Selftest") { + k = ErrorEnum::Selftest; + return; + } + if (s == "DC") { + k = ErrorEnum::DC; + return; + } + if (s == "AC") { + k = ErrorEnum::AC; + return; + } + if (s == "VendorError") { + k = ErrorEnum::VendorError; + return; + } + if (s == "VendorWarning") { + k = ErrorEnum::VendorWarning; + return; + } + if (s == "CommunicationFault") { + k = ErrorEnum::CommunicationFault; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::1_0::types::evse_board_support::ErrorEnum"); +} + +void to_json(json& j, const Error& k) noexcept { + j = json{ + {"type", k.type}, + }; + if (k.sub_type) { + j["sub_type"] = k.sub_type.value(); + } + if (k.message) { + j["message"] = k.message.value(); + }; +} + +void from_json(const json& j, Error& k) { + k.type = j.at("type"); + if (j.contains("sub_type")) { + k.sub_type.emplace(j.at("sub_type")); + } + if (j.contains("message")) { + k.message.emplace(j.at("message")); + } +} + +void to_json(json& j, Connector_type const& k) noexcept { + switch (k) { + case Connector_type::IEC62196Type2Cable: + j = "IEC62196Type2Cable"; + return; + case Connector_type::IEC62196Type2Socket: + j = "IEC62196Type2Socket"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_board_support::Connector_type"; +} + +void from_json(json const& j, Connector_type& k) { + std::string s = j; + if (s == "IEC62196Type2Cable") { + k = Connector_type::IEC62196Type2Cable; + return; + } + if (s == "IEC62196Type2Socket") { + k = Connector_type::IEC62196Type2Socket; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::1_0::types::evse_board_support::Connector_type"); +} + +void to_json(json& j, HardwareCapabilities const& k) noexcept { + j = json{ + {"max_current_A_import", k.max_current_A_import}, + {"min_current_A_import", k.min_current_A_import}, + {"max_phase_count_import", k.max_phase_count_import}, + {"min_phase_count_import", k.min_phase_count_import}, + {"max_current_A_export", k.max_current_A_export}, + {"min_current_A_export", k.min_current_A_export}, + {"max_phase_count_export", k.max_phase_count_export}, + {"min_phase_count_export", k.min_phase_count_export}, + {"supports_changing_phases_during_charging", k.supports_changing_phases_during_charging}, + {"connector_type", k.connector_type}, + }; + if (k.max_plug_temperature_C) { + j["max_plug_temperature_C"] = k.max_plug_temperature_C.value(); + } +} + +void from_json(json const& j, HardwareCapabilities& k) { + k.max_current_A_import = j.at("max_current_A_import"); + k.min_current_A_import = j.at("min_current_A_import"); + k.max_phase_count_import = j.at("max_phase_count_import"); + k.min_phase_count_import = j.at("min_phase_count_import"); + k.max_current_A_export = j.at("max_current_A_export"); + k.min_current_A_export = j.at("min_current_A_export"); + k.max_phase_count_export = j.at("max_phase_count_export"); + k.min_phase_count_export = j.at("min_phase_count_export"); + k.supports_changing_phases_during_charging = j.at("supports_changing_phases_during_charging"); + k.connector_type = j.at("connector_type"); + + if (j.contains("max_plug_temperature_C")) { + k.max_plug_temperature_C.emplace(j.at("max_plug_temperature_C")); + } +} + +void to_json(json& j, Reason const& k) noexcept { + switch (k) { + case Reason::DCCableCheck: + j = "DCCableCheck"; + return; + case Reason::DCPreCharge: + j = "DCPreCharge"; + return; + case Reason::FullPowerCharging: + j = "FullPowerCharging"; + return; + case Reason::PowerOff: + j = "PowerOff"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_board_support::Reason"; +} + +void from_json(json const& j, Reason& k) { + std::string s = j; + if (s == "DCCableCheck") { + k = Reason::DCCableCheck; + return; + } + if (s == "DCPreCharge") { + k = Reason::DCPreCharge; + return; + } + if (s == "FullPowerCharging") { + k = Reason::FullPowerCharging; + return; + } + if (s == "PowerOff") { + k = Reason::PowerOff; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::1_0::types::evse_board_support::Reason"); +} + +void to_json(json& j, PowerOnOff const& k) noexcept { + j = json{ + {"allow_power_on", k.allow_power_on}, + {"reason", k.reason}, + }; +} + +void from_json(json const& j, PowerOnOff& k) { + k.allow_power_on = j.at("allow_power_on"); + k.reason = j.at("reason"); +} + +void to_json(json& j, Ampacity const& k) noexcept { + switch (k) { + case Ampacity::None: + j = "None"; + return; + case Ampacity::A_13: + j = "A_13"; + return; + case Ampacity::A_20: + j = "A_20"; + return; + case Ampacity::A_32: + j = "A_32"; + return; + case Ampacity::A_63_3ph_70_1ph: + j = "A_63_3ph_70_1ph"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_board_support::Ampacity"; +} + +void from_json(json const& j, Ampacity& k) { + std::string s = j; + if (s == "None") { + k = Ampacity::None; + return; + } + if (s == "A_13") { + k = Ampacity::A_13; + return; + } + if (s == "A_20") { + k = Ampacity::A_20; + return; + } + if (s == "A_32") { + k = Ampacity::A_32; + return; + } + if (s == "A_63_3ph_70_1ph") { + k = Ampacity::A_63_3ph_70_1ph; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::1_0::types::evse_board_support::Ampacity"); +} + +void to_json(json& j, ProximityPilot const& k) noexcept { + j = json{ + {"ampacity", k.ampacity}, + }; +} + +void from_json(json const& j, ProximityPilot& k) { + k.ampacity = j.at("ampacity"); +} + +} // namespace everest::lib::API::V1_0::types::evse_board_support diff --git a/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/wrapper.cpp new file mode 100644 index 0000000000..faf9fd36ee --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/evse_board_support/wrapper.cpp @@ -0,0 +1,257 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "evse_board_support/wrapper.hpp" +#include "evse_board_support/API.hpp" + +namespace everest::lib::API::V1_0::types::evse_board_support { + +Event_Internal toInternalApi(Event_External const& val) { + using SrcT = Event_External; + using TarT = Event_Internal; + + switch (val) { + case SrcT::A: + return TarT::A; + case SrcT::B: + return TarT::B; + case SrcT::C: + return TarT::C; + case SrcT::D: + return TarT::D; + case SrcT::E: + return TarT::E; + case SrcT::F: + return TarT::F; + case SrcT::PowerOn: + return TarT::PowerOn; + case SrcT::PowerOff: + return TarT::PowerOff; + case SrcT::EvseReplugStarted: + return TarT::EvseReplugStarted; + case SrcT::EvseReplugFinished: + return TarT::EvseReplugFinished; + case SrcT::Disconnected: + return TarT::Disconnected; + } + + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::evse_board_support::Event_External"); +} + +Event_External toExternalApi(Event_Internal const& val) { + using SrcT = Event_Internal; + using TarT = Event_External; + + switch (val) { + case SrcT::A: + return TarT::A; + case SrcT::B: + return TarT::B; + case SrcT::C: + return TarT::C; + case SrcT::D: + return TarT::D; + case SrcT::E: + return TarT::E; + case SrcT::F: + return TarT::F; + case SrcT::PowerOn: + return TarT::PowerOn; + case SrcT::PowerOff: + return TarT::PowerOff; + case SrcT::EvseReplugStarted: + return TarT::EvseReplugStarted; + case SrcT::EvseReplugFinished: + return TarT::EvseReplugFinished; + case SrcT::Disconnected: + return TarT::Disconnected; + } + + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::evse_board_support::Event_Internal"); +} + +BspEvent_Internal toInternalApi(BspEvent_External const& val) { + BspEvent_Internal result; + result.event = toInternalApi(val.event); + return result; +} + +BspEvent_External toExternalApi(BspEvent_Internal const& val) { + BspEvent_External result; + result.event = toExternalApi(val.event); + return result; +} + +Connector_type_Internal toInternalApi(Connector_type_External const& val) { + using SrcT = Connector_type_External; + using TarT = Connector_type_Internal; + + switch (val) { + case SrcT::IEC62196Type2Cable: + return TarT::IEC62196Type2Cable; + case SrcT::IEC62196Type2Socket: + return TarT::IEC62196Type2Socket; + } + + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::evse_board_support::Connector_type_External"); +} + +Connector_type_External toExternalApi(Connector_type_Internal const& val) { + using SrcT = Connector_type_Internal; + using TarT = Connector_type_External; + + switch (val) { + case SrcT::IEC62196Type2Cable: + return TarT::IEC62196Type2Cable; + case SrcT::IEC62196Type2Socket: + return TarT::IEC62196Type2Socket; + } + + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::evse_board_support::Connector_type_Internal"); +} + +HardwareCapabilities_Internal toInternalApi(HardwareCapabilities_External const& val) { + HardwareCapabilities_Internal result; + result.max_current_A_import = val.max_current_A_import; + result.min_current_A_import = val.min_current_A_import; + result.max_phase_count_import = val.max_phase_count_import; + result.min_phase_count_import = val.min_phase_count_import; + result.max_current_A_export = val.max_current_A_export; + result.min_current_A_export = val.min_current_A_export; + result.max_phase_count_export = val.max_phase_count_export; + result.min_phase_count_export = val.min_phase_count_export; + result.supports_changing_phases_during_charging = val.supports_changing_phases_during_charging; + result.connector_type = toInternalApi(val.connector_type); + result.max_plug_temperature_C = val.max_plug_temperature_C; + + return result; +} + +HardwareCapabilities_External toExternalApi(HardwareCapabilities_Internal const& val) { + HardwareCapabilities_External result; + result.max_current_A_import = val.max_current_A_import; + result.min_current_A_import = val.min_current_A_import; + result.max_phase_count_import = val.max_phase_count_import; + result.min_phase_count_import = val.min_phase_count_import; + result.max_current_A_export = val.max_current_A_export; + result.min_current_A_export = val.min_current_A_export; + result.max_phase_count_export = val.max_phase_count_export; + result.min_phase_count_export = val.min_phase_count_export; + result.supports_changing_phases_during_charging = val.supports_changing_phases_during_charging; + result.connector_type = toExternalApi(val.connector_type); + result.max_plug_temperature_C = val.max_plug_temperature_C; + + return result; +} + +Reason_Internal toInternalApi(Reason_External const& val) { + using SrcT = Reason_External; + using TarT = Reason_Internal; + + switch (val) { + case SrcT::DCCableCheck: + return TarT::DCCableCheck; + case SrcT::DCPreCharge: + return TarT::DCPreCharge; + case SrcT::FullPowerCharging: + return TarT::FullPowerCharging; + case SrcT::PowerOff: + return TarT::PowerOff; + } + + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::evse_board_support::Reason_External"); +} + +Reason_External toExternalApi(Reason_Internal const& val) { + using SrcT = Reason_Internal; + using TarT = Reason_External; + + switch (val) { + case SrcT::DCCableCheck: + return TarT::DCCableCheck; + case SrcT::DCPreCharge: + return TarT::DCPreCharge; + case SrcT::FullPowerCharging: + return TarT::FullPowerCharging; + case SrcT::PowerOff: + return TarT::PowerOff; + } + + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::evse_board_support::Reason_Internal"); +} + +PowerOnOff_Internal toInternalApi(PowerOnOff_External const& val) { + PowerOnOff_Internal result; + + result.allow_power_on = val.allow_power_on; + result.reason = toInternalApi(val.reason); + + return result; +} + +PowerOnOff_External toExternalApi(PowerOnOff_Internal const& val) { + PowerOnOff_External result; + + result.allow_power_on = val.allow_power_on; + result.reason = toExternalApi(val.reason); + + return result; +} + +Ampacity_Internal toInternalApi(Ampacity_External const& val) { + using SrcT = Ampacity_External; + using TarT = Ampacity_Internal; + + switch (val) { + case SrcT::None: + return TarT::None; + case SrcT::A_13: + return TarT::A_13; + case SrcT::A_20: + return TarT::A_20; + case SrcT::A_32: + return TarT::A_32; + case SrcT::A_63_3ph_70_1ph: + return TarT::A_63_3ph_70_1ph; + } + + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::evse_board_support::Ampacity_External"); +} + +Ampacity_External toExternalApi(Ampacity_Internal const& val) { + using SrcT = Ampacity_Internal; + using TarT = Ampacity_External; + + switch (val) { + case SrcT::None: + return TarT::None; + case SrcT::A_13: + return TarT::A_13; + case SrcT::A_20: + return TarT::A_20; + case SrcT::A_32: + return TarT::A_32; + case SrcT::A_63_3ph_70_1ph: + return TarT::A_63_3ph_70_1ph; + } + + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::evse_board_support::Ampacity_Internal"); +} + +ProximityPilot_Internal toInternalApi(ProximityPilot_External const& val) { + ProximityPilot_Internal result; + result.ampacity = toInternalApi(val.ampacity); + return result; +} + +ProximityPilot_External toExternalApi(ProximityPilot_Internal const& val) { + ProximityPilot_External result; + result.ampacity = toExternalApi(val.ampacity); + return result; +} + +} // namespace everest::lib::API::V1_0::types::evse_board_support diff --git a/lib/everest/everest_api_types/src/everest_api_types/evse_manager/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/evse_manager/codec.cpp new file mode 100644 index 0000000000..97f6ff9be3 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/evse_manager/codec.cpp @@ -0,0 +1,443 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "evse_manager/codec.hpp" +#include "evse_manager/API.hpp" +#include "evse_manager/json_codec.hpp" +#include "nlohmann/json.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::evse_manager { + +std::string serialize(StopTransactionReason val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(StopTransactionRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(StartSessionReason val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SessionEventEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SessionEvent const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Limits const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(EVInfo const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(CarManufacturer val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SessionStarted const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SessionFinished const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(TransactionStarted const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(TransactionFinished const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ChargingStateChangedEvent const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(AuthorizationEvent const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorSeverity val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorState val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorOrigin const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Error const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ConnectorTypeEnum const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Connector const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Evse const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(EnableSourceEnum const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(EnableStateEnum const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(EnableDisableSource const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(EnableDisableRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(AuthorizeResponseArgs const& val) noexcept { + json result = val; + return result.dump(4); +} +std::string serialize(PlugAndChargeConfiguration const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, StopTransactionReason const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, StopTransactionRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, StartSessionReason const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SessionEventEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SessionEvent const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Limits const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, EVInfo const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, CarManufacturer const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SessionStarted const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SessionFinished const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, TransactionStarted const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, TransactionFinished const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ChargingStateChangedEvent const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, AuthorizationEvent const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ErrorSeverity const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ErrorState const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ErrorOrigin const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Error const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ConnectorTypeEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Connector const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Evse const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, EnableSourceEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, EnableStateEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, EnableDisableSource const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, EnableDisableRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, AuthorizeResponseArgs const& val) { + os << serialize(val); + return os; +} +std::ostream& operator<<(std::ostream& os, PlugAndChargeConfiguration const& val) { + os << serialize(val); + return os; +} + +template <> StopTransactionReason deserialize(std::string const& s) { + auto data = json::parse(s); + StopTransactionReason result = data; + return result; +} + +template <> StopTransactionRequest deserialize(std::string const& s) { + auto data = json::parse(s); + StopTransactionRequest result = data; + return result; +} + +template <> StartSessionReason deserialize(std::string const& s) { + auto data = json::parse(s); + StartSessionReason result = data; + return result; +} + +template <> SessionEventEnum deserialize(std::string const& s) { + auto data = json::parse(s); + SessionEventEnum result = data; + return result; +} + +template <> SessionEvent deserialize(std::string const& s) { + auto data = json::parse(s); + SessionEvent result = data; + return result; +} + +template <> Limits deserialize(std::string const& s) { + auto data = json::parse(s); + Limits result = data; + return result; +} + +template <> EVInfo deserialize(std::string const& s) { + auto data = json::parse(s); + EVInfo result = data; + return result; +} + +template <> CarManufacturer deserialize(const std::string& s) { + auto data = json::parse(s); + CarManufacturer result = data; + return result; +} + +template <> SessionStarted deserialize(std::string const& s) { + auto data = json::parse(s); + SessionStarted result = data; + return result; +} + +template <> SessionFinished deserialize(std::string const& s) { + auto data = json::parse(s); + SessionFinished result = data; + return result; +} + +template <> TransactionStarted deserialize(std::string const& s) { + auto data = json::parse(s); + TransactionStarted result = data; + return result; +} + +template <> TransactionFinished deserialize(std::string const& s) { + auto data = json::parse(s); + TransactionFinished result = data; + return result; +} + +template <> ChargingStateChangedEvent deserialize(std::string const& s) { + auto data = json::parse(s); + ChargingStateChangedEvent result = data; + return result; +} + +template <> AuthorizationEvent deserialize(std::string const& s) { + auto data = json::parse(s); + AuthorizationEvent result = data; + return result; +} + +template <> ErrorSeverity deserialize(const std::string& s) { + auto data = json::parse(s); + ErrorSeverity result = data; + return result; +} + +template <> ErrorState deserialize(const std::string& s) { + auto data = json::parse(s); + ErrorState result = data; + return result; +} + +template <> ErrorOrigin deserialize(std::string const& s) { + auto data = json::parse(s); + ErrorOrigin result = data; + return result; +} + +template <> Error deserialize(std::string const& s) { + auto data = json::parse(s); + Error result = data; + return result; +} + +template <> ConnectorTypeEnum deserialize(std::string const& s) { + auto data = json::parse(s); + ConnectorTypeEnum result = data; + return result; +} + +template <> Connector deserialize(std::string const& s) { + auto data = json::parse(s); + Connector result = data; + return result; +} + +template <> Evse deserialize(std::string const& s) { + auto data = json::parse(s); + Evse result = data; + return result; +} + +template <> EnableSourceEnum deserialize(std::string const& s) { + auto data = json::parse(s); + EnableSourceEnum result = data; + return result; +} + +template <> EnableStateEnum deserialize(std::string const& s) { + auto data = json::parse(s); + EnableStateEnum result = data; + return result; +} + +template <> EnableDisableSource deserialize(std::string const& s) { + auto data = json::parse(s); + EnableDisableSource result = data; + return result; +} + +template <> EnableDisableRequest deserialize(std::string const& s) { + auto data = json::parse(s); + EnableDisableRequest result = data; + return result; +} + +template <> AuthorizeResponseArgs deserialize(std::string const& s) { + auto data = json::parse(s); + AuthorizeResponseArgs result = data; + return result; +} + +template <> PlugAndChargeConfiguration deserialize(std::string const& s) { + auto data = json::parse(s); + PlugAndChargeConfiguration result = data; + return result; +} + +} // namespace everest::lib::API::V1_0::types::evse_manager diff --git a/lib/everest/everest_api_types/src/everest_api_types/evse_manager/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/evse_manager/json_codec.cpp new file mode 100644 index 0000000000..07f6e200cd --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/evse_manager/json_codec.cpp @@ -0,0 +1,1198 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "evse_manager/json_codec.hpp" +#include "auth/API.hpp" +#include "auth/codec.hpp" +#include "auth/json_codec.hpp" +#include "evse_manager/API.hpp" +#include "evse_manager/codec.hpp" +#include "nlohmann/json.hpp" +#include "powermeter/API.hpp" +#include "powermeter/codec.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::evse_manager { + +void to_json(json& j, StopTransactionReason const& k) noexcept { + switch (k) { + case StopTransactionReason::EmergencyStop: + j = "EmergencyStop"; + return; + case StopTransactionReason::EVDisconnected: + j = "EVDisconnected"; + return; + case StopTransactionReason::HardReset: + j = "HardReset"; + return; + case StopTransactionReason::Local: + j = "Local"; + return; + case StopTransactionReason::Other: + j = "Other"; + return; + case StopTransactionReason::PowerLoss: + j = "PowerLoss"; + return; + case StopTransactionReason::Reboot: + j = "Reboot"; + return; + case StopTransactionReason::Remote: + j = "Remote"; + return; + case StopTransactionReason::SoftReset: + j = "SoftReset"; + return; + case StopTransactionReason::UnlockCommand: + j = "UnlockCommand"; + return; + case StopTransactionReason::DeAuthorized: + j = "DeAuthorized"; + return; + case StopTransactionReason::EnergyLimitReached: + j = "EnergyLimitReached"; + return; + case StopTransactionReason::GroundFault: + j = "GroundFault"; + return; + case StopTransactionReason::LocalOutOfCredit: + j = "LocalOutOfCredit"; + return; + case StopTransactionReason::MasterPass: + j = "MasterPass"; + return; + case StopTransactionReason::OvercurrentFault: + j = "OvercurrentFault"; + return; + case StopTransactionReason::PowerQuality: + j = "PowerQuality"; + return; + case StopTransactionReason::SOCLimitReached: + j = "SOCLimitReached"; + return; + case StopTransactionReason::StoppedByEV: + j = "StoppedByEV"; + return; + case StopTransactionReason::TimeLimitReached: + j = "TimeLimitReached"; + return; + case StopTransactionReason::Timeout: + j = "Timeout"; + return; + case StopTransactionReason::ReqEnergyTransferRejected: + j = "ReqEnergyTransferRejected"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::StopTransactionReason"; +} + +void from_json(json const& j, StopTransactionReason& k) { + std::string s = j; + if (s == "EmergencyStop") { + k = StopTransactionReason::EmergencyStop; + return; + } + if (s == "EVDisconnected") { + k = StopTransactionReason::EVDisconnected; + return; + } + if (s == "HardReset") { + k = StopTransactionReason::HardReset; + return; + } + if (s == "Local") { + k = StopTransactionReason::Local; + return; + } + if (s == "Other") { + k = StopTransactionReason::Other; + return; + } + if (s == "PowerLoss") { + k = StopTransactionReason::PowerLoss; + return; + } + if (s == "Reboot") { + k = StopTransactionReason::Reboot; + return; + } + if (s == "Remote") { + k = StopTransactionReason::Remote; + return; + } + if (s == "SoftReset") { + k = StopTransactionReason::SoftReset; + return; + } + if (s == "UnlockCommand") { + k = StopTransactionReason::UnlockCommand; + return; + } + if (s == "DeAuthorized") { + k = StopTransactionReason::DeAuthorized; + return; + } + if (s == "EnergyLimitReached") { + k = StopTransactionReason::EnergyLimitReached; + return; + } + if (s == "GroundFault") { + k = StopTransactionReason::GroundFault; + return; + } + if (s == "LocalOutOfCredit") { + k = StopTransactionReason::LocalOutOfCredit; + return; + } + if (s == "MasterPass") { + k = StopTransactionReason::MasterPass; + return; + } + if (s == "OvercurrentFault") { + k = StopTransactionReason::OvercurrentFault; + return; + } + if (s == "PowerQuality") { + k = StopTransactionReason::PowerQuality; + return; + } + if (s == "SOCLimitReached") { + k = StopTransactionReason::SOCLimitReached; + return; + } + if (s == "StoppedByEV") { + k = StopTransactionReason::StoppedByEV; + return; + } + if (s == "TimeLimitReached") { + k = StopTransactionReason::TimeLimitReached; + return; + } + if (s == "Timeout") { + k = StopTransactionReason::Timeout; + return; + } + if (s == "ReqEnergyTransferRejected") { + k = StopTransactionReason::ReqEnergyTransferRejected; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_StopTransactionReason"); +} + +void to_json(json& j, StopTransactionRequest const& k) noexcept { + j = json{{"reason", k.reason}}; +} + +void from_json(json const& j, StopTransactionRequest& k) { + k.reason = j.at("reason"); +} + +void to_json(json& j, StartSessionReason const& k) noexcept { + switch (k) { + case StartSessionReason::EVConnected: + j = "EVConnected"; + return; + case StartSessionReason::Authorized: + j = "Authorized"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::StartSessionReason"; +} + +void from_json(json const& j, StartSessionReason& k) { + std::string s = j; + if (s == "EVConnected") { + k = StartSessionReason::EVConnected; + return; + } + if (s == "Authorized") { + k = StartSessionReason::Authorized; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_StartSessionReason"); +} + +void to_json(json& j, SessionEventEnum const& k) noexcept { + switch (k) { + case SessionEventEnum::Authorized: + j = "Authorized"; + return; + case SessionEventEnum::Deauthorized: + j = "Deauthorized"; + return; + case SessionEventEnum::Enabled: + j = "Enabled"; + return; + case SessionEventEnum::Disabled: + j = "Disabled"; + return; + case SessionEventEnum::SessionStarted: + j = "SessionStarted"; + return; + case SessionEventEnum::AuthRequired: + j = "AuthRequired"; + return; + case SessionEventEnum::TransactionStarted: + j = "TransactionStarted"; + return; + case SessionEventEnum::PrepareCharging: + j = "PrepareCharging"; + return; + case SessionEventEnum::ChargingStarted: + j = "ChargingStarted"; + return; + case SessionEventEnum::ChargingPausedEV: + j = "ChargingPausedEV"; + return; + case SessionEventEnum::ChargingPausedEVSE: + j = "ChargingPausedEVSE"; + return; + case SessionEventEnum::WaitingForEnergy: + j = "WaitingForEnergy"; + return; + case SessionEventEnum::ChargingResumed: + j = "ChargingResumed"; + return; + case SessionEventEnum::StoppingCharging: + j = "StoppingCharging"; + return; + case SessionEventEnum::ChargingFinished: + j = "ChargingFinished"; + return; + case SessionEventEnum::TransactionFinished: + j = "TransactionFinished"; + return; + case SessionEventEnum::SessionFinished: + j = "SessionFinished"; + return; + case SessionEventEnum::ReservationStart: + j = "ReservationStart"; + return; + case SessionEventEnum::ReservationEnd: + j = "ReservationEnd"; + return; + case SessionEventEnum::ReplugStarted: + j = "ReplugStarted"; + return; + case SessionEventEnum::ReplugFinished: + j = "ReplugFinished"; + return; + case SessionEventEnum::PluginTimeout: + j = "PluginTimeout"; + return; + case SessionEventEnum::SwitchingPhases: + j = "SwitchingPhases"; + return; + case SessionEventEnum::SessionResumed: + j = "SessionResumed:"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::SessionEventEnum"; +} + +void from_json(json const& j, SessionEventEnum& k) { + std::string s = j; + if (s == "Authorized") { + k = SessionEventEnum::Authorized; + return; + } + if (s == "Deauthorized") { + k = SessionEventEnum::Deauthorized; + return; + } + if (s == "Enabled") { + k = SessionEventEnum::Enabled; + return; + } + if (s == "Disabled") { + k = SessionEventEnum::Disabled; + return; + } + if (s == "SessionStarted") { + k = SessionEventEnum::SessionStarted; + return; + } + if (s == "AuthRequired") { + k = SessionEventEnum::AuthRequired; + return; + } + if (s == "TransactionStarted") { + k = SessionEventEnum::TransactionStarted; + return; + } + if (s == "PrepareCharging") { + k = SessionEventEnum::PrepareCharging; + return; + } + if (s == "ChargingStarted") { + k = SessionEventEnum::ChargingStarted; + return; + } + if (s == "ChargingPausedEV") { + k = SessionEventEnum::ChargingPausedEV; + return; + } + if (s == "ChargingPausedEVSE") { + k = SessionEventEnum::ChargingPausedEVSE; + return; + } + if (s == "WaitingForEnergy") { + k = SessionEventEnum::WaitingForEnergy; + return; + } + if (s == "ChargingResumed") { + k = SessionEventEnum::ChargingResumed; + return; + } + if (s == "StoppingCharging") { + k = SessionEventEnum::StoppingCharging; + return; + } + if (s == "ChargingFinished") { + k = SessionEventEnum::ChargingFinished; + return; + } + if (s == "TransactionFinished") { + k = SessionEventEnum::TransactionFinished; + return; + } + if (s == "SessionFinished") { + k = SessionEventEnum::SessionFinished; + return; + } + if (s == "ReservationStart") { + k = SessionEventEnum::ReservationStart; + return; + } + if (s == "ReservationEnd") { + k = SessionEventEnum::ReservationEnd; + return; + } + if (s == "ReplugStarted") { + k = SessionEventEnum::ReplugStarted; + return; + } + if (s == "ReplugFinished") { + k = SessionEventEnum::ReplugFinished; + return; + } + if (s == "PluginTimeout") { + k = SessionEventEnum::PluginTimeout; + return; + } + if (s == "SwitchingPhases") { + k = SessionEventEnum::SwitchingPhases; + return; + } + if (s == "SessionResumed:") { + k = SessionEventEnum::SessionResumed; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_SessionEventEnum"); +} + +void to_json(json& j, SessionEvent const& k) noexcept { + j = json{ + {"uuid", k.uuid}, + {"timestamp", k.timestamp}, + {"event", k.event}, + }; + if (k.connector_id) { + j["connector_id"] = k.connector_id.value(); + } + if (k.session_started) { + j["session_started"] = k.session_started.value(); + } + if (k.session_finished) { + j["session_finished"] = k.session_finished.value(); + } + if (k.transaction_started) { + j["transaction_started"] = k.transaction_started.value(); + } + if (k.transaction_finished) { + j["transaction_finished"] = k.transaction_finished.value(); + } + if (k.charging_state_changed_event) { + j["charging_state_changed_event"] = k.charging_state_changed_event.value(); + } + if (k.authorization_event) { + j["authorization_event"] = k.authorization_event.value(); + } +} + +void from_json(json const& j, SessionEvent& k) { + k.uuid = j.at("uuid"); + k.timestamp = j.at("timestamp"); + k.event = j.at("event"); + if (j.contains("connector_id")) { + k.connector_id.emplace(j.at("connector_id")); + } + if (j.contains("session_started")) { + k.session_started.emplace(j.at("session_started")); + } + if (j.contains("session_finished")) { + k.session_finished.emplace(j.at("session_finished")); + } + if (j.contains("transaction_started")) { + k.transaction_started.emplace(j.at("transaction_started")); + } + if (j.contains("transaction_finished")) { + k.transaction_finished.emplace(j.at("transaction_finished")); + } + if (j.contains("charging_state_changed_event")) { + k.charging_state_changed_event.emplace(j.at("charging_state_changed_event")); + } + if (j.contains("authorization_event")) { + k.authorization_event.emplace(j.at("authorization_event")); + } +} + +void to_json(json& j, Limits const& k) noexcept { + j = json{ + {"max_current", k.max_current}, + {"nr_of_phases_available", k.nr_of_phases_available}, + }; + if (k.uuid) { + j["uuid"] = k.uuid.value(); + } +} + +void from_json(json const& j, Limits& k) { + k.max_current = j.at("max_current"); + k.nr_of_phases_available = j.at("nr_of_phases_available"); + + if (j.contains("uuid")) { + k.uuid.emplace(j.at("uuid")); + } +} + +void to_json(json& j, EVInfo const& k) noexcept { + j = json({}); + if (k.soc) { + j["soc"] = k.soc.value(); + } + if (k.present_voltage) { + j["present_voltage"] = k.present_voltage.value(); + } + if (k.present_current) { + j["present_current"] = k.present_current.value(); + } + if (k.target_voltage) { + j["target_voltage"] = k.target_voltage.value(); + } + if (k.target_current) { + j["target_current"] = k.target_current.value(); + } + if (k.maximum_current_limit) { + j["maximum_current_limit"] = k.maximum_current_limit.value(); + } + if (k.minimum_current_limit) { + j["minimum_current_limit"] = k.minimum_current_limit.value(); + } + if (k.maximum_voltage_limit) { + j["maximum_voltage_limit"] = k.maximum_voltage_limit.value(); + } + if (k.maximum_power_limit) { + j["maximum_power_limit"] = k.maximum_power_limit.value(); + } + if (k.estimated_time_full) { + j["estimated_time_full"] = k.estimated_time_full.value(); + } + if (k.departure_time) { + j["departure_time"] = k.departure_time.value(); + } + if (k.estimated_time_bulk) { + j["estimated_time_bulk"] = k.estimated_time_bulk.value(); + } + if (k.evcc_id) { + j["evcc_id"] = k.evcc_id.value(); + } + if (k.remaining_energy_needed) { + j["remaining_energy_needed"] = k.remaining_energy_needed.value(); + } + if (k.battery_capacity) { + j["battery_capacity"] = k.battery_capacity.value(); + } + if (k.battery_full_soc) { + j["battery_full_soc"] = k.battery_full_soc.value(); + } + if (k.battery_bulk_soc) { + j["battery_bulk_soc"] = k.battery_bulk_soc.value(); + } +} + +void from_json(json const& j, EVInfo& k) { + if (j.contains("soc")) { + k.soc.emplace(j.at("soc")); + } + if (j.contains("present_voltage")) { + k.present_voltage.emplace(j.at("present_voltage")); + } + if (j.contains("present_current")) { + k.present_current.emplace(j.at("present_current")); + } + if (j.contains("target_voltage")) { + k.target_voltage.emplace(j.at("target_voltage")); + } + if (j.contains("target_current")) { + k.target_current.emplace(j.at("target_current")); + } + if (j.contains("maximum_current_limit")) { + k.maximum_current_limit.emplace(j.at("maximum_current_limit")); + } + if (j.contains("minimum_current_limit")) { + k.minimum_current_limit.emplace(j.at("minimum_current_limit")); + } + if (j.contains("maximum_voltage_limit")) { + k.maximum_voltage_limit.emplace(j.at("maximum_voltage_limit")); + } + if (j.contains("maximum_power_limit")) { + k.maximum_power_limit.emplace(j.at("maximum_power_limit")); + } + if (j.contains("estimated_time_full")) { + k.estimated_time_full.emplace(j.at("estimated_time_full")); + } + if (j.contains("departure_time")) { + k.departure_time.emplace(j.at("departure_time")); + } + if (j.contains("estimated_time_bulk")) { + k.estimated_time_bulk.emplace(j.at("estimated_time_bulk")); + } + if (j.contains("evcc_id")) { + k.evcc_id.emplace(j.at("evcc_id")); + } + if (j.contains("remaining_energy_needed")) { + k.remaining_energy_needed.emplace(j.at("remaining_energy_needed")); + } + if (j.contains("battery_capacity")) { + k.battery_capacity.emplace(j.at("battery_capacity")); + } + if (j.contains("battery_full_soc")) { + k.battery_full_soc.emplace(j.at("battery_full_soc")); + } + if (j.contains("battery_bulk_soc")) { + k.battery_bulk_soc.emplace(j.at("battery_bulk_soc")); + } +} + +void to_json(json& j, CarManufacturer const& k) noexcept { + switch (k) { + case CarManufacturer::VolkswagenGroup: + j = "VolkswagenGroup"; + return; + case CarManufacturer::Tesla: + j = "Tesla"; + return; + case CarManufacturer::Unknown: + j = "Unknown"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::CarManufacturer"; +} + +void from_json(json const& j, CarManufacturer& k) { + std::string s = j; + if (s == "VolkswagenGroup") { + k = CarManufacturer::VolkswagenGroup; + return; + } + if (s == "Tesla") { + k = CarManufacturer::Tesla; + return; + } + if (s == "Unknown") { + k = CarManufacturer::Unknown; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_CarManufacturer"); +} + +void to_json(json& j, SessionStarted const& k) noexcept { + j = json{ + {"reason", k.reason}, + {"meter_value", serialize(k.meter_value)}, + }; + if (k.signed_meter_value) { + j["signed_meter_value"] = serialize(k.signed_meter_value.value()); + } + if (k.reservation_id) { + j["reservation_id"] = k.reservation_id.value(); + } + if (k.logging_path) { + j["logging_path"] = k.logging_path.value(); + } +} + +void from_json(json const& j, SessionStarted& k) { + using namespace powermeter; + k.reason = j.at("reason"); + k.meter_value = powermeter::deserialize(j.at("meter_value")); + if (j.contains("signed_meter_value")) { + k.signed_meter_value.emplace(powermeter::deserialize(j.at("signed_meter_value"))); + } + if (j.contains("reservation_id")) { + k.reservation_id.emplace(j.at("reservation_id")); + } + if (j.contains("logging_path")) { + k.logging_path.emplace(j.at("logging_path")); + } +} + +void to_json(json& j, SessionFinished const& k) noexcept { + j = json{ + {"meter_value", serialize(k.meter_value)}, + }; +} + +void from_json(json const& j, SessionFinished& k) { + using namespace powermeter; + k.meter_value = powermeter::deserialize(j.at("meter_value")); +} + +void to_json(json& j, TransactionStarted const& k) noexcept { + j = json{ + {"id_tag", serialize(k.id_tag)}, + {"meter_value", serialize(k.meter_value)}, + }; + if (k.signed_meter_value) { + j["signed_meter_value"] = serialize(k.signed_meter_value.value()); + } + if (k.reservation_id) { + j["reservation_id"] = k.reservation_id.value(); + } +} + +void from_json(json const& j, TransactionStarted& k) { + using namespace powermeter; + using namespace auth; + k.meter_value = powermeter::deserialize(j.at("meter_value")); + k.id_tag = auth::deserialize(j.at("id_tag")); + if (j.contains("signed_meter_value")) { + k.signed_meter_value.emplace(powermeter::deserialize(j.at("signed_meter_value"))); + } + if (j.contains("reservation_id")) { + k.reservation_id.emplace(j.at("reservation_id")); + } +} + +void to_json(json& j, TransactionFinished const& k) noexcept { + j = json{ + {"meter_value", serialize(k.meter_value)}, + }; + if (k.start_signed_meter_value) { + j["start_signed_meter_value"] = serialize(k.start_signed_meter_value.value()); + } + if (k.signed_meter_value) { + j["signed_meter_value"] = serialize(k.signed_meter_value.value()); + } + if (k.reason) { + j["reason"] = k.reason.value(); + } +} + +void from_json(json const& j, TransactionFinished& k) { + using namespace powermeter; + k.meter_value = powermeter::deserialize(j.at("meter_value")); + if (j.contains("start_signed_meter_value")) { + k.start_signed_meter_value.emplace(powermeter::deserialize(j.at("start_signed_meter_value"))); + } + if (j.contains("signed_meter_value")) { + k.signed_meter_value.emplace(powermeter::deserialize(j.at("signed_meter_value"))); + } + if (j.contains("reason")) { + k.reason.emplace(j.at("reason")); + } +} + +void to_json(json& j, ChargingStateChangedEvent const& k) noexcept { + j = json{ + {"meter_value", serialize(k.meter_value)}, + }; +} + +void from_json(json const& j, ChargingStateChangedEvent& k) { + using namespace powermeter; + k.meter_value = powermeter::deserialize(j.at("meter_value")); +} + +void to_json(json& j, AuthorizationEvent const& k) noexcept { + j = json{ + {"meter_value", serialize(k.meter_value)}, + }; +} + +void from_json(json const& j, AuthorizationEvent& k) { + using namespace powermeter; + k.meter_value = powermeter::deserialize(j.at("meter_value")); +} + +void to_json(json& j, ErrorSeverity const& k) noexcept { + switch (k) { + case ErrorSeverity::High: + j = "High"; + return; + case ErrorSeverity::Medium: + j = "Medium"; + return; + case ErrorSeverity::Low: + j = "Low"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::ErrorSeverity"; +} + +void from_json(json const& j, ErrorSeverity& k) { + std::string s = j; + if (s == "High") { + k = ErrorSeverity::High; + return; + } + if (s == "Medium") { + k = ErrorSeverity::Medium; + return; + } + if (s == "Low") { + k = ErrorSeverity::Low; + return; + } + + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type API_V1_0_ErrorSeverity"); +} + +void to_json(json& j, ErrorState const& k) noexcept { + switch (k) { + case ErrorState::Active: + j = "Active"; + return; + case ErrorState::ClearedByModule: + j = "ClearedByModule"; + return; + case ErrorState::ClearedByReboot: + j = "ClearedByReboot"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::ErrorState"; +} + +void from_json(json const& j, ErrorState& k) { + std::string s = j; + if (s == "Active") { + k = ErrorState::Active; + return; + } + if (s == "ClearedByModule") { + k = ErrorState::ClearedByModule; + return; + } + if (s == "ClearedByReboot") { + k = ErrorState::ClearedByReboot; + return; + } + + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type API_V1_0_ErrorState"); +} + +void to_json(json& j, ErrorOrigin const& k) noexcept { + j = json{ + {"module_id", k.module_id}, + {"implementation_id", k.implementation_id}, + }; +} + +void from_json(json const& j, ErrorOrigin& k) { + k.module_id = j.at("module_id"); + k.implementation_id = j.at("implementation_id"); +} + +void to_json(json& j, Error const& k) noexcept { + j = json{ + {"type", k.type}, {"sub_type", k.sub_type}, {"description", k.description}, + {"message", k.message}, {"severity", k.severity}, {"origin", k.origin}, + {"timestamp", k.timestamp}, {"uuid", k.uuid}, {"state", k.state}, + }; +} + +void from_json(json const& j, Error& k) { + k.type = j.at("type"); + k.sub_type = j.at("sub_type"); + k.description = j.at("description"); + k.message = j.at("message"); + k.severity = j.at("severity"); + k.origin = j.at("origin"); + k.timestamp = j.at("timestamp"); + k.uuid = j.at("uuid"); + k.state = j.at("state"); +} + +void to_json(json& j, ConnectorTypeEnum const& k) noexcept { + switch (k) { + case ConnectorTypeEnum::cCCS1: + j = "cCCS1"; + return; + case ConnectorTypeEnum::cCCS2: + j = "cCCS2"; + return; + case ConnectorTypeEnum::cG105: + j = "cG105"; + return; + case ConnectorTypeEnum::cTesla: + j = "cTesla"; + return; + case ConnectorTypeEnum::cType1: + j = "cType1"; + return; + case ConnectorTypeEnum::cType2: + j = "cType2"; + return; + case ConnectorTypeEnum::s309_1P_16A: + j = "s309_1P_16A"; + return; + case ConnectorTypeEnum::s309_1P_32A: + j = "s309_1P_32A"; + return; + case ConnectorTypeEnum::s309_3P_16A: + j = "s309_3P_16A"; + return; + case ConnectorTypeEnum::s309_3P_32A: + j = "s309_3P_32A"; + return; + case ConnectorTypeEnum::sBS1361: + j = "sBS1361"; + return; + case ConnectorTypeEnum::sCEE_7_7: + j = "sCEE_7_7"; + return; + case ConnectorTypeEnum::sType2: + j = "sType2"; + return; + case ConnectorTypeEnum::sType3: + j = "sType3"; + return; + case ConnectorTypeEnum::Other1PhMax16A: + j = "Other1PhMax16A"; + return; + case ConnectorTypeEnum::Other1PhOver16A: + j = "Other1PhOver16A"; + return; + case ConnectorTypeEnum::Other3Ph: + j = "Other3Ph"; + return; + case ConnectorTypeEnum::Pan: + j = "Pan"; + return; + case ConnectorTypeEnum::wInductive: + j = "wInductive"; + return; + case ConnectorTypeEnum::wResonant: + j = "wResonant"; + return; + case ConnectorTypeEnum::Undetermined: + j = "Undetermined"; + return; + case ConnectorTypeEnum::Unknown: + j = "Unknown"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::ConnectorTypeEnum"; +} + +void from_json(json const& j, ConnectorTypeEnum& k) { + std::string s = j; + if (s == "cCCS1") { + k = ConnectorTypeEnum::cCCS1; + return; + } + if (s == "cCCS2") { + k = ConnectorTypeEnum::cCCS2; + return; + } + if (s == "cG105") { + k = ConnectorTypeEnum::cG105; + return; + } + if (s == "cTesla") { + k = ConnectorTypeEnum::cTesla; + return; + } + if (s == "cType1") { + k = ConnectorTypeEnum::cType1; + return; + } + if (s == "cType2") { + k = ConnectorTypeEnum::cType2; + return; + } + if (s == "s309_1P_16A") { + k = ConnectorTypeEnum::s309_1P_16A; + return; + } + if (s == "s309_1P_32A") { + k = ConnectorTypeEnum::s309_1P_32A; + return; + } + if (s == "s309_3P_16A") { + k = ConnectorTypeEnum::s309_3P_16A; + return; + } + if (s == "s309_3P_32A") { + k = ConnectorTypeEnum::s309_3P_32A; + return; + } + if (s == "sBS1361") { + k = ConnectorTypeEnum::sBS1361; + return; + } + if (s == "sCEE_7_7") { + k = ConnectorTypeEnum::sCEE_7_7; + return; + } + if (s == "sType2") { + k = ConnectorTypeEnum::sType2; + return; + } + if (s == "sType3") { + k = ConnectorTypeEnum::sType3; + return; + } + if (s == "Other1PhMax16A") { + k = ConnectorTypeEnum::Other1PhMax16A; + return; + } + if (s == "Other1PhOver16A") { + k = ConnectorTypeEnum::Other1PhOver16A; + return; + } + if (s == "Other3Ph") { + k = ConnectorTypeEnum::Other3Ph; + return; + } + if (s == "Pan") { + k = ConnectorTypeEnum::Pan; + return; + } + if (s == "wInductive") { + k = ConnectorTypeEnum::wInductive; + return; + } + if (s == "wResonant") { + k = ConnectorTypeEnum::wResonant; + return; + } + if (s == "Undetermined") { + k = ConnectorTypeEnum::Undetermined; + return; + } + if (s == "Unknown") { + k = ConnectorTypeEnum::Unknown; + return; + } + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_TYPES_EVSE_MANAGER_ConnectorTypeEnum"); +} + +void to_json(json& j, Connector const& k) noexcept { + j = json{ + {"id", k.id}, + }; + if (k.type) { + j["type"] = k.type.value(); + } +} + +void from_json(json const& j, Connector& k) { + k.id = j.at("id"); + + if (j.contains("type")) { + k.type.emplace(j.at("type")); + } +} + +void to_json(json& j, Evse const& k) noexcept { + j = json{ + {"id", k.id}, + {"connectors", k.connectors}, + }; +} + +void from_json(json const& j, Evse& k) { + k.id = j.at("id"); + for (auto val : j.at("connectors")) { + k.connectors.push_back(val); + } +} + +void to_json(json& j, EnableSourceEnum const& k) noexcept { + switch (k) { + case EnableSourceEnum::Unspecified: + j = "Unspecified"; + return; + case EnableSourceEnum::LocalAPI: + j = "LocalAPI"; + return; + case EnableSourceEnum::LocalKeyLock: + j = "LocalKeyLock"; + return; + case EnableSourceEnum::ServiceTechnician: + j = "ServiceTechnician"; + return; + case EnableSourceEnum::RemoteKeyLock: + j = "RemoteKeyLock"; + return; + case EnableSourceEnum::MobileApp: + j = "MobileApp"; + return; + case EnableSourceEnum::FirmwareUpdate: + j = "FirmwareUpdate"; + return; + case EnableSourceEnum::CSMS: + j = "CSMS"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::EnableSourceEnum"; +} + +void from_json(json const& j, EnableSourceEnum& k) { + std::string s = j; + if (s == "Unspecified") { + k = EnableSourceEnum::Unspecified; + return; + } + if (s == "LocalAPI") { + k = EnableSourceEnum::LocalAPI; + return; + } + if (s == "LocalKeyLock") { + k = EnableSourceEnum::LocalKeyLock; + return; + } + if (s == "ServiceTechnician") { + k = EnableSourceEnum::ServiceTechnician; + return; + } + if (s == "RemoteKeyLock") { + k = EnableSourceEnum::RemoteKeyLock; + return; + } + if (s == "MobileApp") { + k = EnableSourceEnum::MobileApp; + return; + } + if (s == "FirmwareUpdate") { + k = EnableSourceEnum::FirmwareUpdate; + return; + } + if (s == "CSMS") { + k = EnableSourceEnum::CSMS; + return; + } + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_TYPES_EVSE_MANAGER_EnableSourceEnum"); +} + +void to_json(json& j, EnableStateEnum const& k) noexcept { + switch (k) { + case EnableStateEnum::Unassigned: + j = "Unassigned"; + return; + case EnableStateEnum::Disable: + j = "Disable"; + return; + case EnableStateEnum::Enable: + j = "Enable"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::evse_manger::EnableStateEnum"; +} + +void from_json(json const& j, EnableStateEnum& k) { + std::string s = j; + if (s == "Unassigned") { + k = EnableStateEnum::Unassigned; + return; + } + if (s == "Disable") { + k = EnableStateEnum::Disable; + return; + } + if (s == "Enable") { + k = EnableStateEnum::Enable; + return; + } + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_TYPES_EVSE_MANAGER_EnableStateEnum"); +} + +void to_json(json& j, EnableDisableSource const& k) noexcept { + j = json{ + {"enable_source", k.enable_source}, + {"enable_state", k.enable_state}, + {"enable_priority", k.enable_priority}, + }; +} + +void from_json(json const& j, EnableDisableSource& k) { + k.enable_source = j.at("enable_source"); + k.enable_state = j.at("enable_state"); + k.enable_priority = j.at("enable_priority"); +} + +void to_json(json& j, EnableDisableRequest const& k) noexcept { + j = json{ + {"connector_id", k.connector_id}, + {"source", k.source}, + }; +} + +void from_json(json const& j, EnableDisableRequest& k) { + k.connector_id = j.at("connector_id"); + k.source = j.at("source"); +} + +void to_json(json& j, AuthorizeResponseArgs const& k) noexcept { + j = json{ + {"token", k.token}, + {"result", k.result}, + }; +} + +void from_json(json const& j, AuthorizeResponseArgs& k) { + k.token = j.at("token"); + k.result = j.at("result"); +} + +void to_json(json& j, PlugAndChargeConfiguration const& k) noexcept { + if (k.pnc_enabled) { + j["pnc_enabled"] = k.pnc_enabled.value(); + } + if (k.central_contract_validation_allowed) { + j["central_contract_validation_allowed"] = k.central_contract_validation_allowed.value(); + } + if (k.contract_certificate_installation_enabled) { + j["contract_certificate_installation_enabled"] = k.contract_certificate_installation_enabled.value(); + } +} + +void from_json(json const& j, PlugAndChargeConfiguration& k) { + if (j.contains("pnc_enabled")) { + k.pnc_enabled.emplace(j.at("pnc_enabled")); + } + if (j.contains("central_contract_validation_allowed")) { + k.central_contract_validation_allowed.emplace(j.at("central_contract_validation_allowed")); + } + if (j.contains("contract_certificate_installation_enabled")) { + k.contract_certificate_installation_enabled.emplace(j.at("contract_certificate_installation_enabled")); + } +} + +} // namespace everest::lib::API::V1_0::types::evse_manager diff --git a/lib/everest/everest_api_types/src/everest_api_types/evse_manager/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/evse_manager/wrapper.cpp new file mode 100644 index 0000000000..c8c80bc517 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/evse_manager/wrapper.cpp @@ -0,0 +1,777 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "evse_manager/wrapper.hpp" +#include "auth/wrapper.hpp" +#include "evse_manager/API.hpp" +#include "evse_manager/codec.hpp" +#include "powermeter/codec.hpp" +#include "powermeter/wrapper.hpp" +#include +#include +#include +#include + +namespace everest::lib::API::V1_0::types { + +namespace { +using namespace powermeter; +using namespace evse_manager; +template +auto optToInternal(std::optional const& src) -> std::optional { + if (src) { + return std::make_optional(toInternalApi(src.value())); + } + return std::nullopt; +} + +template +auto optToExternal(std::optional const& src) -> std::optional { + if (src) { + return std::make_optional(toExternalApi(src.value())); + } + return std::nullopt; +} + +} // namespace + +namespace evse_manager { + +StopTransactionReason_Internal toInternalApi(StopTransactionReason_External const& val) { + using SrcT = StopTransactionReason_External; + using TarT = StopTransactionReason_Internal; + + switch (val) { + case SrcT::EmergencyStop: + return TarT::EmergencyStop; + case SrcT::EVDisconnected: + return TarT::EVDisconnected; + case SrcT::HardReset: + return TarT::HardReset; + case SrcT::Local: + return TarT::Local; + case SrcT::Other: + return TarT::Other; + case SrcT::PowerLoss: + return TarT::PowerLoss; + case SrcT::Reboot: + return TarT::Reboot; + case SrcT::Remote: + return TarT::Remote; + case SrcT::SoftReset: + return TarT::SoftReset; + case SrcT::UnlockCommand: + return TarT::UnlockCommand; + case SrcT::DeAuthorized: + return TarT::DeAuthorized; + case SrcT::EnergyLimitReached: + return TarT::EnergyLimitReached; + case SrcT::GroundFault: + return TarT::GroundFault; + case SrcT::LocalOutOfCredit: + return TarT::LocalOutOfCredit; + case SrcT::MasterPass: + return TarT::MasterPass; + case SrcT::OvercurrentFault: + return TarT::OvercurrentFault; + case SrcT::PowerQuality: + return TarT::PowerQuality; + case SrcT::SOCLimitReached: + return TarT::SOCLimitReached; + case SrcT::StoppedByEV: + return TarT::StoppedByEV; + case SrcT::TimeLimitReached: + return TarT::TimeLimitReached; + case SrcT::Timeout: + return TarT::Timeout; + case SrcT::ReqEnergyTransferRejected: + return TarT::ReqEnergyTransferRejected; + } + throw std::out_of_range("Unexpected value for StopTransactionReason_External"); +} + +StopTransactionReason_External toExternalApi(StopTransactionReason_Internal const& val) { + using SrcT = StopTransactionReason_Internal; + using TarT = StopTransactionReason_External; + + switch (val) { + case SrcT::EmergencyStop: + return TarT::EmergencyStop; + case SrcT::EVDisconnected: + return TarT::EVDisconnected; + case SrcT::HardReset: + return TarT::HardReset; + case SrcT::Local: + return TarT::Local; + case SrcT::Other: + return TarT::Other; + case SrcT::PowerLoss: + return TarT::PowerLoss; + case SrcT::Reboot: + return TarT::Reboot; + case SrcT::Remote: + return TarT::Remote; + case SrcT::SoftReset: + return TarT::SoftReset; + case SrcT::UnlockCommand: + return TarT::UnlockCommand; + case SrcT::DeAuthorized: + return TarT::DeAuthorized; + case SrcT::EnergyLimitReached: + return TarT::EnergyLimitReached; + case SrcT::GroundFault: + return TarT::GroundFault; + case SrcT::LocalOutOfCredit: + return TarT::LocalOutOfCredit; + case SrcT::MasterPass: + return TarT::MasterPass; + case SrcT::OvercurrentFault: + return TarT::OvercurrentFault; + case SrcT::PowerQuality: + return TarT::PowerQuality; + case SrcT::SOCLimitReached: + return TarT::SOCLimitReached; + case SrcT::StoppedByEV: + return TarT::StoppedByEV; + case SrcT::TimeLimitReached: + return TarT::TimeLimitReached; + case SrcT::Timeout: + return TarT::Timeout; + case SrcT::ReqEnergyTransferRejected: + return TarT::ReqEnergyTransferRejected; + } + throw std::out_of_range("Unexpected value for StopTransactionReason_Internal"); +} + +StopTransactionRequest_Internal toInternalApi(StopTransactionRequest_External const& val) { + StopTransactionRequest_Internal result; + result.reason = toInternalApi(val.reason); + return result; +} + +StopTransactionRequest_External toExternalApi(StopTransactionRequest_Internal const& val) { + StopTransactionRequest_External result; + result.reason = toExternalApi(val.reason); + return result; +} + +StartSessionReason_Internal toInternalApi(StartSessionReason_External const& val) { + using SrcT = StartSessionReason_External; + using TarT = StartSessionReason_Internal; + switch (val) { + case SrcT::EVConnected: + return TarT::EVConnected; + case SrcT::Authorized: + return TarT::Authorized; + } + + throw std::out_of_range("Unexpected value for StartSessionReason_External"); +} + +StartSessionReason_External toExternalApi(StartSessionReason_Internal const& val) { + using SrcT = StartSessionReason_Internal; + using TarT = StartSessionReason_External; + + switch (val) { + case SrcT::EVConnected: + return TarT::EVConnected; + case SrcT::Authorized: + return TarT::Authorized; + } + + throw std::out_of_range("Unexpected value for StartSessionReason_Internal"); +} + +SessionEventEnum_Internal toInternalApi(SessionEventEnum_External const& val) { + using SrcT = SessionEventEnum_External; + using TarT = SessionEventEnum_Internal; + + switch (val) { + case SrcT::Authorized: + return TarT::Authorized; + case SrcT::Deauthorized: + return TarT::Deauthorized; + case SrcT::Enabled: + return TarT::Enabled; + case SrcT::Disabled: + return TarT::Disabled; + case SrcT::SessionStarted: + return TarT::SessionStarted; + case SrcT::AuthRequired: + return TarT::AuthRequired; + case SrcT::TransactionStarted: + return TarT::TransactionStarted; + case SrcT::PrepareCharging: + return TarT::PrepareCharging; + case SrcT::ChargingStarted: + return TarT::ChargingStarted; + case SrcT::ChargingPausedEV: + return TarT::ChargingPausedEV; + case SrcT::ChargingPausedEVSE: + return TarT::ChargingPausedEVSE; + case SrcT::WaitingForEnergy: + return TarT::WaitingForEnergy; + case SrcT::ChargingResumed: + return TarT::ChargingResumed; + case SrcT::StoppingCharging: + return TarT::StoppingCharging; + case SrcT::ChargingFinished: + return TarT::ChargingFinished; + case SrcT::TransactionFinished: + return TarT::TransactionFinished; + case SrcT::SessionFinished: + return TarT::SessionFinished; + case SrcT::ReservationStart: + return TarT::ReservationStart; + case SrcT::ReservationEnd: + return TarT::ReservationEnd; + case SrcT::ReplugStarted: + return TarT::ReplugStarted; + case SrcT::ReplugFinished: + return TarT::ReplugFinished; + case SrcT::PluginTimeout: + return TarT::PluginTimeout; + case SrcT::SwitchingPhases: + return TarT::SwitchingPhases; + case SrcT::SessionResumed: + return TarT::SessionResumed; + } + + throw std::out_of_range("Unexpected value for SessionEventEnum_Internal"); +} + +SessionEventEnum_External toExternalApi(SessionEventEnum_Internal const& val) { + using SrcT = SessionEventEnum_Internal; + using TarT = SessionEventEnum_External; + + switch (val) { + case SrcT::Authorized: + return TarT::Authorized; + case SrcT::Deauthorized: + return TarT::Deauthorized; + case SrcT::Enabled: + return TarT::Enabled; + case SrcT::Disabled: + return TarT::Disabled; + case SrcT::SessionStarted: + return TarT::SessionStarted; + case SrcT::AuthRequired: + return TarT::AuthRequired; + case SrcT::TransactionStarted: + return TarT::TransactionStarted; + case SrcT::PrepareCharging: + return TarT::PrepareCharging; + case SrcT::ChargingStarted: + return TarT::ChargingStarted; + case SrcT::ChargingPausedEV: + return TarT::ChargingPausedEV; + case SrcT::ChargingPausedEVSE: + return TarT::ChargingPausedEVSE; + case SrcT::WaitingForEnergy: + return TarT::WaitingForEnergy; + case SrcT::ChargingResumed: + return TarT::ChargingResumed; + case SrcT::StoppingCharging: + return TarT::StoppingCharging; + case SrcT::ChargingFinished: + return TarT::ChargingFinished; + case SrcT::TransactionFinished: + return TarT::TransactionFinished; + case SrcT::SessionFinished: + return TarT::SessionFinished; + case SrcT::ReservationStart: + return TarT::ReservationStart; + case SrcT::ReservationEnd: + return TarT::ReservationEnd; + case SrcT::ReplugStarted: + return TarT::ReplugStarted; + case SrcT::ReplugFinished: + return TarT::ReplugFinished; + case SrcT::PluginTimeout: + return TarT::PluginTimeout; + case SrcT::SwitchingPhases: + return TarT::SwitchingPhases; + case SrcT::SessionResumed: + return TarT::SessionResumed; + } + + throw std::out_of_range("Unexpected value for SessionEventEnum_Internal"); +} + +SessionEvent_Internal toInternalApi(SessionEvent_External const& val) { + SessionEvent_Internal result; + result.uuid = val.uuid; + result.timestamp = val.timestamp; + result.event = toInternalApi(val.event); + result.connector_id = val.connector_id; + result.session_started = optToInternal(val.session_started); + result.session_finished = optToInternal(val.session_finished); + result.transaction_started = optToInternal(val.transaction_started); + result.transaction_finished = optToInternal(val.transaction_finished); + result.charging_state_changed_event = optToInternal(val.charging_state_changed_event); + result.authorization_event = optToInternal(val.authorization_event); + return result; +} + +SessionEvent_External toExternalApi(SessionEvent_Internal const& val) { + SessionEvent_External result; + result.uuid = val.uuid; + result.timestamp = val.timestamp; + result.event = toExternalApi(val.event); + result.connector_id = val.connector_id; + result.session_started = optToExternal(val.session_started); + result.session_finished = optToExternal(val.session_finished); + result.transaction_started = optToExternal(val.transaction_started); + result.transaction_finished = optToExternal(val.transaction_finished); + result.charging_state_changed_event = optToExternal(val.charging_state_changed_event); + result.authorization_event = optToExternal(val.authorization_event); + return result; +} + +Limits_Internal toInternalApi(Limits_External const& val) { + Limits_Internal result; + result.max_current = val.max_current; + result.nr_of_phases_available = val.nr_of_phases_available; + result.uuid = val.uuid; + return result; +} + +Limits_External toExternalApi(Limits_Internal const& val) { + Limits_External result; + result.max_current = val.max_current; + result.nr_of_phases_available = val.nr_of_phases_available; + result.uuid = val.uuid; + return result; +} + +EVInfo_Internal toInternalApi(EVInfo_External const& val) { + EVInfo_Internal result; + result.soc = val.soc; + result.present_voltage = val.present_voltage; + result.present_current = val.present_current; + result.target_voltage = val.target_voltage; + result.target_current = val.target_current; + result.maximum_current_limit = val.maximum_current_limit; + result.minimum_current_limit = val.minimum_current_limit; + result.maximum_voltage_limit = val.maximum_voltage_limit; + result.maximum_power_limit = val.maximum_power_limit; + result.estimated_time_full = val.estimated_time_full; + result.departure_time = val.departure_time; + result.estimated_time_bulk = val.estimated_time_bulk; + result.evcc_id = val.evcc_id; + result.remaining_energy_needed = val.remaining_energy_needed; + result.battery_capacity = val.battery_capacity; + result.battery_full_soc = val.battery_full_soc; + result.battery_bulk_soc = val.battery_bulk_soc; + return result; +} + +EVInfo_External toExternalApi(EVInfo_Internal const& val) { + EVInfo_External result; + result.soc = val.soc; + result.present_voltage = val.present_voltage; + result.present_current = val.present_current; + result.target_voltage = val.target_voltage; + result.target_current = val.target_current; + result.maximum_current_limit = val.maximum_current_limit; + result.minimum_current_limit = val.minimum_current_limit; + result.maximum_voltage_limit = val.maximum_voltage_limit; + result.maximum_power_limit = val.maximum_power_limit; + result.estimated_time_full = val.estimated_time_full; + result.departure_time = val.departure_time; + result.estimated_time_bulk = val.estimated_time_bulk; + result.evcc_id = val.evcc_id; + result.remaining_energy_needed = val.remaining_energy_needed; + result.battery_capacity = val.battery_capacity; + result.battery_full_soc = val.battery_full_soc; + result.battery_bulk_soc = val.battery_bulk_soc; + return result; +} + +CarManufacturer_External toExternalApi(CarManufacturer_Internal const& val) { + using SrcT = CarManufacturer_Internal; + using TarT = CarManufacturer_External; + + switch (val) { + case SrcT::VolkswagenGroup: + return TarT::VolkswagenGroup; + case SrcT::Tesla: + return TarT::Tesla; + case SrcT::Unknown: + return TarT::Unknown; + } + + throw std::out_of_range("Unexpected value for CarManufacturer_Internal"); +} + +CarManufacturer_Internal toExternalApi(CarManufacturer_External const& val) { + using SrcT = CarManufacturer_External; + using TarT = CarManufacturer_Internal; + + switch (val) { + case SrcT::VolkswagenGroup: + return TarT::VolkswagenGroup; + case SrcT::Tesla: + return TarT::Tesla; + case SrcT::Unknown: + return TarT::Unknown; + } + + throw std::out_of_range("Unexpected value for CarManufacturer_Internal"); +} + +SessionStarted_Internal toInternalApi(SessionStarted_External const& val) { + SessionStarted_Internal result; + result.reason = toInternalApi(val.reason); + result.meter_value = powermeter::toInternalApi(val.meter_value); + if (val.signed_meter_value) { + result.signed_meter_value = powermeter::toInternalApi(val.signed_meter_value.value()); + } + result.reservation_id = val.reservation_id; + result.logging_path = val.logging_path; + + return result; +} + +SessionStarted_External toExternalApi(SessionStarted_Internal const& val) { + SessionStarted_External result; + result.reason = toExternalApi(val.reason); + result.meter_value = powermeter::toExternalApi(val.meter_value); + if (val.signed_meter_value) { + result.signed_meter_value = powermeter::toExternalApi(val.signed_meter_value.value()); + } + result.reservation_id = val.reservation_id; + result.logging_path = val.logging_path; + + return result; +} + +SessionFinished_Internal toInternalApi(SessionFinished_External const& val) { + SessionFinished_Internal result; + result.meter_value = powermeter::toInternalApi(val.meter_value); + return result; +} + +SessionFinished_External toExternalApi(SessionFinished_Internal const& val) { + SessionFinished_External result; + result.meter_value = powermeter::toExternalApi(val.meter_value); + return result; +} + +TransactionStarted_Internal toInternalApi(TransactionStarted_External const& val) { + TransactionStarted_Internal result; + result.id_tag = auth::toInternalApi(val.id_tag); + result.meter_value = toInternalApi(val.meter_value); + result.signed_meter_value = optToInternal(val.signed_meter_value); + result.reservation_id = val.reservation_id; + return result; +} + +TransactionStarted_External toExternalApi(TransactionStarted_Internal const& val) { + TransactionStarted_External result; + result.id_tag = auth::toExternalApi(val.id_tag); + result.meter_value = powermeter::toExternalApi(val.meter_value); + result.signed_meter_value = optToExternal(val.signed_meter_value); + result.reservation_id = val.reservation_id; + return result; +} + +TransactionFinished_Internal toInternalApi(TransactionFinished_External const& val) { + TransactionFinished_Internal result; + result.meter_value = powermeter::toInternalApi(val.meter_value); + result.start_signed_meter_value = optToInternal(val.start_signed_meter_value); + result.signed_meter_value = optToInternal(val.signed_meter_value); + result.reason = optToInternal(val.reason); + return result; +} + +TransactionFinished_External toExternalApi(TransactionFinished_Internal const& val) { + TransactionFinished_External result; + result.meter_value = powermeter::toExternalApi(val.meter_value); + result.start_signed_meter_value = optToExternal(val.start_signed_meter_value); + result.signed_meter_value = optToExternal(val.signed_meter_value); + result.reason = optToExternal(val.reason); + return result; +} + +ChargingStateChangedEvent_Internal toInternalApi(ChargingStateChangedEvent_External const& val) { + ChargingStateChangedEvent_Internal result; + result.meter_value = powermeter::toInternalApi(val.meter_value); + return result; +} + +ChargingStateChangedEvent_External toExternalApi(ChargingStateChangedEvent_Internal const& val) { + ChargingStateChangedEvent_External result; + result.meter_value = powermeter::toExternalApi(val.meter_value); + return result; +} + +AuthorizationEvent_Internal toInternalApi(AuthorizationEvent_External const& val) { + AuthorizationEvent_Internal result; + result.meter_value = powermeter::toInternalApi(val.meter_value); + return result; +} + +AuthorizationEvent_External toExternalApi(AuthorizationEvent_Internal const& val) { + AuthorizationEvent_External result; + result.meter_value = powermeter::toExternalApi(val.meter_value); + return result; +} + +ConnectorTypeEnum_Internal toInternalApi(ConnectorTypeEnum_External const& val) { + using SrcT = ConnectorTypeEnum_External; + using TarT = ConnectorTypeEnum_Internal; + + switch (val) { + case SrcT::cCCS1: + return TarT::cCCS1; + case SrcT::cCCS2: + return TarT::cCCS2; + case SrcT::cG105: + return TarT::cG105; + case SrcT::cTesla: + return TarT::cTesla; + case SrcT::cType1: + return TarT::cType1; + case SrcT::cType2: + return TarT::cType2; + case SrcT::s309_1P_16A: + return TarT::s309_1P_16A; + case SrcT::s309_1P_32A: + return TarT::s309_1P_32A; + case SrcT::s309_3P_16A: + return TarT::s309_3P_16A; + case SrcT::s309_3P_32A: + return TarT::s309_3P_32A; + case SrcT::sBS1361: + return TarT::sBS1361; + case SrcT::sCEE_7_7: + return TarT::sCEE_7_7; + case SrcT::sType2: + return TarT::sType2; + case SrcT::sType3: + return TarT::sType3; + case SrcT::Other1PhMax16A: + return TarT::Other1PhMax16A; + case SrcT::Other1PhOver16A: + return TarT::Other1PhOver16A; + case SrcT::Other3Ph: + return TarT::Other3Ph; + case SrcT::Pan: + return TarT::Pan; + case SrcT::wInductive: + return TarT::wInductive; + case SrcT::wResonant: + return TarT::wResonant; + case SrcT::Undetermined: + return TarT::Undetermined; + case SrcT::Unknown: + return TarT::Unknown; + } + throw std::out_of_range("Unexpected value for ConnectorTypeEnum_External"); +} + +ConnectorTypeEnum_External toExternalApi(ConnectorTypeEnum_Internal const& val) { + using SrcT = ConnectorTypeEnum_Internal; + using TarT = ConnectorTypeEnum_External; + + switch (val) { + case SrcT::cCCS1: + return TarT::cCCS1; + case SrcT::cCCS2: + return TarT::cCCS2; + case SrcT::cG105: + return TarT::cG105; + case SrcT::cTesla: + return TarT::cTesla; + case SrcT::cType1: + return TarT::cType1; + case SrcT::cType2: + return TarT::cType2; + case SrcT::s309_1P_16A: + return TarT::s309_1P_16A; + case SrcT::s309_1P_32A: + return TarT::s309_1P_32A; + case SrcT::s309_3P_16A: + return TarT::s309_3P_16A; + case SrcT::s309_3P_32A: + return TarT::s309_3P_32A; + case SrcT::sBS1361: + return TarT::sBS1361; + case SrcT::sCEE_7_7: + return TarT::sCEE_7_7; + case SrcT::sType2: + return TarT::sType2; + case SrcT::sType3: + return TarT::sType3; + case SrcT::Other1PhMax16A: + return TarT::Other1PhMax16A; + case SrcT::Other1PhOver16A: + return TarT::Other1PhOver16A; + case SrcT::Other3Ph: + return TarT::Other3Ph; + case SrcT::Pan: + return TarT::Pan; + case SrcT::wInductive: + return TarT::wInductive; + case SrcT::wResonant: + return TarT::wResonant; + case SrcT::Undetermined: + return TarT::Undetermined; + case SrcT::Unknown: + return TarT::Unknown; + } + throw std::out_of_range("Unexpected value for ConnectorTypeEnum_External"); +} + +Connector_Internal toInternalApi(Connector_External const& val) { + Connector_Internal result; + result.id = val.id; + result.type = optToInternal(val.type); + + return result; +} +Connector_External toExternalApi(Connector_Internal const& val) { + Connector_External result; + result.id = val.id; + result.type = optToExternal(val.type); + + return result; +} + +Evse_Internal toInternalApi(Evse_External const& val) { + Evse_Internal result; + result.id = val.id; + for (auto const& elem : val.connectors) { + result.connectors.push_back(toInternalApi(elem)); + } + return result; +} + +Evse_External toExternalApi(Evse_Internal const& val) { + Evse_External result; + result.id = val.id; + for (auto const& elem : val.connectors) { + result.connectors.push_back(toExternalApi(elem)); + } + return result; +} + +EnableSourceEnum_Internal toInternalApi(EnableSourceEnum_External const& val) { + using SrcT = EnableSourceEnum_External; + using TarT = EnableSourceEnum_Internal; + + switch (val) { + case SrcT::Unspecified: + return TarT::Unspecified; + case SrcT::LocalAPI: + return TarT::LocalAPI; + case SrcT::LocalKeyLock: + return TarT::LocalKeyLock; + case SrcT::ServiceTechnician: + return TarT::ServiceTechnician; + case SrcT::RemoteKeyLock: + return TarT::RemoteKeyLock; + case SrcT::MobileApp: + return TarT::MobileApp; + case SrcT::FirmwareUpdate: + return TarT::FirmwareUpdate; + case SrcT::CSMS: + return TarT::CSMS; + } + throw std::out_of_range("Unexpected value for EnableSourceEnum_External"); +} + +EnableSourceEnum_External toExternalApi(EnableSourceEnum_Internal const& val) { + using SrcT = EnableSourceEnum_Internal; + using TarT = EnableSourceEnum_External; + + switch (val) { + case SrcT::Unspecified: + return TarT::Unspecified; + case SrcT::LocalAPI: + return TarT::LocalAPI; + case SrcT::LocalKeyLock: + return TarT::LocalKeyLock; + case SrcT::ServiceTechnician: + return TarT::ServiceTechnician; + case SrcT::RemoteKeyLock: + return TarT::RemoteKeyLock; + case SrcT::MobileApp: + return TarT::MobileApp; + case SrcT::FirmwareUpdate: + return TarT::FirmwareUpdate; + case SrcT::CSMS: + return TarT::CSMS; + } + throw std::out_of_range("Unexpected value for EnableSourceEnum_Internal"); +} + +EnableStateEnum_Internal toInternalApi(EnableStateEnum_External const& val) { + using SrcT = EnableStateEnum_External; + using TarT = EnableStateEnum_Internal; + + switch (val) { + case SrcT::Unassigned: + return TarT::Unassigned; + case SrcT::Disable: + return TarT::Disable; + case SrcT::Enable: + return TarT::Enable; + } + throw std::out_of_range("Unexpected value for EnableStateEnum_External"); +} + +EnableStateEnum_External toExternalApi(EnableStateEnum_Internal const& val) { + using SrcT = EnableStateEnum_Internal; + using TarT = EnableStateEnum_External; + + switch (val) { + case SrcT::Unassigned: + return TarT::Unassigned; + case SrcT::Disable: + return TarT::Disable; + case SrcT::Enable: + return TarT::Enable; + } + throw std::out_of_range("Unexpected value for EnableStateEnum_Internal"); +} + +EnableDisableSource_Internal toInternalApi(EnableDisableSource_External const& val) { + EnableDisableSource_Internal result; + result.enable_source = toInternalApi(val.enable_source); + result.enable_state = toInternalApi(val.enable_state); + result.enable_priority = val.enable_priority; + + return result; +} + +EnableDisableSource_External toExternalApi(EnableDisableSource_Internal const& val) { + EnableDisableSource_External result; + result.enable_source = toExternalApi(val.enable_source); + result.enable_state = toExternalApi(val.enable_state); + result.enable_priority = val.enable_priority; + + return result; +} + +PlugAndChargeConfiguration_Internal toInternalApi(PlugAndChargeConfiguration_External const& val) { + PlugAndChargeConfiguration_Internal result; + result.pnc_enabled = val.pnc_enabled; + result.central_contract_validation_allowed = val.central_contract_validation_allowed; + result.contract_certificate_installation_enabled = val.contract_certificate_installation_enabled; + + return result; +} + +PlugAndChargeConfiguration_External toExternalApi(PlugAndChargeConfiguration_Internal const& val) { + PlugAndChargeConfiguration_External result; + result.pnc_enabled = val.pnc_enabled; + result.central_contract_validation_allowed = val.central_contract_validation_allowed; + result.contract_certificate_installation_enabled = val.contract_certificate_installation_enabled; + + return result; +} + +} // namespace evse_manager +} // namespace everest::lib::API::V1_0::types diff --git a/lib/everest/everest_api_types/src/everest_api_types/generic/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/generic/codec.cpp new file mode 100644 index 0000000000..8170904527 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/generic/codec.cpp @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "generic/codec.hpp" +#include "generic/API.hpp" +#include "generic/json_codec.hpp" +#include "nlohmann/json.hpp" +#include +#include + +using json = nlohmann::json; + +namespace everest::lib::API::V1_0::types::generic { + +std::string serialize(bool val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(int val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(double val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(float val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(std::string const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(RequestReply const& val) { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Error const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, RequestReply const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Error& val) { + os << serialize(val); + return os; +} + +template <> bool deserialize(std::string const& s) { + auto data = json::parse(s); + bool result = data; + return result; +} + +template <> int deserialize(std::string const& s) { + auto data = json::parse(s); + int result = data; + return result; +} + +template <> double deserialize(std::string const& s) { + auto data = json::parse(s); + double result = data; + return result; +} + +template <> float deserialize(std::string const& s) { + auto data = json::parse(s); + float result = data; + return result; +} + +template <> std::string deserialize(std::string const& s) { + auto data = json::parse(s); + std::string result = data; + return result; +} + +template <> RequestReply deserialize(std::string const& s) { + auto data = json::parse(s); + RequestReply result = data; + return result; +} + +template <> ErrorEnum deserialize(std::string const& s) { + auto data = json::parse(s); + ErrorEnum result = data; + return result; +} + +template <> Error deserialize(std::string const& s) { + auto data = json::parse(s); + Error result = data; + return result; +} + +} // namespace everest::lib::API::V1_0::types::generic diff --git a/lib/everest/everest_api_types/src/everest_api_types/generic/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/generic/json_codec.cpp new file mode 100644 index 0000000000..b2c309608f --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/generic/json_codec.cpp @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "generic/json_codec.hpp" +#include "generic/API.hpp" +#include "nlohmann/json.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::generic { + +void to_json(json& j, RequestReply const& k) { + json payload; + try { + payload = json::parse(k.payload); + } catch (...) { + throw std::invalid_argument("payload is invalid json: " + k.payload); + } + j["headers"]["replyTo"] = k.replyTo; + j["payload"] = payload; +} + +void from_json(json const& j, RequestReply& k) { + k.replyTo = j["headers"]["replyTo"]; + if (j.contains("payload")) { + k.payload = j["payload"].dump(); + } else + k.payload = ""; +} + +void to_json(json& j, ErrorEnum const& k) noexcept { + switch (k) { + case ErrorEnum::CommunicationFault: + j = "CommunicationFault"; + return; + case ErrorEnum::VendorError: + j = "VendorError"; + return; + case ErrorEnum::VendorWarning: + j = "VendorWarning"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::generic::ErrorEnum"; +} + +void from_json(json const& j, ErrorEnum& k) { + std::string s = j; + if (s == "CommunicationFault") { + k = ErrorEnum::CommunicationFault; + return; + } + if (s == "VendorError") { + k = ErrorEnum::VendorError; + return; + } + if (s == "VendorWarning") { + k = ErrorEnum::VendorWarning; + return; + } + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_TYPES_GENERIC_ErrorEnum"); +} + +void to_json(json& j, const Error& k) noexcept { + j = json{ + {"type", k.type}, + }; + if (k.sub_type) { + j["sub_type"] = k.sub_type.value(); + } + if (k.message) { + j["message"] = k.message.value(); + }; +} + +void from_json(const json& j, Error& k) { + k.type = j.at("type"); + if (j.contains("sub_type")) { + k.sub_type.emplace(j.at("sub_type")); + } + if (j.contains("message")) { + k.message.emplace(j.at("message")); + } +} + +} // namespace everest::lib::API::V1_0::types::generic diff --git a/lib/everest/everest_api_types/src/everest_api_types/generic/string.cpp b/lib/everest/everest_api_types/src/everest_api_types/generic/string.cpp new file mode 100644 index 0000000000..153dbb81a1 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/generic/string.cpp @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "generic/string.hpp" +#include "nlohmann/json.hpp" + +namespace everest::lib::API::V1_0::types::generic { + +std::string trimmed(std::string const& str) { + auto length = str.length(); + auto offset = length >= 1 and str[0] == '"' ? 1 : 0; + auto count = (length >= 2 and str[length - 1] == '"' ? length - 1 : length) - offset; + return str.substr(offset, count); +} + +std::optional compress_json(std::string data) { + try { + auto obj = nlohmann::json::parse(data); + return obj.dump(); + } catch (...) { + } + return std::nullopt; +} + +} // namespace everest::lib::API::V1_0::types::generic diff --git a/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/codec.cpp new file mode 100644 index 0000000000..9143479909 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/codec.cpp @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "iso15118_charger/codec.hpp" +#include "iso15118_charger/API.hpp" +#include "iso15118_charger/json_codec.hpp" +#include "nlohmann/json.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::iso15118_charger { + +std::string serialize(CertificateActionEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Status val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(RequestExiStreamSchema const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ResponseExiStreamStatus const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, CertificateActionEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Status const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, RequestExiStreamSchema const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ResponseExiStreamStatus const& val) { + os << serialize(val); + return os; +} + +template <> CertificateActionEnum deserialize(std::string const& s) { + auto data = json::parse(s); + CertificateActionEnum result = data; + return result; +} + +template <> Status deserialize(std::string const& s) { + auto data = json::parse(s); + Status result = data; + return result; +} + +template <> RequestExiStreamSchema deserialize(std::string const& s) { + auto data = json::parse(s); + RequestExiStreamSchema result = data; + return result; +} + +template <> ResponseExiStreamStatus deserialize(std::string const& s) { + auto data = json::parse(s); + ResponseExiStreamStatus result = data; + return result; +} + +} // namespace everest::lib::API::V1_0::types::iso15118_charger diff --git a/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/json_codec.cpp new file mode 100644 index 0000000000..6e8d315d76 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/json_codec.cpp @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "iso15118_charger/json_codec.hpp" +#include "iso15118_charger/API.hpp" +#include "iso15118_charger/codec.hpp" +#include "nlohmann/json.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::iso15118_charger { + +void from_json(json const& j, CertificateActionEnum& k) { + std::string s = j; + if (s == "Install") { + k = CertificateActionEnum::Install; + return; + } + if (s == "Update") { + k = CertificateActionEnum::Update; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type API_V1_0_TYPES_ISO15118_CHARGER_CertificateActionEnum"); +} + +void to_json(json& j, CertificateActionEnum const& k) noexcept { + switch (k) { + case CertificateActionEnum::Install: + j = "Install"; + return; + case CertificateActionEnum::Update: + j = "Update"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::iso15118_charger::CertificateActionEnum"; +} + +void from_json(json const& j, Status& k) { + std::string s = j; + if (s == "Accepted") { + k = Status::Accepted; + return; + } + if (s == "Failed") { + k = Status::Failed; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_TYPES_ISO15118_CHARGER_Status"); +} + +void to_json(json& j, Status const& k) noexcept { + switch (k) { + case Status::Accepted: + j = "Accepted"; + return; + case Status::Failed: + j = "Failed"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::iso15118_charger::Status"; +} + +void from_json(const json& j, RequestExiStreamSchema& k) { + k.exi_request = j.at("exi_request"); + k.iso15118_schema_version = j.at("iso15118_schema_version"); + k.certificate_action = j.at("certificate_action"); +} + +void to_json(json& j, RequestExiStreamSchema const& k) noexcept { + j = json{ + {"exi_request", k.exi_request}, + {"iso15118_schema_version", k.iso15118_schema_version}, + {"certificate_action", k.certificate_action}, + }; +} + +void from_json(const json& j, ResponseExiStreamStatus& k) { + k.status = j.at("status"); + k.certificate_action = j.at("certificate_action"); + if (j.contains("exi_response")) { + k.exi_response.emplace(j.at("exi_response")); + } +} + +void to_json(json& j, ResponseExiStreamStatus const& k) noexcept { + j = json{ + {"status", k.status}, + {"certificate_action", k.certificate_action}, + }; + if (k.exi_response) { + j["exi_response"] = k.exi_response.value(); + } +} + +} // namespace everest::lib::API::V1_0::types::iso15118_charger diff --git a/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/wrapper.cpp new file mode 100644 index 0000000000..1f48d44c44 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/iso15118_charger/wrapper.cpp @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "iso15118_charger/wrapper.hpp" +#include "iso15118_charger/API.hpp" +#include "iso15118_charger/codec.hpp" +#include +#include +#include + +namespace everest::lib::API::V1_0::types { + +namespace { +using namespace iso15118_charger; +template +auto optToInternal(std::optional const& src) -> std::optional { + if (src) { + return std::make_optional(toInternalApi(src.value())); + } + return std::nullopt; +} + +template +auto optToExternal(std::optional const& src) -> std::optional { + if (src) { + return std::make_optional(toExternalApi(src.value())); + } + return std::nullopt; +} + +} // namespace + +namespace iso15118_charger { + +CertificateActionEnum_Internal toInternalApi(CertificateActionEnum_External const& val) { + using SrcT = CertificateActionEnum_External; + using TarT = CertificateActionEnum_Internal; + + switch (val) { + case SrcT::Install: + return TarT::Install; + case SrcT::Update: + return TarT::Update; + } + + throw std::out_of_range("Unexpected value for CertificateActionEnum_External"); +} + +CertificateActionEnum_External toExternalApi(CertificateActionEnum_Internal const& val) { + using SrcT = CertificateActionEnum_Internal; + using TarT = CertificateActionEnum_External; + + switch (val) { + case SrcT::Install: + return TarT::Install; + case SrcT::Update: + return TarT::Update; + } + + throw std::out_of_range("Unexpected value for CertificateActionEnum_Internal"); +} + +Status_Internal toInternalApi(Status_External const& val) { + using SrcT = Status_External; + using TarT = Status_Internal; + + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Failed: + return TarT::Failed; + } + + throw std::out_of_range("Unexpected value for Status_External"); +} + +Status_External toExternalApi(Status_Internal const& val) { + using SrcT = Status_Internal; + using TarT = Status_External; + + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Failed: + return TarT::Failed; + } + + throw std::out_of_range("Unexpected value for Status_Internal"); +} + +RequestExiStreamSchema_Internal toInternalApi(RequestExiStreamSchema_External const& val) { + RequestExiStreamSchema_Internal result; + result.exi_request = val.exi_request; + result.iso15118_schema_version = val.iso15118_schema_version; + result.certificate_action = toInternalApi(val.certificate_action); + return result; +} + +RequestExiStreamSchema_External toExternalApi(RequestExiStreamSchema_Internal const& val) { + RequestExiStreamSchema_External result; + result.exi_request = val.exi_request; + result.iso15118_schema_version = val.iso15118_schema_version; + result.certificate_action = toExternalApi(val.certificate_action); + return result; +} + +ResponseExiStreamStatus_Internal toInternalApi(ResponseExiStreamStatus_External const& val) { + ResponseExiStreamStatus_Internal result; + result.status = toInternalApi(val.status); + result.certificate_action = toInternalApi(val.certificate_action); + result.exi_response = val.exi_response; + return result; +} + +ResponseExiStreamStatus_External toExternalApi(ResponseExiStreamStatus_Internal const& val) { + ResponseExiStreamStatus_External result; + result.status = toExternalApi(val.status); + result.certificate_action = toExternalApi(val.certificate_action); + result.exi_response = val.exi_response; + return result; +} + +} // namespace iso15118_charger +} // namespace everest::lib::API::V1_0::types diff --git a/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/codec.cpp new file mode 100644 index 0000000000..7933eb4af6 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/codec.cpp @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "isolation_monitor/codec.hpp" +#include "isolation_monitor/API.hpp" +#include "isolation_monitor/json_codec.hpp" +#include "nlohmann/json.hpp" +#include + +namespace everest::lib::API::V1_0::types::isolation_monitor { + +std::string serialize(IsolationMeasurement const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Error const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, IsolationMeasurement const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Error& val) { + os << serialize(val); + return os; +} + +template <> IsolationMeasurement deserialize(std::string const& s) { + auto data = json::parse(s); + IsolationMeasurement result = data; + return result; +} + +template <> ErrorEnum deserialize(std::string const& s) { + auto data = json::parse(s); + ErrorEnum result = data; + return result; +} + +template <> Error deserialize(std::string const& s) { + auto data = json::parse(s); + Error result = data; + return result; +} + +} // namespace everest::lib::API::V1_0::types::isolation_monitor diff --git a/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/json_codec.cpp new file mode 100644 index 0000000000..ce7babad3c --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/json_codec.cpp @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "isolation_monitor/json_codec.hpp" +#include "isolation_monitor/API.hpp" +#include "isolation_monitor/codec.hpp" +#include "nlohmann/json.hpp" +#include + +namespace everest::lib::API::V1_0::types::isolation_monitor { + +void to_json(json& j, const IsolationMeasurement& k) noexcept { + j = json{{"resistance_F_Ohm", k.resistance_F_Ohm}}; + if (k.voltage_V) { + j["voltage_V"] = k.voltage_V.value(); + } +} + +void from_json(const json& j, IsolationMeasurement& k) { + k.resistance_F_Ohm = j.at("resistance_F_Ohm"); + if (j.contains("voltage_V")) { + k.voltage_V.emplace(j.at("voltage_V")); + } +} + +void to_json(json& j, ErrorEnum const& k) noexcept { + switch (k) { + case ErrorEnum::DeviceFault: + j = "DeviceFault"; + return; + case ErrorEnum::CommunicationFault: + j = "CommunicationFault"; + return; + case ErrorEnum::VendorError: + j = "VendorError"; + return; + case ErrorEnum::VendorWarning: + j = "VendorWarning"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::isolation_monitor::error"; +} + +void from_json(json const& j, ErrorEnum& k) { + std::string s = j; + if (s == "DeviceFault") { + k = ErrorEnum::DeviceFault; + return; + } + if (s == "CommunicationFault") { + k = ErrorEnum::CommunicationFault; + return; + } + if (s == "VendorError") { + k = ErrorEnum::VendorError; + return; + } + if (s == "VendorWarning") { + k = ErrorEnum::VendorWarning; + return; + } + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type isolation_monitor_ErrorEnum_API_1_0"); +} + +void to_json(json& j, const Error& k) noexcept { + j = json{ + {"type", k.type}, + }; + if (k.sub_type) { + j["sub_type"] = k.sub_type.value(); + } + if (k.message) { + j["message"] = k.message.value(); + }; +} + +void from_json(const json& j, Error& k) { + k.type = j.at("type"); + if (j.contains("sub_type")) { + k.sub_type.emplace(j.at("sub_type")); + } + if (j.contains("message")) { + k.message.emplace(j.at("message")); + } +} + +} // namespace everest::lib::API::V1_0::types::isolation_monitor diff --git a/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/wrapper.cpp new file mode 100644 index 0000000000..82dea89d76 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/isolation_monitor/wrapper.cpp @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "isolation_monitor/wrapper.hpp" +#include "isolation_monitor/API.hpp" + +namespace everest::lib::API::V1_0::types::isolation_monitor { + +IsolationMeasurement_Internal toInternalApi(IsolationMeasurement_External const& val) { + IsolationMeasurement_Internal result; + result.resistance_F_Ohm = val.resistance_F_Ohm; + result.voltage_V = val.voltage_V; + return result; +} +IsolationMeasurement_External toExternalApi(IsolationMeasurement_Internal const& val) { + IsolationMeasurement_External result; + result.resistance_F_Ohm = val.resistance_F_Ohm; + result.voltage_V = val.voltage_V; + return result; +} + +} // namespace everest::lib::API::V1_0::types::isolation_monitor diff --git a/lib/everest/everest_api_types/src/everest_api_types/ocpp/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/ocpp/codec.cpp new file mode 100644 index 0000000000..06b63d830d --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/ocpp/codec.cpp @@ -0,0 +1,429 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "ocpp/codec.hpp" +#include "nlohmann/json.hpp" +#include "ocpp/API.hpp" +#include "ocpp/json_codec.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::ocpp { + +std::string serialize(AttributeEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(GetVariableStatusEnumType val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetVariableStatusEnumType val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(DataTransferStatus val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(RegistrationStatus val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(TransactionEvent val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(CustomData const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(DataTransferRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(DataTransferResponse const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(EVSE const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Component const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Variable const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ComponentVariable const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(GetVariableRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(GetVariableResult const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetVariableRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetVariableResult const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(GetVariableRequestList const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(GetVariableResultList const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetVariableRequestList const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetVariableResultList const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SecurityEvent const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(SetVariablesArgs const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(StatusInfoType const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(BootNotificationResponse const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(OcppTransactionEvent const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, AttributeEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, GetVariableStatusEnumType const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetVariableStatusEnumType const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, DataTransferStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, RegistrationStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, TransactionEvent const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, CustomData const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, DataTransferRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, DataTransferResponse const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, EVSE const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Component const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Variable const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ComponentVariable const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, GetVariableRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, GetVariableResult const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetVariableRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetVariableResult const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, GetVariableRequestList const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, GetVariableResultList const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetVariableRequestList const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetVariableResultList const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SetVariablesArgs const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SecurityEvent const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, StatusInfoType const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, BootNotificationResponse const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, OcppTransactionEvent const& val) { + os << serialize(val); + return os; +} + +template <> AttributeEnum deserialize(std::string const& val) { + auto data = json::parse(val); + AttributeEnum obj = data; + return obj; +} + +template <> GetVariableStatusEnumType deserialize<>(std::string const& val) { + auto data = json::parse(val); + GetVariableStatusEnumType obj = data; + return obj; +} + +template <> SetVariableStatusEnumType deserialize<>(std::string const& val) { + auto data = json::parse(val); + SetVariableStatusEnumType obj = data; + return obj; +} + +template <> DataTransferStatus deserialize<>(std::string const& val) { + auto data = json::parse(val); + DataTransferStatus obj = data; + return obj; +} + +template <> RegistrationStatus deserialize<>(std::string const& val) { + auto data = json::parse(val); + RegistrationStatus obj = data; + return obj; +} + +template <> TransactionEvent deserialize<>(std::string const& val) { + auto data = json::parse(val); + TransactionEvent obj = data; + return obj; +} + +template <> CustomData deserialize<>(std::string const& val) { + auto data = json::parse(val); + CustomData obj = data; + return obj; +} + +template <> DataTransferRequest deserialize<>(std::string const& val) { + auto data = json::parse(val); + DataTransferRequest obj = data; + return obj; +} + +template <> DataTransferResponse deserialize<>(std::string const& val) { + auto data = json::parse(val); + DataTransferResponse obj = data; + return obj; +} + +template <> EVSE deserialize<>(const std::string& val) { + auto data = json::parse(val); + EVSE obj = data; + return obj; +} + +template <> Component deserialize<>(const std::string& val) { + auto data = json::parse(val); + Component obj = data; + return obj; +} + +template <> Variable deserialize<>(const std::string& val) { + auto data = json::parse(val); + Variable obj = data; + return obj; +} + +template <> ComponentVariable deserialize<>(const std::string& val) { + auto data = json::parse(val); + ComponentVariable obj = data; + return obj; +} + +template <> GetVariableRequest deserialize<>(const std::string& val) { + auto data = json::parse(val); + GetVariableRequest obj = data; + return obj; +} + +template <> GetVariableResult deserialize<>(const std::string& val) { + auto data = json::parse(val); + GetVariableResult obj = data; + return obj; +} + +template <> SetVariableRequest deserialize<>(const std::string& val) { + auto data = json::parse(val); + SetVariableRequest obj = data; + return obj; +} + +template <> SetVariableResult deserialize<>(const std::string& val) { + auto data = json::parse(val); + SetVariableResult obj = data; + return obj; +} + +template <> GetVariableRequestList deserialize<>(const std::string& val) { + auto data = json::parse(val); + GetVariableRequestList obj = data; + return obj; +} + +template <> GetVariableResultList deserialize<>(const std::string& val) { + auto data = json::parse(val); + GetVariableResultList obj = data; + return obj; +} + +template <> SetVariableRequestList deserialize<>(const std::string& val) { + auto data = json::parse(val); + SetVariableRequestList obj = data; + return obj; +} + +template <> SetVariableResultList deserialize<>(const std::string& val) { + auto data = json::parse(val); + SetVariableResultList obj = data; + return obj; +} + +template <> SetVariablesArgs deserialize<>(const std::string& val) { + auto data = json::parse(val); + SetVariablesArgs obj = data; + return obj; +} + +template <> SecurityEvent deserialize<>(const std::string& val) { + auto data = json::parse(val); + SecurityEvent obj = data; + return obj; +} + +template <> StatusInfoType deserialize<>(const std::string& val) { + auto data = json::parse(val); + StatusInfoType obj = data; + return obj; +} + +template <> BootNotificationResponse deserialize<>(const std::string& val) { + auto data = json::parse(val); + BootNotificationResponse obj = data; + return obj; +} + +template <> OcppTransactionEvent deserialize<>(const std::string& val) { + auto data = json::parse(val); + OcppTransactionEvent obj = data; + return obj; +} + +} // namespace everest::lib::API::V1_0::types::ocpp diff --git a/lib/everest/everest_api_types/src/everest_api_types/ocpp/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/ocpp/json_codec.cpp new file mode 100644 index 0000000000..1a5583277e --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/ocpp/json_codec.cpp @@ -0,0 +1,638 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "ocpp/json_codec.hpp" +#include "nlohmann/json.hpp" +#include "ocpp/API.hpp" +#include "ocpp/codec.hpp" + +namespace everest::lib::API::V1_0::types::ocpp { + +using json = nlohmann::json; + +void to_json(json& j, AttributeEnum const& k) noexcept { + switch (k) { + case AttributeEnum::Actual: + j = "Actual"; + return; + case AttributeEnum::Target: + j = "Target"; + return; + case AttributeEnum::MinSet: + j = "MinSet"; + return; + case AttributeEnum::MaxSet: + j = "MaxSet"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::ocpp::AttributeEnum"; +} + +void from_json(const json& j, AttributeEnum& k) { + std::string s = j; + if (s == "Actual") { + k = AttributeEnum::Actual; + return; + } + if (s == "Target") { + k = AttributeEnum::Target; + return; + } + if (s == "MinSet") { + k = AttributeEnum::MinSet; + return; + } + if (s == "MaxSet") { + k = AttributeEnum::MaxSet; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::ocpp::AttributeEnum"); +} + +void to_json(json& j, GetVariableStatusEnumType const& k) noexcept { + switch (k) { + case GetVariableStatusEnumType::Accepted: + j = "Accepted"; + return; + case GetVariableStatusEnumType::Rejected: + j = "Rejected"; + return; + case GetVariableStatusEnumType::UnknownComponent: + j = "UnknownComponent"; + return; + case GetVariableStatusEnumType::UnknownVariable: + j = "UnknownVariable"; + return; + case GetVariableStatusEnumType::NotSupportedAttributeType: + j = "NotSupportedAttributeType"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::ocpp::GetVariableStatueEnum"; +} + +void from_json(const json& j, GetVariableStatusEnumType& k) { + std::string s = j; + if (s == "Accepted") { + k = GetVariableStatusEnumType::Accepted; + return; + } + if (s == "Rejected") { + k = GetVariableStatusEnumType::Rejected; + return; + } + if (s == "UnknownComponent") { + k = GetVariableStatusEnumType::UnknownComponent; + return; + } + if (s == "UnknownVariable") { + k = GetVariableStatusEnumType::UnknownVariable; + return; + } + if (s == "NotSupportedAttributeType") { + k = GetVariableStatusEnumType::NotSupportedAttributeType; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::ocpp::GetVariableStatusEnum"); +} + +void to_json(json& j, SetVariableStatusEnumType const& k) noexcept { + switch (k) { + case SetVariableStatusEnumType::Accepted: + j = "Accepted"; + return; + case SetVariableStatusEnumType::Rejected: + j = "Rejected"; + return; + case SetVariableStatusEnumType::UnknownComponent: + j = "UnknownComponent"; + return; + case SetVariableStatusEnumType::UnknownVariable: + j = "UnknownVariable"; + return; + case SetVariableStatusEnumType::NotSupportedAttributeType: + j = "NotSupportedAttributeType"; + return; + case SetVariableStatusEnumType::RebootRequired: + j = "RebootRequired"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::ocpp::SetVariableStatueEnum"; +} + +void from_json(const json& j, SetVariableStatusEnumType& k) { + std::string s = j; + if (s == "Accepted") { + k = SetVariableStatusEnumType::Accepted; + return; + } + if (s == "Rejected") { + k = SetVariableStatusEnumType::Rejected; + return; + } + if (s == "UnknownComponent") { + k = SetVariableStatusEnumType::UnknownComponent; + return; + } + if (s == "UnknownVariable") { + k = SetVariableStatusEnumType::UnknownVariable; + return; + } + if (s == "NotSupportedAttributeType") { + k = SetVariableStatusEnumType::NotSupportedAttributeType; + return; + } + if (s == "RebootRequired") { + k = SetVariableStatusEnumType::RebootRequired; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::ocpp::SetVariableStatusEnum"); +} + +void to_json(json& j, DataTransferStatus const& k) noexcept { + switch (k) { + case DataTransferStatus::Accepted: + j = "Accepted"; + return; + case DataTransferStatus::Rejected: + j = "Rejected"; + return; + case DataTransferStatus::UnknownMessageId: + j = "UnknownMessageId"; + return; + case DataTransferStatus::UnknownVendorId: + j = "UnknownVendorId"; + return; + case DataTransferStatus::Offline: + j = "Offline"; + return; + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::ocpp::DataTransferStatus"; + } +} + +void from_json(const json& j, DataTransferStatus& k) { + std::string s = j; + if (s == "Accepted") { + k = DataTransferStatus::Accepted; + return; + } + if (s == "Rejected") { + k = DataTransferStatus::Rejected; + return; + } + if (s == "UnknownMessageId") { + k = DataTransferStatus::UnknownMessageId; + return; + } + if (s == "UnknownVendorId") { + k = DataTransferStatus::UnknownVendorId; + return; + } + if (s == "Offline") { + k = DataTransferStatus::Offline; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::ocpp::DataTransferStatus"); +} + +void to_json(json& j, RegistrationStatus const& k) noexcept { + switch (k) { + case RegistrationStatus::Accepted: + j = "Accepted"; + return; + case RegistrationStatus::Pending: + j = "Pending"; + return; + case RegistrationStatus::Rejected: + j = "Rejected"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::ocpp::RegistrationStatus"; +} + +void from_json(const json& j, RegistrationStatus& k) { + std::string s = j; + if (s == "Accepted") { + k = RegistrationStatus::Accepted; + return; + } + if (s == "Pending") { + k = RegistrationStatus::Pending; + return; + } + if (s == "Rejected") { + k = RegistrationStatus::Rejected; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::ocpp::RegistrationStatus"); +} + +void to_json(json& j, TransactionEvent const& k) noexcept { + switch (k) { + case TransactionEvent::Started: + j = "Started"; + return; + case TransactionEvent::Updated: + j = "Updated"; + return; + case TransactionEvent::Ended: + j = "Ended"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::ocpp::TransactionEvent"; +} + +void from_json(const json& j, TransactionEvent& k) { + std::string s = j; + if (s == "Started") { + k = TransactionEvent::Started; + return; + } + if (s == "Updated") { + k = TransactionEvent::Updated; + return; + } + if (s == "Ended") { + k = TransactionEvent::Ended; + return; + } + + throw std::out_of_range( + "Provided string " + s + + " could not be converted to enum of type everest::lib::API::V1_0::types::ocpp::TransactionEvent"); +} + +void to_json(json& j, CustomData const& k) noexcept { + j = json{ + {"vendor_id", k.vendor_id}, + {"data", k.data}, + }; +} + +void from_json(const json& j, CustomData& k) { + k.vendor_id = j.at("vendor_id"); + k.data = j.at("data"); +} + +void to_json(json& j, DataTransferRequest const& k) noexcept { + j = json{ + {"vendor_id", k.vendor_id}, + }; + if (k.message_id) { + j["message_id"] = k.message_id.value(); + } + if (k.data) { + j["data"] = k.data.value(); + } + if (k.custom_data) { + j["custom_data"] = k.custom_data.value(); + } +} + +void from_json(const json& j, DataTransferRequest& k) { + k.vendor_id = j.at("vendor_id"); + + if (j.contains("message_id")) { + k.message_id.emplace(j.at("message_id")); + } + if (j.contains("data")) { + k.data.emplace(j.at("data")); + } + if (j.contains("custom_data")) { + k.custom_data.emplace(j.at("custom_data")); + } +} + +void to_json(json& j, DataTransferResponse const& k) noexcept { + j = json{ + {"status", k.status}, + }; + if (k.data) { + j["data"] = k.data.value(); + } + if (k.custom_data) { + j["custom_data"] = k.custom_data.value(); + } +} + +void from_json(const json& j, DataTransferResponse& k) { + k.status = j.at("status"); + if (j.contains("data")) { + k.data.emplace(j.at("data")); + } + if (j.contains("custom_data")) { + k.custom_data.emplace(j.at("custom_data")); + } +} + +void to_json(json& j, EVSE const& k) noexcept { + j = json{ + {"id", k.id}, + }; + if (k.connector_id) { + j["connector_id"] = k.connector_id.value(); + } +} + +void from_json(const json& j, EVSE& k) { + k.id = j.at("id"); + + if (j.contains("connector_id")) { + k.connector_id.emplace(j.at("connector_id")); + } +} + +void to_json(json& j, Component const& k) noexcept { + j = json{ + {"name", k.name}, + }; + if (k.instance) { + j["instance"] = k.instance.value(); + } + if (k.evse) { + j["evse"] = k.evse.value(); + } +} + +void from_json(const json& j, Component& k) { + k.name = j.at("name"); + if (j.contains("instance")) { + k.instance.emplace(j.at("instance")); + } + if (j.contains("evse")) { + k.evse.emplace(j.at("evse")); + } +} + +void to_json(json& j, Variable const& k) noexcept { + j = json{ + {"name", k.name}, + }; + if (k.instance) { + j["instance"] = k.instance.value(); + } +} + +void from_json(const json& j, Variable& k) { + k.name = j.at("name"); + if (j.contains("instance")) { + k.instance.emplace(j.at("instance")); + } +} + +void to_json(json& j, ComponentVariable const& k) noexcept { + j = json{ + {"component", k.component}, + {"variable", k.variable}, + }; +} + +void from_json(const json& j, ComponentVariable& k) { + k.component = j.at("component"); + k.variable = j.at("variable"); +} + +void to_json(json& j, GetVariableRequest const& k) noexcept { + j = json{ + {"component_variable", k.component_variable}, + }; + if (k.attribute_type) { + j["attribute_type"] = k.attribute_type.value(); + } +} + +void from_json(const json& j, GetVariableRequest& k) { + k.component_variable = j.at("component_variable"); + if (j.contains("attribute_type")) { + k.attribute_type.emplace(j.at("attribute_type")); + } +} + +void to_json(json& j, GetVariableResult const& k) noexcept { + j = json{ + {"status", k.status}, + {"component_variable", k.component_variable}, + }; + if (k.attribute_type) { + j["attribute_type"] = k.attribute_type.value(); + } + if (k.value) { + j["value"] = k.value.value(); + } +} + +void from_json(const json& j, GetVariableResult& k) { + k.status = j.at("status"); + k.component_variable = j.at("component_variable"); + + if (j.contains("attribute_type")) { + k.attribute_type.emplace(j.at("attribute_type")); + } + if (j.contains("value")) { + k.value.emplace(j.at("value")); + } +} + +void to_json(json& j, SetVariableRequest const& k) noexcept { + j = json{ + {"component_variable", k.component_variable}, + {"value", k.value}, + }; + if (k.attribute_type) { + j["attribute_type"] = k.attribute_type.value(); + } +} + +void from_json(const json& j, SetVariableRequest& k) { + k.component_variable = j.at("component_variable"); + k.value = j.at("value"); + + if (j.contains("attribute_type")) { + k.attribute_type.emplace(j.at("attribute_type")); + } +} + +void to_json(json& j, SetVariableResult const& k) noexcept { + j = json{ + {"status", k.status}, + {"component_variable", k.component_variable}, + }; + if (k.attribute_type) { + j["attribute_type"] = k.attribute_type.value(); + } +} + +void from_json(const json& j, SetVariableResult& k) { + k.status = j.at("status"); + k.component_variable = j.at("component_variable"); + + if (j.contains("attribute_type")) { + k.attribute_type.emplace(j.at("attribute_type")); + } +} + +void to_json(json& j, GetVariableRequestList const& k) noexcept { + j["items"] = json::array(); + for (auto val : k.items) { + j["items"].push_back(val); + } +} + +void from_json(const json& j, GetVariableRequestList& k) { + k.items.clear(); + for (auto val : j.at("items")) { + k.items.push_back(val); + } +} + +void to_json(json& j, GetVariableResultList const& k) noexcept { + j["items"] = json::array(); + for (auto val : k.items) { + j["items"].push_back(val); + } +} + +void from_json(const json& j, GetVariableResultList& k) { + k.items.clear(); + for (auto val : j.at("items")) { + k.items.push_back(val); + } +} + +void to_json(json& j, SetVariableRequestList const& k) noexcept { + j["items"] = json::array(); + for (auto val : k.items) { + j["items"].push_back(val); + } +} + +void from_json(const json& j, SetVariableRequestList& k) { + k.items.clear(); + for (auto val : j.at("items")) { + k.items.push_back(val); + } +} + +void to_json(json& j, SetVariableResultList const& k) noexcept { + j["items"] = json::array(); + for (auto val : k.items) { + j["items"].push_back(val); + } +} + +void from_json(const json& j, SetVariableResultList& k) { + k.items.clear(); + for (auto val : j.at("items")) { + k.items.push_back(val); + } +} + +void to_json(json& j, SetVariablesArgs const& k) noexcept { + j = json{ + {"variables", k.variables}, + {"source", k.source}, + }; +} + +void from_json(const json& j, SetVariablesArgs& k) { + k.variables = j["variables"]; + k.source = j["source"]; +} + +void to_json(json& j, SecurityEvent const& k) noexcept { + j = json{ + {"type", k.type}, + }; + if (k.info) { + j["info"] = k.info.value(); + } +} + +void from_json(const json& j, SecurityEvent& k) { + k.type = j.at("type"); + if (j.contains("info")) { + k.info.emplace(j.at("info")); + } +} + +void to_json(json& j, StatusInfoType const& k) noexcept { + j = json{ + {"reason_code", k.reason_code}, + }; + if (k.additional_info) { + j["additional_info"] = k.additional_info.value(); + } +} + +void from_json(const json& j, StatusInfoType& k) { + k.reason_code = j.at("reason_code"); + if (j.contains("additional_info")) { + k.additional_info.emplace(j.at("additional_info")); + } +} + +void to_json(json& j, BootNotificationResponse const& k) noexcept { + j = json{ + {"status", k.status}, + {"current_time", k.current_time}, + {"interval", k.interval}, + }; + if (k.status_info) { + j["status_info"] = k.status_info.value(); + } +} + +void from_json(const json& j, BootNotificationResponse& k) { + k.status = j.at("status"); + k.current_time = j.at("current_time"); + k.interval = j.at("interval"); + + if (j.contains("status_info")) { + k.status_info.emplace(j.at("status_info")); + } +} + +void to_json(json& j, OcppTransactionEvent const& k) noexcept { + j = json{ + {"transaction_event", k.transaction_event}, + {"session_id", k.session_id}, + }; + if (k.evse) { + j["evse"] = k.evse.value(); + } + if (k.transaction_id) { + j["transaction_id"] = k.transaction_id.value(); + } +} + +void from_json(const json& j, OcppTransactionEvent& k) { + k.transaction_event = j.at("transaction_event"); + k.session_id = j.at("session_id"); + + if (j.contains("evse")) { + k.evse.emplace(j.at("evse")); + } + if (j.contains("transaction_id")) { + k.transaction_id.emplace(j.at("transaction_id")); + } +} + +} // namespace everest::lib::API::V1_0::types::ocpp diff --git a/lib/everest/everest_api_types/src/everest_api_types/ocpp/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/ocpp/wrapper.cpp new file mode 100644 index 0000000000..7ab3b84167 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/ocpp/wrapper.cpp @@ -0,0 +1,535 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "ocpp/wrapper.hpp" +#include "ocpp/API.hpp" +#include + +namespace everest::lib::API::V1_0::types::ocpp { + +namespace { +template +auto srcToTarOpt(std::optional const& src, ConvT const& converter) + -> std::optional { + if (src) { + return std::make_optional(converter(src.value())); + } + return std::nullopt; +} + +template auto srcToTarVec(std::vector const& src, ConvT const& converter) { + using TarT = decltype(converter(src[0])); + std::vector result; + for (SrcT const& elem : src) { + result.push_back(converter(elem)); + } + return result; +} + +template +auto optToInternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toInternalApi(val); }); +} + +template +auto optToExternal(std::optional const& src) -> std::optional { + return srcToTarOpt(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToExternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toExternalApi(val); }); +} + +template auto vecToInternal(std::vector const& src) { + return srcToTarVec(src, [](SrcT const& val) { return toInternalApi(val); }); +} + +} // namespace + +AttributeEnum_Internal toInternalApi(AttributeEnum_External const& val) { + using SrcT = AttributeEnum_External; + using TarT = AttributeEnum_Internal; + switch (val) { + case SrcT::Actual: + return TarT::Actual; + case SrcT::Target: + return TarT::Target; + case SrcT::MinSet: + return TarT::MinSet; + case SrcT::MaxSet: + return TarT::MaxSet; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::ocpp::AttributeEnum_External"); +} + +AttributeEnum_External toExternalApi(AttributeEnum_Internal const& val) { + using SrcT = AttributeEnum_Internal; + using TarT = AttributeEnum_External; + switch (val) { + case SrcT::Actual: + return TarT::Actual; + case SrcT::Target: + return TarT::Target; + case SrcT::MinSet: + return TarT::MinSet; + case SrcT::MaxSet: + return TarT::MaxSet; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::ocpp::AttributeEnum_Internal"); +} + +GetVariableStatusEnumType_Internal toInternalApi(GetVariableStatusEnumType_External const& val) { + using SrcT = GetVariableStatusEnumType_External; + using TarT = GetVariableStatusEnumType_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::UnknownComponent: + return TarT::UnknownComponent; + case SrcT::UnknownVariable: + return TarT::UnknownVariable; + case SrcT::NotSupportedAttributeType: + return TarT::NotSupportedAttributeType; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::ocpp::GetVariableStatusEnumType_External"); +} + +GetVariableStatusEnumType_External toExternalApi(GetVariableStatusEnumType_Internal const& val) { + using SrcT = GetVariableStatusEnumType_Internal; + using TarT = GetVariableStatusEnumType_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::UnknownComponent: + return TarT::UnknownComponent; + case SrcT::UnknownVariable: + return TarT::UnknownVariable; + case SrcT::NotSupportedAttributeType: + return TarT::NotSupportedAttributeType; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::ocpp::GetVariableStatusEnumType_Internal"); +} + +SetVariableStatusEnumType_Internal toInternalApi(SetVariableStatusEnumType_External const& val) { + using SrcT = SetVariableStatusEnumType_External; + using TarT = SetVariableStatusEnumType_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::UnknownComponent: + return TarT::UnknownComponent; + case SrcT::UnknownVariable: + return TarT::UnknownVariable; + case SrcT::NotSupportedAttributeType: + return TarT::NotSupportedAttributeType; + case SrcT::RebootRequired: + return TarT::RebootRequired; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::ocpp::SetVariableStatusEnumType_External"); +} + +SetVariableStatusEnumType_External toExternalApi(SetVariableStatusEnumType_Internal const& val) { + using SrcT = SetVariableStatusEnumType_Internal; + using TarT = SetVariableStatusEnumType_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::UnknownComponent: + return TarT::UnknownComponent; + case SrcT::UnknownVariable: + return TarT::UnknownVariable; + case SrcT::NotSupportedAttributeType: + return TarT::NotSupportedAttributeType; + case SrcT::RebootRequired: + return TarT::RebootRequired; + } + throw std::out_of_range( + "Unexpected value for everest::lib::API::V1_0::types::ocpp::SetVariableStatusEnumType_Internal"); +} + +DataTransferStatus_Internal toInternalApi(DataTransferStatus_External const& val) { + using SrcT = DataTransferStatus_External; + using TarT = DataTransferStatus_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::UnknownMessageId: + return TarT::UnknownMessageId; + case SrcT::UnknownVendorId: + return TarT::UnknownVendorId; + case SrcT::Offline: + return TarT::Offline; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::ocpp::DataTransferStatus_External"); +} + +DataTransferStatus_External toExternalApi(DataTransferStatus_Internal const& val) { + using SrcT = DataTransferStatus_Internal; + using TarT = DataTransferStatus_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::UnknownMessageId: + return TarT::UnknownMessageId; + case SrcT::UnknownVendorId: + return TarT::UnknownVendorId; + case SrcT::Offline: + return TarT::Offline; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::ocpp::DataTransferStatus_Internal"); +} + +RegistrationStatus_Internal toInternalApi(RegistrationStatus_External const& val) { + using SrcT = RegistrationStatus_External; + using TarT = RegistrationStatus_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Pending: + return TarT::Pending; + case SrcT::Rejected: + return TarT::Rejected; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::ocpp::RegistrationStatus_External"); +} + +RegistrationStatus_External toExternalApi(RegistrationStatus_Internal const& val) { + using SrcT = RegistrationStatus_Internal; + using TarT = RegistrationStatus_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Pending: + return TarT::Pending; + case SrcT::Rejected: + return TarT::Rejected; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::ocpp::RegistrationStatus_Internal"); +} + +TransactionEvent_Internal toInternalApi(TransactionEvent_External const& val) { + using SrcT = TransactionEvent_External; + using TarT = TransactionEvent_Internal; + switch (val) { + case SrcT::Started: + return TarT::Started; + case SrcT::Updated: + return TarT::Updated; + case SrcT::Ended: + return TarT::Ended; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::ocpp::TransactionEvent_External"); +} + +TransactionEvent_External toExternalApi(TransactionEvent_Internal const& val) { + using SrcT = TransactionEvent_Internal; + using TarT = TransactionEvent_External; + switch (val) { + case SrcT::Started: + return TarT::Started; + case SrcT::Updated: + return TarT::Updated; + case SrcT::Ended: + return TarT::Ended; + } + throw std::out_of_range("Unexpected value for everest::lib::API::V1_0::types::ocpp::TransactionEvent_Internal"); +} + +CustomData_Internal toInternalApi(CustomData_External const& val) { + CustomData_Internal result; + result.vendor_id = val.vendor_id; + result.data = val.data; + return result; +} + +CustomData_External toExternalApi(CustomData_Internal const& val) { + CustomData_External result; + result.vendor_id = val.vendor_id; + result.data = val.data; + return result; +} + +DataTransferRequest_Internal toInternalApi(DataTransferRequest_External const& val) { + DataTransferRequest_Internal result; + result.vendor_id = val.vendor_id; + result.message_id = val.message_id; + result.data = val.data; + result.custom_data = optToInternal(val.custom_data); + return result; +} + +DataTransferRequest_External toExternalApi(DataTransferRequest_Internal const& val) { + DataTransferRequest_External result; + result.vendor_id = val.vendor_id; + result.message_id = val.message_id; + result.data = val.data; + result.custom_data = optToExternal(val.custom_data); + return result; +} + +DataTransferResponse_Internal toInternalApi(DataTransferResponse_External const& val) { + DataTransferResponse_Internal result; + result.status = toInternalApi(val.status); + result.data = val.data; + result.custom_data = optToInternal(val.custom_data); + return result; +} + +DataTransferResponse_External toExternalApi(DataTransferResponse_Internal const& val) { + DataTransferResponse_External result; + result.status = toExternalApi(val.status); + result.data = val.data; + result.custom_data = optToExternal(val.custom_data); + return result; +} + +EVSE_Internal toInternalApi(EVSE_External const& val) { + EVSE_Internal result; + result.id = val.id; + result.connector_id = val.connector_id; + return result; +} + +EVSE_External toExternalApi(EVSE_Internal const& val) { + EVSE_External result; + result.id = val.id; + result.connector_id = val.connector_id; + return result; +} + +Component_Internal toInternalApi(Component_External const& val) { + Component_Internal result; + result.name = val.name; + result.instance = val.instance; + result.evse = optToInternal(val.evse); + return result; +} + +Component_External toExternalApi(Component_Internal const& val) { + Component_External result; + result.name = val.name; + result.instance = val.instance; + result.evse = optToExternal(val.evse); + return result; +} + +Variable_Internal toInternalApi(Variable_External const& val) { + Variable_Internal result; + result.name = val.name; + result.instance = val.instance; + return result; +} + +Variable_External toExternalApi(Variable_Internal const& val) { + Variable_External result; + result.name = val.name; + result.instance = val.instance; + return result; +} + +ComponentVariable_Internal toInternalApi(ComponentVariable_External const& val) { + ComponentVariable_Internal result; + result.component = toInternalApi(val.component); + result.variable = toInternalApi(val.variable); + return result; +} + +ComponentVariable_External toExternalApi(ComponentVariable_Internal const& val) { + ComponentVariable_External result; + result.component = toExternalApi(val.component); + result.variable = toExternalApi(val.variable); + return result; +} + +GetVariableRequest_Internal toInternalApi(GetVariableRequest_External const& val) { + GetVariableRequest_Internal result; + result.component_variable = toInternalApi(val.component_variable); + result.attribute_type = optToInternal(val.attribute_type); + return result; +} + +GetVariableRequest_External toExternalApi(GetVariableRequest_Internal const& val) { + GetVariableRequest_External result; + result.component_variable = toExternalApi(val.component_variable); + result.attribute_type = optToExternal(val.attribute_type); + return result; +} + +GetVariableResult_Internal toInternalApi(GetVariableResult_External const& val) { + GetVariableResult_Internal result; + result.status = toInternalApi(val.status); + result.component_variable = toInternalApi(val.component_variable); + result.attribute_type = optToInternal(val.attribute_type); + result.value = val.value; + return result; +} + +GetVariableResult_External toExternalApi(GetVariableResult_Internal const& val) { + GetVariableResult_External result; + result.status = toExternalApi(val.status); + result.component_variable = toExternalApi(val.component_variable); + result.attribute_type = optToExternal(val.attribute_type); + result.value = val.value; + return result; +} + +SetVariableRequest_Internal toInternalApi(SetVariableRequest_External const& val) { + SetVariableRequest_Internal result; + result.component_variable = toInternalApi(val.component_variable); + result.value = val.value; + result.attribute_type = optToInternal(val.attribute_type); + return result; +} + +SetVariableRequest_External toExternalApi(SetVariableRequest_Internal const& val) { + SetVariableRequest_External result; + result.component_variable = toExternalApi(val.component_variable); + result.value = val.value; + result.attribute_type = optToExternal(val.attribute_type); + return result; +} + +SetVariableResult_Internal toInternalApi(SetVariableResult_External const& val) { + SetVariableResult_Internal result; + result.status = toInternalApi(val.status); + result.component_variable = toInternalApi(val.component_variable); + result.attribute_type = optToInternal(val.attribute_type); + return result; +} + +SetVariableResult_External toExternalApi(SetVariableResult_Internal const& val) { + SetVariableResult_External result; + result.status = toExternalApi(val.status); + result.component_variable = toExternalApi(val.component_variable); + result.attribute_type = optToExternal(val.attribute_type); + return result; +} + +GetVariableRequestList_Internal toInternalApi(GetVariableRequestList_External const& val) { + GetVariableRequestList_Internal result; + result = vecToInternal(val.items); + return result; +} + +GetVariableRequestList_External toExternalApi(GetVariableRequestList_Internal const& val) { + GetVariableRequestList_External result; + result.items = vecToExternal(val); + return result; +} + +GetVariableResultList_Internal toInternalApi(GetVariableResultList_External const& val) { + GetVariableResultList_Internal result; + result = vecToInternal(val.items); + return result; +} + +GetVariableResultList_External toExternalApi(GetVariableResultList_Internal const& val) { + GetVariableResultList_External result; + result.items = vecToExternal(val); + return result; +} + +SetVariableRequestList_Internal toInternalApi(SetVariableRequestList_External const& val) { + SetVariableRequestList_Internal result; + result = vecToInternal(val.items); + return result; +} + +SetVariableRequestList_External toExternalApi(SetVariableRequestList_Internal const& val) { + SetVariableRequestList_External result; + result.items = vecToExternal(val); + return result; +} + +SetVariableResultList_Internal toInternalApi(SetVariableResultList_External const& val) { + SetVariableResultList_Internal result; + result = vecToInternal(val.items); + return result; +} + +SetVariableResultList_External toExternalApi(SetVariableResultList_Internal const& val) { + SetVariableResultList_External result; + result.items = vecToExternal(val); + return result; +} + +SecurityEvent_Internal toInternalApi(SecurityEvent_External const& val) { + SecurityEvent_Internal result; + result.type = val.type; + result.info = val.info; + return result; +} + +SecurityEvent_External toExternalApi(SecurityEvent_Internal const& val) { + SecurityEvent_External result; + result.type = val.type; + result.info = val.info; + return result; +} + +StatusInfoType_Internal toInternalApi(StatusInfoType_External const& val) { + StatusInfoType_Internal result; + result.reason_code = val.reason_code; + result.additional_info = val.additional_info; + return result; +} + +StatusInfoType_External toExternalApi(StatusInfoType_Internal const& val) { + StatusInfoType_External result; + result.reason_code = val.reason_code; + result.additional_info = val.additional_info; + return result; +} + +BootNotificationResponse_Internal toInternalApi(BootNotificationResponse_External const& val) { + BootNotificationResponse_Internal result; + result.status = toInternalApi(val.status); + result.current_time = val.current_time; + result.interval = val.interval; + result.status_info = optToInternal(val.status_info); + return result; +} + +BootNotificationResponse_External toExternalApi(BootNotificationResponse_Internal const& val) { + BootNotificationResponse_External result; + result.status = toExternalApi(val.status); + result.current_time = val.current_time; + result.interval = val.interval; + result.status_info = optToExternal(val.status_info); + return result; +} + +OcppTransactionEvent_Internal toInternalApi(OcppTransactionEvent_External const& val) { + OcppTransactionEvent_Internal result; + result.transaction_event = toInternalApi(val.transaction_event); + result.session_id = val.session_id; + result.evse = optToInternal(val.evse); + result.transaction_id = val.transaction_id; + return result; +} + +OcppTransactionEvent_External toExternalApi(OcppTransactionEvent_Internal const& val) { + OcppTransactionEvent_External result; + result.transaction_event = toExternalApi(val.transaction_event); + result.session_id = val.session_id; + result.evse = optToExternal(val.evse); + result.transaction_id = val.transaction_id; + return result; +} + +} // namespace everest::lib::API::V1_0::types::ocpp diff --git a/lib/everest/everest_api_types/src/everest_api_types/over_voltage_monitor/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/over_voltage_monitor/codec.cpp new file mode 100644 index 0000000000..54c4d116e3 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/over_voltage_monitor/codec.cpp @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "over_voltage_monitor/codec.hpp" +#include "nlohmann/json.hpp" +#include "over_voltage_monitor/API.hpp" +#include "over_voltage_monitor/json_codec.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::over_voltage_monitor { + +std::string serialize(ErrorEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Error const& val) noexcept { + json result = val; + return result.dump(4); +} + +template <> ErrorEnum deserialize(std::string const& s) { + auto data = json::parse(s); + ErrorEnum result = data; + return result; +} + +template <> Error deserialize(std::string const& s) { + auto data = json::parse(s); + Error result = data; + return result; +} + +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Error& val) { + os << serialize(val); + return os; +} + +} // namespace everest::lib::API::V1_0::types::over_voltage_monitor diff --git a/lib/everest/everest_api_types/src/everest_api_types/over_voltage_monitor/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/over_voltage_monitor/json_codec.cpp new file mode 100644 index 0000000000..d789ee240b --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/over_voltage_monitor/json_codec.cpp @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "over_voltage_monitor/json_codec.hpp" +#include "nlohmann/json.hpp" +#include "over_voltage_monitor/API.hpp" + +namespace everest::lib::API::V1_0::types::over_voltage_monitor { + +void to_json(json& j, ErrorEnum const& k) noexcept { + switch (k) { + case ErrorEnum::MREC5OverVoltage: + j = "MREC5OverVoltage"; + return; + case ErrorEnum::DeviceFault: + j = "DeviceFault"; + return; + case ErrorEnum::CommunicationFault: + j = "CommunicationFault"; + return; + case ErrorEnum::VendorError: + j = "VendorError"; + return; + case ErrorEnum::VendorWarning: + j = "VendorWarning"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::power_supply_DC::ErrorEnum"; +} + +void from_json(json const& j, ErrorEnum& k) { + std::string s = j; + if (s == "MREC5OverVoltage") { + k = ErrorEnum::MREC5OverVoltage; + return; + } + if (s == "DeviceFault") { + k = ErrorEnum::DeviceFault; + return; + } + if (s == "CommunicationFault") { + k = ErrorEnum::CommunicationFault; + return; + } + if (s == "VendorError") { + k = ErrorEnum::VendorError; + return; + } + if (s == "VendorWarning") { + k = ErrorEnum::VendorWarning; + return; + } + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type ErrorEnum_API_1_0"); +} + +void to_json(json& j, const Error& k) noexcept { + j = json{ + {"type", k.type}, + }; + if (k.sub_type) { + j["sub_type"] = k.sub_type.value(); + } + if (k.message) { + j["message"] = k.message.value(); + }; +} + +void from_json(const json& j, Error& k) { + k.type = j.at("type"); + if (j.contains("sub_type")) { + k.sub_type.emplace(j.at("sub_type")); + } + if (j.contains("message")) { + k.message.emplace(j.at("message")); + } +} + +} // namespace everest::lib::API::V1_0::types::over_voltage_monitor diff --git a/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/codec.cpp new file mode 100644 index 0000000000..48bb11da7c --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/codec.cpp @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "power_supply_DC/codec.hpp" +#include "nlohmann/json.hpp" +#include "power_supply_DC/API.hpp" +#include "power_supply_DC/json_codec.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::power_supply_DC { + +std::string serialize(Capabilities const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Mode val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ChargingPhase val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ModeRequest val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(VoltageCurrent const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ErrorEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(Error const& val) noexcept { + json result = val; + return result.dump(4); +} + +template <> Capabilities deserialize(std::string const& s) { + auto data = json::parse(s); + Capabilities result = data; + return result; +} + +template <> Mode deserialize(std::string const& s) { + auto data = json::parse(s); + Mode result = data; + return result; +} + +template <> ChargingPhase deserialize(std::string const& s) { + auto data = json::parse(s); + ChargingPhase result = data; + return result; +} + +template <> ModeRequest deserialize(std::string const& s) { + auto data = json::parse(s); + ModeRequest result = data; + return result; +} + +template <> VoltageCurrent deserialize(std::string const& s) { + auto data = json::parse(s); + VoltageCurrent result = data; + return result; +} + +template <> ErrorEnum deserialize(std::string const& s) { + auto data = json::parse(s); + ErrorEnum result = data; + return result; +} + +template <> Error deserialize(std::string const& s) { + auto data = json::parse(s); + Error result = data; + return result; +} + +std::ostream& operator<<(std::ostream& os, const Capabilities& k) { + os << serialize(k); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Mode& k) { + os << serialize(k); + return os; +} + +std::ostream& operator<<(std::ostream& os, const ChargingPhase& k) { + os << serialize(k); + return os; +} + +std::ostream& operator<<(std::ostream& os, const ModeRequest& k) { + os << serialize(k); + return os; +} + +std::ostream& operator<<(std::ostream& os, const VoltageCurrent& k) { + os << serialize(k); + return os; +} + +std::ostream& operator<<(std::ostream& os, const ErrorEnum& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, const Error& val) { + os << serialize(val); + return os; +} + +} // namespace everest::lib::API::V1_0::types::power_supply_DC diff --git a/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/json_codec.cpp new file mode 100644 index 0000000000..fb74a586a4 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/json_codec.cpp @@ -0,0 +1,303 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "power_supply_DC/json_codec.hpp" +#include "nlohmann/json.hpp" +#include "power_supply_DC/API.hpp" +#include "power_supply_DC/codec.hpp" + +namespace everest::lib::API::V1_0::types::power_supply_DC { + +void to_json(json& j, const Capabilities& k) noexcept { + // the required parts of the type + j = json{ + {"bidirectional", k.bidirectional}, + {"current_regulation_tolerance_A", k.current_regulation_tolerance_A}, + {"peak_current_ripple_A", k.peak_current_ripple_A}, + {"max_export_voltage_V", k.max_export_voltage_V}, + {"min_export_voltage_V", k.min_export_voltage_V}, + {"max_export_current_A", k.max_export_current_A}, + {"min_export_current_A", k.min_export_current_A}, + {"max_export_power_W", k.max_export_power_W}, + }; + // the optional parts of the type + if (k.max_import_voltage_V) { + j["max_import_voltage_V"] = k.max_import_voltage_V.value(); + } + if (k.min_import_voltage_V) { + j["min_import_voltage_V"] = k.min_import_voltage_V.value(); + } + if (k.max_import_current_A) { + j["max_import_current_A"] = k.max_import_current_A.value(); + } + if (k.min_import_current_A) { + j["min_import_current_A"] = k.min_import_current_A.value(); + } + if (k.max_import_power_W) { + j["max_import_power_W"] = k.max_import_power_W.value(); + } + if (k.conversion_efficiency_import) { + j["conversion_efficiency_import"] = k.conversion_efficiency_import.value(); + } + if (k.conversion_efficiency_export) { + j["conversion_efficiency_export"] = k.conversion_efficiency_export.value(); + } +} + +void from_json(const json& j, Capabilities& k) { + // the required parts of the type + k.bidirectional = j.at("bidirectional"); + k.current_regulation_tolerance_A = j.at("current_regulation_tolerance_A"); + k.peak_current_ripple_A = j.at("peak_current_ripple_A"); + k.max_export_voltage_V = j.at("max_export_voltage_V"); + k.min_export_voltage_V = j.at("min_export_voltage_V"); + k.max_export_current_A = j.at("max_export_current_A"); + k.min_export_current_A = j.at("min_export_current_A"); + k.max_export_power_W = j.at("max_export_power_W"); + + // the optional parts of the type + if (j.contains("max_import_voltage_V")) { + k.max_import_voltage_V.emplace(j.at("max_import_voltage_V")); + } + if (j.contains("min_import_voltage_V")) { + k.min_import_voltage_V.emplace(j.at("min_import_voltage_V")); + } + if (j.contains("max_import_current_A")) { + k.max_import_current_A.emplace(j.at("max_import_current_A")); + } + if (j.contains("min_import_current_A")) { + k.min_import_current_A.emplace(j.at("min_import_current_A")); + } + if (j.contains("max_import_power_W")) { + k.max_import_power_W.emplace(j.at("max_import_power_W")); + } + if (j.contains("conversion_efficiency_import")) { + k.conversion_efficiency_import.emplace(j.at("conversion_efficiency_import")); + } + if (j.contains("conversion_efficiency_export")) { + k.conversion_efficiency_export.emplace(j.at("conversion_efficiency_export")); + } +} + +void to_json(json& j, Mode const& k) noexcept { + switch (k) { + case Mode::Off: + j = "Off"; + return; + case Mode::Export: + j = "Export"; + return; + case Mode::Import: + j = "Import"; + return; + case Mode::Fault: + j = "Fault"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::power_supply_DC::Mode"; +} + +void from_json(json const& j, Mode& k) { + std::string s = j; + if (s == "Off") { + k = Mode::Off; + return; + } + if (s == "Export") { + k = Mode::Export; + return; + } + if (s == "Import") { + k = Mode::Import; + return; + } + if (s == "Fault") { + k = Mode::Fault; + return; + } + + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type Mode_API_1_0"); +} + +void to_json(json& j, ChargingPhase const& k) noexcept { + switch (k) { + case ChargingPhase::Other: + j = "Other"; + return; + case ChargingPhase::CableCheck: + j = "CableCheck"; + return; + case ChargingPhase::PreCharge: + j = "PreCharge"; + return; + case ChargingPhase::Charging: + j = "Charging"; + return; + j = "INVALID_VALUE__everest::lib::API::V1_0::types::power_supply_DC::ChargingPhase"; + } +} + +void from_json(json const& j, ChargingPhase& k) { + std::string s = j; + if (s == "Other") { + k = ChargingPhase::Other; + return; + } + if (s == "CableCheck") { + k = ChargingPhase::CableCheck; + return; + } + if (s == "PreCharge") { + k = ChargingPhase::PreCharge; + return; + } + if (s == "Charging") { + k = ChargingPhase::Charging; + return; + } + + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type ChargingPhase_API_1_0"); +} + +void to_json(json& j, const ModeRequest& k) noexcept { + j = json{ + {"mode", k.mode}, + {"charging_phase", k.charging_phase}, + }; +} + +void from_json(const json& j, ModeRequest& k) { + k.mode = j.at("mode"); + k.charging_phase = j.at("charging_phase"); +} + +void to_json(json& j, const VoltageCurrent& k) noexcept { + j = json{ + {"voltage_V", k.voltage_V}, + {"current_A", k.current_A}, + }; +} + +void from_json(const json& j, VoltageCurrent& k) { + k.voltage_V = j.at("voltage_V"); + k.current_A = j.at("current_A"); +} + +void to_json(json& j, ErrorEnum const& k) noexcept { + switch (k) { + case ErrorEnum::CommunicationFault: + j = "CommunicationFault"; + return; + case ErrorEnum::HardwareFault: + j = "HardwareFault"; + return; + case ErrorEnum::OverTemperature: + j = "OverTemperature"; + return; + case ErrorEnum::UnderTemperature: + j = "UnderTemperature"; + return; + case ErrorEnum::UnderVoltageAC: + j = "UnderVoltageAC"; + return; + case ErrorEnum::OverVoltageAC: + j = "OverVoltageAC"; + return; + case ErrorEnum::UnderVoltageDC: + j = "UnderVoltageDC"; + return; + case ErrorEnum::OverVoltageDC: + j = "OverVoltageDC"; + return; + case ErrorEnum::OverCurrentAC: + j = "OverCurrentAC"; + return; + case ErrorEnum::OverCurrentDC: + j = "OverCurrentDC"; + return; + case ErrorEnum::VendorError: + j = "VendorError"; + return; + case ErrorEnum::VendorWarning: + j = "VendorWarning"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::power_supply_DC::ErrorEnum"; +} + +void from_json(json const& j, ErrorEnum& k) { + std::string s = j; + if (s == "CommunicationFault") { + k = ErrorEnum::CommunicationFault; + return; + } + if (s == "HardwareFault") { + k = ErrorEnum::HardwareFault; + return; + } + if (s == "OverTemperature") { + k = ErrorEnum::OverTemperature; + return; + } + if (s == "UnderTemperature") { + k = ErrorEnum::UnderTemperature; + return; + } + if (s == "UnderVoltageAC") { + k = ErrorEnum::UnderVoltageAC; + return; + } + if (s == "OverVoltageAC") { + k = ErrorEnum::OverVoltageAC; + return; + } + if (s == "UnderVoltageDC") { + k = ErrorEnum::UnderVoltageDC; + return; + } + if (s == "OverVoltageDC") { + k = ErrorEnum::OverVoltageDC; + return; + } + if (s == "OverCurrentAC") { + k = ErrorEnum::OverCurrentAC; + return; + } + if (s == "OverCurrentDC") { + k = ErrorEnum::OverCurrentDC; + return; + } + if (s == "VendorError") { + k = ErrorEnum::VendorError; + return; + } + if (s == "VendorWarning") { + k = ErrorEnum::VendorWarning; + return; + } + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type ErrorEnum_API_1_0"); +} + +void to_json(json& j, const Error& k) noexcept { + j = json{ + {"type", k.type}, + }; + if (k.sub_type) { + j["sub_type"] = k.sub_type.value(); + } + if (k.message) { + j["message"] = k.message.value(); + }; +} + +void from_json(const json& j, Error& k) { + k.type = j.at("type"); + if (j.contains("sub_type")) { + k.sub_type.emplace(j.at("sub_type")); + } + if (j.contains("message")) { + k.message.emplace(j.at("message")); + } +} + +} // namespace everest::lib::API::V1_0::types::power_supply_DC diff --git a/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/wrapper.cpp new file mode 100644 index 0000000000..972e927503 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/power_supply_DC/wrapper.cpp @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "power_supply_DC/wrapper.hpp" +#include "power_supply_DC/API.hpp" +#include + +namespace everest::lib::API::V1_0::types::power_supply_DC { + +Capabilities_External toExternalApi(Capabilities_Internal const& val) { + Capabilities_External r; + r.bidirectional = val.bidirectional; + r.current_regulation_tolerance_A = val.current_regulation_tolerance_A; + r.peak_current_ripple_A = val.peak_current_ripple_A; + r.max_export_voltage_V = val.max_export_voltage_V; + r.min_export_voltage_V = val.min_export_voltage_V; + r.max_export_current_A = val.max_export_current_A; + r.min_export_current_A = val.min_export_current_A; + r.max_export_power_W = val.max_export_power_W; + + r.max_import_voltage_V = val.max_import_voltage_V; + r.min_import_voltage_V = val.min_import_voltage_V; + r.max_import_current_A = val.max_import_current_A; + r.min_import_current_A = val.min_import_current_A; + r.max_import_power_W = val.max_import_power_W; + r.conversion_efficiency_import = val.conversion_efficiency_import; + r.conversion_efficiency_export = val.conversion_efficiency_export; + + return r; +} + +Capabilities_Internal toInternalApi(Capabilities_External const& val) { + auto internal = Capabilities_Internal(); + internal.bidirectional = val.bidirectional; + internal.current_regulation_tolerance_A = val.current_regulation_tolerance_A; + internal.peak_current_ripple_A = val.peak_current_ripple_A; + internal.max_export_voltage_V = val.max_export_voltage_V; + internal.min_export_voltage_V = val.min_export_voltage_V; + internal.max_export_current_A = val.max_export_current_A; + internal.min_export_current_A = val.min_export_current_A; + internal.max_export_power_W = val.max_export_power_W; + + internal.max_import_voltage_V = val.max_import_voltage_V; + internal.min_import_voltage_V = val.min_import_voltage_V; + internal.max_import_current_A = val.max_import_current_A; + internal.min_import_current_A = val.min_import_current_A; + internal.max_import_power_W = val.max_import_power_W; + internal.conversion_efficiency_import = val.conversion_efficiency_import; + internal.conversion_efficiency_export = val.conversion_efficiency_export; + return internal; +} + +Mode_External toExternalApi(Mode_Internal mode_internal) { + switch (mode_internal) { + case Mode_Internal::Off: + return Mode::Off; + case Mode_Internal::Export: + return Mode::Export; + case Mode_Internal::Import: + return Mode::Import; + case Mode_Internal::Fault: + return Mode::Fault; + } + + throw std::out_of_range("No know conversion between internal and external mode API"); +} + +Mode_Internal toInternalApi(Mode_External mode_external) { + switch (mode_external) { + case Mode::Off: + return Mode_Internal::Off; + case Mode::Export: + return Mode_Internal::Export; + case Mode::Import: + return Mode_Internal::Import; + case Mode::Fault: + return Mode_Internal::Fault; + } + + throw std::out_of_range("No know conversion between internal and external mode API"); +} + +ChargingPhase_External toExternalApi(ChargingPhase_Internal val) { + switch (val) { + case ChargingPhase_Internal::Other: + return ChargingPhase_External::Other; + case ChargingPhase_Internal::CableCheck: + return ChargingPhase_External::CableCheck; + case ChargingPhase_Internal::PreCharge: + return ChargingPhase_External::PreCharge; + case ChargingPhase_Internal::Charging: + return ChargingPhase_External::Charging; + } + + throw std::out_of_range("No know conversion from internal to external ChargingPhase API"); +} + +ChargingPhase_Internal toInternalApi(ChargingPhase_External val) { + switch (val) { + case ChargingPhase_External::Other: + return ChargingPhase_Internal::Other; + case ChargingPhase_External::CableCheck: + return ChargingPhase_Internal::CableCheck; + case ChargingPhase_External::PreCharge: + return ChargingPhase_Internal::PreCharge; + case ChargingPhase_External::Charging: + return ChargingPhase_Internal::Charging; + } + + throw std::out_of_range("No know conversion from external and internal ChargingPhase API"); +} + +VoltageCurrent_External toExternalApi(VoltageCurrent_Internal const& internal) { + VoltageCurrent_External result; + result.voltage_V = internal.voltage_V; + result.current_A = internal.current_A; + return result; +} + +VoltageCurrent_Internal toInternalApi(VoltageCurrent_External const& external) { + VoltageCurrent_Internal result; + result.current_A = external.current_A; + result.voltage_V = external.voltage_V; + return result; +} + +} // namespace everest::lib::API::V1_0::types::power_supply_DC diff --git a/lib/everest/everest_api_types/src/everest_api_types/powermeter/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/powermeter/codec.cpp new file mode 100644 index 0000000000..efc93b6ef6 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/powermeter/codec.cpp @@ -0,0 +1,381 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "powermeter/codec.hpp" +#include "nlohmann/json.hpp" +#include "powermeter/API.hpp" +#include "powermeter/json_codec.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::powermeter { + +std::string serialize(OCMFUserIdentificationStatus val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(OCMFIdentificationFlags val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(OCMFIdentificationType val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(OCMFIdentificationLevel val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(Current const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(Voltage const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(Frequency const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(Power const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(Energy const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(ReactivePower const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(SignedMeterValue const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(SignedCurrent const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(SignedVoltage const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(SignedFrequency const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(SignedPower const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(SignedEnergy const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(SignedReactivePower const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(PowermeterValues const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(Temperature const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(TransactionStatus val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(ReplyStartTransaction const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(ReplyStopTransaction const& val) noexcept { + json j = val; + return j.dump(4); +} + +std::string serialize(RequestStartTransaction const& val) noexcept { + json j = val; + return j.dump(4); +} + +template <> OCMFUserIdentificationStatus deserialize(std::string const& s) { + auto data = json::parse(s); + OCMFUserIdentificationStatus result = data; + return result; +} + +template <> OCMFIdentificationFlags deserialize(std::string const& s) { + auto data = json::parse(s); + OCMFIdentificationFlags result = data; + return result; +} + +template <> OCMFIdentificationType deserialize(std::string const& s) { + auto data = json::parse(s); + OCMFIdentificationType result = data; + return result; +} + +template <> OCMFIdentificationLevel deserialize(std::string const& s) { + auto data = json::parse(s); + OCMFIdentificationLevel result = data; + return result; +} + +template <> Current deserialize(std::string const& s) { + auto data = json::parse(s); + Current result = data; + return result; +} + +template <> Voltage deserialize(std::string const& s) { + auto data = json::parse(s); + Voltage result = data; + return result; +} + +template <> Frequency deserialize(std::string const& s) { + auto data = json::parse(s); + Frequency result = data; + return result; +} + +template <> Power deserialize(std::string const& s) { + auto data = json::parse(s); + Power result = data; + return result; +} + +template <> Energy deserialize(std::string const& s) { + auto data = json::parse(s); + Energy result = data; + return result; +} + +template <> ReactivePower deserialize(std::string const& s) { + auto data = json::parse(s); + ReactivePower result = data; + return result; +} + +template <> SignedMeterValue deserialize(std::string const& s) { + auto data = json::parse(s); + SignedMeterValue result = data; + return result; +} + +template <> SignedCurrent deserialize(std::string const& s) { + auto data = json::parse(s); + SignedCurrent result = data; + return result; +} + +template <> SignedVoltage deserialize(std::string const& s) { + auto data = json::parse(s); + SignedVoltage result = data; + return result; +} + +template <> SignedFrequency deserialize(std::string const& s) { + auto data = json::parse(s); + SignedFrequency result = data; + return result; +} + +template <> SignedPower deserialize(std::string const& s) { + auto data = json::parse(s); + SignedPower result = data; + return result; +} + +template <> SignedEnergy deserialize(std::string const& s) { + auto data = json::parse(s); + SignedEnergy result = data; + return result; +} + +template <> SignedReactivePower deserialize(std::string const& s) { + auto data = json::parse(s); + SignedReactivePower result = data; + return result; +} + +template <> Temperature deserialize(std::string const& s) { + auto data = json::parse(s); + Temperature result = data; + return result; +} + +template <> PowermeterValues deserialize(std::string const& s) { + auto data = json::parse(s); + PowermeterValues result = data; + return result; +} + +template <> TransactionStatus deserialize(std::string const& s) { + auto data = json::parse(s); + TransactionStatus result = data; + return result; +} + +template <> ReplyStartTransaction deserialize(std::string const& s) { + auto data = json::parse(s); + ReplyStartTransaction result = data; + return result; +} + +template <> ReplyStopTransaction deserialize(std::string const& s) { + auto data = json::parse(s); + ReplyStopTransaction result = data; + return result; +} + +template <> RequestStartTransaction deserialize(std::string const& s) { + auto data = json::parse(s); + RequestStartTransaction result = data; + return result; +} + +std::ostream& operator<<(std::ostream& os, OCMFUserIdentificationStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, OCMFIdentificationFlags const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, OCMFIdentificationType const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, OCMFIdentificationLevel const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Current const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Voltage const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Frequency const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Power const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Energy const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ReactivePower const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SignedMeterValue const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SignedCurrent const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SignedVoltage const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SignedFrequency const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SignedPower const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SignedEnergy const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, SignedReactivePower const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, Temperature const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, PowermeterValues const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, TransactionStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ReplyStartTransaction const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ReplyStopTransaction const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, RequestStartTransaction const& val) { + os << serialize(val); + return os; +} + +} // namespace everest::lib::API::V1_0::types::powermeter diff --git a/lib/everest/everest_api_types/src/everest_api_types/powermeter/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/powermeter/json_codec.cpp new file mode 100644 index 0000000000..f97213874f --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/powermeter/json_codec.cpp @@ -0,0 +1,1035 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "powermeter/json_codec.hpp" +#include "nlohmann/json.hpp" +#include "powermeter/API.hpp" +#include "powermeter/codec.hpp" + +namespace everest::lib::API::V1_0::types::powermeter { + +using json = nlohmann::json; + +void from_json(const json& j, OCMFUserIdentificationStatus& k) { + std::string s = j; + if (s == "ASSIGNED") { + k = OCMFUserIdentificationStatus::ASSIGNED; + return; + } + if (s == "NOT_ASSIGNED") { + k = OCMFUserIdentificationStatus::NOT_ASSIGNED; + return; + } + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type OCMFUserIdentificationStatus _API_1_0"); +} +void to_json(json& j, const OCMFUserIdentificationStatus& k) noexcept { + switch (k) { + case OCMFUserIdentificationStatus::ASSIGNED: + j = "ASSIGNED"; + return; + case OCMFUserIdentificationStatus::NOT_ASSIGNED: + j = "NOT_ASSIGNED"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::powermeter::OCMFUserIdentificationStatus"; +} + +void from_json(const json& j, OCMFIdentificationFlags& k) { + std::string s = j; + if (s == "RFID_NONE") { + k = OCMFIdentificationFlags::RFID_NONE; + return; + } + if (s == "RFID_PLAIN") { + k = OCMFIdentificationFlags::RFID_PLAIN; + return; + } + if (s == "RFID_RELATED") { + k = OCMFIdentificationFlags::RFID_RELATED; + return; + } + if (s == "RFID_PSK") { + k = OCMFIdentificationFlags::RFID_PSK; + return; + } + if (s == "OCPP_NONE") { + k = OCMFIdentificationFlags::OCPP_NONE; + return; + } + if (s == "OCPP_RS") { + k = OCMFIdentificationFlags::OCPP_RS; + return; + } + if (s == "OCPP_AUTH") { + k = OCMFIdentificationFlags::OCPP_AUTH; + return; + } + if (s == "OCPP_RS_TLS") { + k = OCMFIdentificationFlags::OCPP_RS_TLS; + return; + } + if (s == "OCPP_AUTH_TLS") { + k = OCMFIdentificationFlags::OCPP_AUTH_TLS; + return; + } + if (s == "OCPP_CACHE") { + k = OCMFIdentificationFlags::OCPP_CACHE; + return; + } + if (s == "OCPP_WHITELIST") { + k = OCMFIdentificationFlags::OCPP_WHITELIST; + return; + } + if (s == "OCPP_CERTIFIED") { + k = OCMFIdentificationFlags::OCPP_CERTIFIED; + return; + } + if (s == "ISO15118_NONE") { + k = OCMFIdentificationFlags::ISO15118_NONE; + return; + } + if (s == "ISO15118_PNC") { + k = OCMFIdentificationFlags::ISO15118_PNC; + return; + } + if (s == "PLMN_NONE") { + k = OCMFIdentificationFlags::PLMN_NONE; + return; + } + if (s == "PLMN_RING") { + k = OCMFIdentificationFlags::PLMN_RING; + return; + } + if (s == "PLMN_SMS") { + k = OCMFIdentificationFlags::PLMN_SMS; + return; + } + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type OCMFIdentificationFlags _API_1_0"); +} +void to_json(json& j, const OCMFIdentificationFlags& k) noexcept { + switch (k) { + case OCMFIdentificationFlags::RFID_NONE: + j = "RFID_NONE"; + return; + case OCMFIdentificationFlags::RFID_PLAIN: + j = "RFID_PLAIN"; + return; + case OCMFIdentificationFlags::RFID_RELATED: + j = "RFID_RELATED"; + return; + case OCMFIdentificationFlags::RFID_PSK: + j = "RFID_PSK"; + return; + case OCMFIdentificationFlags::OCPP_NONE: + j = "OCPP_NONE"; + return; + case OCMFIdentificationFlags::OCPP_RS: + j = "OCPP_RS"; + return; + case OCMFIdentificationFlags::OCPP_AUTH: + j = "OCPP_AUTH"; + return; + case OCMFIdentificationFlags::OCPP_RS_TLS: + j = "OCPP_RS_TLS"; + return; + case OCMFIdentificationFlags::OCPP_AUTH_TLS: + j = "OCPP_AUTH_TLS"; + return; + case OCMFIdentificationFlags::OCPP_CACHE: + j = "OCPP_CACHE"; + return; + case OCMFIdentificationFlags::OCPP_WHITELIST: + j = "OCPP_WHITELIST"; + return; + case OCMFIdentificationFlags::OCPP_CERTIFIED: + j = "OCPP_CERTIFIED"; + return; + case OCMFIdentificationFlags::ISO15118_NONE: + j = "ISO15118_NONE"; + return; + case OCMFIdentificationFlags::ISO15118_PNC: + j = "ISO15118_PNC"; + return; + case OCMFIdentificationFlags::PLMN_NONE: + j = "PLMN_NONE"; + return; + case OCMFIdentificationFlags::PLMN_RING: + j = "PLMN_RING"; + return; + case OCMFIdentificationFlags::PLMN_SMS: + j = "PLMN_SMS"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::powermeter::OCMFIdentificationFlags"; +} + +void from_json(const json& j, OCMFIdentificationType& k) { + std::string s = j; + if (s == "NONE") { + k = OCMFIdentificationType::NONE; + return; + } + if (s == "DENIED") { + k = OCMFIdentificationType::DENIED; + return; + } + if (s == "UNDEFINED") { + k = OCMFIdentificationType::UNDEFINED; + return; + } + if (s == "ISO14443") { + k = OCMFIdentificationType::ISO14443; + return; + } + if (s == "ISO15693") { + k = OCMFIdentificationType::ISO15693; + return; + } + if (s == "EMAID") { + k = OCMFIdentificationType::EMAID; + return; + } + if (s == "EVCCID") { + k = OCMFIdentificationType::EVCCID; + return; + } + if (s == "EVCOID") { + k = OCMFIdentificationType::EVCOID; + return; + } + if (s == "ISO7812") { + k = OCMFIdentificationType::ISO7812; + return; + } + if (s == "CARD_TXN_NR") { + k = OCMFIdentificationType::CARD_TXN_NR; + return; + } + if (s == "CENTRAL") { + k = OCMFIdentificationType::CENTRAL; + return; + } + if (s == "CENTRAL_1") { + k = OCMFIdentificationType::CENTRAL_1; + return; + } + if (s == "CENTRAL_2") { + k = OCMFIdentificationType::CENTRAL_2; + return; + } + if (s == "LOCAL") { + k = OCMFIdentificationType::LOCAL; + return; + } + if (s == "LOCAL_1") { + k = OCMFIdentificationType::LOCAL_1; + return; + } + if (s == "LOCAL_2") { + k = OCMFIdentificationType::LOCAL_2; + return; + } + if (s == "PHONE_NUMBER") { + k = OCMFIdentificationType::PHONE_NUMBER; + return; + } + if (s == "KEY_CODE") { + k = OCMFIdentificationType::KEY_CODE; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type OCMIdentificationType _API_1_0"); +} +void to_json(json& j, const OCMFIdentificationType& k) noexcept { + switch (k) { + case OCMFIdentificationType::NONE: + j = "NONE"; + return; + case OCMFIdentificationType::DENIED: + j = "DENIED"; + return; + case OCMFIdentificationType::UNDEFINED: + j = "UNDEFINED"; + return; + case OCMFIdentificationType::ISO14443: + j = "ISO14443"; + return; + case OCMFIdentificationType::ISO15693: + j = "ISO15693"; + return; + case OCMFIdentificationType::EMAID: + j = "EMAID"; + return; + case OCMFIdentificationType::EVCCID: + j = "EVCCID"; + return; + case OCMFIdentificationType::EVCOID: + j = "EVCOID"; + return; + case OCMFIdentificationType::ISO7812: + j = "ISO7812"; + return; + case OCMFIdentificationType::CARD_TXN_NR: + j = "CARD_TXN_NR"; + return; + case OCMFIdentificationType::CENTRAL: + j = "CENTRAL"; + return; + case OCMFIdentificationType::CENTRAL_1: + j = "CENTRAL_1"; + return; + case OCMFIdentificationType::CENTRAL_2: + j = "CENTRAL_2"; + return; + case OCMFIdentificationType::LOCAL: + j = "LOCAL"; + return; + case OCMFIdentificationType::LOCAL_1: + j = "LOCAL_1"; + return; + case OCMFIdentificationType::LOCAL_2: + j = "LOCAL_2"; + return; + case OCMFIdentificationType::PHONE_NUMBER: + j = "PHONE_NUMBER"; + return; + case OCMFIdentificationType::KEY_CODE: + j = "KEY_CODE"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::powermeter::OCMFIdentificationType"; +} + +void from_json(const json& j, OCMFIdentificationLevel& k) { + std::string s = j; + if (s == "NONE") { + k = OCMFIdentificationLevel::NONE; + return; + } + if (s == "HEARSAY") { + k = OCMFIdentificationLevel::HEARSAY; + return; + } + if (s == "TRUSTED") { + k = OCMFIdentificationLevel::TRUSTED; + return; + } + if (s == "VERIFIED") { + k = OCMFIdentificationLevel::VERIFIED; + return; + } + if (s == "CERTIFIED") { + k = OCMFIdentificationLevel::CERTIFIED; + return; + } + if (s == "SECURE") { + k = OCMFIdentificationLevel::SECURE; + return; + } + if (s == "MISMATCH") { + k = OCMFIdentificationLevel::MISMATCH; + return; + } + if (s == "INVALID") { + k = OCMFIdentificationLevel::INVALID; + return; + } + if (s == "OUTDATED") { + k = OCMFIdentificationLevel::OUTDATED; + return; + } + if (s == "UNKNOWN") { + k = OCMFIdentificationLevel::UNKNOWN; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type OCMIdentificationLevel _API_1_0"); +} +void to_json(json& j, const OCMFIdentificationLevel& k) noexcept { + switch (k) { + case OCMFIdentificationLevel::NONE: + j = "NONE"; + return; + case OCMFIdentificationLevel::HEARSAY: + j = "HEARSAY"; + return; + case OCMFIdentificationLevel::TRUSTED: + j = "TRUSTED"; + return; + case OCMFIdentificationLevel::VERIFIED: + j = "VERIFIED"; + return; + case OCMFIdentificationLevel::CERTIFIED: + j = "CERTIFIED"; + return; + case OCMFIdentificationLevel::SECURE: + j = "SECURE"; + return; + case OCMFIdentificationLevel::MISMATCH: + j = "MISMATCH"; + return; + case OCMFIdentificationLevel::INVALID: + j = "INVALID"; + return; + case OCMFIdentificationLevel::OUTDATED: + j = "OUTDATED"; + return; + case OCMFIdentificationLevel::UNKNOWN: + j = "UNKNOWN"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::powermeter::OCMFIdentificationLevel"; +} + +void from_json(const json& j, TransactionStatus& k) { + std::string s = j; + if (s == "OK") { + k = TransactionStatus::OK; + return; + } + if (s == "NOT_SUPPORTED") { + k = TransactionStatus::NOT_SUPPORTED; + return; + } + if (s == "UNEXPECTED_ERROR") { + k = TransactionStatus::UNEXPECTED_ERROR; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type TransactionStatus_API_1_0"); +} +void to_json(json& j, const TransactionStatus& k) noexcept { + switch (k) { + case TransactionStatus::OK: + j = "OK"; + return; + case TransactionStatus::NOT_SUPPORTED: + j = "NOT_SUPPORTED"; + return; + case TransactionStatus::UNEXPECTED_ERROR: + j = "UNEXPECTED_ERROR"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::powermeter::TransactionStatus"; +} + +void from_json(const json& j, Current& k) { + if (j.contains("DC")) { + k.DC.emplace(j.at("DC")); + } + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } + if (j.contains("N")) { + k.N.emplace(j.at("N")); + } +} +void to_json(json& j, const Current& k) noexcept { + j = json({}); + if (k.DC) { + j["DC"] = k.DC.value(); + } + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } + if (k.N) { + j["N"] = k.N.value(); + } +} + +void from_json(const json& j, Voltage& k) { + if (j.contains("DC")) { + k.DC.emplace(j.at("DC")); + } + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const Voltage& k) noexcept { + j = json({}); + // the optional parts of the type + if (k.DC) { + j["DC"] = k.DC.value(); + } + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, Frequency& k) { + k.L1 = j.at("L1"); + + // the optional parts of the type + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const Frequency& k) noexcept { + j = json{ + {"L1", k.L1}, + }; + + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, Power& k) { + k.total = j.at("total"); + + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const Power& k) noexcept { + j = json{ + {"total", k.total}, + }; + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, Energy& k) { + k.total = j.at("total"); + + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const Energy& k) noexcept { + j = json{ + {"total", k.total}, + }; + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, ReactivePower& k) { + k.total = j.at("total"); + + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const ReactivePower& k) noexcept { + j = json{ + {"total", k.total}, + }; + + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, SignedMeterValue& k) { + k.signed_meter_data = j.at("signed_meter_data"); + k.signing_method = j.at("signing_method"); + k.encoding_method = j.at("encoding_method"); + + if (j.contains("public_key")) { + k.public_key.emplace(j.at("public_key")); + } + if (j.contains("timestamp")) { + k.timestamp.emplace(j.at("timestamp")); + } +} +void to_json(json& j, const SignedMeterValue& k) noexcept { + j = json{ + {"signed_meter_data", k.signed_meter_data}, + {"signing_method", k.signing_method}, + {"encoding_method", k.encoding_method}, + }; + if (k.public_key) { + j["public_key"] = k.public_key.value(); + } + if (k.timestamp) { + j["timestamp"] = k.timestamp.value(); + } +} + +void from_json(const json& j, SignedCurrent& k) { + if (j.contains("DC")) { + k.DC.emplace(j.at("DC")); + } + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } + if (j.contains("N")) { + k.N.emplace(j.at("N")); + } +} +void to_json(json& j, const SignedCurrent& k) noexcept { + j = json({}); + if (k.DC) { + j["DC"] = k.DC.value(); + } + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } + if (k.N) { + j["N"] = k.N.value(); + } +} + +void from_json(const json& j, SignedVoltage& k) { + if (j.contains("DC")) { + k.DC.emplace(j.at("DC")); + } + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const SignedVoltage& k) noexcept { + j = json({}); + if (k.DC) { + j["DC"] = k.DC.value(); + } + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, SignedFrequency& k) { + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const SignedFrequency& k) noexcept { + j = json({}); + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, SignedPower& k) { + if (j.contains("total")) { + k.total.emplace(j.at("total")); + } + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const SignedPower& k) noexcept { + j = json({}); + if (k.total) { + j["total"] = k.total.value(); + } + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, SignedEnergy& k) { + // the optional parts of the type + if (j.contains("total")) { + k.total.emplace(j.at("total")); + } + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const SignedEnergy& k) noexcept { + j = json({}); + if (k.total) { + j["total"] = k.total.value(); + } + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, SignedReactivePower& k) { + k.total = j.at("total"); + + if (j.contains("L1")) { + k.L1.emplace(j.at("L1")); + } + if (j.contains("L2")) { + k.L2.emplace(j.at("L2")); + } + if (j.contains("L3")) { + k.L3.emplace(j.at("L3")); + } +} +void to_json(json& j, const SignedReactivePower& k) noexcept { + j = json({}); + if (k.total) { + j["total"] = k.total.value(); + } + if (k.L1) { + j["L1"] = k.L1.value(); + } + if (k.L2) { + j["L2"] = k.L2.value(); + } + if (k.L3) { + j["L3"] = k.L3.value(); + } +} + +void from_json(const json& j, Temperature& k) { + k.temperature = j.at("temperature"); + if (j.contains("identification")) { + k.identification.emplace(j.at("identification")); + } +} +void to_json(json& j, const Temperature& k) noexcept { + j = json{ + {"temperature", k.temperature}, + }; + if (k.identification) { + j["identification"] = k.identification.value(); + } +} + +void from_json(const json& j, PowermeterValues& k) { + k.timestamp = j.at("timestamp"); + k.energy_Wh_import = j.at("energy_Wh_import"); + if (j.contains("meter_id")) { + k.meter_id.emplace(j.at("meter_id")); + } + if (j.contains("phase_seq_error")) { + k.phase_seq_error.emplace(j.at("phase_seq_error")); + } + if (j.contains("energy_Wh_export")) { + k.energy_Wh_export.emplace(j.at("energy_Wh_export")); + } + if (j.contains("power_W")) { + k.power_W.emplace(j.at("power_W")); + } + if (j.contains("voltage_V")) { + k.voltage_V.emplace(j.at("voltage_V")); + } + if (j.contains("VAR")) { + k.VAR.emplace(j.at("VAR")); + } + if (j.contains("current_A")) { + k.current_A.emplace(j.at("current_A")); + } + if (j.contains("frequency_Hz")) { + k.frequency_Hz.emplace(j.at("frequency_Hz")); + } + if (j.contains("energy_Wh_import_signed")) { + k.energy_Wh_import_signed.emplace(j.at("energy_Wh_import_signed")); + } + if (j.contains("energy_Wh_export_signed")) { + k.energy_Wh_export_signed.emplace(j.at("energy_Wh_export_signed")); + } + if (j.contains("power_W_signed")) { + k.power_W_signed.emplace(j.at("power_W_signed")); + } + if (j.contains("voltage_V_signed")) { + k.voltage_V_signed.emplace(j.at("voltage_V_signed")); + } + if (j.contains("VAR_signed")) { + k.VAR_signed.emplace(j.at("VAR_signed")); + } + if (j.contains("current_A_signed")) { + k.current_A_signed.emplace(j.at("current_A_signed")); + } + if (j.contains("frequency_Hz_signed")) { + k.frequency_Hz_signed.emplace(j.at("frequency_Hz_signed")); + } + if (j.contains("signed_meter_value")) { + k.signed_meter_value.emplace(j.at("signed_meter_value")); + } + if (j.contains("temperatures")) { + json arr = j.at("temperatures"); + std::vector vec; + for (auto val : arr) { + vec.push_back(val); + } + k.temperatures.emplace(vec); + } +} +void to_json(json& j, const PowermeterValues& k) noexcept { + j = json{ + {"timestamp", k.timestamp}, + {"energy_Wh_import", k.energy_Wh_import}, + }; + if (k.meter_id) { + j["meter_id"] = k.meter_id.value(); + } + if (k.phase_seq_error) { + j["phase_seq_error"] = k.phase_seq_error.value(); + } + if (k.energy_Wh_export) { + j["energy_Wh_export"] = k.energy_Wh_export.value(); + } + if (k.power_W) { + j["power_W"] = k.power_W.value(); + } + if (k.voltage_V) { + j["voltage_V"] = k.voltage_V.value(); + } + if (k.VAR) { + j["VAR"] = k.VAR.value(); + } + if (k.current_A) { + j["current_A"] = k.current_A.value(); + } + if (k.frequency_Hz) { + j["frequency_Hz"] = k.frequency_Hz.value(); + } + if (k.energy_Wh_import_signed) { + j["energy_Wh_import_signed"] = k.energy_Wh_import_signed.value(); + } + if (k.energy_Wh_export_signed) { + j["energy_Wh_export_signed"] = k.energy_Wh_export_signed.value(); + } + if (k.power_W_signed) { + j["power_W_signed"] = k.power_W_signed.value(); + } + if (k.voltage_V_signed) { + j["voltage_V_signed"] = k.voltage_V_signed.value(); + } + if (k.VAR_signed) { + j["VAR_signed"] = k.VAR_signed.value(); + } + if (k.current_A_signed) { + j["current_A_signed"] = k.current_A_signed.value(); + } + if (k.frequency_Hz_signed) { + j["frequency_Hz_signed"] = k.frequency_Hz_signed.value(); + } + if (k.signed_meter_value) { + j["signed_meter_value"] = k.signed_meter_value.value(); + } + if (k.temperatures) { + j["temperatures"] = json::array(); + for (auto val : k.temperatures.value()) { + j["temperatures"].push_back(val); + } + } +} + +void from_json(const json& j, ReplyStartTransaction& k) { + k.status = j.at("status"); + + if (j.contains("error")) { + k.error.emplace(j.at("error")); + } + if (j.contains("transaction_min_stop_time")) { + k.transaction_min_stop_time.emplace(j.at("transaction_min_stop_time")); + } + if (j.contains("transaction_max_stop_time")) { + k.transaction_max_stop_time.emplace(j.at("transaction_max_stop_time")); + } +} +void to_json(json& j, const ReplyStartTransaction& k) noexcept { + j = json{ + {"status", k.status}, + }; + if (k.error) { + j["error"] = k.error.value(); + } + if (k.transaction_min_stop_time) { + j["transaction_min_stop_time"] = k.transaction_min_stop_time.value(); + } + if (k.transaction_max_stop_time) { + j["transaction_max_stop_time"] = k.transaction_max_stop_time.value(); + } +} + +void from_json(const json& j, ReplyStopTransaction& k) { + k.status = j.at("status"); + + if (j.contains("signed_meter_value")) { + k.signed_meter_value.emplace(j.at("signed_meter_value")); + } + if (j.contains("error")) { + k.error.emplace(j.at("error")); + } +} +void to_json(json& j, const ReplyStopTransaction& k) noexcept { + j = json{ + {"status", k.status}, + }; + if (k.signed_meter_value) { + j["signed_meter_value"] = k.signed_meter_value.value(); + } + if (k.error) { + j["error"] = k.error.value(); + } +} + +void from_json(const json& j, RequestStartTransaction& k) { + k.evse_id = j.at("evse_id"); + k.transaction_id = j.at("transaction_id"); + k.identification_status = j.at("identification_status"); + + k.identification_flags.clear(); + if (j.contains("identification_flags")) { + for (auto const& elem : j.at("identification_flags")) { + k.identification_flags.push_back(elem); + } + } + + k.identification_type = j.at("identification_type"); + if (j.contains("identification_level")) { + k.identification_level.emplace(j.at("identification_level")); + } + if (j.contains("identification_data")) { + k.identification_data = j.at("identification_data"); + } + if (j.contains("tariff_text")) { + k.tariff_text = j.at("tariff_text"); + } +} +void to_json(json& j, const RequestStartTransaction& k) noexcept { + j = json{ + {"evse_id", k.evse_id}, + {"transaction_id", k.transaction_id}, + {"identification_status", k.identification_status}, + {"identification_flags", k.identification_flags}, + {"identification_type", k.identification_type}, + }; + if (k.identification_level) { + j["identification_level"] = k.identification_level.value(); + } + if (k.identification_data) { + j["identification_data"] = k.identification_data.value(); + } + if (k.tariff_text) { + j["tariff_text"] = k.tariff_text.value(); + } +} + +} // namespace everest::lib::API::V1_0::types::powermeter diff --git a/lib/everest/everest_api_types/src/everest_api_types/powermeter/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/powermeter/wrapper.cpp new file mode 100644 index 0000000000..97d373a924 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/powermeter/wrapper.cpp @@ -0,0 +1,676 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "powermeter/wrapper.hpp" +#include "generated/types/units_signed.hpp" +#include "powermeter/API.hpp" +#include + +namespace everest::lib::API::V1_0::types::powermeter { + +template T toInternalApi(T const& val) { + return val; +} + +template T toExternalApi(T const& val) { + return val; +} + +template +auto toInternalApi(std::optional const& src) -> std::optional { + if (src) { + return std::make_optional(toInternalApi(src.value())); + } + return std::nullopt; +} + +template +auto toExternalApi(std::optional const& src) -> std::optional { + if (src) { + return std::make_optional(toExternalApi(src.value())); + } + return std::nullopt; +} + +OCMFUserIdentificationStatus_Internal toInternalApi(OCMFUserIdentificationStatus_External const& val) { + switch (val) { + case OCMFUserIdentificationStatus_External::ASSIGNED: + return OCMFUserIdentificationStatus_Internal::ASSIGNED; + case OCMFUserIdentificationStatus_External::NOT_ASSIGNED: + return OCMFUserIdentificationStatus_Internal::NOT_ASSIGNED; + } + throw std::out_of_range("No know conversion between internal and external OCMFUserIdentificationStatus API"); +} + +OCMFUserIdentificationStatus_External toExternalApi(OCMFUserIdentificationStatus_Internal const& val) { + switch (val) { + case OCMFUserIdentificationStatus_Internal::ASSIGNED: + return OCMFUserIdentificationStatus_External::ASSIGNED; + case OCMFUserIdentificationStatus_Internal::NOT_ASSIGNED: + return OCMFUserIdentificationStatus_External::NOT_ASSIGNED; + } + throw std::out_of_range("No know conversion between internal and external OCMFUserIdentificationStatus API"); +} + +OCMFIdentificationFlags_Internal toInternalApi(OCMFIdentificationFlags_External const& val) { + switch (val) { + case OCMFIdentificationFlags_External::RFID_NONE: + return OCMFIdentificationFlags_Internal::RFID_NONE; + case OCMFIdentificationFlags_External::RFID_PLAIN: + return OCMFIdentificationFlags_Internal::RFID_PLAIN; + case OCMFIdentificationFlags_External::RFID_RELATED: + return OCMFIdentificationFlags_Internal::RFID_RELATED; + case OCMFIdentificationFlags_External::RFID_PSK: + return OCMFIdentificationFlags_Internal::RFID_PSK; + case OCMFIdentificationFlags_External::OCPP_NONE: + return OCMFIdentificationFlags_Internal::OCPP_NONE; + case OCMFIdentificationFlags_External::OCPP_RS: + return OCMFIdentificationFlags_Internal::OCPP_RS; + case OCMFIdentificationFlags_External::OCPP_AUTH: + return OCMFIdentificationFlags_Internal::OCPP_AUTH; + case OCMFIdentificationFlags_External::OCPP_RS_TLS: + return OCMFIdentificationFlags_Internal::OCPP_RS_TLS; + case OCMFIdentificationFlags_External::OCPP_AUTH_TLS: + return OCMFIdentificationFlags_Internal::OCPP_AUTH_TLS; + case OCMFIdentificationFlags_External::OCPP_CACHE: + return OCMFIdentificationFlags_Internal::OCPP_CACHE; + case OCMFIdentificationFlags_External::OCPP_WHITELIST: + return OCMFIdentificationFlags_Internal::OCPP_WHITELIST; + case OCMFIdentificationFlags_External::OCPP_CERTIFIED: + return OCMFIdentificationFlags_Internal::OCPP_CERTIFIED; + case OCMFIdentificationFlags_External::ISO15118_NONE: + return OCMFIdentificationFlags_Internal::ISO15118_NONE; + case OCMFIdentificationFlags_External::ISO15118_PNC: + return OCMFIdentificationFlags_Internal::ISO15118_PNC; + case OCMFIdentificationFlags_External::PLMN_NONE: + return OCMFIdentificationFlags_Internal::PLMN_NONE; + case OCMFIdentificationFlags_External::PLMN_RING: + return OCMFIdentificationFlags_Internal::PLMN_RING; + case OCMFIdentificationFlags_External::PLMN_SMS: + return OCMFIdentificationFlags_Internal::PLMN_SMS; + } + throw std::out_of_range("No know conversion between internal and external OCMFIdentificationFlags API"); +} + +OCMFIdentificationFlags_External toExternalApi(OCMFIdentificationFlags_Internal const& val) { + switch (val) { + case OCMFIdentificationFlags_Internal::RFID_NONE: + return OCMFIdentificationFlags_External::RFID_NONE; + case OCMFIdentificationFlags_Internal::RFID_PLAIN: + return OCMFIdentificationFlags_External::RFID_PLAIN; + case OCMFIdentificationFlags_Internal::RFID_RELATED: + return OCMFIdentificationFlags_External::RFID_RELATED; + case OCMFIdentificationFlags_Internal::RFID_PSK: + return OCMFIdentificationFlags_External::RFID_PSK; + case OCMFIdentificationFlags_Internal::OCPP_NONE: + return OCMFIdentificationFlags_External::OCPP_NONE; + case OCMFIdentificationFlags_Internal::OCPP_RS: + return OCMFIdentificationFlags_External::OCPP_RS; + case OCMFIdentificationFlags_Internal::OCPP_AUTH: + return OCMFIdentificationFlags_External::OCPP_AUTH; + case OCMFIdentificationFlags_Internal::OCPP_RS_TLS: + return OCMFIdentificationFlags_External::OCPP_RS_TLS; + case OCMFIdentificationFlags_Internal::OCPP_AUTH_TLS: + return OCMFIdentificationFlags_External::OCPP_AUTH_TLS; + case OCMFIdentificationFlags_Internal::OCPP_CACHE: + return OCMFIdentificationFlags_External::OCPP_CACHE; + case OCMFIdentificationFlags_Internal::OCPP_WHITELIST: + return OCMFIdentificationFlags_External::OCPP_WHITELIST; + case OCMFIdentificationFlags_Internal::OCPP_CERTIFIED: + return OCMFIdentificationFlags_External::OCPP_CERTIFIED; + case OCMFIdentificationFlags_Internal::ISO15118_NONE: + return OCMFIdentificationFlags_External::ISO15118_NONE; + case OCMFIdentificationFlags_Internal::ISO15118_PNC: + return OCMFIdentificationFlags_External::ISO15118_PNC; + case OCMFIdentificationFlags_Internal::PLMN_NONE: + return OCMFIdentificationFlags_External::PLMN_NONE; + case OCMFIdentificationFlags_Internal::PLMN_RING: + return OCMFIdentificationFlags_External::PLMN_RING; + case OCMFIdentificationFlags_Internal::PLMN_SMS: + return OCMFIdentificationFlags_External::PLMN_SMS; + } + throw std::out_of_range("No know conversion between internal and external OCMFIdentificationFlags API"); +} + +OCMFIdentificationType_Internal toInternalApi(OCMFIdentificationType_External const& val) { + switch (val) { + case OCMFIdentificationType_External::NONE: + return OCMFIdentificationType_Internal::NONE; + case OCMFIdentificationType_External::DENIED: + return OCMFIdentificationType_Internal::DENIED; + case OCMFIdentificationType_External::UNDEFINED: + return OCMFIdentificationType_Internal::UNDEFINED; + case OCMFIdentificationType_External::ISO14443: + return OCMFIdentificationType_Internal::ISO14443; + case OCMFIdentificationType_External::ISO15693: + return OCMFIdentificationType_Internal::ISO15693; + case OCMFIdentificationType_External::EMAID: + return OCMFIdentificationType_Internal::EMAID; + case OCMFIdentificationType_External::EVCCID: + return OCMFIdentificationType_Internal::EVCCID; + case OCMFIdentificationType_External::EVCOID: + return OCMFIdentificationType_Internal::EVCOID; + case OCMFIdentificationType_External::ISO7812: + return OCMFIdentificationType_Internal::ISO7812; + case OCMFIdentificationType_External::CARD_TXN_NR: + return OCMFIdentificationType_Internal::CARD_TXN_NR; + case OCMFIdentificationType_External::CENTRAL: + return OCMFIdentificationType_Internal::CENTRAL; + case OCMFIdentificationType_External::CENTRAL_1: + return OCMFIdentificationType_Internal::CENTRAL_1; + case OCMFIdentificationType_External::CENTRAL_2: + return OCMFIdentificationType_Internal::CENTRAL_2; + case OCMFIdentificationType_External::LOCAL: + return OCMFIdentificationType_Internal::LOCAL; + case OCMFIdentificationType_External::LOCAL_1: + return OCMFIdentificationType_Internal::LOCAL_1; + case OCMFIdentificationType_External::LOCAL_2: + return OCMFIdentificationType_Internal::LOCAL_2; + case OCMFIdentificationType_External::PHONE_NUMBER: + return OCMFIdentificationType_Internal::PHONE_NUMBER; + case OCMFIdentificationType_External::KEY_CODE: + return OCMFIdentificationType_Internal::KEY_CODE; + } + throw std::out_of_range("No know conversion between internal and external OCMFIdentificationType API"); +} + +OCMFIdentificationType_External toExternalApi(OCMFIdentificationType_Internal const& val) { + switch (val) { + case OCMFIdentificationType_Internal::NONE: + return OCMFIdentificationType_External::NONE; + case OCMFIdentificationType_Internal::DENIED: + return OCMFIdentificationType_External::DENIED; + case OCMFIdentificationType_Internal::UNDEFINED: + return OCMFIdentificationType_External::UNDEFINED; + case OCMFIdentificationType_Internal::ISO14443: + return OCMFIdentificationType_External::ISO14443; + case OCMFIdentificationType_Internal::ISO15693: + return OCMFIdentificationType_External::ISO15693; + case OCMFIdentificationType_Internal::EMAID: + return OCMFIdentificationType_External::EMAID; + case OCMFIdentificationType_Internal::EVCCID: + return OCMFIdentificationType_External::EVCCID; + case OCMFIdentificationType_Internal::EVCOID: + return OCMFIdentificationType_External::EVCOID; + case OCMFIdentificationType_Internal::ISO7812: + return OCMFIdentificationType_External::ISO7812; + case OCMFIdentificationType_Internal::CARD_TXN_NR: + return OCMFIdentificationType_External::CARD_TXN_NR; + case OCMFIdentificationType_Internal::CENTRAL: + return OCMFIdentificationType_External::CENTRAL; + case OCMFIdentificationType_Internal::CENTRAL_1: + return OCMFIdentificationType_External::CENTRAL_1; + case OCMFIdentificationType_Internal::CENTRAL_2: + return OCMFIdentificationType_External::CENTRAL_2; + case OCMFIdentificationType_Internal::LOCAL: + return OCMFIdentificationType_External::LOCAL; + case OCMFIdentificationType_Internal::LOCAL_1: + return OCMFIdentificationType_External::LOCAL_1; + case OCMFIdentificationType_Internal::LOCAL_2: + return OCMFIdentificationType_External::LOCAL_2; + case OCMFIdentificationType_Internal::PHONE_NUMBER: + return OCMFIdentificationType_External::PHONE_NUMBER; + case OCMFIdentificationType_Internal::KEY_CODE: + return OCMFIdentificationType_External::KEY_CODE; + } + throw std::out_of_range("No know conversion between internal and external OCMFIdentificationType API"); +} + +OCMFIdentificationLevel_Internal toInternalApi(OCMFIdentificationLevel_External const& val) { + switch (val) { + case OCMFIdentificationLevel_External::NONE: + return OCMFIdentificationLevel_Internal::NONE; + case OCMFIdentificationLevel_External::HEARSAY: + return OCMFIdentificationLevel_Internal::HEARSAY; + case OCMFIdentificationLevel_External::TRUSTED: + return OCMFIdentificationLevel_Internal::TRUSTED; + case OCMFIdentificationLevel_External::VERIFIED: + return OCMFIdentificationLevel_Internal::VERIFIED; + case OCMFIdentificationLevel_External::CERTIFIED: + return OCMFIdentificationLevel_Internal::CERTIFIED; + case OCMFIdentificationLevel_External::SECURE: + return OCMFIdentificationLevel_Internal::SECURE; + case OCMFIdentificationLevel_External::MISMATCH: + return OCMFIdentificationLevel_Internal::MISMATCH; + case OCMFIdentificationLevel_External::INVALID: + return OCMFIdentificationLevel_Internal::INVALID; + case OCMFIdentificationLevel_External::OUTDATED: + return OCMFIdentificationLevel_Internal::OUTDATED; + case OCMFIdentificationLevel_External::UNKNOWN: + return OCMFIdentificationLevel_Internal::UNKNOWN; + } + + throw std::out_of_range("No know conversion between internal and external OCMFIdentificationLevel API"); +} + +OCMFIdentificationLevel_External toExternalApi(OCMFIdentificationLevel_Internal const& val) { + switch (val) { + case OCMFIdentificationLevel_Internal::NONE: + return OCMFIdentificationLevel_External::NONE; + case OCMFIdentificationLevel_Internal::HEARSAY: + return OCMFIdentificationLevel_External::HEARSAY; + case OCMFIdentificationLevel_Internal::TRUSTED: + return OCMFIdentificationLevel_External::TRUSTED; + case OCMFIdentificationLevel_Internal::VERIFIED: + return OCMFIdentificationLevel_External::VERIFIED; + case OCMFIdentificationLevel_Internal::CERTIFIED: + return OCMFIdentificationLevel_External::CERTIFIED; + case OCMFIdentificationLevel_Internal::SECURE: + return OCMFIdentificationLevel_External::SECURE; + case OCMFIdentificationLevel_Internal::MISMATCH: + return OCMFIdentificationLevel_External::MISMATCH; + case OCMFIdentificationLevel_Internal::INVALID: + return OCMFIdentificationLevel_External::INVALID; + case OCMFIdentificationLevel_Internal::OUTDATED: + return OCMFIdentificationLevel_External::OUTDATED; + case OCMFIdentificationLevel_Internal::UNKNOWN: + return OCMFIdentificationLevel_External::UNKNOWN; + } + + throw std::out_of_range("No know conversion between internal and external OCMFIdentificationLevel API"); +} + +Temperature_Internal toInternalApi(Temperature_External const& val) { + auto result = Temperature_Internal(); + result.temperature = val.temperature; + result.identification = toInternalApi(val.identification); + return result; +} + +Temperature_External toExternalApi(Temperature_Internal const& val) { + auto result = Temperature_External(); + result.temperature = val.temperature; + result.identification = toExternalApi(val.identification); + return result; +} + +Current_Internal toInternalApi(Current_External const& val) { + auto result = Current_Internal(); + result.DC = toInternalApi(val.DC); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + result.N = toInternalApi(val.N); + return result; +} + +Current_External toExternalApi(Current_Internal const& val) { + auto result = Current_External(); + result.DC = toExternalApi(val.DC); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + result.N = toExternalApi(val.N); + return result; +} + +Voltage_Internal toInternalApi(Voltage_External const& val) { + auto result = Voltage_Internal(); + result.DC = toInternalApi(val.DC); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +Voltage_External toExternalApi(Voltage_Internal const& val) { + auto result = Voltage_External(); + result.DC = toExternalApi(val.DC); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +Frequency_Internal toInternalApi(Frequency_External const& val) { + auto result = Frequency_Internal(); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +Frequency_External toExternalApi(Frequency_Internal const& val) { + auto result = Frequency_External(); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +Energy_Internal toInternalApi(Energy_External const& val) { + auto result = Energy_Internal(); + result.total = toInternalApi(val.total); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +Energy_External toExternalApi(Energy_Internal const& val) { + auto result = Energy_External(); + result.total = toExternalApi(val.total); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +Power_Internal toInternalApi(Power_External const& val) { + auto result = Power_Internal(); + result.total = toInternalApi(val.total); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +Power_External toExternalApi(Power_Internal const& val) { + auto result = Power_External(); + result.total = toExternalApi(val.total); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +ReactivePower_Internal toInternalApi(ReactivePower_External const& val) { + auto result = ReactivePower_Internal(); + result.total = toInternalApi(val.total); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +ReactivePower_External toExternalApi(ReactivePower_Internal const& val) { + auto result = ReactivePower_External(); + result.total = toExternalApi(val.total); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +SignedMeterValue_Internal toInternalApi(SignedMeterValue_External const& val) { + SignedMeterValue_Internal result; + result.signed_meter_data = val.signed_meter_data; + result.signing_method = val.signing_method; + result.encoding_method = val.encoding_method; + result.public_key = val.public_key; + result.timestamp = val.timestamp; + return result; +} + +SignedMeterValue_External toExternalApi(SignedMeterValue_Internal const& val) { + SignedMeterValue_External result; + result.signed_meter_data = val.signed_meter_data; + result.signing_method = val.signing_method; + result.encoding_method = val.encoding_method; + result.public_key = val.public_key; + result.timestamp = val.timestamp; + return result; +} + +SignedCurrent_Internal toInternalApi(SignedCurrent_External const& val) { + auto result = SignedCurrent_Internal(); + result.DC = toInternalApi(val.DC); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + result.N = toInternalApi(val.N); + return result; +} + +SignedCurrent_External toExternalApi(SignedCurrent_Internal const& val) { + auto result = SignedCurrent_External(); + result.DC = toExternalApi(val.DC); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + result.N = toExternalApi(val.N); + return result; +} + +SignedVoltage_Internal toInternalApi(SignedVoltage_External const& val) { + auto result = SignedVoltage_Internal(); + result.DC = toInternalApi(val.DC); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +SignedVoltage_External toExternalApi(SignedVoltage_Internal const& val) { + auto result = SignedVoltage_External(); + result.DC = toExternalApi(val.DC); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +SignedFrequency_Internal toInternalApi(SignedFrequency_External const& val) { + auto result = SignedFrequency_Internal(); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +SignedFrequency_External toExternalApi(SignedFrequency_Internal const& val) { + auto result = SignedFrequency_External(); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +SignedPower_Internal toInternalApi(SignedPower_External const& val) { + auto result = SignedPower_Internal(); + result.total = toInternalApi(val.total); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +SignedPower_External toExternalApi(SignedPower_Internal const& val) { + auto result = SignedPower_External(); + result.total = toExternalApi(val.total); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +SignedReactivePower_Internal toInternalApi(SignedReactivePower_External const& val) { + auto result = SignedReactivePower_Internal(); + result.total = toInternalApi(val.total); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +SignedReactivePower_External toExternalApi(SignedReactivePower_Internal const& val) { + auto result = SignedReactivePower_External(); + result.total = toExternalApi(val.total); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +SignedEnergy_Internal toInternalApi(SignedEnergy_External const& val) { + auto result = SignedEnergy_Internal(); + result.total = toInternalApi(val.total); + result.L1 = toInternalApi(val.L1); + result.L2 = toInternalApi(val.L2); + result.L3 = toInternalApi(val.L3); + return result; +} + +SignedEnergy_External toExternalApi(SignedEnergy_Internal const& val) { + auto result = SignedEnergy_External(); + result.total = toExternalApi(val.total); + result.L1 = toExternalApi(val.L1); + result.L2 = toExternalApi(val.L2); + result.L3 = toExternalApi(val.L3); + return result; +} + +PowermeterValues_Internal toInternalApi(PowermeterValues_External const& val) { + auto result = PowermeterValues_Internal(); + result.timestamp = val.timestamp; + result.energy_Wh_import = toInternalApi(val.energy_Wh_import); + result.meter_id = toInternalApi(val.meter_id); + result.phase_seq_error = toInternalApi(val.phase_seq_error); + result.energy_Wh_export = toInternalApi(val.energy_Wh_export); + result.power_W = toInternalApi(val.power_W); + result.voltage_V = toInternalApi(val.voltage_V); + result.VAR = toInternalApi(val.VAR); + result.current_A = toInternalApi(val.current_A); + result.frequency_Hz = toInternalApi(val.frequency_Hz); + result.energy_Wh_import_signed = toInternalApi(val.energy_Wh_import_signed); + result.energy_Wh_export_signed = toInternalApi(val.energy_Wh_export_signed); + result.power_W_signed = toInternalApi(val.power_W_signed); + result.voltage_V_signed = toInternalApi(val.voltage_V_signed); + result.VAR_signed = toInternalApi(val.VAR_signed); + result.current_A_signed = toInternalApi(val.current_A_signed); + result.frequency_Hz_signed = toInternalApi(val.frequency_Hz_signed); + result.signed_meter_value = toInternalApi(val.signed_meter_value); + if (val.temperatures) { + auto& tmp = result.temperatures.emplace(); + for (auto const& elem : val.temperatures.value()) { + tmp.push_back(toInternalApi(elem)); + } + } + + return result; +} + +PowermeterValues_External toExternalApi(PowermeterValues_Internal const& val) { + auto result = PowermeterValues_External(); + result.timestamp = toExternalApi(val.timestamp); + result.energy_Wh_import = toExternalApi(val.energy_Wh_import); + result.meter_id = toExternalApi(val.meter_id); + result.phase_seq_error = val.phase_seq_error; + result.energy_Wh_export = toExternalApi(val.energy_Wh_export); + result.power_W = toExternalApi(val.power_W); + result.voltage_V = toExternalApi(val.voltage_V); + result.VAR = toExternalApi(val.VAR); + result.current_A = toExternalApi(val.current_A); + result.frequency_Hz = toExternalApi(val.frequency_Hz); + result.energy_Wh_import_signed = toExternalApi(val.energy_Wh_import_signed); + result.energy_Wh_export_signed = toExternalApi(val.energy_Wh_export_signed); + result.power_W_signed = toExternalApi(val.power_W_signed); + result.voltage_V_signed = toExternalApi(val.voltage_V_signed); + result.VAR_signed = toExternalApi(val.VAR_signed); + result.current_A_signed = toExternalApi(val.current_A_signed); + result.frequency_Hz_signed = toExternalApi(val.frequency_Hz_signed); + result.signed_meter_value = toExternalApi(val.signed_meter_value); + if (val.temperatures) { + auto& tmp = result.temperatures.emplace(); + for (auto const& elem : val.temperatures.value()) { + tmp.push_back(toExternalApi(elem)); + } + } + + return result; +} + +TransactionStatus_Internal toInternalApi(TransactionStatus_External const& val) { + switch (val) { + case TransactionStatus_External::OK: + return TransactionStatus_Internal::OK; + case TransactionStatus_External::NOT_SUPPORTED: + return TransactionStatus_Internal::NOT_SUPPORTED; + case TransactionStatus_External::UNEXPECTED_ERROR: + return TransactionStatus_Internal::UNEXPECTED_ERROR; + } + + throw std::out_of_range("No known conversion from external to internal TransactionStatus API"); +} + +TransactionStatus_External toExternalApi(TransactionStatus_Internal const& val) { + switch (val) { + case TransactionStatus_Internal::OK: + return TransactionStatus_External::OK; + case TransactionStatus_Internal::NOT_SUPPORTED: + return TransactionStatus_External::NOT_SUPPORTED; + case TransactionStatus_Internal::UNEXPECTED_ERROR: + return TransactionStatus_External::UNEXPECTED_ERROR; + } + + throw std::out_of_range("No known conversion from internal to external TransactionStatus API"); +} + +ReplyStartTransaction_Internal toInternalApi(ReplyStartTransaction_External const& val) { + auto internal = ReplyStartTransaction_Internal(); + internal.status = toInternalApi(val.status); + internal.error = val.error; + internal.transaction_min_stop_time = val.transaction_min_stop_time; + internal.transaction_max_stop_time = val.transaction_max_stop_time; + return internal; +} + +ReplyStartTransaction_External toExternalApi(ReplyStartTransaction_Internal const& val) { + auto result = ReplyStartTransaction_External(); + result.status = toExternalApi(val.status); + result.error = val.error; + result.transaction_min_stop_time = val.transaction_min_stop_time; + result.transaction_max_stop_time = val.transaction_max_stop_time; + return result; +} + +ReplyStopTransaction_Internal toInternalApi(ReplyStopTransaction_External const& val) { + auto internal = ReplyStopTransaction_Internal(); + internal.status = toInternalApi(val.status); + if (val.signed_meter_value) { + internal.signed_meter_value.emplace(); + internal.signed_meter_value->signed_meter_data = val.signed_meter_value->signed_meter_data; + internal.signed_meter_value->signing_method = val.signed_meter_value->signing_method; + internal.signed_meter_value->encoding_method = val.signed_meter_value->encoding_method; + internal.signed_meter_value->public_key = val.signed_meter_value->public_key; + internal.signed_meter_value->timestamp = val.signed_meter_value->timestamp; + } + internal.error = val.error; + return internal; +} + +ReplyStopTransaction_External toExternalApi(ReplyStopTransaction_Internal const& val) { + auto result = ReplyStopTransaction_External(); + result.status = toExternalApi(val.status); + if (val.signed_meter_value) { + result.signed_meter_value.emplace(); + result.signed_meter_value->signed_meter_data = val.signed_meter_value->signed_meter_data; + result.signed_meter_value->signing_method = val.signed_meter_value->signing_method; + result.signed_meter_value->encoding_method = val.signed_meter_value->encoding_method; + result.signed_meter_value->public_key = val.signed_meter_value->public_key; + result.signed_meter_value->timestamp = val.signed_meter_value->timestamp; + } + result.error = val.error; + return result; +} + +RequestStartTransaction_External toExternalApi(const RequestStartTransaction_Internal& val) { + RequestStartTransaction result; + result.evse_id = val.evse_id; + result.transaction_id = val.transaction_id; + result.identification_status = toExternalApi(val.identification_status); + for (auto elem : val.identification_flags) { + result.identification_flags.push_back(toExternalApi(elem)); + } + result.identification_type = toExternalApi(val.identification_type); + if (val.identification_level) { + result.identification_level = toExternalApi(val.identification_level.value()); + } + if (val.identification_data) { + result.identification_data = val.identification_data; + } + result.tariff_text = val.tariff_text; + return result; +} + +} // namespace everest::lib::API::V1_0::types::powermeter diff --git a/lib/everest/everest_api_types/src/everest_api_types/slac/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/slac/codec.cpp new file mode 100644 index 0000000000..4b4c2a59c8 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/slac/codec.cpp @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "slac/codec.hpp" +#include "nlohmann/json.hpp" +#include "slac/API.hpp" +#include "slac/json_codec.hpp" +#include + +namespace everest::lib::API::V1_0::types::slac { + +std::string serialize(State val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, State const& val) { + os << serialize(val); + return os; +} + +template <> State deserialize(std::string const& s) { + auto data = json::parse(s); + State result = data; + return result; +} +} // namespace everest::lib::API::V1_0::types::slac diff --git a/lib/everest/everest_api_types/src/everest_api_types/slac/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/slac/json_codec.cpp new file mode 100644 index 0000000000..680b1dbd17 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/slac/json_codec.cpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "slac/json_codec.hpp" +#include "nlohmann/json.hpp" +#include "slac/API.hpp" +#include "slac/codec.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::slac { + +void from_json(json const& j, State& k) { + std::string s = j; + if (s == "UNMATCHED") { + k = State::UNMATCHED; + return; + } + if (s == "MATCHING") { + k = State::MATCHING; + return; + } + if (s == "MATCHED") { + k = State::MATCHED; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type API_V1_0_TYPES_SLAC_STATE"); +} + +void to_json(json& j, State const& k) noexcept { + switch (k) { + case State::UNMATCHED: + j = "UNMATCHED"; + return; + case State::MATCHING: + j = "MATCHING"; + return; + case State::MATCHED: + j = "MATCHED"; + return; + } + + j = "INVALID_VALUE__everest::lib::API::V1_0::types::SLAC::STATE"; +} +} // namespace everest::lib::API::V1_0::types::slac diff --git a/lib/everest/everest_api_types/src/everest_api_types/system/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/system/codec.cpp new file mode 100644 index 0000000000..30cf01c7c7 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/system/codec.cpp @@ -0,0 +1,206 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "system/codec.hpp" +#include "nlohmann/json.hpp" +#include "system/API.hpp" +#include "system/json_codec.hpp" +#include +#include +#include + +namespace everest::lib::API::V1_0::types::system { + +std::string serialize(UpdateFirmwareResponse val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(UploadLogsStatus val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(LogStatusEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(FirmwareUpdateStatusEnum val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ResetType val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(BootReason val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(FirmwareUpdateRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(UploadLogsRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(UploadLogsResponse const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(LogStatus const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(FirmwareUpdateStatus const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::string serialize(ResetRequest const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, UpdateFirmwareResponse const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, UploadLogsStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, LogStatusEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, FirmwareUpdateStatusEnum const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ResetType const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, BootReason const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, FirmwareUpdateRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, UploadLogsRequest const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, LogStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, FirmwareUpdateStatus const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, UploadLogsResponse const& val) { + os << serialize(val); + return os; +} + +std::ostream& operator<<(std::ostream& os, ResetRequest const& val) { + os << serialize(val); + return os; +} + +template <> UpdateFirmwareResponse deserialize(std::string const& s) { + auto data = json::parse(s); + UpdateFirmwareResponse result = data; + return result; +} + +template <> UploadLogsStatus deserialize(std::string const& s) { + auto data = json::parse(s); + UploadLogsStatus result = data; + return result; +} + +template <> LogStatusEnum deserialize(std::string const& s) { + auto data = json::parse(s); + LogStatusEnum result = data; + return result; +} + +template <> FirmwareUpdateStatusEnum deserialize(std::string const& s) { + auto data = json::parse(s); + FirmwareUpdateStatusEnum result = data; + return result; +} + +template <> ResetType deserialize(std::string const& s) { + auto data = json::parse(s); + ResetType result = data; + return result; +} + +template <> BootReason deserialize(std::string const& s) { + auto data = json::parse(s); + BootReason result = data; + return result; +} + +template <> FirmwareUpdateRequest deserialize(std::string const& s) { + auto data = json::parse(s); + FirmwareUpdateRequest result = data; + return result; +} + +template <> UploadLogsRequest deserialize(std::string const& s) { + auto data = json::parse(s); + UploadLogsRequest result = data; + return result; +} + +template <> UploadLogsResponse deserialize(std::string const& s) { + auto data = json::parse(s); + UploadLogsResponse result = data; + return result; +} + +template <> LogStatus deserialize(std::string const& s) { + auto data = json::parse(s); + LogStatus result = data; + return result; +} + +template <> FirmwareUpdateStatus deserialize(std::string const& s) { + auto data = json::parse(s); + FirmwareUpdateStatus result = data; + return result; +} + +template <> ResetRequest deserialize(std::string const& s) { + auto data = json::parse(s); + ResetRequest result = data; + return result; +} + +} // namespace everest::lib::API::V1_0::types::system diff --git a/lib/everest/everest_api_types/src/everest_api_types/system/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/system/json_codec.cpp new file mode 100644 index 0000000000..0f785ee17b --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/system/json_codec.cpp @@ -0,0 +1,517 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "system/json_codec.hpp" +#include "nlohmann/json.hpp" +#include "system/API.hpp" +#include "system/codec.hpp" +#include +#include +#include + +namespace everest::lib::API::V1_0::types::system { + +void to_json(json& j, const FirmwareUpdateRequest& k) noexcept { + j = json{ + {"request_id", k.request_id}, + {"location", k.location}, + }; + if (k.retries) { + j["retries"] = k.retries.value(); + } + if (k.retry_interval_s) { + j["retry_interval_s"] = k.retry_interval_s.value(); + } + if (k.retrieve_timestamp) { + j["retrieve_timestamp"] = k.retrieve_timestamp.value(); + } + if (k.install_timestamp) { + j["install_timestamp"] = k.install_timestamp.value(); + } + if (k.signing_certificate) { + j["signing_certificate"] = k.signing_certificate.value(); + } + if (k.signature) { + j["signature"] = k.signature.value(); + } +} +void from_json(const json& j, FirmwareUpdateRequest& k) { + k.request_id = j.at("request_id"); + k.location = j.at("location"); + + if (j.contains("retries")) { + k.retries.emplace(j.at("retries")); + } + if (j.contains("retry_interval_s")) { + k.retry_interval_s.emplace(j.at("retry_interval_s")); + } + if (j.contains("retrieve_timestamp")) { + k.retrieve_timestamp.emplace(j.at("retrieve_timestamp")); + } + if (j.contains("install_timestamp")) { + k.install_timestamp.emplace(j.at("install_timestamp")); + } + if (j.contains("signing_certificate")) { + k.signing_certificate.emplace(j.at("signing_certificate")); + } + if (j.contains("signature")) { + k.signature.emplace(j.at("signature")); + } +} + +void to_json(json& j, const UploadLogsRequest& k) noexcept { + j = json{ + {"location", k.location}, + }; + if (k.retries) { + j["retries"] = k.retries.value(); + } + if (k.retry_interval_s) { + j["retry_interval_s"] = k.retry_interval_s.value(); + } + if (k.oldest_timestamp) { + j["oldest_timestamp"] = k.oldest_timestamp.value(); + } + if (k.latest_timestamp) { + j["latest_timestamp"] = k.latest_timestamp.value(); + } + if (k.type) { + j["type"] = k.type.value(); + } + if (k.request_id) { + j["request_id"] = k.request_id.value(); + } +} +void from_json(const json& j, UploadLogsRequest& k) { + k.location = j.at("location"); + + if (j.contains("retries")) { + k.retries.emplace(j.at("retries")); + } + if (j.contains("retry_interval_s")) { + k.retry_interval_s.emplace(j.at("retry_interval_s")); + } + if (j.contains("oldest_timestamp")) { + k.oldest_timestamp.emplace(j.at("oldest_timestamp")); + } + if (j.contains("latest_timestamp")) { + k.latest_timestamp.emplace(j.at("latest_timestamp")); + } + if (j.contains("type")) { + k.type.emplace(j.at("type")); + } + if (j.contains("request_id")) { + k.request_id.emplace(j.at("request_id")); + } +} + +void to_json(json& j, const UploadLogsResponse& k) noexcept { + j = json{ + {"upload_logs_status", k.upload_logs_status}, + }; + if (k.file_name) { + j["file_name"] = k.file_name.value(); + } +} +void from_json(const json& j, UploadLogsResponse& k) { + k.upload_logs_status = j.at("upload_logs_status"); + + if (j.contains("file_name")) { + k.file_name.emplace(j.at("file_name")); + } +} + +void to_json(json& j, const LogStatus& k) noexcept { + j = json{ + {"log_status", k.log_status}, + {"request_id", k.request_id}, + }; +} +void from_json(const json& j, LogStatus& k) { + k.log_status = j.at("log_status"); + k.request_id = j.at("request_id"); +} + +void to_json(json& j, const FirmwareUpdateStatus& k) noexcept { + j = json{ + {"firmware_update_status", k.firmware_update_status}, + {"request_id", k.request_id}, + }; +} +void from_json(const json& j, FirmwareUpdateStatus& k) { + k.firmware_update_status = j.at("firmware_update_status"); + k.request_id = j.at("request_id"); +} + +void to_json(json& j, const ResetRequest& k) noexcept { + j = json{ + {"type", k.type}, + {"scheduled", k.scheduled}, + }; +} +void from_json(const json& j, ResetRequest& k) { + k.type = j.at("type"); + k.scheduled = j.at("scheduled"); +} + +void to_json(json& j, const UpdateFirmwareResponse& k) noexcept { + switch (k) { + case UpdateFirmwareResponse::Accepted: + j = "Accepted"; + return; + case UpdateFirmwareResponse::Rejected: + j = "Rejected"; + return; + case UpdateFirmwareResponse::AcceptedCanceled: + j = "AcceptedCanceled"; + return; + case UpdateFirmwareResponse::InvalidCertificate: + j = "InvalidCertificate"; + return; + case UpdateFirmwareResponse::RevokedCertificate: + j = "RevokedCertificate"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::system::UpdateFirmwareResponse"; +} +void from_json(const json& j, UpdateFirmwareResponse& k) { + std::string s = j; + if (s == "Accepted") { + k = UpdateFirmwareResponse::Accepted; + return; + } + if (s == "Rejected") { + k = UpdateFirmwareResponse::Rejected; + return; + } + if (s == "AcceptedCanceled") { + k = UpdateFirmwareResponse::AcceptedCanceled; + return; + } + if (s == "InvalidCertificate") { + k = UpdateFirmwareResponse::InvalidCertificate; + return; + } + if (s == "RevokedCertificate") { + k = UpdateFirmwareResponse::RevokedCertificate; + return; + } + + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type UpdateFirmwareResponse"); +} + +void to_json(json& j, const UploadLogsStatus& k) noexcept { + switch (k) { + case UploadLogsStatus::Accepted: + j = "Accepted"; + return; + case UploadLogsStatus::Rejected: + j = "Rejected"; + return; + case UploadLogsStatus::AcceptedCanceled: + j = "AcceptedCanceled"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::system::UploadLogsStatus"; +} +void from_json(const json& j, UploadLogsStatus& k) { + std::string s = j; + if (s == "Accepted") { + k = UploadLogsStatus::Accepted; + return; + } + if (s == "Rejected") { + k = UploadLogsStatus::Rejected; + return; + } + if (s == "AcceptedCanceled") { + k = UploadLogsStatus::AcceptedCanceled; + return; + } + + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type UploadLogsStatus"); +} + +void to_json(json& j, const LogStatusEnum& k) noexcept { + switch (k) { + case LogStatusEnum::BadMessage: + j = "BadMessage"; + return; + case LogStatusEnum::Idle: + j = "Idle"; + return; + case LogStatusEnum::NotSupportedOperation: + j = "NotSupportedOperation"; + return; + case LogStatusEnum::PermissionDenied: + j = "PermissionDenied"; + return; + case LogStatusEnum::Uploaded: + j = "Uploaded"; + return; + case LogStatusEnum::UploadFailure: + j = "UploadFailure"; + return; + case LogStatusEnum::Uploading: + j = "Uploading"; + return; + case LogStatusEnum::AcceptedCanceled: + j = "AcceptedCanceled"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::system::LogStatusEnum"; +} +void from_json(const json& j, LogStatusEnum& k) { + std::string s = j; + if (s == "BadMessage") { + k = LogStatusEnum::BadMessage; + return; + } + if (s == "Idle") { + k = LogStatusEnum::Idle; + return; + } + if (s == "NotSupportedOperation") { + k = LogStatusEnum::NotSupportedOperation; + return; + } + if (s == "PermissionDenied") { + k = LogStatusEnum::PermissionDenied; + return; + } + if (s == "Uploaded") { + k = LogStatusEnum::Uploaded; + return; + } + if (s == "UploadFailure") { + k = LogStatusEnum::UploadFailure; + return; + } + if (s == "Uploading") { + k = LogStatusEnum::Uploading; + return; + } + if (s == "AcceptedCanceled") { + k = LogStatusEnum::AcceptedCanceled; + return; + } + + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type LogStatusEnum"); +} + +void to_json(json& j, const FirmwareUpdateStatusEnum& k) noexcept { + switch (k) { + case FirmwareUpdateStatusEnum::Downloaded: + j = "Downloaded"; + return; + case FirmwareUpdateStatusEnum::DownloadFailed: + j = "DownloadFailed"; + return; + case FirmwareUpdateStatusEnum::Downloading: + j = "Downloading"; + return; + case FirmwareUpdateStatusEnum::DownloadScheduled: + j = "DownloadScheduled"; + return; + case FirmwareUpdateStatusEnum::DownloadPaused: + j = "DownloadPaused"; + return; + case FirmwareUpdateStatusEnum::Idle: + j = "Idle"; + return; + case FirmwareUpdateStatusEnum::InstallationFailed: + j = "InstallationFailed"; + return; + case FirmwareUpdateStatusEnum::Installing: + j = "Installing"; + return; + case FirmwareUpdateStatusEnum::Installed: + j = "Installed"; + return; + case FirmwareUpdateStatusEnum::InstallRebooting: + j = "InstallRebooting"; + return; + case FirmwareUpdateStatusEnum::InstallScheduled: + j = "InstallScheduled"; + return; + case FirmwareUpdateStatusEnum::InstallVerificationFailed: + j = "InstallVerificationFailed"; + return; + case FirmwareUpdateStatusEnum::InvalidSignature: + j = "InvalidSignature"; + return; + case FirmwareUpdateStatusEnum::SignatureVerified: + j = "SignatureVerified"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::system::UpdateFirmwareResponFirmwareUpdateStatusEnum"; +} +void from_json(const json& j, FirmwareUpdateStatusEnum& k) { + std::string s = j; + if (s == "Downloaded") { + k = FirmwareUpdateStatusEnum::Downloaded; + return; + } + if (s == "DownloadFailed") { + k = FirmwareUpdateStatusEnum::DownloadFailed; + return; + } + if (s == "Downloading") { + k = FirmwareUpdateStatusEnum::Downloading; + return; + } + if (s == "DownloadScheduled") { + k = FirmwareUpdateStatusEnum::DownloadScheduled; + return; + } + if (s == "DownloadPaused") { + k = FirmwareUpdateStatusEnum::DownloadPaused; + return; + } + if (s == "Idle") { + k = FirmwareUpdateStatusEnum::Idle; + return; + } + if (s == "InstallationFailed") { + k = FirmwareUpdateStatusEnum::InstallationFailed; + return; + } + if (s == "Installing") { + k = FirmwareUpdateStatusEnum::Installing; + return; + } + if (s == "Installed") { + k = FirmwareUpdateStatusEnum::Installed; + return; + } + if (s == "InstallRebooting") { + k = FirmwareUpdateStatusEnum::InstallRebooting; + return; + } + if (s == "InstallScheduled") { + k = FirmwareUpdateStatusEnum::InstallScheduled; + return; + } + if (s == "InstallVerificationFailed") { + k = FirmwareUpdateStatusEnum::InstallVerificationFailed; + return; + } + if (s == "InvalidSignature") { + k = FirmwareUpdateStatusEnum::InvalidSignature; + return; + } + if (s == "SignatureVerified") { + k = FirmwareUpdateStatusEnum::SignatureVerified; + return; + } + + throw std::out_of_range("Provided string " + s + + " could not be converted to enum of type FirmwareUpdateStatusEnum"); +} + +void to_json(json& j, const ResetType& k) noexcept { + switch (k) { + case ResetType::Soft: + j = "Soft"; + return; + case ResetType::Hard: + j = "Hard"; + return; + case ResetType::NotSpecified: + j = "NotSpecified"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::system::UpdateFirmwareResponResetType"; +} +void from_json(const json& j, ResetType& k) { + std::string s = j; + if (s == "Soft") { + k = ResetType::Soft; + return; + } + if (s == "Hard") { + k = ResetType::Hard; + return; + } + if (s == "NotSpecified") { + k = ResetType::NotSpecified; + return; + } + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type ResetType"); +} + +void to_json(json& j, const BootReason& k) noexcept { + switch (k) { + case BootReason::ApplicationReset: + j = "ApplicationReset"; + return; + case BootReason::FirmwareUpdate: + j = "FirmwareUpdate"; + return; + case BootReason::LocalReset: + j = "LocalReset"; + return; + case BootReason::PowerUp: + j = "PowerUp"; + return; + case BootReason::RemoteReset: + j = "RemoteReset"; + return; + case BootReason::ScheduledReset: + j = "ScheduledReset"; + return; + case BootReason::Triggered: + j = "Triggered"; + return; + case BootReason::Unknown: + j = "Unknown"; + return; + case BootReason::Watchdog: + j = "Watchdog"; + return; + } + j = "INVALID_VALUE__everest::lib::API::V1_0::types::system::BootReason"; +} +void from_json(const json& j, BootReason& k) { + std::string s = j; + if (s == "ApplicationReset") { + k = BootReason::ApplicationReset; + return; + } + if (s == "FirmwareUpdate") { + k = BootReason::FirmwareUpdate; + return; + } + if (s == "LocalReset") { + k = BootReason::LocalReset; + return; + } + if (s == "PowerUp") { + k = BootReason::PowerUp; + return; + } + if (s == "RemoteReset") { + k = BootReason::RemoteReset; + return; + } + if (s == "ScheduledReset") { + k = BootReason::ScheduledReset; + return; + } + if (s == "Triggered") { + k = BootReason::Triggered; + return; + } + if (s == "Unknown") { + k = BootReason::Unknown; + return; + } + if (s == "Watchdog") { + k = BootReason::Watchdog; + return; + } + + throw std::out_of_range("Provided string " + s + " could not be converted to enum of type BootReason"); +} + +} // namespace everest::lib::API::V1_0::types::system diff --git a/lib/everest/everest_api_types/src/everest_api_types/system/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/system/wrapper.cpp new file mode 100644 index 0000000000..4b324f0e95 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/system/wrapper.cpp @@ -0,0 +1,356 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "system/wrapper.hpp" +#include "system/codec.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::system { + +UpdateFirmwareResponse_Internal toInternalApi(UpdateFirmwareResponse_External const& val) { + using SrcT = UpdateFirmwareResponse_External; + using TarT = UpdateFirmwareResponse_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::AcceptedCanceled: + return TarT::AcceptedCanceled; + case SrcT::InvalidCertificate: + return TarT::InvalidCertificate; + case SrcT::RevokedCertificate: + return TarT::RevokedCertificate; + } + throw std::out_of_range("Unexpected value for UpdateFirmwareResponse_Internal" + serialize(val)); +} +UpdateFirmwareResponse_External toExternalApi(UpdateFirmwareResponse_Internal const& val) { + using SrcT = UpdateFirmwareResponse_Internal; + using TarT = UpdateFirmwareResponse_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::AcceptedCanceled: + return TarT::AcceptedCanceled; + case SrcT::InvalidCertificate: + return TarT::InvalidCertificate; + case SrcT::RevokedCertificate: + return TarT::RevokedCertificate; + } + throw std::out_of_range("Unexpected value for UpdateFirmwareResponse_External"); +} + +UploadLogsStatus_Internal toInternalApi(UploadLogsStatus_External const& val) { + using SrcT = UploadLogsStatus_External; + using TarT = UploadLogsStatus_Internal; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::AcceptedCanceled: + return TarT::AcceptedCanceled; + } + throw std::out_of_range("Unexpected value for UploadLogsStatus_Internal" + serialize(val)); +} +UploadLogsStatus_External toExternalApi(UploadLogsStatus_Internal const& val) { + using SrcT = UploadLogsStatus_Internal; + using TarT = UploadLogsStatus_External; + switch (val) { + case SrcT::Accepted: + return TarT::Accepted; + case SrcT::Rejected: + return TarT::Rejected; + case SrcT::AcceptedCanceled: + return TarT::AcceptedCanceled; + } + throw std::out_of_range("Unexpected value for UploadLogsStatus_External"); +} + +LogStatusEnum_Internal toInternalApi(LogStatusEnum_External const& val) { + using SrcT = LogStatusEnum_External; + using TarT = LogStatusEnum_Internal; + switch (val) { + case SrcT::BadMessage: + return TarT::BadMessage; + case SrcT::Idle: + return TarT::Idle; + case SrcT::NotSupportedOperation: + return TarT::NotSupportedOperation; + case SrcT::PermissionDenied: + return TarT::PermissionDenied; + case SrcT::Uploaded: + return TarT::Uploaded; + case SrcT::UploadFailure: + return TarT::UploadFailure; + case SrcT::Uploading: + return TarT::Uploading; + case SrcT::AcceptedCanceled: + return TarT::AcceptedCanceled; + } + throw std::out_of_range("Unexpected value for LogStatusEnum_Internal" + serialize(val)); +} +LogStatusEnum_External toExternalApi(LogStatusEnum_Internal const& val) { + using SrcT = LogStatusEnum_Internal; + using TarT = LogStatusEnum_External; + switch (val) { + case SrcT::BadMessage: + return TarT::BadMessage; + case SrcT::Idle: + return TarT::Idle; + case SrcT::NotSupportedOperation: + return TarT::NotSupportedOperation; + case SrcT::PermissionDenied: + return TarT::PermissionDenied; + case SrcT::Uploaded: + return TarT::Uploaded; + case SrcT::UploadFailure: + return TarT::UploadFailure; + case SrcT::Uploading: + return TarT::Uploading; + case SrcT::AcceptedCanceled: + return TarT::AcceptedCanceled; + } + throw std::out_of_range("Unexpected value for LogStatusEnum_External"); +} + +FirmwareUpdateStatusEnum_Internal toInternalApi(FirmwareUpdateStatusEnum_External const& val) { + using SrcT = FirmwareUpdateStatusEnum_External; + using TarT = FirmwareUpdateStatusEnum_Internal; + switch (val) { + case SrcT::Downloaded: + return TarT::Downloaded; + case SrcT::DownloadFailed: + return TarT::DownloadFailed; + case SrcT::Downloading: + return TarT::Downloading; + case SrcT::DownloadScheduled: + return TarT::DownloadScheduled; + case SrcT::DownloadPaused: + return TarT::DownloadPaused; + case SrcT::Idle: + return TarT::Idle; + case SrcT::InstallationFailed: + return TarT::InstallationFailed; + case SrcT::Installing: + return TarT::Installing; + case SrcT::Installed: + return TarT::Installed; + case SrcT::InstallRebooting: + return TarT::InstallRebooting; + case SrcT::InstallScheduled: + return TarT::InstallScheduled; + case SrcT::InstallVerificationFailed: + return TarT::InstallVerificationFailed; + case SrcT::InvalidSignature: + return TarT::InvalidSignature; + case SrcT::SignatureVerified: + return TarT::SignatureVerified; + } + throw std::out_of_range("Unexpected value for FirmwareUpdateStatusEnum_Internal" + serialize(val)); +} +FirmwareUpdateStatusEnum_External toExternalApi(FirmwareUpdateStatusEnum_Internal const& val) { + using SrcT = FirmwareUpdateStatusEnum_Internal; + using TarT = FirmwareUpdateStatusEnum_External; + switch (val) { + case SrcT::Downloaded: + return TarT::Downloaded; + case SrcT::DownloadFailed: + return TarT::DownloadFailed; + case SrcT::Downloading: + return TarT::Downloading; + case SrcT::DownloadScheduled: + return TarT::DownloadScheduled; + case SrcT::DownloadPaused: + return TarT::DownloadPaused; + case SrcT::Idle: + return TarT::Idle; + case SrcT::InstallationFailed: + return TarT::InstallationFailed; + case SrcT::Installing: + return TarT::Installing; + case SrcT::Installed: + return TarT::Installed; + case SrcT::InstallRebooting: + return TarT::InstallRebooting; + case SrcT::InstallScheduled: + return TarT::InstallScheduled; + case SrcT::InstallVerificationFailed: + return TarT::InstallVerificationFailed; + case SrcT::InvalidSignature: + return TarT::InvalidSignature; + case SrcT::SignatureVerified: + return TarT::SignatureVerified; + } + throw std::out_of_range("Unexpected value for FirmwareUpdateStatusEnum_External"); +} + +ResetType_Internal toInternalApi(ResetType_External const& val) { + using SrcT = ResetType_External; + using TarT = ResetType_Internal; + switch (val) { + case SrcT::Soft: + return TarT::Soft; + case SrcT::Hard: + return TarT::Hard; + case SrcT::NotSpecified: + return TarT::NotSpecified; + } + throw std::out_of_range("Unexpected value for ResetType_Internal" + serialize(val)); +} +ResetType_External toExternalApi(ResetType_Internal const& val) { + using SrcT = ResetType_Internal; + using TarT = ResetType_External; + switch (val) { + case SrcT::Soft: + return TarT::Soft; + case SrcT::Hard: + return TarT::Hard; + case SrcT::NotSpecified: + return TarT::NotSpecified; + } + throw std::out_of_range("Unexpected value for ResetType_External"); +} + +BootReason_Internal toInternalApi(BootReason_External const& val) { + using SrcT = BootReason_External; + using TarT = BootReason_Internal; + switch (val) { + case SrcT::ApplicationReset: + return TarT::ApplicationReset; + case SrcT::FirmwareUpdate: + return TarT::FirmwareUpdate; + case SrcT::LocalReset: + return TarT::LocalReset; + case SrcT::PowerUp: + return TarT::PowerUp; + case SrcT::RemoteReset: + return TarT::RemoteReset; + case SrcT::ScheduledReset: + return TarT::ScheduledReset; + case SrcT::Triggered: + return TarT::Triggered; + case SrcT::Unknown: + return TarT::Unknown; + case SrcT::Watchdog: + return TarT::Watchdog; + } + throw std::out_of_range("Unexpected value for BootReason_Internal" + serialize(val)); +} +BootReason_External toExternalApi(BootReason_Internal const& val) { + using SrcT = BootReason_Internal; + using TarT = BootReason_External; + switch (val) { + case SrcT::ApplicationReset: + return TarT::ApplicationReset; + case SrcT::FirmwareUpdate: + return TarT::FirmwareUpdate; + case SrcT::LocalReset: + return TarT::LocalReset; + case SrcT::PowerUp: + return TarT::PowerUp; + case SrcT::RemoteReset: + return TarT::RemoteReset; + case SrcT::ScheduledReset: + return TarT::ScheduledReset; + case SrcT::Triggered: + return TarT::Triggered; + case SrcT::Unknown: + return TarT::Unknown; + case SrcT::Watchdog: + return TarT::Watchdog; + } + throw std::out_of_range("Unexpected value for BootReason_External"); +} + +FirmwareUpdateRequest_Internal toInternalApi(FirmwareUpdateRequest_External const& val) { + FirmwareUpdateRequest_Internal result; + result.request_id = val.request_id; + result.location = val.location; + result.retries = val.retries; + result.retry_interval_s = val.retry_interval_s; + result.retrieve_timestamp = val.retrieve_timestamp; + result.install_timestamp = val.install_timestamp; + result.signing_certificate = val.signing_certificate; + result.signature = val.signature; + return result; +} +FirmwareUpdateRequest_External toExternalApi(FirmwareUpdateRequest_Internal const& val) { + FirmwareUpdateRequest_External result; + result.request_id = val.request_id; + result.location = val.location; + result.retries = val.retries; + result.retry_interval_s = val.retry_interval_s; + result.retrieve_timestamp = val.retrieve_timestamp; + result.install_timestamp = val.install_timestamp; + result.signing_certificate = val.signing_certificate; + result.signature = val.signature; + return result; +} + +UploadLogsRequest_Internal toInternalApi(UploadLogsRequest_External const& val) { + UploadLogsRequest_Internal result; + result.location = val.location; + result.retries = val.retries; + result.retry_interval_s = val.retry_interval_s; + result.oldest_timestamp = val.oldest_timestamp; + result.latest_timestamp = val.latest_timestamp; + result.type = val.type; + result.request_id = val.request_id; + return result; +} +UploadLogsRequest_External toExternalApi(UploadLogsRequest_Internal const& val) { + UploadLogsRequest_External result; + result.location = val.location; + result.retries = val.retries; + result.retry_interval_s = val.retry_interval_s; + result.oldest_timestamp = val.oldest_timestamp; + result.latest_timestamp = val.latest_timestamp; + result.type = val.type; + result.request_id = val.request_id; + return result; +} + +UploadLogsResponse_Internal toInternalApi(UploadLogsResponse_External const& val) { + UploadLogsResponse_Internal result; + result.upload_logs_status = toInternalApi(val.upload_logs_status); + result.file_name = val.file_name; + return result; +} +UploadLogsResponse_External toExternalApi(UploadLogsResponse_Internal const& val) { + UploadLogsResponse_External result; + result.upload_logs_status = toExternalApi(val.upload_logs_status); + result.file_name = val.file_name; + return result; +} + +LogStatus_Internal toInternalApi(LogStatus_External const& val) { + LogStatus_Internal result; + result.log_status = toInternalApi(val.log_status); + result.request_id = val.request_id; + return result; +} +LogStatus_External toExternalApi(LogStatus_Internal const& val) { + LogStatus_External result; + result.log_status = toExternalApi(val.log_status); + result.request_id = val.request_id; + return result; +} + +FirmwareUpdateStatus_Internal toInternalApi(FirmwareUpdateStatus_External const& val) { + FirmwareUpdateStatus_Internal result; + result.firmware_update_status = toInternalApi(val.firmware_update_status); + result.request_id = val.request_id; + return result; +} +FirmwareUpdateStatus_External toExternalApi(FirmwareUpdateStatus_Internal const& val) { + FirmwareUpdateStatus_External result; + result.firmware_update_status = toExternalApi(val.firmware_update_status); + result.request_id = val.request_id; + return result; +} + +} // namespace everest::lib::API::V1_0::types::system diff --git a/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/codec.cpp new file mode 100644 index 0000000000..2e837cfeac --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/codec.cpp @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "uk_random_delay/codec.hpp" +#include "nlohmann/json.hpp" +#include "uk_random_delay/API.hpp" +#include "uk_random_delay/json_codec.hpp" +#include +#include +#include + +namespace everest::lib::API::V1_0::types::uk_random_delay { + +std::string serialize(CountDown const& val) noexcept { + json result = val; + return result.dump(4); +} + +std::ostream& operator<<(std::ostream& os, CountDown const& val) { + os << serialize(val); + return os; +} + +template <> CountDown deserialize(std::string const& s) { + auto data = json::parse(s); + CountDown result = data; + return result; +} + +} // namespace everest::lib::API::V1_0::types::uk_random_delay diff --git a/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/json_codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/json_codec.cpp new file mode 100644 index 0000000000..be584f591e --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/json_codec.cpp @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "uk_random_delay/json_codec.hpp" +#include "nlohmann/json.hpp" +#include "uk_random_delay/API.hpp" +#include "uk_random_delay/codec.hpp" +#include +#include +#include + +namespace everest::lib::API::V1_0::types::uk_random_delay { + +void to_json(json& j, CountDown const& k) noexcept { + j = json{ + {"countdown_s", k.countdown_s}, + {"current_limit_after_delay_A", k.current_limit_after_delay_A}, + {"current_limit_during_delay_A", k.current_limit_during_delay_A}, + }; + if (k.start_time) { + j["start_time"] = k.start_time.value(); + } +} + +void from_json(const json& j, CountDown& k) { + k.countdown_s = j.at("countdown_s"); + k.current_limit_after_delay_A = j.at("current_limit_after_delay_A"); + k.current_limit_during_delay_A = j.at("current_limit_during_delay_A"); + + if (j.contains("start_time")) { + k.start_time.emplace(j.at("start_time")); + } +} + +} // namespace everest::lib::API::V1_0::types::uk_random_delay diff --git a/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/wrapper.cpp b/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/wrapper.cpp new file mode 100644 index 0000000000..247724887c --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/uk_random_delay/wrapper.cpp @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "uk_random_delay/wrapper.hpp" +#include "uk_random_delay/codec.hpp" +#include +#include + +namespace everest::lib::API::V1_0::types::uk_random_delay { + +CountDown_Internal toInternalApi(CountDown_External const& val) { + CountDown_Internal result; + result.countdown_s = val.countdown_s; + result.current_limit_after_delay_A = val.current_limit_after_delay_A; + result.current_limit_during_delay_A = val.current_limit_during_delay_A; + result.start_time = val.start_time; + return result; +} + +CountDown_External toExternalApi(CountDown_Internal const& val) { + CountDown_External result; + result.countdown_s = val.countdown_s; + result.current_limit_after_delay_A = val.current_limit_after_delay_A; + result.current_limit_during_delay_A = val.current_limit_during_delay_A; + result.start_time = val.start_time; + return result; +} + +} // namespace everest::lib::API::V1_0::types::uk_random_delay diff --git a/lib/everest/everest_api_types/src/everest_api_types/utilities/Topics.cpp b/lib/everest/everest_api_types/src/everest_api_types/utilities/Topics.cpp new file mode 100644 index 0000000000..8d96ab9330 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/utilities/Topics.cpp @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "utilities/Topics.hpp" +#include +#include + +namespace everest::lib::API { + +Topics::Topics(const std::string& target_module_id_) : target_module_id(target_module_id_) { +} + +void Topics::setTargetApiModuleID(const std::string& target_module_id_, const std::string& api_type_) { + target_module_id = target_module_id_; + api_type = api_type_; +} + +std::string Topics::everest_to_extern(const std::string& var) const { + std::stringstream topic; + topic << api_base << "/" << api_version << "/" << api_type << "/" << target_module_id << "/" << api_out << "/" + << var; + return topic.str(); +} + +std::string Topics::extern_to_everest(const std::string& var) const { + std::stringstream topic; + topic << api_base << "/" << api_version << "/" << api_type << "/" << target_module_id << "/" << api_in << "/" + << var; + return topic.str(); +} + +std::string Topics::reply_to_everest(const std::string& reply) const { + std::stringstream topic; + topic << api_base << "/" << api_version << "/" << api_type << "/" << target_module_id << "/" << api_in << "/reply/" + << reply; + return topic.str(); +} + +std::string Topics::cloud_connector(const std::string_view& var) { + std::stringstream topic; + topic << cloud_base << "/" << var; + return topic.str(); +} + +const std::string Topics::api_base = "everest_api"; +const std::string Topics::api_version = "1.0"; +const std::string Topics::api_out = "e2m"; +const std::string Topics::api_in = "m2e"; +const std::string Topics::cloud_base = "everest/cloud"; + +} // namespace everest::lib::API diff --git a/lib/everest/everest_api_types/src/everest_api_types/utilities/codec.cpp b/lib/everest/everest_api_types/src/everest_api_types/utilities/codec.cpp new file mode 100644 index 0000000000..18325b8581 --- /dev/null +++ b/lib/everest/everest_api_types/src/everest_api_types/utilities/codec.cpp @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "everest_api_types/utilities/codec.hpp" +#include "everest_api_types/generic/codec.hpp" + +namespace everest::lib::API { + +template <> bool deserialize(std::string const& data, bool& obj) { + return everest::lib::API::V1_0::types::generic::adl_deserialize(data, obj); +} + +template <> bool deserialize(std::string const& data, int& obj) { + return everest::lib::API::V1_0::types::generic::adl_deserialize(data, obj); +} + +template <> bool deserialize(std::string const& data, double& obj) { + return everest::lib::API::V1_0::types::generic::adl_deserialize(data, obj); +} + +template <> bool deserialize(std::string const& data, float& obj) { + return everest::lib::API::V1_0::types::generic::adl_deserialize(data, obj); +} + +template <> bool deserialize(std::string const& data, std::string& obj) { + return everest::lib::API::V1_0::types::generic::adl_deserialize(data, obj); +} + +} // namespace everest::lib::API diff --git a/lib/everest/everest_api_types/src/utils/date.cpp b/lib/everest/everest_api_types/src/utils/date.cpp new file mode 100644 index 0000000000..cc84e4657c --- /dev/null +++ b/lib/everest/everest_api_types/src/utils/date.cpp @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "utils/date.hpp" + +namespace everest::utils { + +std::string to_rfc3339(const std::chrono::time_point& t) { + return date::format("%FT%TZ", std::chrono::time_point_cast(t)); +} + +std::chrono::time_point from_rfc3339(const std::string& t) { + std::istringstream infile{t}; + std::chrono::time_point tp; + infile >> date::parse("%FT%T", tp); + return tp; +} + +} // namespace everest::utils diff --git a/lib/everest/everest_api_types/tests/CMakeLists.txt b/lib/everest/everest_api_types/tests/CMakeLists.txt new file mode 100644 index 0000000000..2162f49269 --- /dev/null +++ b/lib/everest/everest_api_types/tests/CMakeLists.txt @@ -0,0 +1,61 @@ +set(TEST_TARGET_NAME ${PROJECT_NAME}_API_serialize_tests) +add_executable(${TEST_TARGET_NAME}) + +set(INCLUDE_DIR + "${PROJECT_SOURCE_DIR}/lib/everest/everest_api_types/include" + "${PROJECT_SOURCE_DIR}/lib/everest/everest_api_types/tests" +) + +target_include_directories(${TEST_TARGET_NAME} PUBLIC + ${INCLUDE_DIR} +) + +target_sources(${TEST_TARGET_NAME} PRIVATE + manual_tests/serialization/generic.hpp + manual_tests/serialization/generic.cpp +) + +target_link_libraries(${TEST_TARGET_NAME} PRIVATE + GTest::gmock + GTest::gtest_main + everest::log + everest::framework + everest::everest_api_types +) + +add_test(${TEST_TARGET_NAME} ${TEST_TARGET_NAME}) + +file(GLOB API_FILES ${PROJECT_SOURCE_DIR}/lib/everest/everest_api_types/include/everest_api_types/*/API.hpp) + +set(GENERATED_TESTS_LOCATION ${CMAKE_BINARY_DIR}/generated/lib/everest/everest_api_types/tests/) + +#update tests on api file change + +set( + GENERATE_COMMAND + ${Python3_EXECUTABLE} -B "${PROJECT_SOURCE_DIR}/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/main.py" + "${PROJECT_SOURCE_DIR}/lib/everest/everest_api_types/include/" + "${PROJECT_SOURCE_DIR}/lib/everest/everest_api_types/tests/" + "${PROJECT_SOURCE_DIR}/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/disable.csv" + "${GENERATED_TESTS_LOCATION}" + VERBATIM +) + +ADD_CUSTOM_COMMAND(OUTPUT ${GENERATED_TESTS_LOCATION} + COMMAND + ${GENERATE_COMMAND} + DEPENDS ${API_FILES} +) + +ADD_CUSTOM_TARGET(Generate_new_tests_on_file_change_only ALL DEPENDS ${GENERATED_TESTS_LOCATION}) + +add_dependencies(${TEST_TARGET_NAME} Generate_new_tests_on_file_change_only) + +#generate tests for the first time + +if(NOT EXISTS ${GENERATED_TESTS_LOCATION}) + EXECUTE_PROCESS(COMMAND ${GENERATE_COMMAND}) +endif() + + +add_subdirectory(${GENERATED_TESTS_LOCATION} ${GENERATED_TESTS_LOCATION}) diff --git a/lib/everest/everest_api_types/tests/SerializationTestHelpers.hpp b/lib/everest/everest_api_types/tests/SerializationTestHelpers.hpp new file mode 100644 index 0000000000..d368d5046c --- /dev/null +++ b/lib/everest/everest_api_types/tests/SerializationTestHelpers.hpp @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest +#pragma once + +#include "everest_api_types/utilities/codec.hpp" +#include +#include +#include + +/*This function standardises test for the interactions between serialization, + * stream serialization and deserialization of objects. + * It verifies, that serialization via serialize function and via std::ostream yields the same result; + */ +template T codec_test(T const& original_object) { + // basic serialization + std::string basic_serialization_result = serialize(original_object); + + // stream serialization + std::stringstream serialization_stream; + serialization_stream << original_object; + auto stream_serialization_result = serialization_stream.str(); + EXPECT_EQ(stream_serialization_result, basic_serialization_result); + + // deserialization + T result_object; + everest::lib::API::deserialize(basic_serialization_result, result_object); + + return result_object; +} + +/* Runs the default codec_test for all objects in the list + * This is used to run tests for all fields in a typial enum + * in namespace everest::lib::API::V1_0::types + */ +template void codec_test_all(std::initializer_list const& all_values) { + for (auto const& i : all_values) { + SCOPED_TRACE(i); + T result_object = codec_test(i); + EXPECT_EQ(i, result_object); + } +} + +/* + * Convenience function to test equality of two optionals of a base type + */ +template void expect_opt_eq(std::optional const& left, std::optional const& right) { + EXPECT_EQ(left.has_value(), right.has_value()); + if (right.has_value()) { + EXPECT_EQ(right.value(), left.value()); + } +} + +/* + * Returns a struct of type T with all its mandatory fields set to example values + * There ought to be a concrete implementation for every struct in everest_api_types + */ +template T generate(bool set_optional_fields = true); + +/* + * Works like the GTest function EXPECT_EQ(T first, T second) but it also supports structs as inputs + * There ought to be a concrete implementation for every struct in everest_api_types + */ +template void verify(T original, T result); + +/* + * Performs serialization tests with the given object + */ +template void test(T original) { + auto result = codec_test(original); + verify(original, result); +} + +/* + * Convenience function to use a default struct of type T and perform serialization tests on it + */ +template void gen_test(bool set_optional_fields = true) { + auto original = generate(set_optional_fields); + test(original); +} diff --git a/lib/everest/everest_api_types/tests/manual_tests/serialization/generic.cpp b/lib/everest/everest_api_types/tests/manual_tests/serialization/generic.cpp new file mode 100644 index 0000000000..2dad2cdc8d --- /dev/null +++ b/lib/everest/everest_api_types/tests/manual_tests/serialization/generic.cpp @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "SerializationTestHelpers.hpp" +#include "everest_api_types/generic/codec.hpp" +#include "nlohmann/json.hpp" +#include + +using namespace everest::lib::API::V1_0::types::generic; + +using namespace everest::lib::API::V1_0::types; + +// Warning: these test helpers are generated manually because the serialization of RequestReply works differently +// than other serializations because the to_json function may throw an error +template <> +everest::lib::API::V1_0::types::generic::RequestReply +generate(bool set_optional_fields) { + RequestReply generated_object; + generated_object.replyTo = "mdvChgNGIuAZPRzFEkDOLnsMUcJYyl"; + generated_object.payload = "{\"data\": { \"inner\" : 23, \"inner_str\":\"string\"}}"; + if (set_optional_fields) { + } + return generated_object; +} +template <> +void verify( + everest::lib::API::V1_0::types::generic::RequestReply original, + everest::lib::API::V1_0::types::generic::RequestReply result) { + auto orig_pl = nlohmann::json::parse(original.payload).dump(); + auto res_pl = nlohmann::json::parse(result.payload).dump(); + + EXPECT_EQ(original.replyTo, result.replyTo); + EXPECT_EQ(orig_pl, res_pl); +} + +namespace RequestReplyTestHelper { +RequestReply generate(int payload) { + RequestReply generated_object; + generated_object.replyTo = "mdvChgNGIuAZPRzFEkDOLnsMUcJYyl"; + generated_object.payload = std::to_string(payload); + return generated_object; +} +RequestReply generate(std::string payload) { + RequestReply generated_object; + generated_object.replyTo = "mdvChgNGIuAZPRzFEkDOLnsMUcJYyl"; + generated_object.payload = payload; + return generated_object; +} +void test(RequestReply original) { + auto result = codec_test(original); + verify(original, result); +} +void test(std::string payload) { + test(generate(payload)); +} +void test(int payload) { + test(generate(payload)); +} +void verify(RequestReply original_object, RequestReply result_object) { + EXPECT_EQ(original_object.replyTo, result_object.replyTo); + EXPECT_EQ(original_object.payload, result_object.payload); +} +}; // namespace RequestReplyTestHelper + +// Tests +TEST(generic, RequestReply_obj_payload_set) { + gen_test(); +} +TEST(generic, RequestReply_string_payload_set) { + EXPECT_THROW({ RequestReplyTestHelper::test("RHwxIpQVSTKyngUNAaOBuEsqCZDbze"); }, std::invalid_argument); +} + +TEST(generic, RequestReply_int_payload_set) { + RequestReplyTestHelper::test(1); +} + +TEST(generic, RequestReply_back_and_forth_1) { + RequestReply rr; + rr.replyTo = "/this/is/my/reply/address"; + rr.payload = R"( {"data": { "number" : 23, "string": "string", "obj": {"more": 11 }}} )"; + + auto ser = serialize(rr); + auto des = deserialize(ser); + + // std::cout << "\n\n" + // << "full serialize : " << ser << "\n" + // << "original payload: " << rr.payload << "\n" + // << "result payload : " << des.payload << std::endl; + + EXPECT_EQ(rr.replyTo, des.replyTo); + EXPECT_EQ(nlohmann::json::parse(rr.payload).dump(), nlohmann::json::parse(des.payload).dump()); +} + +TEST(generic, RequestReply_back_and_forth_2) { + RequestReply rr; + rr.replyTo = "/this/is/my/reply/address"; + rr.payload = "\"helloworld\""; + + auto ser = serialize(rr); + auto des = deserialize(ser); + auto ser2 = serialize(des); + auto des2 = deserialize(ser2); + + // std::cout << "\n\n" + // << "full serialize : " << ser << "\n" + // << "original payload : " << rr.payload << "\n" + // << "result payload : " << des.payload << "\n" + // << "result payload2 : " << des2.payload << std::endl; + + EXPECT_EQ(rr.replyTo, des.replyTo); + EXPECT_EQ(rr.payload, des.payload); + EXPECT_EQ(rr.replyTo, des2.replyTo); + EXPECT_EQ(rr.payload, des2.payload); +} diff --git a/lib/everest/everest_api_types/tests/manual_tests/serialization/generic.hpp b/lib/everest/everest_api_types/tests/manual_tests/serialization/generic.hpp new file mode 100644 index 0000000000..0953a1a9e7 --- /dev/null +++ b/lib/everest/everest_api_types/tests/manual_tests/serialization/generic.hpp @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#pragma once +#include "api_types/generic/API.hpp" + +template <> +everest::lib::API::V1_0::types::generic::RequestReply +generate(bool set_optional_fields); + +template <> +void verify( + everest::lib::API::V1_0::types::generic::RequestReply original, + everest::lib::API::V1_0::types::generic::RequestReply result); diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/EnumHelper.py b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/EnumHelper.py new file mode 100644 index 0000000000..5c3c692b9f --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/EnumHelper.py @@ -0,0 +1,32 @@ +import re + +from Helper import Helper + + +class EnumHelper(Helper): + w = Helper.regex_whitespaces + regex_enum_field = "(" + w + r"([A-z_0-9]+)(" + w + r")*)" + regex_structure_type = "enum" + w + r"class" + regex_find_in_file = regex_structure_type + w + r"[A-z]*" + w + r"\{((" + regex_enum_field + r",?" + w + r")*)\};" + + @staticmethod + def get_regex_find_in_file(): + return EnumHelper.regex_find_in_file + + def get_regex_structure_type(self): + return self.regex_structure_type + + def get_fields(self): + fields_string = re.search(self.get_regex_find_in_file(), self.representation).group(1) + a = [] + for i in re.finditer(self.regex_enum_field, fields_string): + a.append(i.group(2)) + return a + + def generate_code(self): + enum_fields_test = "" + enum_class_name = self.get_type() + for i in self.get_fields(): + enum_fields_test += " " + enum_class_name + r"::" + i + ",\n" + test = "\nTEST(" + "%s" + r", " + enum_class_name + ") {\n codec_test_all({\n" + enum_fields_test + " });\n}\n" + self.tests_code=[test] diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/FileTestGenerator.py b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/FileTestGenerator.py new file mode 100644 index 0000000000..5a377fc4a0 --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/FileTestGenerator.py @@ -0,0 +1,129 @@ +import re +import warnings + +from EnumHelper import EnumHelper +from Helper import Helper +from StructHelper import StructHelper +from ValueGenerator import ValueGenerator +from Namespace import Namespace + +class FileTestGenerator: + enums_found = False + structs_found = False + files_to_include = [] + def __init__(self, api_file_path, test_folder_path, across_file_struct_generator, include_path, license_header, deny_list = []): + self.license_header = license_header + self.api_file_path = api_file_path + self.test_folder_path = test_folder_path + FileTestGenerator.files_to_include.append("#include \"" + re.sub(self.test_folder_path, "", FileTestGenerator.calculate_file_path(test_folder_path, api_file_path, "hpp")+ "\"")) + FileTestGenerator.files_to_include.append("#include \"" + re.sub(include_path, "", api_file_path) + "\"") + api_file = open(api_file_path).read() + sanitized = Helper.sanitize(api_file) + self.api_file = sanitized + + namespace = Namespace.from_source_file(sanitized) + self.namespace = namespace + + helpers = [] + enums_map = {} + struct_matches = re.finditer(StructHelper.get_regex_find_in_file(), sanitized) + enum_matches = re.finditer(EnumHelper.get_regex_find_in_file(), sanitized) + for x in enum_matches: + enum_helper = EnumHelper(x.group(), namespace) + if not (enum_helper.get_type() in deny_list): + enums_map[enum_helper.get_type()] = enum_helper.get_fields() + helpers.append(enum_helper) + FileTestGenerator.enums_found = True + for x in struct_matches: + sturct_helper = StructHelper(x.group(), across_file_struct_generator, namespace, enums_map) + if not (sturct_helper.get_type() in deny_list): + helpers.append(sturct_helper) + FileTestGenerator.structs_found = True + self.helpers = helpers + self.name = re.search(r"([^/]+)/API.hpp", api_file_path).group(1) + self.code_cpp = "" + self.code_hpp = "" + + def get_name(self): + return self.name + + def get_test_helper_includes(self): + result = "" + for path in FileTestGenerator.files_to_include: + result += path + "\n" + return result + + @staticmethod + def calculate_file_path(test_folder_path, api_file_path, file_ending): + splitpath = re.split("/", api_file_path) + return test_folder_path + splitpath[-2] + "." + file_ending + + def get_file_path(self, file_ending): + return FileTestGenerator.calculate_file_path(self.test_folder_path, self.api_file_path, file_ending) + + def generate_code(self, with_warning = False): + for i in self.helpers: + i.generate_code() + self.generate_code_cpp(with_warning) + self.generate_code_hpp() + + + def generate_code_cpp(self, with_warning = False): + test_code = self.get_code_test() + if test_code[0] != "" and with_warning: + raise NotImplementedError ("The generation of a struct could not be done automatically, it needs to be supplied manually.\n"+ + "The suplying of manual helpers is not fully implemented. The imports need to be added and the manual helpers need to be registered with the accross file generator. \n"+ + "The problematic struct is probably related to: " + test_code[0]) + code = ( + self.license_header + + "#include \n" + + "#include \"everest_api_types/" + self.name + "/codec.hpp\"\n" + + "#include \"SerializationTestHelpers.hpp\"\n\n" + + self.get_test_helper_includes() + + "using namespace everest::lib::API::V1_0::types::" + self.name + ";\n\n" + # needed for across file types + + "using namespace everest::lib::API::V1_0::types;\n\n" + + "//Automatic test helpers\n" + + test_code[1] + "\n" + + "//Tests\n" + + test_code[2] + "\n" + ) + self.code_cpp = code + if with_warning: + if test_code[0].__len__() > 0: + warnings.warn("Not all required methods could be generated automatically, some need to be added manually, or the code generator neeeds to be updated.") + if not FileTestGenerator.enums_found: + raise ValueError("There was not a single enum found in all api files. This is probably wrong.") + if not FileTestGenerator.structs_found: + raise ValueError("There was not a single struct found in all api files. This is probably wrong.") + + + def get_code_cpp(self): + return self.code_cpp + + def get_code_test(self): + code = ("", "", "") + for i in self.helpers: + helpers = i.get_test_helpers_code(self.name) + code = (ValueGenerator.manual_generator.get_manual_helpers(), code[1] + helpers, + code[2] + i.get_tests_code(self.name)) + return code + + + def get_code_header(self): + code = "" + for i in self.helpers: + code += i.get_test_helpers_headers_code() + return code + + def generate_code_hpp(self): + code = ( + self.license_header + + "#pragma once\n" + + "#include \"everest_api_types/" + self.name + "/API.hpp\"\n" + + self.get_code_header() + ) + self.code_hpp = code + + def get_code_hpp(self): + return self.code_hpp diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/Helper.py b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/Helper.py new file mode 100644 index 0000000000..949c361049 --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/Helper.py @@ -0,0 +1,69 @@ +import re +from abc import ABCMeta, abstractmethod + + +class Helper(metaclass=ABCMeta): + regex_whitespaces = "[\n \t]+" + regex_field_or_class_name = "[A-z_0-9]+" + regex_namespace = r"namespace" + regex_whitespaces + "([A-z0-9:]+)" + regex_whitespaces + r"\{" + + def __init__(self, representation, namespace=None): + if namespace is None: + namespace = [""] + self.namespace = namespace + self.representation = representation + self.test_helpers_code = "" + self.test_helpers_headers_code = "" + self.tests_code = ["%s"] + + def get_representation(self): + return self.sanitize(self.representation) + + @abstractmethod + def generate_code(self): + pass + + def get_test_helpers_code(self, name): + return self.test_helpers_code + + def get_test_helpers_headers_code(self): + return self.test_helpers_headers_code + + def get_tests_code(self, name): + tests = "" + for case in self.tests_code: + tests += case % name + return tests + + @staticmethod + def get_regex_find_in_file(): + pass + + @abstractmethod + def get_regex_structure_type(self): + pass + + def get_type(self): + return re.search( + r"%s%s([A-z]*)%s\{" % (self.get_regex_structure_type(), Helper.regex_whitespaces, Helper.regex_whitespaces), + self.get_representation()).group(1) + + @staticmethod + def sanitize(file): + # removes multi line comments + multi_line_comment = re.compile( + r"((/\*)(\*(?!/)|[^\*])*(\*/))") # matches all starting with /* and ending with first */ + multi_removed = re.sub(multi_line_comment, "", file) + # removes single line comments + comments_removed = re.sub(r"//[^\n]*\n", "", multi_removed) + return comments_removed + + @staticmethod + def get_regex_namespace(): + return Helper.regex_namespace + + def get_namespace(self): + return self.namespace + + def get_type_with_namespace(self): + return self.get_namespace().__str__() + self.get_type() diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/Namespace.py b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/Namespace.py new file mode 100644 index 0000000000..aedf31ebc0 --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/Namespace.py @@ -0,0 +1,49 @@ +import re +from Helper import Helper + +class Namespace: + @classmethod + def from_source_file(self, file_contents): + namespace = [] + namespace_matches = re.finditer(Helper.get_regex_namespace(), file_contents) + for x in namespace_matches: + match = x.group(1) + if "::" in match: + subspaces = re.split("::", match) + for space in subspaces: + namespace.append(space) + else: + namespace.append(match) + return Namespace(namespace) + + def __init__(self, namespace_hirearchy): + namespace = [] + namespace= namespace + namespace_hirearchy + self.namespace_hirearchy = namespace + + def __str__(self): + x = "" + for i in self.namespace_hirearchy: + x = x + i + "::" + return x + + def __eq__(self, value: object): + return self.__str__() == value.__str__() + + def __hash__(self): + return self.__str__().__hash__() + + def get_hirearchy(self): + return self.namespace_hirearchy + + ''' + fuction is used to find the namespace hirearchy of a struct that is adressed relatively in a file + e.g. if within the c++ namespace everest::libs::API::V1_0::types::evse_manager a struct is called via + powermeter::PowermeterValues this function returns the namespace hirearchy everest::libs::API::V1_0::types::powermeter + ''' + def get_absolute_hirearchy_of_sub_namespace(self, sub_namespace): + hirearchy = self.get_hirearchy() + sub_hirearchy = sub_namespace.get_hirearchy() + sub_hirearchy_size = sub_hirearchy.__len__() + absolute_hirearchy = hirearchy[:-sub_hirearchy_size] + sub_hirearchy + return Namespace(absolute_hirearchy) diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/README.md b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/README.md new file mode 100644 index 0000000000..7e507a39f2 --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/README.md @@ -0,0 +1,16 @@ +# Api Serialization Test Autogenerator + +This script generates generic tests based on the API.hpp files in the given include directory. + +The tests try to serialize and deserialize the api structs and check wether the result matches the original. + +The test files are automatically generated by cmake and are updated every time the API.hpp files change. + +# disable.csv + +If the test generation for any struct or enum needs to be disabled, it can be listed here with the following scheme: + +/API.hpp, + +Note that this may also affect the testing of dependent structs, if there are any. +To disable structs and enums that are needed for the automatic generation of other structs, there need to be changes made to the AccrossFileGenerator. \ No newline at end of file diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/StructHelper.py b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/StructHelper.py new file mode 100644 index 0000000000..e11502276b --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/StructHelper.py @@ -0,0 +1,127 @@ +import re + +from Helper import Helper +from ValueGenerator import ValueGenerator + + +class StructHelper(Helper): + w = Helper.regex_whitespaces + default_value = r"\{[A-z:_<>0-9\.]+\}?" + regex_single_field = r"([A-z:_<>0-9]+" + w + Helper.regex_field_or_class_name + r"(" + r"\{[A-z:_<>0-9\.]+\}?" + r")?" + r";)" + w + regex_fields = r"(" + w + regex_single_field + r")*" + + def __init__(self, representation, across_file_struct_generator, namespace=None, enum_map=None): + super().__init__(representation, namespace) + self.has_mandatory_fields = self.get_fields_mandatory().__len__() > 0 + self.has_optional_fields = self.get_fields_optional().__len__() > 0 + self.name_no_opt_helper = self.get_type() + "TestHelperNoOptionalFieldsSet" + if enum_map is None: + enum_map = {"test": []} + self.value_generator = ValueGenerator(self.get_type(), self.get_namespace(), enum_map, across_file_struct_generator) + + def get_regex_structure_type(self): + return "struct" + + def get_fields(self): + fields = [] + representation = self.get_representation() + field = self.regex_single_field + matches = re.findall(field, representation) + for x in matches: + sanatized = re.sub(";", "", x[0]) + # structs with default values are tested as if they had no default values + sanatized = re.sub(self.default_value, "", sanatized) + fields.append(sanatized) + return fields + + def get_fields_mandatory(self): + return self.get_fields_helper(True) + + def get_fields_helper(self, mandatory): + a = [] + for x in self.get_fields(): + if ("std::optional" not in x) == mandatory: + split = re.split(Helper.regex_whitespaces, x) + assert split.__len__() == 2 + a.append((split[0], split[1])) + return a + + def get_fields_optional(self): + a = self.get_fields_helper(False) + for i in range(a.__len__()): + san = ValueGenerator.generics_extractor("std::optional", a[i][0]) + a[i] = (san, a[i][1]) + return a + + @staticmethod + def get_regex_find_in_file(): + w = Helper.regex_whitespaces + return r"(struct" + w + r"[A-z]*" + w + r"\{" + StructHelper.regex_fields + r"\};)" + + def get_helper_namespace(self): + return "helper_" + self.get_type() + + def generate_test_helpers(self): + code = self.get_code_helpers() + self.test_helpers_code = code + self.add_struct_to_helper() + + def generate_test_helper_headers(self): + self.test_helpers_headers_code = self.get_code_helpers(True) + + + def get_code_helpers(self, signature_only= False): + name = self.get_helper_namespace() + return self.get_code_generate_function(signature_only) + self.get_code_verify_function(signature_only) + + def get_code_generate_function(self, signature_only = False): + code = "\ntemplate <> " + self.get_type_with_namespace() + " generate<" + self.get_type_with_namespace() + ">(bool set_optional_fields" + if signature_only: return code + ");\n" + token = "generated_object" + code += ") { \n" + self.get_type() + " " + token + ";\n" + self.generate_set_fields(self.get_fields_mandatory(), token) + "if (set_optional_fields) {" + self.generate_set_fields(self.get_fields_optional(), token) + "}\n" + "return " + token + ";\n" + "}\n" + return code + + def get_code_verify_function(self, signature_only = False): + code = "\ntemplate <> void verify<" + self.get_type_with_namespace() + ">(" + self.get_type_with_namespace()+ " original, " + self.get_type_with_namespace() + " result)" + if signature_only: return code + ";\n" + code += "{\n" + self.generate_test_fields(self.get_fields_mandatory(), False) + self.generate_test_fields(self.get_fields_optional(), True) + "}\n" + return code + + + def generate_set_fields(self, fields, token): + code = "" + for i in fields: + code += self.value_generator.generate_corresponding_value(token + "." + i[1], + i[0], i[1], struct_helper=self) + return code + + def generate_test_fields(self, fields, is_optional): + code = "" + for i in fields: + code += self.value_generator.generate_corresponding_field_test(i[1], i[0], self.get_namespace(), is_optional) + return code + + def add_struct_to_helper(self): + self.value_generator.add_struct_helper(self) + + def generate_test(self): + code = [] + type = self.get_type() + type_namespace = self.get_type_with_namespace() + if self.has_mandatory_fields and self.has_optional_fields: + code.append("\nTEST(" + "%s" + ", " + type + "_no_optional_fields_set){\n gen_test<" + type_namespace + ">(" + "false" + ");\n}\n") + code.append("\nTEST(" + "%s" + ", " + type + "_all_optional_fields_set){\n gen_test<" + type_namespace + ">();\n}\n") + self.tests_code = code + + def generate_code(self): + self.value_generator.clear_manual_generation() + self.generate_test_helpers() + self.generate_test() + self.generate_test_helper_headers() + + @staticmethod + def get_value_generation(a, variable_name_prefix = "", variable_name_suffix=""): + return "generate<" + a + ">();\n " + @staticmethod + def get_comparison(a, b, variable_name_prefix = "", variable_name_suffix=""): + return "verify(" + a + ", " + b + ");\n " \ No newline at end of file diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/ValueGenerator.py b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/ValueGenerator.py new file mode 100644 index 0000000000..cf55578a4c --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/ValueGenerator.py @@ -0,0 +1,270 @@ +import math +import random +import re +import string +from Namespace import Namespace + + +class ManualGenerator: + def __init__(self): + self.is_used = False + self.variable_count = 0 + self.tester_count = 0 + self.variables = {} + self.testers = {} + + def increase_tester_name(self): + self.tester_count += 1 + + def increase_variable_name(self): + self.variable_count += 1 + + def get_variable_name(self, type_string): + self.is_used = True + if type_string in self.variables.keys(): + return self.variables[type_string] + self.increase_variable_name() + name = "manual_variable_" + self.variable_count.__str__() + self.variables[type_string] = name + return name + + def get_tester(self, type_string, a, b): + self.is_used = True + if type_string in self.testers.keys(): + return self.testers[type_string] % (a, b) + self.increase_tester_name() + name = "manual_tester" + self.tester_count.__str__() + "(%s, %s)" + self.testers[type_string] = name + return name % (a, b) + + def get_manual_helpers(self): + code = "" + if not self.is_used: + return code + for i in self.variables.keys(): + code += i + " " + self.get_variable_name( + i) + "= null; //Todo define the generation of this variable\n " + + for i in self.testers.keys(): + code += "void " + self.get_tester(i, i + " a", + i + " b") + " {\n//Todo define the comparison of those two objects\n}" + return code + +class AcrossFileStructGenerator: + def __init__(self): + self.helpers = {"" :{}} + self.dependencies_between_helpers = [] + + def add_helper(self, helper): + namespace = helper.get_namespace() + type_string = helper.get_type() + self.generate_if_needed(namespace) + self.helpers[namespace.__str__()][type_string] = helper + + def generate_if_needed(self, namespace): + if namespace.__str__() not in self.helpers.keys(): + self.helpers[namespace.__str__()] = {} + + def get_value_generation(self, type_string, namespace): + helper = self.helpers[namespace.__str__()][type_string] + return helper.get_value_generation() + + def get_helpers(self): + return self.helpers + + def get_helper(self, type_string, namespace): + return self.helpers[namespace.__str__()][type_string] + + def has_helper(self, type_string, namespace): + helpers = self.get_helpers() + if namespace.__str__() not in helpers.keys(): + return False + return type_string in helpers[namespace.__str__()].keys() + + + +def get_vector_type(type_string): + return ValueGenerator.generics_extractor("std::vector", type_string) + + +def get_vector_length(): + return int(7) + + +def get_vector_declaration(vector_type, variable_name_suffix="", assign_value=""): + return "std::vector<" + vector_type + "> " + get_vector_variable_name( + variable_name_suffix) + assign_value + ";\n " + + +def get_vector_variable_name(variable_name_suffix=""): + return "vector%s" % variable_name_suffix + + +class ValueGenerator: + manual_generator = ManualGenerator() + base_types = ["int32_t", "float", "std::string", "bool"] + + def __init__(self, struct_name, struct_namespace, enum_map, across_file_struct_generator=None): + if(across_file_struct_generator is None): + across_file_struct_generator = AcrossFileStructGenerator() + self.across_file_struct_generator = across_file_struct_generator + self.struct_name = struct_name + self.struct_namespace = struct_namespace + self.enum_map = enum_map + + def clear_manual_generation(self): + self.manual_generator.is_used = False + + def generate_corresponding_value(self, target_variable_name, type_string, name_string, preparations="", + highest_vector_field_index_used=0, struct_helper=None): + prefix = target_variable_name + "= " + if highest_vector_field_index_used > 0: + prefix = type_string + " " + prefix + suffix = ";\n " + random.seed(self.struct_name + name_string) + no_prior_preparations = preparations.__len__() <= 0 + if "std::vector<" in type_string: + vector_type = self.namespace_cleanup(get_vector_type(type_string)) + vector_repr = get_vector_declaration(vector_type) + vector_length = get_vector_length() + for i in range(0, vector_length): + field_name = "vector_field_" + i.__str__() + preparations += self.generate_corresponding_value(field_name, vector_type, (name_string + i.__str__()), + preparations="", + highest_vector_field_index_used=(highest_vector_field_index_used + vector_length), struct_helper=struct_helper) + vector_repr += get_vector_variable_name() + ".push_back(" + field_name + ");\n " + if no_prior_preparations: + vector_repr = preparations + vector_repr + return "{" + vector_repr + target_variable_name + "= " + "vector;}\n " + + # if the enum of the field is in the same namespace as the struct but the namespace was specified regardless + # it needs to be properly resolved + namespace_prefix = "" + type_string_cleaned = self.namespace_cleanup(type_string) + + # after this there are only enums and structs which need to be called with their type as a namespace + # or basic types which need no namespace prefix + if namespace_prefix.__len__() <= 0: + namespace_prefix += type_string_cleaned + "::" + + if type_string_cleaned in self.enum_map.keys(): + options = self.enum_map[type_string_cleaned] + return prefix + namespace_prefix + options[random.randint(0, options.__len__() - 1)] + suffix + + if self.across_file_struct_generator.has_helper(type_string_cleaned, self.struct_namespace): + generation = self.across_file_struct_generator.get_helper(type_string_cleaned, self.struct_namespace).get_value_generation(type_string_cleaned) + return self.struct_printout(prefix, generation) + + if self.is_struct_from_different_namespace(type_string_cleaned): + different_namespace, type_in_different_namespace = self.extract_relative_namespace(type_string_cleaned) + if self.across_file_struct_generator.has_helper(type_in_different_namespace, different_namespace): + generation = self.across_file_struct_generator.get_helper(type_in_different_namespace, different_namespace).get_value_generation(type_string_cleaned) + return self.struct_printout(prefix, generation) + + match type_string_cleaned: + case "int32_t": + s = ((2 ** 32) - 1) / 2 + value_string = random.randint(math.floor(-s), math.floor(s)).__str__() + case "float": + value_string = random.random().__str__() + case "std::string": + value_string = "\"" + "".join(random.sample(string.ascii_letters, 30)) + "\"" + case "bool": + value_string = bool(random.getrandbits(1)).__str__().lower() + case _: + # catchall for values that cannot be assigned with the info in this file alone + value_string = ValueGenerator.manual_generator.get_variable_name(type_string_cleaned) + return prefix + value_string + suffix + + def struct_printout(self, prefix, generation): + return prefix + generation + + def is_struct_from_different_namespace(self, type_string): + return "::" in type_string and not "std::" in type_string + + def extract_relative_namespace(self, type_string): + res = type_string.split("::") + n = res[:-1] + sub_namespace = Namespace(n) + different_namespace = self.struct_namespace.get_absolute_hirearchy_of_sub_namespace(sub_namespace) + type_in_different_namespace = res[-1] + return different_namespace,type_in_different_namespace + + def namespace_cleanup(self, type_string): + cleaned = type_string + for i in self.struct_namespace.get_hirearchy(): + pattern = i + "::" + match = re.match(pattern, cleaned) + if match: + cleaned = re.sub(pattern, "", cleaned) + return cleaned + + def generate_corresponding_field_test(self, field_name, field_type, namespace, is_optional): + return self.generate_corresponding_test("original." + field_name, "result." + field_name, + field_type, namespace, is_optional) + + def generate_corresponding_test(self, original_object, result_object, field_type, namespace, is_optional): + is_simple = field_type in self.base_types or field_type in self.enum_map.keys() or self.namespace_cleanup(field_type) in self.enum_map.keys() + if is_simple: + method_signature = "EXPECT_EQ" + if is_optional: + method_signature = "expect_opt_eq" + return method_signature + "(" + original_object + ", " + result_object + ");\n " + optional_wrapper_front = "" + optional_wrapper_rear = "" + if is_optional: + optional_wrapper_front = "EXPECT_EQ(" + original_object + ".has_value(), " + result_object + ".has_value());\nif (" + result_object + ".has_value()) {" + optional_wrapper_rear = "}\n" + wraped = self.generate_corresponding_test_unsafe(original_object, result_object, field_type, namespace, is_optional) + return optional_wrapper_front + wraped + optional_wrapper_rear + + def generate_corresponding_test_unsafe(self, original_object, result_object, field_type, namespace, is_optional): + if "std::vector<" in field_type: + vector_type = self.namespace_cleanup(get_vector_type(field_type)) + assign_a = "= " + original_object + assign_b = "= " + result_object + if is_optional: + assign_a += ".value()" + assign_b += ".value()" + return ( + "{" + + get_vector_declaration(vector_type, "_a", assign_a) + + get_vector_declaration(vector_type, "_b", assign_b) + + "ASSERT_EQ(" + get_vector_variable_name("_a") + ".size(), " + get_vector_variable_name( + "_b") + ".size()) << \"Vectors are of unequal length\";\n" + + "for (long unsigned int i = 0; i < " + get_vector_variable_name("_a") + ".size(); ++i) {\n" + + self.generate_corresponding_test(get_vector_variable_name("_a") + "[i]", + get_vector_variable_name("_b") + "[i]", vector_type, namespace, False) + + "}\n}" + ) + + field_type = self.namespace_cleanup(field_type) + + + + if is_optional: + original_object += ".value()" + result_object += ".value()" + + if self.across_file_struct_generator.has_helper(field_type, namespace): + tester = self.across_file_struct_generator.get_helper(field_type, namespace) + return tester.get_comparison(original_object, result_object) + + if self.is_struct_from_different_namespace(field_type): + different_namespace, type_in_different_namespace = self.extract_relative_namespace(field_type) + return self.generate_corresponding_test(original_object, result_object, type_in_different_namespace, different_namespace, False) + + return self.manual_generator.get_tester(field_type, original_object, result_object) + ";\n" + + @staticmethod + def generics_extractor(generic_call, whole_call): + san = re.sub(generic_call + "<", "", whole_call) + san = san[::-1] + san = re.sub(">", "", san, 1)[::-1] + return san + + def add_struct_helper(self, struct_helper): + self.across_file_struct_generator.add_helper(struct_helper) + + def get_manual_helpers(self): + return ValueGenerator.manual_generator.get_manual_helpers() diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/disable.csv b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/disable.csv new file mode 100644 index 0000000000..cd1712d298 --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/disable.csv @@ -0,0 +1 @@ +generic/API.hpp,RequestReply \ No newline at end of file diff --git a/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/main.py b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/main.py new file mode 100644 index 0000000000..f606201dac --- /dev/null +++ b/lib/everest/everest_api_types/tests/test_file_autogenerator/pythonProject/main.py @@ -0,0 +1,75 @@ +import os +import re +import sys +import csv + +from pathlib import Path +from FileTestGenerator import FileTestGenerator +from ValueGenerator import AcrossFileStructGenerator + +print("Running API Serialisation Test Autogenerator") + +code_path = sys.argv[1] +test_path = sys.argv[2] +skip_path = sys.argv[3] +write_path = sys.argv[4] + +name = "API.hpp" + +across_file_struct_generator = AcrossFileStructGenerator() +generators = [] + +def write_tests(generator): + Path(write_path).mkdir(parents=True, exist_ok=True) + with open(generator.get_file_path("hpp"), 'w') as test_file: + test_file.write(generator.get_code_hpp()) + with open(generator.get_file_path("cpp"), 'w') as test_file: + test_file.write(generator.get_code_cpp()) + + os.system("clang-format -i " + generator.get_file_path("hpp") + " " + generator.get_file_path("cpp")) + + +def get_make_contents(): + result = "target_sources(${TEST_TARGET_NAME} PRIVATE\n" + for generator in generators: + result += " " + generator.get_name()+ ".cpp\n" + result += ")" + return result + +def get_deny_list(): + deny_lists = {} + with open(skip_path, newline='') as csvfile: + deny_lists_reader = csv.reader(csvfile, delimiter=',', quotechar='"') + for row in deny_lists_reader: + deny_lists[row[0]] = row[1:] + return deny_lists + +def get_single_deny_list(deny_lists, file_to_test): + single_deny_list = [] + for key in deny_lists.keys(): + if key in file_to_test: + single_deny_list = deny_lists[key] + return single_deny_list + +deny_lists = get_deny_list() +license_header = "" +api_files_found = False +for root, dirs, files in os.walk(code_path): + if name in files: + file_to_test = os.path.join(root, name) + print("Generating test for: ", file_to_test) + api_files_found = True + generator = FileTestGenerator(file_to_test, write_path, across_file_struct_generator, code_path, license_header, get_single_deny_list(deny_lists, file_to_test)) + generator.generate_code() + generators.append(generator) +if not api_files_found: + raise FileNotFoundError("API files were not found in include directory\nExpected for example: {include}/apit_types/auth/API.hpp\nInclude Path that was given is: " + code_path) + +for generator in generators: + generator.generate_code(with_warning = True) + +for generator in generators: + write_tests(generator) + +with open(write_path + "CMakeLists.txt", 'w') as make_file: + make_file.write(get_make_contents()) diff --git a/modules/API/CMakeLists.txt b/modules/API/CMakeLists.txt index b748432b07..2636a82e8c 100644 --- a/modules/API/CMakeLists.txt +++ b/modules/API/CMakeLists.txt @@ -1,2 +1,3 @@ ev_add_module(API) ev_add_module(EvAPI) +ev_add_module(power_supply_DC_API) diff --git a/modules/API/power_supply_DC_API/CMakeLists.txt b/modules/API/power_supply_DC_API/CMakeLists.txt new file mode 100644 index 0000000000..9fa4408f4c --- /dev/null +++ b/modules/API/power_supply_DC_API/CMakeLists.txt @@ -0,0 +1,39 @@ +# +# AUTO GENERATED - MARKED REGIONS WILL BE KEPT +# template version 3 +# + +# module setup: +# - ${MODULE_NAME}: module name +ev_setup_cpp_module() + + +# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 +# insert your custom targets and additional config variables here + +if(DISABLE_EDM) + find_package(nlohmann_json REQUIRED) +endif() + +# API module +target_compile_options(${MODULE_NAME} + PUBLIC -Wall -Wextra -pedantic -Werror=switch) + +target_link_libraries(${MODULE_NAME} + PRIVATE + atomic + everest::everest_api_types +) + + +# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 + +target_sources(${MODULE_NAME} + PRIVATE + "if_power_supply_DC/power_supply_DCImpl.cpp" +) + +# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1 +# insert other things like install cmds etc here + +# ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1 diff --git a/modules/API/power_supply_DC_API/doc.rst b/modules/API/power_supply_DC_API/doc.rst new file mode 100644 index 0000000000..1300d0ee0d --- /dev/null +++ b/modules/API/power_supply_DC_API/doc.rst @@ -0,0 +1,22 @@ +.. _everest_modules_handwritten_power_supply_DC_API: + +.. This file is a placeholder for an optional single file + handwritten documentation for the power_supply_DC_API module. + Please decide whether you want to use this single file, + or a set of files in the doc/ directory. + In the latter case, you can delete this file. + In the former case, you can delete the doc/ directory. + +.. This handwritten documentation is optional. In case + you do not want to write it, you can delete this file + and the doc/ directory. + +.. The documentation can be written in reStructuredText, + and will be converted to HTML and PDF by Sphinx. + +******************************************* +power_supply_DC_API +******************************************* + +:ref:`Link ` to the module's reference. +API for DC power supllies diff --git a/modules/API/power_supply_DC_API/docs/index.rst b/modules/API/power_supply_DC_API/docs/index.rst new file mode 100644 index 0000000000..59b0893bd4 --- /dev/null +++ b/modules/API/power_supply_DC_API/docs/index.rst @@ -0,0 +1,23 @@ +.. _everest_modules_handwritten_power_supply_DC_API: + +.. This file is a placeholder for optional multiple files + handwritten documentation for the power_supply_DC_API module. + Please decide whether you want to use the doc.rst file + or a set of files in the doc/ directory. + In the latter case, you can delete the doc.rst file. + In the former case, you can delete the doc/ directory. + +.. This handwritten documentation is optional. In case + you do not want to write it, you can delete this file + and the doc/ directory. + +.. The documentation can be written in reStructuredText, + and will be converted to HTML and PDF by Sphinx. + This index.rst file is the entry point for the module documentation. + +******************************************* +power_supply_DC_API +******************************************* + +:ref:`Link ` to the module's reference. +API for DC power supllies diff --git a/modules/API/power_supply_DC_API/if_power_supply_DC/power_supply_DCImpl.cpp b/modules/API/power_supply_DC_API/if_power_supply_DC/power_supply_DCImpl.cpp new file mode 100644 index 0000000000..51432987d8 --- /dev/null +++ b/modules/API/power_supply_DC_API/if_power_supply_DC/power_supply_DCImpl.cpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "power_supply_DCImpl.hpp" +#include "everest_api_types/power_supply_DC/API.hpp" +#include "everest_api_types/power_supply_DC/codec.hpp" +#include "everest_api_types/power_supply_DC/wrapper.hpp" +#include "everest/exceptions.hpp" +#include "everest/logging.hpp" +#include "framework/ModuleAdapter.hpp" +#include "generated/types/power_supply_DC.hpp" +#include "utils/types.hpp" +#include + +namespace module { +namespace if_power_supply_DC { + +namespace ns_types_int = types::power_supply_DC; + +void power_supply_DCImpl::init() { +} + +void power_supply_DCImpl::ready() { +} + +void power_supply_DCImpl::handle_setMode(ns_types_int::Mode& mode, types::power_supply_DC::ChargingPhase& phase) { + auto topic = mod->get_topics().everest_to_extern("mode"); + auto mode_ext = ns_types_ext::toExternalApi(mode); + auto phase_ext = ns_types_ext::toExternalApi(phase); + auto data = ns_types_ext::ModeRequest{mode_ext, phase_ext}; + mod->mqtt.publish(topic, serialize(data)); +} + +void power_supply_DCImpl::handle_setExportVoltageCurrent(double& voltage, double& current) { + auto topic = mod->get_topics().everest_to_extern("export_voltage_current"); + auto data = ns_types_ext::VoltageCurrent{static_cast(voltage), static_cast(current)}; + mod->mqtt.publish(topic, serialize(data)); +} + +void power_supply_DCImpl::handle_setImportVoltageCurrent(double& voltage, double& current) { + auto topic = mod->get_topics().everest_to_extern("import_voltage_current"); + auto data = ns_types_ext::VoltageCurrent{static_cast(voltage), static_cast(current)}; + mod->mqtt.publish(topic, serialize(data)); +} + +} // namespace if_power_supply_DC +} // namespace module diff --git a/modules/API/power_supply_DC_API/if_power_supply_DC/power_supply_DCImpl.hpp b/modules/API/power_supply_DC_API/if_power_supply_DC/power_supply_DCImpl.hpp new file mode 100644 index 0000000000..11b717949b --- /dev/null +++ b/modules/API/power_supply_DC_API/if_power_supply_DC/power_supply_DCImpl.hpp @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#ifndef IF_POWER_SUPPLY_DC_POWER_SUPPLY_DC_IMPL_HPP +#define IF_POWER_SUPPLY_DC_POWER_SUPPLY_DC_IMPL_HPP + +// +// AUTO GENERATED - MARKED REGIONS WILL BE KEPT +// template version 3 +// +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include +#pragma GCC diagnostic pop + +#include "../power_supply_DC_API.hpp" + +// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1 +// insert your custom include headers here +// ev@75ac1216-19eb-4182-a85c-820f1fc2c091:v1 + +namespace module { +namespace if_power_supply_DC { + +struct Conf {}; + +class power_supply_DCImpl : public power_supply_DCImplBase { +public: + power_supply_DCImpl() = delete; + power_supply_DCImpl(Everest::ModuleAdapter* ev, const Everest::PtrContainer& mod, + Conf& config) : + power_supply_DCImplBase(ev, "if_power_supply_DC"), mod(mod), config(config){}; + + // ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1 + // insert your public definitions here + // ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1 + +protected: + // command handler functions (virtual) + virtual void handle_setMode(types::power_supply_DC::Mode& mode, + types::power_supply_DC::ChargingPhase& phase) override; + virtual void handle_setExportVoltageCurrent(double& voltage, double& current) override; + virtual void handle_setImportVoltageCurrent(double& voltage, double& current) override; + + // ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1 + // insert your protected definitions here + // ev@d2d1847a-7b88-41dd-ad07-92785f06f5c4:v1 + +private: + const Everest::PtrContainer& mod; + const Conf& config; + + virtual void init() override; + virtual void ready() override; + + // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 + // insert your private definitions here + // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 +}; + +// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1 +// insert other definitions here +// ev@3d7da0ad-02c2-493d-9920-0bbbd56b9876:v1 + +} // namespace if_power_supply_DC +} // namespace module + +#endif // IF_POWER_SUPPLY_DC_POWER_SUPPLY_DC_IMPL_HPP diff --git a/modules/API/power_supply_DC_API/manifest.yaml b/modules/API/power_supply_DC_API/manifest.yaml new file mode 100644 index 0000000000..18b8b5833d --- /dev/null +++ b/modules/API/power_supply_DC_API/manifest.yaml @@ -0,0 +1,20 @@ +description: API for DC power supllies +config: + cfg_communication_check_to_s: + description: "Maximum time between to two communication check events and to reply to any request. Values <= 0 disables communication checks" + type: integer + default: 5 + cfg_heartbeat_interval_ms: + description: "Interval between two heartbeat messages send by the API. Values <= 0 disable heartbeat" + type: integer + default: 1000 + +provides: + if_power_supply_DC: + interface: power_supply_DC + description: "API for DC power supply modules" +enable_external_mqtt: true +metadata: + license: https://opensource.org/licenses/Apache-2.0 + authors: + - Jan Christoph Habig diff --git a/modules/API/power_supply_DC_API/power_supply_DC_API.cpp b/modules/API/power_supply_DC_API/power_supply_DC_API.cpp new file mode 100644 index 0000000000..176eef001e --- /dev/null +++ b/modules/API/power_supply_DC_API/power_supply_DC_API.cpp @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#include "power_supply_DC_API.hpp" +#include "everest_api_types/generic/codec.hpp" +#include "everest_api_types/generic/string.hpp" +#include "everest_api_types/power_supply_DC/API.hpp" +#include "everest_api_types/power_supply_DC/codec.hpp" +#include "everest_api_types/power_supply_DC/wrapper.hpp" +#include "everest_api_types/utilities/Topics.hpp" +#include "everest/logging.hpp" +#include "utils/error.hpp" +#include + +namespace module { + +namespace generic = everest::lib::API::V1_0::types::generic; +using ns_types_ext::deserialize; + +void power_supply_DC_API::init() { + invoke_init(*p_if_power_supply_DC); + + topics.setTargetApiModuleID(info.id, "power_supply_DC"); + + generate_api_var_mode(); + generate_api_var_voltage_current(); + generate_api_var_capabilities(); + + generate_api_var_raise_error(); + generate_api_var_clear_error(); +} + +void power_supply_DC_API::ready() { + invoke_ready(*p_if_power_supply_DC); + comm_check.start(config.cfg_communication_check_to_s); + generate_api_var_communication_check(); + + setup_heartbeat_generator(); +} + +void power_supply_DC_API::generate_api_var_mode() { + subscribe_api_var("mode", [=](const std::string& data) { + auto ext = deserialize(data); + auto arg = toInternalApi(ext); + p_if_power_supply_DC->publish_mode(arg); + }); +} + +void power_supply_DC_API::generate_api_var_voltage_current() { + subscribe_api_var("voltage_current", [=](const std::string& data) { + auto ext = deserialize(data); + auto arg = toInternalApi(ext); + p_if_power_supply_DC->publish_voltage_current(arg); + }); +} + +void power_supply_DC_API::generate_api_var_capabilities() { + subscribe_api_var("capabilities", [=](const json& data) { + auto ext = deserialize(data); + auto arg = toInternalApi(ext); + p_if_power_supply_DC->publish_capabilities(arg); + }); +} + +void power_supply_DC_API::generate_api_var_raise_error() { + subscribe_api_var("raise_error", [=](const std::string& data) { + auto error = deserialize(data); + auto sub_type_str = error.sub_type ? error.sub_type.value() : ""; + auto message_str = error.message ? error.message.value() : ""; + auto error_str = make_error_string(error); + auto ev_error = p_if_power_supply_DC->error_factory->create_error(error_str, sub_type_str, message_str, + Everest::error::Severity::High); + p_if_power_supply_DC->raise_error(ev_error); + }); +} + +void power_supply_DC_API::generate_api_var_clear_error() { + subscribe_api_var("clear_error", [=](const std::string& data) { + auto error = deserialize(data); + std::string error_str = make_error_string(error); + if (error.sub_type) { + p_if_power_supply_DC->clear_error(error_str, error.sub_type.value()); + } else { + p_if_power_supply_DC->clear_error(error_str); + } + }); +} + +void power_supply_DC_API::generate_api_var_communication_check() { + subscribe_api_var("communication_check", [this](const std::string& data) { + auto val = generic::deserialize(data); + comm_check.set_value(val); + }); +} + +std::string power_supply_DC_API::make_error_string(ns_types_ext::Error const& error) { + auto error_str = generic::trimmed(serialize(error.type)); + auto result = "power_supply_DC/" + error_str; + return result; +} + +void power_supply_DC_API::setup_heartbeat_generator() { + auto topic = topics.everest_to_extern("heartbeat"); + auto action = [this, topic]() { + mqtt.publish(topic, "{}"); + return true; + }; + comm_check.heartbeat(config.cfg_heartbeat_interval_ms, action); +} + +void power_supply_DC_API::subscribe_api_var(const std::string& var, const ParseAndPublishFtor& parse_and_publish) { + auto topic = topics.extern_to_everest(var); + mqtt.subscribe(topic, [=](std::string const& data) { + try { + parse_and_publish(data); + } catch (const std::exception& e) { + EVLOG_warning << "Variable: '" << topic << "' failed with -> " << e.what() << "\n => " << data; + } catch (...) { + EVLOG_warning << "Invalid data: Failed to parse JSON or to get data from it.\n" << topic; + } + }); +} + +const ns_bc::Topics& power_supply_DC_API::get_topics() const { + return topics; +} + +} // namespace module diff --git a/modules/API/power_supply_DC_API/power_supply_DC_API.hpp b/modules/API/power_supply_DC_API/power_supply_DC_API.hpp new file mode 100644 index 0000000000..31ce4acfbd --- /dev/null +++ b/modules/API/power_supply_DC_API/power_supply_DC_API.hpp @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest + +#ifndef POWER_SUPPLY_DC_API_HPP +#define POWER_SUPPLY_DC_API_HPP + +// +// AUTO GENERATED - MARKED REGIONS WILL BE KEPT +// template version 2 +// +#include "ld-ev.hpp" +#include "utils/error.hpp" +#include +// headers for provided interface implementations +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-function" +#include +#pragma GCC diagnostic pop + +// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1 +// insert your custom include headers here +// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1 + +#include "everest_api_types/utilities/CommCheckHandler.hpp" +#include + +namespace module { + +namespace ns_bc = everest::lib::API; +namespace ns_types_ext = everest::lib::API::V1_0::types::power_supply_DC; + +struct Conf { + int cfg_communication_check_to_s; + int cfg_heartbeat_interval_ms; +}; + +class power_supply_DC_API : public Everest::ModuleBase { +public: + power_supply_DC_API() = delete; + power_supply_DC_API(const ModuleInfo& info, Everest::MqttProvider& mqtt_provider, + std::unique_ptr p_if_power_supply_DC, Conf& config) : + ModuleBase(info), + mqtt(mqtt_provider), + p_if_power_supply_DC(std::move(p_if_power_supply_DC)), + config(config), + comm_check("power_supply_DC/CommunicationFault", "Bridge to implementation connection lost", + this->p_if_power_supply_DC){}; + + Everest::MqttProvider& mqtt; + const std::shared_ptr p_if_power_supply_DC; + const Conf& config; + + // ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1 + // insert your public definitions here + const ns_bc::Topics& get_topics() const; + // ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1 + +protected: + // ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1 + // insert your protected definitions here + // ev@4714b2ab-a24f-4b95-ab81-36439e1478de:v1 + +private: + friend class LdEverest; + void init(); + void ready(); + + // ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1 + // insert your private definitions here + using ParseAndPublishFtor = std::function; + void subscribe_api_var(const std::string& var, const ParseAndPublishFtor& parse_and_publish); + void generate_api_var_mode(); + void generate_api_var_voltage_current(); + void generate_api_var_capabilities(); + void generate_api_var_raise_error(); + void generate_api_var_clear_error(); + void generate_api_var_communication_check(); + + std::string make_error_string(ns_types_ext::Error const& error); + + void setup_heartbeat_generator(); + + ns_bc::Topics topics; + ns_bc::CommCheckHandler comm_check; + // ev@211cfdbe-f69a-4cd6-a4ec-f8aaa3d1b6c8:v1 +}; + +// ev@087e516b-124c-48df-94fb-109508c7cda9:v1 +// insert other definitions here +// ev@087e516b-124c-48df-94fb-109508c7cda9:v1 + +} // namespace module + +#endif // POWER_SUPPLY_DC_API_HPP