From 9587b39707d648bc91d8e7378c6fc215a629b52a Mon Sep 17 00:00:00 2001 From: David Kopf Date: Tue, 8 Nov 2011 12:14:31 -0500 Subject: [PATCH] atmega128rfa1 ajax power and sensor reporting, longint calculation bugfixes. --- apps/webserver-nano/httpd-cgi.c | 228 ++++++++++++++---- .../httpd-fs/makefsdata.ignore/ajax.js | 9 +- apps/webserver-nano/httpd.h | 8 +- 3 files changed, 192 insertions(+), 53 deletions(-) diff --git a/apps/webserver-nano/httpd-cgi.c b/apps/webserver-nano/httpd-cgi.c index b7d6b6d5b..42bb03ede 100644 --- a/apps/webserver-nano/httpd-cgi.c +++ b/apps/webserver-nano/httpd-cgi.c @@ -61,7 +61,7 @@ #if CONTIKI_TARGET_REDBEE_ECONOTAG #include "adc.h" #endif - +short sleepcount; #if WEBSERVER_CONF_CGI static struct httpd_cgi_call *calls = NULL; /*cgi function names*/ @@ -346,9 +346,7 @@ make_tcp_stats(void *arg) conn = &uip_conns[s->u.count]; numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_tcpstat1, uip_htons(conn->lport)); -#if WEBSERVER_CONF_PRINTADDR numprinted += httpd_cgi_sprint_ip6(conn->ripaddr, uip_appdata + numprinted); -#endif httpd_strcpy(tstate,states[conn->tcpstateflags & UIP_TS_MASK]); numprinted += httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_tcpstat2, @@ -429,13 +427,10 @@ uint16_t numprinted; for (i=0; i>2); //Convert to celcius*10 (should be 11.3*h, approximate with 11.25*h) + ADCSRA=0; //disable ADC + ADMUX=0; //turn off internal vref + m=h/10;s=h-10*m; + static const char httpd_cgi_sensor1_printf[] HTTPD_STRING_ATTR = "%d.%d C"; + httpd_snprintf(sensor_temperature,sizeof(sensor_temperature),httpd_cgi_sensor1_printf,m,s); +#endif + +/* Bandgap can't be measured against supply voltage in this chip. */ +/* Use BATMON register instead */ + for ( i=16; i<31; i++) { + BATMON = i; + if ((BATMON&(1<sout); /*TODO:pick up time from ? parameter */ - timer_set(&t, 1*CLOCK_SECOND); + timer_set(&t, 2*CLOCK_SECOND); iter = 0; while(1) { + iter++; #if CONTIKI_TARGET_SKY SENSORS_ACTIVATE(sht11_sensor); @@ -911,6 +939,7 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr)) light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR)); SENSORS_DEACTIVATE(sht11_sensor); SENSORS_DEACTIVATE(light_sensor); + #elif CONTIKI_TARGET_MB851 SENSORS_ACTIVATE(acc_sensor); numprinted = snprintf(buf, sizeof(buf),"t(%d);ax(%d);ay(%d);az(%d);", @@ -921,16 +950,15 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr)) SENSORS_DEACTIVATE(acc_sensor); #elif CONTIKI_TARGET_REDBEE_ECONOTAG -{ -//#include "adc.h" - uint8_t c; +{ 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]); -} +} + #elif CONTIKI_TARGET_MINIMAL_NET static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c7=0x3ff; numprinted = snprintf(buf, sizeof(buf), "t(%d);b(%u);v(%u);",273+(rand()&0x3f),3300-iter/10,iter); @@ -943,11 +971,98 @@ static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c c5+=(rand()&0xf)-8; c6+=(rand()&0xf)-8; c7+=(rand()&0xf)-8; -#else - numprinted = snprintf(buf, sizeof(buf), "v(%u);",iter); + if (iter==1) { + static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Minimal-net "; + 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>2); //Convert to celcius*10 (should be 11.3*h, approximate with 11.25*h) + ADCSRA=0; //disable ADC + ADMUX=0; //turn off internal vref +#endif +/* Bandgap can't be measured against supply voltage in this chip. */ +/* Use BATMON register instead */ + for ( i=16; i<31; i++) { + BATMON = i; + if ((BATMON&(1<sout, buf); timer_restart(&t); PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t)); - iter++; } PSOCK_END(&s->sout); } @@ -1088,7 +1221,6 @@ uint8_t httpd_cgi_sprint_ip6(uip_ip6addr_t addr, char * result) unsigned char numprinted = 0; char * starting = result; unsigned char i = 0; - while (numprinted < 8) { //Address is zero, have we used our ability to @@ -1111,6 +1243,8 @@ uint8_t httpd_cgi_sprint_ip6(uip_ip6addr_t addr, char * result) //Cool - can replace a bunch of zeros i += zerocnt; numprinted += zerocnt; + //all zeroes ? + if (zerocnt > 7) {*result++ = ':';*result++ = ':';} } //Normal address, just print it else diff --git a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js index 0f220f4e7..eb487ac5a 100644 --- a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js +++ b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ajax.js @@ -4,6 +4,7 @@ function e(el){return document.getElementById(el);} function ls(){try{r=new XMLHttpRequest();}catch(e){alert("Browswer does not support Ajax");return false;}r.open("GET","/ajaxdata.shtml",true); x=0;r.onreadystatechange=function(){e('date').innerHTML=(new Date()).toTimeString();if(r.readyState>0){j=r.responseText.substr(x);x+=j.length;eval(j);}};r.send(null);} function s(el,n,max,text){e(el).innerHTML=''+''+''+''+'
'+text+'  
';} +function wt(m){document.title=m;e('v').innerHTML=m;} function dc(n,d){return n.toFixed(d);} function t(m){n=dc(m/10,1);s('temp',n,50,'Temperature '+n+' °C');} function b(m){s('batt',m,5000,'Battery '+dc(m/1000,3)+' volts');} @@ -11,11 +12,11 @@ function ax(m){s('ax',m+2000,4000,'Acceleration (X-axis) '+m+'mg');} function ay(m){s('ay',m+2000,4000,'Acceleration (Y-axis) '+m+'mg');} function az(m){s('az',m+2000,4000,'Acceleration (Z-axis) '+m+'mg');} function rs(m){s('rs',n,100,'RSSI '+n);} -function p(c,l,t,r){tm=c+1;cp=c*18/tm;lt=t*50.4/tm;lr=r*45.6/tm;n=cp+lt+lr; - s('p',n,100,'Power consumption '+dc(n,2)+' mW'); +function p(c,l,t,r){cp=0.136*c;lt=0.478*t;lr=0.412*r;n=cp+lt+lr;//128rfa1@3v3 + s('p',n,200,'Power consumption '+dc(n,2)+' mW'); s('pc',cp,100,'CPU power '+dc(cp,2)+' mW'); - s('pr',lr,100,'Radio RX power '+dc(lr,2)+' mW'); - s('pt',lt,100,'Radio TX power '+dc(lt,2)+' mW');} + s('pr',lr,200,'Radio RX power '+dc(lr,2)+' mW'); + s('pt',lt,200,'Radio TX power '+dc(lt,2)+' mW');} function adc(a0,a1,a2,a3,a4,a5,a6,a7){var t=e('csv'),s=t.scrollTop; t.value+=dc(((new Date()).getTime()-sts.getTime())/1000,1)+','+a0+','+a1+','+a2+','+a3+','+a4+','+a5+','+a6+','+a7+'\r'; if((s+t.clientHeight+30)