![](/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: power_source_monitoring.cpp
- Revision:
- 128:3ae1c74773a8
- Child:
- 132:05cd37f7e007
diff -r e7160a463b6c -r 3ae1c74773a8 power_source_monitoring.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/power_source_monitoring.cpp Mon May 25 13:11:00 2015 +0000 @@ -0,0 +1,52 @@ +#include "power_source_monitoring.h" + +Timer pwr_src_timer; +DigitalIn pwr_src_in(p25, PullDown); +UDPSocket pwr_src_client; +Endpoint pwr_src_server; +uint8_t pwr_src_status = 0; +//extern const char SERVER_IP[]; // definido em vz_protocol.h + +/* Inicializacao da comunicacao UDP com o servidor para monitoramento de fonte de alimentacao */ +int init_pwr_src() { + FILE * fpwr = NULL; + char server_ip[16]; + + /* Inicializacao do timer de leitura de fonte de alimentacao */ + pwr_src_timer.stop(); + pwr_src_timer.reset(); + + /* Inicializacao do comunicacao UDP */ + pwr_src_client.set_blocking( false, 0 ); + pwr_src_client.bind( PWR_SRC_PORT ); + + fpwr = fopen( "/qspi/serverip.txt", "r"); + if( fpwr == NULL) { + if( debug_pwr_src ) debug_msg("Failed to open /qspi/serverip.txt"); + strncpy( server_ip, SERVER_IP, 20 ); + } else { + char tmp[ 16 ] = "\0"; + int read = fread( tmp, 1, 15, fpwr ); + if( read > 0 ){ + for( int i = 0; i < read; i++ ) + if( tmp[ i ] == '\n' || tmp[ i ] == '\r' ){ + tmp[ i ] = '\0'; + break; + } + strcpy( server_ip, tmp ); + if( debug_pwr_src ) debug_msg("ip server%s( read %d chars ), valid %d", server_ip, read, strlen( server_ip ) ); + }else{ + if( debug_pwr_src ) debug_msg("Failed to read /qspi/serverip.txt"); + strncpy( server_ip, SERVER_IP, 20 ); + } + } + fclose( fpwr ); + server_ip[ 15 ] = '\0'; + + // Criar depois, se quiser, arquivo para PWR_SRC_PORT + + //strncpy( server_ip, "192.168.120.205\0", 16 ); + pwr_src_server.set_address( server_ip , PWR_SRC_PORT ); + + return ( 0 ); +} \ No newline at end of file