
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
main.cpp@0:9206091eda82, 2013-06-16 (annotated)
- Committer:
- robt
- Date:
- Sun Jun 16 15:34:26 2013 +0000
- Revision:
- 0:9206091eda82
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robt | 0:9206091eda82 | 1 | /* Program Example 12.12 Using RPC variables for remote mbed control |
robt | 0:9206091eda82 | 2 | */ |
robt | 0:9206091eda82 | 3 | #include "mbed.h" |
robt | 0:9206091eda82 | 4 | #include "EthernetNetIf.h" |
robt | 0:9206091eda82 | 5 | #include "HTTPServer.h" |
robt | 0:9206091eda82 | 6 | #include "RPCVariable.h" |
robt | 0:9206091eda82 | 7 | #include "SerialRPCInterface.h" |
robt | 0:9206091eda82 | 8 | LocalFileSystem fs("webfs"); |
robt | 0:9206091eda82 | 9 | EthernetNetIf eth( |
robt | 0:9206091eda82 | 10 | IpAddr(192,168,0,101),//IP Address |
robt | 0:9206091eda82 | 11 | IpAddr(255,255,255,0),//Network Mask |
robt | 0:9206091eda82 | 12 | IpAddr(192,168,0,1), //Gateway |
robt | 0:9206091eda82 | 13 | IpAddr(192,168,0,1) //DNS |
robt | 0:9206091eda82 | 14 | ); |
robt | 0:9206091eda82 | 15 | HTTPServer svr; |
robt | 0:9206091eda82 | 16 | DigitalOut Led1(LED1); // define mbed object |
robt | 0:9206091eda82 | 17 | DigitalIn Button1(p21); // button |
robt | 0:9206091eda82 | 18 | int RemoteLEDStatus=0; |
robt | 0:9206091eda82 | 19 | RPCVariable<int> RPC_RemoteLEDStatus(&RemoteLEDStatus,"RemoteLEDStatus"); |
robt | 0:9206091eda82 | 20 | int RemoteLED1Button=0; |
robt | 0:9206091eda82 | 21 | RPCVariable<int> RPC_RemoteLED1Button(&RemoteLED1Button,"RemoteLED1Button"); |
robt | 0:9206091eda82 | 22 | int main() { |
robt | 0:9206091eda82 | 23 | Base::add_rpc_class<DigitalOut>(); // RPC base command |
robt | 0:9206091eda82 | 24 | eth.setup(); // Ethernet setup |
robt | 0:9206091eda82 | 25 | FSHandler::mount("/webfs", "/"); // Mount /webfs path root path |
robt | 0:9206091eda82 | 26 | svr.addHandler<FSHandler>("/"); //Default handler |
robt | 0:9206091eda82 | 27 | svr.addHandler<RPCHandler>("/rpc"); // Define RPC handler |
robt | 0:9206091eda82 | 28 | svr.bind(80); |
robt | 0:9206091eda82 | 29 | printf("Listening...\n"); |
robt | 0:9206091eda82 | 30 | while (true) { |
robt | 0:9206091eda82 | 31 | Net::poll(); |
robt | 0:9206091eda82 | 32 | if ((Button1==1)|(RemoteLED1Button==1)) { |
robt | 0:9206091eda82 | 33 | Led1=1; |
robt | 0:9206091eda82 | 34 | RemoteLEDStatus=1; |
robt | 0:9206091eda82 | 35 | } else { |
robt | 0:9206091eda82 | 36 | Led1=0; |
robt | 0:9206091eda82 | 37 | RemoteLEDStatus=0; |
robt | 0:9206091eda82 | 38 | } |
robt | 0:9206091eda82 | 39 | } |
robt | 0:9206091eda82 | 40 | } |
robt | 0:9206091eda82 | 41 |