Library to provide a mechanism to make it easier to add RPC to custom code by using RPCFunction and RPCVariable objects. Also includes a class to receive and process RPC over serial.

Dependencies:   mbed-rpc-3

Dependents:   eMPC_Simulator-v1 eMPC_Simulator_v6

Committer:
MichaelW
Date:
Thu Sep 16 13:27:57 2010 +0000
Revision:
0:9232f9e1178d
Child:
1:67aefdc74b32
Changed to RPCFunction and RPCVariable.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MichaelW 0:9232f9e1178d 1 /**
MichaelW 0:9232f9e1178d 2 *@section LICENSE
MichaelW 0:9232f9e1178d 3 *Copyright (c) 2010 ARM Ltd.
MichaelW 0:9232f9e1178d 4 *
MichaelW 0:9232f9e1178d 5 *Permission is hereby granted, free of charge, to any person obtaining a copy
MichaelW 0:9232f9e1178d 6 *of this software and associated documentation files (the "Software"), to deal
MichaelW 0:9232f9e1178d 7 *in the Software without restriction, including without limitation the rights
MichaelW 0:9232f9e1178d 8 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
MichaelW 0:9232f9e1178d 9 *copies of the Software, and to permit persons to whom the Software is
MichaelW 0:9232f9e1178d 10 *furnished to do so, subject to the following conditions:
MichaelW 0:9232f9e1178d 11 *
MichaelW 0:9232f9e1178d 12 *The above copyright notice and this permission notice shall be included in
MichaelW 0:9232f9e1178d 13 *all copies or substantial portions of the Software.
MichaelW 0:9232f9e1178d 14 *
MichaelW 0:9232f9e1178d 15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MichaelW 0:9232f9e1178d 16 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MichaelW 0:9232f9e1178d 17 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
MichaelW 0:9232f9e1178d 18 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MichaelW 0:9232f9e1178d 19 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
MichaelW 0:9232f9e1178d 20 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
MichaelW 0:9232f9e1178d 21 *THE SOFTWARE.
MichaelW 0:9232f9e1178d 22 *
MichaelW 0:9232f9e1178d 23 *
MichaelW 0:9232f9e1178d 24 @section DESCRIPTION
MichaelW 0:9232f9e1178d 25 *
MichaelW 0:9232f9e1178d 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
MichaelW 0:9232f9e1178d 27 */
MichaelW 0:9232f9e1178d 28 #include "SerialRPCInterface.h"
MichaelW 0:9232f9e1178d 29
MichaelW 0:9232f9e1178d 30 using namespace mbed;
MichaelW 0:9232f9e1178d 31
MichaelW 0:9232f9e1178d 32 //Requires multiple contstructors for each type, serial to set different pin numbers, TCP for port.
MichaelW 0:9232f9e1178d 33 SerialRPCInterface::SerialRPCInterface(PinName tx, PinName rx, int baud):pc(tx, rx) {
MichaelW 0:9232f9e1178d 34 _RegClasses();
MichaelW 0:9232f9e1178d 35 _enabled = true;
MichaelW 0:9232f9e1178d 36 pc.attach(this, &SerialRPCInterface::_RPCSerial, Serial::RxIrq);
MichaelW 0:9232f9e1178d 37 if(baud != 9600)pc.baud(baud);
MichaelW 0:9232f9e1178d 38 }
MichaelW 0:9232f9e1178d 39
MichaelW 0:9232f9e1178d 40 void SerialRPCInterface::_RegClasses(void){
MichaelW 0:9232f9e1178d 41 //Register classes with base
MichaelW 0:9232f9e1178d 42 Base::add_rpc_class<AnalogIn>();
MichaelW 0:9232f9e1178d 43 Base::add_rpc_class<AnalogOut>();
MichaelW 0:9232f9e1178d 44 Base::add_rpc_class<DigitalIn>();
MichaelW 0:9232f9e1178d 45 Base::add_rpc_class<DigitalOut>();
MichaelW 0:9232f9e1178d 46 Base::add_rpc_class<DigitalInOut>();
MichaelW 0:9232f9e1178d 47 Base::add_rpc_class<PwmOut>();
MichaelW 0:9232f9e1178d 48 Base::add_rpc_class<Timer>();
MichaelW 0:9232f9e1178d 49 Base::add_rpc_class<BusOut>();
MichaelW 0:9232f9e1178d 50 Base::add_rpc_class<BusIn>();
MichaelW 0:9232f9e1178d 51 Base::add_rpc_class<BusInOut>();
MichaelW 0:9232f9e1178d 52 Base::add_rpc_class<Serial>();
MichaelW 0:9232f9e1178d 53 }
MichaelW 0:9232f9e1178d 54
MichaelW 0:9232f9e1178d 55 void SerialRPCInterface::Disable(void){
MichaelW 0:9232f9e1178d 56 _enabled = false;
MichaelW 0:9232f9e1178d 57 }
MichaelW 0:9232f9e1178d 58 void SerialRPCInterface::Enable(void){
MichaelW 0:9232f9e1178d 59 _enabled = true;
MichaelW 0:9232f9e1178d 60 }
MichaelW 0:9232f9e1178d 61 void SerialRPCInterface::_MsgProcess(void) {
MichaelW 0:9232f9e1178d 62 if(_enabled == true){
MichaelW 0:9232f9e1178d 63 rpc(_command, _response);
MichaelW 0:9232f9e1178d 64 }
MichaelW 0:9232f9e1178d 65 }
MichaelW 0:9232f9e1178d 66
MichaelW 0:9232f9e1178d 67 void SerialRPCInterface::_RPCSerial() {
MichaelW 0:9232f9e1178d 68 _RPCflag = true;
MichaelW 0:9232f9e1178d 69 if(_enabled == true){
MichaelW 0:9232f9e1178d 70 pc.gets(_command, 256);
MichaelW 0:9232f9e1178d 71 _MsgProcess();
MichaelW 0:9232f9e1178d 72 pc.printf("%s\n", _response);
MichaelW 0:9232f9e1178d 73 }
MichaelW 0:9232f9e1178d 74 _RPCflag = false;
MichaelW 0:9232f9e1178d 75 }
MichaelW 0:9232f9e1178d 76