forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperation.h
More file actions
77 lines (58 loc) · 2.58 KB
/
Copy pathOperation.h
File metadata and controls
77 lines (58 loc) · 2.58 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
/**
* This framework considers OCPP operations to be a combination of two things: first, ensure that the message reaches its
* destination properly (the "Remote procedure call" header, e.g. message Id). Second, transmit the application data
* as specified in the OCPP 1.6 document.
*
* The remote procedure call (RPC) part is implemented by the class Request. The application data part is implemented by
* the respective Operation subclasses, e.g. BootNotification, StartTransaction, ect.
*
* The resulting structure is that the RPC header (=instance of Request) holds a reference to the payload
* message creator (=instance of BootNotification, StartTransaction, ...). Both objects working together give the complete
* OCPP operation.
*/
#ifndef MO_OPERATION_H
#define MO_OPERATION_H
#include <ArduinoJson.h>
#include <memory>
#include <MicroOcpp/Core/RequestStore.h>
namespace MicroOcpp {
std::unique_ptr<DynamicJsonDocument> createEmptyDocument();
class Operation {
public:
Operation();
virtual ~Operation();
virtual const char* getOperationType();
virtual void initiate(StoredOperationHandler *rpcData);
virtual bool restore(StoredOperationHandler *rpcData);
/**
* Create the payload for the respective OCPP message
*
* For instance operation Authorize: creates 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 recreate the request, or do nothing as the operation is still pending.
*/
virtual std::unique_ptr<DynamicJsonDocument> createReq();
virtual void processConf(JsonObject payload);
/*
* returns if the operation must be aborted
*/
virtual bool processErr(const char *code, const char *description, JsonObject details) { return true;}
/**
* Processes the request in the JSON document.
*/
virtual void processReq(JsonObject payload);
/**
* After successfully processing a request sent by the communication counterpart, this function creates the payload for a confirmation
* message.
*/
virtual std::unique_ptr<DynamicJsonDocument> createConf();
virtual const char *getErrorCode() {return nullptr;} //nullptr means no error
virtual const char *getErrorDescription() {return "";}
virtual std::unique_ptr<DynamicJsonDocument> getErrorDetails() {return createEmptyDocument();}
};
} //end namespace MicroOcpp
#endif