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