demonstration software for mbedRail24v board (mbed LPC1768)

Dependencies:   EthernetInterface Tiny-HTTPD mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers demo.cpp Source File

demo.cpp

00001 /* 
00002 Copyright 2014 ELZET80 Mikrocomputer GmbH&Co., KG
00003 
00004 Licensed under the Apache License, Version 2.0 (the "License");
00005 you may not use this file except in compliance with the License.
00006 You may obtain a copy of the License at
00007 
00008     http://www.apache.org/licenses/LICENSE-2.0
00009 
00010 Unless required by applicable law or agreed to in writing, software
00011 distributed under the License is distributed on an "AS IS" BASIS,
00012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 See the License for the specific language governing permissions and
00014 limitations under the License.
00015 */
00016 
00017 /*---------------------------------------------------------------------------*
00018  * mbed RAIL24V demo application
00019  *---------------------------------------------------------------------------*
00020  * Description:
00021  *      This program should demonstrate some features of the mbed RAIL24V Board
00022  *      and help to write own web applications for the LPC1768 mbed board.
00023  *      
00024  *      Features:
00025  *          * Webserver listening on port 80 with io port handling
00026  *          * RS232/RS485 echo
00027  *          * examples for interrupt and thread handling
00028  *
00029  *      Debugging:
00030  *          * via "embedded" mbed USB->Serial Port (9600 Baud)
00031  *---------------------------------------------------------------------------*/
00032 #include "mbed.h"
00033 #include "EthernetInterface.h"
00034 #include "HTTPD.h"
00035 
00036 
00037 #define debug               //enable debug output on virtual usb->com port
00038 #define dhcp_disable        //use user defined ip-address
00039 
00040 /*----------------------------------------------------------------------------
00041  *      constants
00042  *---------------------------------------------------------------------------*/
00043 
00044 /*content and length of "/dynamic/Elogo.gif"*/
00045 const char* const elogo_gif = "\x47\x49\x46\x38\x39\x61\x5D\x00\x70\x00\xC4\x00\x00\x88\xCB\xBB\x47\x7B\xB8\xC3\xE5\xDD\xC1\xD3\xE7\x4D\xB1\x99\x85\xA8\xD0\x19\x5A\xA6\xE0\xE9\xF3\xC2\xD4\xE8\x75\x9C\xCA\x65\x91\xC4\x28\x65\xAC\x93\xB2\xD5\x37\x70\xB2\xEF\xF4\xF9\xA3\xBD\xDB\xB2\xC8\xE1\xC4\xE6\xDD\xD1\xDE\xED\x89\xCC\xBB\x56\x86\xBE\xE1\xF2\xEE\xF0\xF9\xF7\xA6\xD8\xCC\xD2\xEB\xE5\xE2\xF2\xEE\xC4\xE5\xDD\xA3\xBD\xDC\x84\xA7\xD0\x12\x98\x77\x0A\x50\xA1\xFF\xFF\xFF\x21\xF9\x04\x00\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x5D\x00\x70\x00\x00\x05\xFF\x60\xE1\x8D\x64\x69\x9E\x68\xAA\xAE\x6C\xEB\x7A\xE2\x2B\xCF\x74\xCD\xC6\x76\xAE\xEF\x29\xCE\xFF\x40\x9A\x2F\x48\x2C\xA2\x86\x8B\x80\x72\xC9\x4C\x25\x03\x8B\x56\x83\x49\x6D\xA0\xA8\x54\xC3\xC9\x80\x65\x6A\x4B\x43\xCE\x67\x4C\x2E\xA7\xC4\x1F\x4E\x6B\x50\x6E\x0F\x50\xED\x76\xE0\x94\x88\x97\xE7\x60\x13\xDA\xFE\x39\x8F\xD5\x2C\x6C\x7C\x6F\x27\x7C\x63\x78\x25\x7B\x76\x88\x23\x61\x63\x07\x1C\x91\x92\x80\x27\x68\x94\x2A\x0A\x93\x91\x07\x63\x0F\x70\x7F\x9A\x1C\x51\x26\x01\x92\x0F\x8F\x92\xA3\x24\x8E\x1F\x84\x2E\x96\x36\x0E\x63\x14\x9F\x7D\x34\x01\x63\xAE\x27\xAC\xBA\x2C\xB0\x34\x14\x63\x0E\x29\x64\x35\xB8\xAD\x2A\xBC\x32\xBF\x33\xA7\x1F\x9E\xB5\xC6\xB9\xC9\x7A\xD3\x2F\xCC\x2F\x06\x64\xB4\xD1\xB7\xD6\x47\xD5\xC8\xD7\x7F\x34\x0A\x8F\x2A\xC5\xDE\xE2\xE0\x89\xDF\x2D\xD8\x2E\x10\x63\x0C\xE8\x63\xD2\xEB\xBB\xE1\xBD\x2B\xF0\x2C\xDA\x63\x56\x88\xD9\x53\xB7\x6F\x55\x38\x48\x9A\x54\x85\xBB\xD4\xC2\xDC\x87\x03\x2B\xC8\x84\x62\x74\xC5\x9D\x09\x56\x8B\xFC\xA4\x99\x21\xEF\x03\xBD\x7A\x76\x18\x9E\x38\x56\xB0\x51\xB8\x8C\x28\xFA\xFF\xA9\xF8\xF7\x21\xA0\xC0\x90\x2C\x48\x52\x6B\xF7\x41\x02\x96\x2F\x95\xC8\xBD\xA8\x53\x93\x05\x19\x2C\x0A\x2B\xE2\xBB\xA8\x6F\x99\x4E\x17\x12\xC6\x24\xF0\x39\x70\x86\xCC\x1E\x45\xC7\x6D\x74\xB1\x80\x4C\xD0\x42\x4D\x65\x3C\x65\x47\x02\x4D\xC9\x94\x47\x59\xF0\x94\xD0\x22\x9D\x53\x8B\x79\x68\x7E\xCD\x39\xB5\x45\xD2\x0F\x4B\x99\xDA\x3A\x3B\x34\x6D\x57\xB4\x2A\x54\x9E\xA8\x3A\x06\x27\xC8\x7B\x5F\x95\x49\x15\x09\xF6\x03\x04\x17\x66\xB5\xE2\x35\xA9\xD6\x68\xDB\x15\x9C\x3E\x28\x40\x9C\xF5\xC5\xD6\x7C\x8D\x07\x4B\x21\xE3\xF7\x2F\xC1\x99\x77\xEB\xE6\x0D\x9B\x82\xC1\x98\xC3\x94\xE7\x2A\x16\xCD\x38\x34\x1F\x8A\x23\x14\x95\xD9\x27\xC8\x4E\x41\x43\x8F\x47\x2E\x86\x71\x12\x65\xEF\xD9\x27\x6A\xC7\xB9\x6D\x88\x30\x89\xCB\x44\x69\xBE\x2E\x3C\x3C\xB8\x21\xE2\x7C\x8C\x8F\x40\x6E\xD7\x88\x75\xEB\x43\xAE\x6B\xFF\x91\x7D\xBB\x77\x1B\xDD\xBF\x8B\x7F\x11\x7E\x45\xA6\x50\xE8\xD3\xAB\x5F\xCF\x3E\x12\xF8\x1A\xC2\x71\xCB\x9F\x4F\xDF\x4C\x8D\xF2\x2A\xE2\xD7\xDF\xCF\xDF\xBE\x10\xF8\xFD\x05\x28\xE0\x7B\x34\xE8\x27\xE0\x81\x86\xD8\x30\x40\xFF\x7B\xA1\x44\x86\xE0\x83\xC5\x31\xA8\x09\x84\x14\x56\x68\xE1\x85\x0F\x25\x00\x45\x12\x09\x38\xC8\xC7\x01\x1A\x8E\xB0\x00\x05\xCE\x60\x68\x62\x1C\x71\xD1\x61\xC8\x03\x9D\x4D\x27\xCB\x89\x30\x4E\x86\x89\x1D\xD0\xA4\xD0\xC0\x8B\x30\x5E\xF8\x11\x3F\x6D\x38\xD0\xA2\x09\x3C\xE5\x58\xA1\x8F\x2D\x18\x80\x23\x5C\x2E\x78\x58\xE1\x05\x04\x34\xE9\xE4\x93\x50\x3A\x89\x81\x21\x3B\x92\xD0\x80\x4B\x24\x98\xC6\xD9\x2B\xB8\x45\xE9\x65\x94\x13\x74\x20\xE6\x98\x64\x96\x39\xA6\x00\x86\x50\xA4\x65\x8D\xD3\x91\x81\x1A\x09\x06\x0C\xE0\x80\x8C\x24\xF0\xC5\x87\x99\x78\x9A\x19\x66\x9E\x7C\xA2\xC9\x87\x09\x76\xB6\x64\x02\x19\x29\xC6\x26\x4C\x67\x4A\x96\xC1\xE7\xA2\x4C\x7E\xE9\xE8\x94\x76\x0C\x53\x42\x90\xB9\x45\x86\xA5\x07\x0E\xD2\x39\x42\x89\x71\x38\xEA\x29\x86\xBD\x28\xF2\xE6\x08\x82\x98\xC0\xD2\x33\xBF\x09\x19\x60\x2F\xC2\xB1\xDA\x53\x09\xC7\x58\x14\xAB\xAA\x02\xBA\x4A\x86\xAB\xBD\x38\x24\x8C\x09\x0D\xD0\x8A\x20\x59\xCA\x19\x66\x02\x1B\x55\x7A\x20\x1B\x56\xBE\x0E\x38\x69\x19\x0C\x91\x76\xEC\xA0\xC9\x0A\x88\x65\xA0\xD3\x3A\xDB\x46\xFF\x67\x47\x46\x5B\x1F\x43\x5A\x16\xCB\x53\xA1\xC6\xCA\x31\xEC\x85\x15\x08\x60\xEE\xB9\xE8\xA6\x7B\xAE\x05\x86\x1C\xD0\xD9\x95\x27\x44\x46\x51\x47\x3F\x8D\x6B\x87\xBA\xF8\xAA\xBB\xE7\xA2\x66\xFA\xC9\x47\xB1\x28\x68\xF9\x01\x45\xF1\x11\x7C\x27\xBF\x78\xEE\x8B\xF0\x99\xF2\x69\x7A\x82\xAE\x03\xDB\x5B\x6F\x09\x06\x7E\xB0\xB0\x9E\x17\x93\xE9\xAF\x21\x0E\x93\x00\x71\xC4\x14\x8B\x1B\xB2\x1D\x19\x93\xA9\x01\x00\x28\xA7\xAC\xF2\xCA\x29\x57\x20\x1F\xB8\x40\xDE\x21\xF1\x21\x33\x97\xC1\xF2\xCD\x2C\x9F\x08\xB3\x8A\x34\x8F\x3C\x31\x09\x15\x6B\xFB\xDC\x48\xB0\x09\x62\xB0\xCC\x3E\x0B\x4D\x1F\x45\xCE\xB0\xE9\xC1\x31\x47\xFF\x4C\xAA\xD2\xF5\x41\x04\x2B\xD2\x24\x70\x12\x75\xCF\x40\x53\x4D\x9F\xD3\x02\x7B\x64\x82\x69\xDC\x64\x29\x72\xD7\x5E\xBF\x3C\x73\xAE\xB9\xC9\x76\x69\xA2\x69\x9F\x3D\xC2\x91\x56\x1F\xD7\x76\x1B\xC8\x2E\xE9\xE9\x97\x90\xC6\x41\x51\x1C\xA4\xDC\xED\x1F\x09\x86\xEC\xFD\xA5\xC2\x17\x6F\x8C\xF5\x08\x80\x5F\x3D\xAA\x07\x94\xAA\xE6\x41\xA0\x6D\x94\x3C\x26\xE2\x0B\x2B\x2E\xB5\x07\x3D\x06\xDE\xCB\xAC\xC0\xDA\x7D\xB0\xFF\xE5\x98\x23\xAC\x39\xD7\x53\xDF\x1A\xB8\xA4\x56\x02\x57\xC2\xC7\x8A\x5A\xDE\x01\x86\x65\x8F\x40\x2F\xAA\x57\x7F\x10\x14\xB3\x63\xC7\x2D\x1F\x43\x10\x3B\x8C\x46\xED\x1E\xD0\x7B\x69\xD0\xBE\xD7\xF5\x56\xE8\x24\x74\x54\x6C\xAF\xC2\x96\x70\x6A\xF2\x76\x74\x66\x40\x02\x1C\x58\x4F\x46\xDD\x75\x76\x0C\x3B\xF5\xBC\xBB\x00\x31\x6C\x28\x20\x4F\x3D\x91\xFE\x1C\xB9\x56\x9B\xE0\xE3\xF6\x38\x0A\xB7\x8F\xD1\xB1\xF4\x6F\xB5\x6F\x08\x04\x3F\x7A\x60\x00\xA7\x8B\x4B\xCF\xBF\x85\xA5\xE3\xD7\xE9\xDA\x70\x00\x05\xF8\xC5\x00\x0A\x80\x1B\x19\x18\x10\x14\x0A\x28\xB0\x72\xB2\x0B\xE0\xA2\x06\x68\x87\x03\x0C\x60\x00\x0F\x8C\x83\x05\x2F\xC8\x1F\xD9\x75\x40\x82\x7D\xB2\x1F\x19\x3C\x78\x32\x9C\x99\xD0\x65\x22\xFC\x80\x09\x57\x98\xC2\x16\xBA\xF0\x85\x30\x8C\xA1\x0C\x67\xE8\xAB\x94\x9D\xCE\x86\x71\xA8\x00\x0E\xDB\xA0\x43\x94\xA1\xB0\x0C\x3D\x04\xC0\x0F\xA9\x36\x26\x00\x90\x4C\x4C\x46\x6C\x83\x00\x8A\x18\x87\x25\x8A\x49\x73\x4E\xEC\x00\x05\x7D\xC5\xC4\x38\x54\xB1\x0C\x51\x4C\x22\x16\x19\xA6\x44\x2E\x7A\xED\x8A\xB1\xEB\x80\x16\xC9\x90\xC5\xFF\x26\x7A\x91\x8C\x67\x54\x1A\x18\x47\x88\x44\x33\xB6\xB1\x8B\x4F\x74\xA3\x14\x1F\xB4\x01\x25\xFC\x8F\x3E\x6B\x1C\x43\x1E\xCB\x08\xC7\x39\xF6\x71\x8A\x7C\xB0\x89\x12\x62\x20\x9B\xFA\xE4\xD1\x62\x6F\xDC\x62\x22\xD1\x18\xC7\x3F\xAE\xCA\x20\xE1\x0A\xD0\x21\xF7\x48\xC9\x46\x2A\xD2\x8F\xFC\x71\x05\x21\x05\x34\xC9\x45\x8E\x81\x8F\x97\x84\x62\x1A\xE9\xA3\x49\x43\x49\xD2\x93\x7A\x44\x25\x28\x19\x89\x49\x56\x02\xD2\x36\x90\x2C\x24\x1E\x51\x89\x48\x31\xCA\x71\x8C\x9F\x1C\x65\x14\x5F\xD9\x1C\xC6\xC8\x72\x3E\x9D\xB4\x65\x1F\x71\xF9\x81\x5D\xCA\x91\x97\x6D\x08\xDD\x26\x4F\x29\x4C\x08\x36\x93\x95\xC4\x34\xA6\x23\x03\x14\x4B\x4E\xD2\xB2\x92\xCF\xCC\xA5\x25\x5D\xA9\x2C\xDE\x44\xB2\x3F\xC1\x8C\x26\x36\x45\xB9\xCD\xFD\x54\x93\x99\xC4\xAC\xA5\x38\x55\xA9\xCB\x51\xD2\x07\x92\xBE\x18\x5D\x3A\xB1\xB9\xCE\x56\x6A\xD3\x9E\x89\x59\x01\x7E\x5C\xE3\xCC\x79\xB2\xF3\x9F\xF8\x94\x66\xE3\x5A\xB0\x4F\x53\x5A\xF1\x9A\x00\xAD\x27\x39\xF1\x59\x19\x15\x1C\x00\x01\x10\x8D\xA8\x44\x23\xAA\xC0\x08\x58\x34\x03\x76\xB0\x68\x04\x30\xDA\x06\x0B\x68\x13\x94\xA3\x65\xF0\xA8\x45\xD9\xD5\x51\x8D\x92\x34\x0E\x13\x4D\x69\x44\x43\x00\x00\x3B";
00046 const int elogo_gif_len = 1686;
00047 /*content and length of "/dynamic/bg.gif"*/
00048 const char* const bg_gif = "\x47\x49\x46\x38\x39\x61\x02\x00\x7C\x02\xF7\x00\x00\xFF\xFF\xFF\xDD\xEC\xF5\xF9\xFC\xFD\xDF\xED\xF6\x0C\x78\xB8\xEB\xF4\xF9\xF2\xF8\xFB\xEE\xF6\xFA\xF3\xF8\xFC\xFC\xFD\xFE\x05\x74\xB6\x03\x73\xB6\x02\x72\xB6\xF6\xFA\xFC\x0D\x78\xB9\x34\x8E\xC4\xFA\xFC\xFE\xE9\xF3\xF9\xFB\xFD\xFE\x2B\x89\xC1\x14\x7C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\xD5\xAB\x58\xA5\x5E\xBA\xC4\x80\x81\x05\x0B\x15\x2A\x6C\xD8\x00\x0D\x1A\x1E\x3C\x9C\x38\xAD\x5A\x55\xAF\x5E\xB1\x62\xEF\xDE\xE1\xC3\xC7\x85\x8B\x19\x33\xEB\xD6\xF5\xEA\x85\x06\xCD\xB2\x65\x86\x0C\xD5\xA9\x63\xC9\x52\x90\x20\x60\xC0\x78\xF1\x82\x0A\x95\x23\x47\x84\x08\x61\xC0\x00\x08\x90\x09\x13\x36\x6C\xAC\x58\xA1\x49\x93\x01\x03\x0D\x1A\x48\x90\x90\xB5\xB4\xE9\xD3\xA8\xAB\x5E\xBB\x86\x08\x51\x86\x0C\x0B\x16\x28\x50\x30\x6D\x5A\x88\x10\x04\x08\x80\x03\x27\x42\x04\x05\x0A\x28\x50\x94\x28\x31\x62\x44\x87\x0E\x31\x62\xE4\xCB\x17\x2D\x9A\x20\x41\x81\x02\x3D\x78\x30\x6A\xD4\x8D\x1B\x9E\x3C\xF5\xEB\x67\xCA\xD4\x9A\x35\x53\xA6\xC8\xFF\x92\x45\x84\x48\xBA\x74\x3E\x7C\xE8\xD0\xF1\xE3\x07\x0F\x1E\x52\xA4\xD4\xAA\xA5\x44\x89\x2F\x5F\xAC\x58\x29\x52\x54\xA3\xC6\xA3\x47\xE5\x94\x23\x8C\x30\xB9\xE4\x22\x8F\x3C\xB6\xD8\xF2\xCF\x3F\x87\x1C\x32\xC3\x0C\x8C\x30\xA2\x8F\x3E\x50\x40\x91\x46\x1A\x77\xDC\xC1\x0D\x37\x51\x44\x41\x06\x19\x20\x80\x10\x4A\x28\x6A\xA8\x31\xC0\x00\xE4\x90\x03\x09\x24\xCD\x34\x53\x40\x01\x07\x1C\xA0\x81\x06\x08\x20\xC0\x01\x07\x29\xA4\x00\x01\x04\x09\x24\xF0\xC1\x07\xA9\x05\x29\xE4\x90\x44\x16\x69\xE4\x90\x02\x75\xD2\xC9\x1C\x73\x94\x51\x06\x13\x4C\xBC\xD6\x55\x6C\x06\xCD\xF6\x15\x42\xB7\x85\xA5\x8A\x2A\xB9\x29\x34\x96\x35\xD6\xF4\x96\x4A\x2A\xBF\x05\xD7\x4A\x2B\xC3\x1D\x73\x4C\x71\xB8\xE0\x42\x09\x25\xC7\xBD\xF1\xC6\x0B\x2F\x48\x34\xC8\x20\xB4\xD0\x42\x91\x1C\x72\xD0\x43\x4F\x37\xDD\x98\x63\xCE\x74\xC6\x18\xF3\xCA\x2B\xA4\x90\xF2\xC7\x1F\x61\x84\xC1\x06\x1B\x8B\x2C\xA2\x87\x1E\x56\x58\xF1\xCD\x37\xD2\x48\x13\x4F\x3C\x9F\x7C\x22\x86\x18\xDB\x6C\x53\x49\x25\xC8\x20\x23\x84\x10\x5F\x7C\x01\x0A\x28\xEA\xA8\x73\xCF\x3D\x45\x14\xCB\x61\x8F\x3D\xF3\xCC\x93\x47\x1E\x7D\xF4\xE1\x82\x0B\x7C\xF0\x51\x4D\x35\x7E\xF8\xD1\x42\x0B\x38\xE0\xE0\x86\x1B\x89\x24\x72\xC4\x11\xFC\xF0\x93\x44\x12\x76\xD8\x01\x0C\x30\x8D\x34\xE2\x84\x13\xE8\xA0\x13\x4B\x2C\xFE\xF8\x13\x49\x24\xCC\x30\xD3\x44\x13\x5A\x68\xD1\x46\x1B\xBF\xFC\xE2\x8D\x37\x70\xC0\x91\x45\x16\xB7\xDC\xD2\x45\x17\x0B\x6E\xB1\xC5\x29\xA7\xEC\xB1\x47\x0F\x3D\x9C\x71\x46\x1C\x71\x68\xA3\x4D\x15\x55\x50\x41\x45\x32\xC9\xE4\x90\x83\x2B\xAE\x84\x13\x0E\x3B\xEC\x20\x81\xC4\x64\xD4\x50\x03\x04\x10\xBA\xE8\x42\x07\x1D\x21\x8E\x33\x4E\x21\x85\x88\x22\xCA\x65\x40\xF1\xC2\xCB\x89\x30\xC0\x20\x54\x26\x99\x6C\x86\x09\x26\x44\x05\x13\xCC\x8B\xB3\xCC\x12\xE3\x8C\xD9\x64\xF3\x59\x8D\x37\x86\x96\x23\x31\xC4\x28\xB5\xE3\x68\x3D\x32\xF5\xE3\x91\x48\x27\xAD\xF4\xD2\x4C\x37\xED\xF4\xD3\x50\x47\x2D\x55\x40\x00\x3B";
00049 const int bg_gif_len = 1518;
00050 /*content and lenght of "/dynamic/favicon.ico"*/
00051 const char* const favicon_ico = "\x00\x00\x01\x00\x01\x00\x10\x10\x10\x00\x01\x00\x04\x00\x28\x01\x00\x00\x16\x00\x00\x00\x28\x00\x00\x00\x10\x00\x00\x00\x20\x00\x00\x00\x01\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC8\x77\x31\x00\x9E\xBF\x39\x00\xEF\x9E\x58\x00\xFC\xA7\x52\x00\xFF\xA4\x54\x00\xFF\xF4\xC2\x00\xFF\xFF\xFF\x00\xC0\xC0\xC0\x00\x00\x00\xFF\x00\x00\xFF\x00\x00\x00\xFF\xFF\x00\xFF\x00\x00\x00\xFF\x00\xFF\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\x00\x11\x72\x72\x72\x72\x72\x71\x10\x17\x72\x72\x72\x72\x72\x77\x10\x77\x72\x72\x72\x72\x72\x77\x70\x22\x77\x77\x77\x77\x77\x22\x20\x77\x77\x61\x64\x11\x77\x77\x70\x22\x77\x17\x53\x71\x77\x22\x20\x77\x77\x16\x53\x71\x77\x77\x70\x22\x77\x11\x53\x71\x77\x22\x20\x77\x77\x17\x53\x71\x77\x77\x70\x11\x77\x61\x64\x11\x77\x11\x10\x11\x11\x11\x11\x11\x11\x11\x10\x17\x71\x76\x77\x17\x71\x71\x10\x17\x11\x71\x71\x17\x11\x71\x10\x17\x61\x71\x16\x17\x61\x71\x10\x17\x71\x71\x77\x17\x77\x77\x10\x11\x11\x11\x11\x11\x11\x11\x10\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04\x00\x01\xF3\x04";
00052 const int favicon_ico_len = 318;
00053 
00054 /*content of "/dynamic/Cstyle.css"*/
00055 const char* const static_css =
00056 "/* Main Style sheet for the ELZET80 */"
00057 "body{font: 100% Arial,Helvetica,sans-serif;    text-align: center; margin: 0; background: #FFF; color: #000;}"
00058 "#container{width: 100%;}"
00059 "#header{clear: both; width: 80%; min-width: 500px; margin: 0 auto; height:130px; padding: 10px 0 0; color:#999;}"
00060 "#main-outer{float: left; clear: both; width: 100%;background: #FFF url(/dynamic/bg.gif) repeat-x;}"
00061 "#main{clear: both; width: 90%; min-width: 500px; margin: 0 auto; text-align: left; padding: 0 10px;}"
00062 "#footer{width: 100%; background: #BBB; clear:both; font-size: 10pt; color: #555;}"
00063 "img{border: none;}"
00064 ".left{float: left;}"
00065 ".right{float: right;}"
00066 ".left-align{text-align: left;}"
00067 ".right-align{text-align: right;}"
00068 ".center-align{text-align: center;}"
00069 ".lf{clear: both; margin: 0;    padding: 5px 0;}"
00070 ".block1{float: left; display: block; width: 225px; padding: 0 10px; margin: 0 0 10px;}"
00071 ".block2{float: left; display: block; width: 470px; padding: 0 10px; margin: 0 0 10px;}"
00072 ".block100{float: left; display: block; width: 98%; padding: 0 1%; margin: 0 0 10px;}"
00073 ".max750{max-width: 750px;}"
00074 ".max850{max-width: 850px;}"
00075 ".form-table{width: 100%; border: 1px solid #AAA; margin: 5px 0 0; text-align: left; border-collapse: collapse;}"
00076 ".form-table tr td, .form-table tr th{padding: 5px;}"
00077 ".margin-top-10{margin-top: 10px;}"
00078 ".no-border{border: none;}"
00079 ".border-td tr td, .border-td tr th{border: 1px solid #AAA;}"
00080 "legend{font-weight: bold;}"
00081 "#header #logo{float: left; display: block;}"
00082 "#header #title{font-size: 18pt; float: left; margin: 15px 0  0 20px; display: block;}"
00083 "#header #text{float: right; text-align: left; display: block;}"
00084 "#menu-block{float: left; display: block; }"
00085 "#home-page-img img{float: right; display: block; max-width: 300px;}"
00086 "#main h1{float: left; clear: both; color: #FFF;}"
00087 "#main h2{float: left; clear: both; color: #FFF; margin: -10px 0 10px; padding: 0;}"
00088 "#menu{margin: 0;}"
00089 "ul li{list-style-type: circle; padding: 3px;}"
00090 "#footer p {margin: 0; padding: 10px 0 10px 15px;}"
00091 "#footer a {color:#009898;}"
00092 ".io-user-outputs td{text-align: center; font-weight: bold; font-size: 26px; padding: 5px 0; cursor: hand;}"
00093 ".io-user-outputs td:hover{background: #CCC;}";
00094 
00095 
00096 /*header-part of the dynamically generated analog-input website*/
00097 const char* const  analog_header =
00098     "<html xmlns=\"http://www.w3.org/1999/xhtml\">"
00099     "<head>"
00100     "<title>Welcome to mbed\'s Web Page!</title>"
00101     "<meta http-equiv=\"Content-Type\"content=\"no-cache\"content=\"text/html; charset=ISO-8859-1\" />"
00102     "<link rel=\"shortcut icon\" href=\"/dynamic/favicon.ico\" />\n"
00103     "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/dynamic/Cstyle.css\" />\n"
00104     "</head>"
00105     "<body>"
00106     "<div id=\"container\">"
00107     "<div id=\"header\">"
00108     "<div id=\"logo\"><a href=/index.htm><img src=\"/dynamic/Elogo.gif\" alt=\"ELZET80\" title=\"Go to home page\" /></a></div>"
00109     "<div id=\"title\">Welcome Elzet 80 mbedRail24v Demo</div>"
00110     "<div id=\"text\">"
00111     "<p>Running ELZET80 mbed demo</p>"
00112     "</div>"
00113     "</div>"
00114     "<div id=\"main-outer\">"
00115     "<div id=\"main\">";
00116 
00117 /*header-part of the dynamic generated io website*/
00118 const char* const io_header =
00119     "<html xmlns=\"http://www.w3.org/1999/xhtml\">"
00120     "<head>"
00121     "<title>Welcome to mbed\'s Web Page!</title>"
00122     "<meta http-equiv=\"Content-Type\"content=\"no-cache\"content=\"text/html; charset=ISO-8859-1\" />"
00123     "<link rel=\"shortcut icon\" href=\"/dynamic/favicon.ico\" />\n"
00124     "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/dynamic/Cstyle.css\" />\n"
00125     "<script type=\"text/javascript\">\n"
00126     "function key(id){\n"
00127     "var out=\"io.htm?o\"+id;location.href=out}\n"
00128     "</script>\n"
00129     "</head>"
00130     "<body>"
00131     "<div id=\"container\">"
00132     "<div id=\"header\">"
00133     "<div id=\"logo\"><a href=/index.htm><img src=\"/dynamic/Elogo.gif\" alt=\"ELZET80\" title=\"Go to home page\" /></a></div>"
00134     "<div id=\"title\">Welcome Elzet 80 mbedRail24v Demo</div>"
00135     "<div id=\"text\">"
00136     "<p>Running ELZET80 mbed demo</p>"
00137     "</div>"
00138     "</div>"
00139     "<div id=\"main-outer\">"
00140     "<div id=\"main\">";
00141 
00142 /*footer of the dynamic generatred analog and io webpages*/
00143 const char* const io_footer=
00144     "</div>"
00145     "</div>"
00146     "</div>"
00147     "<div id=\"footer\">"
00148     "<p>&copy; 2012 &nbsp; ELZET80 Mikrocomputer GmbH&Co. KG &bull; Aachen &bull; <a href=\"http://www.elzet80.de\">www.elzet80.de</a></p>"
00149     "</div>"
00150     "</div>"
00151     "</body>"
00152     "</html>";
00153     
00154 /*content of index.html*/
00155 const char* const index_html =
00156     "<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n"
00157     "<head>\r\n"
00158     "<title>Welcome to mbed\'s Web Page!</title>\r\n"
00159     "<meta http-equiv=\"Content-Type\"content=\"no-cache\"content=\"text/html; charset=ISO-8859-1\" />\r\n"
00160     "<link rel=\"shortcut icon\" href=\"/dynamic/favicon.ico\" />\r\n"
00161     "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/dynamic/Cstyle.css\" />\r\n"
00162     "</head>\r\n"
00163     "<body>\r\n"
00164     "\r\n"
00165     "<div id=\"container\">\r\n"
00166     "\r\n"
00167     "<div id=\"header\">\r\n"
00168     "<div id=\"logo\"><img src=\"/dynamic/Elogo.gif\" alt=\"ELZET80\" title=\"Home page\" /></div>\r\n"
00169     "<div id=\"title\">Welcome Elzet 80 mbedRail24v Demo</div>\r\n"
00170     "<div id=\"text\">\r\n"
00171     "<p>Running ELZET80 mbed demo</p>\r\n"
00172     "</div>\r\n"
00173     "</div>\r\n"
00174     "\r\n"
00175     "<div id=\"main-outer\">\r\n"
00176     "<div id=\"main\">\r\n"
00177     "<h1>Main menu </h1>\r\n"
00178     "<div class=\"lf\">\r\n"
00179     "<div id=\"menu-block\">\r\n"
00180     "<ul id=\"menu\">\r\n"
00181     "<li><a href=\"/dynamic/io.htm\">Digital I/O Page</a></li>\r\n"
00182     "<li><a href=\"/dynamic/analog.htm\">Analog Input Page</a></li>\r\n"
00183     "</ul>\r\n"
00184     "</br>\r\n"
00185     "</div>\r\n"
00186     "</div>\r\n"
00187     "</div>\r\n"
00188     "</div>\r\n"
00189     "\r\n"
00190     "<div id=\"footer\">\r\n"
00191     "<p>&copy; 2012 &nbsp; ELZET80 Mikrocomputer GmbH&Co. KG &bull; Aachen &bull; <a href=\"http://www.elzet80.de\">www.elzet80.de</a></p>\r\n"
00192     "</div>\r\n"
00193     "\r\n"
00194     "</div>\r\n"
00195     "\r\n"
00196     "</body>\r\n"
00197     "</html>";
00198 
00199 /*definition of constants for hardware abstraction (enables compatibility to "ELZET80 kbed uTasker Platform")*/
00200 const char ASCII_out = '0';         // 0-9 for output ports
00201 const char ASCII_in = 'a';          // a-f for input ports
00202 const char ASCII_analog = '0';      // 0-9 for analog input
00203 
00204   
00205 
00206 /*----------------------------------------------------------------------------
00207  *      io functions
00208  *---------------------------------------------------------------------------*/
00209  
00210 /*assign mbed Rail24V io-ports to LPC1768 io ports*/
00211 
00212 /*ASCII-characters are only relevant for use with http handling routines*/
00213 DigitalOut out1(p23, 1);                   //Output 1   --> ASCII "1"
00214 DigitalOut out2(p24, 1);                   //Output 2   --> ASCII "2"
00215 DigitalOut out3(p25, 1);                   //Output 3   --> ASCII "3"
00216 DigitalOut out4(p26, 1);                   //Output 4   --> ASCII "4"
00217 DigitalOut relay1(p22, 0);                   //Relais     --> ASCII "5"
00218 DigitalOut led1(LED1, 0);                  //MBED led1 - activated in "boot sequence" // blink: led1 (by timer-interrupt ticker)
00219 DigitalOut led2(LED2, 0);                  //MBED led2 - activated in "boot sequence" // blink: led2 (by led2_thread)
00220 DigitalOut led3(LED3, 0);                  //Mbed led3
00221 DigitalOut led4(LED4, 0);                  //MBED led4
00222 DigitalIn in1(p19);                        //Input 1    --> ASCII "a"
00223 DigitalIn in2(p20);                        //Input 2    --> ASCII "b"
00224 DigitalIn in3(p11);                        //Input 3    --> ASCII "c"
00225 DigitalIn in4(p12);                        //Input 4    --> ASCII "d"
00226 AnalogIn ain1(p15);                        //Analog Input 1 --> ASCII "1"
00227 AnalogIn ain2(p16);                        //Analog Input 2 --> ASCII "2"
00228 AnalogIn ain3(p17);                        //Analog Input 3 --> ASCII "3"
00229 AnalogIn ain4(p18);                        //Analog Input 4 --> ASCII "4"
00230 
00231 
00232 DigitalOut rs485_txmode(p21, 0);           //RS485 - enable receiver (Port 21: 0 recieve mode / 1 transmit mode)
00233 
00234 //Serial interfaces
00235 //Pins        UART
00236 //USBTX,USBRX 0
00237 //p13,p14     1
00238 //p28,p27     2
00239 //p9,p10      3
00240 
00241 RawSerial rs232(p9, p10);  // tx, rx -- rawserial is used for compatibility with interrupt routines
00242 RawSerial rs485(p13, p14);  // tx, rx
00243 
00244 
00245 LocalFileSystem local("local");             //initialize the local file system
00246 
00247 Ticker interruptTick;                        //create a timer
00248 
00249 /*httpd*/
00250 HTTPD *httpd;                               //initialize the httpd-webserver
00251 
00252 
00253 /*----------------------------------------------------------------------------
00254  *      functions
00255  *---------------------------------------------------------------------------*/
00256  
00257  
00258 void index_website_handler (int id);
00259 void dynamic_website_handler (int id);
00260 
00261 void dynamic_IO_website(int id);
00262 void dynamic_analog_website(int id);
00263 
00264 int io_webhandler_action(char *input_buf, int input_puf_len);
00265 
00266 unsigned short read_adc(char port_name);
00267 int read_portval(char port_name);
00268 int write_portval(char port_name, int port_val);
00269 int toggle_port(char port_name);
00270 
00271 
00272 
00273 /*----------------------------------------------------------------------------
00274  *      interrupt and thread functions
00275  *---------------------------------------------------------------------------*/
00276 
00277 
00278 /*---------------------------------------------------------------------------*
00279  * Routine:  echoRS232 (interrupt)
00280  *---------------------------------------------------------------------------*
00281  * Description:
00282  *
00283  *      Toggle LED3 to indicate RS232 activity.
00284  *      Read a char from the rs232 input port to a buffer and
00285  *      send the char to rs232 port.
00286  *---------------------------------------------------------------------------*/
00287 void echoRS232() {
00288     char rs232_buffer = 0;                  //local buffer
00289     
00290     led3 = !led3;                           //toggle LED3
00291     
00292     /*read rs232 buffer and write the result back to rs232 interface*/
00293     if (rs232.readable()){                  //avoid hanging up the program in case of multiple use of rs232
00294        
00295        rs232_buffer =  rs232.getc();        //read input to buffer
00296        
00297         if (rs232.writeable()){   
00298             rs232.putc(rs232_buffer);       //write buffer to rs232 output
00299         }
00300     }
00301     return;     
00302 }
00303 
00304 /*---------------------------------------------------------------------------*
00305  * Routine:  echoRS485  (interrupt)
00306  *---------------------------------------------------------------------------*
00307  * Description:
00308  *      Toggle LED3 to indicate RS485 activity.
00309  *      Read a char from the RS485 input port to a buffer, switch RS485 port
00310  *      to transmission mode and send the buffered char to RS485 port.
00311  *---------------------------------------------------------------------------*/
00312 void echoRS485() {
00313     char rs485_buffer = 0;              //local buffer
00314     
00315     led3 = !led3;                       //toggle LED
00316     
00317     rs485_txmode = 1;                   //enable RS485 transmission mode 
00318     
00319     //read rs485 inpuf buffer and write the result back to rs485 interfacee
00320     if (rs485.readable()){
00321        
00322        rs485_buffer =  rs485.getc();
00323        
00324         if (rs485.writeable()){   
00325             rs485.putc(rs485_buffer);
00326         }
00327     }
00328 }
00329 
00330 /*---------------------------------------------------------------------------*
00331  * Routine:  enableRS485receiver  (interrupt)
00332  *---------------------------------------------------------------------------*
00333  * Description:
00334  *      Disable RS485 transmission mode. (TxIRQ -> tx buffer empty)
00335  *---------------------------------------------------------------------------*/
00336 void enableRS485receiver() {
00337      rs485_txmode = 0;                  //disable RS485 transmission mode
00338     }
00339 
00340 
00341 /*---------------------------------------------------------------------------*
00342  * Routine:  interruptTickRoutine
00343  *---------------------------------------------------------------------------*
00344  * Description:
00345  *      Toggle LED1.
00346  *---------------------------------------------------------------------------*/
00347 void interruptTickRoutine() {
00348     led1 = !led1;
00349     return;
00350 }
00351 
00352 
00353 /*---------------------------------------------------------------------------*
00354  * Routine:  led2_thread
00355  *---------------------------------------------------------------------------*
00356  * Description:
00357  *      Example for a thread. Toggle LED2 and sleep 1000ms.
00358  *---------------------------------------------------------------------------*/
00359 void led2_thread(void const *args) {
00360     while (true) {
00361         led2 = !led2;
00362         Thread::wait(1000);
00363     }
00364 }
00365 
00366 
00367 
00368  
00369 
00370 
00371 
00372 /*----------------------------------------------------------------------------
00373  *      main ()
00374  *---------------------------------------------------------------------------*/
00375 int main() {
00376     
00377     #if defined debug
00378         printf("Welcome to ELZET80 mbed demo\r\n");                     //print debug Informations to LPC1768 USB-Comport (9600 baud)
00379     #endif
00380     
00381     /*Example to write a file to the local filesystem:
00382     
00383         FILE *fp = fopen("/local/helloworld.txt", "w");  // Open "helloworld.txt" on the local file system for writing
00384         fprintf(fp, "Hello World!");
00385         fclose(fp);
00386     */
00387 
00388     led1=1;          //enable status led1
00389     
00390     /*Ethernet initialisation - the demo would not start without an ethernet connection*/
00391     EthernetInterface eth;
00392     
00393     #if defined dhcp_disable
00394         static const char* netIP = "192.168.17.73";
00395         static const char* netMask = "255.255.255.0";
00396         static const char* netGateway = "192.168.17.73"; 
00397         eth.init(netIP,netMask,netGateway);                 //use userpecific IP, Netmask and Gateway
00398     #else
00399          eth.init();                                        //use DHCP client function
00400     #endif
00401     
00402     #if defined debug
00403         printf("starting Ethernet Interface setup\r\n");
00404     #endif
00405     
00406     int ethError;                                   //Ethernet error buffer
00407     
00408     /*start ethernet connection*/
00409     do{
00410         ethError = eth.connect(5000);               //connect to network with 5s (5000ms) timout
00411         #if defined debug
00412             if(ethError)printf("Error %d occurrenced \r\n", ethError);
00413         #endif
00414         wait(1);
00415     }while(ethError != 0);                          //wait until a network connection was established
00416     
00417     
00418     led2 = 1;                                       //set status led2 
00419     
00420    #if defined debug
00421         printf("\r\nEthernet Interface setup finished. IP: %s\r\n", eth.getIPAddress());
00422         printf("enabling RS232/RS485 echo mode ... \r\n");
00423     #endif
00424     
00425     
00426     /*init serial ports*/
00427     rs232.baud(9600);                                                   //set rs232 baudrate to 9600
00428     rs232.printf("Enabled RS232 port - starting echo mode \r\n");
00429     rs232.attach(&echoRS232,Serial::RxIrq);                             //attach the rs232 echo function to rs232 rx interrupt
00430     
00431     rs485.attach(&enableRS485receiver,Serial::TxIrq);                   //enable automatic rx/tx switching (tx-buffer empty interrupt)
00432     rs485_txmode = 1;                                                   //enable RS485 transmission mode
00433     rs485.baud(9600);                                                   //set rs485 baudrate to 9600 baud
00434     rs485.printf("Enabled RS485 port - starting echo mode \r\n");
00435     rs485.attach(&echoRS485,Serial::RxIrq);                             //enable echo mode via RS485 echo routine
00436     
00437  
00438     httpd = new HTTPD;
00439     httpd->attach("/dynamic/", &dynamic_website_handler);               //use the function "dynamic_website_handler" for handling the dynamic websites 
00440                                                                         //initialize all virtual directories before the root directory
00441     httpd->attach("/flash/", "/local/");                                //attach the flash storage ("local") to http://mbed.ip/flash/  -- currently the flash file system handler could not handle subdirectories!
00442     
00443     httpd->attach("/", &index_website_handler);                         //index.html
00444                         
00445     
00446     httpd->start(80);                                                   //httpd on port 80
00447     
00448     
00449     #if defined debug
00450         printf("Webserver started.\r\n");
00451     #endif
00452     
00453     
00454     #if defined debug
00455         printf("enabling Ticker for led1 and Thread for led2 \r\n");
00456     #endif
00457     
00458     interruptTick.attach(&interruptTickRoutine,0.5);                      //enabling Ticker for timer interrupt triggered subroutine (.5s periodic toggling of led1)
00459     
00460 
00461     Thread led2Thread(led2_thread, NULL, osPriorityNormal, 1024 * 4);   //create a separate thread
00462     
00463     //endless loop - "httpd-thread"
00464     while(1){
00465         Thread::wait(5);                                                //wait 5 ms
00466         
00467         
00468         /*handle waiting http requests*/
00469         /* the program waits here until a request was made and answered*/
00470         
00471         httpd->poll();                                                  //poll httpd for incoming requests
00472         
00473         led3 = !led3;                                                   //toogle led3 (indicate that a http request was handled)
00474 
00475     }
00476 }
00477 /*  end of main() */
00478 
00479 
00480 
00481 
00482 
00483 /*----------------------------------------------------------------------------
00484  *      website handling functions
00485  *---------------------------------------------------------------------------*/
00486 
00487 
00488 /*---------------------------------------------------------------------------*
00489  * Routine:  index_website_handler
00490  *---------------------------------------------------------------------------*
00491  * Description:
00492  *      Website hander for handling requests of "http://mbed.ip/ *** ".
00493  *
00494  * Inputs:
00495  *      int id                  -- number of httpd web handler
00496  * Outputs:
00497  *      none                    -- only output to web browser
00498  *---------------------------------------------------------------------------*/
00499 void index_website_handler (int id) {
00500     char input_buf[256];                                                //create an input buffer
00501 
00502     strcpy(input_buf, httpd->getFilename(id));                          //copy requested file name to buffer
00503     
00504     #if defined debug
00505     printf("index website handler -- handler-id:%d reqested file:%s\r\n", id, input_buf);
00506     #endif
00507     
00508     httpd->send(id, index_html, strlen(index_html), "Content-Type: text/html\r\n");         //transmit content of "index_html" to browser
00509 
00510 }
00511     
00512 
00513 /*---------------------------------------------------------------------------*
00514  * Routine:  dynamic_website_handler
00515  *---------------------------------------------------------------------------*
00516  * Description:
00517  *      Website hander for handling requests of "http://mbed.ip/dynamic/ *** ".
00518  * Inputs:
00519  *      int id                  -- number of httpd web handler
00520  * Outputs:
00521  *      "http"                  -- output to web browser
00522  *---------------------------------------------------------------------------*/
00523 void dynamic_website_handler (int id) {
00524     char input_buf[256];                                //buffer for request parameters
00525 
00526     strcpy(input_buf, httpd->getFilename(id));          //copy request to buffer
00527     
00528     #if defined debug
00529     printf("dynamic website handler -- handler-id:%d  reqested file:%s\r\n", id, input_buf);
00530     #endif
00531     
00532     /*process the request*/
00533     if(strcmp (input_buf, "Elogo.gif") == 0) {
00534         httpd->send(id, elogo_gif, elogo_gif_len, "Content-Type: image/gif\r\n");
00535     } else if(strcmp (input_buf, "bg.gif") == 0) {
00536         httpd->send(id, bg_gif, bg_gif_len, "Content-Type: image/gif\r\n");
00537     } else if(strcmp (input_buf, "Cstyle.css") == 0) {
00538         httpd->send(id, static_css, strlen(static_css), "Content-Type: text/html\r\n");
00539     } else if(strcmp (input_buf, "favicon.ico") == 0) {
00540         httpd->send(id, favicon_ico, favicon_ico_len, "Content-Type: image/x-icon\r\n");
00541     } else if (strcmp(input_buf, "io.htm") == 0){
00542         dynamic_IO_website(id);
00543     } else if(strcmp (input_buf, "analog.htm") == 0) {
00544         dynamic_analog_website(id);
00545     } else{    
00546         httpd->httpdError(id, 404);
00547     }
00548 }
00549 
00550 
00551 /*---------------------------------------------------------------------------*
00552  * Routine:  dynamic_analog_website
00553  *---------------------------------------------------------------------------*
00554  * Description:
00555  *      Generation and handling of the dynamic website for digital ports.
00556  * Inputs:
00557  *      int id                  -- number of httpd web handler
00558  * Outputs:
00559  *      "http"                  -- output to web browser
00560  *---------------------------------------------------------------------------*/
00561 void dynamic_IO_website(int id){
00562     char out_buf[2000];                                                 //buffer for website output (buffer size is minimized to max. required size)
00563     char query_buf[256];                                                //buffer to store 
00564     char tempstring[32];                                                //buffer for small string construction
00565     int counter = 0;                                                    //counter variable (multiple use)
00566     
00567     strcpy(query_buf, httpd->getQueryString(id));                       //copy transmitted parameters to query_buf
00568     strcpy(out_buf, io_header);                                         //initialize Website output
00569     
00570     io_webhandler_action(query_buf, strlen(query_buf));                 //handle transmitted parameters stored in query_buf
00571     
00572     
00573     /*create website in buffer*/
00574     strcat(out_buf,"<h1>View and Control Ports</h1><div class=\"lf\"><div class=\"block2\"><fieldset><legend>I/OPorts</legend>");
00575     
00576     strcat(out_buf,"<table class=\"form-table border-td\"><tr><th colspan=\"5\" class=\"center-align\">Outputs</th></tr><tr class=\"center-align\"><td>OUT1</td><td>OUT2</td><td>OUT3</td><td>OUT4</td><td>RELAY</td></tr><tr class=\"center-align\">");
00577     
00578     /*read status of output ports*/
00579     for(counter = 1; counter <= 5; counter++){
00580            strcat(out_buf,"<th style=\" background-color:");
00581            if (read_portval(ASCII_out + char(counter))){
00582                 strcat(out_buf,"gold");
00583             }else{
00584                 strcat(out_buf,"lime");
00585             }
00586             strcat(out_buf,"\" onclick=\"key(\'");
00587             sprintf(tempstring,"%i\')\">O%i</th>",counter,counter);
00588             strcat(out_buf,tempstring);
00589         }
00590         
00591     strcat(out_buf, "</tr> </table>");
00592     strcat(out_buf, "<table class=\"form-table border-td\"><tr><th colspan=\"4\" class=\"center-align\">Inputs</th></tr><tr class=\"center-align\"> <td>IN1</td> <td>IN2</td><td>IN3</td><td>IN4</td></tr><tr class=\"center-align\">");
00593     
00594     /*read input values*/
00595     for(counter = 0; counter <= 3; counter++){                          //read port 1-4 (mapped to a-d)
00596         strcat(out_buf,"<th style=\" background-color:");
00597         if (read_portval(ASCII_in + char(counter))){ 
00598               strcat(out_buf,"gold");
00599         }else{
00600                 strcat(out_buf,"lime");
00601         }
00602         sprintf(tempstring,"\">%i</th>",(counter+1));                   //port 1-4 mapped to a-d
00603         strcat(out_buf,tempstring);
00604     }
00605     strcat(out_buf,"</tr></table></div>");
00606           
00607     strcat(out_buf, io_footer);                                         //copy footer to buffer
00608     
00609     #if defined debug
00610         printf("io page html length: %i \r\n",strlen(out_buf));
00611     #endif
00612     
00613     httpd->send(id, out_buf, strlen(out_buf), "Content-Type: text/html\r\n");   //send the constructed website
00614     
00615 }
00616 
00617 
00618 /*---------------------------------------------------------------------------*
00619  * Routine:  dynamic_analog_website
00620  *---------------------------------------------------------------------------*
00621  * Description:
00622  *      Generation and handling of the dynamic website for analog ports.
00623  * Inputs:
00624  *      int id                  -- httpd web handle
00625  * Outputs:
00626  *      "http"                  -- only output to web browser
00627  *---------------------------------------------------------------------------*/
00628 void dynamic_analog_website(int id){
00629     char out_buf[2000];                                                 //buffer for website output
00630     char query_buf[256];                                                //buffer to store 
00631     char tempstring[32];                                                //buffer for small string construction
00632     int counter = 0;                                                    //counter variable (multiple use)
00633     unsigned short analog_buf;                                          //buffer for analog values
00634     
00635     strcpy(query_buf, httpd->getQueryString(id));                       //copy transmitted parameters to query_buf
00636     strcpy(out_buf, io_header);                                         //initialize Website output
00637     
00638     io_webhandler_action(query_buf, strlen(query_buf));                 //handle transmitted parameters stored in query_buf
00639     
00640 
00641 
00642     strcpy(out_buf, analog_header);                                     //initialize Website output
00643     
00644     io_webhandler_action(query_buf, strlen(query_buf));                 //handle transmitted parameters
00645     
00646     /*create website in buffer*/
00647     strcat(out_buf,"<h1>Analog input</h1><div class=\"lf\"> <div class=\"block2\"><fieldset> ");
00648     strcat(out_buf, "<table class=\"form-table border-td\"><tr><th colspan=\"4\" class=\"center-align\">Analog Input</th></tr><tr class=\"center-align\"> <td>A1</td><td>A2</td><td>A3</td><td>A4</td></tr><tr class=\"center-align\">");
00649     
00650     /*read analog ports and create text for website*/
00651     for(counter = 1; counter <= 4; counter++){
00652         strcat(out_buf,"<th>");
00653         analog_buf = read_adc(ASCII_analog + char(counter));            //loop over all analog ports
00654         sprintf(tempstring,"%hu mv</th>",analog_buf);
00655         strcat(out_buf,tempstring);
00656     }
00657     strcat(out_buf,"</tr> </table></div>"); 
00658           
00659     strcat(out_buf, io_footer);                                         //copy footer to buffer
00660     
00661         #if defined debug
00662             printf("html length: %i \r\n",strlen(out_buf));
00663         #endif
00664     httpd->send(id, out_buf, strlen(out_buf), "Content-Type: text/html\r\n");   //send constructed website
00665     
00666 }
00667 
00668 
00669 
00670 /*---------------------------------------------------------------------------*
00671  * Routine:  io_webhandler_action
00672  *---------------------------------------------------------------------------*
00673  * Description:
00674  *      Routine to parse and handle http "get-requests" for dynamic
00675  *      generated websites.
00676  *
00677  *          eg. toggling output port 3: 
00678  *          http://mbed.ip/dynamic/websitename.htm?p30
00679  *          -> set port value of port 3 to 0
00680  *          
00681             eg. "o2" toggles output port 2
00682  *
00683  *      Supported Variables:
00684  *          o = toggle output port
00685  *          p = set bit to value
00686  *
00687  * Inputs:
00688  *      char* query_buf         -- pointer to string with http get request variables
00689  *      int query_buf_len       -- length of request string
00690  * Outputs:
00691  *      int                     -- port value (normally 0 or 1) 
00692  *                                  and in case of an error "-1"
00693  *---------------------------------------------------------------------------*/
00694 int io_webhandler_action(char *query_buf, int query_buf_len){
00695     char io_action = 0;                                                     //variables to store parameters
00696     char io_port = 0;
00697     char io_value = 0;
00698     
00699     #if defined debug
00700         printf ("io_webhandler - querystring: %s string-lenth: %i\r\n", query_buf, query_buf_len);
00701     #endif
00702     
00703     if (query_buf_len >= 3){                                                //evaluate io-action parameters
00704         sscanf(query_buf, "%c%c%c", &io_action, &io_port, &io_value);       //3 or more parameters
00705     }else if (query_buf_len == 2){                                          //2 parameters
00706         sscanf(query_buf, "%c%c", &io_action, &io_port);
00707     }
00708     
00709     #if defined debug
00710         printf("io_webhandler: evaluated http-params %c %c %c \r\n",io_action, io_port, io_value);
00711     #endif
00712     
00713     switch (io_action){
00714         case('o'): if (io_port != 0)return toggle_port(io_port);                                //toggle output port
00715         break;
00716         case('p'): if ((io_port != 0) && (io_value != 0)){return write_portval(io_port,0);}     //set output port value
00717         break;
00718     }   
00719     return -1;                                                              //return -1 if no valid action should be done
00720 }
00721 
00722 
00723 /* =================================================================== */
00724 /*      functions for hardware abstraction                             */
00725 /* =================================================================== */
00726 
00727 
00728 /* analog and digital ports are specified by ascii characters:
00729  *
00730  *   digital input 1 = a
00731  *   digital input 2 = b
00732  *   digital input 3 = c
00733  *   digital input 4 = d
00734  *   
00735  *   digital output 1 = 1
00736  *   digital output 2 = 2
00737  *   digital output 3 = 3
00738  *   digital output 4 = 4
00739  *
00740  * eg. read_portval("b") reads the value of the digital input port 2    
00741  */
00742 
00743 
00744 
00745 /*---------------------------------------------------------------------------*
00746  * Routine:  read_portval
00747  *---------------------------------------------------------------------------*
00748  * Description:
00749  *      Reads a value of an io-port and returns its value. (logically correct)
00750  * Inputs:
00751  *      char port_name          -- ascii character representing the port
00752  * Outputs:
00753  *      int                     -- port value (normally 0 or 1) 
00754  *                                  and in case of an error "-1"
00755  *---------------------------------------------------------------------------*/
00756 int read_portval(char port_name){
00757     switch (port_name){
00758         case (ASCII_out + 1): if(out1){ return 0;} else{ return 1;}
00759         case (ASCII_out + 2): if(out2){ return 0;} else{ return 1;}
00760         case (ASCII_out + 3): if(out3){ return 0;} else{ return 1;}
00761         case (ASCII_out + 4): if(out4){ return 0;} else{ return 1;}
00762         case (ASCII_out + 5): return relay1;
00763         case (ASCII_out + 6): return led1;
00764         case (ASCII_out + 7): return led2;
00765         case (ASCII_out + 8): return led3;
00766         case (ASCII_out + 9): return led4;
00767         case (ASCII_in + 0): if(in1){ return 0;} else{ return 1;}
00768         case (ASCII_in + 1): if(in2){ return 0;} else{ return 1;}
00769         case (ASCII_in + 2): if(in3){ return 0;} else{ return 1;}
00770         case (ASCII_in + 3): if(in4){ return 0;} else{ return 1;}
00771         }
00772     return -1;
00773 }
00774 
00775 //
00776 /*---------------------------------------------------------------------------*
00777  * Routine:  write_portval
00778  *---------------------------------------------------------------------------*
00779  * Description:
00780  *      Function to set output port values (handles inverted logic).
00781  * Inputs:
00782  *      char port_name          -- ascii character representing the port
00783  *      int port_val            -- output value
00784  * Outputs:
00785  *      int                     -- given port value (normally 0 or 1) 
00786  *                                  and in case of an error "-1"
00787  *---------------------------------------------------------------------------*/
00788 int write_portval(char port_name, int port_val){
00789     if (port_val > 1) return 0;                     //no analog/pwm signal output yet, only 0 and 1
00790     
00791         #if defined debug
00792             printf("function write_portval: port %c value %i \r\n",port_name, port_val);
00793         #endif
00794         
00795     switch (port_name){
00796         case (ASCII_out + 1): if(port_val){ out1 = 0; return 0;} else{ out1 = 1; return 1;}     //inverted output logic
00797         case (ASCII_out + 2): if(port_val){ out2 = 0; return 0;} else{ out2 = 1; return 1;}     //inverted output logic
00798         case (ASCII_out + 3): if(port_val){ out3 = 0; return 0;} else{ out3 = 1; return 1;}     //inverted output logic
00799         case (ASCII_out + 4): if(port_val){ out4 = 0; return 0;} else{ out4 = 1; return 1;}     //inverted output logic
00800         case (ASCII_out + 5): relay1 = port_val; return relay1;                                     //relay port
00801         case (ASCII_out + 6): led1 = port_val; return led1;
00802         case (ASCII_out + 7): led2 = port_val; return led2;
00803         case (ASCII_out + 8): led3 = port_val; return led3;
00804         case (ASCII_out + 9): led4 = port_val; return led4;
00805         }
00806     return -1; 
00807 }
00808 
00809 
00810 /*---------------------------------------------------------------------------*
00811  * Routine:  toggle_port
00812  *---------------------------------------------------------------------------*
00813  * Description:
00814  *      Function to toggle output ports.
00815  * Inputs:
00816  *      char port_name          -- ascii character representing the port
00817  * Outputs:
00818  *      int                     -- new port value (normally 0 or 1) 
00819  *                                  and in case of an error "-1"
00820  *---------------------------------------------------------------------------*/
00821 int toggle_port(char port_name){
00822         #if defined debug
00823             printf("function toggle_port: toggle port %c \r\n",port_name);
00824         #endif
00825     switch (port_name){
00826         case (ASCII_out + 1): out1 = !out1; return out1;
00827         case (ASCII_out + 2): out2 = !out2; return out2;
00828         case (ASCII_out + 3): out3 = !out3; return out3;
00829         case (ASCII_out + 4): out4 = !out4; return out4;
00830         case (ASCII_out + 5): relay1 = !relay1; return relay1;
00831         case (ASCII_out + 6): led1 = !led1; return led1;
00832         case (ASCII_out + 7): led2 = !led2; return led2;
00833         case (ASCII_out + 8): led3 = !led3; return led3;
00834         case (ASCII_out + 9): led4 = !led4; return led4;      
00835         }
00836     return -1; 
00837 }
00838 
00839 /*---------------------------------------------------------------------------*
00840  * Routine:  read_adc
00841  *---------------------------------------------------------------------------*
00842  * Description:
00843  *      Function to read the integrated adc-ports and calculate the input
00844  *       voltage in millivolts.
00845  *
00846  * Inputs:
00847  *      char port_name          -- ascii character representing the port
00848  * Outputs:
00849  *      unsigned short          -- input voltage in milivolt 
00850  *---------------------------------------------------------------------------*/
00851 unsigned short read_adc(char port_name){
00852     unsigned int adc_tempval = 0;                   //32 bit buffer for analog value
00853     
00854     /*read raw analog port value*/
00855     switch (port_name){
00856         case (ASCII_analog + 1): adc_tempval = ain1.read_u16();
00857         break;
00858         case (ASCII_analog + 2): adc_tempval = ain2.read_u16();
00859         break;
00860         case (ASCII_analog + 3): adc_tempval = ain3.read_u16();
00861         break;
00862         case (ASCII_analog + 4): adc_tempval = ain4.read_u16();
00863         break;
00864         default: return 0;
00865     }
00866         
00867     /*  calculate the analog input voltage (input voltage is divided by 3.5):
00868     
00869         The reference voltage of 3.3V (3300mV) is diveded into 2^16 steps.
00870         Result in millivolts: Vin_mbed = (3300 * ADC_Value)/65536
00871         mbedRail24v uses a voltage divider: Vin_mbedrail24v = Vin_mbed * 3,5
00872         -> Vin_mbedrail= (3300 * ADC_Value * 3,5)/65536
00873         an integer of 32 bit is required for the calculation, otherwise the multiplication would fail
00874     */
00875     
00876     adc_tempval *= 11550;                                   // ADC_Value * 3300 * 3,5
00877     adc_tempval /= 0xFFFF;                                  // divide by 65536 (0xFFFF)
00878     
00879     return (unsigned short)adc_tempval;                     //return the calculated value of an analog port in milivolt
00880 }