VZTECH / Mbed 2 deprecated main_src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Files at this revision

API Documentation at this revision

Comitter:
klauss
Date:
Tue Sep 23 18:28:37 2014 +0000
Parent:
27:98f824719d1c
Child:
29:7246460b73f8
Commit message:
- peet ext and my ext setable from prompt

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
prompt.cpp Show annotated file Show diff for this revision Revisions of this file
prompt.h Show annotated file Show diff for this revision Revisions of this file
sip.cpp Show annotated file Show diff for this revision Revisions of this file
sip.h Show annotated file Show diff for this revision Revisions of this file
utils.cpp Show annotated file Show diff for this revision Revisions of this file
vz_protocol.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Sep 22 21:15:07 2014 +0000
+++ b/main.cpp	Tue Sep 23 18:28:37 2014 +0000
@@ -24,8 +24,6 @@
 */
 volatile uint8_t status = 0x00;
 
-bool debug_bool = true;
-
 int main(){
     start_cpld();
     config_lpc();
@@ -173,11 +171,13 @@
                 led3 = !led3;
                 CAB_LED = !CAB_LED;
                 
-                if( count  == 8 ){
-                    Call_Box * cb = new Call_Box( ext, port );
-                    cb->registry();
+                if( test_debug ){
+                    if( count  == 8 ){
+                        Call_Box * cb = new Call_Box( ext, port );
+                        cb->registry();
+                    }
+                    count++;
                 }
-                count++;
             }
 //----------------------
         switch( type ){
@@ -325,7 +325,10 @@
                     ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                 }break;
             case __TELEMETRY__ : {
-                    debug_msg("Leitura da bateria :: ( Id : %x, MSB : %x, LSB : %x )", data[ 0 ], data[ 1 ], data[ 2 ] );
+                    pc.printf("Telemetry pkg from %i\n\r", ext );
+                    for( register int i = 0; i < __TELEMETRY_SIZE__; i++ )
+                        pc.printf("%x ", data[ i ]);
+                    pc.printf("\n\r");
                 }break;
             case __AUDIO__ : {
                 Call_Box * cb;
@@ -333,16 +336,12 @@
                 cb = NULL;
                 call = __find_Call__( v_call, ext );
                 if( call != NULL ){
-                    //debug_( 240, data );
-                    //debug_pkg( 242, data );
-                    //char * pkg = call->build_eth_package( oitocentos );
-                    //char * pkg = call->build_eth_package( data );
-                    char * pkg = call->build_eth_package( data + 2 );
+                    char * pkg = call->build_eth_package( data );
                     call->send_message( pkg );
                     cb = __find_CB__( v_cb, ext );
                     if( cb != NULL ) cb->reset_elapsed_time();
                 }else{
-                    debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type );
+                    debug_msg("received missed package  from CBx :: %i -- Type :: %i", ext, type );
                 }
             }break;
         }// fim switch
@@ -357,7 +356,7 @@
                 
                 if( cb != NULL ){
                     cb_port = cb->get_port();
-                }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type );
+                }else debug_msg("received missed package  from CBx :: %i -- Type :: %i", ext, type );
                                 
                 uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, 
                     tmp, __AUDIO__, length, write_buffer );
@@ -366,7 +365,7 @@
             }
         }
         ///debug_msg("");
