forked from ag-prn/ArduinoOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOcppError.h
More file actions
56 lines (48 loc) · 1.37 KB
/
Copy pathOcppError.h
File metadata and controls
56 lines (48 loc) · 1.37 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
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2022
// MIT License
#ifndef OCPPERROR_H
#define OCPPERROR_H
#include <ArduinoJson.h>
#include <ArduinoOcpp/Core/OcppMessage.h>
namespace ArduinoOcpp {
class NotImplemented : public OcppMessage {
public:
const char *getErrorCode() {
return "NotImplemented";
}
};
class OutOfMemory : public OcppMessage {
private:
uint32_t freeHeap;
size_t msgLen;
public:
OutOfMemory(uint32_t freeHeap, size_t msgLen) : freeHeap(freeHeap), msgLen(msgLen) { }
const char *getErrorCode() {
return "InternalError";
}
const char *getErrorDescription() {
return "Too little free memory on the controller. Operation denied";
}
std::unique_ptr<DynamicJsonDocument> getErrorDetails() {
auto errDoc = std::unique_ptr<DynamicJsonDocument>(new DynamicJsonDocument(JSON_OBJECT_SIZE(2)));
JsonObject err = errDoc->to<JsonObject>();
err["free_heap"] = freeHeap;
err["msg_length"] = msgLen;
return errDoc;
}
};
class WebSocketError : public OcppMessage {
private:
const char *description;
public:
WebSocketError(const char *description) : description(description) { }
const char *getErrorCode() {
return "GenericError";
}
const char *getErrorDescription() {
return description;
}
};
} //end namespace ArduinoOcpp
#endif