Add option --listunits

pull/331/head
Fredrik Öhrström 2021-08-26 12:51:59 +02:00
rodzic be284f3ae5
commit 301f7bd3f7
6 zmienionych plików z 68 dodań i 3 usunięć

Wyświetl plik

@ -1,4 +1,7 @@
Added --listunits to list all quantities and the units for each quantity
that wmbusmeteres knows about.
Tomasz Gramza added manual offset setting to the apator162 meter driver.
You can now specify for example: apator162(offset=29) to use the 4 bytes
at offset 29 in the telegram as the water consumption. Other offsets

Wyświetl plik

@ -109,8 +109,8 @@ that driver detection is automatic: `driver=auto`.
Now plugin your wmbus dongle.
Wmbusmeters should start automatically, check with `tail -f /var/log/syslog` and `tail -f /var/log/wmbusmeters/wmbusmeters.log`
(If you are using an rtlsdr dongle, then make sure that either the binaries `/usr/bin/rtl_sdr` and
`/usr/bin/rtl_wmbus` exists and are executable. Or `rtl_sdr/rtl_wmbus` exists inside the same directory
as the wmbusmeters directory is located. If not you will see the
`/usr/bin/rtl_wmbus` exists and are executable. Or that the executable `rtl_sdr/rtl_wmbus` binaries
exists inside the same directory as the wmbusmeters executable. If not you will see the
error message `(rtlwmbus) error: when starting as daemon, wmbusmeters looked for .../rtl_wmbus and /usr/bin/rtl_wmbus, but found neither!`
and the daemon will refuse to start.)

Wyświetl plik

@ -482,6 +482,11 @@ shared_ptr<Configuration> parseCommandLine(int argc, char **argv) {
i++;
continue;
}
else if (!strcmp(argv[i], "--listunits")) {
c->list_units = true;
i++;
continue;
}
if (!strcmp(argv[i], "--oneshot")) {
c->oneshot = true;
i++;
@ -556,7 +561,8 @@ shared_ptr<Configuration> parseCommandLine(int argc, char **argv) {
c->use_auto_device_detect == false &&
!c->list_shell_envs &&
!c->list_fields &&
!c->list_meters)
!c->list_meters &&
!c->list_units)
{
error("You must supply at least one device to communicate using (w)mbus.\n");
}

Wyświetl plik

@ -84,6 +84,7 @@ struct Configuration
bool list_shell_envs {};
bool list_fields {};
bool list_meters {};
bool list_units {};
std::string list_meters_search;
// When asking for envs or fields, this is the meter type to list for.
std::string list_meter;

Wyświetl plik

@ -50,6 +50,7 @@ SpecifiedDevice *find_specified_device_from_detected(Configuration *c, Detected
void list_fields(Configuration *config, string meter_type);
void list_shell_envs(Configuration *config, string meter_type);
void list_meters(Configuration *config);
void list_units();
void log_start_information(Configuration *config);
void oneshot_check(Configuration *config, Telegram *t, Meter *meter);
void regular_checkup(Configuration *config);
@ -132,6 +133,12 @@ provided you with this binary. Read the full license for all details.
exit(0);
}
if (config->list_units)
{
list_units();
exit(0);
}
if (config->need_help)
{
printf("wmbusmeters version: " VERSION "\n");
@ -249,6 +256,50 @@ LIST_OF_METERS
#undef X
}
struct TmpUnit
{
string suff, expl, name, quantity;
};
void list_units()
{
vector<TmpUnit> units;
set<string> quantities;
// X(KVARH,kvarh,"kVARh",Reactive_Energy,"kilo volt amperes reactive hour")
int width = 1;
int total = 1;
int tmp = 0;
#define X(upn,lcn,name,quantity,expl) \
tmp = strlen(#lcn); if (tmp > width) { width = tmp; } \
tmp = strlen(#lcn)+strlen(name)+strlen(expl)+3; if (tmp > total) { total = tmp; } \
units.push_back( { #lcn, expl, name, #quantity } ); \
quantities.insert(#quantity);
LIST_OF_UNITS
#undef X
sort(units.begin(), units.end(), [](const TmpUnit & a, const TmpUnit & b) -> bool { return a.suff > b.suff; });
bool first = true;
for (const string &q : quantities)
{
if (!first)
{
printf("\n");
}
first = false;
printf("%s ", q.c_str());
size_t l = total-strlen(q.c_str());
for (size_t i=0; i<l; ++i) printf("");
printf("\n\n");
for (TmpUnit &u : units)
{
if (u.quantity == q)
{
printf("%-*s %s (%s)\n", width, u.suff.c_str(), u.expl.c_str(), u.name.c_str());
}
}
}
}
void log_start_information(Configuration *config)
{
verbose("(wmbusmeters) version: " VERSION "\n");

Wyświetl plik

@ -34,6 +34,7 @@
X(Text,TXT) \
X(Counter,INT) \
X(Time,Hour) \
X(PointInTime,DateTimeLT) \
X(Voltage,Volt) \
X(Current,Ampere) \
X(Frequency,Hz)
@ -60,6 +61,9 @@
X(Hour,h,"h",Time,"hour") \
X(Day,d,"d",Time,"day") \
X(Year,y,"y",Time,"year") \
X(DateTimeUT,ut,"ut",PointInTime,"unix timestamp") \
X(DateTimeUTC,utc,"utc",PointInTime,"coordinated universal time") \
X(DateTimeLT,lt,"lt",PointInTime,"local time") \
X(Volt,v,"V",Voltage,"volt") \
X(Ampere,a,"A",Current,"ampere") \
X(Hz,hz,"Hz",Frequency,"hz")