forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClearChargingProfile.cpp
More file actions
82 lines (66 loc) · 2.65 KB
/
ClearChargingProfile.cpp
File metadata and controls
82 lines (66 loc) · 2.65 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
82
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/ClearChargingProfile.h>
#include <MicroOcpp/Model/SmartCharging/SmartChargingService.h>
#include <MicroOcpp/Debug.h>
#include <functional>
using MicroOcpp::Ocpp16::ClearChargingProfile;
using MicroOcpp::JsonDoc;
ClearChargingProfile::ClearChargingProfile(SmartChargingService& scService) : MemoryManaged("v16.Operation.", "ClearChargingProfile"), scService(scService) {
}
const char* ClearChargingProfile::getOperationType(){
return "ClearChargingProfile";
}
void ClearChargingProfile::processReq(JsonObject payload) {
std::function<bool(int, int, ChargingProfilePurposeType, int)> filter = [payload]
(int chargingProfileId, int connectorId, ChargingProfilePurposeType chargingProfilePurpose, int stackLevel) {
if (payload.containsKey("id")) {
if (chargingProfileId == (payload["id"] | -1)) {
return true;
} else {
return false;
}
}
if (payload.containsKey("connectorId")) {
if (connectorId != (payload["connectorId"] | -1)) {
return false;
}
}
if (payload.containsKey("chargingProfilePurpose")) {
switch (chargingProfilePurpose) {
case ChargingProfilePurposeType::ChargePointMaxProfile:
if (strcmp(payload["chargingProfilePurpose"] | "INVALID", "ChargePointMaxProfile")) {
return false;
}
break;
case ChargingProfilePurposeType::TxDefaultProfile:
if (strcmp(payload["chargingProfilePurpose"] | "INVALID", "TxDefaultProfile")) {
return false;
}
break;
case ChargingProfilePurposeType::TxProfile:
if (strcmp(payload["chargingProfilePurpose"] | "INVALID", "TxProfile")) {
return false;
}
break;
}
}
if (payload.containsKey("stackLevel")) {
if (stackLevel != (payload["stackLevel"] | -1)) {
return false;
}
}
return true;
};
matchingProfilesFound = scService.clearChargingProfile(filter);
}
std::unique_ptr<JsonDoc> ClearChargingProfile::createConf(){
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
if (matchingProfilesFound)
payload["status"] = "Accepted";
else
payload["status"] = "Unknown";
return doc;
}