4#ifndef OCPP_COMMON_TYPES_HPP
5#define OCPP_COMMON_TYPES_HPP
15#include <nlohmann/json_fwd.hpp>
20#include <ocpp/common/cistring.hpp>
21#include <ocpp/common/support_older_cpp_versions.hpp>
22#include <ocpp/v16/ocpp_enums.hpp>
23#include <ocpp/v2/ocpp_enums.hpp>
25using json = nlohmann::json;
40 msg{
"Timepoint string parsing failed. Could not convert: \"" + timepoint_str +
"\" into DateTime."} {
43 const char* what()
const noexcept override {
54 std::chrono::time_point<date::utc_clock> timepoint;
63 explicit DateTimeImpl(std::chrono::time_point<date::utc_clock> timepoint);
77 std::chrono::time_point<date::utc_clock>
to_time_point()
const;
84 operator std::string() {
117 explicit DateTime(std::chrono::time_point<date::utc_clock> timepoint);
120 explicit DateTime(
const std::string& timepoint_str);
126 using std::out_of_range::out_of_range;
135 template <
typename T>
138 std::to_string(static_cast<int>(enumValue)) +
"' to " + type.data()} {
155enum SessionStartedReason {
159namespace conversions {
162std::string session_started_reason_to_string(SessionStartedReason e);
166SessionStartedReason string_to_session_started_reason(
const std::string& s);
171std::ostream& operator<<(std::ostream& os,
const SessionStartedReason& session_started_reason);
174 std::optional<float>
DC;
175 std::optional<float>
L1;
176 std::optional<float>
L2;
177 std::optional<float>
L3;
178 std::optional<float>
N;
191 std::optional<float>
DC;
192 std::optional<float>
L1;
193 std::optional<float>
L2;
194 std::optional<float>
L3;
208 std::optional<float>
L2;
209 std::optional<float>
L3;
223 std::optional<float>
L1;
224 std::optional<float>
L2;
225 std::optional<float>
L3;
239 std::optional<float>
L1;
240 std::optional<float>
L2;
241 std::optional<float>
L3;
279 std::optional<ReactivePower>
VAR;
336 friend std::ostream&
operator<<(std::ostream& os,
const RPM& k);
358 std::optional<std::string> language;
359 std::optional<v2::MessageFormatEnum> message_format;
368enum class IdentifierType {
375 std::optional<int32_t> id;
376 std::optional<v2::MessagePriorityEnum> priority;
377 std::optional<v2::MessageStateEnum> state;
378 std::optional<DateTime> timestamp_from;
379 std::optional<DateTime> timestamp_to;
380 std::optional<std::string> identifier_id;
381 std::optional<IdentifierType> identifier_type;
383 std::optional<std::string> qr_code;
387 std::optional<double> kWh_price;
388 std::optional<double> hour_price;
389 std::optional<double> flat_fee;
396 std::optional<uint32_t> idle_grace_minutes;
397 std::optional<double> idle_hour_price;
403enum class RunningCostState {
409namespace conversions {
410RunningCostState string_to_running_cost_state(
const std::string& state);
411std::string running_cost_state_to_string(
const RunningCostState& state);
415 std::string transaction_id;
416 std::optional<DateTime> timestamp;
417 std::optional<uint32_t> meter_value;
420 RunningCostState state;
421 std::optional<RunningCostChargingPrice> charging_price;
422 std::optional<RunningCostIdlePrice> idle_price;
423 std::optional<DateTime> next_period_at_time;
424 std::optional<RunningCostChargingPrice> next_period_charging_price;
425 std::optional<RunningCostIdlePrice> next_period_idle_price;
426 std::optional<std::vector<DisplayMessageContent>> cost_messages;
427 std::optional<std::string> qr_code_text;
429 friend void from_json(
const json& j,
RunningCost& c);
433 std::optional<DateTime> at_time;
434 std::optional<int> at_energy_kwh;
435 std::optional<int> at_power_kw;
436 std::vector<v16::ChargePointStatus> at_chargepoint_status;
441enum class CaCertificateType {
448namespace conversions {
451std::string ca_certificate_type_to_string(CaCertificateType e);
455CaCertificateType string_to_ca_certificate_type(
const std::string& s);
462std::ostream& operator<<(std::ostream& os,
const CaCertificateType& ca_certificate_type);
464enum class CertificateValidationResult {
469 InvalidLeafSignature,
474namespace conversions {
477std::string certificate_validation_result_to_string(CertificateValidationResult e);
481CertificateValidationResult string_to_certificate_validation_result(
const std::string& s);
487std::ostream& operator<<(std::ostream& os,
const CertificateValidationResult& certificate_validation_result);
489enum class InstallCertificateResult {
491 InvalidCertificateChain,
494 NoRootCertificateInstalled,
496 CertificateStoreMaxLengthExceeded,
501namespace conversions {
504std::string install_certificate_result_to_string(InstallCertificateResult e);
508InstallCertificateResult string_to_install_certificate_result(
const std::string& s);
514std::ostream& operator<<(std::ostream& os,
const InstallCertificateResult& install_certificate_result);
516enum class DeleteCertificateResult {
522namespace conversions {
525std::string delete_certificate_result_to_string(DeleteCertificateResult e);
529DeleteCertificateResult string_to_delete_certificate_result(
const std::string& s);
535std::ostream& operator<<(std::ostream& os,
const DeleteCertificateResult& delete_certificate_result);
538enum class HashAlgorithmEnumType {
544namespace conversions {
547std::string hash_algorithm_enum_type_to_string(HashAlgorithmEnumType e);
551HashAlgorithmEnumType string_to_hash_algorithm_enum_type(
const std::string& s);
556std::ostream& operator<<(std::ostream& os,
const HashAlgorithmEnumType& hash_algorithm_enum_type);
559 HashAlgorithmEnumType hashAlgorithm;
574enum class CertificateType {
582namespace conversions {
585std::string certificate_type_to_string(CertificateType e);
589CertificateType string_to_certificate_type(
const std::string& s);
594std::ostream& operator<<(std::ostream& os,
const CertificateType& ceritficate_type);
598 CertificateType certificateType;
599 std::optional<std::vector<CertificateHashDataType>> childCertificateHashData;
611enum class OcppProtocolVersion {
618namespace conversions {
621std::string ocpp_protocol_version_to_string(OcppProtocolVersion e);
625OcppProtocolVersion string_to_ocpp_protocol_version(
const std::string& s);
631std::ostream& operator<<(std::ostream& os,
const OcppProtocolVersion& ocpp_protocol_version);
633enum class CertificateSigningUseEnum {
634 ChargingStationCertificate,
636 ManufacturerCertificate
639namespace conversions {
642std::string certificate_signing_use_enum_to_string(CertificateSigningUseEnum e);
646CertificateSigningUseEnum string_to_certificate_signing_use_enum(
const std::string& s);
651std::ostream& operator<<(std::ostream& os,
const CertificateSigningUseEnum& certificate_signing_use_enum);
655 HashAlgorithmEnumType hashAlgorithm;
656 std::string issuerNameHash;
657 std::string issuerKeyHash;
658 std::string serialNumber;
659 std::string responderUrl;
662enum class GetCertificateSignRequestStatus {
664 InvalidRequestedType,
669enum class GetCertificateInfoStatus {
678 GetCertificateSignRequestStatus status;
679 std::optional<std::string> csr;
684 std::optional<fs::path> ocsp_path;
688 std::optional<fs::path> certificate_path;
689 std::optional<fs::path> certificate_single_path;
690 int certificate_count;
692 std::optional<std::string> password;
693 std::vector<CertificateOCSP> ocsp;
697 GetCertificateInfoStatus status;
698 std::optional<CertificateInfo> info;
701enum class LeafCertificateType {
708namespace conversions {
711std::string bool_to_string(
bool b);
715bool string_to_bool(
const std::string& s);
719std::string double_to_string(
double d,
int precision);
723std::string double_to_string(
double d);
726enum class FirmwareStatusNotification {
738 InstallVerificationFailed,
743namespace conversions {
745std::string generate_certificate_signing_request_status_to_string(
const GetCertificateSignRequestStatus status);
748namespace conversions {
751v16::FirmwareStatus firmware_status_notification_to_firmware_status(
const FirmwareStatusNotification status);
754v16::FirmwareStatusEnumType
755firmware_status_notification_to_firmware_status_enum_type(
const FirmwareStatusNotification status);
761enum SecurityProfile {
763 OCPP_1_6_ONLY_UNSECURED_TRANSPORT_WITHOUT_BASIC_AUTHENTICATION = 0,
764 UNSECURED_TRANSPORT_WITH_BASIC_AUTHENTICATION = 1,
765 TLS_WITH_BASIC_AUTHENTICATION = 2,
766 TLS_WITH_CLIENT_SIDE_CERTIFICATES = 3,
770namespace security_events {
778inline const std::string FIRMWARE_UPDATED =
"FirmwareUpdated";
779inline const std::string FAILEDTOAUTHENTICATEATCSMS =
"FailedToAuthenticateAtCsms";
780inline const std::string CSMSFAILEDTOAUTHENTICATE =
"CsmsFailedToAuthenticate";
781inline const std::string CSRGENERATIONFAILED =
"CSRGenerationFailed";
782inline const std::string SETTINGSYSTEMTIME =
"SettingSystemTime";
783inline const std::string RESET_OR_REBOOT =
"ResetOrReboot";
784inline const std::string STARTUP_OF_THE_DEVICE =
"StartupOfTheDevice";
785inline const std::string SECURITYLOGWASCLEARED =
"SecurityLogWasCleared";
786inline const std::string RECONFIGURATIONOFSECURITYPARAMETERS =
"ReconfigurationOfSecurityParameters";
787inline const std::string MEMORYEXHAUSTION =
"MemoryExhaustion";
788inline const std::string INVALIDMESSAGES =
"InvalidMessages";
789inline const std::string ATTEMPTEDREPLAYATTACKS =
"AttemptedReplayAttacks";
790inline const std::string TAMPERDETECTIONACTIVATED =
"TamperDetectionActivated";
791inline const std::string INVALIDFIRMWARESIGNATURE =
"InvalidFirmwareSignature";
792inline const std::string INVALIDFIRMWARESIGNINGCERTIFICATE =
"InvalidFirmwareSigningCertificate";
793inline const std::string INVALIDCSMSCERTIFICATE =
"InvalidCsmsCertificate";
794inline const std::string INVALIDCENTRALSYSTEMCERTIFICATE =
"InvalidCentralSystemCertificate";
795inline const std::string INVALIDCHARGINGSTATIONCERTIFICATE =
"InvalidChargingStationCertificate";
796inline const std::string INVALIDCHARGEPOINTCERTIFICATE =
"InvalidChargePointCertificate";
797inline const std::string INVALIDTLSVERSION =
"InvalidTLSVersion";
798inline const std::string INVALIDTLSCIPHERSUITE =
"InvalidTLSCipherSuite";
799inline const std::string MAINTENANCELOGINACCEPTED =
"MaintenanceLoginAccepted";
800inline const std::string MAINTENANCELOGINFAILED =
"MaintenanceLoginFailed";
803enum class MessageDirection {
804 CSMSToChargingStation,
805 ChargingStationToCSMS
808enum class ConnectionFailedReason {
809 InvalidCSMSCertificate = 0,
810 FailedToAuthenticateAtCsms
816enum class WebsocketCloseReason : uint8_t {
826enum class QueueType {
836 int32_t number_phases;
840enum class ReservationCheckStatus {
843 ReservedForOtherToken,
845 ReservedForOtherTokenAndHasParentToken,
Contains a DateTime implementation that can parse and create RFC 3339 compatible strings.
Definition: types.hpp:52
friend bool operator<(const DateTimeImpl &lhs, const DateTimeImpl &rhs)
Comparison operator< between two DateTimeImpl lhs and rhs.
Definition: types.cpp:74
std::chrono::time_point< date::utc_clock > to_time_point() const
Converts this DateTimeImpl to a std::chrono::time_point.
Definition: types.cpp:52
friend bool operator<=(const DateTimeImpl &lhs, const DateTimeImpl &rhs)
Comparison operator<= between two DateTimeImpl lhs and rhs.
Definition: types.cpp:78
void from_rfc3339(const std::string &timepoint_str)
Sets the timepoint of this DateTimeImpl to the given timepoint_str.
Definition: types.cpp:34
friend bool operator==(const DateTimeImpl &lhs, const DateTimeImpl &rhs)
Comparison operator== between two DateTimeImpl lhs and rhs.
Definition: types.cpp:82
friend bool operator>=(const DateTimeImpl &lhs, const DateTimeImpl &rhs)
Comparison operator>= between two DateTimeImpl lhs and rhs.
Definition: types.cpp:70
std::string to_rfc3339() const
Converts this DateTimeImpl to a RFC 3339 compatible string.
Definition: types.cpp:30
DateTimeImpl()
Creates a new DateTimeImpl object with the current utc time.
Definition: types.cpp:19
friend std::ostream & operator<<(std::ostream &os, const DateTimeImpl &dt)
Writes the given DateTimeImpl dt to the given output stream os as a RFC 3339 compatible string.
Definition: types.cpp:61
DateTimeImpl & operator=(const DateTimeImpl &dt)
Assignment operator= to assign another DateTimeImpl dt to this DateTimeImpl.
Definition: types.cpp:56
friend bool operator>(const DateTimeImpl &lhs, const DateTimeImpl &rhs)
Comparison operator> between two DateTimeImpl lhs and rhs.
Definition: types.cpp:66
Contains a DateTime implementation that can parse and create RFC 3339 compatible strings.
Definition: types.hpp:109
DateTime()
Creates a new DateTime object with the current system time.
Definition: types.cpp:10
Base exception for when a conversion from string to enum or vice versa fails.
Definition: types.hpp:124
Exception used when conversion from enum to string fails.
Definition: types.hpp:130
EnumToStringException(T enumValue, std::string_view type)
Creates a new StringToEnumException.
Definition: types.hpp:136
Exception used when conversion from string to enum fails.
Definition: types.hpp:143
StringToEnumException(std::string_view str, std::string_view type)
Creates a new StringToEnumException.
Definition: types.hpp:148
Exception used when DateTime class is initialized by invalid timepoint string.
Definition: types.hpp:37
Definition: types.hpp:596
Definition: types.hpp:558
Definition: types.hpp:687
Definition: types.hpp:682
Struct containing default limits for amps, watts and number of phases.
Definition: types.hpp:833
Definition: types.hpp:173
std::optional< float > N
AC Neutral value only.
Definition: types.hpp:178
friend std::ostream & operator<<(std::ostream &os, const Current &k)
Definition: types.cpp:189
std::optional< float > DC
DC current.
Definition: types.hpp:174
std::optional< float > L3
AC L3 value only.
Definition: types.hpp:177
friend void from_json(const json &j, Current &k)
Conversion from a given json object j to a given Current k.
Definition: types.cpp:168
friend void to_json(json &j, const Current &k)
Conversion from a given Current k to a given json object j.
Definition: types.cpp:147
std::optional< float > L2
AC L2 value only.
Definition: types.hpp:176
std::optional< float > L1
AC L1 value only.
Definition: types.hpp:175
Definition: types.hpp:356
Definition: types.hpp:374
Definition: types.hpp:237
friend void to_json(json &j, const Energy &k)
Conversion from a given Energy k to a given json object j.
Definition: types.cpp:305
std::optional< float > L3
AC L3 value only.
Definition: types.hpp:241
float total
DC / AC Sum value (which is relevant for billing)
Definition: types.hpp:238
friend void from_json(const json &j, Energy &k)
Conversion from a given json object j to a given Energy k.
Definition: types.cpp:322
friend std::ostream & operator<<(std::ostream &os, const Energy &k)
Definition: types.cpp:338
std::optional< float > L1
AC L1 value only.
Definition: types.hpp:239
std::optional< float > L2
AC L2 value only.
Definition: types.hpp:240
Definition: types.hpp:206
float L1
AC L1 value.
Definition: types.hpp:207
std::optional< float > L2
AC L2 value.
Definition: types.hpp:208
friend void to_json(json &j, const Frequency &k)
Conversion from a given Frequency k to a given json object j.
Definition: types.cpp:235
std::optional< float > L3
AC L3 value.
Definition: types.hpp:209
friend std::ostream & operator<<(std::ostream &os, const Frequency &k)
Definition: types.cpp:262
friend void from_json(const json &j, Frequency &k)
Conversion from a given json object j to a given Frequency k.
Definition: types.cpp:249
Definition: types.hpp:696
Definition: types.hpp:677
Definition: types.hpp:339
Powermeter power_meter
Powermeter data.
Definition: types.hpp:340
friend void from_json(const json &j, Measurement &k)
Conversion from a given json object j to a given Measurement k.
Definition: types.cpp:540
std::optional< RPM > rpm
RPM.
Definition: types.hpp:343
friend std::ostream & operator<<(std::ostream &os, const Measurement &k)
Definition: types.cpp:551
std::vector< Temperature > temperature_C
Temperature in degree Celsius.
Definition: types.hpp:342
std::optional< StateOfCharge > soc_Percent
State of Charge in percent.
Definition: types.hpp:341
friend void to_json(json &j, const Measurement &k)
Conversion from a given Measurement k to a given json object j.
Definition: types.cpp:529
Parent structure for all OCPP messages supported by this implementation.
Definition: types.hpp:30
virtual std::string get_type() const =0
Provides the type of the message.
Struct for OCSPRequestData.
Definition: types.hpp:654
Definition: types.hpp:221
friend std::ostream & operator<<(std::ostream &os, const Power &k)
Definition: types.cpp:300
friend void from_json(const json &j, Power &k)
Conversion from a given json object j to a given Power k.
Definition: types.cpp:284
float total
DC / AC Sum value.
Definition: types.hpp:222
friend void to_json(json &j, const Power &k)
Conversion from a given Power k to a given json object j.
Definition: types.cpp:267
std::optional< float > L2
AC L2 value only.
Definition: types.hpp:224
std::optional< float > L1
AC L1 value only.
Definition: types.hpp:223
std::optional< float > L3
AC L3 value only.
Definition: types.hpp:225
Definition: types.hpp:270
std::optional< Frequency > frequency_Hz
Grid frequency in Hertz.
Definition: types.hpp:281
std::optional< bool > phase_seq_error
AC only: true for 3 phase rotation error (ccw)
Definition: types.hpp:274
std::optional< ReactivePower > VAR
Reactive power VAR.
Definition: types.hpp:279
friend std::ostream & operator<<(std::ostream &os, const Powermeter &k)
Definition: types.cpp:446
std::optional< Energy > energy_Wh_export
Exported energy in Wh (to grid)
Definition: types.hpp:275
std::optional< Voltage > voltage_V
Voltage in Volts.
Definition: types.hpp:278
std::optional< Current > current_A
Current in ampere.
Definition: types.hpp:280
std::string timestamp
Timestamp of measurement.
Definition: types.hpp:271
std::optional< std::string > meter_id
A (user defined) meter if (e.g. id printed on the case)
Definition: types.hpp:273
friend void to_json(json &j, const Powermeter &k)
Conversion from a given Powermeter k to a given json object j.
Definition: types.cpp:381
Energy energy_Wh_import
Imported energy in Wh (from grid)
Definition: types.hpp:272
std::optional< Power > power_W
Instantaneous power in Watt. Negative values are exported, positive values imported Energy.
Definition: types.hpp:277
friend void from_json(const json &j, Powermeter &k)
Conversion from a given json object j to a given Powermeter k.
Definition: types.cpp:414
Definition: types.hpp:324
friend std::ostream & operator<<(std::ostream &os, const RPM &k)
Definition: types.cpp:524
friend void to_json(json &j, const RPM &k)
Conversion from a given RPM k to a given json object j.
Definition: types.cpp:503
std::optional< std::string > location
Location of the RPM measurement.
Definition: types.hpp:326
float value
RPM.
Definition: types.hpp:325
friend void from_json(const json &j, RPM &k)
Conversion from a given json object j to a given RPM k.
Definition: types.cpp:514
Definition: types.hpp:253
std::optional< float > VARphA
VAR phase A.
Definition: types.hpp:255
float total
VAR total.
Definition: types.hpp:254
friend void from_json(const json &j, ReactivePower &k)
Conversion from a given json object j to a given ReactivePower k.
Definition: types.cpp:360
std::optional< float > VARphB
VAR phase B.
Definition: types.hpp:256
friend std::ostream & operator<<(std::ostream &os, const ReactivePower &k)
Definition: types.cpp:376
std::optional< float > VARphC
VAR phase C.
Definition: types.hpp:257
friend void to_json(json &j, const ReactivePower &k)
Conversion from a given ReactivePower k to a given json object j.
Definition: types.cpp:343
Definition: types.hpp:386
Definition: types.hpp:395
Definition: types.hpp:414
Definition: types.hpp:294
std::optional< std::string > location
Location of the State of Charge measurement.
Definition: types.hpp:296
friend void to_json(json &j, const StateOfCharge &k)
Conversion from a given StateOfCharge k to a given json object j.
Definition: types.cpp:477
friend void from_json(const json &j, StateOfCharge &k)
Conversion from a given json object j to a given StateOfCharge k.
Definition: types.cpp:488
friend std::ostream & operator<<(std::ostream &os, const StateOfCharge &k)
Definition: types.cpp:498
float value
State of Charge in percent.
Definition: types.hpp:295
Definition: types.hpp:309
std::optional< std::string > location
Location of the Temperature measurement.
Definition: types.hpp:311
friend std::ostream & operator<<(std::ostream &os, const Temperature &k)
Definition: types.cpp:472
friend void from_json(const json &j, Temperature &k)
Conversion from a given json object j to a given Temperature k.
Definition: types.cpp:462
float value
Temperature in degree Celsius.
Definition: types.hpp:310
friend void to_json(json &j, const Temperature &k)
Conversion from a given Temperature k to a given json object j.
Definition: types.cpp:451
Definition: types.hpp:432
Definition: types.hpp:190
std::optional< float > L2
AC L2 value only.
Definition: types.hpp:193
friend std::ostream & operator<<(std::ostream &os, const Voltage &k)
Definition: types.cpp:230
friend void to_json(json &j, const Voltage &k)
Conversion from a given Voltage k to a given json object j.
Definition: types.cpp:194
friend void from_json(const json &j, Voltage &k)
Conversion from a given json object j to a given Voltage k.
Definition: types.cpp:212
std::optional< float > L3
AC L3 value only.
Definition: types.hpp:194
std::optional< float > L1
AC L1 value only.
Definition: types.hpp:192
std::optional< float > DC
DC voltage.
Definition: types.hpp:191