-        registry_aging( v_cb, buffer, write_buffer );
+        if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer );
         
         int ret = sip_manager( v_cb, v_call, write_buffer );
         if( ret > 0x00 ){
--- a/prompt.cpp	Mon Sep 22 21:15:07 2014 +0000
+++ b/prompt.cpp	Tue Sep 23 18:28:37 2014 +0000
@@ -4,23 +4,25 @@
 #include "vz_protocol.h"
 #include "parallelcpld.h"
 #include "flood.h"
+#include "debug.h"
 
 //#include "debug.h"
 
-uint8_t debug_alive = 1;
+uint8_t debug_alive = 0;
+uint8_t debug_sip = 0;
 uint8_t pcks_s = 0;
 uint8_t pshowcb = 0;
-uint8_t debug_sip = 0;
+
+uint8_t test_debug = 0;
 #define PVERSION 1          // Sempre atualizar a versao do prompt
 
 #define DEBUGBUFSIZE 50
 char debug_buf[DEBUGBUFSIZE];
-FILE *fip,*fmask,*fgate,*fport,*fsip,*fsport; 
+FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext;
 uint8_t dog = 1;
 uint8_t debug_prompt = 0;
 uint8_t bufptr = 0;
  
-
 uint8_t xmemmatch(const uint8_t * s1, const uint8_t * s2, uint16_t size) {      // presente da lib.h pode retirar da versao final
   while (size--) {
     if (*s1++ != *s2++) return 0; /* does not match */
@@ -63,7 +65,7 @@
     
     FILE *fp = fopen(fname, "r");
     if (fp == NULL) {
-        pc.printf("Failed to open %s\n", fname);
+        pc.printf("Failed to open %s", fname);
         return;
     }
     
@@ -76,65 +78,86 @@
     fclose(fp);
 }
 
-
-void files (const char type) {                                          // operantion with the system config files
-       
+// operantion with the system config files
+void files (const char type) {                                                 
     if (type == 's' ){                // show files
         pc.printf("\n\r");
-        pc.printf("1)IP, 2)MASK, 3)GATEWAY, 4)SIP PORT, 5)SERVER IP, 6)SERVER SIP PORT\n\r");
+        pc.printf("Header IP " );
         cat("/qspi/myip.txt");
+        pc.printf("\n\rHeader ext ");
+        cat("/qspi/myext.txt");
+        pc.printf("\n\rHeader port ");
+        cat("/qspi/mysipport.txt");
+        
+        pc.printf("\n\rServer ip ");
+        cat("/qspi/serverip.txt");
+        pc.printf("\n\rServer ext ");
+        cat("/qspi/peerext.txt");
+        pc.printf("\n\rServer port ");
+        cat("/qspi/serverport.txt");
+        
+        pc.printf("\n\rMascara de rede ");
         cat("/qspi/mymask.txt");
+        pc.printf("\n\rGateway IP ");
         cat("/qspi/mygate.txt");
-        cat("/qspi/mysipport.txt");
-        cat("/qspi/serverip.txt");
-        cat("/qspi/serverport.txt");
     }
     
-    
     if (type == 'c' ){                // close all files
-        fclose(fip);
-        fclose(fmask);
-        fclose(fgate);
-        fclose(fport);
-        fclose(fsip);
-        fclose(fsport);
-        
+        fclose( fip );
+        fclose( fmask );
+        fclose( fgate );
+        fclose( fport );
+        fclose( fsip );
+        fclose( fsport );
+        fclose( fext );
+        fclose( fserext );
     }    
     
     if (type == 'i' ){                // Check if files exist, if not create the files
         fip = fopen("/qspi/myip.txt", "r");
         if (fip == NULL){
             fip = fopen("/qspi/myip.txt", "w");
-            //fprintf(fip, "192.168.120.169\n\r");   //myip
             fprintf(fip, "%s\n\r",__MY_IP__);   //myip
         }
+        
+        fserext = fopen("/qspi/myext.txt", "r");
+        if ( fserext == NULL ){
+             fserext = fopen("/qspi/myext.txt", "w");
+             fprintf( fserext, "%i\n\r" ,__MY_EXT__ );  //asterisk ext
+        }
+        fport = fopen("/qspi/mysipport.txt", "r");
+        if (fport == NULL){
+            fport = fopen("/qspi/mysipport.txt", "w");
+            fprintf(fport, "%i\n\r",__MY_PORT__);  //mysipport
+        }
+        fsip = fopen("/qspi/serverip.txt", "r");
+        if (fsip == NULL){
+             fsip = fopen("/qspi/serverip.txt", "w");
+             fprintf(fsip, "%s\n\r",__SERVER_IP__ );  //asterisk ip
+        }
+        
+        fext = fopen("/qspi/peerext.txt", "r");
+        if ( fext == NULL ){
+             fext = fopen("/qspi/peerext.txt", "w");
+             fprintf( fext, "%d\n\r",__PEER_EXT__ );  //asterisk ip
+        }
+        fsport = fopen("/qspi/serverport.txt", "r");
+        if (fsport == NULL){
+            fsport = fopen("/qspi/serverport.txt", "w");
+            fprintf(fsport, "%i\n\r",__SERVER_PORT__ );  //asterisk port
+        pc.printf("\n\r Default configurations set! \n\r");
+        }
+        
         fmask = fopen("/qspi/mymask.txt", "r");
         if (fmask == NULL){
             fmask = fopen("/qspi/mymask.txt", "w");
-            fprintf(fmask, "255.255.255.0\n\r");     //mymask
+            fprintf(fmask, "%s\n\r",__MY_MSK__);     //mymask
         }
         fgate = fopen("/qspi/mygateway.txt", "r");
         if (fgate == NULL){
             fgate = fopen("/qspi/mygate.txt", "w");
-            fprintf(fgate, "192.168.2.254\n\r");    //mygateway
-        }
-        fport = fopen("/qspi/mysipport.txt", "r");
-        if (fport == NULL){
-            fport = fopen("/qspi/mysipport.txt", "w");
-            fprintf(fport, "5075\n\r");  //mysipport
+            fprintf(fgate, "%s\n\r",__MY_GTW__);    //mygateway
         }
-        fsip = fopen("/qspi/serverip.txt", "r");
-        if (fsip == NULL){
-             fsip = fopen("/qspi/serverip.txt", "w");
-             fprintf(fsip, "192.168.30.25\n\r");  //asterisk ip
-        }
-        fsport = fopen("/qspi/serverport.txt", "r");
-        if (fsport == NULL){
-            fsport = fopen("/qspi/serverport.txt", "w");
-            fprintf(fsport, "5060\n\r");  //asterisk port
-        pc.printf("\n\r Default configurations set! \n\r");
-        }
-        
     }
     
     if (type == 'r' ){                // Just open for read
@@ -144,6 +167,8 @@
         fport = fopen("/qspi/mysipport.txt", "r");
         fsip = fopen("/qspi/serverip.txt", "r");
         fsport = fopen("/qspi/serverport.txt", "r");
+        fext = fopen( "/qspi/myext.txt", "r" );
+        fserext = fopen( "/qspi/peerext.txt", "r" );
     }
         
     if (type == 'w'){                 // Create and write the default configs
@@ -153,13 +178,20 @@
         fport = fopen("/qspi/mysipport.txt", "w");
         fsip = fopen("/qspi/serverip.txt", "w");
         fsport = fopen("/qspi/serverport.txt", "w");   
+        fext = fopen( "/qspi/myext.txt", "w" );
+        fserext = fopen( "/qspi/peerext.txt", "w" );
         
-        fprintf(fip, "%s\n\r", __MY_IP__ );   //myip
-        fprintf(fmask, "255.255.255.0\n\r");     //mymask
-        fprintf(fgate, "192.168.2.254\n\r");    //mygateway
-        fprintf(fport, "5075\n\r");  //mysipport
-        fprintf(fsip, "192.168.30.25\n\r");  //asterisk ip
-        fprintf(fsport, "5060\n\r");  //asterisk port
+        fprintf( fip, "%s\n\r", __MY_IP__  );   //myip
+        fprintf( fport, "%d\n\r", __MY_PORT__ );  //mysipport
+        //fprintf( fext, "%d\n\r", __MY_EXT__ );  //myext
+        fprintf( fext, "%d\n\r", 820 );  //myext
+        
+        fprintf( fsip, "%s\n\r", __SERVER_IP__  );  //asterisk ip
+        fprintf( fserext, "%d\n\r",__PEER_EXT__ );  //asterisk port
+        fprintf( fsport, "%d\n\r",__SERVER_PORT__ );  //asterisk port
+        
+        fprintf( fmask, "%s\n\r",__MY_MSK__ );     //mymask
+        fprintf( fgate, "%s\n\r", __MY_GTW__ );    //mygateway
         
         files('c');
         
@@ -180,8 +212,10 @@
     pc.printf("*******System Ready*******\n\r");
 }
 
-
-void prompt_process(){              // main prompt process
+// main prompt process
+void prompt_process(){
+    //FIXME dar flush na serial
+    
     volatile char b = 0;
     static uint8_t bufret = 0;
     
@@ -199,26 +233,54 @@
             }
         }
         
-    if (bufret == 1) {                  // Prompt commands here
+    // Prompt commands here
+    if (bufret == 1) {     
+        bool miss_match = true;
+        
+        if( !bufptr ){
+            miss_match = false;
+        }     
         if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "sconfig" )) {
+            miss_match = false;
             pc.printf("\n\r");
             files('s');
         }
         if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" )) {
+            miss_match = false;
             pc.printf("\n Formatando o sistema de arquivos... espere o sistema reiniciar \n\r");
             //qspifs.format();
             NVIC_SystemReset();
         }
 
-        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ",6 )) {
+        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ", 6 )) {
+            miss_match = false;
             fip = fopen("/qspi/myip.txt", "w");
             fprintf(fip,"%s\n\r",(debug_buf+6));
             fclose(fip);
             pc.printf("\n\r");
             files('s');
         }
+        
+        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "extset ", 7 )) {
+            miss_match = false;
+            fip = fopen("/qspi/myext.txt", "w");
+            fprintf(fip, "%s\n\r" , ( debug_buf + 7) );
+            fclose(fip);
+            pc.printf("\n\r");
+            files('s');
+        }
+        
+        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serextset ", 10 )) {
+            miss_match = false;
+            fip = fopen("/qspi/peerext.txt", "w");
+            fprintf(fip, "%s\n\r" , ( debug_buf + 10 ) );
+            fclose(fip);
+            pc.printf("\n\r");
+            files('s');
+        }
 
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 )) {
+            miss_match = false;
             fmask = fopen("/qspi/mymask.txt", "w");
             fprintf(fmask,"%s\n\r",(debug_buf+8));
             fclose(fmask);
@@ -227,6 +289,7 @@
         }
 
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 )) {
+            miss_match = false;
             fgate = fopen("/qspi/mygate.txt", "w");
             fprintf(fgate,"%s\n\r",(debug_buf+11));
             fclose(fgate);
@@ -236,6 +299,7 @@
 
 
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 )) {
+            miss_match = false;
             fport = fopen("/qspi/mysipport.txt", "w");
             fprintf(fport,"%s\n\r",(debug_buf+9));
             fclose(fport);
@@ -244,6 +308,7 @@
         }
 
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 )) {
+            miss_match = false;
             fsip = fopen("/qspi/serverip.txt", "w");
             fprintf(fsip,"%s\n\r",(debug_buf+9));
             fclose(fsip);
@@ -252,6 +317,7 @@
         }
 
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 )) {
+            miss_match = false;
             fsport = fopen("/qspi/serverport.txt", "w");
             fprintf(fsport,"%s\n\r",(debug_buf+7));
             fclose(fsport);
@@ -261,24 +327,28 @@
 
 
         if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" )) {
+            miss_match = false;
             files('w');
             files('s');
-
         }
 
         if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" )) {
