manufacturer of I/O-rich SBCs, operator interfaces, handheld instruments, and development tools for embedded control low cost single board computers, embedded controllers, and operator interfaces for scientific instruments & industrial control development tools for embedded control order our low cost I/O-rich embedded control products embedded controller manufacturer profile single board computers & embedded controllers development tools & starter kits for your embedded design operator interfaces with touchscreens and graphical user interface plug-in expansion modules for digital & analog I/O C language & Forth language integrated development tools, IDE single board and embedded computer accessories embedded controller enclosures, bezels, environmental gaskets

The EtherSmart Wildcard User Guide

Table of Contents

Introduction

Internet Protocol Support

Summary of EtherSmart Capabilities

Hardware

Connecting To the Wildcard Bus

Selecting the Wildcard Address

Terminology Overview

Browser Notes

The EtherSmart Software Driver Routines

EtherSmart Driver Data Structures

The Demo Program

EtherSmart Initialization, Configuration and Diagnostics

Initialization Functions

Configuring the XPort Device

Assigning an IP Address

Reporting Routines

Using "Ping" for Diagnostics

Initializing Multiple EtherSmart Wildcards

Code Downloads and Interactive Communications via Ethernet

Serial Tunneling

A Serial Tunneling Example

Serial Tunneling Buffer Management Functions

Serial Tunneling Data Transmission and Reception Functions

Serial Tunneling Connection Functions

Serial Tunneling Inter-Task Service Management Functions

Sending Email

Introduction to the Dynamic Webserver

Using the Dynamic Webserver

HTTP Buffer Management

HTTP Header Generation

HTTP Data Transfer Functions

Web Form Processing

An Example of a Dynamic Web Page with a Remote Image Reference

Serving Out a Stand-Alone Image

Implementing a "Remote Front Panel" Using the Webserver

Appendix A: Installing the Software

Generating the EtherSmart Kernel Extension Library

Creating Web Page and Image Resources with the Image Converter

Loading the Software onto the Controller

Using the EtherSmart Driver with C

Using the Driver Code with Forth

Appendix B: C Demo Program

Appendix C: C Remote Front Panel Demo Program

Appendix D: Forth Demo Program

Appendix E: Forth Remote Front Panel Demo Program

Appendix F: Browser Configuration

Using Opera Is Highly Recommended

Reconfiguring the Internet Explorer Browser

Firefox and Mozilla

Appendix G: Hardware Schematic (pdf)

<< Previous | Next>>

Appendix B: C Demo Program

Listing 118   Ether_Demo.c program listing.

// this demonstration code is provided in source form.

// Top level functions:

// Web_Demo( ) // no input parameters; runs web pages, enables email, tunneling;

//    also callable as main

// Ether_Monitor_Demo( int modulenum ) // runs ethernet interactive monitor;see comments

 

// these can be called interactively (from QEDTerminal) after Web_Demo is invoked:

// Tunnel_Test( )       // no input parameters, echoes data from Putty connection

// Email_Test( )        // no input parameters, returns error code.  Sends an email;

                  // Note: YOU MUST EDIT THIS FUNCTION’s HARD-CODED IP ADDRESS and

                  // the hostname_str, sender_str, and recipient_str BEFORE CALLING!

 

 

// ************** #includes **************

 

#include <\mosaic\allqed.h>     // include all of the qed and C utilities

 

// choose the correct kernel version:

 

#include “library_V4_4\library.h”   // for QScreen, QCard, Handheld controllers

#include “library_V4_4\library.c”

 

// #include “library_V4_09\library.h”  // for QVGA controller

// #include “library_V4_09\library.c”

 

 

// include the header file that defines the base xaddress and 32-bit size for each resource:

#include “Resources\V4_4\image_headers.h” // for QScreen, QCard, Handheld controllers

// #include “Resources\V4_09\image_headers.h”   // for QVGA controller

 

 

