Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
27:98f824719d1c
Parent:
25:2cf5e8dd4035
Child:
28:94aec56c6329
--- a/sip.cpp	Mon Sep 22 16:56:00 2014 +0000
+++ b/sip.cpp	Mon Sep 22 21:15:07 2014 +0000
@@ -17,7 +17,22 @@
     strncpy( this->server_ip, server_ip, 20 );
     this->server_ip[19] = 0;
     this->server_port = server_port;
-    strncpy( this->my_ip, my_ip, 20 );
+    
+    FILE *fp = fopen( "/qspi/myip.txt", "r");
+    if (fp == NULL){
+        pc.printf("Failed to open /qspi/myip.txt \n\r" );
+        strncpy( this->my_ip, __MY_IP__, 20 );    
+    }else{
+        if( fread( this->buffer, 1, 512, fp ) > 0 ){
+            strncpy( this->my_ip, this->buffer, 20 );
+            debug_msg("Objeto SIP fixado no ip %s", this->my_ip );
+        }else{
+            pc.printf("Failed to read /qspi/myip.txt \n\r" );
+            strncpy( this->my_ip, __MY_IP__, 20 );
+        }
+    }
+    fclose( fp );
+    
     this->my_ip[19] = 0;
     this->my_port = my_port;
     this->my_rtp_port = fill_random_rtp_port();
@@ -35,13 +50,61 @@
 }
  
 Sip::Sip(){
+    FILE *fp = NULL;/*
+    
+    mudar para mudar a ext aqui
+    fopen( "/qspi/myip.txt", "r");
+    if (fp == NULL){
+        pc.printf("Failed to open /qspi/myip.txt \n\r" );
+        strncpy( this->my_ip, __MY_IP__, 20 );    
+    }else{
+        if( fread( this->buffer, 1, 512, fp ) > 0 ){
+            strncpy( this->my_ip, this->buffer, 20 );
+            debug_msg("Objeto SIP fixado no ip %s", this->my_ip );
+        }else{
+            pc.printf("Failed to read /qspi/myip.txt \n\r" );
+            strncpy( this->my_ip, __MY_IP__, 20 );
+        }
+    }
+    fclose( fp );*/
+    
+    
     this->id = __MY_EXT__;
     strncpy( this->server_ip, __SEVER_IP__, 20 );
     this->server_ip[19] = 0;
     this->server_port = __SERVER_PORT__;
-    strncpy( this->my_ip, __MY_IP__, 20 );
+    
+    fp = fopen( "/qspi/myip.txt", "r");
+    if (fp == NULL){
+        pc.printf("Failed to open /qspi/myip.txt \n\r" );
+        strncpy( this->my_ip, __MY_IP__, 20 );    
+    }else{
+        if( fread( this->buffer, 1, 512, fp ) > 0 ){
+            strncpy( this->my_ip, this->buffer, 20 );
+            debug_msg("Objeto SIP fixado no ip %s", this->my_ip );
+        }else{
+            pc.printf("Failed to read /qspi/myip.txt \n\r" );
+            strncpy( this->my_ip, __MY_IP__, 20 );
+        }
+    }
+    fclose( fp );
     this->my_ip[19] = 0;
-    this->my_port = __MY_PORT__;
+    
+    
+    fp = fopen( "/qspi/mysipport.txt", "r");
+    if (fp == NULL){
+        pc.printf("Failed to open /qspi/mysipport.txt \n\r" );
+        this->my_port = __MY_PORT__;
+    }else{
+        if( fread( &my_port, 1, 32, fp ) > 0 ){
+            debug_msg("Objeto SIP fixado na porta sip %i", this->my_port );
+        }else{
+            pc.printf("Failed to read /qspi/mysipport.txt \n\r" );
+            this->my_port = __MY_PORT__;
+        }
+    }
+    fclose( fp );
+    
     this->my_rtp_port = fill_random_rtp_port();
     this->my_ext = __MY_EXT__;
     itoa( this->my_ext, this->my_display, 10 );
@@ -61,7 +124,22 @@
     strncpy( this->server_ip, __SEVER_IP__, 20 );
     this->server_ip[19] = 0;
     this->server_port = __SERVER_PORT__;
-    strncpy( this->my_ip, __MY_IP__, 20 );
+    
+    FILE *fp = fopen( "/qspi/myip.txt", "r");
+    if (fp == NULL){
+        pc.printf("Failed to open /qspi/myip.txt \n\r" );
+        strncpy( this->my_ip, __MY_IP__, 20 );    
+    }else{
+        if( fread( this->buffer, 1, 512, fp ) > 0 ){
+            strncpy( this->my_ip, this->buffer, 20 );
+            debug_msg("Objeto SIP fixado no ip %s", this->my_ip );
+        }else{
+            pc.printf("Failed to read /qspi/myip.txt \n\r" );
+            strncpy( this->my_ip, __MY_IP__, 20 );
+        }
+    }
+    fclose( fp );
+    
     this->my_ip[19] = 0;
     this->my_port = my_port;
     this->my_rtp_port = fill_random_rtp_port();
@@ -83,7 +161,7 @@
     strncpy( this->server_ip, __SEVER_IP__, 20 );
     this->server_ip[19] = 0;
     this->server_port = __SERVER_PORT__;
-    strncpy( this->my_ip, __MY_IP__, 20 );
+    strncpy( this->my_ip, "192.168.120.172", 20 );
     this->my_ip[19] = 0;
     this->my_port = my_port;
     this->my_rtp_port = fill_random_rtp_port();
@@ -110,7 +188,7 @@
     build_registry_package( buffer );
     int sent = sock.sendTo( sip_server, buffer, sizeof( buffer ) );
     sock.receiveFrom( sip_server, buffer, sizeof( buffer ) );
-    debug_msg(" Recebidos %d bytes para o o ext %d", sent, my_ext );
+    debug_msg(" Recebidos %d bytes para o ext %d", sent, my_ext );
     if( decode_gettag( (unsigned char *)buffer, "cseq: ", out ) ){
         if(strlen( out ) > 7){
             if(strcasecmp("options",out+strlen(out)-7) == 0){