![](/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:
- 55:2f5e7374af9d
- Parent:
- 54:448d57291be6
- Child:
- 56:c64bcbaa621a
diff -r 448d57291be6 -r 2f5e7374af9d prompt.cpp --- a/prompt.cpp Wed Oct 22 13:53:49 2014 +0000 +++ b/prompt.cpp Wed Oct 22 22:32:26 2014 +0000 @@ -334,32 +334,37 @@ ftcpport = fopen( "/qspi/tcpport.txt", "r" ); } - if( type == 'w'){ // Create and write the default configs - char tmp[ 8 ]; + if( type == 'w'){ + // Create and write the default 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"); + //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" ); + //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 set_ip( __MY_IP__ ); - fprintf( fport, "%i\n\r", __MY_PORT__ ); //mysipport // isso pode dar pala + //fprintf( fport, "%i\n\r", __MY_PORT__ ); //mysipport // isso pode dar pala + set_header_sip_port( __MY_PORT__ ); //fprintf( fext, "%i\n\r", __MY_EXT__ ); //myext - set_header_ext( itoa( __MY_EXT__, tmp, 10 ) ); + set_header_ext( __MY_EXT__ ); - fprintf( fsip, "%s\n\r", __SERVER_IP__ ); //asterisk ip - fprintf( fserext, "%i\n\r",__PEER_EXT__ ); //asterisk port - fprintf( fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port + //fprintf( fsip, "%s\n\r", __SERVER_IP__ ); //asterisk ip + set_server_ip( __SERVER_IP__ ); + //fprintf( fserext, "%i\n\r",__PEER_EXT__ ); //asterisk port + set_server_ext( __PEER_EXT__ ); + //fprintf( fsport, "%i\n\r",__SERVER_PORT__ ); //asterisk port + set_server_port( __SERVER_PORT__ ); - fprintf( fmask, "%s\n\r",__MY_MSK__ ); //mymask - fprintf( fgate, "%s\n\r", __MY_GTW__ ); //mygateway - + //fprintf( fmask, "%s\n\r",__MY_MSK__ ); //mymask + set_mask( __MY_MSK__ ); + //fprintf( fgate, "%s\n\r", __MY_GTW__ ); //mygateway + set_gateway( __MY_GTW__ ); fprintf( fudpport, "%i\n\r",UDP_PORT_LISTENER ); fprintf( ftcpport, "%i\n\r",TCP_PORT_LISTENER ); @@ -562,6 +567,7 @@ if ( bufret == 1 ) { static unsigned int promptcb_last_ext = 0; static unsigned int promptcb_last_port = 0; + static char promptcb_last_cmd[ 300 ]; if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) ".",1 )) { miss_match = false; strcpy( debug_buf, last_debug_buf ); @@ -610,65 +616,85 @@ 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"); - set_header_ext( debug_buf + 7); + /* + fip = fopen("/qspi/myext.txt", "w"); + fprintf(fip, "%s\n\r" , ( debug_buf + 7) ); + fclose(fip); + pc.printf("\n\r"); + */ + set_header_ext( atoi( debug_buf + 7 ) ); files('s'); } if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serextset ", 10 ) ){ miss_match = false; + /* fip = fopen("/qspi/peerext.txt", "w"); fprintf(fip, "%i\n\r" , ( debug_buf + 10 ) ); fclose(fip); pc.printf("\n\r"); + */ + set_server_ext( atoi( debug_buf + 10 ) ); files('s'); } if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "maskset ",8 ) ){ miss_match = false; + /* fmask = fopen("/qspi/mymask.txt", "w"); fprintf(fmask,"%s\n\r",(debug_buf+8)); fclose(fmask); pc.printf("\n\r"); + */ + set_mask( debug_buf + 8 ); files('s'); } if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "gatewayset ",11 ) ){ miss_match = false; + /* fgate = fopen("/qspi/mygate.txt", "w"); fprintf(fgate,"%s\n\r",(debug_buf+11)); fclose(fgate); pc.printf("\n\r"); + */ + set_gateway( debug_buf + 11 ); files('s'); } if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "msipport ",9 ) ){ miss_match = false; + /* fport = fopen("/qspi/mysipport.txt", "w"); fprintf(fport,"%i\n\r",(debug_buf+9)); fclose(fport); pc.printf("\n\r"); + */ + set_header_sip_port( atoi( debug_buf + 9 ) ); files('s'); } if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "serverip ",9 ) ){ miss_match = false; + /* fsip = fopen("/qspi/serverip.txt", "w"); fprintf(fsip,"%s\n\r",(debug_buf+9)); fclose(fsip); pc.printf("\n\r"); + */ + set_server_ip( debug_buf + 9 ); files('s'); } if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "ssport ",7 ) ){ miss_match = false; + /* fsport = fopen("/qspi/serverport.txt", "w"); fprintf(fsport,"%i\n\r",(debug_buf+7)); fclose(fsport); pc.printf("\n\r"); + */ + set_server_port( atoi( debug_buf + 7 ) ); files('s'); } @@ -889,6 +915,7 @@ promptcb_last_ext = ext; promptcb_last_port = port; + strcpy( promptcb_last_cmd, cmd ); 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 ) ); @@ -1254,7 +1281,7 @@ ext = atoi( debug_buf + 7 ); port = convert_ext_to_port( ext ); - strcat( cmd, ( ext % 2 ) ? "B" : "A" ); + strcat( cmd, ( ext % 2 ) ? "B\n\r" : "A\n\r" ); promptcb_last_ext = ext; promptcb_last_port = port; @@ -1327,14 +1354,50 @@ } } -void set_ip( char * new_ip ){ +void set_ip( char * new_header_ip ){ fip = fopen("/qspi/myip.txt", "w"); - fprintf( fip, "%s\n\r", new_ip ); + fprintf( fip, "%s\n\r", new_header_ip ); fclose( fip ); } -void set_header_ext( char * new_header_ext ){ +void set_header_ext( int new_header_ext ){ fext = fopen( "/qspi/myext.txt", "w" ); - fprintf( fext, "%i\n\r", new_header_ext ); //myext + 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 ); } \ No newline at end of file