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
Revision 17:a4f380bc2516, committed 2012-05-02
- Comitter:
- Yo_Robot
- Date:
- Wed May 02 01:15:36 2012 +0000
- Parent:
- 16:d50665706f21
- Child:
- 18:cf1e07d82630
- Commit message:
- Version 1.4 Archivo de Configuracin funciona bien, falta funciones del encoder
Changed in this revision
| 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/main.cpp Thu Apr 26 04:35:21 2012 +0000
+++ b/main.cpp Wed May 02 01:15:36 2012 +0000
@@ -10,17 +10,17 @@
Serial pc( USBTX, USBRX );
-DigitalOut pin_son( p26 ); // SON
-DigitalOut pin_dir( p25 ); // SIGN+
+DigitalOut pin_son( p7 ); // SON
+DigitalOut pin_dir( p26 ); // SIGN+
InterruptIn pin_alm( p8 ); // ALM
AnalogOut aout( p18 ); // 0.0 a 1.0 float
DigitalIn isHTTP( p15 ); // Modo Ethernet/Serial
DigitalIn isFast( p16 ); // Serial Alta velocidad/Baja Velocidad
-LocalFileSystem fs("webfs");
+LocalFileSystem fs("local");
-EthernetNetIf eth;
+//EthernetNetIf eth;
HTTPServer svr;
// Anadir funciones al Protocolo RPC
@@ -48,21 +48,103 @@
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 )
+
+
+ //____________ *** 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
{
- printf( "Error %d en setup\n", ethErr );
- return -1;
- }
+ // 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 );
+
+
+ // 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 );
+ return -1;
+ }
+
+ printf("Configuracion Correcta\n\n");
+ }
+ 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 );
+ 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
+ printf("Configuracion Correcta\n\n");
+ }
+ }
+
+ printf("Cerrando archivo...\n");
+ fclose(fp);
+
+ FSHandler::mount("/local", "/files"); //Mount /webfs path on /files web path
+ FSHandler::mount("/local", "/"); //Mount /webfs path on web root path
+
svr.addHandler<SimpleHandler>("/hello");
svr.addHandler<RPCHandler>("/rpc");
svr.addHandler<FSHandler>("/files");
@@ -71,8 +153,9 @@
svr.bind(80);
- printf("Listening...\n");
+ printf("Listo para comunicacion...\n");
}
+
else // Caso Contrario Anadir modo Serial
{
pc.attach( &ISR_Serial );
@@ -80,6 +163,7 @@
pc.baud( 115200 );
}
+ // Ajustes iniciales del Driver
setTimer2(); // Configurar PTO
pin_son = 0; // Servo Apagado por defecto
aout = 0.5; // Voltaje de salida 0V por defecto( +-10V! )
--- a/setup.cpp Thu Apr 26 04:35:21 2012 +0000
+++ b/setup.cpp Wed May 02 01:15:36 2012 +0000
@@ -143,7 +143,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(); //Posición alcanzada ALTO.
if( pin_alm == 0 )
sprintf( output,"Ok" );