solo procedo a publicacion, los cambios fueron minimos.

Fork of RPCInterface by Michael Walker

Committer:
sherckuith
Date:
Mon Nov 26 11:30:42 2012 +0000
Revision:
9:a19cb3dc071b
Parent:
6:f15d3610ddbe
RPC modificado para soporte de buffer a 2048;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherckuith 9:a19cb3dc071b 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:
sherckuith 9:a19cb3dc071b 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.
sherckuith 9:a19cb3dc071b 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
sherckuith 9:a19cb3dc071b 24 *This class provides an object to which a variable can be attached. Any type
sherckuith 9:a19cb3dc071b 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 */
sherckuith 9:a19cb3dc071b 29 #ifndef RPCVARIABLE_H_
sherckuith 9:a19cb3dc071b 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"
sherckuith 9:a19cb3dc071b 35 /**
sherckuith 9:a19cb3dc071b 36 *Class to read and set an attached variable using the RPC
sherckuith 9:a19cb3dc071b 37 *
sherckuith 9:a19cb3dc071b 38 */
MichaelW 5:56fd0b265aba 39 template<class T>
sherckuith 9:a19cb3dc071b 40 class RPCVariable : public Base
sherckuith 9:a19cb3dc071b 41 {
MichaelW 5:56fd0b265aba 42 public:
MichaelW 5:56fd0b265aba 43 /**
MichaelW 5:56fd0b265aba 44 * Constructor
sherckuith 9:a19cb3dc071b 45 *
sherckuith 9:a19cb3dc071b 46 *@param ptr Pointer to the variable to make accessible over RPC. Any type of
MichaelW 5:56fd0b265aba 47 *variable can be connected
MichaelW 5:56fd0b265aba 48 *@param name The name of that this object will be over RPC
MichaelW 5:56fd0b265aba 49 */
MichaelW 5:56fd0b265aba 50 template<class A>
sherckuith 9:a19cb3dc071b 51 RPCVariable(A * ptr, const char * name) : Base(name) {
MichaelW 5:56fd0b265aba 52 _ptr = ptr;
MichaelW 5:56fd0b265aba 53 }
MichaelW 5:56fd0b265aba 54 /**
MichaelW 5:56fd0b265aba 55 *Read the variable over RPC.
sherckuith 9:a19cb3dc071b 56 *
MichaelW 5:56fd0b265aba 57 *@return The value of the variable
MichaelW 5:56fd0b265aba 58 */
sherckuith 9:a19cb3dc071b 59 T read() {
MichaelW 5:56fd0b265aba 60 return(*_ptr);
MichaelW 5:56fd0b265aba 61 }
MichaelW 5:56fd0b265aba 62 /**
MichaelW 5:56fd0b265aba 63 *Write a value to the variable over RPC
sherckuith 9:a19cb3dc071b 64 *
MichaelW 5:56fd0b265aba 65 *@param The value to be written to the attached variable.
MichaelW 5:56fd0b265aba 66 */
sherckuith 9:a19cb3dc071b 67 void write(T value) {
MichaelW 5:56fd0b265aba 68 *_ptr = value;
MichaelW 5:56fd0b265aba 69 }
MichaelW 5:56fd0b265aba 70
sherckuith 9:a19cb3dc071b 71 #ifdef MBED_RPC
sherckuith 9:a19cb3dc071b 72 virtual const struct rpc_method *get_rpc_methods();
MichaelW 5:56fd0b265aba 73 static struct rpc_class *get_rpc_class();
sherckuith 9:a19cb3dc071b 74 #endif
MichaelW 5:56fd0b265aba 75
MichaelW 5:56fd0b265aba 76 private:
MichaelW 5:56fd0b265aba 77 T * _ptr;
sherckuith 9:a19cb3dc071b 78
MichaelW 5:56fd0b265aba 79 };
MichaelW 5:56fd0b265aba 80
MichaelW 5:56fd0b265aba 81 //Set up RPC methods
MichaelW 5:56fd0b265aba 82 #ifdef MBED_RPC
MichaelW 5:56fd0b265aba 83 template <class T>
sherckuith 9:a19cb3dc071b 84 const rpc_method *RPCVariable<T>::get_rpc_methods()
sherckuith 9:a19cb3dc071b 85 {
sherckuith 9:a19cb3dc071b 86 static const rpc_method rpc_methods[] = {
MichaelW 5:56fd0b265aba 87 { "read", rpc_method_caller<T, RPCVariable, &RPCVariable::read> },
MichaelW 5:56fd0b265aba 88 { "write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> },
MichaelW 5:56fd0b265aba 89 RPC_METHOD_SUPER(Base)
sherckuith 9:a19cb3dc071b 90 };
sherckuith 9:a19cb3dc071b 91 return rpc_methods;
sherckuith 9:a19cb3dc071b 92 }
sherckuith 9:a19cb3dc071b 93 template <class T>
sherckuith 9:a19cb3dc071b 94 rpc_class *RPCVariable<T>::get_rpc_class()
sherckuith 9:a19cb3dc071b 95 {
sherckuith 9:a19cb3dc071b 96 static const rpc_function funcs[] = {"new", rpc_function_caller<const char*, T,const char* , &Base::construct<RemoteVar, T ,const char*> >,RPC_METHOD_END};
sherckuith 9:a19cb3dc071b 97 static rpc_class c = { "RPCVariable", funcs, NULL };
sherckuith 9:a19cb3dc071b 98 return &c;
sherckuith 9:a19cb3dc071b 99 }
MichaelW 5:56fd0b265aba 100 #endif
MichaelW 5:56fd0b265aba 101
MichaelW 5:56fd0b265aba 102 //There could be specialisation for integer, to also give increment and decrements
MichaelW 5:56fd0b265aba 103
MichaelW 5:56fd0b265aba 104
MichaelW 4:05f0d66bee57 105 #endif //RPCVARIABLE_H_