Test

Dependencies:   C12832 MMA7660 RPCInterface mbed

Fork of RPC_Serial by Jonathan Caes

Committer:
JonathanCaes
Date:
Wed May 13 07:42:37 2015 +0000
Revision:
1:e245b0b4d96c
RPC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonathanCaes 1:e245b0b4d96c 1 /**
JonathanCaes 1:e245b0b4d96c 2 * @section LICENSE
JonathanCaes 1:e245b0b4d96c 3 *Copyright (c) 2010 ARM Ltd.
JonathanCaes 1:e245b0b4d96c 4 *
JonathanCaes 1:e245b0b4d96c 5 *Permission is hereby granted, free of charge, to any person obtaining a copy
JonathanCaes 1:e245b0b4d96c 6 *of this software and associated documentation files (the "Software"), to deal
JonathanCaes 1:e245b0b4d96c 7 *in the Software without restriction, including without limitation the rights
JonathanCaes 1:e245b0b4d96c 8 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
JonathanCaes 1:e245b0b4d96c 9 *copies of the Software, and to permit persons to whom the Software is
JonathanCaes 1:e245b0b4d96c 10 *furnished to do so, subject to the following conditions:
JonathanCaes 1:e245b0b4d96c 11 *
JonathanCaes 1:e245b0b4d96c 12 *The above copyright notice and this permission notice shall be included in
JonathanCaes 1:e245b0b4d96c 13 *all copies or substantial portions of the Software.
JonathanCaes 1:e245b0b4d96c 14 *
JonathanCaes 1:e245b0b4d96c 15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
JonathanCaes 1:e245b0b4d96c 16 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
JonathanCaes 1:e245b0b4d96c 17 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
JonathanCaes 1:e245b0b4d96c 18 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
JonathanCaes 1:e245b0b4d96c 19 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
JonathanCaes 1:e245b0b4d96c 20 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
JonathanCaes 1:e245b0b4d96c 21 *THE SOFTWARE.
JonathanCaes 1:e245b0b4d96c 22 *
JonathanCaes 1:e245b0b4d96c 23 *
JonathanCaes 1:e245b0b4d96c 24 * @section DESCRIPTION
JonathanCaes 1:e245b0b4d96c 25 *
JonathanCaes 1:e245b0b4d96c 26 *This class sets up RPC communication over serial.
JonathanCaes 1:e245b0b4d96c 27 */
JonathanCaes 1:e245b0b4d96c 28 #ifndef INTERFACE
JonathanCaes 1:e245b0b4d96c 29 #define INTERFACE
JonathanCaes 1:e245b0b4d96c 30
JonathanCaes 1:e245b0b4d96c 31 /**
JonathanCaes 1:e245b0b4d96c 32 *Includes
JonathanCaes 1:e245b0b4d96c 33 */
JonathanCaes 1:e245b0b4d96c 34 #include "mbed.h"
JonathanCaes 1:e245b0b4d96c 35 #include "platform.h"
JonathanCaes 1:e245b0b4d96c 36 #include "rpc.h"
JonathanCaes 1:e245b0b4d96c 37 #include "RPCFunction.h"
JonathanCaes 1:e245b0b4d96c 38 #include "RPCVariable.h"
JonathanCaes 1:e245b0b4d96c 39
JonathanCaes 1:e245b0b4d96c 40
JonathanCaes 1:e245b0b4d96c 41 namespace mbed{
JonathanCaes 1:e245b0b4d96c 42 /**
JonathanCaes 1:e245b0b4d96c 43 *Provides an Interface to mbed over RPC.
JonathanCaes 1:e245b0b4d96c 44 *
JonathanCaes 1:e245b0b4d96c 45 *For the chosen communication type this class sets up the necessary interrupts to receive RPC messages. Receives the messages, passes them to the rpc function and then returns the result.
JonathanCaes 1:e245b0b4d96c 46 */
JonathanCaes 1:e245b0b4d96c 47 class SerialRPCInterface{
JonathanCaes 1:e245b0b4d96c 48 public:
JonathanCaes 1:e245b0b4d96c 49 /**
JonathanCaes 1:e245b0b4d96c 50 *Constructor
JonathanCaes 1:e245b0b4d96c 51 *
JonathanCaes 1:e245b0b4d96c 52 *Sets up RPC communication using serial communication.
JonathanCaes 1:e245b0b4d96c 53 *
JonathanCaes 1:e245b0b4d96c 54 *@param tx The transmit pin of the serial port.
JonathanCaes 1:e245b0b4d96c 55 *@param rx The receive pin of the serial port.
JonathanCaes 1:e245b0b4d96c 56 *@param baud Set the baud rate, default is 9600.
JonathanCaes 1:e245b0b4d96c 57 */
JonathanCaes 1:e245b0b4d96c 58 SerialRPCInterface(PinName tx, PinName rx, int baud = 9600);
JonathanCaes 1:e245b0b4d96c 59
JonathanCaes 1:e245b0b4d96c 60 /**
JonathanCaes 1:e245b0b4d96c 61 *Disable the RPC.
JonathanCaes 1:e245b0b4d96c 62 *
JonathanCaes 1:e245b0b4d96c 63 *This will stop RPC messages being recevied and interpreted by this library. This might be used to prevent RPC commands interrupting an important piece of code on mbed.
JonathanCaes 1:e245b0b4d96c 64 */
JonathanCaes 1:e245b0b4d96c 65 void Disable(void);
JonathanCaes 1:e245b0b4d96c 66
JonathanCaes 1:e245b0b4d96c 67 /**
JonathanCaes 1:e245b0b4d96c 68 *Enable the RPC
JonathanCaes 1:e245b0b4d96c 69 *
JonathanCaes 1:e245b0b4d96c 70 *This will set this class to receiving and executing RPC commands. The class starts in this mode so this function only needs to be called if you have previosuly disabled the RPC.
JonathanCaes 1:e245b0b4d96c 71 *
JonathanCaes 1:e245b0b4d96c 72 */
JonathanCaes 1:e245b0b4d96c 73 void Enable(void);
JonathanCaes 1:e245b0b4d96c 74
JonathanCaes 1:e245b0b4d96c 75 //The Serial Port
JonathanCaes 1:e245b0b4d96c 76 Serial pc;
JonathanCaes 1:e245b0b4d96c 77
JonathanCaes 1:e245b0b4d96c 78
JonathanCaes 1:e245b0b4d96c 79 private:
JonathanCaes 1:e245b0b4d96c 80 //Handle messgaes and take appropriate action
JonathanCaes 1:e245b0b4d96c 81 void _MsgProcess(void);
JonathanCaes 1:e245b0b4d96c 82 void _RegClasses(void);
JonathanCaes 1:e245b0b4d96c 83 void _RPCSerial();
JonathanCaes 1:e245b0b4d96c 84 bool _enabled;
JonathanCaes 1:e245b0b4d96c 85 char _command[256];
JonathanCaes 1:e245b0b4d96c 86 char _response[256];
JonathanCaes 1:e245b0b4d96c 87 bool _RPCflag;
JonathanCaes 1:e245b0b4d96c 88 };
JonathanCaes 1:e245b0b4d96c 89 }
JonathanCaes 1:e245b0b4d96c 90 #endif