-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdriver_apatorna1.cc
More file actions
88 lines (67 loc) · 3.06 KB
/
Copy pathdriver_apatorna1.cc
File metadata and controls
88 lines (67 loc) · 3.06 KB
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
/*
Copyright (C) 2017-2022 Fredrik Öhrström (gpl-3.0-or-later)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include"meters_common_implementation.h"
#include "wmbus_utils.h"
#include <cmath>
namespace
{
struct Driver : public virtual MeterCommonImplementation
{
Driver(MeterInfo &mi, DriverInfo &di);
void processContent(Telegram *t);
};
static bool ok = registerDriver([](DriverInfo&di)
{
di.setName("apatorna1");
di.setDefaultFields("name,id,total_m3,timestamp");
di.setMeterType(MeterType::WaterMeter);
di.addDetection(MANUFACTURER_APA, 0x07, 0x14);
di.usesProcessContent();
di.setConstructor([](MeterInfo& mi, DriverInfo& di){ return std::shared_ptr<Meter>(new Driver(mi, di)); });
});
Driver::Driver(MeterInfo &mi, DriverInfo &di) : MeterCommonImplementation(mi, di)
{
addNumericField(
"total",
Quantity::Volume,
DEFAULT_PRINT_PROPERTIES,
"The total water consumption recorded by this meter.");
}
void Driver::processContent(Telegram *t)
{
std::vector<uchar> content;
t->extractPayload(&content);
if (content.size() < 4) return;
std::vector<uchar> frame(content.begin() + 2, content.begin() + 18);
std::vector<uchar>::iterator pos = frame.begin();
// TODO: read specified key from input
std::vector<uchar> aes_key(16, 0);
int num_encrypted_bytes = 0;
int num_not_encrypted_at_end = 0;
t->tpl_acc = content[0]; //0xBB;
decrypt_TPL_AES_CBC_IV(t, frame, pos, aes_key, &num_encrypted_bytes, &num_not_encrypted_at_end);
const int multiplier = pow(10, (frame.at(1) & 0b00110000) >> 4);
const int reading = static_cast<int>(frame.at(4)) << 20 |
static_cast<int>(frame.at(3)) << 12 |
static_cast<int>(frame.at(2)) << 4 |
(static_cast<int>(frame.at(1)) & 0b00001111);
const double volume = static_cast<double>(reading) * multiplier / 1000;
debug("Volume: %.3f \n", volume);
setNumericValue("total", Unit::M3, volume);
}
}
// Test: ApNa1 apatorna1 04913581 00000000000000000000000000000000
// telegram=|1C440106813591041407A0B000266A705474DDB80D9A0EB9AE2EF29D96|
// {"_":"telegram","media":"water","meter":"apatorna1","name":"ApNa1","id":"04913581","total_m3":345.312,"timestamp":"1111-11-11T11:11:11Z"}
// |ApNa1;04913581;345.312;1111-11-11 11:11.11