Working with RPC Variables
Dependencies: RPCInterface mbed
main.cpp@0:85792dec3d95, 2016-03-12 (annotated)
- Committer:
- nambvarun
- Date:
- Sat Mar 12 02:37:08 2016 +0000
- Revision:
- 0:85792dec3d95
Example RPC Variables Program;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nambvarun | 0:85792dec3d95 | 1 | #include "mbed.h" |
nambvarun | 0:85792dec3d95 | 2 | #include "mbed_rpc.h" |
nambvarun | 0:85792dec3d95 | 3 | |
nambvarun | 0:85792dec3d95 | 4 | // These are examples of some variable types that can be modified through RPC. |
nambvarun | 0:85792dec3d95 | 5 | int wheelsOn; |
nambvarun | 0:85792dec3d95 | 6 | char lcdBannerMessage; |
nambvarun | 0:85792dec3d95 | 7 | float speed; |
nambvarun | 0:85792dec3d95 | 8 | |
nambvarun | 0:85792dec3d95 | 9 | RPCVariable<int> rpcLights(&wheelsOn, "wheels"); |
nambvarun | 0:85792dec3d95 | 10 | RPCVariable<char> rpcBanner(&lcdBannerMessage, "banner"); |
nambvarun | 0:85792dec3d95 | 11 | RPCVariable<float> rpcSpeed(&speed, "speed"); |
nambvarun | 0:85792dec3d95 | 12 | |
nambvarun | 0:85792dec3d95 | 13 | Serial pc(USBTX, USBRX); |
nambvarun | 0:85792dec3d95 | 14 | |
nambvarun | 0:85792dec3d95 | 15 | int main() { |
nambvarun | 0:85792dec3d95 | 16 | //The mbed RPC classes are now wrapped to create an RPC enabled version - see RpcClasses.h so don't add to base class |
nambvarun | 0:85792dec3d95 | 17 | |
nambvarun | 0:85792dec3d95 | 18 | // receive commands, and send back the responses |
nambvarun | 0:85792dec3d95 | 19 | char buf[256], outbuf[256]; |
nambvarun | 0:85792dec3d95 | 20 | while(1) { |
nambvarun | 0:85792dec3d95 | 21 | pc.gets(buf, 256); |
nambvarun | 0:85792dec3d95 | 22 | //Call the static call method on the RPC class |
nambvarun | 0:85792dec3d95 | 23 | RPC::call(buf, outbuf); |
nambvarun | 0:85792dec3d95 | 24 | pc.printf("%s\n", outbuf); |
nambvarun | 0:85792dec3d95 | 25 | } |
nambvarun | 0:85792dec3d95 | 26 | } |