forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetCompositeSchedule.cpp
More file actions
77 lines (59 loc) · 2.5 KB
/
Copy pathGetCompositeSchedule.cpp
File metadata and controls
77 lines (59 loc) · 2.5 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/GetCompositeSchedule.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Model/SmartCharging/SmartChargingService.h>
#include <MicroOcpp/Debug.h>
using MicroOcpp::Ocpp16::GetCompositeSchedule;
using MicroOcpp::JsonDoc;
GetCompositeSchedule::GetCompositeSchedule(Model& model, SmartChargingService& scService) : MemoryManaged("v16.Operation.", "GetCompositeSchedule"), model(model), scService(scService) {
}
const char* GetCompositeSchedule::getOperationType() {
return "GetCompositeSchedule";
}
void GetCompositeSchedule::processReq(JsonObject payload) {
connectorId = payload["connectorId"] | -1;
duration = payload["duration"] | 0;
if (connectorId < 0 || !payload.containsKey("duration")) {
errorCode = "FormationViolation";
return;
}
if ((unsigned int) connectorId >= model.getNumConnectors()) {
errorCode = "PropertyConstraintViolation";
}
const char *unitStr = payload["chargingRateUnit"] | "_Undefined";
if (unitStr[0] == 'A' || unitStr[0] == 'a') {
chargingRateUnit = ChargingRateUnitType_Optional::Amp;
} else if (unitStr[0] == 'W' || unitStr[0] == 'w') {
chargingRateUnit = ChargingRateUnitType_Optional::Watt;
}
}
std::unique_ptr<JsonDoc> GetCompositeSchedule::createConf(){
bool success = false;
auto chargingSchedule = scService.getCompositeSchedule((unsigned int) connectorId, duration, chargingRateUnit);
JsonDoc chargingScheduleDoc {0};
if (chargingSchedule) {
success = chargingSchedule->toJson(chargingScheduleDoc);
}
char scheduleStart_str [JSONDATE_LENGTH + 1] = {'\0'};
if (success && chargingSchedule) {
success = chargingSchedule->startSchedule.toJsonString(scheduleStart_str, JSONDATE_LENGTH + 1);
}
if (success && chargingSchedule) {
auto doc = makeJsonDoc(getMemoryTag(),
JSON_OBJECT_SIZE(4) +
chargingScheduleDoc.memoryUsage());
JsonObject payload = doc->to<JsonObject>();
payload["status"] = "Accepted";
payload["connectorId"] = connectorId;
payload["scheduleStart"] = scheduleStart_str;
payload["chargingSchedule"] = chargingScheduleDoc;
return doc;
} else {
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
payload["status"] = "Rejected";
return doc;
}
}