-            pc.printf("\n\r reset!!! \n\r");
+            miss_match = false;
+            //pc.printf("\n\r reset!!! \n\r");
+            pc.printf("\n\rJob is done\n\r");
             pc.putc(0x01);
             NVIC_SystemReset();
         }
 
         if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" )) {
+            miss_match = false;
             pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r");
             dog = 0;
         }
 
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ",6 )) {
             if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) {
+                miss_match = false;
                 pc.printf("\n\r\t Flood ON\n\r\t");
                 tflood.start();
                 tflood.reset();
@@ -286,6 +356,7 @@
                 pflood = 1;
             }
             if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) {
+                miss_match = false;
                 pc.printf("\n\r\t Flood OFF\n\r\t");
                 pflood = 0;
                 tflood.stop();
@@ -294,16 +365,32 @@
 
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 )) {
             if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) {
+                miss_match = false;
                 pc.printf("\n\r\tDebug ON\n\r\t");
                 debug_alive = 1;
             }
             if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) {
+                miss_match = false;
                 pc.printf("\n\r\tDebug OFF\n\r\t");
                 debug_alive = 0;
             }
         }
-
+        
+        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_sip ", 10 )) {
+            if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on",2 )) {
+                miss_match = false;
+                debug_msg( "Sip Debug ON" );
+                debug_sip = 1;
+            }
+            if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) {
+                miss_match = false;
+                debug_msg( "Sip Debug OFF" );
+                debug_sip = 0;
+            }
+        }
+        
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9)) {         //promptcb ramal porta comando
+            miss_match = false;
             static int id_msg = 0x10;
             uint8_t write_buffer[300];
             unsigned int ext,port;
@@ -315,32 +402,37 @@
             ant1 = str2uint( (debug_buf+9), &ext);
             ant2 = str2uint( ((debug_buf+9)+ant1+1), &port);
 
-            pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",ext, port, debug_buf+9+ant1+2+ant2);
+            pc.printf("ext=%d port=%d\r\ncmd=%s",ext, port, debug_buf+9+ant1+2+ant2);
 
             __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, debug_buf+9+ant1+2+ant2, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
-            pc.printf("\n\rComando enviado\n\r");
+            pc.printf("Comando enviado");
         }
 
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) {
+            miss_match = false;
             pcks_s = 1;
         }
 
         if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) {
+            miss_match = false;
             pshowcb = 1;
         }
         
         if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debugsip ", 9 )) {
             if (xmemmatch( (uint8_t*)( debug_buf + 9 ), (uint8_t*) "on",2 )) {
-                pc.printf("\n\r\tDebug Sip ON\n\r\t");
+                miss_match = false;
+                pc.printf("\tDebug Sip ON");
                 debug_sip = 1;
             }
             if (xmemmatch( (uint8_t*)( debug_buf + 9 ), (uint8_t*) "off",3 )) {
-                pc.printf("\n\r\tDebug Sip OFF\n\r\t");
+                miss_match = false;
+                pc.printf("Debug Sip OFF");
                 debug_sip = 0;
             }
         }
     
         if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) {
+            miss_match = false;
             pc.printf("\n\r****************************PROMPT HELP******************\n\r");
             pc.printf("sconfig                         - mostra o arquivo de configuracao do sistema\n\r");
             pc.printf("dconfig                         - volta as configuracoes do sistema para o padrao de fabrica\n\r");
@@ -349,16 +441,18 @@
             pc.printf("format                          - formata o sistema de arquivos\n\r");
             pc.printf("reset                           - resta o sistema\n\r");
             pc.printf("ipset [ip]                      - Configura o IP da cabeceira\n\r");
+            pc.printf("extset [ext]                    - Configura a ext da cabeceira\n\r");
+            pc.printf("msipport [port]                 - Configura a porta SIP da cabeceira\n\r");
+            pc.printf("serverip [ip]                   - Configura o ip do servidor asterisk\n\r");
+            pc.printf("serextset [ext]                 - Configura a server ext da cabeceira\n\r");
+            pc.printf("ssport [port]                   - Configura a porta SIP do servidor asterisk\n\r");
             pc.printf("maskset [mask]                  - Configura a mascara da cabeceira\n\r");
             pc.printf("gatewayset [gateway]            - Configura o gateway da cabeceira\n\r");
-            pc.printf("msipport [port]                 - Configura a porta SIP da cabeceira\n\r");
-            pc.printf("serverip [ip]                   - Configura o ip do servidor asterisk\n\r");
-            pc.printf("ssport [port]                   - Configura a porta SIP do servidor asterisk\n\r");
             pc.printf("showcb                          - lista os Cbx registrados na header\n\r");
             pc.printf("cks                             - exibe estatisticas de check sum\n\r");
             pc.printf("debug [on|off]                  - enable debugs\n\r");
             pc.printf("flood [on|off]                  - simula envio de pacotes de audio\n\r");
-            pc.printf("\n\rPROMPT VERSION: V%d\n\r",PVERSION);
+            pc.printf("PROMPT VERSION: V%d\n\r",PVERSION);
         }
         /*
         if ( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )) {
@@ -403,9 +497,11 @@
 
         }
         */
