![](/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
prompt.cpp
- Committer:
- klauss
- Date:
- 2014-11-24
- Revision:
- 75:bd3c647b860b
- Parent:
- 74:81c47fff88a5
- Child:
- 76:9f5f99dd895a
File content as of revision 75:bd3c647b860b:
#include "prompt.h" bool flood_silence = false; bool delayed_flood = false; #define PVERSION 5 // Sempre atualizar a versao do prompt char __debug_buf__[ DEBUGBUFSIZE ]; char * debug_buf = __debug_buf__; char last_cmd[ DEBUGBUFSIZE ]; char tmp_cmd[ DEBUGBUFSIZE ] = "help"; char last_debug_buf[ DEBUGBUFSIZE ] = "help"; FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext, *fudpport, *ftcpport, *ftip, *ftport; uint8_t bufptr = 0; uint8_t last_bufptr = 0; uint8_t xmemmatch(const uint8_t * s1, const uint8_t * s2, uint16_t size) { while (size--) { if (*s1++ != *s2++) return 0; /* does not match */ } return 1; /* matches */ } uint8_t xstrmatch(const uint8_t * s1, const uint8_t * s2) { while (*s1) { if (*s1++ != *s2++) return 0; /* does not match */ } if ( *s2 == 0 ) return 1; /* matches */ else return 0; /* does not match */ } void xmemcpy(uint8_t * dest, const uint8_t * src, uint16_t size){ while (size--) *dest++ = *src++; } 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++; } } // Print the content of a given file void cat(const char* fname){ char buff[513]; int num; FILE *fp = fopen(fname, "r"); if (fp == NULL) { if( debug_file ) pc.printf( "Failed to open %s", fname); return; } while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ buff[ num ] = '\0'; pc.printf( buff ); if( from_eth ){ if( tcp_session ) tcp_client.send_all( buff, strlen( buff ) ); else if( udp_request ){ udp_server.sendTo( udp_client, buff, strlen( buff ) ); } } } fclose(fp); } // operantion with the system config files void files( const char type ){ // show files if (type == 's' ){ //pc.printf("\n\rHeader IP " ); pc.printf("Header IP " ); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader IP " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header IP " ); 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 ) ); } } cat("/qspi/myip.txt"); //pc.printf("\n\rHeader ext "); pc.printf("Header ext "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader ext " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header ext " ); 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 ) ); } } cat("/qspi/myext.txt"); //pc.printf("\n\rHeader port "); pc.printf("Header port "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rHeader port " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header port " ); 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 ) ); } } cat("/qspi/mysipport.txt"); //pc.printf("\n\rServer IP "); pc.printf("Server IP "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer IP " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server IP " ); 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 ) ); } } cat("/qspi/serverip.txt"); //pc.printf("\n\rServer ext "); pc.printf("Server ext "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer ext " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server ext " ); 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 ) ); } } cat("/qspi/peerext.txt"); //pc.printf("\n\rServer port "); pc.printf("Server port "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rServer port " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Server port " ); 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 ) ); } } cat("/qspi/serverport.txt"); //pc.printf("\n\rMascara de rede "); pc.printf("Mascara de rede "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rMascara de rede " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Mascara de rede " ); 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 ) ); } } cat("/qspi/mymask.txt"); //pc.printf("\n\rGateway IP "); pc.printf("Gateway IP "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rGateway IP " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Gateway IP " ); 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 ) ); } } cat("/qspi/mygate.txt"); //pc.printf("\n\rUDP Port "); pc.printf("UDP Port "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rUDP Port " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "UDP Port " ); 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 ) ); } } cat("/qspi/udpport.txt"); //pc.printf("\n\rTCP Port "); pc.printf("TCP Port "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTCP Port " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "TCP Port " ); 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 ) ); } } cat("/qspi/tcpport.txt"); //pc.printf("\n\rTelemetry Server IP "); pc.printf("Telemetry Server IP "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTelemetry Server IP " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server IP " ); 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 ) ); } } cat("/qspi/telemetry_ip.txt"); //pc.printf("\n\rTelemetry Server Port "); pc.printf("Telemetry Server Port "); if( from_eth ){ //snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rTelemetry Server Port " ); snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server Port " ); 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 ) ); } } cat("/qspi/telemetry_port.txt"); strcpy( last_cmd, tmp_cmd ); //debug_buf[ 0 ] = 0; //bufptr = 0; 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 fclose( fip ); fclose( fmask ); fclose( fgate ); fclose( fport ); fclose( fsip ); fclose( fsport ); fclose( fext ); fclose( fserext ); fclose( fudpport ); fclose( ftcpport ); } if (type == 'i' ){ // Check if files exist, if not create the files 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; } ftip = fopen("/qspi/telemetry_ip.txt", "r" ); if( ftip == NULL ){ set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); exists = false; } ftport = fopen("/qspi/telemetry_port.txt", "r" ); if( ftport == NULL ){ set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); exists = false; } if( !exists ){ 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 ) ); //debug_buf[ 0 ] = 0; //bufptr = 0; bufptr = 0; for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } } } } 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" ); } 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__ ); strcpy( last_cmd, tmp_cmd ); 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 ) ); } //debug_buf[ 0 ] = 0; //bufptr = 0; 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" ); //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 ); files('c'); pc.printf("\n\rErased configurations set!\n\r"); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rErased configurations set!\n\r"); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; if( tcp_session ){ tcp_client.send_all( debug_buf, strlen( debug_buf ) ); }else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } //debug_buf[ 0 ] = 0; //bufptr = 0; 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(); pc.printf("\n\rFile system configured!!\n\r"); } files('i'); // check if the files are created files('c'); pc.printf("\n\r*******File System Ready*******\n\r"); } void init_prompt(){ tcp_server.bind( TCP_PORT_LISTENER ); tcp_server.listen(); //tcp_timer.start(); tcp_server.set_blocking( false, 1 ); udp_server.set_blocking( false, 2 ); udp_server.bind( UDP_PORT_LISTENER ); pc.printf("*******Prompt eth Ready*******\n\r"); } // main prompt process char * prompt_process( char * msg_from_cb ){ //FIXME dar flush na serial volatile char b = 0; static uint8_t bufret = 0; static Timer flood_timeout; static Timer flood_silence_timer; static uint8_t id_msg = 0x10; static int start_ext, end_ext, ext_count; bool miss_match = true; 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_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; } wdt.kick(); if( tcp_session ){ //if( !( (int)tcp_timer.read_ms() % 100 ) ){ tcp_client.set_blocking( false, 1 ); 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" ); bufptr = strlen( eth_buffer ); debug_buf = eth_buffer; from_eth = true; bufret = 1; if( !( strcmp( eth_buffer, "quit" ) ) ){ tcp_timer.reset(); debug_buf = __debug_buf__; bufptr = last_bufptr; from_eth = false; tcp_session = false; tcp_client.close(); bufret = 0; return( NULL ); } }else{ debug_buf = __debug_buf__; bufptr = last_bufptr; from_eth = false; } //} } if( !from_eth ){ if( pc.readable() ){ // imput do teclado b = pc.getc(); if( b == 0x0D ){ // enter bufret = 1; }else{ pc.putc( b ); if( b == 0x08 || b == 0x7F ){ // BS | DEL if( bufptr > 0 ) debug_buf[ --bufptr ] = 0; }else if( b == 0x09 ){ // ignore tab }else{ debug_buf[bufptr] = b; bufptr++; } } } } 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 ) ); } 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 ) ); 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_request ){ 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'; udp_server.sendTo( udp_client, eth_buffer, strlen( eth_buffer ) ); } flood_silence_timer.reset(); if( ++ext_count > end_ext ){ flood_silence = false; flood_silence_timer.stop(); flood_silence_timer.reset(); 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_request ){ snprintf( eth_buffer, __PROMPT_ETH_BUFFER_SIZE__, "\r\n> " ); udp_server.sendTo( udp_client, eth_buffer, strlen( eth_buffer ) ); } } } } if( delayed_flood ){ tflood.start(); tflood.reset(); floodcount =0; pflood = 1; flood_timeout.start(); delayed_flood = false; 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'; } } // Prompt commands here if ( bufret == 1 ) { 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*) "." ) ){ miss_match = false; strcpy( debug_buf, last_cmd ); strcpy( tmp_cmd, debug_buf ); }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*) "-" ) ){ miss_match = false; strcpy( debug_buf, "flood off" ); strcpy( tmp_cmd, debug_buf ); }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 ) ){ miss_match = false; int ext = atoi( debug_buf + 3 ); 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 ); } //tratamento dos enters if( !bufptr ){ miss_match = false; }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" ) ){ miss_match = false; pc.printf("\n\r"); files('s'); } 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" ) ){ miss_match = false; tx = true; } 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" ) ){ miss_match = false; r_stats = true; } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" ) ){ miss_match = false; 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(); NVIC_SystemReset(); } } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ", 6 )) { miss_match = false; set_ip( debug_buf + 6 ); files('s'); } 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 ) ){ miss_match = false; set_server_ext( atoi( debug_buf + 10 ) ); files('s'); } 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 ) ){ miss_match = false; set_gateway( debug_buf + 11 ); files('s'); } 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 ) ){ miss_match = false; set_server_ip( debug_buf + 9 ); files('s'); } 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*) "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( 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" ) ){ miss_match = false; 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 ){ tcp_client.send_all( debug_buf, strlen( debug_buf ) ); tcp_client.close(); }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" ) ){ miss_match = false; 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'; } } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "ls" ) ){ miss_match = false; 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*) "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*) "types" ) ){ miss_match = false; 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" ) ){ miss_match = false; 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 ) ){ miss_match = false; 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; flood_timeout.start(); } if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "more", 4 ) ){ miss_match = false; 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; 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(); } }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" ) ) ){ 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{ 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 % 2 ) start_ext--; if( !( end_ext % 2 ) ) end_ext++; ext_count = start_ext; flood_silence_timer.start(); }else{ 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 ) ){ if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { miss_match = false; 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'; } debug_alive = 1; } if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { miss_match = false; 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'; } debug_alive = 0; } if( xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "show",4 ) ){ miss_match = false; pc.printf("\n\rdsip"); pc.printf("\n\rdebug_alive"); pc.printf("\n\rdebug_prompt"); pc.printf("\n\rdebug_vector"); pc.printf("\n\rdebug_cb"); pc.printf("\n\rdebug_main"); pc.printf("\n\rdebug_cks"); pc.printf("\n\rdebug_cb_rx"); pc.printf("\n\rdebug_cb_tx*"); pc.printf("\n\rdebug_eth_rx*"); pc.printf("\n\rdebug_eth_tx*"); pc.printf("\n\rdebug_file"); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rdsip \n\rdebug_alive \n\rdebug_prompt \n\rdebug_vector \n\rdebug_cb \n\rdebug_main \n\rdebug_cks \n\rdebug_cb_rx \n\rdebug_cb_tx* \n\rdebug_eth_rx* \n\rdebug_eth_tx* \n\rdebug_file\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } } } 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; pc.printf( "\n\rSip Debug ON\n\r" ); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug On\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_sip = 1; } if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { miss_match = false; pc.printf( "\n\rSip Debug OFF\n\r" ); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Sip Debug Off\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_sip = 0; } } 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; 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'; } dparallel = true; } if( xmemmatch( ( uint8_t * )( debug_buf + 10 ), ( uint8_t *)"off", 3 )) { miss_match = false; 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'; } dparallel = false; } } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "dtelemetry ", 11 ) ){ if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "on",2 ) ){ miss_match = false; 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'; } debug_telemetry = true; } if (xmemmatch( (uint8_t*)(debug_buf + 11 ), (uint8_t*) "off",3 )) { miss_match = false; pc.printf( "\n\rrTelemetry 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'; } debug_telemetry = false; } } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cks ", 10 )) { if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "on",2 )) { miss_match = false; pc.printf( "\n\rCKS Debug ON\n\r" ); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug On\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_cks = 1; } if (xmemmatch( (uint8_t*)(debug_buf + 5 ), (uint8_t*) "off",3 )) { miss_match = false; pc.printf( "\n\rCKS Debug OFF\n\r" ); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "CKS Debug Off\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_cks = 0; } } //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; //debug_buf[ strlen( debug_buf ) ] = 0x0D; strcat( debug_buf, "\r" ); //debug_buf[ strlen( debug_buf ) + 1 ] = 0x00; 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; //int tmp = strlen( cmd ); //cmd[ tmp ] = 0x0D; //cmd[ tmp + 1 ] = 0x00; strcpy( promptcb_last_cmd, cmd ); strcat( cmd, "\r\r\r" ); pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd ); send2callboxes( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); 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 ){ tcp_client.send_all( eth_msg, strlen( 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( 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; 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 ) ); pc.printf("\n\rComando enviado\n\r"); } else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) { miss_match = false; pcks_s = 1; } else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) { miss_match = false; pshowcb = 1; } 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; pc.printf("\r\nDebug Main ON"); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main On\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_main = 1; } if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { miss_match = false; pc.printf("\r\nDebug Main OFF"); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Main Off\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_main = 0; } } else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cb_rx ", 12 )) { if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "on",2 )) { miss_match = false; pc.printf("\tDebug Cbx Rx ON"); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Cbx On Rx on\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_cb_rx = 1; } if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "off",3 )) { miss_match = false; pc.printf("Debug Cbx Rx OFF"); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug Cbx Rx Off\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_cb_rx = 0; } } 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; pc.printf("\tDebug File ON"); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File On\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_cb_rx = 1; } if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "off",3 )) { miss_match = false; pc.printf("Debug File OFF"); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Debug File Off\n\r" ); debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } debug_cb_rx = 0; } } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) { miss_match = false; 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("ifconfig - mostra o arquivo de configuracao do sistema\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ifconfig - mostra o arquivo de configuracao do sistema\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) ); } } */ 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("ipset [ip] - Configura o IP da cabeceira\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ipset [ip] - Configura o IP da cabeceira\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("extset [ext] - Configura a ext da cabeceira\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "extset [ext] - Configura a ext da cabeceira\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("msipport [port] - Configura a porta SIP da cabeceira\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "msipport [port] - Configura a porta SIP da cabeceira\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("serverip [ip] - Configura o ip do servidor asterisk\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "serverip [ip] - Configura o ip do servidor asterisk\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("serextset [ext] - Configura a server ext da cabeceira\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "serextset [ext] - Configura a server ext da cabeceira\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("ssport [port] - Configura a porta SIP do servidor asterisk\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "ssport [port] - Configura a porta SIP do servidor asterisk\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("maskset [mask] - Configura a mascara da cabeceira\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "maskset [mask] - Configura a mascara da cabeceira\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("gatewayset [gateway] - Configura o gateway da cabeceira\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "gatewayset [gateway] - Configura o gateway da cabeceira\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("showcb - lista os Cbx registrados na header\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "showcb - lista os Cbx registrados na header\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } /* 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 ) ); } } */ 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf(". - executa o comando anterior novamente\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, ". - executa o comando anterior novamente\n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "debug [on|off|show] - seleciona debugs gerais | lista de debugs \n\r" ); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("{ flood [ on | off ] | [+|-] } - simula envio de pacotes de audio\n\r"); if( from_eth ){ snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "{ flood [ on | off ] | [+|-] } - simula envio de pacotes de audio\n\r"); if( tcp_session ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } 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 ) tcp_client.send_all( debug_buf, strlen( debug_buf ) ); else if( udp_request ){ udp_server.sendTo( udp_client, debug_buf, strlen( debug_buf ) ); } } pc.printf("PROMPT VERSION: V%d\n\r",PVERSION); //Obs :: a ultima linha nao mandamos direto pro tcp porque ela eh enviada fora desse escopo if( from_eth ) snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "PROMPT VERSION: V%d\n\r",PVERSION); } 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 ); pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd ); pc.printf("\n\r--------------------------------------------------------\n\r"); for( uint16_t i = 0; i < strlen( cmd ) ; i++ ) pc.printf( "%02x ", cmd[ i ] ); send2callboxes( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); pc.printf("\n\r--------------------------------------------------------\n\r"); for( uint16_t i = 0; i < 300 ; i++ ){ pc.printf( "%02x ", write_buffer[ i ] ); if( i != 0 && !( ( i + 1 ) % 30 ) ) pc.printf("\n\r"); } 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 ){ tcp_client.send_all( eth_msg, strlen( eth_msg ) ); }else if( udp_request ){ udp_server.sendTo( udp_client, eth_msg, strlen( eth_msg ) ); } } bufptr = 0; for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } if( miss_match ){ pc.printf("\n\r> %s: command not found\n\r", debug_buf ); if( from_eth ){ snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "> %s: command not found\n ", debug_buf ); //debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } } else{ 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( 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_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( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } pc.putc(0x0A); pc.putc(0x0D); pc.printf("> "); } return( NULL ); } void set_ip( char * new_header_ip ){ fip = fopen("/qspi/myip.txt", "w"); fprintf( fip, "%s\n\r", new_header_ip ); fclose( fip ); } void set_header_ext( int new_header_ext ){ fext = fopen( "/qspi/myext.txt", "w" ); fprintf( fext, "%i\n\r", new_header_ext ); fclose( fext ); } void set_header_sip_port( int new_header_sip_port ){ fport = fopen("/qspi/mysipport.txt", "w"); fprintf( fport,"%i\n\r", new_header_sip_port ); fclose( fport ); } void set_server_ip( char * new_server_ip ){ fsip = fopen("/qspi/serverip.txt", "w"); fprintf( fsip,"%s\n\r", new_server_ip ); fclose( fsip ); } void set_server_ext( int new_server_ext ){ fserext = fopen("/qspi/peerext.txt", "w"); fprintf( fserext , "%i\n\r", new_server_ext ); fclose( fserext ); } void set_server_port( int new_server_port ){ fsport = fopen("/qspi/serverport.txt", "w"); fprintf(fsport,"%i\n\r", new_server_port ); fclose( fsport ); } void set_mask( char * new_mask ){ fmask = fopen("/qspi/mymask.txt", "w"); fprintf(fmask,"%s\n\r",new_mask ); fclose( fmask ); } void set_gateway( char * new_gateway ){ fgate = fopen("/qspi/mygate.txt", "w"); fprintf(fgate,"%s\n\r", new_gateway ); fclose( fgate ); } void set_udp_port_listener( int new_udp_port_listener ){ fudpport = fopen( "/qspi/udpport.txt", "w" ); fprintf( fudpport, "%i\n\r",new_udp_port_listener ); fclose( fudpport ); } void set_tcp_port_listener( int new_tcp_port_listener ){ ftcpport = fopen( "/qspi/tcpport.txt", "w" ); fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); fclose( ftcpport ); } void set_telemetry_ip( char * new_telemetry_ip ){ ftip = fopen("/qspi/telemetry_ip.txt", "w" ); fprintf(ftip,"%s\n\r", new_telemetry_ip ); fclose( ftip ); } void set_telemetry_port( int new_telemetry_port ){ ftport = fopen("/qspi/telemetry_port.txt", "w" ); fprintf(ftport,"%i\n\r", new_telemetry_port ); fclose( ftport ); }