RPCInterface

Fork of RPCInterface by Michael Walker

Committer:
MichaelW
Date:
Sat Jan 28 19:12:00 2012 +0000
Revision:
8:682c65afe534
Parent:
6:f15d3610ddbe
Updated to not register AnalogOut class if the LPC11U24 as it doesn\t have AnalogOut

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MichaelW 5:56fd0b265aba 1 /**
MichaelW 5:56fd0b265aba 2 * @section LICENSE
MichaelW 5:56fd0b265aba 3 *Copyright (c) 2010 ARM Ltd.
MichaelW 5:56fd0b265aba 4 *
MichaelW 5:56fd0b265aba 5 *Permission is hereby granted, free of charge, to any person obtaining a copy
MichaelW 5:56fd0b265aba 6 *of this software and associated documentation files (the "Software"), to deal
MichaelW 5:56fd0b265aba 7 *in the Software without restriction, including without limitation the rights
MichaelW 5:56fd0b265aba 8 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
MichaelW 5:56fd0b265aba 9 *copies of the Software, and to permit persons to whom the Software is
MichaelW 5:56fd0b265aba 10 *furnished to do so, subject to the following conditions:
MichaelW 5:56fd0b265aba 11 *
MichaelW 5:56fd0b265aba 12 *The above copyright notice and this permission notice shall be included in
MichaelW 5:56fd0b265aba 13 *all copies or substantial portions of the Software.
MichaelW 5:56fd0b265aba 14 *
MichaelW 5:56fd0b265aba 15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MichaelW 5:56fd0b265aba 16 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MichaelW 5:56fd0b265aba 17 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
MichaelW 5:56fd0b265aba 18 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MichaelW 5:56fd0b265aba 19 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
MichaelW 5:56fd0b265aba 20 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
MichaelW 5:56fd0b265aba 21 *THE SOFTWARE.
MichaelW 5:56fd0b265aba 22 *
MichaelW 5:56fd0b265aba 23 * @section Description
MichaelW 5:56fd0b265aba 24 *This class provides an object to which a variable can be attached. Any type
MichaelW 5:56fd0b265aba 25 *for which a parse_args function specilisation exists can be attached. This includes
MichaelW 5:56fd0b265aba 26 *all of the standard types.
MichaelW 5:56fd0b265aba 27 *
MichaelW 5:56fd0b265aba 28 */
MichaelW 5:56fd0b265aba 29 #ifndef RPCVARIABLE_H_
MichaelW 5:56fd0b265aba 30 #define RPCVARIABLE_H_
MichaelW 6:f15d3610ddbe 31
MichaelW 5:56fd0b265aba 32 #include "mbed.h"
MichaelW 5:56fd0b265aba 33 #include "platform.h"
MichaelW 5:56fd0b265aba 34 #include "rpc.h"
MichaelW 5:56fd0b265aba 35 /**
MichaelW 5:56fd0b265aba 36 *Class to read and set an attached variable using the RPC
MichaelW 5:56fd0b265aba 37 *
MichaelW 5:56fd0b265aba 38 */
MichaelW 5:56fd0b265aba 39 template<class T>
MichaelW 5:56fd0b265aba 40 class RPCVariable : public Base{
MichaelW 5:56fd0b265aba 41 public:
MichaelW 5:56fd0b265aba 42 /**
MichaelW 5:56fd0b265aba 43 * Constructor
MichaelW 5:56fd0b265aba 44 *
MichaelW 5:56fd0b265aba 45 *@param ptr Pointer to the variable to make accessible over RPC. Any type of
MichaelW 5:56fd0b265aba 46 *variable can be connected
MichaelW 5:56fd0b265aba 47 *@param name The name of that this object will be over RPC
MichaelW 5:56fd0b265aba 48 */
MichaelW 5:56fd0b265aba 49 template<class A>
MichaelW 5:56fd0b265aba 50 RPCVariable(A * ptr, const char * name) : Base(name){
MichaelW 5:56fd0b265aba 51 _ptr = ptr;
MichaelW 5:56fd0b265aba 52 }
MichaelW 5:56fd0b265aba 53 /**
MichaelW 5:56fd0b265aba 54 *Read the variable over RPC.
MichaelW 5:56fd0b265aba 55 *
MichaelW 5:56fd0b265aba 56 *@return The value of the variable
MichaelW 5:56fd0b265aba 57 */
MichaelW 5:56fd0b265aba 58 T read(){
MichaelW 5:56fd0b265aba 59 return(*_ptr);
MichaelW 5:56fd0b265aba 60 }
MichaelW 5:56fd0b265aba 61 /**
MichaelW 5:56fd0b265aba 62 *Write a value to the variable over RPC
MichaelW 5:56fd0b265aba 63 *
MichaelW 5:56fd0b265aba 64 *@param The value to be written to the attached variable.
MichaelW 5:56fd0b265aba 65 */
MichaelW 5:56fd0b265aba 66 void write(T value){
MichaelW 5:56fd0b265aba 67 *_ptr = value;
MichaelW 5:56fd0b265aba 68 }
MichaelW 5:56fd0b265aba 69
MichaelW 5:56fd0b265aba 70 #ifdef MBED_RPC
MichaelW 5:56fd0b265aba 71 virtual const struct rpc_method *get_rpc_methods();
MichaelW 5:56fd0b265aba 72 static struct rpc_class *get_rpc_class();
MichaelW 5:56fd0b265aba 73 #endif
MichaelW 5:56fd0b265aba 74
MichaelW 5:56fd0b265aba 75 private:
MichaelW 5:56fd0b265aba 76 T * _ptr;
MichaelW 5:56fd0b265aba 77
MichaelW 5:56fd0b265aba 78 };
MichaelW 5:56fd0b265aba 79
MichaelW 5:56fd0b265aba 80 //Set up RPC methods
MichaelW 5:56fd0b265aba 81 #ifdef MBED_RPC
MichaelW 5:56fd0b265aba 82 template <class T>
MichaelW 5:56fd0b265aba 83 const rpc_method *RPCVariable<T>::get_rpc_methods() {
MichaelW 5:56fd0b265aba 84 static const rpc_method rpc_methods[] = {
MichaelW 5:56fd0b265aba 85 { "read", rpc_method_caller<T, RPCVariable, &RPCVariable::read> },
MichaelW 5:56fd0b265aba 86 { "write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> },
MichaelW 5:56fd0b265aba 87 RPC_METHOD_SUPER(Base)
MichaelW 5:56fd0b265aba 88 };
MichaelW 5:56fd0b265aba 89 return rpc_methods;
MichaelW 5:56fd0b265aba 90 }
MichaelW 5:56fd0b265aba 91 template <class T>
MichaelW 5:56fd0b265aba 92 rpc_class *RPCVariable<T>::get_rpc_class() {
MichaelW 5:56fd0b265aba 93 static const rpc_function funcs[] = {"new", rpc_function_caller<const char*, T,const char* , &Base::construct<RemoteVar, T ,const char*> >,RPC_METHOD_END};
MichaelW 5:56fd0b265aba 94 static rpc_class c = { "RPCVariable", funcs, NULL };
MichaelW 5:56fd0b265aba 95 return &c;
MichaelW 5:56fd0b265aba 96 }
MichaelW 5:56fd0b265aba 97 #endif
MichaelW 5:56fd0b265aba 98
MichaelW 5:56fd0b265aba 99 //There could be specialisation for integer, to also give increment and decrements
MichaelW 5:56fd0b265aba 100
MichaelW 5:56fd0b265aba 101
MichaelW 4:05f0d66bee57 102 #endif //RPCVARIABLE_H_