![](/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:
- 54:448d57291be6
- Parent:
- 53:bb492a8f115a
- Child:
- 55:2f5e7374af9d
diff -r bb492a8f115a -r 448d57291be6 prompt.cpp --- a/prompt.cpp Tue Oct 21 19:35:07 2014 +0000 +++ b/prompt.cpp Wed Oct 22 13:53:49 2014 +0000 @@ -1,4 +1,5 @@ #include "prompt.h" +#include "utils.h" TCPSocketServer tcp_server; TCPSocketConnection tcp_client; @@ -29,7 +30,7 @@ bool cb_status = false; bool reset_cks = false; bool debug_telemetry = false; -bool telemetry_test = false; +bool main_test = false; uint8_t test_debug = 1; #define PVERSION 4 // Sempre atualizar a versao do prompt @@ -334,20 +335,23 @@ } if( type == 'w'){ // Create and write the default configs - fip = fopen("/qspi/myip.txt", "w"); + char tmp[ 8 ]; + //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" ); + //fext = fopen( "/qspi/myext.txt", "w" ); fserext = fopen( "/qspi/peerext.txt", "w" ); fudpport = fopen( "/qspi/udpport.txt", "w" ); ftcpport = fopen( "/qspi/tcpport.txt", "w" ); - fprintf( fip, "%s\n\r", __MY_IP__ ); //myip + //fprintf( fip, "%s\n\r", __MY_IP__ ); //myip + set_ip( __MY_IP__ ); fprintf( fport, "%i\n\r", __MY_PORT__ ); //mysipport // isso pode dar pala - fprintf( fext, "%i\n\r", __MY_EXT__ ); //myext + //fprintf( fext, "%i\n\r", __MY_EXT__ ); //myext + set_header_ext( itoa( __MY_EXT__, tmp, 10 ) ); fprintf( fsip, "%s\n\r", __SERVER_IP__ ); //asterisk ip fprintf( fserext, "%i\n\r",__PEER_EXT__ ); //asterisk port @@ -596,19 +600,21 @@ if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ipset ", 6 )) { miss_match = false; - fip = fopen("/qspi/myip.txt", "w"); - fprintf(fip,"%s\n\r",(debug_buf+6)); - fclose(fip); - pc.printf("\n\r"); + //fip = fopen("/qspi/myip.txt", "w"); + //fprintf(fip,"%s\n\r",(debug_buf+6)); + //fclose(fip); + //pc.printf("\n\r"); + set_ip( debug_buf + 6 ); files('s'); } if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "extset ", 7 ) ){ miss_match = false; - fip = fopen("/qspi/myext.txt", "w"); - fprintf(fip, "%s\n\r" , ( debug_buf + 7) ); - fclose(fip); - pc.printf("\n\r"); + //fip = fopen("/qspi/myext.txt", "w"); + //fprintf(fip, "%s\n\r" , ( debug_buf + 7) ); + //fclose(fip); + //pc.printf("\n\r"); + set_header_ext( debug_buf + 7); files('s'); } @@ -702,7 +708,7 @@ if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "tt" ) ){ miss_match = false; - telemetry_test = true; + main_test = true; } @@ -868,7 +874,7 @@ static uint8_t id_msg = 0x10; uint8_t write_buffer[ 300 ]; int ext,port; - char *split, *ref; + char *split, *ref, *cmd; ref = debug_buf; debug_buf[ bufptr++ ] = 0x0D; @@ -879,18 +885,24 @@ port = convert_ext_to_port( ext ); split += strlen( split ) + 1; + cmd = split; promptcb_last_ext = ext; promptcb_last_port = port; - pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, split ); - __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, split, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd ); + __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); pc.printf("\n\rComando enviado\n\r"); for( register int i = 0; i < 32; i++ ) pc.printf("%0x ", write_buffer[ i ] ); pc.printf("\n\r"); + if( from_eth ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\r\next=%d port=%d\r\ncmd=%s\r\n\n\rComando enviado\n\r", ext, port, cmd ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; + } + debug_buf = ref; bufptr = 0; debug_buf[ 0 ] = 0; @@ -929,7 +941,6 @@ debug_buf[ bufptr++ ] = 0x00; pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf + 4 ); - __send_to_cb__( __build_cb_package__( promptcb_last_ext, promptcb_last_port, __PROMPT__, debug_buf + 4, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); pc.printf("\n\rComando enviado\n\r"); } @@ -1228,48 +1239,38 @@ //Obs :: a ultima linha nao mandamos direto pro tcp porque ela eh enviada fora desse escopo if( from_eth ) snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "PROMPT VERSION: V%d\n\r",PVERSION); } - /* - if ( xmemmatch( (uint8_t*)debug_buf, (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( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )){ + miss_match = false; + static uint8_t id_msg = 0x10; + uint8_t write_buffer[ 300 ]; + int ext,port; + char cmd[ 16 ]; + strcpy( cmd, "call init " ); + + debug_buf[ bufptr++ ] = 0x0D; + debug_buf[ bufptr++ ] = 0x00; + + ext = atoi( debug_buf + 7 ); + port = convert_ext_to_port( ext ); + + strcat( cmd, ( ext % 2 ) ? "B" : "A" ); + + promptcb_last_ext = ext; + promptcb_last_port = port; + + pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd ); + __send_to_cb__( __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 ){ + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\r\next=%d port=%d\r\ncmd=%s\r\n\n\rComando enviado\n\r", ext, port, cmd ); + debug_buf[ strlen( debug_buf ) - 1 ] = '\0'; } + + bufptr = 0; + debug_buf[ 0 ] = 0; } - */ if( miss_match ){ pc.printf("\n\r> %s: command not found\n\r", debug_buf ); @@ -1325,3 +1326,15 @@ return( aux ); } } + +void set_ip( char * new_ip ){ + fip = fopen("/qspi/myip.txt", "w"); + fprintf( fip, "%s\n\r", new_ip ); + fclose( fip ); +} + +void set_header_ext( char * new_header_ext ){ + fext = fopen( "/qspi/myext.txt", "w" ); + fprintf( fext, "%i\n\r", new_header_ext ); //myext + fclose( fext ); +} \ No newline at end of file