Project_Embedded_C

Dependencies:   mbed DS1307 Servo TextLCD

Committer:
rikvandyck
Date:
Thu Dec 18 10:43:07 2014 +0000
Revision:
2:55b6fd49b738
Parent:
0:e1edd52b1ee2
Project_Embedded_C

Who changed what in which revision?

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