Android controlled
Dependencies: RPCInterface mbed
Fork of RPC_Function_Example by
Revision 0:74f2764b636b, committed 2016-03-11
- Comitter:
- nambvarun
- Date:
- Fri Mar 11 23:42:52 2016 +0000
- Child:
- 1:50a40baa79bf
- Commit message:
- RPC Tutorial Program;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RPCInterface.lib Fri Mar 11 23:42:52 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/MichaelW/code/RPCInterface/#bcc2e05e5da4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 11 23:42:52 2016 +0000 @@ -0,0 +1,54 @@ +#include "mbed.h" +#include "mbed_rpc.h" + +/** + * This example program has been updated to use the RPC implementation in the new mbed libraries. + * This example demonstrates using RPC over serial + */ + + +// These are examples of some variable types that can be modified through RPC. +int wheelsOn; +char lcdBannerMessage; +float speed; + +RPCVariable<int> rpcLights(&wheelsOn, "wheels"); +RPCVariable<char> rpcBanner(&lcdBannerMessage, "banner"); +RPCVariable<float> rpcSpeed(&speed, "speed"); + +Serial pc(USBTX, USBRX); +void moveTo(Arguments *in, Reply *out); +RPCFunction rpcMove(&moveTo, "moveTo"); +double xLoc, yLoc; + +int main() { + //The mbed RPC classes are now wrapped to create an RPC enabled version - see RpcClasses.h so don't add to base class + + // receive commands, and send back the responses + char buf[256], outbuf[256]; + while(1) { + pc.gets(buf, 256); + //Call the static call method on the RPC class + RPC::call(buf, outbuf); + pc.printf("%s\n", outbuf); + } +} + +// Make sure the method takes in Arguments and Reply objects. +void moveTo (Arguments *in, Reply *out) { + bool success = true; + + // In this scenario, when using RPC delimit the two arguments with a space. + xLoc = in->getArg<double>(); + yLoc = in->getArg<double>(); + + // Have code here to move robot to location (xLoc, yLoc) and update success. + + char buffer[200]; + sprintf(buffer, "Successfully moved to location (%f, %f)", xLoc, yLoc); + if (success) { + out->putData(buffer); + } else { + out->putData("Failed to move to location."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Mar 11 23:42:52 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb \ No newline at end of file