nkjnm
Dependencies: MAX44000 nexpaq_mdk
Fork of LED_Demo by
mbd_os/libraries/rpc/RpcClasses.h@7:3a65ef12ba31, 2016-11-04 (annotated)
- Committer:
- nitsshukla
- Date:
- Fri Nov 04 12:06:04 2016 +0000
- Revision:
- 7:3a65ef12ba31
- Parent:
- 1:55a6170b404f
kghj;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 1:55a6170b404f | 1 | /* mbed Microcontroller Library |
nexpaq | 1:55a6170b404f | 2 | * Copyright (c) 2006-2013 ARM Limited |
nexpaq | 1:55a6170b404f | 3 | * |
nexpaq | 1:55a6170b404f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
nexpaq | 1:55a6170b404f | 5 | * you may not use this file except in compliance with the License. |
nexpaq | 1:55a6170b404f | 6 | * You may obtain a copy of the License at |
nexpaq | 1:55a6170b404f | 7 | * |
nexpaq | 1:55a6170b404f | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 1:55a6170b404f | 9 | * |
nexpaq | 1:55a6170b404f | 10 | * Unless required by applicable law or agreed to in writing, software |
nexpaq | 1:55a6170b404f | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
nexpaq | 1:55a6170b404f | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 1:55a6170b404f | 13 | * See the License for the specific language governing permissions and |
nexpaq | 1:55a6170b404f | 14 | * limitations under the License. |
nexpaq | 1:55a6170b404f | 15 | */ |
nexpaq | 1:55a6170b404f | 16 | #ifndef MBED_CLASSES_H |
nexpaq | 1:55a6170b404f | 17 | #define MBED_CLASSES_H |
nexpaq | 1:55a6170b404f | 18 | |
nexpaq | 1:55a6170b404f | 19 | #include "rpc.h" |
nexpaq | 1:55a6170b404f | 20 | |
nexpaq | 1:55a6170b404f | 21 | namespace mbed { |
nexpaq | 1:55a6170b404f | 22 | |
nexpaq | 1:55a6170b404f | 23 | class RpcDigitalOut : public RPC { |
nexpaq | 1:55a6170b404f | 24 | public: |
nexpaq | 1:55a6170b404f | 25 | RpcDigitalOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
nexpaq | 1:55a6170b404f | 26 | |
nexpaq | 1:55a6170b404f | 27 | void write(int a0) {o.write(a0);} |
nexpaq | 1:55a6170b404f | 28 | int read(void) {return o.read();} |
nexpaq | 1:55a6170b404f | 29 | |
nexpaq | 1:55a6170b404f | 30 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 31 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 32 | {"write", rpc_method_caller<RpcDigitalOut, int, &RpcDigitalOut::write>}, |
nexpaq | 1:55a6170b404f | 33 | {"read", rpc_method_caller<int, RpcDigitalOut, &RpcDigitalOut::read>}, |
nexpaq | 1:55a6170b404f | 34 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 35 | }; |
nexpaq | 1:55a6170b404f | 36 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 37 | } |
nexpaq | 1:55a6170b404f | 38 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 39 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 40 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalOut, PinName, const char*> >}, |
nexpaq | 1:55a6170b404f | 41 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 42 | }; |
nexpaq | 1:55a6170b404f | 43 | static rpc_class c = {"DigitalOut", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 44 | return &c; |
nexpaq | 1:55a6170b404f | 45 | } |
nexpaq | 1:55a6170b404f | 46 | private: |
nexpaq | 1:55a6170b404f | 47 | DigitalOut o; |
nexpaq | 1:55a6170b404f | 48 | }; |
nexpaq | 1:55a6170b404f | 49 | |
nexpaq | 1:55a6170b404f | 50 | class RpcDigitalIn : public RPC { |
nexpaq | 1:55a6170b404f | 51 | public: |
nexpaq | 1:55a6170b404f | 52 | RpcDigitalIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
nexpaq | 1:55a6170b404f | 53 | |
nexpaq | 1:55a6170b404f | 54 | int read(void) {return o.read();} |
nexpaq | 1:55a6170b404f | 55 | |
nexpaq | 1:55a6170b404f | 56 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 57 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 58 | {"read", rpc_method_caller<int, RpcDigitalIn, &RpcDigitalIn::read>}, |
nexpaq | 1:55a6170b404f | 59 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 60 | }; |
nexpaq | 1:55a6170b404f | 61 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 62 | } |
nexpaq | 1:55a6170b404f | 63 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 64 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 65 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalIn, PinName, const char*> >}, |
nexpaq | 1:55a6170b404f | 66 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 67 | }; |
nexpaq | 1:55a6170b404f | 68 | static rpc_class c = {"DigitalIn", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 69 | return &c; |
nexpaq | 1:55a6170b404f | 70 | } |
nexpaq | 1:55a6170b404f | 71 | private: |
nexpaq | 1:55a6170b404f | 72 | DigitalIn o; |
nexpaq | 1:55a6170b404f | 73 | }; |
nexpaq | 1:55a6170b404f | 74 | |
nexpaq | 1:55a6170b404f | 75 | class RpcDigitalInOut : public RPC { |
nexpaq | 1:55a6170b404f | 76 | public: |
nexpaq | 1:55a6170b404f | 77 | RpcDigitalInOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
nexpaq | 1:55a6170b404f | 78 | |
nexpaq | 1:55a6170b404f | 79 | int read(void) {return o.read();} |
nexpaq | 1:55a6170b404f | 80 | void write(int a0) {o.write(a0);} |
nexpaq | 1:55a6170b404f | 81 | void input(void) {o.input();} |
nexpaq | 1:55a6170b404f | 82 | void output(void) {o.output();} |
nexpaq | 1:55a6170b404f | 83 | |
nexpaq | 1:55a6170b404f | 84 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 85 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 86 | {"read", rpc_method_caller<int, RpcDigitalInOut, &RpcDigitalInOut::read>}, |
nexpaq | 1:55a6170b404f | 87 | {"write", rpc_method_caller<RpcDigitalInOut, int, &RpcDigitalInOut::write>}, |
nexpaq | 1:55a6170b404f | 88 | {"input", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::input>}, |
nexpaq | 1:55a6170b404f | 89 | {"output", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::output>}, |
nexpaq | 1:55a6170b404f | 90 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 91 | }; |
nexpaq | 1:55a6170b404f | 92 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 93 | } |
nexpaq | 1:55a6170b404f | 94 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 95 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 96 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalInOut, PinName, const char*> >}, |
nexpaq | 1:55a6170b404f | 97 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 98 | }; |
nexpaq | 1:55a6170b404f | 99 | static rpc_class c = {"DigitalInOut", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 100 | return &c; |
nexpaq | 1:55a6170b404f | 101 | } |
nexpaq | 1:55a6170b404f | 102 | private: |
nexpaq | 1:55a6170b404f | 103 | DigitalInOut o; |
nexpaq | 1:55a6170b404f | 104 | }; |
nexpaq | 1:55a6170b404f | 105 | |
nexpaq | 1:55a6170b404f | 106 | #if DEVICE_ANALOGIN |
nexpaq | 1:55a6170b404f | 107 | class RpcAnalogIn : public RPC { |
nexpaq | 1:55a6170b404f | 108 | public: |
nexpaq | 1:55a6170b404f | 109 | RpcAnalogIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
nexpaq | 1:55a6170b404f | 110 | |
nexpaq | 1:55a6170b404f | 111 | float read(void) {return o.read();} |
nexpaq | 1:55a6170b404f | 112 | unsigned short read_u16(void) {return o.read_u16();} |
nexpaq | 1:55a6170b404f | 113 | |
nexpaq | 1:55a6170b404f | 114 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 115 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 116 | {"read", rpc_method_caller<float, RpcAnalogIn, &RpcAnalogIn::read>}, |
nexpaq | 1:55a6170b404f | 117 | {"read_u16", rpc_method_caller<unsigned short, RpcAnalogIn, &RpcAnalogIn::read_u16>}, |
nexpaq | 1:55a6170b404f | 118 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 119 | }; |
nexpaq | 1:55a6170b404f | 120 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 121 | } |
nexpaq | 1:55a6170b404f | 122 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 123 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 124 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogIn, PinName, const char*> >}, |
nexpaq | 1:55a6170b404f | 125 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 126 | }; |
nexpaq | 1:55a6170b404f | 127 | static rpc_class c = {"AnalogIn", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 128 | return &c; |
nexpaq | 1:55a6170b404f | 129 | } |
nexpaq | 1:55a6170b404f | 130 | private: |
nexpaq | 1:55a6170b404f | 131 | AnalogIn o; |
nexpaq | 1:55a6170b404f | 132 | }; |
nexpaq | 1:55a6170b404f | 133 | #endif |
nexpaq | 1:55a6170b404f | 134 | |
nexpaq | 1:55a6170b404f | 135 | #if DEVICE_ANALOGOUT |
nexpaq | 1:55a6170b404f | 136 | class RpcAnalogOut : public RPC { |
nexpaq | 1:55a6170b404f | 137 | public: |
nexpaq | 1:55a6170b404f | 138 | RpcAnalogOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
nexpaq | 1:55a6170b404f | 139 | |
nexpaq | 1:55a6170b404f | 140 | float read(void) {return o.read();} |
nexpaq | 1:55a6170b404f | 141 | void write(float a0) {o.write(a0);} |
nexpaq | 1:55a6170b404f | 142 | void write_u16(unsigned short a0) {o.write_u16(a0);} |
nexpaq | 1:55a6170b404f | 143 | |
nexpaq | 1:55a6170b404f | 144 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 145 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 146 | {"read", rpc_method_caller<float, RpcAnalogOut, &RpcAnalogOut::read>}, |
nexpaq | 1:55a6170b404f | 147 | {"write", rpc_method_caller<RpcAnalogOut, float, &RpcAnalogOut::write>}, |
nexpaq | 1:55a6170b404f | 148 | {"write_u16", rpc_method_caller<RpcAnalogOut, unsigned short, &RpcAnalogOut::write_u16>}, |
nexpaq | 1:55a6170b404f | 149 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 150 | }; |
nexpaq | 1:55a6170b404f | 151 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 152 | } |
nexpaq | 1:55a6170b404f | 153 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 154 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 155 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogOut, PinName, const char*> >}, |
nexpaq | 1:55a6170b404f | 156 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 157 | }; |
nexpaq | 1:55a6170b404f | 158 | static rpc_class c = {"AnalogOut", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 159 | return &c; |
nexpaq | 1:55a6170b404f | 160 | } |
nexpaq | 1:55a6170b404f | 161 | private: |
nexpaq | 1:55a6170b404f | 162 | AnalogOut o; |
nexpaq | 1:55a6170b404f | 163 | }; |
nexpaq | 1:55a6170b404f | 164 | #endif |
nexpaq | 1:55a6170b404f | 165 | |
nexpaq | 1:55a6170b404f | 166 | #if DEVICE_PWMOUT |
nexpaq | 1:55a6170b404f | 167 | class RpcPwmOut : public RPC { |
nexpaq | 1:55a6170b404f | 168 | public: |
nexpaq | 1:55a6170b404f | 169 | RpcPwmOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {} |
nexpaq | 1:55a6170b404f | 170 | |
nexpaq | 1:55a6170b404f | 171 | float read(void) {return o.read();} |
nexpaq | 1:55a6170b404f | 172 | void write(float a0) {o.write(a0);} |
nexpaq | 1:55a6170b404f | 173 | void period(float a0) {o.period(a0);} |
nexpaq | 1:55a6170b404f | 174 | void period_ms(int a0) {o.period_ms(a0);} |
nexpaq | 1:55a6170b404f | 175 | void pulsewidth(float a0) {o.pulsewidth(a0);} |
nexpaq | 1:55a6170b404f | 176 | void pulsewidth_ms(int a0) {o.pulsewidth_ms(a0);} |
nexpaq | 1:55a6170b404f | 177 | |
nexpaq | 1:55a6170b404f | 178 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 179 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 180 | {"read", rpc_method_caller<float, RpcPwmOut, &RpcPwmOut::read>}, |
nexpaq | 1:55a6170b404f | 181 | {"write", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::write>}, |
nexpaq | 1:55a6170b404f | 182 | {"period", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::period>}, |
nexpaq | 1:55a6170b404f | 183 | {"period_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::period_ms>}, |
nexpaq | 1:55a6170b404f | 184 | {"pulsewidth", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::pulsewidth>}, |
nexpaq | 1:55a6170b404f | 185 | {"pulsewidth_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::pulsewidth_ms>}, |
nexpaq | 1:55a6170b404f | 186 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 187 | }; |
nexpaq | 1:55a6170b404f | 188 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 189 | } |
nexpaq | 1:55a6170b404f | 190 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 191 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 192 | {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcPwmOut, PinName, const char*> >}, |
nexpaq | 1:55a6170b404f | 193 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 194 | }; |
nexpaq | 1:55a6170b404f | 195 | static rpc_class c = {"PwmOut", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 196 | return &c; |
nexpaq | 1:55a6170b404f | 197 | } |
nexpaq | 1:55a6170b404f | 198 | private: |
nexpaq | 1:55a6170b404f | 199 | PwmOut o; |
nexpaq | 1:55a6170b404f | 200 | }; |
nexpaq | 1:55a6170b404f | 201 | #endif |
nexpaq | 1:55a6170b404f | 202 | |
nexpaq | 1:55a6170b404f | 203 | #if DEVICE_SPI |
nexpaq | 1:55a6170b404f | 204 | class RpcSPI : public RPC { |
nexpaq | 1:55a6170b404f | 205 | public: |
nexpaq | 1:55a6170b404f | 206 | RpcSPI(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {} |
nexpaq | 1:55a6170b404f | 207 | |
nexpaq | 1:55a6170b404f | 208 | void format(int a0, int a1) {o.format(a0, a1);} |
nexpaq | 1:55a6170b404f | 209 | void frequency(int a0) {o.frequency(a0);} |
nexpaq | 1:55a6170b404f | 210 | int write(int a0) {return o.write(a0);} |
nexpaq | 1:55a6170b404f | 211 | |
nexpaq | 1:55a6170b404f | 212 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 213 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 214 | {"format", rpc_method_caller<RpcSPI, int, int, &RpcSPI::format>}, |
nexpaq | 1:55a6170b404f | 215 | {"frequency", rpc_method_caller<RpcSPI, int, &RpcSPI::frequency>}, |
nexpaq | 1:55a6170b404f | 216 | {"write", rpc_method_caller<int, RpcSPI, int, &RpcSPI::write>}, |
nexpaq | 1:55a6170b404f | 217 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 218 | }; |
nexpaq | 1:55a6170b404f | 219 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 220 | } |
nexpaq | 1:55a6170b404f | 221 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 222 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 223 | {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcSPI, PinName, PinName, PinName, const char*> >}, |
nexpaq | 1:55a6170b404f | 224 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 225 | }; |
nexpaq | 1:55a6170b404f | 226 | static rpc_class c = {"SPI", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 227 | return &c; |
nexpaq | 1:55a6170b404f | 228 | } |
nexpaq | 1:55a6170b404f | 229 | private: |
nexpaq | 1:55a6170b404f | 230 | SPI o; |
nexpaq | 1:55a6170b404f | 231 | }; |
nexpaq | 1:55a6170b404f | 232 | #endif |
nexpaq | 1:55a6170b404f | 233 | |
nexpaq | 1:55a6170b404f | 234 | #if DEVICE_SERIAL |
nexpaq | 1:55a6170b404f | 235 | class RpcSerial : public RPC { |
nexpaq | 1:55a6170b404f | 236 | public: |
nexpaq | 1:55a6170b404f | 237 | RpcSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {} |
nexpaq | 1:55a6170b404f | 238 | |
nexpaq | 1:55a6170b404f | 239 | void baud(int a0) {o.baud(a0);} |
nexpaq | 1:55a6170b404f | 240 | int readable(void) {return o.readable();} |
nexpaq | 1:55a6170b404f | 241 | int writeable(void) {return o.writeable();} |
nexpaq | 1:55a6170b404f | 242 | int putc(int a0) {return o.putc(a0);} |
nexpaq | 1:55a6170b404f | 243 | int getc(void) {return o.getc();} |
nexpaq | 1:55a6170b404f | 244 | int puts(const char * a0) {return o.puts(a0);} |
nexpaq | 1:55a6170b404f | 245 | |
nexpaq | 1:55a6170b404f | 246 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 247 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 248 | {"baud", rpc_method_caller<RpcSerial, int, &RpcSerial::baud>}, |
nexpaq | 1:55a6170b404f | 249 | {"readable", rpc_method_caller<int, RpcSerial, &RpcSerial::readable>}, |
nexpaq | 1:55a6170b404f | 250 | {"writeable", rpc_method_caller<int, RpcSerial, &RpcSerial::writeable>}, |
nexpaq | 1:55a6170b404f | 251 | {"putc", rpc_method_caller<int, RpcSerial, int, &RpcSerial::putc>}, |
nexpaq | 1:55a6170b404f | 252 | {"getc", rpc_method_caller<int, RpcSerial, &RpcSerial::getc>}, |
nexpaq | 1:55a6170b404f | 253 | {"puts", rpc_method_caller<int, RpcSerial, const char *, &RpcSerial::puts>}, |
nexpaq | 1:55a6170b404f | 254 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 255 | }; |
nexpaq | 1:55a6170b404f | 256 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 257 | } |
nexpaq | 1:55a6170b404f | 258 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 259 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 260 | {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcSerial, PinName, PinName, const char*> >}, |
nexpaq | 1:55a6170b404f | 261 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 262 | }; |
nexpaq | 1:55a6170b404f | 263 | static rpc_class c = {"Serial", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 264 | return &c; |
nexpaq | 1:55a6170b404f | 265 | } |
nexpaq | 1:55a6170b404f | 266 | private: |
nexpaq | 1:55a6170b404f | 267 | Serial o; |
nexpaq | 1:55a6170b404f | 268 | }; |
nexpaq | 1:55a6170b404f | 269 | #endif |
nexpaq | 1:55a6170b404f | 270 | |
nexpaq | 1:55a6170b404f | 271 | class RpcTimer : public RPC { |
nexpaq | 1:55a6170b404f | 272 | public: |
nexpaq | 1:55a6170b404f | 273 | RpcTimer(const char *name=NULL) : RPC(name), o() {} |
nexpaq | 1:55a6170b404f | 274 | |
nexpaq | 1:55a6170b404f | 275 | void start(void) {o.start();} |
nexpaq | 1:55a6170b404f | 276 | void stop(void) {o.stop();} |
nexpaq | 1:55a6170b404f | 277 | void reset(void) {o.reset();} |
nexpaq | 1:55a6170b404f | 278 | float read(void) {return o.read();} |
nexpaq | 1:55a6170b404f | 279 | int read_ms(void) {return o.read_ms();} |
nexpaq | 1:55a6170b404f | 280 | int read_us(void) {return o.read_us();} |
nexpaq | 1:55a6170b404f | 281 | |
nexpaq | 1:55a6170b404f | 282 | virtual const struct rpc_method *get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 283 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 284 | {"start", rpc_method_caller<RpcTimer, &RpcTimer::start>}, |
nexpaq | 1:55a6170b404f | 285 | {"stop", rpc_method_caller<RpcTimer, &RpcTimer::stop>}, |
nexpaq | 1:55a6170b404f | 286 | {"reset", rpc_method_caller<RpcTimer, &RpcTimer::reset>}, |
nexpaq | 1:55a6170b404f | 287 | {"read", rpc_method_caller<float, RpcTimer, &RpcTimer::read>}, |
nexpaq | 1:55a6170b404f | 288 | {"read_ms", rpc_method_caller<int, RpcTimer, &RpcTimer::read_ms>}, |
nexpaq | 1:55a6170b404f | 289 | {"read_us", rpc_method_caller<int, RpcTimer, &RpcTimer::read_us>}, |
nexpaq | 1:55a6170b404f | 290 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 291 | }; |
nexpaq | 1:55a6170b404f | 292 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 293 | } |
nexpaq | 1:55a6170b404f | 294 | static struct rpc_class *get_rpc_class() { |
nexpaq | 1:55a6170b404f | 295 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 296 | {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcTimer, const char*> >}, |
nexpaq | 1:55a6170b404f | 297 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 298 | }; |
nexpaq | 1:55a6170b404f | 299 | static rpc_class c = {"Timer", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 300 | return &c; |
nexpaq | 1:55a6170b404f | 301 | } |
nexpaq | 1:55a6170b404f | 302 | private: |
nexpaq | 1:55a6170b404f | 303 | Timer o; |
nexpaq | 1:55a6170b404f | 304 | }; |
nexpaq | 1:55a6170b404f | 305 | |
nexpaq | 1:55a6170b404f | 306 | } |
nexpaq | 1:55a6170b404f | 307 | |
nexpaq | 1:55a6170b404f | 308 | #endif |