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@18:cf1e07d82630, 2012-05-09 (annotated)
- Committer:
- Yo_Robot
- Date:
- Wed May 09 20:51:10 2012 +0000
- Revision:
- 18:cf1e07d82630
- Parent:
- 17:a4f380bc2516
- Child:
- 19:c26cf8a48986
No se puede configurar ethernet aun, el objeto debe ser global... espero q todavia se pueda...
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 | 18:cf1e07d82630 | 9 | //#include "SerialRPCInterface.h" |
Yo_Robot | 9:6976ac1a430e | 10 | |
Yo_Robot | 18:cf1e07d82630 | 11 | Serial pc( USBTX, USBRX ); //Comunicacion Serial directa al computador |
Yo_Robot | 18:cf1e07d82630 | 12 | Serial RS_232(p9, p10); //Comunicacion Serial para MAX232 |
Yo_Robot | 18:cf1e07d82630 | 13 | Serial encoder(p28, p27); //Comunicacion Serial para tarjeta del encoder |
Yo_Robot | 18:cf1e07d82630 | 14 | |
Yo_Robot | 18:cf1e07d82630 | 15 | DigitalOut pin_son( p7 ); // SON |
Yo_Robot | 18:cf1e07d82630 | 16 | DigitalOut pin_dir( p26 ); // SIGN+ |
Yo_Robot | 18:cf1e07d82630 | 17 | InterruptIn pin_alm( p8 ); // ALM |
Yo_Robot | 18:cf1e07d82630 | 18 | AnalogOut aout( p18 ); // 0.0 a 1.0 float |
Yo_Robot | 9:6976ac1a430e | 19 | |
Yo_Robot | 16:d50665706f21 | 20 | DigitalIn isHTTP( p15 ); // Modo Ethernet/Serial |
Yo_Robot | 16:d50665706f21 | 21 | DigitalIn isFast( p16 ); // Serial Alta velocidad/Baja Velocidad |
Yo_Robot | 18:cf1e07d82630 | 22 | DigitalIn isPC ( p17 ); // Salida a compuador o MAX232 |
Yo_Robot | 18:cf1e07d82630 | 23 | |
Yo_Robot | 18:cf1e07d82630 | 24 | // Faltan las interrupciones del enconder. |
Yo_Robot | 18:cf1e07d82630 | 25 | |
Yo_Robot | 18:cf1e07d82630 | 26 | EthernetNetIf eth; |
Yo_Robot | 18:cf1e07d82630 | 27 | HTTPServer svr; |
Yo_Robot | 18:cf1e07d82630 | 28 | |
Yo_Robot | 13:649543aa8b1d | 29 | |
Yo_Robot | 17:a4f380bc2516 | 30 | LocalFileSystem fs("local"); |
Yo_Robot | 5:c5aea1eb10bb | 31 | |
Yo_Robot | 8:958dfe5052b9 | 32 | |
Yo_Robot | 13:649543aa8b1d | 33 | // Anadir funciones al Protocolo RPC |
Yo_Robot | 12:c02b08dacc45 | 34 | RPCFunction SetFQ (&setPTO_eth, "PTO"); |
Yo_Robot | 12:c02b08dacc45 | 35 | RPCFunction SetAOUT(&setAout_eth, "AOUT"); |
Yo_Robot | 12:c02b08dacc45 | 36 | RPCFunction SetDIR (&setDir_eth, "DIR"); |
Yo_Robot | 12:c02b08dacc45 | 37 | RPCFunction SetSON (&setSON_eth, "SON"); |
Yo_Robot | 16:d50665706f21 | 38 | RPCFunction SetANG (&setANG_eth, "ANG"); |
Yo_Robot | 16:d50665706f21 | 39 | RPCFunction SetSpd (&setSPD_eth, "VAN"); |
Yo_Robot | 16:d50665706f21 | 40 | RPCFunction ReadSpd(&getENC_eth, "VLC"); |
Yo_Robot | 8:958dfe5052b9 | 41 | |
Yo_Robot | 3:8d5a9e3cd680 | 42 | |
Yo_Robot | 3:8d5a9e3cd680 | 43 | int main() { |
Yo_Robot | 8:958dfe5052b9 | 44 | |
Yo_Robot | 18:cf1e07d82630 | 45 | //**********************************************************************************************// |
Yo_Robot | 13:649543aa8b1d | 46 | if( isHTTP ) //Configura Red Ethernet |
Yo_Robot | 13:649543aa8b1d | 47 | { |
Yo_Robot | 18:cf1e07d82630 | 48 | |
Yo_Robot | 13:649543aa8b1d | 49 | Base::add_rpc_class<AnalogIn>(); |
Yo_Robot | 13:649543aa8b1d | 50 | Base::add_rpc_class<AnalogOut>(); |
Yo_Robot | 13:649543aa8b1d | 51 | Base::add_rpc_class<DigitalIn>(); |
Yo_Robot | 13:649543aa8b1d | 52 | Base::add_rpc_class<DigitalOut>(); |
Yo_Robot | 13:649543aa8b1d | 53 | Base::add_rpc_class<DigitalInOut>(); |
Yo_Robot | 13:649543aa8b1d | 54 | Base::add_rpc_class<PwmOut>(); |
Yo_Robot | 13:649543aa8b1d | 55 | Base::add_rpc_class<Timer>(); |
Yo_Robot | 13:649543aa8b1d | 56 | Base::add_rpc_class<BusOut>(); |
Yo_Robot | 13:649543aa8b1d | 57 | Base::add_rpc_class<BusIn>(); |
Yo_Robot | 13:649543aa8b1d | 58 | Base::add_rpc_class<BusInOut>(); |
Yo_Robot | 13:649543aa8b1d | 59 | Base::add_rpc_class<Serial>(); |
Yo_Robot | 17:a4f380bc2516 | 60 | |
Yo_Robot | 18:cf1e07d82630 | 61 | printf("Setting up...\n"); |
Yo_Robot | 18:cf1e07d82630 | 62 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 18:cf1e07d82630 | 63 | if(ethErr) |
Yo_Robot | 13:649543aa8b1d | 64 | { |
Yo_Robot | 18:cf1e07d82630 | 65 | printf("Error %d in setup.\n", ethErr); |
Yo_Robot | 18:cf1e07d82630 | 66 | return -1; |
Yo_Robot | 18:cf1e07d82630 | 67 | } |
Yo_Robot | 18:cf1e07d82630 | 68 | printf("Setup OK\n"); |
Yo_Robot | 18:cf1e07d82630 | 69 | |
Yo_Robot | 18:cf1e07d82630 | 70 | |
Yo_Robot | 18:cf1e07d82630 | 71 | FSHandler::mount("/local", "/files"); //Monta /local en /files que es el directorio web |
Yo_Robot | 18:cf1e07d82630 | 72 | FSHandler::mount("/local", "/"); //Mount /local en / que es el directorio raiz |
Yo_Robot | 13:649543aa8b1d | 73 | |
Yo_Robot | 18:cf1e07d82630 | 74 | //Handles para la comunicacion |
Yo_Robot | 13:649543aa8b1d | 75 | svr.addHandler<SimpleHandler>("/hello"); |
Yo_Robot | 13:649543aa8b1d | 76 | svr.addHandler<RPCHandler>("/rpc"); |
Yo_Robot | 13:649543aa8b1d | 77 | svr.addHandler<FSHandler>("/files"); |
Yo_Robot | 18:cf1e07d82630 | 78 | svr.addHandler<FSHandler>("/"); |
Yo_Robot | 18:cf1e07d82630 | 79 | |
Yo_Robot | 18:cf1e07d82630 | 80 | svr.bind(80); // Puerto de comunicacion. |
Yo_Robot | 18:cf1e07d82630 | 81 | |
Yo_Robot | 18:cf1e07d82630 | 82 | printf("Listo para comunicacion...\n"); |
Yo_Robot | 13:649543aa8b1d | 83 | |
Yo_Robot | 18:cf1e07d82630 | 84 | // Para probar la correcta configuracion acceder a mbed.htm |
Yo_Robot | 18:cf1e07d82630 | 85 | // http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
Yo_Robot | 18:cf1e07d82630 | 86 | |
Yo_Robot | 13:649543aa8b1d | 87 | } |
Yo_Robot | 18:cf1e07d82630 | 88 | //**********************************************************************************************************// |
Yo_Robot | 18:cf1e07d82630 | 89 | |
Yo_Robot | 17:a4f380bc2516 | 90 | |
Yo_Robot | 15:a1ffa32ce9d1 | 91 | else // Caso Contrario Anadir modo Serial |
Yo_Robot | 8:958dfe5052b9 | 92 | { |
Yo_Robot | 13:649543aa8b1d | 93 | pc.attach( &ISR_Serial ); |
Yo_Robot | 13:649543aa8b1d | 94 | if( isFast ) //Configurar Serial a alta velocidad |
Yo_Robot | 13:649543aa8b1d | 95 | pc.baud( 115200 ); |
Yo_Robot | 8:958dfe5052b9 | 96 | } |
Yo_Robot | 8:958dfe5052b9 | 97 | |
Yo_Robot | 17:a4f380bc2516 | 98 | // Ajustes iniciales del Driver |
Yo_Robot | 13:649543aa8b1d | 99 | setTimer2(); // Configurar PTO |
Yo_Robot | 13:649543aa8b1d | 100 | pin_son = 0; // Servo Apagado por defecto |
Yo_Robot | 13:649543aa8b1d | 101 | aout = 0.5; // Voltaje de salida 0V por defecto( +-10V! ) |
Yo_Robot | 8:958dfe5052b9 | 102 | |
Yo_Robot | 14:039d070732d5 | 103 | pin_alm.rise( &ISR_Alarm ); //Entrada de la alarma |
Yo_Robot | 14:039d070732d5 | 104 | |
Yo_Robot | 13:649543aa8b1d | 105 | while(1) |
Yo_Robot | 13:649543aa8b1d | 106 | { |
Yo_Robot | 13:649543aa8b1d | 107 | if( isHTTP ) |
Yo_Robot | 15:a1ffa32ce9d1 | 108 | Net::poll(); // Revisa la red solo si la coneccion es HTTP |
Yo_Robot | 13:649543aa8b1d | 109 | } |
Yo_Robot | 8:958dfe5052b9 | 110 | } |
Yo_Robot | 8:958dfe5052b9 | 111 |