Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
50:d9b6577a70f5
Parent:
48:195c97f12e8e
Child:
51:5fc3a8f02fdf
diff -r 4837ed2aad6b -r d9b6577a70f5 prompt.cpp
--- a/prompt.cpp	Mon Oct 20 16:32:12 2014 +0000
+++ b/prompt.cpp	Mon Oct 20 19:28:38 2014 +0000
@@ -330,7 +330,7 @@
         ftcpport = fopen( "/qspi/tcpport.txt", "r" );
     }
         
-    if (type == 'w'){                 // Create and write the default configs
+    if( type == 'w'){                 // Create and write the default configs
         fip = fopen("/qspi/myip.txt", "w");
         fmask = fopen("/qspi/mymask.txt", "w");
         fgate = fopen("/qspi/mygateway.txt", "w");
@@ -371,6 +371,48 @@
             bufptr = 0;
         } 
     }
+    
+    if (type == 'e'){                 // Create and write the default configs
+        fip = fopen("/qspi/myip.txt", "w");
+        fmask = fopen("/qspi/mymask.txt", "w");
+        fgate = fopen("/qspi/mygateway.txt", "w");
+        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" );
+        fudpport = fopen( "/qspi/udpport.txt", "w" );
+        ftcpport = fopen( "/qspi/tcpport.txt", "w" );
+        
+        fprintf( fip, "%s\n\r", ""  );   //myip
+        fprintf( fport, "%i\n\r", "" );  //mysipport // isso pode dar pala
+        fprintf( fext, "%i\n\r", "" );  //myext
+        
+        fprintf( fsip, "%s\n\r", ""  );  //asterisk ip
+        fprintf( fserext, "%i\n\r","" );  //asterisk port
+        fprintf( fsport, "%i\n\r","" );  //asterisk port
+        
+        fprintf( fmask, "%s\n\r","" );     //mymask
+        fprintf( fgate, "%s\n\r", "" );    //mygateway
+        
+        fprintf( fudpport, "%i\n\r","" );
+        fprintf( ftcpport, "%i\n\r","" );
+        
+        files('c');
+        
+        pc.printf("\n\rErased configurations set!\n\r");
+        if( from_eth ){
+            snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rErased configurations set!\n\r");
+            debug_buf[ strlen( debug_buf ) - 1 ] = '\0';
+            if( tcp_session ){
+                tcp_client.send_all( debug_buf, strlen( debug_buf ) );
+            }else if( udp_request ){
+                udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) );
+            }
+            debug_buf[ 0 ] = 0;
+            bufptr = 0;
+        } 
+    }
 }
 void init_fsystem(){                 
    //  init file system and check if files exist
@@ -529,7 +571,7 @@
         }
         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");
+            pc.printf("\n\rFormatando o sistema de arquivos... espere o sistema reiniciar\n\r");
             if( from_eth ){
                 snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Formatando o sistema de arquivos... espere o sistema reiniciar\n\r");
                 debug_buf[ strlen( debug_buf ) - 1 ] = '\0';
@@ -540,6 +582,7 @@
                     udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) );
                 }
             }
+            files('e');
             files('w');
             __disable_irq();
             NVIC_SystemReset();
@@ -620,6 +663,7 @@
 
         if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" ) ){
             miss_match = false;
+            files('e');
             files('w');
             files('s');
         }
@@ -715,7 +759,7 @@
             }
             if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 ) ){
                 miss_match = false;
-                pc.printf("\n\rdebug_sip");
+                pc.printf("\n\rdsip");
                 pc.printf("\n\rdebug_alive");
                 pc.printf("\n\rdebug_prompt");
                 pc.printf("\n\rdebug_vector");
@@ -729,14 +773,14 @@
                 pc.printf("\n\rdebug_file");
                 
                 if( from_eth ){
-                    snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rdebug_sip \n\rdebug_alive \n\rdebug_prompt \n\rdebug_vector \n\rdebug_cb \n\rdebug_main \n\rdebug_cks \n\rdebug_cb_rx \n\rdebug_cb_tx* \n\rdebug_eth_rx* \n\rdebug_eth_tx* \n\rdebug_file\n\r" );
+                    snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rdsip \n\rdebug_alive \n\rdebug_prompt \n\rdebug_vector \n\rdebug_cb \n\rdebug_main \n\rdebug_cks \n\rdebug_cb_rx \n\rdebug_cb_tx* \n\rdebug_eth_rx* \n\rdebug_eth_tx* \n\rdebug_file\n\r" );
                     debug_buf[ strlen( debug_buf ) - 1 ] = '\0';
                 }
             }
         }
         
-        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_sip ", 10 ) ){
-            if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on",2 ) ){
+        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dsip ",5 ) ){
+            if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 ) ){
                 miss_match = false;
                 pc.printf( "\n\rSip Debug ON\n\r" );
                 if( from_eth ){
@@ -745,7 +789,7 @@
                 }
                 debug_sip = 1;
             }
-            if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) {
+            if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) {
                 miss_match = false;
                 pc.printf( "\n\rSip Debug OFF\n\r" );
                 if( from_eth ){
@@ -757,7 +801,7 @@
         }
         
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cks ", 10 )) {
-            if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on",2 )) {
+            if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 )) {
                 miss_match = false;
                 pc.printf( "\n\rCKS Debug ON\n\r" );
                 if( from_eth ){
@@ -766,7 +810,7 @@
                 }
                 debug_cks = 1;
             }
-            if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) {
+            if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) {
                 miss_match = false;
                 pc.printf( "\n\rCKS Debug OFF\n\r" );
                 if( from_eth ){
@@ -778,6 +822,7 @@
         }
         
         //promptcb ramal porta comando
+        //FIXME colocar a parte eth de novo
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcb ", 4 )) {
             miss_match = false;
             static uint8_t id_msg = 0x10;
@@ -791,9 +836,11 @@
             
             split = strtok( debug_buf + 4, " " );
             ext = atoi( split );
-            split = strtok( NULL, " " );
-            port = atoi( split );
+            //split = strtok( NULL, " " );
+            //port = atoi( split );
             //split = strtok( NULL, " " );
+            
+            port = convert_ext_to_port( ext );
             split += strlen( split ) + 1;
             
             promptcb_last_ext = ext;
@@ -1216,4 +1263,12 @@
         pc.printf("> ");
     }    
     return( NULL );
-}
\ No newline at end of file
+}
+
+int convert_ext_to_port( int ext ){                                                                                                                                                                    
+  int aux = 0;                                                                                                                                                                                         
+  aux = ( ext / 1000 ) * 1000;                                                                                                                                                                         
+  ext -= aux;                                                                                                                                                                                          
+  aux += ext % 100;                                                                                                                                                                                    
+  return( aux );                                                                                                                                                                                       
+}