// for reference, image_headers.h defines the following image and html string parameters:

// FORM_PAGE_HTML_XADDR

// FORM_PAGE_HTML_SIZE

// HOME_BODY_HTML_XADDR

// HOME_BODY_HTML_SIZE

// MOSAIC_LOGO_PNG_XADDR

// MOSAIC_LOGO_PNG_SIZE

// OPERA_CONFIG_HTML_XADDR

// OPERA_CONFIG_HTML_SIZE

 

#include “strdefs.h” // defines STRING_XADDR(str_addr) macro; see comments below

 

// ************** USEFUL MACRO FOR STRINGS IN V4.xx C COMPILER **************

 

 

// the TO_XADDR defined in /mosaic/include/types.h

// transforms a separate 16-bit addr, page into a 32-bit xaddress:

// #define TO_XADDR(address,page)     ((xaddr) (((page)<<16)+ (0xFFFF & (address))))

 

// We want to substitute THIS_PAGE (also defined in types.h) for the page,

// as the V4.xx C compiler replicates the strings on each page;

// therefore, in most cases, the calling function’s page is the same as the string page:

 

// #define STRING_XADDR(str_addr) ((xaddr) TO_XADDR(((xaddr) str_addr), ((xaddr) THIS_PAGE)))

 

 

// ************** USEFUL CONSTANTS **************

 

// #define TASK_SIZE 0x400    // 0x400 = decimal 1024 = 1Kbyte = task size

 

#define CR_ASCII  0x0D  // ascii carriage return

#define CRLF_ASCII 0x0D0A  // this is the standard eol sequence for tcp/ip services.

 

#define SMTP_PORT 25       // email Simple Mail Transfer Protocol destination port

 

// *************** IMPORTANT: SET MODULENUM TO MATCH HARDWARE JUMPERS ******************

 

 

#define E_MODULENUM  4 // ******** SET THIS TO MATCH HARDWARE JUMPERS J1 AND J2! *****

// This specifies the modulenum for the high level functions in this file

// except for Ether_Monitor_Demo (see its comments).

 

 

// If EtherSmart is installed on module bus 0, E_MODULENUM = 0, 1, 2, or 3

// If EtherSmart is installed on module bus 1, E_MODULENUM = 4, 5, 6, or 7

// That is, the bus specifies the top bit of a 3-bit modulenum,

// and [J2, J1] specifies the remaining 2 bits of the modulenum.

// Example: On module bus 0, if neither jumper cap is installed: E_MODULENUM = 0

// Example: On module bus 0, if both jumper caps are installed: E_MODULENUM = 3

// Example: On module bus 1, if J2 is installed but J1 is not: E_MODULENUM = 6

 

 

 

// ************** SETUP ETHERNET TASK TO RUN WEB AND TUNNELING SERVICES **************

 

TASK ether_control_task;  // 1 Kbyte per task area

 

_Q void Ether_Task_Setup_Default( void )

// performs full initialization of the Ether_Info struct and mailboxes for the

// specified modulenum, and

// builds and activates an ethernet control task to service the xport

{

 // NEXT_TASK = TASKBASE;    // empties task loop; comment out if other tasks are allowed

   Ether_Task_Setup( &ether_control_task, E_MODULENUM);

}

 

// ***************** INTERACTIVE CONFIGURATION AND REPORTING ************

 

_Q int Ether_Set_Defaults( void )

// call this AFTER calling main() or Ether_Task_Setup_Default() !

// sets mosaic factory defaults; returns error code

// sets local IP and gateway to 0.0.0.0 = unassigned, so IP address

// gets assigned via DHCP (Dynamic Host Configuration Protocol) by the LAN’s gateway.

// see user guide for more information.

{  printf(“\rSetting defaults...\r”);

   Ether_XPort_Defaults(E_MODULENUM);

   return((int) Ether_Await_Response(E_MODULENUM)); // error code is in lsword

}

 

