2018-04-01 06:53:37 +00:00
|
|
|
/*
|
2019-01-01 23:20:10 +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 DVPARSER_H
|
|
|
|
#define DVPARSER_H
|
|
|
|
|
|
|
|
#include"util.h"
|
|
|
|
#include"wmbus.h"
|
|
|
|
|
|
|
|
#include<map>
|
|
|
|
#include<stdint.h>
|
2019-01-01 20:04:06 +00:00
|
|
|
#include<time.h>
|
2018-04-01 06:53:37 +00:00
|
|
|
#include<functional>
|
|
|
|
#include<vector>
|
|
|
|
|
2019-01-27 23:03:25 +00:00
|
|
|
#define LIST_OF_VALUETYPES \
|
|
|
|
X(Volume,0x10,0x17) \
|
|
|
|
X(VolumeFlow,0x38,0x3F) \
|
|
|
|
X(FlowTemperature,0x58,0x5B) \
|
|
|
|
X(ExternalTemperature,0x64,0x67) \
|
2019-02-28 18:38:43 +00:00
|
|
|
X(HeatCostAllocation,0x6E,0x6E) \
|
2019-03-01 14:41:11 +00:00
|
|
|
X(Date,0x6C,0x6C) \
|
|
|
|
X(DateTime,0x6D,0x6D) \
|
2019-03-20 21:16:45 +00:00
|
|
|
X(EnergyWh,0x03,0x07) \
|
|
|
|
X(PowerW,0x28,0x2f) \
|
2019-01-27 23:03:25 +00:00
|
|
|
|
|
|
|
enum class ValueInformation
|
|
|
|
{
|
|
|
|
#define X(name,from,to) name,
|
|
|
|
LIST_OF_VALUETYPES
|
|
|
|
#undef X
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *ValueInformatioName(ValueInformation v);
|
|
|
|
|
|
|
|
struct DVEntry
|
|
|
|
{
|
2019-10-14 18:26:31 +00:00
|
|
|
MeasurementType type {};
|
2019-01-27 23:03:25 +00:00
|
|
|
int value_information {};
|
|
|
|
int storagenr {};
|
|
|
|
int tariff {};
|
|
|
|
int subunit {};
|
|
|
|
string value;
|
|
|
|
|
|
|
|
DVEntry() {}
|
2019-10-14 18:26:31 +00:00
|
|
|
DVEntry(MeasurementType mt, int vi, int st, int ta, int su, string &val) :
|
|
|
|
type(mt), value_information(vi), storagenr(st), tariff(ta), subunit(su), value(val) {}
|
2019-01-27 23:03:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool loadFormatBytesFromSignature(uint16_t format_signature, vector<uchar> *format_bytes);
|
2018-04-01 06:53:37 +00:00
|
|
|
|
|
|
|
bool parseDV(Telegram *t,
|
2018-12-28 17:35:32 +00:00
|
|
|
std::vector<uchar> &databytes,
|
2018-04-01 06:53:37 +00:00
|
|
|
std::vector<uchar>::iterator data,
|
|
|
|
size_t data_len,
|
2019-01-27 23:03:25 +00:00
|
|
|
std::map<std::string,std::pair<int,DVEntry>> *values,
|
2018-04-01 06:53:37 +00:00
|
|
|
std::vector<uchar>::iterator *format = NULL,
|
|
|
|
size_t format_len = 0,
|
2019-08-12 09:47:39 +00:00
|
|
|
uint16_t *format_hash = NULL);
|
2018-04-01 06:53:37 +00:00
|
|
|
|
2019-01-27 23:03:25 +00:00
|
|
|
// Instead of using a hardcoded difvif as key in the extractDV... below,
|
|
|
|
// find an existing difvif entry in the values based on the desired value information type.
|
|
|
|
// Like: Volume, VolumeFlow, FlowTemperature, ExternalTemperature etc
|
|
|
|
// in combination with the storagenr. (Later I will add tariff/subunit)
|
2019-10-14 18:26:31 +00:00
|
|
|
bool findKey(MeasurementType mt, ValueInformation vi, int storagenr, std::string *key, std::map<std::string,std::pair<int,DVEntry>> *values);
|
2019-01-27 23:03:25 +00:00
|
|
|
#define ANY_STORAGENR -1
|
|
|
|
|
2019-03-01 14:41:11 +00:00
|
|
|
bool hasKey(std::map<std::string,std::pair<int,DVEntry>> *values, std::string key);
|
|
|
|
|
2019-01-27 23:03:25 +00:00
|
|
|
bool extractDVuint16(std::map<std::string,std::pair<int,DVEntry>> *values,
|
2018-04-01 06:53:37 +00:00
|
|
|
std::string key,
|
|
|
|
int *offset,
|
|
|
|
uint16_t *value);
|
|
|
|
|
2019-01-01 20:04:06 +00:00
|
|
|
// All volume values are scaled to cubic meters, m3.
|
2019-01-27 23:03:25 +00:00
|
|
|
bool extractDVdouble(std::map<std::string,std::pair<int,DVEntry>> *values,
|
2018-04-01 06:53:37 +00:00
|
|
|
std::string key,
|
|
|
|
int *offset,
|
2019-10-14 14:53:02 +00:00
|
|
|
double *value,
|
|
|
|
bool auto_scale = true);
|
2018-04-01 06:53:37 +00:00
|
|
|
|
2019-01-27 23:03:25 +00:00
|
|
|
bool extractDVstring(std::map<std::string,std::pair<int,DVEntry>> *values,
|
2019-01-01 20:04:06 +00:00
|
|
|
std::string key,
|
|
|
|
int *offset,
|
|
|
|
string *value);
|
|
|
|
|
2019-01-27 23:03:25 +00:00
|
|
|
bool extractDVdate(std::map<std::string,std::pair<int,DVEntry>> *values,
|
2019-01-01 20:04:06 +00:00
|
|
|
std::string key,
|
|
|
|
int *offset,
|
2019-03-01 14:41:11 +00:00
|
|
|
struct tm *value);
|
2019-01-01 20:04:06 +00:00
|
|
|
|
|
|
|
void extractDV(string &s, uchar *dif, uchar *vif);
|
2018-04-01 06:53:37 +00:00
|
|
|
|
|
|
|
#endif
|