Quick Test Hack of the RPCInterface lib - it works for me!!
Dependencies: RPCInterface mbed
Fork of RPC_RangeFinderDemo by
Diff: main.cpp
- Revision:
- 3:29986d0e80da
- Parent:
- 2:9a7f340bf830
- Child:
- 4:7cc27231579b
--- a/main.cpp Wed Dec 19 10:44:10 2012 +0000 +++ b/main.cpp Wed Dec 19 12:16:14 2012 +0000 @@ -9,17 +9,14 @@ using namespace mbed; //Create the interface on the USB Serial Port -SerialRPCInterface RPC(USBTX, USBRX); -void ReadRange(char * input, char * output); -RPCFunction RangeFinder(&ReadRange, "RangeFinder"); -//SRF08 srf08(p9, p10, 0xE0); // Define SDA, SCL pin and I2C address +SerialRPCInterface RPC(USBTX, USBRX, 9600); // it defaults to 9600 if you don't put the baud Paramete in but I've put it in so can be changed +void SetTime(char * input, char * output); +RPCFunction TimeSet(&SetTime, "TimeSet"); DigitalOut myled(LED1); int main() { - while(1) { - - + while(1) { myled = 1; wait(0.2); myled = 0; @@ -27,24 +24,12 @@ } } -//As neither I2C nor the SRF08 library is avalible directly over RPC we create a Custom Function which we make RPCable by attaching to an RPCFunction -void ReadRange(char * input, char * output){ - //Format the output of the srf08 into the output string -// sprintf(output, "%f", srf08.read()); +// REM to call this function via RPC TimeSet +void SetTime(char * input, char * output){ + time_t time_value = time_t(input); + set_time(time_value); + time_t seconds = time(NULL); + sprintf(output, "\n Time as seconds since January 1, 1970 = %d\n", seconds); // puts String into "output" for SerialRPC to process and transmit } - -/* Code Frags -#include "RPCFunction.h" -void setTime(char * input, char * output); -RPCFunction rpc_setTime(&setTime, "setTime"); - -void setTime(char * input, char * output){ - int hours,mins,secs; - sscanf(input, "%i,%i,%i", &hours, &mins, &secs); - - //Use the hours, mins, secs variables to set the time here - - sprintf(ouput, "Anything you want to output here - you don't really need it"); - -*/ \ No newline at end of file + \ No newline at end of file