Code Search for Developers
 
 
  

aensbox_cgi.c from EmStar at Krugle


Show aensbox_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 aensbox_cgi_c_cvsid[] = "$Id: aensbox_cgi.c,v 1.7 2006/11/30 10:57:22 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", "Main Page");
  html_banner(output_stream, title->buf, subtitle->buf, NULL);

  /* Master mode and netrec */
  fprintf(output_stream, "<h3>Current System Status</h3>\n");
  buf_t *master_buf = g_status_client_read_once(sim_path("/dev/opt/netrec/master_mode"), 0, 0);
  int master = (master_buf && strncmp("1", master_buf->buf, 1) == 0) ? 1 : 0;
  html_hardcoded_command_button(output_stream, NULL, "opt/netrec/master_mode", "1", 
				master ? "Re-Enable Master Mode" : "Enable Master Mode");
  if (master) {
    fprintf(output_stream, "Set System Sample Rate: ");
    html_option_form(output_stream, NULL, "opt/netrec/sample_rate", 10, "Set Rate");

    fprintf(output_stream, "Media Control: ");
    
    html_hardcoded_command_button(output_stream, NULL, "netrec/control", "umount", "Unmount CF");
    html_hardcoded_command_button(output_stream, NULL, "netrec/control", "mount", "Mount CF");

    html_hardcoded_command_button(output_stream, NULL, "netrec/control", "umountsd", "Unmount SD");
    html_hardcoded_command_button(output_stream, NULL, "netrec/control", "mountsd", "Mount SD");

  }

  fputs("<!--#include virtual=\"/cgi-bin/status.cgi?device=netrec/control&inline=yes\" -->\n", output_stream);

  if (master) {
    /* recording application */
    fprintf(output_stream, "<h3>Synchronized Recording Control</h3>\n");
    
    buf_t *last_name = g_status_client_read_once(sim_path("/dev/netrec/last_name"), 0, 0);
    buf_t *record_state = g_status_client_read_once(sim_path("/dev/netrec/recorder"), 0, 0);
    char *line = strchr(record_state->buf, '\n');
    
    if (line) {
      line++;
      char *term = strchr(line, '\n');
      if (term) *term = 0;
      fprintf(output_stream,
	      "Local recording is currently %s.<br>", line);
      
      fprintf(output_stream, 
	      "<form method=\"POST\" name=\"\" action=\"/cgi-bin/command.cgi\">\n"
	      "<input type=hidden name=device value=\"netrec/control\">\n"
	      "<input type=hidden name=mapping value=\"record_command,start,name:1,dur,wavpack,sync,single,remote\">\n"
	      "<input type=hidden name=record_command>\n"
	      "<input type=hidden name=start>\n"
	      "Filename <input type=text size=30 name=name:1 value=\"%s\"><br>\n"
	      "Duration (s) <input type=text size=10 name=dur value=\"600\"><br>\n"
	      "<input type=checkbox name=wavpack> WavPack Compression <br>\n"
	      "<input type=checkbox name=sync checked> Globally Synchronized <br>\n"
	      "Record <input type=radio name=single value=1> Channel0 only \n"
	      "<input type=radio name=single value=0 checked> All Channels <br>\n"
	      "Save to <input type=radio name=remote value=1 checked> CF \n"
	      "<input type=radio name=remote value=0> SD <br>\n"
	      "<input type=submit value=\"Start\">\n"
	      "</form>\n",
	      last_name->buf);

      html_hardcoded_command_button(output_stream, NULL, "netrec/control", "record_command=stop", "Stop");
      html_hardcoded_command_button(output_stream, NULL, "netrec/control", "record_command=kill", "Kill");
    }
    
    else{
      fprintf(output_stream, "Warning: Netrec is unavailable.");
    }
    
    fprintf(output_stream, "<br>");
  }

  /* Link to localization page */
  fprintf(output_stream, "<h3>Current Localization Status</h3>\n");
  fputs("<!--#include virtual=\"/cgi-bin/status.cgi?device=mhsync/data/coord-24-4&inline=yes\" -->\n", output_stream);
  fprintf(output_stream, "<a href=\"/cgi-bin/loc.cgi\" target=\"_blank\"><i>Auto-Localization Subsystem</i></a><br>\n");

  /* Link to emrun page */
  fprintf(output_stream, "<h3>Node Status and Logs</h3>\n");
  fprintf(output_stream, "<a href=\"/cgi-bin/node.cgi\" target=\"_blank\"><i>System Information</i></a><br>\n");

  fprintf(output_stream, "<h3>Systemwide Faults</h3></a><br>\n");
  fputs("<!--#include virtual=\"/cgi-bin/status.cgi?device=mhsync/data/faults-44-2&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