![](/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@87:679ee0d594a9, 2015-01-06 (annotated)
- Committer:
- klauss
- Date:
- Tue Jan 06 16:37:03 2015 +0000
- Revision:
- 87:679ee0d594a9
- Parent:
- 86:bf7b0d4c3232
- Child:
- 89:0fe315117b00
rx buffer resized
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 74:81c47fff88a5 | 1 | #include "telemetry.h" |
klauss | 74:81c47fff88a5 | 2 | #include "eth.h" |
klauss | 74:81c47fff88a5 | 3 | #include "bits.h" |
klauss | 74:81c47fff88a5 | 4 | #include "UART3Interrupt.h" // for RXBuffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 74:81c47fff88a5 | 5 | #include "utils.h" |
klauss | 74:81c47fff88a5 | 6 | #include "parallelcpld.h" |
klauss | 74:81c47fff88a5 | 7 | #include "debug.h" |
klauss | 74:81c47fff88a5 | 8 | #include "flood.h" |
klauss | 74:81c47fff88a5 | 9 | #include "bootloader_cbx.h" |
klauss | 74:81c47fff88a5 | 10 | #include "call_manager.h" |
klauss | 74:81c47fff88a5 | 11 | #include "call_box_manager.h" |
klauss | 74:81c47fff88a5 | 12 | #include "sip_manager.h" |
klauss | 74:81c47fff88a5 | 13 | #include "shared_variables.h" |
klauss | 74:81c47fff88a5 | 14 | #include "prompt.h" |
klauss | 0:4d17cd9c8f9d | 15 | #include "configs.h" |
klauss | 87:679ee0d594a9 | 16 | #include "sdram.h" |
klauss | 0:4d17cd9c8f9d | 17 | |
klauss | 87:679ee0d594a9 | 18 | volatile u16_t lpc_low_level_input_counter = 0; |
klauss | 85:b6f2dc1d0f4f | 19 | |
klauss | 0:4d17cd9c8f9d | 20 | int main(){ |
klauss | 81:3656f00ab3db | 21 | init_wdt(); |
klauss | 79:9bc12aa305a9 | 22 | |
klauss | 81:3656f00ab3db | 23 | config_lpc(); |
klauss | 79:9bc12aa305a9 | 24 | |
klauss | 0:4d17cd9c8f9d | 25 | start_cpld(); |
klauss | 79:9bc12aa305a9 | 26 | |
klauss | 87:679ee0d594a9 | 27 | if( sdram_init() == 1 ) |
klauss | 87:679ee0d594a9 | 28 | { |
klauss | 87:679ee0d594a9 | 29 | send_msg("******* Failed to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 30 | return 1; |
klauss | 87:679ee0d594a9 | 31 | } |
klauss | 87:679ee0d594a9 | 32 | else |
klauss | 87:679ee0d594a9 | 33 | { |
klauss | 87:679ee0d594a9 | 34 | send_msg("******* Success to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 35 | } |
klauss | 87:679ee0d594a9 | 36 | |
klauss | 43:455522f98de5 | 37 | init_fsystem(); |
klauss | 43:455522f98de5 | 38 | |
klauss | 78:1353744f01e1 | 39 | short int eth_status = __init_eth__(); |
klauss | 8:e3bfe62a477e | 40 | if( eth_status ){ |
klauss | 87:679ee0d594a9 | 41 | send_msg("******* Cannot connect to eth *******"); |
klauss | 43:455522f98de5 | 42 | }else{ |
klauss | 81:3656f00ab3db | 43 | send_msg("******* Connection eth - ok *******"); |
klauss | 78:1353744f01e1 | 44 | init_prompt_eth(); |
klauss | 82:f55d13babca0 | 45 | init_external_wdt() |
klauss | 8:e3bfe62a477e | 46 | } |
klauss | 78:1353744f01e1 | 47 | |
klauss | 78:1353744f01e1 | 48 | Timer sync_timer, led_sync_timer; |
klauss | 78:1353744f01e1 | 49 | sync_timer.start(), led_sync_timer.start(); |
klauss | 0:4d17cd9c8f9d | 50 | |
klauss | 0:4d17cd9c8f9d | 51 | /* representa ramal do call box */ |
klauss | 0:4d17cd9c8f9d | 52 | int ext = 0; |
klauss | 0:4d17cd9c8f9d | 53 | |
klauss | 0:4d17cd9c8f9d | 54 | /* representa porta do call box */ |
klauss | 78:1353744f01e1 | 55 | int port = 0; |
klauss | 78:1353744f01e1 | 56 | |
klauss | 0:4d17cd9c8f9d | 57 | /* buffer para onde se copia os dados vindos do cb para tratameno interno */ |
klauss | 0:4d17cd9c8f9d | 58 | uint8_t buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 59 | |
klauss | 0:4d17cd9c8f9d | 60 | /* buffer de escrita do pacote de saida que sera enviado pro cb / servidor */ |
klauss | 0:4d17cd9c8f9d | 61 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 62 | |
klauss | 0:4d17cd9c8f9d | 63 | /* ponteiro que aponta para os dados vindo do CPLD */ |
klauss | 0:4d17cd9c8f9d | 64 | uint8_t * buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 0:4d17cd9c8f9d | 65 | |
klauss | 62:07e5bdc9f8f7 | 66 | /* Armazena o ultimo pacote recebido dos CBx */ |
klauss | 62:07e5bdc9f8f7 | 67 | uint8_t cb_rx_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 62:07e5bdc9f8f7 | 68 | |
klauss | 0:4d17cd9c8f9d | 69 | /* referencia para os dados contidos no pacote, sem o header */ |
klauss | 0:4d17cd9c8f9d | 70 | uint8_t * data = NULL; |
klauss | 0:4d17cd9c8f9d | 71 | |
klauss | 0:4d17cd9c8f9d | 72 | /* gerencia o tipo do pacote para providenciar tratamento adequado */ |
klauss | 0:4d17cd9c8f9d | 73 | volatile uint8_t type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 74 | |
klauss | 87:679ee0d594a9 | 75 | /* representa a lista dos Call Boxes atualmente recfonhecidos pela cabeceira */ |
klauss | 0:4d17cd9c8f9d | 76 | Vector * v_cb = new Vector(); |
klauss | 0:4d17cd9c8f9d | 77 | |
klauss | 0:4d17cd9c8f9d | 78 | /* representa a lista de ligacoes ativas na cabeceira */ |
klauss | 0:4d17cd9c8f9d | 79 | Vector * v_call = new Vector(); |
klauss | 0:4d17cd9c8f9d | 80 | |
klauss | 0:4d17cd9c8f9d | 81 | /* gerencia a distribuicao de timeslice para os call boxes */ |
klauss | 0:4d17cd9c8f9d | 82 | Timeslice * ts = new Timeslice(); |
klauss | 87:679ee0d594a9 | 83 | if( ts == NULL ) memory_is_over = true; |
klauss | 78:1353744f01e1 | 84 | |
klauss | 81:3656f00ab3db | 85 | /* instancia o vetor de call boxes // calls */ |
klauss | 0:4d17cd9c8f9d | 86 | if( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 87 | while( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 88 | Vector * v_cb = new Vector(); |
klauss | 78:1353744f01e1 | 89 | if( sync_timer.read() > 5 ){ |
klauss | 48:195c97f12e8e | 90 | send_msg("Erro ao alocar o vetor de CBx"); |
klauss | 78:1353744f01e1 | 91 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 92 | } |
klauss | 0:4d17cd9c8f9d | 93 | } |
klauss | 0:4d17cd9c8f9d | 94 | }else if( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 95 | while( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 96 | Vector * v_call = new Vector(); |
klauss | 78:1353744f01e1 | 97 | if( sync_timer.read() > 5 ){ |
klauss | 48:195c97f12e8e | 98 | send_msg("Erro ao alocar o vetor de Calls"); |
klauss | 78:1353744f01e1 | 99 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 100 | } |
klauss | 0:4d17cd9c8f9d | 101 | } |
klauss | 0:4d17cd9c8f9d | 102 | } |
klauss | 63:0d95da692bb4 | 103 | |
klauss | 87:679ee0d594a9 | 104 | if( v_cb == NULL ) memory_is_over = true; |
klauss | 87:679ee0d594a9 | 105 | if( v_call == NULL ) memory_is_over = true; |
klauss | 87:679ee0d594a9 | 106 | |
klauss | 63:0d95da692bb4 | 107 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 63:0d95da692bb4 | 108 | cb_rx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 109 | cb_tx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 110 | } |
klauss | 63:0d95da692bb4 | 111 | |
klauss | 0:4d17cd9c8f9d | 112 | reset_leds(); |
klauss | 78:1353744f01e1 | 113 | |
klauss | 33:735fd60e96d8 | 114 | udp_timer.start(); |
klauss | 68:b54993674190 | 115 | |
klauss | 68:b54993674190 | 116 | init_telemetry_handler(); |
klauss | 68:b54993674190 | 117 | |
klauss | 81:3656f00ab3db | 118 | init_ranges(); |
klauss | 81:3656f00ab3db | 119 | |
klauss | 80:61d61c9eb75c | 120 | init_refresh(); |
klauss | 80:61d61c9eb75c | 121 | |
klauss | 78:1353744f01e1 | 122 | init_aging(); |
klauss | 78:1353744f01e1 | 123 | |
klauss | 81:3656f00ab3db | 124 | //init_invite_pgk_retry_manager(); |
klauss | 81:3656f00ab3db | 125 | |
klauss | 81:3656f00ab3db | 126 | //void init_bye_pgk_retry_manager(); |
klauss | 62:07e5bdc9f8f7 | 127 | static uint8_t count = 0; |
klauss | 78:1353744f01e1 | 128 | |
klauss | 78:1353744f01e1 | 129 | short int bl_ret = init_bl_handler(); |
klauss | 67:cdedc64d9921 | 130 | if( dbl ) send_msg("Valor de retorno do bl_habdler = %d", bl_ret ); |
klauss | 67:cdedc64d9921 | 131 | |
klauss | 78:1353744f01e1 | 132 | uint8_t max_registered_cbx = 0; |
klauss | 78:1353744f01e1 | 133 | |
klauss | 81:3656f00ab3db | 134 | bool wake_all = false; |
klauss | 81:3656f00ab3db | 135 | |
klauss | 81:3656f00ab3db | 136 | uint16_t pkg_wdt = RX_CB_IDLE; |
klauss | 81:3656f00ab3db | 137 | uint16_t eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 68:b54993674190 | 138 | |
klauss | 83:b8a1d8fdeaeb | 139 | uint32_t uptime = 0; |
klauss | 83:b8a1d8fdeaeb | 140 | |
klauss | 68:b54993674190 | 141 | send_msg("Ready"); |
klauss | 68:b54993674190 | 142 | |
klauss | 86:bf7b0d4c3232 | 143 | bool regystry_test = false; |
klauss | 86:bf7b0d4c3232 | 144 | |
klauss | 86:bf7b0d4c3232 | 145 | static int next_value = 5010; |
klauss | 86:bf7b0d4c3232 | 146 | static int nex_test_registry = next_value; |
klauss | 86:bf7b0d4c3232 | 147 | |
klauss | 86:bf7b0d4c3232 | 148 | { |
klauss | 86:bf7b0d4c3232 | 149 | char s[ 32 ]; |
klauss | 86:bf7b0d4c3232 | 150 | mbed_mac_address( s ); |
klauss | 86:bf7b0d4c3232 | 151 | send_msg( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] ); |
klauss | 86:bf7b0d4c3232 | 152 | } |
klauss | 86:bf7b0d4c3232 | 153 | |
klauss | 87:679ee0d594a9 | 154 | //#define NUM_SOCK 50 |
klauss | 87:679ee0d594a9 | 155 | //#define TEST_SERVER_IP "192.168.120.7" |
klauss | 87:679ee0d594a9 | 156 | //#define ETH_MSG_SIZE 1600 |
klauss | 86:bf7b0d4c3232 | 157 | |
klauss | 86:bf7b0d4c3232 | 158 | //UDPSocket sock[ NUM_SOCK ]; |
klauss | 86:bf7b0d4c3232 | 159 | //Endpoint server[ NUM_SOCK ]; |
klauss | 86:bf7b0d4c3232 | 160 | |
klauss | 86:bf7b0d4c3232 | 161 | /* |
klauss | 86:bf7b0d4c3232 | 162 | for( register int i = 0; i < NUM_SOCK; i++ ) |
klauss | 86:bf7b0d4c3232 | 163 | { |
klauss | 86:bf7b0d4c3232 | 164 | int ref = ( i + 10000 ); |
klauss | 86:bf7b0d4c3232 | 165 | server[ i ].set_address( TEST_SERVER_IP, ref ); |
klauss | 86:bf7b0d4c3232 | 166 | sock[ i ].set_blocking( false, 0 ); |
klauss | 86:bf7b0d4c3232 | 167 | int bind_ret = sock[ i ].bind( ref ); |
klauss | 86:bf7b0d4c3232 | 168 | send_msg("Sock %2d ( %d )%s", i, ref, ( bind_ret ) ? "Fail" : "Ok" ); |
klauss | 86:bf7b0d4c3232 | 169 | } |
klauss | 86:bf7b0d4c3232 | 170 | */ |
klauss | 78:1353744f01e1 | 171 | /*------------------------------------------ main loop ---------------------------------------------------------------*/ |
Cola | 21:0bd688722e81 | 172 | while( true ){ |
klauss | 78:1353744f01e1 | 173 | if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size(); |
klauss | 78:1353744f01e1 | 174 | |
klauss | 78:1353744f01e1 | 175 | if( sync_timer.read() > 5 ){ |
klauss | 78:1353744f01e1 | 176 | sync_timer.reset(); |
klauss | 78:1353744f01e1 | 177 | |
klauss | 78:1353744f01e1 | 178 | if( debug_cks == true ){ |
klauss | 81:3656f00ab3db | 179 | pcks_s = true; |
klauss | 78:1353744f01e1 | 180 | } |
klauss | 78:1353744f01e1 | 181 | |
klauss | 78:1353744f01e1 | 182 | if( debug_alive == true ){ |
klauss | 81:3656f00ab3db | 183 | pshowcb = true; |
klauss | 78:1353744f01e1 | 184 | } |
klauss | 81:3656f00ab3db | 185 | |
klauss | 81:3656f00ab3db | 186 | if( !( ++count % 15 ) ){ |
klauss | 78:1353744f01e1 | 187 | if( eth_status ){ |
klauss | 78:1353744f01e1 | 188 | eth_status = __init_eth__(); |
klauss | 78:1353744f01e1 | 189 | if( eth_status ){ |
klauss | 78:1353744f01e1 | 190 | if( debug_main ) debug_msg("Cannot connect to eth"); |
klauss | 78:1353744f01e1 | 191 | }else{ |
klauss | 78:1353744f01e1 | 192 | if( debug_main ) debug_msg("Connection eth - ok"); |
klauss | 78:1353744f01e1 | 193 | init_prompt_eth(); |
klauss | 82:f55d13babca0 | 194 | init_external_wdt() |
klauss | 78:1353744f01e1 | 195 | } |
klauss | 78:1353744f01e1 | 196 | } |
klauss | 78:1353744f01e1 | 197 | } |
klauss | 81:3656f00ab3db | 198 | //35 sec. |
klauss | 81:3656f00ab3db | 199 | if( ( count > 7 ) && ( wake_all == false ) ){ |
klauss | 81:3656f00ab3db | 200 | wake_all = true; |
klauss | 78:1353744f01e1 | 201 | if( debug_wake == true ) send_msg( "Time to wake" ); |
klauss | 78:1353744f01e1 | 202 | } |
klauss | 78:1353744f01e1 | 203 | |
klauss | 81:3656f00ab3db | 204 | if( wake_all ) if( v_call->size() == 0 ) wake_all_up( v_cb, buffer, write_buffer ); |
klauss | 78:1353744f01e1 | 205 | } |
klauss | 78:1353744f01e1 | 206 | |
klauss | 68:b54993674190 | 207 | //FIXMEj colocar uma condicao aqui caso necessario pra nao comprometer ligacoes ... |
klauss | 35:96885a7931f0 | 208 | prompt_process( NULL ); |
klauss | 63:0d95da692bb4 | 209 | |
klauss | 63:0d95da692bb4 | 210 | if( r_stats ){ |
klauss | 63:0d95da692bb4 | 211 | boot_counter = 0; |
klauss | 63:0d95da692bb4 | 212 | registry_counter = 0; |
klauss | 63:0d95da692bb4 | 213 | invite_counter = 0; |
klauss | 63:0d95da692bb4 | 214 | audio_counter = 0; |
klauss | 63:0d95da692bb4 | 215 | telemetry_counter = 0; |
klauss | 63:0d95da692bb4 | 216 | cb_bye_counter = 0; |
klauss | 63:0d95da692bb4 | 217 | prompt_counter = 0; |
klauss | 63:0d95da692bb4 | 218 | flood_counter = 0; |
klauss | 67:cdedc64d9921 | 219 | bootloader_cbx_counter = 0; |
klauss | 63:0d95da692bb4 | 220 | r_stats = false; |
klauss | 63:0d95da692bb4 | 221 | stats = true; |
klauss | 63:0d95da692bb4 | 222 | } |
klauss | 81:3656f00ab3db | 223 | |
klauss | 63:0d95da692bb4 | 224 | if( stats ){ |
klauss | 63:0d95da692bb4 | 225 | char str[ 200 ]; |
klauss | 81:3656f00ab3db | 226 | snprintf( str, 200, "\n\rReceived Pkgs::\n\r Boot :: %u\n\r Registry :: %u\n\r Ivite :: %u\n\r Audio :: %u\n\r Telemetry :: %u\n\r Cb_bye :: %u\n\r Prompt :: %u\n\r Flood :: %u\n\r Bootloader_cbx :: %u\n\r", |
klauss | 67:cdedc64d9921 | 227 | boot_counter, registry_counter, invite_counter, audio_counter, telemetry_counter, cb_bye_counter, prompt_counter, flood_counter, bootloader_cbx_counter ); |
klauss | 63:0d95da692bb4 | 228 | send_msg( str ); |
klauss | 63:0d95da692bb4 | 229 | stats =false; |
klauss | 63:0d95da692bb4 | 230 | } |
klauss | 63:0d95da692bb4 | 231 | |
klauss | 62:07e5bdc9f8f7 | 232 | if( list ){ |
klauss | 78:1353744f01e1 | 233 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 78:1353744f01e1 | 234 | |
klauss | 78:1353744f01e1 | 235 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 78:1353744f01e1 | 236 | |
klauss | 78:1353744f01e1 | 237 | if( min_ext % 2 ) missed_cb++; |
klauss | 78:1353744f01e1 | 238 | |
klauss | 78:1353744f01e1 | 239 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 78:1353744f01e1 | 240 | |
klauss | 78:1353744f01e1 | 241 | send_msg("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, ts->remain_timeslices(), v_call->size() ); |
klauss | 78:1353744f01e1 | 242 | if( v_cb->size() == 1 ){ |
klauss | 78:1353744f01e1 | 243 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 78:1353744f01e1 | 244 | }else if( v_cb->size() > 1 ){ |
klauss | 62:07e5bdc9f8f7 | 245 | char str[ 1024 ]; |
klauss | 78:1353744f01e1 | 246 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 62:07e5bdc9f8f7 | 247 | register int i = 0; |
klauss | 62:07e5bdc9f8f7 | 248 | for( ; i < v_cb->size(); i++ ){ |
klauss | 78:1353744f01e1 | 249 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 62:07e5bdc9f8f7 | 250 | } |
klauss | 62:07e5bdc9f8f7 | 251 | |
klauss | 62:07e5bdc9f8f7 | 252 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 62:07e5bdc9f8f7 | 253 | |
klauss | 62:07e5bdc9f8f7 | 254 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 255 | strcpy( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 256 | for( i = 0; i < v_cb->size() - 1; i++ ){ |
klauss | 62:07e5bdc9f8f7 | 257 | sprintf( aux, "%i, ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 258 | strcat( str, aux ); |
klauss | 78:1353744f01e1 | 259 | if( ( i != 0 ) && !( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 260 | } |
klauss | 62:07e5bdc9f8f7 | 261 | sprintf( aux, "%i ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 262 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 263 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 264 | } |
klauss | 62:07e5bdc9f8f7 | 265 | list = false; |
klauss | 62:07e5bdc9f8f7 | 266 | } |
klauss | 62:07e5bdc9f8f7 | 267 | |
klauss | 81:3656f00ab3db | 268 | if( long_list ){ |
klauss | 81:3656f00ab3db | 269 | //FIXME implementar um algoritmo que me mostre o timeout de cada cbx do lado da linha, desse. |
klauss | 85:b6f2dc1d0f4f | 270 | /* |
klauss | 81:3656f00ab3db | 271 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 81:3656f00ab3db | 272 | |
klauss | 81:3656f00ab3db | 273 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 81:3656f00ab3db | 274 | |
klauss | 81:3656f00ab3db | 275 | if( min_ext % 2 ) missed_cb++; |
klauss | 81:3656f00ab3db | 276 | |
klauss | 81:3656f00ab3db | 277 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 81:3656f00ab3db | 278 | |
klauss | 81:3656f00ab3db | 279 | send_msg("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, ts->remain_timeslices(), v_call->size() ); |
klauss | 81:3656f00ab3db | 280 | if( v_cb->size() == 1 ){ |
klauss | 81:3656f00ab3db | 281 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 81:3656f00ab3db | 282 | }else if( v_cb->size() > 1 ){ |
klauss | 81:3656f00ab3db | 283 | char str[ 1024 ]; |
klauss | 81:3656f00ab3db | 284 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 81:3656f00ab3db | 285 | register int i = 0; |
klauss | 81:3656f00ab3db | 286 | for( ; i < ( v_cb->size() * 2 ); i += 2 ){ |
klauss | 81:3656f00ab3db | 287 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 81:3656f00ab3db | 288 | ext_list[ i + 1 ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_elapsed_time(); |
klauss | 81:3656f00ab3db | 289 | } |
klauss | 81:3656f00ab3db | 290 | |
klauss | 81:3656f00ab3db | 291 | qsort( ext_list, v_cb->size(), sizeof( int ) * 2, ls_comp ); |
Cola | 24:270b436a1bb0 | 292 | |
klauss | 81:3656f00ab3db | 293 | char aux[ 16 ]; |
klauss | 81:3656f00ab3db | 294 | strcpy( str, "\r\n> " ); |
klauss | 81:3656f00ab3db | 295 | for( i = 0; i < ( v_cb->size() * 2 ) - 2; i++ ){ |
klauss | 81:3656f00ab3db | 296 | sprintf( aux, "%i - %i,", ext_list[ i ], ext_list[ i + 1 ] ); |
klauss | 81:3656f00ab3db | 297 | strcat( str, aux ); |
klauss | 81:3656f00ab3db | 298 | strcat( str, "\r\n> " ); |
klauss | 81:3656f00ab3db | 299 | } |
klauss | 81:3656f00ab3db | 300 | sprintf( aux, "%i - %i,", ext_list[ i ], ext_list[ i + 1 ] ); |
klauss | 81:3656f00ab3db | 301 | strcat( str, aux ); |
klauss | 81:3656f00ab3db | 302 | send_msg( "%s", str ); |
klauss | 81:3656f00ab3db | 303 | } |
klauss | 85:b6f2dc1d0f4f | 304 | */ |
klauss | 85:b6f2dc1d0f4f | 305 | long_list = false; |
klauss | 52:12930cef17c4 | 306 | } |
klauss | 52:12930cef17c4 | 307 | |
klauss | 78:1353744f01e1 | 308 | if( pshowcb == true ){ |
klauss | 78:1353744f01e1 | 309 | send_msg("Registered %d ( of %d ) CBx ( %d - %d ) -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, ts->remain_timeslices(), v_call->size() ); |
Cola | 24:270b436a1bb0 | 310 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 30:8dfb6d8de53d | 311 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 312 | char cb_status[ 32 ]; |
klauss | 78:1353744f01e1 | 313 | char cb_sip_status[ 32 ]; |
klauss | 78:1353744f01e1 | 314 | switch( cb->status ){ |
klauss | 78:1353744f01e1 | 315 | case cb_idle : { strcpy( cb_status, "cb_idle" ); break; } |
klauss | 78:1353744f01e1 | 316 | case cb_ringing : { strcpy( cb_status, "cb_ringing" ); break; } |
klauss | 78:1353744f01e1 | 317 | case cb_trying : { strcpy( cb_status,"cb_trying" ); break; } |
klauss | 78:1353744f01e1 | 318 | case cb_on_call : { strcpy( cb_status, "cb_on_call" ); break; } |
klauss | 78:1353744f01e1 | 319 | case cb_busy : { strcpy( cb_status, "cb_busy" ); break; } |
klauss | 78:1353744f01e1 | 320 | case cb_denied : { strcpy( cb_status, "cb_denied" ); break; } |
klauss | 78:1353744f01e1 | 321 | } |
klauss | 78:1353744f01e1 | 322 | switch( cb->sip->status ){ |
klauss | 78:1353744f01e1 | 323 | case sip_idle : { strcpy( cb_sip_status, "sip_idle" ); break; } |
klauss | 78:1353744f01e1 | 324 | case sip_waiting_trying : { strcpy( cb_sip_status, "sip_waiting_trying" ); break; } |
klauss | 78:1353744f01e1 | 325 | case sip_trying : { strcpy( cb_sip_status, "sip_trying" ); break; } |
klauss | 78:1353744f01e1 | 326 | case sip_ringing : { strcpy( cb_sip_status, "sip_ringing" ); break; } |
klauss | 78:1353744f01e1 | 327 | case sip_busy : { strcpy( cb_sip_status, "sip_busy" ); break; } |
klauss | 78:1353744f01e1 | 328 | case sip_ok : { strcpy( cb_sip_status, "sip_ok" ); break; } |
klauss | 78:1353744f01e1 | 329 | case sip_on_call : { strcpy( cb_sip_status, "sip_on_call" ); break; } |
klauss | 78:1353744f01e1 | 330 | case sip_denied : { strcpy( cb_sip_status, "sip_denied" ); break; } |
klauss | 78:1353744f01e1 | 331 | } |
klauss | 78:1353744f01e1 | 332 | char cbx_to_string[ 254 ]; |
klauss | 78:1353744f01e1 | 333 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 334 | strcpy( cbx_to_string, "Ext :: " ); |
klauss | 78:1353744f01e1 | 335 | itoa( cb->get_ext(), aux , 10 ); |
klauss | 78:1353744f01e1 | 336 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 337 | strcat( cbx_to_string, " :: Status -- " ); |
klauss | 78:1353744f01e1 | 338 | strcat( cbx_to_string, cb_status ); |
klauss | 78:1353744f01e1 | 339 | strcat( cbx_to_string, " - " ); |
klauss | 78:1353744f01e1 | 340 | strcat( cbx_to_string, cb_sip_status ); |
klauss | 78:1353744f01e1 | 341 | if( cb->get_timeslice() != 0 ){ |
klauss | 78:1353744f01e1 | 342 | strcat( cbx_to_string, " -- on TimeSlice :: " ); |
klauss | 78:1353744f01e1 | 343 | itoa( cb->get_timeslice(), aux , 10 ); |
klauss | 78:1353744f01e1 | 344 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 345 | } |
klauss | 78:1353744f01e1 | 346 | send_msg( cbx_to_string ); |
klauss | 48:195c97f12e8e | 347 | } |
klauss | 78:1353744f01e1 | 348 | pshowcb = false; |
klauss | 48:195c97f12e8e | 349 | } |
Cola | 22:d2a4b5939115 | 350 | |
klauss | 81:3656f00ab3db | 351 | if( pflood == true ) flood(); |
klauss | 81:3656f00ab3db | 352 | |
klauss | 81:3656f00ab3db | 353 | if( debug_eth ){ |
klauss | 81:3656f00ab3db | 354 | debug_eth = false; |
klauss | 81:3656f00ab3db | 355 | send_msg("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); |
klauss | 81:3656f00ab3db | 356 | } |
klauss | 30:8dfb6d8de53d | 357 | |
klauss | 0:4d17cd9c8f9d | 358 | if( status != __WAITING__ ){ |
klauss | 81:3656f00ab3db | 359 | pkg_wdt = RX_CB_IDLE; |
klauss | 86:bf7b0d4c3232 | 360 | xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ ); |
klauss | 0:4d17cd9c8f9d | 361 | status = __WAITING__; |
klauss | 81:3656f00ab3db | 362 | missed_pkg--; |
klauss | 78:1353744f01e1 | 363 | xmemcpy( buffer, cb_rx_buffer, __CB_BUFFER_SIZE__ ); |
klauss | 81:3656f00ab3db | 364 | |
klauss | 81:3656f00ab3db | 365 | if( debug_cpld ){ |
klauss | 81:3656f00ab3db | 366 | rx = true; |
klauss | 81:3656f00ab3db | 367 | tx = true; |
klauss | 81:3656f00ab3db | 368 | } |
klauss | 81:3656f00ab3db | 369 | |
klauss | 81:3656f00ab3db | 370 | if( rx ){ |
klauss | 81:3656f00ab3db | 371 | char str[ 1024 ]; |
klauss | 81:3656f00ab3db | 372 | strcpy( str, "RX :: \n\r " ); |
klauss | 81:3656f00ab3db | 373 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 81:3656f00ab3db | 374 | char tmp[ 16 ]; |
klauss | 81:3656f00ab3db | 375 | strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); |
klauss | 81:3656f00ab3db | 376 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 81:3656f00ab3db | 377 | |
klauss | 81:3656f00ab3db | 378 | else strcat( str, " " ); |
klauss | 81:3656f00ab3db | 379 | } |
klauss | 81:3656f00ab3db | 380 | send_msg( "%s", str ); |
klauss | 81:3656f00ab3db | 381 | rx = false; |
klauss | 81:3656f00ab3db | 382 | } |
klauss | 81:3656f00ab3db | 383 | |
klauss | 34:f19d9735428e | 384 | data = __parse_vz_pkg__( &ext, &port, &type, buffer ); |
klauss | 0:4d17cd9c8f9d | 385 | |
klauss | 78:1353744f01e1 | 386 | if( data != NULL ){ |
klauss | 78:1353744f01e1 | 387 | if( min_ext == 0 ) min_ext = ext; |
klauss | 78:1353744f01e1 | 388 | |
klauss | 78:1353744f01e1 | 389 | if( ext > max_ext ) max_ext = ext; |
klauss | 78:1353744f01e1 | 390 | |
klauss | 78:1353744f01e1 | 391 | if( ext < min_ext ) min_ext = ext; |
klauss | 78:1353744f01e1 | 392 | |
klauss | 78:1353744f01e1 | 393 | if( debug_cb_rx == true ) debug_msg("Pkg from CBx :: %d -- Type :: %d", ext, type ); |
klauss | 78:1353744f01e1 | 394 | |
klauss | 7:019b08223b87 | 395 | if( type != __AUDIO__ ){ |
klauss | 0:4d17cd9c8f9d | 396 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 397 | if( cb != NULL ){ |
klauss | 78:1353744f01e1 | 398 | if( ( data[ 0 ] & BIT7 ) >= BIT7 ){ |
klauss | 78:1353744f01e1 | 399 | if( type == __BOOT__ ){ |
klauss | 78:1353744f01e1 | 400 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 78:1353744f01e1 | 401 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 81:3656f00ab3db | 402 | }else if( ( data[ 0 ] & BIT7 ) == BIT7 ){ |
klauss | 81:3656f00ab3db | 403 | if( debug_main ) debug_msg("Received ack pkg with seq_num %d", data[ 0 ] ); |
klauss | 87:679ee0d594a9 | 404 | |
klauss | 81:3656f00ab3db | 405 | switch( type ){ |
klauss | 81:3656f00ab3db | 406 | case __INVITE__ : { |
klauss | 81:3656f00ab3db | 407 | if( debug_main || debug_invite ) debug_msg("Invite Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 408 | cb->set_invite_response_ok(); |
klauss | 81:3656f00ab3db | 409 | break; |
klauss | 81:3656f00ab3db | 410 | } |
klauss | 81:3656f00ab3db | 411 | case __CB_BYE__ : { |
klauss | 81:3656f00ab3db | 412 | if( debug_main || debug_invite ) debug_msg("BYE Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 413 | cb->set_bye_response_ok(); |
klauss | 81:3656f00ab3db | 414 | break; |
klauss | 81:3656f00ab3db | 415 | } |
klauss | 81:3656f00ab3db | 416 | case __REGISTRY__ : { |
klauss | 81:3656f00ab3db | 417 | if( debug_main || debug_aging ) debug_msg("Registry ACK from %d in pkg :: %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 418 | break; |
klauss | 81:3656f00ab3db | 419 | } |
klauss | 81:3656f00ab3db | 420 | default : { |
klauss | 81:3656f00ab3db | 421 | if( debug_main || debug_aging ) debug_msg("ACK from %d in pkg :: %d :: type %d", ext, cb->get_msg_id(), type ); |
klauss | 81:3656f00ab3db | 422 | } |
klauss | 81:3656f00ab3db | 423 | } |
klauss | 82:f55d13babca0 | 424 | if( type != __REGISTRY__ && type != __CB_BYE__ ) type = __DO_NOTHING__; |
klauss | 82:f55d13babca0 | 425 | //if( type != __REGISTRY__ ) type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 426 | } |
klauss | 0:4d17cd9c8f9d | 427 | } |
klauss | 0:4d17cd9c8f9d | 428 | } |
klauss | 0:4d17cd9c8f9d | 429 | } |
klauss | 0:4d17cd9c8f9d | 430 | }else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 431 | } |
klauss | 78:1353744f01e1 | 432 | |
klauss | 87:679ee0d594a9 | 433 | if( main_test == true ) |
klauss | 87:679ee0d594a9 | 434 | { |
klauss | 87:679ee0d594a9 | 435 | main_test = false; |
klauss | 85:b6f2dc1d0f4f | 436 | send_msg("CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter ); |
klauss | 85:b6f2dc1d0f4f | 437 | send_msg("SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter ); |
klauss | 87:679ee0d594a9 | 438 | send_msg("RTP_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter ); |
klauss | 87:679ee0d594a9 | 439 | send_msg("RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter ); |
klauss | 87:679ee0d594a9 | 440 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 441 | send_msg("Memory is %s", ( memory_is_over ) ? "Over" : "Ok" ); |
klauss | 81:3656f00ab3db | 442 | send_msg("Missed_Pkg :: %d ::", missed_pkg ); |
klauss | 87:679ee0d594a9 | 443 | send_msg("Sizeof Sip :: %u", sizeof( Sip ) ); |
klauss | 87:679ee0d594a9 | 444 | send_msg("Sizeof Call_Box :: %u", sizeof( Call_Box ) ); |
klauss | 87:679ee0d594a9 | 445 | send_msg("Sizeof VZ_call :: %u", sizeof( VZ_call ) ); |
klauss | 87:679ee0d594a9 | 446 | send_msg("Sizeof RTP :: %u", sizeof( RTP ) ); |
klauss | 87:679ee0d594a9 | 447 | send_msg("Sizeof RTP_Header :: %u", sizeof( RTP_Header ) ); |
klauss | 87:679ee0d594a9 | 448 | send_msg("Sizeof RTP_Body :: %u", sizeof( RTP_Body ) ); |
klauss | 87:679ee0d594a9 | 449 | send_msg("Sizeof Vector :: %u", sizeof( Vector ) ); |
klauss | 87:679ee0d594a9 | 450 | send_msg("Sizeof Timeslice :: %u", sizeof( Timeslice ) ); |
klauss | 87:679ee0d594a9 | 451 | send_msg("Sizeof Watchdog :: %u", sizeof( Watchdog ) ); |
klauss | 81:3656f00ab3db | 452 | } |
klauss | 86:bf7b0d4c3232 | 453 | if( regystry_test == true ) |
klauss | 86:bf7b0d4c3232 | 454 | { |
klauss | 86:bf7b0d4c3232 | 455 | regystry_test = false; |
klauss | 86:bf7b0d4c3232 | 456 | |
klauss | 86:bf7b0d4c3232 | 457 | if( type == __DO_NOTHING__ ) |
klauss | 86:bf7b0d4c3232 | 458 | { |
klauss | 87:679ee0d594a9 | 459 | //if( next_value < ( 5010 + __MAX_CB_IN_A_BRANCH__ - 2 ) ) |
klauss | 86:bf7b0d4c3232 | 460 | { |
klauss | 86:bf7b0d4c3232 | 461 | type = __REGISTRY__; |
klauss | 86:bf7b0d4c3232 | 462 | data = buffer; |
klauss | 86:bf7b0d4c3232 | 463 | ext = next_value; |
klauss | 86:bf7b0d4c3232 | 464 | port = next_value++; |
klauss | 86:bf7b0d4c3232 | 465 | } |
klauss | 87:679ee0d594a9 | 466 | /* |
klauss | 86:bf7b0d4c3232 | 467 | else |
klauss | 86:bf7b0d4c3232 | 468 | { |
klauss | 87:679ee0d594a9 | 469 | if( nex_test_registry > ( 5010 + __MAX_CB_IN_A_BRANCH__ - 1 - 2 ) ) nex_test_registry = 5010; |
klauss | 86:bf7b0d4c3232 | 470 | type = __REGISTRY__; |
klauss | 86:bf7b0d4c3232 | 471 | data = buffer; |
klauss | 86:bf7b0d4c3232 | 472 | ext = nex_test_registry; |
klauss | 86:bf7b0d4c3232 | 473 | port = nex_test_registry++; |
klauss | 86:bf7b0d4c3232 | 474 | } |
klauss | 87:679ee0d594a9 | 475 | */ |
klauss | 86:bf7b0d4c3232 | 476 | } |
klauss | 86:bf7b0d4c3232 | 477 | } |
klauss | 86:bf7b0d4c3232 | 478 | |
klauss | 81:3656f00ab3db | 479 | if( reset_cks == true ){ |
klauss | 81:3656f00ab3db | 480 | pkg_cksok = 0; |
klauss | 81:3656f00ab3db | 481 | pkg_ckserr = 0; |
klauss | 81:3656f00ab3db | 482 | reset_cks = false; |
klauss | 81:3656f00ab3db | 483 | pcks_s = true; |
klauss | 81:3656f00ab3db | 484 | } |
klauss | 81:3656f00ab3db | 485 | |
klauss | 81:3656f00ab3db | 486 | if( pcks_s == true ){ |
klauss | 86:bf7b0d4c3232 | 487 | send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d :: PKG_ZERO: %d :: Out_of_range: %d :: Missed_Pkg :: %d :: CPLD_RCV :: %d", pkg_cksok, pkg_ckserr, pkg_zero, out_of_range, missed_pkg, received_cpld_pkg ); |
klauss | 81:3656f00ab3db | 488 | pcks_s = false; |
klauss | 81:3656f00ab3db | 489 | } |
klauss | 81:3656f00ab3db | 490 | |
klauss | 78:1353744f01e1 | 491 | if( led_sync_timer.read() > 1 ){ |
klauss | 78:1353744f01e1 | 492 | led_sync_timer.reset(); |
klauss | 78:1353744f01e1 | 493 | led3 = !led3; |
klauss | 78:1353744f01e1 | 494 | CAB_LED = !CAB_LED; |
klauss | 78:1353744f01e1 | 495 | } |
klauss | 78:1353744f01e1 | 496 | |
klauss | 0:4d17cd9c8f9d | 497 | switch( type ){ |
klauss | 0:4d17cd9c8f9d | 498 | case __DO_NOTHING__ :{} |
klauss | 0:4d17cd9c8f9d | 499 | break; |
klauss | 0:4d17cd9c8f9d | 500 | |
klauss | 0:4d17cd9c8f9d | 501 | case __CB_BYE__ : { |
klauss | 81:3656f00ab3db | 502 | //FIXME como mandar um BYE pro servidor ? |
klauss | 63:0d95da692bb4 | 503 | cb_bye_counter++; |
klauss | 0:4d17cd9c8f9d | 504 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 505 | if( cb != NULL ){ |
klauss | 81:3656f00ab3db | 506 | if( debug_invite || debug_main ) debug_msg("Received bye pkg with msg_id %d e pkg_id %d", cb->get_msg_id(), data[ 0 ] ); |
klauss | 0:4d17cd9c8f9d | 507 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 508 | cb->set_msg_id( data[ 0 ] ); |
klauss | 81:3656f00ab3db | 509 | if( debug_main || debug_invite ) debug_msg( "Request bye from CBx " ); |
klauss | 81:3656f00ab3db | 510 | bool already_removed = true; |
klauss | 0:4d17cd9c8f9d | 511 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 512 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 513 | if( call->get_cb_ext() == ext ){ |
klauss | 81:3656f00ab3db | 514 | already_removed = false; |
klauss | 4:de46f0d9b14d | 515 | cb->send_bye(); |
klauss | 78:1353744f01e1 | 516 | |
klauss | 0:4d17cd9c8f9d | 517 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 518 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 519 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 520 | |
klauss | 0:4d17cd9c8f9d | 521 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 522 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 523 | |
klauss | 81:3656f00ab3db | 524 | v_call->remove_element( i ); |
klauss | 81:3656f00ab3db | 525 | |
klauss | 74:81c47fff88a5 | 526 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 527 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 82:f55d13babca0 | 528 | |
klauss | 82:f55d13babca0 | 529 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 530 | |
klauss | 3:cd9148672e25 | 531 | delete( call ); |
klauss | 29:7246460b73f8 | 532 | cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 533 | } |
klauss | 0:4d17cd9c8f9d | 534 | } |
klauss | 82:f55d13babca0 | 535 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from vector call" ); |
klauss | 82:f55d13babca0 | 536 | |
klauss | 82:f55d13babca0 | 537 | //ok, mas nem sempre o cbx "entrou em call |
klauss | 82:f55d13babca0 | 538 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 82:f55d13babca0 | 539 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 82:f55d13babca0 | 540 | if( cb->get_ext() == ext ) { |
klauss | 82:f55d13babca0 | 541 | already_removed = true; |
klauss | 82:f55d13babca0 | 542 | if( cb->get_status() != cb_idle ) { |
klauss | 82:f55d13babca0 | 543 | already_removed = false; |
klauss | 82:f55d13babca0 | 544 | cb->send_bye(); |
klauss | 82:f55d13babca0 | 545 | |
klauss | 82:f55d13babca0 | 546 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 82:f55d13babca0 | 547 | cb->set_timeslice( 0x00 ); |
klauss | 82:f55d13babca0 | 548 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 82:f55d13babca0 | 549 | |
klauss | 82:f55d13babca0 | 550 | set_status( cb->status, cb_idle ); |
klauss | 82:f55d13babca0 | 551 | set_status( cb->sip->status, sip_idle ); |
klauss | 82:f55d13babca0 | 552 | |
klauss | 82:f55d13babca0 | 553 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 82:f55d13babca0 | 554 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 82:f55d13babca0 | 555 | |
klauss | 82:f55d13babca0 | 556 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 82:f55d13babca0 | 557 | |
klauss | 82:f55d13babca0 | 558 | cb->re_start_timer(); |
klauss | 82:f55d13babca0 | 559 | } |
klauss | 82:f55d13babca0 | 560 | } |
klauss | 82:f55d13babca0 | 561 | } |
klauss | 82:f55d13babca0 | 562 | |
klauss | 82:f55d13babca0 | 563 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from inviting queue" ); |
klauss | 81:3656f00ab3db | 564 | |
klauss | 78:1353744f01e1 | 565 | cb->registry(); |
klauss | 81:3656f00ab3db | 566 | }else if( debug_invite || debug_main ) debug_msg("Bye from who ? %d", ext ); |
klauss | 7:019b08223b87 | 567 | }break; |
klauss | 7:019b08223b87 | 568 | |
klauss | 0:4d17cd9c8f9d | 569 | case __INVITE__ : { |
klauss | 63:0d95da692bb4 | 570 | invite_counter++; |
klauss | 78:1353744f01e1 | 571 | if( debug_invite ) debug_msg("Request Invite received from Cbx %i", ext); |
klauss | 0:4d17cd9c8f9d | 572 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 573 | if( cb == NULL ){ |
klauss | 78:1353744f01e1 | 574 | if( debug_main ) debug_msg( "Adding CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 575 | cb = new Call_Box( ext, port ); |
klauss | 87:679ee0d594a9 | 576 | |
klauss | 87:679ee0d594a9 | 577 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 578 | memory_is_over = true; |
klauss | 87:679ee0d594a9 | 579 | }else{ |
klauss | 87:679ee0d594a9 | 580 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 581 | } |
klauss | 0:4d17cd9c8f9d | 582 | } |
klauss | 87:679ee0d594a9 | 583 | if( cb != NULL ){ |
klauss | 87:679ee0d594a9 | 584 | cb->set_msg_id( data[ 0 ] ); |
klauss | 87:679ee0d594a9 | 585 | invite_handler( v_call, v_cb, ts, cb ); |
klauss | 87:679ee0d594a9 | 586 | } |
klauss | 0:4d17cd9c8f9d | 587 | }break; |
klauss | 4:de46f0d9b14d | 588 | case __REGISTRY__ : { |
klauss | 63:0d95da692bb4 | 589 | registry_counter++; |
klauss | 78:1353744f01e1 | 590 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 2:93bec7313ccc | 591 | |
klauss | 78:1353744f01e1 | 592 | if( cb == NULL ){ |
klauss | 78:1353744f01e1 | 593 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 4:de46f0d9b14d | 594 | cb = new Call_Box( ext, port ); |
klauss | 85:b6f2dc1d0f4f | 595 | |
klauss | 87:679ee0d594a9 | 596 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 597 | memory_is_over = true; |
klauss | 87:679ee0d594a9 | 598 | }else{ |
klauss | 87:679ee0d594a9 | 599 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 600 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 87:679ee0d594a9 | 601 | } |
klauss | 0:4d17cd9c8f9d | 602 | } |
klauss | 78:1353744f01e1 | 603 | if( debug_main ) debug_msg("Registered %d - %d", ext, port ); |
klauss | 78:1353744f01e1 | 604 | |
klauss | 87:679ee0d594a9 | 605 | if( cb != NULL ) cb->registry(); |
klauss | 78:1353744f01e1 | 606 | |
klauss | 4:de46f0d9b14d | 607 | }break; |
klauss | 4:de46f0d9b14d | 608 | case __BOOT__ : { |
klauss | 63:0d95da692bb4 | 609 | boot_counter++; |
klauss | 74:81c47fff88a5 | 610 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 78:1353744f01e1 | 611 | ( char * )data, data[ 0 ] | BIT7, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 612 | }break; |
klauss | 4:de46f0d9b14d | 613 | case __TELEMETRY__ : { |
klauss | 78:1353744f01e1 | 614 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 87:679ee0d594a9 | 615 | |
klauss | 78:1353744f01e1 | 616 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 617 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 87:679ee0d594a9 | 618 | ( char * )data, ( ( data[ 0 ] & ~BIT7 ) + 1 ), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 87:679ee0d594a9 | 619 | |
klauss | 87:679ee0d594a9 | 620 | /* |
klauss | 78:1353744f01e1 | 621 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 78:1353744f01e1 | 622 | cb = new Call_Box( ext, port ); |
klauss | 87:679ee0d594a9 | 623 | |
klauss | 87:679ee0d594a9 | 624 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 625 | memory_is_over = true; |
klauss | 87:679ee0d594a9 | 626 | }else{ |
klauss | 87:679ee0d594a9 | 627 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 628 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 87:679ee0d594a9 | 629 | } |
klauss | 87:679ee0d594a9 | 630 | */ |
klauss | 78:1353744f01e1 | 631 | } |
klauss | 87:679ee0d594a9 | 632 | /* |
klauss | 87:679ee0d594a9 | 633 | if( cb != NULL ){ |
klauss | 87:679ee0d594a9 | 634 | cb->registry(); |
klauss | 87:679ee0d594a9 | 635 | }*/ |
klauss | 87:679ee0d594a9 | 636 | |
klauss | 63:0d95da692bb4 | 637 | telemetry_counter++; |
klauss | 78:1353744f01e1 | 638 | if( debug_telemetry ) send_msg("::Telemetry from %d - %d::", ext, port ); |
klauss | 53:bb492a8f115a | 639 | build_telemetry_report( ext, port, ( char *)data ); |
klauss | 4:de46f0d9b14d | 640 | }break; |
klauss | 36:728498a78e1e | 641 | |
klauss | 67:cdedc64d9921 | 642 | case __BOOTLOADER_CBX__ : { |
klauss | 67:cdedc64d9921 | 643 | bootloader_cbx_counter++; |
klauss | 67:cdedc64d9921 | 644 | int ret = bl_cbx_reply_to_eth( ext, ( char * )data ); |
klauss | 67:cdedc64d9921 | 645 | }break; |
klauss | 67:cdedc64d9921 | 646 | |
klauss | 36:728498a78e1e | 647 | case __PROMPT__ : { |
klauss | 78:1353744f01e1 | 648 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 87:679ee0d594a9 | 649 | |
klauss | 78:1353744f01e1 | 650 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 651 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 87:679ee0d594a9 | 652 | ( char * )data, ( ( data[ 0 ] & ~BIT7 ) + 1 ), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 87:679ee0d594a9 | 653 | /* |
klauss | 78:1353744f01e1 | 654 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 78:1353744f01e1 | 655 | cb = new Call_Box( ext, port ); |
klauss | 87:679ee0d594a9 | 656 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 657 | memory_is_over = true; |
klauss | 87:679ee0d594a9 | 658 | }else{ |
klauss | 87:679ee0d594a9 | 659 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 660 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 87:679ee0d594a9 | 661 | } |
klauss | 87:679ee0d594a9 | 662 | */ |
klauss | 48:195c97f12e8e | 663 | } |
klauss | 78:1353744f01e1 | 664 | |
klauss | 87:679ee0d594a9 | 665 | //if( cb!= NULL ) cb->registry(); |
klauss | 48:195c97f12e8e | 666 | |
klauss | 78:1353744f01e1 | 667 | if( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ){ |
klauss | 78:1353744f01e1 | 668 | if( debug_ping ) send_msg( "Prompt pkg from ( %i, %i ) :: Ping", ext, port ); |
klauss | 78:1353744f01e1 | 669 | }else{ |
klauss | 78:1353744f01e1 | 670 | prompt_counter++; |
klauss | 78:1353744f01e1 | 671 | //fixme isso nao poderia ser resolvido com um sendmsg ? |
klauss | 78:1353744f01e1 | 672 | send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); |
klauss | 78:1353744f01e1 | 673 | for( register uint8_t i = 0; i < 32; i++ ){ |
klauss | 78:1353744f01e1 | 674 | pc.printf("%c", data[ i ] ); |
klauss | 78:1353744f01e1 | 675 | if( i == 15 ) pc.printf( "\r\n" ); |
klauss | 78:1353744f01e1 | 676 | } |
klauss | 78:1353744f01e1 | 677 | pc.printf("\n\r> "); |
klauss | 78:1353744f01e1 | 678 | |
klauss | 78:1353744f01e1 | 679 | if( tcp_session ){ |
klauss | 78:1353744f01e1 | 680 | char aux[ __CB_BUFFER_SIZE__ + 3 ]; |
klauss | 78:1353744f01e1 | 681 | strncpy( aux, (char * )data, __CB_BUFFER_SIZE__ ); |
klauss | 78:1353744f01e1 | 682 | strcat( aux, "\n\r\0" ); |
klauss | 78:1353744f01e1 | 683 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 78:1353744f01e1 | 684 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 78:1353744f01e1 | 685 | } |
klauss | 48:195c97f12e8e | 686 | } |
klauss | 36:728498a78e1e | 687 | }break; |
klauss | 0:4d17cd9c8f9d | 688 | case __AUDIO__ : { |
klauss | 63:0d95da692bb4 | 689 | audio_counter++; |
klauss | 78:1353744f01e1 | 690 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 0:4d17cd9c8f9d | 691 | if( call != NULL ){ |
klauss | 30:8dfb6d8de53d | 692 | char * pkg = call->build_eth_package( data + 2 ); |
klauss | 0:4d17cd9c8f9d | 693 | call->send_message( pkg ); |
klauss | 78:1353744f01e1 | 694 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 695 | if( cb != NULL ) cb->reset_elapsed_time(); |
klauss | 18:01a93677e40c | 696 | }else{ |
klauss | 78:1353744f01e1 | 697 | if( debug_main ) debug_msg("received missed package from CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 698 | } |
klauss | 0:4d17cd9c8f9d | 699 | }break; |
klauss | 9:ffa64f38ef9c | 700 | }// fim switch |
klauss | 81:3656f00ab3db | 701 | |
klauss | 78:1353744f01e1 | 702 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 703 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 704 | int length = 0; |
klauss | 0:4d17cd9c8f9d | 705 | char * tmp = call->get_eth_message( &length ); |
klauss | 0:4d17cd9c8f9d | 706 | if( tmp != NULL ){ |
klauss | 0:4d17cd9c8f9d | 707 | int cb_port = 0xffff; |
klauss | 78:1353744f01e1 | 708 | Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 4:de46f0d9b14d | 709 | |
klauss | 4:de46f0d9b14d | 710 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 711 | cb_port = cb->get_port(); |
klauss | 78:1353744f01e1 | 712 | |
klauss | 78:1353744f01e1 | 713 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 0:4d17cd9c8f9d | 714 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 4:de46f0d9b14d | 715 | |
klauss | 78:1353744f01e1 | 716 | send2callboxes( pkg2cb ); |
klauss | 78:1353744f01e1 | 717 | }else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 718 | } |
klauss | 14:22a35f575502 | 719 | } |
klauss | 81:3656f00ab3db | 720 | //if( v_call->size() == 0 ) refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 81:3656f00ab3db | 721 | refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 78:1353744f01e1 | 722 | |
klauss | 78:1353744f01e1 | 723 | //Fixme pensar melhor nessa parte durante ligacoes, pode complicar com muitos cbx ... |
klauss | 81:3656f00ab3db | 724 | //if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 4:de46f0d9b14d | 725 | |
klauss | 78:1353744f01e1 | 726 | // check sip messages only for cbx in call ? |
klauss | 78:1353744f01e1 | 727 | int ext_to__be_removed = sip_manager( v_cb ); |
klauss | 78:1353744f01e1 | 728 | if( ext_to__be_removed > 0x00 ){ |
klauss | 78:1353744f01e1 | 729 | Call_Box * cb = __find_CB__( v_cb, ext_to__be_removed ); |
klauss | 4:de46f0d9b14d | 730 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 731 | if( cb->status == cb_on_call ){ |
klauss | 4:de46f0d9b14d | 732 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 733 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 734 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 735 | |
klauss | 78:1353744f01e1 | 736 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 737 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 738 | |
klauss | 4:de46f0d9b14d | 739 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 4:de46f0d9b14d | 740 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 78:1353744f01e1 | 741 | if( call->get_cb_ext() == ext_to__be_removed ){ |
klauss | 4:de46f0d9b14d | 742 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 743 | delete( call ); |
klauss | 4:de46f0d9b14d | 744 | } |
klauss | 2:93bec7313ccc | 745 | } |
klauss | 78:1353744f01e1 | 746 | |
klauss | 82:f55d13babca0 | 747 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 82:f55d13babca0 | 748 | //cb->set_msg_id( 80 ); |
klauss | 81:3656f00ab3db | 749 | |
klauss | 82:f55d13babca0 | 750 | //debug_msg("msg_id -- %d", cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 751 | |
klauss | 74:81c47fff88a5 | 752 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 4:de46f0d9b14d | 753 | ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 754 | |
klauss | 81:3656f00ab3db | 755 | //cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 756 | } |
klauss | 78:1353744f01e1 | 757 | }else if( debug_main ) debug_msg("Missed bye request from * CBx :: %d", ext ); |
klauss | 0:4d17cd9c8f9d | 758 | } |
klauss | 13:ae278302dffe | 759 | |
klauss | 81:3656f00ab3db | 760 | /* Verifica andamento de ligações para eventualmente encerra-las por timeout */ |
klauss | 10:22da1a0ac1e1 | 761 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 0:4d17cd9c8f9d | 762 | |
klauss | 81:3656f00ab3db | 763 | /* tratamento de pedidos de ligação */ |
klauss | 81:3656f00ab3db | 764 | invite_handler( v_call, v_cb, ts, NULL ); |
klauss | 78:1353744f01e1 | 765 | |
klauss | 81:3656f00ab3db | 766 | /* rotina de verificação de TS's perdidos */ |
klauss | 78:1353744f01e1 | 767 | if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() != __MAX_TIMESLICES__ ) ){ |
klauss | 78:1353744f01e1 | 768 | bool ts_reset = true; |
klauss | 78:1353744f01e1 | 769 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 82:f55d13babca0 | 770 | if ( ( ( Call_Box * )v_cb->get_element( i ) )->get_status() != cb_idle && |
klauss | 82:f55d13babca0 | 771 | ( ( Call_Box * )v_cb->get_element( i ) )->get_sip_status() != sip_idle ) |
klauss | 82:f55d13babca0 | 772 | { |
klauss | 78:1353744f01e1 | 773 | ts_reset = false; |
klauss | 78:1353744f01e1 | 774 | break; |
klauss | 78:1353744f01e1 | 775 | } |
klauss | 78:1353744f01e1 | 776 | } |
klauss | 78:1353744f01e1 | 777 | if( ts_reset ){ |
klauss | 81:3656f00ab3db | 778 | if( debug_invite ) debug_msg("Resetando TS"); |
klauss | 78:1353744f01e1 | 779 | ts->reset(); |
klauss | 78:1353744f01e1 | 780 | } |
klauss | 0:4d17cd9c8f9d | 781 | } |
klauss | 78:1353744f01e1 | 782 | |
klauss | 81:3656f00ab3db | 783 | //invite_pgk_retry_manager( v_call, v_cb, buffer, write_buffer ); |
klauss | 81:3656f00ab3db | 784 | |
klauss | 81:3656f00ab3db | 785 | /* escuta se existe algum procedimento de gravação de cbx */ |
klauss | 67:cdedc64d9921 | 786 | bl_handler(); |
klauss | 78:1353744f01e1 | 787 | |
klauss | 81:3656f00ab3db | 788 | /* rotina que esvazia possiveis pacotes que não foram transmitidos para evitar conflito */ |
klauss | 72:895ca792c647 | 789 | tx_buffer_ring_buffer_handler(); |
klauss | 33:735fd60e96d8 | 790 | |
klauss | 30:8dfb6d8de53d | 791 | type = __DO_NOTHING__; |
klauss | 81:3656f00ab3db | 792 | |
klauss | 81:3656f00ab3db | 793 | if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 81:3656f00ab3db | 794 | |
klauss | 83:b8a1d8fdeaeb | 795 | if( wdt_timer.read() >= 1 ){ |
klauss | 86:bf7b0d4c3232 | 796 | regystry_test = true; |
klauss | 86:bf7b0d4c3232 | 797 | |
klauss | 83:b8a1d8fdeaeb | 798 | char wake_msg[ 48 ]; |
klauss | 83:b8a1d8fdeaeb | 799 | uptime++; |
klauss | 82:f55d13babca0 | 800 | int read = udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) ); |
klauss | 82:f55d13babca0 | 801 | |
klauss | 82:f55d13babca0 | 802 | if( read > 0 ){ |
klauss | 85:b6f2dc1d0f4f | 803 | eth_pkg_received++; |
klauss | 85:b6f2dc1d0f4f | 804 | |
klauss | 82:f55d13babca0 | 805 | if( !( strncmp( wake_msg, "alive", 5 ) ) ){ |
klauss | 83:b8a1d8fdeaeb | 806 | // Just ckeck but not set 'alive?' |
klauss | 83:b8a1d8fdeaeb | 807 | // Ckecking and set 'alive' |
klauss | 84:b64f0e3b283e | 808 | bool question_alive = ( wake_msg[ 5 ] == '?' ); |
klauss | 84:b64f0e3b283e | 809 | |
klauss | 85:b6f2dc1d0f4f | 810 | snprintf( wake_msg, 48,"wdt:%u,%u,%u,%c,%u:", uptime, invite_counter, external_wdt, ( wdt.WatchdogCausedReset() ) ? '1' : '0', cb_new_counter ); |
klauss | 83:b8a1d8fdeaeb | 811 | wake_msg[ 48 - 1 ] = 0; |
klauss | 83:b8a1d8fdeaeb | 812 | int sent = 0; |
klauss | 84:b64f0e3b283e | 813 | sent = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 83:b8a1d8fdeaeb | 814 | |
klauss | 83:b8a1d8fdeaeb | 815 | if( wdt_show ) send_msg( "Sent %d bytes in response", sent ); |
klauss | 84:b64f0e3b283e | 816 | |
klauss | 87:679ee0d594a9 | 817 | if( (!question_alive) && ( cb_new_counter <= __MAX_CB_IN_A_BRANCH__ ) && ( cb_new_counter >= 2 ) ) { |
klauss | 84:b64f0e3b283e | 818 | external_wdt = EXTERN_WDT_IDLE; |
klauss | 84:b64f0e3b283e | 819 | } |
klauss | 83:b8a1d8fdeaeb | 820 | }else if( !( strncmp( wake_msg, "reset", 5 ) ) ){ |
klauss | 83:b8a1d8fdeaeb | 821 | external_wdt = 0; |
klauss | 83:b8a1d8fdeaeb | 822 | |
klauss | 83:b8a1d8fdeaeb | 823 | sprintf( wake_msg, "rst:%u:", uptime ); |
klauss | 83:b8a1d8fdeaeb | 824 | int sent = 0; |
klauss | 83:b8a1d8fdeaeb | 825 | sent = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 83:b8a1d8fdeaeb | 826 | |
klauss | 83:b8a1d8fdeaeb | 827 | if( wdt_show ) send_msg( "Sent %d bytes in response", sent ); |
klauss | 82:f55d13babca0 | 828 | } |
klauss | 82:f55d13babca0 | 829 | } |
klauss | 83:b8a1d8fdeaeb | 830 | if( wdt_show ) if( read < 0 ) debug_msg( "some's wrong ... some's wrong" ); |
klauss | 82:f55d13babca0 | 831 | |
klauss | 81:3656f00ab3db | 832 | wdt_timer.reset(); |
klauss | 81:3656f00ab3db | 833 | |
klauss | 81:3656f00ab3db | 834 | if( wdt_show ) debug_wdt = true; |
klauss | 81:3656f00ab3db | 835 | |
klauss | 81:3656f00ab3db | 836 | if( external_wdt ) external_wdt--; |
klauss | 81:3656f00ab3db | 837 | if( pkg_wdt ) pkg_wdt--; |
klauss | 81:3656f00ab3db | 838 | if( eth_wdt ) eth_wdt--; |
klauss | 81:3656f00ab3db | 839 | |
klauss | 81:3656f00ab3db | 840 | if( eth_wdt && external_wdt && pkg_wdt ){ |
klauss | 81:3656f00ab3db | 841 | wdt.kick(); |
klauss | 81:3656f00ab3db | 842 | } |
klauss | 81:3656f00ab3db | 843 | } |
klauss | 81:3656f00ab3db | 844 | |
klauss | 81:3656f00ab3db | 845 | if( debug_wdt ){ |
klauss | 87:679ee0d594a9 | 846 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 847 | lpc_low_level_input_counter = 0; |
klauss | 85:b6f2dc1d0f4f | 848 | |
klauss | 81:3656f00ab3db | 849 | debug_wdt = false; |
klauss | 81:3656f00ab3db | 850 | if( eth_status == 0 ){ |
klauss | 82:f55d13babca0 | 851 | send_msg( "Wdt last reset: %s - status_eth :: Connected - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )", |
klauss | 81:3656f00ab3db | 852 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 81:3656f00ab3db | 853 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 82:f55d13babca0 | 854 | EXTERN_WDT_IDLE, |
klauss | 82:f55d13babca0 | 855 | RX_CB_IDLE - pkg_wdt, |
klauss | 82:f55d13babca0 | 856 | RX_CB_IDLE |
klauss | 81:3656f00ab3db | 857 | ); |
klauss | 81:3656f00ab3db | 858 | }else{ |
klauss | 82:f55d13babca0 | 859 | send_msg( "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 | 81:3656f00ab3db | 860 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 81:3656f00ab3db | 861 | ETH_CONNECT_TIMEOUT - eth_wdt, |
klauss | 82:f55d13babca0 | 862 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 82:f55d13babca0 | 863 | EXTERN_WDT_IDLE, |
klauss | 82:f55d13babca0 | 864 | RX_CB_IDLE - pkg_wdt, |
klauss | 82:f55d13babca0 | 865 | RX_CB_IDLE |
klauss | 81:3656f00ab3db | 866 | ); |
klauss | 81:3656f00ab3db | 867 | } |
klauss | 81:3656f00ab3db | 868 | } |
klauss | 86:bf7b0d4c3232 | 869 | /* |
klauss | 86:bf7b0d4c3232 | 870 | { |
klauss | 86:bf7b0d4c3232 | 871 | char eth_msg[ ETH_MSG_SIZE ]; |
klauss | 86:bf7b0d4c3232 | 872 | for( register int i = 0; i < NUM_SOCK; i++ ) |
klauss | 86:bf7b0d4c3232 | 873 | { |
klauss | 86:bf7b0d4c3232 | 874 | int rcv = sock[ i ].receiveFrom( server[ i ], eth_msg, sizeof ( eth_msg ) ); |
klauss | 86:bf7b0d4c3232 | 875 | if( rcv > 0 ) |
klauss | 86:bf7b0d4c3232 | 876 | { |
klauss | 86:bf7b0d4c3232 | 877 | int sent = sock[ i ].sendTo( server[ i ], eth_msg, rcv ); |
klauss | 86:bf7b0d4c3232 | 878 | |
klauss | 86:bf7b0d4c3232 | 879 | if( sent < 0 ) send_msg("Sent -1"); |
klauss | 86:bf7b0d4c3232 | 880 | } |
klauss | 86:bf7b0d4c3232 | 881 | } |
klauss | 86:bf7b0d4c3232 | 882 | } |
klauss | 86:bf7b0d4c3232 | 883 | */ |
klauss | 0:4d17cd9c8f9d | 884 | } |
klauss | 0:4d17cd9c8f9d | 885 | } |