From f8ed63b03417cb86f18ddd77f8e4848c33d15a1a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 25 Mar 2011 01:01:30 +0100 Subject: [PATCH] added skeleton of vzlogger utility --- misc/controller/vzlogger/.gitignore | 1 + misc/controller/vzlogger/Makefile | 18 ++++++ misc/controller/vzlogger/src/ehz.c | 53 ++++++++++++++++ misc/controller/vzlogger/src/ehz.h | 32 ++++++++++ misc/controller/vzlogger/src/main.c | 98 +++++++++++++++++++++++++++++ misc/controller/vzlogger/src/main.h | 40 ++++++++++++ 6 files changed, 242 insertions(+) create mode 100644 misc/controller/vzlogger/.gitignore create mode 100644 misc/controller/vzlogger/Makefile create mode 100644 misc/controller/vzlogger/src/ehz.c create mode 100644 misc/controller/vzlogger/src/ehz.h create mode 100644 misc/controller/vzlogger/src/main.c create mode 100644 misc/controller/vzlogger/src/main.h diff --git a/misc/controller/vzlogger/.gitignore b/misc/controller/vzlogger/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/misc/controller/vzlogger/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/misc/controller/vzlogger/Makefile b/misc/controller/vzlogger/Makefile new file mode 100644 index 0000000..37961cc --- /dev/null +++ b/misc/controller/vzlogger/Makefile @@ -0,0 +1,18 @@ +CC=cc +CFLAGS=-c -Wall +LDFLAGS= +TARGET=vzlogger + +all: $(TARGET) + +clean: + rm -rf *.o + +vzlogger: main.c ehz.c + $(CC) $(LDFLAGS) main.o ehz.o -o $(TARGET) + +main.c: + $(CC) $(CFLAGS) src/main.c -o main.o + +ehz.c: + $(CC) $(CFLAGS) src/ehz.c -o ehz.o diff --git a/misc/controller/vzlogger/src/ehz.c b/misc/controller/vzlogger/src/ehz.c new file mode 100644 index 0000000..75f7fad --- /dev/null +++ b/misc/controller/vzlogger/src/ehz.c @@ -0,0 +1,53 @@ +/** + * eHz readout + * + * @package controller + * @copyright Copyright (c) 2010, The volkszaehler.org project + * @license http://www.gnu.org/licenses/gpl.txt GNU Public License + * @author Steffen Vogel + */ +/* + * This file is part of volkzaehler.org + * + * volkzaehler.org 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 + * any later version. + * + * volkzaehler.org 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 volkszaehler.org. If not, see . + */ + +#include +#include +#include + +int ehz_init(char * port) { + struct termios tio; + int fd; + + memset(&tio, 0, sizeof(tio)); + + tio.c_iflag = 0; + tio.c_oflag = 0; + tio.c_cflag = CS7|CREAD|CLOCAL; // 7n1, see termios.h for more information + tio.c_lflag = 0; + tio.c_cc[VMIN] = 1; + tio.c_cc[VTIME] = 5; + + fd = open(port, O_RDWR); // | O_NONBLOCK); + cfsetospeed(&tio, B9600); // 9600 baud + cfsetispeed(&tio, B9600); // 9600 baud + + return fd; +} + +float ehz_get() { + return 0; +} + diff --git a/misc/controller/vzlogger/src/ehz.h b/misc/controller/vzlogger/src/ehz.h new file mode 100644 index 0000000..a64dbfa --- /dev/null +++ b/misc/controller/vzlogger/src/ehz.h @@ -0,0 +1,32 @@ +/** + * libehz header + * + * @package controller + * @copyright Copyright (c) 2010, The volkszaehler.org project + * @license http://www.gnu.org/licenses/gpl.txt GNU Public License + * @author Steffen Vogel + */ +/* + * This file is part of volkzaehler.org + * + * volkzaehler.org 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 + * any later version. + * + * volkzaehler.org 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 volkszaehler.org. If not, see . + */ + +#ifndef _EHZ_H_ +#define _EHZ_H_ + +int ehz_init(char * port); +float ehz_get(); + +#endif /* _EHZ_H_ */ diff --git a/misc/controller/vzlogger/src/main.c b/misc/controller/vzlogger/src/main.c new file mode 100644 index 0000000..0028105 --- /dev/null +++ b/misc/controller/vzlogger/src/main.c @@ -0,0 +1,98 @@ +/** + * main source + * + * @package controller + * @copyright Copyright (c) 2010, The volkszaehler.org project + * @license http://www.gnu.org/licenses/gpl.txt GNU Public License + * @author Steffen Vogel + */ +/* + * This file is part of volkzaehler.org + * + * volkzaehler.org 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 + * any later version. + * + * volkzaehler.org 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 volkszaehler.org. If not, see . + */ + +#include +#include +#include +#include + +#include "main.h" +#include "ehz.h" + +static struct type types[] = { +// {"1wire", "Dallas 1-Wire Sensors", 1wire_get}, + {"ehz", "German \"elektronische Heimzähler\"", ehz_get} +// {"ccost", "CurrentCost", ccost_get}, +// {"fusb", "FluksoUSB prototype board", fusb_get} +}; + +static struct option long_options[] = { + {"middleware", required_argument, 0, 'm'}, + {"uuid", required_argument, 0, 'u'}, + {"value", required_argument, 0, 'v'}, + {"type", required_argument, 0, 't'}, + {"device", required_argument, 0, 'd'}, + {"config", required_argument, 0, 'c'}, + //{"daemon", required_argument, 0, 'D'}, + //{"interval", required_argument, 0, 'i'}, + //{"local", no_argument, 0, 'l'}, + //{"local-port",required_argument, 0, 'p'}, + {"help", no_argument, 0, 'h'}, + {"verbose", no_argument, 0, 'v'}, + {0} /* stop condition for iterator */ +}; + +void usage(char ** argv) { + printf("usage: %s [options]\n\n", argv[0]); + + printf("\n"); + printf(" following options are available\n"); + + struct option * op = long_options; + while (op->name) { + printf("\t--%s,\t-%c\n", op->name, op->val); + op++; + } +} + + +int main(int argc, char * argv[]) { + uint8_t verbose = 0; + + /* parse cli arguments */ + while (1) { + /* getopt_long stores the option index here. */ + int option_index = 0; + + int c = getopt_long(argc, argv, "m:u:v:t:d:c:hv", long_options, &option_index); + + /* detect the end of the options. */ + if (c == -1) + break; + + switch (c) { + case 'v': + verbose = 1; + break; + + case 'h': + case '?': + usage(argv); + exit((c == '?') ? -1 : 0); + } + } + + return 0; +} diff --git a/misc/controller/vzlogger/src/main.h b/misc/controller/vzlogger/src/main.h new file mode 100644 index 0000000..6dcd819 --- /dev/null +++ b/misc/controller/vzlogger/src/main.h @@ -0,0 +1,40 @@ +/** + * main header + * + * @package controller + * @copyright Copyright (c) 2010, The volkszaehler.org project + * @license http://www.gnu.org/licenses/gpl.txt GNU Public License + * @author Steffen Vogel + */ +/* + * This file is part of volkzaehler.org + * + * volkzaehler.org 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 + * any later version. + * + * volkzaehler.org 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 volkszaehler.org. If not, see . + */ + +#ifndef _MAIN_H_ +#define _MAIN_H_ + +typedef float (*rfp)(); + +struct type { + char name[8]; + char desc[50]; + rfp read_fnct; +}; + +void usage(char ** argv); +void config_read(char * file); + +#endif /* _MAIN_H_ */