2018-04-01 06:53:37 +00:00
|
|
|
/*
|
2019-02-24 14:20:55 +00:00
|
|
|
Copyright (C) 2018-2019 Fredrik Öhrström
|
2018-04-01 06:53:37 +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/>.
|
|
|
|
*/
|
2018-03-05 10:29:25 +00:00
|
|
|
|
|
|
|
#ifndef METERS_COMMON_IMPLEMENTATION_H_
|
|
|
|
#define METERS_COMMON_IMPLEMENTATION_H_
|
|
|
|
|
|
|
|
#include"meters.h"
|
2019-05-04 06:52:25 +00:00
|
|
|
#include"units.h"
|
2018-03-05 10:29:25 +00:00
|
|
|
|
2018-04-20 09:42:46 +00:00
|
|
|
#include<map>
|
2019-04-01 21:49:24 +00:00
|
|
|
#include<set>
|
2018-04-20 09:42:46 +00:00
|
|
|
|
2019-05-04 09:10:09 +00:00
|
|
|
struct Print
|
|
|
|
{
|
2019-05-04 11:55:52 +00:00
|
|
|
string vname; // Value name, like: total current previous target
|
|
|
|
Quantity quantity; // Quantity: Energy, Volume
|
|
|
|
Unit default_unit; // Default unit for above quantity: KWH, M3
|
|
|
|
function<double(Unit)> getValueFunc; // Callback to fetch the value from the meter.
|
|
|
|
string help; // Helpful information on this meters use of this value.
|
|
|
|
bool field; // If true, print in hr/fields output.
|
2019-05-04 09:10:09 +00:00
|
|
|
};
|
|
|
|
|
2018-12-28 17:35:32 +00:00
|
|
|
struct MeterCommonImplementation : public virtual Meter
|
|
|
|
{
|
2019-03-05 20:19:05 +00:00
|
|
|
vector<string> ids();
|
2018-03-05 10:29:25 +00:00
|
|
|
string name();
|
|
|
|
MeterType type();
|
2019-03-05 20:19:05 +00:00
|
|
|
vector<int> media();
|
2018-03-05 10:29:25 +00:00
|
|
|
WMBus *bus();
|
2018-11-01 16:17:23 +00:00
|
|
|
LinkMode requiredLinkMode();
|
2018-03-05 10:29:25 +00:00
|
|
|
|
|
|
|
string datetimeOfUpdateHumanReadable();
|
|
|
|
string datetimeOfUpdateRobot();
|
|
|
|
|
2019-03-05 20:19:05 +00:00
|
|
|
void onUpdate(function<void(Telegram*,Meter*)> cb);
|
2018-03-05 10:29:25 +00:00
|
|
|
int numUpdates();
|
|
|
|
|
|
|
|
bool isTelegramForMe(Telegram *t);
|
|
|
|
bool useAes();
|
|
|
|
vector<uchar> key();
|
|
|
|
|
2018-04-20 09:42:46 +00:00
|
|
|
std::vector<std::string> getRecords();
|
|
|
|
double getRecordAsDouble(std::string record);
|
|
|
|
uint16_t getRecordAsUInt16(std::string record);
|
|
|
|
|
2019-02-23 12:41:17 +00:00
|
|
|
MeterCommonImplementation(WMBus *bus, string& name, string& id, string& key,
|
2019-03-05 20:19:05 +00:00
|
|
|
MeterType type, int manufacturer,
|
2018-11-01 16:17:23 +00:00
|
|
|
LinkMode required_link_mode);
|
2018-03-05 10:29:25 +00:00
|
|
|
|
2018-12-28 17:35:32 +00:00
|
|
|
~MeterCommonImplementation() = default;
|
|
|
|
|
2019-05-04 08:52:18 +00:00
|
|
|
string meterName() { return toMeterName(type_); }
|
|
|
|
|
2018-03-05 10:29:25 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void triggerUpdate(Telegram *t);
|
2019-05-04 11:55:52 +00:00
|
|
|
void addConversions(std::vector<Unit> cs);
|
2019-03-05 20:19:05 +00:00
|
|
|
void addMedia(int media);
|
2019-04-01 21:49:24 +00:00
|
|
|
void addManufacturer(int m);
|
2019-05-04 11:55:52 +00:00
|
|
|
void addPrint(string vname, Quantity vquantity, function<double(Unit)> getValueFunc, string help, bool field);
|
2018-03-05 10:29:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
MeterType type_ {};
|
2019-04-01 21:49:24 +00:00
|
|
|
vector<int> media_;
|
|
|
|
set<int> manufacturers_;
|
2018-03-05 10:29:25 +00:00
|
|
|
string name_;
|
2019-03-05 20:19:05 +00:00
|
|
|
vector<string> ids_;
|
2018-03-05 10:29:25 +00:00
|
|
|
vector<uchar> key_;
|
|
|
|
WMBus *bus_ {};
|
2019-03-05 20:19:05 +00:00
|
|
|
vector<function<void(Telegram*,Meter*)>> on_update_;
|
2018-03-05 10:29:25 +00:00
|
|
|
int num_updates_ {};
|
|
|
|
bool use_aes_ {};
|
|
|
|
time_t datetime_of_update_ {};
|
2018-11-01 16:17:23 +00:00
|
|
|
LinkMode required_link_mode_ {};
|
2018-04-20 09:42:46 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::map<std::string,std::pair<int,std::string>> values_;
|
2019-05-04 11:55:52 +00:00
|
|
|
vector<Unit> conversions_;
|
|
|
|
vector<Print> prints_;
|
2018-03-05 10:29:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|