2019-02-23 12:41:17 +00:00
|
|
|
/*
|
2022-02-12 14:28:17 +00:00
|
|
|
Copyright (C) 2019-2021 Fredrik Öhrström (gpl-3.0-or-later)
|
2019-02-23 12:41:17 +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 CONFIG_H
|
|
|
|
#define CONFIG_H
|
|
|
|
|
2019-05-04 06:52:25 +00:00
|
|
|
#include"units.h"
|
2019-02-23 12:41:17 +00:00
|
|
|
#include"util.h"
|
|
|
|
#include"wmbus.h"
|
2019-05-21 12:19:54 +00:00
|
|
|
#include"meters.h"
|
2020-11-01 14:18:13 +00:00
|
|
|
#include<set>
|
2019-02-23 12:41:17 +00:00
|
|
|
#include<vector>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2019-02-24 16:31:32 +00:00
|
|
|
enum class MeterFileType
|
|
|
|
{
|
|
|
|
Overwrite, Append
|
2019-02-23 12:41:17 +00:00
|
|
|
};
|
|
|
|
|
2019-06-20 12:28:52 +00:00
|
|
|
enum class MeterFileNaming
|
|
|
|
{
|
|
|
|
Name, Id, NameId
|
|
|
|
};
|
|
|
|
|
2019-12-11 17:56:34 +00:00
|
|
|
enum class MeterFileTimestamp
|
|
|
|
{
|
|
|
|
Never, Day, Hour, Minute, Micros
|
|
|
|
};
|
|
|
|
|
2022-03-06 21:42:44 +00:00
|
|
|
enum class LogSummary
|
|
|
|
{
|
|
|
|
All, Unknown
|
|
|
|
};
|
|
|
|
|
2022-02-05 15:00:52 +00:00
|
|
|
// These values can be overridden from the command line.
|
|
|
|
struct ConfigOverrides
|
|
|
|
{
|
|
|
|
std::string loglevel_override;
|
|
|
|
std::string device_override;
|
|
|
|
std::string listento_override;
|
|
|
|
std::string exitafter_override;
|
|
|
|
std::string oneshot_override;
|
|
|
|
std::string logfile_override;
|
|
|
|
};
|
|
|
|
|
2019-10-20 17:19:17 +00:00
|
|
|
struct Configuration
|
|
|
|
{
|
2021-03-06 13:16:47 +00:00
|
|
|
string bin_dir {}; // The wmbusmeters binary executed is located here.
|
|
|
|
// Use this directory to look for other tools such as rtl_wmbus/rtl_sdr
|
|
|
|
// inside the same directory.
|
2019-02-23 12:41:17 +00:00
|
|
|
bool daemon {};
|
2019-02-24 08:58:31 +00:00
|
|
|
std::string pid_file;
|
2022-02-05 15:00:52 +00:00
|
|
|
ConfigOverrides overrides;
|
2019-02-23 12:41:17 +00:00
|
|
|
bool useconfig {};
|
2019-02-26 08:33:10 +00:00
|
|
|
std::string config_root;
|
2024-02-10 23:12:31 +00:00
|
|
|
std::string drivers_dir;
|
2019-02-23 12:41:17 +00:00
|
|
|
bool need_help {};
|
2020-11-11 18:29:00 +00:00
|
|
|
bool silent {};
|
2019-02-23 12:41:17 +00:00
|
|
|
bool verbose {};
|
2019-04-15 19:17:15 +00:00
|
|
|
bool version {};
|
|
|
|
bool license {};
|
2021-12-07 18:51:26 +00:00
|
|
|
bool analyze {};
|
2021-12-07 22:56:29 +00:00
|
|
|
OutputFormat analyze_format {};
|
2022-02-06 17:49:55 +00:00
|
|
|
string analyze_driver {};
|
|
|
|
string analyze_key {};
|
|
|
|
bool analyze_verbose {};
|
2022-12-05 17:41:43 +00:00
|
|
|
int analyze_profile {}; // If greater than 0, then run the handleTelegram call this number of times when analyzing.
|
2019-02-23 12:41:17 +00:00
|
|
|
bool debug {};
|
2020-08-01 19:56:46 +00:00
|
|
|
bool trace {};
|
2021-03-13 07:54:08 +00:00
|
|
|
AddLogTimestamps addtimestamps {};
|
2021-06-26 10:24:30 +00:00
|
|
|
bool internaltesting {}; // Not currently used. Was used for speeding up testing. I.e. it shortened all timeouts.
|
|
|
|
// Might be needed in the future. Therefore it is still here.
|
2022-03-06 21:42:44 +00:00
|
|
|
bool logsummary {};
|
2019-02-23 12:41:17 +00:00
|
|
|
bool logtelegrams {};
|
|
|
|
bool meterfiles {};
|
|
|
|
std::string meterfiles_dir;
|
2019-02-26 21:19:16 +00:00
|
|
|
MeterFileType meterfiles_action {};
|
2019-06-20 12:28:52 +00:00
|
|
|
MeterFileNaming meterfiles_naming {};
|
2019-12-11 17:56:34 +00:00
|
|
|
MeterFileTimestamp meterfiles_timestamp {}; // Default is never.
|
2019-02-24 14:20:55 +00:00
|
|
|
bool use_logfile {};
|
2020-09-13 14:55:22 +00:00
|
|
|
bool use_stderr_for_log = true; // Default is to use stderr for logging.
|
2021-02-20 21:21:01 +00:00
|
|
|
bool ignore_duplicate_telegrams = true; // Default is to ignore duplicates.
|
2019-02-24 14:20:55 +00:00
|
|
|
std::string logfile;
|
2019-02-23 12:41:17 +00:00
|
|
|
bool json {};
|
2022-04-23 14:28:54 +00:00
|
|
|
bool pretty_print_json {};
|
2022-05-01 15:05:30 +00:00
|
|
|
int pollinterval {}; // Time between polling of mbus meters.
|
2024-03-03 11:57:40 +00:00
|
|
|
IdentityMode identity_mode {}; // How to group meters identities into state objects.
|
2019-02-23 12:41:17 +00:00
|
|
|
bool fields {};
|
|
|
|
char separator { ';' };
|
2020-07-30 09:18:44 +00:00
|
|
|
std::vector<std::string> telegram_shells;
|
2023-11-29 09:49:37 +00:00
|
|
|
std::vector<std::string> meter_shells;
|
2020-07-30 09:18:44 +00:00
|
|
|
std::vector<std::string> alarm_shells;
|
2020-08-01 19:56:46 +00:00
|
|
|
int alarm_timeout {}; // Maximum number of seconds between dongle receiving two telegrams.
|
|
|
|
std::string alarm_expected_activity; // Only warn when within these time periods.
|
2020-10-04 20:52:05 +00:00
|
|
|
bool exit_instead_of_alarm_ {};
|
2019-02-23 12:41:17 +00:00
|
|
|
bool list_shell_envs {};
|
2020-05-09 21:43:30 +00:00
|
|
|
bool list_fields {};
|
2020-09-13 11:24:46 +00:00
|
|
|
bool list_meters {};
|
2021-08-26 10:51:59 +00:00
|
|
|
bool list_units {};
|
2020-09-13 11:24:46 +00:00
|
|
|
std::string list_meters_search;
|
2020-09-08 20:11:32 +00:00
|
|
|
// When asking for envs or fields, this is the meter type to list for.
|
|
|
|
std::string list_meter;
|
2019-02-23 12:41:17 +00:00
|
|
|
bool oneshot {};
|
|
|
|
int exitafter {}; // Seconds to exit.
|
2020-11-11 23:43:01 +00:00
|
|
|
bool nodeviceexit {}; // If no wmbus receiver device is found, then exit immediately!
|
2020-09-25 21:56:50 +00:00
|
|
|
int resetafter {}; // Reset the wmbus devices regularly.
|
2021-02-13 14:18:59 +00:00
|
|
|
std::vector<SpecifiedDevice> supplied_bus_devices; // /dev/ttyUSB0, simulation.txt, rtlwmbus, /dev/ttyUSB1:9600 /dev/ttyUSB2:mbus
|
|
|
|
int num_wmbus_devices {};
|
|
|
|
int num_mbus_devices {};
|
2020-11-01 14:18:13 +00:00
|
|
|
bool use_auto_device_detect {}; // Set to true if auto was supplied as device.
|
|
|
|
std::set<std::string> do_not_probe_ttys; // Do not probe these ttys! all = all of them.
|
|
|
|
LinkModeSet auto_device_linkmodes; // The linkmodes specified by auto:c1,t1
|
2020-10-07 19:40:33 +00:00
|
|
|
bool single_device_override {}; // Set to true if there is a stdin/file or simulation device.
|
|
|
|
bool simulation_found {};
|
2020-11-01 14:18:13 +00:00
|
|
|
LinkModeSet default_device_linkmodes; // Backwards compatible --listento=c1 or --c1 will set the default_linkmodes.
|
|
|
|
// A device without a :t1 suffix, will use this linkmode.
|
|
|
|
// Is empty when not set.
|
|
|
|
LinkModeSet all_device_linkmodes_specified; // A union of all device specified linkmodes.
|
|
|
|
// Eventually not all devices might be found, so a realtime check is done later.
|
|
|
|
LinkModeSet all_meters_linkmodes_specified; // A union of all meters linkmodes.
|
2019-02-25 21:03:20 +00:00
|
|
|
string telegram_reader;
|
2019-06-06 15:28:20 +00:00
|
|
|
// A set of all link modes (union) that the user requests the wmbus dongle to listen to.
|
2019-02-23 12:41:17 +00:00
|
|
|
bool no_init {};
|
2020-05-09 21:43:30 +00:00
|
|
|
std::vector<std::string> selected_fields;
|
2019-10-20 17:19:17 +00:00
|
|
|
std::vector<MeterInfo> meters;
|
2021-08-01 21:12:52 +00:00
|
|
|
std::vector<std::string> extra_constant_fields; // Additional constant fields to always add to json.
|
2022-11-01 20:15:28 +00:00
|
|
|
std::vector<std::string> extra_calculated_fields; // Additional calculated fields to always add to json.
|
2021-08-08 15:16:52 +00:00
|
|
|
// These extra constant fields can also be part of selected with selectfields.
|
2021-08-29 18:26:06 +00:00
|
|
|
std::vector<SendBusContent> send_bus_content; // Telegrams used to wake up a meter for reading or mbus read-out requests.
|
2022-08-20 17:58:28 +00:00
|
|
|
std::set<BusDeviceType> probe_for; // Which devices should be probed for? DEVICE_AUTO means all.
|
2019-02-24 13:08:51 +00:00
|
|
|
~Configuration() = default;
|
2019-02-23 12:41:17 +00:00
|
|
|
};
|
|
|
|
|
2022-02-05 15:00:52 +00:00
|
|
|
shared_ptr<Configuration> loadConfiguration(string root, ConfigOverrides overrides);
|
2019-02-23 12:41:17 +00:00
|
|
|
|
2021-08-26 20:02:45 +00:00
|
|
|
void parseMeterConfig(Configuration *c, vector<char> &buf, string file);
|
2020-05-09 21:43:30 +00:00
|
|
|
void handleSelectedFields(Configuration *c, string s);
|
2021-08-01 21:12:52 +00:00
|
|
|
void handleAddedFields(Configuration *c, string s);
|
2021-09-12 08:40:40 +00:00
|
|
|
bool handleDeviceOrHex(Configuration *c, string devicefilehex);
|
2019-05-04 11:07:37 +00:00
|
|
|
|
2019-06-06 15:28:20 +00:00
|
|
|
enum class LinkModeCalculationResultType
|
|
|
|
{
|
|
|
|
Success,
|
2019-06-06 15:50:04 +00:00
|
|
|
NoMetersMustSupplyModes,
|
2019-06-06 15:28:20 +00:00
|
|
|
AutomaticDeductionFailed,
|
|
|
|
DongleCannotListenTo,
|
|
|
|
MightMissTelegrams
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LinkModeCalculationResult
|
|
|
|
{
|
|
|
|
LinkModeCalculationResultType type;
|
|
|
|
std::string msg;
|
|
|
|
};
|
|
|
|
|
2022-08-20 17:58:28 +00:00
|
|
|
LinkModeCalculationResult calculateLinkModes(Configuration *c, BusDevice *device, bool link_modes_matter = true);
|
2019-06-06 15:28:20 +00:00
|
|
|
|
2019-02-23 12:41:17 +00:00
|
|
|
#endif
|