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