![](/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: main_app_functions.cpp
- Revision:
- 126:1f90756250fb
- Parent:
- 125:8ff4dc96ad58
- Child:
- 127:e7160a463b6c
--- a/main_app_functions.cpp Wed May 13 21:18:12 2015 +0000 +++ b/main_app_functions.cpp Wed May 20 19:50:31 2015 +0000 @@ -37,8 +37,9 @@ send_msg( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] ); } - short int eth_status = __init_eth__ (); - if( eth_status ) { + eth_status = __init_eth__ (); + if ( eth_status ) + { send_msg("******* Cannot connect to eth *******"); } else { send_msg("******* Connection eth - ok *******"); @@ -48,7 +49,7 @@ if ( init_prompt_eth_ret == BIT1 ) send_msg("******* Prompt eth TCP Ready *******"); - if ( debug_app_init ) send_msg ( "init_prompt_eth() :: %s", ( init_prompt_eth_ret == ( BIT0 | BIT1 ) ) ? "Ok" : "Failure" ); + if ( debug_app_init ) send_msg ( "init_prompt_eth() :: %s", ( init_prompt_eth_ret == ( BIT0 bitor BIT1 ) ) ? "Ok" : "Failure" ); if ( debug_app_init ) send_msg ( "init_external_wdt() :: %s", ( init_external_wdt () == 0 ) ? "Ok" : "Failure" ); @@ -82,7 +83,7 @@ } } - if ( debug_app_init ) send_msg ( "v_cb :: %s", ( v_cb != NULL ) ? "Ok" : "Failure" ); + if ( debug_app_init ) send_msg ( "v_cb :: %s", ( v_cb not_eq NULL ) ? "Ok" : "Failure" ); v_call = new Vector(); if( v_call == NULL ) { @@ -95,7 +96,7 @@ } } - if ( debug_app_init ) send_msg ( "v_call :: %s", ( v_call != NULL ) ? "Ok" : "Failure" ); + if ( debug_app_init ) send_msg ( "v_call :: %s", ( v_call not_eq NULL ) ? "Ok" : "Failure" ); ts = new Timeslice(); if( ts == NULL ) { @@ -103,7 +104,7 @@ if( debug_memory ) send_msg("TS allocation fail"); } - if ( debug_app_init ) send_msg ( "TS :: %s", ( ts != NULL ) ? "Ok" : "Failure" ); + if ( debug_app_init ) send_msg ( "TS :: %s", ( ts not_eq NULL ) ? "Ok" : "Failure" ); for( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) { cb_rx_buffer[ i ] = 0; @@ -142,6 +143,8 @@ if ( debug_app_init ) send_msg ( "init_hello () :: %s", ( init_hello () == 0 ) ? "Ok" : "Failure" ); + test_ts_timer.start (); + send_msg ( "" ); return ( 0 ); @@ -152,7 +155,8 @@ { eth_status = __init_eth__(); - if( eth_status ) { + if ( eth_status ) + { send_msg("******* Cannot connect to eth *******"); } else { send_msg("******* Connection eth - ok *******"); @@ -162,7 +166,7 @@ if ( init_prompt_eth_ret == BIT1 ) send_msg("******* Prompt eth TCP Ready *******"); - if ( debug_app_init ) send_msg ( "init_prompt_eth() :: %s", ( init_prompt_eth_ret == ( BIT0 | BIT1 ) ) ? "Ok" : "Failure" ); + if ( debug_app_init ) send_msg ( "init_prompt_eth() :: %s", ( init_prompt_eth_ret == ( BIT0 bitor BIT1 ) ) ? "Ok" : "Failure" ); if ( debug_app_init ) send_msg ( "init_external_wdt() :: %s", ( init_external_wdt() == 0 ) ? "Ok" : "Failure" ); @@ -255,7 +259,7 @@ for( i = 0; i < v_cb->size() - 1; i++ ) { sprintf( aux, "%i, ", ext_list[ i ] ); strcat( str, aux ); - if( ( i != 0 ) && !( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " ); + if( ( i not_eq 0 ) and not( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " ); } sprintf( aux, "%i ", ext_list[ i ] ); strcat( str, aux ); @@ -292,7 +296,7 @@ Call_Box * cb = find_CB( v_cb, ext_list[ i ] ); - if( cb != NULL ) + if( cb not_eq NULL ) { char cb_status[ 32 ]; char cb_sip_status[ 32 ]; @@ -370,7 +374,7 @@ cb->get_ext(), cb->get_port(), cb_status, cb_sip_status ); - if( cb->get_timeslice() != 0 ) + if( cb->get_timeslice() not_eq 0 ) { char aux[ 32 ]; snprintf ( aux, sizeof ( aux ), " -- on TimeSlice :: %i", cb->get_timeslice() ); @@ -489,7 +493,7 @@ cb->get_ext(), cb->get_port(), cb_status, cb_sip_status ); - if( cb->get_timeslice() != 0 ) + if( cb->get_timeslice() not_eq 0 ) { char aux[ 32 ]; snprintf ( aux, sizeof ( aux ), " -- on TimeSlice :: %i", cb->get_timeslice() ); @@ -595,11 +599,11 @@ udp_bl_timer.stop(); udp_bl_timer.reset(); bl_start_flag = 0; - if (bl_ts != 0) { + if (bl_ts not_eq 0) { ts->return_timeslice( bl_ts ); bl_ts = 0; } - if (bl_cb != NULL) { + if (bl_cb not_eq NULL) { bl_cb -> set_timeslice( 0 ); bl_cb -> cb_set_status ( cb_idle ); bl_cb = NULL; @@ -649,7 +653,7 @@ strncpy(bl_send_buffer + 2,"cbxdead\x00",8); int udp_bl_client_ret = udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, strlen( bl_send_buffer ) ); - if ( udp_bl_client_ret != strlen( bl_send_buffer ) ) + if ( udp_bl_client_ret not_eq strlen( bl_send_buffer ) ) { // TODO implementar os reconnects do bl } @@ -680,11 +684,11 @@ /* pacote para indicar o termino do processo de atualizacao */ else if (!(strncmp(bl_recv_buffer + 2,"finished",8))) { bl_start_flag = 0; - if (bl_ts != 0) { + if (bl_ts not_eq 0) { ts->return_timeslice( bl_ts ); bl_ts = 0; } - if (bl_cb != NULL) { + if (bl_cb not_eq NULL) { bl_cb->set_timeslice( 0 ); bl_cb -> cb_set_status( cb_idle ); bl_cb = NULL; @@ -699,7 +703,7 @@ /* neste momento a cabeceira sabe que o servidor se comunicou com o callbox */ if (!(strncmp(bl_recv_buffer + 2,"\x45",1))) { bl_cb = find_CB( v_cb, bl_peer ); - if (bl_cb != NULL) { + if (bl_cb not_eq NULL) { bl_cb->set_timeslice( bl_ts ); bl_cb -> cb_set_status ( cb_bootloader ); } @@ -709,7 +713,7 @@ if (!(strncmp(bl_recv_buffer + 2,"\x4f\x00\x00\x00",4))) { ts->return_timeslice( bl_ts ); bl_ts = 0; - if (bl_cb != NULL) { + if (bl_cb not_eq NULL) { bl_cb->set_timeslice( 0 ); } } @@ -730,7 +734,7 @@ } pc.printf("\r\n}"); } - if (bl_cb != NULL) { + if (bl_cb not_eq NULL) { bl_port = bl_cb->get_port(); } else { bl_port = bl_peer; @@ -830,7 +834,7 @@ wake_msg[ WAKE_MSG_SIZE - 1 ] = 0; int send = udp_wdt_client.sendTo ( udp_wdt_server, wake_msg, strlen( wake_msg ) ); - if( send != strlen( wake_msg ) ) + if( send not_eq strlen( wake_msg ) ) { if( debug_reconnect ) debug_msg("Reconnect Extern wdt (%d, %d)", send, strlen( wake_msg ) ); reconnect_extern_wdt_socket (); @@ -849,7 +853,7 @@ sprintf( wake_msg, "rst:%u:", uptime ); int send = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); - if( send != strlen( wake_msg ) ) + if( send not_eq strlen( wake_msg ) ) { if( debug_reconnect ) send_msg("Reconnect Extern wdt"); reconnect_extern_wdt_socket(); @@ -871,7 +875,7 @@ int show_cb_content ( void ) { Call_Box * cb = find_CB ( v_cb, print_this_cb ); - if ( cb != NULL ) + if ( cb not_eq NULL ) { cb -> print_yourself (); } @@ -901,7 +905,7 @@ { Call_Box * cb = (Call_Box *)v_cb->get_element( i ); - if ( cb != NULL ) + if ( cb not_eq NULL ) { cb -> print_yourself (); } @@ -931,7 +935,7 @@ for ( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = find_CB( v_cb, ext_list[ i ] ); - if( cb != NULL ) + if( cb not_eq NULL ) { send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", cb -> get_ext (), @@ -949,7 +953,7 @@ int fuck_rtp ( Vector * v_cb ) { Call_Box * cb = find_CB( v_cb, frtp_target ); - if ( cb != NULL ) + if ( cb not_eq NULL ) { cb -> set_rtp_port ( -1008789032 ); } @@ -965,7 +969,7 @@ { uint8_t * ptr = ( uint8_t * ) find_CB ( v_cb, print_hex_this_cb ); - if ( ptr != NULL ) + if ( ptr not_eq NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( Call_Box ); i++ ) @@ -974,7 +978,7 @@ if ( ( i % 32 ) == 0 ) { - if( i != 0 ) + if( i not_eq 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } @@ -1028,7 +1032,7 @@ { uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); - if ( ptr != NULL ) + if ( ptr not_eq NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( Call_Box ); i++ ) @@ -1037,7 +1041,7 @@ if ( ( i % 32 ) == 0 ) { - if( i != 0 ) + if( i not_eq 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } @@ -1093,7 +1097,7 @@ { Call_Box * cb = find_CB ( v_cb, print_this_sip ); - if ( cb != NULL ) + if ( cb not_eq NULL ) { if( cb -> sip_print_yourself () == -1 ) { @@ -1132,7 +1136,7 @@ { Call_Box * cb = (Call_Box *)v_cb->get_element( i ); - if ( cb != NULL ) + if ( cb not_eq NULL ) { if ( cb -> sip_print_yourself () == -1 ) { @@ -1166,12 +1170,12 @@ uint8_t * ptr = NULL; Call_Box * cb = find_CB ( v_cb, print_hex_this_sip ); - if( cb != NULL ) + if( cb not_eq NULL ) { ptr = ( uint8_t * ) cb -> get_sip (); } - if ( ptr != NULL ) + if ( ptr not_eq NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( Sip ); i++ ) @@ -1180,7 +1184,7 @@ if ( ( i % 32 ) == 0 ) { - if( i != 0 ) + if( i not_eq 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } @@ -1205,12 +1209,12 @@ print_hex_sip_var = false; Call_Box * cb = find_CB ( v_cb, print_hex_this_sip ); - if( cb != NULL ) + if( cb not_eq NULL ) { ptr = ( uint8_t * ) cb -> get_sip (); } - if ( ptr != NULL ) + if ( ptr not_eq NULL ) { bool finished = false; volatile int i = 0; @@ -1265,7 +1269,7 @@ for( register uint8_t i = 0; i < v_call->size(); i++ ) { VZ_call * call = ( VZ_call * )v_call->get_element( i ); - if( call != NULL ) + if( call not_eq NULL ) { send_msg("CBX ( %d, %d ) - Server ( %d, %d )", call->get_cb_ext(), @@ -1281,9 +1285,9 @@ int show_call ( void ) { - VZ_call * call = __find_Call__( v_call, print_this_call ); + VZ_call * call = find_Call ( v_call, print_this_call ); - if ( call != NULL ) + if ( call not_eq NULL ) { send_msg ("Values :: %p\r\n", ( void *) call ); call -> print_yourself (); @@ -1305,15 +1309,15 @@ int show_hex_call ( void ) { - VZ_call * call = __find_Call__( v_call, print_hex_this_call ); + VZ_call * call = find_Call ( v_call, print_hex_this_call ); uint8_t * ptr = NULL; - if( call != NULL ) + if( call not_eq NULL ) { ptr = ( uint8_t * ) call; } - if ( ptr != NULL ) + if ( ptr not_eq NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( VZ_call ); i++ ) @@ -1322,7 +1326,7 @@ if ( ( i % 32 ) == 0 ) { - if( i != 0 ) + if( i not_eq 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } @@ -1345,15 +1349,15 @@ ptr = NULL; - VZ_call * call = __find_Call__( v_call, print_hex_this_call ); + VZ_call * call = find_Call ( v_call, print_hex_this_call ); uint8_t * ptr = NULL; - if( call != NULL ) + if( call not_eq NULL ) { ptr = ( uint8_t * ) call; } - if ( ptr != NULL ) + if ( ptr not_eq NULL ) { bool finished = false; volatile int i = 0; @@ -1411,15 +1415,15 @@ int show_cb_rtp ( void ) { - VZ_call * call = __find_Call__( v_call, print_hex_this_rtp ); + VZ_call * call = find_Call ( v_call, print_hex_this_rtp ); uint8_t * ptr = NULL; - if( call != NULL ) + if( call not_eq NULL ) { ptr = ( uint8_t * ) call -> check_rtp (); } - if ( ptr != NULL ) + if ( ptr not_eq NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( RTP ); i++ ) @@ -1428,7 +1432,7 @@ if ( ( i % 32 ) == 0 ) { - if( i != 0 ) + if( i not_eq 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } @@ -1451,15 +1455,15 @@ ptr = NULL; - VZ_call * call = __find_Call__( v_call, print_hex_this_rtp ); + VZ_call * call = find_Call ( v_call, print_hex_this_rtp ); uint8_t * ptr = NULL; - if( call != NULL ) + if( call not_eq NULL ) { ptr = ( uint8_t * ) call -> check_rtp (); } - if ( ptr != NULL ) + if ( ptr not_eq NULL ) { bool finished = false; volatile int i = 0; @@ -1516,11 +1520,11 @@ int show_cb_hex_rtp ( void ) { - VZ_call * call = __find_Call__( v_call, print_this_rtp ); + VZ_call * call = find_Call ( v_call, print_this_rtp ); - if ( call != NULL ) + if ( call not_eq NULL ) { - if ( call -> check_rtp () != NULL ) + if ( call -> check_rtp () not_eq NULL ) { send_msg ("Values :: %p\r\n", ( void *) call -> check_rtp () ); call -> rtp_print_yourself (); @@ -1649,15 +1653,15 @@ bool need_retry = false; Call_Box * cb = NULL; - for ( register int i = 0; i < v_cb->size(); i++ ) + for ( register int i = 0; i < v_cb -> size (); i++ ) { retry_invite_pkg++; - if ( retry_invite_pkg >= v_cb->size() ) retry_invite_pkg = 0; + if ( retry_invite_pkg >= v_cb->size () ) retry_invite_pkg = 0; - cb = (Call_Box * )v_cb->get_element( i ); - if ( cb != NULL ) + cb = (Call_Box * )v_cb -> get_element ( i ); + if ( cb not_eq NULL ) { - if ( ( cb -> get_status () == cb_ringing ) || ( cb -> get_status () == cb_trying ) || ( cb -> get_status () == cb_on_call ) ) + if ( ( cb -> get_status () == cb_ringing ) or ( cb -> get_status () == cb_trying ) or ( cb -> get_status () == cb_on_call ) ) { need_retry = true; break; @@ -1667,29 +1671,29 @@ if ( need_retry ) { - if( cb->get_invite_response() == false ) + if ( cb -> get_invite_response () == false ) { - cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); + buffer [ TIMESLICE_PLACE ] = cb -> get_timeslice (); + + do_not_show_this_invite_pkg = true; + + send2callboxes ( build_cb_package ( cb -> get_ext (), cb -> get_port (), INVITE, ( char * )buffer, + cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); - buffer[ TIMESLICE_PLACE ] = cb->get_timeslice(); - - send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), INVITE, ( char * )buffer, - cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); - - if( debug_invite ) debug_msg("[%d] resend invite OK to Cbx : ( %d, %d )", cb->get_ext(), cb->get_ext(), cb->get_port() ); + //if ( debug_invite ) debug_msg ("[%d] resend invite OK to Cbx : ( %d, %d )", cb -> get_ext (), cb -> get_ext (), cb -> get_port () ); } - if ( __find_Call__( v_call, cb->get_ext () ) == NULL ) + if ( find_Call ( v_call, cb->get_ext () ) == NULL ) { - if ( ( ( cb -> get_status () == cb_ringing ) || ( cb -> get_status () == cb_trying ) ) ) + if ( ( ( cb -> get_status () == cb_ringing ) or ( cb -> get_status () == cb_trying ) ) ) { char rtp_src_tmp_write_buffer [ CB_BUFFER_SIZE ]; uint8_t rtp_dst_tmp_write_buffer [ CB_BUFFER_SIZE ]; - for ( register int i = 0; i < RTP_MSG_SIZE; i++ ) rtp_src_tmp_write_buffer [ i ] = 'U'; // 0x55 + for ( register int i = 0; i < RTP_MSG_SIZE; i++ ) rtp_src_tmp_write_buffer [ i ] = 0x00; - send2callboxes( build_cb_package( cb->get_ext (), cb->get_port (), AUDIO, + send2callboxes ( build_cb_package ( cb -> get_ext (), cb -> get_port (), AUDIO, rtp_src_tmp_write_buffer, AUDIO, RTP_MSG_SIZE, rtp_dst_tmp_write_buffer ) ); } else { if ( cb->get_invite_retry_count() == 0 ) @@ -1702,7 +1706,7 @@ if( call->get_cb_ext() == cb->get_ext() ) { v_call->remove_element( i ); - if( call != NULL ) delete( call ); + if( call not_eq NULL ) delete( call ); break; } } @@ -1720,18 +1724,21 @@ int check_audio_from_ast ( Vector * v_cb, Vector * v_call ) { - for( register uint8_t i = 0; i < v_call->size(); i++ ) { - VZ_call * call = ( VZ_call * )v_call->get_element( i ); - if ( call != NULL ) + for( register uint8_t i = 0; i < v_call->size(); i++ ) + { + VZ_call * call = ( VZ_call * ) v_call -> get_element ( i ); + if ( call not_eq NULL ) { int length = 0; - char * tmp = call->get_eth_message( &length ); - if( tmp != NULL ) { + char * tmp = call -> get_eth_message ( &length ); + if( tmp not_eq NULL ) + { int cb_port = 0xffff; - Call_Box * cb = find_CB( v_cb, call->get_cb_ext() ); + Call_Box * cb = find_CB ( v_cb, call -> get_cb_ext () ); - if( cb != NULL ) { - cb_port = cb->get_port(); + if( cb not_eq NULL ) + { + cb_port = cb -> get_port (); if ( drop_rtp_from_ast_pkg ) { @@ -1739,13 +1746,13 @@ } else { - uint8_t * pkg2cb = build_cb_package( call->get_cb_ext(), cb_port, AUDIO, + uint8_t * pkg2cb = build_cb_package ( call -> get_cb_ext (), cb_port, AUDIO, tmp, AUDIO, length, write_buffer ); send2callboxes( pkg2cb ); } - } else if( debug_main ) debug_msg("[%d] received missed package -- Type :: %i", ext, type ); + } else if ( debug_main ) debug_msg ("[%d] received missed package -- Type :: %i", ext, type ); } } } @@ -1755,21 +1762,24 @@ int wake_up_or_refresh_handler ( Vector * v_cb ) { - if( timer_sync_refresh.read_ms() > 250 ) { + int return_value = 0; + + if( timer_sync_refresh.read_ms() > 250 * 2 ) + { timer_sync_refresh.reset(); static uint8_t time_to_mode = TIME_TO_REFRESH; if ( time_to_mode == TIME_TO_REFRESH ){ time_to_mode = TIME_TO_WAKE_UP; - refresh ( v_cb ); + if ( !do_not_refresh ) return_value = refresh ( v_cb ); } else { time_to_mode = TIME_TO_REFRESH; if ( wake_all ) if ( v_call->size() == 0 ) wake_all_up ( v_cb ); } } - return ( 0 ); + return ( return_value ); } int check_sip_messages_from_ast ( Vector * v_cb, Vector * v_call ) @@ -1778,8 +1788,8 @@ int ext_to__be_removed = sip_manager( v_cb ); if( ext_to__be_removed > 0 ) { Call_Box * cb = find_CB( v_cb, ext_to__be_removed ); - if( cb != NULL ) { - //if( cb->status == cb_on_call ) // poderia ser if( cb->status != cb_idle ) ??? + if( cb not_eq NULL ) { + //if( cb->status == cb_on_call ) // poderia ser if( cb->status not_eq cb_idle ) ??? if ( cb -> get_status () == cb_on_call ) { buffer[ TIMESLICE_PLACE ] = 0; @@ -1807,13 +1817,13 @@ int check_for_runaways_ts ( Vector * v_cb, Timeslice * ts ) { - if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() != MAX_TIMESLICES ) ) { + if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() not_eq MAX_TIMESLICES ) ) { bool ts_reset = true; for( register uint8_t i = 0; i < v_cb->size(); i++ ) { uint16_t cb_status = ((Call_Box *)v_cb->get_element( i ))->get_status(); uint16_t cb_sip_status = ((Call_Box *)v_cb->get_element( i ))->get_sip_status(); - if ((cb_status != cb_idle) and (cb_sip_status != sip_idle)) { + if ((cb_status not_eq cb_idle) and (cb_sip_status not_eq sip_idle)) { ts_reset = false; break; } @@ -1883,7 +1893,7 @@ for ( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = (Call_Box *) v_cb->get_element (i); - if ( cb != NULL ) + if ( cb not_eq NULL ) { if ( ( cb->get_status () == cb_idle ) && ( cb->get_sip_status () == sip_idle ) && ( cb -> is_rtp_timer_timeout () ) ) { @@ -1903,6 +1913,7 @@ { pkg_wdt = RX_CB_IDLE; + // short path if ( buffer_from_cb_ptr [ TYPE_PLACE ] == AUDIO ) { xmemcpy ( buffer, buffer_from_cb_ptr, CB_BUFFER_SIZE ); @@ -1910,6 +1921,7 @@ missed_pkg--; } else + // long path { xmemcpy ( cb_rx_buffer, buffer_from_cb_ptr, CB_BUFFER_SIZE ); status = WAITING; @@ -1918,85 +1930,96 @@ if ( debug_show_rx_cpld ) { - char str[ 256 ]; - strcpy( str, "RX :: \n\r" ); + char str [ 256 ]; + strcpy ( str, "RX :: \n\r" ); - for( register uint16_t i = 0; i < 32; i++ ) + for ( register uint16_t i = 0; i < 32; i++ ) { - char tmp[ 16 ]; + char tmp [ 8 ]; sprintf ( tmp, "%02x ", cb_rx_buffer [ i ] ); - strcat( str, tmp ); + strcat ( str, tmp ); } strcat ( str, "\n\r " ); - send_msg( "%s", str ); + send_msg ( "%s", str ); } } data = parse_vz_pkg ( &ext, &port, &type, buffer ); - if( data != NULL ) + if ( data not_eq NULL ) { - if( min_ext == 0 ) min_ext = ext; + if ( min_ext == 0 ) min_ext = ext; - if( ext > max_ext ) max_ext = ext; + if ( ext > max_ext ) max_ext = ext; - if( ext < min_ext ) min_ext = ext; + if ( ext < min_ext ) min_ext = ext; - if( debug_fw ){ fw_cbx_pkg( ext, port, ( char *)buffer ); } + if ( debug_fw ) { fw_cbx_pkg ( ext, ( char *)buffer ); } - if( type == TELEMETRY ) telemetry_counter++; + if ( type == TELEMETRY ) + { + telemetry_counter++; + if ( debug_telemetry ) show_last_rx = true; + } - if( type != AUDIO ) { + if( type not_eq AUDIO ) { if( - type == TELEMETRY || - type == CB_STATS || - type == FW1 || - type == FW2 || - type == FW3 || - type == FW4 || - type == FW5 || + type == TELEMETRY or + type == CB_STATS or + type == FW1 or + type == FW2 or + type == FW3 or + type == FW4 or + type == FW5 or type == FW6 ) type = FW; - if( debug_cb_rx == true ){ - send_msg("[%d %d] -- Type :: %d", ext, port, type ); - } + if ( debug_cb_rx ) { send_msg ("[%d %d] -- Type :: %d", ext, port, type ); } + + if ( debug_sqn ) { send_msg ("[%d %d] -- Type :: %d -- seq_num :: %u", ext, port, type, cb_tx_buffer [ SEQ_NUM_PLACE ] ); } - Call_Box * cb = find_CB( v_cb, ext ); - if( cb != NULL ) { - if( data[ 0 ] & BIT7 ) { - if( type == BOOT ) { + Call_Box * cb = find_CB ( v_cb, ext ); + if ( cb not_eq NULL ) + { + if ( data[ 0 ] bitand BIT7 ) + { + if ( type == BOOT ) + { send2callboxes( build_cb_package( ext, port, REGISTRY, ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); } else { - if( debug_main ) debug_msg("[%d] Received ack pkg with seq_num %d", ext, data[ 0 ] ); + if ( debug_main ) debug_msg("[%d] Received ack pkg with seq_num %d", ext, data[ 0 ] ); - switch( type ) { + switch ( type ) + { case INVITE : { - if( debug_main || debug_invite ) debug_msg("[%d] Invite Ack - msg_id %d -- Cbx seqNum %d", ext, cb->get_msg_id(), data[ 0 ] ); + if ( debug_main or debug_invite ) debug_msg ("[%d] Invite Ack - msg_id %d -- Cbx seqNum %d", ext, cb->get_msg_id(), data[ 0 ] ); break; } case CB_BYE : { - if( debug_main || debug_invite ) debug_msg("[%d] BYE Ack - msg_id %d", ext, cb->get_msg_id() ); - cb->set_bye_response_ok(); + if ( debug_main or debug_invite ) debug_msg ("[%d] BYE Ack - msg_id %d", ext, cb->get_msg_id() ); + cb -> set_bye_response_ok (); break; } case REGISTRY : { - if( debug_main || debug_aging ) debug_msg("[%d] Registry ACK - msg_id %d", ext, cb->get_msg_id() ); + if ( debug_main or debug_aging ) debug_msg ("[%d] Registry ACK - msg_id %d", ext, cb->get_msg_id() ); break; } default : { - if( debug_main || debug_aging ) debug_msg("[%d] ACK msg_id :: %d :: type %d", ext, cb->get_msg_id(), type ); + if ( debug_main or debug_aging ) debug_msg ("[%d] ACK msg_id :: %d :: type %d", ext, cb->get_msg_id(), type ); } } - if( type != REGISTRY && type != CB_BYE && type != INVITE ) type = DO_NOTHING; - if( type == CB_BYE ){ - VZ_call * call = __find_Call__( v_call, ext ); - if( call != NULL ){ - if( call->get_elapsed_time() < 120000 ){ - if( debug_invite ) debug_msg("[%d] ack bye ignored", ext ); + if ( type not_eq REGISTRY and type not_eq CB_BYE and type not_eq INVITE ) type = DO_NOTHING; + if ( type == CB_BYE ) + { + VZ_call * call = find_Call ( v_call, ext ); + if ( call not_eq NULL ) + { + if ( call -> get_elapsed_time () < 120000 ) + { + if ( debug_invite ) debug_msg("[%d] ack bye ignored", ext ); type = DO_NOTHING; } } @@ -2017,7 +2040,7 @@ for( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); - if ( cb != NULL ) cb -> update_time (); + if ( cb not_eq NULL ) cb -> update_time (); } } @@ -2053,4 +2076,52 @@ void show_hello_status_function ( void ) { send_msg ("hello_sync.read :: %d -- hello_times :: %u", ( int ) hello_sync.read (), hello_times ); +} + +void show_last_rx_pkg_from_cbx ( void ) +{ + char str [ 256 ] = ""; + + for ( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) + { + char tmp[ 8 ]; + + sprintf ( tmp, "%02x", cb_rx_buffer [ i ] ); + + strcat ( str, tmp ); + + if ( ( i not_eq 0 ) && !( ( i + 1 ) % 25 ) ) + { + send_msg ( "%s", str ); + strcpy ( str, "" ); + } + + else { strcat ( str, " " ); } + } + + send_msg ( "%s", str ); +} + +void show_last_tx_pkg_from_cbx ( void ) +{ + char str [ 256 ] = ""; + + for ( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) + { + char tmp[ 8 ]; + + sprintf ( tmp, "%02x", cb_tx_buffer [ i ] ); + + strcat ( str, tmp ); + + if ( ( i not_eq 0 ) && !( ( i + 1 ) % 25 ) ) + { + send_msg ( "%s", str ); + strcpy ( str, "" ); + } + + else { strcat ( str, " " ); } + } + + send_msg ( "%s", str ); } \ No newline at end of file