Main Page | Modules | Directories | File List | Globals | Related Pages

CGI Routines

CGI request handler and dynamic HTML builder. More...

Functions

static void HtmlLedRow (FILE *stream, u_char num, u_char desc, u_long ival, u_long oval, u_long dir)
 Print HTML code for a row of LEDs.
static void HtmlCheckboxRow (FILE *stream, u_char num, u_char desc, u_char *name, u_long check, u_long enable)
 Print HTML code for a row of checkboxes.
static void HtmlSeparatorRow (FILE *stream, u_char width, u_char height)
 Print HTML code for a separator row.
static void HtmlInOutPortRow (FILE *stream, char name, u_char pin, u_char port, u_char ddr, u_char enable)
 Print HTML code to display a single I/O port.
static void ProcessCgiPortRequest (REQUEST *req)
 Process request parameters for CPU port control.
static void ProcessCgiRelayRequest (char *query)
 Process request parameters for relay output control.
int CpuPortControl (FILE *stream, REQUEST *req)
 CGI callback function to control the CPU ports.
int CpuPortStatus (FILE *stream, REQUEST *req)
 CGI callback function to display the status of the CPU ports.
int SpiRelayControl (FILE *stream, REQUEST *req)
 CGI callback function to control a shift register output board.
int SpiOptoStatus (FILE *stream, REQUEST *req)
 CGI callback function to query a shift register input board.
int CharonLedControl (FILE *stream, REQUEST *req)
 CGI callback function to control the Charon II LEDs.
int CharonSwitchStatus (FILE *stream, REQUEST *req)
 CGI callback function to query the Charon II switches.

Variables

static u_char spi_ni = 255
 Number of detected opto inputs.
static u_char spi_no = 255
 Number of detected relays.
static u_long relay_status
 Relays status.
static u_char relay_known
 Equals zero as long as the relay status is unknown.

Detailed Description

CGI request handler and dynamic HTML builder.

This module contains all registered CGI functions and some routines to dynamically create the webpages.


Function Documentation

int CharonLedControl FILE *  stream,
REQUEST *  req
 

CGI callback function to control the Charon II LEDs.

Creates HTML code to show the status of any attached shift register output board plus a HTML form to modify the current relay status via checkboxes.

The resulting HTML code is send back to the browser. If the submit button is clicked on this page, this function will be called again to process the checkboxes and display the updated status.

relay.gif

This function is called by the HTTP module when a browser requests a CGI function, for which this routine has been registered via NutRegisterCgi().

Parameters:
stream Stream device of the HTTP connection.
req Pointer to the CGI REQUEST structure. Detailed information is available in the Nut/OS API documentation.
Returns:
0 on success or -1 in case of any failure.

Definition at line 610 of file cgi.c.

References CHARON_CONTROL_CGI, HtmlCheckboxRow(), and HtmlLedRow().

Referenced by main().

int CharonSwitchStatus FILE *  stream,
REQUEST *  req
 

CGI callback function to query the Charon II switches.

This function is called by the HTTP helper routines when a browser requests a CGI function, for which this routine has been registered via NutRegisterCgi().

opto.gif

Creates HTML code to show the status of the optically isolated inputs of an attached SPI input board. The page will be automatically refreshed every 5 seconds.

Parameters:
stream Stream device of the HTTP connection.
req Pointer to the CGI REQUEST structure. Detailed information is available in the Nut/OS API documentation.
Returns:
0 on success or -1 in case of any failure.

Definition at line 689 of file cgi.c.

References CHARON_STATUS_CGI, and HtmlLedRow().

Referenced by main().

int CpuPortControl FILE *  stream,
REQUEST *  req
 

CGI callback function to control the CPU ports.

Creates HTML code to show the status of CPU ports B, D, E and F plus a HTML form to modify the port and data direction registers of ports B, D and E by checkboxes.

The resulting HTML code is send back to the browser. If the submit button is clicked on this page, this function will be called again to process the checkboxes.

cport.gif

This function is called by the HTTP module when a browser requests a CGI function, for which this routine has been registered via NutRegisterCgi().

Parameters:
stream Stream of the HTTP connection.
req Pointer to the CGI REQUEST structure. Detailed information is available in the Nut/OS API documentation.
Returns:
0 on success or -1 in case of any failure.

Definition at line 330 of file cgi.c.

References HtmlInOutPortRow(), HtmlLedRow(), HtmlSeparatorRow(), PORT_CONTROL_CGI, and ProcessCgiPortRequest().

Referenced by main().

int CpuPortStatus FILE *  stream,
REQUEST *  req
 

CGI callback function to display the status of the CPU ports.

Creates HTML code to show the status of CPU ports B, D, E and F. The page will be automatically refreshed every 5 seconds.

sport.gif

This function is called by the HTTP module when a browser requests a CGI function, for which this routine has been registered via NutRegisterCgi().

Parameters:
stream Stream device of the HTTP connection.
req Pointer to the CGI REQUEST structure. Detailed information is available in the Nut/OS API documentation.
Returns:
0 on success or -1 in case of any failure.

Definition at line 400 of file cgi.c.

References HtmlLedRow(), and PORT_STATUS_CGI.

Referenced by main().

static void HtmlCheckboxRow FILE *  stream,
u_char  num,
u_char  desc,
u_char *  name,
u_long  check,
u_long  enable
[static]
 

Print HTML code for a row of checkboxes.

The resulting HTML code will present a row of checkboxes.

Parameters:
stream HTML code is printed to this stream device.
num The number of checkboxes to print.
desc If not equal zero, bits are processed in descending order.
name Identifier of the checkboxes.
check The checkbox will be checked if the corresponding bit is set.
enable The checkbox will be created only, ff the corresponding bit in this bitmask is set.

