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
|
*
|
PA |
0:a7276b35b90b
|
24
|
* @section DESCRIPTION
|
PA |
0:a7276b35b90b
|
25
|
*
|
PA |
0:a7276b35b90b
|
26
|
*This class sets up RPC communication. This allows objects on mbed to be controlled. Objects can be created or existing objects can be used
|
PA |
0:a7276b35b90b
|
27
|
*/
|
PA |
0:a7276b35b90b
|
28
|
#include "SerialRPCInterface.h"
|
PA |
0:a7276b35b90b
|
29
|
#include "UniPWM.h"
|
PA |
0:a7276b35b90b
|
30
|
#include "LEDFunctions.h"
|
PA |
0:a7276b35b90b
|
31
|
|
PA |
0:a7276b35b90b
|
32
|
using namespace mbed;
|
PA |
0:a7276b35b90b
|
33
|
|
PA |
0:a7276b35b90b
|
34
|
//Requires multiple contstructors for each type, serial to set different pin numbers, TCP for port.
|
PA |
0:a7276b35b90b
|
35
|
SerialRPCInterface::SerialRPCInterface(PinName tx, PinName rx, int baud):pc(tx, rx) {
|
PA |
0:a7276b35b90b
|
36
|
_RegClasses();
|
PA |
0:a7276b35b90b
|
37
|
_enabled = true;
|
PA |
0:a7276b35b90b
|
38
|
pc.attach(this, &SerialRPCInterface::_RPCSerial, Serial::RxIrq);
|
PA |
0:a7276b35b90b
|
39
|
if(baud != 9600)pc.baud(baud);
|
PA |
0:a7276b35b90b
|
40
|
}
|
PA |
0:a7276b35b90b
|
41
|
|
PA |
0:a7276b35b90b
|
42
|
void SerialRPCInterface::_RegClasses(void){
|
PA |
0:a7276b35b90b
|
43
|
//Register classes with base
|
PA |
0:a7276b35b90b
|
44
|
Base::add_rpc_class<AnalogIn>();
|
PA |
0:a7276b35b90b
|
45
|
Base::add_rpc_class<DigitalIn>();
|
PA |
0:a7276b35b90b
|
46
|
Base::add_rpc_class<DigitalOut>();
|
PA |
0:a7276b35b90b
|
47
|
Base::add_rpc_class<DigitalInOut>();
|
PA |
0:a7276b35b90b
|
48
|
Base::add_rpc_class<PwmOut>();
|
PA |
0:a7276b35b90b
|
49
|
Base::add_rpc_class<Timer>();
|
PA |
0:a7276b35b90b
|
50
|
Base::add_rpc_class<BusOut>();
|
PA |
0:a7276b35b90b
|
51
|
Base::add_rpc_class<BusIn>();
|
PA |
0:a7276b35b90b
|
52
|
Base::add_rpc_class<BusInOut>();
|
PA |
0:a7276b35b90b
|
53
|
Base::add_rpc_class<Serial>();
|
PA |
0:a7276b35b90b
|
54
|
|
PA |
0:a7276b35b90b
|
55
|
//Test
|
PA |
0:a7276b35b90b
|
56
|
//Base::add_rpc_class<UniPWM>();
|
PA |
0:a7276b35b90b
|
57
|
//Base::add_rpc_class<LEDFunctions>();
|
PA |
0:a7276b35b90b
|
58
|
|
PA |
0:a7276b35b90b
|
59
|
|
PA |
0:a7276b35b90b
|
60
|
//AnalogOut not avaliable on mbed LPC11U24 so only compile for other devices
|
PA |
0:a7276b35b90b
|
61
|
#if !defined(TARGET_LPC11U24)
|
PA |
0:a7276b35b90b
|
62
|
Base::add_rpc_class<AnalogOut>();
|
PA |
0:a7276b35b90b
|
63
|
#endif
|
PA |
0:a7276b35b90b
|
64
|
}
|
PA |
0:a7276b35b90b
|
65
|
|
PA |
0:a7276b35b90b
|
66
|
void SerialRPCInterface::Disable(void){
|
PA |
0:a7276b35b90b
|
67
|
_enabled = false;
|
PA |
0:a7276b35b90b
|
68
|
}
|
PA |
0:a7276b35b90b
|
69
|
void SerialRPCInterface::Enable(void){
|
PA |
0:a7276b35b90b
|
70
|
_enabled = true;
|
PA |
0:a7276b35b90b
|
71
|
}
|
PA |
0:a7276b35b90b
|
72
|
void SerialRPCInterface::_MsgProcess(void) {
|
PA |
0:a7276b35b90b
|
73
|
if(_enabled == true){
|
PA |
0:a7276b35b90b
|
74
|
rpc(_command, _response);
|
PA |
0:a7276b35b90b
|
75
|
}
|
PA |
0:a7276b35b90b
|
76
|
}
|
PA |
0:a7276b35b90b
|
77
|
|
PA |
0:a7276b35b90b
|
78
|
void SerialRPCInterface::_RPCSerial() {
|
PA |
0:a7276b35b90b
|
79
|
_RPCflag = true;
|
PA |
0:a7276b35b90b
|
80
|
if(_enabled == true){
|
PA |
0:a7276b35b90b
|
81
|
pc.gets(_command, 256);
|
PA |
0:a7276b35b90b
|
82
|
_MsgProcess();
|
PA |
0:a7276b35b90b
|
83
|
pc.printf("%s\n", _response);
|
PA |
0:a7276b35b90b
|
84
|
}
|
PA |
0:a7276b35b90b
|
85
|
_RPCflag = false;
|
PA |
0:a7276b35b90b
|
86
|
}
|