Data uploading through GPRS(uing TCP/FTP)

Hi,
I have wriiten a code On Q2686 to receive the data from serial port (UART2) and upload to the remote server through GPRS uing both TCP and FTP to upload the data, I’m using the sample application present in the open AT to do this .
Info:
Baudrate:9600
Open AT OS:6.20.04

I’m trying to upload 12kb of data to server But I’m facing lots of problem
Problem When I tried With TCP: I sent the data from PC using hyper terminal to the wavecom module(q2686) via UART2(Here I have used level convertor IC to B/W PC and wavecom module),
It uploads the data fine when I sent a “.txt” files from the PC but It didnt upload correct data when I sent “.dat files” I tried this many times same problem exits with “.dat” files but there is no problem when I tried to upload ".txt files it uploads all12kb of data . and it was uploaded only 2 to 3 kb and also it was not correct data , why its happening like this “.dat” files.

Problem When I tried With FTP: Here it uploads first 6kb of data fine and for the next 6kb it duplicates the same first 6Kb of data. ie out of 12kb first ~6 kb data is correct and next ~6kb of data is just duplicate of previous 6kb of data.

Here I have attched the function moudule(UART part and data upload part) which I have written for TCP part . and for FTP I retained the same UART part and changed only the uplaod part (used ftp sample program) .

Kindly help me to solve this problem.
thanks and regards
Ravee

Hi ,
I couldnt upload the file so Pasted the code here itself.
Pls help

static u8 snd_buffer[12002];
static u8 snd_bufferr[12002];
unsigned char dev_status = 0;
int atwritecnt=0;

/***********************************************************************************
READ THE DATA FROM UART
***********************************************************************************/
bool fcmdatahandler2(u16 datalen,u8 *data)
{

//adl_atSendResponsePort(ADL_AT_RSP, uart1_port,("Data at the Uart port  \n" ));
//adl_atSendResponsePort(ADL_AT_RSP, uart1_port," data at uart\n");
  u16 counter;

  	   if((dev_status & 0x01) == 0)
  	   	{

  		 for(counter=0;counter<datalen;counter++)
  			 	  	   		{

  			 	  		// if(data[counter]=='T' &&data[counter+1]=='H')
  			 	  		//	adl_atSendResponsePort(ADL_AT_RSP, uart1_port,"Rcvd the End\n");
  			 	  		 snd_bufferr[atwritecnt] = (u8)data[counter];
  			 	  	   		atwritecnt++;
  			 	  	   		}
  		 if(atwritecnt >= 12000)
  		 	  	   		{
  			dev_status |= 0X01;

  		 
  			atwritecnt = 0;
  			adl_atSendResponsePort(ADL_AT_RSP, uart1_port," 1200byt\n");
  			//send_sms("Oh thanks god i have received 12784b of data using status");
  		 	  	   		 //strcpy(snd_buffer,snd_bufferr);

  			        wm_memcpy(snd_buffer,snd_bufferr,12000);
  			      wm_memcpy(snd_bufferr,"",12002);
  		 	  	   			//Call FTP appln to upload the data
  		 	  	   			adl_tmrSubscribe ( FALSE, 100, ADL_TMR_TYPE_100MS, appli_entry_point()); 
  		 	  	   		}
  	   	}
return TRUE;

}

/*****************************************************************/
/
Function : evh_data /
/
-------------------------------------------------------------------------
/
/
Object : Handling events happenning on the TCP client socket. /
/
-------------------------------------------------------------------------
/
/
Variable Name |IN |OUT|GLB| Utilisation /
/
--------------------±–±--±–±---------------------------------------
/
/
ev | X | | | WIP event /
/
--------------------±–±--±–±---------------------------------------
/
/
ctx | X | | | user data (unused) /
/
--------------------±–±--±–±---------------------------------------
/
/***************************************************************************/
static void evh( wip_event_t *ev, void *ctx) {

switch( ev->kind) {

case WIP_CEV_OPEN: {
wip_debug ("[SAMPLE] Connection established successfully\n");
adl_atSendResponsePort(ADL_AT_RSP, uart1_port,("[SAMPLE] Connection established successfully\n"));

break;

}
case WIP_CEV_READ: {
int nread;
wip_debug ("[SAMPLE] Some data arrived\n");
adl_atSendResponsePort(ADL_AT_RSP, uart1_port,("[SAMPLE] Some data arrived\n"));
nread = wip_read( ev->channel, rcv_buffer + rcv_offset,
sizeof( rcv_buffer) - rcv_offset);
if( nread < 0) { wip_debug( “[SAMPLE] read error %i\n”, nread); return; }
rcv_offset += nread;
if( rcv_offset == sizeof( rcv_buffer)) {
wip_debug( “[SAMPLE] Reception capacity exceeded, won’t read more\n”);
} else {
wip_debug( “[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_DONE:
wip_debug (” Your Data Uploaded successfully\n");
adl_atSendResponsePort(ADL_AT_RSP, uart1_port,(" Your Data Uploaded successfully\n"));
break;
case WIP_CEV_WRITE: {
int nwrite;
// wip_debug ("[SAMPLE] Can send more data\n");
// wm_memcpy(snd_buffer+Mkdatalen,"",2000-Mkdatalen);
// adl_atSendResponsePort(ADL_AT_RSP, uart1_port,("[SAMPLE] Can send more data\n"));
nwrite = wip_write( ev->channel, snd_buffer + snd_offset,
sizeof( snd_buffer) - snd_offset);
if( nwrite < 0) { wip_debug( “[SAMPLE] write error %i\n”, nwrite); return; }
snd_offset += nwrite;

if( snd_offset == sizeof( snd_buffer)) {
 
	dev_status &=~0x01;
 
	wm_memcpy(snd_buffer,"",1002);
 
  wip_debug( "[SAMPLE] Everything has been sent, won't send more.\n");
  adl_atSendResponsePort(ADL_AT_RSP, uart1_port,("[SAMPLE] Everything has been sent, won't send more.\n"));
 print("[SAMPLE] Everything has been sent, won't send more.\n");
  //wip_debug("Buffer which has sent  %s", snd_buffer);

;

  wip_close( ev->channel);


} else {
  wip_debug( "[SAMPLE] Wrote %i bytes. "
             "%i bytes left to send in snd_buffer\n",
             nwrite, sizeof( snd_buffer) - snd_offset);
}
break;

}
case WIP_CEV_ERROR: {
wip_debug( “[SAMPLE] Error %i on socket. Closing.\n”,
ev->content.error.errnum);
adl_atSendResponsePort(ADL_AT_RSP, uart1_port,("[SAMPLE] Error %i on socket. Closing.\n"));
wip_close( ev->channel);
adl_tmrSubscribe ( FALSE, 100, ADL_TMR_TYPE_100MS, FTP_TimerHandler18MS);//call FTP after time out
break;
}
case WIP_CEV_PEER_CLOSE: {
wip_debug( “[SAMPLE] Connection closed by peer\n”);
adl_atSendResponsePort(ADL_AT_RSP, uart1_port,("[SAMPLE] Connection closed by peer\n"));
wip_close( ev->channel);

break;

}
}
}