+        if( miss_match ) pc.printf("--> %s: command not found\n\r", debug_buf );
+        pc.printf("> ");
     }
-
-    if (b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ) {
+    
+    if ( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ) {
         bufptr = 0;
         for (uint8_t i =0; i < DEBUGBUFSIZE; i++) {
             debug_buf[i] = 0;
@@ -414,4 +510,4 @@
         pc.putc(0x0A);
         pc.putc(0x0D);
     }
-}
\ No newline at end of file
+}   
\ No newline at end of file
--- a/prompt.h	Mon Sep 22 21:15:07 2014 +0000
+++ b/prompt.h	Tue Sep 23 18:28:37 2014 +0000
@@ -4,10 +4,24 @@
 extern uint8_t debug_sip;
 extern uint8_t debug_alive;
 extern uint8_t debug_prompt;
+extern uint8_t test_debug;
+    
 extern uint8_t pcks_s;
 extern uint8_t pshowcb;
 extern uint8_t dog;
 
+
+extern FILE *fmask;         // mascara de rede
+extern FILE *fgate;         // gateway ip
+
+extern FILE *fip;           // header ip
+extern FILE *fext;          // header ext
+extern FILE *fport;         // header sip port
+
+extern FILE *fsip;          // server sip ip
+extern FILE *fserext;       // server sip ext
+extern FILE *fsport;        // server sip port
+
 void prompt_process();
 void init_fsystem();
 
