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 * @section Description
chris 3:be428c849e1c 24 *This class provides an object which can be called over RPC to run the function which is attached to it.
chris 3:be428c849e1c 25 *
chris 3:be428c849e1c 26 */
chris 3:be428c849e1c 27 #ifndef RPCFUNCTION_RPC
chris 3:be428c849e1c 28 #define RPCFUNCTION_RPC
chris 3:be428c849e1c 29 /**
chris 3:be428c849e1c 30 *Includes
chris 3:be428c849e1c 31 */
chris 3:be428c849e1c 32 #include "mbed.h"
chris 3:be428c849e1c 33 #include "platform.h"
chris 3:be428c849e1c 34 #include "rpc.h"
chris 3:be428c849e1c 35 #define STR_LEN 64
chris 3:be428c849e1c 36 #include "platform.h"
chris 3:be428c849e1c 37
chris 3:be428c849e1c 38 #ifdef MBED_RPC
chris 3:be428c849e1c 39 #include "rpc.h"
chris 3:be428c849e1c 40 #endif
chris 3:be428c849e1c 41 /**
chris 3:be428c849e1c 42 *
chris 3:be428c849e1c 43 *Class to call custom functions over RPC
chris 3:be428c849e1c 44 *
chris 3:be428c849e1c 45 */
chris 3:be428c849e1c 46 class RPCFunction : public Base{
chris 3:be428c849e1c 47 public:
chris 3:be428c849e1c 48 /**
chris 3:be428c849e1c 49 * Constructor
chris 3:be428c849e1c 50 *
chris 3:be428c849e1c 51 *@param f Pointer to the function to call. the function must be of the form void foo(char * input, char * output)
chris 3:be428c849e1c 52 *@param name The name of this object
chris 3:be428c849e1c 53 */
chris 3:be428c849e1c 54 RPCFunction(void(*f)(char*, char*), const char* = NULL);
chris 3:be428c849e1c 55
chris 3:be428c849e1c 56 /**
chris 3:be428c849e1c 57 *run
chris 3:be428c849e1c 58 *
chris 3:be428c849e1c 59 *Calls the attached function passing the string in but doesn't return the result.
chris 3:be428c849e1c 60 *@param str The string to be passed into the attached function. This string can consist of any ASCII characters apart from escape codes. The usual limtations on argument content for RPC strings has been removed
chris 3:be428c849e1c 61 *@return A string output from the function
chris 3:be428c849e1c 62 */
chris 3:be428c849e1c 63 char * run(char* str);
chris 3:be428c849e1c 64
chris 3:be428c849e1c 65 /**
chris 3:be428c849e1c 66 *Reads the value of the output string.
chris 3:be428c849e1c 67 *
chris 3:be428c849e1c 68 *@returns the string outputted from the last time the function was called
chris 3:be428c849e1c 69 */
chris 3:be428c849e1c 70 char * read();
chris 3:be428c849e1c 71
chris 3:be428c849e1c 72
chris 3:be428c849e1c 73 #ifdef MBED_RPC
chris 3:be428c849e1c 74 virtual const struct rpc_method *get_rpc_methods();
chris 3:be428c849e1c 75 #endif
chris 3:be428c849e1c 76
chris 3:be428c849e1c 77 private:
chris 3:be428c849e1c 78 void (*_ftr)(char*, char*);
chris 3:be428c849e1c 79
chris 3:be428c849e1c 80 char _input[STR_LEN];
chris 3:be428c849e1c 81 char _output[STR_LEN];
chris 3:be428c849e1c 82
chris 3:be428c849e1c 83 };
chris 3:be428c849e1c 84 #endif