worging on checksensor
git-svn-id: file:///home/jan/tmp/wetterstation/trunk@55 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
25e235a8a6
commit
008cbba0cf
|
|
@ -18,7 +18,6 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: process.c v 1.00 11 Aug 2006 losinski $
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -108,28 +107,40 @@ static void get_sensors_from_db(){
|
|||
connection = NULL;
|
||||
}
|
||||
|
||||
static int count_data_by_sensor_id(PGconn *connection, int sens_id){
|
||||
int table_field;
|
||||
int count_field;
|
||||
char *query_buff = malloc(sizeof(char)*BUFFSIZE);
|
||||
static char *get_type_table_by_id(PGconn *connection, int sens_id){
|
||||
char *table;
|
||||
int count;
|
||||
int table_field;
|
||||
PGresult *table_res;
|
||||
PGresult *count_res;
|
||||
|
||||
DEBUGOUT2("\nPrüfe Sensor mit ID: %d ... \n",sens_id);
|
||||
char *query_buff = malloc(sizeof(char)*BUFFSIZE);
|
||||
|
||||
snprintf(query_buff, BUFFSIZE, "select typen.tabelle as tbl FROM typen, sensoren WHERE sensoren.id=%d AND typen.typ=sensoren.typ", sens_id);
|
||||
table_res = pg_check_exec(connection, query_buff);
|
||||
|
||||
if(PQntuples(table_res) < 1)
|
||||
return -1;
|
||||
return NULL;
|
||||
|
||||
table_field = PQfnumber(table_res, "tbl");
|
||||
table = PQgetvalue(table_res, 0, table_field);
|
||||
table = strdup(PQgetvalue(table_res, 0, table_field));
|
||||
|
||||
DEBUGOUT2("\tTabelle: %s \n", table);
|
||||
|
||||
PQclear(table_res);
|
||||
free(query_buff);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
static int count_data_by_sensor_id(PGconn *connection, int sens_id){
|
||||
int count_field;
|
||||
char *table;
|
||||
char *query_buff = malloc(sizeof(char)*BUFFSIZE);
|
||||
int count;
|
||||
PGresult *count_res;
|
||||
|
||||
DEBUGOUT2("\nPrüfe Sensor mit ID: %d ... \n",sens_id);
|
||||
|
||||
table = get_type_table_by_id(connection, sens_id);
|
||||
|
||||
snprintf(query_buff, BUFFSIZE, "SELECT count(sens_id) as num FROM %s WHERE sens_id=%d AND timestamp>(current_timestamp - INTERVAL '%d hours')",table, sens_id, global_opts.interval);
|
||||
count_res = pg_check_exec(connection, query_buff);
|
||||
|
||||
|
|
@ -142,13 +153,49 @@ static int count_data_by_sensor_id(PGconn *connection, int sens_id){
|
|||
DEBUGOUT3("\tWerte in den letzten %d Stunden: %d\n", global_opts.interval, count);
|
||||
|
||||
PQclear(count_res);
|
||||
PQclear(table_res);
|
||||
free(table);
|
||||
free(query_buff);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static sens_info_list_ptr get_sensor_info(PGconn *conn, int id, int count){
|
||||
sens_info_list_ptr new_info;
|
||||
PGresult *res;
|
||||
int typ_desc_field;
|
||||
int sens_desc_field;
|
||||
int sens_loc_field;
|
||||
char *sens_desc;
|
||||
char *type_desc;
|
||||
char *sens_location;
|
||||
char *query_buff = malloc(sizeof(char)*BUFFSIZE);
|
||||
|
||||
snprintf(query_buff, BUFFSIZE, "SELECT typen.bezeichnung as type_desc, sensoren.standort as sens_location, sensoren.beschreibung as sens_desc FROM sensoren, typen WHERE sensoren.id=%d AND typen.typ=sensoren.typ",id);
|
||||
res = pg_check_exec(conn, query_buff);
|
||||
|
||||
if(PQntuples(res) < 1)
|
||||
return NULL;
|
||||
|
||||
typ_desc_field = PQfnumber(res, "type_desc");
|
||||
sens_desc_field = PQfnumber(res, "sens_desc");
|
||||
sens_loc_field = PQfnumber(res, "sens_location");
|
||||
|
||||
|
||||
new_info = malloc(sizeof(sensor_info));
|
||||
|
||||
|
||||
new_info->id = id;
|
||||
new_info->count = count;
|
||||
new_info->type_desc = strdup(PQgetvalue(res, 0, typ_desc_field));
|
||||
new_info->sens_desc = strdup(PQgetvalue(res, 0, sens_desc_field));
|
||||
new_info->sens_location = strdup(PQgetvalue(res, 0, sens_loc_field));
|
||||
new_info->next = NULL;
|
||||
|
||||
PQclear(res);
|
||||
free(query_buff);
|
||||
|
||||
return new_info;
|
||||
}
|
||||
|
||||
static int check_sensors(){
|
||||
sens_id_list_ptr temp_ptr = global_opts.sens_id_list;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,15 @@ typedef struct {
|
|||
char *mail_auth_pass;
|
||||
} w_opts;
|
||||
|
||||
|
||||
typedef struct sens_info_list *sens_info_list_ptr;
|
||||
typedef struct sens_info_list {
|
||||
int id;
|
||||
int count;
|
||||
char *type_desc;
|
||||
char *sens_location;
|
||||
char *sens_desc;
|
||||
sens_info_list_ptr next;
|
||||
} sensor_info;
|
||||
|
||||
/* Funktionen -------------------------------------------------------------*/
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ static int default_auth_cb (auth_client_request_t , char **, int , void *);
|
|||
|
||||
|
||||
/* Funktion zum versenden von Mails */
|
||||
int mail_message(address_all_struct *addresses, char *subject, int eightbit, mail_linereader_cb line_read_cb, server_vars *servopts){
|
||||
int mail_message(address_all_struct *addresses, char *subject, int eightbit, mail_linereader_cb line_read_cb, void *line_read_cb_arg, server_vars *servopts){
|
||||
|
||||
FILE *fd = NULL; /* Zeiger auf Temporaere Datei */
|
||||
int i = 0; /* Laufvariable */
|
||||
|
|
@ -102,7 +102,7 @@ int mail_message(address_all_struct *addresses, char *subject, int eightbit, ma
|
|||
return MAILER_STATUS_FAILTURE_CREATE_HEADER;
|
||||
|
||||
i = 0;
|
||||
while((buf = line_read_cb(i)) != NULL){ /* Solange die Callbackfunktion einen Zeiger auf einen Puffer liefert */
|
||||
while((buf = line_read_cb(i, line_read_cb_arg)) != NULL){ /* Solange die Callbackfunktion einen Zeiger auf einen Puffer liefert */
|
||||
fputs(buf, fd); /* Schreibe dessen Inhalt in eine Datei */
|
||||
i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,8 +62,10 @@
|
|||
#define MAILER_STATUS_FAILTURE_CREATE_HEADER 13 /* Header kann nicht gebaut werden */
|
||||
|
||||
|
||||
/* Die Callback-fkt. zum lesen einer Zeile. das Argument ist die momentane Zeilennummer (beginnend bei 0) */
|
||||
typedef char *(mail_linereader_cb)(int line);
|
||||
/* Die Callback-fkt. zum lesen einer Zeile.
|
||||
* das 1. Argument ist die momentane Zeilennummer (beginnend bei 0)
|
||||
* das 2. Argument ist das Argument, welches der mail_message-fkt. uebergeben wurde */
|
||||
typedef char *(mail_linereader_cb)(int line, void *arg);
|
||||
|
||||
/* Datenstruktur für die Addressliste */
|
||||
typedef struct address_t {
|
||||
|
|
@ -101,9 +103,10 @@ typedef struct server_vars_t {
|
|||
* 2. Argument: Betreff der Nachicht
|
||||
* 3. Argument: eightbit-flag setzen oder nicht
|
||||
* 4. Argument: Callback-Fkt. zum lesen einer Zeile
|
||||
* 5. Argument: Server-Einstellungen
|
||||
* 5. Argument: Argument für die Callback-Fkt.
|
||||
* 6. Argument: Server-Einstellungen
|
||||
* gibt einen Statusnummer zurueck */
|
||||
int mail_message(address_all_struct *, char *, int, mail_linereader_cb, server_vars *);
|
||||
int mail_message(address_all_struct *, char *, int, mail_linereader_cb, void *, server_vars *);
|
||||
|
||||
|
||||
/* Gibt ein grundgerüst mit default-servereinstellungen
|
||||
|
|
|
|||
Loading…
Reference in New Issue