forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorize.cpp
More file actions
58 lines (46 loc) · 1.72 KB
/
Copy pathAuthorize.cpp
File metadata and controls
58 lines (46 loc) · 1.72 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
// matth-x/ESP8266-OCPP
// Copyright Matthias Akstaller 2019 - 2021
// MIT License
#include <ArduinoOcpp/MessagesV16/Authorize.h>
#include <ArduinoOcpp/Core/OcppEngine.h>
#include "Variants.h"
using ArduinoOcpp::Ocpp16::Authorize;
Authorize::Authorize() {
idTag = String("fefed1d19876"); //Use a default payload. In the typical use case of this library, you probably you don't even need Authorization at all
}
Authorize::Authorize(String &idTag) {
this->idTag = String(idTag);
}
const char* Authorize::getOcppOperationType(){
return "Authorize";
}
DynamicJsonDocument* Authorize::createReq() {
DynamicJsonDocument *doc = new DynamicJsonDocument(JSON_OBJECT_SIZE(1) + (idTag.length() + 1));
JsonObject payload = doc->to<JsonObject>();
payload["idTag"] = idTag;
return doc;
}
void Authorize::processConf(JsonObject payload){
String idTagInfo = payload["idTagInfo"]["status"] | "Invalid";
if (idTagInfo.equals("Accepted")) {
if (DEBUG_OUT) Serial.print(F("[Authorize] Request has been accepted!\n"));
ChargePointStatusService *cpStatusService = getChargePointStatusService();
if (cpStatusService != NULL){
cpStatusService->authorize(idTag);
}
} else {
Serial.print(F("[Authorize] Request has been denied!"));
}
}
void Authorize::processReq(JsonObject payload){
/*
* Ignore Contents of this Req-message, because this is for debug purposes only
*/
}
DynamicJsonDocument* Authorize::createConf(){
DynamicJsonDocument* doc = new DynamicJsonDocument(2 * JSON_OBJECT_SIZE(1));
JsonObject payload = doc->to<JsonObject>();
JsonObject idTagInfo = payload.createNestedObject("idTagInfo");
idTagInfo["status"] = "Accepted";
return doc;
}