--- a/sip.cpp	Mon Sep 22 21:15:07 2014 +0000
+++ b/sip.cpp	Tue Sep 23 18:28:37 2014 +0000
@@ -1,5 +1,6 @@
 #include "sip.h"
 #include "utils.h"
+#include "prompt.h"
 
 void Sip::__init_sock__( void ){
     sip_server.set_address( this->server_ip , this->server_port );
@@ -17,22 +18,7 @@
     strncpy( this->server_ip, server_ip, 20 );
     this->server_ip[19] = 0;
     this->server_port = server_port;
-    
-    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 );
-    
+    strncpy( this->my_ip, my_ip, 20 );
     this->my_ip[19] = 0;
     this->my_port = my_port;
     this->my_rtp_port = fill_random_rtp_port();
@@ -50,66 +36,116 @@
 }
  
 Sip::Sip(){
-    FILE *fp = NULL;/*
+    FILE *fp = NULL;
+    
+    fp = fopen( "/qspi/myext.txt", "r");
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/myext.txt" );
+        this->id = __MY_EXT__;
+    }else{
+        if( fread( &id, 1, 512, fp ) > 0 ){
+            this->id = __MY_EXT__;
+            debug_msg("Objeto SIP fixado na ext %i", this->id );
+        }else{
+            debug_msg("Failed to read /qspi/myext.txt" );
+            this->id = __MY_EXT__;
+        }
+    }
+    fclose( fp );
     
-    mudar para mudar a ext aqui
-    fopen( "/qspi/myip.txt", "r");
-    if (fp == NULL){
-        pc.printf("Failed to open /qspi/myip.txt \n\r" );
+    fp = fopen( "/qspi/serverip.txt", "r");
+    if( fp == NULL){
+        debug_msg("Failed to open /qspi/serverip.txt" );
+        strncpy( this->server_ip, __SERVER_IP__, 20 );    
+    }else{
+        if( fread( this->buffer, 1, 512, fp ) > 0 ){
+            strncpy( this->server_ip, this->buffer, 20 );
+            debug_msg("Objeto SIP fixado com ip %s", this->server_ip );
+        }else{
+            debug_msg("Failed to read /qspi/serverip.txt" );
+            strncpy( this->server_ip, __SERVER_IP__, 20 );
+        }
+    }
+    fclose( fp );
+    this->server_ip[19] = 0;
+    
+    fp = fopen( "/qspi/serverport.txt", "r");
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/serverport.txt" );
+        this->server_port = __SERVER_PORT__;
+    }else{
+        if( fread( &server_port, 1, 512, fp ) > 0 ){
+            this->server_port = __SERVER_PORT__;
+            debug_msg("Objeto SIP fixado na server port %i", this->server_port );
+        }else{
+            debug_msg("Failed to read /qspi/serverport.txt" );
+            this->server_port = __SERVER_PORT__;
+        }
+    }
+    fclose( fp );
+    
+    fp = fopen( "/qspi/myip.txt", "r");
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/myip.txt" );
         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__;
-    
-    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" );
+            debug_msg("Failed to read /qspi/myip.txt" );
             strncpy( this->my_ip, __MY_IP__, 20 );
         }
     }
     fclose( fp );
     this->my_ip[19] = 0;
     
-    
     fp = fopen( "/qspi/mysipport.txt", "r");
-    if (fp == NULL){
-        pc.printf("Failed to open /qspi/mysipport.txt \n\r" );
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/mysipport.txt" );
         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" );
+            debug_msg("Failed to read /qspi/mysipport.txt" );
             this->my_port = __MY_PORT__;
         }
     }
     fclose( fp );
     
     this->my_rtp_port = fill_random_rtp_port();
-    this->my_ext = __MY_EXT__;
+    
+    fp = fopen( "/qspi/myext.txt", "r");
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/myext.txt" );
+        this->my_ext = __MY_EXT__;
+    }else{
+        if( fread( &my_ext, 1, 32, fp ) > 0 ){
+            debug_msg("Objeto SIP fixado ext %i", this->my_ext );
+        }else{
+            debug_msg("Failed to read /qspi/myext.txt" );
+            this->my_ext = __MY_EXT__;
+        }
+    }
+    fclose( fp );
+    
     itoa( this->my_ext, this->my_display, 10 );
-    this->peer_ext = __PEER_EXT__;
- 
+    
+    fp = fopen( "/qspi/peerext.txt", "r");
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/peerext.txt" );
+        this->peer_ext = __PEER_EXT__;
+    }else{
+        if( fread( &peer_ext, 1, 32, fp ) > 0 ){
+            debug_msg("Objeto SIP fixado no server ext %i", this->peer_ext );
+        }else{
+            debug_msg("Failed to read /qspi/peerext.txt" );
+            this->peer_ext = __PEER_EXT__;
+        }
+    }
+    fclose( fp );
+    
     strcpy( this->fill_random_aux, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789pP" );
     strcpy( this->last_invite_tag, "" );
     strcpy( this->last_invite_callid, "");
@@ -120,33 +156,73 @@
 }
  
 Sip::Sip( int id, uint16_t my_port ){
+    FILE * fp = NULL;
     this->id = id;
-    strncpy( this->server_ip, __SEVER_IP__, 20 );
+    fp = fopen( "/qspi/serverip.txt", "r");
+    if( fp == NULL){
+        debug_msg("Failed to open /qspi/serverip.txt" );
+        strncpy( this->server_ip, __SERVER_IP__, 20 );    
+    }else{
+        if( fread( this->buffer, 1, 512, fp ) > 0 ){
+            strncpy( this->server_ip, this->buffer, 20 );
+            debug_msg("Objeto SIP fixado com ip %s", this->server_ip );
+        }else{
+            debug_msg("Failed to read /qspi/serverip.txt" );
+            strncpy( this->server_ip, __SERVER_IP__, 20 );
+        }
+    }
+    fclose( fp );
     this->server_ip[19] = 0;
-    this->server_port = __SERVER_PORT__;
     
-    FILE *fp = fopen( "/qspi/myip.txt", "r");
+    fp = fopen( "/qspi/serverport.txt", "r");
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/serverport.txt" );
+        this->server_port = __SERVER_PORT__;
+    }else{
+        if( fread( &server_port, 1, 512, fp ) > 0 ){
+            this->server_port = __SERVER_PORT__;
+            debug_msg("Objeto SIP fixado na server port %i", this->server_port );
+        }else{
+            debug_msg("Failed to read /qspi/serverport.txt" );
+            this->server_port = __SERVER_PORT__;
+        }
+    }
+    fclose( fp );
+    
+    fp = fopen( "/qspi/myip.txt", "r");
     if (fp == NULL){
-        pc.printf("Failed to open /qspi/myip.txt \n\r" );
+        debug_msg("Failed to open /qspi/myip.txt" );
         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" );
+            debug_msg("Failed to read /qspi/myip.txt" );
             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();
+    this->my_ext = id;
+    itoa( this->my_ext, this->my_display, 10 );
+    fp = fopen( "/qspi/peerext.txt", "r");
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/peerext.txt" );
+        this->peer_ext = __PEER_EXT__;
+    }else{
+        if( fread( &peer_ext, 1, 32, fp ) > 0 ){
+            debug_msg("Objeto SIP fixado no server ext %i", this->peer_ext );
+        }else{
+            debug_msg("Failed to read /qspi/peerext.txt" );
+            this->peer_ext = __PEER_EXT__;
+        }
+    }
+    fclose( fp );
     
-    this->my_ip[19] = 0;
-    this->my_port = my_port;
-    this->my_rtp_port = fill_random_rtp_port();
-    this->my_ext = id;
-    itoa( this->my_ext, this->my_display, 10 );
-    this->peer_ext = __PEER_EXT__;
- 
     strcpy( this->fill_random_aux, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789pP" );
     strcpy( this->last_invite_tag, "" );
     strcpy( this->last_invite_callid, "");
@@ -157,12 +233,56 @@
 }
  
 Sip::Sip( int id, uint16_t my_port, int dest_ext  ){
+    FILE * fp = NULL;
     this->id = id;
-    strncpy( this->server_ip, __SEVER_IP__, 20 );
+    
+    fp = fopen( "/qspi/serverip.txt", "r");
+    if( fp == NULL){
+        debug_msg("Failed to open /qspi/serverip.txt" );
+        strncpy( this->server_ip, __SERVER_IP__, 20 );    
+    }else{
+        if( fread( this->buffer, 1, 512, fp ) > 0 ){
+            strncpy( this->server_ip, this->buffer, 20 );
+            debug_msg("Objeto SIP fixado com ip %s", this->server_ip );
+        }else{
+            debug_msg("Failed to read /qspi/serverip.txt" );
+            strncpy( this->server_ip, __SERVER_IP__, 20 );
+        }
+    }
+    fclose( fp );
     this->server_ip[19] = 0;
-    this->server_port = __SERVER_PORT__;
-    strncpy( this->my_ip, "192.168.120.172", 20 );
+    
+    fp = fopen( "/qspi/serverport.txt", "r");
+    if( fp == NULL ){
+        debug_msg("Failed to open /qspi/serverport.txt" );
+        this->server_port = __SERVER_PORT__;
+    }else{
+        if( fread( &server_port, 1, 512, fp ) > 0 ){
+            this->server_port = __SERVER_PORT__;
+            debug_msg("Objeto SIP fixado na server port %i", this->server_port );
+        }else{
+            debug_msg("Failed to read /qspi/serverport.txt" );
+            this->server_port = __SERVER_PORT__;
+        }
+    }
+    fclose( fp );
+    
+    fp = fopen( "/qspi/myip.txt", "r");
+    if (fp == NULL){
+        debug_msg("Failed to open /qspi/myip.txt" );
+        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{
+            debug_msg("Failed to read /qspi/myip.txt" );
+            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();
     this->my_ext = id;
@@ -184,11 +304,11 @@
  
 void Sip::registry(){
     char out[ 1000 ];
-    debug_msg("registrando -- %d", this->my_ext );
+    if( debug_sip ) debug_msg("Registry %d", this->my_ext );
     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 ext %d", sent, my_ext );
+    if( debug_sip ) debug_msg("Received %i bytes to 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){
--- a/sip.h	Mon Sep 22 21:15:07 2014 +0000
+++ b/sip.h	Tue Sep 23 18:28:37 2014 +0000
@@ -17,33 +17,6 @@
 #define DRAMBASEADDR    0xa0000000
 #define SIP_ALLOW "Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, REFER"
 /* #define SIP_ALLOW "Allow: ACK, BYE, CANCEL, INVITE, OPTIONS" */
-/*
-#define __SEVER_IP__ "192.168.120.120"
-#define __SERVER_PORT__ 5075
-//#define __MY_IP__ "192.168.120.191"
-*/
-#define __MY_PORT__ 5062
-#define __MY_EXT__ 820
-//#define __PEER_EXT__ 801 
-#define __PEER_EXT__ 913
-//#define __PEER_EXT__ 803
-
-
-//#ifdef debug_colinas
-//#define __SEVER_IP__ "192.168.30.25"      // Colinas
-#define __SEVER_IP__ "192.168.120.120"
-
-
-//#define __SERVER_PORT__ 5060              // Colinas
-#define __SERVER_PORT__ 5075
-
-//#endif
-//#ifndef debug_colinas
-//#define __SEVER_IP__ "192.168.120.120"
-//#define __SEVER_IP__ "192.168.30.25"
-//#define __SERVER_PORT__ 5075
-//#define __SERVER_PORT__ 5060
-//#endif
 
 #define sip_idle 0
 #define sip_waiting_trying 1 << 1
--- a/utils.cpp	Mon Sep 22 21:15:07 2014 +0000
+++ b/utils.cpp	Tue Sep 23 18:28:37 2014 +0000
@@ -45,15 +45,16 @@
     char buff_ip[ 16 ];
     char buff_msk[ 16 ];
     char buff_gtw[ 16 ];
+    pc.printf("\n\r");
     FILE *fp = fopen( "/qspi/myip.txt", "r");
     if( fp == NULL ){
-        pc.printf("Failed to open /qspi/myip.txt\n\r" );
+        debug_msg("Failed to open /qspi/myip.txt" );
         strncpy( buff_ip, __MY_IP__, 20 );    
     }else{
         if( fread( buff_ip, 1, 512, fp ) > 0 ){
             debug_msg("Eth ip %s", buff_ip );
         }else{
-            pc.printf("Failed to read /qspi/myip.txt\n\r" );
+            debug_msg("Failed to read /qspi/myip.txt" );
             strncpy( buff_ip, __MY_IP__, 20 );
         }
     }
@@ -63,14 +64,14 @@
     
     fp = fopen( "/qspi/mymask.txt", "r");
     if( fp == NULL ){
-        pc.printf("Failed to open /qspi/mymask.txt \n\r" );
-        strncpy( buff_msk, __MY_IP__, 20 );    
+        debug_msg("Failed to open /qspi/mymask.txt" );
+        strncpy( buff_msk, __MY_MSK__, 20 );    
     }else{
         if( fread( buff_msk, 1, 512, fp ) > 0 ){
             debug_msg("mascara de rede Eth %s", buff_msk );
         }else{
-            pc.printf("Failed to read /qspi/mymask.txt\n\r" );
-            strncpy( buff_msk, __MY_IP__, 20 );
+            debug_msg("Failed to read /qspi/mymask.txt" );
+            strncpy( buff_msk, __MY_MSK__, 20 );
         }
     }
     fclose( fp );
@@ -79,14 +80,14 @@
     
     fp = fopen( "/qspi/mygate.txt", "r");
     if( fp == NULL ){
-        pc.printf("Failed to open /qspi/mygate.txt \n\r" );
-        strncpy( buff_gtw, __MY_IP__, 20 );    
+        debug_msg("Failed to open /qspi/mygate.txt" );
+        strncpy( buff_gtw, __MY_GTW__, 20 );    
     }else{
         if( fread( buff_gtw, 1, 512, fp ) > 0 ){
             debug_msg("Ip Gateway Eth %s", buff_gtw );
         }else{
-            pc.printf("Failed to read /qspi/mygate.txt\n\r" );
-            strncpy( buff_gtw, __MY_IP__, 20 );
+            debug_msg("Failed to read /qspi/mygate.txt" );
+            strncpy( buff_gtw, __MY_GTW__, 20 );
         }
     }
     fclose( fp );
@@ -129,18 +130,10 @@
                 }else{
               //      debug_msg("Ping on %d", cb->get_ext() );
                     
-                    cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) );
-                    
-                    debug_msg("");
-                    
+                    cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) );                
                     __send_to_cb__( __build_cb_package__( cb->get_ext(), cb->get_port(), __REGISTRY__, 
                         ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
-                    
-                    debug_msg("");
-                    
                     cb->registry();
-                    
-                    debug_msg("");
                 }
             }
         }
