2018-04-01 06:53:37 +00:00
|
|
|
/*
|
2022-04-19 07:10:14 +00:00
|
|
|
Copyright (C) 2017-2022 Fredrik Öhrström (gpl-3.0-or-later)
|
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/>.
|
|
|
|
*/
|
2017-08-09 10:00:11 +00:00
|
|
|
|
|
|
|
#ifndef METER_H_
|
|
|
|
#define METER_H_
|
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
#include"dvparser.h"
|
2017-08-09 10:00:11 +00:00
|
|
|
#include"util.h"
|
2019-05-04 11:07:37 +00:00
|
|
|
#include"units.h"
|
2022-01-08 14:50:15 +00:00
|
|
|
#include"translatebits.h"
|
2017-08-09 10:00:11 +00:00
|
|
|
#include"wmbus.h"
|
|
|
|
|
2022-04-11 12:01:54 +00:00
|
|
|
#include<assert.h>
|
2020-09-07 08:36:39 +00:00
|
|
|
#include<functional>
|
2021-02-20 21:21:01 +00:00
|
|
|
#include<numeric>
|
|
|
|
#include<string>
|
2017-08-09 10:00:11 +00:00
|
|
|
#include<vector>
|
|
|
|
|
2022-04-11 12:01:54 +00:00
|
|
|
|
2021-12-31 11:27:57 +00:00
|
|
|
#define LIST_OF_METER_TYPES \
|
2022-01-06 17:28:22 +00:00
|
|
|
X(AutoMeter) \
|
2021-12-31 11:27:57 +00:00
|
|
|
X(UnknownMeter) \
|
|
|
|
X(DoorWindowDetector) \
|
|
|
|
X(ElectricityMeter) \
|
|
|
|
X(GasMeter) \
|
|
|
|
X(HeatCostAllocationMeter) \
|
|
|
|
X(HeatMeter) \
|
|
|
|
X(PulseCounter) \
|
|
|
|
X(SmokeDetector) \
|
|
|
|
X(TempHygroMeter) \
|
|
|
|
X(WaterMeter) \
|
|
|
|
|
|
|
|
enum class MeterType {
|
|
|
|
#define X(name) name,
|
|
|
|
LIST_OF_METER_TYPES
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
2022-02-09 13:52:13 +00:00
|
|
|
// This is the old style meter list. Drivers are succesively rewritten
|
|
|
|
// from meter_xyz.cc to driver_xyz.cc only old style drivers are listed here.
|
|
|
|
// The new driver_xyz.cc file format is selfcontained so eventually this
|
|
|
|
// macro LIST_OF_METERS will be empty and go away.
|
|
|
|
|
2019-05-04 08:52:18 +00:00
|
|
|
#define LIST_OF_METERS \
|
2022-01-06 17:28:22 +00:00
|
|
|
X(auto, 0, AutoMeter, AUTO, Auto) \
|
2021-03-07 18:52:21 +00:00
|
|
|
X(unknown, 0, UnknownMeter, UNKNOWN, Unknown) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(apator162, C1_bit|T1_bit, WaterMeter, APATOR162, Apator162) \
|
2021-10-24 15:54:36 +00:00
|
|
|
X(bfw240radio,T1_bit, HeatCostAllocationMeter, BFW240RADIO, BFW240Radio) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(cma12w, C1_bit|T1_bit, TempHygroMeter, CMA12W, CMa12w) \
|
|
|
|
X(compact5, T1_bit, HeatMeter, COMPACT5, Compact5) \
|
2021-04-10 15:58:32 +00:00
|
|
|
X(dme_07, T1_bit, WaterMeter, DME_07, DME_07) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(ebzwmbe, T1_bit, ElectricityMeter, EBZWMBE, EBZWMBE) \
|
|
|
|
X(eurisii, T1_bit, HeatCostAllocationMeter, EURISII, EurisII) \
|
|
|
|
X(ehzp, T1_bit, ElectricityMeter, EHZP, EHZP) \
|
|
|
|
X(esyswm, T1_bit, ElectricityMeter, ESYSWM, ESYSWM) \
|
2021-03-07 13:39:52 +00:00
|
|
|
X(ei6500, C1_bit, SmokeDetector, EI6500, EI6500) \
|
2021-02-14 21:55:25 +00:00
|
|
|
X(elf, T1_bit, HeatMeter, ELF, Elf) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(em24, C1_bit, ElectricityMeter, EM24, EM24) \
|
|
|
|
X(emerlin868, T1_bit, WaterMeter, EMERLIN868, EMerlin868) \
|
|
|
|
X(ev200, T1_bit, WaterMeter, EV200, EV200) \
|
2021-01-26 21:22:59 +00:00
|
|
|
X(evo868, T1_bit, WaterMeter, EVO868, EVO868) \
|
2021-01-06 18:48:56 +00:00
|
|
|
X(fhkvdataiii,T1_bit, HeatCostAllocationMeter, FHKVDATAIII, FHKVDataIII) \
|
|
|
|
X(fhkvdataiv, T1_bit, HeatCostAllocationMeter, FHKVDATAIV, FHKVDataIV) \
|
2021-03-07 13:39:52 +00:00
|
|
|
X(gransystems,T1_bit, ElectricityMeter, CCx01, CCx01) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(hydrus, T1_bit, WaterMeter, HYDRUS, Hydrus) \
|
2021-01-06 18:48:56 +00:00
|
|
|
X(hydrocalm3, T1_bit, HeatMeter, HYDROCALM3, HydrocalM3) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(hydrodigit, T1_bit, WaterMeter, HYDRODIGIT, Hydrodigit) \
|
|
|
|
X(izar, T1_bit, WaterMeter, IZAR, Izar) \
|
|
|
|
X(izar3, T1_bit, WaterMeter, IZAR3, Izar3) \
|
|
|
|
X(lansensm, T1_bit, SmokeDetector, LANSENSM, LansenSM) \
|
|
|
|
X(lansenth, T1_bit, TempHygroMeter, LANSENTH, LansenTH) \
|
|
|
|
X(lansenpu, T1_bit, PulseCounter, LANSENPU, LansenPU) \
|
|
|
|
X(mkradio3, T1_bit, WaterMeter, MKRADIO3, MKRadio3) \
|
2020-11-22 19:39:28 +00:00
|
|
|
X(mkradio4, T1_bit, WaterMeter, MKRADIO4, MKRadio4) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(multical21, C1_bit|T1_bit, WaterMeter, MULTICAL21, Multical21) \
|
2021-12-07 23:55:50 +00:00
|
|
|
X(flowiq2200, C1_bit, WaterMeter, FLOWIQ2200, FlowIQ2200) \
|
|
|
|
X(flowiq3100, C1_bit, WaterMeter, FLOWIQ3100, FlowIQ3100) \
|
2021-01-24 19:36:59 +00:00
|
|
|
X(multical302,C1_bit|T1_bit, HeatMeter, MULTICAL302, Multical302) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(multical403,C1_bit, HeatMeter, MULTICAL403, Multical403) \
|
2021-10-02 09:36:33 +00:00
|
|
|
X(multical602,C1_bit, HeatMeter, MULTICAL602, Multical602) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(multical603,C1_bit, HeatMeter, MULTICAL603, Multical603) \
|
2020-12-05 11:01:33 +00:00
|
|
|
X(multical803,C1_bit, HeatMeter, MULTICAL803, Multical803) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(omnipower, C1_bit, ElectricityMeter, OMNIPOWER, Omnipower) \
|
|
|
|
X(rfmamb, T1_bit, TempHygroMeter, RFMAMB, RfmAmb) \
|
|
|
|
X(rfmtx1, T1_bit, WaterMeter, RFMTX1, RfmTX1) \
|
2020-12-31 13:46:05 +00:00
|
|
|
X(tsd2, T1_bit, SmokeDetector, TSD2, TSD2) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(q400, T1_bit, WaterMeter, Q400, Q400) \
|
|
|
|
X(qcaloric, C1_bit, HeatCostAllocationMeter, QCALORIC, QCaloric) \
|
2021-10-24 15:18:53 +00:00
|
|
|
X(qheat, T1_bit, HeatMeter, QHEAT, QHeat) \
|
2021-11-28 17:23:42 +00:00
|
|
|
X(qsmoke, T1_bit, SmokeDetector, QSMOKE, QSmoke) \
|
2021-03-07 13:39:52 +00:00
|
|
|
X(sensostar, C1_bit|T1_bit, HeatMeter,SENSOSTAR, Sensostar) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(sontex868, T1_bit, HeatCostAllocationMeter, SONTEX868, Sontex868) \
|
2021-03-07 13:39:52 +00:00
|
|
|
X(topaseskr, T1_bit, WaterMeter, TOPASESKR, TopasEsKr) \
|
2020-11-14 09:48:49 +00:00
|
|
|
X(ultrimis, T1_bit, WaterMeter, ULTRIMIS, Ultrimis) \
|
|
|
|
X(vario451, T1_bit, HeatMeter, VARIO451, Vario451) \
|
|
|
|
X(waterstarm, C1_bit|T1_bit, WaterMeter,WATERSTARM, WaterstarM) \
|
2020-12-28 18:20:31 +00:00
|
|
|
X(whe46x, S1_bit, HeatCostAllocationMeter, WHE46X, Whe46x) \
|
2021-03-06 06:42:37 +00:00
|
|
|
X(whe5x, S1_bit, HeatCostAllocationMeter, WHE5X, Whe5x) \
|
2021-03-07 17:52:36 +00:00
|
|
|
X(lse_08, S1_bit|C1_bit, HeatCostAllocationMeter, LSE_08, LSE_08) \
|
2021-03-07 13:39:52 +00:00
|
|
|
X(weh_07, C1_bit, WaterMeter, WEH_07, WEH_07) \
|
2021-09-23 10:06:12 +00:00
|
|
|
X(unismart, T1_bit, GasMeter, UNISMART, Unismart) \
|
2021-10-16 09:41:48 +00:00
|
|
|
X(munia, T1_bit, TempHygroMeter, MUNIA, Munia) \
|
2019-05-04 08:52:18 +00:00
|
|
|
|
2021-03-08 07:40:48 +00:00
|
|
|
enum class MeterDriver {
|
2019-05-04 08:52:18 +00:00
|
|
|
#define X(mname,linkmode,info,type,cname) type,
|
2018-03-05 10:29:25 +00:00
|
|
|
LIST_OF_METERS
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
struct DriverName
|
|
|
|
{
|
|
|
|
DriverName() {};
|
|
|
|
DriverName(string s) : name_(s) {};
|
|
|
|
string str() { return name_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
string name_;
|
|
|
|
};
|
|
|
|
|
2020-09-04 09:31:49 +00:00
|
|
|
struct MeterMatch
|
|
|
|
{
|
2021-03-08 07:40:48 +00:00
|
|
|
MeterDriver driver;
|
2020-09-04 09:31:49 +00:00
|
|
|
int manufacturer;
|
|
|
|
int media;
|
|
|
|
int version;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return a list of matching drivers, like: multical21
|
2021-03-07 18:52:21 +00:00
|
|
|
void detectMeterDrivers(int manufacturer, int media, int version, std::vector<std::string> *drivers);
|
2020-09-04 09:31:49 +00:00
|
|
|
// When entering the driver, check that the telegram is indeed known to be
|
|
|
|
// compatible with the driver(type), if not then print a warning.
|
2021-03-08 07:40:48 +00:00
|
|
|
bool isMeterDriverValid(MeterDriver type, int manufacturer, int media, int version);
|
2022-01-25 20:21:17 +00:00
|
|
|
// For an unknown telegram, when analyzing check if the media type is reasonable in relation to the driver.
|
|
|
|
// Ie. do not try to decode a door sensor telegram with a water meter driver.
|
|
|
|
bool isMeterDriverReasonableForMedia(MeterDriver type, string driver_name, int media);
|
2020-09-04 09:31:49 +00:00
|
|
|
|
2021-03-14 08:41:35 +00:00
|
|
|
bool isValidKey(string& key, MeterDriver mt);
|
|
|
|
|
2017-08-09 10:00:11 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
typedef unsigned char uchar;
|
|
|
|
|
2019-05-21 12:19:54 +00:00
|
|
|
struct MeterInfo
|
|
|
|
{
|
2021-02-20 07:24:33 +00:00
|
|
|
string bus; // The bus used to communicate with this meter. A device like /dev/ttyUSB0 or an alias like BUS1.
|
|
|
|
// A bus can be an mbus or a wmbus dongle.
|
|
|
|
// The bus can be the empty string, which means that it will fallback to the first defined bus.
|
|
|
|
string name; // User specified name of this (group of) meters.
|
2021-03-08 07:40:48 +00:00
|
|
|
MeterDriver driver {}; // Requested driver for decoding telegrams from this meter.
|
2022-01-06 17:28:22 +00:00
|
|
|
DriverName driver_name; // Will replace MeterDriver.
|
2021-03-08 07:40:48 +00:00
|
|
|
string extras; // Extra driver specific settings.
|
2021-02-20 21:21:01 +00:00
|
|
|
vector<string> ids; // Match expressions for ids.
|
|
|
|
string idsc; // Comma separated ids.
|
2021-02-20 07:24:33 +00:00
|
|
|
string key; // Decryption key.
|
2019-06-06 15:28:20 +00:00
|
|
|
LinkModeSet link_modes;
|
2021-02-20 07:24:33 +00:00
|
|
|
int bps {}; // For mbus communication you need to know the baud rate.
|
2019-05-21 12:19:54 +00:00
|
|
|
vector<string> shells;
|
2021-08-01 22:22:13 +00:00
|
|
|
vector<string> extra_constant_fields; // Additional static fields that are added to each message.
|
2021-02-20 21:21:01 +00:00
|
|
|
vector<Unit> conversions; // Additional units desired in json.
|
2019-05-21 12:19:54 +00:00
|
|
|
|
2021-03-08 16:14:03 +00:00
|
|
|
// If this is a meter that needs to be polled.
|
|
|
|
int poll_seconds; // Poll every x seconds.
|
|
|
|
int poll_hour_offset; // Instead of
|
|
|
|
string poll_time_period; // Poll only during these hours.
|
|
|
|
|
2020-09-08 20:11:32 +00:00
|
|
|
MeterInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-13 17:35:47 +00:00
|
|
|
string str();
|
2022-01-08 17:52:06 +00:00
|
|
|
DriverName driverName();
|
2021-03-13 17:35:47 +00:00
|
|
|
|
|
|
|
MeterInfo(string b, string n, MeterDriver d, string e, vector<string> i, string k, LinkModeSet lms, int baud, vector<string> &s, vector<string> &j)
|
2019-06-06 15:28:20 +00:00
|
|
|
{
|
2021-02-20 07:24:33 +00:00
|
|
|
bus = b;
|
2019-05-21 12:19:54 +00:00
|
|
|
name = n;
|
2021-03-08 07:40:48 +00:00
|
|
|
driver = d;
|
2021-03-13 17:35:47 +00:00
|
|
|
extras = e,
|
2021-02-20 21:21:01 +00:00
|
|
|
ids = i;
|
|
|
|
idsc = toIdsCommaSeparated(ids);
|
2019-05-21 12:19:54 +00:00
|
|
|
key = k;
|
|
|
|
shells = s;
|
2021-08-01 22:22:13 +00:00
|
|
|
extra_constant_fields = j;
|
2019-06-06 15:28:20 +00:00
|
|
|
link_modes = lms;
|
2021-02-20 07:24:33 +00:00
|
|
|
bps = baud;
|
2019-05-21 12:19:54 +00:00
|
|
|
}
|
2021-03-13 17:35:47 +00:00
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
bus = "";
|
|
|
|
name = "";
|
|
|
|
driver = MeterDriver::UNKNOWN;
|
|
|
|
ids.clear();
|
|
|
|
idsc = "";
|
|
|
|
key = "";
|
|
|
|
shells.clear();
|
2021-08-01 22:22:13 +00:00
|
|
|
extra_constant_fields.clear();
|
2021-03-13 17:35:47 +00:00
|
|
|
link_modes.clear();
|
|
|
|
bps = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool parse(string name, string driver, string id, string key);
|
2019-05-21 12:19:54 +00:00
|
|
|
};
|
|
|
|
|
2022-01-02 12:08:36 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Dynamic loading of drivers based on the driver info.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct DriverDetect
|
|
|
|
{
|
|
|
|
uint16_t mfct;
|
|
|
|
uchar type;
|
|
|
|
uchar version;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DriverInfo
|
|
|
|
{
|
2022-01-06 17:28:22 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
MeterDriver driver_ {}; // Old driver enum, to go away.
|
|
|
|
DriverName name_; // auto, unknown, amiplus, lse_07_17, multical21 etc
|
|
|
|
LinkModeSet linkmodes_; // C1, T1, S1 or combinations thereof.
|
|
|
|
MeterType type_; // Water, Electricity etc.
|
|
|
|
function<shared_ptr<Meter>(MeterInfo&,DriverInfo&di)> constructor_; // Invoke this to create an instance of the driver.
|
|
|
|
vector<DriverDetect> detect_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DriverInfo() {};
|
|
|
|
DriverInfo(MeterDriver mt) : driver_(mt) {};
|
|
|
|
void setName(std::string n) { name_ = n; }
|
|
|
|
void setMeterType(MeterType t) { type_ = t; }
|
|
|
|
void setExpectedELLSecurityMode(ELLSecurityMode dsm);
|
|
|
|
void setExpectedTPLSecurityMode(TPLSecurityMode tsm);
|
|
|
|
|
|
|
|
void addLinkMode(LinkMode lm) { linkmodes_.addLinkMode(lm); }
|
|
|
|
void setConstructor(function<shared_ptr<Meter>(MeterInfo&,DriverInfo&)> c) { constructor_ = c; }
|
|
|
|
void addDetection(uint16_t mfct, uchar type, uchar ver) { detect_.push_back({ mfct, type, ver }); }
|
|
|
|
vector<DriverDetect> &detect() { return detect_; }
|
|
|
|
|
|
|
|
MeterDriver driver() { return driver_; }
|
|
|
|
DriverName name() { return name_; }
|
|
|
|
MeterType type() { return type_; }
|
|
|
|
LinkModeSet linkModes() { return linkmodes_; }
|
|
|
|
shared_ptr<Meter> construct(MeterInfo& mi) { return constructor_(mi, *this); }
|
|
|
|
bool detect(uint16_t mfct, uchar type, uchar version);
|
2022-01-25 20:21:17 +00:00
|
|
|
bool isValidMedia(uchar type);
|
2022-02-08 19:51:13 +00:00
|
|
|
bool isCloseEnoughMedia(uchar type);
|
2022-01-02 12:08:36 +00:00
|
|
|
};
|
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
bool registerDriver(function<void(DriverInfo&di)> setup);
|
|
|
|
bool lookupDriverInfo(string& driver, DriverInfo *di);
|
|
|
|
// Return the best driver match for a telegram.
|
|
|
|
DriverInfo pickMeterDriver(Telegram *t);
|
2022-02-17 18:59:51 +00:00
|
|
|
// Return true for mbus and S2/C2/T2 meters.
|
|
|
|
bool needsPolling(MeterDriver driver, DriverName& dn);
|
2022-01-02 12:08:36 +00:00
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
vector<DriverInfo>& allRegisteredDrivers();
|
2022-01-02 12:08:36 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
enum class VifScaling
|
2020-09-08 20:11:32 +00:00
|
|
|
{
|
2022-01-13 14:06:53 +00:00
|
|
|
None, // No auto scaling.
|
|
|
|
Auto, // Scale to normalized VIF unit (ie kwh, m3, m3h etc)
|
|
|
|
NoneSigned, // No auto scaling however assume the value is signed.
|
|
|
|
AutoSigned // Scale and assume the value is signed.
|
2022-01-06 17:28:22 +00:00
|
|
|
};
|
|
|
|
|
2022-04-11 12:01:54 +00:00
|
|
|
enum PrintProperty
|
|
|
|
{
|
|
|
|
JSON = 1, // This field should be printed when using --format=json
|
|
|
|
FIELD = 2, // This field should be printed when using --format=field
|
|
|
|
IMPORTANT = 4, // The most important field.
|
|
|
|
OPTIONAL = 8, // If no data has arrived, do include this field in the json output.
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PrintProperties
|
|
|
|
{
|
|
|
|
PrintProperties(int x)
|
|
|
|
{
|
|
|
|
props_ = x;
|
|
|
|
assert(x >=0 && x<=16); // No bits outside of possible PrintProperty values.
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasJSON() { return props_ & PrintProperty::JSON; }
|
|
|
|
bool hasFIELD() { return props_ & PrintProperty::FIELD; }
|
|
|
|
bool hasIMPORTANT() { return props_ & PrintProperty::IMPORTANT; }
|
|
|
|
bool hasOPTIONAL() { return props_ & PrintProperty::OPTIONAL; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int props_;
|
|
|
|
};
|
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
struct FieldInfo
|
|
|
|
{
|
|
|
|
FieldInfo(string vname,
|
|
|
|
Quantity xuantity,
|
|
|
|
Unit default_unit,
|
|
|
|
VifScaling vif_scaling,
|
2022-04-17 13:54:01 +00:00
|
|
|
FieldMatcher matcher,
|
2022-01-06 17:28:22 +00:00
|
|
|
string help,
|
2022-04-11 12:01:54 +00:00
|
|
|
PrintProperties print_properties,
|
2022-01-06 17:28:22 +00:00
|
|
|
string field_name,
|
|
|
|
function<double(Unit)> get_value_double,
|
|
|
|
function<string()> get_value_string,
|
|
|
|
function<void(Unit,double)> set_value_double,
|
|
|
|
function<void(string)> set_value_string,
|
2022-01-08 14:50:15 +00:00
|
|
|
Translate::Lookup lookup
|
2022-01-06 17:28:22 +00:00
|
|
|
) :
|
|
|
|
vname_(vname),
|
|
|
|
xuantity_(xuantity),
|
|
|
|
default_unit_(default_unit),
|
|
|
|
vif_scaling_(vif_scaling),
|
2022-04-17 13:54:01 +00:00
|
|
|
matcher_(matcher),
|
2022-01-06 17:28:22 +00:00
|
|
|
help_(help),
|
2022-04-11 12:01:54 +00:00
|
|
|
print_properties_(print_properties),
|
2022-01-06 17:28:22 +00:00
|
|
|
field_name_(field_name),
|
|
|
|
get_value_double_(get_value_double),
|
|
|
|
get_value_string_(get_value_string),
|
|
|
|
set_value_double_(set_value_double),
|
|
|
|
set_value_string_(set_value_string),
|
2022-01-08 14:50:15 +00:00
|
|
|
lookup_(lookup)
|
2022-01-06 17:28:22 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
string vname() { return vname_; }
|
|
|
|
Quantity xuantity() { return xuantity_; }
|
|
|
|
Unit defaultUnit() { return default_unit_; }
|
|
|
|
VifScaling vifScaling() { return vif_scaling_; }
|
2022-04-19 07:10:14 +00:00
|
|
|
FieldMatcher& matcher() { return matcher_; }
|
2022-01-06 17:28:22 +00:00
|
|
|
string help() { return help_; }
|
2022-04-11 12:01:54 +00:00
|
|
|
PrintProperties printProperties() { return print_properties_; }
|
2022-01-06 17:28:22 +00:00
|
|
|
string fieldName() { return field_name_; }
|
|
|
|
|
|
|
|
double getValueDouble(Unit u) { if (get_value_double_) return get_value_double_(u); else return -12345678; }
|
|
|
|
bool hasGetValueDouble() { return get_value_double_ != NULL; }
|
|
|
|
string getValueString() { if (get_value_string_) return get_value_string_(); else return "?"; }
|
|
|
|
bool hasGetValueString() { return get_value_string_ != NULL; }
|
|
|
|
|
|
|
|
void setValueDouble(Unit u, double d) { if (set_value_double_) set_value_double_(u, d); }
|
|
|
|
void setValueString(string s) { if (set_value_string_) set_value_string_(s); }
|
|
|
|
|
2022-04-17 13:54:01 +00:00
|
|
|
bool extractNumeric(Meter *m, Telegram *t, DVEntry *dve = NULL);
|
|
|
|
bool extractString(Meter *m, Telegram *t, DVEntry *dve = NULL);
|
2022-04-19 07:10:14 +00:00
|
|
|
bool hasMatcher();
|
2022-04-17 13:54:01 +00:00
|
|
|
bool matches(DVEntry *dve);
|
|
|
|
void performExtraction(Meter *m, Telegram *t, DVEntry *dve);
|
2022-01-06 17:28:22 +00:00
|
|
|
|
|
|
|
string renderJsonOnlyDefaultUnit();
|
|
|
|
string renderJson(vector<Unit> *additional_conversions);
|
|
|
|
string renderJsonText();
|
2022-04-22 15:28:57 +00:00
|
|
|
string generateFieldName(DVEntry *dve);
|
2022-01-06 17:28:22 +00:00
|
|
|
|
2022-01-08 14:50:15 +00:00
|
|
|
Translate::Lookup& lookup() { return lookup_; }
|
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
string vname_; // Value name, like: total current previous target
|
|
|
|
Quantity xuantity_; // Quantity: Energy, Volume
|
|
|
|
Unit default_unit_; // Default unit for above quantity: KWH, M3
|
|
|
|
VifScaling vif_scaling_;
|
2022-04-17 13:54:01 +00:00
|
|
|
FieldMatcher matcher_;
|
2022-01-06 17:28:22 +00:00
|
|
|
string help_; // Helpful information on this meters use of this value.
|
2022-04-11 12:01:54 +00:00
|
|
|
PrintProperties print_properties_;
|
2022-01-06 17:28:22 +00:00
|
|
|
string field_name_; // Field name for default unit.
|
|
|
|
|
|
|
|
function<double(Unit)> get_value_double_; // Callback to fetch the value from the meter.
|
|
|
|
function<string()> get_value_string_; // Callback to fetch the value from the meter.
|
|
|
|
function<void(Unit,double)> set_value_double_; // Call back to set the value in the c++ object
|
|
|
|
function<void(string)> set_value_string_; // Call back to set the value string in the c++ object
|
2022-01-08 14:50:15 +00:00
|
|
|
Translate::Lookup lookup_;
|
2020-09-08 20:11:32 +00:00
|
|
|
};
|
|
|
|
|
2021-03-14 08:41:35 +00:00
|
|
|
struct BusManager;
|
|
|
|
|
2019-05-04 17:56:17 +00:00
|
|
|
struct Meter
|
|
|
|
{
|
2021-02-20 21:21:01 +00:00
|
|
|
// Meters are instantiated on the fly from a template, when a telegram arrives
|
|
|
|
// and no exact meter exists. Index 1 is the first meter created etc.
|
|
|
|
virtual int index() = 0;
|
|
|
|
virtual void setIndex(int i) = 0;
|
2021-03-08 16:14:03 +00:00
|
|
|
// Use this bus to send messages to the meter.
|
2021-03-14 08:41:35 +00:00
|
|
|
virtual string bus() = 0;
|
2020-05-09 21:43:30 +00:00
|
|
|
// This meter listens to these ids.
|
2021-02-20 21:21:01 +00:00
|
|
|
virtual vector<string> &ids() = 0;
|
|
|
|
// Comma separated ids.
|
|
|
|
virtual string idsc() = 0;
|
2020-05-09 21:43:30 +00:00
|
|
|
// This meter can report these fields, like total_m3, temp_c.
|
|
|
|
virtual vector<string> fields() = 0;
|
2022-01-06 17:28:22 +00:00
|
|
|
virtual vector<FieldInfo> prints() = 0;
|
2021-02-24 19:50:45 +00:00
|
|
|
virtual string meterDriver() = 0;
|
2017-08-09 10:00:11 +00:00
|
|
|
virtual string name() = 0;
|
2021-03-08 07:40:48 +00:00
|
|
|
virtual MeterDriver driver() = 0;
|
2022-01-06 17:28:22 +00:00
|
|
|
virtual DriverName driverName() = 0;
|
2018-03-05 10:29:25 +00:00
|
|
|
|
|
|
|
virtual string datetimeOfUpdateHumanReadable() = 0;
|
|
|
|
virtual string datetimeOfUpdateRobot() = 0;
|
2021-08-01 16:24:19 +00:00
|
|
|
virtual string unixTimestampOfUpdate() = 0;
|
2018-03-05 10:29:25 +00:00
|
|
|
|
2022-04-22 15:28:57 +00:00
|
|
|
virtual void setNumericValue(std::string field, Unit u, double v, FieldInfo *fi) = 0;
|
2022-04-19 07:10:14 +00:00
|
|
|
virtual double getNumericValue(std::string field, Unit u) = 0;
|
2022-04-22 15:28:57 +00:00
|
|
|
virtual void setStringValue(std::string field, std::string v, FieldInfo *fi) = 0;
|
2022-04-19 07:10:14 +00:00
|
|
|
virtual std::string getStringValue(std::string field) = 0;
|
|
|
|
|
2020-09-07 08:36:39 +00:00
|
|
|
virtual void onUpdate(std::function<void(Telegram*t,Meter*)> cb) = 0;
|
2018-03-05 10:29:25 +00:00
|
|
|
virtual int numUpdates() = 0;
|
2017-09-02 21:26:57 +00:00
|
|
|
|
2019-03-05 20:19:05 +00:00
|
|
|
virtual void printMeter(Telegram *t,
|
2019-03-05 17:38:54 +00:00
|
|
|
string *human_readable,
|
2018-11-02 12:50:12 +00:00
|
|
|
string *fields, char separator,
|
|
|
|
string *json,
|
2019-10-20 17:19:17 +00:00
|
|
|
vector<string> *envs,
|
2020-05-09 21:43:30 +00:00
|
|
|
vector<string> *more_json,
|
2022-01-25 19:10:38 +00:00
|
|
|
vector<string> *selected_fields,
|
|
|
|
bool pretty_print_json) = 0;
|
2018-03-05 10:29:25 +00:00
|
|
|
|
2020-02-15 20:18:21 +00:00
|
|
|
// The handleTelegram expects an input_frame where the DLL crcs have been removed.
|
2020-09-07 08:36:39 +00:00
|
|
|
// Returns true of this meter handled this telegram!
|
2021-02-20 21:21:01 +00:00
|
|
|
// Sets id_match to true, if there was an id match, even though the telegram could not be properly handled.
|
2021-12-07 22:56:29 +00:00
|
|
|
virtual bool handleTelegram(AboutTelegram &about, vector<uchar> input_frame,
|
|
|
|
bool simulated, string *id, bool *id_match, Telegram *out_t = NULL) = 0;
|
2020-01-27 08:29:40 +00:00
|
|
|
virtual MeterKeys *meterKeys() = 0;
|
2018-04-20 09:42:46 +00:00
|
|
|
|
2019-05-04 11:55:52 +00:00
|
|
|
virtual void addConversions(std::vector<Unit> cs) = 0;
|
2022-01-06 17:28:22 +00:00
|
|
|
virtual vector<Unit>& conversions() = 0;
|
2019-05-21 12:19:54 +00:00
|
|
|
virtual void addShell(std::string cmdline) = 0;
|
|
|
|
virtual vector<string> &shellCmdlines() = 0;
|
2021-03-14 08:41:35 +00:00
|
|
|
virtual void poll(shared_ptr<BusManager> bus) = 0;
|
2019-05-04 11:55:52 +00:00
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
virtual FieldInfo *findFieldInfo(string vname) = 0;
|
|
|
|
virtual string renderJsonOnlyDefaultUnit(string vname) = 0;
|
|
|
|
|
2018-12-28 17:35:32 +00:00
|
|
|
virtual ~Meter() = default;
|
2018-03-05 10:29:25 +00:00
|
|
|
};
|
|
|
|
|
2020-09-07 08:36:39 +00:00
|
|
|
struct MeterManager
|
|
|
|
{
|
2021-02-20 21:21:01 +00:00
|
|
|
virtual void addMeterTemplate(MeterInfo &mi) = 0;
|
2020-09-21 19:55:21 +00:00
|
|
|
virtual void addMeter(shared_ptr<Meter> meter) = 0;
|
2020-09-08 20:11:32 +00:00
|
|
|
virtual Meter*lastAddedMeter() = 0;
|
2020-09-07 08:36:39 +00:00
|
|
|
virtual void removeAllMeters() = 0;
|
|
|
|
virtual void forEachMeter(std::function<void(Meter*)> cb) = 0;
|
2020-10-14 18:59:14 +00:00
|
|
|
virtual bool handleTelegram(AboutTelegram &about, vector<uchar> data, bool simulated) = 0;
|
2020-09-07 08:36:39 +00:00
|
|
|
virtual bool hasAllMetersReceivedATelegram() = 0;
|
2020-09-08 12:55:01 +00:00
|
|
|
virtual bool hasMeters() = 0;
|
2022-03-06 21:42:44 +00:00
|
|
|
virtual void onTelegram(function<bool(AboutTelegram&,vector<uchar>)> cb) = 0;
|
2021-02-20 21:21:01 +00:00
|
|
|
virtual void whenMeterUpdated(std::function<void(Telegram*t,Meter*)> cb) = 0;
|
2021-03-14 08:41:35 +00:00
|
|
|
virtual void pollMeters(shared_ptr<BusManager> bus) = 0;
|
2022-02-06 17:49:55 +00:00
|
|
|
virtual void analyzeEnabled(bool b, OutputFormat f, string force_driver, string key, bool verbose) = 0;
|
2021-12-07 18:51:26 +00:00
|
|
|
virtual void analyzeTelegram(AboutTelegram &about, vector<uchar> &input_frame, bool simulated) = 0;
|
2021-02-20 21:21:01 +00:00
|
|
|
|
2020-09-07 08:36:39 +00:00
|
|
|
virtual ~MeterManager() = default;
|
|
|
|
};
|
|
|
|
|
2021-02-20 21:21:01 +00:00
|
|
|
shared_ptr<MeterManager> createMeterManager(bool daemon);
|
2020-09-07 08:36:39 +00:00
|
|
|
|
2022-01-06 17:28:22 +00:00
|
|
|
const char *toString(MeterType type);
|
2021-03-13 17:35:47 +00:00
|
|
|
string toString(MeterDriver driver);
|
2022-01-06 17:28:22 +00:00
|
|
|
string toString(DriverInfo &driver);
|
2021-03-08 07:40:48 +00:00
|
|
|
MeterDriver toMeterDriver(string& driver);
|
|
|
|
LinkModeSet toMeterLinkModeSet(string& driver);
|
2021-03-13 17:35:47 +00:00
|
|
|
LinkModeSet toMeterLinkModeSet(MeterDriver driver);
|
2020-08-30 19:40:50 +00:00
|
|
|
|
2021-12-31 11:27:57 +00:00
|
|
|
#define X(mname,linkmode,info,type,cname) shared_ptr<Meter> create##cname(MeterInfo &m);
|
2020-11-14 09:48:49 +00:00
|
|
|
LIST_OF_METERS
|
|
|
|
#undef X
|
|
|
|
|
2021-02-20 10:08:23 +00:00
|
|
|
struct Configuration;
|
|
|
|
struct MeterInfo;
|
2021-02-20 21:21:01 +00:00
|
|
|
shared_ptr<Meter> createMeter(MeterInfo *mi);
|
2021-02-20 10:08:23 +00:00
|
|
|
|
2017-08-09 10:00:11 +00:00
|
|
|
#endif
|