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