A test of creating custom classes for control over RPC. Creates an LED class with member functions callable over serial.

Dependencies:   mbed

Committer:
JimmyTheHack
Date:
Wed Sep 29 01:48:43 2010 +0000
Revision:
4:840f6002b8c2
separate header file to try to get documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimmyTheHack 4:840f6002b8c2 1 /* Test of custom RPC classes. An introduction to the RPC environment.
JimmyTheHack 4:840f6002b8c2 2
JimmyTheHack 4:840f6002b8c2 3 Based heavily off of code from iva2k
JimmyTheHack 4:840f6002b8c2 4 http://mbed.org/users/iva2k/programs/pub_iva2k_ethrpc/gpdz3x
JimmyTheHack 4:840f6002b8c2 5 in turn based off of servo library
JimmyTheHack 4:840f6002b8c2 6 http://mbed.org/projects/cookbook/svn/Servo/trunk/Servo.h
JimmyTheHack 4:840f6002b8c2 7 http://mbed.org/projects/cookbook/svn/Servo/trunk/Servo.cpp
JimmyTheHack 4:840f6002b8c2 8
JimmyTheHack 4:840f6002b8c2 9 This code features heavy copy-pasting, so I take little credit for the content. My goal was not to create original code, but to put together a basic introduction
JimmyTheHack 4:840f6002b8c2 10 to help myself and others understand how to implement custom classes in RPC.
JimmyTheHack 4:840f6002b8c2 11
JimmyTheHack 4:840f6002b8c2 12 This code creates a custom RPC class called LED. The LED class contains two member functions, toggle and blink.
JimmyTheHack 4:840f6002b8c2 13 Normally when compiling a program the original names of the objects are lost. In order to be able to call these functions by name after compiling, we must save the name in a string.
JimmyTheHack 4:840f6002b8c2 14 The name of our object and necessary arguments for the initialization function are saved using the get_rpc_class() function. The name of each member function and their arguments must also be
JimmyTheHack 4:840f6002b8c2 15 registered using get_rpc_methods().
JimmyTheHack 4:840f6002b8c2 16
JimmyTheHack 4:840f6002b8c2 17
JimmyTheHack 4:840f6002b8c2 18
JimmyTheHack 4:840f6002b8c2 19
JimmyTheHack 4:840f6002b8c2 20 From: http://mbed.org/cookbook/Interfacing-Using-RPC
JimmyTheHack 4:840f6002b8c2 21
JimmyTheHack 4:840f6002b8c2 22 RPC Commands are in the format: "/<Object name>/<Method name> <Arguments separated by spaces>
JimmyTheHack 4:840f6002b8c2 23 If you send just "/" mbed will return a list of objects that can be used
JimmyTheHack 4:840f6002b8c2 24 If you send "/<object name>/" then mbed will return the methods which can be used on this object.
JimmyTheHack 4:840f6002b8c2 25
JimmyTheHack 4:840f6002b8c2 26 I haven't finished digging through this yet, but I think most of the documentation for the RPC functions is in the files:
JimmyTheHack 4:840f6002b8c2 27 http://mbed.org/projects/libraries/svn/mbed/trunk/Base.h
JimmyTheHack 4:840f6002b8c2 28 http://mbed.org/projects/libraries/svn/mbed/trunk/rpc.h
JimmyTheHack 4:840f6002b8c2 29
JimmyTheHack 4:840f6002b8c2 30
JimmyTheHack 4:840f6002b8c2 31 */
JimmyTheHack 4:840f6002b8c2 32 /** Includes
JimmyTheHack 4:840f6002b8c2 33
JimmyTheHack 4:840f6002b8c2 34 *
JimmyTheHack 4:840f6002b8c2 35 */
JimmyTheHack 4:840f6002b8c2 36 #include "mbed.h"
JimmyTheHack 4:840f6002b8c2 37 #include "rpc.h"
JimmyTheHack 4:840f6002b8c2 38
JimmyTheHack 4:840f6002b8c2 39
JimmyTheHack 4:840f6002b8c2 40 /**Class: LED
JimmyTheHack 4:840f6002b8c2 41 *
JimmyTheHack 4:840f6002b8c2 42 *attached to an LED pin, contains simple blink functionality over serial
JimmyTheHack 4:840f6002b8c2 43 */
JimmyTheHack 4:840f6002b8c2 44 class LED :public Base { //make sure to define the class with inheritance from the Base RPC class.
JimmyTheHack 4:840f6002b8c2 45 public:
JimmyTheHack 4:840f6002b8c2 46 /**
JimmyTheHack 4:840f6002b8c2 47 *Constructor
JimmyTheHack 4:840f6002b8c2 48 */
JimmyTheHack 4:840f6002b8c2 49 LED(PinName mypin, const char *name=NULL);
JimmyTheHack 4:840f6002b8c2 50 /**Blink LED*/
JimmyTheHack 4:840f6002b8c2 51 void blink(int n);
JimmyTheHack 4:840f6002b8c2 52 /** switch state of LED*/
JimmyTheHack 4:840f6002b8c2 53 int toggle();
JimmyTheHack 4:840f6002b8c2 54 /** pin LED is attached to*/
JimmyTheHack 4:840f6002b8c2 55 DigitalOut LEDpin;
JimmyTheHack 4:840f6002b8c2 56 /**state of LED
JimmyTheHack 4:840f6002b8c2 57 */
JimmyTheHack 4:840f6002b8c2 58 int state;
JimmyTheHack 4:840f6002b8c2 59
JimmyTheHack 4:840f6002b8c2 60 #ifdef MBED_RPC //this code will not compile unless we have included the rpc.h file. So this class can also be used without RPC.
JimmyTheHack 4:840f6002b8c2 61 /**Defines the methods available over RPC*/
JimmyTheHack 4:840f6002b8c2 62 virtual const struct rpc_method *get_rpc_methods();
JimmyTheHack 4:840f6002b8c2 63 /**Defines the RPC class*/
JimmyTheHack 4:840f6002b8c2 64 static struct rpc_class *get_rpc_class();
JimmyTheHack 4:840f6002b8c2 65 #endif // MBED_RPC
JimmyTheHack 4:840f6002b8c2 66 };