Main Page | Modules | File List | Related Pages

CGI Routines

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

Functions

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.

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.

void HtmlSeparatorRow (FILE *stream, u_char width, u_char height)
 Print HTML code for a separator row.

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.

void ProcessCgiPortRequest (char *query)
 Process request parameters for CPU port control.

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 SPI relay output board.

int SpiOptoStatus (FILE *stream, REQUEST *req)
 CGI callback function to control a SPI input board.


Variables

u_char spi_ni = 255
 Number of detected opto inputs.

u_char spi_no = 255
 Number of detected relays.

u_long relay_status
 Relays status.

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 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.
Returns:
0 on success or -1 in case of any failure.

Definition at line 319 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 once a second.

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.
Returns:
0 on success or -1 in case of any failure.

Definition at line 386 of file cgi.c.

References HtmlLedRow(), and PORT_STATUS_CGI.

Referenced by main().

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 139 of file cgi.c.

Referenced by HtmlInOutPortRow(), and SpiRelayControl().

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 196 of file cgi.c.

References HtmlCheckboxRow(), and HtmlLedRow().

Referenced by CpuPortControl().

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 89 of file cgi.c.

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

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 171 of file cgi.c.

Referenced by CpuPortControl().

void ProcessCgiPortRequest char *  query  )  [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 226 of file cgi.c.

Referenced by CpuPortControl().

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 277 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 control a SPI input board.

Creates HTML code to show the status of the optically isolated inputs of an attached SPI input board. The page will be automatically refreshed once a second.

opto.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.
Returns:
0 on success or -1 in case of any failure.

Definition at line 528 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 SPI relay output board.

Creates HTML code to show the status of any attached SPI relay 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.
Returns:
0 on success or -1 in case of any failure.

Definition at line 453 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/