Dependencies:   EthernetNetIf mbed HTTPServer

Committer:
bouguereau
Date:
Wed Aug 24 09:46:08 2011 +0000
Revision:
0:91decc5a6a3f

        

Who changed what in which revision?

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