![](/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
fw_handler.cpp@125:8ff4dc96ad58, 2015-05-13 (annotated)
- Committer:
- klauss
- Date:
- Wed May 13 21:18:12 2015 +0000
- Revision:
- 125:8ff4dc96ad58
- Parent:
- 124:c1b6c893e1c3
- Child:
- 126:1f90756250fb
Implementado; - dtx [ on | off ]; - drx [ on | off ]; - drxshow [ on | off ]; - dtxshow [ on | off ]; - end_call <ext>; - request_clock
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 | 119:ee6a53069455 | 7 | int init_fw_handler( void ){ |
klauss | 99:e80850c51106 | 8 | char buff_ip[ 16 ] = ""; |
klauss | 99:e80850c51106 | 9 | char buff_port[ 8 ] = ""; |
klauss | 99:e80850c51106 | 10 | int fw_port = 0; |
klauss | 99:e80850c51106 | 11 | |
klauss | 125:8ff4dc96ad58 | 12 | FILE *fip = fopen( "/qspi/fw_ip.txt", "r"); |
klauss | 125:8ff4dc96ad58 | 13 | if( fip == NULL ){ |
klauss | 119:ee6a53069455 | 14 | if( debug_file || debug_reconnect ) send_msg ("Failed to open /qspi/fw_ip.txt" ); |
klauss | 99:e80850c51106 | 15 | strncpy( buff_ip, __FW_SERVER_IP__, 20 ); |
klauss | 99:e80850c51106 | 16 | }else{ |
klauss | 125:8ff4dc96ad58 | 17 | int read = fread( buff_ip, 1, 512, fip ); |
klauss | 99:e80850c51106 | 18 | if( read > 0 ){ |
klauss | 99:e80850c51106 | 19 | for( int i = 0; i < read; i++ ) |
klauss | 99:e80850c51106 | 20 | if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){ |
klauss | 99:e80850c51106 | 21 | buff_ip[ i ] = '\0'; |
klauss | 99:e80850c51106 | 22 | break; |
klauss | 99:e80850c51106 | 23 | } |
klauss | 119:ee6a53069455 | 24 | if( debug_file || debug_reconnect ) send_msg ("fw server ip %s", buff_ip ); |
klauss | 99:e80850c51106 | 25 | }else{ |
klauss | 119:ee6a53069455 | 26 | if( debug_file || debug_reconnect ) send_msg ("Failed to open /qspi/fw_ip.txt" ); |
klauss | 99:e80850c51106 | 27 | strncpy( buff_ip, __FW_SERVER_IP__, 20 ); |
klauss | 99:e80850c51106 | 28 | } |
klauss | 99:e80850c51106 | 29 | } |
klauss | 125:8ff4dc96ad58 | 30 | if( fip != NULL ) fclose( fip ); |
klauss | 124:c1b6c893e1c3 | 31 | |
klauss | 125:8ff4dc96ad58 | 32 | FILE * fport = fopen( "/qspi/fw_port.txt", "r"); |
klauss | 125:8ff4dc96ad58 | 33 | |
klauss | 125:8ff4dc96ad58 | 34 | if( fport == NULL ) { |
klauss | 119:ee6a53069455 | 35 | if( debug_fw || debug_reconnect ) send_msg ("Failed to open /qspi/fw_port.txt" ); |
klauss | 99:e80850c51106 | 36 | fw_port = __FW_SERVER_PORT__; |
klauss | 99:e80850c51106 | 37 | } else { |
klauss | 125:8ff4dc96ad58 | 38 | if( fread ( (void *) buff_port, 1, 32, fport ) > 0 ) |
klauss | 125:8ff4dc96ad58 | 39 | { |
klauss | 125:8ff4dc96ad58 | 40 | fw_port = atoi ( buff_port ); |
klauss | 119:ee6a53069455 | 41 | if( debug_fw || debug_reconnect ) send_msg ( "fw server port %d", fw_port ); |
klauss | 99:e80850c51106 | 42 | } else { |
klauss | 119:ee6a53069455 | 43 | if( debug_fw || debug_reconnect ) send_msg ( "Failed to read /qspi/fw_port.txt" ); |
klauss | 99:e80850c51106 | 44 | fw_port = __FW_SERVER_PORT__; |
klauss | 99:e80850c51106 | 45 | } |
klauss | 99:e80850c51106 | 46 | } |
klauss | 125:8ff4dc96ad58 | 47 | if( fport != NULL ) fclose( fport ); |
klauss | 125:8ff4dc96ad58 | 48 | |
klauss | 99:e80850c51106 | 49 | int addr = fw_server.set_address( buff_ip , fw_port ); |
klauss | 114:472502b31a12 | 50 | if( debug_fw ) send_msg(" Valor de retorno set_address -- %d ", addr ); |
klauss | 99:e80850c51106 | 51 | fw_sock.set_blocking( false, 0 ); |
klauss | 99:e80850c51106 | 52 | int bind = fw_sock.bind( __FW_HEADER_PORT__ ); |
klauss | 114:472502b31a12 | 53 | if( debug_fw ) send_msg(" Valor de retorno bind -- %d ", bind ); |
klauss | 119:ee6a53069455 | 54 | |
klauss | 119:ee6a53069455 | 55 | return ( 0 ); |
klauss | 99:e80850c51106 | 56 | } |
klauss | 99:e80850c51106 | 57 | |
klauss | 99:e80850c51106 | 58 | void re_start_fw( void ){ |
klauss | 99:e80850c51106 | 59 | int close = fw_sock.close(); |
klauss | 119:ee6a53069455 | 60 | if( debug_fw || debug_reconnect ) send_msg (" Valor de retorno close-- %d ", close ); |
klauss | 99:e80850c51106 | 61 | |
klauss | 99:e80850c51106 | 62 | init_fw_handler(); |
klauss | 99:e80850c51106 | 63 | } |
klauss | 99:e80850c51106 | 64 | |
klauss | 99:e80850c51106 | 65 | void fw_cbx_pkg( int ext, int port, char * data ){ |
klauss | 99:e80850c51106 | 66 | static uint8_t fw_cbx_pkg_id = 0x00; |
klauss | 119:ee6a53069455 | 67 | data[ CB_BUFFER_SIZE - 1 ] = fw_cbx_pkg_id++; |
klauss | 99:e80850c51106 | 68 | |
klauss | 119:ee6a53069455 | 69 | int send = fw_sock.sendTo( fw_server, data, CB_BUFFER_SIZE ); |
klauss | 119:ee6a53069455 | 70 | |
klauss | 119:ee6a53069455 | 71 | if( send != CB_BUFFER_SIZE ) |
klauss | 119:ee6a53069455 | 72 | { |
klauss | 119:ee6a53069455 | 73 | if( debug_reconnect ) |
klauss | 119:ee6a53069455 | 74 | { |
klauss | 119:ee6a53069455 | 75 | send_msg("[%d] Reconnect FW - %d", ext, send ); |
klauss | 119:ee6a53069455 | 76 | } |
klauss | 119:ee6a53069455 | 77 | |
klauss | 119:ee6a53069455 | 78 | miss_fw_send_pkg++; |
klauss | 119:ee6a53069455 | 79 | re_start_fw(); |
klauss | 119:ee6a53069455 | 80 | } |
klauss | 99:e80850c51106 | 81 | } |