Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf HTTPServer QEI_hw RPCInterface mbed
Diff: setup.cpp
- Revision:
- 18:cf1e07d82630
- Parent:
- 17:a4f380bc2516
- Child:
- 19:c26cf8a48986
--- a/setup.cpp Wed May 02 01:15:36 2012 +0000
+++ b/setup.cpp Wed May 09 20:51:10 2012 +0000
@@ -11,6 +11,7 @@
#include "setup.h"
+#include "EthernetNetIf.h"
#include "mbed.h"
// Salida Serial de mbed
@@ -24,6 +25,106 @@
// la velocidad de posicionamiento en Hz
+EthernetNetIf configurarEthernet()
+{
+ //____________ *** ARCHIVO DE CONFIGURACION ***_______________________ //
+
+ printf("\n *** CONFIGURACION ETHERNET DE MBED ***\n");
+ printf("Leyendo archivo de configuracion...\n\n");
+
+ FILE *fp = fopen("/local/config.txt", "r"); // Abre el archivo y lo guarda en fp
+
+ if(!fp) // En caso de no encontrarse el archivo
+ {
+ printf("\nEl archivo /mbed/config.txt no puede ser abierto!\n");
+ exit(1);
+
+ }
+ else
+ {
+ // Cadenas de caracteres desde el Archivo config.txt
+ char isDHCP [15]; //Modo Automatico o Manual
+ char empty [2]; // Linea vacia
+ char ip [40]; // Direccion IP
+ char mask [40]; // Mascara de Subred
+ char gate [40]; // Puerta de enlace
+ char dns [40]; // Direccion DNS
+
+ // Valores 'int' para agregar a la configuracion manual
+ int DHCP;
+ int n_ip[4];
+ int n_mask[4];
+ int n_gate[4];
+ int n_dns[4];
+
+
+ // Leer linea a linea el archivo
+ fgets( isDHCP, 15, fp );
+ fgets( empty, 2, fp );
+ fgets( ip, 40, fp );
+ fgets( mask, 40, fp );
+ fgets( gate, 40, fp );
+ fgets( dns, 40, fp );
+
+ printf("Cerrando archivo...\n");
+ fclose(fp);
+
+ // Extraer los valores numericos
+ sscanf( isDHCP,"%*s %d",&DHCP );
+
+ sscanf( ip,"%*s %d.%d.%d.%d",&n_ip[0],&n_ip[1],&n_ip[2],&n_ip[3] );
+ sscanf( mask,"%*s %d.%d.%d.%d",&n_mask[0],&n_mask[1],&n_mask[2],&n_mask[3] );
+ sscanf( gate,"%*s %d.%d.%d.%d",&n_gate[0],&n_gate[1],&n_gate[2],&n_gate[3] );
+ sscanf( dns,"%*s %d.%d.%d.%d",&n_dns[0],&n_dns[1],&n_dns[2],&n_dns[3] );
+
+
+ if(DHCP) //En caso de modo DHCP
+ {
+ printf("\n Configurar red de manera automatica\n");
+ EthernetNetIf eth; //Crea la interfaz
+ EthernetErr ethErr = eth.setup();
+ if( ethErr )
+ {
+ printf( "Error %d en la configuracion\n", ethErr );
+ exit(1);
+ }
+
+ printf("Configuracion Correcta\n\n");
+ return eth;
+ }
+ else
+ {
+ sscanf( ip,"%*s %d.%d.%d.%d",&n_ip[0], &n_ip[1], &n_ip[2], &n_ip[3] );
+ sscanf( mask,"%*s %d.%d.%d.%d",&n_mask[0],&n_mask[1],&n_mask[2],&n_mask[3] );
+ sscanf( gate,"%*s %d.%d.%d.%d",&n_gate[0],&n_gate[1],&n_gate[2],&n_gate[3] );
+ sscanf( dns,"%*s %d.%d.%d.%d",&n_dns[0], &n_dns[1], &n_dns[2], &n_dns[3] );
+ printf(" %s %s %s %s %s\n " , isDHCP, ip, mask, gate, dns );
+
+ printf("\n Configurar red de manera manual\n");
+ EthernetNetIf eth(
+ IpAddr( n_ip[0], n_ip[1], n_ip[2], n_ip[3]), //IP Address
+ IpAddr( n_mask[0],n_mask[1],n_mask[2],n_mask[3]), //Network Mask
+ IpAddr( n_gate[0],n_gate[1],n_gate[2],n_gate[3]), //Gateway
+ IpAddr( n_dns[0], n_dns[1], n_dns[2], n_dns[3] ) //DNS
+ );
+
+ EthernetErr ethErr = eth.setup();
+ if( ethErr )
+ {
+ printf( "Error %d en la configuracion\n", ethErr );
+ exit(1);
+ }
+
+ printf("Configuracion Correcta\n\n");
+ return eth;
+ }
+
+ }
+ EthernetNetIf eth;
+ return eth;
+}
+
+
void setTimer2()
{
// Encender Timer2 (PCONP[22])
@@ -91,9 +192,20 @@
else if( command == 'S')
pin_son = value;
- //else if( command == 'E')
- // setDir( value );
+ else if( command == 'V')
+ fq_posicion = value;
+
+ else if( command == 'G' )
+ {
+ int pulsos = value; //Numero de pulsos a generar
+ float t_alto = pulsos / fq_posicion; //Tiempo que debe ser generado el tren de pulsos.
+ stopTimer2(); //Deten el tren de pulsos
+ setPTO( fq_posicion ); //Nueva frecuencia de salida
+ startTimer2(); //Inicia el tren de pulsos
+ wait( t_alto ); //Espera hasta llegar a la posicion
+ stopTimer2(); //Posicion alcanzada ALTO.
+ }
}
@@ -143,7 +255,7 @@
setPTO( fq_posicion ); //Nueva frecuencia de salida
startTimer2(); //Inicia el tren de pulsos
wait( t_alto ); //Espera hasta llegar a la posicion
- stopTimer2(); //Posición alcanzada ALTO.
+ stopTimer2(); //Posicion alcanzada ALTO.
if( pin_alm == 0 )
sprintf( output,"Ok" );