forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendLocalList.cpp
More file actions
80 lines (57 loc) · 2.16 KB
/
SendLocalList.cpp
File metadata and controls
80 lines (57 loc) · 2.16 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Version.h>
#if MO_ENABLE_LOCAL_AUTH
#include <MicroOcpp/Operations/SendLocalList.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Model/Authorization/AuthorizationService.h>
using MicroOcpp::Ocpp16::SendLocalList;
using MicroOcpp::JsonDoc;
SendLocalList::SendLocalList(AuthorizationService& authService) : MemoryManaged("v16.Operation.", "SendLocalList"), authService(authService) {
}
SendLocalList::~SendLocalList() {
}
const char* SendLocalList::getOperationType(){
return "SendLocalList";
}
void SendLocalList::processReq(JsonObject payload) {
//TC_043_1_CS Send Local Authorization List - NotSupported
if (!authService.localAuthListEnabled()) {
errorCode = "NotSupported";
return;
}
if (!payload.containsKey("listVersion") || !payload.containsKey("updateType")) {
errorCode = "FormationViolation";
return;
}
if (payload.containsKey("localAuthorizationList") && !payload["localAuthorizationList"].is<JsonArray>()) {
errorCode = "FormationViolation";
return;
}
JsonArray localAuthorizationList = payload["localAuthorizationList"];
if (localAuthorizationList.size() > MO_SendLocalListMaxLength) {
errorCode = "OccurenceConstraintViolation";
return;
}
bool differential = !strcmp("Differential", payload["updateType"] | "Invalid"); //updateType Differential or Full
int listVersion = payload["listVersion"];
if (differential && authService.getLocalListVersion() >= listVersion) {
versionMismatch = true;
return;
}
updateFailure = !authService.updateLocalList(localAuthorizationList, listVersion, differential);
}
std::unique_ptr<JsonDoc> SendLocalList::createConf(){
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
if (versionMismatch) {
payload["status"] = "VersionMismatch";
} else if (updateFailure) {
payload["status"] = "Failed";
} else {
payload["status"] = "Accepted";
}
return doc;
}
#endif //MO_ENABLE_LOCAL_AUTH