The MityDSP web server deamon allows you to easily add a web interface to your MityDSP based aplication. A web interface can be used for MityDSP device configuration, monitoring device status and/or as a diagnostic aid.
The MityDSP web server class (tcHttpd) provides full featured web server which may serve static web pages or dynamic web pages using server side includes and HTML forms. Your MityDSP application will provide server side CGI functions which are tailored to the specific requirements of your application. This allows the memory and resource requirements of the webserver to remain small which is ideal for an embedded application. The tcHttpd class handles all of the low level TCP socket interfaces and the HTTP protocol layer messages.
The following simple example will start a web server. A single CGI function "visitors" which will report the number of visitors since the server started.
The web page will generate this text:
This is an example web page with dynamic content. Visitors to this site: 10 |
The following HTML code will be compiled into your application (See: ROM File System):
Note: The "<%" and "%>" tags surround the name of a CGI function, "visitors", which your application will provide. When the MityDSP HTTP server encounters these tags, it will search for a CGI function in the tsHttpdCgiTable with a name that matches the string contained within the tags. If a match is found then that CGI function temporarily takes over rendering HTML code which will be inserted into the final web page. If no matching CGI function is found, then no extra text will be inserted into the web page.
The following C++ code will create the web server deamon object, configure it with a table of application specific CGI functions, then start the server.
The MityDSP web server stores it's web pages in a very simple ROM based file system. The file system can be easily modified to your applications needs, but in its most basic form you will compile the content of your webserver (HTML, GIF, JPG, etc. files) into your application code. With small modifications this approach could be changed to use a particular region of your FLASH or the MityDSP FAT file system.
To compile your webserver content into the application a tool (make_romfs.exe) is included in the MityDSP distribution which will compile all of the files in a directory tree into data arrays in a CPP file which you will then compile into your application. Below is an example of using this tool to generate the ROM file system for a web server demo program. The output from the following example is a file named "romfsdata.cpp", this file is then compiled into a web server demo program. There are two command line parameters to "make_romfs.exe": The -d parameter specifies the directory to compile and the -o option specifies the output file name.
C:\web_server> ..\MityDSP\sw\tools\make_romfs -d web -o romfsdata.cpp make_romfs - Version: 1.0 Built: Apr 26 2005 10:34:55 Copyright 2005 Critical Link LLC, All rights Reserved Including: "404.html" Including: "cgi_demo.html" Including: "eye.gif" Including: "followingeyes.js" Including: "form_demo.html" Including: "index.html" Including: "java_demo.html" Including: "leftchip.gif" Including: "mitylogosmall.gif" Including: "pupils.gif" Including: "rightchip.gif" Including: "thinklink.gif" Successfully Generated: "romfsdata.cpp" Compiled 12 files. 23879 bytes used for the file system. C:\web_server>
There are very few special requirements to the contents of your ROM file system. It must contain all of the files which your web server will serve. It should contain one file named "index.html", which will serve as the homepage for your MityDSP web application. It can optionally contain one file named "404.html" which will act as the default "Web page not found" page for your MityDSP based web server. Beyond that the only limit is available memory in your MityDSP device to hold the file system contents. You should take special care not to allow the directory tree which you run through "make_romfs.exe" to contain any files which you do not want in your web server's ROM. Any unreferenced files will waste memory space in your MityDSP application.
The MityDSP HTTP server is based in part on the Ethernut HTTP server written by egnite Software GmbH. More information on the Ethernut project may be found here http://www.ethernut.de.
Portions of the MitySP HTTP server are Copyright by Critical Link LLC. These portions written by Critical Link do not fall under the same redistribution guidelines (outlined below) as the sections copyrighted by other individuals.
Portions of the MityDSP HTTP server copyright by:
Copyright (C) 2001-2004 by egnite Software GmbH. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH 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 EGNITE SOFTWARE GMBH 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.