forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetDiagnostics.cpp
More file actions
71 lines (60 loc) · 2.4 KB
/
Copy pathGetDiagnostics.cpp
File metadata and controls
71 lines (60 loc) · 2.4 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
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
#include <ArduinoOcpp/Operations/GetDiagnostics.h>
#include <ArduinoOcpp/Model/Model.h>
#include <ArduinoOcpp/Model/Diagnostics/DiagnosticsService.h>
#include <ArduinoOcpp/Debug.h>
using ArduinoOcpp::Ocpp16::GetDiagnostics;
GetDiagnostics::GetDiagnostics(Model& model) : model(model) {
}
void GetDiagnostics::processReq(JsonObject payload) {
/*
* Process the application data here. Note: you have to implement the FW update procedure in your client code. You have to set
* a onSendConfListener in which you initiate a FW update (e.g. calling ESPhttpUpdate.update(...) )
*/
const char *loc = payload["location"] | "";
location = loc;
//check location URL. Maybe introduce Same-Origin-Policy?
if (location.empty()) {
formatError = true;
AO_DBG_WARN("Could not read location. Abort");
return;
}
retries = payload["retries"] | 1;
retryInterval = payload["retryInterval"] | 180;
//check the integrity of startTime
if (payload.containsKey("startTime")) {
const char *startTimeRaw = payload["startTime"] | "Invalid";
if (!startTime.setTime(startTimeRaw)) {
formatError = true;
AO_DBG_WARN("Could not read startTime. Abort");
return;
}
}
//check the integrity of stopTime
if (payload.containsKey("startTime")) {
const char *stopTimeRaw = payload["stopTime"] | "Invalid";
if (!stopTime.setTime(stopTimeRaw)) {
formatError = true;
AO_DBG_WARN("Could not read stopTime. Abort");
return;
}
}
}
std::unique_ptr<DynamicJsonDocument> GetDiagnostics::createConf(){
if (auto diagService = model.getDiagnosticsService()) {
fileName = diagService->requestDiagnosticsUpload(location, retries, retryInterval, startTime, stopTime);
} else {
AO_DBG_WARN("DiagnosticsService has not been initialized before! Please have a look at ArduinoOcpp.cpp for an example. Abort");
return createEmptyDocument();
}
if (fileName.empty()) {
return createEmptyDocument();
} else {
auto doc = std::unique_ptr<DynamicJsonDocument>(new DynamicJsonDocument(JSON_OBJECT_SIZE(1) + fileName.length() + 1));
JsonObject payload = doc->to<JsonObject>();
payload["fileName"] = fileName;
return doc;
}
}