Part Number:CC3100SDK
I am configuring cc3100 as an access point. Mobile phone acts as client i.e STA, which will connect to access point i.e cc3100 and perform file download via FTP.
I am able to download files properly most of the times but sometimes I am observing timeout on the mobile client side. Client socket will timeout. (Reproducible of timeout is once in every 10 iterations).
What could be the reason? Is there anything we have to take care on cc3100. i.e on usage of sl_send. I will be transferring file data continuously in 1K size packets using sl_Send.
In the below example we are just dumping the data packets on sl_Send and checking for the errors. But do not know whether the client has received it or not.
Is there a way to check the transferred data is properly received by mobile client. i.e sl_Send will wait until the data is read by the client STA mobile device.
Code :
#define MAX_NUM_OF_TX_BYTES 1024
uint8_t *pui8FileBuff = FileBuffData[40960];
SlSockAddrIn_t tActiveRemoteAddr;
uint32_t ui32BufferOffset = 0;
uint16_t ui16BytesToBeTransfered = 0;
//Get the Ip address and port number of data port from command
sscanf((const char *)ms_ui8RxBuffer, "PORT %d,%d,%d,%d,%d,%d",&iActIp[0], &iActIp[1], &iActIp[2], &iActIp[3], (int*)&iActPort[0], (int*)&iActPort[1]);
iPortDec = iActPort[0]*256 + iActPort[1];
#ifdef _EMULATOR
printf("IP is %d.%d.%d.%d\n",iActIp[0],iActIp[1],iActIp[2],iActIp[3]);
printf("port %d\n",iPortDec);
#endif
//open new socket for data transfer
ms_i16SDataAct = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0);
if( ms_i16SDataAct < 0 )
{
#ifdef _EMULATOR
printf(" [TCP data socket] Create socket Error \n\r");
#endif
return EN_ERR_SOCKET;
}//end of if( ms_i16SDataAct < 0 )
tActiveRemoteAddr.sin_family = SL_AF_INET; //IPv4 socket
tActiveRemoteAddr.sin_port = sl_Htons((_u16)iPortDec); //client dataport number
tActiveRemoteAddr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(iActIp[0], iActIp[1], iActIp[2],iActIp[3])); //client dataport ipaddress
if (sl_Connect(ms_i16SDataAct, ( SlSockAddr_t *)&tActiveRemoteAddr, (_u16) sizeof(SlSockAddr_t)) < 0)
{
if(ms_i16SDataAct >= 0)
{
sl_Close(ms_i16SDataAct); //CLose the socket of data port on failure
ms_i16SDataAct = -1;
}
}
//Transfer the filedata in packets of 1K size in loop.
while (ui32BufferOffset < ui32NumofBytesRead)
{
ui16BytesToBeTransfered = MAX_NUM_OF_TX_BYTES;
//check for the remaining bytes to be transfered
if (ui16BytesToBeTransfered > (ui32NumofBytesRead - ui32BufferOffset))
{
ui16BytesToBeTransfered = ui32NumofBytesRead - ui32BufferOffset;
}
i32NumOfBytesSent = sl_Send(ms_i16SDataAct, (pui8FileBuff + ui32BufferOffset), ui16BytesToBeTransfered, 0);
if(i32NumOfBytesSent < 0)
return ERR_SL_SEND;
//Increase the buffer offset
ui32BufferOffset += ui16BytesToBeTransfered;
//Need to add NonOsMainloop for busy loops
_SlNonOsMainLoopTask();
} //endof while
Thanks & Regards,
Durga Prasad.