-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLowVoltageSmartElectricEnergyMeter.hpp
148 lines (137 loc) · 6.66 KB
/
LowVoltageSmartElectricEnergyMeter.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
#include "HousingFacilitiesDevice.hpp"
class LowVoltageSmartElectricEnergyMeterClass : public HousingFacilitiesDeviceClass {
public:
/// @brief 低圧スマート電力量メータクラス
/// @version APPENDIX ECHONET 機器オブジェクト詳細規定 Release R
enum class Property : uint8_t {
BRouteIdentificationNumber = 0xC0, ///< Bルート識別番号
CumulativeEnergy1Minute = 0xD0, ///< 1分積算電力量計測値 (正方向、逆方向計測値)
OwnerClassification = 0xD1, ///< 所有者区分
Phase = 0xD2, ///< 相線式設定状態
Coefficient = 0xD3, ///< 係数(合成変成比)
SyntheticTransformationMagnification = 0xD4, ///< 係数(合成変成比)の倍率
CertifiedNumber = 0xD5, ///< 計器認定番号
TestExpirationDate = 0xD6, ///< 検定満了年月
CumulativeAmountEnergyEffectiveDigits = 0xD7, ///< 積算電力量有効桁数
CumulativeEnergyPositive = 0xE0, ///< 積算電力量計測値(正方向)
CumulativeEnergyUnit = 0xE1, ///< 積算電力量単位(正・逆方向)
CumulativeEnergyHistoryPositive = 0xE2, ///< 積算電力量計測値履歴(正方向)
CumulativeEnergyNegative = 0xE3, ///< 積算電力量計測値(逆方向)
CumulativeEnergyHistoryNegative = 0xE4, ///< 積算電力量計測値履歴(逆方向)
DateOfCollectCumulativeEnergyHistory = 0xE5, ///< 積算履歴収集日
InstantaneousPower = 0xE7, ///< 瞬時電力計測値
InstantaneousCurrents = 0xE8, ///< 瞬時電流計測値
InstantaneousVoltage = 0xE9, ///< 瞬時電圧計測値
FixedCumulativeEnergyPositive = 0xEA, ///< 定時積算電力量(正方向)
FixedCumulativeEnergyNegative = 0xEB, ///< 定時積算電力量(逆方向)
CumulativeEnergyHistory2 = 0xEC, ///< 積算電力量計測値履歴2(正方向、逆方向計測値)
DateOfCollectCumulativeEnergyHistory2 = 0xED, ///< 積算履歴収集日2
CumulativeEnergyHistory3 = 0xEE, ///< 積算電力量計測値履歴3(正方向、逆方向計測値)
DateOfCollectCumulativeEnergyHistory3 = 0xEF, ///< 積算履歴収集日3
};
double cumulativeEnergyUnit = 1.0; ///< 積算電力量単位デフォルト値
uint32_t syntheticTransformationRatio = 1; ///< 係数デフォルト値
/// @brief 単位初期化
bool initCumulativeEnergyUnit(void) {
int8_t unit;
if (getSpecifiedPropertyData(Property::CumulativeEnergyUnit, &unit) && convertCumulativeEnergyUnit(unit, &this->cumulativeEnergyUnit)) {
return true;
}
return false;
}
/// @brief 係数初期化
bool initSyntheticTransformationRatio(void) {
uint32_t ratio;
if (getSpecifiedPropertyData(Property::Coefficient, &ratio) && ratio <= 999999) {
this->syntheticTransformationRatio = ratio;
return true;
}
return false;
}
/// @brief 定数初期化
bool initConstantData() {
return initCumulativeEnergyUnit() && initSyntheticTransformationRatio();
}
/// @brief Get要求リクエストデータ生成
template <class PropertyType>
void generateGetRequest(const std::vector<PropertyType> &property) {
HousingFacilitiesDeviceClass::generateGetRequest(property);
data.EDATA.DEOJ.classCode = static_cast<uint8_t>(ClassCode::LowVoltageSmartElectricMeter);
}
/// @brief レスポンスのパース
bool load(const std::string &response) {
const bool result = HousingFacilitiesDeviceClass::load(response);
for (const EchonetLite::EchonetLitePayload &payload : this->data.payload) {
// 係数と単位はあらかじめパースしておく
switch (static_cast<Property>(payload.echonetLiteProperty)) {
case LowVoltageSmartElectricEnergyMeterClass::Property::CumulativeEnergyUnit:
initCumulativeEnergyUnit();
break;
case LowVoltageSmartElectricEnergyMeterClass::Property::Coefficient:
initSyntheticTransformationRatio();
break;
default:
break;
}
}
return result;
}
/// @brief 積算電力量単位変換
bool convertCumulativeEnergyUnit(const uint8_t in, double *const out) {
switch (in) {
case 0x00:
*out = 1.0;
return true;
case 0x01:
*out = 0.1;
return true;
case 0x02:
*out = 0.01;
return true;
case 0x03:
*out = 0.001;
return true;
case 0x04:
*out = 0.0001;
return true;
case 0x0A:
*out = 10.0;
return true;
case 0x0B:
*out = 100.0;
return true;
case 0x0C:
*out = 1000.0;
return true;
case 0x0D:
*out = 10000.0;
return true;
default:
return false;
}
}
/// @brief 瞬時電力計測値取得
bool getInstantaneousPower(int32_t *const instantaneousPower) {
return getSpecifiedPropertyData(Property::InstantaneousPower, instantaneousPower);
}
/// @brief 瞬時電流計測値取得
bool getInstantaneousCurrent(float *const current_R, float *const current_T) {
int16_t current_R_Int = 0;
int16_t current_T_Int = 0;
const auto hasData = getSpecifiedPropertyData(Property::InstantaneousCurrents, ¤t_R_Int, ¤t_T_Int);
if (hasData) {
*current_R = current_R_Int * 0.1;
*current_T = current_T_Int * 0.1;
}
return hasData;
}
/// @brief 積算電力量計測値(正方向)取得
bool getCumulativeEnergyPositive(float *const cumulativeEnergyPositive) {
int32_t cumulativeEnergyPositiveInt = 0;
bool hasData = getSpecifiedPropertyData(Property::CumulativeEnergyPositive, &cumulativeEnergyPositiveInt);
if (hasData) {
*cumulativeEnergyPositive = cumulativeEnergyPositiveInt * this->syntheticTransformationRatio * this->cumulativeEnergyUnit;
}
return hasData;
}
};