forked from SzczepanLeon/wmbus-drivers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver_compact5.h
executable file
·48 lines (36 loc) · 1.27 KB
/
driver_compact5.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
/*
Based on: https://github.com/wmbusmeters/wmbusmeters/blob/master/src/driver_compact5.cc
Copyright (C) 2019-2022 Fredrik Öhrström (gpl-3.0-or-later)
*/
#pragma once
#include "driver.h"
#include <vector>
#include <string>
struct Compact5: Driver
{
Compact5(std::string key = "") : Driver(std::string("compact5"), 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, "current_heating_kwh", this->get_current_heating_kwh(telegram));
add_to_map(ret_val, "previous_heating_kwh", this->get_previous_heating_kwh(telegram));
if (ret_val.size() > 0) {
return ret_val;
}
else {
return {};
}
};
private:
esphome::optional<double> get_current_heating_kwh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
size_t i = 11;
ret_val = (((uint32_t)telegram[i+8] << 8) + (uint32_t)telegram[i+7]);
return ret_val;
};
esphome::optional<double> get_previous_heating_kwh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
size_t i = 11;
ret_val = (((uint32_t)telegram[i+4] << 8) + (uint32_t)telegram[i+3]);
return ret_val;
};
};