Made changes to mbed-rpc

Dependencies:   mbed-rpc

Fork of RPCInterface by Michael Walker

Committer:
Nydrel
Date:
Tue May 01 07:45:42 2018 +0000
Revision:
12:4fce2f9535b2
Parent:
10:9d82e28ffaea
Made changes to mbed-rpc library (support for *char)

Who changed what in which revision?

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