2020-02-11 21:35:57 +00:00
|
|
|
/*
|
2020-10-04 20:52:05 +00:00
|
|
|
Copyright (C) 2019-2020 Fredrik Öhrström
|
2020-02-11 21:35:57 +00:00
|
|
|
|
|
|
|
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"dvparser.h"
|
|
|
|
#include"meters.h"
|
|
|
|
#include"meters_common_implementation.h"
|
|
|
|
#include"wmbus.h"
|
|
|
|
#include"wmbus_utils.h"
|
|
|
|
#include"units.h"
|
|
|
|
#include"util.h"
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
struct MeterFHKVDataIII : public virtual HeatCostMeter, public virtual MeterCommonImplementation
|
|
|
|
{
|
2020-08-30 19:33:48 +00:00
|
|
|
MeterFHKVDataIII(MeterInfo &mi);
|
2020-02-11 21:35:57 +00:00
|
|
|
|
|
|
|
double currentPeriodEnergyConsumption(Unit u);
|
|
|
|
string currentPeriodDate();
|
|
|
|
double previousPeriodEnergyConsumption(Unit u);
|
|
|
|
string previousPeriodDate();
|
|
|
|
double currentRoomTemperature(Unit u);
|
|
|
|
double currentRadiatorTemperature(Unit u);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void processContent(Telegram *t);
|
|
|
|
|
|
|
|
string leadingZeroString(int num);
|
|
|
|
|
|
|
|
double curr_energy_hca_ {};
|
|
|
|
string curr_energy_hca_date {};
|
|
|
|
double prev_energy_hca_ {};
|
|
|
|
string prev_energy_hca_date {};
|
|
|
|
double temp_room_ {};
|
|
|
|
double temp_radiator_ {};
|
|
|
|
};
|
|
|
|
|
2020-09-21 19:55:21 +00:00
|
|
|
shared_ptr<HeatCostMeter> createFHKVDataIII(MeterInfo &mi)
|
2020-02-11 21:35:57 +00:00
|
|
|
{
|
2020-09-21 19:55:21 +00:00
|
|
|
return shared_ptr<HeatCostMeter>(new MeterFHKVDataIII(mi));
|
2020-02-11 21:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 19:33:48 +00:00
|
|
|
MeterFHKVDataIII::MeterFHKVDataIII(MeterInfo &mi) :
|
2020-09-04 11:17:09 +00:00
|
|
|
MeterCommonImplementation(mi, MeterType::FHKVDATAIII)
|
2020-02-11 21:35:57 +00:00
|
|
|
{
|
2020-09-04 09:31:49 +00:00
|
|
|
// media 0x80 T telegrams
|
2020-02-11 21:35:57 +00:00
|
|
|
addLinkMode(LinkMode::T1);
|
|
|
|
|
|
|
|
addPrint("current", Quantity::HCA,
|
|
|
|
[&](Unit u){ return currentPeriodEnergyConsumption(u); },
|
|
|
|
"Energy consumption so far in this billing period.",
|
|
|
|
true, true);
|
|
|
|
|
|
|
|
addPrint("current_date", Quantity::Text,
|
|
|
|
[&](){ return currentPeriodDate(); },
|
|
|
|
"Date of current billing period.",
|
|
|
|
true, true);
|
|
|
|
|
|
|
|
addPrint("previous", Quantity::HCA,
|
|
|
|
[&](Unit u){ return previousPeriodEnergyConsumption(u); },
|
|
|
|
"Energy consumption in previous billing period.",
|
|
|
|
true, true);
|
|
|
|
|
|
|
|
addPrint("previous_date", Quantity::Text,
|
|
|
|
[&](){ return previousPeriodDate(); },
|
|
|
|
"Date of last billing period.",
|
|
|
|
true, true);
|
|
|
|
|
|
|
|
addPrint("temp_room", Quantity::Temperature,
|
|
|
|
[&](Unit u){ return currentRoomTemperature(u); },
|
|
|
|
"Current room temperature.",
|
|
|
|
true, true);
|
|
|
|
|
|
|
|
addPrint("temp_radiator", Quantity::Temperature,
|
|
|
|
[&](Unit u){ return currentRadiatorTemperature(u); },
|
|
|
|
"Current radiator temperature.",
|
|
|
|
true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
double MeterFHKVDataIII::currentPeriodEnergyConsumption(Unit u)
|
|
|
|
{
|
|
|
|
return curr_energy_hca_;
|
|
|
|
}
|
|
|
|
|
|
|
|
string MeterFHKVDataIII::currentPeriodDate()
|
|
|
|
{
|
|
|
|
return curr_energy_hca_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
double MeterFHKVDataIII::previousPeriodEnergyConsumption(Unit u)
|
|
|
|
{
|
|
|
|
return prev_energy_hca_;
|
|
|
|
}
|
|
|
|
|
|
|
|
string MeterFHKVDataIII::previousPeriodDate()
|
|
|
|
{
|
|
|
|
return prev_energy_hca_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
double MeterFHKVDataIII::currentRoomTemperature(Unit u)
|
|
|
|
{
|
|
|
|
assertQuantity(u, Quantity::Temperature);
|
|
|
|
return convert(temp_room_, Unit::C, u);
|
|
|
|
}
|
|
|
|
|
|
|
|
double MeterFHKVDataIII::currentRadiatorTemperature(Unit u)
|
|
|
|
{
|
|
|
|
assertQuantity(u, Quantity::Temperature);
|
|
|
|
return convert(temp_radiator_, Unit::C, u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeterFHKVDataIII::processContent(Telegram *t)
|
|
|
|
{
|
|
|
|
// Unfortunately, the Techem FHKV data ii/iii is mostly a proprieatary protocol
|
|
|
|
// simple wrapped inside a wmbus telegram since the ci-field is 0xa0.
|
|
|
|
// Which means that the entire payload is manufacturer specific.
|
|
|
|
|
|
|
|
vector<uchar> content;
|
|
|
|
|
|
|
|
t->extractPayload(&content);
|
2020-02-12 06:52:29 +00:00
|
|
|
|
2020-02-11 21:35:57 +00:00
|
|
|
// Consumption
|
|
|
|
// Previous Consumption
|
|
|
|
uchar prev_lo = content[14];
|
|
|
|
uchar prev_hi = content[15];
|
|
|
|
double prev = (256.0*prev_hi+prev_lo);
|
|
|
|
prev_energy_hca_ = prev;
|
|
|
|
|
|
|
|
string prevs;
|
|
|
|
strprintf(prevs, "%02x%02x", prev_lo, prev_hi);
|
2020-02-12 06:52:29 +00:00
|
|
|
//t->addMoreExplanation(14, " energy used in previous billing period (%f HCA)", prevs);
|
2020-02-11 21:35:57 +00:00
|
|
|
|
|
|
|
// Previous Date
|
|
|
|
uchar date_prev_lo = content[12];
|
|
|
|
uchar date_prev_hi = content[13];
|
|
|
|
int date_prev = (256.0*date_prev_hi+date_prev_lo);
|
|
|
|
|
|
|
|
int day_prev = (date_prev >> 0) & 0x1F;
|
|
|
|
int month_prev = (date_prev >> 5) & 0x0F;
|
|
|
|
int year_prev = (date_prev >> 9) & 0x3F;
|
|
|
|
prev_energy_hca_date = std::to_string((year_prev + 2000)) + "-" + leadingZeroString(month_prev) + "-" + leadingZeroString(day_prev) + "T02:00:00Z";
|
|
|
|
|
2020-02-12 06:52:29 +00:00
|
|
|
//t->addMoreExplanation(offset, " last date of previous billing period (%s)", prev_energy_hca_date);
|
2020-02-11 21:35:57 +00:00
|
|
|
|
|
|
|
// Current Consumption
|
|
|
|
uchar curr_lo = content[18];
|
|
|
|
uchar curr_hi = content[19];
|
|
|
|
double curr = (256.0*curr_hi+curr_lo);
|
|
|
|
curr_energy_hca_ = curr;
|
|
|
|
|
|
|
|
string currs;
|
|
|
|
strprintf(currs, "%02x%02x", curr_lo, curr_hi);
|
2020-02-12 06:52:29 +00:00
|
|
|
//t->addMoreExplanation(offset, " energy used in current billing period (%f HCA)", currs);
|
2020-02-11 21:35:57 +00:00
|
|
|
|
|
|
|
// Current Date
|
|
|
|
uchar date_curr_lo = content[16];
|
|
|
|
uchar date_curr_hi = content[17];
|
|
|
|
int date_curr = (256.0*date_curr_hi+date_curr_lo);
|
|
|
|
|
|
|
|
time_t now = time(0);
|
|
|
|
tm *ltm = localtime(&now);
|
|
|
|
int year_curr = 1900 + ltm->tm_year;
|
|
|
|
|
|
|
|
int day_curr = (date_curr >> 4) & 0x1F;
|
|
|
|
if (day_curr <= 0) day_curr = 1;
|
|
|
|
int month_curr = (date_curr >> 9) & 0x0F;
|
|
|
|
if (month_curr <= 0) month_curr = 12;
|
2020-02-12 06:52:29 +00:00
|
|
|
curr_energy_hca_date = to_string(year_curr) + "-" + leadingZeroString(month_curr) + "-" + leadingZeroString(day_curr) + "T02:00:00Z";
|
2020-02-11 21:35:57 +00:00
|
|
|
|
2020-02-12 06:52:29 +00:00
|
|
|
// t->addMoreExplanation(offset, " last date of current billing period (%s)", curr_energy_hca_date);
|
2020-02-11 21:35:57 +00:00
|
|
|
|
|
|
|
// Temperature
|
|
|
|
// Room Temperature
|
|
|
|
uchar room_tlo = content[20];
|
|
|
|
uchar room_thi = content[21];
|
|
|
|
double room_t = (256.0*room_thi+room_tlo)/100;
|
|
|
|
temp_room_ = room_t;
|
|
|
|
|
|
|
|
string room_ts;
|
|
|
|
strprintf(room_ts, "%02x%02x", room_tlo, room_thi);
|
2020-02-12 06:52:29 +00:00
|
|
|
// t->addMoreExplanation(offset, " current room temparature (%f °C)", room_ts);
|
2020-02-11 21:35:57 +00:00
|
|
|
|
|
|
|
// Radiator Temperature
|
|
|
|
uchar radiator_tlo = content[22];
|
|
|
|
uchar radiator_thi = content[23];
|
|
|
|
double radiator_t = (256.0*radiator_thi+radiator_tlo)/100;
|
|
|
|
temp_radiator_ = radiator_t;
|
|
|
|
|
|
|
|
string radiator_ts;
|
|
|
|
strprintf(radiator_ts, "%02x%02x", radiator_tlo, radiator_thi);
|
2020-02-12 06:52:29 +00:00
|
|
|
// t->addMoreExplanation(offset, " current radiator temparature (%f °C)", radiator_ts);
|
2020-02-11 21:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string MeterFHKVDataIII::leadingZeroString(int num) {
|
|
|
|
string new_num = (num < 10 ? "0": "") + std::to_string(num);
|
|
|
|
return new_num;
|
2020-02-12 06:52:29 +00:00
|
|
|
}
|