3#ifndef OCPP_COMMON_CALL_TYPES_HPP
4#define OCPP_COMMON_CALL_TYPES_HPP
7#include <nlohmann/json_fwd.hpp>
16#include <ocpp/common/cistring.hpp>
18using json = nlohmann::json;
23const auto MESSAGE_TYPE_ID = 0;
24const auto MESSAGE_ID = 1;
25const auto CALL_ACTION = 2;
26const auto CALL_PAYLOAD = 3;
27const auto CALLRESULT_PAYLOAD = 2;
28const auto CALLERROR_ERROR_CODE = 2;
29const auto CALLERROR_ERROR_DESCRIPTION = 3;
30const auto CALLERROR_ERROR_DETAILS = 4;
45void from_json(
const json& j,
MessageId& k);
48enum class MessageTypeId {
57MessageId create_message_id();
60template <
class T>
struct Call {
71 this->uniqueId = create_message_id();
77 this->uniqueId = uniqueId;
83 j.push_back(MessageTypeId::CALL);
84 j.push_back(c.uniqueId.
get());
85 j.push_back(c.msg.get_type());
86 j.push_back(json(c.msg));
92 c.msg = j.at(CALL_PAYLOAD);
93 c.uniqueId.
set(j.at(MESSAGE_ID));
99 os << json(c).dump(4);
116 this->uniqueId = uniqueId;
122 j.push_back(MessageTypeId::CALLRESULT);
123 j.push_back(c.uniqueId.
get());
124 j.push_back(json(c.msg));
130 c.msg = j.at(CALLRESULT_PAYLOAD);
131 c.uniqueId.
set(j.at(MESSAGE_ID));
137 os << json(c).dump(4);
145 std::string errorCode;
146 std::string errorDescription;
154 CallError(
const MessageId& uniqueId,
const std::string& errorCode,
const std::string& errorDescription,
155 const json& errorDetails);
159void to_json(json& j,
const CallError& c);
162void from_json(
const json& j,
CallError& c);
166std::ostream& operator<<(std::ostream& os,
const CallError& c);
Contains a CaseInsensitive string implementation that only allows printable ASCII characters.
Definition: cistring.hpp:16
CiString()
Creates a string.
Definition: cistring.hpp:30
Contains a MessageId implementation based on a case insensitive string with a maximum length of 36 pr...
Definition: call_types.hpp:34
void set(const std::string &data, StringTooLarge to_large=StringTooLarge::Throw)
Sets the content of the string to the given data.
Definition: string.hpp:49
std::string get() const
Provides a std::string representation of the string.
Definition: string.hpp:44
Contains a OCPP CallError message.
Definition: call_types.hpp:143
CallError()
Creates a new CallError message object.
Definition: types.cpp:86
Contains a OCPP CallResult message.
Definition: call_types.hpp:105
friend void to_json(json &j, const CallResult &c)
Conversion from a given CallResult message c to a given json object j.
Definition: call_types.hpp:120
CallResult()
Creates a new CallResult message object.
Definition: call_types.hpp:110
friend std::ostream & operator<<(std::ostream &os, const CallResult &c)
Writes the given case CallResult c to the given output stream os.
Definition: call_types.hpp:136
friend void from_json(const json &j, CallResult &c)
Conversion from a given json object j to a given CallResult message c.
Definition: call_types.hpp:128
CallResult(T msg, MessageId uniqueId)
Creates a new CallResult message object with the given OCPP message msg and uniqueID.
Definition: call_types.hpp:114
Contains a OCPP Call message.
Definition: call_types.hpp:60
friend std::ostream & operator<<(std::ostream &os, const Call &c)
Writes the given case Call c to the given output stream os.
Definition: call_types.hpp:98
friend void to_json(json &j, const Call &c)
Conversion from a given Call message c to a given json object j.
Definition: call_types.hpp:81
Call(T msg)
Creates a new Call message object with the given OCPP message msg.
Definition: call_types.hpp:69
Call()
Creates a new Call message object.
Definition: call_types.hpp:65
Call(T msg, MessageId uniqueId)
Creates a new Call message object with the given OCPP message msg and uniqueId.
Definition: call_types.hpp:75
friend void from_json(const json &j, Call &c)
Conversion from a given json object j to a given Call message c.
Definition: call_types.hpp:90