Tyari Taylor
/
OS-RPC_Serial
operational RPC with OS5
Fork of OS-RPC_Serial by
main.cpp@68:49b8d619795d, 2018-08-23 (annotated)
- Committer:
- Tyari21
- Date:
- Thu Aug 23 14:06:05 2018 +0000
- Revision:
- 68:49b8d619795d
- Parent:
- 67:f3ca708f5187
operational RC with OS 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
0:2757d7abb7d9 | 1 | #include "mbed.h" |
billcooke51 | 67:f3ca708f5187 | 2 | #include "SerialRPCInterface.h" |
Tyari21 | 68:49b8d619795d | 3 | #include "mbed_rpc.h" |
billcooke51 | 67:f3ca708f5187 | 4 | |
billcooke51 | 67:f3ca708f5187 | 5 | Serial pc(USBTX, USBRX); |
billcooke51 | 67:f3ca708f5187 | 6 | |
billcooke51 | 67:f3ca708f5187 | 7 | // Define some Digit outputs to address via Serial |
billcooke51 | 67:f3ca708f5187 | 8 | RpcDigitalOut myled1(LED1,"myled1"); |
billcooke51 | 67:f3ca708f5187 | 9 | RpcDigitalOut myled2(LED2,"myled2"); |
billcooke51 | 67:f3ca708f5187 | 10 | RpcDigitalOut myled3(LED3,"myled3"); |
billcooke51 | 67:f3ca708f5187 | 11 | RpcDigitalOut myled4(LED4,"myled4"); |
Jonathan Austin |
0:2757d7abb7d9 | 12 | |
billcooke51 | 67:f3ca708f5187 | 13 | // Define a function to address via Serial |
billcooke51 | 67:f3ca708f5187 | 14 | void BCmult(Arguments *input, Reply *output); |
billcooke51 | 67:f3ca708f5187 | 15 | RPCFunction rpcScale(&BCmult, "BCmult"); |
billcooke51 | 67:f3ca708f5187 | 16 | // This makes x and y global, so they can be changed in BCmult |
billcooke51 | 67:f3ca708f5187 | 17 | int x,y; |
billcooke51 | 67:f3ca708f5187 | 18 | // Define some variables to address via Serial |
billcooke51 | 67:f3ca708f5187 | 19 | RPCVariable<int> rpcLights(&x, "x"); |
billcooke51 | 67:f3ca708f5187 | 20 | RPCVariable<int> rpcBanner(&y, "y"); |
Jonathan Austin |
0:2757d7abb7d9 | 21 | |
billcooke51 | 67:f3ca708f5187 | 22 | void BCmult(Arguments *in, Reply *out) { |
billcooke51 | 67:f3ca708f5187 | 23 | //int x,y; |
billcooke51 | 67:f3ca708f5187 | 24 | char buffer[200]; |
billcooke51 | 67:f3ca708f5187 | 25 | x = in->getArg<int>(); |
billcooke51 | 67:f3ca708f5187 | 26 | y = in->getArg<int>(); |
billcooke51 | 67:f3ca708f5187 | 27 | x = 2*x; |
billcooke51 | 67:f3ca708f5187 | 28 | y = 3*y; |
billcooke51 | 67:f3ca708f5187 | 29 | sprintf(buffer, "%i, %i\n", x, y ); |
billcooke51 | 67:f3ca708f5187 | 30 | out->putData(buffer); |
billcooke51 | 67:f3ca708f5187 | 31 | } |
Jonathan Austin |
0:2757d7abb7d9 | 32 | int main() { |
Tyari21 | 68:49b8d619795d | 33 | pc.printf("starting..."); |
billcooke51 | 67:f3ca708f5187 | 34 | char buf[256], outbuf[256]; |
billcooke51 | 67:f3ca708f5187 | 35 | while(1) { |
billcooke51 | 67:f3ca708f5187 | 36 | pc.gets(buf, 256); |
billcooke51 | 67:f3ca708f5187 | 37 | RPC::call(buf, outbuf); |
billcooke51 | 67:f3ca708f5187 | 38 | // Print the response |
billcooke51 | 67:f3ca708f5187 | 39 | pc.printf("%s\n", outbuf); |
Jonathan Austin |
0:2757d7abb7d9 | 40 | } |
Jonathan Austin |
0:2757d7abb7d9 | 41 | } |
Jonathan Austin |
1:846c97078558 | 42 |