background image

  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 

Summary of Contents for Embedded Applications

Page 1: ...Application Note Embedded Applications Using the on board TCP IP stack...

Page 2: ...Mobile Communications reserves the right to make modifications additions and deletions to this manual due to typographical errors inaccurate information or improvements to programs and or equipment a...

Page 3: ...pt 6 2 2 4 TCP Connect Operations 7 2 2 5 Testing Communications over TCP IP 8 2 3 General Restrictions 8 2 4 Resource Restrictions 8 2 4 1 Packet Buffers 8 2 4 2 IP Fragmentation 9 2 4 3 Performance...

Page 4: ...EMBEDDED APPLICATIONS FCT 1 Introduction This application note describes the use of the TCP IP sack that is resident on the module within the embedded applications environment LZT 123 8019 R1A 4...

Page 5: ...series of functions outlined below pdpa Activate and deactivate a PDP context for TCP IP over GPRS ipo Open a UDP or TCP socket for data transfer ipc Close a previously opened UDP or TCP socket tcpc...

Page 6: ...access to any ICMP features 2 2 2 GPRS Transport for IP In order to use the embedded TCP IP functions a GPRS PDP context must be activated first to provide the underlying IP transport This should be d...

Page 7: ...depending upon the link performance lost packets etc Therefore the tcpc function has been made non blocking to avoid stalling the script for long periods A call to tcpc will initiate a connection but...

Page 8: ...ion requires that the script closes one socket before attempting to open or re open another For the majority of applications the module is only ever transferring data over a single socket so the restr...

Page 9: ...ts are being received The TCP IP stack will especially during busy periods buffer and consolidate transmit data This will sometimes result in data being sent from the radio device in larger units than...

Page 10: ...VD 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 p...

Page 11: ...0 prtf n Breaking out of receive loop n Complete TRUE Log status monitoring if gtf APPS_IP_ERROR_TRIGGER prtf n IP ERROR d n gtb APPS_IP_ERROR_STATUSBYTE Err ipc SckNum if Err 0 prtf n Socket close f...

Page 12: ...13 int APPS_IP_DATA_RECVD 13 int APPS_IP_TCPSTATUS_BYTE 14 int TCP_NOT_CONNECTED 1 int TCP_CONNECTING 2 int TCP_CONNECTED 3 Reset the IP error flag by reading it gtf APPS_IP_ERROR_TRIGGER Err pdpa 1 1...

Page 13: ...ct occurs n n else prtf n Received d bytes of data n n len Log status monitoring if gtf APPS_IP_ERROR_TRIGGER prtf n IP ERROR d n gtb APPS_IP_ERROR_STATUSBYTE Complete 1 if gtb APPS_IP_TCPSTATUS_BYTE...

Page 14: ...sent by the tcps function TCPSend char cSckNum char cpTxBuffer int ipLen int MAX_TX_ATTEMPTS 20 int TX_FAILED 2 int TCP_BACKOFF_DLYS 2 int iResult 0 iInitLen ipLen iSent 0 iTxAttempts 0 int iReqLen c...

Page 15: ...ers are inaccessible up to 3 are supported or if the domain name does not resolve there can be an overall delay of between 125 and 140 seconds before the iprh function returns During this delay script...

Page 16: ...it Many modern systems use a TTL of 128 but apart from the most complex of routing arrangements a figure of 64 will be perfectly adequate 2 10 2 DNS Name Caching Period The TCP IP stack of the radio...

Reviews: