forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeartbeat.cpp
More file actions
66 lines (51 loc) · 1.92 KB
/
Heartbeat.cpp
File metadata and controls
66 lines (51 loc) · 1.92 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/Heartbeat.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Debug.h>
#include <string.h>
using MicroOcpp::Ocpp16::Heartbeat;
using MicroOcpp::JsonDoc;
Heartbeat::Heartbeat(Model& model) : MemoryManaged("v16.Operation.", "Heartbeat"), model(model) {
}
const char* Heartbeat::getOperationType(){
return "Heartbeat";
}
std::unique_ptr<JsonDoc> Heartbeat::createReq() {
return createEmptyDocument();
}
void Heartbeat::processConf(JsonObject payload) {
const char* currentTime = payload["currentTime"] | "Invalid";
if (strcmp(currentTime, "Invalid")) {
if (model.getClock().setTime(currentTime)) {
//success
MO_DBG_DEBUG("Request has been accepted");
} else {
MO_DBG_WARN("Could not read time string. Expect format like 2020-02-01T20:53:32.486Z");
}
} else {
MO_DBG_WARN("Missing field currentTime. Expect format like 2020-02-01T20:53:32.486Z");
}
}
void Heartbeat::processReq(JsonObject payload) {
/**
* Ignore Contents of this Req-message, because this is for debug purposes only
*/
}
std::unique_ptr<JsonDoc> Heartbeat::createConf(){
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1) + (JSONDATE_LENGTH + 1));
JsonObject payload = doc->to<JsonObject>();
//safety mechanism; in some test setups the library could have to answer Heartbeats without valid system time
Timestamp ocppTimeReference = Timestamp(2019,10,0,11,59,55);
Timestamp ocppSelect = ocppTimeReference;
auto& ocppNow = model.getClock().now();
if (ocppNow > ocppTimeReference) {
//time has already been set
ocppSelect = ocppNow;
}
char ocppNowJson [JSONDATE_LENGTH + 1] = {'\0'};
ocppSelect.toJsonString(ocppNowJson, JSONDATE_LENGTH + 1);
payload["currentTime"] = ocppNowJson;
return doc;
}