added skeleton of vzlogger utility

This commit is contained in:
Steffen Vogel 2011-03-25 01:01:30 +01:00
parent 82b670c152
commit f8ed63b034
6 changed files with 242 additions and 0 deletions

1
misc/controller/vzlogger/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.o

View file

@ -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

View file

@ -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 <info@steffenvogel.de>
*/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <fcntl.h>
#include <termios.h>
#include <string.h>
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;
}

View file

@ -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 <info@steffenvogel.de>
*/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _EHZ_H_
#define _EHZ_H_
int ehz_init(char * port);
float ehz_get();
#endif /* _EHZ_H_ */

View file

@ -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 <info@steffenvogel.de>
*/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <stdint.h>
#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;
}

View file

@ -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 <info@steffenvogel.de>
*/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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_ */