ソースの整理中ですが、利用はできます。

Dependencies:   EthernetInterface HttpServer TextLCD mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RpcClasses.h Source File

RpcClasses.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_CLASSES_H
00017 #define MBED_CLASSES_H
00018 
00019 #include "rpc.h"
00020 
00021 namespace mbed {
00022 
00023 class RpcDigitalOut : public RPC {
00024 public:
00025     RpcDigitalOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
00026 
00027     void write(int a0) {o.write(a0);}
00028     int read(void) {return o.read();}
00029 
00030     virtual const struct rpc_method *get_rpc_methods() {
00031         static const rpc_method rpc_methods[] = {
00032             {"write", rpc_method_caller<RpcDigitalOut, int, &RpcDigitalOut::write>},
00033             {"read", rpc_method_caller<int, RpcDigitalOut, &RpcDigitalOut::read>},
00034             RPC_METHOD_SUPER(RPC)
00035         };
00036         return rpc_methods;
00037     }
00038     static struct rpc_class *get_rpc_class() {
00039         static const rpc_function funcs[] = {
00040             {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalOut, PinName, const char*> >},
00041             RPC_METHOD_END
00042         };
00043         static rpc_class c = {"DigitalOut", funcs, NULL};
00044         return &c;
00045     }
00046 private:
00047     DigitalOut o;
00048 };
00049 
00050 class RpcDigitalIn : public RPC {
00051 public:
00052     RpcDigitalIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
00053 
00054     int read(void) {return o.read();}
00055 
00056     virtual const struct rpc_method *get_rpc_methods() {
00057         static const rpc_method rpc_methods[] = {
00058             {"read", rpc_method_caller<int, RpcDigitalIn, &RpcDigitalIn::read>},
00059             RPC_METHOD_SUPER(RPC)
00060         };
00061         return rpc_methods;
00062     }
00063     static struct rpc_class *get_rpc_class() {
00064         static const rpc_function funcs[] = {
00065             {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalIn, PinName, const char*> >},
00066             RPC_METHOD_END
00067         };
00068         static rpc_class c = {"DigitalIn", funcs, NULL};
00069         return &c;
00070     }
00071 private:
00072     DigitalIn o;
00073 };
00074 
00075 class RpcDigitalInOut : public RPC {
00076 public:
00077     RpcDigitalInOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
00078 
00079     int read(void) {return o.read();}
00080     void write(int a0) {o.write(a0);}
00081     void input(void) {o.input();}
00082     void output(void) {o.output();}
00083 
00084     virtual const struct rpc_method *get_rpc_methods() {
00085         static const rpc_method rpc_methods[] = {
00086             {"read", rpc_method_caller<int, RpcDigitalInOut, &RpcDigitalInOut::read>},
00087             {"write", rpc_method_caller<RpcDigitalInOut, int, &RpcDigitalInOut::write>},
00088             {"input", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::input>},
00089             {"output", rpc_method_caller<RpcDigitalInOut, &RpcDigitalInOut::output>},
00090             RPC_METHOD_SUPER(RPC)
00091         };
00092         return rpc_methods;
00093     }
00094     static struct rpc_class *get_rpc_class() {
00095         static const rpc_function funcs[] = {
00096             {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcDigitalInOut, PinName, const char*> >},
00097             RPC_METHOD_END
00098         };
00099         static rpc_class c = {"DigitalInOut", funcs, NULL};
00100         return &c;
00101     }
00102 private:
00103     DigitalInOut o;
00104 };
00105 
00106 #if DEVICE_ANALOGIN
00107 class RpcAnalogIn : public RPC {
00108 public:
00109     RpcAnalogIn(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
00110 
00111     float read(void) {return o.read();}
00112     unsigned short read_u16(void) {return o.read_u16();}
00113 
00114     virtual const struct rpc_method *get_rpc_methods() {
00115         static const rpc_method rpc_methods[] = {
00116             {"read", rpc_method_caller<float, RpcAnalogIn, &RpcAnalogIn::read>},
00117             {"read_u16", rpc_method_caller<unsigned short, RpcAnalogIn, &RpcAnalogIn::read_u16>},
00118             RPC_METHOD_SUPER(RPC)
00119         };
00120         return rpc_methods;
00121     }
00122     static struct rpc_class *get_rpc_class() {
00123         static const rpc_function funcs[] = {
00124             {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogIn, PinName, const char*> >},
00125             RPC_METHOD_END
00126         };
00127         static rpc_class c = {"AnalogIn", funcs, NULL};
00128         return &c;
00129     }
00130 private:
00131     AnalogIn o;
00132 };
00133 #endif
00134 
00135 #if DEVICE_ANALOGOUT
00136 class RpcAnalogOut : public RPC {
00137 public:
00138     RpcAnalogOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
00139 
00140     float read(void) {return o.read();}
00141     void write(float a0) {o.write(a0);}
00142     void write_u16(unsigned short a0) {o.write_u16(a0);}
00143 
00144     virtual const struct rpc_method *get_rpc_methods() {
00145         static const rpc_method rpc_methods[] = {
00146             {"read", rpc_method_caller<float, RpcAnalogOut, &RpcAnalogOut::read>},
00147             {"write", rpc_method_caller<RpcAnalogOut, float, &RpcAnalogOut::write>},
00148             {"write_u16", rpc_method_caller<RpcAnalogOut, unsigned short, &RpcAnalogOut::write_u16>},
00149             RPC_METHOD_SUPER(RPC)
00150         };
00151         return rpc_methods;
00152     }
00153     static struct rpc_class *get_rpc_class() {
00154         static const rpc_function funcs[] = {
00155             {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcAnalogOut, PinName, const char*> >},
00156             RPC_METHOD_END
00157         };
00158         static rpc_class c = {"AnalogOut", funcs, NULL};
00159         return &c;
00160     }
00161 private:
00162     AnalogOut o;
00163 };
00164 #endif
00165 
00166 #if DEVICE_PWMOUT
00167 class RpcPwmOut : public RPC {
00168 public:
00169     RpcPwmOut(PinName a0, const char *name=NULL) : RPC(name), o(a0) {}
00170 
00171     float read(void) {return o.read();}
00172     void write(float a0) {o.write(a0);}
00173     void period(float a0) {o.period(a0);}
00174     void period_ms(int a0) {o.period_ms(a0);}
00175     void pulsewidth(float a0) {o.pulsewidth(a0);}
00176     void pulsewidth_ms(int a0) {o.pulsewidth_ms(a0);}
00177 
00178     virtual const struct rpc_method *get_rpc_methods() {
00179         static const rpc_method rpc_methods[] = {
00180             {"read", rpc_method_caller<float, RpcPwmOut, &RpcPwmOut::read>},
00181             {"write", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::write>},
00182             {"period", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::period>},
00183             {"period_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::period_ms>},
00184             {"pulsewidth", rpc_method_caller<RpcPwmOut, float, &RpcPwmOut::pulsewidth>},
00185             {"pulsewidth_ms", rpc_method_caller<RpcPwmOut, int, &RpcPwmOut::pulsewidth_ms>},
00186             RPC_METHOD_SUPER(RPC)
00187         };
00188         return rpc_methods;
00189     }
00190     static struct rpc_class *get_rpc_class() {
00191         static const rpc_function funcs[] = {
00192             {"new", rpc_function_caller<const char*, PinName, const char*, &RPC::construct<RpcPwmOut, PinName, const char*> >},
00193             RPC_METHOD_END
00194         };
00195         static rpc_class c = {"PwmOut", funcs, NULL};
00196         return &c;
00197     }
00198 private:
00199     PwmOut o;
00200 };
00201 #endif
00202 
00203 #if DEVICE_SPI
00204 class RpcSPI : public RPC {
00205 public:
00206     RpcSPI(PinName a0, PinName a1, PinName a2, const char *name=NULL) : RPC(name), o(a0, a1, a2) {}
00207 
00208     void format(int a0, int a1) {o.format(a0, a1);}
00209     void frequency(int a0) {o.frequency(a0);}
00210     int write(int a0) {return o.write(a0);}
00211 
00212     virtual const struct rpc_method *get_rpc_methods() {
00213         static const rpc_method rpc_methods[] = {
00214             {"format", rpc_method_caller<RpcSPI, int, int, &RpcSPI::format>},
00215             {"frequency", rpc_method_caller<RpcSPI, int, &RpcSPI::frequency>},
00216             {"write", rpc_method_caller<int, RpcSPI, int, &RpcSPI::write>},
00217             RPC_METHOD_SUPER(RPC)
00218         };
00219         return rpc_methods;
00220     }
00221     static struct rpc_class *get_rpc_class() {
00222         static const rpc_function funcs[] = {
00223             {"new", rpc_function_caller<const char*, PinName, PinName, PinName, const char*, &RPC::construct<RpcSPI, PinName, PinName, PinName, const char*> >},
00224             RPC_METHOD_END
00225         };
00226         static rpc_class c = {"SPI", funcs, NULL};
00227         return &c;
00228     }
00229 private:
00230     SPI o;
00231 };
00232 #endif
00233 
00234 #if DEVICE_SERIAL
00235 class RpcSerial : public RPC {
00236 public:
00237     RpcSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {}
00238 
00239     void baud(int a0) {o.baud(a0);}
00240     int readable(void) {return o.readable();}
00241     int writeable(void) {return o.writeable();}
00242     int putc(int a0) {return o.putc(a0);}
00243     int getc(void) {return o.getc();}
00244     int puts(const char * a0) {return o.puts(a0);}
00245 
00246     virtual const struct rpc_method *get_rpc_methods() {
00247         static const rpc_method rpc_methods[] = {
00248             {"baud", rpc_method_caller<RpcSerial, int, &RpcSerial::baud>},
00249             {"readable", rpc_method_caller<int, RpcSerial, &RpcSerial::readable>},
00250             {"writeable", rpc_method_caller<int, RpcSerial, &RpcSerial::writeable>},
00251             {"putc", rpc_method_caller<int, RpcSerial, int, &RpcSerial::putc>},
00252             {"getc", rpc_method_caller<int, RpcSerial, &RpcSerial::getc>},
00253             {"puts", rpc_method_caller<int, RpcSerial, const char *, &RpcSerial::puts>},
00254             RPC_METHOD_SUPER(RPC)
00255         };
00256         return rpc_methods;
00257     }
00258     static struct rpc_class *get_rpc_class() {
00259         static const rpc_function funcs[] = {
00260             {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcSerial, PinName, PinName, const char*> >},
00261             RPC_METHOD_END
00262         };
00263         static rpc_class c = {"Serial", funcs, NULL};
00264         return &c;
00265     }
00266 private:
00267     Serial o;
00268 };
00269 #endif
00270 
00271 class RpcTimer : public RPC {
00272 public:
00273     RpcTimer(const char *name=NULL) : RPC(name), o() {}
00274 
00275     void start(void) {o.start();}
00276     void stop(void) {o.stop();}
00277     void reset(void) {o.reset();}
00278     float read(void) {return o.read();}
00279     int read_ms(void) {return o.read_ms();}
00280     int read_us(void) {return o.read_us();}
00281 
00282     virtual const struct rpc_method *get_rpc_methods() {
00283         static const rpc_method rpc_methods[] = {
00284             {"start", rpc_method_caller<RpcTimer, &RpcTimer::start>},
00285             {"stop", rpc_method_caller<RpcTimer, &RpcTimer::stop>},
00286             {"reset", rpc_method_caller<RpcTimer, &RpcTimer::reset>},
00287             {"read", rpc_method_caller<float, RpcTimer, &RpcTimer::read>},
00288             {"read_ms", rpc_method_caller<int, RpcTimer, &RpcTimer::read_ms>},
00289             {"read_us", rpc_method_caller<int, RpcTimer, &RpcTimer::read_us>},
00290             RPC_METHOD_SUPER(RPC)
00291         };
00292         return rpc_methods;
00293     }
00294     static struct rpc_class *get_rpc_class() {
00295         static const rpc_function funcs[] = {
00296             {"new", rpc_function_caller<const char*, const char*, &RPC::construct<RpcTimer, const char*> >},
00297             RPC_METHOD_END
00298         };
00299         static rpc_class c = {"Timer", funcs, NULL};
00300         return &c;
00301     }
00302 private:
00303     Timer o;
00304 };
00305 
00306 }
00307 
00308 #endif