mbed RPC analogin working

Dependents:   RPC_Serial_new_v2

Fork of mbed-rpc by mbed official

Committer:
bhavik
Date:
Sun Jul 27 15:38:21 2014 +0000
Revision:
6:74c79d7abb89
Parent:
1:6919289a5946
biruu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:efe8172b4113 1 /* mbed Microcontroller Library
emilmont 1:6919289a5946 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 0:efe8172b4113 3 *
emilmont 1:6919289a5946 4 * Licensed under the Apache License, Version 2.0 (the "License");
emilmont 1:6919289a5946 5 * you may not use this file except in compliance with the License.
emilmont 1:6919289a5946 6 * You may obtain a copy of the License at
mbed_official 0:efe8172b4113 7 *
emilmont 1:6919289a5946 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 0:efe8172b4113 9 *
emilmont 1:6919289a5946 10 * Unless required by applicable law or agreed to in writing, software
emilmont 1:6919289a5946 11 * distributed under the License is distributed on an "AS IS" BASIS,
emilmont 1:6919289a5946 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
emilmont 1:6919289a5946 13 * See the License for the specific language governing permissions and
emilmont 1:6919289a5946 14 * limitations under the License.
mbed_official 0:efe8172b4113 15 */
mbed_official 0:efe8172b4113 16 #ifndef RPCVARIABLE_H_
mbed_official 0:efe8172b4113 17 #define RPCVARIABLE_H_
mbed_official 0:efe8172b4113 18
mbed_official 0:efe8172b4113 19 #include "rpc.h"
mbed_official 0:efe8172b4113 20
mbed_official 0:efe8172b4113 21 namespace mbed {
mbed_official 0:efe8172b4113 22
mbed_official 0:efe8172b4113 23 /**
mbed_official 0:efe8172b4113 24 *Class to read and set an attached variable using the RPC
mbed_official 0:efe8172b4113 25 *
mbed_official 0:efe8172b4113 26 */
mbed_official 0:efe8172b4113 27 template<class T>
mbed_official 0:efe8172b4113 28 class RPCVariable: public RPC {
mbed_official 0:efe8172b4113 29 public:
mbed_official 0:efe8172b4113 30 /**
mbed_official 0:efe8172b4113 31 * Constructor
emilmont 1:6919289a5946 32 *
emilmont 1:6919289a5946 33 *@param ptr Pointer to the variable to make accessible over RPC. Any type of
mbed_official 0:efe8172b4113 34 *variable can be connected
mbed_official 0:efe8172b4113 35 *@param name The name of that this object will be over RPC
mbed_official 0:efe8172b4113 36 */
mbed_official 0:efe8172b4113 37 template<class A>
mbed_official 0:efe8172b4113 38 RPCVariable(A * ptr, const char * name) : RPC(name) {
mbed_official 0:efe8172b4113 39 _ptr = ptr;
mbed_official 0:efe8172b4113 40 }
mbed_official 0:efe8172b4113 41 /**
mbed_official 0:efe8172b4113 42 *Read the variable over RPC.
emilmont 1:6919289a5946 43 *
mbed_official 0:efe8172b4113 44 *@return The value of the variable
mbed_official 0:efe8172b4113 45 */
mbed_official 0:efe8172b4113 46 T read() {
mbed_official 0:efe8172b4113 47 return (*_ptr);
mbed_official 0:efe8172b4113 48 }
mbed_official 0:efe8172b4113 49 /**
mbed_official 0:efe8172b4113 50 *Write a value to the variable over RPC
emilmont 1:6919289a5946 51 *
mbed_official 0:efe8172b4113 52 *@param The value to be written to the attached variable.
mbed_official 0:efe8172b4113 53 */
mbed_official 0:efe8172b4113 54 void write(T value) {
mbed_official 0:efe8172b4113 55 *_ptr = value;
mbed_official 0:efe8172b4113 56 }
emilmont 1:6919289a5946 57
mbed_official 0:efe8172b4113 58 virtual const struct rpc_method *get_rpc_methods();
mbed_official 0:efe8172b4113 59 static struct rpc_class *get_rpc_class();
mbed_official 0:efe8172b4113 60
mbed_official 0:efe8172b4113 61 private:
mbed_official 0:efe8172b4113 62 T * _ptr;
mbed_official 0:efe8172b4113 63 };
mbed_official 0:efe8172b4113 64
mbed_official 0:efe8172b4113 65 template<class T>
mbed_official 0:efe8172b4113 66 const rpc_method *RPCVariable<T>::get_rpc_methods() {
mbed_official 0:efe8172b4113 67 static const rpc_method rpc_methods[] = {
mbed_official 0:efe8172b4113 68 {"read" , rpc_method_caller<T, RPCVariable, &RPCVariable::read> },
mbed_official 0:efe8172b4113 69 {"write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> },
mbed_official 0:efe8172b4113 70 RPC_METHOD_SUPER(RPC)
mbed_official 0:efe8172b4113 71 };
mbed_official 0:efe8172b4113 72 return rpc_methods;
mbed_official 0:efe8172b4113 73 }
mbed_official 0:efe8172b4113 74
mbed_official 0:efe8172b4113 75 template<class T>
mbed_official 0:efe8172b4113 76 rpc_class *RPCVariable<T>::get_rpc_class() {
mbed_official 0:efe8172b4113 77 static const rpc_function funcs[] = {
mbed_official 0:efe8172b4113 78 "new", rpc_function_caller<const char*, T, const char*, &RPC::construct<RPCVariable, T, const char*> > ,
mbed_official 0:efe8172b4113 79 RPC_METHOD_END
mbed_official 0:efe8172b4113 80 };
mbed_official 0:efe8172b4113 81 static rpc_class c = {"RPCVariable", funcs, NULL};
mbed_official 0:efe8172b4113 82 return &c;
mbed_official 0:efe8172b4113 83 }
mbed_official 0:efe8172b4113 84
mbed_official 0:efe8172b4113 85 }
mbed_official 0:efe8172b4113 86
mbed_official 0:efe8172b4113 87 #endif //RPCVARIABLE_H_