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:
8:958dfe5052b9
Parent:
7:d9aca501126f
Child:
9:6976ac1a430e
--- a/main.cpp	Mon Apr 02 19:47:49 2012 +0000
+++ b/main.cpp	Tue Apr 03 00:31:03 2012 +0000
@@ -2,25 +2,102 @@
  
 #include "mbed.h"
 #include "setup.h"
+#include "EthernetNetIf.h"
+#include "HTTPServer.h"
+#include "RPCFunction.h"
+#include "RPCVariable.h"
+#include "SerialRPCInterface.h"
 
-Serial     pc( USBTX, USBRX );
+LocalFileSystem fs("webfs");
 
-DigitalOut      pin_son( p30 );   // SON
-DigitalOut      pin_dir( p29 );   // SIGN+
-InterruptIn     pin_alm( p14 );   // ALM 
-AnalogOut       aout( p18 );      // 0.0 a 1.0 float
+EthernetNetIf eth;  
+HTTPServer svr;
+
+void setFq( char * input, char * output );  //Cambiar frecuencia
+void setPTO( char * input, char * output );          // Encender/Apagar Pulse Train Output
+
+
+//Set up custom RPC
+RPCFunction SetFQ(&setPTO, "PTO");
+RPCFunction SetAout(&setAOUT, "AOUT");
+
 
 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>();
+    
+    printf("\nSetting Up...\n");
+    
+    EthernetErr ethErr = eth.setup();
+    if( ethErr )
+    {
+        printf( "Error %d in setup\n", ethErr );
+        return -1;
+    }
+    
+    printf("Configuracion Correcta\n");
+    
+    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();
-    pc.attach( &ISR_Serial );
-    pin_alm.rise( &ISR_Alarm );
     
-    pin_son = 0;     //Inicia apagado
-    aout =  0.5;  //Salida en la Mitad.
+    printf("Listening...\n");
     
     while(1) {
-   
+        
+        Net::poll();
     
      }
-}
\ No newline at end of file
+}
+
+
+void setAOUT( char * input, char * output )
+{
+    int vout = atoi( input );
+    
+    aout = (float)( vout + 100 ) / 200;   
+    
+    sprintf(" Ok, Aout = %f ", aout.read() );
+    
+}
+
+void setPTO( char * input, char * output )
+{
+    int freq = atoi( input );
+    
+    if( freq != 0 )
+    {
+        LPC_TIM2->TC = 0x00;  // Resetear Timer
+        setMR2( getMRvalue( frequency ) ); //Cambiar frefuencia
+        startTimer2();
+        sprintf( output, "Ok, Freq = %d", frequency);
+    } else {
+    
+        LPC_TIM2->TC = 0x00;  // Resetear Timer
+        stopTimer2();
+        sprintf( output, "Ok, ALTO" );
+    }
+            
+}
+
+
+
+