![](/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
power_source_monitoring.cpp@128:3ae1c74773a8, 2015-05-25 (annotated)
- Committer:
- klauss
- Date:
- Mon May 25 13:11:00 2015 +0000
- Revision:
- 128:3ae1c74773a8
- Child:
- 132:05cd37f7e007
Merge com as funcionalidade de monitoramento de bateria
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 128:3ae1c74773a8 | 1 | #include "power_source_monitoring.h" |
klauss | 128:3ae1c74773a8 | 2 | |
klauss | 128:3ae1c74773a8 | 3 | Timer pwr_src_timer; |
klauss | 128:3ae1c74773a8 | 4 | DigitalIn pwr_src_in(p25, PullDown); |
klauss | 128:3ae1c74773a8 | 5 | UDPSocket pwr_src_client; |
klauss | 128:3ae1c74773a8 | 6 | Endpoint pwr_src_server; |
klauss | 128:3ae1c74773a8 | 7 | uint8_t pwr_src_status = 0; |
klauss | 128:3ae1c74773a8 | 8 | //extern const char SERVER_IP[]; // definido em vz_protocol.h |
klauss | 128:3ae1c74773a8 | 9 | |
klauss | 128:3ae1c74773a8 | 10 | /* Inicializacao da comunicacao UDP com o servidor para monitoramento de fonte de alimentacao */ |
klauss | 128:3ae1c74773a8 | 11 | int init_pwr_src() { |
klauss | 128:3ae1c74773a8 | 12 | FILE * fpwr = NULL; |
klauss | 128:3ae1c74773a8 | 13 | char server_ip[16]; |
klauss | 128:3ae1c74773a8 | 14 | |
klauss | 128:3ae1c74773a8 | 15 | /* Inicializacao do timer de leitura de fonte de alimentacao */ |
klauss | 128:3ae1c74773a8 | 16 | pwr_src_timer.stop(); |
klauss | 128:3ae1c74773a8 | 17 | pwr_src_timer.reset(); |
klauss | 128:3ae1c74773a8 | 18 | |
klauss | 128:3ae1c74773a8 | 19 | /* Inicializacao do comunicacao UDP */ |
klauss | 128:3ae1c74773a8 | 20 | pwr_src_client.set_blocking( false, 0 ); |
klauss | 128:3ae1c74773a8 | 21 | pwr_src_client.bind( PWR_SRC_PORT ); |
klauss | 128:3ae1c74773a8 | 22 | |
klauss | 128:3ae1c74773a8 | 23 | fpwr = fopen( "/qspi/serverip.txt", "r"); |
klauss | 128:3ae1c74773a8 | 24 | if( fpwr == NULL) { |
klauss | 128:3ae1c74773a8 | 25 | if( debug_pwr_src ) debug_msg("Failed to open /qspi/serverip.txt"); |
klauss | 128:3ae1c74773a8 | 26 | strncpy( server_ip, SERVER_IP, 20 ); |
klauss | 128:3ae1c74773a8 | 27 | } else { |
klauss | 128:3ae1c74773a8 | 28 | char tmp[ 16 ] = "\0"; |
klauss | 128:3ae1c74773a8 | 29 | int read = fread( tmp, 1, 15, fpwr ); |
klauss | 128:3ae1c74773a8 | 30 | if( read > 0 ){ |
klauss | 128:3ae1c74773a8 | 31 | for( int i = 0; i < read; i++ ) |
klauss | 128:3ae1c74773a8 | 32 | if( tmp[ i ] == '\n' || tmp[ i ] == '\r' ){ |
klauss | 128:3ae1c74773a8 | 33 | tmp[ i ] = '\0'; |
klauss | 128:3ae1c74773a8 | 34 | break; |
klauss | 128:3ae1c74773a8 | 35 | } |
klauss | 128:3ae1c74773a8 | 36 | strcpy( server_ip, tmp ); |
klauss | 128:3ae1c74773a8 | 37 | if( debug_pwr_src ) debug_msg("ip server%s( read %d chars ), valid %d", server_ip, read, strlen( server_ip ) ); |
klauss | 128:3ae1c74773a8 | 38 | }else{ |
klauss | 128:3ae1c74773a8 | 39 | if( debug_pwr_src ) debug_msg("Failed to read /qspi/serverip.txt"); |
klauss | 128:3ae1c74773a8 | 40 | strncpy( server_ip, SERVER_IP, 20 ); |
klauss | 128:3ae1c74773a8 | 41 | } |
klauss | 128:3ae1c74773a8 | 42 | } |
klauss | 128:3ae1c74773a8 | 43 | fclose( fpwr ); |
klauss | 128:3ae1c74773a8 | 44 | server_ip[ 15 ] = '\0'; |
klauss | 128:3ae1c74773a8 | 45 | |
klauss | 128:3ae1c74773a8 | 46 | // Criar depois, se quiser, arquivo para PWR_SRC_PORT |
klauss | 128:3ae1c74773a8 | 47 | |
klauss | 128:3ae1c74773a8 | 48 | //strncpy( server_ip, "192.168.120.205\0", 16 ); |
klauss | 128:3ae1c74773a8 | 49 | pwr_src_server.set_address( server_ip , PWR_SRC_PORT ); |
klauss | 128:3ae1c74773a8 | 50 | |
klauss | 128:3ae1c74773a8 | 51 | return ( 0 ); |
klauss | 128:3ae1c74773a8 | 52 | } |