_Q int Ether_Set_Local_IP(int my_ip1, int my_ip2, int my_ip3,  int my_ip4)

// call this AFTER calling main() or Ether_Task_Setup_Default() !

// sets the IP address of the EtherSmart Wildcard specified by E_MODULENUM as:

//   ip1.ip2.ip3.ip4

// For example, to set the IP address to 10.0.1.22, pass to this function the parameters:

//   10 0 1 22

// returns error code

// NOTES: type DECIMAL at the monitor before invoking this function interactively!

//        The input types are declared as int to simplify interactive calling,

//        as the interactive debugger would require char specifiers before each input

//        parameter if the char type were used.

{  printf(“\rSetting local IP address...\r”);

   Ether_Local_IP(my_ip1, my_ip2, my_ip3,  my_ip4, E_MODULENUM);

   Ether_XPort_Update(E_MODULENUM);

   return((int) Ether_Await_Response(E_MODULENUM)); // error code is in lsword

}

 

_Q void Ether_IP_Report(void)

// call this AFTER calling main() or Ether_Task_Setup_Default() !

// takes 7 seconds to execute, so be patient.

// Report is of the form:

// IP 010.000.001.019 GW 010.000.001.022 Mask 255.255.255.000

// which summarizes the IP address, gateway address, and netmask, respectively.

{  Ether_IP_Info_Report(E_MODULENUM);

}

 

_Q void Ether_Ping(int remote_ip1, int remote_ip2, int remote_ip3, int remote_ip4)

// call this AFTER calling main() or Ether_Task_Setup_Default() !

// on error, prints “ Couldn’t enter monitor mode!” or “ No response from remote”.

// takes thirteen seconds to execute, so be patient.

// Report is of the form (summarizes response time from specified remote host):

// Seq 001 time 10ms

// Seq 002 time 10ms

// Seq 003 time 10ms

// Seq 004 time 10ms

// Seq 005 time 10ms

// Seq 006 time 10ms

// NOTES: type DECIMAL at the monitor before invoking this function interactively!

//        The input types are declared as int to simplify interactive calling,

//        as the interactive debugger would require char specifiers before each input

//        parameter if the char type were used.

{  Ether_Ping_Report(remote_ip1, remote_ip2, remote_ip3, remote_ip4, E_MODULENUM);

}

 

// ***************** REVECTORED SERIAL VIA ETHERNET ************

 

// simplest approach:

// simply store the correct modulenum into the global var named ether_revector_module,

// then call Ether_Serial_Revector

// This will run the default (startup) task through the specified ethersmart wildcard.

// Use Putty “rlogin” to connect to the local port (typically = 80)

// at the specified local IP address, and you’re talking to the QED monitor via ethernet.

// To revert to standard serial operation via QED Term, type COLD to revert to standard

// serial, then from QEDTerm type RESTORE to bring back access to all compiled routines,

// then continue communications using QEDTerm.

 

// If you want to maintain serial communications via QEDTerm with the default task

// while running a separate task with I/O revectored via the Ethersmart Wildcard,

// then build and activate a task using Ether_Monitor as the activation routine.

// Use Putty “rlogin” to connect to the local port (typically = 80)

// at the specified local IP address, and you’re talking to the task via ethernet.

 

 

TASK ether_montask;  // 1 Kbyte per task area

 

_Q void Ether_Monitor_Demo( int modulenum )

// builds and activates a monitor task for the specified module.

// this function expects the modulenum as an input parameter so that

// you can run 2 installed Ethersmart wildcards at once:

// one wildcard can run the standard services (web, email, tunneling)

// while the other one (running Ether_Monitor_Demo) is used to download code

// and control program development and debugging.

// To do this, first call Web_Demo (which runs services on the E_MODULENUM wildcard),

// then call this Ether_Monitor_Demo function with a different modulenum.

