![](/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: vz_protocol.cpp
- Revision:
- 81:3656f00ab3db
- Parent:
- 79:9bc12aa305a9
- Child:
- 85:b6f2dc1d0f4f
diff -r 61d61c9eb75c -r 3656f00ab3db vz_protocol.cpp --- a/vz_protocol.cpp Tue Dec 16 19:34:30 2014 +0000 +++ b/vz_protocol.cpp Tue Dec 30 12:37:40 2014 +0000 @@ -3,29 +3,48 @@ uint32_t pkg_ckserr = 0; uint32_t pkg_zero = 0; uint32_t pkg_cksok = 0; +int begin = 0; +int end = 0; + +void init_ranges( void ){ + FILE * begin_ext = fopen( "/qspi/minext.txt", "r" ); + if( begin_ext == NULL ){ + if( debug_out_of_range ) debug_msg("Failed to open /qspi/minext.txt" ); + begin = MIN_EXT; + }else{ + char inner_tmp[ 20 ]; + if( fread( (void *)inner_tmp, 1, 20, begin_ext ) > 0 ){ + begin = atoi( inner_tmp ); + if( debug_out_of_range ) debug_msg("Ext Min %d", begin ); + }else{ + if( debug_out_of_range ) debug_msg("Failed to read /qspi/minext.txt" ); + begin = MIN_EXT; + } + } + fclose( begin_ext ); + + FILE * end_ext = fopen( "/qspi/maxext.txt", "r" ); + if( end_ext == NULL ){ + if( debug_out_of_range ) debug_msg("Failed to open /qspi/maxext.txt" ); + end = MAX_EXT; + }else{ + char inner_tmp[ 20 ]; + if( fread( (void *)inner_tmp, 1, 20, end_ext ) > 0 ){ + end = atoi( inner_tmp ); + if( debug_out_of_range ) debug_msg("Ext Min %d", end ); + }else{ + if( debug_out_of_range ) debug_msg("Failed to read /qspi/maxext.txt" ); + begin = MAX_EXT; + } + } + fclose( begin_ext ); +} uint8_t * __parse_vz_pkg__( int * ext, int * port, volatile uint8_t * type, uint8_t * cb_buffer ){ uint8_t p_lsb, p_msb; uint8_t e_lsb, e_msb; - if( cb_buffer == NULL ) return( NULL ); - - /* - if( cb_buffer[ 6 ] == __TELEMETRY__ ){ - if( debug_telemetry ){ - pc.printf("\n\r Original package\n\r"); - pc.printf("\n\r 1. "); - uint8_t count = 2; - for( register int i = 0; i < __CB_BUFFER_SIZE__; i++ ){ - if( i > 0 && !( i % 15 ) ) pc.printf("\n\r%2i. ", count++ ); - pc.printf("%3x ", cb_buffer[ i ] ); - } - pc.printf("\n\r"); - - if( tcp_session ) tcp_client.send_all( ( char *)cb_buffer, __CB_BUFFER_SIZE__ ); - } - } - */ + if( ( ext && port && type && cb_buffer ) == NULL ) return( NULL ); if( cb_buffer[ 6 ] == __FLOOD__ ){ flood_counter++; @@ -107,12 +126,13 @@ e_lsb = cb_buffer[ 1 ]; *ext = e_msb << 8 | e_lsb; - //restriçao de controle para cbx malucos - if( *ext < MIN_EXT || *ext > MAX_EXT ){ + //restriçao de controle para cbx malucos + if( *ext < begin || *ext > end ){ + if( debug_out_of_range ) send_msg("Trying from %d", *ext ); out_of_range++; return( NULL ); } - + p_msb = cb_buffer[ 2 ]; p_lsb = cb_buffer[ 3 ]; *port = p_msb << 8 | p_lsb;