Trial updated library for RPCInterface. The original library by Michael Walker now includes this fix. The trial library here will be deleted shortly...

Dependents:   HTTPServerExample_LR WebServerRPC WebServerRPC_Mai19 12_06_22_correction_probleme

Committer:
hexley
Date:
Fri Feb 04 00:56:43 2011 +0000
Revision:
0:1c61049a0349
Memory leak addressed in RPCFunction.cpp

Who changed what in which revision?

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