示例#1
0
文件: FTPlib.c 项目: Hotfirenet/Tuto
/**
 * Verifies how many bytes can be read from the specified FTP socket.
 * \param ftpsocklen - The handle of the socket to control (the handle returned by the command FTPOpen).
 * \return The number of bytes available to be read.
 */
WORD FTPRxLen(TCP_SOCKET ftpsocklen)
{
	return TCPRxLen(ftpsocklen);
}
BOOL XivelyPut(TCP_SOCKET MySocket, char* tmpString)
{
	char resString[250];
	BOOL result;
	int i;
	static ROM char GoodHTTPResponse[] = "{\"status\":200";

	#if defined(STACK_USE_UART)
	UARTWrite(1,tmpString);
	#endif
	// Send the blob
	TCPWrite( MySocket, tmpString, (int)strlen(tmpString) );
	#if defined(STACK_USE_UART)
	UARTWrite(1,"Data sent, Waiting response.\r\n");
	#endif
	vTaskDelay(500);
	
	// Make sure there are enough chars to read
	i = 10;
	while (i>0 && (TCPRxLen(MySocket) < 16))
	{
		//vTaskDelay( xDelay(500) );
		vTaskDelay(500);

		i--;
	}
		if(i!=0) 
	{
		// Get the response from the server
		TCPRead( MySocket, resString, 250 );
		#if defined(STACK_USE_UART)
		UARTWrite(1,resString);
		UARTWrite(1,"\r\n");
		#endif
		if (strstr( resString, GoodHTTPResponse) == NULL)
		{
			// We are in an error condition, so light up the Flyport led
			result = FALSE;
			#if defined(STACK_USE_UART)
			UARTWrite(1,"Request failed.\r\n");
			#endif
		} 
		else 
		{
			#if defined(STACK_USE_UART)
			UARTWrite(1,"Request succeeded.\r\n");
			#endif
			result = TRUE;
		}
	}
	
	else 
	{
		#if defined(STACK_USE_UART)
		UARTWrite(1,"Server did not reply.\r\n");
		#endif
		result = FALSE;
	}

	vTaskDelay(500);
	
	return result;
}