Code Search for Developers
 
 
  

toolsPageQuery.c from EmStar at Krugle


Show toolsPageQuery.c syntax highlighted

/*
 *
 * Copyright (c) 2003 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

char cgi_template_c_cvsid[] = "$Id: toolsPageQuery.c,v 1.1 2005/12/15 18:30:26 karenyc Exp $";

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libdev/status_client.h>
#include <libmisc/misc_buf.h>
#include <libmisc/misc_init.h>

#include <devel/http/cgic.h>
#include <devel/http/html.h>
#include <string.h>


void http_header(FILE* output_stream) {
  cgiHeaderContentType("text/html");
  fflush(output_stream);
}



int process_cgi(FILE* output_stream) {

  html_banner(cgiOut, "TOOLS", "Send Query" ,"#FF3399");



  //Sends a query to the mote network in the form of "id=x:[type]:period=y:sensors=a,b"

  char node_id[100];
  char period[500];
  int sensorChoices[41];
  char *sensors[]={
    "humidity",
    "temperature",
    "dewPoint",
    "windSpeed",
    "solarRadiation",
    "leafWetness",
    "windDirection",
    "barometer",
    "rain",
    "lightning",
    "enclosureHumidity",
    "gust",
    "messageLossAtCH1",
    "messageSent",
    "hopsToCH1",
    "moteBattery",
    "insideTemperature",
    "insideHumidity",
    "parCurrent",
    "insideThermopile",
    "analog0",
    "analog1",
    "soilMoistureAt15cm",
    "soilMoistureAt50cm",
    "soilTemperatureAt100cm",
    "soilTemperatureAt30cm",
    "enclosureTemperature",
    "soilTemperatureAt15cm",
    "soilTemperatureAt50cm",
    "analog2",
    "analog3",
    "analog4",
    "analog5",
    "analog6",
    "analog7",
    "parL11905A",
    "parNT53373",
    "parNT53373_2",
    "thermister",
    "humidity_1500_33_JR",
    "thermistor_NTC_25_JR"
  };
   

  int result;
  int invalid;
  int i=0;
  char *types[]= {
    "delete",
    "periodic",
    "cond",
    "single",
    "event",
    "agg"
  };
  int typeChoice;
  char command[256]="id=";
  char qid[10];
  char *list[100];
  int x=0;
  int j=0;
  int commas=0;
  char temp[5]="";
  FILE *f;
  char *queries;
  char s[1];
  int newlines =0;
  int index=0;
  int k=0;
  int query_id= 1;
   
  for( x=0; x <100 ; x++){
    list[x]=calloc(5, 1);
  }

  fprintf(cgiOut, "<FORM ACTION=\"/cgi-bin/toolsPageQuery.cgi\" METHOD=\"POST\"> ");


  //allows users to enter node ID value
  fprintf(cgiOut, "<br>Enter the Node ID (0 if in non sim mode): ");
  fprintf(cgiOut, " <INPUT TYPE=\"text\" NAME=\"my_node_id\" VALUE=\"0\" size=\"6\" maxlength =\"4\"> ");
  if(cgiFormString( "my_node_id", node_id, sizeof(node_id)) == cgiFormSuccess) 
    fprintf( cgiOut, "<br> <font color=#FF3399>Node ID is set to %s.</font>", node_id);
  
  my_node_id = atoi(node_id); 


  //parses out a list of Active Query ID's from the /dev/dse/query file
  //and assigns new query id to new query
  queries = sim_path("/dev/dse/query");
  f = fopen(queries, "r");
   
   if (f == NULL) {
     if(cgiFormSubmitClicked("submit") == cgiFormSuccess)
	fprintf(cgiOut, "<br> query error on open: %m \n");
   }
   
   else{
     while(fgets(s, 2,f)!= NULL ){
       if((*s) == '\n'){
	 newlines++;
       }
       if(newlines ==4){
	 break;
       }
     }  
     //checks for whether any queries have been sent at all
     //and if so, stores all the active query IDs in an array of strings
     
     fgets(s, 2, f);
     if( (*s) == '\n'){
       index=0;
     }
     else {
       
       ungetc((*s), f);  
       while( fgets(s, 2, f)!= NULL){
	 temp[0]='\0';
	 while(!isdigit(*s)){
	   fgets(s, 2, f);
	 }
	 while(( isdigit(*s))){
	   strcat(temp, s);
	   fgets(s, 2, f);
	 }
	 while(fgets(s, 2, f)!= NULL){
	   if( (*s) == '\n')
	     break;
	 }
	 strcpy( list[index],  temp);
	 index++;
	 fgets(s, 2, f);
	 if( (*s) == '\n')
	   break;
	 else 
	   ungetc((*s), f);
       }  
       while( k < index ){
	 if( query_id == atoi(list[k])){
	   query_id++;
	   k=-1;
	 }
	 k++;
       }
  
     }
   }
   sprintf( qid, "%i",query_id);
   strcat(command, qid); 


   //allows users to select a type
  fprintf(cgiOut, "<br><br>Select a type:  ");
  fprintf(cgiOut, "<SELECT NAME= \"type\" >");
  fprintf(cgiOut, "<OPTION SELECTED >delete");
  fprintf(cgiOut, "<OPTION SELECTED >periodic");
  fprintf(cgiOut, "<OPTION SELECTED >cond");
  fprintf(cgiOut, "<OPTION SELECTED >single");
  fprintf(cgiOut, "<OPTION SELECTED >event");
  fprintf(cgiOut, "<OPTION SELECTED >agg");
  fprintf(cgiOut, "</SELECT>");
  if(cgiFormSelectSingle("type", types, 6, &typeChoice, 0) == cgiFormSuccess)
    fprintf( cgiOut, "<br> <font color=#FF3399>Type is set to %s.</font><br>", types[typeChoice]);
  strcat(command, ":");
  strcat(command, types[typeChoice]);


  //allows users to select period
  fprintf(cgiOut, "<br>Enter the Period (in units of 0.1 seconds): ");
  fprintf(cgiOut, " <INPUT TYPE=\"text\" NAME=\"Period\" VALUE=\"0\" size=\"6\" maxlength =\"4\"> ");
  if(cgiFormString( "Period", period, sizeof(period)) == cgiFormSuccess)
    fprintf( cgiOut, "<br><font color=#FF3399> Period is set to %s.</font>", period);
  strcat(command, ":period=");
  strcat(command, period);


  //allows users to select one or multiple sensors
  fprintf(cgiOut, "<br><br>Choose from the Following Sensors: ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"humidity\">humidity ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"temperature\">temperature ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"dewPoint\">dewPoint ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"windSpeed\">windSpeed ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"solarRadiation\">solarRadiation ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"leafWetness\">leafWetness ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"windDirection\">windDirection ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"barometer\">barometer ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"rain\">rain ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"lightning\">lightning ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"enclosureHumidity\">enclosureHumidity ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"gust\">gust ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"messageLossAtCH1\">messageLossAtCH1 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"messageSent\">messageSent ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"hopsToCH1\">hopsToCH1 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"moteBattery\">moteBattery ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"insideTemperature\">insideTemperature ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"insideHumidity\">insideHumidity ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"parCurrent\">parCurrent ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"insideThermopile\">insideThermopile ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"analog0\">analog0 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"analog1\">analog1 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"soilMoistureAt15cm\">soilMoistureAt15cm ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"soilMoistureAt50cm\">soilMoistureAt50cm ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"soilTemperatureAt100cm\">soilTemperatureAt100cm ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"soilTemperatureAt30cm\">soilTemperatureAt30cm ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"enclosureTemperature\">enclosureTemperature ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"soilTemperatureAt15cm\">soilTemperatureAt15cm ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\"  ""VALUE=\"soilTemperatureAt50cm\">soilTemperatureAt50cm ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"analog2\">analog2 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"analog3\">analog3 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"analog4\">analog4 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"analog5\">analog5 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"analog6\">analog6 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"analog7\">analog7 "); 
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"parL11905A\">parL11905A ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"parNT53373\">parNT53373 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"parNT53373_2\">parNT53373_2 ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"thermister\">thermister ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"humidity_1500_33_JR\">humidity_1500_33_JR ");
  fprintf(cgiOut, " <br> <INPUT TYPE=\"checkbox\" NAME=\"sensor\" "" VALUE=\"thermistor_NTC_25_JR\">thermistor_NTC_25_JR ");


  fprintf(cgiOut, "<br> <INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\"> ");

  if(cgiFormSubmitClicked("submit") == cgiFormSuccess){

  result = cgiFormCheckboxMultiple("sensor", sensors, 41, sensorChoices, &invalid);

  //concatenates the rest of the command involving selected sensors
  if (result == cgiFormNotFound) {
    fprintf(cgiOut, "<br><font color=#FF3399>You've selected no sensors!</font><p>\n");
  }
  else {
    for(j=0; (j<41); j++){
      if (sensorChoices[j]){
	commas++;
      }
    }
    commas--;
    strcat(command, ":sensors=");
    fprintf(cgiOut, "<br><font color=#FF3399>You've selected the following sensors:</font> <br>");
    fprintf(cgiOut, "<ul>");
    for (i=0; (i < 41); i++) {
      if (sensorChoices[i]) {
	char value[5];	
	if( i < 35){
	  sprintf(value, "%i",i+33);
	  strcat(command, value);
	  if(commas!=0){
	    strcat(command, ",");
	    commas--;
	  }
	}
	else {
	  sprintf(value, "%i", 128+(i-35));
	  strcat(command, value);
	  if(commas!=0){
	    strcat(command, ",");
	    commas--;
	  }
	}
      
        fprintf(cgiOut, "<font color=#FF3399><li>%s</font><br>", sensors[i]);

      }
    }
    fprintf(cgiOut, "<font color=#FF3399></ul><br></font>");
  }
  
  
  fprintf(cgiOut, "<font color=#FF3399><br>The query is %s</font>", command);
  fprintf(cgiOut, "</FORM>");


  //writes query command to file
  char *path = sim_path("/dev/dse/query");
  int fd;
  int status;
  fd = open(path, O_RDWR);
  if (fd == -1) {
    fprintf(cgiOut, "<br> query error on open: %m \n");
  }
  status = write(fd, command, strlen(command));
  if (status < 0) {
    fprintf(cgiOut, "<br> query error on write arg '%s': %m \n", command);
  }
  else
    fprintf(cgiOut, "<br><font color=#FF3399> You've successfully sent the query to the mote network.</font>");
  }
  fprintf(cgiOut, "<A HREF=\"/cgi-bin/toolsPage.cgi\"<p>Return to Tools</A></P>");
 
  return 0;

}







See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  Final_Documentation.doc
  dataInfo.c
  frontPage.c
  netStatusMoteConfig.c
  netStatusMoteNetwork.c
  netStatusNeighbors.c
  netStatusPage.c
  netStatusQuery.c
  netTaskPage.c
  toolsPage.c
  toolsPageEraseConfig.c
  toolsPageGetConfig.c
  toolsPageLinkDump.c
  toolsPagePutConfig.c
  toolsPageQuery.c
  toolsPageRequery.c