voltando a versao de n aberturas e fechamentos de sockets

Dependencies:   EthernetInterface NTPClient mbed-rtos_old mbed

Fork of header_main_public by VZTECH

Revision:
18:01a93677e40c
Parent:
17:67a6b557eda5
--- a/main.cpp	Fri Sep 19 16:40:17 2014 +0000
+++ b/main.cpp	Fri Sep 19 17:39:09 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,8 +27,6 @@
 int main(){
     start_cpld();
     config_lpc();
-    init_fsystem();
-    wdt.Configure( 40.0 );
     
     /* referencia e inicio da conexao com a ethernet */
     EthernetInterface eth;
@@ -36,8 +34,7 @@
     int eth_status = __init_eth__( &eth );
     
     if( eth_status ){
-        debug_msg("Sem conexao eth");
-        //NVIC_SystemReset();
+        debug_msg("Sem conexao eth");    
     }
         
     /* debugs */
@@ -104,9 +101,7 @@
     }
     reset_leds();
     debug_msg( " Ready " );
-    while( true ){
-        prompt_process();
-        wdt.kick();   
+    while( true ){    
         if( status != __WAITING__ ){
             __read_cb_buffer__( buffer, buffer_from_cb_ptr );     
             status = __WAITING__;
@@ -114,7 +109,7 @@
             data = __parse_cb_buffer__( &ext, &port, &type, buffer );
             
             if( data != NULL ){                
-                debug_msg("Package from :: %d -- Type :: %d", ext, type );
+                debug_msg("Procurando pelo CBx :: %d -- Type :: %d", ext, type );
                 if( type != __AUDIO__ ){
                     Call_Box * cb = __find_CB__( v_cb, ext );
                     if( cb != NULL ){
@@ -138,17 +133,14 @@
             }else type = __DO_NOTHING__;
         }
 //----------------------
-            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("");
+            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 );
                 }
+                debug_msg("");
                 t.reset();
                 led3 = !led3;
-                hack_led = !hack_led;
             }
 //----------------------
         switch( type ){
@@ -158,6 +150,7 @@
             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 " );
@@ -184,6 +177,7 @@
                 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 );
@@ -202,7 +196,7 @@
                     break;
                 }
                 set_status( cb->status, cb_trying );
-                debug_msg("Invite request from CBx -- %d :: Status %d", ext, cb->status );
+                debug_msg(" Ok temos um cbx encontrado com status :: %d", cb->status );
                 switch( cb->status ){
                     case cb_on_call : {
                         // a priori, nao fazer nada
@@ -245,7 +239,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 --" );
+                                debug_msg( "-- Trying -- aceitando pedido de invite -- %s ", write_buffer );
                                 //debug_pkg( 300, write_buffer );
                             }else{
                                 set_status( cb->status,cb_idle);
@@ -255,21 +249,13 @@
                                 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 --" );
+                                debug_msg( "-- Trying -- Negando pedido de invite -- %s ", write_buffer );
                                 set_status( cb->sip->status, sip_idle);
                             }
                         }
                     }break;                    
                     case cb_busy : {
-                        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 );
+                        // tratar sip
                     }break;
                 }                            
             }break;
@@ -282,6 +268,7 @@
                     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 );
@@ -310,6 +297,8 @@
                     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
@@ -324,7 +313,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 );
@@ -357,7 +346,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 );