![](/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:
- 27:98f824719d1c
- Parent:
- 26:725cbbedadd5
- Child:
- 28:94aec56c6329
diff -r 725cbbedadd5 -r 98f824719d1c prompt.cpp --- a/prompt.cpp Mon Sep 22 16:56:00 2014 +0000 +++ b/prompt.cpp Mon Sep 22 21:15:07 2014 +0000 @@ -10,6 +10,7 @@ uint8_t debug_alive = 1; uint8_t pcks_s = 0; uint8_t pshowcb = 0; +uint8_t debug_sip = 0; #define PVERSION 1 // Sempre atualizar a versao do prompt #define DEBUGBUFSIZE 50 @@ -104,7 +105,8 @@ fip = fopen("/qspi/myip.txt", "r"); if (fip == NULL){ fip = fopen("/qspi/myip.txt", "w"); - fprintf(fip, "192.168.120.169\n\r"); //myip + //fprintf(fip, "192.168.120.169\n\r"); //myip + fprintf(fip, "%s\n\r",__MY_IP__); //myip } fmask = fopen("/qspi/mymask.txt", "r"); if (fmask == NULL){ @@ -152,7 +154,7 @@ fsip = fopen("/qspi/serverip.txt", "w"); fsport = fopen("/qspi/serverport.txt", "w"); - fprintf(fip, "192.168.120.169\n\r"); //myip + fprintf(fip, "%s\n\r", __MY_IP__ ); //myip fprintf(fmask, "255.255.255.0\n\r"); //mymask fprintf(fgate, "192.168.2.254\n\r"); //mygateway fprintf(fport, "5075\n\r"); //mysipport @@ -183,225 +185,233 @@ volatile char b = 0; static uint8_t bufret = 0; - if (pc.readable()){ + if ( pc.readable() ){ // imput do teclado b = pc.getc(); - if (b == 0x0D){ // enter - bufret = 1; + if ( b == 0x0D ){ // enter + bufret = 1; } else{ - pc.putc(b); - debug_buf[bufptr] = b; - bufptr++; + pc.putc(b); + debug_buf[bufptr] = b; + bufptr++; } } - if (bufret == 1){ // Prompt commands here - - - if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "sconfig" )) { - pc.printf("\n\r"); - files('s'); - } - - - if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" )) { - pc.printf("\n Formatando o sistema de arquivos... espere o sistema reiniciar \n\r"); - //qspifs.format(); - NVIC_SystemReset(); - } - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ",6 )) { - fip = fopen("/qspi/myip.txt", "w"); - fprintf(fip,"%s\n\r",(debug_buf+6)); - fclose(fip); - pc.printf("\n\r"); - files('s'); - } - + if (bufret == 1) { // Prompt commands here + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "sconfig" )) { + pc.printf("\n\r"); + files('s'); + } + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "format" )) { + pc.printf("\n Formatando o sistema de arquivos... espere o sistema reiniciar \n\r"); + //qspifs.format(); + NVIC_SystemReset(); + } + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ",6 )) { + fip = fopen("/qspi/myip.txt", "w"); + fprintf(fip,"%s\n\r",(debug_buf+6)); + fclose(fip); + pc.printf("\n\r"); + files('s'); + } + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 )) { - fmask = fopen("/qspi/mymask.txt", "w"); - fprintf(fmask,"%s\n\r",(debug_buf+8)); - fclose(fmask); - pc.printf("\n\r"); - files('s'); - } - + fmask = fopen("/qspi/mymask.txt", "w"); + fprintf(fmask,"%s\n\r",(debug_buf+8)); + fclose(fmask); + pc.printf("\n\r"); + files('s'); + } + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 )) { - fgate = fopen("/qspi/mygate.txt", "w"); - fprintf(fgate,"%s\n\r",(debug_buf+11)); - fclose(fgate); - pc.printf("\n\r"); - files('s'); - } - - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 )) { - fport = fopen("/qspi/mysipport.txt", "w"); - fprintf(fport,"%s\n\r",(debug_buf+9)); - fclose(fport); - pc.printf("\n\r"); - files('s'); - } - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 )) { - fsip = fopen("/qspi/serverip.txt", "w"); - fprintf(fsip,"%s\n\r",(debug_buf+9)); - fclose(fsip); - pc.printf("\n\r"); - files('s'); - } - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 )) { - fsport = fopen("/qspi/serverport.txt", "w"); - fprintf(fsport,"%s\n\r",(debug_buf+7)); - fclose(fsport); - pc.printf("\n\r"); - files('s'); - } - - - if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" )) { - files('w'); + fgate = fopen("/qspi/mygate.txt", "w"); + fprintf(fgate,"%s\n\r",(debug_buf+11)); + fclose(fgate); + pc.printf("\n\r"); + files('s'); + } + + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 )) { + fport = fopen("/qspi/mysipport.txt", "w"); + fprintf(fport,"%s\n\r",(debug_buf+9)); + fclose(fport); + pc.printf("\n\r"); + files('s'); + } + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 )) { + fsip = fopen("/qspi/serverip.txt", "w"); + fprintf(fsip,"%s\n\r",(debug_buf+9)); + fclose(fsip); + pc.printf("\n\r"); + files('s'); + } + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 )) { + fsport = fopen("/qspi/serverport.txt", "w"); + fprintf(fsport,"%s\n\r",(debug_buf+7)); + fclose(fsport); + pc.printf("\n\r"); files('s'); - - } - - if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" )) { - pc.printf("\n\r reset!!! \n\r"); - pc.putc(0x01); - NVIC_SystemReset(); - } - - if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" )) { - pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); - dog = 0; - } - + } + + + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" )) { + files('w'); + files('s'); + + } + + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "reset" )) { + pc.printf("\n\r reset!!! \n\r"); + pc.putc(0x01); + NVIC_SystemReset(); + } + + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dog" )) { + pc.printf("\n\r MUUUUUUUuuuuUUUUUU - I'm not a dog!!!! \n\r"); + dog = 0; + } + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "flood ",6 )) { - if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )){ - pc.printf("\n\r\t Flood ON\n\r\t"); - tflood.start(); - tflood.reset(); - floodcount =0; - pflood = 1; - } - if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )){ - pc.printf("\n\r\t Flood OFF\n\r\t"); - pflood = 0; - tflood.stop(); - } - } - + if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { + pc.printf("\n\r\t Flood ON\n\r\t"); + tflood.start(); + tflood.reset(); + floodcount =0; + pflood = 1; + } + if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { + pc.printf("\n\r\t Flood OFF\n\r\t"); + pflood = 0; + tflood.stop(); + } + } + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug ",6 )) { - if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )){ + if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "on",2 )) { pc.printf("\n\r\tDebug ON\n\r\t"); debug_alive = 1; - } - if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )){ - pc.printf("\n\r\tDebug OFF\n\r\t"); + } + if (xmemmatch( (uint8_t*)(debug_buf+6), (uint8_t*) "off",3 )) { + pc.printf("\n\r\tDebug OFF\n\r\t"); debug_alive = 0; - } + } } - - if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9)) { //promptcb ramal porta comando - static int id_msg = 0x10; + + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "promptcb ", 9)) { //promptcb ramal porta comando + static int id_msg = 0x10; uint8_t write_buffer[300]; unsigned int ext,port; int ant1,ant2; - + debug_buf[bufptr++] = 0x0D; debug_buf[bufptr++] = 0x00; - + ant1 = str2uint( (debug_buf+9), &ext); ant2 = str2uint( ((debug_buf+9)+ant1+1), &port); - + pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",ext, port, debug_buf+9+ant1+2+ant2); - + __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, debug_buf+9+ant1+2+ant2, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); pc.printf("\n\rComando enviado\n\r"); } - + if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) { - pcks_s = 1; + pcks_s = 1; } - + if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) { pshowcb = 1; } + + if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debugsip ", 9 )) { + if (xmemmatch( (uint8_t*)( debug_buf + 9 ), (uint8_t*) "on",2 )) { + pc.printf("\n\r\tDebug Sip ON\n\r\t"); + debug_sip = 1; + } + if (xmemmatch( (uint8_t*)( debug_buf + 9 ), (uint8_t*) "off",3 )) { + pc.printf("\n\r\tDebug Sip OFF\n\r\t"); + debug_sip = 0; + } + } + if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) { - pc.printf("\n\r****************************PROMPT HELP******************\n\r"); - pc.printf("sconfig - mostra o arquivo de configuracao do sistema\n\r"); - pc.printf("dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r"); - pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); - pc.printf("promptcb ramal porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r"); - pc.printf("format - formata o sistema de arquivos\n\r"); - pc.printf("reset - resta o sistema\n\r"); - pc.printf("ipset [ip] - Configura o IP da cabeceira\n\r"); - pc.printf("maskset [mask] - Configura a mascara da cabeceira\n\r"); - pc.printf("gatewayset [gateway] - Configura o gateway da cabeceira\n\r"); - pc.printf("msipport [port] - Configura a porta SIP da cabeceira\n\r"); - pc.printf("serverip [ip] - Configura o ip do servidor asterisk\n\r"); - pc.printf("ssport [port] - Configura a porta SIP do servidor asterisk\n\r"); - pc.printf("showcb - lista os Cbx registrados na header\n\r"); - pc.printf("cks - exibe estatisticas de check sum\n\r"); - pc.printf("debug [on|off] - enable debugs\n\r"); - pc.printf("flood [on|off] - simula envio de pacotes de audio\n\r"); - pc.printf("\n\rPROMPT VERSION: V%d\n\r",PVERSION); - } - /* + pc.printf("\n\r****************************PROMPT HELP******************\n\r"); + pc.printf("sconfig - mostra o arquivo de configuracao do sistema\n\r"); + pc.printf("dconfig - volta as configuracoes do sistema para o padrao de fabrica\n\r"); + pc.printf("callme [ramal porta] - envia o pedido de ligacao para o callbox com o ramal e porta indicada\n\r"); + pc.printf("promptcb ramal porta comando - envia o <comando> para o cbx <ramal> e <porta> executar\n\r"); + pc.printf("format - formata o sistema de arquivos\n\r"); + pc.printf("reset - resta o sistema\n\r"); + pc.printf("ipset [ip] - Configura o IP da cabeceira\n\r"); + pc.printf("maskset [mask] - Configura a mascara da cabeceira\n\r"); + pc.printf("gatewayset [gateway] - Configura o gateway da cabeceira\n\r"); + pc.printf("msipport [port] - Configura a porta SIP da cabeceira\n\r"); + pc.printf("serverip [ip] - Configura o ip do servidor asterisk\n\r"); + pc.printf("ssport [port] - Configura a porta SIP do servidor asterisk\n\r"); + pc.printf("showcb - lista os Cbx registrados na header\n\r"); + pc.printf("cks - exibe estatisticas de check sum\n\r"); + pc.printf("debug [on|off] - enable debugs\n\r"); + pc.printf("flood [on|off] - simula envio de pacotes de audio\n\r"); + pc.printf("\n\rPROMPT VERSION: V%d\n\r",PVERSION); + } + /* if ( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )) { if ( debug_buf[16] != 0 && debug_buf[11] != 0x20 ) pc.printf("\n\r Error: formato errado! ramal=xxxx porta=xxxx \n\r"); else { uint8_t data[300]; uint16_t cks=0; - + //data[0] = (uint8_t)( (debug_buf[7]&0xf0)<<4 + (debug_buf[8]&0x0f) ) ; //data[1] = (uint8_t)( (debug_buf[9]&0xf0)<<4 + (debug_buf[10]&0x0f) ) ; //data[2] = (uint8_t)( (debug_buf[12]&0xf0)<<4 + (debug_buf[13]&0x0f) ) ; /data[3] = (uint8_t)( (debug_buf[14]&0xf0)<<4 + (debug_buf[15]&0x0f) ) ; - + data[0] = (uint8_t)( debug_buf[ 7 ] & 0xFF00 >> 8 ); data[1] = (uint8_t)( debug_buf[ 9 ] & 0x00FF ); data[2] = (uint8_t)( debug_buf[ 12 ] & 0xFF00 >> 8 ); data[3] = (uint8_t)( debug_buf[ 14 ] & 0x00FF ); - + data[6] = 0x04; for (int i = 7; i < 300; i++) data[i] = 0x00; cks = __checksum__(data,300); data[4] = cks>>8; data[5] = cks&0xff; - + pc.printf("\n\r"); for( int i = 0; i < 300; i++ ) pc.printf("%x ", data[ i ] ); pc.printf("\n\r"); - + xmemcpy(TXBuffer,data,300); - + pc.printf("\n\r"); for( int i = 0; i < 300; i++ ) pc.printf("%x ", data[ i ] ); pc.printf("\n\r"); - + send2callboxes(); - + pc.printf("\n\r calling callbox %s \n\r",debug_buf+7); } } - */ + */ } - if (b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ){ - bufptr = 0; - for (uint8_t i =0; i < DEBUGBUFSIZE; i++){ - debug_buf[i] = 0; + if (b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ) { + bufptr = 0; + for (uint8_t i =0; i < DEBUGBUFSIZE; i++) { + debug_buf[i] = 0; } - bufret = 0; - pc.putc(0x0A); - pc.putc(0x0D); + bufret = 0; + pc.putc(0x0A); + pc.putc(0x0D); } } \ No newline at end of file