forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStopTransaction.cpp
More file actions
87 lines (60 loc) · 2.44 KB
/
Copy pathStopTransaction.cpp
File metadata and controls
87 lines (60 loc) · 2.44 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
// matth-x/ESP8266-OCPP
// Copyright Matthias Akstaller 2019 - 2021
// MIT License
#include <ArduinoOcpp/MessagesV16/StopTransaction.h>
#include <ArduinoOcpp/Core/OcppEngine.h>
#include <ArduinoOcpp/Tasks/Metering/MeteringService.h>
#include <Variants.h>
using ArduinoOcpp::Ocpp16::StopTransaction;
StopTransaction::StopTransaction() {
}
StopTransaction::StopTransaction(int connectorId) : connectorId(connectorId) {
}
const char* StopTransaction::getOcppOperationType(){
return "StopTransaction";
}
DynamicJsonDocument* StopTransaction::createReq() {
DynamicJsonDocument *doc = new DynamicJsonDocument(JSON_OBJECT_SIZE(4) + (JSONDATE_LENGTH + 1));
JsonObject payload = doc->to<JsonObject>();
float meterStop = 0.0f;
if (getMeteringService() != NULL) {
meterStop = getMeteringService()->readEnergyActiveImportRegister(connectorId);
}
payload["meterStop"] = meterStop; //TODO meterStart is required to be in Wh, but measuring unit is probably inconsistent in implementation
char timestamp[JSONDATE_LENGTH + 1] = {'\0'};
getJsonDateStringFromSystemTime(timestamp, JSONDATE_LENGTH);
payload["timestamp"] = timestamp;
int transactionId = -1;
if (getConnectorStatus(connectorId) != NULL)
transactionId = getConnectorStatus(connectorId)->getTransactionId();
payload["transactionId"] = transactionId;
if (getConnectorStatus(connectorId) != NULL)
getConnectorStatus(connectorId)->stopEnergyOffer();
return doc;
}
void StopTransaction::processConf(JsonObject payload) {
//no need to process anything here
ConnectorStatus *connector = getConnectorStatus(connectorId);
//cpStatusService->stopEnergyOffer(); //No. This should remain in createReq
if (connector != NULL) {
connector->stopTransaction(); //TODO maybe better in createReq
connector->unauthorize();
}
SmartChargingService *scService = getSmartChargingService();
if (scService != NULL){
scService->endChargingNow();
}
if (DEBUG_OUT) Serial.print(F("[StopTransaction] Request has been accepted!\n"));
}
void StopTransaction::processReq(JsonObject payload) {
/**
* Ignore Contents of this Req-message, because this is for debug purposes only
*/
}
DynamicJsonDocument* StopTransaction::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;
}