wmbusmeters/src/meters_common_implementation.h

124 wiersze
3.9 KiB
C
Czysty Zwykły widok Historia

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/>.
*/
#ifndef METERS_COMMON_IMPLEMENTATION_H_
#define METERS_COMMON_IMPLEMENTATION_H_
#include"meters.h"
2019-05-04 06:52:25 +00:00
#include"units.h"
#include<map>
#include<set>
2019-05-04 09:10:09 +00:00
struct Print
{
string vname; // Value name, like: total current previous target
Quantity quantity; // Quantity: Energy, Volume
Unit default_unit; // Default unit for above quantity: KWH, M3
2019-05-04 17:56:17 +00:00
function<double(Unit)> getValueDouble; // Callback to fetch the value from the meter.
function<string()> getValueString; // 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 17:56:17 +00:00
bool json; // If true, print in json and shell env variables.
2019-05-04 09:10:09 +00:00
};
struct MeterCommonImplementation : public virtual Meter
{
vector<string> ids();
string name();
MeterType type();
vector<int> media();
WMBus *bus();
string datetimeOfUpdateHumanReadable();
string datetimeOfUpdateRobot();
void onUpdate(function<void(Telegram*,Meter*)> cb);
int numUpdates();
2019-05-04 17:56:17 +00:00
EncryptionMode encMode();
bool isTelegramForMe(Telegram *t);
bool useAes();
vector<uchar> key();
std::vector<std::string> getRecords();
double getRecordAsDouble(std::string record);
uint16_t getRecordAsUInt16(std::string record);
MeterCommonImplementation(WMBus *bus, MeterInfo &mi,
MeterType type, int manufacturer);
~MeterCommonImplementation() = default;
string meterName() { return toMeterName(type_); }
protected:
void triggerUpdate(Telegram *t);
2019-05-04 17:56:17 +00:00
void setExpectedVersion(int version);
int expectedVersion();
void addConversions(std::vector<Unit> cs);
void addShell(std::string cmdline);
void addJson(std::string json);
std::vector<std::string> &shellCmdlines();
std::vector<std::string> &additionalJsons();
void addMedia(int media);
void addLinkMode(LinkMode lm);
void addManufacturer(int m);
2019-05-04 17:56:17 +00:00
void addPrint(string vname, Quantity vquantity,
function<double(Unit)> getValueFunc, string help, bool field, bool json);
void addPrint(string vname, Quantity vquantity,
function<std::string()> getValueFunc, string help, bool field, bool json);
void setEncryptionMode(EncryptionMode em);
EncryptionMode encryptionMode();
void handleTelegram(Telegram *t);
void printMeter(Telegram *t,
string *human_readable,
string *fields, char separator,
string *json,
vector<string> *envs,
vector<string> *more_json); // Add this json "key"="value" strings.
virtual void processContent(Telegram *t) = 0;
private:
MeterType type_ {};
2019-05-04 17:56:17 +00:00
int expected_meter_version_ {};
vector<int> media_;
set<int> manufacturers_;
string name_;
vector<string> ids_;
vector<uchar> key_;
WMBus *bus_ {};
vector<function<void(Telegram*,Meter*)>> on_update_;
int num_updates_ {};
bool use_aes_ {};
time_t datetime_of_update_ {};
LinkModeSet link_modes_ {};
2019-05-04 17:56:17 +00:00
EncryptionMode enc_mode_ {};
vector<string> shell_cmdlines_;
vector<string> jsons_;
protected:
std::map<std::string,std::pair<int,std::string>> values_;
vector<Unit> conversions_;
vector<Print> prints_;
};
#endif