![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: prompt.cpp
- Revision:
- 38:af5ecd6997ab
- Parent:
- 36:728498a78e1e
- Child:
- 41:69bf7091c2ca
diff -r d66bfb594604 -r af5ecd6997ab prompt.cpp --- a/prompt.cpp Tue Sep 30 19:25:32 2014 +0000 +++ b/prompt.cpp Wed Oct 01 19:14:38 2014 +0000 @@ -21,6 +21,7 @@ uint8_t debug_eth_rx = 0; uint8_t debug_eth_tx = 0; uint8_t debug_file = 0; +bool from_eth = false; uint8_t test_debug = 1; #define PVERSION 1.1 // Sempre atualizar a versao do prompt @@ -70,22 +71,20 @@ } } -void cat(const char* fname) // Print the content of a given file -{ +// Print the content of a given file +void cat(const char* fname){ char buff[513]; int num; FILE *fp = fopen(fname, "r"); if (fp == NULL) { - pc.printf("Failed to open %s", fname); + if( debug_file ) debug_msg("Failed to open %s", fname); return; } - while ((num = fread(buff, 1, 512, fp)) > 0) - { + while ((num = fread(buff, 1, 512, fp)) > 0){ buff[num] = '\0'; pc.printf(buff); - } fclose(fp); } @@ -138,13 +137,13 @@ fserext = fopen("/qspi/myext.txt", "r"); if ( fserext == NULL ){ fserext = fopen("/qspi/myext.txt", "w"); - fprintf( fserext, "%i" ,__MY_EXT__ ); //asterisk ext + fprintf( fserext, "%i\n\r" ,__MY_EXT__ ); //asterisk ext exists = false; } fport = fopen("/qspi/mysipport.txt", "r"); if (fport == NULL){ fport = fopen("/qspi/mysipport.txt", "w"); - fprintf(fport, "%i",__MY_PORT__); //mysipport + fprintf(fport, "%i\n\r",__MY_PORT__); //mysipport exists = false; } fsip = fopen("/qspi/serverip.txt", "r"); @@ -158,13 +157,13 @@ fext = fopen("/qspi/peerext.txt", "r"); if ( fext == NULL ){ fext = fopen("/qspi/peerext.txt", "w"); - fprintf( fext, "%i",__PEER_EXT__ ); //asterisk ip + fprintf( fext, "%i\n\r",__PEER_EXT__ ); //asterisk ip exists = false; } fsport = fopen("/qspi/serverport.txt", "r"); if (fsport == NULL){ fsport = fopen("/qspi/serverport.txt", "w"); - fprintf(fsport, "%i",__SERVER_PORT__ ); //asterisk port + fprintf(fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port exists = false; } @@ -206,13 +205,13 @@ //fprintf( fip, "%s\n\r", __MY_IP__ ); //myip fprintf( fip, "%s", __MY_IP__ ); //myip - fprintf( fport, "%i", __MY_PORT__ ); //mysipport - fprintf( fext, "%i", __MY_EXT__ ); //myext + fprintf( fport, "%i\n\r", __MY_PORT__ ); //mysipport + fprintf( fext, "%i\n\r", __MY_EXT__ ); //myext //fprintf( fsip, "%s\n\r", __SERVER_IP__ ); //asterisk ip fprintf( fsip, "%s", __SERVER_IP__ ); //asterisk ip - fprintf( fserext, "%i",__PEER_EXT__ ); //asterisk port - fprintf( fsport, "%i",__SERVER_PORT__ ); //asterisk port + fprintf( fserext, "%i\n\r",__PEER_EXT__ ); //asterisk port + fprintf( fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port fprintf( fmask, "%s",__MY_MSK__ ); //mymask fprintf( fgate, "%i", __MY_GTW__ ); //mygateway @@ -241,7 +240,6 @@ volatile char b = 0; static uint8_t bufret = 0; static Timer flood_timeout; - bool from_eth = false; bool miss_match = true; if( flood_timeout.read() > 60 ){ @@ -284,7 +282,6 @@ if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) ".",1 )) { miss_match = false; - //xmemcpy( (uint)debug_buf, last_debug_buf, 300); strcpy( debug_buf, last_debug_buf ); } @@ -295,18 +292,23 @@ miss_match = false; pc.printf("\n\r"); files('s'); + //need mount the string in 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(); + + //nunca retorna por conta da interrupcao + //if( from_eth ){ + // snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Formatando o sistema de arquivos... espere o sistema reiniciar\n"); + // debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + //} NVIC_SystemReset(); } 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)); fprintf(fip,"%s",(debug_buf+6)); fclose(fip); pc.printf("\n\r"); @@ -362,7 +364,6 @@ 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)); fprintf(fsip,"%s",(debug_buf+9)); fclose(fsip); pc.printf("\n\r"); @@ -388,6 +389,10 @@ if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" )) { miss_match = false; pc.printf("\n\rJob is done\n\r"); + if( from_eth ){ + snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Job is done\n"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } NVIC_SystemReset(); } @@ -405,6 +410,10 @@ if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { miss_match = false; pc.printf("\n\r\t Flood ON\n\r\t"); + if( from_eth ){ + snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Flood On\n" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } tflood.start(); tflood.reset(); floodcount =0; @@ -414,6 +423,10 @@ if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { miss_match = false; pc.printf("\n\r\t Flood OFF\n\r\t"); + if( from_eth ){ + snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Flood Off\n" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } pflood = 0; tflood.stop(); flood_timeout.reset(); @@ -424,11 +437,19 @@ if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { miss_match = false; pc.printf("\n\r\tDebug ON\n\r\t"); + if( from_eth ){ + snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Debug On\n" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } 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"); + if( from_eth ){ + snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Debug Off\n" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } debug_alive = 0; } if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 )) { @@ -474,7 +495,9 @@ } } - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9)) { //promptcb ramal porta comando + //promptcb ramal porta comando + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9)) { + miss_match = false; static int id_msg = 0x10; uint8_t write_buffer[300]; unsigned int ext,port; @@ -494,6 +517,7 @@ pc.printf("\n\rComando enviado\n\r"); } if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcb ",4 )) { + miss_match = false; static int id_msg = 0x30; uint8_t write_buffer[300]; debug_buf[bufptr++] = 0x0D; @@ -515,16 +539,16 @@ pshowcb = 1; } - if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debugsip ", 9 )) { - if (xmemmatch( (uint8_t*)( debug_buf + 9 ), (uint8_t*) "on",2 )) { + if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_main ", 11 )) { + if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { miss_match = false; - pc.printf("\tDebug Sip ON"); - debug_sip = 1; + pc.printf("\r\nDebug Main ON"); + debug_main = 1; } - if (xmemmatch( (uint8_t*)( debug_buf + 9 ), (uint8_t*) "off",3 )) { + if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { miss_match = false; - pc.printf("Debug Sip OFF"); - debug_sip = 0; + pc.printf("\r\nDebug Main OFF"); + debug_main = 0; } } @@ -622,7 +646,13 @@ } */ - if( miss_match ) pc.printf("\n\r%s: command not found\n\r", debug_buf ); + if( miss_match ){ + pc.printf("\n\r%s: command not found\n\r", debug_buf ); + if( from_eth ){ + snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "%s: command not found\n", debug_buf ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + } else strcpy( last_debug_buf, debug_buf ); }