![](/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@99:e80850c51106, 2015-01-19 (annotated)
- Committer:
- klauss
- Date:
- Mon Jan 19 18:00:42 2015 +0000
- Revision:
- 99:e80850c51106
- Parent:
- 98:43b45f26b430
- Child:
- 100:09a23fcd3bdf
wip header cb tx delay
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 91:c2a86b1f8aaa | 1 | #include "telemetry.h" |
klauss | 91:c2a86b1f8aaa | 2 | #include "eth.h" |
klauss | 91:c2a86b1f8aaa | 3 | #include "bits.h" |
klauss | 74:81c47fff88a5 | 4 | #include "UART3Interrupt.h" // for RXBuffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 91:c2a86b1f8aaa | 5 | #include "utils.h" |
klauss | 91:c2a86b1f8aaa | 6 | #include "parallelcpld.h" |
klauss | 91:c2a86b1f8aaa | 7 | #include "debug.h" |
klauss | 91:c2a86b1f8aaa | 8 | #include "flood.h" |
klauss | 91:c2a86b1f8aaa | 9 | #include "bootloader_cbx.h" |
klauss | 91:c2a86b1f8aaa | 10 | #include "call_manager.h" |
klauss | 91:c2a86b1f8aaa | 11 | #include "call_box_manager.h" |
klauss | 91:c2a86b1f8aaa | 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 | 99:e80850c51106 | 17 | #include "fw.h" |
klauss | 0:4d17cd9c8f9d | 18 | |
klauss | 87:679ee0d594a9 | 19 | volatile u16_t lpc_low_level_input_counter = 0; |
klauss | 85:b6f2dc1d0f4f | 20 | |
klauss | 91:c2a86b1f8aaa | 21 | int main() |
klauss | 91:c2a86b1f8aaa | 22 | { |
klauss | 81:3656f00ab3db | 23 | init_wdt(); |
klauss | 91:c2a86b1f8aaa | 24 | |
klauss | 81:3656f00ab3db | 25 | config_lpc(); |
klauss | 91:c2a86b1f8aaa | 26 | |
klauss | 0:4d17cd9c8f9d | 27 | start_cpld(); |
klauss | 91:c2a86b1f8aaa | 28 | |
klauss | 91:c2a86b1f8aaa | 29 | if( sdram_init() == 1 ) { |
klauss | 87:679ee0d594a9 | 30 | send_msg("******* Failed to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 31 | return 1; |
klauss | 89:0fe315117b00 | 32 | } else { |
klauss | 87:679ee0d594a9 | 33 | send_msg("******* Success to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 34 | } |
klauss | 91:c2a86b1f8aaa | 35 | |
klauss | 43:455522f98de5 | 36 | init_fsystem(); |
klauss | 91:c2a86b1f8aaa | 37 | |
klauss | 89:0fe315117b00 | 38 | { |
klauss | 89:0fe315117b00 | 39 | char s[ 32 ]; |
klauss | 89:0fe315117b00 | 40 | mbed_mac_address( s ); |
klauss | 89:0fe315117b00 | 41 | send_msg( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] ); |
klauss | 89:0fe315117b00 | 42 | } |
klauss | 91:c2a86b1f8aaa | 43 | |
klauss | 78:1353744f01e1 | 44 | short int eth_status = __init_eth__(); |
klauss | 91:c2a86b1f8aaa | 45 | if( eth_status ) { |
klauss | 87:679ee0d594a9 | 46 | send_msg("******* Cannot connect to eth *******"); |
klauss | 91:c2a86b1f8aaa | 47 | } else { |
klauss | 81:3656f00ab3db | 48 | send_msg("******* Connection eth - ok *******"); |
klauss | 78:1353744f01e1 | 49 | init_prompt_eth(); |
klauss | 82:f55d13babca0 | 50 | init_external_wdt() |
klauss | 8:e3bfe62a477e | 51 | } |
klauss | 91:c2a86b1f8aaa | 52 | |
klauss | 78:1353744f01e1 | 53 | Timer sync_timer, led_sync_timer; |
klauss | 78:1353744f01e1 | 54 | sync_timer.start(), led_sync_timer.start(); |
klauss | 91:c2a86b1f8aaa | 55 | |
klauss | 0:4d17cd9c8f9d | 56 | /* representa ramal do call box */ |
klauss | 0:4d17cd9c8f9d | 57 | int ext = 0; |
klauss | 91:c2a86b1f8aaa | 58 | |
klauss | 0:4d17cd9c8f9d | 59 | /* representa porta do call box */ |
klauss | 78:1353744f01e1 | 60 | int port = 0; |
klauss | 91:c2a86b1f8aaa | 61 | |
klauss | 0:4d17cd9c8f9d | 62 | /* buffer para onde se copia os dados vindos do cb para tratameno interno */ |
klauss | 91:c2a86b1f8aaa | 63 | uint8_t buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 91:c2a86b1f8aaa | 64 | |
klauss | 0:4d17cd9c8f9d | 65 | /* buffer de escrita do pacote de saida que sera enviado pro cb / servidor */ |
klauss | 0:4d17cd9c8f9d | 66 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 91:c2a86b1f8aaa | 67 | |
klauss | 0:4d17cd9c8f9d | 68 | /* ponteiro que aponta para os dados vindo do CPLD */ |
klauss | 0:4d17cd9c8f9d | 69 | uint8_t * buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 91:c2a86b1f8aaa | 70 | |
klauss | 62:07e5bdc9f8f7 | 71 | /* Armazena o ultimo pacote recebido dos CBx */ |
klauss | 62:07e5bdc9f8f7 | 72 | uint8_t cb_rx_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 91:c2a86b1f8aaa | 73 | |
klauss | 0:4d17cd9c8f9d | 74 | /* referencia para os dados contidos no pacote, sem o header */ |
klauss | 0:4d17cd9c8f9d | 75 | uint8_t * data = NULL; |
klauss | 91:c2a86b1f8aaa | 76 | |
klauss | 0:4d17cd9c8f9d | 77 | /* gerencia o tipo do pacote para providenciar tratamento adequado */ |
klauss | 0:4d17cd9c8f9d | 78 | volatile uint8_t type = __DO_NOTHING__; |
klauss | 91:c2a86b1f8aaa | 79 | |
klauss | 87:679ee0d594a9 | 80 | /* representa a lista dos Call Boxes atualmente recfonhecidos pela cabeceira */ |
klauss | 0:4d17cd9c8f9d | 81 | Vector * v_cb = new Vector(); |
klauss | 91:c2a86b1f8aaa | 82 | |
klauss | 0:4d17cd9c8f9d | 83 | /* representa a lista de ligacoes ativas na cabeceira */ |
klauss | 0:4d17cd9c8f9d | 84 | Vector * v_call = new Vector(); |
klauss | 91:c2a86b1f8aaa | 85 | |
klauss | 0:4d17cd9c8f9d | 86 | /* gerencia a distribuicao de timeslice para os call boxes */ |
klauss | 0:4d17cd9c8f9d | 87 | Timeslice * ts = new Timeslice(); |
klauss | 91:c2a86b1f8aaa | 88 | if( ts == NULL ) { |
klauss | 89:0fe315117b00 | 89 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 90 | if( debug_memory ) debug_msg("TS allocation fail"); |
klauss | 89:0fe315117b00 | 91 | } |
klauss | 91:c2a86b1f8aaa | 92 | |
klauss | 81:3656f00ab3db | 93 | /* instancia o vetor de call boxes // calls */ |
klauss | 91:c2a86b1f8aaa | 94 | if( v_cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 95 | while( v_cb == NULL ) { |
klauss | 0:4d17cd9c8f9d | 96 | Vector * v_cb = new Vector(); |
klauss | 91:c2a86b1f8aaa | 97 | if( sync_timer.read() > 5 ) { |
klauss | 48:195c97f12e8e | 98 | send_msg("Erro ao alocar o vetor de CBx"); |
klauss | 78:1353744f01e1 | 99 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 100 | } |
klauss | 0:4d17cd9c8f9d | 101 | } |
klauss | 91:c2a86b1f8aaa | 102 | } else if( v_call == NULL ) { |
klauss | 91:c2a86b1f8aaa | 103 | while( v_call == NULL ) { |
klauss | 0:4d17cd9c8f9d | 104 | Vector * v_call = new Vector(); |
klauss | 91:c2a86b1f8aaa | 105 | if( sync_timer.read() > 5 ) { |
klauss | 48:195c97f12e8e | 106 | send_msg("Erro ao alocar o vetor de Calls"); |
klauss | 78:1353744f01e1 | 107 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 108 | } |
klauss | 0:4d17cd9c8f9d | 109 | } |
klauss | 0:4d17cd9c8f9d | 110 | } |
klauss | 91:c2a86b1f8aaa | 111 | |
klauss | 91:c2a86b1f8aaa | 112 | if( v_cb == NULL ) { |
klauss | 89:0fe315117b00 | 113 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 114 | if( debug_memory ) debug_msg("Call_Box vector allocation fail"); |
klauss | 89:0fe315117b00 | 115 | } |
klauss | 91:c2a86b1f8aaa | 116 | |
klauss | 91:c2a86b1f8aaa | 117 | if( v_call == NULL ) { |
klauss | 89:0fe315117b00 | 118 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 119 | if( debug_memory ) debug_msg("Call vector allocation fail"); |
klauss | 89:0fe315117b00 | 120 | } |
klauss | 91:c2a86b1f8aaa | 121 | |
klauss | 91:c2a86b1f8aaa | 122 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) { |
klauss | 63:0d95da692bb4 | 123 | cb_rx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 124 | cb_tx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 125 | } |
klauss | 91:c2a86b1f8aaa | 126 | |
klauss | 0:4d17cd9c8f9d | 127 | reset_leds(); |
klauss | 91:c2a86b1f8aaa | 128 | |
klauss | 33:735fd60e96d8 | 129 | udp_timer.start(); |
klauss | 91:c2a86b1f8aaa | 130 | |
klauss | 68:b54993674190 | 131 | init_telemetry_handler(); |
klauss | 99:e80850c51106 | 132 | |
klauss | 99:e80850c51106 | 133 | //debug_msg(""); |
klauss | 99:e80850c51106 | 134 | init_fw_handler(); |
klauss | 99:e80850c51106 | 135 | //debug_msg(""); |
klauss | 99:e80850c51106 | 136 | |
klauss | 99:e80850c51106 | 137 | led2 = 0; |
klauss | 81:3656f00ab3db | 138 | init_ranges(); |
klauss | 91:c2a86b1f8aaa | 139 | |
klauss | 80:61d61c9eb75c | 140 | init_refresh(); |
klauss | 91:c2a86b1f8aaa | 141 | |
klauss | 78:1353744f01e1 | 142 | init_aging(); |
klauss | 91:c2a86b1f8aaa | 143 | |
klauss | 89:0fe315117b00 | 144 | init_sync_refresh(); |
klauss | 91:c2a86b1f8aaa | 145 | |
klauss | 81:3656f00ab3db | 146 | //init_invite_pgk_retry_manager(); |
klauss | 91:c2a86b1f8aaa | 147 | |
klauss | 81:3656f00ab3db | 148 | //void init_bye_pgk_retry_manager(); |
klauss | 91:c2a86b1f8aaa | 149 | |
klauss | 62:07e5bdc9f8f7 | 150 | static uint8_t count = 0; |
klauss | 91:c2a86b1f8aaa | 151 | |
klauss | 89:0fe315117b00 | 152 | //short int bl_ret = init_bl_handler(); |
klauss | 89:0fe315117b00 | 153 | //if( dbl ) send_msg("Valor de retorno do bl_habdler = %d", bl_ret ); |
klauss | 91:c2a86b1f8aaa | 154 | |
klauss | 78:1353744f01e1 | 155 | uint8_t max_registered_cbx = 0; |
klauss | 91:c2a86b1f8aaa | 156 | |
klauss | 81:3656f00ab3db | 157 | bool wake_all = false; |
klauss | 91:c2a86b1f8aaa | 158 | |
klauss | 81:3656f00ab3db | 159 | uint16_t pkg_wdt = RX_CB_IDLE; |
klauss | 81:3656f00ab3db | 160 | uint16_t eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 83:b8a1d8fdeaeb | 161 | uint32_t uptime = 0; |
klauss | 99:e80850c51106 | 162 | led1 = 0; |
klauss | 68:b54993674190 | 163 | send_msg("Ready"); |
klauss | 91:c2a86b1f8aaa | 164 | |
klauss | 92:92df17f538a8 | 165 | //bool registry_test = false; |
klauss | 92:92df17f538a8 | 166 | //static int next_value = 5002; |
klauss | 92:92df17f538a8 | 167 | //static int nex_test_registry = next_value; |
klauss | 92:92df17f538a8 | 168 | |
klauss | 99:e80850c51106 | 169 | //bool invite_retry_time = false; |
klauss | 99:e80850c51106 | 170 | Timer invite_retry_timer; |
klauss | 99:e80850c51106 | 171 | invite_retry_timer.start(); |
klauss | 91:c2a86b1f8aaa | 172 | |
klauss | 78:1353744f01e1 | 173 | /*------------------------------------------ main loop ---------------------------------------------------------------*/ |
klauss | 91:c2a86b1f8aaa | 174 | while( true ) { |
klauss | 99:e80850c51106 | 175 | reset_leds(); |
klauss | 99:e80850c51106 | 176 | |
klauss | 78:1353744f01e1 | 177 | if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 178 | |
klauss | 91:c2a86b1f8aaa | 179 | if( sync_timer.read() > 5 ) { |
klauss | 78:1353744f01e1 | 180 | sync_timer.reset(); |
klauss | 91:c2a86b1f8aaa | 181 | |
klauss | 91:c2a86b1f8aaa | 182 | if( debug_cks == true ) { |
klauss | 81:3656f00ab3db | 183 | pcks_s = true; |
klauss | 78:1353744f01e1 | 184 | } |
klauss | 91:c2a86b1f8aaa | 185 | |
klauss | 91:c2a86b1f8aaa | 186 | if( debug_alive == true ) { |
klauss | 81:3656f00ab3db | 187 | pshowcb = true; |
klauss | 78:1353744f01e1 | 188 | } |
klauss | 91:c2a86b1f8aaa | 189 | |
klauss | 91:c2a86b1f8aaa | 190 | if( !( ++count % 15 ) ) { |
klauss | 91:c2a86b1f8aaa | 191 | if( eth_status ) { |
klauss | 78:1353744f01e1 | 192 | eth_status = __init_eth__(); |
klauss | 91:c2a86b1f8aaa | 193 | if( eth_status ) { |
klauss | 78:1353744f01e1 | 194 | if( debug_main ) debug_msg("Cannot connect to eth"); |
klauss | 91:c2a86b1f8aaa | 195 | } else { |
klauss | 78:1353744f01e1 | 196 | if( debug_main ) debug_msg("Connection eth - ok"); |
klauss | 78:1353744f01e1 | 197 | init_prompt_eth(); |
klauss | 82:f55d13babca0 | 198 | init_external_wdt() |
klauss | 78:1353744f01e1 | 199 | } |
klauss | 78:1353744f01e1 | 200 | } |
klauss | 78:1353744f01e1 | 201 | } |
klauss | 81:3656f00ab3db | 202 | //35 sec. |
klauss | 91:c2a86b1f8aaa | 203 | if( ( count > 7 ) && ( wake_all == false ) ) { |
klauss | 81:3656f00ab3db | 204 | wake_all = true; |
klauss | 78:1353744f01e1 | 205 | if( debug_wake == true ) send_msg( "Time to wake" ); |
klauss | 78:1353744f01e1 | 206 | } |
klauss | 78:1353744f01e1 | 207 | } |
klauss | 91:c2a86b1f8aaa | 208 | |
klauss | 68:b54993674190 | 209 | //FIXMEj colocar uma condicao aqui caso necessario pra nao comprometer ligacoes ... |
klauss | 35:96885a7931f0 | 210 | prompt_process( NULL ); |
klauss | 91:c2a86b1f8aaa | 211 | |
klauss | 91:c2a86b1f8aaa | 212 | if( r_stats ) { |
klauss | 91:c2a86b1f8aaa | 213 | boot_counter = 0; |
klauss | 91:c2a86b1f8aaa | 214 | registry_counter = 0; |
klauss | 91:c2a86b1f8aaa | 215 | invite_counter = 0; |
klauss | 91:c2a86b1f8aaa | 216 | audio_counter = 0; |
klauss | 91:c2a86b1f8aaa | 217 | telemetry_counter = 0; |
klauss | 91:c2a86b1f8aaa | 218 | cb_bye_counter = 0; |
klauss | 91:c2a86b1f8aaa | 219 | prompt_counter = 0; |
klauss | 91:c2a86b1f8aaa | 220 | flood_counter = 0; |
klauss | 67:cdedc64d9921 | 221 | bootloader_cbx_counter = 0; |
klauss | 99:e80850c51106 | 222 | cb_stats_counter = 0; |
klauss | 63:0d95da692bb4 | 223 | r_stats = false; |
klauss | 63:0d95da692bb4 | 224 | stats = true; |
klauss | 63:0d95da692bb4 | 225 | } |
klauss | 91:c2a86b1f8aaa | 226 | |
klauss | 91:c2a86b1f8aaa | 227 | if( stats ) { |
klauss | 63:0d95da692bb4 | 228 | char str[ 200 ]; |
klauss | 99:e80850c51106 | 229 | snprintf( str, 200, "\n\rReceived Pkgs::\n\r Boot :: %u\n\r Registry :: %u\n\r Invite :: %u\n\r Audio :: %u\n\r Telemetry :: %u\n\r CB_stats :: %u\n\r CB_bye :: %u\n\r Prompt :: %u\n\r Flood :: %u\n\r Bootloader_cbx :: %u\n\r", |
klauss | 99:e80850c51106 | 230 | boot_counter, registry_counter, invite_counter, audio_counter, telemetry_counter, cb_stats_counter, cb_bye_counter, prompt_counter, flood_counter, bootloader_cbx_counter ); |
klauss | 63:0d95da692bb4 | 231 | send_msg( str ); |
klauss | 63:0d95da692bb4 | 232 | stats =false; |
klauss | 63:0d95da692bb4 | 233 | } |
klauss | 91:c2a86b1f8aaa | 234 | |
klauss | 91:c2a86b1f8aaa | 235 | if( list ) { |
klauss | 78:1353744f01e1 | 236 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 237 | |
klauss | 78:1353744f01e1 | 238 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 91:c2a86b1f8aaa | 239 | |
klauss | 78:1353744f01e1 | 240 | if( min_ext % 2 ) missed_cb++; |
klauss | 91:c2a86b1f8aaa | 241 | |
klauss | 78:1353744f01e1 | 242 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 91:c2a86b1f8aaa | 243 | |
klauss | 78:1353744f01e1 | 244 | 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 | 91:c2a86b1f8aaa | 245 | if( v_cb->size() == 1 ) { |
klauss | 78:1353744f01e1 | 246 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 91:c2a86b1f8aaa | 247 | } else if( v_cb->size() > 1 ) { |
klauss | 62:07e5bdc9f8f7 | 248 | char str[ 1024 ]; |
klauss | 78:1353744f01e1 | 249 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 62:07e5bdc9f8f7 | 250 | register int i = 0; |
klauss | 91:c2a86b1f8aaa | 251 | for( ; i < v_cb->size(); i++ ) { |
klauss | 78:1353744f01e1 | 252 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 62:07e5bdc9f8f7 | 253 | } |
klauss | 91:c2a86b1f8aaa | 254 | |
klauss | 62:07e5bdc9f8f7 | 255 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 91:c2a86b1f8aaa | 256 | |
klauss | 62:07e5bdc9f8f7 | 257 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 258 | strcpy( str, "\r\n> " ); |
klauss | 91:c2a86b1f8aaa | 259 | for( i = 0; i < v_cb->size() - 1; i++ ) { |
klauss | 62:07e5bdc9f8f7 | 260 | sprintf( aux, "%i, ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 261 | strcat( str, aux ); |
klauss | 78:1353744f01e1 | 262 | if( ( i != 0 ) && !( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 263 | } |
klauss | 62:07e5bdc9f8f7 | 264 | sprintf( aux, "%i ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 265 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 266 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 267 | } |
klauss | 91:c2a86b1f8aaa | 268 | list = false; |
klauss | 62:07e5bdc9f8f7 | 269 | } |
klauss | 91:c2a86b1f8aaa | 270 | |
klauss | 91:c2a86b1f8aaa | 271 | if( long_list ) { |
klauss | 81:3656f00ab3db | 272 | //FIXME implementar um algoritmo que me mostre o timeout de cada cbx do lado da linha, desse. |
klauss | 85:b6f2dc1d0f4f | 273 | /* |
klauss | 81:3656f00ab3db | 274 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 275 | |
klauss | 81:3656f00ab3db | 276 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 91:c2a86b1f8aaa | 277 | |
klauss | 81:3656f00ab3db | 278 | if( min_ext % 2 ) missed_cb++; |
klauss | 91:c2a86b1f8aaa | 279 | |
klauss | 81:3656f00ab3db | 280 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 91:c2a86b1f8aaa | 281 | |
klauss | 81:3656f00ab3db | 282 | 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 | 283 | if( v_cb->size() == 1 ){ |
klauss | 81:3656f00ab3db | 284 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 81:3656f00ab3db | 285 | }else if( v_cb->size() > 1 ){ |
klauss | 81:3656f00ab3db | 286 | char str[ 1024 ]; |
klauss | 81:3656f00ab3db | 287 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 81:3656f00ab3db | 288 | register int i = 0; |
klauss | 81:3656f00ab3db | 289 | for( ; i < ( v_cb->size() * 2 ); i += 2 ){ |
klauss | 81:3656f00ab3db | 290 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 81:3656f00ab3db | 291 | ext_list[ i + 1 ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_elapsed_time(); |
klauss | 81:3656f00ab3db | 292 | } |
klauss | 91:c2a86b1f8aaa | 293 | |
klauss | 81:3656f00ab3db | 294 | qsort( ext_list, v_cb->size(), sizeof( int ) * 2, ls_comp ); |
klauss | 91:c2a86b1f8aaa | 295 | |
klauss | 81:3656f00ab3db | 296 | char aux[ 16 ]; |
klauss | 81:3656f00ab3db | 297 | strcpy( str, "\r\n> " ); |
klauss | 81:3656f00ab3db | 298 | for( i = 0; i < ( v_cb->size() * 2 ) - 2; i++ ){ |
klauss | 81:3656f00ab3db | 299 | sprintf( aux, "%i - %i,", ext_list[ i ], ext_list[ i + 1 ] ); |
klauss | 81:3656f00ab3db | 300 | strcat( str, aux ); |
klauss | 81:3656f00ab3db | 301 | strcat( str, "\r\n> " ); |
klauss | 81:3656f00ab3db | 302 | } |
klauss | 81:3656f00ab3db | 303 | sprintf( aux, "%i - %i,", ext_list[ i ], ext_list[ i + 1 ] ); |
klauss | 81:3656f00ab3db | 304 | strcat( str, aux ); |
klauss | 81:3656f00ab3db | 305 | send_msg( "%s", str ); |
klauss | 81:3656f00ab3db | 306 | } |
klauss | 85:b6f2dc1d0f4f | 307 | */ |
klauss | 91:c2a86b1f8aaa | 308 | long_list = false; |
klauss | 52:12930cef17c4 | 309 | } |
klauss | 91:c2a86b1f8aaa | 310 | |
klauss | 91:c2a86b1f8aaa | 311 | if( pshowcb == true ) { |
klauss | 78:1353744f01e1 | 312 | 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() ); |
klauss | 91:c2a86b1f8aaa | 313 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 30:8dfb6d8de53d | 314 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 315 | char cb_status[ 32 ]; |
klauss | 78:1353744f01e1 | 316 | char cb_sip_status[ 32 ]; |
klauss | 91:c2a86b1f8aaa | 317 | switch( cb->status ) { |
klauss | 91:c2a86b1f8aaa | 318 | case cb_idle : { |
klauss | 91:c2a86b1f8aaa | 319 | strcpy( cb_status, "cb_idle" ); |
klauss | 91:c2a86b1f8aaa | 320 | break; |
klauss | 91:c2a86b1f8aaa | 321 | } |
klauss | 91:c2a86b1f8aaa | 322 | case cb_ringing : { |
klauss | 91:c2a86b1f8aaa | 323 | strcpy( cb_status, "cb_ringing" ); |
klauss | 91:c2a86b1f8aaa | 324 | break; |
klauss | 91:c2a86b1f8aaa | 325 | } |
klauss | 91:c2a86b1f8aaa | 326 | case cb_trying : { |
klauss | 91:c2a86b1f8aaa | 327 | strcpy( cb_status,"cb_trying" ); |
klauss | 91:c2a86b1f8aaa | 328 | break; |
klauss | 91:c2a86b1f8aaa | 329 | } |
klauss | 91:c2a86b1f8aaa | 330 | case cb_on_call : { |
klauss | 91:c2a86b1f8aaa | 331 | strcpy( cb_status, "cb_on_call" ); |
klauss | 91:c2a86b1f8aaa | 332 | break; |
klauss | 91:c2a86b1f8aaa | 333 | } |
klauss | 91:c2a86b1f8aaa | 334 | case cb_busy : { |
klauss | 91:c2a86b1f8aaa | 335 | strcpy( cb_status, "cb_busy" ); |
klauss | 91:c2a86b1f8aaa | 336 | break; |
klauss | 91:c2a86b1f8aaa | 337 | } |
klauss | 91:c2a86b1f8aaa | 338 | case cb_denied : { |
klauss | 91:c2a86b1f8aaa | 339 | strcpy( cb_status, "cb_denied" ); |
klauss | 91:c2a86b1f8aaa | 340 | break; |
klauss | 91:c2a86b1f8aaa | 341 | } |
klauss | 78:1353744f01e1 | 342 | } |
klauss | 91:c2a86b1f8aaa | 343 | switch( cb->sip->status ) { |
klauss | 91:c2a86b1f8aaa | 344 | case sip_idle : { |
klauss | 91:c2a86b1f8aaa | 345 | strcpy( cb_sip_status, "sip_idle" ); |
klauss | 91:c2a86b1f8aaa | 346 | break; |
klauss | 91:c2a86b1f8aaa | 347 | } |
klauss | 91:c2a86b1f8aaa | 348 | case sip_waiting_trying : { |
klauss | 91:c2a86b1f8aaa | 349 | strcpy( cb_sip_status, "sip_waiting_trying" ); |
klauss | 91:c2a86b1f8aaa | 350 | break; |
klauss | 91:c2a86b1f8aaa | 351 | } |
klauss | 91:c2a86b1f8aaa | 352 | case sip_trying : { |
klauss | 91:c2a86b1f8aaa | 353 | strcpy( cb_sip_status, "sip_trying" ); |
klauss | 91:c2a86b1f8aaa | 354 | break; |
klauss | 91:c2a86b1f8aaa | 355 | } |
klauss | 91:c2a86b1f8aaa | 356 | case sip_ringing : { |
klauss | 91:c2a86b1f8aaa | 357 | strcpy( cb_sip_status, "sip_ringing" ); |
klauss | 91:c2a86b1f8aaa | 358 | break; |
klauss | 91:c2a86b1f8aaa | 359 | } |
klauss | 91:c2a86b1f8aaa | 360 | case sip_busy : { |
klauss | 91:c2a86b1f8aaa | 361 | strcpy( cb_sip_status, "sip_busy" ); |
klauss | 91:c2a86b1f8aaa | 362 | break; |
klauss | 91:c2a86b1f8aaa | 363 | } |
klauss | 91:c2a86b1f8aaa | 364 | case sip_ok : { |
klauss | 91:c2a86b1f8aaa | 365 | strcpy( cb_sip_status, "sip_ok" ); |
klauss | 91:c2a86b1f8aaa | 366 | break; |
klauss | 91:c2a86b1f8aaa | 367 | } |
klauss | 91:c2a86b1f8aaa | 368 | case sip_on_call : { |
klauss | 91:c2a86b1f8aaa | 369 | strcpy( cb_sip_status, "sip_on_call" ); |
klauss | 91:c2a86b1f8aaa | 370 | break; |
klauss | 91:c2a86b1f8aaa | 371 | } |
klauss | 91:c2a86b1f8aaa | 372 | case sip_denied : { |
klauss | 91:c2a86b1f8aaa | 373 | strcpy( cb_sip_status, "sip_denied" ); |
klauss | 91:c2a86b1f8aaa | 374 | break; |
klauss | 91:c2a86b1f8aaa | 375 | } |
klauss | 78:1353744f01e1 | 376 | } |
klauss | 78:1353744f01e1 | 377 | char cbx_to_string[ 254 ]; |
klauss | 78:1353744f01e1 | 378 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 379 | strcpy( cbx_to_string, "Ext :: " ); |
klauss | 78:1353744f01e1 | 380 | itoa( cb->get_ext(), aux , 10 ); |
klauss | 98:43b45f26b430 | 381 | strcat( cbx_to_string, aux ); |
klauss | 97:8985817e8847 | 382 | strcat( cbx_to_string, " :: Port :: " ); |
klauss | 97:8985817e8847 | 383 | itoa( cb->get_port(), aux , 10 ); |
klauss | 78:1353744f01e1 | 384 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 385 | strcat( cbx_to_string, " :: Status -- " ); |
klauss | 78:1353744f01e1 | 386 | strcat( cbx_to_string, cb_status ); |
klauss | 78:1353744f01e1 | 387 | strcat( cbx_to_string, " - " ); |
klauss | 78:1353744f01e1 | 388 | strcat( cbx_to_string, cb_sip_status ); |
klauss | 91:c2a86b1f8aaa | 389 | if( cb->get_timeslice() != 0 ) { |
klauss | 78:1353744f01e1 | 390 | strcat( cbx_to_string, " -- on TimeSlice :: " ); |
klauss | 78:1353744f01e1 | 391 | itoa( cb->get_timeslice(), aux , 10 ); |
klauss | 78:1353744f01e1 | 392 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 393 | } |
klauss | 78:1353744f01e1 | 394 | send_msg( cbx_to_string ); |
klauss | 48:195c97f12e8e | 395 | } |
klauss | 78:1353744f01e1 | 396 | pshowcb = false; |
klauss | 48:195c97f12e8e | 397 | } |
klauss | 97:8985817e8847 | 398 | |
klauss | 97:8985817e8847 | 399 | if( show_sip == true ){ |
klauss | 97:8985817e8847 | 400 | show_sip = false; |
klauss | 99:e80850c51106 | 401 | send_msg(":: Sip :: %u", v_cb->size() ); |
klauss | 97:8985817e8847 | 402 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 97:8985817e8847 | 403 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 99:e80850c51106 | 404 | send_msg("ext :: %d -- port :: %d -- timer %d", cb->get_sip_ext(), cb->get_sip_port(), cb->get_timer() ); |
klauss | 97:8985817e8847 | 405 | } |
klauss | 97:8985817e8847 | 406 | } |
klauss | 91:c2a86b1f8aaa | 407 | |
klauss | 81:3656f00ab3db | 408 | if( pflood == true ) flood(); |
klauss | 91:c2a86b1f8aaa | 409 | |
klauss | 91:c2a86b1f8aaa | 410 | if( debug_eth ) { |
klauss | 81:3656f00ab3db | 411 | debug_eth = false; |
klauss | 81:3656f00ab3db | 412 | send_msg("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); |
klauss | 81:3656f00ab3db | 413 | } |
klauss | 91:c2a86b1f8aaa | 414 | |
klauss | 91:c2a86b1f8aaa | 415 | if( status != __WAITING__ ) { |
klauss | 81:3656f00ab3db | 416 | pkg_wdt = RX_CB_IDLE; |
klauss | 86:bf7b0d4c3232 | 417 | xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ ); |
klauss | 0:4d17cd9c8f9d | 418 | status = __WAITING__; |
klauss | 81:3656f00ab3db | 419 | missed_pkg--; |
klauss | 91:c2a86b1f8aaa | 420 | xmemcpy( buffer, cb_rx_buffer, __CB_BUFFER_SIZE__ ); |
klauss | 98:43b45f26b430 | 421 | |
klauss | 98:43b45f26b430 | 422 | /* |
klauss | 98:43b45f26b430 | 423 | { |
klauss | 98:43b45f26b430 | 424 | uint16_t e, p; |
klauss | 98:43b45f26b430 | 425 | e = buffer[0]; |
klauss | 98:43b45f26b430 | 426 | e <<= 8; |
klauss | 98:43b45f26b430 | 427 | e |= buffer[1]; |
klauss | 98:43b45f26b430 | 428 | p = buffer[2]; |
klauss | 98:43b45f26b430 | 429 | p <<= 8; |
klauss | 98:43b45f26b430 | 430 | p |= buffer[3]; |
klauss | 98:43b45f26b430 | 431 | //if (e != (p+100)) { |
klauss | 98:43b45f26b430 | 432 | if( ( buffer[0] == 0x14 ) && ( buffer[1] == 0x0a ) ) { |
klauss | 98:43b45f26b430 | 433 | int i; |
klauss | 98:43b45f26b430 | 434 | char s[400], ss[4];; |
klauss | 98:43b45f26b430 | 435 | strcpy(s,"OPS-PKG:"); |
klauss | 98:43b45f26b430 | 436 | for (i=0; i<40; i++) { |
klauss | 98:43b45f26b430 | 437 | sprintf(ss," %02x",buffer[i]); |
klauss | 98:43b45f26b430 | 438 | strcat(s,ss); |
klauss | 98:43b45f26b430 | 439 | } |
klauss | 98:43b45f26b430 | 440 | debug_msg( s ); |
klauss | 98:43b45f26b430 | 441 | } |
klauss | 98:43b45f26b430 | 442 | } |
klauss | 98:43b45f26b430 | 443 | */ |
klauss | 98:43b45f26b430 | 444 | |
klauss | 91:c2a86b1f8aaa | 445 | if( debug_cpld ) { |
klauss | 81:3656f00ab3db | 446 | rx = true; |
klauss | 81:3656f00ab3db | 447 | tx = true; |
klauss | 81:3656f00ab3db | 448 | } |
klauss | 91:c2a86b1f8aaa | 449 | |
klauss | 91:c2a86b1f8aaa | 450 | if( rx ) { |
klauss | 81:3656f00ab3db | 451 | char str[ 1024 ]; |
klauss | 81:3656f00ab3db | 452 | strcpy( str, "RX :: \n\r " ); |
klauss | 91:c2a86b1f8aaa | 453 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) { |
klauss | 81:3656f00ab3db | 454 | char tmp[ 16 ]; |
klauss | 81:3656f00ab3db | 455 | strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); |
klauss | 81:3656f00ab3db | 456 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 91:c2a86b1f8aaa | 457 | |
klauss | 81:3656f00ab3db | 458 | else strcat( str, " " ); |
klauss | 81:3656f00ab3db | 459 | } |
klauss | 81:3656f00ab3db | 460 | send_msg( "%s", str ); |
klauss | 91:c2a86b1f8aaa | 461 | rx = false; |
klauss | 81:3656f00ab3db | 462 | } |
klauss | 91:c2a86b1f8aaa | 463 | |
klauss | 34:f19d9735428e | 464 | data = __parse_vz_pkg__( &ext, &port, &type, buffer ); |
klauss | 91:c2a86b1f8aaa | 465 | |
klauss | 91:c2a86b1f8aaa | 466 | if( data != NULL ) { |
klauss | 78:1353744f01e1 | 467 | if( min_ext == 0 ) min_ext = ext; |
klauss | 91:c2a86b1f8aaa | 468 | |
klauss | 78:1353744f01e1 | 469 | if( ext > max_ext ) max_ext = ext; |
klauss | 91:c2a86b1f8aaa | 470 | |
klauss | 78:1353744f01e1 | 471 | if( ext < min_ext ) min_ext = ext; |
klauss | 99:e80850c51106 | 472 | |
klauss | 99:e80850c51106 | 473 | if( debug_fw ){ |
klauss | 99:e80850c51106 | 474 | fw_cbx_pkg( ext, port, ( char *)buffer ); |
klauss | 99:e80850c51106 | 475 | } |
klauss | 99:e80850c51106 | 476 | |
klauss | 99:e80850c51106 | 477 | if( type == __TELEMETRY__ ) telemetry_counter++; |
klauss | 91:c2a86b1f8aaa | 478 | |
klauss | 91:c2a86b1f8aaa | 479 | if( type != __AUDIO__ ) { |
klauss | 99:e80850c51106 | 480 | if( |
klauss | 99:e80850c51106 | 481 | type == __TELEMETRY__ || |
klauss | 99:e80850c51106 | 482 | type == __CB_STATS__ || |
klauss | 99:e80850c51106 | 483 | type == __FW1__ || |
klauss | 99:e80850c51106 | 484 | type == __FW2__ || |
klauss | 99:e80850c51106 | 485 | type == __FW3__ || |
klauss | 99:e80850c51106 | 486 | type == __FW4__ || |
klauss | 99:e80850c51106 | 487 | type == __FW5__ || |
klauss | 99:e80850c51106 | 488 | type == __FW6__ |
klauss | 99:e80850c51106 | 489 | ) type = __FW__; |
klauss | 99:e80850c51106 | 490 | |
klauss | 99:e80850c51106 | 491 | if( debug_cb_rx == true ){ |
klauss | 99:e80850c51106 | 492 | send_msg("Pkg from CBx :: ( %d, %d ) -- Type :: %d", ext, port, type ); |
klauss | 99:e80850c51106 | 493 | } |
klauss | 99:e80850c51106 | 494 | |
klauss | 0:4d17cd9c8f9d | 495 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 496 | if( cb != NULL ) { |
klauss | 92:92df17f538a8 | 497 | if( data[ 0 ] & BIT7 ) { |
klauss | 91:c2a86b1f8aaa | 498 | if( type == __BOOT__ ) { |
klauss | 91:c2a86b1f8aaa | 499 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 92:92df17f538a8 | 500 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 92:92df17f538a8 | 501 | } else { |
klauss | 81:3656f00ab3db | 502 | if( debug_main ) debug_msg("Received ack pkg with seq_num %d", data[ 0 ] ); |
klauss | 91:c2a86b1f8aaa | 503 | |
klauss | 91:c2a86b1f8aaa | 504 | switch( type ) { |
klauss | 81:3656f00ab3db | 505 | case __INVITE__ : { |
klauss | 81:3656f00ab3db | 506 | if( debug_main || debug_invite ) debug_msg("Invite Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 92:92df17f538a8 | 507 | //cb->first_invite_response_ok(); |
klauss | 91:c2a86b1f8aaa | 508 | break; |
klauss | 81:3656f00ab3db | 509 | } |
klauss | 81:3656f00ab3db | 510 | case __CB_BYE__ : { |
klauss | 81:3656f00ab3db | 511 | if( debug_main || debug_invite ) debug_msg("BYE Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 512 | cb->set_bye_response_ok(); |
klauss | 91:c2a86b1f8aaa | 513 | break; |
klauss | 81:3656f00ab3db | 514 | } |
klauss | 81:3656f00ab3db | 515 | case __REGISTRY__ : { |
klauss | 81:3656f00ab3db | 516 | if( debug_main || debug_aging ) debug_msg("Registry ACK from %d in pkg :: %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 517 | break; |
klauss | 81:3656f00ab3db | 518 | } |
klauss | 81:3656f00ab3db | 519 | default : { |
klauss | 91:c2a86b1f8aaa | 520 | if( debug_main || debug_aging ) debug_msg("ACK from %d in pkg :: %d :: type %d", ext, cb->get_msg_id(), type ); |
klauss | 91:c2a86b1f8aaa | 521 | } |
klauss | 81:3656f00ab3db | 522 | } |
klauss | 92:92df17f538a8 | 523 | if( type != __REGISTRY__ && type != __CB_BYE__ ) type = __DO_NOTHING__; |
klauss | 92:92df17f538a8 | 524 | if( type == __CB_BYE__ ){ |
klauss | 92:92df17f538a8 | 525 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 92:92df17f538a8 | 526 | if( call != NULL ){ |
klauss | 92:92df17f538a8 | 527 | if( call->get_elapsed_time() < 120000 ){ |
klauss | 92:92df17f538a8 | 528 | if( debug_invite ) debug_msg("%d ack bye ignored", ext ); |
klauss | 92:92df17f538a8 | 529 | type = __DO_NOTHING__; |
klauss | 92:92df17f538a8 | 530 | } |
klauss | 92:92df17f538a8 | 531 | } |
klauss | 92:92df17f538a8 | 532 | } |
klauss | 0:4d17cd9c8f9d | 533 | } |
klauss | 0:4d17cd9c8f9d | 534 | } |
klauss | 0:4d17cd9c8f9d | 535 | } |
klauss | 0:4d17cd9c8f9d | 536 | } |
klauss | 91:c2a86b1f8aaa | 537 | } else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 538 | } |
klauss | 91:c2a86b1f8aaa | 539 | |
klauss | 91:c2a86b1f8aaa | 540 | if( main_test == true ) { |
klauss | 87:679ee0d594a9 | 541 | main_test = false; |
klauss | 85:b6f2dc1d0f4f | 542 | send_msg("CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter ); |
klauss | 85:b6f2dc1d0f4f | 543 | send_msg("SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter ); |
klauss | 87:679ee0d594a9 | 544 | send_msg("RTP_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter ); |
klauss | 87:679ee0d594a9 | 545 | send_msg("RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter ); |
klauss | 91:c2a86b1f8aaa | 546 | send_msg("Call_New (%u) -- Call_Delete (%u)", call_new_counter, call_delete_counter ); |
klauss | 87:679ee0d594a9 | 547 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 548 | send_msg("Memory is %s", ( memory_is_over ) ? "Over" : "Ok" ); |
klauss | 81:3656f00ab3db | 549 | send_msg("Missed_Pkg :: %d ::", missed_pkg ); |
klauss | 87:679ee0d594a9 | 550 | send_msg("Sizeof Sip :: %u", sizeof( Sip ) ); |
klauss | 87:679ee0d594a9 | 551 | send_msg("Sizeof Call_Box :: %u", sizeof( Call_Box ) ); |
klauss | 87:679ee0d594a9 | 552 | send_msg("Sizeof VZ_call :: %u", sizeof( VZ_call ) ); |
klauss | 87:679ee0d594a9 | 553 | send_msg("Sizeof RTP :: %u", sizeof( RTP ) ); |
klauss | 87:679ee0d594a9 | 554 | send_msg("Sizeof RTP_Header :: %u", sizeof( RTP_Header ) ); |
klauss | 87:679ee0d594a9 | 555 | send_msg("Sizeof RTP_Body :: %u", sizeof( RTP_Body ) ); |
klauss | 87:679ee0d594a9 | 556 | send_msg("Sizeof Vector :: %u", sizeof( Vector ) ); |
klauss | 87:679ee0d594a9 | 557 | send_msg("Sizeof Timeslice :: %u", sizeof( Timeslice ) ); |
klauss | 87:679ee0d594a9 | 558 | send_msg("Sizeof Watchdog :: %u", sizeof( Watchdog ) ); |
klauss | 81:3656f00ab3db | 559 | } |
klauss | 91:c2a86b1f8aaa | 560 | |
klauss | 92:92df17f538a8 | 561 | //static int wdt_count = 0; |
klauss | 92:92df17f538a8 | 562 | /* |
klauss | 91:c2a86b1f8aaa | 563 | if( registry_test == true ) { |
klauss | 91:c2a86b1f8aaa | 564 | registry_test = false; |
klauss | 91:c2a86b1f8aaa | 565 | |
klauss | 91:c2a86b1f8aaa | 566 | if( wdt_count++ > 5 || v_cb->size() < 66 ) { |
klauss | 89:0fe315117b00 | 567 | wdt_count = 0; |
klauss | 91:c2a86b1f8aaa | 568 | |
klauss | 91:c2a86b1f8aaa | 569 | if( type == __DO_NOTHING__ ) { |
klauss | 91:c2a86b1f8aaa | 570 | if( next_value < ( 5002 + __MAX_CB_IN_A_BRANCH__ - 2 ) ) { |
klauss | 91:c2a86b1f8aaa | 571 | //type = __REGISTRY__; |
klauss | 89:0fe315117b00 | 572 | data = buffer; |
klauss | 89:0fe315117b00 | 573 | ext = next_value; |
klauss | 89:0fe315117b00 | 574 | port = next_value++; |
klauss | 91:c2a86b1f8aaa | 575 | } else { |
klauss | 91:c2a86b1f8aaa | 576 | if( nex_test_registry > ( 5002 + __MAX_CB_IN_A_BRANCH__ - 1 - 2 ) ) nex_test_registry = 5002; |
klauss | 91:c2a86b1f8aaa | 577 | //type = __REGISTRY__; |
klauss | 89:0fe315117b00 | 578 | data = buffer; |
klauss | 89:0fe315117b00 | 579 | ext = nex_test_registry; |
klauss | 89:0fe315117b00 | 580 | port = nex_test_registry++; |
klauss | 89:0fe315117b00 | 581 | } |
klauss | 86:bf7b0d4c3232 | 582 | } |
klauss | 86:bf7b0d4c3232 | 583 | } |
klauss | 86:bf7b0d4c3232 | 584 | } |
klauss | 92:92df17f538a8 | 585 | */ |
klauss | 92:92df17f538a8 | 586 | |
klauss | 91:c2a86b1f8aaa | 587 | { |
klauss | 91:c2a86b1f8aaa | 588 | fd_set fdSet; |
klauss | 91:c2a86b1f8aaa | 589 | FD_ZERO(&fdSet); |
klauss | 91:c2a86b1f8aaa | 590 | |
klauss | 91:c2a86b1f8aaa | 591 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 91:c2a86b1f8aaa | 592 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 91:c2a86b1f8aaa | 593 | FD_SET( cb->get_sip_socket_fd(), &fdSet); |
klauss | 91:c2a86b1f8aaa | 594 | } |
klauss | 91:c2a86b1f8aaa | 595 | |
klauss | 91:c2a86b1f8aaa | 596 | FD_SET( udp_wdt_client.get_fd(), &fdSet); |
klauss | 91:c2a86b1f8aaa | 597 | |
klauss | 91:c2a86b1f8aaa | 598 | struct timeval t; |
klauss | 91:c2a86b1f8aaa | 599 | t.tv_sec = 0; |
klauss | 91:c2a86b1f8aaa | 600 | t.tv_usec = 0; |
klauss | 91:c2a86b1f8aaa | 601 | int ret = lwip_select( FD_SETSIZE, &fdSet, NULL, NULL, &t ); |
klauss | 91:c2a86b1f8aaa | 602 | |
klauss | 91:c2a86b1f8aaa | 603 | if(ret > 0 ) { |
klauss | 91:c2a86b1f8aaa | 604 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 91:c2a86b1f8aaa | 605 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 91:c2a86b1f8aaa | 606 | int fd = cb->get_sip_socket_fd(); |
klauss | 91:c2a86b1f8aaa | 607 | if( FD_ISSET( fd, &fdSet ) ) { |
klauss | 91:c2a86b1f8aaa | 608 | int rcv = cb->sip_udp_incomming_pkg(); |
klauss | 91:c2a86b1f8aaa | 609 | } |
klauss | 91:c2a86b1f8aaa | 610 | } |
klauss | 91:c2a86b1f8aaa | 611 | if( FD_ISSET( udp_wdt_client.get_fd(), &fdSet ) ) { |
klauss | 91:c2a86b1f8aaa | 612 | char wake_msg[ 768 ]; |
klauss | 91:c2a86b1f8aaa | 613 | Endpoint udp_wdt_server; |
klauss | 91:c2a86b1f8aaa | 614 | |
klauss | 91:c2a86b1f8aaa | 615 | if( udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) ) > 0 ){ |
klauss | 91:c2a86b1f8aaa | 616 | if( !( strncmp( wake_msg, "alive", 5 ) ) ) { |
klauss | 91:c2a86b1f8aaa | 617 | // Just ckeck but not set 'alive?' |
klauss | 91:c2a86b1f8aaa | 618 | // 'alive*' - force wdt tick right now |
klauss | 91:c2a86b1f8aaa | 619 | // Ckecking and set 'alive' |
klauss | 91:c2a86b1f8aaa | 620 | bool question_alive = ( wake_msg[ 5 ] == '?' ); |
klauss | 91:c2a86b1f8aaa | 621 | if( wake_msg[ 5 ] == '*' ) wdt.kick(); |
klauss | 99:e80850c51106 | 622 | |
klauss | 99:e80850c51106 | 623 | /* |
klauss | 99:e80850c51106 | 624 | uint8_t registered_cbx = v_cb->size(); |
klauss | 99:e80850c51106 | 625 | for( register int i = 0; i < v_cb->size(); i++ ){ |
klauss | 99:e80850c51106 | 626 | Call_Box * cb = (Call_Box * )v_cb->get_element( i ); |
klauss | 99:e80850c51106 | 627 | if( cb->is_timeout() ){ if( registered_cbx ) registered_cbx--; } |
klauss | 99:e80850c51106 | 628 | } |
klauss | 99:e80850c51106 | 629 | */ |
klauss | 99:e80850c51106 | 630 | |
klauss | 99:e80850c51106 | 631 | snprintf( wake_msg, 48,"wdt:%u,%u,%u,%c,%u,%u,%u,%u,%u:", |
klauss | 99:e80850c51106 | 632 | uptime, |
klauss | 99:e80850c51106 | 633 | invite_counter, |
klauss | 99:e80850c51106 | 634 | external_wdt, |
klauss | 99:e80850c51106 | 635 | ( wdt.WatchdogCausedReset() ) ? '1' : '0', |
klauss | 99:e80850c51106 | 636 | cb_new_counter, |
klauss | 99:e80850c51106 | 637 | v_cb->size(), |
klauss | 99:e80850c51106 | 638 | ts->remain_timeslices(), |
klauss | 99:e80850c51106 | 639 | sip_socket_send_failure, |
klauss | 99:e80850c51106 | 640 | v_call->size() |
klauss | 99:e80850c51106 | 641 | // registered_cbx |
klauss | 99:e80850c51106 | 642 | ); |
klauss | 92:92df17f538a8 | 643 | wake_msg[ 768 - 1 ] = 0; |
klauss | 91:c2a86b1f8aaa | 644 | udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 91:c2a86b1f8aaa | 645 | |
klauss | 91:c2a86b1f8aaa | 646 | if( ( (!question_alive) && ( cb_new_counter <= __MAX_CB_IN_A_BRANCH__ ) && ( cb_new_counter >= 2 ) ) ) { |
klauss | 91:c2a86b1f8aaa | 647 | external_wdt = EXTERN_WDT_IDLE; |
klauss | 91:c2a86b1f8aaa | 648 | } |
klauss | 91:c2a86b1f8aaa | 649 | } else if( !( strncmp( wake_msg, "reset", 5 ) ) ) { |
klauss | 91:c2a86b1f8aaa | 650 | external_wdt = 0; |
klauss | 91:c2a86b1f8aaa | 651 | |
klauss | 91:c2a86b1f8aaa | 652 | sprintf( wake_msg, "rst:%u:", uptime ); |
klauss | 91:c2a86b1f8aaa | 653 | udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 91:c2a86b1f8aaa | 654 | } |
klauss | 91:c2a86b1f8aaa | 655 | } |
klauss | 91:c2a86b1f8aaa | 656 | } |
klauss | 91:c2a86b1f8aaa | 657 | } |
klauss | 91:c2a86b1f8aaa | 658 | } |
klauss | 91:c2a86b1f8aaa | 659 | |
klauss | 91:c2a86b1f8aaa | 660 | if( reset_cks == true ) { |
klauss | 81:3656f00ab3db | 661 | pkg_cksok = 0; |
klauss | 81:3656f00ab3db | 662 | pkg_ckserr = 0; |
klauss | 99:e80850c51106 | 663 | pkg_zero = 0; |
klauss | 81:3656f00ab3db | 664 | reset_cks = false; |
klauss | 99:e80850c51106 | 665 | out_of_range = 0; |
klauss | 99:e80850c51106 | 666 | missed_pkg = 0; |
klauss | 99:e80850c51106 | 667 | droped_pkg_to_cb = 0; |
klauss | 99:e80850c51106 | 668 | cpld_pkg_tx_counter = 0; |
klauss | 99:e80850c51106 | 669 | cpld_pkg_rx_counter = 0; |
klauss | 81:3656f00ab3db | 670 | pcks_s = true; |
klauss | 81:3656f00ab3db | 671 | } |
klauss | 91:c2a86b1f8aaa | 672 | |
klauss | 91:c2a86b1f8aaa | 673 | if( pcks_s == true ) { |
klauss | 99:e80850c51106 | 674 | send_msg("PKG_CKS OK: %d :: PKG_CKS ERR: %d :: PKG_0: %d :: Out_of_range: %d :: Miss_Pkg :: %d" |
klauss | 99:e80850c51106 | 675 | "\n\rTX_MISS :: %d :: TX_Counter :: %d :: RX_Counter :: %d", pkg_cksok, pkg_ckserr, pkg_zero, out_of_range, missed_pkg, droped_pkg_to_cb, cpld_pkg_tx_counter, cpld_pkg_rx_counter ); |
klauss | 81:3656f00ab3db | 676 | pcks_s = false; |
klauss | 81:3656f00ab3db | 677 | } |
klauss | 91:c2a86b1f8aaa | 678 | |
klauss | 91:c2a86b1f8aaa | 679 | if( led_sync_timer.read() > 1 ) { |
klauss | 78:1353744f01e1 | 680 | led_sync_timer.reset(); |
klauss | 78:1353744f01e1 | 681 | led3 = !led3; |
klauss | 78:1353744f01e1 | 682 | CAB_LED = !CAB_LED; |
klauss | 78:1353744f01e1 | 683 | } |
klauss | 91:c2a86b1f8aaa | 684 | |
klauss | 91:c2a86b1f8aaa | 685 | switch( type ) { |
klauss | 91:c2a86b1f8aaa | 686 | case __DO_NOTHING__ : |
klauss | 91:c2a86b1f8aaa | 687 | {} |
klauss | 91:c2a86b1f8aaa | 688 | break; |
klauss | 91:c2a86b1f8aaa | 689 | |
klauss | 0:4d17cd9c8f9d | 690 | case __CB_BYE__ : { |
klauss | 63:0d95da692bb4 | 691 | cb_bye_counter++; |
klauss | 0:4d17cd9c8f9d | 692 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 693 | if( cb != NULL ) { |
klauss | 81:3656f00ab3db | 694 | 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 | 695 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 696 | cb->set_msg_id( data[ 0 ] ); |
klauss | 81:3656f00ab3db | 697 | if( debug_main || debug_invite ) debug_msg( "Request bye from CBx " ); |
klauss | 92:92df17f538a8 | 698 | |
klauss | 96:b4660d559ac3 | 699 | //debug_msg("----------"); |
klauss | 92:92df17f538a8 | 700 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 92:92df17f538a8 | 701 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 96:b4660d559ac3 | 702 | //debug_msg("--%d--", call->get_cb_ext() ); |
klauss | 92:92df17f538a8 | 703 | } |
klauss | 96:b4660d559ac3 | 704 | //debug_msg("----------"); |
klauss | 92:92df17f538a8 | 705 | |
klauss | 81:3656f00ab3db | 706 | bool already_removed = true; |
klauss | 91:c2a86b1f8aaa | 707 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 0:4d17cd9c8f9d | 708 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 91:c2a86b1f8aaa | 709 | if( call->get_cb_ext() == ext ) { |
klauss | 81:3656f00ab3db | 710 | already_removed = false; |
klauss | 4:de46f0d9b14d | 711 | cb->send_bye(); |
klauss | 91:c2a86b1f8aaa | 712 | |
klauss | 0:4d17cd9c8f9d | 713 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 714 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 715 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 91:c2a86b1f8aaa | 716 | |
klauss | 0:4d17cd9c8f9d | 717 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 718 | set_status( cb->sip->status, sip_idle ); |
klauss | 91:c2a86b1f8aaa | 719 | |
klauss | 81:3656f00ab3db | 720 | v_call->remove_element( i ); |
klauss | 92:92df17f538a8 | 721 | |
klauss | 92:92df17f538a8 | 722 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 92:92df17f538a8 | 723 | //cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 91:c2a86b1f8aaa | 724 | |
klauss | 74:81c47fff88a5 | 725 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 726 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 92:92df17f538a8 | 727 | |
klauss | 92:92df17f538a8 | 728 | // envia o ack bye depois atualiza o msg_id |
klauss | 92:92df17f538a8 | 729 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 91:c2a86b1f8aaa | 730 | |
klauss | 3:cd9148672e25 | 731 | delete( call ); |
klauss | 99:e80850c51106 | 732 | //cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 733 | } |
klauss | 0:4d17cd9c8f9d | 734 | } |
klauss | 82:f55d13babca0 | 735 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from vector call" ); |
klauss | 91:c2a86b1f8aaa | 736 | |
klauss | 82:f55d13babca0 | 737 | //ok, mas nem sempre o cbx "entrou em call |
klauss | 82:f55d13babca0 | 738 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 82:f55d13babca0 | 739 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 82:f55d13babca0 | 740 | if( cb->get_ext() == ext ) { |
klauss | 82:f55d13babca0 | 741 | already_removed = true; |
klauss | 82:f55d13babca0 | 742 | if( cb->get_status() != cb_idle ) { |
klauss | 82:f55d13babca0 | 743 | already_removed = false; |
klauss | 82:f55d13babca0 | 744 | cb->send_bye(); |
klauss | 82:f55d13babca0 | 745 | |
klauss | 82:f55d13babca0 | 746 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 82:f55d13babca0 | 747 | cb->set_timeslice( 0x00 ); |
klauss | 82:f55d13babca0 | 748 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 82:f55d13babca0 | 749 | |
klauss | 82:f55d13babca0 | 750 | set_status( cb->status, cb_idle ); |
klauss | 82:f55d13babca0 | 751 | set_status( cb->sip->status, sip_idle ); |
klauss | 82:f55d13babca0 | 752 | |
klauss | 82:f55d13babca0 | 753 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 92:92df17f538a8 | 754 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 82:f55d13babca0 | 755 | |
klauss | 92:92df17f538a8 | 756 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 92:92df17f538a8 | 757 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 82:f55d13babca0 | 758 | |
klauss | 99:e80850c51106 | 759 | //cb->re_start_timer(); |
klauss | 82:f55d13babca0 | 760 | } |
klauss | 82:f55d13babca0 | 761 | } |
klauss | 82:f55d13babca0 | 762 | } |
klauss | 91:c2a86b1f8aaa | 763 | |
klauss | 82:f55d13babca0 | 764 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from inviting queue" ); |
klauss | 91:c2a86b1f8aaa | 765 | |
klauss | 78:1353744f01e1 | 766 | cb->registry(); |
klauss | 91:c2a86b1f8aaa | 767 | } else if( debug_invite || debug_main ) debug_msg("Bye from who ? %d", ext ); |
klauss | 91:c2a86b1f8aaa | 768 | } |
klauss | 91:c2a86b1f8aaa | 769 | break; |
klauss | 91:c2a86b1f8aaa | 770 | |
klauss | 0:4d17cd9c8f9d | 771 | case __INVITE__ : { |
klauss | 63:0d95da692bb4 | 772 | invite_counter++; |
klauss | 78:1353744f01e1 | 773 | if( debug_invite ) debug_msg("Request Invite received from Cbx %i", ext); |
klauss | 0:4d17cd9c8f9d | 774 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 775 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 776 | if( v_cb->size() < __MAX_CB_IN_A_BRANCH__ ) { |
klauss | 91:c2a86b1f8aaa | 777 | if( debug_main ) debug_msg( "Adding CBx :: %i", ext ); |
klauss | 91:c2a86b1f8aaa | 778 | cb = new Call_Box( ext, port ); |
klauss | 91:c2a86b1f8aaa | 779 | |
klauss | 91:c2a86b1f8aaa | 780 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 781 | memory_is_over = true; |
klauss | 91:c2a86b1f8aaa | 782 | if( debug_memory ) debug_msg("Invite allocation cb fail"); |
klauss | 91:c2a86b1f8aaa | 783 | } else { |
klauss | 91:c2a86b1f8aaa | 784 | v_cb->add( cb ); |
klauss | 91:c2a86b1f8aaa | 785 | } |
klauss | 89:0fe315117b00 | 786 | } |
klauss | 0:4d17cd9c8f9d | 787 | } |
klauss | 91:c2a86b1f8aaa | 788 | if( cb != NULL ) { |
klauss | 91:c2a86b1f8aaa | 789 | cb->set_msg_id( data[ 0 ] ); |
klauss | 92:92df17f538a8 | 790 | if( cb->status == cb_idle ){ |
klauss | 92:92df17f538a8 | 791 | cb->set_invite_response_ok(); |
klauss | 92:92df17f538a8 | 792 | cb->invite_retry_count_reset(); |
klauss | 92:92df17f538a8 | 793 | } |
klauss | 87:679ee0d594a9 | 794 | invite_handler( v_call, v_cb, ts, cb ); |
klauss | 87:679ee0d594a9 | 795 | } |
klauss | 91:c2a86b1f8aaa | 796 | } |
klauss | 91:c2a86b1f8aaa | 797 | break; |
klauss | 4:de46f0d9b14d | 798 | case __REGISTRY__ : { |
klauss | 63:0d95da692bb4 | 799 | registry_counter++; |
klauss | 78:1353744f01e1 | 800 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 801 | if( v_cb->size() < __MAX_CB_IN_A_BRANCH__ ) { |
klauss | 91:c2a86b1f8aaa | 802 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 803 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 91:c2a86b1f8aaa | 804 | cb = new Call_Box( ext, port ); |
klauss | 91:c2a86b1f8aaa | 805 | |
klauss | 91:c2a86b1f8aaa | 806 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 807 | memory_is_over = true; |
klauss | 91:c2a86b1f8aaa | 808 | if( debug_memory ) debug_msg("Registry cb allocation fail"); |
klauss | 91:c2a86b1f8aaa | 809 | } else { |
klauss | 91:c2a86b1f8aaa | 810 | v_cb->add( cb ); |
klauss | 91:c2a86b1f8aaa | 811 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 91:c2a86b1f8aaa | 812 | } |
klauss | 87:679ee0d594a9 | 813 | } |
klauss | 0:4d17cd9c8f9d | 814 | } |
klauss | 78:1353744f01e1 | 815 | if( debug_main ) debug_msg("Registered %d - %d", ext, port ); |
klauss | 91:c2a86b1f8aaa | 816 | |
klauss | 87:679ee0d594a9 | 817 | if( cb != NULL ) cb->registry(); |
klauss | 91:c2a86b1f8aaa | 818 | |
klauss | 91:c2a86b1f8aaa | 819 | } |
klauss | 91:c2a86b1f8aaa | 820 | break; |
klauss | 4:de46f0d9b14d | 821 | case __BOOT__ : { |
klauss | 63:0d95da692bb4 | 822 | boot_counter++; |
klauss | 99:e80850c51106 | 823 | if( debug_boot == true ){ |
klauss | 99:e80850c51106 | 824 | send_msg("Rcv boot pkg from (%d, %d) pkg-id %d", ext, port, data[ 0 ] ); |
klauss | 99:e80850c51106 | 825 | } |
klauss | 91:c2a86b1f8aaa | 826 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 92:92df17f538a8 | 827 | ( char * )data, data[ 0 ] | BIT7, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 91:c2a86b1f8aaa | 828 | } |
klauss | 91:c2a86b1f8aaa | 829 | break; |
klauss | 99:e80850c51106 | 830 | |
klauss | 4:de46f0d9b14d | 831 | case __TELEMETRY__ : { |
klauss | 78:1353744f01e1 | 832 | if( debug_telemetry ) send_msg("::Telemetry from %d - %d::", ext, port ); |
klauss | 91:c2a86b1f8aaa | 833 | build_telemetry_report( ext, port, ( char *)data ); |
klauss | 91:c2a86b1f8aaa | 834 | } |
klauss | 91:c2a86b1f8aaa | 835 | break; |
klauss | 99:e80850c51106 | 836 | |
klauss | 99:e80850c51106 | 837 | case __FW__ : { |
klauss | 99:e80850c51106 | 838 | if( debug_fw_print ) send_msg("::FW pkg from %d - %d::", ext, port ); |
klauss | 99:e80850c51106 | 839 | fw_cbx_pkg( ext, port, ( char *)buffer ); |
klauss | 99:e80850c51106 | 840 | } |
klauss | 99:e80850c51106 | 841 | break; |
klauss | 91:c2a86b1f8aaa | 842 | |
klauss | 67:cdedc64d9921 | 843 | case __BOOTLOADER_CBX__ : { |
klauss | 67:cdedc64d9921 | 844 | bootloader_cbx_counter++; |
klauss | 91:c2a86b1f8aaa | 845 | //int ret = bl_cbx_reply_to_eth( ext, ( char * )data ); |
klauss | 91:c2a86b1f8aaa | 846 | } |
klauss | 91:c2a86b1f8aaa | 847 | break; |
klauss | 91:c2a86b1f8aaa | 848 | |
klauss | 36:728498a78e1e | 849 | case __PROMPT__ : { |
klauss | 78:1353744f01e1 | 850 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 851 | |
klauss | 91:c2a86b1f8aaa | 852 | if( cb == NULL ) { |
klauss | 92:92df17f538a8 | 853 | // send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 92:92df17f538a8 | 854 | // ( char * )data, ( ( data[ 0 ] & ~BIT7 ) + 1 ), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 92:92df17f538a8 | 855 | |
klauss | 78:1353744f01e1 | 856 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 78:1353744f01e1 | 857 | cb = new Call_Box( ext, port ); |
klauss | 87:679ee0d594a9 | 858 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 859 | memory_is_over = true; |
klauss | 87:679ee0d594a9 | 860 | }else{ |
klauss | 87:679ee0d594a9 | 861 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 862 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 87:679ee0d594a9 | 863 | } |
klauss | 48:195c97f12e8e | 864 | } |
klauss | 91:c2a86b1f8aaa | 865 | |
klauss | 92:92df17f538a8 | 866 | if( cb!= NULL ) cb->registry(); |
klauss | 91:c2a86b1f8aaa | 867 | |
klauss | 91:c2a86b1f8aaa | 868 | if( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ) { |
klauss | 78:1353744f01e1 | 869 | if( debug_ping ) send_msg( "Prompt pkg from ( %i, %i ) :: Ping", ext, port ); |
klauss | 91:c2a86b1f8aaa | 870 | } else { |
klauss | 78:1353744f01e1 | 871 | prompt_counter++; |
klauss | 78:1353744f01e1 | 872 | //fixme isso nao poderia ser resolvido com um sendmsg ? |
klauss | 78:1353744f01e1 | 873 | send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); |
klauss | 91:c2a86b1f8aaa | 874 | for( register uint8_t i = 0; i < 32; i++ ) { |
klauss | 78:1353744f01e1 | 875 | pc.printf("%c", data[ i ] ); |
klauss | 78:1353744f01e1 | 876 | if( i == 15 ) pc.printf( "\r\n" ); |
klauss | 78:1353744f01e1 | 877 | } |
klauss | 78:1353744f01e1 | 878 | pc.printf("\n\r> "); |
klauss | 91:c2a86b1f8aaa | 879 | |
klauss | 91:c2a86b1f8aaa | 880 | if( tcp_session ) { |
klauss | 78:1353744f01e1 | 881 | char aux[ __CB_BUFFER_SIZE__ + 3 ]; |
klauss | 78:1353744f01e1 | 882 | strncpy( aux, (char * )data, __CB_BUFFER_SIZE__ ); |
klauss | 78:1353744f01e1 | 883 | strcat( aux, "\n\r\0" ); |
klauss | 78:1353744f01e1 | 884 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 78:1353744f01e1 | 885 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 78:1353744f01e1 | 886 | } |
klauss | 48:195c97f12e8e | 887 | } |
klauss | 91:c2a86b1f8aaa | 888 | } |
klauss | 91:c2a86b1f8aaa | 889 | break; |
klauss | 0:4d17cd9c8f9d | 890 | case __AUDIO__ : { |
klauss | 63:0d95da692bb4 | 891 | audio_counter++; |
klauss | 78:1353744f01e1 | 892 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 91:c2a86b1f8aaa | 893 | if( call != NULL ) { |
klauss | 91:c2a86b1f8aaa | 894 | char * pkg = call->build_eth_package( data + 2 ); |
klauss | 0:4d17cd9c8f9d | 895 | call->send_message( pkg ); |
klauss | 92:92df17f538a8 | 896 | call->cbx_pkg_idle_timer_reset(); |
klauss | 78:1353744f01e1 | 897 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 92:92df17f538a8 | 898 | if( cb != NULL ){ |
klauss | 99:e80850c51106 | 899 | //cb->reset_elapsed_time(); |
klauss | 92:92df17f538a8 | 900 | cb->set_invite_response_ok(); |
klauss | 92:92df17f538a8 | 901 | cb->invite_retry_count_reset(); |
klauss | 92:92df17f538a8 | 902 | } |
klauss | 91:c2a86b1f8aaa | 903 | } else { |
klauss | 78:1353744f01e1 | 904 | if( debug_main ) debug_msg("received missed package from CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 905 | } |
klauss | 91:c2a86b1f8aaa | 906 | } |
klauss | 91:c2a86b1f8aaa | 907 | break; |
klauss | 9:ffa64f38ef9c | 908 | }// fim switch |
klauss | 92:92df17f538a8 | 909 | |
klauss | 99:e80850c51106 | 910 | { // rajada |
klauss | 99:e80850c51106 | 911 | //if( invite_retry_time == true ){ |
klauss | 99:e80850c51106 | 912 | // invite_retry_time = false; |
klauss | 99:e80850c51106 | 913 | if( invite_retry_timer.read_ms() > 30 ) { |
klauss | 99:e80850c51106 | 914 | invite_retry_timer.reset(); |
klauss | 92:92df17f538a8 | 915 | static int retry_invite_pkg = 0; |
klauss | 99:e80850c51106 | 916 | |
klauss | 92:92df17f538a8 | 917 | if( retry_invite_pkg >= v_cb->size() ) retry_invite_pkg = 0; |
klauss | 99:e80850c51106 | 918 | |
klauss | 99:e80850c51106 | 919 | register int i = 0; |
klauss | 99:e80850c51106 | 920 | for( ; i < v_cb->size(); i++ ) { |
klauss | 99:e80850c51106 | 921 | Call_Box * cb = (Call_Box * )v_cb->get_element( i ); |
klauss | 99:e80850c51106 | 922 | if( ( cb->status == cb_ringing ) || ( cb->status == cb_trying ) || ( cb->status == cb_on_call ) ) { |
klauss | 99:e80850c51106 | 923 | if( i > retry_invite_pkg ) { |
klauss | 99:e80850c51106 | 924 | retry_invite_pkg = i; |
klauss | 99:e80850c51106 | 925 | break; |
klauss | 99:e80850c51106 | 926 | } |
klauss | 92:92df17f538a8 | 927 | } |
klauss | 99:e80850c51106 | 928 | } |
klauss | 99:e80850c51106 | 929 | |
klauss | 99:e80850c51106 | 930 | if( i != v_cb->size() ){ |
klauss | 99:e80850c51106 | 931 | Call_Box * cb = (Call_Box *)v_cb->get_element( retry_invite_pkg++ ); |
klauss | 99:e80850c51106 | 932 | |
klauss | 99:e80850c51106 | 933 | if( ( cb->status == cb_ringing ) || ( cb->status == cb_trying ) || ( cb->status == cb_on_call ) ) { |
klauss | 99:e80850c51106 | 934 | if( cb->get_invite_response() == false ) { |
klauss | 99:e80850c51106 | 935 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 99:e80850c51106 | 936 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 99:e80850c51106 | 937 | |
klauss | 99:e80850c51106 | 938 | buffer[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 99:e80850c51106 | 939 | |
klauss | 99:e80850c51106 | 940 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __INVITE__, ( char * )buffer, |
klauss | 99:e80850c51106 | 941 | cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 99:e80850c51106 | 942 | if( debug_invite ) debug_msg("resend invite OK to Cbx : ( %d, %d )", cb->get_ext(), cb->get_port() ); |
klauss | 99:e80850c51106 | 943 | } |
klauss | 99:e80850c51106 | 944 | if( cb->get_invite_retry_count() == 0 ) { |
klauss | 99:e80850c51106 | 945 | cb->send_bye(); |
klauss | 92:92df17f538a8 | 946 | |
klauss | 99:e80850c51106 | 947 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 99:e80850c51106 | 948 | cb->set_timeslice( 0x00 ); |
klauss | 99:e80850c51106 | 949 | |
klauss | 99:e80850c51106 | 950 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 99:e80850c51106 | 951 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 99:e80850c51106 | 952 | |
klauss | 99:e80850c51106 | 953 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 99:e80850c51106 | 954 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 99:e80850c51106 | 955 | if( call->get_cb_ext() == cb->get_ext() ) { |
klauss | 99:e80850c51106 | 956 | v_call->remove_element( i ); |
klauss | 99:e80850c51106 | 957 | if( call != NULL ) delete( call ); |
klauss | 99:e80850c51106 | 958 | break; |
klauss | 99:e80850c51106 | 959 | } |
klauss | 92:92df17f538a8 | 960 | } |
klauss | 99:e80850c51106 | 961 | |
klauss | 99:e80850c51106 | 962 | if( debug_invite ) debug_msg( "-- No audio pkgs --" ); |
klauss | 99:e80850c51106 | 963 | set_status( cb->status, cb_idle ); |
klauss | 99:e80850c51106 | 964 | set_status( cb->sip->status, sip_idle ); |
klauss | 92:92df17f538a8 | 965 | } |
klauss | 92:92df17f538a8 | 966 | } |
klauss | 92:92df17f538a8 | 967 | } |
klauss | 92:92df17f538a8 | 968 | } |
klauss | 92:92df17f538a8 | 969 | } |
klauss | 91:c2a86b1f8aaa | 970 | |
klauss | 91:c2a86b1f8aaa | 971 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 0:4d17cd9c8f9d | 972 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 973 | int length = 0; |
klauss | 0:4d17cd9c8f9d | 974 | char * tmp = call->get_eth_message( &length ); |
klauss | 91:c2a86b1f8aaa | 975 | if( tmp != NULL ) { |
klauss | 0:4d17cd9c8f9d | 976 | int cb_port = 0xffff; |
klauss | 78:1353744f01e1 | 977 | Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 91:c2a86b1f8aaa | 978 | |
klauss | 91:c2a86b1f8aaa | 979 | if( cb != NULL ) { |
klauss | 4:de46f0d9b14d | 980 | cb_port = cb->get_port(); |
klauss | 91:c2a86b1f8aaa | 981 | |
klauss | 91:c2a86b1f8aaa | 982 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 91:c2a86b1f8aaa | 983 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 99:e80850c51106 | 984 | |
klauss | 99:e80850c51106 | 985 | //static uint8_t valerioduto = 0; |
klauss | 99:e80850c51106 | 986 | //if( valerioduto++ == 2 ){ |
klauss | 99:e80850c51106 | 987 | // valerioduto = 0; |
klauss | 99:e80850c51106 | 988 | send2callboxes( pkg2cb ); |
klauss | 99:e80850c51106 | 989 | //} |
klauss | 99:e80850c51106 | 990 | |
klauss | 91:c2a86b1f8aaa | 991 | } else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 992 | } |
klauss | 14:22a35f575502 | 993 | } |
klauss | 92:92df17f538a8 | 994 | |
klauss | 81:3656f00ab3db | 995 | //if( v_call->size() == 0 ) refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 91:c2a86b1f8aaa | 996 | |
klauss | 99:e80850c51106 | 997 | if( timer_sync_refresh.read_ms() > 250 ) { |
klauss | 89:0fe315117b00 | 998 | timer_sync_refresh.reset(); |
klauss | 91:c2a86b1f8aaa | 999 | |
klauss | 89:0fe315117b00 | 1000 | static uint8_t mode = TIME_TO_REFRESH; |
klauss | 91:c2a86b1f8aaa | 1001 | |
klauss | 91:c2a86b1f8aaa | 1002 | if( mode == TIME_TO_REFRESH ) { |
klauss | 89:0fe315117b00 | 1003 | mode = TIME_TO_WAKE_UP; |
klauss | 89:0fe315117b00 | 1004 | refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 91:c2a86b1f8aaa | 1005 | } else { |
klauss | 89:0fe315117b00 | 1006 | mode = TIME_TO_REFRESH; |
klauss | 91:c2a86b1f8aaa | 1007 | if( wake_all ) if( v_call->size() == 0 ) wake_all_up( v_cb, buffer, write_buffer ); |
klauss | 89:0fe315117b00 | 1008 | } |
klauss | 89:0fe315117b00 | 1009 | } |
klauss | 91:c2a86b1f8aaa | 1010 | |
klauss | 91:c2a86b1f8aaa | 1011 | |
klauss | 89:0fe315117b00 | 1012 | //refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 91:c2a86b1f8aaa | 1013 | |
klauss | 78:1353744f01e1 | 1014 | //Fixme pensar melhor nessa parte durante ligacoes, pode complicar com muitos cbx ... |
klauss | 81:3656f00ab3db | 1015 | //if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 91:c2a86b1f8aaa | 1016 | |
klauss | 78:1353744f01e1 | 1017 | // check sip messages only for cbx in call ? |
klauss | 78:1353744f01e1 | 1018 | int ext_to__be_removed = sip_manager( v_cb ); |
klauss | 91:c2a86b1f8aaa | 1019 | if( ext_to__be_removed > 0x00 ) { |
klauss | 78:1353744f01e1 | 1020 | Call_Box * cb = __find_CB__( v_cb, ext_to__be_removed ); |
klauss | 91:c2a86b1f8aaa | 1021 | if( cb != NULL ) { |
klauss | 91:c2a86b1f8aaa | 1022 | if( cb->status == cb_on_call ) { |
klauss | 4:de46f0d9b14d | 1023 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 1024 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 1025 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 91:c2a86b1f8aaa | 1026 | |
klauss | 78:1353744f01e1 | 1027 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 1028 | set_status( cb->sip->status, sip_idle ); |
klauss | 91:c2a86b1f8aaa | 1029 | |
klauss | 91:c2a86b1f8aaa | 1030 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 4:de46f0d9b14d | 1031 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 91:c2a86b1f8aaa | 1032 | if( call->get_cb_ext() == ext_to__be_removed ) { |
klauss | 4:de46f0d9b14d | 1033 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 1034 | delete( call ); |
klauss | 4:de46f0d9b14d | 1035 | } |
klauss | 2:93bec7313ccc | 1036 | } |
klauss | 91:c2a86b1f8aaa | 1037 | |
klauss | 92:92df17f538a8 | 1038 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 92:92df17f538a8 | 1039 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 91:c2a86b1f8aaa | 1040 | |
klauss | 82:f55d13babca0 | 1041 | //debug_msg("msg_id -- %d", cb->get_msg_id() ); |
klauss | 91:c2a86b1f8aaa | 1042 | |
klauss | 91:c2a86b1f8aaa | 1043 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 4:de46f0d9b14d | 1044 | ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 91:c2a86b1f8aaa | 1045 | |
klauss | 91:c2a86b1f8aaa | 1046 | if( debug_invite ) debug_msg("Received Bye from *"); |
klauss | 99:e80850c51106 | 1047 | //cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 1048 | } |
klauss | 91:c2a86b1f8aaa | 1049 | } else if( debug_main ) debug_msg("Missed bye request from * CBx :: %d", ext ); |
klauss | 0:4d17cd9c8f9d | 1050 | } |
klauss | 91:c2a86b1f8aaa | 1051 | |
klauss | 81:3656f00ab3db | 1052 | /* Verifica andamento de ligações para eventualmente encerra-las por timeout */ |
klauss | 10:22da1a0ac1e1 | 1053 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 91:c2a86b1f8aaa | 1054 | |
klauss | 81:3656f00ab3db | 1055 | /* tratamento de pedidos de ligação */ |
klauss | 81:3656f00ab3db | 1056 | invite_handler( v_call, v_cb, ts, NULL ); |
klauss | 91:c2a86b1f8aaa | 1057 | |
klauss | 81:3656f00ab3db | 1058 | /* rotina de verificação de TS's perdidos */ |
klauss | 91:c2a86b1f8aaa | 1059 | if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() != __MAX_TIMESLICES__ ) ) { |
klauss | 91:c2a86b1f8aaa | 1060 | bool ts_reset = true; |
klauss | 91:c2a86b1f8aaa | 1061 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 82:f55d13babca0 | 1062 | if ( ( ( Call_Box * )v_cb->get_element( i ) )->get_status() != cb_idle && |
klauss | 91:c2a86b1f8aaa | 1063 | ( ( Call_Box * )v_cb->get_element( i ) )->get_sip_status() != sip_idle ) { |
klauss | 78:1353744f01e1 | 1064 | ts_reset = false; |
klauss | 78:1353744f01e1 | 1065 | break; |
klauss | 78:1353744f01e1 | 1066 | } |
klauss | 91:c2a86b1f8aaa | 1067 | } |
klauss | 91:c2a86b1f8aaa | 1068 | if( ts_reset ) { |
klauss | 81:3656f00ab3db | 1069 | if( debug_invite ) debug_msg("Resetando TS"); |
klauss | 78:1353744f01e1 | 1070 | ts->reset(); |
klauss | 78:1353744f01e1 | 1071 | } |
klauss | 0:4d17cd9c8f9d | 1072 | } |
klauss | 91:c2a86b1f8aaa | 1073 | |
klauss | 81:3656f00ab3db | 1074 | //invite_pgk_retry_manager( v_call, v_cb, buffer, write_buffer ); |
klauss | 91:c2a86b1f8aaa | 1075 | |
klauss | 81:3656f00ab3db | 1076 | /* escuta se existe algum procedimento de gravação de cbx */ |
klauss | 91:c2a86b1f8aaa | 1077 | //bl_handler(); |
klauss | 91:c2a86b1f8aaa | 1078 | |
klauss | 81:3656f00ab3db | 1079 | /* rotina que esvazia possiveis pacotes que não foram transmitidos para evitar conflito */ |
klauss | 72:895ca792c647 | 1080 | tx_buffer_ring_buffer_handler(); |
klauss | 91:c2a86b1f8aaa | 1081 | |
klauss | 30:8dfb6d8de53d | 1082 | type = __DO_NOTHING__; |
klauss | 91:c2a86b1f8aaa | 1083 | |
klauss | 81:3656f00ab3db | 1084 | if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 91:c2a86b1f8aaa | 1085 | |
klauss | 91:c2a86b1f8aaa | 1086 | if( wdt_timer.read() >= 1 ) { |
klauss | 91:c2a86b1f8aaa | 1087 | //FIXME remove myself |
klauss | 92:92df17f538a8 | 1088 | //registry_test = true; |
klauss | 99:e80850c51106 | 1089 | //invite_retry_time = true; |
klauss | 91:c2a86b1f8aaa | 1090 | |
klauss | 83:b8a1d8fdeaeb | 1091 | uptime++; |
klauss | 91:c2a86b1f8aaa | 1092 | |
klauss | 81:3656f00ab3db | 1093 | wdt_timer.reset(); |
klauss | 91:c2a86b1f8aaa | 1094 | |
klauss | 81:3656f00ab3db | 1095 | if( wdt_show ) debug_wdt = true; |
klauss | 91:c2a86b1f8aaa | 1096 | |
klauss | 81:3656f00ab3db | 1097 | if( external_wdt ) external_wdt--; |
klauss | 81:3656f00ab3db | 1098 | if( pkg_wdt ) pkg_wdt--; |
klauss | 81:3656f00ab3db | 1099 | if( eth_wdt ) eth_wdt--; |
klauss | 91:c2a86b1f8aaa | 1100 | |
klauss | 91:c2a86b1f8aaa | 1101 | if( eth_wdt && external_wdt && pkg_wdt ){ |
klauss | 81:3656f00ab3db | 1102 | wdt.kick(); |
klauss | 81:3656f00ab3db | 1103 | } |
klauss | 81:3656f00ab3db | 1104 | } |
klauss | 91:c2a86b1f8aaa | 1105 | |
klauss | 91:c2a86b1f8aaa | 1106 | if( debug_wdt ) { |
klauss | 87:679ee0d594a9 | 1107 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 1108 | lpc_low_level_input_counter = 0; |
klauss | 91:c2a86b1f8aaa | 1109 | |
klauss | 81:3656f00ab3db | 1110 | debug_wdt = false; |
klauss | 91:c2a86b1f8aaa | 1111 | if( eth_status == 0 ) { |
klauss | 91:c2a86b1f8aaa | 1112 | 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 | 91:c2a86b1f8aaa | 1113 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 91:c2a86b1f8aaa | 1114 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 91:c2a86b1f8aaa | 1115 | EXTERN_WDT_IDLE, |
klauss | 91:c2a86b1f8aaa | 1116 | RX_CB_IDLE - pkg_wdt, |
klauss | 91:c2a86b1f8aaa | 1117 | RX_CB_IDLE |
klauss | 91:c2a86b1f8aaa | 1118 | ); |
klauss | 91:c2a86b1f8aaa | 1119 | } else { |
klauss | 91:c2a86b1f8aaa | 1120 | 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 | 91:c2a86b1f8aaa | 1121 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 91:c2a86b1f8aaa | 1122 | ETH_CONNECT_TIMEOUT - eth_wdt, |
klauss | 91:c2a86b1f8aaa | 1123 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 91:c2a86b1f8aaa | 1124 | EXTERN_WDT_IDLE, |
klauss | 91:c2a86b1f8aaa | 1125 | RX_CB_IDLE - pkg_wdt, |
klauss | 91:c2a86b1f8aaa | 1126 | RX_CB_IDLE |
klauss | 91:c2a86b1f8aaa | 1127 | ); |
klauss | 81:3656f00ab3db | 1128 | } |
klauss | 81:3656f00ab3db | 1129 | } |
klauss | 0:4d17cd9c8f9d | 1130 | } |
klauss | 0:4d17cd9c8f9d | 1131 | } |