From 85b11538f7d5046e572ba5c43adf358537526789 Mon Sep 17 00:00:00 2001 From: dak664 Date: Fri, 12 Feb 2010 16:42:59 +0000 Subject: [PATCH] Add RADIOSTATS to sensors cgi --- .../avr-raven/apps/raven-webserver/httpd-cgi.c | 92 ++++++++++++++++++++-- .../avr-raven/apps/raven-webserver/httpd-cgi.h | 3 +- 2 files changed, 88 insertions(+), 7 deletions(-) diff --git a/platform/avr-raven/apps/raven-webserver/httpd-cgi.c b/platform/avr-raven/apps/raven-webserver/httpd-cgi.c index 801b9fff..bc92d38a 100644 --- a/platform/avr-raven/apps/raven-webserver/httpd-cgi.c +++ b/platform/avr-raven/apps/raven-webserver/httpd-cgi.c @@ -28,7 +28,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: httpd-cgi.c,v 1.5 2010/02/09 14:41:18 dak664 Exp $ + * $Id: httpd-cgi.c,v 1.6 2010/02/12 16:42:59 dak664 Exp $ * */ @@ -61,6 +61,9 @@ extern char TCPBUF[512]; #endif +/* RADIOSTATS must also be set in clock.c and the radio driver */ +#define RADIOSTATS 0 + static struct httpd_cgi_call *calls = NULL; /*cgi function names*/ @@ -98,12 +101,28 @@ static const char *states[] = { running, called}; - char sensor_temperature[12]; + static char sensor_temperature[12]="Not Enabled"; + static char sensor_extvoltage[12]="Not Enabled"; + static unsigned long last_tempupdate,last_extvoltageupdate; + extern unsigned long seconds; +#if RADIOSTATS + extern unsigned long radioontime; + extern uint8_t RF230_radio_on, RF230_rsigsi; + extern uint16_t RF230_sendpackets,RF230_receivepackets,RF230_sendfail,RF230_receivefail; +#endif + void web_set_temp(char *s) { strcpy(sensor_temperature, s); + last_tempupdate=seconds; +} +void +web_set_voltage(char *s) +{ + strcpy(sensor_extvoltage, s); + last_extvoltageupdate=seconds; } /*---------------------------------------------------------------------------*/ @@ -265,11 +284,68 @@ PT_THREAD(processes(struct httpd_state *s, char *ptr)) static unsigned short generate_sensor_readings(void *arg) { - static const char httpd_cgi_sensor1[] HTTPD_STRING_ATTR = "Temperature: Not enabled\n"; - static const char httpd_cgi_sensor2[] HTTPD_STRING_ATTR = "Temperature: %s\n"; - if (!sensor_temperature[0]) return httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_sensor1); - return httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_sensor2, sensor_temperature); + uint16_t numprinted; + uint16_t h,m,s; + static const char httpd_cgi_sensor0[] HTTPD_STRING_ATTR = "[Updated %d seconds ago]

"; + static const char httpd_cgi_sensor1[] HTTPD_STRING_ATTR = "Temperature: %s
"; + static const char httpd_cgi_sensor2[] HTTPD_STRING_ATTR = "Voltage: %s
"; + static const char httpd_cgi_sensor3[] HTTPD_STRING_ATTR = "Up time: %02d:%02d:%02d
"; + + numprinted=0; + if (last_tempupdate) { + numprinted =httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_sensor0,seconds-last_tempupdate); + } + + numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensor1, sensor_temperature); + +#if 0 +//Measuring AVcc might be useful to check on battery condition but on ext power it's always 3v3 + ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference. +//ADMUX =0x5E; //Select AVCC as reference, measure 1.1 volt bandgap reference. + ADCSRA=0x07; //Enable ADC, not free running, interrupt disabled, clock divider 128 (62 KHz@ 8 MHz) + ADCSRA|=1<sout); PSOCK_GENERATOR_SEND(&s->sout, generate_sensor_readings, s); +#if RADIOSTATS + PSOCK_GENERATOR_SEND(&s->sout, generate_radio_stats, s); +#endif + PSOCK_END(&s->sout); } diff --git a/platform/avr-raven/apps/raven-webserver/httpd-cgi.h b/platform/avr-raven/apps/raven-webserver/httpd-cgi.h index 60cb7c7f..5ec87162 100644 --- a/platform/avr-raven/apps/raven-webserver/httpd-cgi.h +++ b/platform/avr-raven/apps/raven-webserver/httpd-cgi.h @@ -28,7 +28,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: httpd-cgi.h,v 1.2 2010/02/09 14:41:18 dak664 Exp $ + * $Id: httpd-cgi.h,v 1.3 2010/02/12 16:42:59 dak664 Exp $ * */ @@ -55,6 +55,7 @@ static struct httpd_cgi_call name = {NULL, str, function} void httpd_cgi_init(void); void web_set_temp(char *s); +void web_set_voltage(char *s); uint8_t httpd_cgi_sprint_ip6(uip_ip6addr_t addr, char * result); #endif /* __HTTPD_CGI_H__ */ -- 2.11.4.GIT