forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatusNotification.cpp
More file actions
143 lines (124 loc) · 4.36 KB
/
Copy pathStatusNotification.cpp
File metadata and controls
143 lines (124 loc) · 4.36 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2021
// MIT License
#include <ArduinoOcpp/MessagesV16/StatusNotification.h>
#include <ArduinoOcpp/Core/OcppEngine.h>
#include <Variants.h>
#include <string.h>
using ArduinoOcpp::Ocpp16::StatusNotification;
StatusNotification::StatusNotification(int connectorId, OcppEvseState currentStatus, const OcppTimestamp &otimestamp, const char *errorCode)
: connectorId(connectorId), currentStatus(currentStatus), otimestamp(otimestamp), errorCode(errorCode) {
if (DEBUG_OUT) {
Serial.print(F("[StatusNotification] New StatusNotification. New Status: "));
}
switch (currentStatus) {
case (OcppEvseState::Available):
if (DEBUG_OUT) Serial.print(F("Available\n"));
break;
case (OcppEvseState::Preparing):
if (DEBUG_OUT) Serial.print(F("Preparing\n"));
break;
case (OcppEvseState::Charging):
if (DEBUG_OUT) Serial.print(F("Charging\n"));
break;
case (OcppEvseState::SuspendedEVSE):
if (DEBUG_OUT) Serial.print(F("SuspendedEVSE\n"));
break;
case (OcppEvseState::SuspendedEV):
if (DEBUG_OUT) Serial.print(F("SuspendedEV\n"));
break;
case (OcppEvseState::Finishing):
if (DEBUG_OUT) Serial.print(F("Finishing\n"));
break;
case (OcppEvseState::Reserved):
if (DEBUG_OUT) Serial.print(F("Reserved\n"));
break;
case (OcppEvseState::Unavailable):
if (DEBUG_OUT) Serial.print(F("Unavailable\n"));
break;
case (OcppEvseState::Faulted):
if (DEBUG_OUT) Serial.print(F("Faulted\n"));
break;
case (OcppEvseState::NOT_SET):
Serial.print(F("NOT_SET\n"));
break;
default:
Serial.print(F("[Error, invalid status code]\n"));
break;
}
}
const char* StatusNotification::getOcppOperationType(){
return "StatusNotification";
}
//TODO if the status has changed again when sendReq() is called, abort the operation completely (note: if req is already sent, stick with listening to conf). The OcppEvseStateService will enqueue a new operation itself
DynamicJsonDocument* StatusNotification::createReq() {
DynamicJsonDocument *doc = new DynamicJsonDocument(JSON_OBJECT_SIZE(4) + (JSONDATE_LENGTH + 1));
JsonObject payload = doc->to<JsonObject>();
payload["connectorId"] = connectorId;
if (errorCode != NULL) {
payload["errorCode"] = errorCode;
} else {
payload["errorCode"] = "NoError";
}
switch (currentStatus) {
case (OcppEvseState::Available):
payload["status"] = "Available";
break;
case (OcppEvseState::Preparing):
payload["status"] = "Preparing";
break;
case (OcppEvseState::Charging):
payload["status"] = "Charging";
break;
case (OcppEvseState::SuspendedEVSE):
payload["status"] = "SuspendedEVSE";
break;
case (OcppEvseState::SuspendedEV):
payload["status"] = "SuspendedEV";
break;
case (OcppEvseState::Finishing):
payload["status"] = "Finishing";
break;
case (OcppEvseState::Reserved):
payload["status"] = "Reserved";
break;
case (OcppEvseState::Unavailable):
payload["status"] = "Unavailable";
break;
case (OcppEvseState::Faulted):
payload["status"] = "Faulted";
break;
default:
payload["status"] = "NOT_SET";
Serial.print(F("[StatusNotification] Error: Sending status NOT_SET!\n"));
break;
}
char timestamp[JSONDATE_LENGTH + 1] = {'\0'};
otimestamp.toJsonString(timestamp, JSONDATE_LENGTH + 1);
payload["timestamp"] = timestamp;
return doc;
}
void StatusNotification::processConf(JsonObject payload) {
/*
* Empty payload
*/
}
/*
* For debugging only
*/
StatusNotification::StatusNotification() {
otimestamp = OcppTimestamp();
}
/*
* For debugging only
*/
void StatusNotification::processReq(JsonObject payload) {
}
/*
* For debugging only
*/
DynamicJsonDocument* StatusNotification::createConf(){
DynamicJsonDocument* doc = new DynamicJsonDocument(0);
doc->to<JsonObject>();
return doc;
}