UART connection to TCP Server pointer hand over

[attachment=0]TCP.jpg[/attachment]

Hello Sierra Wireless world,

I have a litte Problem connecting a Terminalprogram via FXT 009 with a Server.

The connection between the Terminal and the Modem works fine and the connection from Modem to Server, too

My problem is, that I can’t hand over the pointer from my UART programm to my TCP programm. The pointer (ptrbuff) shows the data which comes from the terminal.

This is the UART programm:

void cbUART1Rx (void)
{
u32 NbTbRead = UA_ZERO;
u32 NbRead = UA_ZERO;
s32 Ret = OK;
u32 Idxbuff = UA_ZERO;
eChStatus_t WriteRet = CH_STATUS_NORMAL;
static bool BuffFull = FALSE;

TRACE ( ( UA_UART1_TRACEID, "[cbUART1Rx] Task Context [%d]",
                                adl_ctxGetID ( ) ) );

// create Uart1 Event
Uart1EventHandle = adl_eventCreate ( UART1_INIT_TX_RX_MASK );
TRACE ( ( UA_UART1_TRACEID, "cbUART1Rx [%x]", Uart1EventHandle ) );

//Received Data are just forwarded to UART2 ...
while ( UA_INFINITE_LOOP_COUNTER )
{
    TRACE ( ( UA_UART1_TRACEID, "Wait for a Received Data......" ) );

    // wait for Rx Available event
    Ret = adl_eventWait ( Uart1EventHandle, UART1_RX_EVENT_WAIT_MASK,
                          NULL, ADL_EVENT_WAIT_ALL,
                          ADL_EVENT_NO_TIMEOUT );
    TRACE ( ( UA_UART1_TRACEID, "Wait for a Received Data......[%d]",
                                    Ret ) );

    // clear Rx Available event
    adl_eventClear ( Uart1EventHandle, UART1_RX_EVENT_WAIT_MASK, NULL );

    ptrbuff = ( u8* )buffer_pool[ Idxbuff ];
    Idxbuff ^= 1;
    wm_memset ( ptrbuff, UA_ZERO, UART_MAX_DATA_SIZE );

    for ( NbTbRead = UART1_MAX_DATA_SIZE;
          ( NbRead = uart1_itf.read ( Uart1Handle, ptrbuff,
                                      NbTbRead ) ); )
    {
        TRACE ( ( UA_UART1_TRACEID, "Read Data Size : %d", NbRead ) );

         //Point at first free byte position in the receive buffer
        ptrbuff += NbRead;

        // Compute maximum allowed amount of bytes to be read
        NbTbRead -= NbRead;

        TRACE ( ( UA_UART1_TRACEID, "Data is : %d", NbRead ) );
        if ( !NbTbRead )
        {
            // No more available space
            TRACE ( ( UA_UART1_TRACEID, "Read buffer is FULL" ) );
            BuffFull = TRUE;
            adl_eventSet ( Uart1EventHandle, UART1_RX_EVENT_WAIT_MASK );
            break;
        }
    } // END of Data READ

    // Alpha Rx chars in lower case are put in upper case and in upper case
    // are put in lower case

   for ( NbRead = ( UART1_MAX_DATA_SIZE - NbTbRead ); NbRead--; )
    {
        if ( isalpha ( *--ptrbuff ) )
        {
            // Char in lower case goes in upper case and vice & versa
            *ptrbuff ^= ' ';
        }
    }

    // Processed data are sent to UART2
    if ( NbTbRead != UART1_MAX_DATA_SIZE )
    {
        TRACE ( ( UA_UART1_TRACEID, "Wait for last Tx complete......" ) );

        // wait for Tx Complete event
        adl_eventWait ( Uart2EventHandle, UART2_TX_EVENT_WAIT_MASK, NULL,
                        ADL_EVENT_WAIT_ALL, ADL_EVENT_NO_TIMEOUT );

       // clear TxComplete event
        adl_eventClear ( Uart2EventHandle, UART2_TX_EVENT_WAIT_MASK, NULL );


        TRACE ( ( UA_UART1_TRACEID, (ascii*)ptrbuff ) );

        snd_buffer=ptrbuff;

       // write all former read data
        WriteRet = uart2_itf.write ( Uart2Handle, ptrbuff,
                                      ( UART2_MAX_DATA_SIZE - NbTbRead ) );


        if ( WriteRet == CH_STATUS_ERROR )
        {
            TRACE ( ( UA_UART1_TRACEID, "ERROR write !!!!!   pWriteData %x"\
                      "DataNbToWrite %d", \
                      ( UART1_MAX_DATA_SIZE - NbTbRead ) ) );
        }
        else
        {
            TRACE ( ( UA_UART1_TRACEID, "ADL Write Process Returns [%d]", \
                      WriteRet ) );

            TRACE ( ( UA_UART1_TRACEID, (ascii*) ptrbuff) );

            if ( BuffFull == TRUE )
            {
                BuffFull = FALSE;
                // clear RxComplete event
                adl_eventClear ( Uart1EventHandle,
                                UART1_RX_EVENT_WAIT_MASK, NULL );
            }
            wm_memset ( ptrbuff, UA_ZERO, UART_MAX_DATA_SIZE );
        }
    }
    else
    {
        TRACE ( ( 1, "No Data Received so far" ) );
    }
 // End of while ( UA_INFINITE_LOOP_COUNTER )
}

}

