![](/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: fw_handler.cpp
- Revision:
- 132:05cd37f7e007
- Parent:
- 126:1f90756250fb
--- a/fw_handler.cpp Tue Jul 21 20:03:35 2015 +0000 +++ b/fw_handler.cpp Tue Sep 01 17:21:11 2015 +0000 @@ -4,82 +4,52 @@ Endpoint fw_server; uint16_t miss_fw_send_pkg = 0; -int init_fw_handler( void ){ - char buff_ip[ 16 ] = ""; - char buff_port[ 8 ] = ""; - int fw_port = 0; - - FILE *fip = fopen( "/qspi/fw_ip.txt", "r"); - if( fip == NULL ){ - if( debug_file || debug_reconnect ) send_msg ("Failed to open /qspi/fw_ip.txt" ); - strncpy( buff_ip, __FW_SERVER_IP__, 20 ); - }else{ - int read = fread( buff_ip, 1, 512, fip ); - if( read > 0 ){ - for( int i = 0; i < read; i++ ) - if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){ - buff_ip[ i ] = '\0'; - break; - } - if( debug_file || debug_reconnect ) send_msg ("fw server ip %s", buff_ip ); - }else{ - if( debug_file || debug_reconnect ) send_msg ("Failed to open /qspi/fw_ip.txt" ); - strncpy( buff_ip, __FW_SERVER_IP__, 20 ); - } - } +int init_fw_handler ( void ) +{ + char buffer_fw_server_ip [ 16 ] = ""; + + cm -> get_fw_server_ip ( buffer_fw_server_ip ); + + int addr = fw_server.set_address ( buffer_fw_server_ip , ( int ) cm -> get_fw_server_port () ); - if( fip != NULL ) fclose( fip ); + if ( debug_fw ) vz_printf (" Valor de retorno set_address -- %d ", addr ); - FILE * fport = fopen( "/qspi/fw_port.txt", "r"); + int bind = fw_sock.bind ( __FW_HEADER_PORT__ ); - if( fport == NULL ) { - if( debug_fw || debug_reconnect ) send_msg ("Failed to open /qspi/fw_port.txt" ); - fw_port = __FW_SERVER_PORT__; - } else { - if( fread ( (void *) buff_port, 1, 32, fport ) > 0 ) - { - fw_port = atoi ( buff_port ); - if( debug_fw || debug_reconnect ) send_msg ( "fw server port %d", fw_port ); - } else { - if( debug_fw || debug_reconnect ) send_msg ( "Failed to read /qspi/fw_port.txt" ); - fw_port = __FW_SERVER_PORT__; - } - } + fw_sock.set_blocking ( false, 0 ); - if( fport != NULL ) fclose( fport ); - - int addr = fw_server.set_address( buff_ip , fw_port ); - if( debug_fw ) send_msg(" Valor de retorno set_address -- %d ", addr ); - fw_sock.set_blocking( false, 0 ); - int bind = fw_sock.bind( __FW_HEADER_PORT__ ); - if( debug_fw ) send_msg(" Valor de retorno bind -- %d ", bind ); + if( debug_fw ) vz_printf (" Valor de retorno bind -- %d ", bind ); return ( 0 ); } -void re_start_fw( void ){ - int close = fw_sock.close(); - if( debug_fw || debug_reconnect ) send_msg (" Valor de retorno close-- %d ", close ); +void re_start_fw ( void ) +{ + int close = fw_sock.close (); + if ( debug_fw || debug_reconnect ) vz_printf (" Valor de retorno close-- %d ", close ); - init_fw_handler(); + init_fw_handler (); } void fw_cbx_pkg ( const int ext, char * data ) { - static uint8_t fw_cbx_pkg_id = 0x00; - - data [ CB_BUFFER_SIZE - 1 ] = fw_cbx_pkg_id++; - - int send = fw_sock.sendTo ( fw_server, data, CB_BUFFER_SIZE ); - - if( send != CB_BUFFER_SIZE ) + if ( data not_eq NULL ) { - if( debug_reconnect ) + static uint8_t fw_cbx_pkg_id = 0x00; + + data [ CB_BUFFER_SIZE - 1 ] = fw_cbx_pkg_id ++; + + int send = fw_sock.sendTo ( fw_server, data, CB_BUFFER_SIZE ); + + if ( send not_eq CB_BUFFER_SIZE ) { - send_msg("[%d] Reconnect FW - %d", ext, send ); + if ( debug_reconnect ) + { + vz_printf ( "[%d] Reconnect FW - %d", ext, send ); + } + + miss_fw_send_pkg ++; + re_start_fw (); } - - miss_fw_send_pkg++; - re_start_fw(); } } \ No newline at end of file