Demo Application for the Celeritous Breakout Board

Dependencies:   mbed

Committer:
celeritous
Date:
Fri May 18 03:55:10 2012 +0000
Revision:
0:1a3da73fe36a
Celeritous_BreakoutBoardDemo

Who changed what in which revision?

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