mbed rpc
Dependents: GSwifi_ap_ws_rpc gba_rpc
Fork of mbed-rpc by
RpcClasses.h@0:efe8172b4113, 2012-11-20 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Nov 20 17:23:59 2012 +0000
- Revision:
- 0:efe8172b4113
- Child:
- 1:6919289a5946
mbed RPC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:efe8172b4113 | 1 | /* mbed Microcontroller Library |
mbed_official | 0:efe8172b4113 | 2 | * Copyright (c) 2006-2012 ARM Limited |
mbed_official | 0:efe8172b4113 | 3 | * |
mbed_official | 0:efe8172b4113 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
mbed_official | 0:efe8172b4113 | 5 | * of this software and associated documentation files (the "Software"), to deal |
mbed_official | 0:efe8172b4113 | 6 | * in the Software without restriction, including without limitation the rights |
mbed_official | 0:efe8172b4113 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
mbed_official | 0:efe8172b4113 | 8 | * copies of the Software, and to permit persons to whom the Software is |
mbed_official | 0:efe8172b4113 | 9 | * furnished to do so, subject to the following conditions: |
mbed_official | 0:efe8172b4113 | 10 | * |
mbed_official | 0:efe8172b4113 | 11 | * The above copyright notice and this permission notice shall be included in |
mbed_official | 0:efe8172b4113 | 12 | * all copies or substantial portions of the Software. |
mbed_official | 0:efe8172b4113 | 13 | * |
mbed_official | 0:efe8172b4113 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
mbed_official | 0:efe8172b4113 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
mbed_official | 0:efe8172b4113 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
mbed_official | 0:efe8172b4113 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
mbed_official | 0:efe8172b4113 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
mbed_official | 0:efe8172b4113 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
mbed_official | 0:efe8172b4113 | 20 | * SOFTWARE. |
mbed_official | 0:efe8172b4113 | 21 | */ |
mbed_official | 0:efe8172b4113 | 22 | #ifndef MBED_CLASSES_H |
mbed_official | 0:efe8172b4113 | 23 | #define MBED_CLASSES_H |
mbed_official | 0:efe8172b4113 | 24 | |
mbed_official | 0:efe8172b4113 | 25 | #include "rpc.h" |
mbed_official | 0:efe8172b4113 | 26 | |
mbed_official | 0:efe8172b4113 | 27 | namespace mbed { |
mbed_official | 0:efe8172b4113 | 28 | |
mbed_official | 0:efe8172b4113 | 29 | class RpcDigitalOut : public RPC { |
mbed_official | 0:efe8172b4113 | 30 | public: |
mbed_official | 0:efe8172b4113 | 31 | RpcDigitalOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
mbed_official | 0:efe8172b4113 | 32 | |
mbed_official | 0:efe8172b4113 | 33 | void write(int a0) {o.write(a0);} |
mbed_official | 0:efe8172b4113 | 34 | int read(void) {return o.read();} |
mbed_official | 0:efe8172b4113 | 35 | |
mbed_official | 0:efe8172b4113 | 36 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 37 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 38 | {"write", rpc_method_caller<RpcDigitalOut, int, &RpcDigitalOut::write>}, |
mbed_official | 0:efe8172b4113 | 39 | {"read", rpc_method_caller<int, RpcDigitalOut, &RpcDigitalOut::read>}, |
mbed_official | 0:efe8172b4113 | 40 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 41 | }; |
mbed_official | 0:efe8172b4113 | 42 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 43 | } |
mbed_official | 0:efe8172b4113 | 44 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 45 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 46 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalOut, PinName, const char*> >}, |
mbed_official | 0:efe8172b4113 | 47 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 48 | }; |
mbed_official | 0:efe8172b4113 | 49 | static rpc_class c = {"DigitalOut", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 50 | return &c; |
mbed_official | 0:efe8172b4113 | 51 | } |
mbed_official | 0:efe8172b4113 | 52 | private: |
mbed_official | 0:efe8172b4113 | 53 | DigitalOut o; |
mbed_official | 0:efe8172b4113 | 54 | }; |
mbed_official | 0:efe8172b4113 | 55 | |
mbed_official | 0:efe8172b4113 | 56 | class RpcDigitalIn : public RPC { |
mbed_official | 0:efe8172b4113 | 57 | public: |
mbed_official | 0:efe8172b4113 | 58 | RpcDigitalIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
mbed_official | 0:efe8172b4113 | 59 | |
mbed_official | 0:efe8172b4113 | 60 | int read(void) {return o.read();} |
mbed_official | 0:efe8172b4113 | 61 | |
mbed_official | 0:efe8172b4113 | 62 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 63 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 64 | {"read", rpc_method_caller<int, RpcDigitalIn, &RpcDigitalIn::read>}, |
mbed_official | 0:efe8172b4113 | 65 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 66 | }; |
mbed_official | 0:efe8172b4113 | 67 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 68 | } |
mbed_official | 0:efe8172b4113 | 69 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 70 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 71 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalIn, PinName, const char*> >}, |
mbed_official | 0:efe8172b4113 | 72 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 73 | }; |
mbed_official | 0:efe8172b4113 | 74 | static rpc_class c = {"DigitalIn", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 75 | return &c; |
mbed_official | 0:efe8172b4113 | 76 | } |
mbed_official | 0:efe8172b4113 | 77 | private: |
mbed_official | 0:efe8172b4113 | 78 | DigitalIn o; |
mbed_official | 0:efe8172b4113 | 79 | }; |
mbed_official | 0:efe8172b4113 | 80 | |
mbed_official | 0:efe8172b4113 | 81 | class RpcDigitalInOut : public RPC { |
mbed_official | 0:efe8172b4113 | 82 | public: |
mbed_official | 0:efe8172b4113 | 83 | RpcDigitalInOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
mbed_official | 0:efe8172b4113 | 84 | |
mbed_official | 0:efe8172b4113 | 85 | int read(void) {return o.read();} |
mbed_official | 0:efe8172b4113 | 86 | void write(int a0) {o.write(a0);} |
mbed_official | 0:efe8172b4113 | 87 | void input(void) {o.input();} |
mbed_official | 0:efe8172b4113 | 88 | void output(void) {o.output();} |
mbed_official | 0:efe8172b4113 | 89 | |
mbed_official | 0:efe8172b4113 | 90 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 91 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 92 | {"read", rpc_method_caller<int, RpcDigitalInOut, &RpcDigitalInOut::read>}, |
mbed_official | 0:efe8172b4113 | 93 | {"write", rpc_method_caller<RpcDigitalInOut, int, &RpcDigitalInOut::write>}, |
mbed_official | 0:efe8172b4113 | 94 | {"input", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::input>}, |
mbed_official | 0:efe8172b4113 | 95 | {"output", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::output>}, |
mbed_official | 0:efe8172b4113 | 96 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 97 | }; |
mbed_official | 0:efe8172b4113 | 98 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 99 | } |
mbed_official | 0:efe8172b4113 | 100 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 101 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 102 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalInOut, PinName, const char*> >}, |
mbed_official | 0:efe8172b4113 | 103 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 104 | }; |
mbed_official | 0:efe8172b4113 | 105 | static rpc_class c = {"DigitalInOut", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 106 | return &c; |
mbed_official | 0:efe8172b4113 | 107 | } |
mbed_official | 0:efe8172b4113 | 108 | private: |
mbed_official | 0:efe8172b4113 | 109 | DigitalInOut o; |
mbed_official | 0:efe8172b4113 | 110 | }; |
mbed_official | 0:efe8172b4113 | 111 | |
mbed_official | 0:efe8172b4113 | 112 | #if DEVICE_ANALOGIN |
mbed_official | 0:efe8172b4113 | 113 | class RpcAnalogIn : public RPC { |
mbed_official | 0:efe8172b4113 | 114 | public: |
mbed_official | 0:efe8172b4113 | 115 | RpcAnalogIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
mbed_official | 0:efe8172b4113 | 116 | |
mbed_official | 0:efe8172b4113 | 117 | float read(void) {return o.read();} |
mbed_official | 0:efe8172b4113 | 118 | unsigned short read_u16(void) {return o.read_u16();} |
mbed_official | 0:efe8172b4113 | 119 | |
mbed_official | 0:efe8172b4113 | 120 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 121 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 122 | {"read", rpc_method_caller<float, RpcAnalogIn, &RpcAnalogIn::read>}, |
mbed_official | 0:efe8172b4113 | 123 | {"read_u16", rpc_method_caller<unsigned short, RpcAnalogIn, &RpcAnalogIn::read_u16>}, |
mbed_official | 0:efe8172b4113 | 124 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 125 | }; |
mbed_official | 0:efe8172b4113 | 126 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 127 | } |
mbed_official | 0:efe8172b4113 | 128 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 129 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 130 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogIn, PinName, const char*> >}, |
mbed_official | 0:efe8172b4113 | 131 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 132 | }; |
mbed_official | 0:efe8172b4113 | 133 | static rpc_class c = {"AnalogIn", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 134 | return &c; |
mbed_official | 0:efe8172b4113 | 135 | } |
mbed_official | 0:efe8172b4113 | 136 | private: |
mbed_official | 0:efe8172b4113 | 137 | AnalogIn o; |
mbed_official | 0:efe8172b4113 | 138 | }; |
mbed_official | 0:efe8172b4113 | 139 | #endif |
mbed_official | 0:efe8172b4113 | 140 | |
mbed_official | 0:efe8172b4113 | 141 | #if DEVICE_ANALOGOUT |
mbed_official | 0:efe8172b4113 | 142 | class RpcAnalogOut : public RPC { |
mbed_official | 0:efe8172b4113 | 143 | public: |
mbed_official | 0:efe8172b4113 | 144 | RpcAnalogOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
mbed_official | 0:efe8172b4113 | 145 | |
mbed_official | 0:efe8172b4113 | 146 | float read(void) {return o.read();} |
mbed_official | 0:efe8172b4113 | 147 | void write(float a0) {o.write(a0);} |
mbed_official | 0:efe8172b4113 | 148 | void write_u16(unsigned short a0) {o.write_u16(a0);} |
mbed_official | 0:efe8172b4113 | 149 | |
mbed_official | 0:efe8172b4113 | 150 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 151 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 152 | {"read", rpc_method_caller<float, RpcAnalogOut, &RpcAnalogOut::read>}, |
mbed_official | 0:efe8172b4113 | 153 | {"write", rpc_method_caller<RpcAnalogOut, float, &RpcAnalogOut::write>}, |
mbed_official | 0:efe8172b4113 | 154 | {"write_u16", rpc_method_caller<RpcAnalogOut, unsigned short, &RpcAnalogOut::write_u16>}, |
mbed_official | 0:efe8172b4113 | 155 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 156 | }; |
mbed_official | 0:efe8172b4113 | 157 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 158 | } |
mbed_official | 0:efe8172b4113 | 159 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 160 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 161 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogOut, PinName, const char*> >}, |
mbed_official | 0:efe8172b4113 | 162 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 163 | }; |
mbed_official | 0:efe8172b4113 | 164 | static rpc_class c = {"AnalogOut", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 165 | return &c; |
mbed_official | 0:efe8172b4113 | 166 | } |
mbed_official | 0:efe8172b4113 | 167 | private: |
mbed_official | 0:efe8172b4113 | 168 | AnalogOut o; |
mbed_official | 0:efe8172b4113 | 169 | }; |
mbed_official | 0:efe8172b4113 | 170 | #endif |
mbed_official | 0:efe8172b4113 | 171 | |
mbed_official | 0:efe8172b4113 | 172 | #if DEVICE_PWMOUT |
mbed_official | 0:efe8172b4113 | 173 | class RpcPwmOut : public RPC { |
mbed_official | 0:efe8172b4113 | 174 | public: |
mbed_official | 0:efe8172b4113 | 175 | RpcPwmOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
mbed_official | 0:efe8172b4113 | 176 | |
mbed_official | 0:efe8172b4113 | 177 | float read(void) {return o.read();} |
mbed_official | 0:efe8172b4113 | 178 | void write(float a0) {o.write(a0);} |
mbed_official | 0:efe8172b4113 | 179 | void period(float a0) {o.period(a0);} |
mbed_official | 0:efe8172b4113 | 180 | void period_ms(int a0) {o.period_ms(a0);} |
mbed_official | 0:efe8172b4113 | 181 | void pulsewidth(float a0) {o.pulsewidth(a0);} |
mbed_official | 0:efe8172b4113 | 182 | void pulsewidth_ms(int a0) {o.pulsewidth_ms(a0);} |
mbed_official | 0:efe8172b4113 | 183 | |
mbed_official | 0:efe8172b4113 | 184 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 185 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 186 | {"read", rpc_method_caller<float, RpcPwmOut, &RpcPwmOut::read>}, |
mbed_official | 0:efe8172b4113 | 187 | {"write", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::write>}, |
mbed_official | 0:efe8172b4113 | 188 | {"period", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::period>}, |
mbed_official | 0:efe8172b4113 | 189 | {"period_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::period_ms>}, |
mbed_official | 0:efe8172b4113 | 190 | {"pulsewidth", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::pulsewidth>}, |
mbed_official | 0:efe8172b4113 | 191 | {"pulsewidth_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::pulsewidth_ms>}, |
mbed_official | 0:efe8172b4113 | 192 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 193 | }; |
mbed_official | 0:efe8172b4113 | 194 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 195 | } |
mbed_official | 0:efe8172b4113 | 196 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 197 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 198 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcPwmOut, PinName, const char*> >}, |
mbed_official | 0:efe8172b4113 | 199 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 200 | }; |
mbed_official | 0:efe8172b4113 | 201 | static rpc_class c = {"PwmOut", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 202 | return &c; |
mbed_official | 0:efe8172b4113 | 203 | } |
mbed_official | 0:efe8172b4113 | 204 | private: |
mbed_official | 0:efe8172b4113 | 205 | PwmOut o; |
mbed_official | 0:efe8172b4113 | 206 | }; |
mbed_official | 0:efe8172b4113 | 207 | #endif |
mbed_official | 0:efe8172b4113 | 208 | |
mbed_official | 0:efe8172b4113 | 209 | #if DEVICE_SPI |
mbed_official | 0:efe8172b4113 | 210 | class RpcSPI : public RPC { |
mbed_official | 0:efe8172b4113 | 211 | public: |
mbed_official | 0:efe8172b4113 | 212 | RpcSPI(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {} |
mbed_official | 0:efe8172b4113 | 213 | |
mbed_official | 0:efe8172b4113 | 214 | void format(int a0, int a1) {o.format(a0, a1);} |
mbed_official | 0:efe8172b4113 | 215 | void frequency(int a0) {o.frequency(a0);} |
mbed_official | 0:efe8172b4113 | 216 | int write(int a0) {return o.write(a0);} |
mbed_official | 0:efe8172b4113 | 217 | |
mbed_official | 0:efe8172b4113 | 218 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 219 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 220 | {"format", rpc_method_caller<RpcSPI, int, int, &RpcSPI::format>}, |
mbed_official | 0:efe8172b4113 | 221 | {"frequency", rpc_method_caller<RpcSPI, int, &RpcSPI::frequency>}, |
mbed_official | 0:efe8172b4113 | 222 | {"write", rpc_method_caller<int, RpcSPI, int, &RpcSPI::write>}, |
mbed_official | 0:efe8172b4113 | 223 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 224 | }; |
mbed_official | 0:efe8172b4113 | 225 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 226 | } |
mbed_official | 0:efe8172b4113 | 227 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 228 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 229 | {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcSPI, PinName, PinName, PinName, const char*> >}, |
mbed_official | 0:efe8172b4113 | 230 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 231 | }; |
mbed_official | 0:efe8172b4113 | 232 | static rpc_class c = {"SPI", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 233 | return &c; |
mbed_official | 0:efe8172b4113 | 234 | } |
mbed_official | 0:efe8172b4113 | 235 | private: |
mbed_official | 0:efe8172b4113 | 236 | SPI o; |
mbed_official | 0:efe8172b4113 | 237 | }; |
mbed_official | 0:efe8172b4113 | 238 | #endif |
mbed_official | 0:efe8172b4113 | 239 | |
mbed_official | 0:efe8172b4113 | 240 | #if DEVICE_SERIAL |
mbed_official | 0:efe8172b4113 | 241 | class RpcSerial : public RPC { |
mbed_official | 0:efe8172b4113 | 242 | public: |
mbed_official | 0:efe8172b4113 | 243 | RpcSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {} |
mbed_official | 0:efe8172b4113 | 244 | |
mbed_official | 0:efe8172b4113 | 245 | void baud(int a0) {o.baud(a0);} |
mbed_official | 0:efe8172b4113 | 246 | int readable(void) {return o.readable();} |
mbed_official | 0:efe8172b4113 | 247 | int writeable(void) {return o.writeable();} |
mbed_official | 0:efe8172b4113 | 248 | int putc(int a0) {return o.putc(a0);} |
mbed_official | 0:efe8172b4113 | 249 | int getc(void) {return o.getc();} |
mbed_official | 0:efe8172b4113 | 250 | int puts(const char * a0) {return o.puts(a0);} |
mbed_official | 0:efe8172b4113 | 251 | |
mbed_official | 0:efe8172b4113 | 252 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 253 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 254 | {"baud", rpc_method_caller<RpcSerial, int, &RpcSerial::baud>}, |
mbed_official | 0:efe8172b4113 | 255 | {"readable", rpc_method_caller<int, RpcSerial, &RpcSerial::readable>}, |
mbed_official | 0:efe8172b4113 | 256 | {"writeable", rpc_method_caller<int, RpcSerial, &RpcSerial::writeable>}, |
mbed_official | 0:efe8172b4113 | 257 | {"putc", rpc_method_caller<int, RpcSerial, int, &RpcSerial::putc>}, |
mbed_official | 0:efe8172b4113 | 258 | {"getc", rpc_method_caller<int, RpcSerial, &RpcSerial::getc>}, |
mbed_official | 0:efe8172b4113 | 259 | {"puts", rpc_method_caller<int, RpcSerial, const char *, &RpcSerial::puts>}, |
mbed_official | 0:efe8172b4113 | 260 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 261 | }; |
mbed_official | 0:efe8172b4113 | 262 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 263 | } |
mbed_official | 0:efe8172b4113 | 264 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 265 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 266 | {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcSerial, PinName, PinName, const char*> >}, |
mbed_official | 0:efe8172b4113 | 267 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 268 | }; |
mbed_official | 0:efe8172b4113 | 269 | static rpc_class c = {"Serial", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 270 | return &c; |
mbed_official | 0:efe8172b4113 | 271 | } |
mbed_official | 0:efe8172b4113 | 272 | private: |
mbed_official | 0:efe8172b4113 | 273 | Serial o; |
mbed_official | 0:efe8172b4113 | 274 | }; |
mbed_official | 0:efe8172b4113 | 275 | #endif |
mbed_official | 0:efe8172b4113 | 276 | |
mbed_official | 0:efe8172b4113 | 277 | class RpcTimer : public RPC { |
mbed_official | 0:efe8172b4113 | 278 | public: |
mbed_official | 0:efe8172b4113 | 279 | RpcTimer(const char *name=NULL) : RPC(name), o() {} |
mbed_official | 0:efe8172b4113 | 280 | |
mbed_official | 0:efe8172b4113 | 281 | void start(void) {o.start();} |
mbed_official | 0:efe8172b4113 | 282 | void stop(void) {o.stop();} |
mbed_official | 0:efe8172b4113 | 283 | void reset(void) {o.reset();} |
mbed_official | 0:efe8172b4113 | 284 | float read(void) {return o.read();} |
mbed_official | 0:efe8172b4113 | 285 | int read_ms(void) {return o.read_ms();} |
mbed_official | 0:efe8172b4113 | 286 | int read_us(void) {return o.read_us();} |
mbed_official | 0:efe8172b4113 | 287 | |
mbed_official | 0:efe8172b4113 | 288 | virtual const struct rpc_method *get_rpc_methods() { |
mbed_official | 0:efe8172b4113 | 289 | static const rpc_method rpc_methods[] = { |
mbed_official | 0:efe8172b4113 | 290 | {"start", rpc_method_caller<RpcTimer, &RpcTimer::start>}, |
mbed_official | 0:efe8172b4113 | 291 | {"stop", rpc_method_caller<RpcTimer, &RpcTimer::stop>}, |
mbed_official | 0:efe8172b4113 | 292 | {"reset", rpc_method_caller<RpcTimer, &RpcTimer::reset>}, |
mbed_official | 0:efe8172b4113 | 293 | {"read", rpc_method_caller<float, RpcTimer, &RpcTimer::read>}, |
mbed_official | 0:efe8172b4113 | 294 | {"read_ms", rpc_method_caller<int, RpcTimer, &RpcTimer::read_ms>}, |
mbed_official | 0:efe8172b4113 | 295 | {"read_us", rpc_method_caller<int, RpcTimer, &RpcTimer::read_us>}, |
mbed_official | 0:efe8172b4113 | 296 | RPC_METHOD_SUPER(RPC) |
mbed_official | 0:efe8172b4113 | 297 | }; |
mbed_official | 0:efe8172b4113 | 298 | return rpc_methods; |
mbed_official | 0:efe8172b4113 | 299 | } |
mbed_official | 0:efe8172b4113 | 300 | static struct rpc_class *get_rpc_class() { |
mbed_official | 0:efe8172b4113 | 301 | static const rpc_function funcs[] = { |
mbed_official | 0:efe8172b4113 | 302 | {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcTimer, const char*> >}, |
mbed_official | 0:efe8172b4113 | 303 | RPC_METHOD_END |
mbed_official | 0:efe8172b4113 | 304 | }; |
mbed_official | 0:efe8172b4113 | 305 | static rpc_class c = {"Timer", funcs, NULL}; |
mbed_official | 0:efe8172b4113 | 306 | return &c; |
mbed_official | 0:efe8172b4113 | 307 | } |
mbed_official | 0:efe8172b4113 | 308 | private: |
mbed_official | 0:efe8172b4113 | 309 | Timer o; |
mbed_official | 0:efe8172b4113 | 310 | }; |
mbed_official | 0:efe8172b4113 | 311 | |
mbed_official | 0:efe8172b4113 | 312 | } |
mbed_official | 0:efe8172b4113 | 313 | |
mbed_official | 0:efe8172b4113 | 314 | #endif |