![](/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:
- 17:67a6b557eda5
- Parent:
- 16:b45b5b7363d7
- Child:
- 18:01a93677e40c
--- a/main.cpp Thu Sep 18 13:59:58 2014 +0000 +++ b/main.cpp Fri Sep 19 16:40:17 2014 +0000 @@ -3,7 +3,7 @@ #include "configs.h" #include "UART3Interrupt.h" #include "parallelcpld.h" - +#include "prompt.h" #include "debug.h" #include "utils.h" @@ -27,6 +27,8 @@ int main(){ start_cpld(); config_lpc(); + init_fsystem(); + wdt.Configure( 40.0 ); /* referencia e inicio da conexao com a ethernet */ EthernetInterface eth; @@ -34,7 +36,8 @@ int eth_status = __init_eth__( ð ); if( eth_status ){ - debug_msg("Sem conexao eth"); + debug_msg("Sem conexao eth"); + //NVIC_SystemReset(); } /* debugs */ @@ -101,7 +104,9 @@ } reset_leds(); debug_msg( " Ready " ); - while( true ){ + while( true ){ + prompt_process(); + wdt.kick(); if( status != __WAITING__ ){ __read_cb_buffer__( buffer, buffer_from_cb_ptr ); status = __WAITING__; @@ -109,7 +114,7 @@ data = __parse_cb_buffer__( &ext, &port, &type, buffer ); if( data != NULL ){ - debug_msg("Procurando pelo CBx :: %d -- Type :: %d", ext, type ); + debug_msg("Package from :: %d -- Type :: %d", ext, type ); if( type != __AUDIO__ ){ Call_Box * cb = __find_CB__( v_cb, ext ); if( cb != NULL ){ @@ -133,14 +138,17 @@ }else type = __DO_NOTHING__; } //---------------------- - if( t.read() > 5 ){ - 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 ); + if( t.read() > 5 ){ + if( debug_alive ){ + 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 ); + } + if( v_cb->size() != 0 ) debug_msg(""); } - debug_msg(""); t.reset(); led3 = !led3; + hack_led = !hack_led; } //---------------------- switch( type ){ @@ -150,7 +158,6 @@ case __CB_BYE__ : { Call_Box * cb = __find_CB__( v_cb, ext ); if( cb != NULL ){ - debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); data[ 0 ] |= BIT7; cb->set_msg_id( data[ 0 ] ); debug_msg( " Request bye from CBx " ); @@ -177,7 +184,6 @@ debug_msg("ok -- recebido o invite pelo menos"); Call_Box * cb = __find_CB__( v_cb, ext ); if( cb == NULL ){ - debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); cb = new Call_Box( ext, port ); v_cb->add( cb ); set_status( cb->status, cb_idle ); @@ -196,7 +202,7 @@ break; } set_status( cb->status, cb_trying ); - debug_msg(" Ok temos um cbx encontrado com status :: %d", cb->status ); + debug_msg("Invite request from CBx -- %d :: Status %d", ext, cb->status ); switch( cb->status ){ case cb_on_call : { // a priori, nao fazer nada @@ -239,7 +245,7 @@ debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - debug_msg( "-- Trying -- aceitando pedido de invite -- %s ", write_buffer ); + debug_msg( "-- Trying -- aceitando pedido de invite --" ); //debug_pkg( 300, write_buffer ); }else{ set_status( cb->status,cb_idle); @@ -249,13 +255,21 @@ debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - debug_msg( "-- Trying -- Negando pedido de invite -- %s ", write_buffer ); + debug_msg( "-- Trying -- Negando pedido de invite --" ); set_status( cb->sip->status, sip_idle); } } }break; case cb_busy : { - // tratar sip + set_status( cb->status,cb_idle); + ts->return_timeslice( cb->get_timeslice() ); + cb->set_timeslice( 0x00 ); + data[ __TIMESLICE_PLACE__ ] = 0x00; + debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); + __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, + ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + debug_msg( "-- Trying -- Negando pedido de invite << Busy Here >> --" ); + set_status( cb->sip->status, sip_idle ); }break; } }break; @@ -268,7 +282,6 @@ cb->reset_elapsed_time(); debug_msg(" reset_elapsed_time CBx -- %d", ext ); }else{ - debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); cb = new Call_Box( ext, port ); v_cb->add( cb ); debug_msg(" Criado CBx -- %d", ext ); @@ -297,8 +310,6 @@ call->send_message( pkg ); cb = __find_CB__( v_cb, ext ); if( cb != NULL ) cb->reset_elapsed_time(); - }else{ - debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); } }break; }// fim switch @@ -313,7 +324,7 @@ if( cb != NULL ){ cb_port = cb->get_port(); - }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); + } uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, tmp, __AUDIO__, length, write_buffer ); @@ -346,7 +357,7 @@ cb->reset_sip(); set_status( cb->sip->status, sip_idle ); } - }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); + } } call_manager( v_call, v_cb, buffer, write_buffer, ts );