Working on charts
git-svn-id: file:///home/jan/tmp/wetterstation/trunk@68 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
4091dea6b2
commit
1880abfc3e
|
|
@ -6,7 +6,7 @@ LDFLAS = -o
|
||||||
INCL = -I$$(pg_config --includedir)
|
INCL = -I$$(pg_config --includedir)
|
||||||
|
|
||||||
BIN_NAME = chart
|
BIN_NAME = chart
|
||||||
OBJS = chart.o config.o common.o image_file/image_file.o
|
OBJS = chart.o config.o common.o image_file/image_file.o image_file/image_config.o
|
||||||
|
|
||||||
CONF_NAME = chart.conf
|
CONF_NAME = chart.conf
|
||||||
|
|
||||||
|
|
@ -24,8 +24,8 @@ all: $(BIN_NAME)
|
||||||
|
|
||||||
# Binary Linken
|
# Binary Linken
|
||||||
$(BIN_NAME): $(OBJS)
|
$(BIN_NAME): $(OBJS)
|
||||||
@ echo Linke: $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lesmtp -lssl -lpq $(LDFLAS) $(BIN_NAME) $(OBJS)
|
@ echo Linke: $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lpq $(LDFLAS) $(BIN_NAME) $(OBJS)
|
||||||
@ $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lesmtp -lssl -lpq $(LDFLAS) $(BIN_NAME) $(OBJS)
|
@ $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lpq $(LDFLAS) $(BIN_NAME) $(OBJS)
|
||||||
@ echo Binary $(BIN_NAME) ist fertig!
|
@ echo Binary $(BIN_NAME) ist fertig!
|
||||||
|
|
||||||
# Abhängigkeiten
|
# Abhängigkeiten
|
||||||
|
|
@ -41,8 +41,15 @@ config.o: config.c \
|
||||||
config.h \
|
config.h \
|
||||||
definitions.h \
|
definitions.h \
|
||||||
common.h
|
common.h
|
||||||
|
image_file/image_config.o: image_file/image_config.c \
|
||||||
|
common.h \
|
||||||
|
image_file/image_common.h \
|
||||||
|
config.h
|
||||||
image_file/image_file.o: image_file/image_file.c \
|
image_file/image_file.o: image_file/image_file.c \
|
||||||
image_file/image_file.h
|
common.h \
|
||||||
|
image_file/image_common.h \
|
||||||
|
image_file/image_file.h \
|
||||||
|
image_file/image_config.h
|
||||||
|
|
||||||
# Compillieren
|
# Compillieren
|
||||||
$(OBJS):
|
$(OBJS):
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ int main(int argc, char *argv[]){
|
||||||
exit_error(ERROR_SEIINST);
|
exit_error(ERROR_SEIINST);
|
||||||
DEBUGOUT1("Signalhandler zum beenden per SIGTERM installiert\n");
|
DEBUGOUT1("Signalhandler zum beenden per SIGTERM installiert\n");
|
||||||
|
|
||||||
read_config(DEFAULT_CONFIG_FILE, 1);
|
read_config(DEFAULT_CONFIG_FILE, 1, NULL);
|
||||||
|
|
||||||
/* Debug-Ausgaben, um zu sehen, ob die Optionen richtig gesetzt werden */
|
/* Debug-Ausgaben, um zu sehen, ob die Optionen richtig gesetzt werden */
|
||||||
DEBUGOUT1("\nOptionen:\n");
|
DEBUGOUT1("\nOptionen:\n");
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
fork yes
|
fork yes
|
||||||
image_cfg_location blub/
|
image_cfg_location image_file/
|
||||||
|
|
||||||
|
image_cfg testimage.conf
|
||||||
image_cfg bla
|
image_cfg bla
|
||||||
image_cfg blo
|
image_cfg blo
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
typedef struct image_cfg_list_t *image_cfg_list_ptr;
|
typedef struct image_cfg_list_t *image_cfg_list_ptr;
|
||||||
typedef struct image_cfg_list_t {
|
typedef struct image_cfg_list_t {
|
||||||
char *image_cfg_file;
|
char *image_cfg_file;
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,12 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
/* Funktionsdefinitionen */
|
/* Funktionsdefinitionen */
|
||||||
static int read_int(const char *, void *);
|
|
||||||
static int read_yn(const char *, void *);
|
|
||||||
static int add_image_cfg(const char *, void *);
|
static int add_image_cfg(const char *, void *);
|
||||||
static int read_str(const char *, void *);
|
|
||||||
|
|
||||||
|
|
||||||
/* Zuordnung zwischen Schlüsselwörtern in der Config, Der Funktion, die diese auswertet
|
/* Zuordnung zwischen Schlüsselwörtern in der Config, Der Funktion, die diese auswertet
|
||||||
* und dem eld in der Options-Struktur */
|
* und dem eld in der Options-Struktur */
|
||||||
static const struct config_keyword keywords[] = {
|
static const config_keyword dflt_keywords[] = {
|
||||||
/* keyword handler variable address default */
|
/* keyword handler variable address default */
|
||||||
{"fork", read_yn, &(global_opts.fork), ""},
|
{"fork", read_yn, &(global_opts.fork), ""},
|
||||||
{"image_cfg", add_image_cfg, &(global_opts.image_cfg), ""},
|
{"image_cfg", add_image_cfg, &(global_opts.image_cfg), ""},
|
||||||
|
|
@ -62,7 +59,7 @@ static const struct config_keyword keywords[] = {
|
||||||
|
|
||||||
/* Liest eine Option (line) als String und speichert diese in
|
/* Liest eine Option (line) als String und speichert diese in
|
||||||
* dem entsprechendem Feld der Optionen-Struktur (arg) */
|
* dem entsprechendem Feld der Optionen-Struktur (arg) */
|
||||||
static int read_str(const char *line, void *arg){
|
int read_str(const char *line, void *arg){
|
||||||
char **dest = arg;
|
char **dest = arg;
|
||||||
if (*dest) free(*dest);
|
if (*dest) free(*dest);
|
||||||
*dest = strdup(line);
|
*dest = strdup(line);
|
||||||
|
|
@ -71,13 +68,13 @@ static int read_str(const char *line, void *arg){
|
||||||
|
|
||||||
|
|
||||||
/* Interval lesen, indem die Sensoren das letzte mal etwas gesendet haben sollen */
|
/* Interval lesen, indem die Sensoren das letzte mal etwas gesendet haben sollen */
|
||||||
static int read_int(const char *line, void *arg){
|
int read_int(const char *line, void *arg){
|
||||||
int *dest = arg;
|
int *dest = arg;
|
||||||
*dest = atoi(line);
|
*dest = atoi(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lesen, ob id's aus der Datenbank gelesen werden sollen oder nicht */
|
/* lesen, ob id's aus der Datenbank gelesen werden sollen oder nicht */
|
||||||
static int read_yn(const char *line, void *arg){
|
int read_yn(const char *line, void *arg){
|
||||||
char *dest = arg;
|
char *dest = arg;
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
if (!strcasecmp("yes", line))
|
if (!strcasecmp("yes", line))
|
||||||
|
|
@ -116,13 +113,15 @@ static int add_image_cfg(const char *line, void *arg){
|
||||||
/* Liest und verarbeitet die Config-File
|
/* Liest und verarbeitet die Config-File
|
||||||
* der Integer reset gibt an, ob zu begin defaultwerte
|
* der Integer reset gibt an, ob zu begin defaultwerte
|
||||||
* gesetzt werden sollen oder nicht */
|
* gesetzt werden sollen oder nicht */
|
||||||
int read_config(const char *file, int reset){
|
int read_config(char *file, int reset, const config_keyword *keywords){
|
||||||
FILE *in; /* File-Handler */
|
FILE *in; /* File-Handler */
|
||||||
char buffer[CONFIG_BUFFERSIZE], *token, *line; /* Puffer zum lesen der config-file (imer 1 Zeile)*/
|
char buffer[CONFIG_BUFFERSIZE], *token, *line; /* Puffer zum lesen der config-file (imer 1 Zeile)*/
|
||||||
char orig[CONFIG_BUFFERSIZE]; /* Originalpuffer zum lesen der config-file, um die Log und debug-ausgabe zu realisieren */
|
char orig[CONFIG_BUFFERSIZE]; /* Originalpuffer zum lesen der config-file, um die Log und debug-ausgabe zu realisieren */
|
||||||
int i; /* Laufvariable */
|
int i; /* Laufvariable */
|
||||||
int lm = 0; /* Zeilen-Nummer */
|
int lm = 0; /* Zeilen-Nummer */
|
||||||
|
|
||||||
|
if(keywords == NULL)
|
||||||
|
keywords = (config_keyword *)dflt_keywords;
|
||||||
|
|
||||||
/* Optionen mit default-werten füllen */
|
/* Optionen mit default-werten füllen */
|
||||||
if(reset){
|
if(reset){
|
||||||
|
|
@ -134,7 +133,7 @@ int read_config(const char *file, int reset){
|
||||||
|
|
||||||
/* config-file öffnen */
|
/* config-file öffnen */
|
||||||
if (!(in = fopen(file, "r"))) {
|
if (!(in = fopen(file, "r"))) {
|
||||||
DEBUGOUT2("Kann Config-File: %s nicht öffnen!\n", file);
|
DEBUGOUT2("Kann Config-File: '%s' nicht öffnen!\n", file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,21 +18,23 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: process.c v 1.00 11 Aug 2006 losinski $
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Datenstruktur zum Auswerten des Config-Files */
|
/* Datenstruktur zum Auswerten des Config-Files */
|
||||||
struct config_keyword {
|
typedef struct config_keyword_t {
|
||||||
const char *keyword;
|
const char *keyword;
|
||||||
int (* const handler)(const char *line, void *var);
|
int (* const handler)(const char *line, void *var);
|
||||||
void *var;
|
void *var;
|
||||||
const char *def;
|
const char *def;
|
||||||
} ;
|
} config_keyword;
|
||||||
|
|
||||||
/* Config lesen */
|
/* Config lesen */
|
||||||
int read_config(const char *, int);
|
int read_config(char *, int , const config_keyword *);
|
||||||
|
|
||||||
|
|
||||||
|
/* Config-Zeilen auswerten */
|
||||||
|
int read_str(const char *, void *);
|
||||||
|
int read_int(const char *, void *);
|
||||||
|
int read_yn(const char *, void *);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
typedef struct image_cfg_t {
|
||||||
|
char *img_name;
|
||||||
|
} image_cfg;
|
||||||
|
|
||||||
|
|
||||||
|
extern image_cfg img_cfg;
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
chart.c -- Part of Chart-generator for the weatherstation
|
||||||
|
|
||||||
|
Copyright (C) 2006 Jan Losinski
|
||||||
|
|
||||||
|
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 2 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, write to the Free Software
|
||||||
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "../common.h"
|
||||||
|
#include "image_common.h"
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
|
/* Zuordnung zwischen Schlüsselwörtern in der Config, Der Funktion, die diese auswertet
|
||||||
|
* und dem eld in der Options-Struktur */
|
||||||
|
static const config_keyword keywords[] = {
|
||||||
|
/* keyword handler variable address default */
|
||||||
|
{"filename", read_str, &(img_cfg.img_name), ""},
|
||||||
|
/* {"image_cfg", add_image_cfg, &(global_opts.image_cfg), ""},
|
||||||
|
{"image_cfg_location",read_str, &(global_opts.image_cfg_location), DEFAULT_PG_HOST},
|
||||||
|
*/
|
||||||
|
{"", NULL, NULL, ""}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
get_image_cfg(char *file){
|
||||||
|
char *buff = malloc(sizeof(char)*(strlen(file)+strlen(global_opts.image_cfg_location)+1));
|
||||||
|
|
||||||
|
buff = strcpy(buff, global_opts.image_cfg_location);
|
||||||
|
buff = strcat(buff, file);
|
||||||
|
|
||||||
|
printf("dada\n");
|
||||||
|
|
||||||
|
return read_config(file, 1, keywords);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
chart.c -- Part of Chart-generator for the weatherstation
|
||||||
|
|
||||||
|
Copyright (C) 2006 Jan Losinski
|
||||||
|
|
||||||
|
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 2 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, write to the Free Software
|
||||||
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
int get_image_cfg(char *);
|
||||||
|
|
@ -21,9 +21,25 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "../definitions.h"
|
||||||
|
#include "../common.h"
|
||||||
|
#include "image_common.h"
|
||||||
#include "image_file.h"
|
#include "image_file.h"
|
||||||
|
#include "image_config.h"
|
||||||
|
|
||||||
|
|
||||||
|
image_cfg img_cfg;
|
||||||
|
|
||||||
void process_image_cfg(char *image_cfg_file){
|
void process_image_cfg(char *image_cfg_file){
|
||||||
printf("%s\n",image_cfg_file);
|
printf("%s\n",image_cfg_file);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
get_image_cfg(image_cfg_file);
|
||||||
|
|
||||||
|
if (img_cfg.img_name != NULL){
|
||||||
|
DEBUGOUT2("Image-Name = %s\n",img_cfg.img_name);
|
||||||
|
}
|
||||||
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
filename testbildl
|
||||||
Loading…
Reference in New Issue