{  ether_revector_module = modulenum;  // set variable to specify which module’s revectored

   SERIAL_ACCESS = RELEASE_ALWAYS; // allow sharing of serial ports

 // NEXT_TASK = TASKBASE;    // empties task loop; comment out if other tasks are allowed

   BUILD_C_TASK(0, 0, &ether_montask );

   ACTIVATE(Ether_Monitor, &ether_montask );

}

 

 

// ******************* SERIAL TUNNELING TEST **************

 

_Q void Tunnel_Test( void )

// call after doing Ether_Task_Setup_Default

// Waits for incoming non-web connection on this module’s IP address on port 80

// (the default local port), and examines the linefeed-delimited first line to see

// if it starts with GET; if not, it accepts it as a passive non-web connection.

// So: don’t type GET as the first characters of the connection (you’ll confuse the system).

// The easiest way to open a connection is via Putty, using the “raw” mode.

// Note: If you use “telnet” mode, you’ll see some garbage characters in the first line;

// these are control bytes with the msbit set that are accepted by the connection manager.

{  int num_received=0, inbufcount=0, i=0, numlines=0;

   char c;

   int timeout = 20000; // 20 second timeout for testing; sets delay til function exit

   xaddr ether_inbuf_base = Ether_Inbuf(E_MODULENUM);

   uint ether_inbuf_size =  Ether_Inbufsize(E_MODULENUM);

   xaddr http_inbuf_base = HTTP_Inbuf(E_MODULENUM);

   char* prompt = “Line was received>“;

   int prompt_length = strlen(prompt);

   printf(“\rWaiting for connection (type a carriage return from QEDTerm to abort)...\r”);

   printf(“Suggestion: To connect, use Putty in ‘raw’ mode, specify IP address, port 80,\r”);

   printf(“and type a carriage return once the session window opens.\r”);

   do

   {  PauseOnKey;    // abort on CR, pause/resume on other keys

      Ether_Check_Response(E_MODULENUM); // keep mailbox clean, ignore messages

   }

   while( !Ether_Passive_Non_Web_Connection(E_MODULENUM) ); // wait for tunnel connection

   printf(“\rAn incoming connection has been accepted;\r”);

   printf(“each incoming line will be printed to the serial terminal, and a\r”);

   printf(“response prompt will be sent to the ethernet terminal.\r”);

   printf(“To exit this routine, wait 20 seconds without typing a line.\r”);

      // the first line is in HTTP_Inbuf (because webserver had to check its identity)...

      // count is in 1st 2bytes of buffer

   inbufcount = (FetchInt(http_inbuf_base)); // count is stored in first 2bytes of buffer

   for( i=0; i<inbufcount; i++)

      {  c = FetchChar(http_inbuf_base + 2 + i); // skip 2byte count,get char

         Emit(c);

      }  // type first line including terminating crlf to local serial terminal

   do    // loop and echo additional lines til timeout...

   {  Ether_Get_Line( ether_inbuf_base,ether_inbuf_size,CR_ASCII,1,1,timeout,E_MODULENUM);

            // xlbuf,maxchars,eol,discard.alt.eol?,no.msbitset?,timeout_msec,module

            // get 1 line into counted ether_inbuf (count is stored in first 2 bytes)

      num_received = (int) Ether_Await_Response(E_MODULENUM); // get lsword of result

 

      inbufcount = (FetchInt(ether_inbuf_base));

      for( i=0; i<inbufcount; i++)

         {  c = FetchChar(ether_inbuf_base + 2 + i); // skip 2byte count,get char

            Emit(c);

         }  // type line including terminating crlf to local serial terminal

      if(num_received)  // send prompt and wait for response if chars were received...

      {  Ether_Send_Buffer( STRING_XADDR(prompt), prompt_length, timeout, E_MODULENUM);

         Ether_Await_Response(E_MODULENUM); // wait for result, ignore rtn value

         numlines++;                   // bump numlines

      }

   }

   while(num_received);    // until no chars rcvd due to timeout or connection close

   Ether_Disconnect_Flush(E_MODULENUM); // clean up

   Ether_Await_Response(E_MODULENUM); // synchronize to result mailbox before exit

   printf(“\r\nConnection terminated.\r\n”);

}

 

 

