![](/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:
- 42:480335bdde12
- Parent:
- 41:69bf7091c2ca
- Child:
- 43:455522f98de5
diff -r 69bf7091c2ca -r 480335bdde12 prompt.cpp --- a/prompt.cpp Thu Oct 02 21:22:54 2014 +0000 +++ b/prompt.cpp Fri Oct 03 20:14:59 2014 +0000 @@ -24,18 +24,19 @@ uint8_t debug_eth_tx = 0; uint8_t debug_file = 0; bool from_eth = false; +bool udp_request = false; +bool tcp_session = false; bool udp_pkg; -bool tcp_pkg; uint8_t test_debug = 1; -#define PVERSION 1.1 // Sempre atualizar a versao do prompt +#define PVERSION 3 // Sempre atualizar a versao do prompt #define DEBUGBUFSIZE 50 char __debug_buf__[DEBUGBUFSIZE]; char * debug_buf = __debug_buf__; char last_debug_buf[ DEBUGBUFSIZE ] = "help"; FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext; -uint8_t dog = 1; +//uint8_t dog = 1; uint8_t debug_prompt = 0; uint8_t bufptr = 0; uint8_t last_bufptr = 0; @@ -82,38 +83,78 @@ FILE *fp = fopen(fname, "r"); if (fp == NULL) { - if( debug_file ) debug_msg("Failed to open %s", fname); + if( debug_file ) pc.printf( "Failed to open %s", fname); return; } - while ((num = fread(buff, 1, 512, fp)) > 0){ - buff[num] = '\0'; - pc.printf(buff); + while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ + buff[ num ] = '\0'; + pc.printf( buff ); + if( from_eth ){ + if( tcp_session ) client.send_all( buff, strlen( buff ) ); + } } fclose(fp); } // operantion with the system config files -void files (const char type) { - if (type == 's' ){ // show files - pc.printf("\n\r"); - pc.printf("Header IP " ); +void files( const char type ){ + // show files + if (type == 's' ){ + pc.printf("\n\rHeader IP " ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader IP " ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } cat("/qspi/myip.txt"); + pc.printf("\n\rHeader ext "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader ext " ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } cat("/qspi/myext.txt"); + pc.printf("\n\rHeader port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader port " ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } cat("/qspi/mysipport.txt"); - pc.printf("\n\rServer ip "); + pc.printf("\n\rServer IP "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer IP " ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } cat("/qspi/serverip.txt"); + pc.printf("\n\rServer ext "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer ext " ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } cat("/qspi/peerext.txt"); + pc.printf("\n\rServer port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer port " ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } cat("/qspi/serverport.txt"); pc.printf("\n\rMascara de rede "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rMascara de rede " ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } cat("/qspi/mymask.txt"); + pc.printf("\n\rGateway IP "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rGateway IP " ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } cat("/qspi/mygate.txt"); } @@ -251,482 +292,643 @@ static Timer flood_timeout; bool miss_match = true; char buffer[ 1024 ]; - - if( flood_timeout.read() > 60 ){ - pflood = 0; - flood_timeout.stop(); - flood_timeout.reset(); - } - if( tcp_timer.read() > 3 ){ - wdt.kick(); - tcp_timer.reset(); - if( !server.accept( client ) ){ - //FIXME mudar essa condicao para parar depois de 30 sec for instance - while( tcp_timer.read() < 30 ){ - client.set_blocking( false, 1 ); - int n = client.receive(buffer, sizeof( buffer )); - if( n > 0 ){ - wdt.kick(); - tcp_timer.reset(); - + do{ + if( flood_timeout.read() > 60 ){ + pflood = 0; + flood_timeout.stop(); + flood_timeout.reset(); + } + if( tcp_timer.read() > 3 || tcp_session ){ + wdt.kick(); + tcp_timer.reset(); + if( tcp_session ){ + while( tcp_timer.read() < 30 ){ + client.set_blocking( false, 1 ); + int n = client.receive( buffer, sizeof( buffer ) ); + if( n > 0 ){ + wdt.kick(); + tcp_timer.reset(); + buffer[ n - 2 ] = 0; + bufptr = n - 2; + if( !( strcmp( buffer, "quit" ) ) ){ + debug_msg("quit request"); + debug_buf = __debug_buf__; + bufptr = last_bufptr; + tcp_session = false; + client.close(); + bufret = 0; + return( NULL ); + } + from_eth = true; + bufret = 1; + break; + } + } + }else{ + if( !server.accept( client ) ){ + tcp_session = true; + from_eth = true; last_bufptr = bufptr; - debug_msg("%x -- %x", buffer[ n - 2 ], buffer[ n - 1 ] ); - bufptr = n - 2;//strlen( buffer ); - debug_msg("Sizeof pkg received (n, strlen( buffer ) ) (%d, %d)", n , bufptr ); + buffer[ 0 ] = '\0'; debug_buf = buffer; - debug_buf[ n - 2 ] = 0; - debug_msg("Command received %s::endl", debug_buf ); - from_eth = true; - tcp_pkg = true; - bufret = 1; + bufptr = 0; + bufret = 0; } } if( tcp_timer.read() >= 30 ){ tcp_timer.reset(); - tcp_pkg = false; + tcp_session = false; debug_buf = __debug_buf__; bufptr = last_bufptr; bufret = 0; - from_eth = false; + from_eth = false; + tcp_session = false; return( NULL ); } - } - }else if( msg_to_eth == NULL ){ - if ( pc.readable() ){ - // imput do teclado - b = pc.getc(); - - if( b == 0x0D ){ // enter - bufret = 1; + }else if( !tcp_session ){ + if( msg_to_eth == NULL ){ + if ( pc.readable() ){ + // imput do teclado + b = pc.getc(); + + if( b == 0x0D ){ // enter + bufret = 1; + }else{ + pc.putc( b ); + if( b == 0x08 || b == 0x7F ){ // BS | DEL + if( bufptr > 0 ) debug_buf[ --bufptr ] = 0; + }else if( b == 0x09 ){ + // ignore tab + }else{ + debug_buf[bufptr] = b; + bufptr++; + } + } + } }else{ - pc.putc( b ); - if( b == 0x08 || b == 0x7F ){ // BS | DEL - if( bufptr > 0 ) debug_buf[ --bufptr ] = 0; - }else if( b == 0x09 ){ - // ignore tab - }else{ - debug_buf[bufptr] = b; - bufptr++; - } + last_bufptr = bufptr; + bufptr = strlen( msg_to_eth ); + debug_buf = msg_to_eth; + from_eth = true; + bufret = 1; } } - }else{ - last_bufptr = bufptr; - bufptr = strlen( msg_to_eth ); - debug_buf = msg_to_eth; - from_eth = true; - bufret = 1; - } - - // Prompt commands here - if ( bufret == 1 ) { - static unsigned int promptcb_last_ext = 0; - static unsigned int promptcb_last_port = 0; - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) ".",1 )) { - miss_match = false; - strcpy( debug_buf, last_debug_buf ); - } - - if( !bufptr ){ - miss_match = false; - } - if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "sconfig" )) { - 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"); + + // Prompt commands here + if ( bufret == 1 ) { + static unsigned int promptcb_last_ext = 0; + static unsigned int promptcb_last_port = 0; + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) ".",1 )) { + miss_match = false; + strcpy( debug_buf, last_debug_buf ); + } + + if( !bufptr ){ + miss_match = false; + } + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ifconfig" ) ){ + 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"); + 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'; + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + client.close(); + } + NVIC_SystemReset(); + } + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ", 6 )) { + miss_match = false; + fip = fopen("/qspi/myip.txt", "w"); + fprintf(fip,"%s",(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" , ( debug_buf + 7) ); + fclose(fip); + pc.printf("\n\r"); + files('s'); + } - //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",(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" , ( 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); - pc.printf("\n\r"); - files('s'); - } - - 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); - pc.printf("\n\r"); - files('s'); - } - - - 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); - pc.printf("\n\r"); - files('s'); - } - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 )) { - miss_match = false; - fsip = fopen("/qspi/serverip.txt", "w"); - fprintf(fsip,"%s",(debug_buf+9)); - fclose(fsip); - pc.printf("\n\r"); - files('s'); - } - - 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); - pc.printf("\n\r"); - files('s'); - } - - - 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" )) { - 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'; + 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); + pc.printf("\n\r"); + files('s'); + } + + 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); + pc.printf("\n\r"); + files('s'); + } + + 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); + pc.printf("\n\r"); + files('s'); } - 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"); - if( from_eth ){ - snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "MUUUUUUUuuuuUUUUUU - I'm not a dog!!!!\n"); - debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 ) ){ + miss_match = false; + fsip = fopen("/qspi/serverip.txt", "w"); + fprintf(fsip,"%s",(debug_buf+9)); + fclose(fsip); + pc.printf("\n\r"); + files('s'); } - dog = 0; - } - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ",6 )) { - if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 ) ){ 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; - pflood = 1; - flood_timeout.start(); + fsport = fopen("/qspi/serverport.txt", "w"); + fprintf(fsport,"%s\n\r",(debug_buf+7)); + fclose(fsport); + pc.printf("\n\r"); + files('s'); } - if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { + + + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" ) ){ 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(); + files('w'); + files('s'); } - } - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 )) { - if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { + + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" ) ){ miss_match = false; - pc.printf("\n\r\tDebug ON\n\r\t"); + pc.printf("\n\rJob is done\n\r"); if( from_eth ){ - snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Debug On\n" ); + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Job is done\n\r"); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + client.close(); } - debug_alive = 1; + NVIC_SystemReset(); } - if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { + + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" ) ){ miss_match = false; - pc.printf("\n\r\tDebug OFF\n\r\t"); + pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); if( from_eth ){ - snprintf( debug_buf, __UDP_ETH_BUFFER_SIZE__, "Debug Off\n" ); + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "MUUUUUUUuuuuUUUUUU - I'm not a dog!!!!\n\r"); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } - debug_alive = 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"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood On\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + tflood.start(); + tflood.reset(); + floodcount =0; + pflood = 1; + flood_timeout.start(); + } + 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, __PROMPT_ETH_BUFFER_SIZE__, "Flood Off\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + pflood = 0; + tflood.stop(); + flood_timeout.reset(); + } } - if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 )) { - miss_match = false; - pc.printf("\n\rdebug_sip"); - pc.printf("\n\rdebug_alive"); - pc.printf("\n\rdebug_prompt"); - pc.printf("\n\rdebug_vector"); - pc.printf("\n\rdebug_cb"); - pc.printf("\n\rdebug_main"); - pc.printf("\n\rdebug_cks"); - pc.printf("\n\rdebug_cb_rx"); - pc.printf("\n\rdebug_cb_tx*"); - pc.printf("\n\rdebug_eth_rx*"); - pc.printf("\n\rdebug_eth_tx*"); - pc.printf("\n\rdebug_file"); + + 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"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug On\n\r" ); + 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, __PROMPT_ETH_BUFFER_SIZE__, "Debug Off\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_alive = 0; + } + if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 ) ){ + miss_match = false; + pc.printf("\n\rdebug_sip"); + pc.printf("\n\rdebug_alive"); + pc.printf("\n\rdebug_prompt"); + pc.printf("\n\rdebug_vector"); + pc.printf("\n\rdebug_cb"); + pc.printf("\n\rdebug_main"); + pc.printf("\n\rdebug_cks"); + pc.printf("\n\rdebug_cb_rx"); + pc.printf("\n\rdebug_cb_tx*"); + pc.printf("\n\rdebug_eth_rx*"); + pc.printf("\n\rdebug_eth_tx*"); + 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" ); + 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 )) { - miss_match = false; - pc.printf( "\n\rSip Debug ON\n\r" ); - debug_sip = 1; + + 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; + pc.printf( "\n\rSip Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug On\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_sip = 1; + } + if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) { + miss_match = false; + pc.printf( "\n\rSip Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug Off\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_sip = 0; + } } - if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) { - miss_match = false; - pc.printf( "\n\rSip Debug OFF\n\r" ); - debug_sip = 0; + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cks ", 10 )) { + if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on",2 )) { + miss_match = false; + pc.printf( "\n\rCKS Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug On\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_cks = 1; + } + if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) { + miss_match = false; + pc.printf( "\n\rCKS Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug Off\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_cks = 0; + } } - } - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cks ", 10 )) { - if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on",2 )) { + + //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; + int ant1,ant2; + + debug_buf[bufptr++] = 0x0D; + debug_buf[bufptr++] = 0x00; + + ant1 = str2uint( (debug_buf+9), &ext); + ant2 = str2uint( ((debug_buf+9)+ant1+1), &port); + + promptcb_last_ext = ext; + promptcb_last_port = port; + pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",ext, port, debug_buf+9+ant1+2+ant2); + promptcb_last_ext = ext; + __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"); + } + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcb ",4 )) { miss_match = false; - pc.printf( "\n\rCKS Debug ON\n\r" ); - debug_cks = 1; + static int id_msg = 0x30; + uint8_t write_buffer[300]; + debug_buf[bufptr++] = 0x0D; + debug_buf[bufptr++] = 0x00; + + pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf+4); + + __send_to_cb__( __build_cb_package__( promptcb_last_ext, promptcb_last_port, __PROMPT__, debug_buf+4, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + pc.printf("\n\rComando enviado\n\r"); + } + + 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 + 10 ), (uint8_t*) "off",3 )) { - miss_match = false; - pc.printf( "\n\rCKS Debug OFF\n\r" ); - debug_cks = 0; + + 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("\r\nDebug Main ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main On\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_main = 1; + } + if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { + miss_match = false; + pc.printf("\r\nDebug Main OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main Off\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_main = 0; + } } - } - - //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; - int ant1,ant2; - - debug_buf[bufptr++] = 0x0D; - debug_buf[bufptr++] = 0x00; - - ant1 = str2uint( (debug_buf+9), &ext); - ant2 = str2uint( ((debug_buf+9)+ant1+1), &port); - - promptcb_last_ext = ext; - promptcb_last_port = port; - pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",ext, port, debug_buf+9+ant1+2+ant2); - promptcb_last_ext = ext; - __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"); - } - 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; - debug_buf[bufptr++] = 0x00; - - pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf+4); - - __send_to_cb__( __build_cb_package__( promptcb_last_ext, promptcb_last_port, __PROMPT__, debug_buf+4, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - pc.printf("\n\rComando enviado\n\r"); - } - - 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*) "debug_main ", 11 )) { - if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { - miss_match = false; - pc.printf("\r\nDebug Main ON"); - debug_main = 1; + + if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cb_rx ", 12 )) { + if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "on",2 )) { + miss_match = false; + pc.printf("\tDebug Cbx Rx ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Cbx On Rx on\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_cb_rx = 1; + } + if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "off",3 )) { + miss_match = false; + pc.printf("Debug Cbx Rx OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Cbx Rx Off\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_cb_rx = 0; + } } - if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { + + if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_file ", 11 )) { + if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { + miss_match = false; + pc.printf("\tDebug File ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File On\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_cb_rx = 1; + } + if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { + miss_match = false; + pc.printf("Debug File OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File Off\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_cb_rx = 0; + } + } + + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) { miss_match = false; - pc.printf("\r\nDebug Main OFF"); - debug_main = 0; - } - } - - if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cb_rx ", 12 )) { - if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "on",2 )) { - miss_match = false; - pc.printf("\tDebug Cbx Rx ON"); - debug_cb_rx = 1; - } - if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "off",3 )) { - miss_match = false; - pc.printf("Debug Cbx Rx OFF"); - debug_cb_rx = 0; - } - } - - if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_file ", 11 )) { - if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) { - miss_match = false; - pc.printf("\tDebug File ON"); - debug_cb_rx = 1; + pc.printf("\n\r****************************PROMPT HELP******************\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "\n\r****************************PROMPT HELP******************\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("ifconfig - mostra o arquivo de configuracao do sistema\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ifconfig - mostra o arquivo de configuracao do sistema\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("promptcb ramal porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "promptcb ramal porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("format - formata o sistema de arquivos\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "format - formata o sistema de arquivos\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("reset - resta o sistema\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "reset - resta o sistema\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("ipset [ip] - Configura o IP da cabeceira\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ipset [ip] - Configura o IP da cabeceira\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("extset [ext] - Configura a ext da cabeceira\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "extset [ext] - Configura a ext da cabeceira\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("msipport [port] - Configura a porta SIP da cabeceira\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "msipport [port] - Configura a porta SIP da cabeceira\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("serverip [ip] - Configura o ip do servidor asterisk\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "serverip [ip] - Configura o ip do servidor asterisk\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("serextset [ext] - Configura a server ext da cabeceira\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "serextset [ext] - Configura a server ext da cabeceira\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("ssport [port] - Configura a porta SIP do servidor asterisk\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ssport [port] - Configura a porta SIP do servidor asterisk\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("maskset [mask] - Configura a mascara da cabeceira\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "maskset [mask] - Configura a mascara da cabeceira\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("gatewayset [gateway] - Configura o gateway da cabeceira\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "gatewayset [gateway] - Configura o gateway da cabeceira\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("showcb - lista os Cbx registrados na header\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "showcb - lista os Cbx registrados na header\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("cks - exibe estatisticas de check sum\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "cks - exibe estatisticas de check sum\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf(". - executa o comando anterior novamente\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, ". - executa o comando anterior novamente\n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r" ); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("flood [on|off] - simula envio de pacotes de audio\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "flood [on|off] - simula envio de pacotes de audio\n\r"); + if( tcp_session ) client.send_all( debug_buf, strlen( debug_buf ) ); + } + pc.printf("PROMPT VERSION: V%d\n\r",PVERSION); + //Obs :: a ultima linha nao mandamos direto pro tcp porque ela eh enviada fora desse escopo + if( from_eth ) snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "PROMPT VERSION: V%d\n\r",PVERSION); } - if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { - miss_match = false; - pc.printf("Debug File OFF"); - debug_cb_rx = 0; + /* + if ( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )) { + if ( debug_buf[16] != 0 && debug_buf[11] != 0x20 ) + pc.printf("\n\r Error: formato errado! ramal=xxxx porta=xxxx \n\r"); + else { + uint8_t data[300]; + uint16_t cks=0; + + //data[0] = (uint8_t)( (debug_buf[7]&0xf0)<<4 + (debug_buf[8]&0x0f) ) ; + //data[1] = (uint8_t)( (debug_buf[9]&0xf0)<<4 + (debug_buf[10]&0x0f) ) ; + //data[2] = (uint8_t)( (debug_buf[12]&0xf0)<<4 + (debug_buf[13]&0x0f) ) ; + /data[3] = (uint8_t)( (debug_buf[14]&0xf0)<<4 + (debug_buf[15]&0x0f) ) ; + + data[0] = (uint8_t)( debug_buf[ 7 ] & 0xFF00 >> 8 ); + data[1] = (uint8_t)( debug_buf[ 9 ] & 0x00FF ); + data[2] = (uint8_t)( debug_buf[ 12 ] & 0xFF00 >> 8 ); + data[3] = (uint8_t)( debug_buf[ 14 ] & 0x00FF ); + + data[6] = 0x04; + for (int i = 7; i < 300; i++) data[i] = 0x00; + cks = __checksum__(data,300); + data[4] = cks>>8; + data[5] = cks&0xff; + + pc.printf("\n\r"); + for( int i = 0; i < 300; i++ ) + pc.printf("%x ", data[ i ] ); + pc.printf("\n\r"); + + xmemcpy(TXBuffer,data,300); + + pc.printf("\n\r"); + for( int i = 0; i < 300; i++ ) + pc.printf("%x ", data[ i ] ); + pc.printf("\n\r"); + + send2callboxes(); + + pc.printf("\n\r calling callbox %s \n\r",debug_buf+7); + } + } - } - - 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"); - pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); - pc.printf("promptcb ramal porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r"); - 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("showcb - lista os Cbx registrados na header\n\r"); - pc.printf("cks - exibe estatisticas de check sum\n\r"); - pc.printf(". - executa o comando anterior novamente\n\r"); - pc.printf("debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r"); - pc.printf("flood [on|off] - simula envio de pacotes de audio\n\r"); - pc.printf("PROMPT VERSION: V%d\n\r",PVERSION); + */ + + if( miss_match ){ + debug_msg(""); + pc.printf("\n\r%s: command not found\n\r", debug_buf ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "%s: command not found\n", debug_buf ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + } + + else strcpy( last_debug_buf, debug_buf ); } /* - if ( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )) { - if ( debug_buf[16] != 0 && debug_buf[11] != 0x20 ) - pc.printf("\n\r Error: formato errado! ramal=xxxx porta=xxxx \n\r"); - else { - uint8_t data[300]; - uint16_t cks=0; - - //data[0] = (uint8_t)( (debug_buf[7]&0xf0)<<4 + (debug_buf[8]&0x0f) ) ; - //data[1] = (uint8_t)( (debug_buf[9]&0xf0)<<4 + (debug_buf[10]&0x0f) ) ; - //data[2] = (uint8_t)( (debug_buf[12]&0xf0)<<4 + (debug_buf[13]&0x0f) ) ; - /data[3] = (uint8_t)( (debug_buf[14]&0xf0)<<4 + (debug_buf[15]&0x0f) ) ; - - data[0] = (uint8_t)( debug_buf[ 7 ] & 0xFF00 >> 8 ); - data[1] = (uint8_t)( debug_buf[ 9 ] & 0x00FF ); - data[2] = (uint8_t)( debug_buf[ 12 ] & 0xFF00 >> 8 ); - data[3] = (uint8_t)( debug_buf[ 14 ] & 0x00FF ); - - data[6] = 0x04; - for (int i = 7; i < 300; i++) data[i] = 0x00; - cks = __checksum__(data,300); - data[4] = cks>>8; - data[5] = cks&0xff; - - pc.printf("\n\r"); - for( int i = 0; i < 300; i++ ) - pc.printf("%x ", data[ i ] ); - pc.printf("\n\r"); - - xmemcpy(TXBuffer,data,300); - - pc.printf("\n\r"); - for( int i = 0; i < 300; i++ ) - pc.printf("%x ", data[ i ] ); - pc.printf("\n\r"); - - send2callboxes(); - - pc.printf("\n\r calling callbox %s \n\r",debug_buf+7); + if( from_eth ){ + if( tcp_session ){ + client.send_all( debug_buf, strlen( debug_buf ) ); + tcp_timer.reset(); + bufret = 0; + from_eth = false; + }else{ + msg_to_eth = debug_buf; + debug_buf = __debug_buf__; + bufptr = last_bufptr; + bufret = 0; + from_eth = false; + + if( miss_match ) return( NULL ); + + else return( msg_to_eth ); } - - } - */ - - 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 ); - } - if( from_eth ){ - if( tcp_pkg ){ - debug_msg(""); - client.send_all( debug_buf, bufptr ); - tcp_pkg = false; - tcp_timer.reset(); - return( NULL ); - } + }*/ - msg_to_eth = debug_buf; - debug_buf = __debug_buf__; - bufptr = last_bufptr; - bufret = 0; - from_eth = false; - - if( miss_match ) return( NULL ); - - else return( msg_to_eth ); - } - if ( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ) { - bufptr = 0; - for (uint8_t i =0; i < DEBUGBUFSIZE; i++) { - debug_buf[i] = 0; - } - bufret = 0; - pc.putc(0x0A); - pc.putc(0x0D); - pc.printf("> "); - } + if( tcp_session ){ + strcat( debug_buf, "\n\r> " ); + client.send_all( debug_buf, strlen( debug_buf ) ); + tcp_timer.reset(); + bufret = 0; + from_eth = false; + }else if( udp_request ){ + msg_to_eth = debug_buf; + debug_buf = __debug_buf__; + bufptr = last_bufptr; + bufret = 0; + from_eth = false; + + if( miss_match ) return( NULL ); + + else return( msg_to_eth ); + } + if( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ){ + bufptr = 0; + for (uint8_t i =0; i < DEBUGBUFSIZE; i++) { + debug_buf[i] = 0; + } + bufret = 0; + pc.putc(0x0A); + pc.putc(0x0D); + pc.printf("> "); + } + }while( tcp_session ); + return( NULL ); -} \ No newline at end of file +} \ No newline at end of file