--- a/vz_protocol.h	Mon Sep 22 21:15:07 2014 +0000
+++ b/vz_protocol.h	Tue Sep 23 18:28:37 2014 +0000
@@ -12,6 +12,7 @@
 
 #define __VZ_HEADER_OFFSET__ 7
 #define __CB_BUFFER_SIZE__ 300
+#define __TELEMETRY_SIZE__ __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__
 #define __ETH_BUFFER_SIZE__ __CB_BUFFER_SIZE__ + __RTP_HEADER_SIZE__ + 1 // 313  
 #define __CB_AUDIO_DATA_SIZE__ 240
 #define __CHECKSUM_OFFSET__ 7
@@ -37,9 +38,16 @@
 
 #define __DO_NOTHING__ 0x99
 
-//#define __MY_IP__ "192.168.120.169"
-//#define __MY_IP__ "192.168.120.172"
 #define __MY_IP__ "192.168.2.200"
+#define __MY_EXT__ 820
+#define __MY_PORT__ 5062
+
+#define __SERVER_IP__ "192.168.120.120"
+#define __PEER_EXT__ 913
+#define __SERVER_PORT__ 5075
+
+#define __MY_GTW__ "192.168.2.254"
+#define __MY_MSK__ "255.255.255.0"
 
 extern uint16_t pkg_ckserr;
 extern uint16_t pkg_cksok;