Back to ESAcademy Home Page


www.cmx.comInternet connectivity: The time is right and the technology is ready for you

By Olaf Pfeiffer and John Rodrigues

[ Introduction | Internet Connectivity Parameters | Case Study ]
[ Adapting the Software | Dynamic Web Pages | Feedback with Forms ]
[ Continuous Refresh | Security | Summary ]

 

Home

News

Training Classes

Products

Consulting

Technical Library

Contact Us

Recommended Books

< Previous Page

Dynamic Web Pages

To create dynamic Web pages, we used a method similar to one used by many "full-grown" Web servers to transmit dynamic pages: SSI - Server Side Includes.

Using some special HTML tags to indicate SSI, an HTML page can be marked up to insert dynamic data in the place of the tags. The SSI tag itself indicates the name of a function that the Web server needs to call locally to get access to the dynamic data. So for each SSI tag used, a function must be implemented within the application that will be called from the server. The syntax for these SSI tags is:

<!--#exec cgi="FunctionName"-->

The implementation works as follows: During the initialization phase, the TCP/IP software builds up a list of all the applications SSI functions.

The entire process of requesting dynamic Web pages involves the following steps:

  1. When a Web page is requested, the server copies the page from its ROM location into a RAM output buffer.

  2. While copying, the server scans for SSI tags.

  3. If an SSI tag is found, the matching function within the application is called. The parameter passed on to the function is a char pointer to the current location in the output buffer.

  4. The SSI function can now directly insert ASCII characters into the output buffer. This could be as simple as converting a local variable that should be displayed into an ASCII string right into the output buffer.

  5. After the SSI function returns, the server updates the pointers used to ensure that continuous copying will not overwrite any of the data just copied into the output buffer by the SSI function.

  6. Steps 2. through 4. are repeated until the end-of-file is reached

  7. The server can now transmit the contents of the output buffer to the requesting host / Web browser.

Listing 1 shows the implementation of the SSI function getDIPVal that reads current settings of DIP switches and generates an appropriate ASCII representation. In this hardware environment, reading from the address 0xFF80 tells us the current DIP switch settings. A fixed value of 8 is returned for the length of the inserted ASCII text, as we will always process 8 bits. The output is "0" for switch is off and "1" for switch is on.

#define DIP_ADDR 0xFF80

// passed is a pointer to the web page buffer
// returned is the number of characters inserted
// into the web page buffer by the function

word16 getDIPVal(byte *str) cmx_reentrant
{
  char xdata *dPTR;
  byte DIP, c;

  // initialize a pointer to the DIP switches dPTR = DIP_ADDR;
  // read DIP switches DIP = *dPTR; c = 0x80;
  // step through bits in read value

  while (c > 0)
  {
    // if bit is set then insert '1' otherwise
    // insert '0' into the web page

    if ((DIP & c) > 0)
      *str++ = '1';
    else
      *str++ = '0';
    c = c >> 1;
  }

  // return size of data inserted into the web page
  return (8);
}

To use this SSI function in a Web page and get an array of 8 digits representing the settings of the DIP switches, we just have to insert something like the following into the HTML code:

...
<p>
Current settings of the DIP switches: <b><!--#exec cgi="getDIPVal"--></b>
</p>
...

< Previous Page

[ Introduction | Internet Connectivity Parameters | Case Study ]
[ Adapting the Software | Dynamic Web Pages | Feedback with Forms ]
[ Continuous Refresh | Security | Summary ]


Copyright © 2001 EE Times. All rights reserved.

ESAcademy, 2000

All materials
provided 'as is'
see Disclaimer

www.esacademy.com
info@esacademy.com