Definition at line 140 of file cgi.c.

Referenced by CharonLedControl(), HtmlInOutPortRow(), and SpiRelayControl().

static void HtmlInOutPortRow FILE *  stream,
char  name,
u_char  pin,
u_char  port,
u_char  ddr,
u_char  enable
[static]
 

Print HTML code to display a single I/O port.

The resulting HTML code will present a row of LEDs and two rows of checkboxes. While the LEDs show the current port status, the checkboxes may be used to modify the port output and the data direction register.

See HtmlLedRow() for further details about how LEDs are displayed. The checkboxes are created by calling HtmlCheckboxRow().

Parameters:
stream HTML code is printed to this stream device.
name Port identifier, typically 'A' for Port A, 'B' for port B etc.
pin Contents of the PIN register.
port Contents of the PORT register.
ddr Contents of the data direction register.
enable If a bit is not set in this bit mask, then the corresponding checkboxes are not created and the port bits and data direction can't be modified.

Definition at line 195 of file cgi.c.

References HtmlCheckboxRow(), and HtmlLedRow().

Referenced by CpuPortControl().

static void HtmlLedRow FILE *  stream,
u_char  num,
u_char  desc,
u_long  ival,
u_long  oval,
u_long  dir
[static]
 

Print HTML code for a row of LEDs.

The resulting HTML code will present a row of LEDs. The color and the lit state of each LED is determined by three bit values. The required images are expected in the URL root of the urom flash filesystem:

  • r0.gif Red LED not lit. Will be displayed if the corresponding bit in the direction mask is set and the input and output bits are both not set.
  • r1.gif Red LED lit. Will be displayed if the corresponding bit in the direction mask is set and the input and output bits are both set.
  • g0.gif Green LED not lit. Will be displayed if the corresponding bit in the direction mask and the input value are both not set.
  • g1.gif Green LED lit. Will be displayed if the corresponding bit in the direction mask is not set and the input bit is set.
  • y0.gif Yellow LED not lit. Will be displayed if the corresponding bit in the direction mask is set, the output bit is set but the input bit is not set.
  • y1.gif Yellow LED lit. Will be displayed if the corresponding bit in the direction mask is set, the output bit is not set but the input bit is set.

All LED images must be of the same size, 28 x 28 pixels.

Parameters:
stream HTML code is printed to this stream device.
num The number of LEDs to print.
desc If not equal zero, bits are processed in descending order.
ival Input bit values.
oval Output bit values.
dir Data direction mask. Any bit set to one represents an output.

Definition at line 93 of file cgi.c.

Referenced by CharonLedControl(), CharonSwitchStatus(), CpuPortControl(), CpuPortStatus(), HtmlInOutPortRow(), SpiOptoStatus(), and SpiRelayControl().

static void HtmlSeparatorRow FILE *  stream,
u_char  width,
u_char  height
[static]
 

Print HTML code for a separator row.

The resulting HTML code will present a black row.

Parameters:
stream HTML code is printed to this stream device.
width Separator width in columns.
height Separator width in pixels.

Definition at line 170 of file cgi.c.

Referenced by CpuPortControl().

static void ProcessCgiPortRequest REQUEST *  req  )  [static]
 

Process request parameters for CPU port control.

Parse the CGI query and perform the corresponding action:

  • Dx=y will set bit y in the data direction register of port x.
  • Px=y will set bit y in the port output register of port x.

All other bits are switched off.

Parameters:
query CGI query string.

Definition at line 225 of file cgi.c.

Referenced by CpuPortControl().

static void ProcessCgiRelayRequest char *  query  )  [static]
 

Process request parameters for relay output control.

Parse the CGI query and switch the corresponding relays. 'S=y' will switch on relay y. All other relays are switched off.

Note, that before calling this function is called for the first time, the status of the relays is unknown.

Parameters:
query CGI query string.

Definition at line 285 of file cgi.c.

References relay_known, relay_status, and spi_no.

Referenced by SpiRelayControl().

int SpiOptoStatus FILE *  stream,
REQUEST *  req
 

CGI callback function to query a shift register input board.

This function is called by the HTTP helper routines when a browser requests a CGI function, for which this routine has been registered via NutRegisterCgi().

opto.gif

Creates HTML code to show the status of the optically isolated inputs of an attached input shift register board. The page will be automatically refreshed every 5 seconds.

Parameters:
stream Stream device of the HTTP connection.
req Pointer to the CGI REQUEST structure. Detailed information is available in the Nut/OS API documentation.
Returns:
0 on success or -1 in case of any failure.

Definition at line 547 of file cgi.c.

References HtmlLedRow(), OPTO_STATUS_CGI, spi_ni, and spi_no.

Referenced by main().

int SpiRelayControl FILE *  stream,
REQUEST *  req
 

CGI callback function to control a shift register output board.

Creates HTML code to show the status of any attached shift register output board plus a HTML form to modify the current relay status via checkboxes.

The resulting HTML code is send back to the browser. If the submit button is clicked on this page, this function will be called again to process the checkboxes and display the updated status.

relay.gif

This function is called by the HTTP module when a browser requests a CGI function, for which this routine has been registered via NutRegisterCgi().

Parameters:
stream Stream device of the HTTP connection.
req Pointer to the CGI REQUEST structure. Detailed information is available in the Nut/OS API documentation.
Returns:
0 on success or -1 in case of any failure.

Definition at line 470 of file cgi.c.

References HtmlCheckboxRow(), HtmlLedRow(), ProcessCgiRelayRequest(), RELAY_CONTROL_CGI, relay_known, relay_status, spi_ni, and spi_no.

Referenced by main().


© 2002-2004 by egnite Software GmbH - visit http://www.ethernut.de/