RTOS Support.

Dependents:   SerialRPC_rtos_example

Fork of RPCInterface by Michael Walker

Committer:
MichaelW
Date:
Mon Sep 27 08:32:57 2010 +0000
Revision:
4:05f0d66bee57
Parent:
1:67aefdc74b32
Child:
5:56fd0b265aba
Initial publish in new library format

Who changed what in which revision?

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