Capstone project for Bachelor's in Mechanical Engineering 2011

Dependencies:   FatFileSystem MAX3100 MODGPS MODSERIAL SDFileSystem mbed

Committer:
lhiggs
Date:
Wed May 29 00:45:41 2013 +0000
Revision:
0:0529d2d7762f
Broken, after updating all the libraries. RPC has issues with new mbed libraries.

Who changed what in which revision?

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