VZTECH / Mbed 2 deprecated main_src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vz_stdio.cpp Source File

vz_stdio.cpp

00001 %: include "vz_stdio.h"
00002 
00003 Serial serial_pc ( USBTX, USBRX );
00004 
00005 UDPSocket udp_client;
00006 
00007 Endpoint udp_server;
00008 
00009 TCPSocketServer tcp_server;
00010 
00011 TCPSocketConnection tcp_client;
00012 
00013 bool debug_io_eth = false;
00014 
00015 bool udp_request = false;
00016 
00017 bool udp_query = false;
00018 
00019 bool tcp_session = false;
00020 
00021 bool from_eth = false;
00022 
00023 char io_msg1 [ IO_MSG_SIZE + IO_AUX_MSG_SIZE ];
00024 
00025 char io_msg2 [ IO_MSG_SIZE ];
00026 
00027 char io_debug_msg1 [ IO_MSG_SIZE + IO_AUX_MSG_SIZE ];
00028 
00029 char io_debug_msg2 [ IO_MSG_SIZE ];
00030 
00031 char io_msg_ [ IO_MSG_SIZE ];
00032 
00033 int 
00034 vz_io_eth_init ( void )
00035 {
00036     int return_value = 0;
00037 
00038     int udp_bind = udp_client.bind ( u16_UDP_PORT_LISTENER );
00039 
00040     udp_client.set_blocking ( false, 0 );
00041 
00042     if ( debug_io_eth ) serial_pc.printf ( "udp_client.bind :: %d", udp_bind );
00043 
00044     if ( udp_bind == 0 ) return_value |= BIT0;
00045 
00046     int tcp_bind = tcp_server.bind ( u16_TCP_PORT_LISTENER );
00047 
00048     tcp_server.set_blocking ( false, 0 );
00049 
00050     tcp_server.listen ();  
00051 
00052     if ( debug_io_eth ) serial_pc.printf ( "tcp_server.bind :: %d", tcp_bind );
00053 
00054     if ( tcp_bind == 0 ) return_value |= BIT1;
00055 
00056     return ( return_value );
00057 }
00058 
00059 int
00060 vz_printf ( const char * format, ... )
00061 {
00062         va_list arg;
00063 
00064         va_start ( arg, format );
00065 
00066         int done = vsnprintf ( io_msg_, IO_MSG_SIZE -1, format, arg );
00067         
00068         snprintf ( io_msg1, sizeof ( io_msg1 ) - 1, "%s\r\n> ", io_msg_ );
00069         
00070         if ( debug_uart3 && !udp_query && !from_eth ) serial_pc.printf ( "%s",io_msg1 );
00071         
00072         if ( tcp_session && !udp_query )
00073         {
00074             while ( !( tcp_client.send_all ( io_msg1, strlen ( io_msg1 ) ) ) );
00075         }
00076         
00077         if ( udp_query )
00078         {
00079             int send = udp_client.sendTo ( udp_server, io_msg_, strlen ( io_msg_ ) );
00080             if ( send not_eq strlen ( io_msg_ ) )
00081             {
00082                 if ( debug_reconnect && debug_uart3 ) serial_pc.printf ("\n\rReconnect udp_query client\n\r");
00083                 reconnect_prompt_udp_socket ();
00084                 miss_prompt_udp_send_pkg ++;
00085             }
00086         }
00087         
00088         va_end ( arg );
00089         
00090         return done;
00091 }
00092 
00093 void 
00094 udp_query_send_msg ( char * msg )
00095 {
00096     if ( ( msg != NULL ) && ( strlen ( msg ) > 0 ) )
00097     {   
00098         int send = udp_client.sendTo ( udp_server, msg, strlen ( msg ) );
00099         
00100         if( send not_eq strlen ( msg ) )
00101         {
00102             reconnect_prompt_udp_socket ();
00103             miss_prompt_udp_send_pkg ++;
00104         }
00105     }
00106 }