コード例 #1
0
void prvPingTask(void *pvParameters)
{
    for(;;) {
        debug("Sending ping request...\n");
        FreeRTOS_SendPingRequest(FreeRTOS_inet_addr("192.168.0.1") , 8, 100 / portTICK_PERIOD_MS );
        vTaskDelay(2000);
    }
}
コード例 #2
0
	static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
	{
	char * pcParameter;
	BaseType_t lParameterStringLength, xReturn = pdFALSE;
	uint32_t ulIPAddress, ulBytesToPing;
	const uint32_t ulDefaultBytesToPing = 8UL;
	char cBuffer[ 16 ];

		/* Remove compile time warnings about unused parameters, and check the
		write buffer is not NULL.  NOTE - for simplicity, this example assumes the
		write buffer length is adequate, so does not check for buffer overflows. */
		( void ) pcCommandString;
		( void ) xWriteBufferLen;
		configASSERT( pcWriteBuffer );

		/* Start with an empty string. */
		pcWriteBuffer[ 0 ] = 0x00;

		/* Obtain the number of bytes to ping. */
		pcParameter = ( char * ) FreeRTOS_CLIGetParameter
								(
									pcCommandString,		/* The command string itself. */
									2,						/* Return the second parameter. */
									&lParameterStringLength	/* Store the parameter string length. */
								);

		if( pcParameter == NULL )
		{
			/* The number of bytes was not specified, so default it. */
			ulBytesToPing = ulDefaultBytesToPing;
		}
		else
		{
			ulBytesToPing = atol( pcParameter );
		}

		/* Obtain the IP address string. */
		pcParameter = ( char * ) FreeRTOS_CLIGetParameter
								(
									pcCommandString,		/* The command string itself. */
									1,						/* Return the first parameter. */
									&lParameterStringLength	/* Store the parameter string length. */
								);

		if( pcParameter != NULL )
		{
			/* Terminate the host name or IP address string. */
			pcParameter[ lParameterStringLength ] = 0x00;

			/* Attempt to obtain the IP address.   If the first character is not a
			digit, assume the host name has been passed in. */
			if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
			{
				ulIPAddress = FreeRTOS_inet_addr( pcParameter );
			}
			else
			{
				/* Attempt to resolve host. */
				ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
			}

			/* Convert IP address, which may have come from a DNS lookup, to string. */
			FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );

			if( ulIPAddress != 0 )
			{
				xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
			}
		}

		if( xReturn == pdFALSE )
		{
			sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
		}
		else
		{
			sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, ( int ) xReturn );
		}

		return pdFALSE;
	}
コード例 #3
0
ファイル: FreeRTOS_DNS.c プロジェクト: cjlano/freertos
uint32_t FreeRTOS_gethostbyname_a( const char *pcHostName, FOnDNSEvent pCallback, void *pvSearchID, TickType_t xTimeout )
#endif
{
uint32_t ulIPAddress = 0UL;
static uint16_t usIdentifier = 0u;
TickType_t xReadTimeOut_ms = 1200U;
/* Generate a unique identifier for this query. Keep it in a local variable
 as gethostbyname() may be called from different threads */
TickType_t xIdentifier = ( TickType_t )usIdentifier++;

	/* If the supplied hostname is IP address, convert it to uint32_t
	and return. */
	#if( ipconfigINCLUDE_FULL_INET_ADDR == 1 )
	{
		ulIPAddress = FreeRTOS_inet_addr( pcHostName );
	}
	#endif /* ipconfigINCLUDE_FULL_INET_ADDR == 1 */

	/* If a DNS cache is used then check the cache before issuing another DNS
	request. */
	#if( ipconfigUSE_DNS_CACHE == 1 )
	{
		if( ulIPAddress == 0UL )
		{
			ulIPAddress = FreeRTOS_dnslookup( pcHostName );
			if( ulIPAddress != 0 )
			{
				FreeRTOS_debug_printf( ( "FreeRTOS_gethostbyname: found '%s' in cache: %lxip\n", pcHostName, ulIPAddress ) );
			}
			else
			{
				/* prvGetHostByName will be called to start a DNS lookup */
			}
		}
	}
	#endif /* ipconfigUSE_DNS_CACHE == 1 */

	#if( ipconfigDNS_USE_CALLBACKS != 0 )
	{
		if( pCallback != NULL )
		{
			if( ulIPAddress == 0UL )
			{
				/* The user has provided a callback function, so do not block on recvfrom() */
				xReadTimeOut_ms  = 0;
				vDNSSetCallBack( pcHostName, pvSearchID, pCallback, xTimeout, ( TickType_t ) xIdentifier );
			}
			else
			{
				/* The IP address is known, do the call-back now. */
				pCallback( pcHostName, pvSearchID, ulIPAddress );
			}
		}
	}
	#endif

	if( ulIPAddress == 0UL)
	{
		ulIPAddress = prvGetHostByName( pcHostName, xIdentifier, xReadTimeOut_ms );
	}

	return ulIPAddress;
}