demonstration software for mbedRail24v board (mbed LPC1768)

Dependencies:   EthernetInterface Tiny-HTTPD mbed-rtos mbed

Committer:
kbed
Date:
Fri Aug 01 10:04:07 2014 +0000
Revision:
0:7b5e68d593c6
Child:
1:d4107c3853a6
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kbed 0:7b5e68d593c6 1 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 2 * mbed RAIL24V demo application
kbed 0:7b5e68d593c6 3 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 4 * Description:
kbed 0:7b5e68d593c6 5 * This program should demonstrate some features of the mbed RAIL24V Board
kbed 0:7b5e68d593c6 6 * and help to write own web applications for the LPC1768 mbed board.
kbed 0:7b5e68d593c6 7 *
kbed 0:7b5e68d593c6 8 * Features:
kbed 0:7b5e68d593c6 9 * * Webserver listening on port 80 with io port handling
kbed 0:7b5e68d593c6 10 * * RS232/RS485 echo
kbed 0:7b5e68d593c6 11 * * examples for interrupt and thread handling
kbed 0:7b5e68d593c6 12 *
kbed 0:7b5e68d593c6 13 * Debugging:
kbed 0:7b5e68d593c6 14 * * via "embedded" mbed USB->Serial Port (9600 Baud)
kbed 0:7b5e68d593c6 15 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 16 #include "mbed.h"
kbed 0:7b5e68d593c6 17 #include "EthernetInterface.h"
kbed 0:7b5e68d593c6 18 #include "HTTPD.h"
kbed 0:7b5e68d593c6 19
kbed 0:7b5e68d593c6 20
kbed 0:7b5e68d593c6 21 #define debug //enable debug output on virtual usb->com port
kbed 0:7b5e68d593c6 22 #define dhcp_disable //use user defined ip-address
kbed 0:7b5e68d593c6 23
kbed 0:7b5e68d593c6 24 /*----------------------------------------------------------------------------
kbed 0:7b5e68d593c6 25 * constants
kbed 0:7b5e68d593c6 26 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 27
kbed 0:7b5e68d593c6 28 /*content and length of "/dynamic/Elogo.gif"*/
kbed 0:7b5e68d593c6 29 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";
kbed 0:7b5e68d593c6 30 const int elogo_gif_len = 1686;
kbed 0:7b5e68d593c6 31 /*content and length of "/dynamic/bg.gif"*/
kbed 0:7b5e68d593c6 32 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\xBB\x0A\x77\xB8\x06\x74\xB7\xE3\xEF\xF7\xCB\xE2\xF0\x01\x72\xB5\xF0\xF7\xFB\x0F\x79\xB9\xF5\xF9\xFC\x20\x83\xBE\x25\x86\xC0\xFE\xFE\xFF\xD4\xE7\xF3\x09\x76\xB8\x11\x7A\xBA\x1C\x81\xBD\x08\x75\xB7\x19\x7F\xBC\xDA\xEA\xF4\x00\x59\x8F\x16\x7D\xBB\xF7\xFB\xFD\xFD\xFE\xFE\xE6\xF1\xF8\x04\x73\xB6\x75\xB2\xD7\x6C\xAD\xD4\x24\x85\xBF\xE1\xEE\xF6\x23\x84\xBF\x6B\xAD\xD4\xB2\xD4\xE9\x74\xB2\xD7\x8C\xBF\xDE\xE0\xEE\xF6\x3C\x92\xC6\x77\xB3\xD8\xC1\xDC\xED\x65\xA9\xD2\x02\x72\xB5\x6E\xAE\xD5\xB3\xD5\xE9\x61\xA7\xD1\x69\xAB\xD3\xCE\xE4\xF1\x9B\xC7\xE2\x57\xA1\xCE\x52\x9F\xCD\x58\xA2\xCF\x62\xA8\xD1\xA8\xCF\xE6\x7E\xB7\xDA\xC9\xE1\xEF\x82\xB9\xDB\x7B\xB5\xD9\xC0\xDC\xED\x00\x71\xB5\x98\xC6\xE1\x8B\xBE\xDD\x33\x8D\xC4\xBE\xDB\xEC\xCD\xE3\xF0\x72\xB0\xD6\x50\x9E\xCC\xBD\xDA\xEC\xBB\xD9\xEB\x45\x97\xC9\x7D\xB7\xD9\xCF\xE4\xF1\xA5\xCD\xE5\x9A\xC7\xE2\xAD\xD1\xE7\x4E\x9C\xCC\xA9\xCF\xE6\xAC\xD1\xE7\x59\xA3\xCF\xA4\xCC\xE5\x3D\x93\xC7\x4F\x9D\xCC\xEF\xF6\xFA\xD1\xE5\xF2\x06\x72\xB3\x56\xA1\xCE\xB5\xD6\xEA\x70\xAF\xD6\xC2\xDD\xED\xDB\xEB\xF5\x4C\x9B\xCB\x3F\x94\xC7\x9C\xC8\xE2\x7A\xB5\xD8\x22\x84\xBF\xA2\xCB\xE4\xB7\xD7\xEA\x2C\x8A\xC2\x09\x6E\xAB\xD2\xE6\xF2\x8A\xBE\xDD\x84\xBB\xDB\xC6\xDF\xEE\x1B\x80\xBD\x68\xAB\xD3\x43\x96\xC8\xB1\xD4\xE8\x6F\xAF\xD5\x6A\xAC\xD4\x73\xB1\xD6\x3B\x92\xC6\xD3\xE6\xF2\x31\x8C\xC3\x2D\x8A\xC2\x27\x87\xC0\xC4\xDE\xEE\xD7\xE9\xF3\x81\xB9\xDA\xAE\xD2\xE7\x08\x71\xB0\x7C\xB6\xD9\x88\xBD\xDC\x41\x95\xC8\xB6\xD6\xEA\x89\xBD\xDD\xBC\xDA\xEC\x90\xC1\xDF\xE5\xF1\xF7\x94\xC3\xE0\x63\xA8\xD2\x1E\x82\xBE\x1F\x82\xBE\x53\x9F\xCD\x93\xC3\xE0\x08\x6A\xA4\xE7\xF2\xF8\xE4\xF0\xF7\xEC\xF4\xF9\xB8\xD7\xEA\x21\x83\xBF\x06\x64\x9C\x40\x95\xC8\x4D\x9C\xCB\x5B\xA4\xCF\xD8\xE9\xF4\xD9\xEA\xF4\x38\x90\xC5\x39\x91\xC6\x3A\x91\xC6\x48\x99\xCA\xAF\xD2\xE8\xB4\xD5\xE9\x13\x7C\xBB\x0B\x77\xB8\x28\x87\xC1\x83\xBA\xDB\x17\x7E\xBC\xC3\xDE\xEE\x37\x90\xC5\x9F\xCA\xE3\x8F\xC1\xDE\x54\xA0\xCD\xED\xF5\xFA\x29\x88\xC1\x76\xB3\xD7\xA6\xCD\xE5\xA7\xCE\xE5\x1D\x81\xBD\x9D\xC8\xE3\xD0\xE5\xF1\xB0\xD3\xE8\xDE\xED\xF5\x67\xAA\xD3\x7F\xB8\xDA\x9E\xC9\xE3\x87\xBC\xDC\xEA\xF3\xF9\x99\xC6\xE1\x12\x7B\xBA\xF8\xFB\xFD\x36\x8F\xC5\x35\x8F\xC4\x1A\x7F\xBD\x55\xA0\xCE\xBF\xDB\xEC\x42\x96\xC8\x78\xB4\xD8\x96\xC5\xE1\xE8\xF2\xF8\x97\xC5\xE1\x85\xBB\xDC\x15\x7D\xBB\x2A\x88\xC1\x49\x9A\xCA\x07\x75\xB7\xCC\xE3\xF0\x71\xB0\xD6\x10\x7A\xBA\x03\x5E\x94\x5A\xA3\xCF\xF1\xF7\xFB\xB9\xD8\xEB\x51\x9E\xCD\xCA\xE1\xF0\x30\x8C\xC3\xA0\xCA\xE3\x47\x99\xCA\x0E\x79\xB9\xC5\xDF\xEE\xF4\xF9\xFC\xD5\xE8\xF3\xE2\xEF\xF7\x95\xC4\xE0\x32\x8D\xC4\x18\x7E\xBC\x8D\xC0\xDE\x5D\xA5\xD0\x5E\xA5\xD0\x5F\xA6\xD1\xC7\xE0\xEF\xC8\xE0\xEF\x8E\xC0\xDE\x3E\x94\xC7\x4A\x9A\xCA\x4B\x9B\xCB\xA1\xCB\xE4\x66\xAA\xD3\x2E\x8B\xC2\x2F\x8B\xC3\x64\xA9\xD2\x60\xA6\xD1\x46\x98\xC9\x26\x86\xC0\xBA\xD9\xEB\xD6\xE8\xF3\x80\xB8\xDA\x44\x97\xC9\x91\xC2\xDF\xAA\xD0\xE6\x21\xF9\x04\x00\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x02\x00\x7C\x02\x40\x08\xFF\x00\x4F\x9C\xD8\xB1\x83\x05\x0B\x12\x24\x1C\x38\x18\x36\xEC\xDC\xB9\x49\x93\x3C\x78\x98\x30\xE1\xC9\x93\x52\xA5\x94\x29\x83\x07\x6F\xC8\x10\x6C\xD8\x24\x49\x92\x21\x83\x06\x8D\x2B\x57\x9E\x3D\x73\xE7\xCE\x99\x33\x58\xB0\x8C\x18\xD9\xB5\x6B\xD3\xA6\x25\x4B\xDA\xB5\xC3\x82\x65\xDF\xBE\x00\x01\x2E\x5C\x88\x10\x61\xCC\x18\x71\xE2\x04\x08\x50\xA1\x02\x80\xD3\xA7\x50\xA3\x4A\x9D\x4A\xB5\xAA\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";
kbed 0:7b5e68d593c6 33 const int bg_gif_len = 1518;
kbed 0:7b5e68d593c6 34 /*content and lenght of "/dynamic/favicon.ico"*/
kbed 0:7b5e68d593c6 35 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";
kbed 0:7b5e68d593c6 36 const int favicon_ico_len = 318;
kbed 0:7b5e68d593c6 37
kbed 0:7b5e68d593c6 38 /*content of "/dynamic/Cstyle.css"*/
kbed 0:7b5e68d593c6 39 const char* const static_css =
kbed 0:7b5e68d593c6 40 "/* Main Style sheet for the ELZET80 */"
kbed 0:7b5e68d593c6 41 "body{font: 100% Arial,Helvetica,sans-serif; text-align: center; margin: 0; background: #FFF; color: #000;}"
kbed 0:7b5e68d593c6 42 "#container{width: 100%;}"
kbed 0:7b5e68d593c6 43 "#header{clear: both; width: 80%; min-width: 500px; margin: 0 auto; height:130px; padding: 10px 0 0; color:#999;}"
kbed 0:7b5e68d593c6 44 "#main-outer{float: left; clear: both; width: 100%;background: #FFF url(/dynamic/bg.gif) repeat-x;}"
kbed 0:7b5e68d593c6 45 "#main{clear: both; width: 90%; min-width: 500px; margin: 0 auto; text-align: left; padding: 0 10px;}"
kbed 0:7b5e68d593c6 46 "#footer{width: 100%; background: #BBB; clear:both; font-size: 10pt; color: #555;}"
kbed 0:7b5e68d593c6 47 "img{border: none;}"
kbed 0:7b5e68d593c6 48 ".left{float: left;}"
kbed 0:7b5e68d593c6 49 ".right{float: right;}"
kbed 0:7b5e68d593c6 50 ".left-align{text-align: left;}"
kbed 0:7b5e68d593c6 51 ".right-align{text-align: right;}"
kbed 0:7b5e68d593c6 52 ".center-align{text-align: center;}"
kbed 0:7b5e68d593c6 53 ".lf{clear: both; margin: 0; padding: 5px 0;}"
kbed 0:7b5e68d593c6 54 ".block1{float: left; display: block; width: 225px; padding: 0 10px; margin: 0 0 10px;}"
kbed 0:7b5e68d593c6 55 ".block2{float: left; display: block; width: 470px; padding: 0 10px; margin: 0 0 10px;}"
kbed 0:7b5e68d593c6 56 ".block100{float: left; display: block; width: 98%; padding: 0 1%; margin: 0 0 10px;}"
kbed 0:7b5e68d593c6 57 ".max750{max-width: 750px;}"
kbed 0:7b5e68d593c6 58 ".max850{max-width: 850px;}"
kbed 0:7b5e68d593c6 59 ".form-table{width: 100%; border: 1px solid #AAA; margin: 5px 0 0; text-align: left; border-collapse: collapse;}"
kbed 0:7b5e68d593c6 60 ".form-table tr td, .form-table tr th{padding: 5px;}"
kbed 0:7b5e68d593c6 61 ".margin-top-10{margin-top: 10px;}"
kbed 0:7b5e68d593c6 62 ".no-border{border: none;}"
kbed 0:7b5e68d593c6 63 ".border-td tr td, .border-td tr th{border: 1px solid #AAA;}"
kbed 0:7b5e68d593c6 64 "legend{font-weight: bold;}"
kbed 0:7b5e68d593c6 65 "#header #logo{float: left; display: block;}"
kbed 0:7b5e68d593c6 66 "#header #title{font-size: 18pt; float: left; margin: 15px 0 0 20px; display: block;}"
kbed 0:7b5e68d593c6 67 "#header #text{float: right; text-align: left; display: block;}"
kbed 0:7b5e68d593c6 68 "#menu-block{float: left; display: block; }"
kbed 0:7b5e68d593c6 69 "#home-page-img img{float: right; display: block; max-width: 300px;}"
kbed 0:7b5e68d593c6 70 "#main h1{float: left; clear: both; color: #FFF;}"
kbed 0:7b5e68d593c6 71 "#main h2{float: left; clear: both; color: #FFF; margin: -10px 0 10px; padding: 0;}"
kbed 0:7b5e68d593c6 72 "#menu{margin: 0;}"
kbed 0:7b5e68d593c6 73 "ul li{list-style-type: circle; padding: 3px;}"
kbed 0:7b5e68d593c6 74 "#footer p {margin: 0; padding: 10px 0 10px 15px;}"
kbed 0:7b5e68d593c6 75 "#footer a {color:#009898;}"
kbed 0:7b5e68d593c6 76 ".io-user-outputs td{text-align: center; font-weight: bold; font-size: 26px; padding: 5px 0; cursor: hand;}"
kbed 0:7b5e68d593c6 77 ".io-user-outputs td:hover{background: #CCC;}";
kbed 0:7b5e68d593c6 78
kbed 0:7b5e68d593c6 79
kbed 0:7b5e68d593c6 80 /*header-part of the dynamically generated analog-input website*/
kbed 0:7b5e68d593c6 81 const char* const analog_header =
kbed 0:7b5e68d593c6 82 "<html xmlns=\"http://www.w3.org/1999/xhtml\">"
kbed 0:7b5e68d593c6 83 "<head>"
kbed 0:7b5e68d593c6 84 "<title>Welcome to mbed\'s Web Page!</title>"
kbed 0:7b5e68d593c6 85 "<meta http-equiv=\"Content-Type\"content=\"no-cache\"content=\"text/html; charset=ISO-8859-1\" />"
kbed 0:7b5e68d593c6 86 "<link rel=\"shortcut icon\" href=\"/dynamic/favicon.ico\" />\n"
kbed 0:7b5e68d593c6 87 "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/dynamic/Cstyle.css\" />\n"
kbed 0:7b5e68d593c6 88 "</head>"
kbed 0:7b5e68d593c6 89 "<body>"
kbed 0:7b5e68d593c6 90 "<div id=\"container\">"
kbed 0:7b5e68d593c6 91 "<div id=\"header\">"
kbed 0:7b5e68d593c6 92 "<div id=\"logo\"><a href=/index.htm><img src=\"/dynamic/Elogo.gif\" alt=\"ELZET80\" title=\"Go to home page\" /></a></div>"
kbed 0:7b5e68d593c6 93 "<div id=\"title\">Welcome Elzet 80 mbedRail24v Demo</div>"
kbed 0:7b5e68d593c6 94 "<div id=\"text\">"
kbed 0:7b5e68d593c6 95 "<p>Running ELZET80 mbed demo</p>"
kbed 0:7b5e68d593c6 96 "</div>"
kbed 0:7b5e68d593c6 97 "</div>"
kbed 0:7b5e68d593c6 98 "<div id=\"main-outer\">"
kbed 0:7b5e68d593c6 99 "<div id=\"main\">";
kbed 0:7b5e68d593c6 100
kbed 0:7b5e68d593c6 101 /*header-part of the dynamic generated io website*/
kbed 0:7b5e68d593c6 102 const char* const io_header =
kbed 0:7b5e68d593c6 103 "<html xmlns=\"http://www.w3.org/1999/xhtml\">"
kbed 0:7b5e68d593c6 104 "<head>"
kbed 0:7b5e68d593c6 105 "<title>Welcome to mbed\'s Web Page!</title>"
kbed 0:7b5e68d593c6 106 "<meta http-equiv=\"Content-Type\"content=\"no-cache\"content=\"text/html; charset=ISO-8859-1\" />"
kbed 0:7b5e68d593c6 107 "<link rel=\"shortcut icon\" href=\"/dynamic/favicon.ico\" />\n"
kbed 0:7b5e68d593c6 108 "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/dynamic/Cstyle.css\" />\n"
kbed 0:7b5e68d593c6 109 "<script type=\"text/javascript\">\n"
kbed 0:7b5e68d593c6 110 "function key(id){\n"
kbed 0:7b5e68d593c6 111 "var out=\"io.htm?o\"+id;location.href=out}\n"
kbed 0:7b5e68d593c6 112 "</script>\n"
kbed 0:7b5e68d593c6 113 "</head>"
kbed 0:7b5e68d593c6 114 "<body>"
kbed 0:7b5e68d593c6 115 "<div id=\"container\">"
kbed 0:7b5e68d593c6 116 "<div id=\"header\">"
kbed 0:7b5e68d593c6 117 "<div id=\"logo\"><a href=/index.htm><img src=\"/dynamic/Elogo.gif\" alt=\"ELZET80\" title=\"Go to home page\" /></a></div>"
kbed 0:7b5e68d593c6 118 "<div id=\"title\">Welcome Elzet 80 mbedRail24v Demo</div>"
kbed 0:7b5e68d593c6 119 "<div id=\"text\">"
kbed 0:7b5e68d593c6 120 "<p>Running ELZET80 mbed demo</p>"
kbed 0:7b5e68d593c6 121 "</div>"
kbed 0:7b5e68d593c6 122 "</div>"
kbed 0:7b5e68d593c6 123 "<div id=\"main-outer\">"
kbed 0:7b5e68d593c6 124 "<div id=\"main\">";
kbed 0:7b5e68d593c6 125
kbed 0:7b5e68d593c6 126 /*footer of the dynamic generatred analog and io webpages*/
kbed 0:7b5e68d593c6 127 const char* const io_footer=
kbed 0:7b5e68d593c6 128 "</div>"
kbed 0:7b5e68d593c6 129 "</div>"
kbed 0:7b5e68d593c6 130 "</div>"
kbed 0:7b5e68d593c6 131 "<div id=\"footer\">"
kbed 0:7b5e68d593c6 132 "<p>&copy; 2012 &nbsp; ELZET80 Mikrocomputer GmbH&Co. KG &bull; Aachen &bull; <a href=\"http://www.elzet80.de\">www.elzet80.de</a></p>"
kbed 0:7b5e68d593c6 133 "</div>"
kbed 0:7b5e68d593c6 134 "</div>"
kbed 0:7b5e68d593c6 135 "</body>"
kbed 0:7b5e68d593c6 136 "</html>";
kbed 0:7b5e68d593c6 137
kbed 0:7b5e68d593c6 138 /*content of index.html*/
kbed 0:7b5e68d593c6 139 const char* const index_html =
kbed 0:7b5e68d593c6 140 "<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n"
kbed 0:7b5e68d593c6 141 "<head>\r\n"
kbed 0:7b5e68d593c6 142 "<title>Welcome to mbed\'s Web Page!</title>\r\n"
kbed 0:7b5e68d593c6 143 "<meta http-equiv=\"Content-Type\"content=\"no-cache\"content=\"text/html; charset=ISO-8859-1\" />\r\n"
kbed 0:7b5e68d593c6 144 "<link rel=\"shortcut icon\" href=\"/dynamic/favicon.ico\" />\r\n"
kbed 0:7b5e68d593c6 145 "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/dynamic/Cstyle.css\" />\r\n"
kbed 0:7b5e68d593c6 146 "</head>\r\n"
kbed 0:7b5e68d593c6 147 "<body>\r\n"
kbed 0:7b5e68d593c6 148 "\r\n"
kbed 0:7b5e68d593c6 149 "<div id=\"container\">\r\n"
kbed 0:7b5e68d593c6 150 "\r\n"
kbed 0:7b5e68d593c6 151 "<div id=\"header\">\r\n"
kbed 0:7b5e68d593c6 152 "<div id=\"logo\"><img src=\"/dynamic/Elogo.gif\" alt=\"ELZET80\" title=\"Home page\" /></div>\r\n"
kbed 0:7b5e68d593c6 153 "<div id=\"title\">Welcome Elzet 80 mbedRail24v Demo</div>\r\n"
kbed 0:7b5e68d593c6 154 "<div id=\"text\">\r\n"
kbed 0:7b5e68d593c6 155 "<p>Running ELZET80 mbed demo</p>\r\n"
kbed 0:7b5e68d593c6 156 "</div>\r\n"
kbed 0:7b5e68d593c6 157 "</div>\r\n"
kbed 0:7b5e68d593c6 158 "\r\n"
kbed 0:7b5e68d593c6 159 "<div id=\"main-outer\">\r\n"
kbed 0:7b5e68d593c6 160 "<div id=\"main\">\r\n"
kbed 0:7b5e68d593c6 161 "<h1>Main menu </h1>\r\n"
kbed 0:7b5e68d593c6 162 "<div class=\"lf\">\r\n"
kbed 0:7b5e68d593c6 163 "<div id=\"menu-block\">\r\n"
kbed 0:7b5e68d593c6 164 "<ul id=\"menu\">\r\n"
kbed 0:7b5e68d593c6 165 "<li><a href=\"/dynamic/io.htm\">Digital I/O Page</a></li>\r\n"
kbed 0:7b5e68d593c6 166 "<li><a href=\"/dynamic/analog.htm\">Analog Input Page</a></li>\r\n"
kbed 0:7b5e68d593c6 167 "</ul>\r\n"
kbed 0:7b5e68d593c6 168 "</br>\r\n"
kbed 0:7b5e68d593c6 169 "</div>\r\n"
kbed 0:7b5e68d593c6 170 "</div>\r\n"
kbed 0:7b5e68d593c6 171 "</div>\r\n"
kbed 0:7b5e68d593c6 172 "</div>\r\n"
kbed 0:7b5e68d593c6 173 "\r\n"
kbed 0:7b5e68d593c6 174 "<div id=\"footer\">\r\n"
kbed 0:7b5e68d593c6 175 "<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"
kbed 0:7b5e68d593c6 176 "</div>\r\n"
kbed 0:7b5e68d593c6 177 "\r\n"
kbed 0:7b5e68d593c6 178 "</div>\r\n"
kbed 0:7b5e68d593c6 179 "\r\n"
kbed 0:7b5e68d593c6 180 "</body>\r\n"
kbed 0:7b5e68d593c6 181 "</html>";
kbed 0:7b5e68d593c6 182
kbed 0:7b5e68d593c6 183 /*definition of constants for hardware abstraction (enables compatibility to "ELZET80 kbed uTasker Platform")*/
kbed 0:7b5e68d593c6 184 const char ASCII_out = '0'; // 0-9 for output ports
kbed 0:7b5e68d593c6 185 const char ASCII_in = 'a'; // a-f for input ports
kbed 0:7b5e68d593c6 186 const char ASCII_analog = '0'; // 0-9 for analog input
kbed 0:7b5e68d593c6 187
kbed 0:7b5e68d593c6 188
kbed 0:7b5e68d593c6 189
kbed 0:7b5e68d593c6 190 /*----------------------------------------------------------------------------
kbed 0:7b5e68d593c6 191 * io functions
kbed 0:7b5e68d593c6 192 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 193
kbed 0:7b5e68d593c6 194 /*assign mbed Rail24V io-ports to LPC1768 io ports*/
kbed 0:7b5e68d593c6 195
kbed 0:7b5e68d593c6 196 /*ASCII-characters are only relevant for use with http handling routines*/
kbed 0:7b5e68d593c6 197 DigitalOut out1(p23, 1); //Output 1 --> ASCII "1"
kbed 0:7b5e68d593c6 198 DigitalOut out2(p24, 1); //Output 2 --> ASCII "2"
kbed 0:7b5e68d593c6 199 DigitalOut out3(p25, 1); //Output 3 --> ASCII "3"
kbed 0:7b5e68d593c6 200 DigitalOut out4(p26, 1); //Output 4 --> ASCII "4"
kbed 0:7b5e68d593c6 201 DigitalOut relay1(p22, 0); //Relais --> ASCII "5"
kbed 0:7b5e68d593c6 202 DigitalOut led1(LED1, 0); //MBED led1 - activated in "boot sequence" // blink: led1 (by timer-interrupt ticker)
kbed 0:7b5e68d593c6 203 DigitalOut led2(LED2, 0); //MBED led2 - activated in "boot sequence" // blink: led2 (by led2_thread)
kbed 0:7b5e68d593c6 204 DigitalOut led3(LED3, 0); //Mbed led3
kbed 0:7b5e68d593c6 205 DigitalOut led4(LED4, 0); //MBED led4
kbed 0:7b5e68d593c6 206 DigitalIn in1(p19); //Input 1 --> ASCII "a"
kbed 0:7b5e68d593c6 207 DigitalIn in2(p20); //Input 2 --> ASCII "b"
kbed 0:7b5e68d593c6 208 DigitalIn in3(p11); //Input 3 --> ASCII "c"
kbed 0:7b5e68d593c6 209 DigitalIn in4(p12); //Input 4 --> ASCII "d"
kbed 0:7b5e68d593c6 210 AnalogIn ain1(p15); //Analog Input 1 --> ASCII "1"
kbed 0:7b5e68d593c6 211 AnalogIn ain2(p16); //Analog Input 2 --> ASCII "2"
kbed 0:7b5e68d593c6 212 AnalogIn ain3(p17); //Analog Input 3 --> ASCII "3"
kbed 0:7b5e68d593c6 213 AnalogIn ain4(p18); //Analog Input 4 --> ASCII "4"
kbed 0:7b5e68d593c6 214
kbed 0:7b5e68d593c6 215
kbed 0:7b5e68d593c6 216 DigitalOut rs485_txmode(p21, 0); //RS485 - enable receiver (Port 21: 0 recieve mode / 1 transmit mode)
kbed 0:7b5e68d593c6 217
kbed 0:7b5e68d593c6 218 //Serial interfaces
kbed 0:7b5e68d593c6 219 //Pins UART
kbed 0:7b5e68d593c6 220 //USBTX,USBRX 0
kbed 0:7b5e68d593c6 221 //p13,p14 1
kbed 0:7b5e68d593c6 222 //p28,p27 2
kbed 0:7b5e68d593c6 223 //p9,p10 3
kbed 0:7b5e68d593c6 224
kbed 0:7b5e68d593c6 225 RawSerial rs232(p9, p10); // tx, rx -- rawserial is used for compatibility with interrupt routines
kbed 0:7b5e68d593c6 226 RawSerial rs485(p13, p14); // tx, rx
kbed 0:7b5e68d593c6 227
kbed 0:7b5e68d593c6 228
kbed 0:7b5e68d593c6 229 LocalFileSystem local("local"); //initialize the local file system
kbed 0:7b5e68d593c6 230
kbed 0:7b5e68d593c6 231 Ticker interruptTick; //create a timer
kbed 0:7b5e68d593c6 232
kbed 0:7b5e68d593c6 233 /*httpd*/
kbed 0:7b5e68d593c6 234 HTTPD *httpd; //initialize the httpd-webserver
kbed 0:7b5e68d593c6 235
kbed 0:7b5e68d593c6 236
kbed 0:7b5e68d593c6 237 /*----------------------------------------------------------------------------
kbed 0:7b5e68d593c6 238 * functions
kbed 0:7b5e68d593c6 239 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 240
kbed 0:7b5e68d593c6 241
kbed 0:7b5e68d593c6 242 void index_website_handler (int id);
kbed 0:7b5e68d593c6 243 void dynamic_website_handler (int id);
kbed 0:7b5e68d593c6 244
kbed 0:7b5e68d593c6 245 void dynamic_IO_website(int id);
kbed 0:7b5e68d593c6 246 void dynamic_analog_website(int id);
kbed 0:7b5e68d593c6 247
kbed 0:7b5e68d593c6 248 int io_webhandler_action(char *input_buf, int input_puf_len);
kbed 0:7b5e68d593c6 249
kbed 0:7b5e68d593c6 250 unsigned short read_adc(char port_name);
kbed 0:7b5e68d593c6 251 int read_portval(char port_name);
kbed 0:7b5e68d593c6 252 int write_portval(char port_name, int port_val);
kbed 0:7b5e68d593c6 253 int toggle_port(char port_name);
kbed 0:7b5e68d593c6 254
kbed 0:7b5e68d593c6 255
kbed 0:7b5e68d593c6 256
kbed 0:7b5e68d593c6 257 /*----------------------------------------------------------------------------
kbed 0:7b5e68d593c6 258 * interrupt and thread functions
kbed 0:7b5e68d593c6 259 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 260
kbed 0:7b5e68d593c6 261
kbed 0:7b5e68d593c6 262 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 263 * Routine: echoRS232 (interrupt)
kbed 0:7b5e68d593c6 264 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 265 * Description:
kbed 0:7b5e68d593c6 266 *
kbed 0:7b5e68d593c6 267 * Toggle LED3 to indicate RS232 activity.
kbed 0:7b5e68d593c6 268 * Read a char from the rs232 input port to a buffer and
kbed 0:7b5e68d593c6 269 * send the char to rs232 port.
kbed 0:7b5e68d593c6 270 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 271 void echoRS232() {
kbed 0:7b5e68d593c6 272 char rs232_buffer = 0; //local buffer
kbed 0:7b5e68d593c6 273
kbed 0:7b5e68d593c6 274 led3 = !led3; //toggle LED3
kbed 0:7b5e68d593c6 275
kbed 0:7b5e68d593c6 276 /*read rs232 buffer and write the result back to rs232 interface*/
kbed 0:7b5e68d593c6 277 if (rs232.readable()){ //avoid hanging up the program in case of multiple use of rs232
kbed 0:7b5e68d593c6 278
kbed 0:7b5e68d593c6 279 rs232_buffer = rs232.getc(); //read input to buffer
kbed 0:7b5e68d593c6 280
kbed 0:7b5e68d593c6 281 if (rs232.writeable()){
kbed 0:7b5e68d593c6 282 rs232.putc(rs232_buffer); //write buffer to rs232 output
kbed 0:7b5e68d593c6 283 }
kbed 0:7b5e68d593c6 284 }
kbed 0:7b5e68d593c6 285 return;
kbed 0:7b5e68d593c6 286 }
kbed 0:7b5e68d593c6 287
kbed 0:7b5e68d593c6 288 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 289 * Routine: echoRS485 (interrupt)
kbed 0:7b5e68d593c6 290 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 291 * Description:
kbed 0:7b5e68d593c6 292 * Toggle LED3 to indicate RS485 activity.
kbed 0:7b5e68d593c6 293 * Read a char from the RS485 input port to a buffer, switch RS485 port
kbed 0:7b5e68d593c6 294 * to transmission mode and send the buffered char to RS485 port.
kbed 0:7b5e68d593c6 295 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 296 void echoRS485() {
kbed 0:7b5e68d593c6 297 char rs485_buffer = 0; //local buffer
kbed 0:7b5e68d593c6 298
kbed 0:7b5e68d593c6 299 led3 = !led3; //toggle LED
kbed 0:7b5e68d593c6 300
kbed 0:7b5e68d593c6 301 rs485_txmode = 1; //enable RS485 transmission mode
kbed 0:7b5e68d593c6 302
kbed 0:7b5e68d593c6 303 //read rs485 inpuf buffer and write the result back to rs485 interfacee
kbed 0:7b5e68d593c6 304 if (rs485.readable()){
kbed 0:7b5e68d593c6 305
kbed 0:7b5e68d593c6 306 rs485_buffer = rs485.getc();
kbed 0:7b5e68d593c6 307
kbed 0:7b5e68d593c6 308 if (rs485.writeable()){
kbed 0:7b5e68d593c6 309 rs485.putc(rs485_buffer);
kbed 0:7b5e68d593c6 310 }
kbed 0:7b5e68d593c6 311 }
kbed 0:7b5e68d593c6 312 }
kbed 0:7b5e68d593c6 313
kbed 0:7b5e68d593c6 314 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 315 * Routine: enableRS485receiver (interrupt)
kbed 0:7b5e68d593c6 316 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 317 * Description:
kbed 0:7b5e68d593c6 318 * Disable RS485 transmission mode. (TxIRQ -> tx buffer empty)
kbed 0:7b5e68d593c6 319 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 320 void enableRS485receiver() {
kbed 0:7b5e68d593c6 321 rs485_txmode = 0; //disable RS485 transmission mode
kbed 0:7b5e68d593c6 322 }
kbed 0:7b5e68d593c6 323
kbed 0:7b5e68d593c6 324
kbed 0:7b5e68d593c6 325 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 326 * Routine: interruptTickRoutine
kbed 0:7b5e68d593c6 327 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 328 * Description:
kbed 0:7b5e68d593c6 329 * Toggle LED1.
kbed 0:7b5e68d593c6 330 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 331 void interruptTickRoutine() {
kbed 0:7b5e68d593c6 332 led1 = !led1;
kbed 0:7b5e68d593c6 333 return;
kbed 0:7b5e68d593c6 334 }
kbed 0:7b5e68d593c6 335
kbed 0:7b5e68d593c6 336
kbed 0:7b5e68d593c6 337 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 338 * Routine: led2_thread
kbed 0:7b5e68d593c6 339 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 340 * Description:
kbed 0:7b5e68d593c6 341 * Example for a thread. Toggle LED2 and sleep 1000ms.
kbed 0:7b5e68d593c6 342 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 343 void led2_thread(void const *args) {
kbed 0:7b5e68d593c6 344 while (true) {
kbed 0:7b5e68d593c6 345 led2 = !led2;
kbed 0:7b5e68d593c6 346 Thread::wait(1000);
kbed 0:7b5e68d593c6 347 }
kbed 0:7b5e68d593c6 348 }
kbed 0:7b5e68d593c6 349
kbed 0:7b5e68d593c6 350
kbed 0:7b5e68d593c6 351
kbed 0:7b5e68d593c6 352
kbed 0:7b5e68d593c6 353
kbed 0:7b5e68d593c6 354
kbed 0:7b5e68d593c6 355
kbed 0:7b5e68d593c6 356 /*----------------------------------------------------------------------------
kbed 0:7b5e68d593c6 357 * main ()
kbed 0:7b5e68d593c6 358 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 359 int main() {
kbed 0:7b5e68d593c6 360
kbed 0:7b5e68d593c6 361 #if defined debug
kbed 0:7b5e68d593c6 362 printf("Welcome to ELZET80 mbed demo\r\n"); //print debug Informations to LPC1768 USB-Comport (9600 baud)
kbed 0:7b5e68d593c6 363 #endif
kbed 0:7b5e68d593c6 364
kbed 0:7b5e68d593c6 365 /*Example to write a file to the local filesystem:
kbed 0:7b5e68d593c6 366
kbed 0:7b5e68d593c6 367 FILE *fp = fopen("/local/helloworld.txt", "w"); // Open "helloworld.txt" on the local file system for writing
kbed 0:7b5e68d593c6 368 fprintf(fp, "Hello World!");
kbed 0:7b5e68d593c6 369 fclose(fp);
kbed 0:7b5e68d593c6 370 */
kbed 0:7b5e68d593c6 371
kbed 0:7b5e68d593c6 372 led1=1; //enable status led1
kbed 0:7b5e68d593c6 373
kbed 0:7b5e68d593c6 374 /*Ethernet initialisation - the demo would not start without an ethernet connection*/
kbed 0:7b5e68d593c6 375 EthernetInterface eth;
kbed 0:7b5e68d593c6 376
kbed 0:7b5e68d593c6 377 #if defined dhcp_disable
kbed 0:7b5e68d593c6 378 static const char* netIP = "192.168.17.73";
kbed 0:7b5e68d593c6 379 static const char* netMask = "255.255.255.0";
kbed 0:7b5e68d593c6 380 static const char* netGateway = "192.168.17.73";
kbed 0:7b5e68d593c6 381 eth.init(netIP,netMask,netGateway); //use userpecific IP, Netmask and Gateway
kbed 0:7b5e68d593c6 382 #else
kbed 0:7b5e68d593c6 383 eth.init(); //use DHCP client function
kbed 0:7b5e68d593c6 384 #endif
kbed 0:7b5e68d593c6 385
kbed 0:7b5e68d593c6 386 #if defined debug
kbed 0:7b5e68d593c6 387 printf("starting Ethernet Interface setup\r\n");
kbed 0:7b5e68d593c6 388 #endif
kbed 0:7b5e68d593c6 389
kbed 0:7b5e68d593c6 390 int ethError; //Ethernet error buffer
kbed 0:7b5e68d593c6 391
kbed 0:7b5e68d593c6 392 /*start ethernet connection*/
kbed 0:7b5e68d593c6 393 do{
kbed 0:7b5e68d593c6 394 ethError = eth.connect(5000); //connect to network with 5s (5000ms) timout
kbed 0:7b5e68d593c6 395 #if defined debug
kbed 0:7b5e68d593c6 396 if(ethError)printf("Error %d occurrenced \r\n", ethError);
kbed 0:7b5e68d593c6 397 #endif
kbed 0:7b5e68d593c6 398 wait(1);
kbed 0:7b5e68d593c6 399 }while(ethError != 0); //wait until a network connection was established
kbed 0:7b5e68d593c6 400
kbed 0:7b5e68d593c6 401
kbed 0:7b5e68d593c6 402 led2 = 1; //set status led2
kbed 0:7b5e68d593c6 403
kbed 0:7b5e68d593c6 404 #if defined debug
kbed 0:7b5e68d593c6 405 printf("\r\nEthernet Interface setup finished. IP: %s\r\n", eth.getIPAddress());
kbed 0:7b5e68d593c6 406 printf("enabling RS232/RS485 echo mode ... \r\n");
kbed 0:7b5e68d593c6 407 #endif
kbed 0:7b5e68d593c6 408
kbed 0:7b5e68d593c6 409
kbed 0:7b5e68d593c6 410 /*init serial ports*/
kbed 0:7b5e68d593c6 411 rs232.baud(9600); //set rs232 baudrate to 9600
kbed 0:7b5e68d593c6 412 rs232.printf("Enabled RS232 port - starting echo mode \r\n");
kbed 0:7b5e68d593c6 413 rs232.attach(&echoRS232,Serial::RxIrq); //attach the rs232 echo function to rs232 rx interrupt
kbed 0:7b5e68d593c6 414
kbed 0:7b5e68d593c6 415 rs485.attach(&enableRS485receiver,Serial::TxIrq); //enable automatic rx/tx switching (tx-buffer empty interrupt)
kbed 0:7b5e68d593c6 416 rs485_txmode = 1; //enable RS485 transmission mode
kbed 0:7b5e68d593c6 417 rs485.baud(9600); //set rs485 baudrate to 9600 baud
kbed 0:7b5e68d593c6 418 rs485.printf("Enabled RS485 port - starting echo mode \r\n");
kbed 0:7b5e68d593c6 419 rs485.attach(&echoRS485,Serial::RxIrq); //enable echo mode via RS485 echo routine
kbed 0:7b5e68d593c6 420
kbed 0:7b5e68d593c6 421
kbed 0:7b5e68d593c6 422 httpd = new HTTPD;
kbed 0:7b5e68d593c6 423 httpd->attach("/dynamic/", &dynamic_website_handler); //use the function "dynamic_website_handler" for handling the dynamic websites
kbed 0:7b5e68d593c6 424 //initialize all virtual directories before the root directory
kbed 0:7b5e68d593c6 425 httpd->attach("/flash/", "/local/"); //attach the flash storage ("local") to http://mbed.ip/flash/ -- currently the flash file system handler could not handle subdirectories!
kbed 0:7b5e68d593c6 426
kbed 0:7b5e68d593c6 427 httpd->attach("/", &index_website_handler); //index.html
kbed 0:7b5e68d593c6 428
kbed 0:7b5e68d593c6 429
kbed 0:7b5e68d593c6 430 httpd->start(80); //httpd on port 80
kbed 0:7b5e68d593c6 431
kbed 0:7b5e68d593c6 432
kbed 0:7b5e68d593c6 433 #if defined debug
kbed 0:7b5e68d593c6 434 printf("Webserver started.\r\n");
kbed 0:7b5e68d593c6 435 #endif
kbed 0:7b5e68d593c6 436
kbed 0:7b5e68d593c6 437
kbed 0:7b5e68d593c6 438 #if defined debug
kbed 0:7b5e68d593c6 439 printf("enabling Ticker for led1 and Thread for led2 \r\n");
kbed 0:7b5e68d593c6 440 #endif
kbed 0:7b5e68d593c6 441
kbed 0:7b5e68d593c6 442 interruptTick.attach(&interruptTickRoutine,0.5); //enabling Ticker for timer interrupt triggered subroutine (.5s periodic toggling of led1)
kbed 0:7b5e68d593c6 443
kbed 0:7b5e68d593c6 444
kbed 0:7b5e68d593c6 445 Thread led2Thread(led2_thread, NULL, osPriorityNormal, 1024 * 4); //create a separate thread
kbed 0:7b5e68d593c6 446
kbed 0:7b5e68d593c6 447 //endless loop - "httpd-thread"
kbed 0:7b5e68d593c6 448 while(1){
kbed 0:7b5e68d593c6 449 Thread::wait(5); //wait 5 ms
kbed 0:7b5e68d593c6 450
kbed 0:7b5e68d593c6 451
kbed 0:7b5e68d593c6 452 /*handle waiting http requests*/
kbed 0:7b5e68d593c6 453 /* the program waits here until a request was made and answered*/
kbed 0:7b5e68d593c6 454
kbed 0:7b5e68d593c6 455 httpd->poll(); //poll httpd for incoming requests
kbed 0:7b5e68d593c6 456
kbed 0:7b5e68d593c6 457 led3 = !led3; //toogle led3 (indicate that a http request was handled)
kbed 0:7b5e68d593c6 458
kbed 0:7b5e68d593c6 459 }
kbed 0:7b5e68d593c6 460 }
kbed 0:7b5e68d593c6 461 /* end of main() */
kbed 0:7b5e68d593c6 462
kbed 0:7b5e68d593c6 463
kbed 0:7b5e68d593c6 464
kbed 0:7b5e68d593c6 465
kbed 0:7b5e68d593c6 466
kbed 0:7b5e68d593c6 467 /*----------------------------------------------------------------------------
kbed 0:7b5e68d593c6 468 * website handling functions
kbed 0:7b5e68d593c6 469 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 470
kbed 0:7b5e68d593c6 471
kbed 0:7b5e68d593c6 472 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 473 * Routine: dynamic_website_handler
kbed 0:7b5e68d593c6 474 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 475 * Description:
kbed 0:7b5e68d593c6 476 * Website hander for handling requests of "http://mbed.ip/ *** ".
kbed 0:7b5e68d593c6 477 *
kbed 0:7b5e68d593c6 478 * Inputs:
kbed 0:7b5e68d593c6 479 * int id -- number of httpd web handler
kbed 0:7b5e68d593c6 480 * Outputs:
kbed 0:7b5e68d593c6 481 * none -- only output to web browser
kbed 0:7b5e68d593c6 482 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 483 void index_website_handler (int id) {
kbed 0:7b5e68d593c6 484 char input_buf[256]; //create an input buffer
kbed 0:7b5e68d593c6 485
kbed 0:7b5e68d593c6 486 strcpy(input_buf, httpd->getFilename(id)); //copy requested file name to buffer
kbed 0:7b5e68d593c6 487
kbed 0:7b5e68d593c6 488 #if defined debug
kbed 0:7b5e68d593c6 489 printf("index website handler -- handler-id:%d reqested file:%s\r\n", id, input_buf);
kbed 0:7b5e68d593c6 490 #endif
kbed 0:7b5e68d593c6 491
kbed 0:7b5e68d593c6 492 httpd->send(id, index_html, strlen(index_html), "Content-Type: text/html\r\n"); //transmit content of "index_html" to browser
kbed 0:7b5e68d593c6 493
kbed 0:7b5e68d593c6 494 }
kbed 0:7b5e68d593c6 495
kbed 0:7b5e68d593c6 496
kbed 0:7b5e68d593c6 497 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 498 * Routine: dynamic_website_handler
kbed 0:7b5e68d593c6 499 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 500 * Description:
kbed 0:7b5e68d593c6 501 * Website hander for handling requests of "http://mbed.ip/dynamic/ *** ".
kbed 0:7b5e68d593c6 502 * Inputs:
kbed 0:7b5e68d593c6 503 * int id -- number of httpd web handler
kbed 0:7b5e68d593c6 504 * Outputs:
kbed 0:7b5e68d593c6 505 * "http" -- output to web browser
kbed 0:7b5e68d593c6 506 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 507 void dynamic_website_handler (int id) {
kbed 0:7b5e68d593c6 508 char input_buf[256]; //buffer for request parameters
kbed 0:7b5e68d593c6 509
kbed 0:7b5e68d593c6 510 strcpy(input_buf, httpd->getFilename(id)); //copy request to buffer
kbed 0:7b5e68d593c6 511
kbed 0:7b5e68d593c6 512 #if defined debug
kbed 0:7b5e68d593c6 513 printf("dynamic website handler -- handler-id:%d reqested file:%s\r\n", id, input_buf);
kbed 0:7b5e68d593c6 514 #endif
kbed 0:7b5e68d593c6 515
kbed 0:7b5e68d593c6 516 /*process the request*/
kbed 0:7b5e68d593c6 517 if(strcmp (input_buf, "Elogo.gif") == 0) {
kbed 0:7b5e68d593c6 518 httpd->send(id, elogo_gif, elogo_gif_len, "Content-Type: image/gif\r\n");
kbed 0:7b5e68d593c6 519 } else if(strcmp (input_buf, "bg.gif") == 0) {
kbed 0:7b5e68d593c6 520 httpd->send(id, bg_gif, bg_gif_len, "Content-Type: image/gif\r\n");
kbed 0:7b5e68d593c6 521 } else if(strcmp (input_buf, "Cstyle.css") == 0) {
kbed 0:7b5e68d593c6 522 httpd->send(id, static_css, strlen(static_css), "Content-Type: text/html\r\n");
kbed 0:7b5e68d593c6 523 } else if(strcmp (input_buf, "favicon.ico") == 0) {
kbed 0:7b5e68d593c6 524 httpd->send(id, favicon_ico, favicon_ico_len, "Content-Type: image/x-icon\r\n");
kbed 0:7b5e68d593c6 525 } else if (strcmp(input_buf, "io.htm") == 0){
kbed 0:7b5e68d593c6 526 dynamic_IO_website(id);
kbed 0:7b5e68d593c6 527 } else if(strcmp (input_buf, "analog.htm") == 0) {
kbed 0:7b5e68d593c6 528 dynamic_analog_website(id);
kbed 0:7b5e68d593c6 529 } else{
kbed 0:7b5e68d593c6 530 httpd->httpdError(id, 404);
kbed 0:7b5e68d593c6 531 }
kbed 0:7b5e68d593c6 532 }
kbed 0:7b5e68d593c6 533
kbed 0:7b5e68d593c6 534
kbed 0:7b5e68d593c6 535 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 536 * Routine: dynamic_analog_website
kbed 0:7b5e68d593c6 537 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 538 * Description:
kbed 0:7b5e68d593c6 539 * Generation and handling of the dynamic website for digital ports.
kbed 0:7b5e68d593c6 540 * Inputs:
kbed 0:7b5e68d593c6 541 * int id -- number of httpd web handler
kbed 0:7b5e68d593c6 542 * Outputs:
kbed 0:7b5e68d593c6 543 * "http" -- output to web browser
kbed 0:7b5e68d593c6 544 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 545 void dynamic_IO_website(int id){
kbed 0:7b5e68d593c6 546 char out_buf[2000]; //buffer for website output (buffer size is minimized to max. required size)
kbed 0:7b5e68d593c6 547 char query_buf[256]; //buffer to store
kbed 0:7b5e68d593c6 548 char tempstring[32]; //buffer for small string construction
kbed 0:7b5e68d593c6 549 int counter = 0; //counter variable (multiple use)
kbed 0:7b5e68d593c6 550
kbed 0:7b5e68d593c6 551 strcpy(query_buf, httpd->getQueryString(id)); //copy transmitted parameters to query_buf
kbed 0:7b5e68d593c6 552 strcpy(out_buf, io_header); //initialize Website output
kbed 0:7b5e68d593c6 553
kbed 0:7b5e68d593c6 554 io_webhandler_action(query_buf, strlen(query_buf)); //handle transmitted parameters stored in query_buf
kbed 0:7b5e68d593c6 555
kbed 0:7b5e68d593c6 556
kbed 0:7b5e68d593c6 557 /*create website in buffer*/
kbed 0:7b5e68d593c6 558 strcat(out_buf,"<h1>View and Control Ports</h1><div class=\"lf\"><div class=\"block2\"><fieldset><legend>I/OPorts</legend>");
kbed 0:7b5e68d593c6 559
kbed 0:7b5e68d593c6 560 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\">");
kbed 0:7b5e68d593c6 561
kbed 0:7b5e68d593c6 562 /*read status of output ports*/
kbed 0:7b5e68d593c6 563 for(counter = 1; counter <= 5; counter++){
kbed 0:7b5e68d593c6 564 strcat(out_buf,"<th style=\" background-color:");
kbed 0:7b5e68d593c6 565 if (read_portval(ASCII_out + char(counter))){
kbed 0:7b5e68d593c6 566 strcat(out_buf,"gold");
kbed 0:7b5e68d593c6 567 }else{
kbed 0:7b5e68d593c6 568 strcat(out_buf,"lime");
kbed 0:7b5e68d593c6 569 }
kbed 0:7b5e68d593c6 570 strcat(out_buf,"\" onclick=\"key(\'");
kbed 0:7b5e68d593c6 571 sprintf(tempstring,"%i\')\">O%i</th>",counter,counter);
kbed 0:7b5e68d593c6 572 strcat(out_buf,tempstring);
kbed 0:7b5e68d593c6 573 }
kbed 0:7b5e68d593c6 574
kbed 0:7b5e68d593c6 575 strcat(out_buf, "</tr> </table>");
kbed 0:7b5e68d593c6 576 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\">");
kbed 0:7b5e68d593c6 577
kbed 0:7b5e68d593c6 578 /*read input values*/
kbed 0:7b5e68d593c6 579 for(counter = 0; counter <= 3; counter++){ //read port 1-4 (mapped to a-d)
kbed 0:7b5e68d593c6 580 strcat(out_buf,"<th style=\" background-color:");
kbed 0:7b5e68d593c6 581 if (read_portval(ASCII_in + char(counter))){
kbed 0:7b5e68d593c6 582 strcat(out_buf,"gold");
kbed 0:7b5e68d593c6 583 }else{
kbed 0:7b5e68d593c6 584 strcat(out_buf,"lime");
kbed 0:7b5e68d593c6 585 }
kbed 0:7b5e68d593c6 586 sprintf(tempstring,"\">%i</th>",(counter+1)); //port 1-4 mapped to a-d
kbed 0:7b5e68d593c6 587 strcat(out_buf,tempstring);
kbed 0:7b5e68d593c6 588 }
kbed 0:7b5e68d593c6 589 strcat(out_buf,"</tr></table></div>");
kbed 0:7b5e68d593c6 590
kbed 0:7b5e68d593c6 591 strcat(out_buf, io_footer); //copy footer to buffer
kbed 0:7b5e68d593c6 592
kbed 0:7b5e68d593c6 593 #if defined debug
kbed 0:7b5e68d593c6 594 printf("io page html length: %i \r\n",strlen(out_buf));
kbed 0:7b5e68d593c6 595 #endif
kbed 0:7b5e68d593c6 596
kbed 0:7b5e68d593c6 597 httpd->send(id, out_buf, strlen(out_buf), "Content-Type: text/html\r\n"); //send the constructed website
kbed 0:7b5e68d593c6 598
kbed 0:7b5e68d593c6 599 }
kbed 0:7b5e68d593c6 600
kbed 0:7b5e68d593c6 601
kbed 0:7b5e68d593c6 602 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 603 * Routine: dynamic_analog_website
kbed 0:7b5e68d593c6 604 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 605 * Description:
kbed 0:7b5e68d593c6 606 * Generation and handling of the dynamic website for analog ports.
kbed 0:7b5e68d593c6 607 * Inputs:
kbed 0:7b5e68d593c6 608 * int id -- httpd web handle
kbed 0:7b5e68d593c6 609 * Outputs:
kbed 0:7b5e68d593c6 610 * "http" -- only output to web browser
kbed 0:7b5e68d593c6 611 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 612 void dynamic_analog_website(int id){
kbed 0:7b5e68d593c6 613 char out_buf[2000]; //buffer for website output
kbed 0:7b5e68d593c6 614 char query_buf[256]; //buffer to store
kbed 0:7b5e68d593c6 615 char tempstring[32]; //buffer for small string construction
kbed 0:7b5e68d593c6 616 int counter = 0; //counter variable (multiple use)
kbed 0:7b5e68d593c6 617 unsigned short analog_buf; //buffer for analog values
kbed 0:7b5e68d593c6 618
kbed 0:7b5e68d593c6 619 strcpy(query_buf, httpd->getQueryString(id)); //copy transmitted parameters to query_buf
kbed 0:7b5e68d593c6 620 strcpy(out_buf, io_header); //initialize Website output
kbed 0:7b5e68d593c6 621
kbed 0:7b5e68d593c6 622 io_webhandler_action(query_buf, strlen(query_buf)); //handle transmitted parameters stored in query_buf
kbed 0:7b5e68d593c6 623
kbed 0:7b5e68d593c6 624
kbed 0:7b5e68d593c6 625
kbed 0:7b5e68d593c6 626 strcpy(out_buf, analog_header); //initialize Website output
kbed 0:7b5e68d593c6 627
kbed 0:7b5e68d593c6 628 io_webhandler_action(query_buf, strlen(query_buf)); //handle transmitted parameters
kbed 0:7b5e68d593c6 629
kbed 0:7b5e68d593c6 630 /*create website in buffer*/
kbed 0:7b5e68d593c6 631 strcat(out_buf,"<h1>Analog input</h1><div class=\"lf\"> <div class=\"block2\"><fieldset> ");
kbed 0:7b5e68d593c6 632 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\">");
kbed 0:7b5e68d593c6 633
kbed 0:7b5e68d593c6 634 /*read analog ports and create text for website*/
kbed 0:7b5e68d593c6 635 for(counter = 1; counter <= 4; counter++){
kbed 0:7b5e68d593c6 636 strcat(out_buf,"<th>");
kbed 0:7b5e68d593c6 637 analog_buf = read_adc(ASCII_analog + char(counter)); //loop over all analog ports
kbed 0:7b5e68d593c6 638 sprintf(tempstring,"%hu mv</th>",analog_buf);
kbed 0:7b5e68d593c6 639 strcat(out_buf,tempstring);
kbed 0:7b5e68d593c6 640 }
kbed 0:7b5e68d593c6 641 strcat(out_buf,"</tr> </table></div>");
kbed 0:7b5e68d593c6 642
kbed 0:7b5e68d593c6 643 strcat(out_buf, io_footer); //copy footer to buffer
kbed 0:7b5e68d593c6 644
kbed 0:7b5e68d593c6 645 #if defined debug
kbed 0:7b5e68d593c6 646 printf("html length: %i \r\n",strlen(out_buf));
kbed 0:7b5e68d593c6 647 #endif
kbed 0:7b5e68d593c6 648 httpd->send(id, out_buf, strlen(out_buf), "Content-Type: text/html\r\n"); //send constructed website
kbed 0:7b5e68d593c6 649
kbed 0:7b5e68d593c6 650 }
kbed 0:7b5e68d593c6 651
kbed 0:7b5e68d593c6 652
kbed 0:7b5e68d593c6 653
kbed 0:7b5e68d593c6 654 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 655 * Routine: io_webhandler_action
kbed 0:7b5e68d593c6 656 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 657 * Description:
kbed 0:7b5e68d593c6 658 * Routine to parse and handle http "get-requests" for dynamic
kbed 0:7b5e68d593c6 659 * generated websites.
kbed 0:7b5e68d593c6 660 *
kbed 0:7b5e68d593c6 661 * eg. toggling output port 3:
kbed 0:7b5e68d593c6 662 * http://mbed.ip/dynamic/websitename.htm?p30
kbed 0:7b5e68d593c6 663 * -> set port value of port 3 to 0
kbed 0:7b5e68d593c6 664 *
kbed 0:7b5e68d593c6 665 eg. "o2" toggles output port 2
kbed 0:7b5e68d593c6 666 *
kbed 0:7b5e68d593c6 667 * Supported Variables:
kbed 0:7b5e68d593c6 668 * o = toggle output port
kbed 0:7b5e68d593c6 669 * p = set bit to value
kbed 0:7b5e68d593c6 670 *
kbed 0:7b5e68d593c6 671 * Inputs:
kbed 0:7b5e68d593c6 672 * char* query_buf -- pointer to string with http get request variables
kbed 0:7b5e68d593c6 673 * int query_buf_len -- length of request string
kbed 0:7b5e68d593c6 674 * Outputs:
kbed 0:7b5e68d593c6 675 * int -- port value (normally 0 or 1)
kbed 0:7b5e68d593c6 676 * and in case of an error "-1"
kbed 0:7b5e68d593c6 677 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 678 int io_webhandler_action(char *query_buf, int query_buf_len){
kbed 0:7b5e68d593c6 679 char io_action = 0; //variables to store parameters
kbed 0:7b5e68d593c6 680 char io_port = 0;
kbed 0:7b5e68d593c6 681 char io_value = 0;
kbed 0:7b5e68d593c6 682
kbed 0:7b5e68d593c6 683 #if defined debug
kbed 0:7b5e68d593c6 684 printf ("io_webhandler - querystring: %s string-lenth: %i\r\n", query_buf, query_buf_len);
kbed 0:7b5e68d593c6 685 #endif
kbed 0:7b5e68d593c6 686
kbed 0:7b5e68d593c6 687 if (query_buf_len >= 3){ //evaluate io-action parameters
kbed 0:7b5e68d593c6 688 sscanf(query_buf, "%c%c%c", &io_action, &io_port, &io_value); //3 or more parameters
kbed 0:7b5e68d593c6 689 }else if (query_buf_len == 2){ //2 parameters
kbed 0:7b5e68d593c6 690 sscanf(query_buf, "%c%c", &io_action, &io_port);
kbed 0:7b5e68d593c6 691 }
kbed 0:7b5e68d593c6 692
kbed 0:7b5e68d593c6 693 #if defined debug
kbed 0:7b5e68d593c6 694 printf("io_webhandler: evaluated http-params %c %c %c \r\n",io_action, io_port, io_value);
kbed 0:7b5e68d593c6 695 #endif
kbed 0:7b5e68d593c6 696
kbed 0:7b5e68d593c6 697 switch (io_action){
kbed 0:7b5e68d593c6 698 case('o'): if (io_port != 0)return toggle_port(io_port); //toggle output port
kbed 0:7b5e68d593c6 699 break;
kbed 0:7b5e68d593c6 700 case('p'): if ((io_port != 0) && (io_value != 0)){return write_portval(io_port,0);} //set output port value
kbed 0:7b5e68d593c6 701 break;
kbed 0:7b5e68d593c6 702 }
kbed 0:7b5e68d593c6 703 return -1; //return -1 if no valid action should be done
kbed 0:7b5e68d593c6 704 }
kbed 0:7b5e68d593c6 705
kbed 0:7b5e68d593c6 706
kbed 0:7b5e68d593c6 707 /* =================================================================== */
kbed 0:7b5e68d593c6 708 /* functions for hardware abstraction */
kbed 0:7b5e68d593c6 709 /* =================================================================== */
kbed 0:7b5e68d593c6 710
kbed 0:7b5e68d593c6 711
kbed 0:7b5e68d593c6 712 /* analog and digital ports are specified by ascii characters:
kbed 0:7b5e68d593c6 713 *
kbed 0:7b5e68d593c6 714 * digital input 1 = a
kbed 0:7b5e68d593c6 715 * digital input 2 = b
kbed 0:7b5e68d593c6 716 * digital input 3 = c
kbed 0:7b5e68d593c6 717 * digital input 4 = d
kbed 0:7b5e68d593c6 718 *
kbed 0:7b5e68d593c6 719 * digital output 1 = 1
kbed 0:7b5e68d593c6 720 * digital output 2 = 2
kbed 0:7b5e68d593c6 721 * digital output 3 = 3
kbed 0:7b5e68d593c6 722 * digital output 4 = 4
kbed 0:7b5e68d593c6 723 *
kbed 0:7b5e68d593c6 724 * eg. read_portval("b") reads the value of the digital input port 2
kbed 0:7b5e68d593c6 725 */
kbed 0:7b5e68d593c6 726
kbed 0:7b5e68d593c6 727
kbed 0:7b5e68d593c6 728
kbed 0:7b5e68d593c6 729 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 730 * Routine: read_portval
kbed 0:7b5e68d593c6 731 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 732 * Description:
kbed 0:7b5e68d593c6 733 * Reads a value of an io-port and returns its value. (logically correct)
kbed 0:7b5e68d593c6 734 * Inputs:
kbed 0:7b5e68d593c6 735 * char port_name -- ascii character representing the port
kbed 0:7b5e68d593c6 736 * Outputs:
kbed 0:7b5e68d593c6 737 * int -- port value (normally 0 or 1)
kbed 0:7b5e68d593c6 738 * and in case of an error "-1"
kbed 0:7b5e68d593c6 739 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 740 int read_portval(char port_name){
kbed 0:7b5e68d593c6 741 switch (port_name){
kbed 0:7b5e68d593c6 742 case (ASCII_out + 1): if(out1){ return 0;} else{ return 1;}
kbed 0:7b5e68d593c6 743 case (ASCII_out + 2): if(out2){ return 0;} else{ return 1;}
kbed 0:7b5e68d593c6 744 case (ASCII_out + 3): if(out3){ return 0;} else{ return 1;}
kbed 0:7b5e68d593c6 745 case (ASCII_out + 4): if(out4){ return 0;} else{ return 1;}
kbed 0:7b5e68d593c6 746 case (ASCII_out + 5): return relay1;
kbed 0:7b5e68d593c6 747 case (ASCII_out + 6): return led1;
kbed 0:7b5e68d593c6 748 case (ASCII_out + 7): return led2;
kbed 0:7b5e68d593c6 749 case (ASCII_out + 8): return led3;
kbed 0:7b5e68d593c6 750 case (ASCII_out + 9): return led4;
kbed 0:7b5e68d593c6 751 case (ASCII_in + 0): if(in1){ return 0;} else{ return 1;}
kbed 0:7b5e68d593c6 752 case (ASCII_in + 1): if(in2){ return 0;} else{ return 1;}
kbed 0:7b5e68d593c6 753 case (ASCII_in + 2): if(in3){ return 0;} else{ return 1;}
kbed 0:7b5e68d593c6 754 case (ASCII_in + 3): if(in4){ return 0;} else{ return 1;}
kbed 0:7b5e68d593c6 755 }
kbed 0:7b5e68d593c6 756 return -1;
kbed 0:7b5e68d593c6 757 }
kbed 0:7b5e68d593c6 758
kbed 0:7b5e68d593c6 759 //
kbed 0:7b5e68d593c6 760 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 761 * Routine: write_portval
kbed 0:7b5e68d593c6 762 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 763 * Description:
kbed 0:7b5e68d593c6 764 * Function to set output port values (handles inverted logic).
kbed 0:7b5e68d593c6 765 * Inputs:
kbed 0:7b5e68d593c6 766 * char port_name -- ascii character representing the port
kbed 0:7b5e68d593c6 767 * int port_val -- output value
kbed 0:7b5e68d593c6 768 * Outputs:
kbed 0:7b5e68d593c6 769 * int -- given port value (normally 0 or 1)
kbed 0:7b5e68d593c6 770 * and in case of an error "-1"
kbed 0:7b5e68d593c6 771 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 772 int write_portval(char port_name, int port_val){
kbed 0:7b5e68d593c6 773 if (port_val > 1) return 0; //no analog/pwm signal output yet, only 0 and 1
kbed 0:7b5e68d593c6 774
kbed 0:7b5e68d593c6 775 #if defined debug
kbed 0:7b5e68d593c6 776 printf("write Port %c Value %i \r\n",port_name, port_val);
kbed 0:7b5e68d593c6 777 #endif
kbed 0:7b5e68d593c6 778
kbed 0:7b5e68d593c6 779 switch (port_name){
kbed 0:7b5e68d593c6 780 case (ASCII_out + 1): if(port_val){ out1 = 0; return 0;} else{ out1 = 1; return 1;} //inverted output logic
kbed 0:7b5e68d593c6 781 case (ASCII_out + 2): if(port_val){ out2 = 0; return 0;} else{ out2 = 1; return 1;} //inverted output logic
kbed 0:7b5e68d593c6 782 case (ASCII_out + 3): if(port_val){ out3 = 0; return 0;} else{ out3 = 1; return 1;} //inverted output logic
kbed 0:7b5e68d593c6 783 case (ASCII_out + 4): if(port_val){ out4 = 0; return 0;} else{ out4 = 1; return 1;} //inverted output logic
kbed 0:7b5e68d593c6 784 case (ASCII_out + 5): relay1 = port_val; return relay1; //relay port
kbed 0:7b5e68d593c6 785 case (ASCII_out + 6): led1 = port_val; return led1;
kbed 0:7b5e68d593c6 786 case (ASCII_out + 7): led2 = port_val; return led2;
kbed 0:7b5e68d593c6 787 case (ASCII_out + 8): led3 = port_val; return led3;
kbed 0:7b5e68d593c6 788 case (ASCII_out + 9): led4 = port_val; return led4;
kbed 0:7b5e68d593c6 789 }
kbed 0:7b5e68d593c6 790 return -1;
kbed 0:7b5e68d593c6 791 }
kbed 0:7b5e68d593c6 792
kbed 0:7b5e68d593c6 793
kbed 0:7b5e68d593c6 794 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 795 * Routine: toggle_port
kbed 0:7b5e68d593c6 796 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 797 * Description:
kbed 0:7b5e68d593c6 798 * Function to toggle output ports.
kbed 0:7b5e68d593c6 799 * Inputs:
kbed 0:7b5e68d593c6 800 * char port_name -- ascii character representing the port
kbed 0:7b5e68d593c6 801 * Outputs:
kbed 0:7b5e68d593c6 802 * int -- new port value (normally 0 or 1)
kbed 0:7b5e68d593c6 803 * and in case of an error "-1"
kbed 0:7b5e68d593c6 804 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 805 int toggle_port(char port_name){
kbed 0:7b5e68d593c6 806 #if defined debug
kbed 0:7b5e68d593c6 807 printf("toggle Port %c \r\n",port_name);
kbed 0:7b5e68d593c6 808 #endif
kbed 0:7b5e68d593c6 809 switch (port_name){
kbed 0:7b5e68d593c6 810 case (ASCII_out + 1): out1 = !out1; return out1;
kbed 0:7b5e68d593c6 811 case (ASCII_out + 2): out2 = !out2; return out2;
kbed 0:7b5e68d593c6 812 case (ASCII_out + 3): out3 = !out3; return out3;
kbed 0:7b5e68d593c6 813 case (ASCII_out + 4): out4 = !out4; return out4;
kbed 0:7b5e68d593c6 814 case (ASCII_out + 5): relay1 = !relay1; return relay1;
kbed 0:7b5e68d593c6 815 case (ASCII_out + 6): led1 = !led1; return led1;
kbed 0:7b5e68d593c6 816 case (ASCII_out + 7): led2 = !led2; return led2;
kbed 0:7b5e68d593c6 817 case (ASCII_out + 8): led3 = !led3; return led3;
kbed 0:7b5e68d593c6 818 case (ASCII_out + 9): led4 = !led4; return led4;
kbed 0:7b5e68d593c6 819 }
kbed 0:7b5e68d593c6 820 return -1;
kbed 0:7b5e68d593c6 821 }
kbed 0:7b5e68d593c6 822
kbed 0:7b5e68d593c6 823 /*---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 824 * Routine: read_adc
kbed 0:7b5e68d593c6 825 *---------------------------------------------------------------------------*
kbed 0:7b5e68d593c6 826 * Description:
kbed 0:7b5e68d593c6 827 * Function to read the integrated adc-ports and calculate the input
kbed 0:7b5e68d593c6 828 * voltage in millivolts.
kbed 0:7b5e68d593c6 829 *
kbed 0:7b5e68d593c6 830 * Inputs:
kbed 0:7b5e68d593c6 831 * char port_name -- ascii character representing the port
kbed 0:7b5e68d593c6 832 * Outputs:
kbed 0:7b5e68d593c6 833 * unsigned short -- input voltage in milivolt
kbed 0:7b5e68d593c6 834 *---------------------------------------------------------------------------*/
kbed 0:7b5e68d593c6 835 unsigned short read_adc(char port_name){
kbed 0:7b5e68d593c6 836 unsigned int adc_tempval = 0; //32 bit buffer for analog value
kbed 0:7b5e68d593c6 837
kbed 0:7b5e68d593c6 838 /*read raw analog port value*/
kbed 0:7b5e68d593c6 839 switch (port_name){
kbed 0:7b5e68d593c6 840 case (ASCII_analog + 1): adc_tempval = ain1.read_u16();
kbed 0:7b5e68d593c6 841 break;
kbed 0:7b5e68d593c6 842 case (ASCII_analog + 2): adc_tempval = ain2.read_u16();
kbed 0:7b5e68d593c6 843 break;
kbed 0:7b5e68d593c6 844 case (ASCII_analog + 3): adc_tempval = ain3.read_u16();
kbed 0:7b5e68d593c6 845 break;
kbed 0:7b5e68d593c6 846 case (ASCII_analog + 4): adc_tempval = ain4.read_u16();
kbed 0:7b5e68d593c6 847 break;
kbed 0:7b5e68d593c6 848 default: return 0;
kbed 0:7b5e68d593c6 849 }
kbed 0:7b5e68d593c6 850
kbed 0:7b5e68d593c6 851 /* calculate the analog input voltage (input voltage is divided by 3.5):
kbed 0:7b5e68d593c6 852
kbed 0:7b5e68d593c6 853 The reference voltage of 3.3V (3300mV) is diveded into 2^16 steps.
kbed 0:7b5e68d593c6 854 Result in millivolts: Vin_mbed = (3300 * ADC_Value)/65536
kbed 0:7b5e68d593c6 855 mbedRail24v uses a voltage divider: Vin_mbedrail24v = Vin_mbed * 3,5
kbed 0:7b5e68d593c6 856 -> Vin_mbedrail= (3300 * ADC_Value * 3,5)/65536
kbed 0:7b5e68d593c6 857 an integer of 32 bit is required for the calculation, otherwise the multiplication would fail
kbed 0:7b5e68d593c6 858 */
kbed 0:7b5e68d593c6 859
kbed 0:7b5e68d593c6 860 adc_tempval *= 11550; // ADC_Value * 3300 * 3,5
kbed 0:7b5e68d593c6 861 adc_tempval /= 0xFFFF; // divide by 65536 (0xFFFF)
kbed 0:7b5e68d593c6 862
kbed 0:7b5e68d593c6 863 return (unsigned short)adc_tempval; //return the calculated value of an analog port in milivolt
kbed 0:7b5e68d593c6 864 }