Labview
Dependencies: C12832_lcd LCD_fonts LM75B analogintest3 MMA7660 mbed
Fork of analogintest3 by
RPCInterface/SerialRPCInterface.cpp@1:6c1caefc30c3, 2015-05-19 (annotated)
- Committer:
- Bramvr
- Date:
- Tue May 19 11:20:51 2015 +0000
- Revision:
- 1:6c1caefc30c3
- Parent:
- 0:e4782112c3fd
Labview
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 | * |
u0068206 | 0:e4782112c3fd | 24 | * @section DESCRIPTION |
u0068206 | 0:e4782112c3fd | 25 | * |
u0068206 | 0:e4782112c3fd | 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 |
u0068206 | 0:e4782112c3fd | 27 | */ |
u0068206 | 0:e4782112c3fd | 28 | #include "SerialRPCInterface.h" |
u0068206 | 0:e4782112c3fd | 29 | |
u0068206 | 0:e4782112c3fd | 30 | using namespace mbed; |
u0068206 | 0:e4782112c3fd | 31 | |
u0068206 | 0:e4782112c3fd | 32 | //Requires multiple contstructors for each type, serial to set different pin numbers, TCP for port. |
u0068206 | 0:e4782112c3fd | 33 | SerialRPCInterface::SerialRPCInterface(PinName tx, PinName rx, int baud):pc(tx, rx) { |
u0068206 | 0:e4782112c3fd | 34 | _RegClasses(); |
u0068206 | 0:e4782112c3fd | 35 | _enabled = true; |
u0068206 | 0:e4782112c3fd | 36 | pc.attach(this, &SerialRPCInterface::_RPCSerial, Serial::RxIrq); |
u0068206 | 0:e4782112c3fd | 37 | if(baud != 9600)pc.baud(baud); |
u0068206 | 0:e4782112c3fd | 38 | } |
u0068206 | 0:e4782112c3fd | 39 | |
u0068206 | 0:e4782112c3fd | 40 | void SerialRPCInterface::_RegClasses(void){ |
u0068206 | 0:e4782112c3fd | 41 | //Register classes with base |
u0068206 | 0:e4782112c3fd | 42 | Base::add_rpc_class<AnalogIn>(); |
u0068206 | 0:e4782112c3fd | 43 | Base::add_rpc_class<DigitalIn>(); |
u0068206 | 0:e4782112c3fd | 44 | Base::add_rpc_class<DigitalOut>(); |
u0068206 | 0:e4782112c3fd | 45 | Base::add_rpc_class<DigitalInOut>(); |
u0068206 | 0:e4782112c3fd | 46 | Base::add_rpc_class<PwmOut>(); |
u0068206 | 0:e4782112c3fd | 47 | Base::add_rpc_class<Timer>(); |
u0068206 | 0:e4782112c3fd | 48 | Base::add_rpc_class<BusOut>(); |
u0068206 | 0:e4782112c3fd | 49 | Base::add_rpc_class<BusIn>(); |
u0068206 | 0:e4782112c3fd | 50 | Base::add_rpc_class<BusInOut>(); |
u0068206 | 0:e4782112c3fd | 51 | Base::add_rpc_class<Serial>(); |
u0068206 | 0:e4782112c3fd | 52 | |
u0068206 | 0:e4782112c3fd | 53 | //AnalogOut not avaliable on mbed LPC11U24 so only compile for other devices |
u0068206 | 0:e4782112c3fd | 54 | #if !defined(TARGET_LPC11U24) |
u0068206 | 0:e4782112c3fd | 55 | Base::add_rpc_class<AnalogOut>(); |
u0068206 | 0:e4782112c3fd | 56 | #endif |
u0068206 | 0:e4782112c3fd | 57 | } |
u0068206 | 0:e4782112c3fd | 58 | |
u0068206 | 0:e4782112c3fd | 59 | void SerialRPCInterface::Disable(void){ |
u0068206 | 0:e4782112c3fd | 60 | _enabled = false; |
u0068206 | 0:e4782112c3fd | 61 | } |
u0068206 | 0:e4782112c3fd | 62 | void SerialRPCInterface::Enable(void){ |
u0068206 | 0:e4782112c3fd | 63 | _enabled = true; |
u0068206 | 0:e4782112c3fd | 64 | } |
u0068206 | 0:e4782112c3fd | 65 | void SerialRPCInterface::_MsgProcess(void) { |
u0068206 | 0:e4782112c3fd | 66 | if(_enabled == true){ |
u0068206 | 0:e4782112c3fd | 67 | rpc(_command, _response); |
u0068206 | 0:e4782112c3fd | 68 | } |
u0068206 | 0:e4782112c3fd | 69 | } |
u0068206 | 0:e4782112c3fd | 70 | |
u0068206 | 0:e4782112c3fd | 71 | void SerialRPCInterface::_RPCSerial() { |
u0068206 | 0:e4782112c3fd | 72 | _RPCflag = true; |
u0068206 | 0:e4782112c3fd | 73 | if(_enabled == true){ |
u0068206 | 0:e4782112c3fd | 74 | pc.gets(_command, 256); |
u0068206 | 0:e4782112c3fd | 75 | _MsgProcess(); |
u0068206 | 0:e4782112c3fd | 76 | pc.printf("%s\n", _response); |
u0068206 | 0:e4782112c3fd | 77 | } |
u0068206 | 0:e4782112c3fd | 78 | _RPCflag = false; |
u0068206 | 0:e4782112c3fd | 79 | } |