// ********************* EMAIL  TEST ***************************

 

// NOTE: Edit these to specify valid host, sender, and recipient:

char* hostname_str = “xport.yourdomain.com”;    // hostname string

char* sender_str =  “niceguy@yourdomain.com”;   // email sender string

char* recipient_str = “notso_niceguy@yourdomain.com”; // email recipient string

 

char* email_body_str =  // email_body string

“Subject: EtherSmart Email Test\r\n\

This is a test email from the EtherSmart Wildcard.\r\n\

Emails can of course have multiple lines...”;

 

 

_Q int Email_Test( void )

// smtp email test routine.

// Note: YOU MUST EDIT THIS FUNCTION’s HARD-CODED IP ADDRESS

// AND the hostname_str, sender_str, and recipient_str BEFORE CALLING!

// Otherwise, it will not work on your system.

// error= 0 on success, or error_no_response = 0x10, or the smtp 3-digit decimal error code

{  xaddr scratchbuf = Ether_Inbuf( E_MODULENUM );     // scratchpad xbuffer

   Ether_Send_Email(

      STRING_XADDR(email_body_str), strlen(email_body_str), // subject plus 2-line email

      STRING_XADDR(hostname_str), strlen(hostname_str),

      STRING_XADDR(sender_str), strlen(sender_str),

      STRING_XADDR(recipient_str), strlen(recipient_str),

      scratchbuf,       // scratchpad xbuffer

      10, 0, 1, 1,      // IMPORTANT: ENTER YOUR GATEWAY’S IP ADDRESS HERE!

      SMTP_PORT,        // port 25 = standard mailserver destination port

      10000,            // use a 10 second timeout (10,000 msec) for testing

      E_MODULENUM);     // specify module number (must match hardware jumpers)

   return((int) Ether_Await_Response(E_MODULENUM)); // error code is in lsword

}

 

 

// *********************** WEBSERVER DEMO (Ethersmart Web Pages) ***************

 

 

// time announcement string for home page:

char* time_announce_str = “seconds since system initialization.</body></html>“;

 

// form_response page strings:

 

char* form_response_str = “<html><head><title>Form Response</title></head><body>\r\n\

<H3>Thanks for your response!</H3><p><p>It must be great to be a “;

 

char* person_str = “person”;

 

char* name_announce_str = “ with a name like “;

 

char* yours_str = “yours”;

 

char* good_to_hear_str = “. It’s good to hear that “;

 

char* rainbow_str = “rainbow”;

 

char* favorite_str = “ is your favorite color!</body></html>“;

 

// url strings:

char* slash_url_str = “/”; // synonym for home page url

 

char* index_url_str = “/index.html”; // home page url

 

char* opera_url_str = “/opera_configuration.html”; // opera page url

 

char* form_entry_url_str = “/form_entry.html”; // form entry page url

 

char* form_response_url_str = “/form_response.cgi”; // form response page url

 

char* logo_response_url_str = “/logo_response.png”; // logo response page url

 

 

 

// note: in form_page_str, we mark one of the radio buttons as checked; otherwise,

// the browser can skip the field entirely, then we would have to match the fieldnames!

 

 

char seconds_str[16];   // will hold elapsed seconds string

 

void Home_Page( int modulenum )

// this is the handler function for the /index.html and the / URLs.

// sends the http header with dynamic (because of changing time stamp) text/html

// content type,  followed by home_body_str text and the elapsed seconds since the

// system was initialized.

