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@14:039d070732d5, 2012-04-21 (annotated)
- Committer:
- Yo_Robot
- Date:
- Sat Apr 21 14:50:06 2012 +0000
- Revision:
- 14:039d070732d5
- Parent:
- 13:649543aa8b1d
- Child:
- 15:a1ffa32ce9d1
Version 1.1 Serial y HTTP. Se cambio los pines de SON y DIR, se aumento la resolucin del DAC. En HTTP mbed envia "Ok" o "AL" dependiendo del estado del pin_alm, y en serial y HTTP se ejecuta la rutina en modo .rise
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 | 13:649543aa8b1d | 11 | Serial pc( USBTX, USBRX ); |
Yo_Robot | 9:6976ac1a430e | 12 | |
Yo_Robot | 14:039d070732d5 | 13 | DigitalOut pin_son( p26 ); // SON |
Yo_Robot | 14:039d070732d5 | 14 | DigitalOut pin_dir( p25 ); // 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 | 13:649543aa8b1d | 18 | DigitalIn isHTTP( p21 ); // Modo Ethernet/Serial |
Yo_Robot | 13:649543aa8b1d | 19 | DigitalIn isFast( p22 ); // Serial Alta velocidad/Baja Velocidad |
Yo_Robot | 13:649543aa8b1d | 20 | |
Yo_Robot | 8:958dfe5052b9 | 21 | LocalFileSystem fs("webfs"); |
Yo_Robot | 5:c5aea1eb10bb | 22 | |
Yo_Robot | 8:958dfe5052b9 | 23 | EthernetNetIf eth; |
Yo_Robot | 8:958dfe5052b9 | 24 | HTTPServer svr; |
Yo_Robot | 8:958dfe5052b9 | 25 | |
Yo_Robot | 13:649543aa8b1d | 26 | // Anadir funciones al Protocolo RPC |
Yo_Robot | 12:c02b08dacc45 | 27 | RPCFunction SetFQ (&setPTO_eth, "PTO"); |
Yo_Robot | 12:c02b08dacc45 | 28 | RPCFunction SetAOUT(&setAout_eth, "AOUT"); |
Yo_Robot | 12:c02b08dacc45 | 29 | RPCFunction SetDIR (&setDir_eth, "DIR"); |
Yo_Robot | 12:c02b08dacc45 | 30 | RPCFunction SetSON (&setSON_eth, "SON"); |
Yo_Robot | 12:c02b08dacc45 | 31 | // falta encoders y alarma..... |
Yo_Robot | 8:958dfe5052b9 | 32 | |
Yo_Robot | 3:8d5a9e3cd680 | 33 | |
Yo_Robot | 3:8d5a9e3cd680 | 34 | int main() { |
Yo_Robot | 8:958dfe5052b9 | 35 | |
Yo_Robot | 13:649543aa8b1d | 36 | if( isHTTP ) //Configura Red Ethernet |
Yo_Robot | 13:649543aa8b1d | 37 | { |
Yo_Robot | 13:649543aa8b1d | 38 | Base::add_rpc_class<AnalogIn>(); |
Yo_Robot | 13:649543aa8b1d | 39 | Base::add_rpc_class<AnalogOut>(); |
Yo_Robot | 13:649543aa8b1d | 40 | Base::add_rpc_class<DigitalIn>(); |
Yo_Robot | 13:649543aa8b1d | 41 | Base::add_rpc_class<DigitalOut>(); |
Yo_Robot | 13:649543aa8b1d | 42 | Base::add_rpc_class<DigitalInOut>(); |
Yo_Robot | 13:649543aa8b1d | 43 | Base::add_rpc_class<PwmOut>(); |
Yo_Robot | 13:649543aa8b1d | 44 | Base::add_rpc_class<Timer>(); |
Yo_Robot | 13:649543aa8b1d | 45 | Base::add_rpc_class<BusOut>(); |
Yo_Robot | 13:649543aa8b1d | 46 | Base::add_rpc_class<BusIn>(); |
Yo_Robot | 13:649543aa8b1d | 47 | Base::add_rpc_class<BusInOut>(); |
Yo_Robot | 13:649543aa8b1d | 48 | Base::add_rpc_class<Serial>(); |
Yo_Robot | 13:649543aa8b1d | 49 | |
Yo_Robot | 13:649543aa8b1d | 50 | printf("\nSetting Up...\n"); |
Yo_Robot | 8:958dfe5052b9 | 51 | |
Yo_Robot | 13:649543aa8b1d | 52 | EthernetErr ethErr = eth.setup(); |
Yo_Robot | 13:649543aa8b1d | 53 | if( ethErr ) |
Yo_Robot | 13:649543aa8b1d | 54 | { |
Yo_Robot | 13:649543aa8b1d | 55 | printf( "Error %d en setup\n", ethErr ); |
Yo_Robot | 13:649543aa8b1d | 56 | return -1; |
Yo_Robot | 13:649543aa8b1d | 57 | } |
Yo_Robot | 13:649543aa8b1d | 58 | |
Yo_Robot | 13:649543aa8b1d | 59 | printf("Configuracion Correcta\n"); |
Yo_Robot | 8:958dfe5052b9 | 60 | |
Yo_Robot | 13:649543aa8b1d | 61 | FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path |
Yo_Robot | 13:649543aa8b1d | 62 | FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path |
Yo_Robot | 13:649543aa8b1d | 63 | |
Yo_Robot | 13:649543aa8b1d | 64 | svr.addHandler<SimpleHandler>("/hello"); |
Yo_Robot | 13:649543aa8b1d | 65 | svr.addHandler<RPCHandler>("/rpc"); |
Yo_Robot | 13:649543aa8b1d | 66 | svr.addHandler<FSHandler>("/files"); |
Yo_Robot | 13:649543aa8b1d | 67 | svr.addHandler<FSHandler>("/"); //Default handler |
Yo_Robot | 13:649543aa8b1d | 68 | //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
Yo_Robot | 13:649543aa8b1d | 69 | |
Yo_Robot | 13:649543aa8b1d | 70 | svr.bind(80); |
Yo_Robot | 13:649543aa8b1d | 71 | |
Yo_Robot | 13:649543aa8b1d | 72 | printf("Listening...\n"); |
Yo_Robot | 13:649543aa8b1d | 73 | } |
Yo_Robot | 14:039d070732d5 | 74 | else // Caso Contrario Añadir modo Serial |
Yo_Robot | 8:958dfe5052b9 | 75 | { |
Yo_Robot | 13:649543aa8b1d | 76 | pc.attach( &ISR_Serial ); |
Yo_Robot | 13:649543aa8b1d | 77 | if( isFast ) //Configurar Serial a alta velocidad |
Yo_Robot | 13:649543aa8b1d | 78 | pc.baud( 115200 ); |
Yo_Robot | 8:958dfe5052b9 | 79 | } |
Yo_Robot | 8:958dfe5052b9 | 80 | |
Yo_Robot | 13:649543aa8b1d | 81 | setTimer2(); // Configurar PTO |
Yo_Robot | 13:649543aa8b1d | 82 | pin_son = 0; // Servo Apagado por defecto |
Yo_Robot | 13:649543aa8b1d | 83 | aout = 0.5; // Voltaje de salida 0V por defecto( +-10V! ) |
Yo_Robot | 8:958dfe5052b9 | 84 | |
Yo_Robot | 14:039d070732d5 | 85 | pin_alm.rise( &ISR_Alarm ); //Entrada de la alarma |
Yo_Robot | 14:039d070732d5 | 86 | |
Yo_Robot | 13:649543aa8b1d | 87 | while(1) |
Yo_Robot | 13:649543aa8b1d | 88 | { |
Yo_Robot | 13:649543aa8b1d | 89 | if( isHTTP ) |
Yo_Robot | 14:039d070732d5 | 90 | Net::poll(); // Revisa la red solo si la conección es HTTP |
Yo_Robot | 13:649543aa8b1d | 91 | } |
Yo_Robot | 8:958dfe5052b9 | 92 | } |
Yo_Robot | 8:958dfe5052b9 | 93 |