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@19:c26cf8a48986, 2012-05-23 (annotated)
- Committer:
- Yo_Robot
- Date:
- Wed May 23 17:09:28 2012 +0000
- Revision:
- 19:c26cf8a48986
- Parent:
- 18:cf1e07d82630
- Child:
- 20:4b154134ab20
Version 1.5 El Switch de configuracin funciona bien. Archivo de configuracin aun no se prueba. El conector ethernet tiene problemas en la placa 1.
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 | 19:c26cf8a48986 | 24 | DigitalOut led_verde( p21 ); // Led verde del conector Ethernet |
Yo_Robot | 19:c26cf8a48986 | 25 | DigitalOut led_rojo( p22 ); // Led naranja del conector Ethernet |
Yo_Robot | 19:c26cf8a48986 | 26 | |
Yo_Robot | 18:cf1e07d82630 | 27 | // Faltan las interrupciones del enconder. |
Yo_Robot | 18:cf1e07d82630 | 28 | |
Yo_Robot | 18:cf1e07d82630 | 29 | EthernetNetIf eth; |
Yo_Robot | 18:cf1e07d82630 | 30 | HTTPServer svr; |
Yo_Robot | 18:cf1e07d82630 | 31 | |
Yo_Robot | 13:649543aa8b1d | 32 | |
Yo_Robot | 17:a4f380bc2516 | 33 | LocalFileSystem fs("local"); |
Yo_Robot | 5:c5aea1eb10bb | 34 | |
Yo_Robot | 8:958dfe5052b9 | 35 | |
Yo_Robot | 13:649543aa8b1d | 36 | // Anadir funciones al Protocolo RPC |
Yo_Robot | 12:c02b08dacc45 | 37 | RPCFunction SetFQ (&setPTO_eth, "PTO"); |
Yo_Robot | 12:c02b08dacc45 | 38 | RPCFunction SetAOUT(&setAout_eth, "AOUT"); |
Yo_Robot | 12:c02b08dacc45 | 39 | RPCFunction SetDIR (&setDir_eth, "DIR"); |
Yo_Robot | 12:c02b08dacc45 | 40 | RPCFunction SetSON (&setSON_eth, "SON"); |
Yo_Robot | 16:d50665706f21 | 41 | RPCFunction SetANG (&setANG_eth, "ANG"); |
Yo_Robot | 16:d50665706f21 | 42 | RPCFunction SetSpd (&setSPD_eth, "VAN"); |
Yo_Robot | 16:d50665706f21 | 43 | RPCFunction ReadSpd(&getENC_eth, "VLC"); |
Yo_Robot | 8:958dfe5052b9 | 44 | |
Yo_Robot | 3:8d5a9e3cd680 | 45 | |
Yo_Robot | 3:8d5a9e3cd680 | 46 | int main() { |
Yo_Robot | 8:958dfe5052b9 | 47 | |
Yo_Robot | 18:cf1e07d82630 | 48 | //**********************************************************************************************// |
Yo_Robot | 13:649543aa8b1d | 49 | if( isHTTP ) //Configura Red Ethernet |
Yo_Robot | 13:649543aa8b1d | 50 | { |
Yo_Robot | 18:cf1e07d82630 | 51 | |
Yo_Robot | 13:649543aa8b1d | 52 | Base::add_rpc_class<AnalogIn>(); |
Yo_Robot | 13:649543aa8b1d | 53 | Base::add_rpc_class<AnalogOut>(); |
Yo_Robot | 13:649543aa8b1d | 54 | Base::add_rpc_class<DigitalIn>(); |
Yo_Robot | 13:649543aa8b1d | 55 | Base::add_rpc_class<DigitalOut>(); |
Yo_Robot | 13:649543aa8b1d | 56 | Base::add_rpc_class<DigitalInOut>(); |
Yo_Robot | 13:649543aa8b1d | 57 | Base::add_rpc_class<PwmOut>(); |
Yo_Robot | 13:649543aa8b1d | 58 | Base::add_rpc_class<Timer>(); |
Yo_Robot | 13:649543aa8b1d | 59 | Base::add_rpc_class<BusOut>(); |
Yo_Robot | 13:649543aa8b1d | 60 | Base::add_rpc_class<BusIn>(); |
Yo_Robot | 13:649543aa8b1d | 61 | Base::add_rpc_class<BusInOut>(); |
Yo_Robot | 13:649543aa8b1d | 62 | Base::add_rpc_class<Serial>(); |
Yo_Robot | 17:a4f380bc2516 | 63 | |
Yo_Robot | 19:c26cf8a48986 | 64 | printf("Configurando...\n"); |
Yo_Robot | 18:cf1e07d82630 | 65 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 18:cf1e07d82630 | 66 | if(ethErr) |
Yo_Robot | 13:649543aa8b1d | 67 | { |
Yo_Robot | 19:c26cf8a48986 | 68 | printf("Error %d en setup.\n", ethErr); |
Yo_Robot | 18:cf1e07d82630 | 69 | return -1; |
Yo_Robot | 18:cf1e07d82630 | 70 | } |
Yo_Robot | 18:cf1e07d82630 | 71 | printf("Setup OK\n"); |
Yo_Robot | 18:cf1e07d82630 | 72 | |
Yo_Robot | 18:cf1e07d82630 | 73 | FSHandler::mount("/local", "/files"); //Monta /local en /files que es el directorio web |
Yo_Robot | 18:cf1e07d82630 | 74 | FSHandler::mount("/local", "/"); //Mount /local en / que es el directorio raiz |
Yo_Robot | 13:649543aa8b1d | 75 | |
Yo_Robot | 18:cf1e07d82630 | 76 | //Handles para la comunicacion |
Yo_Robot | 13:649543aa8b1d | 77 | svr.addHandler<SimpleHandler>("/hello"); |
Yo_Robot | 13:649543aa8b1d | 78 | svr.addHandler<RPCHandler>("/rpc"); |
Yo_Robot | 13:649543aa8b1d | 79 | svr.addHandler<FSHandler>("/files"); |
Yo_Robot | 18:cf1e07d82630 | 80 | svr.addHandler<FSHandler>("/"); |
Yo_Robot | 18:cf1e07d82630 | 81 | |
Yo_Robot | 18:cf1e07d82630 | 82 | svr.bind(80); // Puerto de comunicacion. |
Yo_Robot | 18:cf1e07d82630 | 83 | |
Yo_Robot | 18:cf1e07d82630 | 84 | printf("Listo para comunicacion...\n"); |
Yo_Robot | 13:649543aa8b1d | 85 | |
Yo_Robot | 18:cf1e07d82630 | 86 | // Para probar la correcta configuracion acceder a mbed.htm |
Yo_Robot | 18:cf1e07d82630 | 87 | // http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
Yo_Robot | 18:cf1e07d82630 | 88 | |
Yo_Robot | 13:649543aa8b1d | 89 | } |
Yo_Robot | 18:cf1e07d82630 | 90 | //**********************************************************************************************************// |
Yo_Robot | 17:a4f380bc2516 | 91 | |
Yo_Robot | 15:a1ffa32ce9d1 | 92 | else // Caso Contrario Anadir modo Serial |
Yo_Robot | 8:958dfe5052b9 | 93 | { |
Yo_Robot | 19:c26cf8a48986 | 94 | if( isPC ) //Si utiliza el Puerto Virtual Incluido. |
Yo_Robot | 19:c26cf8a48986 | 95 | { |
Yo_Robot | 19:c26cf8a48986 | 96 | pc.attach( &ISR_Serial ); |
Yo_Robot | 19:c26cf8a48986 | 97 | if( isFast ) //Configurar Serial a alta velocidad |
Yo_Robot | 19:c26cf8a48986 | 98 | pc.baud( 115200 ); |
Yo_Robot | 19:c26cf8a48986 | 99 | } |
Yo_Robot | 19:c26cf8a48986 | 100 | else // Utiiliza el puerto con MAX232 o directamente (TTL) |
Yo_Robot | 19:c26cf8a48986 | 101 | { |
Yo_Robot | 19:c26cf8a48986 | 102 | RS_232.attach( &ISR_Serial ); |
Yo_Robot | 19:c26cf8a48986 | 103 | if( isFast ) //Configuración serial a alta velocidad |
Yo_Robot | 19:c26cf8a48986 | 104 | RS_232.baud( 115200 ); |
Yo_Robot | 19:c26cf8a48986 | 105 | } |
Yo_Robot | 8:958dfe5052b9 | 106 | } |
Yo_Robot | 8:958dfe5052b9 | 107 | |
Yo_Robot | 17:a4f380bc2516 | 108 | // Ajustes iniciales del Driver |
Yo_Robot | 13:649543aa8b1d | 109 | setTimer2(); // Configurar PTO |
Yo_Robot | 13:649543aa8b1d | 110 | pin_son = 0; // Servo Apagado por defecto |
Yo_Robot | 13:649543aa8b1d | 111 | aout = 0.5; // Voltaje de salida 0V por defecto( +-10V! ) |
Yo_Robot | 8:958dfe5052b9 | 112 | |
Yo_Robot | 19:c26cf8a48986 | 113 | pin_alm.fall( &ISR_Alarm ); //Entrada de la alarma |
Yo_Robot | 14:039d070732d5 | 114 | |
Yo_Robot | 13:649543aa8b1d | 115 | while(1) |
Yo_Robot | 13:649543aa8b1d | 116 | { |
Yo_Robot | 13:649543aa8b1d | 117 | if( isHTTP ) |
Yo_Robot | 15:a1ffa32ce9d1 | 118 | Net::poll(); // Revisa la red solo si la coneccion es HTTP |
Yo_Robot | 13:649543aa8b1d | 119 | } |
Yo_Robot | 8:958dfe5052b9 | 120 | } |
Yo_Robot | 8:958dfe5052b9 | 121 |