Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>
Dependencies: EthernetNetIf HTTPServer QEI_hw RPCInterface mbed
main.cpp@12:c02b08dacc45, 2012-04-06 (annotated)
- Committer:
- Yo_Robot
- Date:
- Fri Apr 06 02:19:39 2012 +0000
- Revision:
- 12:c02b08dacc45
- Parent:
- 9:6976ac1a430e
- Child:
- 13:649543aa8b1d
v0.3 Ethernet RPC. Mismos archivos setup.h y setup.cpp para serial y ethernet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yo_Robot | 4:552beeda4722 | 1 | // GENERADOR DE FRECUENCIAS |
Yo_Robot | 3:8d5a9e3cd680 | 2 | |
Yo_Robot | 3:8d5a9e3cd680 | 3 | #include "mbed.h" |
Yo_Robot | 3:8d5a9e3cd680 | 4 | #include "setup.h" |
Yo_Robot | 8:958dfe5052b9 | 5 | #include "EthernetNetIf.h" |
Yo_Robot | 8:958dfe5052b9 | 6 | #include "HTTPServer.h" |
Yo_Robot | 8:958dfe5052b9 | 7 | #include "RPCFunction.h" |
Yo_Robot | 8:958dfe5052b9 | 8 | #include "RPCVariable.h" |
Yo_Robot | 8:958dfe5052b9 | 9 | #include "SerialRPCInterface.h" |
Yo_Robot | 3:8d5a9e3cd680 | 10 | |
Yo_Robot | 12:c02b08dacc45 | 11 | Serial pc( USBTX, USBRX ); |
Yo_Robot | 9:6976ac1a430e | 12 | |
Yo_Robot | 9:6976ac1a430e | 13 | DigitalOut pin_son( p30 ); // SON |
Yo_Robot | 9:6976ac1a430e | 14 | DigitalOut pin_dir( p29 ); // SIGN+ |
Yo_Robot | 9:6976ac1a430e | 15 | InterruptIn pin_alm( p14 ); // ALM |
Yo_Robot | 9:6976ac1a430e | 16 | AnalogOut aout( p18 ); // 0.0 a 1.0 float |
Yo_Robot | 9:6976ac1a430e | 17 | |
Yo_Robot | 8:958dfe5052b9 | 18 | LocalFileSystem fs("webfs"); |
Yo_Robot | 5:c5aea1eb10bb | 19 | |
Yo_Robot | 8:958dfe5052b9 | 20 | EthernetNetIf eth; |
Yo_Robot | 8:958dfe5052b9 | 21 | HTTPServer svr; |
Yo_Robot | 8:958dfe5052b9 | 22 | |
Yo_Robot | 12:c02b08dacc45 | 23 | // Añadir funciones al Protocolo RPC |
Yo_Robot | 12:c02b08dacc45 | 24 | RPCFunction SetFQ (&setPTO_eth, "PTO"); |
Yo_Robot | 12:c02b08dacc45 | 25 | RPCFunction SetAOUT(&setAout_eth, "AOUT"); |
Yo_Robot | 12:c02b08dacc45 | 26 | RPCFunction SetDIR (&setDir_eth, "DIR"); |
Yo_Robot | 12:c02b08dacc45 | 27 | RPCFunction SetSON (&setSON_eth, "SON"); |
Yo_Robot | 12:c02b08dacc45 | 28 | // falta encoders y alarma..... |
Yo_Robot | 8:958dfe5052b9 | 29 | |
Yo_Robot | 3:8d5a9e3cd680 | 30 | |
Yo_Robot | 3:8d5a9e3cd680 | 31 | int main() { |
Yo_Robot | 8:958dfe5052b9 | 32 | |
Yo_Robot | 8:958dfe5052b9 | 33 | Base::add_rpc_class<AnalogIn>(); |
Yo_Robot | 8:958dfe5052b9 | 34 | Base::add_rpc_class<AnalogOut>(); |
Yo_Robot | 8:958dfe5052b9 | 35 | Base::add_rpc_class<DigitalIn>(); |
Yo_Robot | 8:958dfe5052b9 | 36 | Base::add_rpc_class<DigitalOut>(); |
Yo_Robot | 8:958dfe5052b9 | 37 | Base::add_rpc_class<DigitalInOut>(); |
Yo_Robot | 8:958dfe5052b9 | 38 | Base::add_rpc_class<PwmOut>(); |
Yo_Robot | 8:958dfe5052b9 | 39 | Base::add_rpc_class<Timer>(); |
Yo_Robot | 8:958dfe5052b9 | 40 | Base::add_rpc_class<BusOut>(); |
Yo_Robot | 8:958dfe5052b9 | 41 | Base::add_rpc_class<BusIn>(); |
Yo_Robot | 8:958dfe5052b9 | 42 | Base::add_rpc_class<BusInOut>(); |
Yo_Robot | 8:958dfe5052b9 | 43 | Base::add_rpc_class<Serial>(); |
Yo_Robot | 8:958dfe5052b9 | 44 | |
Yo_Robot | 8:958dfe5052b9 | 45 | printf("\nSetting Up...\n"); |
Yo_Robot | 8:958dfe5052b9 | 46 | |
Yo_Robot | 8:958dfe5052b9 | 47 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 8:958dfe5052b9 | 48 | if( ethErr ) |
Yo_Robot | 8:958dfe5052b9 | 49 | { |
Yo_Robot | 9:6976ac1a430e | 50 | printf( "Error %d en setup\n", ethErr ); |
Yo_Robot | 8:958dfe5052b9 | 51 | return -1; |
Yo_Robot | 8:958dfe5052b9 | 52 | } |
Yo_Robot | 8:958dfe5052b9 | 53 | |
Yo_Robot | 8:958dfe5052b9 | 54 | printf("Configuracion Correcta\n"); |
Yo_Robot | 8:958dfe5052b9 | 55 | |
Yo_Robot | 8:958dfe5052b9 | 56 | FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path |
Yo_Robot | 8:958dfe5052b9 | 57 | FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path |
Yo_Robot | 8:958dfe5052b9 | 58 | |
Yo_Robot | 8:958dfe5052b9 | 59 | svr.addHandler<SimpleHandler>("/hello"); |
Yo_Robot | 8:958dfe5052b9 | 60 | svr.addHandler<RPCHandler>("/rpc"); |
Yo_Robot | 8:958dfe5052b9 | 61 | svr.addHandler<FSHandler>("/files"); |
Yo_Robot | 8:958dfe5052b9 | 62 | svr.addHandler<FSHandler>("/"); //Default handler |
Yo_Robot | 8:958dfe5052b9 | 63 | //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
Yo_Robot | 8:958dfe5052b9 | 64 | |
Yo_Robot | 8:958dfe5052b9 | 65 | svr.bind(80); |
Yo_Robot | 6:b4dae934e1ea | 66 | setTimer2(); |
Yo_Robot | 3:8d5a9e3cd680 | 67 | |
Yo_Robot | 8:958dfe5052b9 | 68 | printf("Listening...\n"); |
Yo_Robot | 4:552beeda4722 | 69 | |
Yo_Robot | 3:8d5a9e3cd680 | 70 | while(1) { |
Yo_Robot | 8:958dfe5052b9 | 71 | |
Yo_Robot | 8:958dfe5052b9 | 72 | Net::poll(); |
Yo_Robot | 3:8d5a9e3cd680 | 73 | |
Yo_Robot | 3:8d5a9e3cd680 | 74 | } |
Yo_Robot | 8:958dfe5052b9 | 75 | } |
Yo_Robot | 8:958dfe5052b9 | 76 | |
Yo_Robot | 8:958dfe5052b9 | 77 |