![](/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.cpp@132:05cd37f7e007, 2015-09-01 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 01 17:21:11 2015 +0000
- Revision:
- 132:05cd37f7e007
- Parent:
- 130:850163037da5
- 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 | 120:770f00554b1e | 2 | #include "main_app_var_configs.h" |
klauss | 85:b6f2dc1d0f4f | 3 | |
klauss | 91:c2a86b1f8aaa | 4 | int main() |
klauss | 114:472502b31a12 | 5 | { |
klauss | 100:09a23fcd3bdf | 6 | debug_uart3 = true; |
klauss | 119:ee6a53069455 | 7 | |
klauss | 119:ee6a53069455 | 8 | int header_app_init_ret = header_app_init (); |
klauss | 117:e9facba9db27 | 9 | |
klauss | 132:05cd37f7e007 | 10 | vz_printf ( "header_app_init %s" , ( header_app_init_ret == 0 ) ? "Ok" : "Failure" ); |
klauss | 99:e80850c51106 | 11 | |
klauss | 132:05cd37f7e007 | 12 | if ( header_app_init_ret == 0 ) vz_printf ("Ready"); |
klauss | 105:a930035b6556 | 13 | |
klauss | 114:472502b31a12 | 14 | debug_uart3 = false; |
klauss | 105:a930035b6556 | 15 | |
klauss | 132:05cd37f7e007 | 16 | power_source_timer.start (); |
klauss | 132:05cd37f7e007 | 17 | |
klauss | 119:ee6a53069455 | 18 | /*------------------------------------------ main loop ---------------------------------------------------------------*/ |
klauss | 115:a1e1e2e60a2c | 19 | |
klauss | 119:ee6a53069455 | 20 | while( true ) |
klauss | 119:ee6a53069455 | 21 | { |
klauss | 132:05cd37f7e007 | 22 | prompt_process ( NULL, 0 ); |
klauss | 132:05cd37f7e007 | 23 | |
klauss | 132:05cd37f7e007 | 24 | if ( cm -> was_modified () ) |
klauss | 132:05cd37f7e007 | 25 | { |
klauss | 132:05cd37f7e007 | 26 | update_config_values (); |
klauss | 132:05cd37f7e007 | 27 | cm -> set_modified_false (); |
klauss | 132:05cd37f7e007 | 28 | } |
klauss | 126:1f90756250fb | 29 | |
klauss | 126:1f90756250fb | 30 | if ( show_last_rx ) |
klauss | 126:1f90756250fb | 31 | { |
klauss | 127:e7160a463b6c | 32 | if ( v_call -> size () == 0 ) show_last_rx_pkg_from_cbx (); |
klauss | 126:1f90756250fb | 33 | show_last_rx = false; |
klauss | 126:1f90756250fb | 34 | } |
klauss | 126:1f90756250fb | 35 | |
klauss | 126:1f90756250fb | 36 | if ( show_last_tx ) |
klauss | 126:1f90756250fb | 37 | { |
klauss | 127:e7160a463b6c | 38 | if ( v_call -> size () == 0 ) show_last_tx_pkg_from_cbx (); |
klauss | 126:1f90756250fb | 39 | show_last_tx = false; |
klauss | 126:1f90756250fb | 40 | } |
klauss | 126:1f90756250fb | 41 | |
klauss | 124:c1b6c893e1c3 | 42 | if ( show_hello_status ) |
klauss | 124:c1b6c893e1c3 | 43 | { |
klauss | 124:c1b6c893e1c3 | 44 | show_hello_status_function (); |
klauss | 124:c1b6c893e1c3 | 45 | show_hello_status = false; |
klauss | 124:c1b6c893e1c3 | 46 | } |
klauss | 124:c1b6c893e1c3 | 47 | |
klauss | 78:1353744f01e1 | 48 | if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 49 | |
klauss | 120:770f00554b1e | 50 | if ( sync_timer.read() > 5 ) |
klauss | 119:ee6a53069455 | 51 | { |
klauss | 78:1353744f01e1 | 52 | sync_timer.reset(); |
klauss | 91:c2a86b1f8aaa | 53 | |
klauss | 119:ee6a53069455 | 54 | if( debug_cks == true ) { pcks_s = true; } |
klauss | 91:c2a86b1f8aaa | 55 | |
klauss | 119:ee6a53069455 | 56 | if( debug_alive == true ) { pshowcb = true; } |
klauss | 105:a930035b6556 | 57 | |
klauss | 114:472502b31a12 | 58 | if( !( ++count % 15 ) ) { |
klauss | 91:c2a86b1f8aaa | 59 | if( eth_status ) { |
klauss | 119:ee6a53069455 | 60 | try_reconnect_with_eth (); |
klauss | 78:1353744f01e1 | 61 | } |
klauss | 78:1353744f01e1 | 62 | } |
klauss | 100:09a23fcd3bdf | 63 | |
klauss | 114:472502b31a12 | 64 | //35 sec. |
klauss | 126:1f90756250fb | 65 | if( ( count > 7 ) and ( wake_all == false ) ) { |
klauss | 81:3656f00ab3db | 66 | wake_all = true; |
klauss | 132:05cd37f7e007 | 67 | if( debug_wake == true ) vz_printf ( "Time to wake" ); |
klauss | 78:1353744f01e1 | 68 | } |
klauss | 119:ee6a53069455 | 69 | |
klauss | 119:ee6a53069455 | 70 | // enable na variavel que exibe lista com estatisticas de pacotes que falharam ao serem enviados via interface eth |
klauss | 119:ee6a53069455 | 71 | if ( debug_missed ) { missed_send_udp_pkg = true; } |
klauss | 119:ee6a53069455 | 72 | |
klauss | 114:472502b31a12 | 73 | } |
klauss | 124:c1b6c893e1c3 | 74 | |
klauss | 124:c1b6c893e1c3 | 75 | if ( show_wake_all_up_status ) |
klauss | 124:c1b6c893e1c3 | 76 | { |
klauss | 132:05cd37f7e007 | 77 | vz_printf ("wake_all_up status :: %s", ( wake_all ) ? "Enable" : "Disable" ); |
klauss | 124:c1b6c893e1c3 | 78 | show_wake_all_up_status = false; |
klauss | 124:c1b6c893e1c3 | 79 | } |
klauss | 119:ee6a53069455 | 80 | |
klauss | 119:ee6a53069455 | 81 | check_clock (); |
klauss | 114:472502b31a12 | 82 | |
klauss | 119:ee6a53069455 | 83 | if ( r_stats ) |
klauss | 119:ee6a53069455 | 84 | { |
klauss | 119:ee6a53069455 | 85 | reset_stats (); |
klauss | 120:770f00554b1e | 86 | stats = true; |
klauss | 63:0d95da692bb4 | 87 | r_stats = false; |
klauss | 63:0d95da692bb4 | 88 | } |
klauss | 91:c2a86b1f8aaa | 89 | |
klauss | 119:ee6a53069455 | 90 | if ( stats ) |
klauss | 119:ee6a53069455 | 91 | { |
klauss | 119:ee6a53069455 | 92 | show_stats (); |
klauss | 63:0d95da692bb4 | 93 | stats =false; |
klauss | 63:0d95da692bb4 | 94 | } |
klauss | 114:472502b31a12 | 95 | |
klauss | 119:ee6a53069455 | 96 | if ( list ) |
klauss | 119:ee6a53069455 | 97 | { |
klauss | 119:ee6a53069455 | 98 | show_cb_list ( v_cb ); |
klauss | 91:c2a86b1f8aaa | 99 | list = false; |
klauss | 114:472502b31a12 | 100 | } |
klauss | 114:472502b31a12 | 101 | |
klauss | 119:ee6a53069455 | 102 | if ( long_list ) |
klauss | 106:a34fcf9f0e02 | 103 | { |
klauss | 132:05cd37f7e007 | 104 | show_cb_long_list ( v_cb, show_time, show_invites ); |
klauss | 91:c2a86b1f8aaa | 105 | long_list = false; |
klauss | 123:1d395b5a4cad | 106 | show_time = false; |
klauss | 132:05cd37f7e007 | 107 | show_invites = false; |
klauss | 52:12930cef17c4 | 108 | } |
klauss | 119:ee6a53069455 | 109 | |
klauss | 119:ee6a53069455 | 110 | if ( pshowcb ) |
klauss | 119:ee6a53069455 | 111 | { |
klauss | 119:ee6a53069455 | 112 | show_cb ( v_cb ); |
klauss | 78:1353744f01e1 | 113 | pshowcb = false; |
klauss | 48:195c97f12e8e | 114 | } |
klauss | 97:8985817e8847 | 115 | |
klauss | 124:c1b6c893e1c3 | 116 | if ( request_clock_now ) |
klauss | 124:c1b6c893e1c3 | 117 | { |
klauss | 124:c1b6c893e1c3 | 118 | request_clock_to_server (); |
klauss | 124:c1b6c893e1c3 | 119 | show_current_time = true; |
klauss | 124:c1b6c893e1c3 | 120 | request_clock_now = false; |
klauss | 124:c1b6c893e1c3 | 121 | } |
klauss | 124:c1b6c893e1c3 | 122 | |
klauss | 119:ee6a53069455 | 123 | if ( show_current_time ) |
klauss | 119:ee6a53069455 | 124 | { |
klauss | 119:ee6a53069455 | 125 | show_clock (); |
klauss | 119:ee6a53069455 | 126 | show_current_time = false;; |
klauss | 119:ee6a53069455 | 127 | } |
klauss | 119:ee6a53069455 | 128 | |
klauss | 120:770f00554b1e | 129 | if( show_sip ){ |
klauss | 120:770f00554b1e | 130 | show_cb_sip ( v_cb ); |
klauss | 97:8985817e8847 | 131 | show_sip = false; |
klauss | 97:8985817e8847 | 132 | } |
klauss | 91:c2a86b1f8aaa | 133 | |
klauss | 81:3656f00ab3db | 134 | if( pflood == true ) flood(); |
klauss | 91:c2a86b1f8aaa | 135 | |
klauss | 91:c2a86b1f8aaa | 136 | if( debug_eth ) { |
klauss | 132:05cd37f7e007 | 137 | vz_printf ("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); |
klauss | 81:3656f00ab3db | 138 | debug_eth = false; |
klauss | 81:3656f00ab3db | 139 | } |
klauss | 132:05cd37f7e007 | 140 | |
klauss | 91:c2a86b1f8aaa | 141 | |
klauss | 120:770f00554b1e | 142 | // chechando se existe um pacote vindo do cbx pendente |
klauss | 121:ee02790d00b7 | 143 | if( status != WAITING ) |
klauss | 121:ee02790d00b7 | 144 | { |
klauss | 126:1f90756250fb | 145 | process_received_pkg_from_cbx (); |
klauss | 126:1f90756250fb | 146 | } |
klauss | 126:1f90756250fb | 147 | else if ( test_ts and test_ts_timer.read_ms () > 10 ) |
klauss | 126:1f90756250fb | 148 | { |
klauss | 126:1f90756250fb | 149 | if ( v_cb -> size () not_eq 0 ) |
klauss | 126:1f90756250fb | 150 | { |
klauss | 126:1f90756250fb | 151 | Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( 0 ); |
klauss | 126:1f90756250fb | 152 | if ( cb not_eq NULL ) |
klauss | 126:1f90756250fb | 153 | { |
klauss | 126:1f90756250fb | 154 | ext = cb -> get_ext (); |
klauss | 126:1f90756250fb | 155 | port = cb -> get_port (); |
klauss | 126:1f90756250fb | 156 | } |
klauss | 126:1f90756250fb | 157 | } |
klauss | 126:1f90756250fb | 158 | else |
klauss | 126:1f90756250fb | 159 | { |
klauss | 126:1f90756250fb | 160 | ext = 5000; |
klauss | 126:1f90756250fb | 161 | port = 5000; |
klauss | 126:1f90756250fb | 162 | } |
klauss | 126:1f90756250fb | 163 | |
klauss | 126:1f90756250fb | 164 | type = INVITE; |
klauss | 126:1f90756250fb | 165 | data = buffer; |
klauss | 126:1f90756250fb | 166 | |
klauss | 126:1f90756250fb | 167 | test_ts_timer.reset (); |
klauss | 0:4d17cd9c8f9d | 168 | } |
klauss | 91:c2a86b1f8aaa | 169 | |
klauss | 119:ee6a53069455 | 170 | if( sizes == true ) |
klauss | 119:ee6a53069455 | 171 | { |
klauss | 120:770f00554b1e | 172 | show_sizes (); |
klauss | 119:ee6a53069455 | 173 | sizes = false; |
klauss | 109:a5b8264ffbbc | 174 | } |
klauss | 109:a5b8264ffbbc | 175 | |
klauss | 120:770f00554b1e | 176 | // usado pra testes |
klauss | 112:6ae726539ab9 | 177 | { |
klauss | 132:05cd37f7e007 | 178 | if ( registra ) |
klauss | 132:05cd37f7e007 | 179 | { |
klauss | 132:05cd37f7e007 | 180 | int internal_ext = 8000; |
klauss | 132:05cd37f7e007 | 181 | registra = false; |
klauss | 132:05cd37f7e007 | 182 | for( register uint8_t i = 0; i < MAX_CB_IN_A_BRANCH - 2; i++ ) { |
klauss | 132:05cd37f7e007 | 183 | v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); |
klauss | 132:05cd37f7e007 | 184 | } |
klauss | 132:05cd37f7e007 | 185 | } |
klauss | 132:05cd37f7e007 | 186 | |
klauss | 132:05cd37f7e007 | 187 | if ( registra4 ) |
klauss | 132:05cd37f7e007 | 188 | { |
klauss | 132:05cd37f7e007 | 189 | int internal_ext = 8000; |
klauss | 132:05cd37f7e007 | 190 | registra4 = false; |
klauss | 132:05cd37f7e007 | 191 | for( register uint8_t i = 0; i < 4; i++ ) |
klauss | 132:05cd37f7e007 | 192 | { |
klauss | 132:05cd37f7e007 | 193 | v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); |
klauss | 132:05cd37f7e007 | 194 | } |
klauss | 132:05cd37f7e007 | 195 | } |
klauss | 112:6ae726539ab9 | 196 | } |
klauss | 112:6ae726539ab9 | 197 | |
klauss | 132:05cd37f7e007 | 198 | check_udp_packages_pending ( v_cb ); |
klauss | 120:770f00554b1e | 199 | |
klauss | 120:770f00554b1e | 200 | if( dshow_rtp == true ) |
klauss | 109:a5b8264ffbbc | 201 | { |
klauss | 120:770f00554b1e | 202 | show_rtp (); |
klauss | 120:770f00554b1e | 203 | dshow_rtp = false; |
klauss | 120:770f00554b1e | 204 | } |
klauss | 117:e9facba9db27 | 205 | |
klauss | 120:770f00554b1e | 206 | // usado pra test |
klauss | 120:770f00554b1e | 207 | if ( frtp ) |
klauss | 120:770f00554b1e | 208 | { |
klauss | 120:770f00554b1e | 209 | fuck_rtp ( v_cb ); |
klauss | 120:770f00554b1e | 210 | frtp = false; |
klauss | 109:a5b8264ffbbc | 211 | } |
klauss | 109:a5b8264ffbbc | 212 | |
klauss | 120:770f00554b1e | 213 | // usado pra test |
klauss | 109:a5b8264ffbbc | 214 | if ( rescue_rtp ) |
klauss | 109:a5b8264ffbbc | 215 | { |
klauss | 109:a5b8264ffbbc | 216 | rescue_rtp = false; |
klauss | 121:ee02790d00b7 | 217 | Call_Box * cb = find_CB( v_cb, rescue_rtp_target ); |
klauss | 109:a5b8264ffbbc | 218 | if ( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 219 | { |
klauss | 109:a5b8264ffbbc | 220 | cb -> set_rtp_port ( rescue_rtp_value ); |
klauss | 109:a5b8264ffbbc | 221 | } |
klauss | 109:a5b8264ffbbc | 222 | else |
klauss | 109:a5b8264ffbbc | 223 | { |
klauss | 132:05cd37f7e007 | 224 | vz_debug ("rescue rtp fail"); |
klauss | 109:a5b8264ffbbc | 225 | } |
klauss | 109:a5b8264ffbbc | 226 | } |
klauss | 109:a5b8264ffbbc | 227 | |
klauss | 109:a5b8264ffbbc | 228 | if ( print_v_cb ) |
klauss | 109:a5b8264ffbbc | 229 | { |
klauss | 120:770f00554b1e | 230 | v_cb->print_yourself (); |
klauss | 109:a5b8264ffbbc | 231 | print_v_cb = false; |
klauss | 109:a5b8264ffbbc | 232 | } |
klauss | 109:a5b8264ffbbc | 233 | |
klauss | 109:a5b8264ffbbc | 234 | if ( print_v_call ) |
klauss | 109:a5b8264ffbbc | 235 | { |
klauss | 109:a5b8264ffbbc | 236 | v_call->print_yourself (); |
klauss | 120:770f00554b1e | 237 | print_v_call = false; |
klauss | 109:a5b8264ffbbc | 238 | } |
klauss | 109:a5b8264ffbbc | 239 | |
klauss | 109:a5b8264ffbbc | 240 | if ( print_cb_var ) |
klauss | 109:a5b8264ffbbc | 241 | { |
klauss | 120:770f00554b1e | 242 | show_cb_content (); |
klauss | 109:a5b8264ffbbc | 243 | print_cb_var = false; |
klauss | 109:a5b8264ffbbc | 244 | } |
klauss | 109:a5b8264ffbbc | 245 | |
klauss | 109:a5b8264ffbbc | 246 | if ( print_cb_all ) |
klauss | 109:a5b8264ffbbc | 247 | { |
klauss | 120:770f00554b1e | 248 | show_cb_content_all (); |
klauss | 109:a5b8264ffbbc | 249 | print_cb_all = false; |
klauss | 109:a5b8264ffbbc | 250 | } |
klauss | 109:a5b8264ffbbc | 251 | |
klauss | 109:a5b8264ffbbc | 252 | if ( print_hex_cb_var ) |
klauss | 109:a5b8264ffbbc | 253 | { |
klauss | 120:770f00554b1e | 254 | show_hex_cb_content (); |
klauss | 109:a5b8264ffbbc | 255 | print_hex_cb_var = false; |
klauss | 81:3656f00ab3db | 256 | } |
klauss | 106:a34fcf9f0e02 | 257 | |
klauss | 109:a5b8264ffbbc | 258 | if ( print_hex_cb_all ) |
klauss | 109:a5b8264ffbbc | 259 | { |
klauss | 120:770f00554b1e | 260 | show_hex_cb_content_all (); |
klauss | 109:a5b8264ffbbc | 261 | print_hex_cb_all = false; |
klauss | 109:a5b8264ffbbc | 262 | } |
klauss | 106:a34fcf9f0e02 | 263 | |
klauss | 120:770f00554b1e | 264 | if ( print_sip_var ) |
klauss | 109:a5b8264ffbbc | 265 | { |
klauss | 132:05cd37f7e007 | 266 | show_cb_sip (); |
klauss | 120:770f00554b1e | 267 | print_sip_var = false; |
klauss | 120:770f00554b1e | 268 | } |
klauss | 109:a5b8264ffbbc | 269 | |
klauss | 120:770f00554b1e | 270 | if ( print_sip_all ) |
klauss | 120:770f00554b1e | 271 | { |
klauss | 132:05cd37f7e007 | 272 | show_cb_sip_all (); |
klauss | 120:770f00554b1e | 273 | print_sip_all = false; |
klauss | 120:770f00554b1e | 274 | } |
klauss | 120:770f00554b1e | 275 | |
klauss | 120:770f00554b1e | 276 | if ( print_hex_sip_var ) |
klauss | 120:770f00554b1e | 277 | { |
klauss | 132:05cd37f7e007 | 278 | show_cb_hex_sip (); |
klauss | 120:770f00554b1e | 279 | print_hex_sip_var = false; |
klauss | 120:770f00554b1e | 280 | } |
klauss | 109:a5b8264ffbbc | 281 | |
klauss | 109:a5b8264ffbbc | 282 | if( dcallshow_rtp == true ){ |
klauss | 120:770f00554b1e | 283 | show_rtp_on_call (); |
klauss | 109:a5b8264ffbbc | 284 | dcallshow_rtp = false; |
klauss | 109:a5b8264ffbbc | 285 | } |
klauss | 109:a5b8264ffbbc | 286 | |
klauss | 109:a5b8264ffbbc | 287 | if ( print_call_var ) |
klauss | 109:a5b8264ffbbc | 288 | { |
klauss | 120:770f00554b1e | 289 | show_call (); |
klauss | 109:a5b8264ffbbc | 290 | print_call_var = false; |
klauss | 120:770f00554b1e | 291 | |
klauss | 109:a5b8264ffbbc | 292 | } |
klauss | 109:a5b8264ffbbc | 293 | |
klauss | 109:a5b8264ffbbc | 294 | if ( print_hex_call_var ) |
klauss | 109:a5b8264ffbbc | 295 | { |
klauss | 120:770f00554b1e | 296 | show_hex_call (); |
klauss | 109:a5b8264ffbbc | 297 | print_hex_call_var = false; |
klauss | 109:a5b8264ffbbc | 298 | } |
klauss | 109:a5b8264ffbbc | 299 | |
klauss | 109:a5b8264ffbbc | 300 | |
klauss | 109:a5b8264ffbbc | 301 | if ( print_hex_rtp_var ) |
klauss | 109:a5b8264ffbbc | 302 | { |
klauss | 120:770f00554b1e | 303 | show_cb_rtp (); |
klauss | 109:a5b8264ffbbc | 304 | print_hex_rtp_var = false; |
klauss | 109:a5b8264ffbbc | 305 | } |
klauss | 109:a5b8264ffbbc | 306 | |
klauss | 109:a5b8264ffbbc | 307 | if ( print_rtp_var ) |
klauss | 109:a5b8264ffbbc | 308 | { |
klauss | 120:770f00554b1e | 309 | show_cb_hex_rtp (); |
klauss | 109:a5b8264ffbbc | 310 | print_rtp_var = false; |
klauss | 81:3656f00ab3db | 311 | } |
klauss | 91:c2a86b1f8aaa | 312 | |
klauss | 120:770f00554b1e | 313 | if( reset_cks == true ) |
klauss | 120:770f00554b1e | 314 | { |
klauss | 120:770f00554b1e | 315 | reset_stats_cks (); |
klauss | 120:770f00554b1e | 316 | pcks_s = true; |
klauss | 120:770f00554b1e | 317 | reset_cks = false; |
klauss | 120:770f00554b1e | 318 | } |
klauss | 120:770f00554b1e | 319 | |
klauss | 91:c2a86b1f8aaa | 320 | if( pcks_s == true ) { |
klauss | 120:770f00554b1e | 321 | show_cb_stats (); |
klauss | 81:3656f00ab3db | 322 | pcks_s = false; |
klauss | 81:3656f00ab3db | 323 | } |
klauss | 119:ee6a53069455 | 324 | |
klauss | 132:05cd37f7e007 | 325 | if ( show_wdt_string ) |
klauss | 132:05cd37f7e007 | 326 | { |
klauss | 132:05cd37f7e007 | 327 | char wdt_msg [ 1024 ]; |
klauss | 132:05cd37f7e007 | 328 | build_wdt_string ( wdt_msg, sizeof ( wdt_msg ) - 1 ); |
klauss | 132:05cd37f7e007 | 329 | |
klauss | 132:05cd37f7e007 | 330 | int siRet = strlen ( wdt_msg ); |
klauss | 132:05cd37f7e007 | 331 | |
klauss | 132:05cd37f7e007 | 332 | vz_printf ( "wdt_msg.length::%d\r\n%s", siRet, wdt_msg ); |
klauss | 132:05cd37f7e007 | 333 | |
klauss | 132:05cd37f7e007 | 334 | show_wdt_string = false; |
klauss | 132:05cd37f7e007 | 335 | } |
klauss | 132:05cd37f7e007 | 336 | |
klauss | 120:770f00554b1e | 337 | if( reset_missed_send_udp_pkg ) |
klauss | 120:770f00554b1e | 338 | { |
klauss | 120:770f00554b1e | 339 | reset_missed_send_udp (); |
klauss | 120:770f00554b1e | 340 | missed_send_udp_pkg = true; |
klauss | 119:ee6a53069455 | 341 | reset_missed_send_udp_pkg = false; |
klauss | 119:ee6a53069455 | 342 | } |
klauss | 119:ee6a53069455 | 343 | |
klauss | 124:c1b6c893e1c3 | 344 | if ( missed_send_udp_pkg ) |
klauss | 119:ee6a53069455 | 345 | { |
klauss | 120:770f00554b1e | 346 | show_missed_send_udp_pkg (); |
klauss | 119:ee6a53069455 | 347 | missed_send_udp_pkg = false; |
klauss | 119:ee6a53069455 | 348 | } |
klauss | 124:c1b6c893e1c3 | 349 | |
klauss | 121:ee02790d00b7 | 350 | // usado pra test |
klauss | 126:1f90756250fb | 351 | if ( flood_bug_pkg ){ |
klauss | 100:09a23fcd3bdf | 352 | static int id = 0x10; |
klauss | 100:09a23fcd3bdf | 353 | if( id < 10 ) id = 0x0b; |
klauss | 119:ee6a53069455 | 354 | send2callboxes( build_cb_package( 5828, 5123, REGISTRY, |
klauss | 119:ee6a53069455 | 355 | ( char * )buffer, id++, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 100:09a23fcd3bdf | 356 | } |
klauss | 100:09a23fcd3bdf | 357 | |
klauss | 126:1f90756250fb | 358 | if ( led_sync_timer.read() > 1 ) { |
klauss | 78:1353744f01e1 | 359 | led_sync_timer.reset(); |
klauss | 78:1353744f01e1 | 360 | led3 = !led3; |
klauss | 78:1353744f01e1 | 361 | CAB_LED = !CAB_LED; |
klauss | 78:1353744f01e1 | 362 | } |
klauss | 126:1f90756250fb | 363 | |
klauss | 126:1f90756250fb | 364 | switch( type ) |
klauss | 126:1f90756250fb | 365 | { |
klauss | 126:1f90756250fb | 366 | case DO_NOTHING :{} |
klauss | 91:c2a86b1f8aaa | 367 | break; |
klauss | 91:c2a86b1f8aaa | 368 | |
klauss | 126:1f90756250fb | 369 | case CB_BYE : |
klauss | 126:1f90756250fb | 370 | { |
klauss | 132:05cd37f7e007 | 371 | cb_bye_counter ++; |
klauss | 132:05cd37f7e007 | 372 | Call_Box * cb = find_CB ( v_cb, ext ); |
klauss | 132:05cd37f7e007 | 373 | if ( cb != NULL ) |
klauss | 132:05cd37f7e007 | 374 | { |
klauss | 132:05cd37f7e007 | 375 | if ( debug_invite or debug_main ) vz_debug ("[%d] Bye pkg - msg_id %d e pkg_id %d", ext, cb -> get_msg_id (), data [ 0 ] ); |
klauss | 92:92df17f538a8 | 376 | |
klauss | 81:3656f00ab3db | 377 | bool already_removed = true; |
klauss | 119:ee6a53069455 | 378 | |
klauss | 132:05cd37f7e007 | 379 | if ( cb -> get_status () != cb_idle ) |
klauss | 132:05cd37f7e007 | 380 | { |
klauss | 119:ee6a53069455 | 381 | already_removed = false; |
klauss | 119:ee6a53069455 | 382 | |
klauss | 132:05cd37f7e007 | 383 | data [ TIMESLICE_PLACE ] = 0; |
klauss | 119:ee6a53069455 | 384 | |
klauss | 132:05cd37f7e007 | 385 | send2callboxes ( build_cb_package ( ext, port, CB_BYE, |
klauss | 132:05cd37f7e007 | 386 | ( char * )data, data [ 0 ] or_eq BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 119:ee6a53069455 | 387 | |
klauss | 132:05cd37f7e007 | 388 | ts -> return_timeslice ( cb -> call_end () ); |
klauss | 119:ee6a53069455 | 389 | } |
klauss | 119:ee6a53069455 | 390 | |
klauss | 132:05cd37f7e007 | 391 | if ( already_removed ) if ( debug_main or debug_invite ) vz_debug ( "[%d] Already removed from inviting queue", ext ); |
klauss | 119:ee6a53069455 | 392 | |
klauss | 119:ee6a53069455 | 393 | already_removed = true; |
klauss | 119:ee6a53069455 | 394 | |
klauss | 119:ee6a53069455 | 395 | for ( register uint8_t i = 0; i < v_call->size(); i++ ) |
klauss | 119:ee6a53069455 | 396 | { |
klauss | 0:4d17cd9c8f9d | 397 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 119:ee6a53069455 | 398 | if( call->get_cb_ext() == ext ) |
klauss | 119:ee6a53069455 | 399 | { |
klauss | 81:3656f00ab3db | 400 | already_removed = false; |
klauss | 119:ee6a53069455 | 401 | |
klauss | 119:ee6a53069455 | 402 | data[ TIMESLICE_PLACE ] = 0; |
klauss | 91:c2a86b1f8aaa | 403 | |
klauss | 81:3656f00ab3db | 404 | v_call->remove_element( i ); |
klauss | 119:ee6a53069455 | 405 | |
klauss | 119:ee6a53069455 | 406 | send2callboxes( build_cb_package( ext, port, CB_BYE, |
klauss | 126:1f90756250fb | 407 | ( char * )data, data[ 0 ] or_eq BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 117:e9facba9db27 | 408 | |
klauss | 3:cd9148672e25 | 409 | delete( call ); |
klauss | 119:ee6a53069455 | 410 | |
klauss | 119:ee6a53069455 | 411 | ts->return_timeslice( cb->call_end () ); |
klauss | 0:4d17cd9c8f9d | 412 | } |
klauss | 0:4d17cd9c8f9d | 413 | } |
klauss | 119:ee6a53069455 | 414 | |
klauss | 132:05cd37f7e007 | 415 | if( already_removed ) if( debug_main or debug_invite ) vz_debug ( "[%d] Already removed from vector call", ext ); |
klauss | 82:f55d13babca0 | 416 | |
klauss | 119:ee6a53069455 | 417 | cb -> registry(); |
klauss | 119:ee6a53069455 | 418 | |
klauss | 132:05cd37f7e007 | 419 | } else if ( debug_invite or debug_main ) vz_debug ("[%d] Bye from who ?", ext ); |
klauss | 91:c2a86b1f8aaa | 420 | } |
klauss | 91:c2a86b1f8aaa | 421 | break; |
klauss | 91:c2a86b1f8aaa | 422 | |
klauss | 126:1f90756250fb | 423 | case INVITE : |
klauss | 126:1f90756250fb | 424 | { |
klauss | 126:1f90756250fb | 425 | if ( drop_invite_pkg ) |
klauss | 126:1f90756250fb | 426 | { |
klauss | 132:05cd37f7e007 | 427 | vz_debug ("[%d] Dropando invite pck - msg id :: %d", ext, data[ 0 ] ); |
klauss | 114:472502b31a12 | 428 | break; |
klauss | 114:472502b31a12 | 429 | } |
klauss | 119:ee6a53069455 | 430 | |
klauss | 63:0d95da692bb4 | 431 | invite_counter++; |
klauss | 119:ee6a53069455 | 432 | |
klauss | 132:05cd37f7e007 | 433 | if ( debug_invite ) vz_debug ("[%d] Invite request", ext ); |
klauss | 119:ee6a53069455 | 434 | |
klauss | 122:480c44b0e205 | 435 | Call_Box * cb = find_CB ( v_cb, ext ); |
klauss | 119:ee6a53069455 | 436 | |
klauss | 122:480c44b0e205 | 437 | if ( cb == NULL ) |
klauss | 122:480c44b0e205 | 438 | { |
klauss | 122:480c44b0e205 | 439 | if ( v_cb -> size () < MAX_CB_IN_A_BRANCH ) |
klauss | 122:480c44b0e205 | 440 | { |
klauss | 132:05cd37f7e007 | 441 | if ( debug_main or debug_invite ) vz_debug ( "[%d] Adding CBx", ext ); |
klauss | 122:480c44b0e205 | 442 | cb = new Call_Box ( ext, port ); |
klauss | 91:c2a86b1f8aaa | 443 | |
klauss | 122:480c44b0e205 | 444 | if ( cb == NULL ) |
klauss | 122:480c44b0e205 | 445 | { |
klauss | 91:c2a86b1f8aaa | 446 | memory_is_over = true; |
klauss | 132:05cd37f7e007 | 447 | if ( debug_memory or debug_invite ) vz_debug ("[%d] Invite allocation cb fail", ext ); |
klauss | 91:c2a86b1f8aaa | 448 | } else { |
klauss | 122:480c44b0e205 | 449 | v_cb->add ( cb ); |
klauss | 91:c2a86b1f8aaa | 450 | } |
klauss | 89:0fe315117b00 | 451 | } |
klauss | 0:4d17cd9c8f9d | 452 | } |
klauss | 119:ee6a53069455 | 453 | |
klauss | 122:480c44b0e205 | 454 | if ( cb != NULL ) |
klauss | 119:ee6a53069455 | 455 | { |
klauss | 132:05cd37f7e007 | 456 | cb -> update_invite_counter (); |
klauss | 132:05cd37f7e007 | 457 | |
klauss | 122:480c44b0e205 | 458 | cb -> invite_retry_count_reset (); |
klauss | 119:ee6a53069455 | 459 | |
klauss | 122:480c44b0e205 | 460 | cb -> set_msg_id ( data [ 0 ] ); |
klauss | 119:ee6a53069455 | 461 | |
klauss | 122:480c44b0e205 | 462 | if ( cb -> get_status () == cb_idle ) { |
klauss | 119:ee6a53069455 | 463 | cb -> call_config (); |
klauss | 132:05cd37f7e007 | 464 | if ( test_ts ) vz_debug ("TST::IDLE"); |
klauss | 119:ee6a53069455 | 465 | } else { |
klauss | 122:480c44b0e205 | 466 | data [ TIMESLICE_PLACE ] = cb -> get_timeslice (); |
klauss | 119:ee6a53069455 | 467 | |
klauss | 122:480c44b0e205 | 468 | cb -> set_invite_response_pending (); |
klauss | 126:1f90756250fb | 469 | |
klauss | 132:05cd37f7e007 | 470 | if ( test_ts ) vz_debug ("TST::%u ", data [ TIMESLICE_PLACE ]); |
klauss | 126:1f90756250fb | 471 | |
klauss | 126:1f90756250fb | 472 | send2callboxes ( build_cb_package ( ext, port, INVITE, |
klauss | 119:ee6a53069455 | 473 | ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 92:92df17f538a8 | 474 | } |
klauss | 119:ee6a53069455 | 475 | |
klauss | 121:ee02790d00b7 | 476 | invite_handler ( v_call, v_cb, ts, cb ); |
klauss | 87:679ee0d594a9 | 477 | } |
klauss | 91:c2a86b1f8aaa | 478 | } |
klauss | 126:1f90756250fb | 479 | |
klauss | 91:c2a86b1f8aaa | 480 | break; |
klauss | 120:770f00554b1e | 481 | |
klauss | 119:ee6a53069455 | 482 | case REGISTRY : { |
klauss | 63:0d95da692bb4 | 483 | registry_counter++; |
klauss | 121:ee02790d00b7 | 484 | Call_Box * cb = find_CB ( v_cb, ext ); |
klauss | 119:ee6a53069455 | 485 | |
klauss | 121:ee02790d00b7 | 486 | if ( cb == NULL ) |
klauss | 119:ee6a53069455 | 487 | { |
klauss | 119:ee6a53069455 | 488 | if( v_cb->size() < MAX_CB_IN_A_BRANCH ) |
klauss | 119:ee6a53069455 | 489 | { |
klauss | 132:05cd37f7e007 | 490 | if( debug_main ) vz_debug ("[%d] Adding Cbx", ext ); |
klauss | 91:c2a86b1f8aaa | 491 | cb = new Call_Box( ext, port ); |
klauss | 91:c2a86b1f8aaa | 492 | |
klauss | 91:c2a86b1f8aaa | 493 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 494 | memory_is_over = true; |
klauss | 132:05cd37f7e007 | 495 | if( debug_memory ) vz_debug ("[%d] Registry cb allocation fail", ext ); |
klauss | 91:c2a86b1f8aaa | 496 | } else { |
klauss | 91:c2a86b1f8aaa | 497 | v_cb->add( cb ); |
klauss | 132:05cd37f7e007 | 498 | if( debug_main ) vz_debug ("[%d] Added CBx", ext ); |
klauss | 91:c2a86b1f8aaa | 499 | } |
klauss | 87:679ee0d594a9 | 500 | } |
klauss | 0:4d17cd9c8f9d | 501 | } |
klauss | 119:ee6a53069455 | 502 | |
klauss | 132:05cd37f7e007 | 503 | if ( debug_main ) vz_debug ("[%d %d] Registered", ext, port ); |
klauss | 91:c2a86b1f8aaa | 504 | |
klauss | 126:1f90756250fb | 505 | int registry_ret = -1; |
klauss | 126:1f90756250fb | 506 | |
klauss | 126:1f90756250fb | 507 | if ( cb != NULL ) registry_ret = cb -> registry (); |
klauss | 126:1f90756250fb | 508 | |
klauss | 130:850163037da5 | 509 | if ( ( registry_ret > 0 ) and eth_status ) try_reconnect_with_eth (); |
klauss | 130:850163037da5 | 510 | |
klauss | 130:850163037da5 | 511 | /* Resetando o timer usado no wdt somente no recebimento de |
klauss | 130:850163037da5 | 512 | pacotes validos do tipo REGISTRY. |
klauss | 130:850163037da5 | 513 | */ |
klauss | 130:850163037da5 | 514 | pkg_wdt = RX_CB_IDLE; |
klauss | 91:c2a86b1f8aaa | 515 | } |
klauss | 91:c2a86b1f8aaa | 516 | break; |
klauss | 120:770f00554b1e | 517 | |
klauss | 119:ee6a53069455 | 518 | case BOOT : { |
klauss | 63:0d95da692bb4 | 519 | boot_counter++; |
klauss | 99:e80850c51106 | 520 | if( debug_boot == true ){ |
klauss | 132:05cd37f7e007 | 521 | vz_printf ("[%d %d] Boot pkg -- pkg-id %d", ext, port, data[ 0 ] ); |
klauss | 99:e80850c51106 | 522 | } |
klauss | 119:ee6a53069455 | 523 | send2callboxes( build_cb_package( ext, port, REGISTRY, |
klauss | 126:1f90756250fb | 524 | ( char * )data, data[ 0 ] bitor BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); |
klauss | 117:e9facba9db27 | 525 | } |
klauss | 117:e9facba9db27 | 526 | break; |
klauss | 117:e9facba9db27 | 527 | |
klauss | 119:ee6a53069455 | 528 | case FW : { |
klauss | 132:05cd37f7e007 | 529 | if ( debug_fw_print ) vz_printf ("[%d %d]::FW pkg::", ext, port ); |
klauss | 126:1f90756250fb | 530 | fw_cbx_pkg ( ext, ( char *) buffer ); |
klauss | 99:e80850c51106 | 531 | } |
klauss | 99:e80850c51106 | 532 | break; |
klauss | 91:c2a86b1f8aaa | 533 | |
klauss | 119:ee6a53069455 | 534 | case BOOTLOADER_CBX : { |
klauss | 117:e9facba9db27 | 535 | uint16_t bl_cnt2 = 0; |
klauss | 117:e9facba9db27 | 536 | if (debug_bootloader) { |
klauss | 117:e9facba9db27 | 537 | pc.printf("\r\npacote CBX->HDR {"); |
klauss | 117:e9facba9db27 | 538 | for (bl_cnt2 = 0;bl_cnt2 < BL_SIZE + 1;bl_cnt2++) { |
klauss | 117:e9facba9db27 | 539 | if ((bl_cnt2 % 30) == 0) { |
klauss | 117:e9facba9db27 | 540 | pc.printf("\r\n "); |
klauss | 117:e9facba9db27 | 541 | pc.printf(hex16(bl_cnt2)); |
klauss | 117:e9facba9db27 | 542 | pc.printf(" : "); |
klauss | 117:e9facba9db27 | 543 | } |
klauss | 117:e9facba9db27 | 544 | pc.printf(hex8(data[bl_cnt2])); |
klauss | 117:e9facba9db27 | 545 | pc.printf(", "); |
klauss | 117:e9facba9db27 | 546 | } |
klauss | 117:e9facba9db27 | 547 | pc.printf("\r\n}"); |
klauss | 117:e9facba9db27 | 548 | } |
klauss | 67:cdedc64d9921 | 549 | bootloader_cbx_counter++; |
klauss | 117:e9facba9db27 | 550 | bl_send_buffer[0] = (char)(ext >> 8); |
klauss | 117:e9facba9db27 | 551 | bl_send_buffer[1] = (char)(ext & 0xff); |
klauss | 117:e9facba9db27 | 552 | for (bl_cnt2 = 0; bl_cnt2 < BL_SIZE; bl_cnt2++) { |
klauss | 117:e9facba9db27 | 553 | bl_send_buffer[bl_cnt2 + 2] = data[bl_cnt2 + 1]; |
klauss | 117:e9facba9db27 | 554 | } |
klauss | 117:e9facba9db27 | 555 | if (debug_bootloader) { |
klauss | 117:e9facba9db27 | 556 | pc.printf("\r\npacote HDR->SRV {"); |
klauss | 117:e9facba9db27 | 557 | for (bl_cnt2 = 0;bl_cnt2 < UDP_BL_SIZE;bl_cnt2++) { |
klauss | 117:e9facba9db27 | 558 | if ((bl_cnt2 % 30) == 0) { |
klauss | 117:e9facba9db27 | 559 | pc.printf("\r\n "); |
klauss | 117:e9facba9db27 | 560 | pc.printf(hex16(bl_cnt2)); |
klauss | 117:e9facba9db27 | 561 | pc.printf(" : "); |
klauss | 117:e9facba9db27 | 562 | } |
klauss | 117:e9facba9db27 | 563 | pc.printf(hex8(bl_send_buffer[bl_cnt2])); |
klauss | 117:e9facba9db27 | 564 | pc.printf(", "); |
klauss | 117:e9facba9db27 | 565 | } |
klauss | 117:e9facba9db27 | 566 | pc.printf("\r\n}"); |
klauss | 117:e9facba9db27 | 567 | } |
klauss | 132:05cd37f7e007 | 568 | int udp_bl_client_ret = udp_bl_client.sendTo ( udp_bl_server, bl_send_buffer, UDP_BL_SIZE ); |
klauss | 132:05cd37f7e007 | 569 | if ( udp_bl_client_ret not_eq UDP_BL_SIZE ) |
klauss | 132:05cd37f7e007 | 570 | { |
klauss | 132:05cd37f7e007 | 571 | reconnect_bl (); |
klauss | 132:05cd37f7e007 | 572 | miss_bl_udp_send_pkg ++; |
klauss | 132:05cd37f7e007 | 573 | if ( debug_reconnect ) vz_printf ( "[%d] Reconnect BL - %d", ext, udp_bl_client_ret ); |
klauss | 132:05cd37f7e007 | 574 | } |
klauss | 91:c2a86b1f8aaa | 575 | } |
klauss | 91:c2a86b1f8aaa | 576 | break; |
klauss | 91:c2a86b1f8aaa | 577 | |
klauss | 119:ee6a53069455 | 578 | case PROMPT : { |
klauss | 129:d73538fbc017 | 579 | Call_Box * cb = find_CB ( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 580 | |
klauss | 91:c2a86b1f8aaa | 581 | if( cb == NULL ) { |
klauss | 119:ee6a53069455 | 582 | if( v_cb->size() < MAX_CB_IN_A_BRANCH ) { |
klauss | 132:05cd37f7e007 | 583 | if( debug_main ) vz_debug ("[%d] Adding Cbx", ext ); |
klauss | 119:ee6a53069455 | 584 | cb = new Call_Box( ext, port ); |
klauss | 119:ee6a53069455 | 585 | if( cb == NULL ){ |
klauss | 119:ee6a53069455 | 586 | memory_is_over = true; |
klauss | 119:ee6a53069455 | 587 | }else{ |
klauss | 119:ee6a53069455 | 588 | v_cb->add( cb ); |
klauss | 132:05cd37f7e007 | 589 | if( debug_main ) vz_debug ("[%d] Added CBx", ext ); |
klauss | 119:ee6a53069455 | 590 | } |
klauss | 87:679ee0d594a9 | 591 | } |
klauss | 48:195c97f12e8e | 592 | } |
klauss | 91:c2a86b1f8aaa | 593 | |
klauss | 126:1f90756250fb | 594 | if( cb!= NULL ) cb -> registry (); |
klauss | 91:c2a86b1f8aaa | 595 | |
klauss | 126:1f90756250fb | 596 | // if( ( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ) or xstrmatch ( ( uint8_t * )data, ( uint8_t * )"pong" ) ) |
klauss | 126:1f90756250fb | 597 | if ( ( strncasecmp ( ( const char * )data, "ping", 4 ) == 0 ) or ( strncasecmp ( ( const char * )data, "pong", 4 ) == 0 ) ) |
klauss | 126:1f90756250fb | 598 | { |
klauss | 132:05cd37f7e007 | 599 | if( debug_ping ) vz_printf ( "[%d %d] Prompt pkg :: Ping", ext, port ); |
klauss | 126:1f90756250fb | 600 | } |
klauss | 126:1f90756250fb | 601 | else |
klauss | 126:1f90756250fb | 602 | { |
klauss | 78:1353744f01e1 | 603 | prompt_counter++; |
klauss | 132:05cd37f7e007 | 604 | vz_printf ( "[%i, %i] Prompt pkg::", ext, port ); |
klauss | 91:c2a86b1f8aaa | 605 | for( register uint8_t i = 0; i < 32; i++ ) { |
klauss | 100:09a23fcd3bdf | 606 | if( debug_uart3 ) pc.printf("%c", data[ i ] ); |
klauss | 100:09a23fcd3bdf | 607 | if( i == 15 ) if( debug_uart3 ) pc.printf( "\r\n" ); |
klauss | 78:1353744f01e1 | 608 | } |
klauss | 100:09a23fcd3bdf | 609 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 91:c2a86b1f8aaa | 610 | |
klauss | 114:472502b31a12 | 611 | if( tcp_session ) { |
klauss | 119:ee6a53069455 | 612 | char aux[ CB_BUFFER_SIZE + 3 ]; |
klauss | 119:ee6a53069455 | 613 | strncpy( aux, (char * )data, CB_BUFFER_SIZE ); |
klauss | 78:1353744f01e1 | 614 | strcat( aux, "\n\r\0" ); |
klauss | 78:1353744f01e1 | 615 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 78:1353744f01e1 | 616 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 78:1353744f01e1 | 617 | } |
klauss | 48:195c97f12e8e | 618 | } |
klauss | 91:c2a86b1f8aaa | 619 | } |
klauss | 91:c2a86b1f8aaa | 620 | break; |
klauss | 120:770f00554b1e | 621 | |
klauss | 119:ee6a53069455 | 622 | case AUDIO : { |
klauss | 63:0d95da692bb4 | 623 | audio_counter++; |
klauss | 119:ee6a53069455 | 624 | if ( received_audio_from_cb ) { |
klauss | 132:05cd37f7e007 | 625 | vz_debug ("[%d] audio pkg", ext ); |
klauss | 119:ee6a53069455 | 626 | } |
klauss | 119:ee6a53069455 | 627 | |
klauss | 126:1f90756250fb | 628 | VZ_call * call = find_Call ( v_call, ext ); |
klauss | 126:1f90756250fb | 629 | if ( call != NULL ) |
klauss | 126:1f90756250fb | 630 | { |
klauss | 126:1f90756250fb | 631 | if ( drop_rtp_from_cbx_pkg ) |
klauss | 126:1f90756250fb | 632 | { |
klauss | 114:472502b31a12 | 633 | led2 = !led2; |
klauss | 114:472502b31a12 | 634 | break; |
klauss | 119:ee6a53069455 | 635 | } else { |
klauss | 126:1f90756250fb | 636 | char * pkg = call -> build_eth_package ( data + 2 ); |
klauss | 126:1f90756250fb | 637 | call -> send_message ( pkg ); |
klauss | 132:05cd37f7e007 | 638 | call -> cbx_pkg_idle_timer_reset (); |
klauss | 114:472502b31a12 | 639 | } |
klauss | 119:ee6a53069455 | 640 | } |
klauss | 119:ee6a53069455 | 641 | |
klauss | 132:05cd37f7e007 | 642 | Call_Box * cb = find_CB ( v_cb, ext ); |
klauss | 126:1f90756250fb | 643 | if ( cb != NULL ) |
klauss | 126:1f90756250fb | 644 | { |
klauss | 132:05cd37f7e007 | 645 | if ( cb -> get_invite_response () == false ) |
klauss | 126:1f90756250fb | 646 | { |
klauss | 126:1f90756250fb | 647 | cb -> set_invite_response_ok (); |
klauss | 126:1f90756250fb | 648 | cb -> invite_retry_count_reset (); |
klauss | 126:1f90756250fb | 649 | } |
klauss | 126:1f90756250fb | 650 | } else { |
klauss | 132:05cd37f7e007 | 651 | if ( debug_main ) vz_debug ("[%d] received missed package", ext ); |
klauss | 0:4d17cd9c8f9d | 652 | } |
klauss | 91:c2a86b1f8aaa | 653 | } |
klauss | 91:c2a86b1f8aaa | 654 | break; |
klauss | 114:472502b31a12 | 655 | }// fim switch |
klauss | 105:a930035b6556 | 656 | |
klauss | 120:770f00554b1e | 657 | // rajada |
klauss | 120:770f00554b1e | 658 | if( invite_retry_timer.read_ms() >= 20 ) |
klauss | 120:770f00554b1e | 659 | { |
klauss | 120:770f00554b1e | 660 | invite_ack_to_cb_handler ( v_cb, v_call ); |
klauss | 112:6ae726539ab9 | 661 | |
klauss | 120:770f00554b1e | 662 | invite_retry_timer.reset(); |
klauss | 120:770f00554b1e | 663 | } |
klauss | 120:770f00554b1e | 664 | |
klauss | 120:770f00554b1e | 665 | check_audio_from_ast ( v_cb, v_call ); |
klauss | 99:e80850c51106 | 666 | |
klauss | 120:770f00554b1e | 667 | wake_up_or_refresh_handler ( v_cb ); |
klauss | 117:e9facba9db27 | 668 | |
klauss | 120:770f00554b1e | 669 | check_sip_messages_from_ast ( v_cb, v_call ); |
klauss | 119:ee6a53069455 | 670 | |
klauss | 81:3656f00ab3db | 671 | /* Verifica andamento de ligações para eventualmente encerra-las por timeout */ |
klauss | 119:ee6a53069455 | 672 | call_manager( v_call, v_cb, ts ); |
klauss | 91:c2a86b1f8aaa | 673 | |
klauss | 81:3656f00ab3db | 674 | invite_handler( v_call, v_cb, ts, NULL ); |
klauss | 114:472502b31a12 | 675 | |
klauss | 120:770f00554b1e | 676 | check_for_runaways_ts ( v_cb, ts ); |
klauss | 112:6ae726539ab9 | 677 | |
klauss | 120:770f00554b1e | 678 | check_for_unwanted_rtp_ports ( v_cb ); |
klauss | 120:770f00554b1e | 679 | |
klauss | 72:895ca792c647 | 680 | tx_buffer_ring_buffer_handler(); |
klauss | 91:c2a86b1f8aaa | 681 | |
klauss | 119:ee6a53069455 | 682 | type = DO_NOTHING; |
klauss | 114:472502b31a12 | 683 | |
klauss | 81:3656f00ab3db | 684 | if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 114:472502b31a12 | 685 | |
klauss | 91:c2a86b1f8aaa | 686 | if( wdt_timer.read() >= 1 ) { |
klauss | 132:05cd37f7e007 | 687 | if ( -1 == wdt_update () ) vz_debug ("Erro!!!!!"); |
klauss | 81:3656f00ab3db | 688 | wdt_timer.reset(); |
klauss | 114:472502b31a12 | 689 | } |
klauss | 114:472502b31a12 | 690 | |
klauss | 120:770f00554b1e | 691 | if( debug_wdt ) |
klauss | 120:770f00554b1e | 692 | { |
klauss | 120:770f00554b1e | 693 | show_wdt_status (); |
klauss | 132:05cd37f7e007 | 694 | debug_wdt = false; |
klauss | 114:472502b31a12 | 695 | } |
klauss | 123:1d395b5a4cad | 696 | |
klauss | 123:1d395b5a4cad | 697 | update_all_cb_timer ( v_cb ); |
klauss | 123:1d395b5a4cad | 698 | |
klauss | 124:c1b6c893e1c3 | 699 | if ( !dont_say_hello_again ) send_hello_to_cbx (); |
klauss | 124:c1b6c893e1c3 | 700 | |
klauss | 128:3ae1c74773a8 | 701 | /* Verificacao da fonte de alimentacao */ |
klauss | 132:05cd37f7e007 | 702 | if ( power_source_timer.read () > 1 ) |
klauss | 128:3ae1c74773a8 | 703 | { |
klauss | 132:05cd37f7e007 | 704 | check_power_source (); |
klauss | 128:3ae1c74773a8 | 705 | } |
klauss | 132:05cd37f7e007 | 706 | |
klauss | 132:05cd37f7e007 | 707 | %: ifdef MODE_TEST |
klauss | 132:05cd37f7e007 | 708 | wdt.kick(); |
klauss | 132:05cd37f7e007 | 709 | %: endif |
klauss | 120:770f00554b1e | 710 | }// fim while |
klauss | 120:770f00554b1e | 711 | }// fim main \o/ |