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

Dependencies:   EthernetNetIf HTTPServer QEI_hw RPCInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
Yo_Robot
Date:
Wed Mar 28 23:13:53 2012 +0000
Parent:
4:552beeda4722
Child:
6:b4dae934e1ea
Commit message:
First RPC Version, seems to work ok....

Changed in this revision

RPC.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
setup.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/RPC.lib	Wed Mar 28 18:42:32 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/thumren/libraries/RPC/ltoaq1
\ No newline at end of file
--- a/main.cpp	Wed Mar 28 18:42:32 2012 +0000
+++ b/main.cpp	Wed Mar 28 23:13:53 2012 +0000
@@ -2,41 +2,106 @@
  
 #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 );
+DigitalOut led1(LED1, "led1");
+DigitalOut led2(LED2, "led2");
+DigitalOut led3(LED3, "led3");
+DigitalOut led4(LED4, "led4");
+
+LocalFileSystem fs("webfs");
+
+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(&setFq, "Frecuencia");
+RPCFunction SetPTO(&setPTO, "Encender");
+
 
 int main() {
     
-    // IMPRIMIR modo de operacion
-    pc.printf( "\n GENERADOR DE FRECUENCIAS\n" );
-    pc.printf( "\n Formato: F___H\\r " );
-    pc.printf( "\n Genera un tren de pulsos en Hz ej: F500H" );
-    pc.printf( "\n Generara un tren de impulsos de 500Hz, al final del comando se debe" );
-    pc.printf( "\n ingresar enter (CarriageReturn, \\r )\n" );
+    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>();
     
-    pc.printf( "\n Formato: F___K\\r " );
-    pc.printf( "\n Genera un tren de pulsos en kHz ej: F250K" );
-    pc.printf( "\n Generara un tren de impulsos de 250kHz, al final del comando se debe" );
-    pc.printf( "\n ingresar enter (CarriageReturn, \\r )\n" );
+    printf("\nSetting Up...\n");
     
-    pc.printf( "\n Formato: I___I\\r " );
-    pc.printf( "\n INICIO del tren de pulsos ej: I22I" );
-    pc.printf( "\n El numero entre las I no interesa, al final del comando se debe" );
-    pc.printf( "\n ingresar un enter (CarriageReturn, \\r )\n" );
+    EthernetErr ethErr = eth.setup();
+    if( ethErr )
+    {
+        printf( "Error %d in setup\n", ethErr );
+        return -1;
+    }
+    
+    printf("Configuracion Correcta\n");
     
-    pc.printf( "\n Formato: P___P\\r " );
-    pc.printf( "\n PARO del tren de pulsos ej: P22P" );
-    pc.printf( "\n El numero entre las I no interesa, al final del comando se debe" );
-    pc.printf( "\n ingresar un enter (CarriageReturn, \\r )\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.printf( "\n Los numeros ingresados deben ser solamente enteros \n\n" );
-    
-    setTimer2();
-    pc.attach( &ISR_Serial );
-
+    printf("Listening...\n");
     
     while(1) {
-   
+        
+        Net::poll();
     
      }
-}
\ No newline at end of file
+}
+
+
+void setFq( char * input, char * output )
+{
+    int frequency = atoi( input );
+    setMR2( getMRvalue( frequency ) );
+    
+    sprintf( output, "Ok, Freq = %d", frequency);
+}
+
+void setPTO( char * input, char * output )
+{
+    int command = atoi( input );
+    
+    if( command == 1)
+    {
+        startTimer2();
+        sprintf( output, "On" );
+    }
+    else if( command == 0)
+    {
+        stopTimer2();
+        sprintf( output, "Off" );
+    }
+    
+    sprintf( output, "Error, intentelo nuevamente: %c", command );
+    
+        
+}
+
+
+
+
--- a/setup.cpp	Wed Mar 28 18:42:32 2012 +0000
+++ b/setup.cpp	Wed Mar 28 23:13:53 2012 +0000
@@ -44,43 +44,11 @@
                                 //      y MAT2.3
 
     LPC_PINCON->PINSEL0 |= 15UL << 16;  //Activar  MAT2.2 
-                                       // y MAT2.3 como salidas
-    
+                                      // y MAT2.3 como salidas
+   
 }
 
 
-/** @brief: Esta es la rutina que maneja las interrupciones
- *  seriales, al recibir un caracter.
- */
-void ISR_Serial()
-{
-    int freq;        //Frecuencia del PTO
-    char command;    //Comando a ejecutar
-    char scale;      //Escala de la frecuencia
-
-    pc.scanf( "%c%d%c", &command, &freq, &scale ) ;
-    LPC_UART0->FCR = 0x06;
-    pc.printf("\n %c%d%c \n", command, freq, scale );
-
-    // Establecer nueva frecuencia
-    if( command == 'F')
-    {
-       if( scale == 'H' )
-            setMR2( getMRvalue( freq ) );
-       else if( scale == 'K' )
-            setMR2( getMRvalue( freq * 1000 ) );
-    }
-    
-    // INICIAR Timer
-    else if( command == 'I')
-        startTimer2( );
-        
-    // PARAR Timer    
-    else if( command == 'P')
-        stopTimer2( );
-    
-}
-
 int getMRvalue( int fout  )
 {
     float exact, error;
@@ -90,7 +58,7 @@
     toRegister = exact;  // Valor redondeado;
     error = exact - toRegister;
        
-    pc.printf( "\n\n MR value: %d\n error: %f\n" ,toRegister ,error );
+    printf( "\n\n MR value: %d\n error: %f\n" ,toRegister ,error );
     
     return toRegister;
 }
@@ -118,8 +86,8 @@
 
 /*  LEGACY FUNCTIONS
  *
- *  El código actual no hace referencia a estas funciones
- *  sin embargo no hay daño en definirlas.
+ *  El codigo actual no hace referencia a estas funciones
+ *  sin embargo no hay problema en definirlas.
  */ 
 void setMR3( int newValue )
 {
@@ -131,3 +99,5 @@
 {
     LPC_TIM2->PR = newValue; 
 }
+
+