Proyecto de Tesis en Mecatrónica. Universidad Técnica del Norte. Ernesto Palacios <mecatronica.mid@gmail.com>

Dependencies:   EthernetNetIf HTTPServer QEI_hw RPCInterface mbed

Revision:
13:649543aa8b1d
Parent:
12:c02b08dacc45
Child:
14:039d070732d5
--- a/main.cpp	Fri Apr 06 02:19:39 2012 +0000
+++ b/main.cpp	Wed Apr 11 02:15:24 2012 +0000
@@ -8,19 +8,22 @@
 #include "RPCVariable.h"
 #include "SerialRPCInterface.h"
 
-Serial     		pc( USBTX, USBRX );
+Serial          pc( USBTX, USBRX );
 
 DigitalOut      pin_son( p30 );   // SON
 DigitalOut      pin_dir( p29 );   // SIGN+
 InterruptIn     pin_alm( p14 );   // ALM 
 AnalogOut       aout( p18 );      // 0.0 a 1.0 float
 
+DigitalIn       isHTTP( p21 );   // Modo Ethernet/Serial
+DigitalIn       isFast( p22 );   // Serial Alta velocidad/Baja Velocidad
+
 LocalFileSystem fs("webfs");
 
 EthernetNetIf eth;  
 HTTPServer svr;
 
-//  Añadir funciones al Protocolo RPC
+//  Anadir funciones al Protocolo RPC
 RPCFunction SetFQ  (&setPTO_eth,  "PTO");
 RPCFunction SetAOUT(&setAout_eth, "AOUT");
 RPCFunction SetDIR (&setDir_eth,  "DIR");
@@ -30,48 +33,59 @@
 
 int main() {
     
-    Base::add_rpc_class<AnalogIn>();
-    Base::add_rpc_class<AnalogOut>();
-    Base::add_rpc_class<DigitalIn>();
-    Base::add_rpc_class<DigitalOut>();
-    Base::add_rpc_class<DigitalInOut>();
-    Base::add_rpc_class<PwmOut>();
-    Base::add_rpc_class<Timer>();
-    Base::add_rpc_class<BusOut>();
-    Base::add_rpc_class<BusIn>();
-    Base::add_rpc_class<BusInOut>();
-    Base::add_rpc_class<Serial>();
+    if( isHTTP )   //Configura Red Ethernet
+    {
+        Base::add_rpc_class<AnalogIn>();
+        Base::add_rpc_class<AnalogOut>();
+        Base::add_rpc_class<DigitalIn>();
+        Base::add_rpc_class<DigitalOut>();
+        Base::add_rpc_class<DigitalInOut>();
+        Base::add_rpc_class<PwmOut>();
+        Base::add_rpc_class<Timer>();
+        Base::add_rpc_class<BusOut>();
+        Base::add_rpc_class<BusIn>();
+        Base::add_rpc_class<BusInOut>();
+        Base::add_rpc_class<Serial>();
+    
+        printf("\nSetting Up...\n");
     
-    printf("\nSetting Up...\n");
+        EthernetErr ethErr = eth.setup();
+        if( ethErr )
+        {
+            printf( "Error %d en setup\n", ethErr );
+            return -1;
+        }
+    
+        printf("Configuracion Correcta\n");
     
-    EthernetErr ethErr = eth.setup();
-    if( ethErr )
+        FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
+        FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
+  
+        svr.addHandler<SimpleHandler>("/hello");
+        svr.addHandler<RPCHandler>("/rpc");
+        svr.addHandler<FSHandler>("/files");
+        svr.addHandler<FSHandler>("/"); //Default handler
+        //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
+   
+        svr.bind(80);
+        
+        printf("Listening...\n");
+    }
+    else  // Caso Contrario Añadir modo Serial
     {
-        printf( "Error %d en setup\n", ethErr );
-        return -1;
+        pc.attach( &ISR_Serial );
+        if( isFast ) //Configurar Serial a alta velocidad
+            pc.baud( 115200 );
     }
     
-    printf("Configuracion Correcta\n");
+    setTimer2();  // Configurar PTO
+    pin_son = 0;  // Servo Apagado por defecto
+    aout = 0.5;   // Voltaje de salida 0V por defecto( +-10V! )
     
-    FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
-    FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
-  
-    svr.addHandler<SimpleHandler>("/hello");
-    svr.addHandler<RPCHandler>("/rpc");
-    svr.addHandler<FSHandler>("/files");
-    svr.addHandler<FSHandler>("/"); //Default handler
-    //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
-   
-    svr.bind(80);
-    setTimer2();
-    
-    printf("Listening...\n");
-    
-    while(1) {
-        
-        Net::poll();
-    
-     }
+    while(1) 
+    {
+        if( isHTTP )
+            Net::poll();  // Revisa la red solo si la conección es HTTP
+    }
 }
 
-