
http://mbed.org/users/okini3939/notebook/RPC_jp/
Revision 0:9b9a9bfadf9b, committed 2012-06-05
- Comitter:
- okini3939
- Date:
- Tue Jun 05 02:20:50 2012 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r 9b9a9bfadf9b MyRPC.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyRPC.cpp Tue Jun 05 02:20:50 2012 +0000 @@ -0,0 +1,48 @@ +/* + * sample from http://mbed.org/forum/mbed/topic/234/?page=1#comment-1067 + */ + +#include "MyRPC.h" +#ifdef MBED_RPC +#include "rpc.h" +#endif + +namespace mbed { + +MyRPC::MyRPC(PinName pin, const char *name) : Base(name), _pin(pin) {} + +void MyRPC::blink(int n) { + for (int i=0; i<n; i++) { + _pin = 1; + wait(0.2); + _pin = 0; + wait(0.2); + } +} + +int MyRPC::number() { + return rand(); +} + +#ifdef MBED_RPC +const rpc_method *MyRPC::get_rpc_methods() { + static const rpc_method rpc_methods[] = { + { "blink", rpc_method_caller<MyRPC, int, &MyRPC::blink>}, + { "number", rpc_method_caller<int, MyRPC, &MyRPC::number> }, + RPC_METHOD_SUPER(Base) + }; + return rpc_methods; +} + +rpc_class *MyRPC::get_rpc_class() { + static const rpc_function funcs[] = { + "new", rpc_function_caller<const char*, PinName, const char*, &Base::construct<MyRPC,PinName,const char*> >, + RPC_METHOD_END + }; + static rpc_class c = { "MyRPC", funcs, NULL }; + return &c; +} +#endif + +} // namespace mbed +
diff -r 000000000000 -r 9b9a9bfadf9b MyRPC.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyRPC.h Tue Jun 05 02:20:50 2012 +0000 @@ -0,0 +1,27 @@ +/* + * sample from http://mbed.org/forum/mbed/topic/234/?page=1#comment-1067 + */ + +#ifndef MYRPC_H +#define MYRPC_H + +#include "mbed.h" + +namespace mbed { + +class MyRPC : public Base { +public: + MyRPC(PinName pin, const char* name = NULL); + void blink(int n); + int number(); +#ifdef MBED_RPC + virtual const struct rpc_method *get_rpc_methods(); + static struct rpc_class *get_rpc_class(); +#endif // MBED_RPC + +protected: + DigitalOut _pin; +}; + +} // namespace mbed +#endif // MYRPC_H \ No newline at end of file
diff -r 000000000000 -r 9b9a9bfadf9b main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 05 02:20:50 2012 +0000 @@ -0,0 +1,18 @@ +#include "mbed.h" +#include "rpc.h" +#include "MyRPC.h" + +Serial pc(USBTX, USBRX); + +int main() { + // setup the classes that can be created dynamically + Base::add_rpc_class<MyRPC>(); + + // receive commands, and send back the responses + char buf[256], outbuf[256]; + while(1) { + pc.gets(buf, 256); + rpc(buf, outbuf); + pc.printf("%s\n", outbuf); + } +}
diff -r 000000000000 -r 9b9a9bfadf9b mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jun 05 02:20:50 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479