![](/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: main.cpp
- Revision:
- 83:b8a1d8fdeaeb
- Parent:
- 82:f55d13babca0
- Child:
- 84:b64f0e3b283e
--- a/main.cpp Tue Dec 30 21:00:00 2014 +0000 +++ b/main.cpp Fri Jan 02 18:38:39 2015 +0000 @@ -119,6 +119,8 @@ uint16_t pkg_wdt = RX_CB_IDLE; uint16_t eth_wdt = ETH_CONNECT_TIMEOUT; + uint32_t uptime = 0; + send_msg("Ready"); /*------------------------------------------ main loop ---------------------------------------------------------------*/ @@ -542,7 +544,7 @@ if( debug_main ) debug_msg("Added CBx -- %d", ext ); } cb->registry(); - //FIXME mandar um pacote do tipo 2 pro cbx precis + //FIXME mandar um pacote do tipo 2 pro cbx ? telemetry_counter++; if( debug_telemetry ) send_msg("::Telemetry from %d - %d::", ext, port ); build_telemetry_report( ext, port, ( char *)data ); @@ -692,19 +694,37 @@ if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; - if( wdt_timer.read() > 1 ){ - char wake_msg[ 8 ]; - + if( wdt_timer.read() >= 1 ){ + char wake_msg[ 48 ]; + uptime++; int read = udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) ); if( read > 0 ){ if( !( strncmp( wake_msg, "alive", 5 ) ) ){ - external_wdt = EXTERN_WDT_IDLE; - strcpy( wake_msg, "wakeup" ); - while( !( udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ) ) ); + // Just ckeck but not set 'alive?' + // Ckecking and set 'alive' + if( wake_msg[ 5 ] != '?' ) { + external_wdt = EXTERN_WDT_IDLE; + } + snprintf( wake_msg, 48,"wdt:%u,%u,%c:", uptime, invite_counter, ( wdt.WatchdogCausedReset() ) ? '1' : '0' ); + wake_msg[ 48 - 1 ] = 0; + int sent = 0; +// do{ + sent = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); +// }while( sent == 0 ); + + if( wdt_show ) send_msg( "Sent %d bytes in response", sent ); + }else if( !( strncmp( wake_msg, "reset", 5 ) ) ){ + external_wdt = 0; + + sprintf( wake_msg, "rst:%u:", uptime ); + int sent = 0; + sent = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); + + if( wdt_show ) send_msg( "Sent %d bytes in response", sent ); } } - if( debug_wdt ) if( read < 0 ) debug_msg( "some's wrong ... some's wrong" ); + if( wdt_show ) if( read < 0 ) debug_msg( "some's wrong ... some's wrong" ); wdt_timer.reset();