{  ulong elapsed_sec;

   xaddr http_outbuf_base = HTTP_Outbuf(modulenum);

   uint http_outbuf_size =  HTTP_Outbufsize(modulenum);

   HTTP_Put_Header(http_outbuf_base, http_outbuf_size);  // http header->outbuf

   HTTP_Put_Content_Type(http_outbuf_base, http_outbuf_size, 1, HTTP_TEXT_HTML_CONTENT);

                  // params: xlbuf,maxbufsize,dynamic?,content_type

                  // dynamic text/html content ->outbuf;header is done

   HTTP_Send_LBuffer(http_outbuf_base, modulenum); // send out header, ignore #bytes_sent

   HTTP_Send_Buffer(HOME_BODY_HTML_XADDR, HOME_BODY_HTML_SIZE, modulenum);

                  // send home_body.html, ignore #bytes_sent

   StoreInt(0, http_outbuf_base);      // reset lcount to start fresh in buffer

   elapsed_sec = ReadElapsedSeconds();  // get elapsed time, used by sprintf...

   HTTP_Outbuf_Cat((xaddr) seconds_str,(int) sprintf(seconds_str,”%ld”,elapsed_sec),modulenum);

               // params: xstring_to_add,cnt_to_add,module

               // convert seconds to string, add line & crlf to longstring, update lcnt

   HTTP_Outbuf_Cat(STRING_XADDR(time_announce_str), strlen(time_announce_str), modulenum);

   // add to lbuffer: “ seconds since system initialization.</body></html>“

   HTTP_Send_LBuffer( http_outbuf_base, modulenum); // send elapsed time, ignore #bytes_sent

}

 

 

void Opera_Config_Page( int modulenum )

// this is the handler function for the /opera_configuration.html URL.

// sends the http header with static text/html content type,

// followed by opera_config.html text

{  xaddr http_outbuf_base = HTTP_Outbuf(modulenum);

   uint http_outbuf_size =  HTTP_Outbufsize(modulenum);

   HTTP_Put_Header(http_outbuf_base, http_outbuf_size);  // http header->outbuf

   HTTP_Put_Content_Type(http_outbuf_base, http_outbuf_size,0, HTTP_TEXT_HTML_CONTENT);

                  // params: xlbuf,maxbufsize,dynamic?,content_type

                  // static text/html content ->outbuf;header is done

   HTTP_Send_LBuffer(http_outbuf_base, modulenum); // send out header, ignore #bytes_sent

   HTTP_Send_Buffer(OPERA_CONFIG_HTML_XADDR, OPERA_CONFIG_HTML_SIZE, modulenum);

}                 // send opera_config.html, ignore #bytes_sent

 

 

void Form_Entry_Page( int modulenum )

// responds to url= /form_entry.html

// places FORM_TEXT into the buffer as a longstring after the http header.

// we send directly from compiled string in flash to avoid copy into ether_out buffer;

// this method is ideal for serving static text.

{  xaddr http_outbuf_base = HTTP_Outbuf(modulenum);

   uint http_outbuf_size =  HTTP_Outbufsize(modulenum);

   HTTP_Put_Header(http_outbuf_base, http_outbuf_size);  // http header->outbuf

   HTTP_Put_Content_Type(http_outbuf_base, http_outbuf_size,0, HTTP_TEXT_HTML_CONTENT);

                  // params: xlbuf,maxbufsize,dynamic?,content_type

                  // static text/html content ->outbuf;header is done

   HTTP_Send_LBuffer(http_outbuf_base, modulenum); // send out header, ignore #bytes_sent

   HTTP_Send_Buffer(FORM_PAGE_HTML_XADDR, FORM_PAGE_HTML_SIZE, modulenum);

}                 // send form_page.html, ignore #bytes_sent

 

 

void Form_Response_Page ( int modulenum )

// this is the handler function that responds to url= /form_response.cgi

// incoming request from browser looks like this:

// GET /form_response.cgi?classification=<man/woman/child>&name_id=<namestring>

// &color=<red/blue/yellow/green>

// We respond:

// It must be great to be a <man/woman/child/person> with a name like <namestring/yours>.

