STM32F103

Fork of mbed-rpc by Mbed

Committer:
mbed_official
Date:
Tue Nov 20 17:23:59 2012 +0000
Revision:
0:efe8172b4113
Child:
1:6919289a5946
mbed RPC

Who changed what in which revision?

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