-
Notifications
You must be signed in to change notification settings - Fork 25
/
driver_flowiq2200.h
175 lines (156 loc) · 6.4 KB
/
driver_flowiq2200.h
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
Based on: https://github.com/wmbusmeters/wmbusmeters/blob/master/src/driver_flowiq2200.cc
Copyright (C) 2017-2022 Fredrik Öhrström (gpl-3.0-or-later)
*/
#pragma once
#include "driver.h"
#include <vector>
#include <string>
struct Flowiq2200: Driver
{
Flowiq2200(std::string key = "") : Driver(std::string("flowiq2200"), key) {};
virtual esphome::optional<std::map<std::string, double>> get_values(std::vector<unsigned char> &telegram) override {
std::map<std::string, double> ret_val{};
add_to_map(ret_val, "total_water_m3", this->get_total_water_m3(telegram));
add_to_map(ret_val, "target_water_m3", this->get_target_water_m3(telegram));
add_to_map(ret_val, "status", this->get_status(telegram));
add_to_map(ret_val, "volume_flow_lh", this->get_volume_flow_lh(telegram));
add_to_map(ret_val, "min_flow_lh", this->get_min_flow_lh(telegram));
add_to_map(ret_val, "max_flow_lh", this->get_max_flow_lh(telegram));
if (ret_val.size() > 0) {
return ret_val;
}
else {
return {};
}
};
// X X X X X
// CRC status prev maxF 06FF1B date T1 T2 flow total
// 0001 1718 1920212223 24252627 28293031 3233 343536373839 4041 42 43 4445 46474849 50
// 3244 ... FDC3 7905099CE6 00000000 7CE20300 7C05 06600006D000 0132 0B 11 0000 79E70300 0F
// see https://github.com/SzczepanLeon/esphome-components/issues/86
private:
esphome::optional<double> get_total_water_m3(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint8_t l_field = telegram[0];
uint8_t tpl_ci_field = telegram[19];
if (tpl_ci_field == 0x78) {
ret_val = this->get_0413(telegram);
}
else if ((tpl_ci_field == 0x79) && (l_field > 49)) {
uint16_t signature = ((uint16_t)telegram[20] << 8) | telegram[21];
ESP_LOGVV(TAG, "Signature of message is: '%X'", signature);
if (signature == 0xF3A9) {
uint32_t usage{0};
uint8_t i = 28;
usage = (((uint32_t)telegram[i+3] << 24) | ((uint32_t)telegram[i+2] << 16) |
((uint32_t)telegram[i+1] << 8) | ((uint32_t)telegram[i+0]));
ret_val = usage / 1000.0;
ESP_LOGVV(TAG, "Found total_water with '%d'->'%f'", usage, ret_val.value());
}
}
return ret_val;
};
esphome::optional<double> get_target_water_m3(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint8_t l_field = telegram[0];
uint8_t tpl_ci_field = telegram[19];
if (tpl_ci_field == 0x78) {
ret_val = this->get_4413(telegram);
}
else if ((tpl_ci_field == 0x79) && (l_field > 49)) {
uint16_t signature = ((uint16_t)telegram[20] << 8) | telegram[21];
ESP_LOGVV(TAG, "Signature of message is: '%X'", signature);
if (signature == 0xF3A9) {
uint32_t usage{0};
uint8_t i = 32;
usage = (((uint32_t)telegram[i+3] << 24) | ((uint32_t)telegram[i+2] << 16) |
((uint32_t)telegram[i+1] << 8) | ((uint32_t)telegram[i+0]));
ret_val = usage / 1000.0;
ESP_LOGVV(TAG, "Found target_water with '%d'->'%f'", usage, ret_val.value());
}
}
return ret_val;
};
esphome::optional<double> get_status(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint8_t l_field = telegram[0];
uint8_t tpl_ci_field = telegram[19];
if (tpl_ci_field == 0x78) {
ret_val = this->get_04FF23(telegram);
}
else if ((tpl_ci_field == 0x79) && (l_field > 49)) {
uint16_t signature = ((uint16_t)telegram[20] << 8) | telegram[21];
ESP_LOGVV(TAG, "Signature of message is: '%X'", signature);
if (signature == 0xF3A9) {
uint32_t status{0};
uint8_t i = 24;
status = (((uint32_t)telegram[i+3] << 24) | ((uint32_t)telegram[i+2] << 16) |
((uint32_t)telegram[i+1] << 8) | ((uint32_t)telegram[i+0]));
ret_val = (double)status;
ESP_LOGVV(TAG, "Found status with '%08X'", status);
}
}
return ret_val;
};
esphome::optional<double> get_volume_flow_lh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint8_t l_field = telegram[0];
uint8_t tpl_ci_field = telegram[19];
if (tpl_ci_field == 0x78) {
ret_val = this->get_023B(telegram);
}
else if ((tpl_ci_field == 0x79) && (l_field > 49)) {
uint16_t signature = ((uint16_t)telegram[20] << 8) | telegram[21];
ESP_LOGVV(TAG, "Signature of message is: '%X'", signature);
if (signature == 0xF3A9) {
uint32_t flow{0};
uint8_t i = 22;
flow = (((uint32_t)telegram[i+1] << 8) | ((uint32_t)telegram[i+0]));
ret_val = (double)flow;
ESP_LOGVV(TAG, "Found volume_flow with '%d'->'%f'", flow, ret_val.value());
}
}
return ret_val;
};
esphome::optional<double> get_min_flow_lh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint8_t l_field = telegram[0];
uint8_t tpl_ci_field = telegram[19];
if (tpl_ci_field == 0x78) {
ret_val = this->get_523B(telegram);
}
else if ((tpl_ci_field == 0x79) && (l_field > 49)) {
uint16_t signature = ((uint16_t)telegram[20] << 8) | telegram[21];
ESP_LOGVV(TAG, "Signature of message is: '%X'", signature);
if (signature == 0xF3A9) {
uint32_t flow{0};
uint8_t i = 27;
flow = (((uint32_t)telegram[i+1] << 8) | ((uint32_t)telegram[i+0]));
ret_val = (double)flow;
ESP_LOGVV(TAG, "Found min_flow with '%d'->'%f'", flow, ret_val.value());
}
}
return ret_val;
};
esphome::optional<double> get_max_flow_lh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint8_t l_field = telegram[0];
uint8_t tpl_ci_field = telegram[19];
if (tpl_ci_field == 0x78) {
ret_val = this->get_523B(telegram);
}
else if ((tpl_ci_field == 0x79) && (l_field > 49)) {
uint16_t signature = ((uint16_t)telegram[20] << 8) | telegram[21];
ESP_LOGVV(TAG, "Signature of message is: '%X'", signature);
if (signature == 0xF3A9) {
uint32_t flow{0};
uint8_t i = 40;
flow = (((uint32_t)telegram[i+1] << 8) | ((uint32_t)telegram[i+0]));
ret_val = (double)flow;
ESP_LOGVV(TAG, "Found max_flow with '%d'->'%f'", flow, ret_val.value());
}
}
return ret_val;
};
};