Added support for specifying in which dir to store the meterfiles (ie not just /tmp).

pull/5/head
weetmuts 2018-03-05 13:42:56 +01:00
rodzic acafccfc5e
commit 68b20665be
6 zmienionych plików z 26 dodań i 9 usunięć

Wyświetl plik

@ -16,8 +16,9 @@ Add --verbose for detailed debug information.
--robot or --robot=json for json output.
--robot=fields for semicolon separated fields.
--separator=X change field separator to X.
--meterfiles to create status files below tmp,
named /tmp/meter_name, containing the latest reading.
--meterfiles=dir to create status files below dir,
named dir/meter_name, containing the latest reading.
--meterfiles defaults dir to /tmp.
--oneshot wait for an update from each meter, then quit.
Specifying auto as the device will automatically look for usb

Wyświetl plik

@ -88,8 +88,20 @@ CommandLine *parseCommandLine(int argc, char **argv) {
i++;
continue;
}
if (!strcmp(argv[i], "--meterfiles")) {
if (!strncmp(argv[i], "--meterfiles", 12)) {
c->meterfiles = true;
if (strlen(argv[i]) > 12 && argv[i][12] == '=') {
size_t len = strlen(argv[i])-13;
if (len > 0) {
c->meterfiles_dir = new char[len+1];
strncpy((char*)c->meterfiles_dir, argv[i]+13, len);
} else {
c->meterfiles_dir = "/tmp";
}
} else {
c->meterfiles_dir = "/tmp";
}
verbose("Storing meter files here: %s\n", c->meterfiles_dir);
i++;
continue;
}

Wyświetl plik

@ -49,6 +49,7 @@ struct CommandLine {
bool debug {};
bool logtelegrams {};
bool meterfiles {};
const char *meterfiles_dir {};
bool json {};
bool fields {};
char separator { ';' };

Wyświetl plik

@ -43,8 +43,9 @@ int main(int argc, char **argv)
printf(" --robot or --robot=json for json output.\n");
printf(" --robot=fields for semicolon separated fields.\n");
printf(" --separator=X change field separator to X.\n");
printf(" --meterfiles to create status files below tmp,\n"
" named /tmp/meter_name, containing the latest reading.\n");
printf(" --meterfiles=dir to create status files below dir,\n"
" named dir/meter_name, containing the latest reading.\n");
printf(" --meterfiles defaults dir to /tmp.\n");
printf(" --oneshot wait for an update from each meter, then quit.\n\n");
printf("Specifying auto as the device will automatically look for usb\n");
printf("wmbus dongles on /dev/im871a and /dev/amb8465\n\n");
@ -90,7 +91,7 @@ int main(int argc, char **argv)
if (wmbus->getLinkMode()!=LinkModeC1) error("Could not set link mode to receive C1 telegrams.\n");
Printer *output = new Printer(cmdline->json, cmdline->fields,
cmdline->separator, cmdline->meterfiles);
cmdline->separator, cmdline->meterfiles, cmdline->meterfiles_dir);
if (cmdline->meters.size() > 0) {
for (auto &m : cmdline->meters) {

Wyświetl plik

@ -22,12 +22,13 @@
using namespace std;
Printer::Printer(bool json, bool fields, char separator, bool meterfiles)
Printer::Printer(bool json, bool fields, char separator, bool meterfiles, const char *meterfiles_dir)
{
json_ = json;
fields_ = fields;
separator_ = separator;
meterfiles_ = meterfiles;
meterfiles_dir_ = meterfiles_dir;
}
void Printer::print(Meter *meter)
@ -37,7 +38,7 @@ void Printer::print(Meter *meter)
if (meterfiles_) {
char filename[128];
memset(filename, 0, sizeof(filename));
snprintf(filename, 127, "/tmp/%s", meter->name().c_str());
snprintf(filename, 127, "%s/%s", meterfiles_dir_, meter->name().c_str());
output = fopen(filename, "w");
}

Wyświetl plik

@ -24,12 +24,13 @@
using namespace std;
struct Printer {
Printer(bool json, bool fields, char separator, bool meterfiles);
Printer(bool json, bool fields, char separator, bool meterfiles, const char *meterfiles_dir);
void print(Meter *meter);
private:
bool json_, fields_, meterfiles_;
const char *meterfiles_dir_;
char separator_;
};