ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
average_meter_values.hpp
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
3
4#pragma once
5
6#include <everest/logging.hpp>
7#include <everest/timer.hpp>
8#include <ocpp/common/types.hpp>
9#include <ocpp/v2/ocpp_enums.hpp>
10#include <ocpp/v2/ocpp_types.hpp>
11#include <ocpp/v2/types.hpp>
12#include <ocpp/v2/utils.hpp>
13#include <vector>
14namespace ocpp {
15namespace v2 {
17
18public:
22 void set_values(const MeterValue& meter_value);
27 void clear_values();
28
29private:
30 struct MeterValueCalc {
31 double sum;
32 int num_elements;
33 };
34 struct MeterValueMeasurands {
35 MeasurandEnum measurand;
36 std::optional<PhaseEnum> phase; // measurand may or may not have a phase field
37 std::optional<LocationEnum> location; // measurand may or may not have location field
38
39 // Define a comparison operator for the struct
40 bool operator<(const MeterValueMeasurands& other) const {
41 // Using tie here to compare the two lexicographically instead of writing it all out
42 return std::tie(measurand, location, phase) < std::tie(other.measurand, other.location, other.phase);
43 }
44 };
45
46 MeterValue averaged_meter_values;
47 std::mutex avg_meter_value_mutex;
48 std::map<MeterValueMeasurands, MeterValueCalc> aligned_meter_values;
49 bool is_avg_meas(const SampledValue& sample);
50 void average_meter_value();
51};
52} // namespace v2
53
54} // namespace ocpp
Definition: average_meter_values.hpp:16
void clear_values()
Manually clear the local object meter values.
Definition: average_meter_values.cpp:12
void set_values(const MeterValue &meter_value)
Set the meter values into the local object for processing.
Definition: average_meter_values.cpp:18
MeterValue retrieve_processed_values()
retrive the processed values
Definition: average_meter_values.cpp:36
Definition: ocpp_types.hpp:436
Definition: ocpp_types.hpp:416