forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReset.cpp
More file actions
119 lines (95 loc) · 3.33 KB
/
Reset.cpp
File metadata and controls
119 lines (95 loc) · 3.33 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/Reset.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Model/Reset/ResetService.h>
#include <MicroOcpp/Debug.h>
using MicroOcpp::Ocpp16::Reset;
using MicroOcpp::JsonDoc;
Reset::Reset(Model& model) : MemoryManaged("v16.Operation.", "Reset"), model(model) {
}
const char* Reset::getOperationType(){
return "Reset";
}
void Reset::processReq(JsonObject payload) {
/*
* Process the application data here. Note: you have to implement the device reset procedure in your client code. You have to set
* a onSendConfListener in which you initiate a reset (e.g. calling ESP.reset() )
*/
bool isHard = !strcmp(payload["type"] | "undefined", "Hard");
if (auto rService = model.getResetService()) {
if (!rService->getExecuteReset()) {
MO_DBG_ERR("No reset handler set. Abort operation");
//resetAccepted remains false
} else {
if (!rService->getPreReset() || rService->getPreReset()(isHard) || isHard) {
resetAccepted = true;
rService->initiateReset(isHard);
for (unsigned int cId = 0; cId < model.getNumConnectors(); cId++) {
model.getConnector(cId)->endTransaction(nullptr, isHard ? "HardReset" : "SoftReset");
}
}
}
} else {
resetAccepted = true; //assume that onReceiveReset is set
}
}
std::unique_ptr<JsonDoc> Reset::createConf() {
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
payload["status"] = resetAccepted ? "Accepted" : "Rejected";
return doc;
}
#if MO_ENABLE_V201
#include <MicroOcpp/Model/ConnectorBase/EvseId.h>
namespace MicroOcpp {
namespace Ocpp201 {
Reset::Reset(ResetService& resetService) : MemoryManaged("v201.Operation.", "Reset"), resetService(resetService) {
}
const char* Reset::getOperationType(){
return "Reset";
}
void Reset::processReq(JsonObject payload) {
ResetType type;
const char *typeCstr = payload["type"] | "_Undefined";
if (!strcmp(typeCstr, "Immediate")) {
type = ResetType_Immediate;
} else if (!strcmp(typeCstr, "OnIdle")) {
type = ResetType_OnIdle;
} else {
errorCode = "FormationViolation";
return;
}
int evseIdRaw = payload["evseId"] | 0;
if (evseIdRaw < 0 || evseIdRaw >= MO_NUM_EVSEID) {
errorCode = "PropertyConstraintViolation";
return;
}
unsigned int evseId = (unsigned int) evseIdRaw;
status = resetService.initiateReset(type, evseId);
}
std::unique_ptr<JsonDoc> Reset::createConf() {
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
const char *statusCstr = "";
switch (status) {
case ResetStatus_Accepted:
statusCstr = "Accepted";
break;
case ResetStatus_Rejected:
statusCstr = "Rejected";
break;
case ResetStatus_Scheduled:
statusCstr = "Scheduled";
break;
default:
MO_DBG_ERR("internal error");
break;
}
payload["status"] = statusCstr;
return doc;
}
} //end namespace Ocpp201
} //end namespace MicroOcpp
#endif //MO_ENABLE_V201