Code Search for Developers
 
 
  

loc_cgi.c from EmStar at Krugle


Show loc_cgi.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 loc_cgi_c_cvsid[] = "$Id: loc_cgi.c,v 1.4 2006/07/16 10:05:49 girod 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 <libmisc/misc_network.h>

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


/**
 *
 * This file will print all the information for a single node.
 *
 * required args:
 *   none
 *
 * optional args: 
 *   none
 */


/**
 *
 * This function is called by the library before the process_cgi
 * function. You can use it to hijack the header being printed so you
 * can do fancy redirects or play with the cookies or other
 * things. You can use the cgic library calls, or do it yourself using
 * the output_stream. This is NOT passed through the SSI parser.
 *
 */
void http_header(FILE* output_stream) {
  cgiHeaderContentType("text/html");
  fflush(output_stream);
}


int process_cgi(FILE* output_stream) {

  buf_t *title = buf_new();
  buf_t *subtitle = buf_new();
  bufprintf(title, "Acoustic ENSBox %d", my_node_id);
  bufprintf(subtitle, "%s", "Auto-Localization");
  html_banner(output_stream, title->buf, subtitle->buf, NULL);

  fprintf(output_stream, "<a href=\"/cgi-bin/aensbox.cgi\" target=\"_blank\"><h3>Back to AENSBox Main Page</h3></a><br>\n");

  fprintf(output_stream, "<h3>Current Published Coordinates</h3></a>\n");
  fputs("<!--#include virtual=\"/cgi-bin/status.cgi?device=mhsync/data/coord-24-4&inline=yes\" -->\n", output_stream);

  /* are we master mode? */
  buf_t *master_buf = g_status_client_read_once(sim_path("/dev/opt/loc/master_mode"), 0, 0);
  int master = (master_buf && strncmp("1", master_buf->buf, 1) == 0) ? 1 : 0;

  fprintf(output_stream, "<h3>Localization System Control</h3></a>\n");

  if (master) {

    /* Re-init, refine */
    html_hardcoded_command_button(output_stream, NULL, "loc/mlat_cmd", "inval", "Restart Localization");
    html_hardcoded_command_button(output_stream, NULL, "loc/mlat_cmd", "refine", "Refine");
    html_hardcoded_command_button(output_stream, NULL, "loc/mlat_cmd", "comp", "Compute Now");

    fprintf(output_stream, "Cut and paste into plotit.pl: ");
    fputs("<!--#include virtual=\"/cgi-bin/status.cgi?device=loc/dump_coords&inline=yes\" -->\n", output_stream);
    
    /* config resid thresh */
    fprintf(output_stream, "Residual theshold: ");
    html_option_form(output_stream, NULL, "opt/loc/resid_thresh", 10, "Set Threshold");
    
    /* set survey points */
    fprintf(output_stream, "Configure survey points (format is node,x,y,z,angle):<br>");

    char *s1 = html_get_status_value("opt/loc/survey_points/1");
    char *s2 = html_get_status_value("opt/loc/survey_points/2");
    char *s3 = html_get_status_value("opt/loc/survey_points/3");

    fprintf(output_stream, 
	    "<form method=\"POST\" name=\"\" action=\"/cgi-bin/command.cgi\">\n"
	    "<input type=hidden name=device value=\"loc/mlat_cmd\">\n"
	    "<input type=hidden name=mapping value=\"survey:1,survey:2,survey:3\">\n"
	    "<input type=text size=30 name=survey:1 value=\"%s\"><br>\n"
	    "<input type=text size=30 name=survey:2 value=\"%s\"><br>\n"
	    "<input type=text size=30 name=survey:3 value=\"%s\"><br>\n"
	    "<input type=submit value=\"Adjust\">\n"
	    "</form>\n",
	    s1, s2, s3);
    
    /* turn off master mode */
    html_hardcoded_command_button(output_stream, NULL, "opt/loc/master_mode", "off", "Disable Master Mode");
  }

  else {
    /* turn on master mode */
    html_hardcoded_command_button(output_stream, NULL, "opt/loc/master_mode", "on", "Enable Master Mode");
  }

  fprintf(output_stream, "<h3>Multilat Debugging Info</h3></a>\n");

  char *status = html_get_status_value("loc/convergence");
  fprintf(output_stream, "Current status: %s", status);

  fprintf(output_stream, "<h4>Constraint Errors</h4></a>\n");
  fputs("<!--#include virtual=\"/cgi-bin/status.cgi?device=loc/range_errors&inline=yes\" -->\n", output_stream);

  fprintf(output_stream, "<h4>Residuals</h4></a>\n");
  fputs("<!--#include virtual=\"/cgi-bin/status.cgi?device=loc/residuals&inline=yes\" -->\n", output_stream);

  fprintf(output_stream, "<h4>Current Published Ranges</h4></a>\n");
  fputs("<!--#include virtual=\"/cgi-bin/status.cgi?device=mhsync/data/range-20-4&inline=yes\" -->\n", output_stream);

  fflush(output_stream);

  buf_free(title);
  buf_free(subtitle);

  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

  aensbox_cgi.c
  index.html
  loc_cgi.c