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
83 lines (59 loc) · 2.41 KB
/
Copy pathMeterValues.cpp
File metadata and controls
83 lines (59 loc) · 2.41 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
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
#include <ArduinoOcpp/Operations/MeterValues.h>
#include <ArduinoOcpp/Model/Model.h>
#include <ArduinoOcpp/Model/Metering/MeterValue.h>
#include <ArduinoOcpp/Model/Transactions/Transaction.h>
#include <ArduinoOcpp/Debug.h>
using ArduinoOcpp::Ocpp16::MeterValues;
#define ENERGY_METER_TIMEOUT_MS 30 * 1000 //after waiting for 30s, send MeterValues without missing readings
//can only be used for echo server debugging
MeterValues::MeterValues() {
}
MeterValues::MeterValues(std::vector<std::unique_ptr<MeterValue>>&& meterValue, unsigned int connectorId, std::shared_ptr<Transaction> transaction)
: meterValue{std::move(meterValue)}, connectorId{connectorId}, transaction{transaction} {
}
MeterValues::~MeterValues(){
}
const char* MeterValues::getOperationType(){
return "MeterValues";
}
std::unique_ptr<DynamicJsonDocument> MeterValues::createReq() {
size_t capacity = 0;
std::vector<std::unique_ptr<DynamicJsonDocument>> entries;
for (auto value = meterValue.begin(); value != meterValue.end(); value++) {
auto entry = (*value)->toJson();
if (entry) {
capacity += entry->capacity();
entries.push_back(std::move(entry));
} else {
AO_DBG_ERR("Energy meter reading not convertible to JSON");
(void)0;
}
}
capacity += JSON_OBJECT_SIZE(3);
capacity += JSON_ARRAY_SIZE(entries.size());
auto doc = std::unique_ptr<DynamicJsonDocument>(new DynamicJsonDocument(capacity + 100)); //TODO remove safety space
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 meterValueJson = payload.createNestedArray("meterValue");
for (auto entry = entries.begin(); entry != entries.end(); entry++) {
meterValueJson.add(**entry);
}
return doc;
}
void MeterValues::processConf(JsonObject payload) {
AO_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<DynamicJsonDocument> MeterValues::createConf(){
return createEmptyDocument();
}