// It’s good to hear that <red/blue/yellow/green/rainbow> is your favorite color.

{  xaddr http_outbuf_base = HTTP_Outbuf(modulenum);

   uint http_outbuf_size =  HTTP_Outbufsize(modulenum);

   xaddr http_value_ptr = HTTP_Value_Ptr(modulenum); // load value,cnt for first field

   uint http_value_count =  HTTP_Value_Count(modulenum);

   xaddr next_http_value_ptr; // used for look-ahead field to avoid unescape problems

   uint next_http_value_count;   // used for look-ahead field to avoid unescape problems

   HTTP_Put_Header(http_outbuf_base, http_outbuf_size);  // http header->outbuf

   HTTP_Put_Content_Type(http_outbuf_base, http_outbuf_size,0, HTTP_TEXT_HTML_CONTENT);

                  // params: xlbuf,maxbufsize,dynamic?,content_type

                  // static text/html content ->outbuf;header is done

   HTTP_Send_LBuffer(http_outbuf_base, modulenum); // send out header, ignore #bytes_sent

   HTTP_Send_Buffer(STRING_XADDR(form_response_str), strlen(form_response_str), modulenum);

                  // send form_response_str, ignore #bytes_sent

   StoreInt(0, http_outbuf_base);      // reset lcount to start fresh in buffer

   if(http_value_count) // if first field was entered, add it to response

      HTTP_Outbuf_Cat(http_value_ptr, http_value_count, modulenum);

   else              // else add “person” to response

      HTTP_Outbuf_Cat(STRING_XADDR(person_str), strlen(person_str), modulenum);

   HTTP_Outbuf_Cat(STRING_XADDR(name_announce_str), strlen(name_announce_str), modulenum);

                     // add “ with a name like “ to response

   HTTP_To_Next_Field(modulenum); // go to name_id field, ignore #chars_advanced

   http_value_ptr = HTTP_Value_Ptr(modulenum); // load value,cnt for name_id field

   http_value_count =  HTTP_Value_Count(modulenum);

   HTTP_To_Next_Field(modulenum); // go to color field, ignore #chars_advanced

   next_http_value_ptr = HTTP_Value_Ptr(modulenum); // load value,cnt for color field

   next_http_value_count =  HTTP_Value_Count(modulenum);

   if(http_value_count) // if a name was entered, process it and add it to response

   {  HTTP_Plus_To_Space(http_value_ptr, http_value_count); // get rid of +’s in name text

      http_value_count = HTTP_Unescape(http_value_ptr, http_value_count);

      HTTP_Outbuf_Cat(http_value_ptr, http_value_count, modulenum);

   }

   else              // else add “yours” to response

      HTTP_Outbuf_Cat(STRING_XADDR(yours_str), strlen(yours_str), modulenum);

   HTTP_Outbuf_Cat(STRING_XADDR(good_to_hear_str), strlen(good_to_hear_str), modulenum);

                     // add “. It’s good to hear that “ to response

   if(next_http_value_count)  // if color field was entered, add it to response

      HTTP_Outbuf_Cat(next_http_value_ptr, next_http_value_count, modulenum);

   else              // else add “rainbow” to response

      HTTP_Outbuf_Cat(STRING_XADDR(rainbow_str), strlen(rainbow_str), modulenum);

   HTTP_Outbuf_Cat(STRING_XADDR(favorite_str), strlen(favorite_str), modulenum);

                     // add “ is your favorite color!</body></html>“ to response

   HTTP_Send_LBuffer( http_outbuf_base, modulenum); // send response, ignore #bytes_sent

}

 

 

void Logo_Response_Page ( int modulenum )

// this is the handler function that responds to url= /logo_response.png

// assumes that logo.s2 has been loaded into memory. serves it as static image.

