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:
- 104:62646ef786a3
- Parent:
- 100:09a23fcd3bdf
- Child:
- 105:a930035b6556
diff -r e3cabfc2f533 -r 62646ef786a3 fw_handler.cpp --- a/fw_handler.cpp Thu Feb 19 18:04:33 2015 +0000 +++ b/fw_handler.cpp Wed Feb 25 18:44:11 2015 +0000 @@ -2,6 +2,7 @@ UDPSocket fw_sock; Endpoint fw_server; +uint16_t miss_fw_send_pkg = 0; void init_fw_handler( void ){ char buff_ip[ 16 ] = ""; @@ -11,7 +12,7 @@ FILE *fp = fopen( "/qspi/fw_ip.txt", "r"); //debug_msg(""); if( fp == NULL ){ - if( debug_file ) debug_msg("Failed to open /qspi/fw_ip.txt" ); + if( debug_file | debug_reconnect ) debug_msg("Failed to open /qspi/fw_ip.txt" ); strncpy( buff_ip, __FW_SERVER_IP__, 20 ); //debug_msg(""); }else{ @@ -23,10 +24,10 @@ buff_ip[ i ] = '\0'; break; } - if( debug_file ) debug_msg("fw server ip %s", buff_ip ); + if( debug_file | debug_reconnect ) debug_msg("fw server ip %s", buff_ip ); //debug_msg(""); }else{ - if( debug_file ) debug_msg("Failed to open /qspi/fw_ip.txt" ); + if( debug_file | debug_reconnect ) debug_msg("Failed to open /qspi/fw_ip.txt" ); strncpy( buff_ip, __FW_SERVER_IP__, 20 ); //debug_msg(""); } @@ -35,32 +36,29 @@ //debug_msg(""); fp = fopen( "/qspi/fw_port.txt", "r"); if( fp == NULL ) { - if( debug_fw ) debug_msg("Failed to open /qspi/fw_port.txt" ); + if( debug_fw | debug_reconnect ) debug_msg("Failed to open /qspi/fw_port.txt" ); fw_port = __FW_SERVER_PORT__; } else { //debug_msg(""); if( fread( (void *)buff_port, 1, 32, fp ) > 0 ) { fw_port = atoi( buff_port ); - if( debug_fw ) send_msg( "fw server port %d", fw_port ); + if( debug_fw | debug_reconnect ) send_msg( "fw server port %d", fw_port ); } else { - if( debug_fw ) send_msg( "Failed to read /qspi/fw_port.txt" ); + if( debug_fw | debug_reconnect ) send_msg( "Failed to read /qspi/fw_port.txt" ); fw_port = __FW_SERVER_PORT__; } } - if( fp != NULL ) fclose( fp ); - //debug_msg(""); + if( fp != NULL ) fclose( fp ); int addr = fw_server.set_address( buff_ip , fw_port ); - if( debug_fw ) send_msg(" Valor de retorno set_address -- %d ", addr ); + if( debug_fw | debug_reconnect ) send_msg(" Valor de retorno set_address -- %d ", addr ); fw_sock.set_blocking( false, 0 ); - //debug_msg(""); int bind = fw_sock.bind( __FW_HEADER_PORT__ ); - if( debug_fw ) send_msg(" Valor de retorno bind -- %d ", bind ); - //debug_msg(""); + if( debug_fw | debug_reconnect ) send_msg(" Valor de retorno bind -- %d ", bind ); } void re_start_fw( void ){ int close = fw_sock.close(); - if( debug_fw ) send_msg(" Valor de retorno close-- %d ", close ); + if( debug_fw | debug_reconnect ) send_msg(" Valor de retorno close-- %d ", close ); init_fw_handler(); } @@ -69,8 +67,16 @@ static uint8_t fw_cbx_pkg_id = 0x00; data[ __CB_BUFFER_SIZE__ - 1 ] = fw_cbx_pkg_id++; - int8_t sent = 0; - do{ - sent = fw_sock.sendTo( fw_server, data, __CB_BUFFER_SIZE__ ); - }while( sent == 0 ); + int send = fw_sock.sendTo( fw_server, data, __CB_BUFFER_SIZE__ ); + + if( send != __CB_BUFFER_SIZE__ ) + { + if( debug_reconnect ) + { + send_msg("Reconnect FW"); + } + + miss_fw_send_pkg++; + re_start_fw(); + } } \ No newline at end of file