From 709822042c51d2260fea015db7d80e12b123373b Mon Sep 17 00:00:00 2001 From: David Kopf Date: Fri, 2 Mar 2012 15:51:42 -0500 Subject: [PATCH] Redo html output, more options, httpd state variables to allow neighbors and routes to span tcp segments. --- apps/webserver-nano/httpd-cgi.c | 273 ++++++++++++++++++++++---------- apps/webserver-nano/httpd.h | 32 +++- 2 files changed, 215 insertions(+), 90 deletions(-) diff --git a/apps/webserver-nano/httpd-cgi.c b/apps/webserver-nano/httpd-cgi.c index 8a78bee0a..ba36461e1 100644 --- a/apps/webserver-nano/httpd-cgi.c +++ b/apps/webserver-nano/httpd-cgi.c @@ -283,7 +283,7 @@ generate_file_stats(void *arg) { struct httpd_state *s = (struct httpd_state *)arg; #if WEBSERVER_CONF_LOADTIME - static const char httpd_cgi_filestat1[] HTTPD_STRING_ATTR = "



This page has been sent %u times (%1u.%u sec)"; + static const char httpd_cgi_filestat1[] HTTPD_STRING_ATTR = "



This page has been sent %u times (%1u.%02u sec)"; #else static const char httpd_cgi_filestat1[] HTTPD_STRING_ATTR = "



This page has been sent %u times"; #endif @@ -301,7 +301,7 @@ generate_file_stats(void *arg) #if WEBSERVER_CONF_LOADTIME s->pagetime = clock_time() - s->pagetime; numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat1, httpd_fs_open(s->filename, 0), - (unsigned int)s->pagetime/CLOCK_SECOND,(unsigned int)s->pagetime%CLOCK_SECOND); + (unsigned int)s->pagetime/CLOCK_SECOND,(100*((unsigned int)s->pagetime%CLOCK_SECOND))/CLOCK_SECOND); #else numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat1, httpd_fs_open(s->filename, 0)); #endif @@ -433,10 +433,12 @@ PT_THREAD(processes(struct httpd_state *s, char *ptr)) #endif /* WEBSERVER_CONF_PROCESSES */ #if WEBSERVER_CONF_ADDRESSES || WEBSERVER_CONF_NEIGHBORS || WEBSERVER_CONF_ROUTES -static const char httpd_cgi_addrh[] HTTPD_STRING_ATTR = ""; -static const char httpd_cgi_addrf[] HTTPD_STRING_ATTR = "[Room for %u more]"; -static const char httpd_cgi_addrb[] HTTPD_STRING_ATTR = "
"; -static const char httpd_cgi_addrn[] HTTPD_STRING_ATTR = "(none)
"; +#if WEBSERVER_CONF_SHOW_ROOM +static const char httpd_cgi_addrf[] HTTPD_STRING_ATTR = "[Room for %u more]\n"; +#else +static const char httpd_cgi_addrf[] HTTPD_STRING_ATTR = "[Table is full]\n"; +#endif +static const char httpd_cgi_addrn[] HTTPD_STRING_ATTR = "[None]\n"; #endif #if WEBSERVER_CONF_ADDRESSES @@ -447,16 +449,21 @@ static unsigned short make_addresses(void *p) { uint8_t i,j=0; -uint16_t numprinted; - numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(),httpd_cgi_addrh); +uint16_t numprinted = 0; for (i=0; istarti;j=s->startj; + for (;i (uip_mss() - 50)) { + s->savei=i;s->savej=j; + return numprinted; + } } } - numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf,UIP_DS6_NBR_NB-j); +#if WEBSERVER_CONF_SHOW_ROOM + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf,UIP_DS6_NBR_NB-j); +#else + if(UIP_DS6_NBR_NB == j) { + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf); + } +#endif + + /* Signal that this was the last segment */ + s->savei = 0; return numprinted; } /*---------------------------------------------------------------------------*/ @@ -496,7 +541,13 @@ PT_THREAD(neighbors(struct httpd_state *s, char *ptr)) { PSOCK_BEGIN(&s->sout); - PSOCK_GENERATOR_SEND(&s->sout, make_neighbors, s->u.ptr); + /* Send as many TCP segments as needed for the neighbor table */ + /* Move to next seqment after each successful transmission */ + s->starti=s->startj=0; + do { + PSOCK_GENERATOR_SEND(&s->sout, make_neighbors, (void *)s); + s->starti=s->savei+1;s->startj=s->savej; + } while(s->savei); PSOCK_END(&s->sout); } @@ -508,27 +559,57 @@ extern uip_ds6_route_t uip_ds6_routing_table[]; static unsigned short make_routes(void *p) { -static const char httpd_cgi_rtes1[] HTTPD_STRING_ATTR = "(%u (via "; -static const char httpd_cgi_rtes2[] HTTPD_STRING_ATTR = ") %lus
"; -static const char httpd_cgi_rtes3[] HTTPD_STRING_ATTR = ")
"; -uint8_t i,j=0; -uint16_t numprinted; - numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(),httpd_cgi_addrh); - for (i=0; istarti;j=s->startj; + for (;i (uip_mss() - 200)) { + s->savei=i;s->savej=j; + return numprinted; + } } } if (j==0) numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrn); - numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf,UIP_DS6_ROUTE_NB-j); +#if WEBSERVER_CONF_SHOW_ROOM + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf,UIP_DS6_ROUTE_NB-j); +#else + if(UIP_DS6_ROUTE_NB == j) { + numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf); + } +#endif + + /* Signal that this was the last segment */ + s->savei = 0; return numprinted; } /*---------------------------------------------------------------------------*/ @@ -536,8 +617,14 @@ static PT_THREAD(routes(struct httpd_state *s, char *ptr)) { PSOCK_BEGIN(&s->sout); - - PSOCK_GENERATOR_SEND(&s->sout, make_routes, s->u.ptr); + + /* Send as many TCP segments as needed for the route table */ + /* Move to next seqment after each successful transmission */ + s->starti=s->startj=0; + do { + PSOCK_GENERATOR_SEND(&s->sout, make_routes, s); + s->starti=s->savei+1;s->startj=s->savej; + } while(s->savei); PSOCK_END(&s->sout); } @@ -548,18 +635,15 @@ PT_THREAD(routes(struct httpd_state *s, char *ptr)) static unsigned short generate_sensor_readings(void *arg) { - uint16_t numprinted; + uint16_t numprinted=0; uint16_t days,h,m,s; unsigned long seconds=clock_seconds(); - static const char httpd_cgi_sensor0[] HTTPD_STRING_ATTR = "[Updated %d seconds ago]

"; - static const char httpd_cgi_sensor1[] HTTPD_STRING_ATTR = "

Temperature: %s\n";
+  static const char httpd_cgi_sensor0[] HTTPD_STRING_ATTR = "[Updated %d seconds ago]\n";
+  static const char httpd_cgi_sensor1[] HTTPD_STRING_ATTR = "Temperature: %s\n";
   static const char httpd_cgi_sensor2[] HTTPD_STRING_ATTR = "Battery    : %s\n";
-//  static const char httpd_cgi_sensr12[] HTTPD_STRING_ATTR = "Temperature: %s   Battery: %s
"; static const char httpd_cgi_sensor3[] HTTPD_STRING_ATTR = "Uptime : %02d:%02d:%02d\n"; static const char httpd_cgi_sensor3d[] HTTPD_STRING_ATTR = "Uptime : %u days %02u:%02u:%02u\n"; -// static const char httpd_cgi_sensor4[] HTTPD_STRING_ATTR = "Sleeping time : %02d:%02d:%02d (%d%%)
"; - numprinted=0; /* Generate temperature and voltage strings for each platform */ #if CONTIKI_TARGET_AVR_ATMEGA128RFA1 {uint8_t i; @@ -623,29 +707,36 @@ generate_sensor_readings(void *arg) #elif CONTIKI_TARGET_REDBEE_ECONOTAG //#include "adc.h" { +#if 0 +/* Scan ADC channels if not already being done elsewhere */ uint8_t c; - adc_reading[8]=0; - adc_init(); - while (adc_reading[8]==0) adc_service(); - // for (c=0; csout); PSOCK_GENERATOR_SEND(&s->sout, generate_sensor_readings, s); -#if RADIOSTATS - PSOCK_GENERATOR_SEND(&s->sout, generate_radio_stats, s); +#if WEBSERVER_CONF_STATISTICS + PSOCK_GENERATOR_SEND(&s->sout, generate_stats, s); #endif PSOCK_END(&s->sout); @@ -971,15 +1055,40 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr)) SENSORS_DEACTIVATE(acc_sensor); #elif CONTIKI_TARGET_REDBEE_ECONOTAG -{ uint8_t c; - adc_reading[8]=0; - adc_init(); - while (adc_reading[8]==0) adc_service(); - adc_disable(); - numprinted = snprintf(buf, sizeof(buf),"b(%u);adc(%u,%u,%u,%u,%u,%u,%u,%u);", - 1200*0xfff/adc_reading[8],adc_reading[0],adc_reading[1],adc_reading[2],adc_reading[3],adc_reading[4],adc_reading[5],adc_reading[6],adc_reading[7]); +#if 0 +/* Scan ADC channels if not already done elsewhere */ +{ uint8_t c; + adc_reading[8]=0; + adc_init(); + while (adc_reading[8]==0) adc_service(); + adc_disable(); +#endif + +#if 0 + numprinted = snprintf(buf, sizeof(buf),"b(%u);adc(%u,%u,%u,%u,%u,%u,%u,%u);", + 1200*0xfff/adc_reading[8],adc_reading[0],adc_reading[1],adc_reading[2],adc_reading[3],adc_reading[4],adc_reading[5],adc_reading[6],adc_reading[7]); +#else + // numprinted = snprintf(buf, sizeof(buf),"b(%u);",1200*0xfff/adc_reading[8]); + numprinted = snprintf(buf, sizeof(buf),"b(%u);adc(%u,%u,%u);",1200*0xfff/adc_reading[8],adc_reading[1],adc_reading[7],adc_reading[8]); +#endif } - + if (iter<3) { + static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Econtag ["; + static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');"; + numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11); +#if WEBSERVER_CONF_PRINTADDR +/* Note address table is filled from the end down */ +{int i; + for (i=0; i