Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
fw_handler.cpp@137:32dd35a6dbc9, 2015-11-24 (annotated)
- Committer:
- klauss
- Date:
- Tue Nov 24 14:06:22 2015 +0000
- Revision:
- 137:32dd35a6dbc9
- Parent:
- 132:05cd37f7e007
core source of the .bin (09/21/2015) in the field
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 122:480c44b0e205 | 1 | #include "fw.h" |
klauss | 99:e80850c51106 | 2 | |
klauss | 99:e80850c51106 | 3 | UDPSocket fw_sock; |
klauss | 99:e80850c51106 | 4 | Endpoint fw_server; |
klauss | 119:ee6a53069455 | 5 | uint16_t miss_fw_send_pkg = 0; |
klauss | 99:e80850c51106 | 6 | |
klauss | 132:05cd37f7e007 | 7 | int init_fw_handler ( void ) |
klauss | 132:05cd37f7e007 | 8 | { |
klauss | 132:05cd37f7e007 | 9 | char buffer_fw_server_ip [ 16 ] = ""; |
klauss | 132:05cd37f7e007 | 10 | |
klauss | 132:05cd37f7e007 | 11 | cm -> get_fw_server_ip ( buffer_fw_server_ip ); |
klauss | 132:05cd37f7e007 | 12 | |
klauss | 132:05cd37f7e007 | 13 | int addr = fw_server.set_address ( buffer_fw_server_ip , ( int ) cm -> get_fw_server_port () ); |
klauss | 126:1f90756250fb | 14 | |
klauss | 132:05cd37f7e007 | 15 | if ( debug_fw ) vz_printf (" Valor de retorno set_address -- %d ", addr ); |
klauss | 124:c1b6c893e1c3 | 16 | |
klauss | 132:05cd37f7e007 | 17 | int bind = fw_sock.bind ( __FW_HEADER_PORT__ ); |
klauss | 125:8ff4dc96ad58 | 18 | |
klauss | 132:05cd37f7e007 | 19 | fw_sock.set_blocking ( false, 0 ); |
klauss | 126:1f90756250fb | 20 | |
klauss | 132:05cd37f7e007 | 21 | if( debug_fw ) vz_printf (" Valor de retorno bind -- %d ", bind ); |
klauss | 119:ee6a53069455 | 22 | |
klauss | 119:ee6a53069455 | 23 | return ( 0 ); |
klauss | 99:e80850c51106 | 24 | } |
klauss | 99:e80850c51106 | 25 | |
klauss | 132:05cd37f7e007 | 26 | void re_start_fw ( void ) |
klauss | 132:05cd37f7e007 | 27 | { |
klauss | 132:05cd37f7e007 | 28 | int close = fw_sock.close (); |
klauss | 132:05cd37f7e007 | 29 | if ( debug_fw || debug_reconnect ) vz_printf (" Valor de retorno close-- %d ", close ); |
klauss | 99:e80850c51106 | 30 | |
klauss | 132:05cd37f7e007 | 31 | init_fw_handler (); |
klauss | 99:e80850c51106 | 32 | } |
klauss | 99:e80850c51106 | 33 | |
klauss | 126:1f90756250fb | 34 | void fw_cbx_pkg ( const int ext, char * data ) |
klauss | 126:1f90756250fb | 35 | { |
klauss | 132:05cd37f7e007 | 36 | if ( data not_eq NULL ) |
klauss | 119:ee6a53069455 | 37 | { |
klauss | 132:05cd37f7e007 | 38 | static uint8_t fw_cbx_pkg_id = 0x00; |
klauss | 132:05cd37f7e007 | 39 | |
klauss | 132:05cd37f7e007 | 40 | data [ CB_BUFFER_SIZE - 1 ] = fw_cbx_pkg_id ++; |
klauss | 132:05cd37f7e007 | 41 | |
klauss | 132:05cd37f7e007 | 42 | int send = fw_sock.sendTo ( fw_server, data, CB_BUFFER_SIZE ); |
klauss | 132:05cd37f7e007 | 43 | |
klauss | 132:05cd37f7e007 | 44 | if ( send not_eq CB_BUFFER_SIZE ) |
klauss | 119:ee6a53069455 | 45 | { |
klauss | 132:05cd37f7e007 | 46 | if ( debug_reconnect ) |
klauss | 132:05cd37f7e007 | 47 | { |
klauss | 132:05cd37f7e007 | 48 | vz_printf ( "[%d] Reconnect FW - %d", ext, send ); |
klauss | 132:05cd37f7e007 | 49 | } |
klauss | 132:05cd37f7e007 | 50 | |
klauss | 132:05cd37f7e007 | 51 | miss_fw_send_pkg ++; |
klauss | 132:05cd37f7e007 | 52 | re_start_fw (); |
klauss | 119:ee6a53069455 | 53 | } |
klauss | 119:ee6a53069455 | 54 | } |
klauss | 99:e80850c51106 | 55 | } |