{  xaddr http_outbuf_base = HTTP_Outbuf(modulenum);

   uint http_outbuf_size =  HTTP_Outbufsize(modulenum);

   int http_header_size;

   HTTP_Put_Header(http_outbuf_base, http_outbuf_size);  // http header->outbuf

   HTTP_Put_Content_Type(http_outbuf_base, http_outbuf_size,0, HTTP_IMAGE_PNG_CONTENT);

                  // params: xlbuf,maxbufsize,dynamic?,content_type

                  // static png image type->outbuf, cnt in first 2bytes; header’s done

   http_header_size = FetchInt(http_outbuf_base); // get size of http header we created

   HTTP_Send_2Buffers(http_outbuf_base+2, http_header_size,

                  MOSAIC_LOGO_PNG_XADDR, MOSAIC_LOGO_PNG_SIZE, modulenum);

                  // params: xbuf1,cnt1,xbuf2,count2,modulenum

}                 // send header&image, ignore numbytes_sent

 

#ifdef      __FABIUS__

#pragma option init=.doubleword    // declare 32-bit function pointers in code area

#include </mosaic/gui_tk/to_large.h>

#endif   // __FABIUS__

 

xaddr (*home_page_ptr)(void)          = Home_Page;

xaddr (*opera_config_page_ptr)(void)  = Opera_Config_Page;

xaddr (*form_entry_page_ptr)(void)    = Form_Entry_Page;

xaddr (*form_response_page_ptr)(void) = Form_Response_Page;

xaddr (*logo_response_page_ptr)(void) = Logo_Response_Page;

 

 

#ifdef      __FABIUS__

#include </mosaic/gui_tk/fr_large.h>

#pragma option init=.init       // return the initialized variable area to RAM;

#endif   // __FABIUS__

 

 

int Web_Handler_Installation( int modulenum )

// call this after Ether_Task_Setup_Default

// point browser to raw ip or to ip/index.html to see the home web page.

// urls are case sensitive. any other url’s serve out: page not found.

// returns nonzero error if too many handlers were added

// (limited by AUTOSERVE_DEFAULT_ROWS passed to ether_init)

{  int error = 0; // we’ll OR error results together and return final result

   error |= HTTP_Add_Handler(STRING_XADDR(slash_url_str), strlen(slash_url_str),

            home_page_ptr, modulenum);

   error |= HTTP_Add_Handler(STRING_XADDR(index_url_str), strlen(index_url_str),

            home_page_ptr, modulenum);

   error |= HTTP_Add_Handler(STRING_XADDR(opera_url_str), strlen(opera_url_str),

            opera_config_page_ptr, modulenum);

   error |= HTTP_Add_Handler(STRING_XADDR(form_entry_url_str), strlen(form_entry_url_str),

            form_entry_page_ptr, modulenum);

   error |= HTTP_Add_Handler(STRING_XADDR(form_response_url_str),

            strlen(form_response_url_str), form_response_page_ptr, modulenum);

   error |= HTTP_Add_Handler(STRING_XADDR(logo_response_url_str),

            strlen(logo_response_url_str), logo_response_page_ptr, modulenum);

   InitElapsedTime();      // start at zero so home page reports correct elapsed time

   return(error);

}

 

 

void Web_Demo( void )

// call this after Ether_Task_Setup_Default point browser to raw ip or to

//  ip/index.html to see the home web page.  urls are case sensitive.

// any other url’s serve out: page not found.

// returns nonzero error if too many handlers were added

// (limited by AUTOSERVE_DEFAULT_ROWS passed to ether_init)

{  Ether_Task_Setup_Default();

   Web_Handler_Installation(E_MODULENUM); // ignore too_many_handlers? flag

}

 

void main( void )

{  Web_Demo();

}

 

 

 

 

 

 

 


<< Previous | Next>>


Home|Site Map|Products|Manuals|Resources|Order|About Us
Copyright (c) 2006 Mosaic Industries, Inc.
Your source for single board computers, embedded controllers, and operator interfaces for instruments and automation