forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetBaseReport.cpp
More file actions
81 lines (62 loc) · 2.19 KB
/
GetBaseReport.cpp
File metadata and controls
81 lines (62 loc) · 2.19 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Version.h>
#if MO_ENABLE_V201
#include <MicroOcpp/Operations/GetBaseReport.h>
#include <MicroOcpp/Model/Variables/VariableService.h>
#include <MicroOcpp/Debug.h>
using MicroOcpp::Ocpp201::GetBaseReport;
using MicroOcpp::JsonDoc;
GetBaseReport::GetBaseReport(VariableService& variableService) : MemoryManaged("v201.Operation.", "GetBaseReport"), variableService(variableService) {
}
const char* GetBaseReport::getOperationType(){
return "GetBaseReport";
}
void GetBaseReport::processReq(JsonObject payload) {
int requestId = payload["requestId"] | -1;
if (requestId < 0) {
errorCode = "FormationViolation";
MO_DBG_ERR("invalid requestId");
return;
}
ReportBase reportBase;
const char *reportBaseCstr = payload["reportBase"] | "";
if (!strcmp(reportBaseCstr, "ConfigurationInventory")) {
reportBase = ReportBase_ConfigurationInventory;
} else if (!strcmp(reportBaseCstr, "FullInventory")) {
reportBase = ReportBase_FullInventory;
} else if (!strcmp(reportBaseCstr, "SummaryInventory")) {
reportBase = ReportBase_SummaryInventory;
} else {
errorCode = "FormationViolation";
MO_DBG_ERR("invalid reportBase");
return;
}
status = variableService.getBaseReport(requestId, reportBase);
}
std::unique_ptr<JsonDoc> GetBaseReport::createConf(){
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
const char *statusCstr = "";
switch (status) {
case GenericDeviceModelStatus_Accepted:
statusCstr = "Accepted";
break;
case GenericDeviceModelStatus_Rejected:
statusCstr = "Rejected";
break;
case GenericDeviceModelStatus_NotSupported:
statusCstr = "NotSupported";
break;
case GenericDeviceModelStatus_EmptyResultSet:
statusCstr = "EmptyResultSet";
break;
default:
MO_DBG_ERR("internal error");
break;
}
payload["status"] = statusCstr;
return doc;
}
#endif // MO_ENABLE_V201