EMBEDDED APPLICATIONS FCT
2.5
UDP Example Script {UDP_transfer.sc}
A simple example of a UDP data transfer script is listed
below. The script creates a UDP socket, sends some start
data and then sits in a receive loop until a ‘$’ character is
received, after which it closes the socket and exits.
int Err;
int Port = 3000;
int Address = 0x0A8402A3; /* 10.132.2.163 */
int RXTX_SIZE = 1000;
char RxTxBuf[RXTX_SIZE] = “Starting! “;
char Complete = FALSE;
int APPS_IP_ERROR_TRIGGER = 36;
int APPS_IP_ERROR_STATUSBYTE = 13;
int APPS_IP_DATA_RECVD = 13;
int APPS_IP_TCPSTATUS_BYTE = 14;
/* Reset the IP error flag by reading it */
gtf( APPS_IP_ERROR_TRIGGER );
Err = pdpa( 1, 1 );
prtf( "\n PDP activate result = %d\n", Err );
if ( Err == 0 )
{
Val = ipi( 0 );
prtf(" IP Address = %x", Val );
Val = ipi( 1 );
prtf( "\n DNS 1 = %x", Val );
Val = ipi( 2 );
prtf( "\n DNS 2 = %x\n", Val );
}
else
{
prtf( "\n PDP activation failed!\n" );
return;
}
Err = ipo( 0, &SckNum );
if( Err != 0 )
{
prtf( “ \n UDP Socket open failed!\n” );
}
else
{
int
len;
prtf( "\n UDP Socket Opened!\n" );
prtf( "\n Sending start data...\n" );
len = 10;
Err = udps( SckNum, Port, Address, RxTxBuf, len );
while( !Complete && (gtb( APPS_IP_ERROR_STATUSBYTE ) == 0) )
{
/* Receive some data */
if( gtf( APPS_IP_DATA_RECVD ) )
{
prtf( "\n IP DATA RECVD" );
len
=
RXTX_SIZE;
Err = udpr( SckNum, &Port, &Address, RxTxBuf, RXTX_SIZE, &len );
if( Err != 0 )
{
prtf( "\n UDP receive error!\n" );
}
}
LZT 123 8019 R1A
10