Test HTTP Server, including RPCFunction
Dependencies: EthernetNetIf mbed HTTPServer
Revision 0:dacaf456d264, committed 2011-02-03
- Comitter:
- pbaston
- Date:
- Thu Feb 03 20:23:51 2011 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r dacaf456d264 EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Thu Feb 03 20:23:51 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mamezu/code/EthernetNetIf/#0f6c82fcde82
diff -r 000000000000 -r dacaf456d264 HTTPServer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPServer.cpp Thu Feb 03 20:23:51 2011 +0000 @@ -0,0 +1,68 @@ +#include "mbed.h" +#include "EthernetNetIf.h" +#include "HTTPServer.h" +#include "RPCFunction.h" + +EthernetNetIf eth; + +HTTPServer svr; + +LocalFileSystem fs("webfs"); + +//Create a function of the required format +void testFunc(char * input, char * output); +//Attach it to an RPC object +RPCFunction rpcTestFunc(&testFunc, "testFunc"); + +int main() { + + Base::add_rpc_class<DigitalOut>(); + Base::add_rpc_class<PwmOut>(); + Base::add_rpc_class<AnalogIn>(); + + + printf("Setting up...\r\n"); + EthernetErr ethErr = eth.setup(); + if (ethErr) { + printf("Error %d in setup.\r\n", ethErr); + return -1; + } + printf("Setup OK\r\n"); + + FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path + + svr.addHandler<SimpleHandler>("/hello"); //Default handler + svr.addHandler<RPCHandler>("/rpc"); + svr.addHandler<FSHandler>("/"); //Default handler + + svr.bind(80); + + printf("Listening...\r\n"); + + Timer tm; + tm.start(); + //Listen indefinitely + while (true) { + Net::poll(); + if (tm.read()>.5) { + tm.start(); + printf("alive!\r\n"); + } + } + + return 0; +} + +void testFunc(char * input, char * output) { + + static int toggle=0; + + if (toggle != 0) { + sprintf(output, "Hello"); + toggle = 0; + } else { + sprintf(output, "Bye !"); + toggle = 1; + } +} +
diff -r 000000000000 -r dacaf456d264 HTTPServer.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPServer.lib Thu Feb 03 20:23:51 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
diff -r 000000000000 -r dacaf456d264 RPCInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RPCInterface.lib Thu Feb 03 20:23:51 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/MichaelW/code/RPCInterface/#f15d3610ddbe
diff -r 000000000000 -r dacaf456d264 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 03 20:23:51 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9a9732ce53a1