RTOS Support.

Dependents:   SerialRPC_rtos_example

Fork of RPCInterface by Michael Walker

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SerialRPCInterface.h Source File

SerialRPCInterface.h

00001 /**
00002 * @section LICENSE
00003 *Copyright (c) 2010 ARM Ltd.
00004 *
00005 *Permission is hereby granted, free of charge, to any person obtaining a copy
00006 *of this software and associated documentation files (the "Software"), to deal
00007 *in the Software without restriction, including without limitation the rights
00008 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 *copies of the Software, and to permit persons to whom the Software is
00010 *furnished to do so, subject to the following conditions:
00011 * 
00012 *The above copyright notice and this permission notice shall be included in
00013 *all copies or substantial portions of the Software.
00014 * 
00015 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 *THE SOFTWARE.
00022 * 
00023 *
00024 * @section DESCRIPTION
00025 *
00026 *This class sets up RPC communication over serial.
00027 */
00028 #ifndef INTERFACE
00029 #define INTERFACE
00030 
00031 /**
00032 *Includes
00033 */
00034 #include "mbed.h"
00035 #include "rtos.h"
00036 #include "platform.h"
00037 #include "rpc.h"
00038 #include "RPCFunction.h"
00039 #include "RPCVariable.h"
00040 #include "RpcClasses.h"
00041 
00042 #define PROCESS_THREAD 1
00043 
00044 
00045 namespace mbed{
00046 /**
00047 *Provides an Interface to mbed over RPC. 
00048 * 
00049 *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.
00050 */
00051 class SerialRPCInterface{
00052 public:
00053     /**
00054     *Constructor
00055     *
00056     *Sets up RPC communication using serial communication.
00057     *
00058     *@param tx The transmit pin of the serial port.
00059     *@param rx The receive pin of the serial port. 
00060     *@param baud Set the baud rate, default is 9600.
00061     */
00062     SerialRPCInterface(PinName tx, PinName rx, int baud = 9600);
00063  
00064     /**
00065     *Disable the RPC. 
00066     * 
00067     *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.
00068     */
00069     void Disable(void);
00070     
00071     /**
00072     *Enable the RPC
00073     * 
00074     *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.
00075     *
00076     */
00077     void Enable(void);
00078     
00079     //The Serial Port
00080     RawSerial pc;
00081     
00082 
00083 private:
00084     typedef struct {
00085         char command[256];
00086     } mail_t;
00087 
00088     //Handle messgaes and take appropriate action
00089     static void _MsgProcessStarter(const void *args);
00090     void _MsgProcess(void);
00091     void _RegClasses(void);
00092     void _RPCSerial();
00093     bool _enabled;
00094     char _command[256];
00095     char* _command_ptr;
00096     char _response[256];
00097     bool _RPCflag;
00098     Thread _thread;
00099     Mail<mail_t, 8> _commandMail;
00100 };
00101 }
00102 #endif