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
63 lines (46 loc) · 1.59 KB
/
Copy pathSendLocalList.cpp
File metadata and controls
63 lines (46 loc) · 1.59 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
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
#include <ArduinoOcpp/Operations/SendLocalList.h>
#include <ArduinoOcpp/Model/Model.h>
#include <ArduinoOcpp/Model/Authorization/AuthorizationService.h>
using ArduinoOcpp::Ocpp16::SendLocalList;
SendLocalList::SendLocalList(Model& model) : model(model) {
}
SendLocalList::~SendLocalList() {
}
const char* SendLocalList::getOperationType(){
return "SendLocalList";
}
void SendLocalList::processReq(JsonObject payload) {
if (!payload.containsKey("listVersion") || !payload.containsKey("updateType")) {
errorCode = "FormationViolation";
return;
}
auto authService = model.getAuthorizationService();
if (!authService) {
errorCode = "InternalError";
return;
}
if (payload["localAuthorizationList"].as<JsonArray>().size() > AO_SendLocalListMaxLength) {
errorCode = "OccurenceConstraintViolation";
}
int listVersion = payload["listVersion"];
if (authService->getLocalListVersion() >= listVersion) {
versionMismatch = true;
return;
}
updateFailure = !authService->updateLocalList(payload);
}
std::unique_ptr<DynamicJsonDocument> SendLocalList::createConf(){
auto doc = std::unique_ptr<DynamicJsonDocument>(new DynamicJsonDocument(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;
}