![](/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:
- 114:472502b31a12
- Parent:
- 113:db67ae00550e
- Child:
- 115:a1e1e2e60a2c
--- a/prompt.cpp Thu Apr 16 12:57:13 2015 +0000 +++ b/prompt.cpp Mon Apr 20 14:40:09 2015 +0000 @@ -4,39 +4,582 @@ bool delayed_flood = false; Timer tcp_timer; - bool tcp_alive = false; -bool serial_pc_pending = false; char __debug_buf__[ DEBUGBUFSIZE ]; char * debug_buf = __debug_buf__; char last_cmd[ DEBUGBUFSIZE ]; char tmp_cmd[ DEBUGBUFSIZE ] = "help"; char last_debug_buf[ DEBUGBUFSIZE ] = "help"; -char eth_buffer[ __PROMPT_ETH_BUFFER_SIZE__ ]; -char eth_udp_buffer[ __PROMPT_ETH_BUFFER_SIZE__ ]; -char gp_buff[ DEBUGBUFSIZE ]; -FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext, *fudpport, *ftcpport, *ffwip, *ffwport, *fmax, *fmin, *fshift_port; +FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext, *fudpport, *ftcpport, *ftip, *ftport, *ffwip, *ffwport, *fmax, *fmin; uint8_t bufptr = 0; uint8_t last_bufptr = 0; -void init_prompt_eth() -{ - int udp_bind = udp_client.bind( UDP_PORT_LISTENER ); - udp_client.set_blocking( false, 0 ); - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\n******* Prompt eth UDP Ready [ %d ] *******\r\n", udp_bind ); +int str2uint ( char * s, unsigned int * val ){ + int i = 0; + unsigned int ret = 0; + for (;;) { + if (s[i] < '0') { + *val = ret; + return i; + } + ret *= 10; + ret += s[i] - '0'; + i++; + } +} - int tcp_bind = tcp_server.bind( TCP_PORT_LISTENER ); +// operantion with the system config files +void files( const char type ){ + // show files + if (type == 's' ){ + if( debug_uart3 ) pc.printf("Header IP " ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header IP " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/myip.txt"); + + if( debug_uart3 ) pc.printf("Header ext "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header ext " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/myext.txt"); + + if( debug_uart3 ) pc.printf("Header port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header port " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/mysipport.txt"); + + if( debug_uart3 ) pc.printf("Server IP "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server IP " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/serverip.txt"); + + if( debug_uart3 ) pc.printf("Server ext "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server ext " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/peerext.txt"); + + if( debug_uart3 ) pc.printf("Server port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server port " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + cat("/qspi/serverport.txt"); + + if( debug_uart3 ) pc.printf("Mascara de rede "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Mascara de rede " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + cat("/qspi/mymask.txt"); + + if( debug_uart3 ) pc.printf("Gateway IP "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Gateway IP " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + cat("/qspi/mygateway.txt"); + + if( debug_uart3 ) pc.printf("UDP Port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "UDP Port " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/udpport.txt"); + + if( debug_uart3 ) pc.printf("TCP Port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "TCP Port " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/tcpport.txt"); + + if( debug_uart3 ) pc.printf("Telemetry Server IP "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server IP " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/telemetry_ip.txt"); + + if( debug_uart3 ) pc.printf("Telemetry Server Port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server Port " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/telemetry_port.txt"); + + /* + if( debug_uart3 ) pc.printf("FW Server IP "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW Server IP " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/fw_ip.txt"); + + if( debug_uart3 ) pc.printf("FW Server Port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Fw Server Port " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/fw_port.txt"); + */ + + if( debug_uart3 ) pc.printf("FW Server IP "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW Server IP " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/fw_ip.txt"); + + if( debug_uart3 ) pc.printf("FW Server Port "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW Server Port " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/fw_port.txt"); + + if( debug_uart3 ) pc.printf("Max Ext "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Max Ext " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/maxext.txt"); + + if( debug_uart3 ) pc.printf("Min Ext "); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Min Ext " ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + cat("/qspi/minext.txt"); + + + //*------------ formatando a saida ----------------*// + strcpy( last_cmd, tmp_cmd ); + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + + if( tcp_session ) tcp_client.send_all( "\n\r> " , strlen( "\n\r> " ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, "\n\r> ", strlen( "\n\r> " ) ); + } + } + + if (type == 'c' ){ + // close all files + //debug_msg(""); + if( fip ) fclose( fip ); + if( fmask ) fclose( fmask ); + if( fgate ) fclose( fgate ); + if( fport )fclose( fport ); + if( fsip ) fclose( fsip ); + if( fsport ) fclose( fsport ); + if( fext ) fclose( fext ); + if( fserext ) fclose( fserext ); + if( fudpport ) fclose( fudpport ); + if( ftcpport ) fclose( ftcpport ); + if( fmax ) fclose( fmax ); + if( fmin ) fclose( fmin ); + if( ftip ) fclose( ftip ); + if( ftport ) fclose( ftport ); + if( ffwip ) fclose( ffwip ); + if( ffwport) fclose( ffwport ); + //debug_msg(""); + } + + if (type == 'i' ){ + //debug_msg(""); + // Check if files exist, if not create the files + //fixme criar um bool pra cada file + bool exists = true; + + fip = fopen("/qspi/myip.txt", "r"); + if( fip == NULL){ + set_ip( __MY_IP__ ); + exists = false; + } + //fclose( fip ); + + fserext = fopen("/qspi/myext.txt", "r"); + if( fserext == NULL ){ + set_header_ext( __MY_EXT__ ); + exists = false; + } + //fclose( fserext ); + + fport = fopen("/qspi/mysipport.txt", "r"); + if (fport == NULL){ + set_header_sip_port( __MY_PORT__ ); + exists = false; + } + //fclose( fport ); + + fsip = fopen("/qspi/serverip.txt", "r"); + if (fsip == NULL){ + set_server_ip( __SERVER_IP__ ); + exists = false; + } + //fclose( fsip ); + + fext = fopen("/qspi/peerext.txt", "r"); + if ( fext == NULL ){ + set_server_ext( __PEER_EXT__ ); + exists = false; + } + //fclose( fext ); + + fsport = fopen("/qspi/serverport.txt", "r"); + if (fsport == NULL){ + set_server_port( __SERVER_PORT__ ); + exists = false; + } + //fclose( fsport ); + + fmask = fopen("/qspi/mymask.txt", "r"); + if (fmask == NULL){ + set_mask( __MY_MSK__ ); + exists = false; + } + //fclose( fmask ); + + fgate = fopen("/qspi/mygateway.txt", "r"); + if (fgate == NULL){ + set_gateway( __MY_GTW__ ); + exists = false; + } + //fclose( fgate ); + + fudpport = fopen("/qspi/udpport.txt", "r" ); + if( fudpport == NULL ){ + set_udp_port_listener( UDP_PORT_LISTENER ); + exists = false; + } + //fclose( fudpport ); + + ftcpport = fopen("/qspi/tcpport.txt", "r" ); + if( ftcpport == NULL ){ + set_tcp_port_listener( TCP_PORT_LISTENER ); + exists = false; + } + //fclose( ftcpport ); + + ftip = fopen("/qspi/telemetry_ip.txt", "r" ); + if( ftip == NULL ){ + set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); + exists = false; + } + //fclose( ftip ); + + ftport = fopen("/qspi/telemetry_port.txt", "r" ); + if( ftport == NULL ){ + set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); + exists = false; + } + //fclose( ftport ); + + //debug_msg(""); + ffwip = fopen("/qspi/fw_ip.txt", "r" ); + if( ffwip == NULL ){ + set_fw_ip( __FW_SERVER_IP__ ); + exists = false; + } + //debug_msg(""); + //fclose( ffwip ); + //debug_msg(""); + ffwport = fopen("/qspi/fw_port.txt", "r" ); + if( ffwport == NULL ){ + set_fw_port( __FW_SERVER_PORT__ ); + exists = false; + } + //fclose( ffwport ); + //debug_msg(""); + fmax = fopen("/qspi/maxext.txt", "r" ); + //debug_msg(""); + if( fmax == NULL ){ + //debug_msg(""); + set_max_ext( MAX_EXT ); + //debug_msg(""); + exists = false; + //debug_msg(""); + } + //fclose( fmax ); + //debug_msg(""); + fmin = fopen("/qspi/minext.txt", "r" ); + if( fmin == NULL ){ + set_min_ext( MIN_EXT ); + exists = false; + } + //fclose( fmin ); + //debug_msg(""); + if( !exists ){ + if( debug_uart3 ) pc.printf("\n\rDefault configurations set!\n\r"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Default configurations set!\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session ){ + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + } + } + //debug_msg(""); + reset_leds(); + } + + if (type == 'r' ){ + // Just open for read + fip = fopen("/qspi/myip.txt", "r"); + fmask = fopen("/qspi/mymask.txt", "r"); + fgate = fopen("/qspi/mygateway.txt", "r"); + 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" ); + fudpport = fopen( "/qspi/udpport.txt", "r" ); + ftcpport = fopen( "/qspi/tcpport.txt", "r" ); + ftip = fopen("/qspi/telemetry_ip.txt", "r" ); + ftport = fopen("/qspi/telemetry_port.txt", "r" ); + ffwip = fopen("/qspi/fw_ip.txt", "r" ); + ffwport = fopen("/qspi/fw_port.txt", "r" ); + fmax = fopen("/qspi/maxext.txt", "r" ); + fmin = fopen("/qspi/minext.txt", "r" ); + } + + if( type == 'w'){ + // Create and write the default configs + + set_ip( __MY_IP__ ); + + set_header_sip_port( __MY_PORT__ ); + + set_header_ext( __MY_EXT__ ); + + set_server_ip( __SERVER_IP__ ); + + set_server_ext( __PEER_EXT__ ); + + set_server_port( __SERVER_PORT__ ); + + set_mask( __MY_MSK__ ); + + set_gateway( __MY_GTW__ ); + + set_udp_port_listener( UDP_PORT_LISTENER ); + + set_tcp_port_listener( TCP_PORT_LISTENER ); + + set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); + + set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); + + set_fw_ip( __FW_SERVER_IP__ ); + + set_fw_port( __FW_SERVER_PORT__ ); + + set_max_ext( MAX_EXT ); + + set_min_ext( MIN_EXT ); + + strcpy( last_cmd, tmp_cmd ); + + if( debug_uart3 ) pc.printf("\n\rDefault configurations set!\n\r"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rDefault 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 ) ); + } + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + } + + if (type == 'e'){ + //Erase 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" ); + ftip = fopen("/qspi/telemetry_ip.txt", "w" ); + ftport = fopen("/qspi/telemetry_port.txt", "w" ); + ffwip = fopen("/qspi/fw_ip.txt", "w" ); + ffwport = fopen("/qspi/fw_port.txt", "w" ); + fmax = fopen("/qspi/maxext.txt", "w" ); + fmin = fopen("/qspi/minext.txt", "w" ); + + //FIXME verificar se deveria colocar tudo para %s + fprintf( fip, "%s\n\r", "" ); + fprintf( fport, "%i\n\r", 0 ); + fprintf( fext, "%i\n\r", 0 ); + + fprintf( fsip, "%s\n\r", "" ); + fprintf( fserext, "%i\n\r", 0 ); + fprintf( fsport, "%i\n\r", 0 ); + + fprintf( fmask, "%s\n\r","" ); + fprintf( fgate, "%s\n\r", "" ); + + fprintf( fudpport, "%i\n\r", 0 ); + fprintf( ftcpport, "%i\n\r", 0 ); + + fprintf( ftip, "%s\n\r","" ); + fprintf( ftport, "%i\n\r",0 ); + + fprintf( ffwip, "%s\n\r","" ); + fprintf( ffwport, "%i\n\r",0 ); + + fprintf( fmax, "%i\n\r", 0 ); + fprintf( fmin, "%i\n\r", 0 ); + + files('c'); + + if( debug_uart3 ) 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 ) ); + } + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + } +} + +void init_fsystem(){ + // init file system and check if files exist + if (!qspifs.isformatted()) { + qspifs.format(); + if( debug_uart3 ) pc.printf("\n\rFile system configured!!\n\r"); + } + files('i'); // check if the files are created + files('c'); + send_msg("******* File System Ready *******"); +} + +void init_prompt_eth(){ + tcp_server.bind( TCP_PORT_LISTENER ); + tcp_server.listen(); + //tcp_server.set_blocking( false, 1 ); + //udp_server.set_blocking( false, 2 ); tcp_server.set_blocking( false, 0 ); - int tcp_listen = tcp_server.listen(); - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\n******* Prompt eth TCP Ready [ %d, %d ] *******\r\n", tcp_bind, tcp_listen ); + udp_server.set_blocking( false, 0 ); + udp_server.bind( UDP_PORT_LISTENER ); + if( debug_uart3 ) pc.printf("******* Prompt eth Ready *******\n\r"); } // main prompt process -char * prompt_process( char * msg_from_cb, int length ) -{ +char * prompt_process( char * msg_from_cb ){ //FIXME dar flush na serial volatile char b = 0; static uint8_t bufret = 0; @@ -45,75 +588,62 @@ static uint8_t id_msg = 0x10; static int start_ext, end_ext, ext_count; bool miss_match = true; - uint8_t write_buffer[ CB_BUFFER_SIZE ]; - - if( flood_timeout.read() > 60 ) { + char eth_buffer[ __PROMPT_ETH_BUFFER_SIZE__ ]; + uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; + + if( flood_timeout.read() > 60 ){ pflood = 0; flood_timeout.stop(); flood_timeout.reset(); } - - if( tcp_timer.read() >= TCP_IDLE_MAX_TIME ) { - tcp_alive = false; - tcp_timer.stop(); - tcp_timer.reset(); - tcp_session = false; - debug_buf = __debug_buf__; - bufptr = last_bufptr; + + if( tcp_timer.read() >= TCP_IDLE_MAX_TIME ){ + bool close_tcp = true; + //if( tcp_alive && ( tcp_timer.read() < TCP_ALIVE_IDLE_MAX_TIME ) ){ + // close_tcp = false; + //} + if( close_tcp ){ + tcp_alive = false; + tcp_timer.stop(); + tcp_timer.reset(); + tcp_session = false; + debug_buf = __debug_buf__; + bufptr = last_bufptr; + bufret = 0; + from_eth = false; + tcp_client.close(); + return( NULL ); + } + } + if( !tcp_server.accept( tcp_client ) ){ + tcp_session = true; + tcp_timer.start(); + last_bufptr = bufptr; + eth_buffer[ 0 ] = 0; bufret = 0; - from_eth = false; - tcp_client.close(); - return( NULL ); - } - - if( udp_query ) - { - if( msg_from_cb != NULL ) - { - last_bufptr = bufptr; - if( ( length > 2 ) && ( msg_from_cb[ length - 2 ] == '\r' ) ) msg_from_cb[ length - 2 ] = 0; - - if( ( length > 1 ) && ( msg_from_cb[ length - 1 ] == '\n' ) ) msg_from_cb[ length - 1 ] = 0; + } + if( tcp_session ){ + //if( !( (int)tcp_timer.read_ms() % 100 ) ){ + //tcp_client.set_blocking( false, 1 ); + tcp_client.set_blocking( false, 0 ); + int n = tcp_client.receive( eth_buffer, sizeof( eth_buffer ) - 1 ); + if( n > 0 ){ + tcp_timer.reset(); + + if( ( n > 2 ) && ( eth_buffer[ n - 2 ] == '\r' ) ) eth_buffer[ n - 2 ] = 0; + + if( ( n > 1 ) && ( eth_buffer[ n - 1 ] == '\n' ) ) eth_buffer[ n - 1 ] = 0; + + if( ( n == 1 ) && eth_buffer[ 0 ] == 0x0A ) strcpy( eth_buffer, "\r" ); + + //if( eth_buffer[ 0 ] == '\r' || eth_buffer[ 1 ] == '\n' || eth_buffer[ 2 ] == 'r' || eth_buffer[ 2 ] == '\n' ) strcpy( eth_buffer, "\r" ); - if( ( length == 1 ) && msg_from_cb[ 0 ] == 0x0A ) strcpy( msg_from_cb, "\r" ); - - bufptr = strlen( msg_from_cb ); - debug_buf = msg_from_cb; - from_eth = true; - bufret = 1; - } - } - else - { - if( !tcp_server.accept( tcp_client ) ) - { - tcp_session = true; - tcp_timer.start(); - last_bufptr = bufptr; - for( register int i = 0; i < __PROMPT_ETH_BUFFER_SIZE__; i++ ) eth_buffer[ i ] = 0; - } - if( tcp_session && !udp_query ) - { - tcp_client.set_blocking( false, 0 ); - //for( register int i = 0; i < __PROMPT_ETH_BUFFER_SIZE__; i++ ) eth_buffer[ i ] = 0; - int n = tcp_client.receive( eth_buffer, sizeof( eth_buffer ) - 1 ); - if( n > 0 ) { - tcp_timer.reset(); - - if( ( n > 2 ) && ( eth_buffer[ n - 2 ] == '\r' ) ) eth_buffer[ n - 2 ] = 0; - - if( ( n > 1 ) && ( eth_buffer[ n - 1 ] == '\n' ) ) eth_buffer[ n - 1 ] = 0; - - if( ( n == 1 ) && eth_buffer[ 0 ] == 0x0A ) strcpy( eth_buffer, "\r" ); - bufptr = strlen( eth_buffer ); debug_buf = eth_buffer; from_eth = true; bufret = 1; - - if( !( strcmp( eth_buffer, "quit" ) ) ) - { - tcp_timer.stop(); + + if( !( strcmp( eth_buffer, "quit" ) ) ){ tcp_timer.reset(); debug_buf = __debug_buf__; bufptr = last_bufptr; @@ -123,181 +653,194 @@ bufret = 0; return( NULL ); } - } else { + /*else if( !( strcmp( eth_buffer, "alive" ) ) ){ + char wake_msg[ 8 ]; + external_wdt = EXTERN_WDT_IDLE; + strcpy( wake_msg, "wakeup\n" ); + while( !( tcp_client.send_all( wake_msg, strlen( wake_msg ) ) ) ); + strcpy( eth_buffer, "0" ); + bufret = 0; + } + */ + }else{ debug_buf = __debug_buf__; bufptr = last_bufptr; from_eth = false; } - } + //} } - - if( ( !from_eth ) && ( !udp_query ) ) - { - if( pc.readable() ) { + + if( !from_eth ){ + if( pc.readable() ){ + // imput do teclado b = pc.getc(); - if( b == 0x0D ) { - // enter + if( b == 0x0D ){ // enter bufret = 1; - if( from_eth ) serial_pc_pending = true; - } else { + }else{ pc.putc( b ); - if( b == 0x08 || b == 0x7F ) { - // BS | DEL - if( bufptr > 0 ) { - __debug_buf__[ --bufptr ] = 0; - } - } else if( b == 0x09 ) { + if( b == 0x08 || b == 0x7F ){ // BS | DEL + if( bufptr > 0 ) debug_buf[ --bufptr ] = 0; + }else if( b == 0x09 ){ // ignore tab - } else { - //debug_msg("--%c,%d--%d--", b, bufptr, last_bufptr ); - __debug_buf__[ bufptr ] = b; + }else{ + debug_buf[bufptr] = b; bufptr++; } - last_bufptr = bufptr; } } } - - if( flood_silence ) { - if( flood_silence_timer.read_ms() > 250 ) { + + if( msg_from_cb ){ + if( tcp_session ){ + tcp_client.send_all( msg_from_cb, strlen( msg_from_cb ) ); + }else if( udp_request ){ + udp_server.sendTo( udp_client, msg_from_cb, strlen( msg_from_cb ) ); + } + if( debug_uart3 ) pc.printf( "\n\r%s\n\r", msg_from_cb ); + } + + if( flood_silence ){ + if( flood_silence_timer.read_ms() > 250 ){ char cmd[ 16 ] = "flood off"; int str_end = strlen( cmd ); cmd[ str_end ] = 0x0D; cmd[ str_end + 1 ] = 0x00; - + int port = convert_ext_to_port( ext_count ); - send2callboxes( build_cb_package( ext_count, port, __PROMPT__, cmd, id_msg++, CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nSilence sent to ext=%d port=%d", ext_count, port ); - - if( tcp_session && !udp_query ) { + send2callboxes( __build_cb_package__( ext_count, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + if( debug_uart3 ) pc.printf("\r\nSilence sent to ext=%d port=%d", ext_count, port ); + + if( tcp_session ){ snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\nSilence sent to ext=%d port=%d", ext_count, port ); + //eth_buffer[ strlen( eth_buffer ) - 1 ] = '\0'; + tcp_client.send_all( eth_buffer, strlen( eth_buffer ) ); - } else if( udp_query ) { + }else if( udp_request ){ snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\nSilence sent to ext=%d port=%d", ext_count, port ); - udp_query_send_msg( eth_buffer ); + //eth_buffer[ strlen( eth_buffer ) - 1 ] = '\0'; + + udp_server.sendTo( udp_client, eth_buffer, strlen( eth_buffer ) ); } flood_silence_timer.reset(); - - // importante para o uso da funçao silence - if( ++ext_count > end_ext ) { + + if( ++ext_count > end_ext ){ flood_silence = false; flood_silence_timer.stop(); flood_silence_timer.reset(); - - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\n> " ); - if( tcp_session && !udp_query ) { + + if( debug_uart3 ) pc.printf("\r\n> " ); + if( tcp_session ){ snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\n> " ); tcp_client.send_all( eth_buffer, strlen( eth_buffer ) ); - } else if( udp_query ) { + }else if( udp_request ){ snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\n> " ); - udp_query_send_msg( eth_buffer ); + udp_server.sendTo( udp_client, eth_buffer, strlen( eth_buffer ) ); } } } } - - if( delayed_flood ) { + + if( delayed_flood ){ tflood.start(); tflood.reset(); floodcount =0; pflood = 1; flood_timeout.start(); delayed_flood = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rFlood ON\n\r"); - //FIXME avaliar melhor essa expressao - if( from_eth ) { + if( debug_uart3 ) pc.printf("\n\rFlood ON\n\r"); + if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood On\n\r" ); + //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } } - - if( serial_pc_pending && !from_eth ) { - bufret = 1; - } + // Prompt commands here if ( bufret == 1 ) { - static unsigned int promptcb_last_ext = 0; - static unsigned int promptcb_last_port = 0; + static unsigned int promptcb_last_ext = 0; + static unsigned int promptcb_last_port = 0; static char promptcb_last_cmd[ 300 ]; strcpy( tmp_cmd, debug_buf ); - if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "." ) ) { + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "." ) ){ miss_match = false; strcpy( debug_buf, last_cmd ); strcpy( tmp_cmd, debug_buf ); - } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "+" ) ) { + }else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "+" ) ){ miss_match = false; strcpy( debug_buf, "flood on" ); strcpy( tmp_cmd, debug_buf ); - } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "-" ) ) { + }else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "-" ) ){ miss_match = false; strcpy( debug_buf, "flood off" ); strcpy( tmp_cmd, debug_buf ); - } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "++ ", 3 ) ) { + }else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "++ ", 3 ) ){ miss_match = false; delayed_flood = true; int ext = atoi( debug_buf + 3 ); sprintf( debug_buf, "pcb %i flood on", ext ); - } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "-- ", 3 ) ) { + }else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "-- ", 3 ) ){ miss_match = false; int ext = atoi( debug_buf + 3 ); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rFlood OFF\n\r"); - if( from_eth ) { + if( debug_uart3 ) pc.printf("\n\rFlood OFF\n\r"); + 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(); - sprintf( debug_buf, "pcb %i flood off", ext ); + sprintf( debug_buf, "pcb %i flood off", ext ); } - + //tratamento dos enters - if( !bufptr ) { + if( !bufptr ){ miss_match = false; - } else if( bufptr == 1 ) { + }else if( bufptr == 1 ) { if( debug_buf[ 0 ] == 0x0D || debug_buf[ 0 ] == 0x0D ) miss_match = false; } - - if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ifconfig" ) ) { + + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ifconfig" ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\r"); + if( debug_uart3 ) pc.printf("\n\r"); files('s'); - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; - bufptr = 0; } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "rx" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "rx" ) ){ miss_match = false; rx = true; } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "tx" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "tx" ) ){ miss_match = false; tx = true; } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "stats" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "stats" ) ){ miss_match = false; stats = true; - } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset_stats" ) ) { + } + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset_stats" ) ){ miss_match = false; r_stats = true; } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "rtp" ) ) { + miss_match = false; + dshow_rtp = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "callrtp" ) ) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rFormatando o sistema de arquivos... espere o sistema reiniciar\n\r"); - - if( from_eth ) - { - char msg[ 32 ]; - snprintf( msg, 32, "Not Allowed\n\r"); - - if( tcp_session && !udp_query ) { - tcp_client.send_all( msg, strlen( msg ) ); - } else if( udp_query ) { - udp_query_send_msg( msg ); - } - } else { + dcallshow_rtp = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" ) ){ + miss_match = false; + if( debug_uart3 ) pc.printf("\n\rFormatando o sistema de arquivos... espere o sistema reiniciar\n\r"); + + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Not Allowed\n\r"); + }else{ files('e'); files('w'); __disable_irq(); @@ -311,170 +854,120 @@ files('s'); } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "prompt_tcp_port ", 16 )) { - miss_match = false; - set_tcp_port_listener( atoi( debug_buf + 16 ) ); - files('s'); - } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "prompt_udp_port ", 16 )) { - miss_match = false; - set_udp_port_listener( atoi( debug_buf + 16 ) ); - files('s'); - } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "extset ", 7 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "extset ", 7 ) ){ miss_match = false; set_header_ext( atoi( debug_buf + 7 ) ); files('s'); } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serextset ", 10 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serextset ", 10 ) ){ miss_match = false; set_server_ext( atoi( debug_buf + 10 ) ); files('s'); } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 ) ){ miss_match = false; set_mask( debug_buf + 8 ); files('s'); } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 ) ){ miss_match = false; set_gateway( debug_buf + 11 ); files('s'); } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 ) ){ miss_match = false; set_header_sip_port( atoi( debug_buf + 9 ) ); files('s'); } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 ) ){ miss_match = false; set_server_ip( debug_buf + 9 ); files('s'); } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maxext ", 7 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maxext ", 7 ) ){ miss_match = false; set_max_ext( atoi( debug_buf + 7 ) ); files('s'); } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "minext ", 7 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "minext ", 7 ) ){ miss_match = false; set_min_ext( atoi( debug_buf + 7 ) ); files('s'); } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ", 7 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ", 7 ) ){ miss_match = false; set_server_port( atoi( debug_buf + 7 ) ); files('s'); } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "fw_ip ", 6 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "telemetry_ip ", 13 ) ){ + miss_match = false; + set_telemetry_ip( debug_buf + 13 ); + files('s'); + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "telemetry_port ", 15 ) ){ + miss_match = false; + set_telemetry_port( atoi( debug_buf + 15 ) ); + files('s'); + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "fw_ip ", 6 ) ){ miss_match = false; set_fw_ip( debug_buf + 6 ); files('s'); } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "fw_port ", 8 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "fw_port ", 8 ) ){ miss_match = false; set_fw_port( atoi( debug_buf + 8 ) ); files('s'); } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "shift_port ", 11 ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" ) ){ miss_match = false; - set_shift_port( atoi( debug_buf + 11 ) ); - files('s'); - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" ) ) { - miss_match = false; + /* files('e'); files('w'); files('s'); + */ } - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" ) ) { + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rJob is done\n\r"); - if( from_eth ) { + if( debug_uart3 ) pc.printf("\n\rJob is done\n\r"); + if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Job is done\n\r"); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; - if( tcp_session && !udp_query ) { + if( tcp_session ){ tcp_client.send_all( debug_buf, strlen( debug_buf ) ); tcp_client.close(); - } else if( udp_query ) { - udp_query_send_msg( debug_buf ); + }else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } __disable_irq(); NVIC_SystemReset(); } - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" ) ) { + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); - if( from_eth ) { + if( debug_uart3 ) pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); + if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "MUUUUUUUuuuuUUUUUU - I'm not a dog!!!!\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_buf[ strlen( debug_buf ) - 1 ] = '\0'; } } - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "date" ) ) { - miss_match = false; - send_msg(" %s %s", __DATE__, __TIME__ ); - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "rtp" ) ) { - miss_match = false; - dshow_rtp = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "callrtp" ) ) { - miss_match = false; - dcallshow_rtp = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "test" ) ) { - miss_match = false; - debug_msg("Test something"); - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "uptime" ) ) { - miss_match = false; - send_msg(" %d", uptime ); - } - - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "deleted" ) ) { - miss_match = false; - send_msg("::%d::", deleted_sip ); - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "missed" ) ) { - miss_match = false; - missed_send_udp_pkg = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset_missed" ) ) { - miss_match = false; - reset_missed_send_udp_pkg = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dep" ) ){ + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dep" ) ){ miss_match = false; drop_entendi_pkg = !drop_entendi_pkg; if ( drop_entendi_pkg ) @@ -524,6 +1017,7 @@ { debug_msg ("invite pkgs from cbx don't will be droped"); } + } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dap" ) ){ @@ -536,7 +1030,8 @@ else { debug_msg ("ack pkgs don't will be droped"); - } + } + } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "drfa" ) ){ @@ -551,7 +1046,8 @@ debug_msg ("rtp pkgs from ast don't will be droped"); } - } + } + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "drfc" ) ){ miss_match = false; @@ -566,77 +1062,57 @@ } } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ftq" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ftq" ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rFTQ ON\n\r" ); - send_msg("FTQ On"); - /* - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FTQ On\n\r" ); - debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; - } - */ - big_bug_pkg = true; + if( debug_uart3 ) pc.printf( "\n\rFTQ ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FTQ On\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + big_bug_pkg = true; } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ktq" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ktq" ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rFTQ!!!\n\r" ); - send_msg("FTQ"); - /* - 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( 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; } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ls" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ls" ) ){ miss_match = false; list = 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*) "tt" ) ) { - miss_match = false; - main_test = !main_test; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "size" ) ) { - miss_match = false; - sizes = !sizes; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "show_sip" ) ) { - miss_match = false; - show_sip = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset_cks" ) ) { - miss_match = false; - reset_cks = true; - } - - //replaced by ls - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "status" ) ) { - miss_match = false; - list = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "wdt" ) ) { - miss_match = false; - debug_wdt = true; - } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "eth" ) ) { - miss_match = false; - debug_eth = true; + + 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" ); + if( from_eth ) { + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Rtp Debug On\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session ) { + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + } + } + debug_rtp = true; + } + if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "off", 3 ) ){ + miss_match = false; + if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rRtp Debug OFF\n\r" ); + if( from_eth ) { + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Rtp Debug Off\n\r"); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + if( tcp_session ) { + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); + } + } + debug_rtp = false; + } } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "deleted" ) ) { @@ -704,1083 +1180,968 @@ miss_match = false; chicago = !chicago; } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "types" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "show_sip" ) ){ + miss_match = false; + show_sip = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset_cks" ) ){ + miss_match = false; + reset_cks = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "malasia" ) ){ + miss_match = false; + malasia = !malasia; + } + + //replaced by ls + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "status" ) ){ miss_match = false; - - //send_msg("hex :: dec :: Type \n\r0x00 :: 0 :: boot \n\r0x02 :: 2 :: registry \n\r0x04 :: 4 :: invite \n\r0x08 :: 8 :: audio \n\r0x10 :: 16 :: telemetry \n\r0x20 :: 32 :: cb_bye \n\r0x01 :: 1 :: prompt \n\r0x40 :: 64 :: flood" ); - - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rhex :: dec :: Type \n\r0x00 :: 0 :: boot \n\r0x02 :: 2 :: registry \n\r0x04 :: 4 :: invite \n\r0x08 :: 8 :: audio \n\r0x10 :: 16 :: telemetry \n\r0x20 :: 32 :: cb_bye \n\r0x01 :: 1 :: prompt \n\r0x40 :: 64 :: flood \n\r" ); - - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "hex :: dec :: Type \n\r0x00 :: 0 :: boot \n\r0x02 :: 2 :: registry \n\r0x04 :: 4 :: invite \n\r0x08 :: 8 :: audio \n\r0x10 :: 16 :: telemetry \n\r0x20 :: 32 :: cb_bye \n\r0x01 :: 1 :: prompt \n\r0x40 :: 64 :: flood\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 ); - } + list = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "wdt" ) ){ + miss_match = false; + debug_wdt = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "eth" ) ){ + miss_match = false; + debug_eth = true; + } + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "types" ) ){ + miss_match = false; + + if( debug_uart3 ) pc.printf( "\n\rhex :: dec :: Type \n\r0x00 :: 0 :: boot \n\r0x02 :: 2 :: registry \n\r0x04 :: 4 :: invite \n\r0x08 :: 8 :: audio \n\r0x10 :: 16 :: telemetry \n\r0x20 :: 32 :: cb_bye \n\r0x01 :: 1 :: prompt \n\r0x40 :: 64 :: flood \n\r" ); + + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rhex :: dec :: Type \n\r0x00 :: 0 :: boot \n\r0x02 :: 2 :: registry \n\r0x04 :: 4 :: invite \n\r0x08 :: 8 :: audio \n\r0x10 :: 16 :: telemetry \n\r0x20 :: 32 :: cb_bye \n\r0x01 :: 1 :: prompt \n\r0x40 :: 64 :: flood \n\r" ); + //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } } - - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "protocol" ) ) { + + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "protocol" ) ){ miss_match = false; - - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\r| E | E | P | P | C | C | T | [ Seq_num | Audio ] | 14[ Clock | Audio ] | [ TS | Audio ] | ... |\n\r \n\rE = Ext = Ramal\n\r \n\rP = Port = Porta\n\r \n\rC = Checksum\n\r \n\rT = Type = Tipo\n\r \n\rSeq_num = Sequence Number = Numero de sequencia\n\r \n\rClock = 14 bytes to sync\n\r \n\r... = demais CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__ bytes\n\r" ); - - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "| E | E | P | P | C | C | T | [ Seq_num | Audio ] | 14[ Clock | Audio ] | [ TS | Audio ] | ... |\n\r \n\rE = Ext = Ramal\n\r \n\rP = Port = Porta\n\r \n\rC = Checksum\n\r \n\rT = Type = Tipo\n\r \n\rSeq_num = Sequence Number = Numero de sequencia\n\r \n\rClock = 14 bytes to sync\n\r \n\r... = demais CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__ bytes\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 ); - } + + if( debug_uart3 ) pc.printf( "\n\r| E | E | P | P | C | C | T | [ Seq_num | Audio ] | 14[ Clock | Audio ] | [ TS | Audio ] | ... |\n\r \n\rE = Ext = Ramal\n\r \n\rP = Port = Porta\n\r \n\rC = Checksum\n\r \n\rT = Type = Tipo\n\r \n\rSeq_num = Sequence Number = Numero de sequencia\n\r \n\rClock = 14 bytes to sync\n\r \n\r... = demais __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__ bytes\n\r" ); + + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\r| E | E | P | P | C | C | T | [ Seq_num | Audio ] | 14[ Clock | Audio ] | [ TS | Audio ] | ... |\n\r \n\rE = Ext = Ramal\n\r \n\rP = Port = Porta\n\r \n\rC = Checksum\n\r \n\rT = Type = Tipo\n\r \n\rSeq_num = Sequence Number = Numero de sequencia\n\r \n\rClock = 14 bytes to sync\n\r \n\r... = demais __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__ bytes\n\r" ); + //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ", 6 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ", 6 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rFlood ON\n\r"); - - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood On\n\r"); + if( debug_uart3 ) pc.printf("\n\rFlood ON\n\r"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood 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 ); - } - } + } tflood.start(); tflood.reset(); floodcount =0; pflood = 1; flood_timeout.start(); } - - if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "more", 4 ) ) { + + if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "more", 4 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rFlood ON\n\r"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood 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 ); - } + if( debug_uart3 ) pc.printf("\n\rFlood ON\n\r"); + 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; } - + if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off", 3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rFlood OFF\n\r"); - - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood Off\n\r"); + if( debug_uart3 ) pc.printf("\n\rFlood OFF\n\r"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Flood 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 ); - } } pflood = 0; tflood.stop(); flood_timeout.reset(); } - } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "silence ", 8 ) ) { + }else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "silence ", 8 ) ){ miss_match = false; char *ref, *split; - + strcpy( promptcb_last_cmd, debug_buf ); - - if( !( strcmp( debug_buf + 8, "-h" ) && strcmp( debug_buf + 8, "--help" ) ) ) { - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rUsage :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 "); - - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Usage :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 "); - 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 ); - } + + if( !( strcmp( debug_buf + 8, "-h" ) && strcmp( debug_buf + 8, "--help" ) ) ){ + if( debug_uart3 ) pc.printf("\n\rUsage :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 "); + + if( tcp_session ){ + snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "Usage :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 " ); } - } else { + }else{ ref = debug_buf; - + split = strtok( debug_buf + 8, " " ); - + start_ext = atoi( split ); - + split += strlen( split ) + 1; - + end_ext = atoi( split ); - + debug_buf = ref; - - if( start_ext < end_ext && ( end_ext - start_ext ) < 50 ) { + + if( start_ext < end_ext && ( end_ext - start_ext ) < 50 ){ if( start_ext % 2 ) start_ext--; if( !( end_ext % 2 ) ) end_ext++; - + ext_count = start_ext; flood_silence_timer.start(); - } else { - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rUsage Error :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 "); - - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Usage Error :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 "); - 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 ); - } + }else{ + if( debug_uart3 ) pc.printf("\n\rUsage Error :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 "); + + if( tcp_session ){ + snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "Usage Error :: silence start_ext end_ext | start_ext must be greater than end_ext\n\rObs : ( end_ext - start_ext ) < 50 " ); } } flood_silence = true; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 ) ){ if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDebug ON\n\r"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug On\n\r"); + if( debug_uart3 ) pc.printf("\n\rDebug ON\n\r"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "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_alive = true; } if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDebug OFF\n\r"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Off\n\r"); + if( debug_uart3 ) pc.printf("\n\rDebug OFF\n\r"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "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_alive = false; } - if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 ) ) { + if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdsip"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_alive"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_prompt"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_vector"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_cb"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_main"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdcks"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_cb_rx"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_cb_tx*"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_eth_rx*"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_eth_tx*"); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rdebug_file"); + if( debug_uart3 ) pc.printf("\n\rdsip"); + if( debug_uart3 ) pc.printf("\n\rdebug_alive"); + if( debug_uart3 ) pc.printf("\n\rdebug_prompt"); + if( debug_uart3 ) pc.printf("\n\rdebug_vector"); + if( debug_uart3 ) pc.printf("\n\rdebug_cb"); + if( debug_uart3 ) pc.printf("\n\rdebug_main"); + if( debug_uart3 ) pc.printf("\n\rdcks"); + if( debug_uart3 ) pc.printf("\n\rdebug_cb_rx"); + if( debug_uart3 ) pc.printf("\n\rdebug_cb_tx*"); + if( debug_uart3 ) pc.printf("\n\rdebug_eth_rx*"); + if( debug_uart3 ) pc.printf("\n\rdebug_eth_tx*"); + if( debug_uart3 ) pc.printf("\n\rdebug_file"); - if( from_eth ) { - 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\rdcks \n\rdebug_cb_rx \n\rdebug_cb_tx* \n\rdebug_eth_rx* \n\rdebug_eth_tx* \n\rdebug_file\n\r"); + if( from_eth ){ + 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\rdcks \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( tcp_session && !udp_query ) { - tcp_client.send_all( debug_buf, strlen( debug_buf ) ); - } else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } } } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dsip ", 5 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dsip ", 5 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rSip Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug On\n\r"); + if( debug_uart3 ) 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'; - 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_sip = true; } if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rSip Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug Off\n\r"); + if( debug_uart3 ) 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'; - 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_sip = false; } } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dresetrtp ", 10 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on", 2 ) ) { - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rReset RTP Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Reset RTP 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_reset_rtp = true; - } - if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) { - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rReset RTP Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Reset RTP 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_reset_rtp = false; - } - } - - - 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" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Rtp 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_rtp = true; - } - if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "off", 3 ) ){ - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rRtp Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Rtp 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_rtp = false; - } - } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dmissed ", 8 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "on", 2 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "duart ", 6 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDebug Missed ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Missed 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_missed = true; - } - if (xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "off", 3 )) { - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDebug Missed Off\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Missed 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_missed = false; - } - } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dreconnect ", 11 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "on", 2 ) ) { - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rReconnecet Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Reconnecet Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rEnable UART3 usage\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Dinable UART3 usage\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_reconnect = true; - } - if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "off", 3 )) { - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rReconnecet Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Reconnecet 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_reconnect = false; - } - } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "duart ", 6 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "on", 2 ) ) { - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rEnable UART3 usage\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Enable UART3 usage\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_uart3 = true; } if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDisable UART3 usage\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Disable UART3 usage\n\r"); + if( debug_uart3 ) pc.printf( "\n\rEnable UART3 usage\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Dinable UART3 usage\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_uart3 = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dmatch ", 7 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dprint ", 7 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "on", 2 ) ){ + miss_match = false; + if( debug_uart3 ) pc.printf( "\n\rDebug print On\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug print On\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + print_values = true; + } + if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rPort Match Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Port Match Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rDebug print Off\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug print 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 ); - } + } + print_values = false; + } + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dmatch ", 7 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "on", 2 ) ){ + miss_match = false; + if( debug_uart3 ) pc.printf( "\n\rPort Match Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Port Match Debug On\n\r" ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_port_match = true; } if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rPort Match Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Port Match Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rPort Match Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Port Match 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_port_match = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dmuted ", 7 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dmuted ", 7 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rMuted Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Muted Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rMuted Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Muted 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_muted = true; } if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rMuted Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Muted Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rMuted Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Muted 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_muted = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dwdt ", 5 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dwdt ", 5 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rWdt Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Wdt Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rWdt Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Wdt 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 ); - } } wdt_show = true; } if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rWdt Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Wdt Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rWdt Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Wdt 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 ); - } } wdt_show = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "drefresh ", 9 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 9 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "drefresh ", 9 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 9 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rRefresh Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Refresh Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rRefresh Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Refresh 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_refresh= true; } if (xmemmatch( (uint8_t*)(debug_buf + 9 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rRefresh Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Refresh Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rRefresh Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Refresh 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_refresh = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dping ", 6 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dping ", 6 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rPing Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Ping Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rPing Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Ping 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_ping = true; } if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rPing Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Ping Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rPing Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Ping 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_ping= false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dwu ", 4 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 4 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dwu ", 4 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 4 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rWake Up Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Wake Up Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rWake Up Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Wake Up 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_wake = true; } if (xmemmatch( (uint8_t*)(debug_buf + 4 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rWake Up Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Wake Up Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rWake Up Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Wake Up 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_wake = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "tcp_alive ", 10 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "tcp_alive ", 10 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rTCP don't drop mode on\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "TCP don't drop mode on\n\r"); + if( debug_uart3 ) pc.printf( "\n\rTCP don't drop mode on\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "TCP don't drop mode 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 ); - } } tcp_alive = true; } if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rTCP don't drop mode off\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "TCP don't drop mode off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rTCP don't drop mode off\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "TCP don't drop mode 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 ); - } } tcp_alive = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "daging ",7 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "daging ",7 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rAging Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Aging Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rAging Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Aging 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_aging = true; } if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rAging Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Aging Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rAging Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Aging 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_aging = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dcpld ", 6 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dcpld ", 6 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "DCPLD Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rDCPLD Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "DCPLD 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_cpld = true; - debug_cb_rx = true; - debug_cb_tx = true; } - if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "off",3 ) ) { + if (xmemmatch( (uint8_t*)(debug_buf + 6 ), (uint8_t*) "off",3 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "DCPLD Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rDCPLD Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "DCPLD 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_cpld = false; - debug_cb_rx = false; - debug_cb_tx = false; } } - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dshowcpld ", 10 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "on", 2 ) ) { + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dcks_err ", 9 ) ){ + if (xmemmatch( (uint8_t*)(debug_buf + 9 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Show Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "DCPLD Show 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_cpld = true; - } - if (xmemmatch( (uint8_t*)(debug_buf + 10 ), (uint8_t*) "off",3 ) ) { - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rDCPLD Show Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "DCPLD Show Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rCKS_ERR Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS_ERR 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_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 ) ) { - miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rCKS_ERR Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS_ERR 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_cks_err = true; } - if (xmemmatch( (uint8_t*)(debug_buf + 9 ), (uint8_t*) "off", 3 ) ) { + if (xmemmatch( (uint8_t*)(debug_buf + 9 ), (uint8_t*) "off", 3 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rCKS_ERR Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS_ERR Debug off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rCKS_ERR Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS_ERR 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_cks_err = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dinvite ", 8 ) ) { - if( xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dinvite ", 8 ) ){ + if( xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rInvite Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Invite Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rInvite Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Invite 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_invite = true; } if( xmemmatch( (uint8_t*)(debug_buf + 8 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rInvite Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Invite Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rInvite Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Invite 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_invite = 0; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dparallel ", 10 ) ) { - if( xmemmatch( ( uint8_t * )( debug_buf + 10 ), ( uint8_t * )"on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dparallel ", 10 ) ){ + if( xmemmatch( ( uint8_t * )( debug_buf + 10 ), ( uint8_t * )"on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rParallel Write Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rParallel Write Debug ON\n\r"); + if( debug_uart3 ) pc.printf( "\n\rParallel Write Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rParallel Write 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 ); - } } dparallel = true; } if( xmemmatch( ( uint8_t * )( debug_buf + 10 ), ( uint8_t *)"off", 3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rParallel Write Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rParallel Write Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rParallel Write Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rParallel Write 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 ); - } } dparallel = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dtelos ", 7 ) ) { - if (xmemmatch( (uint8_t*)( debug_buf + 7 ), (uint8_t*) "on", 2 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dtelos ", 7 ) ){ + if (xmemmatch( (uint8_t*)( debug_buf + 7 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rTelemetry Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTelemetry Debug On\n\r"); + if( debug_uart3 ) pc.printf( "\n\rTelemetry Debug ON\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\rTelemetry 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_telemetry = true; } if (xmemmatch( (uint8_t*)(debug_buf + 7 ), (uint8_t*) "off", 3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rTelemetry Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTelemetry Debug Off\n\r"); + if( debug_uart3 ) pc.printf( "\n\rTelemetry Debug OFF\n\r" ); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\rTelemetry 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_telemetry = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dcks ", 5 ) ) { - if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 ) ) { + + 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 && !( from_eth ) ) pc.printf( "\n\rCKS Debug ON\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug On\n\r"); + if( debug_uart3 ) 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'; - 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_cks = true; } if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf( "\n\rCKS Debug OFF\n\r" ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug Off\n\r"); + if( debug_uart3 ) 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'; - 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_cks = false; } } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9 ) ) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9 ) ){ miss_match = false; - uint8_t write_buffer[ CB_BUFFER_SIZE ]; + //static uint8_t id_msg = 0x10; + uint8_t write_buffer[ 300 ]; int ext,port; char *split, *ref, *cmd; - + ref = debug_buf; - + strcat( debug_buf, "\r" ); - + split = strtok( debug_buf + 9, " " ); ext = atoi( split ); split = strtok( NULL, " " ); port = atoi( split ); split += strlen( split ) + 1; cmd = split; - + promptcb_last_ext = ext; promptcb_last_port = port; - + strcpy( promptcb_last_cmd, cmd ); strcat( cmd, "\r\r\r\n" ); - - 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 ) { + + if( debug_uart3 ) 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 ) 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 ) { + if( tcp_session ){ tcp_client.send_all( eth_msg, strlen( eth_msg ) ); - } else if( udp_query ) { - udp_query_send_msg( eth_msg ); + }else if( udp_request ){ + udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); } } - + debug_buf = ref; bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + for( uint8_t 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[ CB_BUFFER_SIZE ], data[ CB_BUFFER_SIZE ]; - + uint8_t write_buffer[ 300 ], data[ 300 ]; + ref = debug_buf; - + strcat( debug_buf, "\r\r\r\n" ); - + split = strtok( debug_buf + 4, " " ); ext = atoi( split ); port = convert_ext_to_port( ext ); - - if( debug_uart3 && !( from_eth ) ) 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 && !( from_eth ) ) pc.printf("\n\rBye enviado"); - - if( from_eth ) { + + 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 ){ char eth_msg[ 512 ]; snprintf( eth_msg, 512 - 1, "\r\next=%d port=%d request bye\n\r", ext, port ); - if( tcp_session && !udp_query ) { + if( tcp_session ){ tcp_client.send_all( eth_msg, strlen( eth_msg ) ); - } else if( udp_query ) { - udp_query_send_msg( eth_msg ); + }else if( udp_request ){ + udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); } } - + debug_buf = ref; bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } - + //promptcb ramal porta comando //FIXME colocar a parte eth de novo else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcb ", 4 )) { miss_match = false; int ext,port; char *split, *ref, *cmd; - + ref = debug_buf; - + strcat( debug_buf, "\r" ); - + split = strtok( debug_buf + 4, " " ); ext = atoi( split ); - + port = convert_ext_to_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 ) { + strcat( cmd, "\r\r\r\n" ); + + //send_msg( "Tamanho do cmd == %d", strlen( cmd ) ); + + //for( register uint16_t i = strlen( cmd ); i < __CB_BUFFER_SIZE__; i++ ) cmd[ i ] = 0; + + if( debug_uart3 ) 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 ) 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 ) { + if( tcp_session ){ tcp_client.send_all( eth_msg, strlen( eth_msg ) ); - } else if( udp_query ) { - udp_query_send_msg( eth_msg ); + }else if( udp_request ){ + udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); } } - + debug_buf = ref; + //bufptr = 0; + //debug_buf[ 0 ] = 0; bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } - + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "pcc ", 4 )) { miss_match = false; int ext,port; char *split, *ref, *cmd; - + ref = debug_buf; - + strcat( debug_buf, "\r" ); - + split = strtok( debug_buf + 4, " " ); ext = atoi( split ); - + split += strlen( split ) + 1; split = strtok( NULL, " " ); port = atoi( split ); - + 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 ) { + strcat( cmd, "\r\r\r\n" ); + + if( debug_uart3 ) 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 ) 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 ) { + if( tcp_session ){ tcp_client.send_all( eth_msg, strlen( eth_msg ) ); - } else if( udp_query ) { - udp_query_send_msg( eth_msg ); + }else if( udp_request ){ + udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); } } - + debug_buf = ref; bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "print_cb ", 9 )) { + miss_match = false; + char *split; + + split = strtok( debug_buf + 9, " " ); + if( 0 == ( strcasecmp( split, "all" ) ) ) + { + print_cb_all = true; + } + else + { + print_cb_var = true; + print_this_cb = atoi( split ); + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "frtp ", 5 )) { + miss_match = false; + char *split; + + split = strtok( debug_buf + 5, " " ); + frtp = true; + frtp_target = atoi( split ); + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "rrtp ", 5 )) { + miss_match = false; + char *split; + + split = strtok( debug_buf + 5, " " ); + rescue_rtp = true; + rescue_rtp_target = atoi( split ); + + split += strlen( split ) + 1; + split = strtok( NULL, " " ); + rescue_rtp_value = atoi( split ); + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "print_hex_cb ", 13 )) { + miss_match = false; + char *split; + + split = strtok( debug_buf + 13, " " ); + if( 0 == ( strcasecmp( split, "all" ) ) ) + { + print_hex_cb_all = true; + } + else + { + print_hex_cb_var = true; + print_hex_this_cb = atoi( split ); + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "print_sip ", 10 )) { + miss_match = false; + char *split; + + split = strtok( debug_buf + 10, " " ); + if( 0 == ( strcasecmp( split, "all" ) ) ) + { + print_sip_all = true; + } + else + { + print_sip_var = true; + print_this_sip = atoi( split ); + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } - + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "print_hex_sip ", 14 )) { + miss_match = false; + char *split; + + split = strtok( debug_buf + 14, " " ); + if( 0 == ( strcasecmp( split, "all" ) ) ) + { + print_hex_sip_all = true; + } + else + { + print_hex_sip_var = true; + print_hex_this_sip = atoi( split ); + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "print_call ", 11 ) ) + { + miss_match = false; + char *split; + + split = strtok( debug_buf + 11, " " ); + if( 0 == ( strcasecmp( split, "all" ) ) ) + { + print_call_all = true; + } + else + { + print_call_var = true; + print_this_call = atoi( split ); + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "print_hex_call ", 15 ) ) + { + miss_match = false; + char *split; + + split = strtok( debug_buf + 15, " " ); + if( 0 == ( strcasecmp( split, "all" ) ) ) + { + print_hex_call_all = true; + } + else + { + print_hex_call_var = true; + print_hex_this_call = atoi( split ); + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "print_rtp ", 10 ) ) + { + miss_match = false; + char *split; + + split = strtok( debug_buf + 10, " " ); + if( 0 == ( strcasecmp( split, "all" ) ) ) + { + print_rtp_all = true; + } + else + { + print_rtp_var = true; + print_this_rtp = atoi( split ); + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "print_hex_rtp ", 14 ) ) + { + miss_match = false; + char *split; + + split = strtok( debug_buf + 14, " " ); + if( 0 == ( strcasecmp( split, "all" ) ) ) + { + print_hex_rtp_all = true; + } + else + { + print_hex_rtp_var = true; + print_hex_this_rtp = atoi( split ); + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "log ", 4 )) { + miss_match = false; + + char * split = strtok( debug_buf + 4, " " ); + + { + print_cb_var = true; + print_this_cb = atoi( split ); + print_sip_var = true; + print_this_sip = print_this_cb; + print_call_var = true; + print_this_call = print_this_cb; + print_rtp_var = true; + print_this_rtp = print_this_cb; + } + + bufptr = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "rush ", 5 )) { miss_match = false; int ext,port; char *split, *ref, cmd[ 32 ]; - + ref = debug_buf; - + strcat( debug_buf, "\r" ); - + split = strtok( debug_buf + 5, " " ); ext = atoi( split ); - + split += strlen( split ) + 1; split = strtok( NULL, " " ); port = atoi( split ); - + strcpy( cmd, "ping\r\n" ); - + promptcb_last_ext = ext; promptcb_last_port = port; - + strcpy( promptcb_last_cmd, cmd ); strcat( cmd, "\r\r\r\n" ); - - for( register uint8_t i = 0; i < 3; i++ ) { - 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 ) { + + for( register uint8_t i = 0; i < 3; i++ ){ + if( debug_uart3 ) 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 ) 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 ) { + if( tcp_session ){ tcp_client.send_all( eth_msg, strlen( eth_msg ) ); - } else if( udp_query ) { - udp_query_send_msg( eth_msg ); + }else if( udp_request ){ + udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); } } } - + debug_buf = ref; bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } - - - + + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "_pcb",4 )) { miss_match = false; debug_buf[ bufptr++ ] = 0x0D; debug_buf[ bufptr++ ] = 0x00; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf + 4 ); - send2callboxes( build_cb_package( promptcb_last_ext, promptcb_last_port, __PROMPT__, debug_buf + 4, id_msg++, CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rComando enviado\n\r"); + if( debug_uart3 ) pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf + 4 ); + send2callboxes( __build_cb_package__( promptcb_last_ext, promptcb_last_port, __PROMPT__, debug_buf + 4, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + if( debug_uart3 ) pc.printf("\n\rComando enviado\n\r"); } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) { @@ -1792,1200 +2153,613 @@ miss_match = false; pshowcb = true; } - + else 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; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nDebug Main ON"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main On\n\r"); + if( debug_uart3 ) 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'; - 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_main = true; } if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off", 3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nDebug Main OFF"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main Off\n\r"); + if( debug_uart3 ) 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'; - 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_main = 0; } } - - else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dout ", 5 ) ) { - if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "on", 2 ) ) { + + else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dout ", 5 ) ){ + if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nOut Debug ON"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Out Debug On\n\r"); + if( debug_uart3 ) pc.printf("\r\nOut Debug ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Out 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_out_of_range = true; } - if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "off", 3 ) ) { + if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "off", 3 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nOut Debug OFF"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Out Debug Off\n\r"); + if( debug_uart3 ) pc.printf("\r\nOut Debug OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Out 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_out_of_range = false; } } - - else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dboot ", 6 ) ) { - if (xmemmatch( (uint8_t*)( debug_buf + 6 ), (uint8_t*) "on", 2 ) ) { + + else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dboot ", 6 ) ){ + if (xmemmatch( (uint8_t*)( debug_buf + 6 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nBoot Debug ON"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Boot Debug On\n\r"); + if( debug_uart3 ) pc.printf("\r\nBoot Debug ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Boot 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_boot = true; } - if (xmemmatch( (uint8_t*)( debug_buf + 6 ), (uint8_t*) "off", 3 ) ) { + if (xmemmatch( (uint8_t*)( debug_buf + 6 ), (uint8_t*) "off", 3 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nBoot Debug OFF"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Boot Debug Off\n\r"); + if( debug_uart3 ) pc.printf("\r\nBoot Debug OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Boot 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_boot = false; } } - - else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dfw ", 4 ) ) { - if (xmemmatch( (uint8_t*)( debug_buf + 4 ), (uint8_t*) "on", 2 ) ) { + + else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dfw ", 4 ) ){ + if (xmemmatch( (uint8_t*)( debug_buf + 4 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nFW Debug ON"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW Debug On\n\r"); + if( debug_uart3 ) pc.printf("\r\nFW Debug ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW 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_fw = true; } - if (xmemmatch( (uint8_t*)( debug_buf + 4 ), (uint8_t*) "off", 3 ) ) { + if (xmemmatch( (uint8_t*)( debug_buf + 4 ), (uint8_t*) "off", 3 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nFW Debug OFF"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW Debug Off\n\r"); + if( debug_uart3 ) pc.printf("\r\nFW Debug OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW 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_fw = false; } } - - else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dfwp ", 5 ) ) { - if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "on", 2 ) ) { + + else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dfwp ", 5 ) ){ + if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "on", 2 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nFWPrint Debug ON"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FWPrint Debug On\n\r"); + if( debug_uart3 ) pc.printf("\r\nFWPrint Debug ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FWPrint 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_fw_print = true; } - if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "off", 3 ) ) { + if (xmemmatch( (uint8_t*)( debug_buf + 5 ), (uint8_t*) "off", 3 ) ){ miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\nFWPrint Debug OFF"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FWPrint Debug Off\n\r"); + if( debug_uart3 ) pc.printf("\r\nFWPrint Debug OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FWPrint 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_fw_print = false; } } - + else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "drx ", 4 )) { if (xmemmatch( (uint8_t*)( debug_buf + 4 ), (uint8_t*) "on",2 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\tDebug Cbx Rx ON"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug Cbx On Rx on\n\r"); + if( debug_uart3 ) pc.printf("\tDebug Cbx Rx ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug Cbx On Rx 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_cb_rx = true; } if (xmemmatch( (uint8_t*)( debug_buf + 4 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\tDebug Cbx Rx OFF"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug Cbx On Rx off\n\r"); + if( debug_uart3 ) pc.printf("\tDebug Cbx Rx OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug Cbx Rx 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_cb_rx = false; } } - + else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dtx ", 4 )) { if (xmemmatch( (uint8_t*)( debug_buf + 4 ), (uint8_t*) "on",2 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\tDebug Cbx Tx ON"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug Cbx Tx on\n\r"); + if( debug_uart3 ) pc.printf("\tDebug Cbx Rx ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug Cbx On Rx 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_cb_tx = true; } if (xmemmatch( (uint8_t*)( debug_buf + 4 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\tDebug Cbx Tx OFF"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug Cbx Tx off\n\r"); + if( debug_uart3 ) pc.printf("\tDebug Cbx Rx OFF"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug Cbx Rx 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_cb_tx = false; } } - + else 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; - if( debug_uart3 && !( from_eth ) ) pc.printf("\tDebug File ON"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug File On\n\r"); + if( debug_uart3 ) pc.printf("\tDebug File ON"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\tDebug File 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_file = true; + debug_cb_rx = true; } if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("Debug File OFF"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File Off\n\r"); + if( debug_uart3 ) 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'; - 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_file = false; + debug_cb_rx = false; } } - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "uptime" ) ) - { - miss_match = false; - show_uptime = true; - } - else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) { miss_match = false; - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\r****************************PROMPT HELP******************\n\r"); - if( from_eth ) { + if( debug_uart3 ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - /* - int send = udp_client.sendTo( udp_server, debug_buf, strlen( debug_buf ) ); - - if( send != strlen( debug_buf ) ) { - if( debug_reconnect ) send_msg("Reconnect udp_query client"); - reconnect_prompt_udp_socket(); - miss_prompt_udp_send_pkg++; - } - */ + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + while( !( udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ) ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("ifconfig - mostra o arquivo de configuracao do sistema\n\r"); - if( from_eth ) { + + if( debug_uart3 ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) pc.printf("pcb 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) pc.printf("pcb 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) pc.printf("format - formata o sistema de arquivos\n\r"); + //desabilitado via eth + /* + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "format - formata o sistema de arquivos\n\r" ); + 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 ) ); } } - if( debug_uart3 && !( from_eth ) ) pc.printf("format - formata o sistema de arquivos\n\r"); - if( debug_uart3 && !( from_eth ) ) pc.printf("reset - resta o sistema\n\r"); - if( from_eth ) { + */ + if( debug_uart3 ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) pc.printf("telemetry_ip - Configura o IP do servidor de telemetria\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "telemetry_ip - Configura o IP do servidor de telemetria\n\r" ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("fw_ip - Configura o IP do servidor de fw\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "fw_ip - Configura o IP do servidor de fw\n\r" ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) pc.printf("telemetry_port - Configura a port do servidor de telemetria\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "telemetry_port - Configura a port do servidor de telemetria\n\r" ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) pc.printf("fw_port - Configura a porta do servidor de fw\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "fw_port - Configura a porta do servidor de fw\n\r" ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + + if( debug_uart3 ) pc.printf("fw_ip - Configura o IP do servidor de fw\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "fw_ip - Configura o IP do servidor de fw\n\r" ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("maxext - Configura o maior ramal possivel de ser registrado nesse ramo\n\r"); - if( from_eth ) { + if( debug_uart3 ) pc.printf("fw_port - Configura a porta do servidor de fw\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "fw_port - Configura a porta do servidor de fw\n\r" ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + if( debug_uart3 ) pc.printf("maxext - Configura o maior ramal possivel de ser registrado nesse ramo\n\r"); + if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "maxext - Configura o maior ramal possivel de ser registrado nesse ramo\n\r" ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("minext - Configura o menor ramal possivel de ser registrado nesse ramo\n\r"); - if( from_eth ) { + + if( debug_uart3 ) pc.printf("minext - Configura o menor ramal possivel de ser registrado nesse ramo\n\r"); + if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "minext - Configura o menor ramal possivel de ser registrado nesse ramo\n\r" ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("showcb - lista os Cbx registrados na header\n\r"); - if( from_eth ) { + + if( debug_uart3 ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) pc.printf("reset_cks - reseta estatisticas de check sum\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "reset_cks - reseta estatisticas de check sum\n\r" ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + /* + if( debug_uart3 ) pc.printf("status - lista resumida de cbx registrados na header\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "showcb - lista resumida de cbx registrados na header\n\r" ); + 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 ) ); } } - - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + */ + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) pc.printf("reset_cks - reseta estatisticas de check sum\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "reset_cks - reseta estatisticas de check sum\n\r" ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("silence <start_ext end_ext> - envia comando de flood off para os ramais no intervalo end_ext - start_ext\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "silence <start_ext end_ext> - envia comando de flood off para os ramais no intervalo end_ext - start_ext\n\r"); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("++ ext - Header flood on, ext flood on\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "++ ext - Header flood on, ext flood on\n\r"); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) 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 ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + if( debug_uart3 ) pc.printf("silence <start_ext end_ext> - envia comando de flood off para os ramais no intervalo end_ext - start_ext\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "silence <start_ext end_ext> - envia comando de flood off para os ramais no intervalo end_ext - start_ext\n\r"); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("-- ext - Header flood off, ext flood off\n\r"); - if( from_eth ) { + + if( debug_uart3 ) pc.printf("++ ext - Header flood on, ext flood on\n\r"); + if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "++ ext - Header flood on, ext flood on\n\r"); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("rx - Exibe ultimo pacote recebido dos CBx\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "rx - Exibe ultimo pacote recebido dos CBx\n\r"); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - if( debug_uart3 && !( from_eth ) ) pc.printf("tx - Exibe ultimo pacote enviado para os CBx\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "tx - Exibe ultimo pacote enviado para os CBx\n\r"); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + + if( debug_uart3 ) pc.printf("-- ext - Header flood off, ext flood off\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "++ ext - Header flood on, ext flood on\n\r"); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) pc.printf("ls | status - Exibe uma lista ordenada por ext do CBx registrados na Header\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ls | status - Exibe uma lista ordenada por ext do CBx registrados na Header\n\r"); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + + if( debug_uart3 ) pc.printf("rx - Exibe ultimo pacote recebido dos CBx\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "rx - Exibe ultimo pacote recebido dos CBx\n\r"); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - if( debug_uart3 && !( from_eth ) ) pc.printf("types - Lista os types usados no protocolo de comunicacao Header -- CBx\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "types - Lista os types usados no protocolo de comunicacao Header -- CBx\n\r"); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - if( debug_uart3 && !( from_eth ) ) pc.printf("protocol - Exibe formato do pacote seguindo o protocolo de comunicacao Header -- CBx\n\r"); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "protocol - Exibe formato do pacote seguindo o protocolo de comunicacao Header -- CBx\n\r"); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) pc.printf("tx - Exibe ultimo pacote enviado para os CBx\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "tx - Exibe ultimo pacote enviado para os CBx\n\r"); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - - if( debug_uart3 && !( from_eth ) ) pc.printf("PROMPT VERSION: V%d\n\r", PVERSION); - if( from_eth ) { - snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "PROMPT VERSION: V%d\n\r", PVERSION); - if( tcp_session && !udp_query ) { - while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - } else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( debug_uart3 ) pc.printf("ls | status - Exibe uma lista ordenada por ext do CBx registrados na Header\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ls | status - Exibe uma lista ordenada por ext do CBx registrados na Header\n\r"); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } - //*------------ formatando a saida ----------------*// - strcpy( last_cmd, tmp_cmd ); - bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; - - if( from_eth ) { - if( tcp_session && !udp_query ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "> " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - } else if( udp_query ) { - udp_query_send_msg( "> " ); + if( debug_uart3 ) pc.printf("types - Lista os types usados no protocolo de comunicacao Header -- CBx\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "types - Lista os types usados no protocolo de comunicacao Header -- CBx\n\r"); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } + if( debug_uart3 ) pc.printf("protocol - Exibe formato do pacote seguindo o protocolo de comunicacao Header -- CBx\n\r"); + if( from_eth ){ + snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "protocol - Exibe formato do pacote seguindo o protocolo de comunicacao Header -- CBx\n\r"); + if( tcp_session ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + } + } + + if( debug_uart3 ) 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); } - - else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )) { + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )){ miss_match = false; int ext,port; char cmd[ 16 ]; - + ext = atoi( debug_buf + 7 ); port = convert_ext_to_port( ext ); - + strcpy( cmd, ( ext % 2 ) ? "call init B" : "call init A" ); - + if( ext % 2 ) ext--; - + promptcb_last_ext = ext; promptcb_last_port = port; - + int tmp = strlen( cmd ); cmd[ tmp ] = 0x0D; cmd[ tmp + 1 ] = 0x00; strcpy( promptcb_last_cmd, cmd ); - - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd ); - - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\r--------------------------------------------------------\n\r"); - for( uint16_t i = 0; i < strlen( cmd ) ; i++ ) if( debug_uart3 && !( from_eth ) ) pc.printf( "%02x ", cmd[ i ] ); - - 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\r--------------------------------------------------------\n\r"); - for( uint16_t i = 0; i < 300 ; i++ ) { - if( debug_uart3 && !( from_eth ) ) pc.printf( "%02x ", write_buffer[ i ] ); - if( i != 0 && !( ( i + 1 ) % 30 ) ) if( debug_uart3 && !( from_eth ) ) pc.printf("\n\r"); - } - - - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rComando enviado\n\r"); - - if( from_eth ) { + + if( debug_uart3 ) pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd ); + + if( debug_uart3 ) pc.printf("\n\r--------------------------------------------------------\n\r"); + for( uint16_t i = 0; i < strlen( cmd ) ; i++ ) if( debug_uart3 ) pc.printf( "%02x ", cmd[ i ] ); + + send2callboxes( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + if( debug_uart3 ) pc.printf("\n\r--------------------------------------------------------\n\r"); + for( uint16_t i = 0; i < 300 ; i++ ){ + if( debug_uart3 ) pc.printf( "%02x ", write_buffer[ i ] ); + if( i != 0 && !( ( i + 1 ) % 30 ) ) if( debug_uart3 ) pc.printf("\n\r"); + } + + + if( debug_uart3 ) pc.printf("\n\rComando enviado\n\r"); + + if( from_eth ){ char eth_msg[ 512 ]; snprintf( eth_msg, 512 - 1, "\r\next=%d port=%d\r\ncmd=%s\r\n\n\rComando enviado\n\r", ext, port, cmd ); - if( tcp_session && !udp_query ) { + if( tcp_session ){ 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; - } - - if( miss_match ) { - if( debug_uart3 && !( from_eth ) ) 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 ); - if( tcp_session && !udp_query ) { - tcp_client.send_all( debug_buf, strlen( debug_buf ) ); - } else if( udp_query ) { - udp_query_send_msg( debug_buf ); + }else if( udp_request ){ + udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); } } - } else { - if( from_eth && strlen( debug_buf ) > 2 ) strcpy( last_cmd, tmp_cmd ); - - else if( strlen( debug_buf ) > 2 ) strcpy( last_cmd, tmp_cmd ); - } - } - if( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ) { - bufret = 0; - - if( debug_uart3 && !( from_eth ) ) pc.putc(0x0A); - if( debug_uart3 && !( from_eth ) ) pc.putc(0x0D); - if( debug_uart3 && !( from_eth ) ) pc.printf("> "); - - if( from_eth ) - { - if( strlen( debug_buf ) > 0 ) - { - - if( debug_buf[ strlen( debug_buf ) - 1 ] == '\r' || debug_buf[ strlen( debug_buf ) - 1 ] == '\n' ) - { - //strcat( debug_buf, "> " ); - strcpy( debug_buf, "> " ); - } else { - //strcat( debug_buf, "\n\r> " ); - strcpy( debug_buf, "\n\r> " ); - } - }else{ - - } - if( tcp_session && !udp_query ) - { - tcp_client.send_all( debug_buf, strlen( debug_buf ) ); - } else if( udp_query ) { - - udp_query_send_msg( debug_buf ); - - } - for( register uint16_t i = 0; i < __PROMPT_ETH_BUFFER_SIZE__; i++ ) eth_buffer[ i ] = 0; - - debug_buf = __debug_buf__; - - bufptr = last_bufptr; - - } - else - { bufptr = 0; - last_bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; - } - } - return( NULL ); -}//fim prompt_process - - -// operantion with the system config files -void files( const char type ) -{ - // show files - if (type == 's' ) { - - if( debug_uart3 && !( from_eth ) ) pc.printf("Header IP " ); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header IP " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/myip.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Header ext "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header ext " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/myext.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Header port "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header port " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/mysipport.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Server IP "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server IP " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/serverip.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Server ext "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server ext " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/peerext.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Server port "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server port " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } - cat("/qspi/serverport.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Mascara de rede "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Mascara de rede " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - cat("/qspi/mymask.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Gateway IP "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Gateway IP " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - cat("/qspi/mygateway.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("UDP Port "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "UDP Port " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/udpport.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("TCP Port "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "TCP Port " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/tcpport.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("FW Server IP "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW Server IP " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/fw_ip.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("FW Server Port "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "FW Server Port " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/fw_port.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Max Ext "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Max Ext " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/maxext.txt"); - - if( debug_uart3 && !( from_eth ) ) pc.printf("Min Ext "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Min Ext " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - } - - cat("/qspi/minext.txt"); - if( debug_uart3 && !( from_eth ) ) pc.printf("Shift Port "); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Shift Port " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - - else if( udp_query ) { - udp_query_send_msg( debug_buf ); + if( miss_match ){ + if( debug_uart3 ) 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'; } } - - cat("/qspi/shift_port.txt"); - - - //*------------ formatando a saida ----------------*// - strcpy( last_cmd, tmp_cmd ); - bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; - - if( from_eth ) { + else{ + if( from_eth && strlen( debug_buf ) > 2 ) strcpy( last_cmd, tmp_cmd ); - if( tcp_session && !udp_query ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "> " ); - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); - } else if( udp_query ) { - udp_query_send_msg( "> " ); - - } - } - } - - if (type == 'c' ) { - // close all files - if( fip ) fclose( fip ); - if( fmask ) fclose( fmask ); - if( fgate ) fclose( fgate ); - if( fport )fclose( fport ); - if( fsip ) fclose( fsip ); - if( fsport ) fclose( fsport ); - if( fext ) fclose( fext ); - if( fserext ) fclose( fserext ); - if( fudpport ) fclose( fudpport ); - if( ftcpport ) fclose( ftcpport ); - if( fmax ) fclose( fmax ); - if( fmin ) fclose( fmin ); - if( ffwip ) fclose( ffwip ); - if( ffwport) fclose( ffwport ); - if( fshift_port ) fclose ( fshift_port ); - } - - if (type == 'i' ) { - - // Check if files exist, if not create the files - //fixme criar um bool pra cada file - bool exists = true; - - fip = fopen("/qspi/myip.txt", "r"); - if( fip == NULL) { - set_ip( __MY_IP__ ); - exists = false; - } - - fserext = fopen("/qspi/myext.txt", "r"); - if( fserext == NULL ) { - set_header_ext( __MY_EXT__ ); - exists = false; - } - - fport = fopen("/qspi/mysipport.txt", "r"); - if (fport == NULL) { - set_header_sip_port( __MY_PORT__ ); - exists = false; - } - - fsip = fopen("/qspi/serverip.txt", "r"); - if (fsip == NULL) { - set_server_ip( __SERVER_IP__ ); - exists = false; - } - - fext = fopen("/qspi/peerext.txt", "r"); - if ( fext == NULL ) { - set_server_ext( __PEER_EXT__ ); - exists = false; - } - - fsport = fopen("/qspi/serverport.txt", "r"); - if (fsport == NULL) { - set_server_port( __SERVER_PORT__ ); - exists = false; - } - - fmask = fopen("/qspi/mymask.txt", "r"); - if (fmask == NULL) { - set_mask( __MY_MSK__ ); - exists = false; - } - - fgate = fopen("/qspi/mygateway.txt", "r"); - if (fgate == NULL) { - set_gateway( __MY_GTW__ ); - exists = false; - } - - fudpport = fopen("/qspi/udpport.txt", "r" ); - if( fudpport == NULL ) { - set_udp_port_listener( UDP_PORT_LISTENER ); - exists = false; - } - - ftcpport = fopen("/qspi/tcpport.txt", "r" ); - if( ftcpport == NULL ) { - set_tcp_port_listener( TCP_PORT_LISTENER ); - exists = false; - } - - ffwip = fopen("/qspi/fw_ip.txt", "r" ); - if( ffwip == NULL ) { - set_fw_ip( __FW_SERVER_IP__ ); - exists = false; - } - - ffwport = fopen("/qspi/fw_port.txt", "r" ); - if( ffwport == NULL ) { - set_fw_port( __FW_SERVER_PORT__ ); - exists = false; - } - - fmax = fopen("/qspi/maxext.txt", "r" ); - if( fmax == NULL ) { - set_max_ext( MAX_EXT ); - exists = false; - } - - fmin = fopen("/qspi/minext.txt", "r" ); - if( fmin == NULL ) { - if( debug_file ) debug_msg("Don't exist /qspi/minext.txt"); - set_min_ext( MIN_EXT ); - exists = false; - } - - fshift_port = fopen("/qspi/shift_port.txt", "r" ); - if( fshift_port == NULL ) - { - if( debug_file ) debug_msg("Don't exist /qspi/shift_port.txt"); - set_shift_port( SHIFT_PORT ); - exists = false; - } - - if( !exists ) { - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDefault configurations set!\n\r"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Default configurations set!\n\r"); - debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; - if( tcp_session && !udp_query ) { - tcp_client.send_all( debug_buf, strlen( debug_buf ) ); - bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; - } - } + else if( strlen( debug_buf ) > 2 ) strcpy( last_cmd, tmp_cmd ); } - reset_leds(); - } - - if (type == 'r' ) { - // Just open for read - - fip = fopen("/qspi/myip.txt", "r"); - fmask = fopen("/qspi/mymask.txt", "r"); - fgate = fopen("/qspi/mygateway.txt", "r"); - 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" ); - fudpport = fopen( "/qspi/udpport.txt", "r" ); - ftcpport = fopen( "/qspi/tcpport.txt", "r" ); - ffwip = fopen("/qspi/fw_ip.txt", "r" ); - ffwport = fopen("/qspi/fw_port.txt", "r" ); - fmax = fopen("/qspi/maxext.txt", "r" ); - fmin = fopen("/qspi/minext.txt", "r" ); - fshift_port = fopen("/qspi/shift_port.txt", "r" ); - - } - - if( type == 'w') { - - // Create and write the default configs - set_ip( __MY_IP__ ); - - set_header_sip_port( __MY_PORT__ ); - - set_header_ext( __MY_EXT__ ); - - set_server_ip( __SERVER_IP__ ); - - set_server_ext( __PEER_EXT__ ); - - set_server_port( __SERVER_PORT__ ); - - set_mask( __MY_MSK__ ); - - set_gateway( __MY_GTW__ ); - - set_udp_port_listener( UDP_PORT_LISTENER ); - - set_tcp_port_listener( TCP_PORT_LISTENER ); - - set_fw_ip( __FW_SERVER_IP__ ); - - set_fw_port( __FW_SERVER_PORT__ ); - - set_max_ext( MAX_EXT ); - - set_min_ext( MIN_EXT ); - - set_shift_port( SHIFT_PORT ); - - strcpy( last_cmd, tmp_cmd ); - - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDefault configurations set!\n\r"); - if( from_eth ) { - snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rDefault configurations set!\n\r"); - debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; - if( tcp_session && !udp_query ) { + } + if( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ){ + bufret = 0; + if( from_eth ){ + from_eth = false; + + if( debug_buf[ strlen( debug_buf ) - 1 ] == '\r' || debug_buf[ strlen( debug_buf ) - 1 ] == '\n' ) strcat( debug_buf, "> " ); + + else strcat( debug_buf, "\n\r> " ); + + if( tcp_session ){ + tcp_client.send_all( debug_buf, strlen( debug_buf ) ); - } else if( udp_query ) { - udp_query_send_msg( debug_buf ); + + }else if( udp_request ){ + + int sent = udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); + + udp_request = false; } + for( register uint16_t i = 0; i < __PROMPT_ETH_BUFFER_SIZE__; i++ ) eth_buffer[ i ] = 0; + debug_buf = __debug_buf__; + bufptr = last_bufptr; + }else{ bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } - - } - - if (type == 'e') - { - //Erase 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" ); - ffwip = fopen("/qspi/fw_ip.txt", "w" ); - ffwport = fopen("/qspi/fw_port.txt", "w" ); - fmax = fopen("/qspi/maxext.txt", "w" ); - fmin = fopen("/qspi/minext.txt", "w" ); - fshift_port = fopen("/qspi/shift_port.txt", "w" ); - - if( fip ) fprintf( fip, "%s\n\r", "" ); - if( fport ) fprintf( fport, "%i\n\r", 0 ); - if( fext ) fprintf( fext, "%i\n\r", 0 ); - - if( fsip ) fprintf( fsip, "%s\n\r", "" ); - if( fserext ) fprintf( fserext, "%i\n\r", 0 ); - if( fsport ) fprintf( fsport, "%i\n\r", 0 ); - - if( fmask ) fprintf( fmask, "%s\n\r","" ); - if( fgate ) fprintf( fgate, "%s\n\r", "" ); - - if( fudpport ) fprintf( fudpport, "%i\n\r", 0 ); - if( ftcpport ) fprintf( ftcpport, "%i\n\r", 0 ); - - if( ffwip ) fprintf( ffwip, "%s\n\r","" ); - if( ffwport ) fprintf( ffwport, "%i\n\r",0 ); - - if( fmax ) fprintf( fmax, "%i\n\r", 0 ); - if( fmin ) fprintf( fmin, "%i\n\r", 0 ); - - if( fshift_port ) fprintf( fshift_port, "%i\n\r", 0 ); - - files('c'); - - if( debug_uart3 && !( from_eth ) ) 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 && !udp_query ) { - tcp_client.send_all( debug_buf, strlen( debug_buf ) ); - } else if( udp_query ) { - udp_query_send_msg( debug_buf ); - } - bufptr = 0; - for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; - } - - } -} - -void init_fsystem() -{ - // init file system and check if files exist - if (!qspifs.isformatted()) { - qspifs.format(); - if( debug_uart3 && !( from_eth ) ) pc.printf("\n\r******* File system configured!!******* \n\r"); - } - // check if the files are created - files('i'); - files('c'); - pc.printf("\r\n******* File System Ready *******\r\n"); - debug_file = false; -} - -int str2uint ( char * s, unsigned int * val ) -{ - int i = 0; - unsigned int ret = 0; - for (;;) { - if (s[i] < '0') { - *val = ret; - return i; - } - ret *= 10; - ret += s[i] - '0'; - i++; - } + pc.putc(0x0A); + pc.putc(0x0D); + if( debug_uart3 ) pc.printf("> "); + } + return( NULL ); } \ No newline at end of file