![](/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
main_app_functions.cpp@132:05cd37f7e007, 2015-09-01 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 01 17:21:11 2015 +0000
- Revision:
- 132:05cd37f7e007
- Parent:
- 131:938ab88facae
- Child:
- 135:2f4290590e51
Substitui??o de; send_msg -> vz_printf; debug_msg -> vz_debug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 121:ee02790d00b7 | 1 | #include "main_app_functions.h" |
klauss | 121:ee02790d00b7 | 2 | |
klauss | 121:ee02790d00b7 | 3 | inline void reset_leds() { led1 = led2 = 1; led3 = led4 = 0; } |
klauss | 121:ee02790d00b7 | 4 | |
klauss | 121:ee02790d00b7 | 5 | int header_app_init ( void ) |
klauss | 121:ee02790d00b7 | 6 | { |
klauss | 121:ee02790d00b7 | 7 | |
klauss | 132:05cd37f7e007 | 8 | vz_printf ( "\r\n" ); |
klauss | 121:ee02790d00b7 | 9 | |
klauss | 132:05cd37f7e007 | 10 | if ( debug_app_init ) vz_printf ( "init_wdt() :: %s", ( init_wdt () == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 11 | |
klauss | 132:05cd37f7e007 | 12 | if ( debug_app_init ) vz_printf ( "config_lpc() :: %s", ( config_lpc () == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 13 | |
klauss | 132:05cd37f7e007 | 14 | if ( debug_app_init ) vz_printf ( "start_cpld() :: %s", ( start_cpld () == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 15 | |
klauss | 121:ee02790d00b7 | 16 | if( sdram_init() == 1 ) { |
klauss | 132:05cd37f7e007 | 17 | vz_printf ("******* Failed to initialize SDRAM *******"); |
klauss | 121:ee02790d00b7 | 18 | return 1; |
klauss | 121:ee02790d00b7 | 19 | } else { |
klauss | 132:05cd37f7e007 | 20 | vz_printf ("******* Success to initialize SDRAM *******"); |
klauss | 121:ee02790d00b7 | 21 | } |
klauss | 121:ee02790d00b7 | 22 | |
klauss | 121:ee02790d00b7 | 23 | int init_fsystem_ret = init_fsystem(); |
klauss | 121:ee02790d00b7 | 24 | if( init_fsystem_ret & BIT0 ) |
klauss | 121:ee02790d00b7 | 25 | { |
klauss | 132:05cd37f7e007 | 26 | vz_printf ("******* File system configured!!*******"); |
klauss | 121:ee02790d00b7 | 27 | } |
klauss | 121:ee02790d00b7 | 28 | |
klauss | 121:ee02790d00b7 | 29 | if( init_fsystem_ret & BIT1 ) |
klauss | 121:ee02790d00b7 | 30 | { |
klauss | 132:05cd37f7e007 | 31 | vz_printf ("******* File System Ready *******"); |
klauss | 121:ee02790d00b7 | 32 | } |
klauss | 121:ee02790d00b7 | 33 | |
klauss | 121:ee02790d00b7 | 34 | { |
klauss | 121:ee02790d00b7 | 35 | char s[ 32 ]; |
klauss | 121:ee02790d00b7 | 36 | mbed_mac_address( s ); |
klauss | 132:05cd37f7e007 | 37 | vz_printf ( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] ); |
klauss | 121:ee02790d00b7 | 38 | } |
klauss | 121:ee02790d00b7 | 39 | |
klauss | 126:1f90756250fb | 40 | eth_status = __init_eth__ (); |
klauss | 126:1f90756250fb | 41 | if ( eth_status ) |
klauss | 126:1f90756250fb | 42 | { |
klauss | 132:05cd37f7e007 | 43 | vz_printf ("******* Cannot connect to eth *******"); |
klauss | 121:ee02790d00b7 | 44 | } else { |
klauss | 132:05cd37f7e007 | 45 | vz_printf ("******* Connection eth - ok *******"); |
klauss | 132:05cd37f7e007 | 46 | int vz_io_eth_init_ret = vz_io_eth_init (); |
klauss | 121:ee02790d00b7 | 47 | |
klauss | 132:05cd37f7e007 | 48 | if ( vz_io_eth_init_ret == BIT0 ) vz_printf ("******* Prompt eth UDP Ready *******"); |
klauss | 121:ee02790d00b7 | 49 | |
klauss | 132:05cd37f7e007 | 50 | if ( vz_io_eth_init_ret == BIT1 ) vz_printf ("******* Prompt eth TCP Ready *******"); |
klauss | 121:ee02790d00b7 | 51 | |
klauss | 132:05cd37f7e007 | 52 | if ( debug_app_init ) vz_printf ( "vz_io_eth_init () :: %s", ( vz_io_eth_init_ret == ( BIT0 bitor BIT1 ) ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 53 | |
klauss | 132:05cd37f7e007 | 54 | if ( debug_app_init ) vz_printf ( "init_external_wdt () :: %s", ( init_external_wdt () == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 55 | |
klauss | 132:05cd37f7e007 | 56 | if ( debug_app_init ) vz_printf ( "init_bl () :: %s", ( init_bl() == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 57 | |
klauss | 132:05cd37f7e007 | 58 | if ( debug_app_init ) vz_printf ( "init_clock () :: %s", ( init_clock () == 0 ) ? "Ok" : "Failure" ); |
klauss | 128:3ae1c74773a8 | 59 | |
klauss | 132:05cd37f7e007 | 60 | if ( debug_app_init ) vz_printf ( "init_pwr_src () :: %s", ( init_power_source () == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 61 | } |
klauss | 121:ee02790d00b7 | 62 | |
klauss | 121:ee02790d00b7 | 63 | sync_timer.start(); |
klauss | 121:ee02790d00b7 | 64 | |
klauss | 121:ee02790d00b7 | 65 | led_sync_timer.start(); |
klauss | 121:ee02790d00b7 | 66 | |
klauss | 121:ee02790d00b7 | 67 | ext = 0; |
klauss | 121:ee02790d00b7 | 68 | |
klauss | 121:ee02790d00b7 | 69 | port = 0; |
klauss | 121:ee02790d00b7 | 70 | |
klauss | 121:ee02790d00b7 | 71 | buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 121:ee02790d00b7 | 72 | |
klauss | 121:ee02790d00b7 | 73 | data = NULL; |
klauss | 121:ee02790d00b7 | 74 | |
klauss | 121:ee02790d00b7 | 75 | type = DO_NOTHING; |
klauss | 121:ee02790d00b7 | 76 | |
klauss | 121:ee02790d00b7 | 77 | v_cb = new Vector(); |
klauss | 121:ee02790d00b7 | 78 | if( v_cb == NULL ) { |
klauss | 121:ee02790d00b7 | 79 | while( v_cb == NULL ) { |
klauss | 121:ee02790d00b7 | 80 | Vector * v_cb = new Vector(); |
klauss | 121:ee02790d00b7 | 81 | if( sync_timer.read() > 5 ) { |
klauss | 132:05cd37f7e007 | 82 | if( debug_memory ) vz_printf ("Call_Box vector allocation fail"); |
klauss | 121:ee02790d00b7 | 83 | sync_timer.reset(); |
klauss | 121:ee02790d00b7 | 84 | } |
klauss | 121:ee02790d00b7 | 85 | } |
klauss | 121:ee02790d00b7 | 86 | } |
klauss | 121:ee02790d00b7 | 87 | |
klauss | 132:05cd37f7e007 | 88 | if ( debug_app_init ) vz_printf ( "v_cb :: %s", ( v_cb not_eq NULL ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 89 | |
klauss | 121:ee02790d00b7 | 90 | v_call = new Vector(); |
klauss | 121:ee02790d00b7 | 91 | if( v_call == NULL ) { |
klauss | 121:ee02790d00b7 | 92 | while( v_call == NULL ) { |
klauss | 121:ee02790d00b7 | 93 | Vector * v_call = new Vector(); |
klauss | 121:ee02790d00b7 | 94 | if( sync_timer.read() > 5 ) { |
klauss | 132:05cd37f7e007 | 95 | if( debug_memory ) vz_printf ("Call vector allocation fail"); |
klauss | 121:ee02790d00b7 | 96 | sync_timer.reset(); |
klauss | 121:ee02790d00b7 | 97 | } |
klauss | 121:ee02790d00b7 | 98 | } |
klauss | 121:ee02790d00b7 | 99 | } |
klauss | 121:ee02790d00b7 | 100 | |
klauss | 132:05cd37f7e007 | 101 | if ( debug_app_init ) vz_printf ( "v_call :: %s", ( v_call not_eq NULL ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 102 | |
klauss | 121:ee02790d00b7 | 103 | ts = new Timeslice(); |
klauss | 121:ee02790d00b7 | 104 | if( ts == NULL ) { |
klauss | 121:ee02790d00b7 | 105 | memory_is_over = true; |
klauss | 132:05cd37f7e007 | 106 | if( debug_memory ) vz_printf ("TS allocation fail"); |
klauss | 121:ee02790d00b7 | 107 | } |
klauss | 121:ee02790d00b7 | 108 | |
klauss | 132:05cd37f7e007 | 109 | if ( debug_app_init ) vz_printf ( "TS :: %s", ( ts not_eq NULL ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 110 | |
klauss | 121:ee02790d00b7 | 111 | for( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) { |
klauss | 121:ee02790d00b7 | 112 | cb_rx_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 113 | cb_tx_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 114 | } |
klauss | 121:ee02790d00b7 | 115 | |
klauss | 121:ee02790d00b7 | 116 | reset_leds(); |
klauss | 121:ee02790d00b7 | 117 | |
klauss | 132:05cd37f7e007 | 118 | if ( debug_app_init ) vz_printf ( "init_fw_handler() :: %s", ( init_fw_handler() == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 119 | |
klauss | 132:05cd37f7e007 | 120 | if ( debug_app_init ) vz_printf ( "init_ranges() :: %s", ( init_ranges() == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 121 | |
klauss | 132:05cd37f7e007 | 122 | if ( debug_app_init ) vz_printf ( "init_refresh() :: %s", ( init_refresh() == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 123 | |
klauss | 132:05cd37f7e007 | 124 | if ( debug_app_init ) vz_printf ( "init_sync_refresh() :: %s", ( init_sync_refresh() == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 125 | |
klauss | 121:ee02790d00b7 | 126 | count = 0; |
klauss | 121:ee02790d00b7 | 127 | |
klauss | 121:ee02790d00b7 | 128 | max_registered_cbx = 0; |
klauss | 121:ee02790d00b7 | 129 | |
klauss | 121:ee02790d00b7 | 130 | wake_all = false; |
klauss | 121:ee02790d00b7 | 131 | |
klauss | 121:ee02790d00b7 | 132 | pkg_wdt = RX_CB_IDLE; |
klauss | 121:ee02790d00b7 | 133 | |
klauss | 121:ee02790d00b7 | 134 | eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 121:ee02790d00b7 | 135 | |
klauss | 121:ee02790d00b7 | 136 | invite_retry_timer.start(); |
klauss | 121:ee02790d00b7 | 137 | |
klauss | 132:05cd37f7e007 | 138 | if ( debug_app_init ) vz_printf ( "hex_init() :: %s", ( hex_init() == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 139 | |
klauss | 121:ee02790d00b7 | 140 | reset_leds(); |
klauss | 121:ee02790d00b7 | 141 | |
klauss | 121:ee02790d00b7 | 142 | lpc_low_level_input_counter = 0; |
klauss | 121:ee02790d00b7 | 143 | |
klauss | 132:05cd37f7e007 | 144 | if ( debug_app_init ) vz_printf ( "init_hello () :: %s", ( init_hello () == 0 ) ? "Ok" : "Failure" ); |
klauss | 124:c1b6c893e1c3 | 145 | |
klauss | 126:1f90756250fb | 146 | test_ts_timer.start (); |
klauss | 126:1f90756250fb | 147 | |
klauss | 132:05cd37f7e007 | 148 | vz_printf ( "\r\n" ); |
klauss | 121:ee02790d00b7 | 149 | |
klauss | 121:ee02790d00b7 | 150 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 151 | } |
klauss | 121:ee02790d00b7 | 152 | |
klauss | 121:ee02790d00b7 | 153 | |
klauss | 121:ee02790d00b7 | 154 | int try_reconnect_with_eth ( void ) |
klauss | 121:ee02790d00b7 | 155 | { |
klauss | 121:ee02790d00b7 | 156 | eth_status = __init_eth__(); |
klauss | 121:ee02790d00b7 | 157 | |
klauss | 126:1f90756250fb | 158 | if ( eth_status ) |
klauss | 126:1f90756250fb | 159 | { |
klauss | 132:05cd37f7e007 | 160 | vz_printf ("******* Cannot connect to eth *******"); |
klauss | 121:ee02790d00b7 | 161 | } else { |
klauss | 132:05cd37f7e007 | 162 | vz_printf ("******* Connection eth - ok *******"); |
klauss | 132:05cd37f7e007 | 163 | int vz_io_eth_init_ret = vz_io_eth_init (); |
klauss | 121:ee02790d00b7 | 164 | |
klauss | 132:05cd37f7e007 | 165 | if ( vz_io_eth_init_ret == BIT0 ) vz_printf ("******* Prompt eth UDP Ready *******"); |
klauss | 121:ee02790d00b7 | 166 | |
klauss | 132:05cd37f7e007 | 167 | if ( vz_io_eth_init_ret == BIT1 ) vz_printf ("******* Prompt eth TCP Ready *******"); |
klauss | 121:ee02790d00b7 | 168 | |
klauss | 132:05cd37f7e007 | 169 | if ( debug_app_init ) vz_printf ( "vz_io_eth_init () :: %s", ( vz_io_eth_init_ret == ( BIT0 bitor BIT1 ) ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 170 | |
klauss | 132:05cd37f7e007 | 171 | if ( debug_app_init ) vz_printf ( "init_external_wdt() :: %s", ( init_external_wdt() == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 172 | |
klauss | 132:05cd37f7e007 | 173 | if ( debug_app_init ) vz_printf ( "init_bl() :: %s", ( init_bl() == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 174 | |
klauss | 132:05cd37f7e007 | 175 | if ( debug_app_init ) vz_printf ( "init_clock() :: %s", ( init_clock() == 0 ) ? "Ok" : "Failure" ); |
klauss | 128:3ae1c74773a8 | 176 | |
klauss | 132:05cd37f7e007 | 177 | if ( debug_app_init ) vz_printf ( "init_pwr_src () :: %s", ( init_power_source () == 0 ) ? "Ok" : "Failure" ); |
klauss | 121:ee02790d00b7 | 178 | } |
klauss | 121:ee02790d00b7 | 179 | |
klauss | 121:ee02790d00b7 | 180 | return eth_status; |
klauss | 121:ee02790d00b7 | 181 | } |
klauss | 121:ee02790d00b7 | 182 | |
klauss | 121:ee02790d00b7 | 183 | |
klauss | 121:ee02790d00b7 | 184 | int show_stats ( void ) |
klauss | 121:ee02790d00b7 | 185 | { |
klauss | 132:05cd37f7e007 | 186 | char str [ 256 ]; |
klauss | 132:05cd37f7e007 | 187 | int snprintf_ret = snprintf( str, sizeof ( str ) - 1, |
klauss | 121:ee02790d00b7 | 188 | "\n\rReceived Pkgs::\n\r " |
klauss | 121:ee02790d00b7 | 189 | "Boot :: %u\n\r " |
klauss | 121:ee02790d00b7 | 190 | "Registry :: %u\n\r " |
klauss | 121:ee02790d00b7 | 191 | "Invite :: %u\n\r " |
klauss | 121:ee02790d00b7 | 192 | "Audio :: %u\n\r " |
klauss | 121:ee02790d00b7 | 193 | "Telemetry :: %u\n\r " |
klauss | 121:ee02790d00b7 | 194 | "CB_stats :: %u\n\r " |
klauss | 121:ee02790d00b7 | 195 | "CB_bye :: %u\n\r " |
klauss | 121:ee02790d00b7 | 196 | "Prompt :: %u\n\r " |
klauss | 121:ee02790d00b7 | 197 | "Flood :: %u\n\r " |
klauss | 121:ee02790d00b7 | 198 | "Bootloader_cbx :: %u\n\r", |
klauss | 121:ee02790d00b7 | 199 | boot_counter, |
klauss | 121:ee02790d00b7 | 200 | registry_counter, |
klauss | 121:ee02790d00b7 | 201 | invite_counter, |
klauss | 121:ee02790d00b7 | 202 | audio_counter, |
klauss | 121:ee02790d00b7 | 203 | telemetry_counter, |
klauss | 121:ee02790d00b7 | 204 | cb_stats_counter, |
klauss | 121:ee02790d00b7 | 205 | cb_bye_counter, |
klauss | 121:ee02790d00b7 | 206 | prompt_counter, |
klauss | 121:ee02790d00b7 | 207 | flood_counter, |
klauss | 121:ee02790d00b7 | 208 | bootloader_cbx_counter |
klauss | 121:ee02790d00b7 | 209 | ); |
klauss | 132:05cd37f7e007 | 210 | |
klauss | 132:05cd37f7e007 | 211 | vz_printf ( "%s", str ); |
klauss | 121:ee02790d00b7 | 212 | |
klauss | 132:05cd37f7e007 | 213 | if ( debug_string_length ) vz_debug ( "str.length ( %d )", snprintf_ret ); |
klauss | 132:05cd37f7e007 | 214 | |
klauss | 121:ee02790d00b7 | 215 | return ( snprintf_ret ); |
klauss | 121:ee02790d00b7 | 216 | } |
klauss | 121:ee02790d00b7 | 217 | |
klauss | 121:ee02790d00b7 | 218 | |
klauss | 121:ee02790d00b7 | 219 | int reset_stats ( void ) |
klauss | 121:ee02790d00b7 | 220 | { |
klauss | 121:ee02790d00b7 | 221 | boot_counter = 0; |
klauss | 121:ee02790d00b7 | 222 | registry_counter = 0; |
klauss | 121:ee02790d00b7 | 223 | invite_counter = 0; |
klauss | 121:ee02790d00b7 | 224 | audio_counter = 0; |
klauss | 121:ee02790d00b7 | 225 | telemetry_counter = 0; |
klauss | 121:ee02790d00b7 | 226 | cb_bye_counter = 0; |
klauss | 121:ee02790d00b7 | 227 | prompt_counter = 0; |
klauss | 121:ee02790d00b7 | 228 | flood_counter = 0; |
klauss | 121:ee02790d00b7 | 229 | bootloader_cbx_counter = 0; |
klauss | 121:ee02790d00b7 | 230 | cb_stats_counter = 0; |
klauss | 121:ee02790d00b7 | 231 | fw_counter = 0; |
klauss | 121:ee02790d00b7 | 232 | |
klauss | 121:ee02790d00b7 | 233 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 234 | } |
klauss | 121:ee02790d00b7 | 235 | |
klauss | 132:05cd37f7e007 | 236 | int |
klauss | 132:05cd37f7e007 | 237 | show_cb_list ( Vector * v_cb ) |
klauss | 121:ee02790d00b7 | 238 | { |
klauss | 132:05cd37f7e007 | 239 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb -> size(); |
klauss | 121:ee02790d00b7 | 240 | |
klauss | 132:05cd37f7e007 | 241 | if ( ( max_ext % 2 ) == 0 ) missed_cb ++; |
klauss | 121:ee02790d00b7 | 242 | |
klauss | 132:05cd37f7e007 | 243 | if ( min_ext % 2 ) missed_cb ++; |
klauss | 121:ee02790d00b7 | 244 | |
klauss | 132:05cd37f7e007 | 245 | if ( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 121:ee02790d00b7 | 246 | |
klauss | 132:05cd37f7e007 | 247 | vz_printf ("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- " |
klauss | 132:05cd37f7e007 | 248 | "Remain_timeslices :: %d :: v_call->size() :: %d", |
klauss | 132:05cd37f7e007 | 249 | v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, |
klauss | 132:05cd37f7e007 | 250 | ts->remain_timeslices(), v_call->size() |
klauss | 132:05cd37f7e007 | 251 | ); |
klauss | 132:05cd37f7e007 | 252 | |
klauss | 121:ee02790d00b7 | 253 | if( v_cb->size() == 1 ) { |
klauss | 132:05cd37f7e007 | 254 | vz_printf (" %d ", ( ( Call_Box * )v_cb -> get_element( 0 ) ) -> get_ext () ); |
klauss | 132:05cd37f7e007 | 255 | } else if( v_cb -> size() > 1 ) { |
klauss | 132:05cd37f7e007 | 256 | char str [ 1024 ]; |
klauss | 132:05cd37f7e007 | 257 | int ext_list [ MAX_CB_IN_A_BRANCH ]; |
klauss | 121:ee02790d00b7 | 258 | register int i = 0; |
klauss | 132:05cd37f7e007 | 259 | for( ; i < v_cb -> size(); i++ ) { |
klauss | 132:05cd37f7e007 | 260 | ext_list [ i ] = ( ( Call_Box * )v_cb->get_element ( i ) ) -> get_ext (); |
klauss | 121:ee02790d00b7 | 261 | } |
klauss | 121:ee02790d00b7 | 262 | |
klauss | 121:ee02790d00b7 | 263 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 121:ee02790d00b7 | 264 | |
klauss | 121:ee02790d00b7 | 265 | char aux[ 16 ]; |
klauss | 132:05cd37f7e007 | 266 | strcpy ( str, "\r\n> " ); |
klauss | 132:05cd37f7e007 | 267 | for ( i = 0; i < v_cb -> size () - 1; i ++ ) |
klauss | 132:05cd37f7e007 | 268 | { |
klauss | 132:05cd37f7e007 | 269 | sprintf ( aux, "%i, ", ext_list [ i ] ); |
klauss | 132:05cd37f7e007 | 270 | strcat ( str, aux ); |
klauss | 132:05cd37f7e007 | 271 | if ( ( i not_eq 0 ) and not ( ( i + 1 ) % 16 ) ) strcat ( str, "\r\n> " ); |
klauss | 121:ee02790d00b7 | 272 | } |
klauss | 132:05cd37f7e007 | 273 | sprintf ( aux, "%i ", ext_list [ i ] ); |
klauss | 132:05cd37f7e007 | 274 | strcat ( str, aux ); |
klauss | 132:05cd37f7e007 | 275 | vz_printf ( "%s", str ); |
klauss | 121:ee02790d00b7 | 276 | } |
klauss | 121:ee02790d00b7 | 277 | |
klauss | 121:ee02790d00b7 | 278 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 279 | } |
klauss | 121:ee02790d00b7 | 280 | |
klauss | 132:05cd37f7e007 | 281 | int |
klauss | 132:05cd37f7e007 | 282 | show_cb_long_list ( Vector * v_cb, bool show_time, bool show_invite ) |
klauss | 121:ee02790d00b7 | 283 | { |
klauss | 132:05cd37f7e007 | 284 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb -> size (); |
klauss | 121:ee02790d00b7 | 285 | |
klauss | 132:05cd37f7e007 | 286 | if ( ( max_ext % 2 ) == 0 ) missed_cb ++; |
klauss | 121:ee02790d00b7 | 287 | |
klauss | 132:05cd37f7e007 | 288 | if ( min_ext % 2 ) missed_cb ++; |
klauss | 121:ee02790d00b7 | 289 | |
klauss | 132:05cd37f7e007 | 290 | if ( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 121:ee02790d00b7 | 291 | |
klauss | 121:ee02790d00b7 | 292 | { |
klauss | 132:05cd37f7e007 | 293 | int ext_list [ MAX_CB_IN_A_BRANCH ]; |
klauss | 121:ee02790d00b7 | 294 | |
klauss | 132:05cd37f7e007 | 295 | if ( v_cb -> size () >= 1 ) |
klauss | 132:05cd37f7e007 | 296 | { |
klauss | 132:05cd37f7e007 | 297 | for ( register int i = 0; i < v_cb -> size (); i ++ ) |
klauss | 121:ee02790d00b7 | 298 | { |
klauss | 132:05cd37f7e007 | 299 | ext_list [ i ] = ( ( Call_Box * )v_cb -> get_element ( i ) ) -> get_ext (); |
klauss | 121:ee02790d00b7 | 300 | } |
klauss | 132:05cd37f7e007 | 301 | qsort ( ext_list, v_cb -> size (), sizeof ( int ), ls_comp ); |
klauss | 121:ee02790d00b7 | 302 | } |
klauss | 121:ee02790d00b7 | 303 | |
klauss | 132:05cd37f7e007 | 304 | vz_printf ("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- " |
klauss | 132:05cd37f7e007 | 305 | "Remain_timeslices :: %d :: v_call->size() :: %d", |
klauss | 132:05cd37f7e007 | 306 | v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, |
klauss | 132:05cd37f7e007 | 307 | ts->remain_timeslices(), v_call->size() |
klauss | 132:05cd37f7e007 | 308 | ); |
klauss | 121:ee02790d00b7 | 309 | |
klauss | 132:05cd37f7e007 | 310 | for ( register uint8_t i = 0; i < v_cb -> size (); i ++ ) |
klauss | 132:05cd37f7e007 | 311 | { |
klauss | 132:05cd37f7e007 | 312 | Call_Box * cb = find_CB ( v_cb, ext_list [ i ] ); |
klauss | 121:ee02790d00b7 | 313 | |
klauss | 132:05cd37f7e007 | 314 | if ( cb not_eq NULL ) |
klauss | 121:ee02790d00b7 | 315 | { |
klauss | 132:05cd37f7e007 | 316 | char cb_status [ 32 ]; |
klauss | 132:05cd37f7e007 | 317 | char cb_sip_status [ 32 ]; |
klauss | 121:ee02790d00b7 | 318 | switch ( cb -> get_status () ) |
klauss | 121:ee02790d00b7 | 319 | { |
klauss | 121:ee02790d00b7 | 320 | case cb_idle : { |
klauss | 132:05cd37f7e007 | 321 | strcpy ( cb_status, "cb_idle" ); |
klauss | 121:ee02790d00b7 | 322 | break; |
klauss | 121:ee02790d00b7 | 323 | } |
klauss | 121:ee02790d00b7 | 324 | case cb_ringing : { |
klauss | 132:05cd37f7e007 | 325 | strcpy ( cb_status, "cb_ringing" ); |
klauss | 121:ee02790d00b7 | 326 | break; |
klauss | 121:ee02790d00b7 | 327 | } |
klauss | 121:ee02790d00b7 | 328 | case cb_trying : { |
klauss | 132:05cd37f7e007 | 329 | strcpy ( cb_status,"cb_trying" ); |
klauss | 121:ee02790d00b7 | 330 | break; |
klauss | 121:ee02790d00b7 | 331 | } |
klauss | 121:ee02790d00b7 | 332 | case cb_on_call : { |
klauss | 132:05cd37f7e007 | 333 | strcpy ( cb_status, "cb_on_call" ); |
klauss | 121:ee02790d00b7 | 334 | break; |
klauss | 121:ee02790d00b7 | 335 | } |
klauss | 121:ee02790d00b7 | 336 | case cb_busy : { |
klauss | 132:05cd37f7e007 | 337 | strcpy ( cb_status, "cb_busy" ); |
klauss | 121:ee02790d00b7 | 338 | break; |
klauss | 121:ee02790d00b7 | 339 | } |
klauss | 121:ee02790d00b7 | 340 | case cb_denied : { |
klauss | 132:05cd37f7e007 | 341 | strcpy ( cb_status, "cb_denied" ); |
klauss | 121:ee02790d00b7 | 342 | break; |
klauss | 121:ee02790d00b7 | 343 | } |
klauss | 121:ee02790d00b7 | 344 | case cb_bootloader : { |
klauss | 132:05cd37f7e007 | 345 | strcpy ( cb_status, "cb_bootloader" ); |
klauss | 121:ee02790d00b7 | 346 | break; |
klauss | 121:ee02790d00b7 | 347 | } |
klauss | 121:ee02790d00b7 | 348 | } |
klauss | 121:ee02790d00b7 | 349 | |
klauss | 121:ee02790d00b7 | 350 | switch( cb -> get_sip_status () ) |
klauss | 121:ee02790d00b7 | 351 | { |
klauss | 121:ee02790d00b7 | 352 | case sip_idle : { |
klauss | 132:05cd37f7e007 | 353 | strcpy ( cb_sip_status, "sip_idle" ); |
klauss | 121:ee02790d00b7 | 354 | break; |
klauss | 121:ee02790d00b7 | 355 | } |
klauss | 121:ee02790d00b7 | 356 | case sip_waiting_trying : { |
klauss | 132:05cd37f7e007 | 357 | strcpy ( cb_sip_status, "sip_waiting_trying" ); |
klauss | 121:ee02790d00b7 | 358 | break; |
klauss | 121:ee02790d00b7 | 359 | } |
klauss | 121:ee02790d00b7 | 360 | case sip_trying : { |
klauss | 132:05cd37f7e007 | 361 | strcpy ( cb_sip_status, "sip_trying" ); |
klauss | 121:ee02790d00b7 | 362 | break; |
klauss | 121:ee02790d00b7 | 363 | } |
klauss | 121:ee02790d00b7 | 364 | case sip_ringing : { |
klauss | 132:05cd37f7e007 | 365 | strcpy ( cb_sip_status, "sip_ringing" ); |
klauss | 121:ee02790d00b7 | 366 | break; |
klauss | 121:ee02790d00b7 | 367 | } |
klauss | 121:ee02790d00b7 | 368 | case sip_busy : { |
klauss | 132:05cd37f7e007 | 369 | strcpy ( cb_sip_status, "sip_busy" ); |
klauss | 121:ee02790d00b7 | 370 | break; |
klauss | 121:ee02790d00b7 | 371 | } |
klauss | 121:ee02790d00b7 | 372 | case sip_ok : { |
klauss | 132:05cd37f7e007 | 373 | strcpy ( cb_sip_status, "sip_ok" ); |
klauss | 121:ee02790d00b7 | 374 | break; |
klauss | 121:ee02790d00b7 | 375 | } |
klauss | 121:ee02790d00b7 | 376 | case sip_on_call : { |
klauss | 132:05cd37f7e007 | 377 | strcpy ( cb_sip_status, "sip_on_call" ); |
klauss | 121:ee02790d00b7 | 378 | break; |
klauss | 121:ee02790d00b7 | 379 | } |
klauss | 121:ee02790d00b7 | 380 | case sip_denied : { |
klauss | 132:05cd37f7e007 | 381 | strcpy ( cb_sip_status, "sip_denied" ); |
klauss | 121:ee02790d00b7 | 382 | break; |
klauss | 121:ee02790d00b7 | 383 | } |
klauss | 121:ee02790d00b7 | 384 | } |
klauss | 121:ee02790d00b7 | 385 | |
klauss | 132:05cd37f7e007 | 386 | char cbx_to_string [ 254 ]; |
klauss | 121:ee02790d00b7 | 387 | snprintf ( cbx_to_string, sizeof ( cbx_to_string ), |
klauss | 123:1d395b5a4cad | 388 | "Ext :: %5i :: Port :: %5i :: Status -- %s - %s", |
klauss | 121:ee02790d00b7 | 389 | cb->get_ext(), cb->get_port(), cb_status, cb_sip_status |
klauss | 121:ee02790d00b7 | 390 | ); |
klauss | 121:ee02790d00b7 | 391 | |
klauss | 132:05cd37f7e007 | 392 | if( cb -> get_timeslice () not_eq 0 ) |
klauss | 121:ee02790d00b7 | 393 | { |
klauss | 132:05cd37f7e007 | 394 | char aux [ 32 ]; |
klauss | 132:05cd37f7e007 | 395 | snprintf ( aux, sizeof ( aux ), " -- on TimeSlice :: %i", cb->get_timeslice () ); |
klauss | 121:ee02790d00b7 | 396 | strcat( cbx_to_string, aux ); |
klauss | 121:ee02790d00b7 | 397 | } |
klauss | 123:1d395b5a4cad | 398 | |
klauss | 123:1d395b5a4cad | 399 | if ( show_time ) |
klauss | 123:1d395b5a4cad | 400 | { |
klauss | 123:1d395b5a4cad | 401 | char get_timer_msg [ 128 ]; |
klauss | 123:1d395b5a4cad | 402 | |
klauss | 123:1d395b5a4cad | 403 | snprintf ( get_timer_msg, sizeof ( get_timer_msg ) -1, " -- timer %4i [ %s ", |
klauss | 123:1d395b5a4cad | 404 | cb -> get_timer (), |
klauss | 123:1d395b5a4cad | 405 | ( cb -> get_overflow_flag () ) ? "Overflow" : "Ok" |
klauss | 123:1d395b5a4cad | 406 | ); |
klauss | 123:1d395b5a4cad | 407 | |
klauss | 123:1d395b5a4cad | 408 | int get_overflow_times_tmp = cb -> get_overflow_times (); |
klauss | 123:1d395b5a4cad | 409 | |
klauss | 123:1d395b5a4cad | 410 | if ( get_overflow_times_tmp == 0 ) strcat ( get_timer_msg, "]" ); |
klauss | 123:1d395b5a4cad | 411 | |
klauss | 123:1d395b5a4cad | 412 | else { |
klauss | 123:1d395b5a4cad | 413 | char strcat_tmp [ 16 ]; |
klauss | 132:05cd37f7e007 | 414 | if ( get_overflow_times_tmp == 1 ) snprintf ( strcat_tmp, sizeof ( strcat_tmp ) - 1, "1 time ]" ); |
klauss | 123:1d395b5a4cad | 415 | |
klauss | 132:05cd37f7e007 | 416 | else snprintf ( strcat_tmp, sizeof ( strcat_tmp ) - 1, "%u times ]", get_overflow_times_tmp ); |
klauss | 123:1d395b5a4cad | 417 | |
klauss | 123:1d395b5a4cad | 418 | strcat ( get_timer_msg, strcat_tmp ); |
klauss | 123:1d395b5a4cad | 419 | } |
klauss | 123:1d395b5a4cad | 420 | |
klauss | 123:1d395b5a4cad | 421 | strcat ( cbx_to_string, get_timer_msg ); |
klauss | 123:1d395b5a4cad | 422 | } |
klauss | 123:1d395b5a4cad | 423 | |
klauss | 132:05cd37f7e007 | 424 | if ( show_invites ) |
klauss | 132:05cd37f7e007 | 425 | { |
klauss | 132:05cd37f7e007 | 426 | char get_invites_msg [ 32 ]; |
klauss | 132:05cd37f7e007 | 427 | |
klauss | 132:05cd37f7e007 | 428 | snprintf ( get_invites_msg, |
klauss | 132:05cd37f7e007 | 429 | sizeof ( get_invites_msg ) -1, |
klauss | 132:05cd37f7e007 | 430 | " :: invites :: %u ", cb -> get_invite_counter () ); |
klauss | 132:05cd37f7e007 | 431 | |
klauss | 132:05cd37f7e007 | 432 | strcat ( cbx_to_string, get_invites_msg ); |
klauss | 132:05cd37f7e007 | 433 | } |
klauss | 132:05cd37f7e007 | 434 | |
klauss | 132:05cd37f7e007 | 435 | vz_printf ( cbx_to_string ); |
klauss | 121:ee02790d00b7 | 436 | } |
klauss | 121:ee02790d00b7 | 437 | } |
klauss | 121:ee02790d00b7 | 438 | } |
klauss | 121:ee02790d00b7 | 439 | |
klauss | 121:ee02790d00b7 | 440 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 441 | } |
klauss | 121:ee02790d00b7 | 442 | |
klauss | 121:ee02790d00b7 | 443 | int show_cb ( Vector * v_cb ) |
klauss | 121:ee02790d00b7 | 444 | { |
klauss | 132:05cd37f7e007 | 445 | vz_printf ("Registered %d ( of %d ) CBx ( %d - %d ) -- Remain_timeslices :: %d :: v_call->size() :: %d", |
klauss | 132:05cd37f7e007 | 446 | v_cb->size(), max_registered_cbx, min_ext, max_ext, ts->remain_timeslices(), v_call->size() |
klauss | 132:05cd37f7e007 | 447 | ); |
klauss | 132:05cd37f7e007 | 448 | |
klauss | 132:05cd37f7e007 | 449 | for( register uint8_t i = 0; i < v_cb -> size (); i++ ) |
klauss | 132:05cd37f7e007 | 450 | { |
klauss | 132:05cd37f7e007 | 451 | Call_Box * cb = ( Call_Box * )v_cb -> get_element ( i ); |
klauss | 132:05cd37f7e007 | 452 | char cb_status [ 32 ]; |
klauss | 132:05cd37f7e007 | 453 | char cb_sip_status [ 32 ]; |
klauss | 121:ee02790d00b7 | 454 | switch ( cb -> get_status () ) |
klauss | 121:ee02790d00b7 | 455 | { |
klauss | 121:ee02790d00b7 | 456 | case cb_idle : { |
klauss | 132:05cd37f7e007 | 457 | strcpy ( cb_status, "cb_idle" ); |
klauss | 121:ee02790d00b7 | 458 | break; |
klauss | 121:ee02790d00b7 | 459 | } |
klauss | 121:ee02790d00b7 | 460 | case cb_ringing : { |
klauss | 132:05cd37f7e007 | 461 | strcpy ( cb_status, "cb_ringing" ); |
klauss | 121:ee02790d00b7 | 462 | break; |
klauss | 121:ee02790d00b7 | 463 | } |
klauss | 121:ee02790d00b7 | 464 | case cb_trying : { |
klauss | 132:05cd37f7e007 | 465 | strcpy ( cb_status,"cb_trying" ); |
klauss | 121:ee02790d00b7 | 466 | break; |
klauss | 121:ee02790d00b7 | 467 | } |
klauss | 121:ee02790d00b7 | 468 | case cb_on_call : { |
klauss | 132:05cd37f7e007 | 469 | strcpy ( cb_status, "cb_on_call" ); |
klauss | 121:ee02790d00b7 | 470 | break; |
klauss | 121:ee02790d00b7 | 471 | } |
klauss | 121:ee02790d00b7 | 472 | case cb_busy : { |
klauss | 132:05cd37f7e007 | 473 | strcpy ( cb_status, "cb_busy" ); |
klauss | 121:ee02790d00b7 | 474 | break; |
klauss | 121:ee02790d00b7 | 475 | } |
klauss | 121:ee02790d00b7 | 476 | case cb_denied : { |
klauss | 132:05cd37f7e007 | 477 | strcpy ( cb_status, "cb_denied" ); |
klauss | 121:ee02790d00b7 | 478 | break; |
klauss | 121:ee02790d00b7 | 479 | } |
klauss | 121:ee02790d00b7 | 480 | case cb_bootloader : { |
klauss | 132:05cd37f7e007 | 481 | strcpy ( cb_status, "cb_bootloader" ); |
klauss | 121:ee02790d00b7 | 482 | break; |
klauss | 121:ee02790d00b7 | 483 | } |
klauss | 121:ee02790d00b7 | 484 | } |
klauss | 121:ee02790d00b7 | 485 | switch( cb -> get_sip_status () ) { |
klauss | 121:ee02790d00b7 | 486 | case sip_idle : { |
klauss | 132:05cd37f7e007 | 487 | strcpy ( cb_sip_status, "sip_idle" ); |
klauss | 121:ee02790d00b7 | 488 | break; |
klauss | 121:ee02790d00b7 | 489 | } |
klauss | 121:ee02790d00b7 | 490 | case sip_waiting_trying : { |
klauss | 132:05cd37f7e007 | 491 | strcpy ( cb_sip_status, "sip_waiting_trying" ); |
klauss | 121:ee02790d00b7 | 492 | break; |
klauss | 121:ee02790d00b7 | 493 | } |
klauss | 121:ee02790d00b7 | 494 | case sip_trying : { |
klauss | 132:05cd37f7e007 | 495 | strcpy ( cb_sip_status, "sip_trying" ); |
klauss | 121:ee02790d00b7 | 496 | break; |
klauss | 121:ee02790d00b7 | 497 | } |
klauss | 121:ee02790d00b7 | 498 | case sip_ringing : { |
klauss | 132:05cd37f7e007 | 499 | strcpy ( cb_sip_status, "sip_ringing" ); |
klauss | 121:ee02790d00b7 | 500 | break; |
klauss | 121:ee02790d00b7 | 501 | } |
klauss | 121:ee02790d00b7 | 502 | case sip_busy : { |
klauss | 132:05cd37f7e007 | 503 | strcpy ( cb_sip_status, "sip_busy" ); |
klauss | 121:ee02790d00b7 | 504 | break; |
klauss | 121:ee02790d00b7 | 505 | } |
klauss | 121:ee02790d00b7 | 506 | case sip_ok : { |
klauss | 132:05cd37f7e007 | 507 | strcpy ( cb_sip_status, "sip_ok" ); |
klauss | 121:ee02790d00b7 | 508 | break; |
klauss | 121:ee02790d00b7 | 509 | } |
klauss | 121:ee02790d00b7 | 510 | case sip_on_call : { |
klauss | 132:05cd37f7e007 | 511 | strcpy ( cb_sip_status, "sip_on_call" ); |
klauss | 121:ee02790d00b7 | 512 | break; |
klauss | 121:ee02790d00b7 | 513 | } |
klauss | 121:ee02790d00b7 | 514 | case sip_denied : { |
klauss | 132:05cd37f7e007 | 515 | strcpy ( cb_sip_status, "sip_denied" ); |
klauss | 121:ee02790d00b7 | 516 | break; |
klauss | 121:ee02790d00b7 | 517 | } |
klauss | 121:ee02790d00b7 | 518 | } |
klauss | 121:ee02790d00b7 | 519 | |
klauss | 132:05cd37f7e007 | 520 | char cbx_to_string [ 254 ]; |
klauss | 121:ee02790d00b7 | 521 | snprintf ( cbx_to_string, sizeof ( cbx_to_string ), |
klauss | 123:1d395b5a4cad | 522 | "Ext :: %5i :: Port :: %5i :: Status -- %s - %s", |
klauss | 132:05cd37f7e007 | 523 | cb -> get_ext (), cb -> get_port (), cb_status, cb_sip_status |
klauss | 121:ee02790d00b7 | 524 | ); |
klauss | 121:ee02790d00b7 | 525 | |
klauss | 132:05cd37f7e007 | 526 | if ( cb -> get_timeslice () not_eq 0 ) |
klauss | 121:ee02790d00b7 | 527 | { |
klauss | 132:05cd37f7e007 | 528 | char aux [ 32 ]; |
klauss | 132:05cd37f7e007 | 529 | snprintf ( aux, sizeof ( aux ), " -- on TimeSlice :: %i", cb -> get_timeslice () ); |
klauss | 132:05cd37f7e007 | 530 | strcat ( cbx_to_string, aux ); |
klauss | 121:ee02790d00b7 | 531 | } |
klauss | 121:ee02790d00b7 | 532 | |
klauss | 121:ee02790d00b7 | 533 | |
klauss | 132:05cd37f7e007 | 534 | vz_printf ( cbx_to_string ); |
klauss | 121:ee02790d00b7 | 535 | } |
klauss | 121:ee02790d00b7 | 536 | |
klauss | 121:ee02790d00b7 | 537 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 538 | } |
klauss | 121:ee02790d00b7 | 539 | |
klauss | 121:ee02790d00b7 | 540 | int show_cb_sip ( Vector * v_cb ) |
klauss | 121:ee02790d00b7 | 541 | { |
klauss | 132:05cd37f7e007 | 542 | vz_printf (":: Sip :: %u", v_cb -> size () ); |
klauss | 122:480c44b0e205 | 543 | for ( register uint8_t i = 0; i < v_cb -> size (); i++ ) |
klauss | 122:480c44b0e205 | 544 | { |
klauss | 122:480c44b0e205 | 545 | Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( i ); |
klauss | 121:ee02790d00b7 | 546 | |
klauss | 123:1d395b5a4cad | 547 | char tmp_send_msg [ 256 ]; |
klauss | 123:1d395b5a4cad | 548 | |
klauss | 123:1d395b5a4cad | 549 | snprintf ( tmp_send_msg, sizeof ( tmp_send_msg ) - 1, |
klauss | 123:1d395b5a4cad | 550 | "ext :: %5i -- port :: %5i -- timer %4i [ %s ", |
klauss | 122:480c44b0e205 | 551 | cb -> get_sip_ext (), |
klauss | 121:ee02790d00b7 | 552 | cb -> get_sip_port (), |
klauss | 121:ee02790d00b7 | 553 | cb -> get_timer (), |
klauss | 121:ee02790d00b7 | 554 | ( cb -> get_overflow_flag () ) ? "Overflow" : "Ok" |
klauss | 121:ee02790d00b7 | 555 | ); |
klauss | 123:1d395b5a4cad | 556 | |
klauss | 123:1d395b5a4cad | 557 | int get_overflow_times_tmp = cb -> get_overflow_times (); |
klauss | 123:1d395b5a4cad | 558 | |
klauss | 123:1d395b5a4cad | 559 | if ( get_overflow_times_tmp == 0 ) strcat ( tmp_send_msg, "]" ); |
klauss | 123:1d395b5a4cad | 560 | |
klauss | 123:1d395b5a4cad | 561 | else { |
klauss | 123:1d395b5a4cad | 562 | char strcat_tmp [ 16 ]; |
klauss | 123:1d395b5a4cad | 563 | if ( get_overflow_times_tmp == 1 ) snprintf( strcat_tmp, sizeof ( strcat_tmp ) - 1, "1 time ]" ); |
klauss | 123:1d395b5a4cad | 564 | |
klauss | 123:1d395b5a4cad | 565 | else snprintf( strcat_tmp, sizeof ( strcat_tmp ) - 1, "%d times ]", get_overflow_times_tmp ); |
klauss | 123:1d395b5a4cad | 566 | |
klauss | 123:1d395b5a4cad | 567 | strcat ( tmp_send_msg, strcat_tmp ); |
klauss | 123:1d395b5a4cad | 568 | } |
klauss | 123:1d395b5a4cad | 569 | |
klauss | 132:05cd37f7e007 | 570 | vz_printf ( tmp_send_msg ); |
klauss | 121:ee02790d00b7 | 571 | } |
klauss | 121:ee02790d00b7 | 572 | |
klauss | 121:ee02790d00b7 | 573 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 574 | } |
klauss | 121:ee02790d00b7 | 575 | |
klauss | 121:ee02790d00b7 | 576 | int show_sizes ( void ) |
klauss | 121:ee02790d00b7 | 577 | { |
klauss | 121:ee02790d00b7 | 578 | sizes = false; |
klauss | 132:05cd37f7e007 | 579 | vz_printf ( "CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter ); |
klauss | 132:05cd37f7e007 | 580 | vz_printf ( "SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter ); |
klauss | 132:05cd37f7e007 | 581 | vz_printf ( "RTP_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter ); |
klauss | 132:05cd37f7e007 | 582 | vz_printf ( "RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter ); |
klauss | 132:05cd37f7e007 | 583 | vz_printf ( "Call_New (%u) -- Call_Delete (%u)", call_new_counter, call_delete_counter ); |
klauss | 132:05cd37f7e007 | 584 | vz_printf ( "lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 132:05cd37f7e007 | 585 | vz_printf ( "Memory is %s", ( memory_is_over ) ? "Over" : "Ok" ); |
klauss | 132:05cd37f7e007 | 586 | vz_printf ( "Missed_Pkg :: %d ::", missed_pkg ); |
klauss | 132:05cd37f7e007 | 587 | vz_printf ( "Sizeof Sip :: %u", sizeof ( Sip ) ); |
klauss | 132:05cd37f7e007 | 588 | vz_printf ( "Sizeof Call_Box :: %u", sizeof ( Call_Box ) ); |
klauss | 132:05cd37f7e007 | 589 | vz_printf ( "Sizeof VZ_call :: %u", sizeof ( VZ_call ) ); |
klauss | 132:05cd37f7e007 | 590 | vz_printf ( "Sizeof RTP :: %u", sizeof ( RTP ) ); |
klauss | 132:05cd37f7e007 | 591 | vz_printf ( "Sizeof RTP_Header :: %u", sizeof ( RTP_Header ) ); |
klauss | 132:05cd37f7e007 | 592 | vz_printf ( "Sizeof RTP_Body :: %u", sizeof ( RTP_Body ) ); |
klauss | 132:05cd37f7e007 | 593 | vz_printf ( "Sizeof Vector :: %u", sizeof ( Vector ) ); |
klauss | 132:05cd37f7e007 | 594 | vz_printf ("Sizeof Timeslice :: %u", sizeof ( Timeslice ) ); |
klauss | 132:05cd37f7e007 | 595 | vz_printf ( "Sizeof Watchdog :: %u", sizeof ( Watchdog ) ); |
klauss | 121:ee02790d00b7 | 596 | |
klauss | 121:ee02790d00b7 | 597 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 598 | } |
klauss | 121:ee02790d00b7 | 599 | |
klauss | 121:ee02790d00b7 | 600 | int check_udp_packages_pending ( Vector * v_cb ) |
klauss | 121:ee02790d00b7 | 601 | { |
klauss | 121:ee02790d00b7 | 602 | fd_set fdSet; |
klauss | 121:ee02790d00b7 | 603 | FD_ZERO(&fdSet); |
klauss | 132:05cd37f7e007 | 604 | |
klauss | 132:05cd37f7e007 | 605 | udp_query = false; |
klauss | 132:05cd37f7e007 | 606 | from_eth = false; |
klauss | 121:ee02790d00b7 | 607 | |
klauss | 121:ee02790d00b7 | 608 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 121:ee02790d00b7 | 609 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 121:ee02790d00b7 | 610 | FD_SET( cb->get_sip_socket_fd(), &fdSet); |
klauss | 121:ee02790d00b7 | 611 | } |
klauss | 121:ee02790d00b7 | 612 | |
klauss | 121:ee02790d00b7 | 613 | /* Recepcao de pacotes UDP para atualizacao de callboxes */ |
klauss | 124:c1b6c893e1c3 | 614 | FD_SET( udp_bl_client.get_fd (), &fdSet); |
klauss | 121:ee02790d00b7 | 615 | |
klauss | 121:ee02790d00b7 | 616 | /* Recepcao de pacotes UDP para "tickagem" do watchdog */ |
klauss | 124:c1b6c893e1c3 | 617 | FD_SET( udp_wdt_client.get_fd (), &fdSet); |
klauss | 121:ee02790d00b7 | 618 | |
klauss | 121:ee02790d00b7 | 619 | // adiciona o socket de comandos prompt-UDP-ETH |
klauss | 124:c1b6c893e1c3 | 620 | FD_SET( udp_client.get_fd (), &fdSet ); |
klauss | 121:ee02790d00b7 | 621 | |
klauss | 121:ee02790d00b7 | 622 | // adiciona o socket de pedido de clock para o servidor |
klauss | 124:c1b6c893e1c3 | 623 | FD_SET( clock_sock.get_fd (), &fdSet ); |
klauss | 121:ee02790d00b7 | 624 | |
klauss | 121:ee02790d00b7 | 625 | struct timeval t; |
klauss | 121:ee02790d00b7 | 626 | t.tv_sec = 0; |
klauss | 121:ee02790d00b7 | 627 | t.tv_usec = 0; |
klauss | 124:c1b6c893e1c3 | 628 | int ret = lwip_select ( FD_SETSIZE, &fdSet, NULL, NULL, &t ); |
klauss | 121:ee02790d00b7 | 629 | |
klauss | 124:c1b6c893e1c3 | 630 | if ( ( udp_bl_timer.read() > 30) and (bl_start_flag) ) |
klauss | 124:c1b6c893e1c3 | 631 | { |
klauss | 121:ee02790d00b7 | 632 | udp_bl_timer.stop(); |
klauss | 121:ee02790d00b7 | 633 | udp_bl_timer.reset(); |
klauss | 121:ee02790d00b7 | 634 | bl_start_flag = 0; |
klauss | 126:1f90756250fb | 635 | if (bl_ts not_eq 0) { |
klauss | 121:ee02790d00b7 | 636 | ts->return_timeslice( bl_ts ); |
klauss | 121:ee02790d00b7 | 637 | bl_ts = 0; |
klauss | 121:ee02790d00b7 | 638 | } |
klauss | 126:1f90756250fb | 639 | if (bl_cb not_eq NULL) { |
klauss | 121:ee02790d00b7 | 640 | bl_cb -> set_timeslice( 0 ); |
klauss | 121:ee02790d00b7 | 641 | bl_cb -> cb_set_status ( cb_idle ); |
klauss | 121:ee02790d00b7 | 642 | bl_cb = NULL; |
klauss | 121:ee02790d00b7 | 643 | } |
klauss | 121:ee02790d00b7 | 644 | } |
klauss | 121:ee02790d00b7 | 645 | |
klauss | 121:ee02790d00b7 | 646 | if ( ret > 0 ) |
klauss | 121:ee02790d00b7 | 647 | { |
klauss | 132:05cd37f7e007 | 648 | for ( register uint8_t i = 0; i < v_cb -> size (); i++ ) |
klauss | 132:05cd37f7e007 | 649 | { |
klauss | 132:05cd37f7e007 | 650 | Call_Box * cb = ( Call_Box * )v_cb -> get_element ( i ); |
klauss | 132:05cd37f7e007 | 651 | int fd = cb -> get_sip_socket_fd (); |
klauss | 132:05cd37f7e007 | 652 | if ( FD_ISSET ( fd, &fdSet ) ) |
klauss | 132:05cd37f7e007 | 653 | { |
klauss | 132:05cd37f7e007 | 654 | int rcv = cb -> sip_udp_incomming_pkg (); |
klauss | 121:ee02790d00b7 | 655 | } |
klauss | 121:ee02790d00b7 | 656 | } |
klauss | 121:ee02790d00b7 | 657 | |
klauss | 121:ee02790d00b7 | 658 | /* Tratamento dos pacotes de bootloader vindo do servidor */ |
klauss | 121:ee02790d00b7 | 659 | if( FD_ISSET( udp_bl_client.get_fd(), &fdSet ) ) { |
klauss | 121:ee02790d00b7 | 660 | if( udp_bl_client.receiveFrom( udp_bl_server, bl_recv_buffer, sizeof( bl_recv_buffer ) ) > 0 ) { |
klauss | 121:ee02790d00b7 | 661 | uint16_t cnt = 0; |
klauss | 121:ee02790d00b7 | 662 | if (debug_bootloader) { |
klauss | 121:ee02790d00b7 | 663 | pc.printf("\r\nPACOTE SRV->HDR {"); |
klauss | 121:ee02790d00b7 | 664 | for (cnt = 0;cnt < UDP_BL_SIZE;cnt++) { |
klauss | 121:ee02790d00b7 | 665 | if ((cnt % 30) == 0) { |
klauss | 121:ee02790d00b7 | 666 | pc.printf("\r\n "); |
klauss | 121:ee02790d00b7 | 667 | pc.printf(hex16(cnt)); |
klauss | 121:ee02790d00b7 | 668 | pc.printf(" : "); |
klauss | 121:ee02790d00b7 | 669 | } |
klauss | 121:ee02790d00b7 | 670 | pc.printf(hex8(bl_recv_buffer[cnt])); |
klauss | 121:ee02790d00b7 | 671 | pc.printf(", "); |
klauss | 121:ee02790d00b7 | 672 | } |
klauss | 121:ee02790d00b7 | 673 | pc.printf("\r\n}"); |
klauss | 121:ee02790d00b7 | 674 | } |
klauss | 121:ee02790d00b7 | 675 | bl_peer = ((uint8_t)bl_recv_buffer[0])*256 + (uint8_t)bl_recv_buffer[1]; |
klauss | 121:ee02790d00b7 | 676 | bl_send_buffer[0] = bl_recv_buffer[0]; |
klauss | 121:ee02790d00b7 | 677 | bl_send_buffer[1] = bl_recv_buffer[1]; |
klauss | 121:ee02790d00b7 | 678 | for (cnt = 2;cnt < UDP_BL_SIZE;cnt++) { |
klauss | 121:ee02790d00b7 | 679 | bl_send_buffer[cnt] = 0; |
klauss | 121:ee02790d00b7 | 680 | } |
klauss | 121:ee02790d00b7 | 681 | |
klauss | 121:ee02790d00b7 | 682 | if ((bl_ts == 0) and !(bl_start_flag)) { |
klauss | 121:ee02790d00b7 | 683 | bl_ts = ts->get_timeslice(); |
klauss | 121:ee02790d00b7 | 684 | } |
klauss | 121:ee02790d00b7 | 685 | |
klauss | 121:ee02790d00b7 | 686 | /* caso nao haja timeslice disponivel informar servidor */ |
klauss | 121:ee02790d00b7 | 687 | if ((bl_ts == 0) and !(bl_start_flag)) { |
klauss | 121:ee02790d00b7 | 688 | strncpy(bl_send_buffer + 2,"cbxdead\x00",8); |
klauss | 132:05cd37f7e007 | 689 | int udp_bl_client_ret = udp_bl_client.sendTo ( udp_bl_server, bl_send_buffer, strlen ( bl_send_buffer ) ); |
klauss | 121:ee02790d00b7 | 690 | |
klauss | 126:1f90756250fb | 691 | if ( udp_bl_client_ret not_eq strlen( bl_send_buffer ) ) |
klauss | 121:ee02790d00b7 | 692 | { |
klauss | 132:05cd37f7e007 | 693 | reconnect_bl (); |
klauss | 132:05cd37f7e007 | 694 | miss_bl_udp_send_pkg ++; |
klauss | 132:05cd37f7e007 | 695 | if ( debug_reconnect ) vz_printf ( "[%d] Reconnect BL - %d", bl_peer, udp_bl_client_ret ); |
klauss | 121:ee02790d00b7 | 696 | } |
klauss | 121:ee02790d00b7 | 697 | } else { |
klauss | 121:ee02790d00b7 | 698 | |
klauss | 121:ee02790d00b7 | 699 | /* pacote para verificar se o callbox esta disponivel */ |
klauss | 121:ee02790d00b7 | 700 | if (!(strncmp(bl_recv_buffer + 2,"avaiable?",9))) { |
klauss | 121:ee02790d00b7 | 701 | bl_start_flag = 1; |
klauss | 121:ee02790d00b7 | 702 | udp_bl_timer.start(); |
klauss | 121:ee02790d00b7 | 703 | udp_bl_timer.reset(); |
klauss | 121:ee02790d00b7 | 704 | strncpy(bl_send_buffer + 2,"cbxalive\x00",9); |
klauss | 121:ee02790d00b7 | 705 | if (debug_bootloader) { |
klauss | 121:ee02790d00b7 | 706 | pc.printf("\r\nPACOTE HDR->SRV {"); |
klauss | 121:ee02790d00b7 | 707 | for (cnt = 0;cnt < UDP_BL_SIZE;cnt++) { |
klauss | 121:ee02790d00b7 | 708 | if ((cnt % 30) == 0) { |
klauss | 121:ee02790d00b7 | 709 | pc.printf("\r\n "); |
klauss | 121:ee02790d00b7 | 710 | pc.printf(hex16(cnt)); |
klauss | 121:ee02790d00b7 | 711 | pc.printf(" : "); |
klauss | 121:ee02790d00b7 | 712 | } |
klauss | 121:ee02790d00b7 | 713 | pc.printf(hex8(bl_send_buffer[cnt])); |
klauss | 121:ee02790d00b7 | 714 | pc.printf(", "); |
klauss | 121:ee02790d00b7 | 715 | } |
klauss | 121:ee02790d00b7 | 716 | pc.printf("\r\n}"); |
klauss | 121:ee02790d00b7 | 717 | } |
klauss | 132:05cd37f7e007 | 718 | int udp_bl_client_ret = udp_bl_client.sendTo ( udp_bl_server, bl_send_buffer, strlen ( bl_send_buffer ) ); |
klauss | 132:05cd37f7e007 | 719 | |
klauss | 132:05cd37f7e007 | 720 | if ( udp_bl_client_ret not_eq strlen( bl_send_buffer ) ) |
klauss | 132:05cd37f7e007 | 721 | { |
klauss | 132:05cd37f7e007 | 722 | reconnect_bl (); |
klauss | 132:05cd37f7e007 | 723 | miss_bl_udp_send_pkg ++; |
klauss | 132:05cd37f7e007 | 724 | if ( debug_reconnect ) vz_printf ( "[%d] Reconnect BL - %d", bl_peer, udp_bl_client_ret ); |
klauss | 132:05cd37f7e007 | 725 | } |
klauss | 121:ee02790d00b7 | 726 | } |
klauss | 121:ee02790d00b7 | 727 | |
klauss | 121:ee02790d00b7 | 728 | /* pacote para indicar o termino do processo de atualizacao */ |
klauss | 121:ee02790d00b7 | 729 | else if (!(strncmp(bl_recv_buffer + 2,"finished",8))) { |
klauss | 121:ee02790d00b7 | 730 | bl_start_flag = 0; |
klauss | 126:1f90756250fb | 731 | if (bl_ts not_eq 0) { |
klauss | 121:ee02790d00b7 | 732 | ts->return_timeslice( bl_ts ); |
klauss | 121:ee02790d00b7 | 733 | bl_ts = 0; |
klauss | 121:ee02790d00b7 | 734 | } |
klauss | 126:1f90756250fb | 735 | if (bl_cb not_eq NULL) { |
klauss | 121:ee02790d00b7 | 736 | bl_cb->set_timeslice( 0 ); |
klauss | 121:ee02790d00b7 | 737 | bl_cb -> cb_set_status( cb_idle ); |
klauss | 121:ee02790d00b7 | 738 | bl_cb = NULL; |
klauss | 121:ee02790d00b7 | 739 | } |
klauss | 121:ee02790d00b7 | 740 | } |
klauss | 121:ee02790d00b7 | 741 | |
klauss | 121:ee02790d00b7 | 742 | /* pacotes a serem repassados para o callbox */ |
klauss | 121:ee02790d00b7 | 743 | else if (bl_start_flag) { |
klauss | 121:ee02790d00b7 | 744 | uint16_t bl_cnt = 0; |
klauss | 121:ee02790d00b7 | 745 | udp_bl_timer.reset(); |
klauss | 121:ee02790d00b7 | 746 | /* pacote de ERASE enviado para o cbx */ |
klauss | 121:ee02790d00b7 | 747 | /* neste momento a cabeceira sabe que o servidor se comunicou com o callbox */ |
klauss | 121:ee02790d00b7 | 748 | if (!(strncmp(bl_recv_buffer + 2,"\x45",1))) { |
klauss | 121:ee02790d00b7 | 749 | bl_cb = find_CB( v_cb, bl_peer ); |
klauss | 126:1f90756250fb | 750 | if (bl_cb not_eq NULL) { |
klauss | 121:ee02790d00b7 | 751 | bl_cb->set_timeslice( bl_ts ); |
klauss | 121:ee02790d00b7 | 752 | bl_cb -> cb_set_status ( cb_bootloader ); |
klauss | 121:ee02790d00b7 | 753 | } |
klauss | 121:ee02790d00b7 | 754 | } |
klauss | 121:ee02790d00b7 | 755 | /* pacote de OK enviado para o cbx */ |
klauss | 121:ee02790d00b7 | 756 | /* neste momento a cabeceira desaloca o timeslice do callbox */ |
klauss | 121:ee02790d00b7 | 757 | if (!(strncmp(bl_recv_buffer + 2,"\x4f\x00\x00\x00",4))) { |
klauss | 121:ee02790d00b7 | 758 | ts->return_timeslice( bl_ts ); |
klauss | 121:ee02790d00b7 | 759 | bl_ts = 0; |
klauss | 126:1f90756250fb | 760 | if (bl_cb not_eq NULL) { |
klauss | 121:ee02790d00b7 | 761 | bl_cb->set_timeslice( 0 ); |
klauss | 121:ee02790d00b7 | 762 | } |
klauss | 121:ee02790d00b7 | 763 | } |
klauss | 121:ee02790d00b7 | 764 | bl_cbx_buffer[0] = bl_ts; |
klauss | 121:ee02790d00b7 | 765 | for (bl_cnt = 0; bl_cnt < BL_SIZE; bl_cnt++) { |
klauss | 121:ee02790d00b7 | 766 | bl_cbx_buffer[bl_cnt + 1] = bl_recv_buffer[bl_cnt + 2]; |
klauss | 121:ee02790d00b7 | 767 | } |
klauss | 121:ee02790d00b7 | 768 | if (debug_bootloader) { |
klauss | 121:ee02790d00b7 | 769 | pc.printf("\r\nPACOTE HDR->CBX {"); |
klauss | 121:ee02790d00b7 | 770 | for (cnt = 0;cnt < BL_SIZE + 1;cnt++) { |
klauss | 121:ee02790d00b7 | 771 | if ((cnt % 30) == 0) { |
klauss | 121:ee02790d00b7 | 772 | pc.printf("\r\n "); |
klauss | 121:ee02790d00b7 | 773 | pc.printf(hex16(cnt)); |
klauss | 121:ee02790d00b7 | 774 | pc.printf(" : "); |
klauss | 121:ee02790d00b7 | 775 | } |
klauss | 121:ee02790d00b7 | 776 | pc.printf(hex8(bl_cbx_buffer[cnt])); |
klauss | 121:ee02790d00b7 | 777 | pc.printf(", "); |
klauss | 121:ee02790d00b7 | 778 | } |
klauss | 121:ee02790d00b7 | 779 | pc.printf("\r\n}"); |
klauss | 121:ee02790d00b7 | 780 | } |
klauss | 126:1f90756250fb | 781 | if (bl_cb not_eq NULL) { |
klauss | 121:ee02790d00b7 | 782 | bl_port = bl_cb->get_port(); |
klauss | 121:ee02790d00b7 | 783 | } else { |
klauss | 121:ee02790d00b7 | 784 | bl_port = bl_peer; |
klauss | 121:ee02790d00b7 | 785 | } |
klauss | 121:ee02790d00b7 | 786 | send2callboxes( build_cb_package( bl_peer, bl_port, BOOTLOADER_CBX,bl_cbx_buffer, 0, BL_SIZE + 1, write_buffer) ); |
klauss | 121:ee02790d00b7 | 787 | } |
klauss | 121:ee02790d00b7 | 788 | } |
klauss | 121:ee02790d00b7 | 789 | } |
klauss | 121:ee02790d00b7 | 790 | } |
klauss | 121:ee02790d00b7 | 791 | |
klauss | 121:ee02790d00b7 | 792 | // verifica o socket do prompt-UDP-ETH |
klauss | 121:ee02790d00b7 | 793 | if( FD_ISSET( udp_client.get_fd(), &fdSet ) ) { |
klauss | 132:05cd37f7e007 | 794 | char to_prompt_process [ PROMPT_UDP_COMMAND_SIZE ]; |
klauss | 121:ee02790d00b7 | 795 | for( register int i = 0; i < PROMPT_UDP_COMMAND_SIZE; i++ ) to_prompt_process[ i ] = 0; |
klauss | 121:ee02790d00b7 | 796 | |
klauss | 132:05cd37f7e007 | 797 | int prompt_process_msg_rcv = udp_client.receiveFrom ( udp_server, to_prompt_process, ( PROMPT_UDP_COMMAND_SIZE - 1 ) ); |
klauss | 121:ee02790d00b7 | 798 | |
klauss | 132:05cd37f7e007 | 799 | if ( prompt_process_msg_rcv == -1 ) |
klauss | 121:ee02790d00b7 | 800 | { |
klauss | 132:05cd37f7e007 | 801 | if ( debug_reconnect ) vz_printf ("Reconnect Prompt Process"); |
klauss | 132:05cd37f7e007 | 802 | reconnect_udp_prompt_process (); |
klauss | 132:05cd37f7e007 | 803 | miss_prompt_udp_rcv_pkg ++; |
klauss | 121:ee02790d00b7 | 804 | } |
klauss | 132:05cd37f7e007 | 805 | else if ( prompt_process_msg_rcv > 0 ) |
klauss | 121:ee02790d00b7 | 806 | { |
klauss | 121:ee02790d00b7 | 807 | udp_query = true; |
klauss | 132:05cd37f7e007 | 808 | from_eth = true; |
klauss | 132:05cd37f7e007 | 809 | prompt_process ( to_prompt_process, prompt_process_msg_rcv ); |
klauss | 121:ee02790d00b7 | 810 | } |
klauss | 121:ee02790d00b7 | 811 | } |
klauss | 121:ee02790d00b7 | 812 | |
klauss | 121:ee02790d00b7 | 813 | // verifica o socket do watchdog |
klauss | 124:c1b6c893e1c3 | 814 | if ( FD_ISSET ( udp_wdt_client.get_fd(), &fdSet ) ) |
klauss | 124:c1b6c893e1c3 | 815 | { |
klauss | 122:480c44b0e205 | 816 | const uint16_t WAKE_MSG_SIZE = 768; |
klauss | 122:480c44b0e205 | 817 | static char wake_msg [ WAKE_MSG_SIZE ]; |
klauss | 122:480c44b0e205 | 818 | |
klauss | 122:480c44b0e205 | 819 | for ( register uint16_t i = 0; i < WAKE_MSG_SIZE; i ++ ) wake_msg [ i ] = 0; |
klauss | 122:480c44b0e205 | 820 | |
klauss | 121:ee02790d00b7 | 821 | Endpoint udp_wdt_server; |
klauss | 121:ee02790d00b7 | 822 | |
klauss | 132:05cd37f7e007 | 823 | int wake_msg_rcv = udp_wdt_client.receiveFrom ( udp_wdt_server, wake_msg, sizeof ( wake_msg ) ); |
klauss | 121:ee02790d00b7 | 824 | |
klauss | 132:05cd37f7e007 | 825 | if ( dmissed_wdt ) vz_debug ("wake_msg_rcv :: %d -- wake_msg :: %s", wake_msg_rcv, wake_msg ); |
klauss | 122:480c44b0e205 | 826 | |
klauss | 121:ee02790d00b7 | 827 | if( wake_msg_rcv == -1 ) |
klauss | 121:ee02790d00b7 | 828 | { |
klauss | 132:05cd37f7e007 | 829 | if( debug_reconnect ) vz_printf ("Reconnect Extern wdt"); |
klauss | 132:05cd37f7e007 | 830 | reconnect_extern_wdt_socket (); |
klauss | 132:05cd37f7e007 | 831 | miss_wdt_send_pkg ++; |
klauss | 121:ee02790d00b7 | 832 | } |
klauss | 121:ee02790d00b7 | 833 | else if( wake_msg_rcv > 0 ) |
klauss | 121:ee02790d00b7 | 834 | { |
klauss | 121:ee02790d00b7 | 835 | if( !( strncmp( wake_msg, "alive", 5 ) ) ) { |
klauss | 121:ee02790d00b7 | 836 | // Just ckeck but not set 'alive?' |
klauss | 121:ee02790d00b7 | 837 | // 'alive*' - force wdt tick right now |
klauss | 121:ee02790d00b7 | 838 | // Ckecking and set 'alive' |
klauss | 121:ee02790d00b7 | 839 | bool question_alive = ( wake_msg[ 5 ] == '?' ); |
klauss | 121:ee02790d00b7 | 840 | if( wake_msg[ 5 ] == '*' ) wdt.kick(); |
klauss | 121:ee02790d00b7 | 841 | |
klauss | 132:05cd37f7e007 | 842 | if ( dmissed_wdt ) if ( wake_msg [ 5 ] == '?' ) vz_debug ("Recebi o alive ???"); |
klauss | 122:480c44b0e205 | 843 | |
klauss | 132:05cd37f7e007 | 844 | build_wdt_string ( wake_msg, WAKE_MSG_SIZE - 1 ); |
klauss | 132:05cd37f7e007 | 845 | |
klauss | 122:480c44b0e205 | 846 | wake_msg[ WAKE_MSG_SIZE - 1 ] = 0; |
klauss | 122:480c44b0e205 | 847 | |
klauss | 132:05cd37f7e007 | 848 | int send = udp_wdt_client.sendTo ( udp_wdt_server, wake_msg, strlen ( wake_msg ) ); |
klauss | 132:05cd37f7e007 | 849 | if( send not_eq strlen ( wake_msg ) ) |
klauss | 121:ee02790d00b7 | 850 | { |
klauss | 132:05cd37f7e007 | 851 | if ( debug_reconnect ) vz_debug ("Reconnect Extern wdt (%d, %d)", send, strlen ( wake_msg ) ); |
klauss | 122:480c44b0e205 | 852 | reconnect_extern_wdt_socket (); |
klauss | 132:05cd37f7e007 | 853 | miss_wdt_send_pkg ++; |
klauss | 121:ee02790d00b7 | 854 | } |
klauss | 122:480c44b0e205 | 855 | |
klauss | 132:05cd37f7e007 | 856 | if ( ( |
klauss | 132:05cd37f7e007 | 857 | (!question_alive) |
klauss | 132:05cd37f7e007 | 858 | && ( cb_new_counter <= MAX_CB_IN_A_BRANCH ) |
klauss | 132:05cd37f7e007 | 859 | && ( ( cb_new_counter >= MIN_CBX_IN_A_BRANCH ) || ( disable_wdt_from_cbx ) ) |
klauss | 132:05cd37f7e007 | 860 | ) ) |
klauss | 132:05cd37f7e007 | 861 | { |
klauss | 132:05cd37f7e007 | 862 | external_wdt = EXTERN_WDT_IDLE; |
klauss | 132:05cd37f7e007 | 863 | if ( dmissed_wdt ) vz_debug ("kickando"); |
klauss | 132:05cd37f7e007 | 864 | } |
klauss | 132:05cd37f7e007 | 865 | |
klauss | 132:05cd37f7e007 | 866 | if ( dmissed_wdt ) vz_debug ("Mandei send = %d[::%s::] to [%s:%i]", send, wake_msg, udp_wdt_server.get_address (), udp_wdt_server.get_port () ); |
klauss | 122:480c44b0e205 | 867 | |
klauss | 121:ee02790d00b7 | 868 | } else if( !( strncmp( wake_msg, "reset", 5 ) ) ) { |
klauss | 121:ee02790d00b7 | 869 | external_wdt = 0; |
klauss | 121:ee02790d00b7 | 870 | |
klauss | 121:ee02790d00b7 | 871 | sprintf( wake_msg, "rst:%u:", uptime ); |
klauss | 132:05cd37f7e007 | 872 | int send = udp_wdt_client.sendTo ( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 126:1f90756250fb | 873 | if( send not_eq strlen( wake_msg ) ) |
klauss | 121:ee02790d00b7 | 874 | { |
klauss | 132:05cd37f7e007 | 875 | if( debug_reconnect ) vz_printf ("Reconnect Extern wdt"); |
klauss | 132:05cd37f7e007 | 876 | reconnect_extern_wdt_socket (); |
klauss | 132:05cd37f7e007 | 877 | miss_wdt_send_pkg ++; |
klauss | 121:ee02790d00b7 | 878 | } |
klauss | 121:ee02790d00b7 | 879 | } |
klauss | 121:ee02790d00b7 | 880 | } |
klauss | 121:ee02790d00b7 | 881 | } |
klauss | 121:ee02790d00b7 | 882 | |
klauss | 121:ee02790d00b7 | 883 | if( FD_ISSET( clock_sock.get_fd(), &fdSet ) ) |
klauss | 121:ee02790d00b7 | 884 | { |
klauss | 121:ee02790d00b7 | 885 | update_clock (); |
klauss | 121:ee02790d00b7 | 886 | } |
klauss | 121:ee02790d00b7 | 887 | } |
klauss | 121:ee02790d00b7 | 888 | |
klauss | 121:ee02790d00b7 | 889 | return ( ret ); |
klauss | 121:ee02790d00b7 | 890 | } |
klauss | 121:ee02790d00b7 | 891 | |
klauss | 121:ee02790d00b7 | 892 | int show_cb_content ( void ) |
klauss | 121:ee02790d00b7 | 893 | { |
klauss | 121:ee02790d00b7 | 894 | Call_Box * cb = find_CB ( v_cb, print_this_cb ); |
klauss | 132:05cd37f7e007 | 895 | if ( cb not_eq NULL ) { |
klauss | 121:ee02790d00b7 | 896 | cb -> print_yourself (); |
klauss | 132:05cd37f7e007 | 897 | } else { |
klauss | 132:05cd37f7e007 | 898 | if ( print_values ) { |
klauss | 132:05cd37f7e007 | 899 | vz_debug ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 132:05cd37f7e007 | 900 | } else { |
klauss | 132:05cd37f7e007 | 901 | vz_printf ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 121:ee02790d00b7 | 902 | } |
klauss | 121:ee02790d00b7 | 903 | } |
klauss | 121:ee02790d00b7 | 904 | |
klauss | 121:ee02790d00b7 | 905 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 906 | } |
klauss | 121:ee02790d00b7 | 907 | |
klauss | 121:ee02790d00b7 | 908 | int show_cb_content_all ( void ) |
klauss | 121:ee02790d00b7 | 909 | { |
klauss | 132:05cd37f7e007 | 910 | if ( v_cb -> size () == 0 ) { |
klauss | 132:05cd37f7e007 | 911 | vz_printf ("known CBx :: 0"); |
klauss | 121:ee02790d00b7 | 912 | } |
klauss | 121:ee02790d00b7 | 913 | |
klauss | 121:ee02790d00b7 | 914 | for ( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 121:ee02790d00b7 | 915 | { |
klauss | 121:ee02790d00b7 | 916 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 121:ee02790d00b7 | 917 | |
klauss | 132:05cd37f7e007 | 918 | if ( cb not_eq NULL ) { |
klauss | 121:ee02790d00b7 | 919 | cb -> print_yourself (); |
klauss | 132:05cd37f7e007 | 920 | } else { |
klauss | 132:05cd37f7e007 | 921 | if ( print_values ) vz_debug ("Objeto CBx ( %d ) nao encontrado", i ); |
klauss | 121:ee02790d00b7 | 922 | } |
klauss | 121:ee02790d00b7 | 923 | } |
klauss | 121:ee02790d00b7 | 924 | |
klauss | 121:ee02790d00b7 | 925 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 926 | } |
klauss | 121:ee02790d00b7 | 927 | |
klauss | 121:ee02790d00b7 | 928 | int show_rtp ( void ) |
klauss | 121:ee02790d00b7 | 929 | { |
klauss | 132:05cd37f7e007 | 930 | vz_printf (":: RTP :: %u", v_cb->size() ); |
klauss | 121:ee02790d00b7 | 931 | |
klauss | 121:ee02790d00b7 | 932 | int ext_list[ MAX_CB_IN_A_BRANCH ]; |
klauss | 121:ee02790d00b7 | 933 | |
klauss | 121:ee02790d00b7 | 934 | if( v_cb->size() >= 1 ) { |
klauss | 121:ee02790d00b7 | 935 | for( register int i = 0; i < v_cb->size(); i++ ) |
klauss | 121:ee02790d00b7 | 936 | { |
klauss | 121:ee02790d00b7 | 937 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 121:ee02790d00b7 | 938 | } |
klauss | 121:ee02790d00b7 | 939 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 121:ee02790d00b7 | 940 | } |
klauss | 121:ee02790d00b7 | 941 | |
klauss | 121:ee02790d00b7 | 942 | for ( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 121:ee02790d00b7 | 943 | { |
klauss | 121:ee02790d00b7 | 944 | Call_Box * cb = find_CB( v_cb, ext_list[ i ] ); |
klauss | 126:1f90756250fb | 945 | if( cb not_eq NULL ) |
klauss | 121:ee02790d00b7 | 946 | { |
klauss | 132:05cd37f7e007 | 947 | vz_printf ("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", |
klauss | 121:ee02790d00b7 | 948 | cb -> get_ext (), |
klauss | 121:ee02790d00b7 | 949 | cb -> get_port (), |
klauss | 121:ee02790d00b7 | 950 | cb -> get_sip_ext (), |
klauss | 121:ee02790d00b7 | 951 | cb -> get_sip_port (), |
klauss | 121:ee02790d00b7 | 952 | cb -> get_rtp_port () |
klauss | 121:ee02790d00b7 | 953 | ); |
klauss | 121:ee02790d00b7 | 954 | } |
klauss | 121:ee02790d00b7 | 955 | } |
klauss | 121:ee02790d00b7 | 956 | |
klauss | 121:ee02790d00b7 | 957 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 958 | } |
klauss | 121:ee02790d00b7 | 959 | |
klauss | 132:05cd37f7e007 | 960 | int |
klauss | 132:05cd37f7e007 | 961 | fuck_rtp ( Vector * v_cb ) |
klauss | 121:ee02790d00b7 | 962 | { |
klauss | 121:ee02790d00b7 | 963 | Call_Box * cb = find_CB( v_cb, frtp_target ); |
klauss | 132:05cd37f7e007 | 964 | |
klauss | 132:05cd37f7e007 | 965 | if ( cb not_eq NULL ) { |
klauss | 121:ee02790d00b7 | 966 | cb -> set_rtp_port ( -1008789032 ); |
klauss | 132:05cd37f7e007 | 967 | } else { |
klauss | 132:05cd37f7e007 | 968 | vz_debug ("frtp fail"); |
klauss | 121:ee02790d00b7 | 969 | } |
klauss | 121:ee02790d00b7 | 970 | |
klauss | 121:ee02790d00b7 | 971 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 972 | } |
klauss | 121:ee02790d00b7 | 973 | |
klauss | 132:05cd37f7e007 | 974 | int |
klauss | 132:05cd37f7e007 | 975 | show_hex_cb_content ( void ) |
klauss | 121:ee02790d00b7 | 976 | { |
klauss | 121:ee02790d00b7 | 977 | uint8_t * ptr = ( uint8_t * ) find_CB ( v_cb, print_hex_this_cb ); |
klauss | 121:ee02790d00b7 | 978 | |
klauss | 126:1f90756250fb | 979 | if ( ptr not_eq NULL ) |
klauss | 121:ee02790d00b7 | 980 | { |
klauss | 132:05cd37f7e007 | 981 | vz_printf ( "Values :: %p\r\n", ( void *) ptr ); |
klauss | 132:05cd37f7e007 | 982 | |
klauss | 121:ee02790d00b7 | 983 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 121:ee02790d00b7 | 984 | { |
klauss | 121:ee02790d00b7 | 985 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 121:ee02790d00b7 | 986 | |
klauss | 121:ee02790d00b7 | 987 | if ( ( i % 32 ) == 0 ) |
klauss | 121:ee02790d00b7 | 988 | { |
klauss | 132:05cd37f7e007 | 989 | if ( i not_eq 0 ) { |
klauss | 121:ee02790d00b7 | 990 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 132:05cd37f7e007 | 991 | } else { |
klauss | 121:ee02790d00b7 | 992 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 993 | } |
klauss | 132:05cd37f7e007 | 994 | } else { |
klauss | 121:ee02790d00b7 | 995 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 996 | } |
klauss | 121:ee02790d00b7 | 997 | } |
klauss | 132:05cd37f7e007 | 998 | |
klauss | 121:ee02790d00b7 | 999 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 121:ee02790d00b7 | 1000 | |
klauss | 121:ee02790d00b7 | 1001 | if ( tcp_session ) { |
klauss | 121:ee02790d00b7 | 1002 | char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ]; |
klauss | 121:ee02790d00b7 | 1003 | |
klauss | 121:ee02790d00b7 | 1004 | for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0; |
klauss | 121:ee02790d00b7 | 1005 | |
klauss | 121:ee02790d00b7 | 1006 | uint8_t * ptr = ( uint8_t * ) find_CB ( v_cb, print_hex_this_cb ); |
klauss | 121:ee02790d00b7 | 1007 | |
klauss | 121:ee02790d00b7 | 1008 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 121:ee02790d00b7 | 1009 | { |
klauss | 121:ee02790d00b7 | 1010 | char tmp[ 16 ]; |
klauss | 121:ee02790d00b7 | 1011 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1012 | strcat( aux, tmp ); |
klauss | 121:ee02790d00b7 | 1013 | } |
klauss | 121:ee02790d00b7 | 1014 | |
klauss | 121:ee02790d00b7 | 1015 | strcat( aux, "\n\r\0" ); |
klauss | 121:ee02790d00b7 | 1016 | tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 121:ee02790d00b7 | 1017 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 121:ee02790d00b7 | 1018 | } |
klauss | 121:ee02790d00b7 | 1019 | } |
klauss | 121:ee02790d00b7 | 1020 | else |
klauss | 121:ee02790d00b7 | 1021 | { |
klauss | 132:05cd37f7e007 | 1022 | if ( print_values ) vz_debug ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 121:ee02790d00b7 | 1023 | } |
klauss | 121:ee02790d00b7 | 1024 | |
klauss | 121:ee02790d00b7 | 1025 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1026 | } |
klauss | 121:ee02790d00b7 | 1027 | |
klauss | 121:ee02790d00b7 | 1028 | int show_hex_cb_content_all () |
klauss | 121:ee02790d00b7 | 1029 | { |
klauss | 121:ee02790d00b7 | 1030 | if ( v_cb -> size () == 0 ) |
klauss | 121:ee02790d00b7 | 1031 | { |
klauss | 132:05cd37f7e007 | 1032 | vz_printf ("known CBx :: 0"); |
klauss | 121:ee02790d00b7 | 1033 | } |
klauss | 121:ee02790d00b7 | 1034 | |
klauss | 121:ee02790d00b7 | 1035 | for ( register uint8_t j = 0; j < v_cb->size(); j++ ) |
klauss | 121:ee02790d00b7 | 1036 | { |
klauss | 121:ee02790d00b7 | 1037 | uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); |
klauss | 121:ee02790d00b7 | 1038 | |
klauss | 126:1f90756250fb | 1039 | if ( ptr not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1040 | { |
klauss | 132:05cd37f7e007 | 1041 | vz_printf ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 121:ee02790d00b7 | 1042 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 121:ee02790d00b7 | 1043 | { |
klauss | 121:ee02790d00b7 | 1044 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1045 | |
klauss | 121:ee02790d00b7 | 1046 | if ( ( i % 32 ) == 0 ) |
klauss | 121:ee02790d00b7 | 1047 | { |
klauss | 132:05cd37f7e007 | 1048 | if( i not_eq 0 ) { |
klauss | 121:ee02790d00b7 | 1049 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 132:05cd37f7e007 | 1050 | } else { |
klauss | 121:ee02790d00b7 | 1051 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 1052 | } |
klauss | 132:05cd37f7e007 | 1053 | } else { |
klauss | 121:ee02790d00b7 | 1054 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 1055 | } |
klauss | 121:ee02790d00b7 | 1056 | } |
klauss | 132:05cd37f7e007 | 1057 | |
klauss | 121:ee02790d00b7 | 1058 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 121:ee02790d00b7 | 1059 | |
klauss | 132:05cd37f7e007 | 1060 | if ( tcp_session ) |
klauss | 132:05cd37f7e007 | 1061 | { |
klauss | 121:ee02790d00b7 | 1062 | char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ]; |
klauss | 121:ee02790d00b7 | 1063 | |
klauss | 121:ee02790d00b7 | 1064 | for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0; |
klauss | 121:ee02790d00b7 | 1065 | |
klauss | 121:ee02790d00b7 | 1066 | uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); |
klauss | 121:ee02790d00b7 | 1067 | |
klauss | 121:ee02790d00b7 | 1068 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 121:ee02790d00b7 | 1069 | { |
klauss | 121:ee02790d00b7 | 1070 | char tmp[ 16 ]; |
klauss | 121:ee02790d00b7 | 1071 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1072 | strcat( aux, tmp ); |
klauss | 121:ee02790d00b7 | 1073 | } |
klauss | 121:ee02790d00b7 | 1074 | |
klauss | 121:ee02790d00b7 | 1075 | strcat( aux, "\n\r\0" ); |
klauss | 121:ee02790d00b7 | 1076 | tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 121:ee02790d00b7 | 1077 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 121:ee02790d00b7 | 1078 | } |
klauss | 132:05cd37f7e007 | 1079 | } else { |
klauss | 132:05cd37f7e007 | 1080 | if ( print_values ) { |
klauss | 132:05cd37f7e007 | 1081 | vz_debug ("Objeto CBx ( %d ) nao encontrado", j ); |
klauss | 132:05cd37f7e007 | 1082 | } else { |
klauss | 132:05cd37f7e007 | 1083 | vz_printf ("Objeto CBx ( %d ) nao encontrado", j ); |
klauss | 121:ee02790d00b7 | 1084 | } |
klauss | 121:ee02790d00b7 | 1085 | } |
klauss | 121:ee02790d00b7 | 1086 | } |
klauss | 121:ee02790d00b7 | 1087 | |
klauss | 121:ee02790d00b7 | 1088 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1089 | } |
klauss | 121:ee02790d00b7 | 1090 | |
klauss | 121:ee02790d00b7 | 1091 | |
klauss | 132:05cd37f7e007 | 1092 | int show_cb_sip ( void ) |
klauss | 121:ee02790d00b7 | 1093 | { |
klauss | 121:ee02790d00b7 | 1094 | Call_Box * cb = find_CB ( v_cb, print_this_sip ); |
klauss | 121:ee02790d00b7 | 1095 | |
klauss | 126:1f90756250fb | 1096 | if ( cb not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1097 | { |
klauss | 121:ee02790d00b7 | 1098 | if( cb -> sip_print_yourself () == -1 ) |
klauss | 121:ee02790d00b7 | 1099 | { |
klauss | 132:05cd37f7e007 | 1100 | if( print_values ) { |
klauss | 132:05cd37f7e007 | 1101 | vz_debug ("Sip param of %d equals NULL", print_this_sip ); |
klauss | 132:05cd37f7e007 | 1102 | } else { |
klauss | 132:05cd37f7e007 | 1103 | vz_printf ("Sip param of %d equals NULL", print_this_sip ); |
klauss | 121:ee02790d00b7 | 1104 | } |
klauss | 121:ee02790d00b7 | 1105 | } |
klauss | 132:05cd37f7e007 | 1106 | } else { |
klauss | 132:05cd37f7e007 | 1107 | if ( print_values ) { |
klauss | 132:05cd37f7e007 | 1108 | vz_debug ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 132:05cd37f7e007 | 1109 | } else { |
klauss | 132:05cd37f7e007 | 1110 | vz_printf ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 121:ee02790d00b7 | 1111 | } |
klauss | 121:ee02790d00b7 | 1112 | } |
klauss | 121:ee02790d00b7 | 1113 | |
klauss | 121:ee02790d00b7 | 1114 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1115 | } |
klauss | 132:05cd37f7e007 | 1116 | int show_cb_sip_all ( void ) |
klauss | 121:ee02790d00b7 | 1117 | { |
klauss | 121:ee02790d00b7 | 1118 | if ( v_cb -> size () == 0 ) |
klauss | 121:ee02790d00b7 | 1119 | { |
klauss | 132:05cd37f7e007 | 1120 | vz_printf ("known CBx :: 0"); |
klauss | 121:ee02790d00b7 | 1121 | } |
klauss | 121:ee02790d00b7 | 1122 | |
klauss | 121:ee02790d00b7 | 1123 | for ( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 121:ee02790d00b7 | 1124 | { |
klauss | 121:ee02790d00b7 | 1125 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 121:ee02790d00b7 | 1126 | |
klauss | 126:1f90756250fb | 1127 | if ( cb not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1128 | { |
klauss | 121:ee02790d00b7 | 1129 | if ( cb -> sip_print_yourself () == -1 ) |
klauss | 121:ee02790d00b7 | 1130 | { |
klauss | 132:05cd37f7e007 | 1131 | if ( print_values ) { |
klauss | 132:05cd37f7e007 | 1132 | vz_debug ("Sip param of %d equals NULL", print_this_sip ); |
klauss | 132:05cd37f7e007 | 1133 | } else { |
klauss | 132:05cd37f7e007 | 1134 | vz_printf ("Sip param of %d equals NULL", print_this_sip ); |
klauss | 121:ee02790d00b7 | 1135 | } |
klauss | 121:ee02790d00b7 | 1136 | } |
klauss | 132:05cd37f7e007 | 1137 | } else { |
klauss | 132:05cd37f7e007 | 1138 | if( print_values ) { |
klauss | 132:05cd37f7e007 | 1139 | vz_debug ("CBx %d not found", print_this_sip ); |
klauss | 132:05cd37f7e007 | 1140 | } else { |
klauss | 132:05cd37f7e007 | 1141 | vz_printf ("CBx %d not found", print_this_sip ); |
klauss | 121:ee02790d00b7 | 1142 | } |
klauss | 121:ee02790d00b7 | 1143 | } |
klauss | 121:ee02790d00b7 | 1144 | } |
klauss | 121:ee02790d00b7 | 1145 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1146 | } |
klauss | 121:ee02790d00b7 | 1147 | |
klauss | 132:05cd37f7e007 | 1148 | int show_cb_hex_sip ( void ) |
klauss | 121:ee02790d00b7 | 1149 | { |
klauss | 121:ee02790d00b7 | 1150 | uint8_t * ptr = NULL; |
klauss | 121:ee02790d00b7 | 1151 | |
klauss | 121:ee02790d00b7 | 1152 | Call_Box * cb = find_CB ( v_cb, print_hex_this_sip ); |
klauss | 132:05cd37f7e007 | 1153 | |
klauss | 126:1f90756250fb | 1154 | if( cb not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1155 | { |
klauss | 121:ee02790d00b7 | 1156 | ptr = ( uint8_t * ) cb -> get_sip (); |
klauss | 121:ee02790d00b7 | 1157 | } |
klauss | 121:ee02790d00b7 | 1158 | |
klauss | 126:1f90756250fb | 1159 | if ( ptr not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1160 | { |
klauss | 132:05cd37f7e007 | 1161 | vz_printf ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 121:ee02790d00b7 | 1162 | for ( register int i = 0; i < sizeof( Sip ); i++ ) |
klauss | 121:ee02790d00b7 | 1163 | { |
klauss | 121:ee02790d00b7 | 1164 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1165 | |
klauss | 121:ee02790d00b7 | 1166 | if ( ( i % 32 ) == 0 ) |
klauss | 121:ee02790d00b7 | 1167 | { |
klauss | 132:05cd37f7e007 | 1168 | if( i not_eq 0 ) { |
klauss | 121:ee02790d00b7 | 1169 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 132:05cd37f7e007 | 1170 | } else { |
klauss | 121:ee02790d00b7 | 1171 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 1172 | } |
klauss | 132:05cd37f7e007 | 1173 | } else { |
klauss | 121:ee02790d00b7 | 1174 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 1175 | } |
klauss | 121:ee02790d00b7 | 1176 | } |
klauss | 132:05cd37f7e007 | 1177 | |
klauss | 121:ee02790d00b7 | 1178 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 121:ee02790d00b7 | 1179 | |
klauss | 121:ee02790d00b7 | 1180 | if ( tcp_session ) { |
klauss | 121:ee02790d00b7 | 1181 | char aux[ ( 32 * 3 ) + 5 ]; |
klauss | 121:ee02790d00b7 | 1182 | |
klauss | 121:ee02790d00b7 | 1183 | for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; |
klauss | 121:ee02790d00b7 | 1184 | |
klauss | 121:ee02790d00b7 | 1185 | ptr = NULL; |
klauss | 121:ee02790d00b7 | 1186 | |
klauss | 121:ee02790d00b7 | 1187 | print_hex_sip_var = false; |
klauss | 121:ee02790d00b7 | 1188 | Call_Box * cb = find_CB ( v_cb, print_hex_this_sip ); |
klauss | 126:1f90756250fb | 1189 | if( cb not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1190 | { |
klauss | 121:ee02790d00b7 | 1191 | ptr = ( uint8_t * ) cb -> get_sip (); |
klauss | 121:ee02790d00b7 | 1192 | } |
klauss | 121:ee02790d00b7 | 1193 | |
klauss | 126:1f90756250fb | 1194 | if ( ptr not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1195 | { |
klauss | 121:ee02790d00b7 | 1196 | bool finished = false; |
klauss | 121:ee02790d00b7 | 1197 | volatile int i = 0; |
klauss | 121:ee02790d00b7 | 1198 | int count = 0; |
klauss | 121:ee02790d00b7 | 1199 | Timer dont_overwrite_tcp_buffer; |
klauss | 121:ee02790d00b7 | 1200 | dont_overwrite_tcp_buffer.reset (); |
klauss | 121:ee02790d00b7 | 1201 | dont_overwrite_tcp_buffer.start (); |
klauss | 121:ee02790d00b7 | 1202 | |
klauss | 121:ee02790d00b7 | 1203 | while ( !finished ) |
klauss | 121:ee02790d00b7 | 1204 | { |
klauss | 121:ee02790d00b7 | 1205 | if( dont_overwrite_tcp_buffer.read_ms () >= 500 ) |
klauss | 121:ee02790d00b7 | 1206 | { |
klauss | 121:ee02790d00b7 | 1207 | dont_overwrite_tcp_buffer.reset(); |
klauss | 121:ee02790d00b7 | 1208 | for ( ; i < sizeof( Sip ); i++ ) |
klauss | 121:ee02790d00b7 | 1209 | { |
klauss | 121:ee02790d00b7 | 1210 | char tmp[ 16 ]; |
klauss | 121:ee02790d00b7 | 1211 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1212 | strcat( aux, tmp ); |
klauss | 121:ee02790d00b7 | 1213 | count++; |
klauss | 121:ee02790d00b7 | 1214 | |
klauss | 121:ee02790d00b7 | 1215 | if ( count >= 32 ) |
klauss | 121:ee02790d00b7 | 1216 | { |
klauss | 121:ee02790d00b7 | 1217 | count = 0; |
klauss | 121:ee02790d00b7 | 1218 | i++; |
klauss | 121:ee02790d00b7 | 1219 | break; |
klauss | 121:ee02790d00b7 | 1220 | } |
klauss | 121:ee02790d00b7 | 1221 | } |
klauss | 121:ee02790d00b7 | 1222 | strcat ( aux, "\n\r\0" ); |
klauss | 121:ee02790d00b7 | 1223 | tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 121:ee02790d00b7 | 1224 | if ( i >= sizeof ( Sip ) ) finished = true; |
klauss | 121:ee02790d00b7 | 1225 | strcpy ( aux, "\0" ); |
klauss | 121:ee02790d00b7 | 1226 | } |
klauss | 121:ee02790d00b7 | 1227 | } |
klauss | 121:ee02790d00b7 | 1228 | dont_overwrite_tcp_buffer.reset(); |
klauss | 121:ee02790d00b7 | 1229 | dont_overwrite_tcp_buffer.stop(); |
klauss | 121:ee02790d00b7 | 1230 | tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 121:ee02790d00b7 | 1231 | } |
klauss | 121:ee02790d00b7 | 1232 | } |
klauss | 121:ee02790d00b7 | 1233 | } |
klauss | 121:ee02790d00b7 | 1234 | else |
klauss | 121:ee02790d00b7 | 1235 | { |
klauss | 132:05cd37f7e007 | 1236 | if ( print_values ) vz_debug ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 121:ee02790d00b7 | 1237 | } |
klauss | 121:ee02790d00b7 | 1238 | |
klauss | 121:ee02790d00b7 | 1239 | |
klauss | 121:ee02790d00b7 | 1240 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1241 | } |
klauss | 121:ee02790d00b7 | 1242 | |
klauss | 121:ee02790d00b7 | 1243 | int show_rtp_on_call ( void ) |
klauss | 121:ee02790d00b7 | 1244 | { |
klauss | 132:05cd37f7e007 | 1245 | vz_printf (":: CAll RTP :: %u", v_call->size() ); |
klauss | 121:ee02790d00b7 | 1246 | |
klauss | 121:ee02790d00b7 | 1247 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 121:ee02790d00b7 | 1248 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 126:1f90756250fb | 1249 | if( call not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1250 | { |
klauss | 132:05cd37f7e007 | 1251 | vz_printf ("CBX ( %d, %d ) - Server ( %d, %d )", |
klauss | 121:ee02790d00b7 | 1252 | call->get_cb_ext(), |
klauss | 121:ee02790d00b7 | 1253 | call->get_cb_port(), |
klauss | 121:ee02790d00b7 | 1254 | call->get_rtp_server_ext(), |
klauss | 121:ee02790d00b7 | 1255 | call->get_rtp_server_port() |
klauss | 121:ee02790d00b7 | 1256 | ); |
klauss | 121:ee02790d00b7 | 1257 | } |
klauss | 121:ee02790d00b7 | 1258 | } |
klauss | 121:ee02790d00b7 | 1259 | |
klauss | 121:ee02790d00b7 | 1260 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1261 | } |
klauss | 121:ee02790d00b7 | 1262 | |
klauss | 121:ee02790d00b7 | 1263 | int show_call ( void ) |
klauss | 121:ee02790d00b7 | 1264 | { |
klauss | 126:1f90756250fb | 1265 | VZ_call * call = find_Call ( v_call, print_this_call ); |
klauss | 121:ee02790d00b7 | 1266 | |
klauss | 126:1f90756250fb | 1267 | if ( call not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1268 | { |
klauss | 132:05cd37f7e007 | 1269 | vz_printf ("Values :: %p\r\n", ( void *) call ); |
klauss | 121:ee02790d00b7 | 1270 | call -> print_yourself (); |
klauss | 121:ee02790d00b7 | 1271 | } |
klauss | 121:ee02790d00b7 | 1272 | else |
klauss | 121:ee02790d00b7 | 1273 | { |
klauss | 132:05cd37f7e007 | 1274 | if( print_values ) { |
klauss | 132:05cd37f7e007 | 1275 | vz_debug ("Call %d not found", print_this_call ); |
klauss | 132:05cd37f7e007 | 1276 | } else { |
klauss | 132:05cd37f7e007 | 1277 | vz_printf ("Call %d not found", print_this_call ); |
klauss | 121:ee02790d00b7 | 1278 | } |
klauss | 121:ee02790d00b7 | 1279 | } |
klauss | 121:ee02790d00b7 | 1280 | |
klauss | 121:ee02790d00b7 | 1281 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1282 | } |
klauss | 121:ee02790d00b7 | 1283 | |
klauss | 121:ee02790d00b7 | 1284 | int show_hex_call ( void ) |
klauss | 121:ee02790d00b7 | 1285 | { |
klauss | 126:1f90756250fb | 1286 | VZ_call * call = find_Call ( v_call, print_hex_this_call ); |
klauss | 121:ee02790d00b7 | 1287 | |
klauss | 121:ee02790d00b7 | 1288 | uint8_t * ptr = NULL; |
klauss | 126:1f90756250fb | 1289 | if( call not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1290 | { |
klauss | 121:ee02790d00b7 | 1291 | ptr = ( uint8_t * ) call; |
klauss | 121:ee02790d00b7 | 1292 | } |
klauss | 121:ee02790d00b7 | 1293 | |
klauss | 126:1f90756250fb | 1294 | if ( ptr not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1295 | { |
klauss | 132:05cd37f7e007 | 1296 | vz_printf ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 121:ee02790d00b7 | 1297 | for ( register int i = 0; i < sizeof( VZ_call ); i++ ) |
klauss | 121:ee02790d00b7 | 1298 | { |
klauss | 121:ee02790d00b7 | 1299 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1300 | |
klauss | 121:ee02790d00b7 | 1301 | if ( ( i % 32 ) == 0 ) |
klauss | 121:ee02790d00b7 | 1302 | { |
klauss | 132:05cd37f7e007 | 1303 | if( i not_eq 0 ) { |
klauss | 121:ee02790d00b7 | 1304 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 132:05cd37f7e007 | 1305 | } else { |
klauss | 121:ee02790d00b7 | 1306 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 1307 | } |
klauss | 121:ee02790d00b7 | 1308 | } |
klauss | 121:ee02790d00b7 | 1309 | else |
klauss | 121:ee02790d00b7 | 1310 | { |
klauss | 121:ee02790d00b7 | 1311 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 1312 | } |
klauss | 121:ee02790d00b7 | 1313 | } |
klauss | 121:ee02790d00b7 | 1314 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 121:ee02790d00b7 | 1315 | |
klauss | 121:ee02790d00b7 | 1316 | if ( tcp_session ) { |
klauss | 121:ee02790d00b7 | 1317 | char aux[ ( 32 * 3 ) + 5 ]; |
klauss | 121:ee02790d00b7 | 1318 | |
klauss | 121:ee02790d00b7 | 1319 | for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; |
klauss | 121:ee02790d00b7 | 1320 | |
klauss | 121:ee02790d00b7 | 1321 | ptr = NULL; |
klauss | 121:ee02790d00b7 | 1322 | |
klauss | 126:1f90756250fb | 1323 | VZ_call * call = find_Call ( v_call, print_hex_this_call ); |
klauss | 121:ee02790d00b7 | 1324 | |
klauss | 121:ee02790d00b7 | 1325 | uint8_t * ptr = NULL; |
klauss | 126:1f90756250fb | 1326 | if( call not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1327 | { |
klauss | 121:ee02790d00b7 | 1328 | ptr = ( uint8_t * ) call; |
klauss | 121:ee02790d00b7 | 1329 | } |
klauss | 121:ee02790d00b7 | 1330 | |
klauss | 126:1f90756250fb | 1331 | if ( ptr not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1332 | { |
klauss | 121:ee02790d00b7 | 1333 | bool finished = false; |
klauss | 121:ee02790d00b7 | 1334 | volatile int i = 0; |
klauss | 121:ee02790d00b7 | 1335 | int count = 0; |
klauss | 121:ee02790d00b7 | 1336 | Timer dont_overwrite_tcp_buffer; |
klauss | 121:ee02790d00b7 | 1337 | dont_overwrite_tcp_buffer.reset (); |
klauss | 121:ee02790d00b7 | 1338 | dont_overwrite_tcp_buffer.start (); |
klauss | 121:ee02790d00b7 | 1339 | |
klauss | 121:ee02790d00b7 | 1340 | while ( !finished ) |
klauss | 121:ee02790d00b7 | 1341 | { |
klauss | 121:ee02790d00b7 | 1342 | if( dont_overwrite_tcp_buffer.read_ms () >= 20 ) |
klauss | 121:ee02790d00b7 | 1343 | { |
klauss | 121:ee02790d00b7 | 1344 | dont_overwrite_tcp_buffer.reset(); |
klauss | 121:ee02790d00b7 | 1345 | for ( ; i < sizeof( VZ_call ); i++ ) |
klauss | 121:ee02790d00b7 | 1346 | { |
klauss | 121:ee02790d00b7 | 1347 | char tmp[ 16 ]; |
klauss | 121:ee02790d00b7 | 1348 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1349 | strcat( aux, tmp ); |
klauss | 121:ee02790d00b7 | 1350 | count++; |
klauss | 121:ee02790d00b7 | 1351 | |
klauss | 121:ee02790d00b7 | 1352 | if ( count >= 32 ) |
klauss | 121:ee02790d00b7 | 1353 | { |
klauss | 121:ee02790d00b7 | 1354 | count = 0; |
klauss | 121:ee02790d00b7 | 1355 | i++; |
klauss | 121:ee02790d00b7 | 1356 | break; |
klauss | 121:ee02790d00b7 | 1357 | } |
klauss | 121:ee02790d00b7 | 1358 | } |
klauss | 121:ee02790d00b7 | 1359 | strcat ( aux, "\n\r\0" ); |
klauss | 121:ee02790d00b7 | 1360 | tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 121:ee02790d00b7 | 1361 | if ( i >= sizeof ( VZ_call ) ) finished = true; |
klauss | 121:ee02790d00b7 | 1362 | strcpy ( aux, "\0" ); |
klauss | 121:ee02790d00b7 | 1363 | } |
klauss | 121:ee02790d00b7 | 1364 | } |
klauss | 121:ee02790d00b7 | 1365 | dont_overwrite_tcp_buffer.reset(); |
klauss | 121:ee02790d00b7 | 1366 | dont_overwrite_tcp_buffer.stop(); |
klauss | 121:ee02790d00b7 | 1367 | tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 121:ee02790d00b7 | 1368 | } |
klauss | 121:ee02790d00b7 | 1369 | } |
klauss | 121:ee02790d00b7 | 1370 | } |
klauss | 121:ee02790d00b7 | 1371 | else |
klauss | 121:ee02790d00b7 | 1372 | { |
klauss | 121:ee02790d00b7 | 1373 | if( print_values ) |
klauss | 121:ee02790d00b7 | 1374 | { |
klauss | 132:05cd37f7e007 | 1375 | vz_debug ("Call %d not found", print_this_call ); |
klauss | 121:ee02790d00b7 | 1376 | } |
klauss | 121:ee02790d00b7 | 1377 | else |
klauss | 121:ee02790d00b7 | 1378 | { |
klauss | 132:05cd37f7e007 | 1379 | vz_printf ("Call %d not found", print_this_call ); |
klauss | 121:ee02790d00b7 | 1380 | } |
klauss | 121:ee02790d00b7 | 1381 | } |
klauss | 121:ee02790d00b7 | 1382 | |
klauss | 121:ee02790d00b7 | 1383 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1384 | } |
klauss | 121:ee02790d00b7 | 1385 | |
klauss | 121:ee02790d00b7 | 1386 | |
klauss | 121:ee02790d00b7 | 1387 | int show_cb_rtp ( void ) |
klauss | 121:ee02790d00b7 | 1388 | { |
klauss | 126:1f90756250fb | 1389 | VZ_call * call = find_Call ( v_call, print_hex_this_rtp ); |
klauss | 121:ee02790d00b7 | 1390 | |
klauss | 121:ee02790d00b7 | 1391 | uint8_t * ptr = NULL; |
klauss | 126:1f90756250fb | 1392 | if( call not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1393 | { |
klauss | 121:ee02790d00b7 | 1394 | ptr = ( uint8_t * ) call -> check_rtp (); |
klauss | 121:ee02790d00b7 | 1395 | } |
klauss | 121:ee02790d00b7 | 1396 | |
klauss | 126:1f90756250fb | 1397 | if ( ptr not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1398 | { |
klauss | 132:05cd37f7e007 | 1399 | vz_printf ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 121:ee02790d00b7 | 1400 | for ( register int i = 0; i < sizeof( RTP ); i++ ) |
klauss | 121:ee02790d00b7 | 1401 | { |
klauss | 121:ee02790d00b7 | 1402 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1403 | |
klauss | 121:ee02790d00b7 | 1404 | if ( ( i % 32 ) == 0 ) |
klauss | 121:ee02790d00b7 | 1405 | { |
klauss | 126:1f90756250fb | 1406 | if( i not_eq 0 ) |
klauss | 121:ee02790d00b7 | 1407 | { |
klauss | 121:ee02790d00b7 | 1408 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 121:ee02790d00b7 | 1409 | } |
klauss | 121:ee02790d00b7 | 1410 | else |
klauss | 121:ee02790d00b7 | 1411 | { |
klauss | 121:ee02790d00b7 | 1412 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 1413 | } |
klauss | 121:ee02790d00b7 | 1414 | } |
klauss | 121:ee02790d00b7 | 1415 | else |
klauss | 121:ee02790d00b7 | 1416 | { |
klauss | 121:ee02790d00b7 | 1417 | if( debug_uart3 ) pc.printf(" "); |
klauss | 121:ee02790d00b7 | 1418 | } |
klauss | 121:ee02790d00b7 | 1419 | } |
klauss | 121:ee02790d00b7 | 1420 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 121:ee02790d00b7 | 1421 | |
klauss | 121:ee02790d00b7 | 1422 | if ( tcp_session ) { |
klauss | 121:ee02790d00b7 | 1423 | char aux[ ( 32 * 3 ) + 5 ]; |
klauss | 121:ee02790d00b7 | 1424 | |
klauss | 121:ee02790d00b7 | 1425 | for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; |
klauss | 121:ee02790d00b7 | 1426 | |
klauss | 121:ee02790d00b7 | 1427 | ptr = NULL; |
klauss | 121:ee02790d00b7 | 1428 | |
klauss | 126:1f90756250fb | 1429 | VZ_call * call = find_Call ( v_call, print_hex_this_rtp ); |
klauss | 121:ee02790d00b7 | 1430 | |
klauss | 121:ee02790d00b7 | 1431 | uint8_t * ptr = NULL; |
klauss | 126:1f90756250fb | 1432 | if( call not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1433 | { |
klauss | 121:ee02790d00b7 | 1434 | ptr = ( uint8_t * ) call -> check_rtp (); |
klauss | 121:ee02790d00b7 | 1435 | } |
klauss | 121:ee02790d00b7 | 1436 | |
klauss | 126:1f90756250fb | 1437 | if ( ptr not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1438 | { |
klauss | 121:ee02790d00b7 | 1439 | bool finished = false; |
klauss | 121:ee02790d00b7 | 1440 | volatile int i = 0; |
klauss | 121:ee02790d00b7 | 1441 | int count = 0; |
klauss | 121:ee02790d00b7 | 1442 | Timer dont_overwrite_tcp_buffer; |
klauss | 121:ee02790d00b7 | 1443 | dont_overwrite_tcp_buffer.reset (); |
klauss | 121:ee02790d00b7 | 1444 | dont_overwrite_tcp_buffer.start (); |
klauss | 121:ee02790d00b7 | 1445 | |
klauss | 121:ee02790d00b7 | 1446 | while ( !finished ) |
klauss | 121:ee02790d00b7 | 1447 | { |
klauss | 121:ee02790d00b7 | 1448 | if( dont_overwrite_tcp_buffer.read_ms () >= 20 ) |
klauss | 121:ee02790d00b7 | 1449 | { |
klauss | 121:ee02790d00b7 | 1450 | dont_overwrite_tcp_buffer.reset(); |
klauss | 121:ee02790d00b7 | 1451 | for ( ; i < sizeof( RTP ); i++ ) |
klauss | 121:ee02790d00b7 | 1452 | { |
klauss | 121:ee02790d00b7 | 1453 | char tmp[ 16 ]; |
klauss | 121:ee02790d00b7 | 1454 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 121:ee02790d00b7 | 1455 | strcat( aux, tmp ); |
klauss | 121:ee02790d00b7 | 1456 | count++; |
klauss | 121:ee02790d00b7 | 1457 | |
klauss | 121:ee02790d00b7 | 1458 | if ( count >= 32 ) |
klauss | 121:ee02790d00b7 | 1459 | { |
klauss | 121:ee02790d00b7 | 1460 | count = 0; |
klauss | 121:ee02790d00b7 | 1461 | i++; |
klauss | 121:ee02790d00b7 | 1462 | break; |
klauss | 121:ee02790d00b7 | 1463 | } |
klauss | 121:ee02790d00b7 | 1464 | } |
klauss | 121:ee02790d00b7 | 1465 | strcat ( aux, "\n\r\0" ); |
klauss | 121:ee02790d00b7 | 1466 | tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 121:ee02790d00b7 | 1467 | if ( i >= sizeof ( RTP ) ) finished = true; |
klauss | 121:ee02790d00b7 | 1468 | strcpy ( aux, "\0" ); |
klauss | 121:ee02790d00b7 | 1469 | } |
klauss | 121:ee02790d00b7 | 1470 | } |
klauss | 121:ee02790d00b7 | 1471 | dont_overwrite_tcp_buffer.reset(); |
klauss | 121:ee02790d00b7 | 1472 | dont_overwrite_tcp_buffer.stop(); |
klauss | 121:ee02790d00b7 | 1473 | tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 121:ee02790d00b7 | 1474 | } |
klauss | 121:ee02790d00b7 | 1475 | } |
klauss | 121:ee02790d00b7 | 1476 | } |
klauss | 121:ee02790d00b7 | 1477 | else |
klauss | 121:ee02790d00b7 | 1478 | { |
klauss | 121:ee02790d00b7 | 1479 | if( print_values ) |
klauss | 121:ee02790d00b7 | 1480 | { |
klauss | 132:05cd37f7e007 | 1481 | vz_debug ("Call %d not found", print_this_rtp ); |
klauss | 121:ee02790d00b7 | 1482 | } |
klauss | 121:ee02790d00b7 | 1483 | else |
klauss | 121:ee02790d00b7 | 1484 | { |
klauss | 132:05cd37f7e007 | 1485 | vz_printf ("Call %d not found", print_this_rtp ); |
klauss | 121:ee02790d00b7 | 1486 | } |
klauss | 121:ee02790d00b7 | 1487 | } |
klauss | 121:ee02790d00b7 | 1488 | |
klauss | 121:ee02790d00b7 | 1489 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1490 | } |
klauss | 121:ee02790d00b7 | 1491 | |
klauss | 121:ee02790d00b7 | 1492 | int show_cb_hex_rtp ( void ) |
klauss | 121:ee02790d00b7 | 1493 | { |
klauss | 126:1f90756250fb | 1494 | VZ_call * call = find_Call ( v_call, print_this_rtp ); |
klauss | 121:ee02790d00b7 | 1495 | |
klauss | 126:1f90756250fb | 1496 | if ( call not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1497 | { |
klauss | 126:1f90756250fb | 1498 | if ( call -> check_rtp () not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1499 | { |
klauss | 132:05cd37f7e007 | 1500 | vz_printf ("Values :: %p\r\n", ( void *) call -> check_rtp () ); |
klauss | 121:ee02790d00b7 | 1501 | call -> rtp_print_yourself (); |
klauss | 121:ee02790d00b7 | 1502 | } |
klauss | 121:ee02790d00b7 | 1503 | else |
klauss | 121:ee02790d00b7 | 1504 | { |
klauss | 121:ee02790d00b7 | 1505 | if( print_values ) |
klauss | 121:ee02790d00b7 | 1506 | { |
klauss | 132:05cd37f7e007 | 1507 | vz_debug ("Call->RTP %d not found", print_this_rtp ); |
klauss | 121:ee02790d00b7 | 1508 | } |
klauss | 121:ee02790d00b7 | 1509 | else |
klauss | 121:ee02790d00b7 | 1510 | { |
klauss | 132:05cd37f7e007 | 1511 | vz_printf ("Call->RTP %d not found", print_this_rtp ); |
klauss | 121:ee02790d00b7 | 1512 | } |
klauss | 121:ee02790d00b7 | 1513 | } |
klauss | 121:ee02790d00b7 | 1514 | } |
klauss | 121:ee02790d00b7 | 1515 | else |
klauss | 121:ee02790d00b7 | 1516 | { |
klauss | 121:ee02790d00b7 | 1517 | if( print_values ) |
klauss | 121:ee02790d00b7 | 1518 | { |
klauss | 132:05cd37f7e007 | 1519 | vz_debug ("Call->RTP %d not found", print_this_rtp ); |
klauss | 121:ee02790d00b7 | 1520 | } |
klauss | 121:ee02790d00b7 | 1521 | else |
klauss | 121:ee02790d00b7 | 1522 | { |
klauss | 132:05cd37f7e007 | 1523 | vz_printf ("Call->RTP %d not found", print_this_rtp ); |
klauss | 121:ee02790d00b7 | 1524 | } |
klauss | 121:ee02790d00b7 | 1525 | } |
klauss | 121:ee02790d00b7 | 1526 | |
klauss | 121:ee02790d00b7 | 1527 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1528 | } |
klauss | 121:ee02790d00b7 | 1529 | |
klauss | 121:ee02790d00b7 | 1530 | |
klauss | 121:ee02790d00b7 | 1531 | int reset_stats_cks ( void ) |
klauss | 121:ee02790d00b7 | 1532 | { |
klauss | 121:ee02790d00b7 | 1533 | pkg_cksok = 0; |
klauss | 121:ee02790d00b7 | 1534 | pkg_ckserr = 0; |
klauss | 121:ee02790d00b7 | 1535 | pkg_zero = 0; |
klauss | 121:ee02790d00b7 | 1536 | out_of_range = 0; |
klauss | 121:ee02790d00b7 | 1537 | missed_pkg = 0; |
klauss | 121:ee02790d00b7 | 1538 | delayed_pkg_to_cb = 0; |
klauss | 121:ee02790d00b7 | 1539 | cpld_pkg_tx_counter = 0; |
klauss | 121:ee02790d00b7 | 1540 | cpld_pkg_rx_counter = 0; |
klauss | 121:ee02790d00b7 | 1541 | |
klauss | 121:ee02790d00b7 | 1542 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1543 | } |
klauss | 121:ee02790d00b7 | 1544 | |
klauss | 121:ee02790d00b7 | 1545 | int show_cb_stats ( void ) |
klauss | 121:ee02790d00b7 | 1546 | { |
klauss | 132:05cd37f7e007 | 1547 | vz_printf ( |
klauss | 121:ee02790d00b7 | 1548 | "\r\n" |
klauss | 121:ee02790d00b7 | 1549 | " PKG_CKS OK: %d ( %003.2f )\r\n" |
klauss | 121:ee02790d00b7 | 1550 | " PKG_CKS ERR: %d ( %003.2f )\r\n" |
klauss | 121:ee02790d00b7 | 1551 | " PKG_0: %d ( %003.2f )\r\n" |
klauss | 121:ee02790d00b7 | 1552 | " Out_of_range: %d ( %003.2f )\r\n" |
klauss | 121:ee02790d00b7 | 1553 | " Miss_Pkg: %d\r\n" |
klauss | 121:ee02790d00b7 | 1554 | " TX_delayed: %d\n\r" |
klauss | 121:ee02790d00b7 | 1555 | " TX_Counter: %d\n\r" |
klauss | 121:ee02790d00b7 | 1556 | " RX_Counter: %d\r\n", |
klauss | 121:ee02790d00b7 | 1557 | pkg_cksok, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_cksok / cpld_pkg_rx_counter ) * 100, |
klauss | 121:ee02790d00b7 | 1558 | pkg_ckserr, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_ckserr / cpld_pkg_rx_counter ) * 100, |
klauss | 121:ee02790d00b7 | 1559 | pkg_zero, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_zero / cpld_pkg_rx_counter ) * 100, |
klauss | 121:ee02790d00b7 | 1560 | out_of_range, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) out_of_range / cpld_pkg_rx_counter ) * 100, |
klauss | 121:ee02790d00b7 | 1561 | missed_pkg, |
klauss | 121:ee02790d00b7 | 1562 | delayed_pkg_to_cb, |
klauss | 121:ee02790d00b7 | 1563 | cpld_pkg_tx_counter, |
klauss | 121:ee02790d00b7 | 1564 | cpld_pkg_rx_counter |
klauss | 121:ee02790d00b7 | 1565 | ); |
klauss | 121:ee02790d00b7 | 1566 | |
klauss | 121:ee02790d00b7 | 1567 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1568 | } |
klauss | 121:ee02790d00b7 | 1569 | |
klauss | 121:ee02790d00b7 | 1570 | |
klauss | 121:ee02790d00b7 | 1571 | int reset_missed_send_udp ( void ) |
klauss | 121:ee02790d00b7 | 1572 | { |
klauss | 132:05cd37f7e007 | 1573 | miss_fw_send_pkg = 0; |
klauss | 132:05cd37f7e007 | 1574 | miss_prompt_udp_send_pkg = 0; |
klauss | 132:05cd37f7e007 | 1575 | miss_sip_registry_send_pkg = 0; |
klauss | 132:05cd37f7e007 | 1576 | miss_sip_invite_send_pkg = 0; |
klauss | 132:05cd37f7e007 | 1577 | miss_sip_bye_send_pkg = 0; |
klauss | 132:05cd37f7e007 | 1578 | miss_sip_ok_send_pkg = 0; |
klauss | 121:ee02790d00b7 | 1579 | miss_sip_rcv_bye_send_pkg = 0; |
klauss | 121:ee02790d00b7 | 1580 | miss_wdt_send_pkg = 0; |
klauss | 121:ee02790d00b7 | 1581 | miss_prompt_udp_send_pkg = 0; |
klauss | 132:05cd37f7e007 | 1582 | miss_rtp_udp_send_pkg = 0; |
klauss | 121:ee02790d00b7 | 1583 | miss_prompt_udp_rcv_pkg = 0; |
klauss | 121:ee02790d00b7 | 1584 | |
klauss | 121:ee02790d00b7 | 1585 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1586 | } |
klauss | 121:ee02790d00b7 | 1587 | |
klauss | 121:ee02790d00b7 | 1588 | int show_missed_send_udp_pkg ( void ) |
klauss | 121:ee02790d00b7 | 1589 | { |
klauss | 132:05cd37f7e007 | 1590 | vz_printf ( "\r\nMissed pkgs ::\r\n " |
klauss | 121:ee02790d00b7 | 1591 | "FW: %d\r\n " |
klauss | 121:ee02790d00b7 | 1592 | "Prompt UDP %d\r\n " |
klauss | 121:ee02790d00b7 | 1593 | "Registry %d\r\n " |
klauss | 121:ee02790d00b7 | 1594 | "Invite %d\r\n " |
klauss | 121:ee02790d00b7 | 1595 | "Bye %d\r\n " |
klauss | 121:ee02790d00b7 | 1596 | "UDP incoming ( invite ans ) %d\r\n " |
klauss | 121:ee02790d00b7 | 1597 | "UDP incoming ( bye from * ) %d\r\n " |
klauss | 121:ee02790d00b7 | 1598 | "Wdt [ alive | rst ] %d\r\n " |
klauss | 121:ee02790d00b7 | 1599 | "Rcv prompt %d\r\n " |
klauss | 121:ee02790d00b7 | 1600 | "[ debug | send ]_msg %d\r\n " |
klauss | 121:ee02790d00b7 | 1601 | "RTP %d\r\n", |
klauss | 121:ee02790d00b7 | 1602 | miss_fw_send_pkg, |
klauss | 121:ee02790d00b7 | 1603 | miss_prompt_udp_send_pkg, |
klauss | 121:ee02790d00b7 | 1604 | miss_sip_registry_send_pkg, |
klauss | 121:ee02790d00b7 | 1605 | miss_sip_invite_send_pkg, |
klauss | 121:ee02790d00b7 | 1606 | miss_sip_bye_send_pkg, |
klauss | 121:ee02790d00b7 | 1607 | miss_sip_ok_send_pkg, |
klauss | 121:ee02790d00b7 | 1608 | miss_sip_rcv_bye_send_pkg, |
klauss | 121:ee02790d00b7 | 1609 | miss_wdt_send_pkg, |
klauss | 121:ee02790d00b7 | 1610 | miss_prompt_udp_send_pkg, |
klauss | 121:ee02790d00b7 | 1611 | miss_prompt_udp_rcv_pkg, |
klauss | 132:05cd37f7e007 | 1612 | miss_rtp_udp_send_pkg |
klauss | 121:ee02790d00b7 | 1613 | ); |
klauss | 121:ee02790d00b7 | 1614 | |
klauss | 121:ee02790d00b7 | 1615 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1616 | } |
klauss | 121:ee02790d00b7 | 1617 | |
klauss | 132:05cd37f7e007 | 1618 | int |
klauss | 132:05cd37f7e007 | 1619 | invite_ack_to_cb_handler ( Vector * v_cb, Vector * v_call ) |
klauss | 121:ee02790d00b7 | 1620 | { |
klauss | 121:ee02790d00b7 | 1621 | static int retry_invite_pkg = 0; |
klauss | 121:ee02790d00b7 | 1622 | bool need_retry = false; |
klauss | 121:ee02790d00b7 | 1623 | Call_Box * cb = NULL; |
klauss | 121:ee02790d00b7 | 1624 | |
klauss | 132:05cd37f7e007 | 1625 | for ( register uint8_t i = 0; i < v_cb -> size (); i++ ) |
klauss | 121:ee02790d00b7 | 1626 | { |
klauss | 132:05cd37f7e007 | 1627 | retry_invite_pkg ++; |
klauss | 132:05cd37f7e007 | 1628 | if ( retry_invite_pkg >= v_cb -> size () ) retry_invite_pkg = 0; |
klauss | 121:ee02790d00b7 | 1629 | |
klauss | 126:1f90756250fb | 1630 | cb = (Call_Box * )v_cb -> get_element ( i ); |
klauss | 132:05cd37f7e007 | 1631 | |
klauss | 126:1f90756250fb | 1632 | if ( cb not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1633 | { |
klauss | 132:05cd37f7e007 | 1634 | switch ( cb -> get_status () ) |
klauss | 121:ee02790d00b7 | 1635 | { |
klauss | 132:05cd37f7e007 | 1636 | case cb_ringing : |
klauss | 132:05cd37f7e007 | 1637 | case cb_trying : |
klauss | 132:05cd37f7e007 | 1638 | case cb_on_call : |
klauss | 132:05cd37f7e007 | 1639 | need_retry = true; |
klauss | 132:05cd37f7e007 | 1640 | break; |
klauss | 121:ee02790d00b7 | 1641 | } |
klauss | 132:05cd37f7e007 | 1642 | |
klauss | 132:05cd37f7e007 | 1643 | if ( need_retry ) break; |
klauss | 121:ee02790d00b7 | 1644 | } |
klauss | 121:ee02790d00b7 | 1645 | } |
klauss | 121:ee02790d00b7 | 1646 | |
klauss | 121:ee02790d00b7 | 1647 | if ( need_retry ) |
klauss | 121:ee02790d00b7 | 1648 | { |
klauss | 132:05cd37f7e007 | 1649 | uint16_t ext = cb -> get_ext (); |
klauss | 132:05cd37f7e007 | 1650 | uint16_t port = cb -> get_port (); |
klauss | 132:05cd37f7e007 | 1651 | |
klauss | 126:1f90756250fb | 1652 | if ( cb -> get_invite_response () == false ) |
klauss | 121:ee02790d00b7 | 1653 | { |
klauss | 126:1f90756250fb | 1654 | buffer [ TIMESLICE_PLACE ] = cb -> get_timeslice (); |
klauss | 126:1f90756250fb | 1655 | |
klauss | 126:1f90756250fb | 1656 | do_not_show_this_invite_pkg = true; |
klauss | 126:1f90756250fb | 1657 | |
klauss | 132:05cd37f7e007 | 1658 | send2callboxes ( build_cb_package ( ext, port, INVITE, ( char * )buffer, |
klauss | 126:1f90756250fb | 1659 | cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 121:ee02790d00b7 | 1660 | |
klauss | 132:05cd37f7e007 | 1661 | if ( debug_resend_invite ) vz_debug ("[%d] resend invite OK to Cbx : ( %d, %d )", ext, ext, port ); |
klauss | 121:ee02790d00b7 | 1662 | } |
klauss | 121:ee02790d00b7 | 1663 | |
klauss | 132:05cd37f7e007 | 1664 | if ( find_Call ( v_call, ext ) == NULL ) |
klauss | 121:ee02790d00b7 | 1665 | { |
klauss | 132:05cd37f7e007 | 1666 | uint8_t cb_status = cb -> get_status (); |
klauss | 132:05cd37f7e007 | 1667 | |
klauss | 132:05cd37f7e007 | 1668 | if ( ( ( cb_status == cb_ringing ) or ( cb_status == cb_trying ) ) ) |
klauss | 121:ee02790d00b7 | 1669 | { |
klauss | 121:ee02790d00b7 | 1670 | char rtp_src_tmp_write_buffer [ CB_BUFFER_SIZE ]; |
klauss | 132:05cd37f7e007 | 1671 | |
klauss | 121:ee02790d00b7 | 1672 | uint8_t rtp_dst_tmp_write_buffer [ CB_BUFFER_SIZE ]; |
klauss | 121:ee02790d00b7 | 1673 | |
klauss | 126:1f90756250fb | 1674 | for ( register int i = 0; i < RTP_MSG_SIZE; i++ ) rtp_src_tmp_write_buffer [ i ] = 0x00; |
klauss | 121:ee02790d00b7 | 1675 | |
klauss | 132:05cd37f7e007 | 1676 | send2callboxes ( build_cb_package ( ext, port, AUDIO, |
klauss | 121:ee02790d00b7 | 1677 | rtp_src_tmp_write_buffer, AUDIO, RTP_MSG_SIZE, rtp_dst_tmp_write_buffer ) ); |
klauss | 121:ee02790d00b7 | 1678 | } else { |
klauss | 132:05cd37f7e007 | 1679 | if ( cb -> get_invite_retry_count () == 0 ) |
klauss | 121:ee02790d00b7 | 1680 | { |
klauss | 132:05cd37f7e007 | 1681 | cb -> set_msg_id ( ( cb->get_msg_id () + 1 ) & ~BIT7 ); |
klauss | 121:ee02790d00b7 | 1682 | |
klauss | 132:05cd37f7e007 | 1683 | for ( register uint8_t i = 0; i < v_call -> size(); i++ ) |
klauss | 121:ee02790d00b7 | 1684 | { |
klauss | 132:05cd37f7e007 | 1685 | VZ_call * call = ( VZ_call * )v_call -> get_element ( i ); |
klauss | 132:05cd37f7e007 | 1686 | if ( call -> get_cb_ext () == ext ) |
klauss | 121:ee02790d00b7 | 1687 | { |
klauss | 132:05cd37f7e007 | 1688 | v_call -> remove_element ( i ); |
klauss | 132:05cd37f7e007 | 1689 | if ( call not_eq NULL ) delete( call ); |
klauss | 121:ee02790d00b7 | 1690 | break; |
klauss | 121:ee02790d00b7 | 1691 | } |
klauss | 121:ee02790d00b7 | 1692 | } |
klauss | 121:ee02790d00b7 | 1693 | |
klauss | 132:05cd37f7e007 | 1694 | ts -> return_timeslice ( cb -> call_end () ); |
klauss | 121:ee02790d00b7 | 1695 | |
klauss | 132:05cd37f7e007 | 1696 | if( debug_invite or debug_resend_invite ) vz_debug ( "[%d] No audio pkgs from cbx", ext ); |
klauss | 121:ee02790d00b7 | 1697 | } |
klauss | 121:ee02790d00b7 | 1698 | } |
klauss | 121:ee02790d00b7 | 1699 | } |
klauss | 121:ee02790d00b7 | 1700 | } |
klauss | 121:ee02790d00b7 | 1701 | |
klauss | 121:ee02790d00b7 | 1702 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1703 | } |
klauss | 121:ee02790d00b7 | 1704 | |
klauss | 121:ee02790d00b7 | 1705 | int check_audio_from_ast ( Vector * v_cb, Vector * v_call ) |
klauss | 121:ee02790d00b7 | 1706 | { |
klauss | 126:1f90756250fb | 1707 | for( register uint8_t i = 0; i < v_call->size(); i++ ) |
klauss | 126:1f90756250fb | 1708 | { |
klauss | 126:1f90756250fb | 1709 | VZ_call * call = ( VZ_call * ) v_call -> get_element ( i ); |
klauss | 126:1f90756250fb | 1710 | if ( call not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1711 | { |
klauss | 121:ee02790d00b7 | 1712 | int length = 0; |
klauss | 126:1f90756250fb | 1713 | char * tmp = call -> get_eth_message ( &length ); |
klauss | 126:1f90756250fb | 1714 | if( tmp not_eq NULL ) |
klauss | 126:1f90756250fb | 1715 | { |
klauss | 121:ee02790d00b7 | 1716 | int cb_port = 0xffff; |
klauss | 126:1f90756250fb | 1717 | Call_Box * cb = find_CB ( v_cb, call -> get_cb_ext () ); |
klauss | 121:ee02790d00b7 | 1718 | |
klauss | 126:1f90756250fb | 1719 | if( cb not_eq NULL ) |
klauss | 126:1f90756250fb | 1720 | { |
klauss | 126:1f90756250fb | 1721 | cb_port = cb -> get_port (); |
klauss | 121:ee02790d00b7 | 1722 | |
klauss | 121:ee02790d00b7 | 1723 | if ( drop_rtp_from_ast_pkg ) |
klauss | 121:ee02790d00b7 | 1724 | { |
klauss | 121:ee02790d00b7 | 1725 | led1 = !led1; |
klauss | 121:ee02790d00b7 | 1726 | } |
klauss | 121:ee02790d00b7 | 1727 | else |
klauss | 121:ee02790d00b7 | 1728 | { |
klauss | 126:1f90756250fb | 1729 | uint8_t * pkg2cb = build_cb_package ( call -> get_cb_ext (), cb_port, AUDIO, |
klauss | 121:ee02790d00b7 | 1730 | tmp, AUDIO, length, write_buffer ); |
klauss | 121:ee02790d00b7 | 1731 | |
klauss | 121:ee02790d00b7 | 1732 | send2callboxes( pkg2cb ); |
klauss | 121:ee02790d00b7 | 1733 | } |
klauss | 121:ee02790d00b7 | 1734 | |
klauss | 132:05cd37f7e007 | 1735 | } else if ( debug_main ) vz_debug ("[%d] received missed package -- Type :: %i", ext, type ); |
klauss | 121:ee02790d00b7 | 1736 | } |
klauss | 121:ee02790d00b7 | 1737 | } |
klauss | 121:ee02790d00b7 | 1738 | } |
klauss | 121:ee02790d00b7 | 1739 | |
klauss | 121:ee02790d00b7 | 1740 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1741 | } |
klauss | 121:ee02790d00b7 | 1742 | |
klauss | 121:ee02790d00b7 | 1743 | int wake_up_or_refresh_handler ( Vector * v_cb ) |
klauss | 121:ee02790d00b7 | 1744 | { |
klauss | 126:1f90756250fb | 1745 | int return_value = 0; |
klauss | 126:1f90756250fb | 1746 | |
klauss | 132:05cd37f7e007 | 1747 | // analizar este caso com mais cuidado |
klauss | 132:05cd37f7e007 | 1748 | // dado que vão ter 2 carinhas "perdidos" |
klauss | 132:05cd37f7e007 | 1749 | // perceber a frequencia de envio de pacotes |
klauss | 132:05cd37f7e007 | 1750 | // perceber possiveis gargalos nesses envios |
klauss | 132:05cd37f7e007 | 1751 | if( timer_sync_refresh.read_ms () > 250 * 2 ) |
klauss | 126:1f90756250fb | 1752 | { |
klauss | 132:05cd37f7e007 | 1753 | timer_sync_refresh.reset (); |
klauss | 121:ee02790d00b7 | 1754 | |
klauss | 121:ee02790d00b7 | 1755 | static uint8_t time_to_mode = TIME_TO_REFRESH; |
klauss | 121:ee02790d00b7 | 1756 | |
klauss | 132:05cd37f7e007 | 1757 | if ( time_to_mode == TIME_TO_REFRESH ) |
klauss | 132:05cd37f7e007 | 1758 | { |
klauss | 121:ee02790d00b7 | 1759 | time_to_mode = TIME_TO_WAKE_UP; |
klauss | 126:1f90756250fb | 1760 | if ( !do_not_refresh ) return_value = refresh ( v_cb ); |
klauss | 121:ee02790d00b7 | 1761 | } else { |
klauss | 121:ee02790d00b7 | 1762 | time_to_mode = TIME_TO_REFRESH; |
klauss | 132:05cd37f7e007 | 1763 | if ( wake_all and ( v_call -> size() == 0 ) ) wake_all_up ( v_cb ); |
klauss | 121:ee02790d00b7 | 1764 | } |
klauss | 121:ee02790d00b7 | 1765 | } |
klauss | 121:ee02790d00b7 | 1766 | |
klauss | 126:1f90756250fb | 1767 | return ( return_value ); |
klauss | 121:ee02790d00b7 | 1768 | } |
klauss | 121:ee02790d00b7 | 1769 | |
klauss | 121:ee02790d00b7 | 1770 | int check_sip_messages_from_ast ( Vector * v_cb, Vector * v_call ) |
klauss | 121:ee02790d00b7 | 1771 | { |
klauss | 121:ee02790d00b7 | 1772 | // check sip messages only for cbx in call ? |
klauss | 121:ee02790d00b7 | 1773 | int ext_to__be_removed = sip_manager( v_cb ); |
klauss | 121:ee02790d00b7 | 1774 | if( ext_to__be_removed > 0 ) { |
klauss | 121:ee02790d00b7 | 1775 | Call_Box * cb = find_CB( v_cb, ext_to__be_removed ); |
klauss | 126:1f90756250fb | 1776 | if( cb not_eq NULL ) { |
klauss | 126:1f90756250fb | 1777 | //if( cb->status == cb_on_call ) // poderia ser if( cb->status not_eq cb_idle ) ??? |
klauss | 121:ee02790d00b7 | 1778 | if ( cb -> get_status () == cb_on_call ) |
klauss | 121:ee02790d00b7 | 1779 | { |
klauss | 121:ee02790d00b7 | 1780 | buffer[ TIMESLICE_PLACE ] = 0; |
klauss | 121:ee02790d00b7 | 1781 | |
klauss | 121:ee02790d00b7 | 1782 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 121:ee02790d00b7 | 1783 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 121:ee02790d00b7 | 1784 | if( call->get_cb_ext() == ext_to__be_removed ) { |
klauss | 121:ee02790d00b7 | 1785 | v_call->remove_element( i ); |
klauss | 121:ee02790d00b7 | 1786 | delete( call ); |
klauss | 121:ee02790d00b7 | 1787 | } |
klauss | 121:ee02790d00b7 | 1788 | } |
klauss | 121:ee02790d00b7 | 1789 | |
klauss | 121:ee02790d00b7 | 1790 | ts->return_timeslice( cb->call_end ( false ) ); |
klauss | 121:ee02790d00b7 | 1791 | |
klauss | 121:ee02790d00b7 | 1792 | send2callboxes( build_cb_package( cb->get_ext (), cb->get_port (), CB_BYE, |
klauss | 121:ee02790d00b7 | 1793 | ( char * )buffer, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 121:ee02790d00b7 | 1794 | |
klauss | 132:05cd37f7e007 | 1795 | if( debug_invite ) vz_debug ("[%d] Received Bye from *", cb->get_ext () ); |
klauss | 121:ee02790d00b7 | 1796 | } |
klauss | 132:05cd37f7e007 | 1797 | } else if( debug_main ) vz_debug ("[%d] Missed bye request", ext_to__be_removed ); |
klauss | 121:ee02790d00b7 | 1798 | } |
klauss | 121:ee02790d00b7 | 1799 | |
klauss | 121:ee02790d00b7 | 1800 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1801 | } |
klauss | 121:ee02790d00b7 | 1802 | |
klauss | 121:ee02790d00b7 | 1803 | int check_for_runaways_ts ( Vector * v_cb, Timeslice * ts ) |
klauss | 121:ee02790d00b7 | 1804 | { |
klauss | 126:1f90756250fb | 1805 | if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() not_eq MAX_TIMESLICES ) ) { |
klauss | 121:ee02790d00b7 | 1806 | bool ts_reset = true; |
klauss | 121:ee02790d00b7 | 1807 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 121:ee02790d00b7 | 1808 | uint16_t cb_status = ((Call_Box *)v_cb->get_element( i ))->get_status(); |
klauss | 121:ee02790d00b7 | 1809 | uint16_t cb_sip_status = ((Call_Box *)v_cb->get_element( i ))->get_sip_status(); |
klauss | 121:ee02790d00b7 | 1810 | |
klauss | 126:1f90756250fb | 1811 | if ((cb_status not_eq cb_idle) and (cb_sip_status not_eq sip_idle)) { |
klauss | 121:ee02790d00b7 | 1812 | ts_reset = false; |
klauss | 121:ee02790d00b7 | 1813 | break; |
klauss | 121:ee02790d00b7 | 1814 | } |
klauss | 121:ee02790d00b7 | 1815 | |
klauss | 121:ee02790d00b7 | 1816 | } |
klauss | 121:ee02790d00b7 | 1817 | if( ts_reset && !bl_start_flag ) |
klauss | 121:ee02790d00b7 | 1818 | { |
klauss | 132:05cd37f7e007 | 1819 | if( debug_invite ) vz_debug ("Resetando TS"); |
klauss | 121:ee02790d00b7 | 1820 | ts->reset(); |
klauss | 121:ee02790d00b7 | 1821 | } |
klauss | 121:ee02790d00b7 | 1822 | } |
klauss | 121:ee02790d00b7 | 1823 | |
klauss | 121:ee02790d00b7 | 1824 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1825 | } |
klauss | 121:ee02790d00b7 | 1826 | |
klauss | 132:05cd37f7e007 | 1827 | |
klauss | 132:05cd37f7e007 | 1828 | void show_lpc_low_level_input_counter ( void ) |
klauss | 132:05cd37f7e007 | 1829 | { |
klauss | 132:05cd37f7e007 | 1830 | vz_printf ("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 132:05cd37f7e007 | 1831 | lpc_low_level_input_counter = 0; |
klauss | 132:05cd37f7e007 | 1832 | } |
klauss | 132:05cd37f7e007 | 1833 | |
klauss | 121:ee02790d00b7 | 1834 | int show_wdt_status ( void ) |
klauss | 121:ee02790d00b7 | 1835 | { |
klauss | 121:ee02790d00b7 | 1836 | if( eth_status == 0 ) { |
klauss | 132:05cd37f7e007 | 1837 | vz_printf ( "Wdt last reset: %s - status_eth :: Connected - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )", |
klauss | 121:ee02790d00b7 | 1838 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 121:ee02790d00b7 | 1839 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 121:ee02790d00b7 | 1840 | EXTERN_WDT_IDLE, |
klauss | 121:ee02790d00b7 | 1841 | RX_CB_IDLE - pkg_wdt, |
klauss | 121:ee02790d00b7 | 1842 | RX_CB_IDLE |
klauss | 121:ee02790d00b7 | 1843 | ); |
klauss | 121:ee02790d00b7 | 1844 | } else { |
klauss | 132:05cd37f7e007 | 1845 | vz_printf ( "Wdt last reset: %s - status_eth :: Disconnected :: since %3d sec - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )", |
klauss | 121:ee02790d00b7 | 1846 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 121:ee02790d00b7 | 1847 | ETH_CONNECT_TIMEOUT - eth_wdt, |
klauss | 121:ee02790d00b7 | 1848 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 121:ee02790d00b7 | 1849 | EXTERN_WDT_IDLE, |
klauss | 121:ee02790d00b7 | 1850 | RX_CB_IDLE - pkg_wdt, |
klauss | 121:ee02790d00b7 | 1851 | RX_CB_IDLE |
klauss | 121:ee02790d00b7 | 1852 | ); |
klauss | 121:ee02790d00b7 | 1853 | } |
klauss | 121:ee02790d00b7 | 1854 | |
klauss | 121:ee02790d00b7 | 1855 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1856 | } |
klauss | 121:ee02790d00b7 | 1857 | |
klauss | 121:ee02790d00b7 | 1858 | |
klauss | 121:ee02790d00b7 | 1859 | int wdt_update ( void ) |
klauss | 121:ee02790d00b7 | 1860 | { |
klauss | 121:ee02790d00b7 | 1861 | uptime++; |
klauss | 121:ee02790d00b7 | 1862 | |
klauss | 121:ee02790d00b7 | 1863 | current_time++; |
klauss | 121:ee02790d00b7 | 1864 | |
klauss | 122:480c44b0e205 | 1865 | if ( wdt_show ) debug_wdt = true; |
klauss | 121:ee02790d00b7 | 1866 | |
klauss | 122:480c44b0e205 | 1867 | if ( external_wdt ) external_wdt--; |
klauss | 122:480c44b0e205 | 1868 | if ( pkg_wdt ) pkg_wdt--; |
klauss | 122:480c44b0e205 | 1869 | if ( eth_wdt ) eth_wdt--; |
klauss | 121:ee02790d00b7 | 1870 | |
klauss | 132:05cd37f7e007 | 1871 | if ( eth_wdt && external_wdt && ( pkg_wdt || disable_wdt_from_cbx ) ){ |
klauss | 121:ee02790d00b7 | 1872 | wdt.kick(); |
klauss | 122:480c44b0e205 | 1873 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1874 | } |
klauss | 121:ee02790d00b7 | 1875 | |
klauss | 122:480c44b0e205 | 1876 | return ( 1 ); |
klauss | 121:ee02790d00b7 | 1877 | } |
klauss | 121:ee02790d00b7 | 1878 | |
klauss | 121:ee02790d00b7 | 1879 | int check_for_unwanted_rtp_ports ( Vector * v_cb ) |
klauss | 121:ee02790d00b7 | 1880 | { |
klauss | 121:ee02790d00b7 | 1881 | for ( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 121:ee02790d00b7 | 1882 | { |
klauss | 121:ee02790d00b7 | 1883 | Call_Box * cb = (Call_Box *) v_cb->get_element (i); |
klauss | 126:1f90756250fb | 1884 | if ( cb not_eq NULL ) |
klauss | 121:ee02790d00b7 | 1885 | { |
klauss | 121:ee02790d00b7 | 1886 | if ( ( cb->get_status () == cb_idle ) && ( cb->get_sip_status () == sip_idle ) && ( cb -> is_rtp_timer_timeout () ) ) |
klauss | 121:ee02790d00b7 | 1887 | { |
klauss | 132:05cd37f7e007 | 1888 | if ( debug_reset_rtp ) vz_debug ( "[%d] rtp reset", cb -> get_ext () ); |
klauss | 121:ee02790d00b7 | 1889 | cb -> cb_set_status( cb_idle ); |
klauss | 121:ee02790d00b7 | 1890 | cb -> set_sip_status ( sip_idle ); |
klauss | 121:ee02790d00b7 | 1891 | cb -> reset_rtp_timer (); |
klauss | 121:ee02790d00b7 | 1892 | cb -> set_rtp_port ( 0 ); |
klauss | 121:ee02790d00b7 | 1893 | } |
klauss | 121:ee02790d00b7 | 1894 | } |
klauss | 121:ee02790d00b7 | 1895 | } |
klauss | 121:ee02790d00b7 | 1896 | return ( 0 ); |
klauss | 121:ee02790d00b7 | 1897 | } |
klauss | 121:ee02790d00b7 | 1898 | |
klauss | 121:ee02790d00b7 | 1899 | |
klauss | 121:ee02790d00b7 | 1900 | int process_received_pkg_from_cbx ( void ) |
klauss | 130:850163037da5 | 1901 | { |
klauss | 126:1f90756250fb | 1902 | // short path |
klauss | 125:8ff4dc96ad58 | 1903 | if ( buffer_from_cb_ptr [ TYPE_PLACE ] == AUDIO ) |
klauss | 124:c1b6c893e1c3 | 1904 | { |
klauss | 125:8ff4dc96ad58 | 1905 | xmemcpy ( buffer, buffer_from_cb_ptr, CB_BUFFER_SIZE ); |
klauss | 124:c1b6c893e1c3 | 1906 | status = WAITING; |
klauss | 132:05cd37f7e007 | 1907 | missed_pkg --; |
klauss | 124:c1b6c893e1c3 | 1908 | } |
klauss | 124:c1b6c893e1c3 | 1909 | else |
klauss | 126:1f90756250fb | 1910 | // long path |
klauss | 124:c1b6c893e1c3 | 1911 | { |
klauss | 125:8ff4dc96ad58 | 1912 | xmemcpy ( cb_rx_buffer, buffer_from_cb_ptr, CB_BUFFER_SIZE ); |
klauss | 124:c1b6c893e1c3 | 1913 | status = WAITING; |
klauss | 132:05cd37f7e007 | 1914 | missed_pkg --; |
klauss | 125:8ff4dc96ad58 | 1915 | xmemcpy ( buffer, cb_rx_buffer, CB_BUFFER_SIZE ); |
klauss | 125:8ff4dc96ad58 | 1916 | |
klauss | 125:8ff4dc96ad58 | 1917 | if ( debug_show_rx_cpld ) |
klauss | 124:c1b6c893e1c3 | 1918 | { |
klauss | 126:1f90756250fb | 1919 | char str [ 256 ]; |
klauss | 126:1f90756250fb | 1920 | strcpy ( str, "RX :: \n\r" ); |
klauss | 125:8ff4dc96ad58 | 1921 | |
klauss | 126:1f90756250fb | 1922 | for ( register uint16_t i = 0; i < 32; i++ ) |
klauss | 125:8ff4dc96ad58 | 1923 | { |
klauss | 126:1f90756250fb | 1924 | char tmp [ 8 ]; |
klauss | 125:8ff4dc96ad58 | 1925 | sprintf ( tmp, "%02x ", cb_rx_buffer [ i ] ); |
klauss | 126:1f90756250fb | 1926 | strcat ( str, tmp ); |
klauss | 124:c1b6c893e1c3 | 1927 | } |
klauss | 125:8ff4dc96ad58 | 1928 | |
klauss | 125:8ff4dc96ad58 | 1929 | strcat ( str, "\n\r " ); |
klauss | 125:8ff4dc96ad58 | 1930 | |
klauss | 132:05cd37f7e007 | 1931 | vz_printf ( "%s", str ); |
klauss | 124:c1b6c893e1c3 | 1932 | } |
klauss | 121:ee02790d00b7 | 1933 | } |
klauss | 121:ee02790d00b7 | 1934 | |
klauss | 121:ee02790d00b7 | 1935 | data = parse_vz_pkg ( &ext, &port, &type, buffer ); |
klauss | 121:ee02790d00b7 | 1936 | |
klauss | 126:1f90756250fb | 1937 | if ( data not_eq NULL ) |
klauss | 130:850163037da5 | 1938 | { |
klauss | 126:1f90756250fb | 1939 | if ( min_ext == 0 ) min_ext = ext; |
klauss | 121:ee02790d00b7 | 1940 | |
klauss | 126:1f90756250fb | 1941 | if ( ext > max_ext ) max_ext = ext; |
klauss | 121:ee02790d00b7 | 1942 | |
klauss | 126:1f90756250fb | 1943 | if ( ext < min_ext ) min_ext = ext; |
klauss | 121:ee02790d00b7 | 1944 | |
klauss | 126:1f90756250fb | 1945 | if ( debug_fw ) { fw_cbx_pkg ( ext, ( char *)buffer ); } |
klauss | 121:ee02790d00b7 | 1946 | |
klauss | 126:1f90756250fb | 1947 | if ( type == TELEMETRY ) |
klauss | 126:1f90756250fb | 1948 | { |
klauss | 132:05cd37f7e007 | 1949 | telemetry_counter ++; |
klauss | 126:1f90756250fb | 1950 | if ( debug_telemetry ) show_last_rx = true; |
klauss | 126:1f90756250fb | 1951 | } |
klauss | 121:ee02790d00b7 | 1952 | |
klauss | 127:e7160a463b6c | 1953 | if( type not_eq AUDIO ) |
klauss | 127:e7160a463b6c | 1954 | { |
klauss | 132:05cd37f7e007 | 1955 | if ( debug_cb_rx ) { vz_printf ("[%d %d] -- Type :: %d", ext, port, type ); } |
klauss | 127:e7160a463b6c | 1956 | |
klauss | 121:ee02790d00b7 | 1957 | if( |
klauss | 126:1f90756250fb | 1958 | type == TELEMETRY or |
klauss | 126:1f90756250fb | 1959 | type == CB_STATS or |
klauss | 126:1f90756250fb | 1960 | type == FW1 or |
klauss | 126:1f90756250fb | 1961 | type == FW2 or |
klauss | 126:1f90756250fb | 1962 | type == FW3 or |
klauss | 126:1f90756250fb | 1963 | type == FW4 or |
klauss | 126:1f90756250fb | 1964 | type == FW5 or |
klauss | 121:ee02790d00b7 | 1965 | type == FW6 |
klauss | 121:ee02790d00b7 | 1966 | ) type = FW; |
klauss | 121:ee02790d00b7 | 1967 | |
klauss | 132:05cd37f7e007 | 1968 | if ( debug_sqn ) { vz_printf ("[%d %d] -- Type :: %d -- seq_num :: %u", ext, port, type, cb_tx_buffer [ SEQ_NUM_PLACE ] ); } |
klauss | 121:ee02790d00b7 | 1969 | |
klauss | 126:1f90756250fb | 1970 | Call_Box * cb = find_CB ( v_cb, ext ); |
klauss | 126:1f90756250fb | 1971 | if ( cb not_eq NULL ) |
klauss | 126:1f90756250fb | 1972 | { |
klauss | 126:1f90756250fb | 1973 | if ( data[ 0 ] bitand BIT7 ) |
klauss | 126:1f90756250fb | 1974 | { |
klauss | 126:1f90756250fb | 1975 | if ( type == BOOT ) |
klauss | 126:1f90756250fb | 1976 | { |
klauss | 121:ee02790d00b7 | 1977 | send2callboxes( build_cb_package( ext, port, REGISTRY, |
klauss | 121:ee02790d00b7 | 1978 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 121:ee02790d00b7 | 1979 | } else { |
klauss | 132:05cd37f7e007 | 1980 | if ( debug_main ) vz_debug ("[%d] Received ack pkg with seq_num %d", ext, data[ 0 ] ); |
klauss | 121:ee02790d00b7 | 1981 | |
klauss | 126:1f90756250fb | 1982 | switch ( type ) |
klauss | 126:1f90756250fb | 1983 | { |
klauss | 121:ee02790d00b7 | 1984 | case INVITE : { |
klauss | 132:05cd37f7e007 | 1985 | if ( debug_main or debug_invite ) vz_debug ("[%d] Invite ACK - msg_id %d -- Cbx seqNum %d", ext, cb->get_msg_id(), data[ 0 ] ); |
klauss | 121:ee02790d00b7 | 1986 | break; |
klauss | 121:ee02790d00b7 | 1987 | } |
klauss | 121:ee02790d00b7 | 1988 | case CB_BYE : { |
klauss | 132:05cd37f7e007 | 1989 | if ( debug_main or debug_invite ) vz_debug ("[%d] BYE ACK - msg_id %d", ext, cb->get_msg_id() ); |
klauss | 126:1f90756250fb | 1990 | cb -> set_bye_response_ok (); |
klauss | 121:ee02790d00b7 | 1991 | break; |
klauss | 121:ee02790d00b7 | 1992 | } |
klauss | 121:ee02790d00b7 | 1993 | case REGISTRY : { |
klauss | 132:05cd37f7e007 | 1994 | if ( debug_main or debug_aging ) vz_debug ("[%d] Registry ACK - msg_id %d", ext, cb->get_msg_id() ); |
klauss | 121:ee02790d00b7 | 1995 | break; |
klauss | 121:ee02790d00b7 | 1996 | } |
klauss | 121:ee02790d00b7 | 1997 | default : { |
klauss | 132:05cd37f7e007 | 1998 | if ( debug_main or debug_aging ) vz_debug ("[%d] ACK msg_id :: %d :: type %d", ext, cb->get_msg_id(), type ); |
klauss | 121:ee02790d00b7 | 1999 | } |
klauss | 121:ee02790d00b7 | 2000 | } |
klauss | 126:1f90756250fb | 2001 | if ( type not_eq REGISTRY and type not_eq CB_BYE and type not_eq INVITE ) type = DO_NOTHING; |
klauss | 126:1f90756250fb | 2002 | if ( type == CB_BYE ) |
klauss | 126:1f90756250fb | 2003 | { |
klauss | 126:1f90756250fb | 2004 | VZ_call * call = find_Call ( v_call, ext ); |
klauss | 126:1f90756250fb | 2005 | if ( call not_eq NULL ) |
klauss | 126:1f90756250fb | 2006 | { |
klauss | 126:1f90756250fb | 2007 | if ( call -> get_elapsed_time () < 120000 ) |
klauss | 126:1f90756250fb | 2008 | { |
klauss | 132:05cd37f7e007 | 2009 | if ( debug_invite ) vz_debug ("[%d] ack bye ignored", ext ); |
klauss | 121:ee02790d00b7 | 2010 | type = DO_NOTHING; |
klauss | 121:ee02790d00b7 | 2011 | } |
klauss | 121:ee02790d00b7 | 2012 | } |
klauss | 121:ee02790d00b7 | 2013 | } |
klauss | 121:ee02790d00b7 | 2014 | } |
klauss | 121:ee02790d00b7 | 2015 | } |
klauss | 121:ee02790d00b7 | 2016 | } |
klauss | 121:ee02790d00b7 | 2017 | } |
klauss | 121:ee02790d00b7 | 2018 | } else type = DO_NOTHING; |
klauss | 121:ee02790d00b7 | 2019 | |
klauss | 121:ee02790d00b7 | 2020 | return 0; |
klauss | 123:1d395b5a4cad | 2021 | } |
klauss | 123:1d395b5a4cad | 2022 | |
klauss | 123:1d395b5a4cad | 2023 | void update_all_cb_timer ( Vector * v_cb ) |
klauss | 123:1d395b5a4cad | 2024 | { |
klauss | 123:1d395b5a4cad | 2025 | if ( v_cb == NULL ) return; |
klauss | 123:1d395b5a4cad | 2026 | |
klauss | 123:1d395b5a4cad | 2027 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 123:1d395b5a4cad | 2028 | { |
klauss | 123:1d395b5a4cad | 2029 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 126:1f90756250fb | 2030 | if ( cb not_eq NULL ) cb -> update_time (); |
klauss | 123:1d395b5a4cad | 2031 | } |
klauss | 124:c1b6c893e1c3 | 2032 | } |
klauss | 124:c1b6c893e1c3 | 2033 | |
klauss | 124:c1b6c893e1c3 | 2034 | int init_hello ( void ) |
klauss | 124:c1b6c893e1c3 | 2035 | { |
klauss | 124:c1b6c893e1c3 | 2036 | hello_sync.start (); |
klauss | 124:c1b6c893e1c3 | 2037 | hello_times = 0; |
klauss | 124:c1b6c893e1c3 | 2038 | return ( 0 ); |
klauss | 124:c1b6c893e1c3 | 2039 | } |
klauss | 124:c1b6c893e1c3 | 2040 | |
klauss | 124:c1b6c893e1c3 | 2041 | void send_hello_to_cbx ( void ) |
klauss | 124:c1b6c893e1c3 | 2042 | { |
klauss | 124:c1b6c893e1c3 | 2043 | if ( hello_times >= 3 ){ |
klauss | 124:c1b6c893e1c3 | 2044 | hello_sync.stop (); |
klauss | 124:c1b6c893e1c3 | 2045 | hello_sync.reset (); |
klauss | 124:c1b6c893e1c3 | 2046 | dont_say_hello_again = true; |
klauss | 124:c1b6c893e1c3 | 2047 | } |
klauss | 124:c1b6c893e1c3 | 2048 | |
klauss | 124:c1b6c893e1c3 | 2049 | if ( ( !dont_say_hello_again ) && ( hello_sync.read () > 3 ) && ( hello_times < 3 ) ) |
klauss | 124:c1b6c893e1c3 | 2050 | { |
klauss | 124:c1b6c893e1c3 | 2051 | hello_times++; |
klauss | 124:c1b6c893e1c3 | 2052 | |
klauss | 124:c1b6c893e1c3 | 2053 | char cmd_msg [ CB_BUFFER_SIZE ] = "pend\r"; |
klauss | 124:c1b6c893e1c3 | 2054 | |
klauss | 132:05cd37f7e007 | 2055 | if ( debug_hello ) vz_debug ("Enviando pend_all nro [ %i ]", hello_times ); |
klauss | 124:c1b6c893e1c3 | 2056 | |
klauss | 124:c1b6c893e1c3 | 2057 | send2callboxes( build_cb_package( BROADCAST_EXT, BROADCAST_EXT, PROMPT, cmd_msg, ( 0x11 + hello_times ), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 124:c1b6c893e1c3 | 2058 | |
klauss | 124:c1b6c893e1c3 | 2059 | hello_sync.reset (); |
klauss | 124:c1b6c893e1c3 | 2060 | } |
klauss | 124:c1b6c893e1c3 | 2061 | } |
klauss | 124:c1b6c893e1c3 | 2062 | |
klauss | 124:c1b6c893e1c3 | 2063 | void show_hello_status_function ( void ) |
klauss | 124:c1b6c893e1c3 | 2064 | { |
klauss | 132:05cd37f7e007 | 2065 | vz_printf ("hello_sync.read :: %d -- hello_times :: %u", ( int ) hello_sync.read (), hello_times ); |
klauss | 126:1f90756250fb | 2066 | } |
klauss | 126:1f90756250fb | 2067 | |
klauss | 126:1f90756250fb | 2068 | void show_last_rx_pkg_from_cbx ( void ) |
klauss | 126:1f90756250fb | 2069 | { |
klauss | 126:1f90756250fb | 2070 | char str [ 256 ] = ""; |
klauss | 126:1f90756250fb | 2071 | |
klauss | 126:1f90756250fb | 2072 | for ( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) |
klauss | 126:1f90756250fb | 2073 | { |
klauss | 126:1f90756250fb | 2074 | char tmp[ 8 ]; |
klauss | 126:1f90756250fb | 2075 | |
klauss | 126:1f90756250fb | 2076 | sprintf ( tmp, "%02x", cb_rx_buffer [ i ] ); |
klauss | 126:1f90756250fb | 2077 | |
klauss | 126:1f90756250fb | 2078 | strcat ( str, tmp ); |
klauss | 126:1f90756250fb | 2079 | |
klauss | 126:1f90756250fb | 2080 | if ( ( i not_eq 0 ) && !( ( i + 1 ) % 25 ) ) |
klauss | 126:1f90756250fb | 2081 | { |
klauss | 132:05cd37f7e007 | 2082 | vz_printf ( "%s", str ); |
klauss | 126:1f90756250fb | 2083 | strcpy ( str, "" ); |
klauss | 126:1f90756250fb | 2084 | } |
klauss | 126:1f90756250fb | 2085 | |
klauss | 126:1f90756250fb | 2086 | else { strcat ( str, " " ); } |
klauss | 126:1f90756250fb | 2087 | } |
klauss | 126:1f90756250fb | 2088 | |
klauss | 132:05cd37f7e007 | 2089 | vz_printf ( "%s", str ); |
klauss | 126:1f90756250fb | 2090 | } |
klauss | 126:1f90756250fb | 2091 | |
klauss | 126:1f90756250fb | 2092 | void show_last_tx_pkg_from_cbx ( void ) |
klauss | 126:1f90756250fb | 2093 | { |
klauss | 126:1f90756250fb | 2094 | char str [ 256 ] = ""; |
klauss | 126:1f90756250fb | 2095 | |
klauss | 126:1f90756250fb | 2096 | for ( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) |
klauss | 126:1f90756250fb | 2097 | { |
klauss | 126:1f90756250fb | 2098 | char tmp[ 8 ]; |
klauss | 126:1f90756250fb | 2099 | |
klauss | 126:1f90756250fb | 2100 | sprintf ( tmp, "%02x", cb_tx_buffer [ i ] ); |
klauss | 126:1f90756250fb | 2101 | |
klauss | 126:1f90756250fb | 2102 | strcat ( str, tmp ); |
klauss | 126:1f90756250fb | 2103 | |
klauss | 126:1f90756250fb | 2104 | if ( ( i not_eq 0 ) && !( ( i + 1 ) % 25 ) ) |
klauss | 126:1f90756250fb | 2105 | { |
klauss | 132:05cd37f7e007 | 2106 | vz_printf ( "%s", str ); |
klauss | 126:1f90756250fb | 2107 | strcpy ( str, "" ); |
klauss | 126:1f90756250fb | 2108 | } |
klauss | 126:1f90756250fb | 2109 | |
klauss | 126:1f90756250fb | 2110 | else { strcat ( str, " " ); } |
klauss | 126:1f90756250fb | 2111 | } |
klauss | 126:1f90756250fb | 2112 | |
klauss | 132:05cd37f7e007 | 2113 | vz_printf ( "%s", str ); |
klauss | 128:3ae1c74773a8 | 2114 | } |
klauss | 128:3ae1c74773a8 | 2115 | |
klauss | 128:3ae1c74773a8 | 2116 | /* Funcao para leitura da fonte de alimentacao e aviso ao servidor */ |
klauss | 128:3ae1c74773a8 | 2117 | void check_power_source ( void ) |
klauss | 128:3ae1c74773a8 | 2118 | { |
klauss | 128:3ae1c74773a8 | 2119 | static uint8_t samples = 0, warn_back = 0, wait_to_warn = 0; |
klauss | 128:3ae1c74773a8 | 2120 | |
klauss | 132:05cd37f7e007 | 2121 | power_source_timer.stop (); |
klauss | 132:05cd37f7e007 | 2122 | power_source_timer.reset (); |
klauss | 128:3ae1c74773a8 | 2123 | |
klauss | 132:05cd37f7e007 | 2124 | if ( pwr_src_in ) |
klauss | 132:05cd37f7e007 | 2125 | { |
klauss | 132:05cd37f7e007 | 2126 | if ( samples < 8 ) samples ++; |
klauss | 128:3ae1c74773a8 | 2127 | } else { |
klauss | 132:05cd37f7e007 | 2128 | if ( samples > 0 ) samples --; |
klauss | 128:3ae1c74773a8 | 2129 | } |
klauss | 128:3ae1c74773a8 | 2130 | |
klauss | 132:05cd37f7e007 | 2131 | if ( wait_to_warn ) wait_to_warn --; |
klauss | 128:3ae1c74773a8 | 2132 | |
klauss | 132:05cd37f7e007 | 2133 | if ( samples >= 8 ) |
klauss | 132:05cd37f7e007 | 2134 | { |
klauss | 132:05cd37f7e007 | 2135 | power_source_status = 1; |
klauss | 132:05cd37f7e007 | 2136 | if (!wait_to_warn ) |
klauss | 132:05cd37f7e007 | 2137 | { |
klauss | 132:05cd37f7e007 | 2138 | wait_to_warn = u8_WAIT_TO_WARN; |
klauss | 128:3ae1c74773a8 | 2139 | warn_back = 1; |
klauss | 132:05cd37f7e007 | 2140 | int power_source_client_ret = power_source_client.sendTo ( pwr_src_server, "mainpowerisdown", u8_POWER_MSG_LENGTH ); |
klauss | 132:05cd37f7e007 | 2141 | |
klauss | 132:05cd37f7e007 | 2142 | if ( power_source_client_ret not_eq u8_POWER_MSG_LENGTH ) |
klauss | 132:05cd37f7e007 | 2143 | { |
klauss | 132:05cd37f7e007 | 2144 | reconnect_power_source (); |
klauss | 132:05cd37f7e007 | 2145 | miss_power_source_send_pkg ++; |
klauss | 132:05cd37f7e007 | 2146 | if ( debug_reconnect ) vz_debug ( |
klauss | 132:05cd37f7e007 | 2147 | "Reconnect power_source_client_ret [ %d - %d ]", |
klauss | 132:05cd37f7e007 | 2148 | power_source_client_ret, u8_POWER_MSG_LENGTH |
klauss | 132:05cd37f7e007 | 2149 | ); |
klauss | 132:05cd37f7e007 | 2150 | } |
klauss | 132:05cd37f7e007 | 2151 | |
klauss | 132:05cd37f7e007 | 2152 | vz_debug ( "Main power is DOWN!"); |
klauss | 128:3ae1c74773a8 | 2153 | } else { |
klauss | 128:3ae1c74773a8 | 2154 | wait_to_warn--; |
klauss | 128:3ae1c74773a8 | 2155 | } |
klauss | 128:3ae1c74773a8 | 2156 | } |
klauss | 132:05cd37f7e007 | 2157 | |
klauss | 132:05cd37f7e007 | 2158 | if ( ( samples == 0 ) and ( warn_back ) ) |
klauss | 132:05cd37f7e007 | 2159 | { |
klauss | 132:05cd37f7e007 | 2160 | power_source_status = 0; |
klauss | 128:3ae1c74773a8 | 2161 | warn_back = 0; |
klauss | 128:3ae1c74773a8 | 2162 | wait_to_warn = 0; |
klauss | 132:05cd37f7e007 | 2163 | int power_source_client_ret = power_source_client.sendTo ( pwr_src_server, "mainpowerisback", u8_POWER_MSG_LENGTH ); |
klauss | 132:05cd37f7e007 | 2164 | if ( power_source_client_ret not_eq u8_POWER_MSG_LENGTH ); |
klauss | 132:05cd37f7e007 | 2165 | { |
klauss | 132:05cd37f7e007 | 2166 | reconnect_power_source (); |
klauss | 132:05cd37f7e007 | 2167 | miss_power_source_send_pkg ++; |
klauss | 132:05cd37f7e007 | 2168 | if ( debug_reconnect ) vz_debug ( |
klauss | 132:05cd37f7e007 | 2169 | "Reconnect power_source_client_ret [ %d - %d ]", |
klauss | 132:05cd37f7e007 | 2170 | power_source_client_ret, u8_POWER_MSG_LENGTH |
klauss | 132:05cd37f7e007 | 2171 | ); |
klauss | 132:05cd37f7e007 | 2172 | } |
klauss | 132:05cd37f7e007 | 2173 | vz_debug ( "Main power is BACK!" ); |
klauss | 132:05cd37f7e007 | 2174 | } |
klauss | 132:05cd37f7e007 | 2175 | |
klauss | 132:05cd37f7e007 | 2176 | power_source_timer.start (); |
klauss | 132:05cd37f7e007 | 2177 | } |
klauss | 132:05cd37f7e007 | 2178 | |
klauss | 132:05cd37f7e007 | 2179 | void update_config_values ( void ) |
klauss | 132:05cd37f7e007 | 2180 | { |
klauss | 132:05cd37f7e007 | 2181 | if ( cm -> min_ext_was_modified () or cm -> max_ext_was_modified () ) init_ranges (); |
klauss | 132:05cd37f7e007 | 2182 | |
klauss | 132:05cd37f7e007 | 2183 | if ( cm -> header_ip_was_modified () or |
klauss | 132:05cd37f7e007 | 2184 | cm -> net_mask_was_modified () or |
klauss | 132:05cd37f7e007 | 2185 | cm -> gateway_was_modified () ) |
klauss | 132:05cd37f7e007 | 2186 | { |
klauss | 132:05cd37f7e007 | 2187 | __reconnect (); |
klauss | 132:05cd37f7e007 | 2188 | } |
klauss | 132:05cd37f7e007 | 2189 | |
klauss | 132:05cd37f7e007 | 2190 | if ( cm -> header_ip_was_modified () or |
klauss | 132:05cd37f7e007 | 2191 | cm -> shift_port_was_modified () or |
klauss | 132:05cd37f7e007 | 2192 | cm -> server_ext_was_modified () or |
klauss | 132:05cd37f7e007 | 2193 | cm -> server_port_was_modified () or |
klauss | 132:05cd37f7e007 | 2194 | cm -> server_ip_was_modified () |
klauss | 132:05cd37f7e007 | 2195 | ) |
klauss | 132:05cd37f7e007 | 2196 | { |
klauss | 132:05cd37f7e007 | 2197 | for ( register uint8_t i = 0; i < v_cb -> size (); i++ ) |
klauss | 132:05cd37f7e007 | 2198 | { |
klauss | 132:05cd37f7e007 | 2199 | Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( i ); |
klauss | 132:05cd37f7e007 | 2200 | |
klauss | 132:05cd37f7e007 | 2201 | if ( cb not_eq NULL ) { |
klauss | 132:05cd37f7e007 | 2202 | cb -> update (); |
klauss | 132:05cd37f7e007 | 2203 | } |
klauss | 132:05cd37f7e007 | 2204 | } |
klauss | 128:3ae1c74773a8 | 2205 | } |
klauss | 128:3ae1c74773a8 | 2206 | |
klauss | 132:05cd37f7e007 | 2207 | if ( cm -> server_ip_was_modified () ) reconnect_power_source (); |
klauss | 132:05cd37f7e007 | 2208 | |
klauss | 132:05cd37f7e007 | 2209 | if ( cm -> fw_server_ip_was_modified () or cm -> fw_server_port_was_modified () ) { |
klauss | 132:05cd37f7e007 | 2210 | re_start_fw (); |
klauss | 132:05cd37f7e007 | 2211 | } |
klauss | 132:05cd37f7e007 | 2212 | } |
klauss | 132:05cd37f7e007 | 2213 | |
klauss | 132:05cd37f7e007 | 2214 | char * build_wdt_string ( char * wake_msg, const size_t length ) |
klauss | 132:05cd37f7e007 | 2215 | { |
klauss | 132:05cd37f7e007 | 2216 | if ( wake_msg == NULL ) return ( NULL ); |
klauss | 132:05cd37f7e007 | 2217 | |
klauss | 132:05cd37f7e007 | 2218 | snprintf( wake_msg, length,"wdt:%u,%u,%u,%c,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u:", |
klauss | 132:05cd37f7e007 | 2219 | uptime, |
klauss | 132:05cd37f7e007 | 2220 | invite_counter, |
klauss | 132:05cd37f7e007 | 2221 | external_wdt, |
klauss | 132:05cd37f7e007 | 2222 | ( wdt.WatchdogCausedReset() ) ? '1' : '0', |
klauss | 132:05cd37f7e007 | 2223 | cb_new_counter, |
klauss | 132:05cd37f7e007 | 2224 | v_cb->size(), |
klauss | 132:05cd37f7e007 | 2225 | ts->remain_timeslices(), |
klauss | 132:05cd37f7e007 | 2226 | sip_socket_send_failure, |
klauss | 132:05cd37f7e007 | 2227 | v_call->size(), |
klauss | 132:05cd37f7e007 | 2228 | pkg_cksok, |
klauss | 132:05cd37f7e007 | 2229 | pkg_ckserr, |
klauss | 132:05cd37f7e007 | 2230 | pkg_zero, |
klauss | 132:05cd37f7e007 | 2231 | out_of_range, |
klauss | 132:05cd37f7e007 | 2232 | missed_pkg, |
klauss | 132:05cd37f7e007 | 2233 | delayed_pkg_to_cb, |
klauss | 132:05cd37f7e007 | 2234 | cpld_pkg_tx_counter, |
klauss | 132:05cd37f7e007 | 2235 | cpld_pkg_rx_counter, |
klauss | 132:05cd37f7e007 | 2236 | eth_wdt, |
klauss | 132:05cd37f7e007 | 2237 | pkg_wdt, |
klauss | 132:05cd37f7e007 | 2238 | miss_fw_send_pkg, |
klauss | 132:05cd37f7e007 | 2239 | miss_prompt_udp_send_pkg, |
klauss | 132:05cd37f7e007 | 2240 | miss_sip_registry_send_pkg, |
klauss | 132:05cd37f7e007 | 2241 | miss_sip_invite_send_pkg, |
klauss | 132:05cd37f7e007 | 2242 | miss_sip_bye_send_pkg, |
klauss | 132:05cd37f7e007 | 2243 | miss_sip_ok_send_pkg, |
klauss | 132:05cd37f7e007 | 2244 | miss_sip_rcv_bye_send_pkg, |
klauss | 132:05cd37f7e007 | 2245 | miss_wdt_send_pkg, |
klauss | 132:05cd37f7e007 | 2246 | miss_rtp_udp_send_pkg, |
klauss | 132:05cd37f7e007 | 2247 | miss_prompt_udp_rcv_pkg, |
klauss | 132:05cd37f7e007 | 2248 | miss_clock_send_pkg, |
klauss | 132:05cd37f7e007 | 2249 | miss_sip_inc_pkg, |
klauss | 132:05cd37f7e007 | 2250 | miss_power_source_send_pkg, |
klauss | 132:05cd37f7e007 | 2251 | miss_bl_udp_send_pkg, |
klauss | 132:05cd37f7e007 | 2252 | miss_rtp_udp_rcv_pkg |
klauss | 132:05cd37f7e007 | 2253 | ); |
klauss | 132:05cd37f7e007 | 2254 | |
klauss | 132:05cd37f7e007 | 2255 | return ( wake_msg ); |
klauss | 121:ee02790d00b7 | 2256 | } |