A slight Alteration to Donatien's HTTP Server Example so that it registers all the classes with RPC support to demonstrate RPC over HTTP

Dependencies:   EthernetNetIf mbed HTTPServer

Committer:
MichaelW
Date:
Thu Sep 09 13:47:59 2010 +0000
Revision:
1:71b64a776133
Parent:
0:e30eeef17180

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MichaelW 1:71b64a776133 1 /*
MichaelW 1:71b64a776133 2 Copyright (c) 2010 ARM Ltd
MichaelW 1:71b64a776133 3
MichaelW 1:71b64a776133 4 Permission is hereby granted, free of charge, to any person obtaining a copy
MichaelW 1:71b64a776133 5 of this software and associated documentation files (the "Software"), to deal
MichaelW 1:71b64a776133 6 in the Software without restriction, including without limitation the rights
MichaelW 1:71b64a776133 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
MichaelW 1:71b64a776133 8 copies of the Software, and to permit persons to whom the Software is
MichaelW 1:71b64a776133 9 furnished to do so, subject to the following conditions:
MichaelW 1:71b64a776133 10
MichaelW 1:71b64a776133 11 The above copyright notice and this permission notice shall be included in
MichaelW 1:71b64a776133 12 all copies or substantial portions of the Software.
MichaelW 1:71b64a776133 13
MichaelW 1:71b64a776133 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MichaelW 1:71b64a776133 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MichaelW 1:71b64a776133 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
MichaelW 1:71b64a776133 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MichaelW 1:71b64a776133 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
MichaelW 1:71b64a776133 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
MichaelW 1:71b64a776133 20 THE SOFTWARE.
MichaelW 1:71b64a776133 21 */
MichaelW 1:71b64a776133 22 #include "mbed.h"
MichaelW 1:71b64a776133 23 #include "EthernetNetIf.h"
MichaelW 1:71b64a776133 24 #include "HTTPServer.h"
MichaelW 1:71b64a776133 25
MichaelW 1:71b64a776133 26 DigitalOut led1(LED1, "led1");
MichaelW 1:71b64a776133 27 DigitalOut led2(LED2, "led2");
MichaelW 1:71b64a776133 28 DigitalOut led3(LED3, "led3");
MichaelW 1:71b64a776133 29 DigitalOut led4(LED4, "led4");
MichaelW 1:71b64a776133 30
MichaelW 1:71b64a776133 31 LocalFileSystem fs("webfs");
MichaelW 1:71b64a776133 32
MichaelW 1:71b64a776133 33 EthernetNetIf eth;
MichaelW 1:71b64a776133 34 HTTPServer svr;
MichaelW 1:71b64a776133 35
MichaelW 1:71b64a776133 36 int main() {
MichaelW 1:71b64a776133 37 Base::add_rpc_class<AnalogIn>();
MichaelW 1:71b64a776133 38 Base::add_rpc_class<AnalogOut>();
MichaelW 1:71b64a776133 39 Base::add_rpc_class<DigitalIn>();
MichaelW 1:71b64a776133 40 Base::add_rpc_class<DigitalOut>();
MichaelW 1:71b64a776133 41 Base::add_rpc_class<DigitalInOut>();
MichaelW 1:71b64a776133 42 Base::add_rpc_class<PwmOut>();
MichaelW 1:71b64a776133 43 Base::add_rpc_class<Timer>();
MichaelW 1:71b64a776133 44 Base::add_rpc_class<BusOut>();
MichaelW 1:71b64a776133 45 Base::add_rpc_class<BusIn>();
MichaelW 1:71b64a776133 46 Base::add_rpc_class<BusInOut>();
MichaelW 1:71b64a776133 47 Base::add_rpc_class<Serial>();
MichaelW 1:71b64a776133 48
MichaelW 1:71b64a776133 49 printf("Setting up...\n");
MichaelW 1:71b64a776133 50 EthernetErr ethErr = eth.setup();
MichaelW 1:71b64a776133 51 if(ethErr)
MichaelW 1:71b64a776133 52 {
MichaelW 1:71b64a776133 53 printf("Error %d in setup.\n", ethErr);
MichaelW 1:71b64a776133 54 return -1;
MichaelW 1:71b64a776133 55 }
MichaelW 1:71b64a776133 56 printf("Setup OK\n");
MichaelW 1:71b64a776133 57
MichaelW 1:71b64a776133 58 FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
MichaelW 1:71b64a776133 59 FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
MichaelW 1:71b64a776133 60
MichaelW 1:71b64a776133 61 svr.addHandler<SimpleHandler>("/hello");
MichaelW 1:71b64a776133 62 svr.addHandler<RPCHandler>("/rpc");
MichaelW 1:71b64a776133 63 svr.addHandler<FSHandler>("/files");
MichaelW 1:71b64a776133 64 svr.addHandler<FSHandler>("/"); //Default handler
MichaelW 1:71b64a776133 65 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
MichaelW 1:71b64a776133 66
MichaelW 1:71b64a776133 67 svr.bind(80);
MichaelW 1:71b64a776133 68
MichaelW 1:71b64a776133 69 printf("Listening...\n");
MichaelW 1:71b64a776133 70
MichaelW 1:71b64a776133 71 Timer tm;
MichaelW 1:71b64a776133 72 tm.start();
MichaelW 1:71b64a776133 73 //Listen indefinitely
MichaelW 1:71b64a776133 74 while(true)
MichaelW 1:71b64a776133 75 {
MichaelW 1:71b64a776133 76 Net::poll();
MichaelW 1:71b64a776133 77 if(tm.read()>.5)
MichaelW 1:71b64a776133 78 {
MichaelW 1:71b64a776133 79 led1=!led1; //Show that we are alive
MichaelW 1:71b64a776133 80 tm.start();
MichaelW 1:71b64a776133 81 }
MichaelW 1:71b64a776133 82 }
MichaelW 1:71b64a776133 83
MichaelW 1:71b64a776133 84 return 0;
MichaelW 1:71b64a776133 85
MichaelW 1:71b64a776133 86 }