-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMeasurementType.hpp
156 lines (132 loc) · 10.4 KB
/
MeasurementType.hpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifndef __LIBSPEEDWIRE_MEASUREMENTTYPE_HPP__
#define __LIBSPEEDWIRE_MEASUREMENTTYPE_HPP__
#include <string>
namespace libspeedwire {
/**
* Enumeration describing the direction of energy flows.
*/
enum class Direction {
POSITIVE, //!< Positive direction - energy is consumed from the grid
NEGATIVE, //!< Negative direction - energy is provided to the grid
SIGNED, //!< Positive and negative direction expressed by a signed value
NO_DIRECTION //!< Direction is not applicable
};
//! Convert Direction to a string
std::string toString(const Direction direction);
/**
* Enumeration describing the wire for the energy or information flow.
* Totals and status values are considered as separate wires.
*/
enum class Wire {
TOTAL, //!< Total of L1+L2+L3 of three-phase alternating current
L1, //!< Phase L1 of three-phase alternating current wire
L2, //!< Phase L2 of three-phase alternating current wire
L3, //!< Phase L3 of three-phase alternating current wire
L1L2, //!< Phase L1 of three-phase alternating current wire
L2L3, //!< Phase L2 of three-phase alternating current wire
L3L1, //!< Phase L3 of three-phase alternating current wire
MPP_TOTAL, //!< Total of MPP1+MPP2 direct current
MPP1, //!< MPP1 direct current wire
MPP2, //!< MPP2 direct current wire
LOSS_TOTAL, //!< Total of L1+L2+L3 of three-phase alternating current minus total of MPP1+MPP2 direct current
GRID_TOTAL, //!< Total of L1+L2+L3 of three-phase alternating current at grid connection point
DEVICE_OK, //!< Device OK status
RELAY_ON, //!< Grid relay switched on
FEED_IN, //!< Monetary income from grid feed-in
SELF_CONSUMPTION, //!< Monetary savings from self-consumption
NO_WIRE //!< Wire is not applicable
};
//! Convert Wire to a string
std::string toString(const Wire line);
/**
* Enumeration describing the physical quantity.
*/
enum class Quantity {
POWER, //!< Electrical power
ENERGY, //!< Electrical energy
POWER_FACTOR, //!< Power factor
FREQUENCY, //!< Frequency
CURRENT, //!< Electrical current
VOLTAGE, //!< Electrical voltage
STATUS, //!< Device status
EFFICIENCY, //!< Energy efficiency
STATE_OF_CHARGE, //!< State of charge
TEMPERATURE, //!< Temperature
DURATION, //!< Time duration
CURRENCY, //!< Monetary amount
NO_QUANTITY //!< Quantity is not applicable
};
//! Convert Quantity to a string
std::string toString(const Quantity quantity);
//! Returns if the given Quantity is an instantaneous quantity like power, voltage, current, ...; contrary to energy which is an accumulated quantity like energy
bool isInstantaneous(const Quantity quantity);
/**
* Enumeration describing the type of the measurement.
*/
enum class Type {
ACTIVE, //!< Electrical active power or energy
REACTIVE, //!< Electrical reactive power or energy
APPARENT, //!< Electrical apparent power or energy
NOMINAL, //!< Electrical nominal power
VERSION, //!< Software version
END_OF_DATA, //!< End of data marker
NO_TYPE //!< Type is not applicable
};
//! Convert Type to a string
std::string toString(const Type type);
/**
* Class encapsulating fixed properties of a measurement type.
*/
class MeasurementType {
public:
std::string name; //!< Printable name constructed from the Direction, Quantity and Type properties below
std::string unit; //!< Measurement unit after applying the divisor, e.g. W, kWh
unsigned long divisor; //!< Divide value by divisor to obtain floating point measurements in the given unit
bool instaneous; //!< True for power measurements, false for energy measurements
Direction direction; //!< Direction of the energy flow
Quantity quantity; //!< Physical quantity of the measurement
Type type; //!< Type of the measurement
MeasurementType(const Direction direction, const Type type, const Quantity quantity, const std::string& unit, const unsigned long divisor);
std::string getFullName(const Wire wire) const;
// pre-defined instances for emeter measurement types
// these definitions are used by static initializers; to avoid static initialization ordering issues, define them as methods
static MeasurementType EmeterPositiveActivePower(void) { return MeasurementType(Direction::POSITIVE, Type::ACTIVE, Quantity::POWER, "W", 10); }
static MeasurementType EmeterPositiveActiveEnergy(void) { return MeasurementType(Direction::POSITIVE, Type::ACTIVE, Quantity::ENERGY, "kWh", 3600000); }
static MeasurementType EmeterNegativeActivePower(void) { return MeasurementType(Direction::NEGATIVE, Type::ACTIVE, Quantity::POWER, "W", 10); }
static MeasurementType EmeterNegativeActiveEnergy(void) { return MeasurementType(Direction::NEGATIVE, Type::ACTIVE, Quantity::ENERGY, "kWh", 3600000); }
static MeasurementType EmeterPositiveApparentPower(void) { return MeasurementType(Direction::POSITIVE, Type::APPARENT, Quantity::POWER, "VA", 10); }
static MeasurementType EmeterPositiveApparentEnergy(void) { return MeasurementType(Direction::POSITIVE, Type::APPARENT, Quantity::ENERGY, "VAh", 3600000); }
static MeasurementType EmeterNegativeApparentPower(void) { return MeasurementType(Direction::NEGATIVE, Type::APPARENT, Quantity::POWER, "VA", 10); }
static MeasurementType EmeterNegativeApparentEnergy(void) { return MeasurementType(Direction::NEGATIVE, Type::APPARENT, Quantity::ENERGY, "VAh", 3600000); }
static MeasurementType EmeterPositiveReactivePower(void) { return MeasurementType(Direction::POSITIVE, Type::REACTIVE, Quantity::POWER, "Var", 10); }
static MeasurementType EmeterPositiveReactiveEnergy(void) { return MeasurementType(Direction::POSITIVE, Type::REACTIVE, Quantity::ENERGY, "Varh", 3600000); }
static MeasurementType EmeterNegativeReactivePower(void) { return MeasurementType(Direction::NEGATIVE, Type::REACTIVE, Quantity::POWER, "Var", 10); }
static MeasurementType EmeterNegativeReactiveEnergy(void) { return MeasurementType(Direction::NEGATIVE, Type::REACTIVE, Quantity::ENERGY, "Varh", 3600000); }
static MeasurementType EmeterSignedActivePower(void) { return MeasurementType(Direction::SIGNED, Type::ACTIVE, Quantity::POWER, "W", 10); }
static MeasurementType EmeterPowerFactor(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::POWER_FACTOR, "phi", 1000); }
static MeasurementType EmeterFrequency(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::FREQUENCY, "Hz", 1000); }
static MeasurementType EmeterVoltage(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::VOLTAGE, "V", 1000); }
static MeasurementType EmeterCurrent(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::CURRENT, "A", 1000); }
static MeasurementType EmeterSoftwareVersion(void) { return MeasurementType(Direction::NO_DIRECTION, Type::VERSION, Quantity::NO_QUANTITY, "", 1); }
static MeasurementType EmeterEndOfData(void) { return MeasurementType(Direction::NO_DIRECTION, Type::END_OF_DATA, Quantity::NO_QUANTITY, "", 1); }
// pre-defined instances for inverter measurement types
static MeasurementType InverterPower(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::POWER, "W", 1); }
static MeasurementType InverterReactivePower(void) { return MeasurementType(Direction::NO_DIRECTION, Type::REACTIVE, Quantity::POWER, "Var", 1); }
static MeasurementType InverterNominalPower(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NOMINAL, Quantity::POWER, "W", 1); }
static MeasurementType InverterPowerFactor(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::POWER_FACTOR, "phi", 100); }
static MeasurementType InverterFrequency(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::FREQUENCY, "Hz", 100); }
static MeasurementType InverterVoltage(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::VOLTAGE, "V", 100); }
static MeasurementType InverterCurrent(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::CURRENT, "A", 1000); }
static MeasurementType InverterStatus(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::STATUS, "", 1); }
static MeasurementType InverterRelay(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::STATUS, "", 1); }
static MeasurementType InverterEfficiency(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::EFFICIENCY, "%", 1); }
static MeasurementType InverterStateOfCharge(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::STATE_OF_CHARGE, "%", 1); }
static MeasurementType InverterTemperature(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::TEMPERATURE, "°C", 10); }
static MeasurementType InverterLoss(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::POWER, "W", 1); }
static MeasurementType InverterEnergy(const Direction direction = Direction::NO_DIRECTION) { return MeasurementType(direction, Type::ACTIVE, Quantity::ENERGY, "Wh", 1); }
static MeasurementType InverterDuration(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::DURATION, "s", 1); }
// pre-defined instances for miscellaneous measurement types
static MeasurementType Currency(void) { return MeasurementType(Direction::NO_DIRECTION, Type::NO_TYPE, Quantity::CURRENCY, "Eur", 1); }
};
} // namespace libspeedwire
#endif