forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOcppOperation.h
More file actions
139 lines (106 loc) · 4.76 KB
/
Copy pathOcppOperation.h
File metadata and controls
139 lines (106 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2022
// MIT License
#ifndef OCPPOPERATION_H
#define OCPPOPERATION_H
#define MESSAGE_TYPE_CALL 2
#define MESSAGE_TYPE_CALLRESULT 3
#define MESSAGE_TYPE_CALLERROR 4
#include <memory>
#include <ArduinoOcpp/Core/OcppOperationCallbacks.h>
#include <Variants.h>
namespace ArduinoOcpp {
class OcppMessage;
class OcppModel;
class OcppSocket;
class OcppOperation {
private:
String messageID{'\0'};
std::unique_ptr<OcppMessage> ocppMessage;
const String *getMessageID();
void setMessageID(const String &id);
OnReceiveConfListener onReceiveConfListener = [] (JsonObject payload) {};
OnReceiveReqListener onReceiveReqListener = [] (JsonObject payload) {};
OnSendConfListener onSendConfListener = [] (JsonObject payload) {};
OnTimeoutListener onTimeoutListener = [] () {};
OnReceiveErrorListener onReceiveErrorListener = [] (const char *code, const char *description, JsonObject details) {};
OnAbortListener onAbortListener = [] () {};
boolean reqExecuted = false;
std::unique_ptr<Timeout> timeout{new OfflineSensitiveTimeout(40000)};
const ulong RETRY_INTERVAL = 3000; //in ms; first retry after ... ms; second retry after 2 * ... ms; third after 4 ...
const ulong RETRY_INTERVAL_MAX = 20000; //in ms;
ulong retry_start = 0;
ulong retry_interval_mult = 1; // RETRY_INTERVAL * retry_interval_mult gives longer periods with each iteration
#if DEBUG_OUT
uint16_t printReqCounter = 0;
#endif
public:
OcppOperation(std::unique_ptr<OcppMessage> msg);
OcppOperation();
~OcppOperation();
void setOcppMessage(std::unique_ptr<OcppMessage> msg);
void setOcppModel(std::shared_ptr<OcppModel> oModel);
void setTimeout(std::unique_ptr<Timeout> timeout);
Timeout *getTimeout();
/**
* Sends the message(s) that belong to the OCPP Operation. This function puts a JSON message on the lower protocol layer.
*
* For instance operation Authorize: sends Authorize.req(idTag)
*
* This function is usually called multiple times by the Arduino loop(). On first call, the request is initially sent. In the
* succeeding calls, the implementers decide to either resend the request, or do nothing as the operation is still pending. When
* the operation is completed (for example when conf() has been called), return true. When the operation is still pending, return
* false.
*/
boolean sendReq(OcppSocket& ocppSocket);
/**
* Decides if message belongs to this operation instance and if yes, proccesses it. For example, multiple instances of an
* operation type can run in the case of Metering Data being sent.
*
* Returns true if JSON object has been consumed, false otherwise.
*/
boolean receiveConf(JsonDocument& json);
/**
* Decides if message belongs to this operation instance and if yes, notifies the OcppMessage object about the CallError.
*
* Returns true if JSON object has been consumed, false otherwise.
*/
boolean receiveError(JsonDocument& json);
/**
* Processes the request in the JSON document. Returns true on success, false on error.
*
* Returns false if the request doesn't belong to the corresponding operation instance
*/
boolean receiveReq(JsonDocument& json);
/**
* After processing a request sent by the communication counterpart, this function sends a confirmation
* message. Returns true on success, false otherwise. Returns also true if a CallError has successfully
* been sent
*/
boolean sendConf(OcppSocket& ocppSocket);
void setInitiated();
void setOnReceiveConfListener(OnReceiveConfListener onReceiveConf);
/**
* Sets a Listener that is called after this machine processed a request by the communication counterpart
*/
void setOnReceiveReqListener(OnReceiveReqListener onReceiveReq);
void setOnSendConfListener(OnSendConfListener onSendConf);
void setOnTimeoutListener(OnTimeoutListener onTimeout);
void setOnReceiveErrorListener(OnReceiveErrorListener onReceiveError);
/**
* The listener onAbort will be called whenever the engine stops trying to execute an operation normally which were initiated
* on this device. This includes timeouts or if the ocpp counterpart sends an error (then it will be called in addition to
* onTimeout or onReceiveError, respectively). Causes for onAbort:
*
* - Cannot create OCPP payload
* - Timeout
* - Receives error msg instead of confirmation msg
*
* The engine uses this listener in both modes: EVSE mode and Central system mode
*/
void setOnAbortListener(OnAbortListener onAbort);
boolean isFullyConfigured();
void print_debug();
};
} //end namespace ArduinoOcpp
#endif