Accepts RPC commands over bluetooth (RN42)

Dependencies:   mbed m3pi

Committer:
chris
Date:
Thu May 12 15:46:41 2011 +0000
Revision:
3:be428c849e1c

        

Who changed what in which revision?

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