![](/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:
- 124:c1b6c893e1c3
- Parent:
- 123:1d395b5a4cad
- Child:
- 126:1f90756250fb
diff -r 1d395b5a4cad -r c1b6c893e1c3 prompt.cpp --- a/prompt.cpp Mon May 11 19:21:39 2015 +0000 +++ b/prompt.cpp Wed May 13 14:25:57 2015 +0000 @@ -229,6 +229,16 @@ static unsigned int promptcb_last_port = 0; static char promptcb_last_cmd[ 300 ]; + // removendo espacos em branco no inicio da string + uint16_t shift_blank_spaces = 0; + for ( register uint16_t i = 0; i < DEBUGBUFSIZE; i++ ) + { + if ( debug_buf [ i ] == 0x20 ) shift_blank_spaces++; + + if ( debug_buf [ i ] != 0x20 ) break; + } + debug_buf += shift_blank_spaces; + strcpy( tmp_cmd, debug_buf ); if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "." ) ){ miss_match = false; @@ -443,6 +453,16 @@ } } + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "request_clock" ) ) { + miss_match = false; + request_clock_now = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "hello" ) ) { + miss_match = false; + show_hello_status = true; + } + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "date" ) ) { miss_match = false; send_msg(" %s %s", __DATE__, __TIME__ ); @@ -584,13 +604,28 @@ send_msg(" %d", uptime ); } + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "wake" ) ) { + miss_match = false; + show_wake_all_up_status = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "wake_on" ) ) { + miss_match = false; + send_msg("Function wake_all_up : Enable"); + wake_all = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "wake_off" ) ) { + miss_match = false; + send_msg("Function wake_all_up : Disable"); + wake_all = false; + } + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "sizes" ) ) { miss_match = false; sizes = true; } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ftq" ) ){ miss_match = false; if( debug_uart3 ) pc.printf( "\n\rFTQ ON\n\r" ); @@ -604,19 +639,42 @@ else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ktq" ) ){ miss_match = false; if( debug_uart3 ) pc.printf( "\n\rFTQ!!!\n\r" ); - if( from_eth ){ - snprintf( debug_buf, PROMPT_ETH_BUFFER_SIZE, "FTQ!!!\n\r" ); - debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; - } - flood_bug_pkg = !flood_bug_pkg; + + if( from_eth ){ + snprintf( debug_buf, PROMPT_ETH_BUFFER_SIZE, "FTQ!!!\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + flood_bug_pkg = !flood_bug_pkg; } - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ls" ) ){ + else if ( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ls", 2 ) ) + { miss_match = false; + reverse_list = false; list = true; + + if ( strlen ( debug_buf ) != 2 ) + { + if ( strstr ( ( debug_buf + 2 ), "r" ) ) + { + reverse_list = true; + } + + if ( strstr ( ( debug_buf + 2 ), "l" ) ) + { + list = false; + long_list = true; + } + if ( strstr ( ( debug_buf + 2 ), "t" ) ) + { + long_list = true; + list = false; + show_time = true; + } + } } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "drtp ", 5 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "drtp ", 5 ) ) { if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on", 2 ) ) { miss_match = false; if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rRtp Debug ON\n\r" ); @@ -653,23 +711,6 @@ print_v_call = true; } - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ls -l" ) ){ - miss_match = false; - long_list = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ls -lt" ) ){ - miss_match = false; - long_list = true; - show_time = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ls -tl" ) ){ - miss_match = false; - long_list = true; - show_time = true; - } - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "tt" ) ){ miss_match = false; main_test = !main_test; @@ -708,7 +749,7 @@ else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "deleted" ) ) { miss_match = false; - send_msg("::deleted_sip [%5i]::", deleted_sip ); + send_msg("::deleted_sip [ %5i ]::", deleted_sip ); } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "types" ) ) { @@ -926,6 +967,38 @@ } } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dhello ", 7 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "on", 2 ) ) { + miss_match = false; + if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rHello Debug ON\n\r" ); + if( from_eth ) { + snprintf( debug_buf, PROMPT_ETH_BUFFER_SIZE, "Hello Debug On\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session && !udp_query ) { + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + } else if( udp_query ) { + udp_query_send_msg( debug_buf ); + } + } + debug_hello = true; + } + if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "off",3 )) { + miss_match = false; + if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rHello Debug OFF\n\r" ); + if( from_eth ) { + snprintf( debug_buf, PROMPT_ETH_BUFFER_SIZE, "Hello Debug Off\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session && !udp_query ) { + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + } else if( udp_query ) { + udp_query_send_msg( debug_buf ); + } + } + debug_hello = false; + } + } + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dmissedwdt ", 11 ) ){ if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "on", 2 ) ) { miss_match = false; @@ -1479,7 +1552,38 @@ } } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dshowcpld ", 10 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dtxshow ", 8 ) ) { + if (xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "on", 2 ) ) { + miss_match = false; + if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Show TX Debug ON\n\r" ); + if( from_eth ) { + snprintf( debug_buf, PROMPT_ETH_BUFFER_SIZE, "DCPLD Show TX Debug On\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session && !udp_query ) { + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + } else if( udp_query ) { + udp_query_send_msg( debug_buf ); + } + } + debug_show_tx_cpld = true; + } + if (xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "off",3 ) ) { + miss_match = false; + if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Show TX Debug OFF\n\r" ); + if( from_eth ) { + snprintf( debug_buf, PROMPT_ETH_BUFFER_SIZE, "DCPLD Show TX Debug Off\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session && !udp_query ) { + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + } else if( udp_query ) { + udp_query_send_msg( debug_buf ); + } + } + debug_show_tx_cpld = false; + } + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dshowcpld ", 10 ) ) { if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on", 2 ) ) { miss_match = false; if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Show Debug ON\n\r" ); @@ -1492,7 +1596,8 @@ udp_query_send_msg( debug_buf ); } } - debug_show_cpld = true; + debug_show_tx_cpld = true; + debug_show_rx_cpld = true; } if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 ) ) { miss_match = false; @@ -1506,10 +1611,42 @@ udp_query_send_msg( debug_buf ); } } - debug_show_cpld = false; + debug_show_tx_cpld = false; + debug_show_rx_cpld = false; } } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "drxshow ", 8 ) ) { + if (xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "on", 2 ) ) { + miss_match = false; + if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Show RX Debug ON\n\r" ); + if( from_eth ) { + snprintf( debug_buf, PROMPT_ETH_BUFFER_SIZE, "DCPLD Show RX Debug On\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session && !udp_query ) { + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + } else if( udp_query ) { + udp_query_send_msg( debug_buf ); + } + } + debug_show_rx_cpld = true; + } + if (xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "off",3 ) ) { + miss_match = false; + if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Show RX Debug OFF\n\r" ); + if( from_eth ) { + snprintf( debug_buf, PROMPT_ETH_BUFFER_SIZE, "DCPLD Show RX Debug Off\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session && !udp_query ) { + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + } else if( udp_query ) { + udp_query_send_msg( debug_buf ); + } + } + debug_show_rx_cpld = false; + } + } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dcks_err ", 9 ) ){ if (xmemmatch( (uint8_t*)(debug_buf + 9 ), (uint8_t*) "on", 2 ) ) { @@ -1634,7 +1771,8 @@ } } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dcks ", 5 ) ){ + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dcks ", 5 ) ) + { if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 ) ){ miss_match = false; if( debug_uart3 ) pc.printf( "\n\rCKS Debug ON\n\r" ); @@ -1655,6 +1793,83 @@ } } + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cc ", 3 ) ) + { + miss_match = false; + int ext,port; + char *split, *ref, *cmd; + + ref = debug_buf; + + strcat( debug_buf, "\r" ); + + split = strtok( debug_buf + 3, " " ); + ext = atoi( split ); + + port = ext; + + split += strlen( split ) + 1; + cmd = split; + + promptcb_last_ext = ext; + promptcb_last_port = port; + + strcpy( promptcb_last_cmd, cmd ); + + for ( register int i = strlen( cmd ); i < DEBUGBUFSIZE; i++ ) cmd [ i ] = 0; + + if ( debug_uart3 && !( from_eth ) ) pc.printf("\r\next=%d port=%d cmd=%s", ext, port, cmd ); + + send2callboxes( build_cb_package( ext, port, PROMPT, cmd, id_msg++, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); + + if ( debug_uart3 && !( from_eth ) ) pc.printf("\n\rComando enviado"); + + if( from_eth ) { + char eth_msg[ 512 ]; + snprintf( eth_msg, 512 - 1, "\r\next=%d port=%d cmd=%s\r\nComando enviado\n\r> ", ext, port, cmd ); + if( tcp_session && !udp_query ) { + tcp_client.send_all( eth_msg, strlen( eth_msg ) ); + } else if( udp_query ) { + udp_query_send_msg( eth_msg ); + } + } + + debug_buf = ref; + bufptr = 0; + for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "bc ", 3 ) ) + { + miss_match = false; + + strcat( debug_buf, "\r" ); + + char * cmd = debug_buf + 3; + + for ( register int i = strlen( cmd ); i < DEBUGBUFSIZE; i++ ) cmd [ i ] = 0; + + if ( debug_uart3 && !( from_eth ) ) pc.printf("\r\next=%x port=%x cmd=%s", BROADCAST_EXT, BROADCAST_EXT, cmd ); + + send2callboxes ( build_cb_package( BROADCAST_EXT, BROADCAST_EXT, PROMPT, cmd, id_msg++, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); + + if ( debug_uart3 && !( from_eth ) ) pc.printf("\n\rComando enviado"); + + if( from_eth ) { + char eth_msg[ 512 ]; + snprintf( eth_msg, 512 - 1, "\r\next=%x port=%x cmd=%s\r\nComando enviado\n\r> ", BROADCAST_EXT, BROADCAST_EXT, cmd ); + if( tcp_session && !udp_query ) { + tcp_client.send_all( eth_msg, strlen( eth_msg ) ); + } else if( udp_query ) { + udp_query_send_msg( eth_msg ); + } + } + + bufptr = 0; + for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf [ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcb ", 4 )) { miss_match = false; int ext,port; @@ -1725,34 +1940,56 @@ for ( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf [ i ] = 0; } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "bye ", 4 ) ){ + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "bye ", 4 ) ) + { miss_match = false; int ext,port; - char *split, *ref; - uint8_t write_buffer[ 300 ], data[ 300 ]; - + char * ref; + ref = debug_buf; - - strcat( debug_buf, "\r\r\r\n" ); + + strcat( debug_buf, "\r" ); + + ext = atoi( strtok( debug_buf + 4, " " ) ); + + port = ext; + + promptcb_last_ext = ext; + promptcb_last_port = port; - split = strtok( debug_buf + 4, " " ); - ext = atoi( split ); - port = convert_ext_to_port( ext ); + char msg[] = "bye"; + + if ( debug_uart3 && !( from_eth ) ) pc.printf("\r\nSend BYE to ext=%d port=%d", ext, port ); + + send2callboxes ( build_cb_package( ext, port, CB_BYE, msg, ( id_msg++ & ~BIT7 ), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); - if( debug_uart3 ) pc.printf("\r\next=%d port=%d request bye", ext, port ); - send2callboxes( build_cb_package( ext, port, CB_BYE, (char * )data, 0x20, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); - if( debug_uart3 ) pc.printf("\n\rBye enviado"); - - if( from_eth ){ + if ( debug_uart3 && !( from_eth ) ) pc.printf("\n\rComando enviado"); + + if( from_eth ) { char eth_msg[ 512 ]; - snprintf( eth_msg, 512 - 1, "\r\next=%d port=%d request bye\n\r", ext, port ); + snprintf( eth_msg, 512 - 1, "\r\nSend BYE to ext=%d port=%d\r\nComando enviado\n\r> ", ext, port ); if( tcp_session && !udp_query ) { tcp_client.send_all( eth_msg, strlen( eth_msg ) ); } else if( udp_query ) { udp_query_send_msg( eth_msg ); } } - + + debug_buf = ref; + bufptr = 0; + for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "end_call ", 9 ) ) + { + miss_match = false; + char * ref; + + ref = debug_buf; + + end_call_ext = atoi( strtok( debug_buf + 9, " " ) ); + end_call = true; + debug_buf = ref; bufptr = 0; for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0;