forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeterValues.cpp
More file actions
93 lines (66 loc) · 2.7 KB
/
MeterValues.cpp
File metadata and controls
93 lines (66 loc) · 2.7 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/MeterValues.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Model/Metering/MeterValue.h>
#include <MicroOcpp/Model/Transactions/Transaction.h>
#include <MicroOcpp/Debug.h>
using MicroOcpp::Ocpp16::MeterValues;
using MicroOcpp::JsonDoc;
//can only be used for echo server debugging
MeterValues::MeterValues(Model& model) : MemoryManaged("v16.Operation.", "MeterValues"), model(model) {
}
MeterValues::MeterValues(Model& model, MeterValue *meterValue, unsigned int connectorId, std::shared_ptr<Transaction> transaction)
: MemoryManaged("v16.Operation.", "MeterValues"), model(model), meterValue{meterValue}, connectorId{connectorId}, transaction{transaction} {
}
MeterValues::MeterValues(Model& model, std::unique_ptr<MeterValue> meterValue, unsigned int connectorId, std::shared_ptr<Transaction> transaction)
: MeterValues(model, meterValue.get(), connectorId, transaction) {
this->meterValueOwnership = std::move(meterValue);
}
MeterValues::~MeterValues(){
}
const char* MeterValues::getOperationType(){
return "MeterValues";
}
std::unique_ptr<JsonDoc> MeterValues::createReq() {
size_t capacity = 0;
std::unique_ptr<JsonDoc> meterValueJson;
if (meterValue) {
if (meterValue->getTimestamp() < MIN_TIME) {
MO_DBG_DEBUG("adjust preboot MeterValue timestamp");
Timestamp adjusted = model.getClock().adjustPrebootTimestamp(meterValue->getTimestamp());
meterValue->setTimestamp(adjusted);
}
meterValueJson = meterValue->toJson();
if (meterValueJson) {
capacity += meterValueJson->capacity();
} else {
MO_DBG_ERR("Energy meter reading not convertible to JSON");
}
}
capacity += JSON_OBJECT_SIZE(3);
capacity += JSON_ARRAY_SIZE(1);
auto doc = makeJsonDoc(getMemoryTag(), capacity);
auto payload = doc->to<JsonObject>();
payload["connectorId"] = connectorId;
if (transaction && transaction->getTransactionId() > 0) { //add txId if MVs are assigned to a tx with txId
payload["transactionId"] = transaction->getTransactionId();
}
auto meterValueArray = payload.createNestedArray("meterValue");
if (meterValueJson) {
meterValueArray.add(*meterValueJson);
}
return doc;
}
void MeterValues::processConf(JsonObject payload) {
MO_DBG_DEBUG("Request has been confirmed");
}
void MeterValues::processReq(JsonObject payload) {
/**
* Ignore Contents of this Req-message, because this is for debug purposes only
*/
}
std::unique_ptr<JsonDoc> MeterValues::createConf(){
return createEmptyDocument();
}