And this my TCP client programm: It is a modificated program from the example

static void cbevh ( wip_event_t *ev, void *ctx )
{
switch ( ev->kind )
{
case WIP_CEV_OPEN:
{
TRACE ( ( NORMAL_TRACE_LEVEL, “[SAMPLE] Connection established successfully” ) );
break;
}

    case WIP_CEV_READ:
    {
        int nread;
        TRACE ( ( NORMAL_TRACE_LEVEL, "[SAMPLE] Some data arrived\n" ) );
        nread = wip_read ( ev->channel, rcv_buffer + rcv_offset, sizeof ( rcv_buffer ) );


          if ( nread < 0 )
        {
            TRACE ( ( ERROR_TRACE_LEVEL, "[SAMPLE] read error %i", nread ) );
           // wip_write ( ev->channel,  rcv_buffer, sizeof (  rcv_buffer  ));
           return;
        }
        rcv_offset += nread;
        if ( rcv_offset == sizeof ( rcv_buffer ) )
        {
            TRACE ( ( ERROR_TRACE_LEVEL, "[SAMPLE] Reception capacity exceeded, won't read more" ) );
        }
        else
        {
            TRACE ( ( NORMAL_TRACE_LEVEL, "[SAMPLE] Wrote %i bytes of data from network to rcv_buffer. "
                            "%i bytes remain available in rcv_buffer\n", nread, sizeof ( rcv_buffer ) - rcv_offset ) );
        }
        break;
    }

    case WIP_CEV_WRITE:
    {
    	int nwrite;
    	int i;
    	int a;



    	//while (nwrite==0)
    	//		{
    	//	TRACE ( ( NORMAL_TRACE_LEVEL, "[SAMPLE] No data available" ) );

    		//	}

        TRACE ( ( NORMAL_TRACE_LEVEL, "[SAMPLE] Can send more data" ) );



    for (i=0;i<=20;i++)

    	nwrite=wip_write ( ev->channel, snd_buffer ,sizeof ( snd_buffer )-1);


    	for (a=0;a<=2000000000;a++)
    	{
    		TRACE ( ( 1, "%i", a ) );
    	}

    	TRACE ( ( 1, "%i", i ) );


               if ( nwrite < 0 )
        {
            TRACE ( ( ERROR_TRACE_LEVEL, "[SAMPLE] write error %i", nwrite ) );
            return;
        }
       snd_offset += nwrite;
        if ( snd_offset == sizeof ( snd_buffer ) )
        {
            TRACE ( ( NORMAL_TRACE_LEVEL, "[SAMPLE] Everything has been sent, won't send more." ) );
        }
        else
        {
            TRACE ( ( NORMAL_TRACE_LEVEL, "[SAMPLE] Wrote %i bytes. %i bytes left to send in snd_buffer",
                            nwrite, sizeof ( snd_buffer ) ) );
        }

    }
        break;

    case WIP_CEV_ERROR:
    {
        TRACE ( ( ERROR_TRACE_LEVEL, "[SAMPLE] Error %i on socket. Closing.", ev->content.error.errnum ) );
        wip_close ( ev->channel );
        break;
    }

    case WIP_CEV_PEER_CLOSE:
    {
        TRACE ( ( NORMAL_TRACE_LEVEL, "[SAMPLE] Connection closed by peer" ) );
        wip_close ( ev->channel );
        break;
    }

    default:
    {
        break;
    }
}

}

It would be perfect if I can have the data in snd_buffer.

I think it is very simple but I see no trees because of the would^^

Tank you

Hi,

Did you mean the data is “NULL” in the snd_buffer? or any error? or the applicaton crashes? Please elaborate.

Regards,
Rex

Hello Rex Alex,

I don’t know which Data was in snd_buffer. On my console I got data like smilees and hearts etc :smiley:.

The problem was a wrong pointer to data hand over.

I wrote snd_buffer= ptrbuff but the correct line is snd_buffer=&buff_1 because my data is in buf_1 and ptrbuff is only a pointer to the data.

Now I have corrected the line and everything works fine :slight_smile: