![](/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
Diff: main.cpp
- Revision:
- 48:195c97f12e8e
- Parent:
- 46:a670f187a704
- Child:
- 49:4837ed2aad6b
diff -r 3983efe3aeba -r 195c97f12e8e main.cpp --- a/main.cpp Tue Oct 07 18:43:44 2014 +0000 +++ b/main.cpp Mon Oct 20 16:13:10 2014 +0000 @@ -12,21 +12,20 @@ volatile uint8_t status = 0x00; int main(){ + wdt.Configure( 40.0 ); start_cpld(); config_lpc(); - /* referencia e inicio da conexao com a ethernet */ - EthernetInterface eth; - init_fsystem(); // pensar melhor em como saber se estou conectado na eth - int eth_status = __init_eth__( ð ); + //int eth_status = __init_eth__( ð ); + int eth_status = __init_eth__(); if( eth_status ){ - debug_msg("Cannot connect to eth"); + send_msg("Cannot connect to eth\n\r"); }else{ - debug_msg("Connection eth - ok"); + send_msg("Connection eth - ok"); init_prompt(); } Timer t; @@ -69,7 +68,7 @@ Vector * v_cb = new Vector(); led1 = led1; if( t.read() > 5 ){ - debug_msg("Erro ao alocar o vetor de CBx"); + send_msg("Erro ao alocar o vetor de CBx"); t.reset(); } } @@ -79,29 +78,58 @@ while( v_call == NULL ){ Vector * v_call = new Vector(); if( t.read() > 5 ){ - debug_msg("Erro ao alocar o vetor de Calls"); + send_msg("Erro ao alocar o vetor de Calls"); t.reset(); } } } reset_leds(); - wdt.Configure( 40.0 ); udp_timer.start(); - debug_msg("Ready"); + send_msg("Ready"); while( true ){ prompt_process( NULL ); wdt.kick(); if (pcks_s == 1){ - pc.printf("\n\r PKG_CSK OK: %d", pkg_cksok); - pc.printf("\n\r PKG_CSK ERR: %d\n\r", pkg_ckserr); + //pc.printf("\n\r PKG_CSK OK: %d", pkg_cksok); + //pc.printf("\n\r PKG_CSK ERR: %d\n\r", pkg_ckserr); + send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d", pkg_cksok, pkg_ckserr ); pcks_s =0; } if (pshowcb == 1){ + send_msg("Registred %d CBx", v_cb->size() ); for( register uint8_t i = 0; i < v_cb->size(); i++ ){ Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); - debug_msg(" Type :: %d -- Ext :: %d -- TimeSlice :: %d -- remain_timeslices :: %d :: v_call->size() :: %d :: Status :: %d :: SIP Status %d", type , cb->get_ext(), cb->get_timeslice(), ts->remain_timeslices(), v_call->size(), cb->status, cb->sip->status ); - pshowcb = 0; + send_msg("Type :: %d -- Ext :: %d -- TimeSlice :: %d -- remain_timeslices :: %d :: v_call->size() :: %d :: Status :: %d :: SIP Status %d", type , cb->get_ext(), cb->get_timeslice(), ts->remain_timeslices(), v_call->size(), cb->status, cb->sip->status ); + } + pshowcb = 0; + } + if( cb_status ){ + cb_status = false; + send_msg("Registred %d CBx", v_cb->size() ); + char str[ 1024 ]; + + if( v_cb->size() == 0 ){ + send_msg("{-/-}"); + }else if( v_cb->size() == 1 ){ + Call_Box * cb = ( Call_Box * )v_cb->get_element( 0 ); + send_msg("{ %d }", cb->get_ext() ); + }else{ + register uint8_t i; + char aux[ 16 ]; + Call_Box * cb = NULL; + strcpy( str, "{ " ); + for( i = 0; i < v_cb->size() - 1; i++ ){ + cb = ( Call_Box * )v_cb->get_element( i ); + sprintf( aux, "%5d, ", cb->get_ext() ); + strcat( str, aux ); + if( ( i != 0 ) && !( i % 10 ) ) strcat( str, "\n\r " ); + } + cb = ( Call_Box * )v_cb->get_element( i ); + sprintf( aux, "%5d ", cb->get_ext() ); + strcat( str, aux ); + strcat( str, " }" ); + send_msg( "%s", str ); } } @@ -140,29 +168,37 @@ //---------------------- if( t.read() > 5 ){ static int count = 0; - for( register uint8_t i = 0; i < v_cb->size(); i++ ){ - Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); - if( debug_alive ){ - debug_msg(" Type :: %d -- Ext :: %d -- TimeSlice :: %d -- remain_timeslices :: %d :: v_call->size() :: %d :: Status :: %d :: SIP Status %d", type , cb->get_ext(), cb->get_timeslice(), ts->remain_timeslices(), v_call->size(), cb->status, cb->sip->status ); + static int test_ext = 870; + static int test_port = 5170; + static bool main_test = false; + //send_msg("from_eth = %s - tcp_session = %s", ( from_eth ) ? "true" : "false", ( tcp_session ) ? "true" : "false" ); + if( debug_alive ){ + send_msg("Registred %d CBx", v_cb->size() ); + for( register uint8_t i = 0; i < v_cb->size(); i++ ){ + Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); + send_msg("Type :: %d -- Ext :: %d -- TimeSlice :: %d -- remain_timeslices :: %d :: v_call->size() :: %d :: Status :: %d :: SIP Status %d", type , cb->get_ext(), cb->get_timeslice(), ts->remain_timeslices(), v_call->size(), cb->status, cb->sip->status ); } } + /* if( debug_alive == 1 ){ - if( debug_main ) debug_msg("Status - alive "); + if( debug_main ) send_msg("Status - alive "); //uint32_t errper = 100*(pkg_ckserr/(pkg_ckserr + pkg_cksok)); //pc.printf("\n\r Error = %d", errper); } + */ t.reset(); led3 = !led3; CAB_LED = !CAB_LED; - if( debug_cks ) debug_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d", pkg_cksok, pkg_ckserr ); + if( debug_cks ) send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d", pkg_cksok, pkg_ckserr ); //<><><><><><><><><><> count++; if( !( count % 3 ) ){ if( eth_status ){ wdt.kick(); - eth_status = __init_eth__( ð ); + //eth_status = __init_eth__( ð ); + eth_status = __init_eth__(); if( eth_status ){ if( debug_main ) debug_msg("Cannot connect to eth"); }else{ @@ -171,16 +207,20 @@ } } } - /* - if( count == 5 ){ + if( count == 4 ){ //debug_msg("Colocar simulacoes de cbx aqui"); + main_test = true; + } + if( main_test ){ + send_msg("Request registry from %d", test_ext ); data = buffer; - ext = 891; - port = 5001; + ext = test_ext++; + port = test_port++; type = __REGISTRY__; - debug_msg("registro enviado"); + //if( test_ext == 881 ) main_test = false; + main_test = false; } - + /* if( count == 5 * 2 ){ //debug_msg("Colocar simulacoes de cbx aqui"); data = buffer; @@ -342,14 +382,31 @@ ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); }break; case __TELEMETRY__ : { - build_telemetry_report( ext, port, ( char *)data ); + if( debug_main ) debug_msg("::telemetry from %d - %d::", ext, port ); + //build_telemetry_report( ext, port, ( char *)data ); }break; case __PROMPT__ : { - pc.printf("Prompt pkg from ( %i, %i ) ::\n\r", ext, port ); - for( register int i = 0; i < __CB_BUFFER_SIZE__; i++ ) + send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); + /* + if( tcp_session ){ // udp ? + char tmp[ 255 ]; + sprintf( tmp, "Prompt pkg from ( %i, %i ) :: ", ext, port ); + tcp_client.send_all( tmp, strlen( tmp ) ); + } + */ + for( register int i = 0; i < __CB_BUFFER_SIZE__; i++ ){ pc.printf("%3i ", data[ i ] ); + } + //FIXMEj isso nao vai funcionar em udp, mudar pra send_msg pc.printf("\n\r"); + + if( tcp_session ){ + char aux[ __CB_BUFFER_SIZE__ + 3 ]; + strncpy( aux, (char * )data, __CB_BUFFER_SIZE__ ); + strcat( aux, "\n\r\0" ); + tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); + } }break; case __AUDIO__ : { Call_Box * cb;